2014-10-20 17 views
5

Utilizzo la versione 4.3.0 delle librerie di Archiviazione di Windows di Windows per .NET. Nella mia classe repository ATS, ho un paio di lotti eliminare metodi che assomigliano a questo:"Codice di risposta imprevisto per l'operazione: 0" quando si esegue l'eliminazione batch di Archiviazione tabella Azure

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

In altri posti nel mio codice, che DeleteAsync() metodo funziona correttamente. Tuttavia, in un luogo particolare, ricevo questo messaggio di errore durante l'esecuzione del lotto:

Unexpected Response Code for Operation: 0 

Ecco il sito di chiamata:

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

Il metodo UpsertAsync() sopra riesce, ma il DeleteAsync() fallisce. Si noti che non riesce a eliminare con precisione le stesse entità che FindByPartitionRowAsync() ha recuperato dalla tabella, quindi non riesco a immaginare come potrebbe avere nulla a che fare con entità malformate o qualcosa del genere.

Ecco un esempio di uno degli oggetti "toDelete" (in formato 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'\\"" 
} 

messaggi di errore Azure sono notoriamente e spettacolarmente inutili, e usare Google è tornato nulla batch elimina in mancanza di questo particolare errore.

Questo errore si verifica quando si utilizza lo storage di sviluppo locale e in fase di produzione.

Qualche idea?

+0

Ciao Ken, ti dispiacerebbe condividere il tuo codice .ForEachParallel() e .ToSegmentedList() è qualcosa che sembra molto utile. Grazie. –

+0

Sicuro. Vedere https://gist.github.com/smithkl42/ca5b98e909952eddef1e3a076c0dd91d e https://gist.github.com/smithkl42/36ca70a63fe1a3bbf2d03a4d0bbe46c2. –

risposta

21

'Codice di risposta imprevisto per operazione: 0' significa in sostanza che la prima operazione nel batch non è riuscita. L'indice dell'operazione non riuscita viene restituito nell'errore generato in modo che sia più semplice per gli utenti andare e modificare l'operazione specifica nel batch che non è riuscita.

È possibile ottenere ulteriori informazioni sulla richiesta che non è riuscita e l'errore di prendere lo StorageException e controllo:

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

La stessa informazione è anche disponibile nell'ultimo risultato di OperationContext se si utilizza OperationContext per tracciare la richiesta e utilizzare me adatto sovraccarichi di thod che contengono OperationContext.

Guarderemo a cambiare il messaggio di errore in futuro, quindi è meno confuso. Grazie per il feedback!

0

nel mio caso è stato risolto per l'errore. 'Microsoft.WindowsAzure.Storage.StorageException: 'Elemento 0 nel batch ha restituito un codice di risposta inaspettata'

frammento di codice

tavolo.CreateIfNotExists();

codice principale

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

Tabella CloudTableClientClient = SA.CreateCloudTableClient();

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

table.CreateIfNotExists();

TableBatchOperation batchOperation = new TableBatchOperation();

batchOperation.Insert (oggetto);

table.ExecuteBatch (batchOperation);

Problemi correlati