Skip to content

feat: add support for BatchWriteAtLeastOnce #2520

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

Merged
merged 28 commits into from
Sep 26, 2023
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7ff7cb2
feat: add support for BatchWriteAtleastOnce
rajatbhatta Jun 5, 2023
43c4f63
test: add batchwrite() support to MockSpannerServiceImpl
rajatbhatta Jun 5, 2023
abedd15
test: add commit timestamp to proto
rajatbhatta Jun 5, 2023
21d8f67
test: add commit timestamp to proto
rajatbhatta Jun 5, 2023
4858965
test: add commit timestamp to proto
rajatbhatta Jun 12, 2023
81743a7
consume the stream in tests
rajatbhatta Jun 12, 2023
65abc96
refactor tests
rajatbhatta Jun 12, 2023
8d76346
refactor tests
rajatbhatta Jun 14, 2023
a3569ae
test if mutations are correctly applied
rajatbhatta Jun 20, 2023
4cb0ada
null check
rajatbhatta Jun 20, 2023
5401b7d
skip for emulator
rajatbhatta Jun 20, 2023
5103b5c
Merge branch 'googleapis:main' into batch-write
rajatbhatta Jun 20, 2023
95c3326
add method documentation
rajatbhatta Jun 20, 2023
5678207
add method documentation
rajatbhatta Jun 20, 2023
347e9c3
add method documentation
rajatbhatta Jun 20, 2023
4c7251f
Merge branch 'googleapis:main' into batch-write
rajatbhatta Jul 6, 2023
1deaa29
remove autogenerated code
rajatbhatta Jul 6, 2023
acece36
remove autogenerated tests
rajatbhatta Jul 6, 2023
5f04154
batchWriteAtleastOnce -> batchWriteAtLeastOnce
rajatbhatta Jul 6, 2023
8e15c5c
batchWriteAtleastOnceWithOptions -> batchWriteAtLeastOnceWithOptions
rajatbhatta Jul 6, 2023
56f3929
changes based on updated batch write API
rajatbhatta Aug 17, 2023
356849e
add copyright and doc
rajatbhatta Aug 17, 2023
07f3bfb
Merge branch 'main' into batch-write-review
rajatbhatta Aug 17, 2023
1ca0d31
address review comments
rajatbhatta Aug 22, 2023
c3e3d7b
address review comments
rajatbhatta Aug 22, 2023
a036ced
add more documentation
rajatbhatta Aug 25, 2023
d8ef791
Merge branch 'googleapis:main' into batch-write-review
rajatbhatta Sep 18, 2023
7c4c73d
Merge branch 'googleapis:main' into batch-write-review
arpan14 Sep 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add method documentation
  • Loading branch information
rajatbhatta committed Jun 20, 2023
commit 95c3326f249d6b8621ef05fc63f41c598ed1c000
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,91 @@ CommitResponse writeWithOptions(Iterable<Mutation> mutations, TransactionOption.
CommitResponse writeAtLeastOnceWithOptions(
Iterable<Mutation> mutations, TransactionOption... options) throws SpannerException;

/**
* Batches the supplied mutations in a collection of efficient transactions. The mutations are
* applied non-atomically in an unspecified order and thus, they must be independent of each
* other. Partial failure is possible, i.e., some mutations may have been applied successfully,
* while some may have failed. The results of individual batches are streamed into the response as
* and when the batches are applied.
*
* <p>Since this method does not feature replay protection, it may attempt to apply {@code
* mutations} more than once; if the mutations are not idempotent, this may lead to a failure
* being reported when the mutation was applied once. For example, an insert may fail with {@link
* ErrorCode#ALREADY_EXISTS} even though the row did not exist before this method was called. For
* this reason, most users of the library will prefer to use {@link #write(Iterable)} instead.
* However, {@code batchWriteAtLeastOnce()} method may be appropriate for non-atomically
* committing multiple mutations in a single RPC with low latency.
*
* <p>Example of BatchWriteAtleastOnce
*
* <pre>{@code
* long singerId = my_singer_id;
* Mutation mutation = Mutation.newInsertBuilder("Singers")
* .set("SingerId")
* .to(singerId)
* .set("FirstName")
* .to("Billy")
* .set("LastName")
* .to("Joel")
* .build();
* ServerStream<BatchWriteResponse> responses =
* dbClient.batchWriteAtLeastOnce(
* Collections.singletonList(mutation),
* Options.priority(RpcPriority.LOW));
* for (BatchWriteResponse response : responses) {
* // Do something when a response is received.
* }
* }</pre>
*
* @return ServerStream\<BatchWriteResponse>
*/
ServerStream<BatchWriteResponse> batchWriteAtleastOnce(Iterable<Mutation> mutations)
throws SpannerException;

/**
* Batches the supplied mutations in a collection of efficient transactions. The mutations are
* applied non-atomically in an unspecified order and thus, they must be independent of each
* other. Partial failure is possible, i.e., some mutations may have been applied successfully,
* while some may have failed. The results of individual batches are streamed into the response as
* and when the batches are applied.
*
* <p>Since this method does not feature replay protection, it may attempt to apply {@code
* mutations} more than once; if the mutations are not idempotent, this may lead to a failure
* being reported when the mutation was applied once. For example, an insert may fail with {@link
* ErrorCode#ALREADY_EXISTS} even though the row did not exist before this method was called. For
* this reason, most users of the library will prefer to use {@link #write(Iterable)} instead.
* However, {@code batchWriteAtLeastOnce()} method may be appropriate for non-atomically
* committing multiple mutations in a single RPC with low latency.
*
* <p>Example of BatchWriteAtleastOnce
*
* <pre>{@code
* long singerId = my_singer_id;
* Mutation mutation = Mutation.newInsertBuilder("Singers")
* .set("SingerId")
* .to(singerId)
* .set("FirstName")
* .to("Billy")
* .set("LastName")
* .to("Joel")
* .build();
* ServerStream<BatchWriteResponse> responses =
* dbClient.batchWriteAtLeastOnce(Collections.singletonList(mutation));
* for (BatchWriteResponse response : responses) {
* // Do something when a response is received.
* }
* }</pre>
*
* Options for a transaction can include:
*
* <ul>
* <li>{@link Options#priority(com.google.cloud.spanner.Options.RpcPriority)}: The {@link
* RpcPriority} to use for the batch write request.
* <li>{@link Options#tag(String)}: The transaction tag to use for the batch write request.
* </ul>
*
* @return ServerStream\<BatchWriteResponse>
*/
ServerStream<BatchWriteResponse> batchWriteAtleastOnceWithOptions(
Iterable<Mutation> mutations, TransactionOption... options) throws SpannerException;

Expand Down