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

feat: add support for BatchWriteAtLeastOnce #2520

Merged
merged 28 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
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
refactor tests
  • Loading branch information
rajatbhatta committed Jun 14, 2023
commit 8d76346f58335091606c493b447b49fbff700c9d
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,10 @@ public ServerStream<BatchWriteResponse> batchWriteAtleastOnceWithOptions(
}
Span span = tracer.spanBuilder(SpannerImpl.BATCH_WRITE).startSpan();
try (Scope s = tracer.withSpan(span)) {
ServerStream<BatchWriteResponse> response =
spanner.getRpc().batchWriteAtleastOnce(requestBuilder.build(), this.options);
return response;
} catch (RuntimeException e) {
return spanner.getRpc().batchWriteAtleastOnce(requestBuilder.build(), this.options);
} catch (Throwable e) {
TraceUtil.setWithFailure(span, e);
throw e;
throw SpannerExceptionFactory.newSpannerException(e);
} finally {
span.end(TraceUtil.END_SPAN_OPTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;

import com.google.api.gax.rpc.ServerStream;
import com.google.cloud.ByteArray;
import com.google.cloud.Date;
import com.google.cloud.Timestamp;
Expand All @@ -53,6 +54,9 @@
import com.google.cloud.spanner.testing.EmulatorSpannerHelper;
import com.google.common.collect.ImmutableList;
import com.google.protobuf.NullValue;
import com.google.rpc.Code;
import com.google.rpc.Status;
import com.google.spanner.v1.BatchWriteResponse;
import io.grpc.Context;
import java.math.BigDecimal;
import java.util.ArrayList;
Expand Down Expand Up @@ -212,6 +216,28 @@ public void writeAtLeastOnce() {
assertThat(row.getString(0)).isEqualTo("v1");
}

@Test
public void batchWriteAtLeastOnce() {
ServerStream<BatchWriteResponse> responses =
client.batchWriteAtleastOnce(
ImmutableList.of(
Mutation.newInsertOrUpdateBuilder("T")
.set("K")
.to(lastKey = uniqueString())
.set("StringValue")
.to("v1")
.build()));
for (BatchWriteResponse response : responses) {
assertEquals(response.getIndexesList(), Collections.singletonList(0));
if (response.getStatus().equals(Status.newBuilder().setCode(Code.OK_VALUE).build())) {
assertNotNull(response.getCommitTimestamp());
Struct row = readLastRow("StringValue");
assertFalse(row.isNull(0));
assertEquals(row.getString(0), "v1");
}
}
}

@Test
public void testWriteReturnsCommitStats() {
assumeFalse("Emulator does not return commit statistics", isUsingEmulator());
Expand Down
Loading