Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling unsuccessful documents upsert / delete via Bulk API #4748

Open
cieciurm opened this issue Oct 4, 2024 · 0 comments
Open

Handling unsuccessful documents upsert / delete via Bulk API #4748

cieciurm opened this issue Oct 4, 2024 · 0 comments
Labels
customer-reported Issue created by a customer needs-investigation

Comments

@cieciurm
Copy link

cieciurm commented Oct 4, 2024

Hi,

I've migrated my application using Azure CosmosDB SDK to v3 and I'm using the bulk functionality to upsert somewhere between 200 and 1000 items.

Using the BulkExecutor and its configuration I was getting 100% success rate when upserting - all documents were saved.

In V3 I'm getting 429 response, and only some documents are saved. I'm not sure how I should handle those that were not saved.

ClientOptions setup:

var options = new CosmosDbOptions
{
  AllowBulkExecution = true,
  MaxRetryWaitTimeOnRateLimitedRequests = TimeSpan.FromSeconds(60),
  MaxRetryAttemptsOnRateLimitedRequests = 19,
}

I'm using the BulkOperations<T> wrapper as described in the docs.

My main method for bulk upserting looks like this:

public async Task<BulkOperationResponse<TDocument>> ImportAsync(IEnumerable<TDocument> documents)
{
     var bulkOperations = new BulkOperations<TDocument>(documents.Count());

    foreach (var document in documents)
    {
        bulkOperations.Tasks.Add(CaptureOperationResponse(_container.Value.CreateItemAsync(document, new PartitionKey(document.PartitionKey)), document));
    }

    var response = await bulkOperations.ExecuteAsync();
    return response;
}

After inspecting the BulkOperationResponse<T> I often see that only a chunk of documents, were saved.

image

I have the same issue when trying to bulk delete documents via a method:

public async Task<BulkOperationResponse<TDocument>> DeleteAsync(IEnumerable<TDocument> documents)
{
    var bulkOperations = new BulkOperations<TDocument>(documents.Count());

    foreach (var document in documents)
    {
        bulkOperations.Tasks.Add(CaptureOperationResponse(_container.Value.DeleteItemAsync<TDocument>(document.Id, new PartitionKey(document.PartitionKey)), document));
    }

    var response = await bulkOperations.ExecuteAsync();

    return response;
}

I'm using a shared throughput for 4 containers - 400 RU/s.

What's the recommended approach to retry upserting of the failed documents?
Should it be handled by the SDK or should I retry in my code?

Thanks in advance for any guidance :)

Environment summary
SDK Version: 3.43.1

@microsoft-github-policy-service microsoft-github-policy-service bot added the customer-reported Issue created by a customer label Oct 4, 2024
@cieciurm cieciurm changed the title Handling unsuccessful documents upsert via Bulk API Handling unsuccessful documents upsert / delete via Bulk API Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issue created by a customer needs-investigation
Projects
None yet
Development

No branches or pull requests

1 participant