我正在使用适用于.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);
}
Run Code Online (Sandbox Code Playgroud)
在我的代码的其他地方,该DeleteAsync()方法正常工作.但是,在一个特定的地方,我在执行批处理时收到此错误消息:
Unexpected Response Code for Operation: 0
Run Code Online (Sandbox Code Playgroud)
这是呼叫站点:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
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'\\""
}
Run Code Online (Sandbox Code Playgroud)
Azure存储错误消息是众所周知且非常无益的,并且谷歌搜索没有返回任何有关此特定错误失败的批量删除.
在使用本地开发存储和生产时,这都失败了.
有什么想法吗?
小智 26
'意外的操作响应代码:0'基本上意味着批处理中的第一个操作失败.在抛出的错误中返回失败操作的索引,这样用户就可以更轻松地更改失败批处理中的特定操作.
您可以通过捕获StorageException并检查以下内容来获取有关失败请求和错误的更多信息:
exception.RequestInformation.HttpStatusCodeexception.RequestInformation.ExtendedErrorInformation.ErrorCodeexception.RequestInformation.ExtendedErrorInformation.ErrorMessage如果您使用OperationContext跟踪请求并使用接收OperationContext的合适方法重载,则OperationContext的最后结果中也会提供相同的信息.
我们将在未来更改错误消息,以免混淆.感谢您的反馈!