Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface to wrap google cloud java #1963

Merged
merged 3 commits into from
Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* 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;
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 IBigtableDataClient {

/**
* 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</Void> returns api future.
* @throws InterruptedException
*/
ApiFuture<Void> 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<Row> returns future.
* @throws InterruptedException
*/
ApiFuture<Row> readModifyWriteRowAsync(ReadModifyWriteRow readModifyWriteRow) throws InterruptedException;

/**
* Creates BulMutation batcher.
*/
IBulkMutation createBulkMutationBatcher();

/**
* Mutate a row atomically dependent on a precondition.
*
* @param conditionalRowMutation a {@link ConditionalRowMutation} model object.
* @return ApiFuture<Boolean> returns api future.
*/
ApiFuture<Boolean> 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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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;
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 IBulkMutation {
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 IBulkMutation
* 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<Void> add(RowMutation rowMutation);
}