use of com.google.cloud.bigtable.data.v2.internal.RequestContext in project java-bigtable by googleapis.
the class EnhancedBigtableStub method createMutateRowCallable.
/**
* Creates a callable chain to handle MutateRow RPCs. The chain will:
*
* <ul>
* <li>Convert a {@link RowMutation} into a {@link com.google.bigtable.v2.MutateRowRequest}.
* <li>Add tracing & metrics.
* </ul>
*/
private UnaryCallable<RowMutation, Void> createMutateRowCallable() {
String methodName = "MutateRow";
UnaryCallable<MutateRowRequest, MutateRowResponse> base = GrpcRawCallableFactory.createUnaryCallable(GrpcCallSettings.<MutateRowRequest, MutateRowResponse>newBuilder().setMethodDescriptor(BigtableGrpc.getMutateRowMethod()).setParamsExtractor(new RequestParamsExtractor<MutateRowRequest>() {
@Override
public Map<String, String> extract(MutateRowRequest mutateRowRequest) {
return ImmutableMap.of("table_name", mutateRowRequest.getTableName(), "app_profile_id", mutateRowRequest.getAppProfileId());
}
}).build(), settings.mutateRowSettings().getRetryableCodes());
UnaryCallable<MutateRowRequest, MutateRowResponse> withStatsHeaders = new StatsHeadersUnaryCallable<>(base);
UnaryCallable<MutateRowRequest, MutateRowResponse> withHeaderTracer = new HeaderTracerUnaryCallable<>(withStatsHeaders);
UnaryCallable<MutateRowRequest, MutateRowResponse> retrying = Callables.retrying(withHeaderTracer, settings.mutateRowSettings(), clientContext);
return createUserFacingUnaryCallable(methodName, new MutateRowCallable(retrying, requestContext));
}
use of com.google.cloud.bigtable.data.v2.internal.RequestContext in project java-bigtable by googleapis.
the class EnhancedBigtableStub method createBulkMutateRowsCallable.
/**
* Creates a callable chain to handle MutatesRows RPCs. This is meant to be used for manual
* batching. The chain will:
*
* <ul>
* <li>Convert a {@link BulkMutation} into a {@link MutateRowsRequest}.
* <li>Process the response and schedule retries. At the end of each attempt, entries that have
* been applied, are filtered from the next attempt. Also, any entries that failed with a
* nontransient error, are filtered from the next attempt. This will continue until there
* are no more entries or there are no more retry attempts left.
* <li>Wrap batch failures in a {@link
* com.google.cloud.bigtable.data.v2.models.MutateRowsException}.
* <li>Add tracing & metrics.
* </ul>
*/
private UnaryCallable<BulkMutation, Void> createBulkMutateRowsCallable() {
UnaryCallable<MutateRowsRequest, Void> baseCallable = createMutateRowsBaseCallable();
UnaryCallable<MutateRowsRequest, Void> flowControlCallable = null;
if (settings.bulkMutateRowsSettings().isLatencyBasedThrottlingEnabled()) {
flowControlCallable = new DynamicFlowControlCallable(baseCallable, bulkMutationFlowController, bulkMutationDynamicFlowControlStats, settings.bulkMutateRowsSettings().getTargetRpcLatencyMs(), FLOW_CONTROL_ADJUSTING_INTERVAL_MS);
}
UnaryCallable<BulkMutation, Void> userFacing = new BulkMutateRowsUserFacingCallable(flowControlCallable != null ? flowControlCallable : baseCallable, requestContext);
SpanName spanName = getSpanName("MutateRows");
UnaryCallable<BulkMutation, Void> tracedBatcher = new TracedBatcherUnaryCallable<>(userFacing);
UnaryCallable<BulkMutation, Void> withHeaderTracer = new HeaderTracerUnaryCallable<>(tracedBatcher);
UnaryCallable<BulkMutation, Void> traced = new TracedUnaryCallable<>(withHeaderTracer, clientContext.getTracerFactory(), spanName);
return traced.withDefaultCallContext(clientContext.getDefaultCallContext());
}
use of com.google.cloud.bigtable.data.v2.internal.RequestContext in project java-bigtable-hbase by googleapis.
the class TestIncrementAdapter method testBasicRowKeyIncrement.
@Test
public void testBasicRowKeyIncrement() {
byte[] rowKey = dataHelper.randomData("rk1-");
Increment incr = new Increment(rowKey);
ReadModifyWriteRow readModifyWriteRow = ReadModifyWriteRow.create(TABLE_ID, ByteString.copyFrom(rowKey));
incrementAdapter.adapt(incr, readModifyWriteRow);
ReadModifyWriteRowRequest requestBuilder = readModifyWriteRow.toProto(requestContext);
ByteString adaptedRowKey = requestBuilder.getRowKey();
Assert.assertArrayEquals(rowKey, adaptedRowKey.toByteArray());
}
use of com.google.cloud.bigtable.data.v2.internal.RequestContext in project java-bigtable-hbase by googleapis.
the class TestIncrementAdapter method testMultipleIncrementWithDuplicateQualifier.
@Test
public void testMultipleIncrementWithDuplicateQualifier() {
byte[] rowKey = dataHelper.randomData("rk1-");
byte[] family1 = Bytes.toBytes("family1");
byte[] qualifier1 = Bytes.toBytes("qualifier1");
long amount1 = 1234;
byte[] family2 = Bytes.toBytes("family2");
byte[] qualifier2 = Bytes.toBytes("qualifier2");
long amount2 = 4321;
long amount3 = 5000;
Increment incr = new Increment(rowKey);
incr.addColumn(family1, qualifier1, amount1);
incr.addColumn(family2, qualifier2, amount2);
incr.addColumn(family2, qualifier2, amount3);
ReadModifyWriteRow readModifyWriteRow = ReadModifyWriteRow.create(TABLE_ID, ByteString.copyFrom(rowKey));
incrementAdapter.adapt(incr, readModifyWriteRow);
ReadModifyWriteRowRequest requestBuilder = readModifyWriteRow.toProto(requestContext);
Assert.assertEquals(2, requestBuilder.getRulesCount());
ReadModifyWriteRule rule = requestBuilder.getRules(0);
Assert.assertEquals("family1", rule.getFamilyName());
Assert.assertEquals("qualifier1", rule.getColumnQualifier().toStringUtf8());
Assert.assertEquals(amount1, rule.getIncrementAmount());
rule = requestBuilder.getRules(1);
Assert.assertEquals("family2", rule.getFamilyName());
Assert.assertEquals("qualifier2", rule.getColumnQualifier().toStringUtf8());
// amount3 since it was added after amount2:
Assert.assertEquals(amount3, rule.getIncrementAmount());
}
use of com.google.cloud.bigtable.data.v2.internal.RequestContext in project java-bigtable-hbase by googleapis.
the class TestAppendAdapter method testBasicRowKeyAppend.
@Test
public void testBasicRowKeyAppend() {
byte[] rowKey = dataHelper.randomData("rk1-");
Append append = new Append(rowKey);
ReadModifyWriteRow readModifyWriteRow = ReadModifyWriteRow.create(TABLE_ID, ByteString.copyFrom(rowKey));
appendAdapter.adapt(append, readModifyWriteRow);
ReadModifyWriteRowRequest request = readModifyWriteRow.toProto(requestContext);
ByteString adaptedRowKey = request.getRowKey();
Assert.assertArrayEquals(rowKey, adaptedRowKey.toByteArray());
}
Aggregations