Skip to content

Commit

Permalink
Merge branch 'main' into mux-unit-test-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
harshachinta authored Jan 10, 2025
2 parents 8608191 + a5f9e7a commit 4031ad4
Show file tree
Hide file tree
Showing 29 changed files with 244 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/hermetic_library_generation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
with:
fetch-depth: 0
token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
- uses: googleapis/sdk-platform-java/.github/[email protected].0
- uses: googleapis/sdk-platform-java/.github/[email protected].1
if: env.SHOULD_RUN == 'true'
with:
base_ref: ${{ github.base_ref }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unmanaged_dependency_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
# repository
.kokoro/build.sh
- name: Unmanaged dependency check
uses: googleapis/sdk-platform-java/java-shared-dependencies/unmanaged-dependency-check@google-cloud-shared-dependencies/v3.41.0
uses: googleapis/sdk-platform-java/java-shared-dependencies/unmanaged-dependency-check@google-cloud-shared-dependencies/v3.41.1
with:
bom-path: google-cloud-spanner-bom/pom.xml
2 changes: 1 addition & 1 deletion .kokoro/presubmit/graalvm-native-17.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_b:3.41.0"
value: "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_b:3.41.1"
}

env_vars: {
Expand Down
2 changes: 1 addition & 1 deletion .kokoro/presubmit/graalvm-native.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_a:3.41.0"
value: "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_a:3.41.1"
}

