-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(spanner): add getIsolationLevel and getReadLockMode methods to CommitResponse #13004
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ | |
|
|
||
| import com.google.cloud.Timestamp; | ||
| import com.google.common.base.Preconditions; | ||
| import com.google.spanner.v1.TransactionOptions.IsolationLevel; | ||
| import com.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode; | ||
| import java.util.Objects; | ||
| import javax.annotation.Nullable; | ||
|
|
||
|
|
@@ -54,6 +56,30 @@ public Timestamp getCommitTimestamp() { | |
| return Timestamp.fromProto(proto.getSnapshotTimestamp()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the {@link IsolationLevel} used for the read-write transaction if the transaction ran | ||
| * in internal test environments, and otherwise returns null. | ||
| */ | ||
| public @Nullable IsolationLevel getIsolationLevel() { | ||
| if (proto.getIsolationLevel() == IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED | ||
|
shobhitsg marked this conversation as resolved.
|
||
| || proto.getIsolationLevel() == IsolationLevel.UNRECOGNIZED) { | ||
| return null; | ||
| } | ||
| return proto.getIsolationLevel(); | ||
| } | ||
|
Comment on lines
+59
to
+69
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this method is intended for internal test environments, it should be annotated with @internalapi to indicate it is not part of the stable public API. Additionally, using a local variable for the isolation level avoids multiple calls to the underlying proto getter. /**
* Returns the {@link IsolationLevel} used for the read-write transaction if the transaction ran
* in internal test environments, and otherwise returns null.
*/
@InternalApi
public @Nullable IsolationLevel getIsolationLevel() {
IsolationLevel isolationLevel = proto.getIsolationLevel();
if (isolationLevel == IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED
|| isolationLevel == IsolationLevel.UNRECOGNIZED) {
return null;
}
return isolationLevel;
}References
|
||
|
|
||
| /** | ||
| * Returns the {@link ReadLockMode} used for the read-write transaction if the transaction ran in | ||
| * internal test environments, and otherwise returns null. | ||
| */ | ||
| public @Nullable ReadLockMode getReadLockMode() { | ||
| if (proto.getReadLockMode() == ReadLockMode.READ_LOCK_MODE_UNSPECIFIED | ||
| || proto.getReadLockMode() == ReadLockMode.UNRECOGNIZED) { | ||
| return null; | ||
| } | ||
| return proto.getReadLockMode(); | ||
| } | ||
|
Comment on lines
+71
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to getIsolationLevel, this method should be annotated with @internalapi and can be optimized by using a local variable for the read lock mode. /**
* Returns the {@link ReadLockMode} used for the read-write transaction if the transaction ran in
* internal test environments, and otherwise returns null.
*/
@InternalApi
public @Nullable ReadLockMode getReadLockMode() {
ReadLockMode readLockMode = proto.getReadLockMode();
if (readLockMode == ReadLockMode.READ_LOCK_MODE_UNSPECIFIED
|| readLockMode == ReadLockMode.UNRECOGNIZED) {
return null;
}
return readLockMode;
}References
|
||
|
|
||
| /** | ||
| * @return true if the {@link CommitResponse} includes {@link CommitStats} | ||
| */ | ||
|
|
||
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.
Add the imports for InternalApi and Nullable to support marking the new methods as internal and nullable, as they are intended for internal test environments.