-
Notifications
You must be signed in to change notification settings - Fork 124
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 CommitStats #544
Conversation
Adds support for returning CommitStats from read/write transactions.
Codecov Report
@@ Coverage Diff @@
## master #544 +/- ##
============================================
+ Coverage 85.04% 85.26% +0.22%
- Complexity 2583 2616 +33
============================================
Files 143 144 +1
Lines 14145 14208 +63
Branches 1369 1372 +3
============================================
+ Hits 12030 12115 +85
+ Misses 1542 1522 -20
+ Partials 573 571 -2
Continue to review full report at Codecov.
|
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'm not quite sure if we need the breaking change here. If it's just because of the interface update, I wouldn't mark it as such. But if there is an actual breaking change where users will have to update their code in order to use the next release, then let me know.
...cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPoolAsyncTransactionManager.java
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionManagerImpl.java
Outdated
Show resolved
Hide resolved
There are no changes in this PR that will break existing code that just uses these interfaces. Binary compatibility with the previous version will be broken, and code that actually implements the |
Warning: This pull request is touching the following templated files:
|
Warning: This pull request is touching the following templated files:
|
Warning: This pull request is touching the following templated files:
|
@@ -406,4 +406,62 @@ | |||
<className>com/google/cloud/spanner/AbstractLazyInitializer</className> | |||
<method>java.lang.Object initialize()</method> | |||
</difference> | |||
|
|||
<!-- Support for CommitStats added --> |
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.
another one where a major version bump is required
@olavloite, I just merged in #817 so you can rebase this PR. In light of the discussions about binary incompatibility, please take a look and see if the implementation needs to be changed to avoid a breaking change or if we'll just have to do a semver updgrade. |
I think that's a great idea. It is an option after all and as long as it's accessible when required, then it works. @thiagotnunes FYI. |
@olavloite hey Knut, after talking with @skuruppu we have decided not to change the design right now, but to do a major release instead. |
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.
It's always acceptable to bump the major version. I think you'll want to add a ! after feat in the PR description (i.e. feat! ) so the release automation notices this. It might also be useful to update the snapshot version in this PR.
After this release goes out, you can remove the ignored differences file and point it at the newly released major version.
google-cloud-spanner/src/main/java/com/google/cloud/spanner/Options.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/OptionsTest.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/OptionsTest.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITAsyncAPITest.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITAsyncAPITest.java
Outdated
Show resolved
Hide resolved
@elharo Thanks, updated the PR description. |
|
||
@Test | ||
public void transactionRunnerReturnsCommitStats() { | ||
assumeFalse("Emulator does not return commit statistics", isUsingEmulator()); |
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.
The assume here is surprising. Why would this be sometimes be true and sometimes not true in this one test 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.
isUsingEmulator()
checks whether the environment variable SPANNER_EMULATOR_HOST
has been set to a non-empty value. If so, the integration tests are running against the emulator. The emulator does not support all features of Cloud Spanner, which means we need to skip some specific tests. The CI environments runs the tests both against the emulator and Cloud Spanner.
google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITTransactionTest.java
Outdated
Show resolved
Hide resolved
@olavloite this can now be merged when you're ready. |
@elharo friendly ping. This feature is launching soon so we need to start merging in the PRs to make sure that the samples are ready to ingested into the Cloud Docs. |
@@ -56,4 +56,10 @@ | |||
* {@link ExecutionException} if the transaction did not commit. | |||
*/ | |||
ApiFuture<Timestamp> getCommitTimestamp(); | |||
|
|||
/** | |||
* Returns the {@link CommitResponse} of this transaction. {@link ApiFuture#get()} will throw an |
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.
will throw --> throws
per Google style
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.
Done
try { | ||
commitTimestamp.set(delegate.getCommitTimestamp()); | ||
commitResponse.set(delegate.getCommitResponse()); | ||
} catch (Throwable t) { |
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.
letting it slide because it isn't changed in this PR, but catching Throwable is only rarely what you want. This is probably worth filing a bug on.
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.
Added issue: #875
@@ -132,29 +133,37 @@ public void onError(Throwable t) { | |||
SpannerExceptionFactory.newSpannerException( | |||
ErrorCode.ABORTED, "Transaction already aborted")); | |||
} | |||
ApiFuture<Timestamp> res = txn.commitAsync(); | |||
ApiFuture<CommitResponse> res = txn.commitAsync(); |
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.
no abbreviated variable names per google style.
Concretely I did not know what this was when I read it below and had to scroll up to find out.
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.
Changed to commitResponseFuture
* row from a parent table that has the ON DELETE CASCADE annotation is also counted as one | ||
* mutation regardless of the number of interleaved child rows present. The exception to this is | ||
* if there are secondary indexes defined on rows being deleted, then the changes to the secondary | ||
* indexes will be counted individually. For example, if a table has 2 secondary indexes, deleting |
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.
will be --> are
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.
Done
* mutation regardless of the number of interleaved child rows present. The exception to this is | ||
* if there are secondary indexes defined on rows being deleted, then the changes to the secondary | ||
* indexes will be counted individually. For example, if a table has 2 secondary indexes, deleting | ||
* a range of rows in the table will count as 1 mutation for the table, plus 2 mutations for each |
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.
will count --> counts
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.
Done
public void testTransactionOptions_withCommitStatsAndOtherOptionAreNotEqual() { | ||
Options option1 = Options.fromTransactionOptions(Options.commitStats()); | ||
Options option2 = Options.fromQueryOptions(Options.prefetchChunks(10)); | ||
assertFalse(option1.equals(option2)); |
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.
assertNotEquals
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.
Done
public void testTransactionOptions_withCommitStatsAreEqual() { | ||
Options option1 = Options.fromTransactionOptions(Options.commitStats()); | ||
Options option2 = Options.fromTransactionOptions(Options.commitStats()); | ||
assertTrue(option1.equals(option2)); |
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.
assertEquals
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.
Done
public void testTransactionOptions_noOptionsAreEqual() { | ||
Options option1 = Options.fromTransactionOptions(); | ||
Options option2 = Options.fromTransactionOptions(); | ||
assertTrue(option1.equals(option2)); |
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.
assertEquals
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.
Done
assumeFalse("Emulator does not return commit statistics", isUsingEmulator()); | ||
try (TransactionManager manager = client.transactionManager(Options.commitStats())) { | ||
TransactionContext transaction = manager.begin(); | ||
while (true) { |
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.
This one scares me since it looks like an infinite loop Could you add a counter with a maximum number of retries before failure?
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.
This is the recommended way to use TransactionManager
according to the documentation. It is also the way it is already used in multiple other test cases. I would rather either:
- Keep this and all other instances as they are.
- Change this and other instances + the documentation in a separate PR.
assertEquals(2L, manager.getCommitResponse().getCommitStats().getMutationCount()); | ||
break; | ||
} catch (AbortedException e) { | ||
Thread.sleep(e.getRetryDelayInMillis() / 1000); |
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.
BUG! Thread.sleep takes milliseconds. No need to divide by 1000.
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.
Good point. Changed and filed a bug for the documentation that also includes this.
This is an auto-generated regeneration of the .pb.go files by cloud.google.com/go/internal/gapicgen. Once this PR is submitted, genbot will update the corresponding PR to depend on the newer version of go-genproto, and assign reviewers. Whilst this or any regen PR is open in go-genproto, genbot will not create any more regeneration PRs. If all regen PRs are closed, gapicgen will create a new set of regeneration PRs once per night. If you have been assigned to review this PR, please: - Ensure that CI is passing. If it's failing, it requires your manual attention. - Approve and submit this PR if you believe it's ready to ship. That will prompt genbot to assign reviewers to the google-cloud-go PR. Corresponding google-cloud-go PR: googleapis/google-cloud-go#3765 Changes: build: update package name to already published name PiperOrigin-RevId: 360469636 Source-Link: googleapis/googleapis@c5435cb feat: allow to disable webhook invocation per request PiperOrigin-RevId: 360468675 Source-Link: googleapis/googleapis@a031936 build(policytroubleshooter): update BUILD file for policy troubleshooter PiperOrigin-RevId: 360450845 Source-Link: googleapis/googleapis@2f0798a fix(functions): Fix service namespace in grpc_service_config. PiperOrigin-RevId: 360443299 Source-Link: googleapis/googleapis@7cef880 chore(apigateway): Set namespaces for Ruby, PHP, and C# clients PiperOrigin-RevId: 360255957 Source-Link: googleapis/googleapis@7f8b19b
…cies to v2 (googleapis#544) * deps: update dependency com.google.cloud:google-cloud-shared-dependencies to v2 * Update pom.xml Co-authored-by: Neenu Shaji <[email protected]>
🤖 I have created a release \*beep\* \*boop\* --- ## [2.3.0](https://www.github.com/googleapis/java-spanner-jdbc/compare/v2.2.6...v2.3.0) (2021-08-11) ### Features * add support for tagging to JDBC connection ([googleapis#270](https://www.github.com/googleapis/java-spanner-jdbc/issues/270)) ([a4bd82c](https://www.github.com/googleapis/java-spanner-jdbc/commit/a4bd82c8e4ce8b7179b943ac06b049598276f1b4)) ### Dependencies * update dependency com.google.cloud:google-cloud-shared-dependencies to v2 ([googleapis#544](https://www.github.com/googleapis/java-spanner-jdbc/issues/544)) ([366430d](https://www.github.com/googleapis/java-spanner-jdbc/commit/366430dc270edd09de1a0749ba360f312897b1aa)) * update dependency com.google.cloud:google-cloud-spanner-bom to v6.10.0 ([googleapis#537](https://www.github.com/googleapis/java-spanner-jdbc/issues/537)) ([8655ae5](https://www.github.com/googleapis/java-spanner-jdbc/commit/8655ae5955f5385a9d6445e13264427d73c4d37e)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Adds support for returning
CommitStats
from read/write transactions.Replaces #522