Skip to content

feat(spanner): support max_commit_delay in Spanner transactions #2854

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 17 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
add commit delay options
  • Loading branch information
rahul2393 committed Dec 5, 2023
commit 8c689a1d07f7e79b142e4b0771db1b67af12919d
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ implementation 'com.google.cloud:google-cloud-spanner'
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-spanner:6.54.0'
implementation 'com.google.cloud:google-cloud-spanner:6.55.0'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.54.0"
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.55.0"
```
<!-- {x-version-update-end} -->

Expand Down Expand Up @@ -433,7 +433,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java11.html
[stability-image]: https://img.shields.io/badge/stability-stable-green
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-spanner.svg
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.54.0
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.55.0
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,7 @@ public final CommitResponse commit(
* SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString())
* .addAllMutations(new ArrayList<Mutation>())
* .setReturnCommitStats(true)
* .setMaxCommitDelay(Duration.newBuilder().build())
* .setRequestOptions(RequestOptions.newBuilder().build())
* .build();
* CommitResponse response = spannerClient.commit(request);
Expand Down Expand Up @@ -1686,6 +1687,7 @@ public final CommitResponse commit(CommitRequest request) {
* SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString())
* .addAllMutations(new ArrayList<Mutation>())
* .setReturnCommitStats(true)
* .setMaxCommitDelay(Duration.newBuilder().build())
* .setRequestOptions(RequestOptions.newBuilder().build())
* .build();
* ApiFuture<CommitResponse> future = spannerClient.commitCallable().futureCall(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,36 @@ public boolean getReturnCommitStats() {
return returnCommitStats_;
}

public static final int MAX_COMMIT_DELAY_FIELD_NUMBER = 8;
private com.google.protobuf.Duration maxCommitDelay_;
/**
* <code>.google.protobuf.Duration max_commit_delay = 8;</code>
*
* @return Whether the maxCommitDelay field is set.
*/
@java.lang.Override
public boolean hasMaxCommitDelay() {
return maxCommitDelay_ != null;
}
/**
* <code>.google.protobuf.Duration max_commit_delay = 8;</code>
*
* @return The maxCommitDelay.
*/
@java.lang.Override
public com.google.protobuf.Duration getMaxCommitDelay() {
return maxCommitDelay_ == null
? com.google.protobuf.Duration.getDefaultInstance()
: maxCommitDelay_;
}
/** <code>.google.protobuf.Duration max_commit_delay = 8;</code> */
@java.lang.Override
public com.google.protobuf.DurationOrBuilder getMaxCommitDelayOrBuilder() {
return maxCommitDelay_ == null
? com.google.protobuf.Duration.getDefaultInstance()
: maxCommitDelay_;
}

public static final int REQUEST_OPTIONS_FIELD_NUMBER = 6;
private com.google.spanner.v1.RequestOptions requestOptions_;
/**
Expand Down Expand Up @@ -460,6 +490,9 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io
if (requestOptions_ != null) {
output.writeMessage(6, getRequestOptions());
}
if (maxCommitDelay_ != null) {
output.writeMessage(8, getMaxCommitDelay());
}
getUnknownFields().writeTo(output);
}

Expand Down Expand Up @@ -491,6 +524,9 @@ public int getSerializedSize() {
if (requestOptions_ != null) {
size += com.google.protobuf.CodedOutputStream.computeMessageSize(6, getRequestOptions());
}
if (maxCommitDelay_ != null) {
size += com.google.protobuf.CodedOutputStream.computeMessageSize(8, getMaxCommitDelay());
}
size += getUnknownFields().getSerializedSize();
memoizedSize = size;
return size;
Expand All @@ -509,6 +545,10 @@ public boolean equals(final java.lang.Object obj) {
if (!getSession().equals(other.getSession())) return false;
if (!getMutationsList().equals(other.getMutationsList())) return false;
if (getReturnCommitStats() != other.getReturnCommitStats()) return false;
if (hasMaxCommitDelay() != other.hasMaxCommitDelay()) return false;
if (hasMaxCommitDelay()) {
if (!getMaxCommitDelay().equals(other.getMaxCommitDelay())) return false;
}
if (hasRequestOptions() != other.hasRequestOptions()) return false;
if (hasRequestOptions()) {
if (!getRequestOptions().equals(other.getRequestOptions())) return false;
Expand Down Expand Up @@ -543,6 +583,10 @@ public int hashCode() {
}
hash = (37 * hash) + RETURN_COMMIT_STATS_FIELD_NUMBER;
hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean(getReturnCommitStats());
if (hasMaxCommitDelay()) {
hash = (37 * hash) + MAX_COMMIT_DELAY_FIELD_NUMBER;
hash = (53 * hash) + getMaxCommitDelay().hashCode();
}
if (hasRequestOptions()) {
hash = (37 * hash) + REQUEST_OPTIONS_FIELD_NUMBER;
hash = (53 * hash) + getRequestOptions().hashCode();
Expand Down Expand Up @@ -709,6 +753,11 @@ public Builder clear() {
}
bitField0_ = (bitField0_ & ~0x00000008);
returnCommitStats_ = false;
maxCommitDelay_ = null;
if (maxCommitDelayBuilder_ != null) {
maxCommitDelayBuilder_.dispose();
maxCommitDelayBuilder_ = null;
}
requestOptions_ = null;
if (requestOptionsBuilder_ != null) {
requestOptionsBuilder_.dispose();
Expand Down Expand Up @@ -772,6 +821,10 @@ private void buildPartial0(com.google.spanner.v1.CommitRequest result) {
result.returnCommitStats_ = returnCommitStats_;
}
if (((from_bitField0_ & 0x00000020) != 0)) {
result.maxCommitDelay_ =
maxCommitDelayBuilder_ == null ? maxCommitDelay_ : maxCommitDelayBuilder_.build();
}
if (((from_bitField0_ & 0x00000040) != 0)) {
result.requestOptions_ =
requestOptionsBuilder_ == null ? requestOptions_ : requestOptionsBuilder_.build();
}
Expand Down Expand Up @@ -865,6 +918,9 @@ public Builder mergeFrom(com.google.spanner.v1.CommitRequest other) {
if (other.getReturnCommitStats() != false) {
setReturnCommitStats(other.getReturnCommitStats());
}
if (other.hasMaxCommitDelay()) {
mergeMaxCommitDelay(other.getMaxCommitDelay());
}
if (other.hasRequestOptions()) {
mergeRequestOptions(other.getRequestOptions());
}
Expand Down Expand Up @@ -950,9 +1006,15 @@ public Builder mergeFrom(
case 50:
{
input.readMessage(getRequestOptionsFieldBuilder().getBuilder(), extensionRegistry);
bitField0_ |= 0x00000020;
bitField0_ |= 0x00000040;
break;
} // case 50
case 66:
{
input.readMessage(getMaxCommitDelayFieldBuilder().getBuilder(), extensionRegistry);
bitField0_ |= 0x00000020;
break;
} // case 66
default:
{
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
Expand Down Expand Up @@ -1896,6 +1958,121 @@ public Builder clearReturnCommitStats() {
return this;
}

private com.google.protobuf.Duration maxCommitDelay_;
private com.google.protobuf.SingleFieldBuilderV3<
com.google.protobuf.Duration,
com.google.protobuf.Duration.Builder,
com.google.protobuf.DurationOrBuilder>
maxCommitDelayBuilder_;
/**
* <code>.google.protobuf.Duration max_commit_delay = 8;</code>
*
* @return Whether the maxCommitDelay field is set.
*/
public boolean hasMaxCommitDelay() {
return ((bitField0_ & 0x00000020) != 0);
}
/**
* <code>.google.protobuf.Duration max_commit_delay = 8;</code>
*
* @return The maxCommitDelay.
*/
public com.google.protobuf.Duration getMaxCommitDelay() {
if (maxCommitDelayBuilder_ == null) {
return maxCommitDelay_ == null
? com.google.protobuf.Duration.getDefaultInstance()
: maxCommitDelay_;
} else {
return maxCommitDelayBuilder_.getMessage();
}
}
/** <code>.google.protobuf.Duration max_commit_delay = 8;</code> */
public Builder setMaxCommitDelay(com.google.protobuf.Duration value) {
if (maxCommitDelayBuilder_ == null) {
if (value == null) {
throw new NullPointerException();
}
maxCommitDelay_ = value;
} else {
maxCommitDelayBuilder_.setMessage(value);
}
bitField0_ |= 0x00000020;
onChanged();
return this;
}
/** <code>.google.protobuf.Duration max_commit_delay = 8;</code> */
public Builder setMaxCommitDelay(com.google.protobuf.Duration.Builder builderForValue) {
if (maxCommitDelayBuilder_ == null) {
maxCommitDelay_ = builderForValue.build();
} else {
maxCommitDelayBuilder_.setMessage(builderForValue.build());
}
bitField0_ |= 0x00000020;
onChanged();
return this;
}
/** <code>.google.protobuf.Duration max_commit_delay = 8;</code> */
public Builder mergeMaxCommitDelay(com.google.protobuf.Duration value) {
if (maxCommitDelayBuilder_ == null) {
if (((bitField0_ & 0x00000020) != 0)
&& maxCommitDelay_ != null
&& maxCommitDelay_ != com.google.protobuf.Duration.getDefaultInstance()) {
getMaxCommitDelayBuilder().mergeFrom(value);
} else {
maxCommitDelay_ = value;
}
} else {
maxCommitDelayBuilder_.mergeFrom(value);
}
bitField0_ |= 0x00000020;
onChanged();
return this;
}
/** <code>.google.protobuf.Duration max_commit_delay = 8;</code> */
public Builder clearMaxCommitDelay() {
bitField0_ = (bitField0_ & ~0x00000020);
maxCommitDelay_ = null;
if (maxCommitDelayBuilder_ != null) {
maxCommitDelayBuilder_.dispose();
maxCommitDelayBuilder_ = null;
}
onChanged();
return this;
}
/** <code>.google.protobuf.Duration max_commit_delay = 8;</code> */
public com.google.protobuf.Duration.Builder getMaxCommitDelayBuilder() {
bitField0_ |= 0x00000020;
onChanged();
return getMaxCommitDelayFieldBuilder().getBuilder();
}
/** <code>.google.protobuf.Duration max_commit_delay = 8;</code> */
public com.google.protobuf.DurationOrBuilder getMaxCommitDelayOrBuilder() {
if (maxCommitDelayBuilder_ != null) {
return maxCommitDelayBuilder_.getMessageOrBuilder();
} else {
return maxCommitDelay_ == null
? com.google.protobuf.Duration.getDefaultInstance()
: maxCommitDelay_;
}
}
/** <code>.google.protobuf.Duration max_commit_delay = 8;</code> */
private com.google.protobuf.SingleFieldBuilderV3<
com.google.protobuf.Duration,
com.google.protobuf.Duration.Builder,
com.google.protobuf.DurationOrBuilder>
getMaxCommitDelayFieldBuilder() {
if (maxCommitDelayBuilder_ == null) {
maxCommitDelayBuilder_ =
new com.google.protobuf.SingleFieldBuilderV3<
com.google.protobuf.Duration,
com.google.protobuf.Duration.Builder,
com.google.protobuf.DurationOrBuilder>(
getMaxCommitDelay(), getParentForChildren(), isClean());
maxCommitDelay_ = null;
}
return maxCommitDelayBuilder_;
}

private com.google.spanner.v1.RequestOptions requestOptions_;
private com.google.protobuf.SingleFieldBuilderV3<
com.google.spanner.v1.RequestOptions,
Expand All @@ -1914,7 +2091,7 @@ public Builder clearReturnCommitStats() {
* @return Whether the requestOptions field is set.
*/
public boolean hasRequestOptions() {
return ((bitField0_ & 0x00000020) != 0);
return ((bitField0_ & 0x00000040) != 0);
}
/**
*
Expand Down Expand Up @@ -1954,7 +2131,7 @@ public Builder setRequestOptions(com.google.spanner.v1.RequestOptions value) {
} else {
requestOptionsBuilder_.setMessage(value);
}
bitField0_ |= 0x00000020;
bitField0_ |= 0x00000040;
onChanged();
return this;
}
Expand All @@ -1973,7 +2150,7 @@ public Builder setRequestOptions(com.google.spanner.v1.RequestOptions.Builder bu
} else {
requestOptionsBuilder_.setMessage(builderForValue.build());
}
bitField0_ |= 0x00000020;
bitField0_ |= 0x00000040;
onChanged();
return this;
}
Expand All @@ -1988,7 +2165,7 @@ public Builder setRequestOptions(com.google.spanner.v1.RequestOptions.Builder bu
*/
public Builder mergeRequestOptions(com.google.spanner.v1.RequestOptions value) {
if (requestOptionsBuilder_ == null) {
if (((bitField0_ & 0x00000020) != 0)
if (((bitField0_ & 0x00000040) != 0)
&& requestOptions_ != null
&& requestOptions_ != com.google.spanner.v1.RequestOptions.getDefaultInstance()) {
getRequestOptionsBuilder().mergeFrom(value);
Expand All @@ -1998,7 +2175,7 @@ public Builder mergeRequestOptions(com.google.spanner.v1.RequestOptions value) {
} else {
requestOptionsBuilder_.mergeFrom(value);
}
bitField0_ |= 0x00000020;
bitField0_ |= 0x00000040;
onChanged();
return this;
}
Expand All @@ -2012,7 +2189,7 @@ public Builder mergeRequestOptions(com.google.spanner.v1.RequestOptions value) {
* <code>.google.spanner.v1.RequestOptions request_options = 6;</code>
*/
public Builder clearRequestOptions() {
bitField0_ = (bitField0_ & ~0x00000020);
bitField0_ = (bitField0_ & ~0x00000040);
requestOptions_ = null;
if (requestOptionsBuilder_ != null) {
requestOptionsBuilder_.dispose();
Expand All @@ -2031,7 +2208,7 @@ public Builder clearRequestOptions() {
* <code>.google.spanner.v1.RequestOptions request_options = 6;</code>
*/
public com.google.spanner.v1.RequestOptions.Builder getRequestOptionsBuilder() {
bitField0_ |= 0x00000020;
bitField0_ |= 0x00000040;
onChanged();
return getRequestOptionsFieldBuilder().getBuilder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,21 @@ public interface CommitRequestOrBuilder
*/
boolean getReturnCommitStats();

/**
* <code>.google.protobuf.Duration max_commit_delay = 8;</code>
*
* @return Whether the maxCommitDelay field is set.
*/
boolean hasMaxCommitDelay();
/**
* <code>.google.protobuf.Duration max_commit_delay = 8;</code>
*
* @return The maxCommitDelay.
*/
com.google.protobuf.Duration getMaxCommitDelay();
/** <code>.google.protobuf.Duration max_commit_delay = 8;</code> */
com.google.protobuf.DurationOrBuilder getMaxCommitDelayOrBuilder();

/**
*
*
Expand Down
Loading