"Unexpected response code for operation: 0" while performing Azure Table Storage batch uninstall

I am using version 4.3.0 for Windows Azure libraries for .NET. In my ATS repository class, I have several batch removal methods that look like this:

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); } 

Elsewhere in my code, this DeleteAsync() method works correctly. However, in one specific place, I get this error message while executing a package:

 Unexpected Response Code for Operation: 0 

Here's the call site:

 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() method UpsertAsync() , but DeleteAsync() fails. Please note that it does not delete exactly the same objects that FindByPartitionRowAsync() retrieved from the table, so I cannot imagine how this could have anything to do with distorted objects or anything from this file.

Here is an example of one of the "toDelete" objects (in JSON format):

 { "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 Storage error messages are known and impressively useless, and Googling did not respond that batch deletes did not run with this particular error.

This does not work when using the local development repository, or during the production process.

Any thoughts?

+7
source share
3 answers

"Unexpected response code for operation: 0" basically means that the first operation in the batch failed. The index of a failed operation is returned in the event of an error, so the user becomes simpler and cannot perform a specific operation in a batch error.

You can get additional information about the failed request and error by catching StorageException and checking:

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

The same information is also available in the last result of the OperationContext if you use the OperationContext to track the request and use the appropriate method overloads that are accepted in the OperationContext.

We will look at changing the error message in the future so that it is less confusing. Thanks for the answer!

+26
source

in my case, he got permission to make a mistake. ' Microsoft.WindowsAzure.Storage.StorageException:' Element 0 in package returned an unexpected response code

code snippet

table.CreateIfNotExists ();

Main code

CloudStorageAccount SA = CloudStorageAccount.Parse (CloudConfigurationManager.GetSetting ("SC"));

CloudTableClient tableClient = SA.CreateCloudTableClient ();

Table CloudTable = tableClient.GetTableReference ("myWorld");

table.CreateIfNotExists ();

TableBatchOperation batchOperation = new TableBatchOperation ();

batchOperation.Insert (object);

table.ExecuteBatch (batchOperation);

0
source

Another reason for this is the use of invalid characters in key fields. If you google this error message, you can skip this answer:

Azure Table Storage RowKey Limited Character Templates?

Characters are not allowed in key fields The following characters are not allowed in the values ​​of the PartitionKey and RowKey properties:

Slash Character (/)

Backslash Character ()

Sign of the number (#) symbol

Question mark (?) Symbol

Control characters from U + 0000 to U + 001F, including:

The horizontal tab character (\ t)

Line feed character (\ n)

Carriage Return Character (\ r)

Control characters from U + 007F to U + 009F

0
source

Source: https://habr.com/ru/post/1205118/


All Articles