From 1617301512f41de5c4e34ceb2a172c9d71619962 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 30 Aug 2024 16:55:17 -0400 Subject: [PATCH 01/26] Introduce ConsistencyParams model Change-Id: I7ae07cc4f13e8ffe9ea4a55fb407eae1d64f8547 --- .../admin/v2/models/ConsistencyParams.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java new file mode 100644 index 0000000000..f6abe47fd0 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java @@ -0,0 +1,30 @@ +package com.google.cloud.bigtable.admin.v2.models; + +import com.google.auto.value.AutoValue; +import com.google.bigtable.admin.v2.TableName; + +@AutoValue +public abstract class ConsistencyParams { + public enum ConsistencyMode { + /** + * Checks that reads using an app profile with `StandardIsolation` can + * see all writes committed before the token was created, even if the + * read and write target different clusters. + */ + STANDARD, + + /** + * Checks that reads using an app profile with `DataBoostIsolationReadOnly` + * can see all writes committed before the token was created, but only if + * the read and write target the same cluster. + */ + DATA_BOOST; + } + public static ConsistencyParams create(TableName tableName, ConsistencyMode mode) { + return new AutoValue_ConsistencyParams(tableName, mode); + } + + public abstract TableName getTableName(); + + public abstract ConsistencyMode getConsistencyMode(); +} From 54e6540eeee1138076fe408cc2ed8f99a737d41f Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Wed, 4 Sep 2024 10:48:49 -0400 Subject: [PATCH 02/26] Create AwaitConsistencyCallable, a delegate for AwaitReplicationCallable Change-Id: I16d7c69b4e1b9153f93e83f7f846d6c172aae8a6 --- .../admin/v2/models/ConsistencyParams.java | 67 +++++- .../v2/stub/AwaitConsistencyCallable.java | 192 ++++++++++++++++++ .../v2/stub/AwaitReplicationCallable.java | 138 +------------ .../stub/EnhancedBigtableTableAdminStub.java | 8 +- .../v2/stub/AwaitReplicationCallableTest.java | 8 +- 5 files changed, 265 insertions(+), 148 deletions(-) create mode 100644 google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java index f6abe47fd0..5bc86f5c31 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java @@ -1,30 +1,79 @@ package com.google.cloud.bigtable.admin.v2.models; -import com.google.auto.value.AutoValue; +import com.google.api.core.InternalApi; +import com.google.bigtable.admin.v2.CheckConsistencyRequest; import com.google.bigtable.admin.v2.TableName; +import com.google.common.base.Preconditions; -@AutoValue -public abstract class ConsistencyParams { +import javax.annotation.Nonnull; + +public class ConsistencyParams { public enum ConsistencyMode { /** * Checks that reads using an app profile with `StandardIsolation` can * see all writes committed before the token was created, even if the * read and write target different clusters. */ - STANDARD, + STANDARD(CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES), /** * Checks that reads using an app profile with `DataBoostIsolationReadOnly` * can see all writes committed before the token was created, but only if * the read and write target the same cluster. */ - DATA_BOOST; + DATA_BOOST(CheckConsistencyRequest.ModeCase.DATA_BOOST_READ_LOCAL_WRITES); + + @Nonnull + private final CheckConsistencyRequest.ModeCase proto; + + ConsistencyMode(CheckConsistencyRequest.ModeCase proto) { + this.proto = proto; + } + + /** + * Wraps the protobuf. This method is considered an internal implementation detail and not meant + * to be used by applications. + */ + @InternalApi + public static ConsistencyParams.ConsistencyMode fromProto(CheckConsistencyRequest.ModeCase proto) { + for (ConsistencyParams.ConsistencyMode mode : values()) { + if (mode.proto.equals(proto)) { + return mode; + } + } + throw new IllegalArgumentException("Unknown consistency mode: " + proto); + } + + /** + * Creates the request protobuf. This method is considered an internal implementation detail and + * not meant to be used by applications. + */ + @InternalApi + public CheckConsistencyRequest.ModeCase toProto() { + return proto; + } + } + + private final TableName tableName; + + private final ConsistencyMode consistencyMode; + + ConsistencyParams(TableName tableName, ConsistencyMode mode) { + Preconditions.checkNotNull(tableName); + Preconditions.checkNotNull(mode); + this.tableName = tableName; + this.consistencyMode = mode; } - public static ConsistencyParams create(TableName tableName, ConsistencyMode mode) { - return new AutoValue_ConsistencyParams(tableName, mode); + + public static ConsistencyParams of(TableName tableName, ConsistencyMode mode) { + return new ConsistencyParams(tableName, mode); } - public abstract TableName getTableName(); + public TableName getTableName() { + return tableName; + } - public abstract ConsistencyMode getConsistencyMode(); + public ConsistencyMode getConsistencyMode() { + return consistencyMode; + } } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java new file mode 100644 index 0000000000..a19f22c6f8 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java @@ -0,0 +1,192 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2.stub; + +import com.google.api.core.ApiAsyncFunction; +import com.google.api.core.ApiFunction; +import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; +import com.google.api.gax.retrying.ExponentialPollAlgorithm; +import com.google.api.gax.retrying.NonCancellableFuture; +import com.google.api.gax.retrying.ResultRetryAlgorithm; +import com.google.api.gax.retrying.RetryAlgorithm; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.retrying.RetryingExecutor; +import com.google.api.gax.retrying.RetryingFuture; +import com.google.api.gax.retrying.ScheduledRetryingExecutor; +import com.google.api.gax.retrying.TimedAttemptSettings; +import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.admin.v2.CheckConsistencyRequest; +import com.google.bigtable.admin.v2.CheckConsistencyResponse; +import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest; +import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse; +import com.google.bigtable.admin.v2.TableName; +import com.google.cloud.bigtable.admin.v2.models.ConsistencyParams; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.util.concurrent.MoreExecutors; +import java.util.concurrent.Callable; +import java.util.concurrent.CancellationException; + +/** + * Callable that waits until either replication or Data Boost has caught up to the point it was called. + * + *

This callable wraps GenerateConsistencyToken and CheckConsistency RPCs. It will generate a + * token then poll until isConsistent is true. + */ +class AwaitConsistencyCallable extends UnaryCallable { + private final UnaryCallable + generateCallable; + private final UnaryCallable checkCallable; + private final RetryingExecutor executor; + + static AwaitConsistencyCallable create( + UnaryCallable + generateCallable, + UnaryCallable checkCallable, + ClientContext clientContext, + RetrySettings pollingSettings) { + + RetryAlgorithm retryAlgorithm = + new RetryAlgorithm<>( + new PollResultAlgorithm(), + new ExponentialPollAlgorithm(pollingSettings, clientContext.getClock())); + + RetryingExecutor retryingExecutor = + new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); + + return new AwaitConsistencyCallable(generateCallable, checkCallable, retryingExecutor); + } + + @VisibleForTesting + AwaitConsistencyCallable( + UnaryCallable + generateCallable, + UnaryCallable checkCallable, + RetryingExecutor executor) { + this.generateCallable = generateCallable; + this.checkCallable = checkCallable; + this.executor = executor; + } + + @Override + public ApiFuture futureCall(final ConsistencyParams consistencyParams, final ApiCallContext context) { + TableName tableName = consistencyParams.getTableName(); + ApiFuture tokenFuture = generateToken(tableName, context); + + return ApiFutures.transformAsync( + tokenFuture, + new ApiAsyncFunction() { + @Override + public ApiFuture apply(GenerateConsistencyTokenResponse input) { + CheckConsistencyRequest request = + CheckConsistencyRequest.newBuilder() + .setName(tableName.toString()) + .setConsistencyToken(input.getConsistencyToken()) + .build(); + + return pollToken(request, context); + } + }, + MoreExecutors.directExecutor()); + } + + private ApiFuture generateToken( + TableName tableName, ApiCallContext context) { + GenerateConsistencyTokenRequest generateRequest = + GenerateConsistencyTokenRequest.newBuilder().setName(tableName.toString()).build(); + return generateCallable.futureCall(generateRequest, context); + } + + private ApiFuture pollToken(CheckConsistencyRequest request, ApiCallContext context) { + AttemptCallable attemptCallable = + new AttemptCallable<>(checkCallable, request, context); + RetryingFuture retryingFuture = + executor.createFuture(attemptCallable); + attemptCallable.setExternalFuture(retryingFuture); + attemptCallable.call(); + + return ApiFutures.transform( + retryingFuture, + new ApiFunction() { + @Override + public Void apply(CheckConsistencyResponse input) { + return null; + } + }, + MoreExecutors.directExecutor()); + } + + /** A callable representing an attempt to make an RPC call. */ + private static class AttemptCallable implements Callable { + private final UnaryCallable callable; + private final RequestT request; + + private volatile RetryingFuture externalFuture; + private volatile ApiCallContext callContext; + + AttemptCallable( + UnaryCallable callable, RequestT request, ApiCallContext callContext) { + this.callable = callable; + this.request = request; + this.callContext = callContext; + } + + void setExternalFuture(RetryingFuture externalFuture) { + this.externalFuture = externalFuture; + } + + @Override + public ResponseT call() { + try { + // NOTE: unlike gax's AttemptCallable, this ignores rpc timeouts + externalFuture.setAttemptFuture(new NonCancellableFuture()); + if (externalFuture.isDone()) { + return null; + } + ApiFuture internalFuture = callable.futureCall(request, callContext); + externalFuture.setAttemptFuture(internalFuture); + } catch (Throwable e) { + externalFuture.setAttemptFuture(ApiFutures.immediateFailedFuture(e)); + } + + return null; + } + } + + /** + * A polling algorithm for waiting for a consistent {@link CheckConsistencyResponse}. Please note + * that this class doesn't handle retryable errors and expects the underlying callable chain to + * handle this. + */ + private static class PollResultAlgorithm + implements ResultRetryAlgorithm { + @Override + public TimedAttemptSettings createNextAttempt( + Throwable prevThrowable, + CheckConsistencyResponse prevResponse, + TimedAttemptSettings prevSettings) { + return null; + } + + @Override + public boolean shouldRetry(Throwable prevThrowable, CheckConsistencyResponse prevResponse) + throws CancellationException { + return prevResponse != null && !prevResponse.getConsistent(); + } + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java index a09026f7f7..663fb5368e 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java @@ -36,6 +36,7 @@ import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest; import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse; import com.google.bigtable.admin.v2.TableName; +import com.google.cloud.bigtable.admin.v2.models.ConsistencyParams; import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.MoreExecutors; import java.util.concurrent.Callable; @@ -48,143 +49,22 @@ * token then poll until isConsistent is true. */ class AwaitReplicationCallable extends UnaryCallable { - private final UnaryCallable - generateCallable; - private final UnaryCallable checkCallable; - private final RetryingExecutor executor; + private final AwaitConsistencyCallable awaitConsistencyCallable; - static AwaitReplicationCallable create( - UnaryCallable - generateCallable, - UnaryCallable checkCallable, - ClientContext clientContext, - RetrySettings pollingSettings) { + static AwaitReplicationCallable create(AwaitConsistencyCallable awaitConsistencyCallable) { - RetryAlgorithm retryAlgorithm = - new RetryAlgorithm<>( - new PollResultAlgorithm(), - new ExponentialPollAlgorithm(pollingSettings, clientContext.getClock())); - - RetryingExecutor retryingExecutor = - new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); - - return new AwaitReplicationCallable(generateCallable, checkCallable, retryingExecutor); - } - - @VisibleForTesting - AwaitReplicationCallable( - UnaryCallable - generateCallable, - UnaryCallable checkCallable, - RetryingExecutor executor) { - this.generateCallable = generateCallable; - this.checkCallable = checkCallable; - this.executor = executor; + return new AwaitReplicationCallable(awaitConsistencyCallable); } @Override public ApiFuture futureCall(final TableName tableName, final ApiCallContext context) { - ApiFuture tokenFuture = generateToken(tableName, context); - - return ApiFutures.transformAsync( - tokenFuture, - new ApiAsyncFunction() { - @Override - public ApiFuture apply(GenerateConsistencyTokenResponse input) { - CheckConsistencyRequest request = - CheckConsistencyRequest.newBuilder() - .setName(tableName.toString()) - .setConsistencyToken(input.getConsistencyToken()) - .build(); - - return pollToken(request, context); - } - }, - MoreExecutors.directExecutor()); - } - - private ApiFuture generateToken( - TableName tableName, ApiCallContext context) { - GenerateConsistencyTokenRequest generateRequest = - GenerateConsistencyTokenRequest.newBuilder().setName(tableName.toString()).build(); - return generateCallable.futureCall(generateRequest, context); - } + ConsistencyParams consistencyParams = ConsistencyParams.of(tableName, ConsistencyParams.ConsistencyMode.STANDARD); - private ApiFuture pollToken(CheckConsistencyRequest request, ApiCallContext context) { - AttemptCallable attemptCallable = - new AttemptCallable<>(checkCallable, request, context); - RetryingFuture retryingFuture = - executor.createFuture(attemptCallable); - attemptCallable.setExternalFuture(retryingFuture); - attemptCallable.call(); - - return ApiFutures.transform( - retryingFuture, - new ApiFunction() { - @Override - public Void apply(CheckConsistencyResponse input) { - return null; - } - }, - MoreExecutors.directExecutor()); - } - - /** A callable representing an attempt to make an RPC call. */ - private static class AttemptCallable implements Callable { - private final UnaryCallable callable; - private final RequestT request; - - private volatile RetryingFuture externalFuture; - private volatile ApiCallContext callContext; - - AttemptCallable( - UnaryCallable callable, RequestT request, ApiCallContext callContext) { - this.callable = callable; - this.request = request; - this.callContext = callContext; - } - - void setExternalFuture(RetryingFuture externalFuture) { - this.externalFuture = externalFuture; - } - - @Override - public ResponseT call() { - try { - // NOTE: unlike gax's AttemptCallable, this ignores rpc timeouts - externalFuture.setAttemptFuture(new NonCancellableFuture()); - if (externalFuture.isDone()) { - return null; - } - ApiFuture internalFuture = callable.futureCall(request, callContext); - externalFuture.setAttemptFuture(internalFuture); - } catch (Throwable e) { - externalFuture.setAttemptFuture(ApiFutures.immediateFailedFuture(e)); - } - - return null; - } + return awaitConsistencyCallable.futureCall(consistencyParams); } - /** - * A polling algorithm for waiting for a consistent {@link CheckConsistencyResponse}. Please note - * that this class doesn't handle retryable errors and expects the underlying callable chain to - * handle this. - */ - private static class PollResultAlgorithm - implements ResultRetryAlgorithm { - @Override - public TimedAttemptSettings createNextAttempt( - Throwable prevThrowable, - CheckConsistencyResponse prevResponse, - TimedAttemptSettings prevSettings) { - return null; - } - - @Override - public boolean shouldRetry(Throwable prevThrowable, CheckConsistencyResponse prevResponse) - throws CancellationException { - return prevResponse != null && !prevResponse.getConsistent(); - } + @VisibleForTesting + AwaitReplicationCallable(AwaitConsistencyCallable awaitConsistencyCallable) { + this.awaitConsistencyCallable = awaitConsistencyCallable; } } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java index 0a6e8efec3..193bd97da2 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java @@ -92,11 +92,9 @@ private AwaitReplicationCallable createAwaitReplicationCallable() { .setRpcTimeoutMultiplier(1.0) .build(); - return AwaitReplicationCallable.create( - generateConsistencyTokenCallable(), - checkConsistencyCallable(), - clientContext, - pollingSettings); + AwaitConsistencyCallable awaitConsistencyCallable = AwaitConsistencyCallable.create( + generateConsistencyTokenCallable(), checkConsistencyCallable(), clientContext, pollingSettings); + return AwaitReplicationCallable.create(awaitConsistencyCallable); } // Plug into gax operation infrastructure diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java index ac9941b2fc..9b99cb669f 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java @@ -81,12 +81,10 @@ public void setUp() { .setRpcTimeoutMultiplier(1.0) .build(); + AwaitConsistencyCallable awaitConsistencyCallable = AwaitConsistencyCallable.create( + mockGenerateConsistencyTokenCallable, mockCheckConsistencyCallable, clientContext, retrySettings); callable = - AwaitReplicationCallable.create( - mockGenerateConsistencyTokenCallable, - mockCheckConsistencyCallable, - clientContext, - retrySettings); + AwaitReplicationCallable.create(awaitConsistencyCallable); } @Test From d1b43200b01d18d4f799170eba64da2fbadd6309 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Wed, 4 Sep 2024 11:57:02 -0400 Subject: [PATCH 03/26] Address some PR comments Change-Id: Icdf94f2f6a13f55d2c9204774d4ebbac5aa6a8b3 --- .../admin/v2/models/ConsistencyParams.java | 17 +++-------------- .../admin/v2/stub/AwaitReplicationCallable.java | 2 ++ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java index 5bc86f5c31..01f5d5ac26 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java @@ -30,20 +30,6 @@ public enum ConsistencyMode { this.proto = proto; } - /** - * Wraps the protobuf. This method is considered an internal implementation detail and not meant - * to be used by applications. - */ - @InternalApi - public static ConsistencyParams.ConsistencyMode fromProto(CheckConsistencyRequest.ModeCase proto) { - for (ConsistencyParams.ConsistencyMode mode : values()) { - if (mode.proto.equals(proto)) { - return mode; - } - } - throw new IllegalArgumentException("Unknown consistency mode: " + proto); - } - /** * Creates the request protobuf. This method is considered an internal implementation detail and * not meant to be used by applications. @@ -76,4 +62,7 @@ public TableName getTableName() { public ConsistencyMode getConsistencyMode() { return consistencyMode; } + + @InternalApi + public static } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java index 663fb5368e..fc674252b0 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java @@ -48,6 +48,8 @@ *

This callable wraps GenerateConsistencyToken and CheckConsistency RPCs. It will generate a * token then poll until isConsistent is true. */ +/** @deprecated Please use {@link AwaitConsistencyCallable instead. */ +@Deprecated class AwaitReplicationCallable extends UnaryCallable { private final AwaitConsistencyCallable awaitConsistencyCallable; From febfb02dc46ab1b9fd73de35a6e9e8c77556dacf Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Wed, 4 Sep 2024 11:58:47 -0400 Subject: [PATCH 04/26] Remove unused imports from AwaitReplicationCallable Change-Id: Ia4861f1a5796061ca86844c67c68f54711fdbb94 --- .../v2/stub/AwaitReplicationCallable.java | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java index fc674252b0..d8477fda7e 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java @@ -15,32 +15,12 @@ */ package com.google.cloud.bigtable.admin.v2.stub; -import com.google.api.core.ApiAsyncFunction; -import com.google.api.core.ApiFunction; import com.google.api.core.ApiFuture; -import com.google.api.core.ApiFutures; -import com.google.api.gax.retrying.ExponentialPollAlgorithm; -import com.google.api.gax.retrying.NonCancellableFuture; -import com.google.api.gax.retrying.ResultRetryAlgorithm; -import com.google.api.gax.retrying.RetryAlgorithm; -import com.google.api.gax.retrying.RetrySettings; -import com.google.api.gax.retrying.RetryingExecutor; -import com.google.api.gax.retrying.RetryingFuture; -import com.google.api.gax.retrying.ScheduledRetryingExecutor; -import com.google.api.gax.retrying.TimedAttemptSettings; import com.google.api.gax.rpc.ApiCallContext; -import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; -import com.google.bigtable.admin.v2.CheckConsistencyRequest; -import com.google.bigtable.admin.v2.CheckConsistencyResponse; -import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest; -import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse; import com.google.bigtable.admin.v2.TableName; import com.google.cloud.bigtable.admin.v2.models.ConsistencyParams; import com.google.common.annotations.VisibleForTesting; -import com.google.common.util.concurrent.MoreExecutors; -import java.util.concurrent.Callable; -import java.util.concurrent.CancellationException; /** * Callable that waits until replication has caught up to the point it was called. From 84a242267b383bc535cda534a55d71fde1bfb7f9 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 6 Sep 2024 10:23:38 -0400 Subject: [PATCH 05/26] Plumb the Consistency callable through to some places, add some tests Change-Id: Ibe60e2a1044933af1008c0cd1b84f757dd6867a8 --- .../admin/v2/BigtableTableAdminClient.java | 27 ++++------ .../admin/v2/models/ConsistencyParams.java | 3 -- .../stub/EnhancedBigtableTableAdminStub.java | 54 +++++++++++-------- .../v2/BigtableTableAdminClientTests.java | 45 ++++++++++------ .../v2/models/ConsistencyParamsTest.java | 8 +++ 5 files changed, 82 insertions(+), 55 deletions(-) create mode 100644 google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParamsTest.java diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java index f640bb6a30..8159d4ec73 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java @@ -44,22 +44,7 @@ import com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPage; import com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; -import com.google.cloud.bigtable.admin.v2.models.AuthorizedView; -import com.google.cloud.bigtable.admin.v2.models.Backup; -import com.google.cloud.bigtable.admin.v2.models.CopyBackupRequest; -import com.google.cloud.bigtable.admin.v2.models.CreateAuthorizedViewRequest; -import com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest; -import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest; -import com.google.cloud.bigtable.admin.v2.models.EncryptionInfo; -import com.google.cloud.bigtable.admin.v2.models.GCRules; -import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest; -import com.google.cloud.bigtable.admin.v2.models.OptimizeRestoredTableOperationToken; -import com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest; -import com.google.cloud.bigtable.admin.v2.models.RestoredTableResult; -import com.google.cloud.bigtable.admin.v2.models.Table; -import com.google.cloud.bigtable.admin.v2.models.UpdateAuthorizedViewRequest; -import com.google.cloud.bigtable.admin.v2.models.UpdateBackupRequest; -import com.google.cloud.bigtable.admin.v2.models.UpdateTableRequest; +import com.google.cloud.bigtable.admin.v2.models.*; import com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -917,6 +902,16 @@ public void awaitReplication(String tableId) { stub.awaitReplicationCallable().futureCall(tableName)); } + public void awaitConsistency(String tableId, ConsistencyParams.ConsistencyMode mode) { + com.google.bigtable.admin.v2.TableName tableName = + com.google.bigtable.admin.v2.TableName.of(projectId, instanceId, tableId); + + ConsistencyParams consistencyParams = ConsistencyParams.of(tableName, mode); + + ApiExceptions.callAndTranslateApiException( + stub.awaitConsistencyCallable().futureCall(consistencyParams)); + } + /** * Creates a backup with the specified configuration. * diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java index 01f5d5ac26..91b0ab2333 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java @@ -62,7 +62,4 @@ public TableName getTableName() { public ConsistencyMode getConsistencyMode() { return consistencyMode; } - - @InternalApi - public static } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java index 193bd97da2..c374736341 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java @@ -31,6 +31,7 @@ import com.google.api.gax.rpc.UnaryCallable; import com.google.bigtable.admin.v2.OptimizeRestoredTableMetadata; import com.google.bigtable.admin.v2.TableName; +import com.google.cloud.bigtable.admin.v2.models.ConsistencyParams; import com.google.longrunning.Operation; import com.google.protobuf.Empty; import io.grpc.MethodDescriptor; @@ -53,6 +54,8 @@ public class EnhancedBigtableTableAdminStub extends GrpcBigtableTableAdminStub { private final ClientContext clientContext; private final AwaitReplicationCallable awaitReplicationCallable; + + private final AwaitConsistencyCallable awaitConsistencyCallable; private final OperationCallable optimizeRestoredTableOperationBaseCallable; @@ -67,36 +70,41 @@ private EnhancedBigtableTableAdminStub( this.settings = settings; this.clientContext = clientContext; + this.awaitConsistencyCallable = createAwaitConsistencyCallable(); this.awaitReplicationCallable = createAwaitReplicationCallable(); this.optimizeRestoredTableOperationBaseCallable = createOptimizeRestoredTableOperationBaseCallable(); } private AwaitReplicationCallable createAwaitReplicationCallable() { - // TODO(igorbernstein2): expose polling settings - RetrySettings pollingSettings = - RetrySettings.newBuilder() - // use overall timeout from checkConsistencyCallable - // NOTE: The overall timeout might exceed this value due to underlying retries - .setTotalTimeout( - settings.checkConsistencySettings().getRetrySettings().getTotalTimeout()) - // Use constant polling with jitter - .setInitialRetryDelay(Duration.ofSeconds(10)) - .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(Duration.ofSeconds(10)) - .setJittered(true) - // These rpc timeouts are ignored, instead the rpc timeouts defined for - // generateConsistencyToken and checkConsistency callables will be used. - .setInitialRpcTimeout(Duration.ZERO) - .setMaxRpcTimeout(Duration.ZERO) - .setRpcTimeoutMultiplier(1.0) - .build(); - - AwaitConsistencyCallable awaitConsistencyCallable = AwaitConsistencyCallable.create( - generateConsistencyTokenCallable(), checkConsistencyCallable(), clientContext, pollingSettings); return AwaitReplicationCallable.create(awaitConsistencyCallable); } + private AwaitConsistencyCallable createAwaitConsistencyCallable() { + // TODO(igorbernstein2): expose polling settings + RetrySettings pollingSettings = + RetrySettings.newBuilder() + // use overall timeout from checkConsistencyCallable + // NOTE: The overall timeout might exceed this value due to underlying retries + .setTotalTimeout( + settings.checkConsistencySettings().getRetrySettings().getTotalTimeout()) + // Use constant polling with jitter + .setInitialRetryDelay(Duration.ofSeconds(10)) + .setRetryDelayMultiplier(1.0) + .setMaxRetryDelay(Duration.ofSeconds(10)) + .setJittered(true) + // These rpc timeouts are ignored, instead the rpc timeouts defined for + // generateConsistencyToken and checkConsistency callables will be used. + .setInitialRpcTimeout(Duration.ZERO) + .setMaxRpcTimeout(Duration.ZERO) + .setRpcTimeoutMultiplier(1.0) + .build(); + + return AwaitConsistencyCallable.create( + generateConsistencyTokenCallable(), checkConsistencyCallable(), clientContext, pollingSettings); + } + + // Plug into gax operation infrastructure // gax assumes that all operations are started immediately and doesn't provide support for child // operations @@ -192,6 +200,10 @@ public UnaryCallable awaitReplicationCallable() { return awaitReplicationCallable; } + public UnaryCallable awaitConsistencyCallable() { + return awaitConsistencyCallable; + } + public OperationCallable awaitOptimizeRestoredTableCallable() { return optimizeRestoredTableOperationBaseCallable; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java index a7f2f74a17..3d4e014a94 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java @@ -61,21 +61,7 @@ import com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPage; import com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; -import com.google.cloud.bigtable.admin.v2.models.AuthorizedView; -import com.google.cloud.bigtable.admin.v2.models.Backup; -import com.google.cloud.bigtable.admin.v2.models.CopyBackupRequest; -import com.google.cloud.bigtable.admin.v2.models.CreateAuthorizedViewRequest; -import com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest; -import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest; -import com.google.cloud.bigtable.admin.v2.models.EncryptionInfo; -import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest; -import com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest; -import com.google.cloud.bigtable.admin.v2.models.RestoredTableResult; -import com.google.cloud.bigtable.admin.v2.models.SubsetView; -import com.google.cloud.bigtable.admin.v2.models.Table; -import com.google.cloud.bigtable.admin.v2.models.Type; -import com.google.cloud.bigtable.admin.v2.models.UpdateAuthorizedViewRequest; -import com.google.cloud.bigtable.admin.v2.models.UpdateBackupRequest; +import com.google.cloud.bigtable.admin.v2.models.*; import com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; @@ -156,6 +142,8 @@ public class BigtableTableAdminClientTests { @Mock private UnaryCallable mockDropRowRangeCallable; @Mock private UnaryCallable mockAwaitReplicationCallable; + @Mock private UnaryCallable mockAwaitConsistencyCallable; + @Mock private OperationCallable< com.google.bigtable.admin.v2.CreateBackupRequest, @@ -566,6 +554,33 @@ public void testAwaitReplication() { assertThat(wasCalled.get()).isTrue(); } + @Test + public void testAwaitConsistency() { + // Setup + Mockito.when(mockStub.awaitConsistencyCallable()).thenReturn(mockAwaitConsistencyCallable); + + TableName tableName = TableName.parse(TABLE_NAME); + ConsistencyParams.ConsistencyMode mode = ConsistencyParams.ConsistencyMode.DATA_BOOST; + + ConsistencyParams expectedRequest = ConsistencyParams.of(tableName, mode); + + final AtomicBoolean wasCalled = new AtomicBoolean(false); + + Mockito.when(mockAwaitConsistencyCallable.futureCall(expectedRequest)) + .thenAnswer( + (Answer>) + invocationOnMock -> { + wasCalled.set(true); + return ApiFutures.immediateFuture(null); + }); + + // Execute + adminClient.awaitConsistency(TABLE_ID, mode); + + // Verify + assertThat(wasCalled.get()).isTrue(); + } + @Test public void testExistsTrue() { // Setup diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParamsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParamsTest.java new file mode 100644 index 0000000000..60d9095922 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParamsTest.java @@ -0,0 +1,8 @@ +package com.google.cloud.bigtable.admin.v2.models; + +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class ConsistencyParamsTest { +} From 0f1faec323d53880164a13c3bcd53ad5a4924534 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 6 Sep 2024 10:49:56 -0400 Subject: [PATCH 06/26] Add integration test Change-Id: Ie3b2b2983ca585cb1d6a2cdb8b18b55e81205759 --- .../admin/v2/it/BigtableTableAdminClientIT.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java index a1b5c97e34..a3553de466 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java @@ -27,15 +27,11 @@ import com.google.api.gax.rpc.NotFoundException; import com.google.cloud.Policy; import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient; -import com.google.cloud.bigtable.admin.v2.models.ColumnFamily; -import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest; +import com.google.cloud.bigtable.admin.v2.models.*; import com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule; import com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule; import com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule; import com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule; -import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest; -import com.google.cloud.bigtable.admin.v2.models.Table; -import com.google.cloud.bigtable.admin.v2.models.UpdateTableRequest; import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv; import com.google.cloud.bigtable.test_helpers.env.PrefixGenerator; import com.google.cloud.bigtable.test_helpers.env.TestEnvRule; @@ -227,6 +223,13 @@ public void awaitReplication() { tableAdmin.awaitReplication(tableId); } + @Test + public void awaitConsistency() { + tableAdmin.createTable(CreateTableRequest.of(tableId)); + ConsistencyParams.ConsistencyMode mode = ConsistencyParams.ConsistencyMode.DATA_BOOST; + tableAdmin.awaitConsistency(tableId, mode); + } + @Test public void iamUpdateTest() { assume() From 20f78092efec958d4071f905d1d710d31ebb2844 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 6 Sep 2024 15:35:40 -0400 Subject: [PATCH 07/26] Rework the ConsistencyRequest model, plumb through RequestContext to BigtableTableAdminClient Change-Id: I840282587d3d6cb4150dfbdd568c347dc32a732d --- .../admin/v2/BigtableTableAdminClient.java | 15 ++--- .../admin/v2/models/ConsistencyParams.java | 65 ------------------- .../admin/v2/models/ConsistencyRequest.java | 56 ++++++++++++++++ .../v2/stub/AwaitConsistencyCallable.java | 32 +++++---- .../v2/stub/AwaitReplicationCallable.java | 8 ++- .../stub/EnhancedBigtableTableAdminStub.java | 16 +++-- .../v2/BigtableTableAdminClientTests.java | 10 +-- .../v2/it/BigtableTableAdminClientIT.java | 14 +++- 8 files changed, 110 insertions(+), 106 deletions(-) delete mode 100644 google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java create mode 100644 google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java index 8159d4ec73..ed6184f6aa 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java @@ -46,6 +46,7 @@ import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.cloud.bigtable.admin.v2.models.*; import com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub; +import com.google.cloud.bigtable.data.v2.internal.RequestContext; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -57,6 +58,8 @@ import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.ByteString; import com.google.protobuf.Empty; +import com.google.rpc.context.AttributeContext; + import java.io.IOException; import java.util.Arrays; import java.util.List; @@ -139,8 +142,9 @@ public static BigtableTableAdminClient create( /** Constructs an instance of BigtableTableAdminClient with the given settings. */ public static BigtableTableAdminClient create(@Nonnull BigtableTableAdminSettings settings) throws IOException { + RequestContext requestContext = RequestContext.create(settings.getProjectId(), settings.getInstanceId(), "dummyAppProfileId"); EnhancedBigtableTableAdminStub stub = - EnhancedBigtableTableAdminStub.createEnhanced(settings.getStubSettings()); + EnhancedBigtableTableAdminStub.createEnhanced(settings.getStubSettings(), requestContext); return create(settings.getProjectId(), settings.getInstanceId(), stub); } @@ -902,14 +906,9 @@ public void awaitReplication(String tableId) { stub.awaitReplicationCallable().futureCall(tableName)); } - public void awaitConsistency(String tableId, ConsistencyParams.ConsistencyMode mode) { - com.google.bigtable.admin.v2.TableName tableName = - com.google.bigtable.admin.v2.TableName.of(projectId, instanceId, tableId); - - ConsistencyParams consistencyParams = ConsistencyParams.of(tableName, mode); - + public void awaitConsistency(ConsistencyRequest consistencyRequest) { ApiExceptions.callAndTranslateApiException( - stub.awaitConsistencyCallable().futureCall(consistencyParams)); + stub.awaitConsistencyCallable().futureCall(consistencyRequest)); } /** diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java deleted file mode 100644 index 91b0ab2333..0000000000 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParams.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.google.cloud.bigtable.admin.v2.models; - -import com.google.api.core.InternalApi; -import com.google.bigtable.admin.v2.CheckConsistencyRequest; -import com.google.bigtable.admin.v2.TableName; -import com.google.common.base.Preconditions; - -import javax.annotation.Nonnull; - -public class ConsistencyParams { - public enum ConsistencyMode { - /** - * Checks that reads using an app profile with `StandardIsolation` can - * see all writes committed before the token was created, even if the - * read and write target different clusters. - */ - STANDARD(CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES), - - /** - * Checks that reads using an app profile with `DataBoostIsolationReadOnly` - * can see all writes committed before the token was created, but only if - * the read and write target the same cluster. - */ - DATA_BOOST(CheckConsistencyRequest.ModeCase.DATA_BOOST_READ_LOCAL_WRITES); - - @Nonnull - private final CheckConsistencyRequest.ModeCase proto; - - ConsistencyMode(CheckConsistencyRequest.ModeCase proto) { - this.proto = proto; - } - - /** - * Creates the request protobuf. This method is considered an internal implementation detail and - * not meant to be used by applications. - */ - @InternalApi - public CheckConsistencyRequest.ModeCase toProto() { - return proto; - } - } - - private final TableName tableName; - - private final ConsistencyMode consistencyMode; - - ConsistencyParams(TableName tableName, ConsistencyMode mode) { - Preconditions.checkNotNull(tableName); - Preconditions.checkNotNull(mode); - this.tableName = tableName; - this.consistencyMode = mode; - } - - public static ConsistencyParams of(TableName tableName, ConsistencyMode mode) { - return new ConsistencyParams(tableName, mode); - } - - public TableName getTableName() { - return tableName; - } - - public ConsistencyMode getConsistencyMode() { - return consistencyMode; - } -} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java new file mode 100644 index 0000000000..7718cb01d1 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java @@ -0,0 +1,56 @@ +package com.google.cloud.bigtable.admin.v2.models; + +import com.google.api.core.InternalApi; +import com.google.bigtable.admin.v2.*; +import com.google.cloud.bigtable.data.v2.internal.RequestContext; +import com.google.common.base.Preconditions; +import org.checkerframework.checker.units.qual.C; + +public class ConsistencyRequest { + private final String tableId; + + private final CheckConsistencyRequest.ModeCase consistencyMode; + + ConsistencyRequest(String tableId, CheckConsistencyRequest.ModeCase consistencyMode) { + Preconditions.checkNotNull(tableId); + Preconditions.checkNotNull(consistencyMode); + this.tableId = tableId; + this.consistencyMode = consistencyMode; + } + + public static ConsistencyRequest getStandardConsistencyRequest(String tableId) { + return new ConsistencyRequest(tableId, CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES); + } + + public static ConsistencyRequest getDataBoostConsistencyRequest(String tableId) { + return new ConsistencyRequest(tableId, CheckConsistencyRequest.ModeCase.DATA_BOOST_READ_LOCAL_WRITES); + } + + @InternalApi + public CheckConsistencyRequest toCheckConsistencyProto(RequestContext requestContext, String token) { + CheckConsistencyRequest.Builder builder = CheckConsistencyRequest.newBuilder(); + TableName tableName = TableName.of(requestContext.getProjectId(), requestContext.getInstanceId(), tableId); + + if (consistencyMode.equals(CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES)) { + builder.setStandardReadRemoteWrites(StandardReadRemoteWrites.newBuilder().build()); + } else { + builder.setDataBoostReadLocalWrites(DataBoostReadLocalWrites.newBuilder().build()); + } + + return builder + .setName(tableName.toString()) + .setConsistencyToken(token) + .build(); + } + + @InternalApi + public GenerateConsistencyTokenRequest toGenerateTokenProto(RequestContext requestContext) { + GenerateConsistencyTokenRequest.Builder builder = + GenerateConsistencyTokenRequest.newBuilder(); + TableName tableName = TableName.of(requestContext.getProjectId(), requestContext.getInstanceId(), tableId); + + return builder + .setName(tableName.toString()) + .build(); + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java index a19f22c6f8..3abbf59a6f 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java @@ -36,7 +36,8 @@ import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest; import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse; import com.google.bigtable.admin.v2.TableName; -import com.google.cloud.bigtable.admin.v2.models.ConsistencyParams; +import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; +import com.google.cloud.bigtable.data.v2.internal.RequestContext; import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.MoreExecutors; import java.util.concurrent.Callable; @@ -48,18 +49,21 @@ *

This callable wraps GenerateConsistencyToken and CheckConsistency RPCs. It will generate a * token then poll until isConsistent is true. */ -class AwaitConsistencyCallable extends UnaryCallable { +class AwaitConsistencyCallable extends UnaryCallable { private final UnaryCallable generateCallable; private final UnaryCallable checkCallable; private final RetryingExecutor executor; + private final RequestContext requestContext; + static AwaitConsistencyCallable create( UnaryCallable generateCallable, UnaryCallable checkCallable, ClientContext clientContext, - RetrySettings pollingSettings) { + RetrySettings pollingSettings, + RequestContext requestContext) { RetryAlgorithm retryAlgorithm = new RetryAlgorithm<>( @@ -69,7 +73,7 @@ static AwaitConsistencyCallable create( RetryingExecutor retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); - return new AwaitConsistencyCallable(generateCallable, checkCallable, retryingExecutor); + return new AwaitConsistencyCallable(generateCallable, checkCallable, retryingExecutor, requestContext); } @VisibleForTesting @@ -77,28 +81,24 @@ static AwaitConsistencyCallable create( UnaryCallable generateCallable, UnaryCallable checkCallable, - RetryingExecutor executor) { + RetryingExecutor executor, + RequestContext requestContext) { this.generateCallable = generateCallable; this.checkCallable = checkCallable; this.executor = executor; + this.requestContext = requestContext; } @Override - public ApiFuture futureCall(final ConsistencyParams consistencyParams, final ApiCallContext context) { - TableName tableName = consistencyParams.getTableName(); - ApiFuture tokenFuture = generateToken(tableName, context); + public ApiFuture futureCall(final ConsistencyRequest consistencyRequest, final ApiCallContext context) { + ApiFuture tokenFuture = generateToken(consistencyRequest.toGenerateTokenProto(requestContext), context); return ApiFutures.transformAsync( tokenFuture, new ApiAsyncFunction() { @Override public ApiFuture apply(GenerateConsistencyTokenResponse input) { - CheckConsistencyRequest request = - CheckConsistencyRequest.newBuilder() - .setName(tableName.toString()) - .setConsistencyToken(input.getConsistencyToken()) - .build(); - + CheckConsistencyRequest request = consistencyRequest.toCheckConsistencyProto(requestContext, input.getConsistencyToken()); return pollToken(request, context); } }, @@ -106,9 +106,7 @@ public ApiFuture apply(GenerateConsistencyTokenResponse input) { } private ApiFuture generateToken( - TableName tableName, ApiCallContext context) { - GenerateConsistencyTokenRequest generateRequest = - GenerateConsistencyTokenRequest.newBuilder().setName(tableName.toString()).build(); + GenerateConsistencyTokenRequest generateRequest, ApiCallContext context) { return generateCallable.futureCall(generateRequest, context); } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java index d8477fda7e..fa01e390f0 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java @@ -18,8 +18,9 @@ import com.google.api.core.ApiFuture; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.admin.v2.CheckConsistencyRequest; import com.google.bigtable.admin.v2.TableName; -import com.google.cloud.bigtable.admin.v2.models.ConsistencyParams; +import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; import com.google.common.annotations.VisibleForTesting; /** @@ -40,9 +41,10 @@ static AwaitReplicationCallable create(AwaitConsistencyCallable awaitConsistency @Override public ApiFuture futureCall(final TableName tableName, final ApiCallContext context) { - ConsistencyParams consistencyParams = ConsistencyParams.of(tableName, ConsistencyParams.ConsistencyMode.STANDARD); + ConsistencyRequest consistencyRequest = ConsistencyRequest.of(tableName.getTable()); + consistencyRequest.setStandardMode(); - return awaitConsistencyCallable.futureCall(consistencyParams); + return awaitConsistencyCallable.futureCall(consistencyRequest, context); } @VisibleForTesting diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java index c374736341..1e7acebd41 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java @@ -31,7 +31,8 @@ import com.google.api.gax.rpc.UnaryCallable; import com.google.bigtable.admin.v2.OptimizeRestoredTableMetadata; import com.google.bigtable.admin.v2.TableName; -import com.google.cloud.bigtable.admin.v2.models.ConsistencyParams; +import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; +import com.google.cloud.bigtable.data.v2.internal.RequestContext; import com.google.longrunning.Operation; import com.google.protobuf.Empty; import io.grpc.MethodDescriptor; @@ -53,6 +54,8 @@ public class EnhancedBigtableTableAdminStub extends GrpcBigtableTableAdminStub { private final BigtableTableAdminStubSettings settings; private final ClientContext clientContext; + private final RequestContext requestContext; + private final AwaitReplicationCallable awaitReplicationCallable; private final AwaitConsistencyCallable awaitConsistencyCallable; @@ -60,12 +63,12 @@ public class EnhancedBigtableTableAdminStub extends GrpcBigtableTableAdminStub { optimizeRestoredTableOperationBaseCallable; public static EnhancedBigtableTableAdminStub createEnhanced( - BigtableTableAdminStubSettings settings) throws IOException { - return new EnhancedBigtableTableAdminStub(settings, ClientContext.create(settings)); + BigtableTableAdminStubSettings settings, RequestContext requestContext) throws IOException { + return new EnhancedBigtableTableAdminStub(settings, ClientContext.create(settings), requestContext); } private EnhancedBigtableTableAdminStub( - BigtableTableAdminStubSettings settings, ClientContext clientContext) throws IOException { + BigtableTableAdminStubSettings settings, ClientContext clientContext, RequestContext requestContext) throws IOException { super(settings, clientContext); this.settings = settings; @@ -74,6 +77,7 @@ private EnhancedBigtableTableAdminStub( this.awaitReplicationCallable = createAwaitReplicationCallable(); this.optimizeRestoredTableOperationBaseCallable = createOptimizeRestoredTableOperationBaseCallable(); + this.requestContext = requestContext; } private AwaitReplicationCallable createAwaitReplicationCallable() { @@ -101,7 +105,7 @@ private AwaitConsistencyCallable createAwaitConsistencyCallable() { .build(); return AwaitConsistencyCallable.create( - generateConsistencyTokenCallable(), checkConsistencyCallable(), clientContext, pollingSettings); + generateConsistencyTokenCallable(), checkConsistencyCallable(), clientContext, pollingSettings, requestContext); } @@ -200,7 +204,7 @@ public UnaryCallable awaitReplicationCallable() { return awaitReplicationCallable; } - public UnaryCallable awaitConsistencyCallable() { + public UnaryCallable awaitConsistencyCallable() { return awaitConsistencyCallable; } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java index 3d4e014a94..4bda452123 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java @@ -142,7 +142,7 @@ public class BigtableTableAdminClientTests { @Mock private UnaryCallable mockDropRowRangeCallable; @Mock private UnaryCallable mockAwaitReplicationCallable; - @Mock private UnaryCallable mockAwaitConsistencyCallable; + @Mock private UnaryCallable mockAwaitConsistencyCallable; @Mock private OperationCallable< @@ -560,9 +560,9 @@ public void testAwaitConsistency() { Mockito.when(mockStub.awaitConsistencyCallable()).thenReturn(mockAwaitConsistencyCallable); TableName tableName = TableName.parse(TABLE_NAME); - ConsistencyParams.ConsistencyMode mode = ConsistencyParams.ConsistencyMode.DATA_BOOST; + ConsistencyRequest.ConsistencyMode mode = ConsistencyRequest.ConsistencyMode.DATA_BOOST; - ConsistencyParams expectedRequest = ConsistencyParams.of(tableName, mode); + ConsistencyRequest expectedRequest = ConsistencyRequest.of(tableName, mode); final AtomicBoolean wasCalled = new AtomicBoolean(false); @@ -574,8 +574,10 @@ public void testAwaitConsistency() { return ApiFutures.immediateFuture(null); }); + ConsistencyRequest consistencyRequest = ConsistencyRequest.of(TABLE_ID); + consistencyRequest.setDataBoostMode(); // Execute - adminClient.awaitConsistency(TABLE_ID, mode); + adminClient.awaitConsistency(consistencyRequest); // Verify assertThat(wasCalled.get()).isTrue(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java index a3553de466..922b13d5d8 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java @@ -223,11 +223,19 @@ public void awaitReplication() { tableAdmin.awaitReplication(tableId); } + /** + * Note: Data Boost consistency is essentially a check that the data you are trying to read was written + * at least 35 minutes ago. + */ @Test - public void awaitConsistency() { + public void awaitDataBoostConsistency() { + assume() + .withMessage("Data Boost consistency not supported on Emulator") + .that(testEnvRule.env()) + .isNotInstanceOf(EmulatorEnv.class); tableAdmin.createTable(CreateTableRequest.of(tableId)); - ConsistencyParams.ConsistencyMode mode = ConsistencyParams.ConsistencyMode.DATA_BOOST; - tableAdmin.awaitConsistency(tableId, mode); + ConsistencyRequest consistencyRequest = ConsistencyRequest.getDataBoostConsistencyRequest(tableId); + tableAdmin.awaitConsistency(consistencyRequest); } @Test From 2c47294a2f69b7e05b5b4db20f72ccb73c2f3ba4 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 6 Sep 2024 15:44:01 -0400 Subject: [PATCH 08/26] Fix imports Change-Id: Ic7588b3d04877a56089c23036d6df73a5c9b0cd5 --- .../admin/v2/BigtableTableAdminClient.java | 18 ++++++++++++- .../v2/BigtableTableAdminClientTests.java | 27 +++++++++++++------ .../v2/it/BigtableTableAdminClientIT.java | 7 ++++- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java index ed6184f6aa..d18fc0c84b 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java @@ -44,7 +44,23 @@ import com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPage; import com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; -import com.google.cloud.bigtable.admin.v2.models.*; +import com.google.cloud.bigtable.admin.v2.models.AuthorizedView; +import com.google.cloud.bigtable.admin.v2.models.Backup; +import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; +import com.google.cloud.bigtable.admin.v2.models.CopyBackupRequest; +import com.google.cloud.bigtable.admin.v2.models.CreateAuthorizedViewRequest; +import com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest; +import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest; +import com.google.cloud.bigtable.admin.v2.models.EncryptionInfo; +import com.google.cloud.bigtable.admin.v2.models.GCRules; +import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest; +import com.google.cloud.bigtable.admin.v2.models.OptimizeRestoredTableOperationToken; +import com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest; +import com.google.cloud.bigtable.admin.v2.models.RestoredTableResult; +import com.google.cloud.bigtable.admin.v2.models.Table; +import com.google.cloud.bigtable.admin.v2.models.UpdateAuthorizedViewRequest; +import com.google.cloud.bigtable.admin.v2.models.UpdateBackupRequest; +import com.google.cloud.bigtable.admin.v2.models.UpdateTableRequest; import com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub; import com.google.cloud.bigtable.data.v2.internal.RequestContext; import com.google.common.base.Preconditions; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java index 4bda452123..2d75c08253 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java @@ -61,7 +61,22 @@ import com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPage; import com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; -import com.google.cloud.bigtable.admin.v2.models.*; +import com.google.cloud.bigtable.admin.v2.models.AuthorizedView; +import com.google.cloud.bigtable.admin.v2.models.Backup; +import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; +import com.google.cloud.bigtable.admin.v2.models.CopyBackupRequest; +import com.google.cloud.bigtable.admin.v2.models.CreateAuthorizedViewRequest; +import com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest; +import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest; +import com.google.cloud.bigtable.admin.v2.models.EncryptionInfo; +import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest; +import com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest; +import com.google.cloud.bigtable.admin.v2.models.RestoredTableResult; +import com.google.cloud.bigtable.admin.v2.models.SubsetView; +import com.google.cloud.bigtable.admin.v2.models.Table; +import com.google.cloud.bigtable.admin.v2.models.Type; +import com.google.cloud.bigtable.admin.v2.models.UpdateAuthorizedViewRequest; +import com.google.cloud.bigtable.admin.v2.models.UpdateBackupRequest; import com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; @@ -555,14 +570,11 @@ public void testAwaitReplication() { } @Test - public void testAwaitConsistency() { + public void testAwaitConsistencyForDataBoost() { // Setup Mockito.when(mockStub.awaitConsistencyCallable()).thenReturn(mockAwaitConsistencyCallable); - TableName tableName = TableName.parse(TABLE_NAME); - ConsistencyRequest.ConsistencyMode mode = ConsistencyRequest.ConsistencyMode.DATA_BOOST; - - ConsistencyRequest expectedRequest = ConsistencyRequest.of(tableName, mode); + ConsistencyRequest expectedRequest = ConsistencyRequest.getDataBoostConsistencyRequest(TABLE_ID); final AtomicBoolean wasCalled = new AtomicBoolean(false); @@ -574,8 +586,7 @@ public void testAwaitConsistency() { return ApiFutures.immediateFuture(null); }); - ConsistencyRequest consistencyRequest = ConsistencyRequest.of(TABLE_ID); - consistencyRequest.setDataBoostMode(); + ConsistencyRequest consistencyRequest = ConsistencyRequest.getDataBoostConsistencyRequest(TABLE_ID); // Execute adminClient.awaitConsistency(consistencyRequest); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java index 922b13d5d8..2ef33086dd 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java @@ -27,11 +27,16 @@ import com.google.api.gax.rpc.NotFoundException; import com.google.cloud.Policy; import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient; -import com.google.cloud.bigtable.admin.v2.models.*; +import com.google.cloud.bigtable.admin.v2.models.ColumnFamily; +import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; +import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest; import com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule; import com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule; import com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule; import com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule; +import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest; +import com.google.cloud.bigtable.admin.v2.models.Table; +import com.google.cloud.bigtable.admin.v2.models.UpdateTableRequest; import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv; import com.google.cloud.bigtable.test_helpers.env.PrefixGenerator; import com.google.cloud.bigtable.test_helpers.env.TestEnvRule; From ce0a43921f4be1581c6b4fdee108b61982c8dfd8 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 6 Sep 2024 15:50:16 -0400 Subject: [PATCH 09/26] Fix more imports, fix some tests Change-Id: I2723fd67bd301a4eb3aeae80d91fa663cdd6ab01 --- .../bigtable/admin/v2/BigtableTableAdminClient.java | 1 - .../admin/v2/stub/AwaitReplicationCallable.java | 3 +-- .../admin/v2/stub/AwaitReplicationCallableTest.java | 12 ++++++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java index d18fc0c84b..e15d1bc2aa 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java @@ -74,7 +74,6 @@ import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.ByteString; import com.google.protobuf.Empty; -import com.google.rpc.context.AttributeContext; import java.io.IOException; import java.util.Arrays; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java index fa01e390f0..d2b0e75715 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java @@ -41,8 +41,7 @@ static AwaitReplicationCallable create(AwaitConsistencyCallable awaitConsistency @Override public ApiFuture futureCall(final TableName tableName, final ApiCallContext context) { - ConsistencyRequest consistencyRequest = ConsistencyRequest.of(tableName.getTable()); - consistencyRequest.setStandardMode(); + ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(tableName.getTable()); return awaitConsistencyCallable.futureCall(consistencyRequest, context); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java index 9b99cb669f..17f871a1bb 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java @@ -34,9 +34,12 @@ import com.google.bigtable.admin.v2.TableName; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; + +import com.google.cloud.bigtable.data.v2.internal.RequestContext; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.runner.Request; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mock; @@ -50,7 +53,10 @@ public class AwaitReplicationCallableTest { @Rule public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.WARN); - private static final TableName TABLE_NAME = TableName.of("my-project", "my-instance", "my-table"); + private static final String PROJECT_ID = "my-project"; + private static final String INSTANCE_ID = "my-instance"; + private static final String TABLE_ID = "my-table"; + private static final TableName TABLE_NAME = TableName.of(PROJECT_ID, INSTANCE_ID, TABLE_ID); private static final ApiCallContext CALL_CONTEXT = FakeCallContext.createDefault(); @Mock @@ -81,8 +87,10 @@ public void setUp() { .setRpcTimeoutMultiplier(1.0) .build(); + RequestContext requestContext = RequestContext.create(PROJECT_ID, INSTANCE_ID, "dummyAppProfile"); + AwaitConsistencyCallable awaitConsistencyCallable = AwaitConsistencyCallable.create( - mockGenerateConsistencyTokenCallable, mockCheckConsistencyCallable, clientContext, retrySettings); + mockGenerateConsistencyTokenCallable, mockCheckConsistencyCallable, clientContext, retrySettings, requestContext); callable = AwaitReplicationCallable.create(awaitConsistencyCallable); } From 032703871d803f7f4bb8adb1baeaf53be966645a Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 6 Sep 2024 15:58:17 -0400 Subject: [PATCH 10/26] Rename some things Change-Id: Ie1bc8478c418d49b0c2e014edbeb6f56b56b0dd1 --- .../cloud/bigtable/admin/v2/BigtableTableAdminClient.java | 1 - .../bigtable/admin/v2/stub/AwaitConsistencyCallable.java | 6 +++--- .../admin/v2/stub/AwaitReplicationCallableTest.java | 2 -- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java index e15d1bc2aa..a955554673 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java @@ -74,7 +74,6 @@ import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.ByteString; import com.google.protobuf.Empty; - import java.io.IOException; import java.util.Arrays; import java.util.List; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java index 3abbf59a6f..7809afeae4 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java @@ -90,8 +90,8 @@ static AwaitConsistencyCallable create( } @Override - public ApiFuture futureCall(final ConsistencyRequest consistencyRequest, final ApiCallContext context) { - ApiFuture tokenFuture = generateToken(consistencyRequest.toGenerateTokenProto(requestContext), context); + public ApiFuture futureCall(final ConsistencyRequest consistencyRequest, final ApiCallContext apiCallContext) { + ApiFuture tokenFuture = generateToken(consistencyRequest.toGenerateTokenProto(requestContext), apiCallContext); return ApiFutures.transformAsync( tokenFuture, @@ -99,7 +99,7 @@ public ApiFuture futureCall(final ConsistencyRequest consistencyRequest, f @Override public ApiFuture apply(GenerateConsistencyTokenResponse input) { CheckConsistencyRequest request = consistencyRequest.toCheckConsistencyProto(requestContext, input.getConsistencyToken()); - return pollToken(request, context); + return pollToken(request, apiCallContext); } }, MoreExecutors.directExecutor()); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java index 17f871a1bb..85193e8092 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java @@ -34,12 +34,10 @@ import com.google.bigtable.admin.v2.TableName; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; - import com.google.cloud.bigtable.data.v2.internal.RequestContext; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.runner.Request; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mock; From c7fbb27d0658cdaea94149fcc8cb649b31e52f86 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 6 Sep 2024 16:16:48 -0400 Subject: [PATCH 11/26] Add tests for ConsistencyRequest model Change-Id: I3548b7aa673be5a92cd4c180e3edb8649657811c --- .../v2/models/ConsistencyParamsTest.java | 8 --- .../v2/models/ConsistencyRequestTest.java | 56 +++++++++++++++++++ 2 files changed, 56 insertions(+), 8 deletions(-) delete mode 100644 google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParamsTest.java create mode 100644 google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParamsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParamsTest.java deleted file mode 100644 index 60d9095922..0000000000 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyParamsTest.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.google.cloud.bigtable.admin.v2.models; - -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class ConsistencyParamsTest { -} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java new file mode 100644 index 0000000000..30f14d9aba --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java @@ -0,0 +1,56 @@ +package com.google.cloud.bigtable.admin.v2.models; + +import com.google.bigtable.admin.v2.CheckConsistencyRequest; +import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest; +import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse; +import com.google.cloud.bigtable.data.v2.internal.RequestContext; +import org.junit.Test; +import org.junit.runner.Request; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import static com.google.common.truth.Truth.assertThat; + +@RunWith(JUnit4.class) +public class ConsistencyRequestTest { + private final String PROJECT_ID = "my-project"; + private final String INSTANCE_ID = "my-instance"; + private final String TABLE_ID = "my-table"; + private final String CONSISTENCY_TOKEN = "my-token"; + @Test + public void testToCheckConsistencyProtoWithStandard() { + ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(TABLE_ID); + + RequestContext requestContext = RequestContext.create(PROJECT_ID, INSTANCE_ID, TABLE_ID); + + CheckConsistencyRequest checkConsistencyRequest = consistencyRequest.toCheckConsistencyProto(requestContext, CONSISTENCY_TOKEN); + + assertThat(checkConsistencyRequest.getName().equals(TABLE_ID)); + assertThat(checkConsistencyRequest.getConsistencyToken().equals(CONSISTENCY_TOKEN)); + assertThat(checkConsistencyRequest.getModeCase().equals(CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES)); + } + + @Test + public void testToCheckConsistencyProtoWithDataBoost() { + ConsistencyRequest consistencyRequest = ConsistencyRequest.getDataBoostConsistencyRequest(TABLE_ID); + + RequestContext requestContext = RequestContext.create(PROJECT_ID, INSTANCE_ID, TABLE_ID); + + CheckConsistencyRequest checkConsistencyRequest = consistencyRequest.toCheckConsistencyProto(requestContext, CONSISTENCY_TOKEN); + + assertThat(checkConsistencyRequest.getName().equals(TABLE_ID)); + assertThat(checkConsistencyRequest.getConsistencyToken().equals(CONSISTENCY_TOKEN)); + assertThat(checkConsistencyRequest.getModeCase().equals(CheckConsistencyRequest.ModeCase.DATA_BOOST_READ_LOCAL_WRITES)); + } + + @Test + public void testToGenerateTokenProto() { + ConsistencyRequest consistencyRequest = ConsistencyRequest.getDataBoostConsistencyRequest(TABLE_ID); + + RequestContext requestContext = RequestContext.create(PROJECT_ID, INSTANCE_ID, TABLE_ID); + + GenerateConsistencyTokenRequest generateRequest = consistencyRequest.toGenerateTokenProto(requestContext); + + assertThat(generateRequest.getName().equals(TABLE_ID)); + } +} From c8ff829e5695b65ceba3e91fbdf3fc5d85a989d4 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 6 Sep 2024 16:17:27 -0400 Subject: [PATCH 12/26] Add newline Change-Id: Icdd22ce2857e5b4316c6fa3f0e139ea9de825178 --- .../cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java index 30f14d9aba..c7e98fc53a 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java @@ -17,6 +17,7 @@ public class ConsistencyRequestTest { private final String INSTANCE_ID = "my-instance"; private final String TABLE_ID = "my-table"; private final String CONSISTENCY_TOKEN = "my-token"; + @Test public void testToCheckConsistencyProtoWithStandard() { ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(TABLE_ID); From f57b84d826a0a724c9b9921ad72efd8c360a4f3f Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 6 Sep 2024 16:35:57 -0400 Subject: [PATCH 13/26] Fix broken test Change-Id: Idbd7c0f10ebe575d104ab7ac46a3a1e347e35fe8 --- .../bigtable/admin/v2/BigtableTableAdminClientTests.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java index 2d75c08253..7e0b6a4104 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java @@ -574,11 +574,11 @@ public void testAwaitConsistencyForDataBoost() { // Setup Mockito.when(mockStub.awaitConsistencyCallable()).thenReturn(mockAwaitConsistencyCallable); - ConsistencyRequest expectedRequest = ConsistencyRequest.getDataBoostConsistencyRequest(TABLE_ID); + ConsistencyRequest consistencyRequest = ConsistencyRequest.getDataBoostConsistencyRequest(TABLE_ID); final AtomicBoolean wasCalled = new AtomicBoolean(false); - Mockito.when(mockAwaitConsistencyCallable.futureCall(expectedRequest)) + Mockito.when(mockAwaitConsistencyCallable.futureCall(consistencyRequest)) .thenAnswer( (Answer>) invocationOnMock -> { @@ -586,7 +586,6 @@ public void testAwaitConsistencyForDataBoost() { return ApiFutures.immediateFuture(null); }); - ConsistencyRequest consistencyRequest = ConsistencyRequest.getDataBoostConsistencyRequest(TABLE_ID); // Execute adminClient.awaitConsistency(consistencyRequest); From 86f6d8aa80099303a33ec1047679f7cb9c0c190e Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 6 Sep 2024 16:43:47 -0400 Subject: [PATCH 14/26] Make request context a final variable in test Change-Id: I81f2a25fe4493021bab150ab0af65d7318ba2399 --- .../bigtable/admin/v2/stub/AwaitReplicationCallableTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java index 85193e8092..fe16d8df20 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java @@ -56,6 +56,7 @@ public class AwaitReplicationCallableTest { private static final String TABLE_ID = "my-table"; private static final TableName TABLE_NAME = TableName.of(PROJECT_ID, INSTANCE_ID, TABLE_ID); private static final ApiCallContext CALL_CONTEXT = FakeCallContext.createDefault(); + private static final RequestContext REQUEST_CONTEXT = RequestContext.create(PROJECT_ID, INSTANCE_ID, "dummyAppProfile"); @Mock private UnaryCallable @@ -85,10 +86,8 @@ public void setUp() { .setRpcTimeoutMultiplier(1.0) .build(); - RequestContext requestContext = RequestContext.create(PROJECT_ID, INSTANCE_ID, "dummyAppProfile"); - AwaitConsistencyCallable awaitConsistencyCallable = AwaitConsistencyCallable.create( - mockGenerateConsistencyTokenCallable, mockCheckConsistencyCallable, clientContext, retrySettings, requestContext); + mockGenerateConsistencyTokenCallable, mockCheckConsistencyCallable, clientContext, retrySettings, REQUEST_CONTEXT); callable = AwaitReplicationCallable.create(awaitConsistencyCallable); } From 916535ff5b8abecf8958caa66556cc36d15a6ec2 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 6 Sep 2024 18:09:22 -0400 Subject: [PATCH 15/26] Get test working using correct expectations Change-Id: Ie34d5171bd7a472fc695d603849e260054aedfbd --- ...java => AwaitConsistencyCallableTest.java} | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) rename google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/{AwaitReplicationCallableTest.java => AwaitConsistencyCallableTest.java} (85%) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java similarity index 85% rename from google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java rename to google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java index fe16d8df20..2b4acae584 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java @@ -31,9 +31,12 @@ import com.google.bigtable.admin.v2.CheckConsistencyResponse; import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest; import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse; +import com.google.bigtable.admin.v2.StandardReadRemoteWrites; import com.google.bigtable.admin.v2.TableName; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; + +import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; import com.google.cloud.bigtable.data.v2.internal.RequestContext; import org.junit.Before; import org.junit.Rule; @@ -48,7 +51,7 @@ import org.threeten.bp.Duration; @RunWith(JUnit4.class) -public class AwaitReplicationCallableTest { +public class AwaitConsistencyCallableTest { @Rule public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.WARN); private static final String PROJECT_ID = "my-project"; @@ -68,6 +71,8 @@ public class AwaitReplicationCallableTest { private AwaitReplicationCallable callable; + private AwaitConsistencyCallable awaitConsistencyCallable; + @Before public void setUp() { ClientContext clientContext = @@ -86,8 +91,8 @@ public void setUp() { .setRpcTimeoutMultiplier(1.0) .build(); - AwaitConsistencyCallable awaitConsistencyCallable = AwaitConsistencyCallable.create( - mockGenerateConsistencyTokenCallable, mockCheckConsistencyCallable, clientContext, retrySettings, REQUEST_CONTEXT); + awaitConsistencyCallable = AwaitConsistencyCallable.create(mockGenerateConsistencyTokenCallable, + mockCheckConsistencyCallable, clientContext, retrySettings, REQUEST_CONTEXT); callable = AwaitReplicationCallable.create(awaitConsistencyCallable); } @@ -128,6 +133,7 @@ public void testCheckFailure() throws Exception { CheckConsistencyRequest.newBuilder() .setName(TABLE_NAME.toString()) .setConsistencyToken("fake-token") + .setStandardReadRemoteWrites(StandardReadRemoteWrites.newBuilder().build()) .build(); FakeApiException expectedError = new FakeApiException("fake", null, Code.INTERNAL, false); @@ -135,7 +141,8 @@ public void testCheckFailure() throws Exception { Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)) .thenReturn(ApiFutures.immediateFailedFuture(expectedError)); - ApiFuture future = callable.futureCall(TABLE_NAME, CALL_CONTEXT); + ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(TABLE_ID); + ApiFuture future = awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); Throwable actualError = null; @@ -163,6 +170,7 @@ public void testImmediatelyConsistent() throws Exception { CheckConsistencyRequest.newBuilder() .setName(TABLE_NAME.toString()) .setConsistencyToken("fake-token") + .setStandardReadRemoteWrites(StandardReadRemoteWrites.newBuilder().build()) .build(); CheckConsistencyResponse expectedResponse2 = CheckConsistencyResponse.newBuilder().setConsistent(true).build(); @@ -170,7 +178,8 @@ public void testImmediatelyConsistent() throws Exception { Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)) .thenReturn(ApiFutures.immediateFuture(expectedResponse2)); - ApiFuture consistentFuture = callable.futureCall(TABLE_NAME, CALL_CONTEXT); + ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(TABLE_ID); + ApiFuture consistentFuture = awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); consistentFuture.get(1, TimeUnit.MILLISECONDS); } @@ -190,6 +199,7 @@ public void testPolling() throws Exception { CheckConsistencyRequest.newBuilder() .setName(TABLE_NAME.toString()) .setConsistencyToken("fake-token") + .setStandardReadRemoteWrites(StandardReadRemoteWrites.newBuilder().build()) .build(); CheckConsistencyResponse expectedResponse2 = @@ -202,7 +212,8 @@ public void testPolling() throws Exception { .thenReturn(ApiFutures.immediateFuture(expectedResponse2)) .thenReturn(ApiFutures.immediateFuture(expectedResponse3)); - ApiFuture consistentFuture = callable.futureCall(TABLE_NAME, CALL_CONTEXT); + ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(TABLE_ID); + ApiFuture consistentFuture = awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); consistentFuture.get(1, TimeUnit.SECONDS); } @@ -222,6 +233,7 @@ public void testPollingTimeout() throws Exception { CheckConsistencyRequest.newBuilder() .setName(TABLE_NAME.toString()) .setConsistencyToken("fake-token") + .setStandardReadRemoteWrites(StandardReadRemoteWrites.newBuilder().build()) .build(); CheckConsistencyResponse expectedResponse2 = @@ -230,7 +242,8 @@ public void testPollingTimeout() throws Exception { Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)) .thenReturn(ApiFutures.immediateFuture(expectedResponse2)); - ApiFuture consistentFuture = callable.futureCall(TABLE_NAME, CALL_CONTEXT); + ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(TABLE_ID); + ApiFuture consistentFuture = awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); Throwable actualError = null; try { From 119ba2344c261c2d2687c65fc960bde23969ae5a Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 6 Sep 2024 18:32:45 -0400 Subject: [PATCH 16/26] Add a couple of tests for AwaitReplicationCallable Change-Id: I70014db2c0a1d4e74c23b18de7ef591bc70cda2a --- .../v2/stub/AwaitConsistencyCallableTest.java | 70 +++++++++++++++++-- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java index 2b4acae584..e10c21d3e5 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java @@ -35,7 +35,6 @@ import com.google.bigtable.admin.v2.TableName; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; - import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; import com.google.cloud.bigtable.data.v2.internal.RequestContext; import org.junit.Before; @@ -69,7 +68,7 @@ public class AwaitConsistencyCallableTest { private UnaryCallable mockCheckConsistencyCallable; - private AwaitReplicationCallable callable; + private AwaitReplicationCallable awaitReplicationCallable; private AwaitConsistencyCallable awaitConsistencyCallable; @@ -93,8 +92,7 @@ public void setUp() { awaitConsistencyCallable = AwaitConsistencyCallable.create(mockGenerateConsistencyTokenCallable, mockCheckConsistencyCallable, clientContext, retrySettings, REQUEST_CONTEXT); - callable = - AwaitReplicationCallable.create(awaitConsistencyCallable); + awaitReplicationCallable = AwaitReplicationCallable.create(awaitConsistencyCallable); } @Test @@ -106,7 +104,8 @@ public void testGenerateFailure() throws Exception { Mockito.when(mockGenerateConsistencyTokenCallable.futureCall(expectedRequest, CALL_CONTEXT)) .thenReturn(ApiFutures.immediateFailedFuture(fakeError)); - ApiFuture future = callable.futureCall(TABLE_NAME, CALL_CONTEXT); + ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(TABLE_ID); + ApiFuture future = awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); Throwable actualError = null; @@ -254,4 +253,65 @@ public void testPollingTimeout() throws Exception { assertThat(actualError).isInstanceOf(PollException.class); } + + @Test + public void testAwaitReplicationCallableImmediatelyConsistent() throws Exception { + GenerateConsistencyTokenRequest expectedRequest = + GenerateConsistencyTokenRequest.newBuilder().setName(TABLE_NAME.toString()).build(); + + GenerateConsistencyTokenResponse expectedResponse = + GenerateConsistencyTokenResponse.newBuilder().setConsistencyToken("fake-token").build(); + + Mockito.when(mockGenerateConsistencyTokenCallable.futureCall(expectedRequest, CALL_CONTEXT)) + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); + + CheckConsistencyRequest expectedRequest2 = + CheckConsistencyRequest.newBuilder() + .setName(TABLE_NAME.toString()) + .setConsistencyToken("fake-token") + .setStandardReadRemoteWrites(StandardReadRemoteWrites.newBuilder().build()) + .build(); + CheckConsistencyResponse expectedResponse2 = + CheckConsistencyResponse.newBuilder().setConsistent(true).build(); + + Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)) + .thenReturn(ApiFutures.immediateFuture(expectedResponse2)); + + ApiFuture consistentFuture = awaitReplicationCallable.futureCall(TABLE_NAME, CALL_CONTEXT); + + consistentFuture.get(1, TimeUnit.MILLISECONDS); + } + + @Test + public void testAwaitReplicationCallablePolling() throws Exception { + GenerateConsistencyTokenRequest expectedRequest = + GenerateConsistencyTokenRequest.newBuilder().setName(TABLE_NAME.toString()).build(); + + GenerateConsistencyTokenResponse expectedResponse = + GenerateConsistencyTokenResponse.newBuilder().setConsistencyToken("fake-token").build(); + + Mockito.when(mockGenerateConsistencyTokenCallable.futureCall(expectedRequest, CALL_CONTEXT)) + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); + + CheckConsistencyRequest expectedRequest2 = + CheckConsistencyRequest.newBuilder() + .setName(TABLE_NAME.toString()) + .setConsistencyToken("fake-token") + .setStandardReadRemoteWrites(StandardReadRemoteWrites.newBuilder().build()) + .build(); + + CheckConsistencyResponse expectedResponse2 = + CheckConsistencyResponse.newBuilder().setConsistent(false).build(); + + CheckConsistencyResponse expectedResponse3 = + CheckConsistencyResponse.newBuilder().setConsistent(true).build(); + + Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)) + .thenReturn(ApiFutures.immediateFuture(expectedResponse2)) + .thenReturn(ApiFutures.immediateFuture(expectedResponse3)); + + ApiFuture consistentFuture = awaitReplicationCallable.futureCall(TABLE_NAME, CALL_CONTEXT); + + consistentFuture.get(1, TimeUnit.SECONDS); + } } From c16491c42e0d5efd32ee7ae652b59f570ed644ba Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Mon, 9 Sep 2024 13:59:50 -0400 Subject: [PATCH 17/26] Use RequestContextNoAP class Change-Id: I897b343cd1067d43bcc644cac3db44e88bbf1e69 --- .../admin/v2/BigtableTableAdminClient.java | 3 +- .../admin/v2/models/ConsistencyRequest.java | 7 ++- .../v2/stub/AwaitConsistencyCallable.java | 9 ++-- .../stub/EnhancedBigtableTableAdminStub.java | 8 ++-- .../data/v2/internal/RequestContextNoAP.java | 46 +++++++++++++++++++ .../v2/models/ConsistencyRequestTest.java | 10 ++-- .../v2/stub/AwaitConsistencyCallableTest.java | 4 +- 7 files changed, 65 insertions(+), 22 deletions(-) create mode 100644 google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContextNoAP.java diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java index a955554673..3feeca8259 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java @@ -63,6 +63,7 @@ import com.google.cloud.bigtable.admin.v2.models.UpdateTableRequest; import com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub; import com.google.cloud.bigtable.data.v2.internal.RequestContext; +import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -156,7 +157,7 @@ public static BigtableTableAdminClient create( /** Constructs an instance of BigtableTableAdminClient with the given settings. */ public static BigtableTableAdminClient create(@Nonnull BigtableTableAdminSettings settings) throws IOException { - RequestContext requestContext = RequestContext.create(settings.getProjectId(), settings.getInstanceId(), "dummyAppProfileId"); + RequestContextNoAP requestContext = RequestContextNoAP.create(settings.getProjectId(), settings.getInstanceId()); EnhancedBigtableTableAdminStub stub = EnhancedBigtableTableAdminStub.createEnhanced(settings.getStubSettings(), requestContext); return create(settings.getProjectId(), settings.getInstanceId(), stub); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java index 7718cb01d1..2e8805e3da 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java @@ -2,9 +2,8 @@ import com.google.api.core.InternalApi; import com.google.bigtable.admin.v2.*; -import com.google.cloud.bigtable.data.v2.internal.RequestContext; +import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; import com.google.common.base.Preconditions; -import org.checkerframework.checker.units.qual.C; public class ConsistencyRequest { private final String tableId; @@ -27,7 +26,7 @@ public static ConsistencyRequest getDataBoostConsistencyRequest(String tableId) } @InternalApi - public CheckConsistencyRequest toCheckConsistencyProto(RequestContext requestContext, String token) { + public CheckConsistencyRequest toCheckConsistencyProto(RequestContextNoAP requestContext, String token) { CheckConsistencyRequest.Builder builder = CheckConsistencyRequest.newBuilder(); TableName tableName = TableName.of(requestContext.getProjectId(), requestContext.getInstanceId(), tableId); @@ -44,7 +43,7 @@ public CheckConsistencyRequest toCheckConsistencyProto(RequestContext requestCon } @InternalApi - public GenerateConsistencyTokenRequest toGenerateTokenProto(RequestContext requestContext) { + public GenerateConsistencyTokenRequest toGenerateTokenProto(RequestContextNoAP requestContext) { GenerateConsistencyTokenRequest.Builder builder = GenerateConsistencyTokenRequest.newBuilder(); TableName tableName = TableName.of(requestContext.getProjectId(), requestContext.getInstanceId(), tableId); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java index 7809afeae4..139efdf266 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java @@ -35,9 +35,8 @@ import com.google.bigtable.admin.v2.CheckConsistencyResponse; import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest; import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse; -import com.google.bigtable.admin.v2.TableName; import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; -import com.google.cloud.bigtable.data.v2.internal.RequestContext; +import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.MoreExecutors; import java.util.concurrent.Callable; @@ -55,7 +54,7 @@ class AwaitConsistencyCallable extends UnaryCallable { private final UnaryCallable checkCallable; private final RetryingExecutor executor; - private final RequestContext requestContext; + private final RequestContextNoAP requestContext; static AwaitConsistencyCallable create( UnaryCallable @@ -63,7 +62,7 @@ static AwaitConsistencyCallable create( UnaryCallable checkCallable, ClientContext clientContext, RetrySettings pollingSettings, - RequestContext requestContext) { + RequestContextNoAP requestContext) { RetryAlgorithm retryAlgorithm = new RetryAlgorithm<>( @@ -82,7 +81,7 @@ static AwaitConsistencyCallable create( generateCallable, UnaryCallable checkCallable, RetryingExecutor executor, - RequestContext requestContext) { + RequestContextNoAP requestContext) { this.generateCallable = generateCallable; this.checkCallable = checkCallable; this.executor = executor; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java index 1e7acebd41..ffe69de189 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java @@ -32,7 +32,7 @@ import com.google.bigtable.admin.v2.OptimizeRestoredTableMetadata; import com.google.bigtable.admin.v2.TableName; import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; -import com.google.cloud.bigtable.data.v2.internal.RequestContext; +import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; import com.google.longrunning.Operation; import com.google.protobuf.Empty; import io.grpc.MethodDescriptor; @@ -54,7 +54,7 @@ public class EnhancedBigtableTableAdminStub extends GrpcBigtableTableAdminStub { private final BigtableTableAdminStubSettings settings; private final ClientContext clientContext; - private final RequestContext requestContext; + private final RequestContextNoAP requestContext; private final AwaitReplicationCallable awaitReplicationCallable; @@ -63,12 +63,12 @@ public class EnhancedBigtableTableAdminStub extends GrpcBigtableTableAdminStub { optimizeRestoredTableOperationBaseCallable; public static EnhancedBigtableTableAdminStub createEnhanced( - BigtableTableAdminStubSettings settings, RequestContext requestContext) throws IOException { + BigtableTableAdminStubSettings settings, RequestContextNoAP requestContext) throws IOException { return new EnhancedBigtableTableAdminStub(settings, ClientContext.create(settings), requestContext); } private EnhancedBigtableTableAdminStub( - BigtableTableAdminStubSettings settings, ClientContext clientContext, RequestContext requestContext) throws IOException { + BigtableTableAdminStubSettings settings, ClientContext clientContext, RequestContextNoAP requestContext) throws IOException { super(settings, clientContext); this.settings = settings; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContextNoAP.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContextNoAP.java new file mode 100644 index 0000000000..f07c2298cb --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContextNoAP.java @@ -0,0 +1,46 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.data.v2.internal; + +import com.google.api.core.InternalApi; +import com.google.auto.value.AutoValue; +import java.io.Serializable; + +/** + * Contains information necessary to construct Bigtable protobuf requests from user facing models. + * + *

The intention is to extract repetitive details like instance names into a + * configurable values in {@link com.google.cloud.bigtable.data.v2.BigtableDataSettings} and expose + * them (via this class) to each wrapper's toProto method. + * + *

This class is considered an internal implementation detail and not meant to be used by + * applications. + */ +@InternalApi +@AutoValue +public abstract class RequestContextNoAP implements Serializable { + + /** Creates a new instance of the {@link RequestContextNoAP}. */ + public static RequestContextNoAP create(String projectId, String instanceId) { + return new AutoValue_RequestContextNoAP(projectId, instanceId); + } + + /** The project id that the client is configured to target. */ + public abstract String getProjectId(); + + /** The instance id that the client is configured to target. */ + public abstract String getInstanceId(); +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java index c7e98fc53a..170338c9d0 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java @@ -2,10 +2,8 @@ import com.google.bigtable.admin.v2.CheckConsistencyRequest; import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest; -import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse; -import com.google.cloud.bigtable.data.v2.internal.RequestContext; +import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; import org.junit.Test; -import org.junit.runner.Request; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -22,7 +20,7 @@ public class ConsistencyRequestTest { public void testToCheckConsistencyProtoWithStandard() { ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(TABLE_ID); - RequestContext requestContext = RequestContext.create(PROJECT_ID, INSTANCE_ID, TABLE_ID); + RequestContextNoAP requestContext = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); CheckConsistencyRequest checkConsistencyRequest = consistencyRequest.toCheckConsistencyProto(requestContext, CONSISTENCY_TOKEN); @@ -35,7 +33,7 @@ public void testToCheckConsistencyProtoWithStandard() { public void testToCheckConsistencyProtoWithDataBoost() { ConsistencyRequest consistencyRequest = ConsistencyRequest.getDataBoostConsistencyRequest(TABLE_ID); - RequestContext requestContext = RequestContext.create(PROJECT_ID, INSTANCE_ID, TABLE_ID); + RequestContextNoAP requestContext = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); CheckConsistencyRequest checkConsistencyRequest = consistencyRequest.toCheckConsistencyProto(requestContext, CONSISTENCY_TOKEN); @@ -48,7 +46,7 @@ public void testToCheckConsistencyProtoWithDataBoost() { public void testToGenerateTokenProto() { ConsistencyRequest consistencyRequest = ConsistencyRequest.getDataBoostConsistencyRequest(TABLE_ID); - RequestContext requestContext = RequestContext.create(PROJECT_ID, INSTANCE_ID, TABLE_ID); + RequestContextNoAP requestContext = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); GenerateConsistencyTokenRequest generateRequest = consistencyRequest.toGenerateTokenProto(requestContext); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java index e10c21d3e5..c86eeaed1e 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java @@ -36,7 +36,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; -import com.google.cloud.bigtable.data.v2.internal.RequestContext; +import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -58,7 +58,7 @@ public class AwaitConsistencyCallableTest { private static final String TABLE_ID = "my-table"; private static final TableName TABLE_NAME = TableName.of(PROJECT_ID, INSTANCE_ID, TABLE_ID); private static final ApiCallContext CALL_CONTEXT = FakeCallContext.createDefault(); - private static final RequestContext REQUEST_CONTEXT = RequestContext.create(PROJECT_ID, INSTANCE_ID, "dummyAppProfile"); + private static final RequestContextNoAP REQUEST_CONTEXT = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); @Mock private UnaryCallable From 09a230f3a108d658f2333083d36a91b801027d7b Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Mon, 9 Sep 2024 14:13:49 -0400 Subject: [PATCH 18/26] Make ConsistencyRequest model an AutoValue Change-Id: I9529fb79da69e12a834a2d0fea032d72ae6ea157 --- .../admin/v2/BigtableTableAdminClient.java | 1 - .../admin/v2/models/ConsistencyRequest.java | 33 +++++++++---------- .../v2/stub/AwaitReplicationCallable.java | 2 +- .../v2/BigtableTableAdminClientTests.java | 2 +- .../v2/it/BigtableTableAdminClientIT.java | 2 +- .../v2/models/ConsistencyRequestTest.java | 6 ++-- .../v2/stub/AwaitConsistencyCallableTest.java | 10 +++--- 7 files changed, 26 insertions(+), 30 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java index 3feeca8259..22743f7c33 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java @@ -62,7 +62,6 @@ import com.google.cloud.bigtable.admin.v2.models.UpdateBackupRequest; import com.google.cloud.bigtable.admin.v2.models.UpdateTableRequest; import com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub; -import com.google.cloud.bigtable.data.v2.internal.RequestContext; import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java index 2e8805e3da..911673f148 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java @@ -1,36 +1,33 @@ package com.google.cloud.bigtable.admin.v2.models; import com.google.api.core.InternalApi; +import com.google.auto.value.AutoValue; import com.google.bigtable.admin.v2.*; import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; -import com.google.common.base.Preconditions; -public class ConsistencyRequest { - private final String tableId; +import javax.annotation.Nonnull; - private final CheckConsistencyRequest.ModeCase consistencyMode; +@AutoValue +public abstract class ConsistencyRequest { + @Nonnull + protected abstract String getTableId(); + @Nonnull + protected abstract CheckConsistencyRequest.ModeCase getMode(); - ConsistencyRequest(String tableId, CheckConsistencyRequest.ModeCase consistencyMode) { - Preconditions.checkNotNull(tableId); - Preconditions.checkNotNull(consistencyMode); - this.tableId = tableId; - this.consistencyMode = consistencyMode; + public static ConsistencyRequest forReplication(String tableId) { + return new AutoValue_ConsistencyRequest(tableId, CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES); } - public static ConsistencyRequest getStandardConsistencyRequest(String tableId) { - return new ConsistencyRequest(tableId, CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES); - } - - public static ConsistencyRequest getDataBoostConsistencyRequest(String tableId) { - return new ConsistencyRequest(tableId, CheckConsistencyRequest.ModeCase.DATA_BOOST_READ_LOCAL_WRITES); + public static ConsistencyRequest forDataBoost(String tableId) { + return new AutoValue_ConsistencyRequest(tableId, CheckConsistencyRequest.ModeCase.DATA_BOOST_READ_LOCAL_WRITES); } @InternalApi public CheckConsistencyRequest toCheckConsistencyProto(RequestContextNoAP requestContext, String token) { CheckConsistencyRequest.Builder builder = CheckConsistencyRequest.newBuilder(); - TableName tableName = TableName.of(requestContext.getProjectId(), requestContext.getInstanceId(), tableId); + TableName tableName = TableName.of(requestContext.getProjectId(), requestContext.getInstanceId(), getTableId()); - if (consistencyMode.equals(CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES)) { + if (getMode().equals(CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES)) { builder.setStandardReadRemoteWrites(StandardReadRemoteWrites.newBuilder().build()); } else { builder.setDataBoostReadLocalWrites(DataBoostReadLocalWrites.newBuilder().build()); @@ -46,7 +43,7 @@ public CheckConsistencyRequest toCheckConsistencyProto(RequestContextNoAP reques public GenerateConsistencyTokenRequest toGenerateTokenProto(RequestContextNoAP requestContext) { GenerateConsistencyTokenRequest.Builder builder = GenerateConsistencyTokenRequest.newBuilder(); - TableName tableName = TableName.of(requestContext.getProjectId(), requestContext.getInstanceId(), tableId); + TableName tableName = TableName.of(requestContext.getProjectId(), requestContext.getInstanceId(), getTableId()); return builder .setName(tableName.toString()) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java index d2b0e75715..cf00190013 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java @@ -41,7 +41,7 @@ static AwaitReplicationCallable create(AwaitConsistencyCallable awaitConsistency @Override public ApiFuture futureCall(final TableName tableName, final ApiCallContext context) { - ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(tableName.getTable()); + ConsistencyRequest consistencyRequest = ConsistencyRequest.forReplication(tableName.getTable()); return awaitConsistencyCallable.futureCall(consistencyRequest, context); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java index 7e0b6a4104..c6de1edb5f 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java @@ -574,7 +574,7 @@ public void testAwaitConsistencyForDataBoost() { // Setup Mockito.when(mockStub.awaitConsistencyCallable()).thenReturn(mockAwaitConsistencyCallable); - ConsistencyRequest consistencyRequest = ConsistencyRequest.getDataBoostConsistencyRequest(TABLE_ID); + ConsistencyRequest consistencyRequest = ConsistencyRequest.forDataBoost(TABLE_ID); final AtomicBoolean wasCalled = new AtomicBoolean(false); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java index 2ef33086dd..6518d74258 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java @@ -239,7 +239,7 @@ public void awaitDataBoostConsistency() { .that(testEnvRule.env()) .isNotInstanceOf(EmulatorEnv.class); tableAdmin.createTable(CreateTableRequest.of(tableId)); - ConsistencyRequest consistencyRequest = ConsistencyRequest.getDataBoostConsistencyRequest(tableId); + ConsistencyRequest consistencyRequest = ConsistencyRequest.forDataBoost(tableId); tableAdmin.awaitConsistency(consistencyRequest); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java index 170338c9d0..4eca56415e 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java @@ -18,7 +18,7 @@ public class ConsistencyRequestTest { @Test public void testToCheckConsistencyProtoWithStandard() { - ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(TABLE_ID); + ConsistencyRequest consistencyRequest = ConsistencyRequest.forReplication(TABLE_ID); RequestContextNoAP requestContext = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); @@ -31,7 +31,7 @@ public void testToCheckConsistencyProtoWithStandard() { @Test public void testToCheckConsistencyProtoWithDataBoost() { - ConsistencyRequest consistencyRequest = ConsistencyRequest.getDataBoostConsistencyRequest(TABLE_ID); + ConsistencyRequest consistencyRequest = ConsistencyRequest.forDataBoost(TABLE_ID); RequestContextNoAP requestContext = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); @@ -44,7 +44,7 @@ public void testToCheckConsistencyProtoWithDataBoost() { @Test public void testToGenerateTokenProto() { - ConsistencyRequest consistencyRequest = ConsistencyRequest.getDataBoostConsistencyRequest(TABLE_ID); + ConsistencyRequest consistencyRequest = ConsistencyRequest.forDataBoost(TABLE_ID); RequestContextNoAP requestContext = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java index c86eeaed1e..0217773710 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java @@ -104,7 +104,7 @@ public void testGenerateFailure() throws Exception { Mockito.when(mockGenerateConsistencyTokenCallable.futureCall(expectedRequest, CALL_CONTEXT)) .thenReturn(ApiFutures.immediateFailedFuture(fakeError)); - ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(TABLE_ID); + ConsistencyRequest consistencyRequest = ConsistencyRequest.forReplication(TABLE_ID); ApiFuture future = awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); Throwable actualError = null; @@ -140,7 +140,7 @@ public void testCheckFailure() throws Exception { Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)) .thenReturn(ApiFutures.immediateFailedFuture(expectedError)); - ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(TABLE_ID); + ConsistencyRequest consistencyRequest = ConsistencyRequest.forReplication(TABLE_ID); ApiFuture future = awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); Throwable actualError = null; @@ -177,7 +177,7 @@ public void testImmediatelyConsistent() throws Exception { Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)) .thenReturn(ApiFutures.immediateFuture(expectedResponse2)); - ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(TABLE_ID); + ConsistencyRequest consistencyRequest = ConsistencyRequest.forReplication(TABLE_ID); ApiFuture consistentFuture = awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); consistentFuture.get(1, TimeUnit.MILLISECONDS); @@ -211,7 +211,7 @@ public void testPolling() throws Exception { .thenReturn(ApiFutures.immediateFuture(expectedResponse2)) .thenReturn(ApiFutures.immediateFuture(expectedResponse3)); - ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(TABLE_ID); + ConsistencyRequest consistencyRequest = ConsistencyRequest.forReplication(TABLE_ID); ApiFuture consistentFuture = awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); consistentFuture.get(1, TimeUnit.SECONDS); @@ -241,7 +241,7 @@ public void testPollingTimeout() throws Exception { Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)) .thenReturn(ApiFutures.immediateFuture(expectedResponse2)); - ConsistencyRequest consistencyRequest = ConsistencyRequest.getStandardConsistencyRequest(TABLE_ID); + ConsistencyRequest consistencyRequest = ConsistencyRequest.forReplication(TABLE_ID); ApiFuture consistentFuture = awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); Throwable actualError = null; From 4aa93f29b98a20a33cedf4e5a11cd648e64265a7 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Mon, 9 Sep 2024 14:19:27 -0400 Subject: [PATCH 19/26] Fix license year, fix some formatting Change-Id: Ibcca1ca9f49988764fdbeeacc59cac5d276ab266 --- .../admin/v2/models/ConsistencyRequest.java | 21 +++++++- .../v2/stub/AwaitConsistencyCallable.java | 2 +- .../stub/EnhancedBigtableTableAdminStub.java | 52 +++++++++---------- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java index 911673f148..7056d2fd58 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java @@ -1,8 +1,27 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.google.cloud.bigtable.admin.v2.models; import com.google.api.core.InternalApi; import com.google.auto.value.AutoValue; -import com.google.bigtable.admin.v2.*; +import com.google.bigtable.admin.v2.CheckConsistencyRequest; +import com.google.bigtable.admin.v2.DataBoostReadLocalWrites; +import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest; +import com.google.bigtable.admin.v2.StandardReadRemoteWrites; +import com.google.bigtable.admin.v2.TableName; import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; import javax.annotation.Nonnull; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java index 139efdf266..7a82769488 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java index ffe69de189..49d76bfedb 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java @@ -84,29 +84,29 @@ private AwaitReplicationCallable createAwaitReplicationCallable() { return AwaitReplicationCallable.create(awaitConsistencyCallable); } - private AwaitConsistencyCallable createAwaitConsistencyCallable() { - // TODO(igorbernstein2): expose polling settings - RetrySettings pollingSettings = - RetrySettings.newBuilder() - // use overall timeout from checkConsistencyCallable - // NOTE: The overall timeout might exceed this value due to underlying retries - .setTotalTimeout( - settings.checkConsistencySettings().getRetrySettings().getTotalTimeout()) - // Use constant polling with jitter - .setInitialRetryDelay(Duration.ofSeconds(10)) - .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(Duration.ofSeconds(10)) - .setJittered(true) - // These rpc timeouts are ignored, instead the rpc timeouts defined for - // generateConsistencyToken and checkConsistency callables will be used. - .setInitialRpcTimeout(Duration.ZERO) - .setMaxRpcTimeout(Duration.ZERO) - .setRpcTimeoutMultiplier(1.0) - .build(); - - return AwaitConsistencyCallable.create( - generateConsistencyTokenCallable(), checkConsistencyCallable(), clientContext, pollingSettings, requestContext); - } + private AwaitConsistencyCallable createAwaitConsistencyCallable() { + // TODO(igorbernstein2): expose polling settings + RetrySettings pollingSettings = + RetrySettings.newBuilder() + // use overall timeout from checkConsistencyCallable + // NOTE: The overall timeout might exceed this value due to underlying retries + .setTotalTimeout( + settings.checkConsistencySettings().getRetrySettings().getTotalTimeout()) + // Use constant polling with jitter + .setInitialRetryDelay(Duration.ofSeconds(10)) + .setRetryDelayMultiplier(1.0) + .setMaxRetryDelay(Duration.ofSeconds(10)) + .setJittered(true) + // These rpc timeouts are ignored, instead the rpc timeouts defined for + // generateConsistencyToken and checkConsistency callables will be used. + .setInitialRpcTimeout(Duration.ZERO) + .setMaxRpcTimeout(Duration.ZERO) + .setRpcTimeoutMultiplier(1.0) + .build(); + + return AwaitConsistencyCallable.create( + generateConsistencyTokenCallable(), checkConsistencyCallable(), clientContext, pollingSettings, requestContext); + } // Plug into gax operation infrastructure @@ -204,9 +204,9 @@ public UnaryCallable awaitReplicationCallable() { return awaitReplicationCallable; } - public UnaryCallable awaitConsistencyCallable() { - return awaitConsistencyCallable; - } + public UnaryCallable awaitConsistencyCallable() { + return awaitConsistencyCallable; + } public OperationCallable awaitOptimizeRestoredTableCallable() { From 1da2dc7c881af1a4a7e15a4617030031f3de94b9 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Mon, 9 Sep 2024 14:31:55 -0400 Subject: [PATCH 20/26] Run auto formatter Change-Id: I9f5e3f7c7fd79262092c507a523e16a533bc4382 --- .../admin/v2/BigtableTableAdminClient.java | 5 +- .../admin/v2/models/ConsistencyRequest.java | 65 +++-- .../v2/stub/AwaitConsistencyCallable.java | 262 +++++++++--------- .../v2/stub/AwaitReplicationCallable.java | 1 - .../stub/EnhancedBigtableTableAdminStub.java | 60 ++-- .../data/v2/internal/RequestContextNoAP.java | 22 +- .../v2/BigtableTableAdminClientTests.java | 12 +- .../v2/it/BigtableTableAdminClientIT.java | 10 +- .../v2/models/ConsistencyRequestTest.java | 71 ++--- .../v2/stub/AwaitConsistencyCallableTest.java | 75 ++--- 10 files changed, 308 insertions(+), 275 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java index 22743f7c33..110783f6c3 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java @@ -156,7 +156,8 @@ public static BigtableTableAdminClient create( /** Constructs an instance of BigtableTableAdminClient with the given settings. */ public static BigtableTableAdminClient create(@Nonnull BigtableTableAdminSettings settings) throws IOException { - RequestContextNoAP requestContext = RequestContextNoAP.create(settings.getProjectId(), settings.getInstanceId()); + RequestContextNoAP requestContext = + RequestContextNoAP.create(settings.getProjectId(), settings.getInstanceId()); EnhancedBigtableTableAdminStub stub = EnhancedBigtableTableAdminStub.createEnhanced(settings.getStubSettings(), requestContext); return create(settings.getProjectId(), settings.getInstanceId(), stub); @@ -922,7 +923,7 @@ public void awaitReplication(String tableId) { public void awaitConsistency(ConsistencyRequest consistencyRequest) { ApiExceptions.callAndTranslateApiException( - stub.awaitConsistencyCallable().futureCall(consistencyRequest)); + stub.awaitConsistencyCallable().futureCall(consistencyRequest)); } /** diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java index 7056d2fd58..f58e72186f 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java @@ -23,49 +23,48 @@ import com.google.bigtable.admin.v2.StandardReadRemoteWrites; import com.google.bigtable.admin.v2.TableName; import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; - import javax.annotation.Nonnull; @AutoValue public abstract class ConsistencyRequest { - @Nonnull - protected abstract String getTableId(); - @Nonnull - protected abstract CheckConsistencyRequest.ModeCase getMode(); + @Nonnull + protected abstract String getTableId(); - public static ConsistencyRequest forReplication(String tableId) { - return new AutoValue_ConsistencyRequest(tableId, CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES); - } + @Nonnull + protected abstract CheckConsistencyRequest.ModeCase getMode(); - public static ConsistencyRequest forDataBoost(String tableId) { - return new AutoValue_ConsistencyRequest(tableId, CheckConsistencyRequest.ModeCase.DATA_BOOST_READ_LOCAL_WRITES); - } + public static ConsistencyRequest forReplication(String tableId) { + return new AutoValue_ConsistencyRequest( + tableId, CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES); + } - @InternalApi - public CheckConsistencyRequest toCheckConsistencyProto(RequestContextNoAP requestContext, String token) { - CheckConsistencyRequest.Builder builder = CheckConsistencyRequest.newBuilder(); - TableName tableName = TableName.of(requestContext.getProjectId(), requestContext.getInstanceId(), getTableId()); + public static ConsistencyRequest forDataBoost(String tableId) { + return new AutoValue_ConsistencyRequest( + tableId, CheckConsistencyRequest.ModeCase.DATA_BOOST_READ_LOCAL_WRITES); + } - if (getMode().equals(CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES)) { - builder.setStandardReadRemoteWrites(StandardReadRemoteWrites.newBuilder().build()); - } else { - builder.setDataBoostReadLocalWrites(DataBoostReadLocalWrites.newBuilder().build()); - } + @InternalApi + public CheckConsistencyRequest toCheckConsistencyProto( + RequestContextNoAP requestContext, String token) { + CheckConsistencyRequest.Builder builder = CheckConsistencyRequest.newBuilder(); + TableName tableName = + TableName.of(requestContext.getProjectId(), requestContext.getInstanceId(), getTableId()); - return builder - .setName(tableName.toString()) - .setConsistencyToken(token) - .build(); + if (getMode().equals(CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES)) { + builder.setStandardReadRemoteWrites(StandardReadRemoteWrites.newBuilder().build()); + } else { + builder.setDataBoostReadLocalWrites(DataBoostReadLocalWrites.newBuilder().build()); } - @InternalApi - public GenerateConsistencyTokenRequest toGenerateTokenProto(RequestContextNoAP requestContext) { - GenerateConsistencyTokenRequest.Builder builder = - GenerateConsistencyTokenRequest.newBuilder(); - TableName tableName = TableName.of(requestContext.getProjectId(), requestContext.getInstanceId(), getTableId()); + return builder.setName(tableName.toString()).setConsistencyToken(token).build(); + } - return builder - .setName(tableName.toString()) - .build(); - } + @InternalApi + public GenerateConsistencyTokenRequest toGenerateTokenProto(RequestContextNoAP requestContext) { + GenerateConsistencyTokenRequest.Builder builder = GenerateConsistencyTokenRequest.newBuilder(); + TableName tableName = + TableName.of(requestContext.getProjectId(), requestContext.getInstanceId(), getTableId()); + + return builder.setName(tableName.toString()).build(); + } } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java index 7a82769488..bae6e32b9c 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java @@ -43,147 +43,153 @@ import java.util.concurrent.CancellationException; /** - * Callable that waits until either replication or Data Boost has caught up to the point it was called. + * Callable that waits until either replication or Data Boost has caught up to the point it was + * called. * *

This callable wraps GenerateConsistencyToken and CheckConsistency RPCs. It will generate a * token then poll until isConsistent is true. */ class AwaitConsistencyCallable extends UnaryCallable { - private final UnaryCallable - generateCallable; - private final UnaryCallable checkCallable; - private final RetryingExecutor executor; - - private final RequestContextNoAP requestContext; - - static AwaitConsistencyCallable create( - UnaryCallable - generateCallable, - UnaryCallable checkCallable, - ClientContext clientContext, - RetrySettings pollingSettings, - RequestContextNoAP requestContext) { - - RetryAlgorithm retryAlgorithm = - new RetryAlgorithm<>( - new PollResultAlgorithm(), - new ExponentialPollAlgorithm(pollingSettings, clientContext.getClock())); - - RetryingExecutor retryingExecutor = - new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); - - return new AwaitConsistencyCallable(generateCallable, checkCallable, retryingExecutor, requestContext); + private final UnaryCallable + generateCallable; + private final UnaryCallable checkCallable; + private final RetryingExecutor executor; + + private final RequestContextNoAP requestContext; + + static AwaitConsistencyCallable create( + UnaryCallable + generateCallable, + UnaryCallable checkCallable, + ClientContext clientContext, + RetrySettings pollingSettings, + RequestContextNoAP requestContext) { + + RetryAlgorithm retryAlgorithm = + new RetryAlgorithm<>( + new PollResultAlgorithm(), + new ExponentialPollAlgorithm(pollingSettings, clientContext.getClock())); + + RetryingExecutor retryingExecutor = + new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); + + return new AwaitConsistencyCallable( + generateCallable, checkCallable, retryingExecutor, requestContext); + } + + @VisibleForTesting + AwaitConsistencyCallable( + UnaryCallable + generateCallable, + UnaryCallable checkCallable, + RetryingExecutor executor, + RequestContextNoAP requestContext) { + this.generateCallable = generateCallable; + this.checkCallable = checkCallable; + this.executor = executor; + this.requestContext = requestContext; + } + + @Override + public ApiFuture futureCall( + final ConsistencyRequest consistencyRequest, final ApiCallContext apiCallContext) { + ApiFuture tokenFuture = + generateToken(consistencyRequest.toGenerateTokenProto(requestContext), apiCallContext); + + return ApiFutures.transformAsync( + tokenFuture, + new ApiAsyncFunction() { + @Override + public ApiFuture apply(GenerateConsistencyTokenResponse input) { + CheckConsistencyRequest request = + consistencyRequest.toCheckConsistencyProto( + requestContext, input.getConsistencyToken()); + return pollToken(request, apiCallContext); + } + }, + MoreExecutors.directExecutor()); + } + + private ApiFuture generateToken( + GenerateConsistencyTokenRequest generateRequest, ApiCallContext context) { + return generateCallable.futureCall(generateRequest, context); + } + + private ApiFuture pollToken(CheckConsistencyRequest request, ApiCallContext context) { + AttemptCallable attemptCallable = + new AttemptCallable<>(checkCallable, request, context); + RetryingFuture retryingFuture = + executor.createFuture(attemptCallable); + attemptCallable.setExternalFuture(retryingFuture); + attemptCallable.call(); + + return ApiFutures.transform( + retryingFuture, + new ApiFunction() { + @Override + public Void apply(CheckConsistencyResponse input) { + return null; + } + }, + MoreExecutors.directExecutor()); + } + + /** A callable representing an attempt to make an RPC call. */ + private static class AttemptCallable implements Callable { + private final UnaryCallable callable; + private final RequestT request; + + private volatile RetryingFuture externalFuture; + private volatile ApiCallContext callContext; + + AttemptCallable( + UnaryCallable callable, RequestT request, ApiCallContext callContext) { + this.callable = callable; + this.request = request; + this.callContext = callContext; } - @VisibleForTesting - AwaitConsistencyCallable( - UnaryCallable - generateCallable, - UnaryCallable checkCallable, - RetryingExecutor executor, - RequestContextNoAP requestContext) { - this.generateCallable = generateCallable; - this.checkCallable = checkCallable; - this.executor = executor; - this.requestContext = requestContext; + void setExternalFuture(RetryingFuture externalFuture) { + this.externalFuture = externalFuture; } @Override - public ApiFuture futureCall(final ConsistencyRequest consistencyRequest, final ApiCallContext apiCallContext) { - ApiFuture tokenFuture = generateToken(consistencyRequest.toGenerateTokenProto(requestContext), apiCallContext); - - return ApiFutures.transformAsync( - tokenFuture, - new ApiAsyncFunction() { - @Override - public ApiFuture apply(GenerateConsistencyTokenResponse input) { - CheckConsistencyRequest request = consistencyRequest.toCheckConsistencyProto(requestContext, input.getConsistencyToken()); - return pollToken(request, apiCallContext); - } - }, - MoreExecutors.directExecutor()); - } - - private ApiFuture generateToken( - GenerateConsistencyTokenRequest generateRequest, ApiCallContext context) { - return generateCallable.futureCall(generateRequest, context); - } - - private ApiFuture pollToken(CheckConsistencyRequest request, ApiCallContext context) { - AttemptCallable attemptCallable = - new AttemptCallable<>(checkCallable, request, context); - RetryingFuture retryingFuture = - executor.createFuture(attemptCallable); - attemptCallable.setExternalFuture(retryingFuture); - attemptCallable.call(); - - return ApiFutures.transform( - retryingFuture, - new ApiFunction() { - @Override - public Void apply(CheckConsistencyResponse input) { - return null; - } - }, - MoreExecutors.directExecutor()); - } - - /** A callable representing an attempt to make an RPC call. */ - private static class AttemptCallable implements Callable { - private final UnaryCallable callable; - private final RequestT request; - - private volatile RetryingFuture externalFuture; - private volatile ApiCallContext callContext; - - AttemptCallable( - UnaryCallable callable, RequestT request, ApiCallContext callContext) { - this.callable = callable; - this.request = request; - this.callContext = callContext; - } - - void setExternalFuture(RetryingFuture externalFuture) { - this.externalFuture = externalFuture; + public ResponseT call() { + try { + // NOTE: unlike gax's AttemptCallable, this ignores rpc timeouts + externalFuture.setAttemptFuture(new NonCancellableFuture()); + if (externalFuture.isDone()) { + return null; } + ApiFuture internalFuture = callable.futureCall(request, callContext); + externalFuture.setAttemptFuture(internalFuture); + } catch (Throwable e) { + externalFuture.setAttemptFuture(ApiFutures.immediateFailedFuture(e)); + } - @Override - public ResponseT call() { - try { - // NOTE: unlike gax's AttemptCallable, this ignores rpc timeouts - externalFuture.setAttemptFuture(new NonCancellableFuture()); - if (externalFuture.isDone()) { - return null; - } - ApiFuture internalFuture = callable.futureCall(request, callContext); - externalFuture.setAttemptFuture(internalFuture); - } catch (Throwable e) { - externalFuture.setAttemptFuture(ApiFutures.immediateFailedFuture(e)); - } - - return null; - } + return null; + } + } + + /** + * A polling algorithm for waiting for a consistent {@link CheckConsistencyResponse}. Please note + * that this class doesn't handle retryable errors and expects the underlying callable chain to + * handle this. + */ + private static class PollResultAlgorithm + implements ResultRetryAlgorithm { + @Override + public TimedAttemptSettings createNextAttempt( + Throwable prevThrowable, + CheckConsistencyResponse prevResponse, + TimedAttemptSettings prevSettings) { + return null; } - /** - * A polling algorithm for waiting for a consistent {@link CheckConsistencyResponse}. Please note - * that this class doesn't handle retryable errors and expects the underlying callable chain to - * handle this. - */ - private static class PollResultAlgorithm - implements ResultRetryAlgorithm { - @Override - public TimedAttemptSettings createNextAttempt( - Throwable prevThrowable, - CheckConsistencyResponse prevResponse, - TimedAttemptSettings prevSettings) { - return null; - } - - @Override - public boolean shouldRetry(Throwable prevThrowable, CheckConsistencyResponse prevResponse) - throws CancellationException { - return prevResponse != null && !prevResponse.getConsistent(); - } + @Override + public boolean shouldRetry(Throwable prevThrowable, CheckConsistencyResponse prevResponse) + throws CancellationException { + return prevResponse != null && !prevResponse.getConsistent(); } + } } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java index cf00190013..2cb8549f5d 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallable.java @@ -18,7 +18,6 @@ import com.google.api.core.ApiFuture; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.UnaryCallable; -import com.google.bigtable.admin.v2.CheckConsistencyRequest; import com.google.bigtable.admin.v2.TableName; import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; import com.google.common.annotations.VisibleForTesting; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java index 49d76bfedb..be6f984cd6 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java @@ -63,12 +63,17 @@ public class EnhancedBigtableTableAdminStub extends GrpcBigtableTableAdminStub { optimizeRestoredTableOperationBaseCallable; public static EnhancedBigtableTableAdminStub createEnhanced( - BigtableTableAdminStubSettings settings, RequestContextNoAP requestContext) throws IOException { - return new EnhancedBigtableTableAdminStub(settings, ClientContext.create(settings), requestContext); + BigtableTableAdminStubSettings settings, RequestContextNoAP requestContext) + throws IOException { + return new EnhancedBigtableTableAdminStub( + settings, ClientContext.create(settings), requestContext); } private EnhancedBigtableTableAdminStub( - BigtableTableAdminStubSettings settings, ClientContext clientContext, RequestContextNoAP requestContext) throws IOException { + BigtableTableAdminStubSettings settings, + ClientContext clientContext, + RequestContextNoAP requestContext) + throws IOException { super(settings, clientContext); this.settings = settings; @@ -85,29 +90,32 @@ private AwaitReplicationCallable createAwaitReplicationCallable() { } private AwaitConsistencyCallable createAwaitConsistencyCallable() { - // TODO(igorbernstein2): expose polling settings - RetrySettings pollingSettings = - RetrySettings.newBuilder() - // use overall timeout from checkConsistencyCallable - // NOTE: The overall timeout might exceed this value due to underlying retries - .setTotalTimeout( - settings.checkConsistencySettings().getRetrySettings().getTotalTimeout()) - // Use constant polling with jitter - .setInitialRetryDelay(Duration.ofSeconds(10)) - .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(Duration.ofSeconds(10)) - .setJittered(true) - // These rpc timeouts are ignored, instead the rpc timeouts defined for - // generateConsistencyToken and checkConsistency callables will be used. - .setInitialRpcTimeout(Duration.ZERO) - .setMaxRpcTimeout(Duration.ZERO) - .setRpcTimeoutMultiplier(1.0) - .build(); - - return AwaitConsistencyCallable.create( - generateConsistencyTokenCallable(), checkConsistencyCallable(), clientContext, pollingSettings, requestContext); - } + // TODO(igorbernstein2): expose polling settings + RetrySettings pollingSettings = + RetrySettings.newBuilder() + // use overall timeout from checkConsistencyCallable + // NOTE: The overall timeout might exceed this value due to underlying retries + .setTotalTimeout( + settings.checkConsistencySettings().getRetrySettings().getTotalTimeout()) + // Use constant polling with jitter + .setInitialRetryDelay(Duration.ofSeconds(10)) + .setRetryDelayMultiplier(1.0) + .setMaxRetryDelay(Duration.ofSeconds(10)) + .setJittered(true) + // These rpc timeouts are ignored, instead the rpc timeouts defined for + // generateConsistencyToken and checkConsistency callables will be used. + .setInitialRpcTimeout(Duration.ZERO) + .setMaxRpcTimeout(Duration.ZERO) + .setRpcTimeoutMultiplier(1.0) + .build(); + return AwaitConsistencyCallable.create( + generateConsistencyTokenCallable(), + checkConsistencyCallable(), + clientContext, + pollingSettings, + requestContext); + } // Plug into gax operation infrastructure // gax assumes that all operations are started immediately and doesn't provide support for child @@ -205,7 +213,7 @@ public UnaryCallable awaitReplicationCallable() { } public UnaryCallable awaitConsistencyCallable() { - return awaitConsistencyCallable; + return awaitConsistencyCallable; } public OperationCallable diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContextNoAP.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContextNoAP.java index f07c2298cb..5b076d01e5 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContextNoAP.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContextNoAP.java @@ -22,9 +22,9 @@ /** * Contains information necessary to construct Bigtable protobuf requests from user facing models. * - *

The intention is to extract repetitive details like instance names into a - * configurable values in {@link com.google.cloud.bigtable.data.v2.BigtableDataSettings} and expose - * them (via this class) to each wrapper's toProto method. + *

The intention is to extract repetitive details like instance names into a configurable values + * in {@link com.google.cloud.bigtable.data.v2.BigtableDataSettings} and expose them (via this + * class) to each wrapper's toProto method. * *

This class is considered an internal implementation detail and not meant to be used by * applications. @@ -33,14 +33,14 @@ @AutoValue public abstract class RequestContextNoAP implements Serializable { - /** Creates a new instance of the {@link RequestContextNoAP}. */ - public static RequestContextNoAP create(String projectId, String instanceId) { - return new AutoValue_RequestContextNoAP(projectId, instanceId); - } + /** Creates a new instance of the {@link RequestContextNoAP}. */ + public static RequestContextNoAP create(String projectId, String instanceId) { + return new AutoValue_RequestContextNoAP(projectId, instanceId); + } - /** The project id that the client is configured to target. */ - public abstract String getProjectId(); + /** The project id that the client is configured to target. */ + public abstract String getProjectId(); - /** The instance id that the client is configured to target. */ - public abstract String getInstanceId(); + /** The instance id that the client is configured to target. */ + public abstract String getInstanceId(); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java index c6de1edb5f..6cb830b11a 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java @@ -579,12 +579,12 @@ public void testAwaitConsistencyForDataBoost() { final AtomicBoolean wasCalled = new AtomicBoolean(false); Mockito.when(mockAwaitConsistencyCallable.futureCall(consistencyRequest)) - .thenAnswer( - (Answer>) - invocationOnMock -> { - wasCalled.set(true); - return ApiFutures.immediateFuture(null); - }); + .thenAnswer( + (Answer>) + invocationOnMock -> { + wasCalled.set(true); + return ApiFutures.immediateFuture(null); + }); // Execute adminClient.awaitConsistency(consistencyRequest); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java index 6518d74258..c301f5d41a 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java @@ -229,15 +229,15 @@ public void awaitReplication() { } /** - * Note: Data Boost consistency is essentially a check that the data you are trying to read was written - * at least 35 minutes ago. + * Note: Data Boost consistency is essentially a check that the data you are trying to read was + * written at least 35 minutes ago. */ @Test public void awaitDataBoostConsistency() { assume() - .withMessage("Data Boost consistency not supported on Emulator") - .that(testEnvRule.env()) - .isNotInstanceOf(EmulatorEnv.class); + .withMessage("Data Boost consistency not supported on Emulator") + .that(testEnvRule.env()) + .isNotInstanceOf(EmulatorEnv.class); tableAdmin.createTable(CreateTableRequest.of(tableId)); ConsistencyRequest consistencyRequest = ConsistencyRequest.forDataBoost(tableId); tableAdmin.awaitConsistency(consistencyRequest); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java index 4eca56415e..da79bf8ff0 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java @@ -1,5 +1,7 @@ package com.google.cloud.bigtable.admin.v2.models; +import static com.google.common.truth.Truth.assertThat; + import com.google.bigtable.admin.v2.CheckConsistencyRequest; import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest; import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; @@ -7,49 +9,56 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import static com.google.common.truth.Truth.assertThat; - @RunWith(JUnit4.class) public class ConsistencyRequestTest { - private final String PROJECT_ID = "my-project"; - private final String INSTANCE_ID = "my-instance"; - private final String TABLE_ID = "my-table"; - private final String CONSISTENCY_TOKEN = "my-token"; + private final String PROJECT_ID = "my-project"; + private final String INSTANCE_ID = "my-instance"; + private final String TABLE_ID = "my-table"; + private final String CONSISTENCY_TOKEN = "my-token"; - @Test - public void testToCheckConsistencyProtoWithStandard() { - ConsistencyRequest consistencyRequest = ConsistencyRequest.forReplication(TABLE_ID); + @Test + public void testToCheckConsistencyProtoWithStandard() { + ConsistencyRequest consistencyRequest = ConsistencyRequest.forReplication(TABLE_ID); - RequestContextNoAP requestContext = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); + RequestContextNoAP requestContext = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); - CheckConsistencyRequest checkConsistencyRequest = consistencyRequest.toCheckConsistencyProto(requestContext, CONSISTENCY_TOKEN); + CheckConsistencyRequest checkConsistencyRequest = + consistencyRequest.toCheckConsistencyProto(requestContext, CONSISTENCY_TOKEN); - assertThat(checkConsistencyRequest.getName().equals(TABLE_ID)); - assertThat(checkConsistencyRequest.getConsistencyToken().equals(CONSISTENCY_TOKEN)); - assertThat(checkConsistencyRequest.getModeCase().equals(CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES)); - } + assertThat(checkConsistencyRequest.getName().equals(TABLE_ID)); + assertThat(checkConsistencyRequest.getConsistencyToken().equals(CONSISTENCY_TOKEN)); + assertThat( + checkConsistencyRequest + .getModeCase() + .equals(CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES)); + } - @Test - public void testToCheckConsistencyProtoWithDataBoost() { - ConsistencyRequest consistencyRequest = ConsistencyRequest.forDataBoost(TABLE_ID); + @Test + public void testToCheckConsistencyProtoWithDataBoost() { + ConsistencyRequest consistencyRequest = ConsistencyRequest.forDataBoost(TABLE_ID); - RequestContextNoAP requestContext = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); + RequestContextNoAP requestContext = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); - CheckConsistencyRequest checkConsistencyRequest = consistencyRequest.toCheckConsistencyProto(requestContext, CONSISTENCY_TOKEN); + CheckConsistencyRequest checkConsistencyRequest = + consistencyRequest.toCheckConsistencyProto(requestContext, CONSISTENCY_TOKEN); - assertThat(checkConsistencyRequest.getName().equals(TABLE_ID)); - assertThat(checkConsistencyRequest.getConsistencyToken().equals(CONSISTENCY_TOKEN)); - assertThat(checkConsistencyRequest.getModeCase().equals(CheckConsistencyRequest.ModeCase.DATA_BOOST_READ_LOCAL_WRITES)); - } + assertThat(checkConsistencyRequest.getName().equals(TABLE_ID)); + assertThat(checkConsistencyRequest.getConsistencyToken().equals(CONSISTENCY_TOKEN)); + assertThat( + checkConsistencyRequest + .getModeCase() + .equals(CheckConsistencyRequest.ModeCase.DATA_BOOST_READ_LOCAL_WRITES)); + } - @Test - public void testToGenerateTokenProto() { - ConsistencyRequest consistencyRequest = ConsistencyRequest.forDataBoost(TABLE_ID); + @Test + public void testToGenerateTokenProto() { + ConsistencyRequest consistencyRequest = ConsistencyRequest.forDataBoost(TABLE_ID); - RequestContextNoAP requestContext = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); + RequestContextNoAP requestContext = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); - GenerateConsistencyTokenRequest generateRequest = consistencyRequest.toGenerateTokenProto(requestContext); + GenerateConsistencyTokenRequest generateRequest = + consistencyRequest.toGenerateTokenProto(requestContext); - assertThat(generateRequest.getName().equals(TABLE_ID)); - } + assertThat(generateRequest.getName().equals(TABLE_ID)); + } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java index 0217773710..f0e305b194 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java @@ -33,10 +33,10 @@ import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse; import com.google.bigtable.admin.v2.StandardReadRemoteWrites; import com.google.bigtable.admin.v2.TableName; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -58,7 +58,8 @@ public class AwaitConsistencyCallableTest { private static final String TABLE_ID = "my-table"; private static final TableName TABLE_NAME = TableName.of(PROJECT_ID, INSTANCE_ID, TABLE_ID); private static final ApiCallContext CALL_CONTEXT = FakeCallContext.createDefault(); - private static final RequestContextNoAP REQUEST_CONTEXT = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); + private static final RequestContextNoAP REQUEST_CONTEXT = + RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); @Mock private UnaryCallable @@ -90,8 +91,13 @@ public void setUp() { .setRpcTimeoutMultiplier(1.0) .build(); - awaitConsistencyCallable = AwaitConsistencyCallable.create(mockGenerateConsistencyTokenCallable, - mockCheckConsistencyCallable, clientContext, retrySettings, REQUEST_CONTEXT); + awaitConsistencyCallable = + AwaitConsistencyCallable.create( + mockGenerateConsistencyTokenCallable, + mockCheckConsistencyCallable, + clientContext, + retrySettings, + REQUEST_CONTEXT); awaitReplicationCallable = AwaitReplicationCallable.create(awaitConsistencyCallable); } @@ -178,7 +184,8 @@ public void testImmediatelyConsistent() throws Exception { .thenReturn(ApiFutures.immediateFuture(expectedResponse2)); ConsistencyRequest consistencyRequest = ConsistencyRequest.forReplication(TABLE_ID); - ApiFuture consistentFuture = awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); + ApiFuture consistentFuture = + awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); consistentFuture.get(1, TimeUnit.MILLISECONDS); } @@ -212,7 +219,8 @@ public void testPolling() throws Exception { .thenReturn(ApiFutures.immediateFuture(expectedResponse3)); ConsistencyRequest consistencyRequest = ConsistencyRequest.forReplication(TABLE_ID); - ApiFuture consistentFuture = awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); + ApiFuture consistentFuture = + awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); consistentFuture.get(1, TimeUnit.SECONDS); } @@ -242,7 +250,8 @@ public void testPollingTimeout() throws Exception { .thenReturn(ApiFutures.immediateFuture(expectedResponse2)); ConsistencyRequest consistencyRequest = ConsistencyRequest.forReplication(TABLE_ID); - ApiFuture consistentFuture = awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); + ApiFuture consistentFuture = + awaitConsistencyCallable.futureCall(consistencyRequest, CALL_CONTEXT); Throwable actualError = null; try { @@ -257,27 +266,28 @@ public void testPollingTimeout() throws Exception { @Test public void testAwaitReplicationCallableImmediatelyConsistent() throws Exception { GenerateConsistencyTokenRequest expectedRequest = - GenerateConsistencyTokenRequest.newBuilder().setName(TABLE_NAME.toString()).build(); + GenerateConsistencyTokenRequest.newBuilder().setName(TABLE_NAME.toString()).build(); GenerateConsistencyTokenResponse expectedResponse = - GenerateConsistencyTokenResponse.newBuilder().setConsistencyToken("fake-token").build(); + GenerateConsistencyTokenResponse.newBuilder().setConsistencyToken("fake-token").build(); Mockito.when(mockGenerateConsistencyTokenCallable.futureCall(expectedRequest, CALL_CONTEXT)) - .thenReturn(ApiFutures.immediateFuture(expectedResponse)); + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); CheckConsistencyRequest expectedRequest2 = - CheckConsistencyRequest.newBuilder() - .setName(TABLE_NAME.toString()) - .setConsistencyToken("fake-token") - .setStandardReadRemoteWrites(StandardReadRemoteWrites.newBuilder().build()) - .build(); + CheckConsistencyRequest.newBuilder() + .setName(TABLE_NAME.toString()) + .setConsistencyToken("fake-token") + .setStandardReadRemoteWrites(StandardReadRemoteWrites.newBuilder().build()) + .build(); CheckConsistencyResponse expectedResponse2 = - CheckConsistencyResponse.newBuilder().setConsistent(true).build(); + CheckConsistencyResponse.newBuilder().setConsistent(true).build(); Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)) - .thenReturn(ApiFutures.immediateFuture(expectedResponse2)); + .thenReturn(ApiFutures.immediateFuture(expectedResponse2)); - ApiFuture consistentFuture = awaitReplicationCallable.futureCall(TABLE_NAME, CALL_CONTEXT); + ApiFuture consistentFuture = + awaitReplicationCallable.futureCall(TABLE_NAME, CALL_CONTEXT); consistentFuture.get(1, TimeUnit.MILLISECONDS); } @@ -285,32 +295,33 @@ public void testAwaitReplicationCallableImmediatelyConsistent() throws Exception @Test public void testAwaitReplicationCallablePolling() throws Exception { GenerateConsistencyTokenRequest expectedRequest = - GenerateConsistencyTokenRequest.newBuilder().setName(TABLE_NAME.toString()).build(); + GenerateConsistencyTokenRequest.newBuilder().setName(TABLE_NAME.toString()).build(); GenerateConsistencyTokenResponse expectedResponse = - GenerateConsistencyTokenResponse.newBuilder().setConsistencyToken("fake-token").build(); + GenerateConsistencyTokenResponse.newBuilder().setConsistencyToken("fake-token").build(); Mockito.when(mockGenerateConsistencyTokenCallable.futureCall(expectedRequest, CALL_CONTEXT)) - .thenReturn(ApiFutures.immediateFuture(expectedResponse)); + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); CheckConsistencyRequest expectedRequest2 = - CheckConsistencyRequest.newBuilder() - .setName(TABLE_NAME.toString()) - .setConsistencyToken("fake-token") - .setStandardReadRemoteWrites(StandardReadRemoteWrites.newBuilder().build()) - .build(); + CheckConsistencyRequest.newBuilder() + .setName(TABLE_NAME.toString()) + .setConsistencyToken("fake-token") + .setStandardReadRemoteWrites(StandardReadRemoteWrites.newBuilder().build()) + .build(); CheckConsistencyResponse expectedResponse2 = - CheckConsistencyResponse.newBuilder().setConsistent(false).build(); + CheckConsistencyResponse.newBuilder().setConsistent(false).build(); CheckConsistencyResponse expectedResponse3 = - CheckConsistencyResponse.newBuilder().setConsistent(true).build(); + CheckConsistencyResponse.newBuilder().setConsistent(true).build(); Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)) - .thenReturn(ApiFutures.immediateFuture(expectedResponse2)) - .thenReturn(ApiFutures.immediateFuture(expectedResponse3)); + .thenReturn(ApiFutures.immediateFuture(expectedResponse2)) + .thenReturn(ApiFutures.immediateFuture(expectedResponse3)); - ApiFuture consistentFuture = awaitReplicationCallable.futureCall(TABLE_NAME, CALL_CONTEXT); + ApiFuture consistentFuture = + awaitReplicationCallable.futureCall(TABLE_NAME, CALL_CONTEXT); consistentFuture.get(1, TimeUnit.SECONDS); } From beadfb0020cabf5fc097a08e41c077a1b40d3375 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Mon, 9 Sep 2024 14:41:35 -0400 Subject: [PATCH 21/26] Rename new RequestContext to TableAdminRequestContext, re run auto formatter Change-Id: Ib3f5918ef0f5b1ac53147baf93dcb72c476d877b --- .../bigtable/admin/v2/BigtableTableAdminClient.java | 6 +++--- .../bigtable/admin/v2/models/ConsistencyRequest.java | 7 ++++--- .../admin/v2/stub/AwaitConsistencyCallable.java | 8 ++++---- .../admin/v2/stub/EnhancedBigtableTableAdminStub.java | 8 ++++---- ...ContextNoAP.java => TableAdminRequestContext.java} | 8 ++++---- .../admin/v2/models/ConsistencyRequestTest.java | 11 +++++++---- .../admin/v2/stub/AwaitConsistencyCallableTest.java | 6 +++--- 7 files changed, 29 insertions(+), 25 deletions(-) rename google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/{RequestContextNoAP.java => TableAdminRequestContext.java} (82%) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java index 110783f6c3..889598020a 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java @@ -62,7 +62,7 @@ import com.google.cloud.bigtable.admin.v2.models.UpdateBackupRequest; import com.google.cloud.bigtable.admin.v2.models.UpdateTableRequest; import com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub; -import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; +import com.google.cloud.bigtable.data.v2.internal.TableAdminRequestContext; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -156,8 +156,8 @@ public static BigtableTableAdminClient create( /** Constructs an instance of BigtableTableAdminClient with the given settings. */ public static BigtableTableAdminClient create(@Nonnull BigtableTableAdminSettings settings) throws IOException { - RequestContextNoAP requestContext = - RequestContextNoAP.create(settings.getProjectId(), settings.getInstanceId()); + TableAdminRequestContext requestContext = + TableAdminRequestContext.create(settings.getProjectId(), settings.getInstanceId()); EnhancedBigtableTableAdminStub stub = EnhancedBigtableTableAdminStub.createEnhanced(settings.getStubSettings(), requestContext); return create(settings.getProjectId(), settings.getInstanceId(), stub); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java index f58e72186f..0718af03c1 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequest.java @@ -22,7 +22,7 @@ import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest; import com.google.bigtable.admin.v2.StandardReadRemoteWrites; import com.google.bigtable.admin.v2.TableName; -import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; +import com.google.cloud.bigtable.data.v2.internal.TableAdminRequestContext; import javax.annotation.Nonnull; @AutoValue @@ -45,7 +45,7 @@ public static ConsistencyRequest forDataBoost(String tableId) { @InternalApi public CheckConsistencyRequest toCheckConsistencyProto( - RequestContextNoAP requestContext, String token) { + TableAdminRequestContext requestContext, String token) { CheckConsistencyRequest.Builder builder = CheckConsistencyRequest.newBuilder(); TableName tableName = TableName.of(requestContext.getProjectId(), requestContext.getInstanceId(), getTableId()); @@ -60,7 +60,8 @@ public CheckConsistencyRequest toCheckConsistencyProto( } @InternalApi - public GenerateConsistencyTokenRequest toGenerateTokenProto(RequestContextNoAP requestContext) { + public GenerateConsistencyTokenRequest toGenerateTokenProto( + TableAdminRequestContext requestContext) { GenerateConsistencyTokenRequest.Builder builder = GenerateConsistencyTokenRequest.newBuilder(); TableName tableName = TableName.of(requestContext.getProjectId(), requestContext.getInstanceId(), getTableId()); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java index bae6e32b9c..7cdcb66599 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallable.java @@ -36,7 +36,7 @@ import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest; import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse; import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; -import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; +import com.google.cloud.bigtable.data.v2.internal.TableAdminRequestContext; import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.MoreExecutors; import java.util.concurrent.Callable; @@ -55,7 +55,7 @@ class AwaitConsistencyCallable extends UnaryCallable { private final UnaryCallable checkCallable; private final RetryingExecutor executor; - private final RequestContextNoAP requestContext; + private final TableAdminRequestContext requestContext; static AwaitConsistencyCallable create( UnaryCallable @@ -63,7 +63,7 @@ static AwaitConsistencyCallable create( UnaryCallable checkCallable, ClientContext clientContext, RetrySettings pollingSettings, - RequestContextNoAP requestContext) { + TableAdminRequestContext requestContext) { RetryAlgorithm retryAlgorithm = new RetryAlgorithm<>( @@ -83,7 +83,7 @@ static AwaitConsistencyCallable create( generateCallable, UnaryCallable checkCallable, RetryingExecutor executor, - RequestContextNoAP requestContext) { + TableAdminRequestContext requestContext) { this.generateCallable = generateCallable; this.checkCallable = checkCallable; this.executor = executor; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java index be6f984cd6..78a8d034c6 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java @@ -32,7 +32,7 @@ import com.google.bigtable.admin.v2.OptimizeRestoredTableMetadata; import com.google.bigtable.admin.v2.TableName; import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; -import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; +import com.google.cloud.bigtable.data.v2.internal.TableAdminRequestContext; import com.google.longrunning.Operation; import com.google.protobuf.Empty; import io.grpc.MethodDescriptor; @@ -54,7 +54,7 @@ public class EnhancedBigtableTableAdminStub extends GrpcBigtableTableAdminStub { private final BigtableTableAdminStubSettings settings; private final ClientContext clientContext; - private final RequestContextNoAP requestContext; + private final TableAdminRequestContext requestContext; private final AwaitReplicationCallable awaitReplicationCallable; @@ -63,7 +63,7 @@ public class EnhancedBigtableTableAdminStub extends GrpcBigtableTableAdminStub { optimizeRestoredTableOperationBaseCallable; public static EnhancedBigtableTableAdminStub createEnhanced( - BigtableTableAdminStubSettings settings, RequestContextNoAP requestContext) + BigtableTableAdminStubSettings settings, TableAdminRequestContext requestContext) throws IOException { return new EnhancedBigtableTableAdminStub( settings, ClientContext.create(settings), requestContext); @@ -72,7 +72,7 @@ public static EnhancedBigtableTableAdminStub createEnhanced( private EnhancedBigtableTableAdminStub( BigtableTableAdminStubSettings settings, ClientContext clientContext, - RequestContextNoAP requestContext) + TableAdminRequestContext requestContext) throws IOException { super(settings, clientContext); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContextNoAP.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/TableAdminRequestContext.java similarity index 82% rename from google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContextNoAP.java rename to google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/TableAdminRequestContext.java index 5b076d01e5..05554425b4 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContextNoAP.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/TableAdminRequestContext.java @@ -31,11 +31,11 @@ */ @InternalApi @AutoValue -public abstract class RequestContextNoAP implements Serializable { +public abstract class TableAdminRequestContext implements Serializable { - /** Creates a new instance of the {@link RequestContextNoAP}. */ - public static RequestContextNoAP create(String projectId, String instanceId) { - return new AutoValue_RequestContextNoAP(projectId, instanceId); + /** Creates a new instance of the {@link TableAdminRequestContext}. */ + public static TableAdminRequestContext create(String projectId, String instanceId) { + return new AutoValue_TableAdminRequestContext(projectId, instanceId); } /** The project id that the client is configured to target. */ diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java index da79bf8ff0..07fa4fcf45 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java @@ -4,7 +4,7 @@ import com.google.bigtable.admin.v2.CheckConsistencyRequest; import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest; -import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; +import com.google.cloud.bigtable.data.v2.internal.TableAdminRequestContext; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -20,7 +20,8 @@ public class ConsistencyRequestTest { public void testToCheckConsistencyProtoWithStandard() { ConsistencyRequest consistencyRequest = ConsistencyRequest.forReplication(TABLE_ID); - RequestContextNoAP requestContext = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); + TableAdminRequestContext requestContext = + TableAdminRequestContext.create(PROJECT_ID, INSTANCE_ID); CheckConsistencyRequest checkConsistencyRequest = consistencyRequest.toCheckConsistencyProto(requestContext, CONSISTENCY_TOKEN); @@ -37,7 +38,8 @@ public void testToCheckConsistencyProtoWithStandard() { public void testToCheckConsistencyProtoWithDataBoost() { ConsistencyRequest consistencyRequest = ConsistencyRequest.forDataBoost(TABLE_ID); - RequestContextNoAP requestContext = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); + TableAdminRequestContext requestContext = + TableAdminRequestContext.create(PROJECT_ID, INSTANCE_ID); CheckConsistencyRequest checkConsistencyRequest = consistencyRequest.toCheckConsistencyProto(requestContext, CONSISTENCY_TOKEN); @@ -54,7 +56,8 @@ public void testToCheckConsistencyProtoWithDataBoost() { public void testToGenerateTokenProto() { ConsistencyRequest consistencyRequest = ConsistencyRequest.forDataBoost(TABLE_ID); - RequestContextNoAP requestContext = RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); + TableAdminRequestContext requestContext = + TableAdminRequestContext.create(PROJECT_ID, INSTANCE_ID); GenerateConsistencyTokenRequest generateRequest = consistencyRequest.toGenerateTokenProto(requestContext); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java index f0e305b194..2628cdf224 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java @@ -34,7 +34,7 @@ import com.google.bigtable.admin.v2.StandardReadRemoteWrites; import com.google.bigtable.admin.v2.TableName; import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; -import com.google.cloud.bigtable.data.v2.internal.RequestContextNoAP; +import com.google.cloud.bigtable.data.v2.internal.TableAdminRequestContext; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import org.junit.Before; @@ -58,8 +58,8 @@ public class AwaitConsistencyCallableTest { private static final String TABLE_ID = "my-table"; private static final TableName TABLE_NAME = TableName.of(PROJECT_ID, INSTANCE_ID, TABLE_ID); private static final ApiCallContext CALL_CONTEXT = FakeCallContext.createDefault(); - private static final RequestContextNoAP REQUEST_CONTEXT = - RequestContextNoAP.create(PROJECT_ID, INSTANCE_ID); + private static final TableAdminRequestContext REQUEST_CONTEXT = + TableAdminRequestContext.create(PROJECT_ID, INSTANCE_ID); @Mock private UnaryCallable From f774895051bf04407e3d8b7e6e25003e0e258724 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 9 Sep 2024 18:49:54 +0000 Subject: [PATCH 22/26] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bac33a9b29..f9a31670e7 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ If you are using Maven without the BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.44.0') +implementation platform('com.google.cloud:libraries-bom:26.45.0') implementation 'com.google.cloud:google-cloud-bigtable' ``` From e263edd8739a43658f9c3bca1a8a7301932af937 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Tue, 10 Sep 2024 13:45:50 -0400 Subject: [PATCH 23/26] Add license header to ConsistencyRequestTest Change-Id: I733d2f8c082647ad32b72b04b218cd5ba79d2377 --- .../admin/v2/models/ConsistencyRequestTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java index 07fa4fcf45..cc039d7d80 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.google.cloud.bigtable.admin.v2.models; import static com.google.common.truth.Truth.assertThat; From f628eb61cd6d63c00e2303d2caaa4d6b7e8158e1 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Wed, 11 Sep 2024 14:58:35 -0400 Subject: [PATCH 24/26] Add EnhancedBigtableTableAdminStub to clirr-ignored-differences Change-Id: I7eefeda777305dd3d7c5664097bda87ac63daa72 --- google-cloud-bigtable/clirr-ignored-differences.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/google-cloud-bigtable/clirr-ignored-differences.xml b/google-cloud-bigtable/clirr-ignored-differences.xml index fb5b514b3d..8ddcb6fdf0 100644 --- a/google-cloud-bigtable/clirr-ignored-differences.xml +++ b/google-cloud-bigtable/clirr-ignored-differences.xml @@ -259,4 +259,10 @@ com/google/cloud/bigtable/admin/v2/models/Type$Int64$Encoding$BigEndianBytes * + + + 7004 + com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub + * + From 3614dca603d43c8996317966a18f5a36e06eb8b2 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Thu, 12 Sep 2024 13:06:45 -0400 Subject: [PATCH 25/26] Fix IT tests, skip data boost one for now until we run it concurrently Change-Id: I764190b0f91614753080e0a96e7e11e3dfb1fde0 --- .../admin/v2/stub/EnhancedBigtableTableAdminStub.java | 2 +- .../bigtable/admin/v2/it/BigtableTableAdminClientIT.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java index 78a8d034c6..1cb80e0c49 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java @@ -78,11 +78,11 @@ private EnhancedBigtableTableAdminStub( this.settings = settings; this.clientContext = clientContext; + this.requestContext = requestContext; this.awaitConsistencyCallable = createAwaitConsistencyCallable(); this.awaitReplicationCallable = createAwaitReplicationCallable(); this.optimizeRestoredTableOperationBaseCallable = createOptimizeRestoredTableOperationBaseCallable(); - this.requestContext = requestContext; } private AwaitReplicationCallable createAwaitReplicationCallable() { diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java index c301f5d41a..af6b58a1d5 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java @@ -47,6 +47,7 @@ import org.junit.After; import org.junit.Before; import org.junit.ClassRule; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -230,9 +231,11 @@ public void awaitReplication() { /** * Note: Data Boost consistency is essentially a check that the data you are trying to read was - * written at least 35 minutes ago. + * written at least 35 minutes ago. The test thus takes ~35 minutes, and we should add a separate profile + * to run this concurrently with the other tests. */ @Test + @Ignore public void awaitDataBoostConsistency() { assume() .withMessage("Data Boost consistency not supported on Emulator") From 1240b3c696697095097eeed5d1c17707a8e5ce4b Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 13 Sep 2024 14:53:46 -0400 Subject: [PATCH 26/26] Run autoformatter Change-Id: Iba4671e4781f1b333279a2410563869f53b284d5 --- .../bigtable/admin/v2/it/BigtableTableAdminClientIT.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java index af6b58a1d5..cfcc8d0b42 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java @@ -231,8 +231,8 @@ public void awaitReplication() { /** * Note: Data Boost consistency is essentially a check that the data you are trying to read was - * written at least 35 minutes ago. The test thus takes ~35 minutes, and we should add a separate profile - * to run this concurrently with the other tests. + * written at least 35 minutes ago. The test thus takes ~35 minutes, and we should add a separate + * profile to run this concurrently with the other tests. */ @Test @Ignore