From caa98a436891f3637a2a238d5cbc1acbe1d7072a Mon Sep 17 00:00:00 2001 From: Ajay Date: Thu, 11 Oct 2018 10:53:18 -0400 Subject: [PATCH 1/3] interface for client wrapper --- .../cloud/bigtable/core/BulkMutation.java | 37 +++++++++ .../cloud/bigtable/core/ClientWrapper.java | 77 +++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/BulkMutation.java create mode 100644 bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/ClientWrapper.java diff --git a/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/BulkMutation.java b/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/BulkMutation.java new file mode 100644 index 0000000000..1939060a43 --- /dev/null +++ b/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/BulkMutation.java @@ -0,0 +1,37 @@ +package com.google.cloud.bigtable.core; + +import com.google.api.core.ApiFuture; +import com.google.bigtable.v2.MutateRowRequest; +import com.google.cloud.bigtable.data.v2.models.RowMutation; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +/** + * Interface to support batching multiple RowMutation request in to singe grpc request. + */ +public interface BulkMutation { + long MAX_RPC_WAIT_TIME_NANOS = TimeUnit.MINUTES.toNanos(12); + + /** + * Send any outstanding {@link MutateRowRequest}s and wait until all requests are complete. + */ + void flush() throws InterruptedException, TimeoutException; + + void sendUnsent(); + + /** + * @return false if there are any outstanding {@link MutateRowRequest} that still need to be sent. + */ + boolean isFlushed(); + + /** + * Adds a {@link com.google.cloud.bigtable.data.v2.models.RowMutation} to the underlying BulkMutation + * mechanism. + * + * @param rowMutation The {@link com.google.cloud.bigtable.data.v2.models.RowMutation} to add + * @return a {@link com.google.common.util.concurrent.SettableFuture} will be set when request is + * successful otherwise exception will be thrown. + */ + ApiFuture add(RowMutation rowMutation); +} diff --git a/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/ClientWrapper.java b/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/ClientWrapper.java new file mode 100644 index 0000000000..db57afc373 --- /dev/null +++ b/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/ClientWrapper.java @@ -0,0 +1,77 @@ +package com.google.cloud.bigtable.core; + +import com.google.api.core.ApiFuture; +import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation; +import com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow; +import com.google.cloud.bigtable.data.v2.models.Row; +import com.google.cloud.bigtable.data.v2.models.RowMutation; + +import java.util.concurrent.ExecutionException; + +/** + * Interface to access Bigtable data service api. + */ +public interface ClientWrapper { + + /** + * Mutate a row atomically. + * + * @param rowMutation a {@link RowMutation} model object. + * @throws ExecutionException + * @throws InterruptedException + */ + void mutateRow(RowMutation rowMutation) throws ExecutionException, InterruptedException; + + /** + * Mutate a row atomically. + * + * @param rowMutation a {@link RowMutation} model object. + * @return ApiFuture returns api future. + * @throws InterruptedException + */ + ApiFuture mutateRowAsync(RowMutation rowMutation) throws InterruptedException; + + /** + * Perform an atomic read-modify-write operation on a row. + * + * @param readModifyWriteRow a {@link ReadModifyWriteRow} model object. + * @return Row a modified row. + * @throws ExecutionException + * @throws InterruptedException + */ + Row readModifyWriteRow(ReadModifyWriteRow readModifyWriteRow) + throws ExecutionException, InterruptedException; + + /** + * Perform an atomic read-modify-write operation on a row. + * + * @param readModifyWriteRow a {@link ReadModifyWriteRow} model object. + * @return ApiFuture returns future. + * @throws InterruptedException + */ + ApiFuture readModifyWriteRowAsync(ReadModifyWriteRow readModifyWriteRow) throws InterruptedException; + + /** + * Creates BulMutation batcher. + */ + BulkMutation createBulkMutationBatcher(); + + /** + * Mutate a row atomically dependent on a precondition. + * + * @param conditionalRowMutation a {@link ConditionalRowMutation} model object. + * @return ApiFuture returns api future. + */ + ApiFuture checkAndMutateRowAsync(ConditionalRowMutation conditionalRowMutation); + + /** + * Mutate a row atomically dependent on a precondition. + * + * @param conditionalRowMutation a {@link ConditionalRowMutation} model object. + * @return Boolean returns true if predicate returns any result. + * @throws ExecutionException + * @throws InterruptedException + */ + Boolean checkAndMutateRow(ConditionalRowMutation conditionalRowMutation) + throws ExecutionException, InterruptedException; +} From e2e4cb62857c96479019fa8e7df2c3b30e1b80f7 Mon Sep 17 00:00:00 2001 From: Ajay Date: Thu, 11 Oct 2018 11:53:36 -0400 Subject: [PATCH 2/3] add licence --- .../google/cloud/bigtable/core/BulkMutation.java | 15 +++++++++++++++ .../google/cloud/bigtable/core/ClientWrapper.java | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/BulkMutation.java b/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/BulkMutation.java index 1939060a43..7111234ca6 100644 --- a/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/BulkMutation.java +++ b/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/BulkMutation.java @@ -1,3 +1,18 @@ +/* + * 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.core; import com.google.api.core.ApiFuture; diff --git a/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/ClientWrapper.java b/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/ClientWrapper.java index db57afc373..cb554acaf2 100644 --- a/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/ClientWrapper.java +++ b/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/ClientWrapper.java @@ -1,3 +1,18 @@ +/* + * 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.core; import com.google.api.core.ApiFuture; From 0090cd595f091f3d6f2e1b046553a08e49926c56 Mon Sep 17 00:00:00 2001 From: Ajay Date: Mon, 15 Oct 2018 10:57:52 -0400 Subject: [PATCH 3/3] rename the interface --- .../core/{ClientWrapper.java => IBigtableDataClient.java} | 4 ++-- .../bigtable/core/{BulkMutation.java => IBulkMutation.java} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/{ClientWrapper.java => IBigtableDataClient.java} (97%) rename bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/{BulkMutation.java => IBulkMutation.java} (95%) diff --git a/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/ClientWrapper.java b/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/IBigtableDataClient.java similarity index 97% rename from bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/ClientWrapper.java rename to bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/IBigtableDataClient.java index cb554acaf2..4c03e0b7e6 100644 --- a/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/ClientWrapper.java +++ b/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/IBigtableDataClient.java @@ -26,7 +26,7 @@ /** * Interface to access Bigtable data service api. */ -public interface ClientWrapper { +public interface IBigtableDataClient { /** * Mutate a row atomically. @@ -69,7 +69,7 @@ Row readModifyWriteRow(ReadModifyWriteRow readModifyWriteRow) /** * Creates BulMutation batcher. */ - BulkMutation createBulkMutationBatcher(); + IBulkMutation createBulkMutationBatcher(); /** * Mutate a row atomically dependent on a precondition. diff --git a/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/BulkMutation.java b/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/IBulkMutation.java similarity index 95% rename from bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/BulkMutation.java rename to bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/IBulkMutation.java index 7111234ca6..49cf2f1c7e 100644 --- a/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/BulkMutation.java +++ b/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/core/IBulkMutation.java @@ -25,7 +25,7 @@ /** * Interface to support batching multiple RowMutation request in to singe grpc request. */ -public interface BulkMutation { +public interface IBulkMutation { long MAX_RPC_WAIT_TIME_NANOS = TimeUnit.MINUTES.toNanos(12); /** @@ -41,7 +41,7 @@ public interface BulkMutation { boolean isFlushed(); /** - * Adds a {@link com.google.cloud.bigtable.data.v2.models.RowMutation} to the underlying BulkMutation + * Adds a {@link com.google.cloud.bigtable.data.v2.models.RowMutation} to the underlying IBulkMutation * mechanism. * * @param rowMutation The {@link com.google.cloud.bigtable.data.v2.models.RowMutation} to add