Search in sources :

Example 6 with RequestContext

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));
}
Also used : MutateRowRequest(com.google.bigtable.v2.MutateRowRequest) CheckAndMutateRowRequest(com.google.bigtable.v2.CheckAndMutateRowRequest) CheckAndMutateRowResponse(com.google.bigtable.v2.CheckAndMutateRowResponse) MutateRowResponse(com.google.bigtable.v2.MutateRowResponse) HeaderTracerUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable) StatsHeadersUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersUnaryCallable) ByteString(com.google.protobuf.ByteString) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with 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());
}
Also used : BulkMutation(com.google.cloud.bigtable.data.v2.models.BulkMutation) BulkMutateRowsUserFacingCallable(com.google.cloud.bigtable.data.v2.stub.mutaterows.BulkMutateRowsUserFacingCallable) SpanName(com.google.api.gax.tracing.SpanName) TracedUnaryCallable(com.google.api.gax.tracing.TracedUnaryCallable) HeaderTracerUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable) MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) TracedBatcherUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.TracedBatcherUnaryCallable)

Example 8 with RequestContext

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());
}
Also used : ReadModifyWriteRowRequest(com.google.bigtable.v2.ReadModifyWriteRowRequest) ByteString(com.google.protobuf.ByteString) Increment(org.apache.hadoop.hbase.client.Increment) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Example 9 with RequestContext

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());
}
Also used : ReadModifyWriteRowRequest(com.google.bigtable.v2.ReadModifyWriteRowRequest) Increment(org.apache.hadoop.hbase.client.Increment) ReadModifyWriteRule(com.google.bigtable.v2.ReadModifyWriteRule) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Example 10 with RequestContext

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());
}
Also used : Append(org.apache.hadoop.hbase.client.Append) ReadModifyWriteRowRequest(com.google.bigtable.v2.ReadModifyWriteRowRequest) ByteString(com.google.protobuf.ByteString) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 ReadModifyWriteRowRequest (com.google.bigtable.v2.ReadModifyWriteRowRequest)9 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)8 ByteString (com.google.protobuf.ByteString)7 ReadModifyWriteRule (com.google.bigtable.v2.ReadModifyWriteRule)6 HeaderTracerUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable)6 StatsHeadersUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersUnaryCallable)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Map (java.util.Map)4 Append (org.apache.hadoop.hbase.client.Append)4 Increment (org.apache.hadoop.hbase.client.Increment)4 SpanName (com.google.api.gax.tracing.SpanName)3 Filters (com.google.cloud.bigtable.data.v2.models.Filters)3 Query (com.google.cloud.bigtable.data.v2.models.Query)3 TracedUnaryCallable (com.google.api.gax.tracing.TracedUnaryCallable)2 CheckAndMutateRowRequest (com.google.bigtable.v2.CheckAndMutateRowRequest)2 CheckAndMutateRowResponse (com.google.bigtable.v2.CheckAndMutateRowResponse)2 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)2 BulkMutation (com.google.cloud.bigtable.data.v2.models.BulkMutation)2 TracedBatcherUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.TracedBatcherUnaryCallable)2