Skip to content

Commit

Permalink
Batch API: Fixes the size limit to match with bulk v2. (#1757)
Browse files Browse the repository at this point in the history
* Batch size update

Signed-off-by: Rakesh Kumar <rakkuma@microsoft.com>

* Test case

Signed-off-by: Rakesh Kumar <rakkuma@microsoft.com>

* code review fix

Signed-off-by: Rakesh Kumar <rakkuma@microsoft.com>

* Fixing comment

Signed-off-by: Rakesh Kumar <rakkuma@microsoft.com>

Co-authored-by: j82w <j82w@users.noreply.github.com>
Co-authored-by: Matias Quaranta <ealsur@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 7, 2020
1 parent efade5c commit 4411655
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Microsoft.Azure.Cosmos
/// </summary>
internal class BatchAsyncContainerExecutorCache : IDisposable
{
// Keeping same performance tuned value of Bulk V2.
internal const int DefaultMaxBulkRequestBodySizeInBytes = 220201;
private ConcurrentDictionary<string, BatchAsyncContainerExecutor> executorsPerContainer = new ConcurrentDictionary<string, BatchAsyncContainerExecutor>();

public BatchAsyncContainerExecutor GetExecutorForContainer(
Expand All @@ -35,7 +37,7 @@ public BatchAsyncContainerExecutor GetExecutorForContainer(
container,
cosmosClientContext,
Constants.MaxOperationsInDirectModeBatchRequest,
Constants.MaxDirectModeBatchRequestBodySizeInBytes);
DefaultMaxBulkRequestBodySizeInBytes);
if (!this.executorsPerContainer.TryAdd(containerLink, newExecutor))
{
newExecutor.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task RetryOnSplit()
},
string.Empty);
mockContainer.Setup(x => x.GetRoutingMapAsync(It.IsAny<CancellationToken>())).Returns(Task.FromResult(routingMap));
BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, Constants.MaxDirectModeBatchRequestBodySizeInBytes);
BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, BatchAsyncContainerExecutorCache.DefaultMaxBulkRequestBodySizeInBytes);
TransactionalBatchOperationResult result = await executor.AddAsync(itemBatchOperation);

Mock.Get(mockContainer.Object)
Expand Down Expand Up @@ -117,7 +117,7 @@ public async Task RetryOnNameStale()
},
string.Empty);
mockContainer.Setup(x => x.GetRoutingMapAsync(It.IsAny<CancellationToken>())).Returns(Task.FromResult(routingMap));
BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, Constants.MaxDirectModeBatchRequestBodySizeInBytes);
BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, BatchAsyncContainerExecutorCache.DefaultMaxBulkRequestBodySizeInBytes);
TransactionalBatchOperationResult result = await executor.AddAsync(itemBatchOperation);

Mock.Get(mockContainer.Object)
Expand Down Expand Up @@ -177,7 +177,7 @@ public async Task RetryOn429()
},
string.Empty);
mockContainer.Setup(x => x.GetRoutingMapAsync(It.IsAny<CancellationToken>())).Returns(Task.FromResult(routingMap));
BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, Constants.MaxDirectModeBatchRequestBodySizeInBytes);
BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, BatchAsyncContainerExecutorCache.DefaultMaxBulkRequestBodySizeInBytes);
TransactionalBatchOperationResult result = await executor.AddAsync(itemBatchOperation);

Mock.Get(mockContainer.Object)
Expand Down Expand Up @@ -236,7 +236,7 @@ public async Task DoesNotRecalculatePartitionKeyRangeOnNoSplits()
},
string.Empty);
mockContainer.Setup(x => x.GetRoutingMapAsync(It.IsAny<CancellationToken>())).Returns(Task.FromResult(routingMap));
BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, Constants.MaxDirectModeBatchRequestBodySizeInBytes);
BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, BatchAsyncContainerExecutorCache.DefaultMaxBulkRequestBodySizeInBytes);
TransactionalBatchOperationResult result = await executor.AddAsync(itemBatchOperation);

Mock.Get(mockContainer.Object)
Expand Down

0 comments on commit 4411655

Please sign in to comment.