Skip to content

Commit 4d15ddf

Browse files
igorbernstein2pongad
authored andcommitted
---
yaml --- r: 10101 b: refs/heads/master c: c90b5ba h: refs/heads/master i: 10099: 18fb27a
1 parent e5da159 commit 4d15ddf

9 files changed

Lines changed: 527 additions & 244 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 43d53a80559e3c928bfdc261982fa82aa323e2a0
2+
refs/heads/master: c90b5ba509e2c02327ef92a6497f5d6d27152be4
33
refs/heads/travis: 47e4fee4fd5af9b2a8ce46f23c72ec95f9b195b2
44
refs/heads/gh-pages: 78e4171d070ae014fe1e1ea58a414126c9126c61
55
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

trunk/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java

Lines changed: 30 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,18 @@
1919
import com.google.api.core.ApiFunction;
2020
import com.google.api.core.ApiFuture;
2121
import com.google.api.core.ApiFutures;
22-
import com.google.bigtable.admin.v2.CheckConsistencyResponse;
2322
import com.google.bigtable.admin.v2.DeleteTableRequest;
2423
import com.google.bigtable.admin.v2.DropRowRangeRequest;
25-
import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest;
26-
import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse;
2724
import com.google.bigtable.admin.v2.GetTableRequest;
2825
import com.google.bigtable.admin.v2.InstanceName;
2926
import com.google.bigtable.admin.v2.ListTablesRequest;
3027
import com.google.bigtable.admin.v2.TableName;
3128
import com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPage;
3229
import com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse;
33-
import com.google.cloud.bigtable.admin.v2.models.ConsistencyToken;
3430
import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest;
3531
import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest;
3632
import com.google.cloud.bigtable.admin.v2.models.Table;
3733
import com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub;
38-
import com.google.common.annotations.VisibleForTesting;
3934
import com.google.common.base.Preconditions;
4035
import com.google.common.collect.Lists;
4136
import com.google.common.util.concurrent.Futures;
@@ -649,91 +644,57 @@ public ApiFuture<Void> dropAllRowsAsync(String tableId) {
649644
}
650645

651646
/**
652-
* Generates a token to verify the replication status of table mutations invoked before this call.
653-
* Token expires in 90 days
647+
* Blocks until replication has caught up to the point this method was called. This allows callers
648+
* to make sure that their mutations have been replicated across all of their clusters.
654649
*
655-
* <p>Sample code:
650+
* <p>Sample code
656651
*
657652
* <pre>{@code
658-
* ConsistencyToken consistencyToken = client.generateConsistencyToken("my-table");
653+
* client.awaitReplication("my-table");
659654
* }</pre>
660-
*/
661-
@SuppressWarnings("WeakerAccess")
662-
public ConsistencyToken generateConsistencyToken(String tableId) {
663-
return awaitFuture(generateConsistencyTokenAsync(tableId));
664-
}
665-
666-
/**
667-
* Asynchornously generates a token to verify the replication status of table mutations invoked
668-
* before this call. Token expires in 90 days
669-
*
670-
* <p>Sample code:
671655
*
672-
* <pre>{@code
673-
* ApiFuture<ConsistencyToken> consistencyTokenFuture = client.generateConsistencyToken("my-table");
674-
* }</pre>
656+
* @throws com.google.api.gax.retrying.PollException when polling exceeds the total timeout
675657
*/
676-
// TODO(igorbernstein2): add sample code for waiting for the fetch consistency token
677658
@SuppressWarnings("WeakerAccess")
678-
public ApiFuture<ConsistencyToken> generateConsistencyTokenAsync(final String tableId) {
679-
GenerateConsistencyTokenRequest request = GenerateConsistencyTokenRequest.newBuilder()
680-
.setName(getTableName(tableId))
681-
.build();
682-
683-
return ApiFutures.transform(
684-
stub.generateConsistencyTokenCallable().futureCall(request),
685-
new ApiFunction<GenerateConsistencyTokenResponse, ConsistencyToken>() {
686-
@Override
687-
public ConsistencyToken apply(GenerateConsistencyTokenResponse proto) {
688-
TableName tableName = TableName
689-
.of(instanceName.getProject(), instanceName.getInstance(), tableId);
690-
return ConsistencyToken.of(tableName, proto.getConsistencyToken());
691-
}
692-
},
693-
MoreExecutors.directExecutor());
659+
public void awaitReplication(String tableId) {
660+
TableName tableName = TableName
661+
.of(instanceName.getProject(), instanceName.getInstance(), tableId);
662+
awaitFuture(stub.awaitReplicationCallable().futureCall(tableName));
694663
}
695664

696665
/**
697-
* Checks replication consistency for the specified token consistency token
666+
* Returns a future that is resolved when replication has caught up to the point this method was
667+
* called. This allows callers to make sure that their mutations have been replicated across all
668+
* of their clusters.
698669
*
699670
* <p>Sample code:
700671
*
701672
* <pre>{@code
702-
* try(BigtableTableAdminClient client = BigtableTableAdminClient.create(InstanceName.of("[PROJECT]", "[INSTANCE]"))) {
703-
* // Perform some mutations.
673+
* ApiFuture<Void> replicationFuture = client.awaitReplicationAsync("my-table");
704674
*
705-
* ConsistencyToken token = client.generateConsistencyToken("table-id");
706-
* while(!client.isConsistent(token)) {
707-
* Thread.sleep(100);
708-
* }
675+
* ApiFutures.addCallback(
676+
* replicationFuture,
677+
* new ApiFutureCallback<Void>() {
678+
* public void onSuccess(Table table) {
679+
* System.out.println("All clusters are now consistent");
680+
* }
681+
*
682+
* public void onFailure(Throwable t) {
683+
* t.printStackTrace();
684+
* }
685+
* },
686+
* MoreExecutors.directExecutor()
687+
* );
709688
*
710-
* // Now all clusters are consistent
711-
* }
712689
* }</pre>
713690
*/
714691
@SuppressWarnings("WeakerAccess")
715-
public boolean isConsistent(ConsistencyToken token) {
716-
return awaitFuture(isConsistentAsync(token));
692+
public ApiFuture<Void> awaitReplicationAsync(final String tableId) {
693+
TableName tableName = TableName
694+
.of(instanceName.getProject(), instanceName.getInstance(), tableId);
695+
return stub.awaitReplicationCallable().futureCall(tableName);
717696
}
718697

719-
@VisibleForTesting
720-
ApiFuture<Boolean> isConsistentAsync(ConsistencyToken token) {
721-
ApiFuture<CheckConsistencyResponse> checkConsResp = stub.checkConsistencyCallable()
722-
.futureCall(token.toProto(instanceName));
723-
724-
return ApiFutures.transform(
725-
checkConsResp,
726-
new ApiFunction<CheckConsistencyResponse, Boolean>() {
727-
@Override
728-
public Boolean apply(CheckConsistencyResponse input) {
729-
return input.getConsistent();
730-
}
731-
},
732-
MoreExecutors.directExecutor());
733-
}
734-
735-
// TODO(igorbernstein2): add awaitConsist() & awaitConsistAsync() that generate & poll a token
736-
737698
/**
738699
* Helper method to construct the table name in format: projects/{project}/instances/{instance}/tables/{tableId}
739700
*/

trunk/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyToken.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)