-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Transactional batch for Java #15775
Transactional batch for Java #15775
Conversation
Signed-off-by: Rakesh Kumar <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some specific comments to api and implementation.
The following ones are common comments which are applicable to different classes. Summarizing them here to avoid repeating them everywhere. Please go over these and ensure addressed everywhere.
-
any class in com.azure.cosmos is in our public apis (Except
BridgeInternal
). in this package, If a method is not meant to be used by the end user, then it should not be marked as public. If a method in the public package is only meant to be used for internal implementation by other java packages, then it should be package private and you should use BridgeInternal technique to access the method from other packages.
There are places in different public classes that setter or constructor is only used by implementation. those should not be public. -
implementing
AutoClosable
in batch response. It seems to me it is a 1-1 port from dot-netdisposable
. Do you have any specific use-case in Java? I didn't see anything inclose()
method which requires special handing. -
sublcassing
List
. that seems smelly to me why we should do that. other option is to just add the methods which are relevant instead of subclassing List. -
please follow our test pattern both for assertion and also re-using shared db/container resources as our tests are running against prod
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncContainer.java
Outdated
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/TransactionalBatch.java
Outdated
Show resolved
Hide resolved
...cosmos/azure-cosmos/src/main/java/com/azure/cosmos/TransactionalBatchItemRequestOptions.java
Outdated
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/TransactionalBatchOperationResult.java
Outdated
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/TransactionalBatchOperationResult.java
Outdated
Show resolved
Hide resolved
...os/azure-cosmos/src/main/java/com/azure/cosmos/implementation/batch/BatchResponseParser.java
Outdated
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/batch/BatchExecUtils.java
Outdated
Show resolved
Hide resolved
...os/azure-cosmos/src/main/java/com/azure/cosmos/implementation/batch/BatchResponseParser.java
Outdated
Show resolved
Hide resolved
...os/azure-cosmos/src/main/java/com/azure/cosmos/implementation/batch/BatchResponseParser.java
Outdated
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/BatchTestBase.java
Outdated
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/TransactionalBatch.java
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/TransactionalBatchResponse.java
Outdated
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/OperationType.java
Show resolved
Hide resolved
...os/azure-cosmos/src/main/java/com/azure/cosmos/implementation/batch/BatchResponseParser.java
Outdated
Show resolved
Hide resolved
...os/azure-cosmos/src/main/java/com/azure/cosmos/implementation/batch/BatchResponseParser.java
Show resolved
Hide resolved
Nice-to-have (I will pick it up after merging the PR if you don't get to it): I think it would be nice to have a benchmark operation in the .Net benchmark tool (which is available under azure-cosmos-dotnet-benchmark in a Java-ported version now as well). That way we could compare throughput results between .Net and Java to get a baseline. Probably the easiest way to get a feeling for performance on TransactionalBatch in Java. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM - blocking mainly on the question around NPE vs. IllegalArgumentException and types from implementation package leaking into public surface area
Signed-off-by: Rakesh Kumar <[email protected]>
Signed-off-by: Rakesh Kumar <[email protected]>
Signed-off-by: Rakesh Kumar <[email protected]>
Signed-off-by: Rakesh Kumar <[email protected]>
Signed-off-by: Rakesh Kumar <[email protected]>
Signed-off-by: Rakesh Kumar <[email protected]>
Signed-off-by: Rakesh Kumar <[email protected]>
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/TransactionalBatch.java
Show resolved
Hide resolved
...cosmos/azure-cosmos/src/main/java/com/azure/cosmos/TransactionalBatchItemRequestOptions.java
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/TransactionalBatchOperationResult.java
Outdated
Show resolved
Hide resolved
No pipelines are associated with this pull request. |
/azp run java - cosmos - tests |
No pipelines are associated with this pull request. |
/azp run java - cosmos - tests |
No pipelines are associated with this pull request. |
/azp run java - cosmos - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run java - cosmos - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run java - appconfiguration - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Rakesh Kumar <[email protected]>
Signed-off-by: Rakesh Kumar <[email protected]>
/azp run java - cosmos - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
* | ||
* @return The transactional batch instance with the operation added. | ||
*/ | ||
public <T> CosmosItemOperation createItem(T item) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT - as discussed I think naming the factory methods xxxItemOperation here - like createItemOperation or upsertItemOperation would be clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Rakesh - LGTM now except for the payload size comment from Mo and the NIT on the naming. Thanks for your due diligence - great work!
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosItemOperationType.java
Outdated
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosItemOperationType.java
Show resolved
Hide resolved
Signed-off-by: Rakesh Kumar <[email protected]>
* @return The list of operations which are to be executed. | ||
*/ | ||
List<ItemBatchOperation<?>> getOperationsInternal() { | ||
return UnmodifiableList.unmodifiableList(operations); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate.
you can rely on getOperations() public method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah changed it to use CosmosItemOperation everywhere except when serializing it.
Signed-off-by: Rakesh Kumar <[email protected]>
/azp run java - cosmos - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Rakesh Kumar <[email protected]>
/azp run java - cosmos - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
This PR adds Transactional batch feature in Java SDK.
Use TransactionalBatch.createTransactionalBatch(PartitionKey) or new TransactionalBatch(PartitionKey) to create an instance of TransactionalBatch.
Add operations in it like createItem/deleteItem/replaceItem/upsertItem/readItem for same partition key which you want to execute in all or nothing fashion.
Execute it using the container instance like container.executeTransactionalBatch(batch) which will return a TransactionalBatchResponse which will have array of responses and one response per operation
Implementation: