![](/img/trans.png)
[英]Azure Table Storage, ExecuteBatchAsync, Unexpected response code for operation : 0
[英]“Unexpected Response Code for Operation: 0” when executing Azure Table Storage batch delete
我使用的是適用於.NET的Windows Azure存儲庫的版本4.3.0。 在我的ATS儲存庫類中,我有幾個批處理刪除方法,如下所示:
public async Task DeleteAsync(IEnumerable<T> entities)
{
await ExecuteAsBatch(entities, (batch, entity) => batch.Delete(entity));
}
private async Task ExecuteAsBatch(IEnumerable<T> entities, Action<TableBatchOperation, T> batchAction)
{
var byPartition = entities.GroupBy(x => x.PartitionKey).ToList();
await byPartition.ForEachParallel(async group =>
{
// A maximum of 100 actions are allowed per batch job
var segments = group.ToList().ToSegmentedList(100);
await segments.ForEachParallel(async segment =>
{
var batch = new TableBatchOperation();
foreach (var entity in segment)
{
batchAction(batch, entity);
}
await Table.ExecuteBatchAsync(batch);
}, 10);
}, 10);
}
在我代碼的其他地方,該DeleteAsync()
方法可以正常工作。 但是,在一個特定的位置,執行批處理時出現此錯誤消息:
Unexpected Response Code for Operation: 0
這里是呼叫站點:
private async Task MergeAtsOrganizationUserEvents(int organizationId, IEnumerable<CustomerUserEvent> fromEvents, CustomerUser to)
{
var toDelete = (await fromEvents.SelectParallel(async fromEvent =>
{
var pkey = AtsOrganizationUserEventByMinute.GetPartitionKey(organizationId, fromEvent.OccurredOn);
var rkey = AtsOrganizationUserEventByMinute.GetRowKey(fromEvent.OccurredOn, fromEvent.CustomerUserEventId);
return await Ats.OrganizationUserEventByMinute.FindByPartitionRowAsync(pkey, rkey);
})).Where(x => x != null).ToList();
var toInsert = toDelete
.Select(x => AtsOrganizationUserEventByMinute.FromBase(x.OrganizationId, x.OccurredOn, x.CookieId,
to.CustomerUserId, x))
.ToList();
try
{
await Ats.OrganizationUserEventByMinute.UpsertAsync(toInsert);
await Ats.OrganizationUserEventByMinute.DeleteAsync(toDelete);
}
catch (Exception ex)
{
_logger.Error("Unable to merge {0} AtsOrganizationEvents for org {1}, to customer user {2}: {3}",
toInsert.Count, organizationId, to.CustomerUserId, ex.CompleteMessage());
throw;
}
}
上面的UpsertAsync()
方法成功,但是DeleteAsync()
失敗。 請注意,它無法刪除與從表中檢索到的FindByPartitionRowAsync()
完全相同的實體,因此我無法想象它與變形的實體或任何類似的實體有什么關系。
這是一個“ toDelete”對象(JSON格式)的示例:
{
"CookieId":null,
"CustomerUserId":185766,
"CustomerUserEventId":3568687,
"OrganizationId":4190,
"EventName":"event1",
"SessionId":null,
"OccurredOn":"2014-10-20T18:17:09.9971379Z",
"UrlId":null,
"Url":null,
"ReferrerUrlId":null,
"ReferrerUrl":null,
"IsSynthetic":false,
"IpAddress":null,
"PartitionKey":"4190.2014.10.20",
"RowKey":"18.17.3568687",
"Timestamp":"2014-10-20T18:17:11.237+00:00",
"ETag":"W/\\" datetime'2014-10-20T18%3A17%3A11.237Z'\\""
}
眾所周知,Azure存儲錯誤消息無濟於事,並且無濟於事,並且Googling對於因該特定錯誤而導致的批量刪除失敗沒有返回任何信息。
在使用本地開發存儲和在生產中這都失敗。
有什么想法嗎?
“意外的操作響應代碼:0”基本上意味着該批次中的第一個操作失敗。 失敗的操作的索引會在拋出的錯誤中返回,因此它使用戶可以更輕松地更改失敗的批處理中的特定操作。
您可以通過捕獲StorageException並檢查以下內容來獲取有關失敗的請求和錯誤的更多信息:
exception.RequestInformation.HttpStatusCode
exception.RequestInformation.ExtendedErrorInformation.ErrorCode
exception.RequestInformation.ExtendedErrorInformation.ErrorMessage
如果您使用OperationContext跟蹤請求並使用OperationContext中采用的適當方法重載,則在OperationContext的最后結果中也可以使用相同的信息。
我們將在將來着眼於更改錯誤消息,以減少混亂。 感謝您的反饋!
就我而言,它已經解決了錯誤。 ' Microsoft.WindowsAzure.Storage.StorageException:'批處理中的元素0返回了意外的響應代碼 '
程式碼片段
table.CreateIfNotExists();
主要代號
CloudStorageAccount SA = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting(“ SC”));
CloudTableClient tableClient = SA.CreateCloudTableClient();
CloudTable表= tableClient.GetTableReference(“ myWorld”);
table.CreateIfNotExists();
TableBatchOperation batchOperation = new TableBatchOperation();
batchOperation.Insert(object);
table.ExecuteBatch(batchOperation);
造成這種情況的另一個原因是在關鍵字段中使用了無效字符。 如果您正在搜索此錯誤消息,則可能會錯過以下答案:
鍵字段中不允許使用的字符PartitionKey和RowKey屬性的值中不允許使用以下字符:
正斜杠(/)字符
反斜杠()字符
數字符號(#)字符
問號(?)字符
從U + 0000到U + 001F的控制字符,包括:
水平制表符(\\ t)
換行符(\\ n)
回車符(\\ r)
從U + 007F到U + 009F的控制字符
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.