Azure / azure-cosmosdb-bulkexecutor-dotnet-getting-started

Bulk Executor Utility for Azure Cosmos DB .NET SQL API
MIT License
66 stars 41 forks source link

How to retry bulk import if it fails or not imported all document in one batch/call. #38

Closed AjitBhosale closed 5 years ago

AjitBhosale commented 5 years ago

executing bulk import with following configurations -

  1. MaxRetryWaitTimeInSeconds and MaxRetryAttemptsOnThrottledRequests set to 0.
  2. Importing document without id, enableUpsert is flase and disableAutomaticIdGeneration is false.
  3. code -

    do { try { bulkImportResponse = await bulkExecutor.BulkImportAsync(bulkDocument, false, false); } catch (Exception e) { // log exception } } while (bulkImportResponse.NumberOfDocumentsImported < bulkDocument.Count());

So if it throw any exception during documents insertion(line 5) than it will rollback inserted document internally or not? if not than i require to remove NumberOfDocumentsImported from bulkDocument before retry with do-while loop?

abinav2307 commented 5 years ago

If the batch fails, you can simply re-run the BulkImportAsync method with the same batch of documents, but this time, with enableUpsert set to true.

As a pre-processing step for a scenario such as this, we would also recommend assigning Guids as ids for the documents to avoid duplicates when retrying the batch.