env_vars: {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ If you are using Maven without the BOM, add this to your dependencies:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<version>6.81.1</version>
<version>6.84.0</version>
</dependency>

```
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-parent</artifactId>
<version>6.84.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.84.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</parent>

<properties>
Expand Down Expand Up @@ -80,7 +80,7 @@
<dependency>
<groupId>com.google.re2j</groupId>
<artifactId>re2j</artifactId>
<version>1.7</version>
<version>1.8</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
Expand All @@ -92,7 +92,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<version>6.81.1</version>
<version>6.84.0</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
Expand Down
2 changes: 1 addition & 1 deletion generation_config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
gapic_generator_version: 2.51.0
googleapis_commitish: c72d7385435589176aa6e44563fcfbc795b9a476
googleapis_commitish: 00196e2a68b16a864c57db2e870822875a7f1198
libraries_bom_version: 26.52.0
libraries:
- api_shortname: spanner
Expand Down
20 changes: 10 additions & 10 deletions google-cloud-spanner-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-bom</artifactId>
<version>6.84.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.84.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<packaging>pom</packaging>
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>sdk-platform-java-config</artifactId>
<version>3.41.0</version>
<version>3.41.1</version>
</parent>

<name>Google Cloud Spanner BOM</name>
Expand Down Expand Up @@ -53,43 +53,43 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<version>6.84.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.84.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<type>test-jar</type>
<version>6.84.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.84.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-spanner-v1</artifactId>
<version>6.84.0</version><!-- {x-version-update:grpc-google-cloud-spanner-v1:current} -->
<version>6.84.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-cloud-spanner-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-spanner-admin-instance-v1</artifactId>
<version>6.84.0</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-instance-v1:current} -->
<version>6.84.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-instance-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-spanner-admin-database-v1</artifactId>
<version>6.84.0</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-database-v1:current} -->
<version>6.84.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-database-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-spanner-admin-instance-v1</artifactId>
<version>6.84.0</version><!-- {x-version-update:proto-google-cloud-spanner-admin-instance-v1:current} -->
<version>6.84.1-SNAPSHOT</version><!-- {x-version-update:proto-google-cloud-spanner-admin-instance-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-spanner-v1</artifactId>
<version>6.84.0</version><!-- {x-version-update:proto-google-cloud-spanner-v1:current} -->
<version>6.84.1-SNAPSHOT</version><!-- {x-version-update:proto-google-cloud-spanner-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-spanner-admin-database-v1</artifactId>
<version>6.84.0</version><!-- {x-version-update:proto-google-cloud-spanner-admin-database-v1:current} -->
<version>6.84.1-SNAPSHOT</version><!-- {x-version-update:proto-google-cloud-spanner-admin-database-v1:current} -->
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
4 changes: 2 additions & 2 deletions google-cloud-spanner-executor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-executor</artifactId>
<version>6.84.0</version><!-- {x-version-update:google-cloud-spanner-executor:current} -->
<version>6.84.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner-executor:current} -->
<packaging>jar</packaging>
<name>Google Cloud Spanner Executor</name>

<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-parent</artifactId>
<version>6.84.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.84.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</parent>

<properties>
Expand Down
6 changes: 3 additions & 3 deletions google-cloud-spanner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<version>6.84.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.84.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<packaging>jar</packaging>
<name>Google Cloud Spanner</name>
<url>https://github.com/googleapis/java-spanner</url>
<description>Java idiomatic client for Google Cloud Spanner.</description>
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-parent</artifactId>
<version>6.84.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.84.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</parent>
<properties>
<site.installationModule>google-cloud-spanner</site.installationModule>
Expand Down Expand Up @@ -270,7 +270,7 @@
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-monitoring-v3</artifactId>
<version>3.55.0</version>
<version>3.57.0</version>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;

Expand All @@ -67,6 +68,7 @@
*/
abstract class AbstractReadContext
implements ReadContext, AbstractResultSet.Listener, SessionTransaction {
private static final Logger logger = Logger.getLogger(AbstractReadContext.class.getName());

abstract static class Builder<B extends Builder<?, T>, T extends AbstractReadContext> {
private SessionImpl session;
Expand Down Expand Up @@ -951,6 +953,15 @@ ResultSet readInternalWithOptions(
} else if (defaultDirectedReadOptions != null) {
builder.setDirectedReadOptions(defaultDirectedReadOptions);
}
if (readOptions.hasLockHint()) {
if (isReadOnly()) {
logger.warning(
"Lock hint is only supported for ReadWrite transactions. "
+ "Overriding lock hint to default unspecified.");
} else {
builder.setLockHint(readOptions.lockHint());
}
}
final int prefetchChunks =
readOptions.hasPrefetchChunks() ? readOptions.prefetchChunks() : defaultPrefetchChunks;
ResumableStreamIterator stream =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.common.base.Preconditions;
import com.google.spanner.v1.DirectedReadOptions;
import com.google.spanner.v1.ReadRequest.LockHint;
import com.google.spanner.v1.ReadRequest.OrderBy;
import com.google.spanner.v1.RequestOptions.Priority;
import java.io.Serializable;
Expand Down Expand Up @@ -75,6 +76,25 @@ public static RpcOrderBy fromProto(OrderBy proto) {
}
}

public enum RpcLockHint {
UNSPECIFIED(LockHint.LOCK_HINT_UNSPECIFIED),
SHARED(LockHint.LOCK_HINT_SHARED),
EXCLUSIVE(LockHint.LOCK_HINT_EXCLUSIVE);

private final LockHint proto;

RpcLockHint(LockHint proto) {
this.proto = Preconditions.checkNotNull(proto);
}

public static RpcLockHint fromProto(LockHint proto) {
for (RpcLockHint e : RpcLockHint.values()) {
if (e.proto.equals(proto)) return e;
}
return RpcLockHint.UNSPECIFIED;
}
}

/** Marker interface to mark options applicable to both Read and Query operations */
public interface ReadAndQueryOption extends ReadOption, QueryOption {}

Expand Down Expand Up @@ -160,6 +180,10 @@ public static ReadOption orderBy(RpcOrderBy orderBy) {
return new OrderByOption(orderBy);
}

public static ReadOption lockHint(RpcLockHint orderBy) {
return new LockHintOption(orderBy);
}

/**
* Specifying this will allow the client to prefetch up to {@code prefetchChunks} {@code
* PartialResultSet} chunks for read and query. The data size of each chunk depends on the server
Expand Down Expand Up @@ -469,6 +493,7 @@ void appendToOptions(Options options) {
private DirectedReadOptions directedReadOptions;
private DecodeMode decodeMode;
private RpcOrderBy orderBy;
private RpcLockHint lockHint;

// Construction is via factory methods below.
private Options() {}
Expand Down Expand Up @@ -605,6 +630,14 @@ OrderBy orderBy() {
return orderBy == null ? null : orderBy.proto;
}

boolean hasLockHint() {
return lockHint != null;
}

LockHint lockHint() {
return lockHint == null ? null : lockHint.proto;
}

@Override
public String toString() {
StringBuilder b = new StringBuilder();
Expand Down Expand Up @@ -661,6 +694,9 @@ public String toString() {
if (orderBy != null) {
b.append("orderBy: ").append(orderBy).append(' ');
}
if (lockHint != null) {
b.append("lockHint: ").append(lockHint).append(' ');
}
return b.toString();
}

Expand Down Expand Up @@ -700,7 +736,8 @@ public boolean equals(Object o) {
&& Objects.equals(withExcludeTxnFromChangeStreams(), that.withExcludeTxnFromChangeStreams())
&& Objects.equals(dataBoostEnabled(), that.dataBoostEnabled())
&& Objects.equals(directedReadOptions(), that.directedReadOptions())
&& Objects.equals(orderBy(), that.orderBy());
&& Objects.equals(orderBy(), that.orderBy())
&& Objects.equals(lockHint(), that.lockHint());
}

@Override
Expand Down Expand Up @@ -760,6 +797,9 @@ public int hashCode() {
if (orderBy != null) {
result = 31 * result + orderBy.hashCode();
}
if (lockHint != null) {
result = 31 * result + lockHint.hashCode();
}
return result;
}

Expand Down Expand Up @@ -853,6 +893,19 @@ void appendToOptions(Options options) {
}
}

static class LockHintOption extends InternalOption implements ReadOption {
private final RpcLockHint lockHint;

LockHintOption(RpcLockHint lockHint) {
this.lockHint = lockHint;
}

@Override
void appendToOptions(Options options) {
options.lockHint = lockHint;
}
}

static final class DataBoostQueryOption extends InternalOption implements ReadAndQueryOption {

private final Boolean dataBoostEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.spanner;

import com.google.api.gax.core.GaxProperties;
import com.google.cloud.spanner.Options.TagOption;
import com.google.cloud.spanner.Options.TransactionOption;
import com.google.cloud.spanner.SpannerOptions.TracingFramework;
Expand Down Expand Up @@ -46,6 +47,12 @@ class TraceWrapper {
private static final AttributeKey<List<String>> DB_STATEMENT_ARRAY_KEY =
AttributeKey.stringArrayKey("db.statement");
private static final AttributeKey<String> DB_TABLE_NAME_KEY = AttributeKey.stringKey("db.table");
private static final AttributeKey<String> GCP_CLIENT_SERVICE_KEY =
AttributeKey.stringKey("gcp.client.service");
private static final AttributeKey<String> GCP_CLIENT_VERSION_KEY =
AttributeKey.stringKey("gcp.client.version");
private static final AttributeKey<String> GCP_CLIENT_REPO_KEY =
AttributeKey.stringKey("gcp.client.repo");
private static final AttributeKey<String> THREAD_NAME_KEY = AttributeKey.stringKey("thread.name");

private final Tracer openCensusTracer;
Expand Down Expand Up @@ -204,6 +211,9 @@ Attributes createCommonAttributes(DatabaseId db) {
AttributesBuilder builder = Attributes.builder();
builder.put(DB_NAME_KEY, db.getDatabase());
builder.put(INSTANCE_NAME_KEY, db.getInstanceId().getInstance());
builder.put(GCP_CLIENT_SERVICE_KEY, "spanner");
builder.put(GCP_CLIENT_REPO_KEY, "googleapis/java-spanner");
builder.put(GCP_CLIENT_VERSION_KEY, GaxProperties.getLibraryVersion(TraceWrapper.class));
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.spanner.v1.ExecuteSqlRequest.QueryMode;
import com.google.spanner.v1.ExecuteSqlRequest.QueryOptions;
import com.google.spanner.v1.ReadRequest;
import com.google.spanner.v1.ReadRequest.LockHint;
import com.google.spanner.v1.ReadRequest.OrderBy;
import com.google.spanner.v1.RequestOptions;
import com.google.spanner.v1.RequestOptions.Priority;
Expand Down Expand Up @@ -241,6 +242,21 @@ public void testGetReadRequestBuilderWithOrderBy() {
assertEquals(OrderBy.ORDER_BY_NO_ORDER, request.getOrderBy());
}

@Test
public void testGetReadRequestBuilderWithLockHint() {
ReadRequest request =
ReadRequest.newBuilder()
.setSession(
SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString())
.setTransaction(TransactionSelector.newBuilder().build())
.setTable("table110115790")
.setIndex("index100346066")
.addAllColumns(new ArrayList<String>())
.setLockHintValue(2)
.build();
assertEquals(LockHint.LOCK_HINT_EXCLUSIVE, request.getLockHint());
}

@Test
public void testGetExecuteBatchDmlRequestBuilderWithPriority() {
ExecuteBatchDmlRequest.Builder request =
Expand Down
Loading

0 comments on commit 4031ad4

Please sign in to comment.