gpt4 book ai didi

c# - "Unexpected Response Code for Operation: 0"执行 Azure Table Storage 批量删除时

转载 作者:太空狗 更新时间:2023-10-29 19:50:42 24 4
gpt4 key购买 nike

我使用的是适用于 .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 存储错误消息毫无帮助,而且谷歌搜索没有返回任何关于批量删除因该特定错误而失败的信息。

这在使用本地开发存储和生产环境时都失败了。

有什么想法吗?

最佳答案

'Unexpected Response Code for Operation: 0' 基本上意味着批处理中的第一个操作失败。失败操作的索引在抛出的错误中返回,因此用户可以更轻松地更改失败的批处理中的特定操作。

您可以通过捕获 StorageException 并检查来获取有关失败请求和错误的更多信息:

  • exception.RequestInformation.HttpStatusCode
  • exception.RequestInformation.ExtendedErrorInformation.ErrorCode
  • exception.RequestInformation.ExtendedErrorInformation.ErrorMessage

如果您使用 OperationContext 跟踪请求并使用接受 OperationContext 的合适方法重载,则 OperationContext 的最后结果中也提供相同的信息。

我们将考虑在未来更改错误消息,以减少混淆。感谢您的反馈!

关于c# - "Unexpected Response Code for Operation: 0"执行 Azure Table Storage 批量删除时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26472190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com