From 4411655cee17aa1eac54e36c3b931f6b78826c26 Mon Sep 17 00:00:00 2001 From: rakkuma <49558901+rakkuma@users.noreply.github.com> Date: Sat, 8 Aug 2020 04:46:22 +0530 Subject: [PATCH] Batch API: Fixes the size limit to match with bulk v2. (#1757) * Batch size update Signed-off-by: Rakesh Kumar * Test case Signed-off-by: Rakesh Kumar * code review fix Signed-off-by: Rakesh Kumar * Fixing comment Signed-off-by: Rakesh Kumar Co-authored-by: j82w Co-authored-by: Matias Quaranta --- .../src/Batch/BatchAsyncContainerExecutorCache.cs | 4 +++- .../Batch/BatchAsyncContainerExecutorTests.cs | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncContainerExecutorCache.cs b/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncContainerExecutorCache.cs index f8141cffd4..a16683b400 100644 --- a/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncContainerExecutorCache.cs +++ b/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncContainerExecutorCache.cs @@ -14,6 +14,8 @@ namespace Microsoft.Azure.Cosmos /// internal class BatchAsyncContainerExecutorCache : IDisposable { + // Keeping same performance tuned value of Bulk V2. + internal const int DefaultMaxBulkRequestBodySizeInBytes = 220201; private ConcurrentDictionary executorsPerContainer = new ConcurrentDictionary(); public BatchAsyncContainerExecutor GetExecutorForContainer( @@ -35,7 +37,7 @@ public BatchAsyncContainerExecutor GetExecutorForContainer( container, cosmosClientContext, Constants.MaxOperationsInDirectModeBatchRequest, - Constants.MaxDirectModeBatchRequestBodySizeInBytes); + DefaultMaxBulkRequestBodySizeInBytes); if (!this.executorsPerContainer.TryAdd(containerLink, newExecutor)) { newExecutor.Dispose(); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchAsyncContainerExecutorTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchAsyncContainerExecutorTests.cs index cc6a4af9eb..eb514d979b 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchAsyncContainerExecutorTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchAsyncContainerExecutorTests.cs @@ -57,7 +57,7 @@ public async Task RetryOnSplit() }, string.Empty); mockContainer.Setup(x => x.GetRoutingMapAsync(It.IsAny())).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) @@ -117,7 +117,7 @@ public async Task RetryOnNameStale() }, string.Empty); mockContainer.Setup(x => x.GetRoutingMapAsync(It.IsAny())).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) @@ -177,7 +177,7 @@ public async Task RetryOn429() }, string.Empty); mockContainer.Setup(x => x.GetRoutingMapAsync(It.IsAny())).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) @@ -236,7 +236,7 @@ public async Task DoesNotRecalculatePartitionKeyRangeOnNoSplits() }, string.Empty); mockContainer.Setup(x => x.GetRoutingMapAsync(It.IsAny())).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)