Search in sources :

Example 16 with RequestContext

use of com.google.cloud.bigtable.data.v2.internal.RequestContext in project java-bigtable by googleapis.

the class EnhancedBigtableStub method createCheckAndMutateRowCallable.

/**
 * Creates a callable chain to handle CheckAndMutateRow RPCs. THe chain will:
 *
 * <ul>
 *   <li>Convert {@link ConditionalRowMutation}s into {@link
 *       com.google.bigtable.v2.CheckAndMutateRowRequest}s.
 *   <li>Add tracing & metrics.
 * </ul>
 */
private UnaryCallable<ConditionalRowMutation, Boolean> createCheckAndMutateRowCallable() {
    String methodName = "CheckAndMutateRow";
    UnaryCallable<CheckAndMutateRowRequest, CheckAndMutateRowResponse> base = GrpcRawCallableFactory.createUnaryCallable(GrpcCallSettings.<CheckAndMutateRowRequest, CheckAndMutateRowResponse>newBuilder().setMethodDescriptor(BigtableGrpc.getCheckAndMutateRowMethod()).setParamsExtractor(new RequestParamsExtractor<CheckAndMutateRowRequest>() {

        @Override
        public Map<String, String> extract(CheckAndMutateRowRequest checkAndMutateRowRequest) {
            return ImmutableMap.of("table_name", checkAndMutateRowRequest.getTableName(), "app_profile_id", checkAndMutateRowRequest.getAppProfileId());
        }
    }).build(), settings.checkAndMutateRowSettings().getRetryableCodes());
    UnaryCallable<CheckAndMutateRowRequest, CheckAndMutateRowResponse> withStatsHeaders = new StatsHeadersUnaryCallable<>(base);
    UnaryCallable<CheckAndMutateRowRequest, CheckAndMutateRowResponse> withHeaderTracer = new HeaderTracerUnaryCallable<>(withStatsHeaders);
    UnaryCallable<CheckAndMutateRowRequest, CheckAndMutateRowResponse> retrying = Callables.retrying(withHeaderTracer, settings.checkAndMutateRowSettings(), clientContext);
    return createUserFacingUnaryCallable(methodName, new CheckAndMutateRowCallable(retrying, requestContext));
}
Also used : HeaderTracerUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable) CheckAndMutateRowResponse(com.google.bigtable.v2.CheckAndMutateRowResponse) 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) CheckAndMutateRowRequest(com.google.bigtable.v2.CheckAndMutateRowRequest)

Example 17 with RequestContext

use of com.google.cloud.bigtable.data.v2.internal.RequestContext in project java-bigtable by googleapis.

the class EnhancedBigtableStub method createReadRowsCallable.

/**
 * Creates a callable chain to handle streaming ReadRows RPCs. The chain will:
 *
 * <ul>
 *   <li>Convert a {@link Query} into a {@link com.google.bigtable.v2.ReadRowsRequest} and
 *       dispatch the RPC.
 *   <li>Upon receiving the response stream, it will merge the {@link
 *       com.google.bigtable.v2.ReadRowsResponse.CellChunk}s in logical rows. The actual row
 *       implementation can be configured in by the {@code rowAdapter} parameter.
 *   <li>Retry/resume on failure.
 *   <li>Filter out marker rows.
 *   <li>Add tracing & metrics.
 * </ul>
 */
public <RowT> ServerStreamingCallable<Query, RowT> createReadRowsCallable(RowAdapter<RowT> rowAdapter) {
    ServerStreamingCallable<ReadRowsRequest, RowT> readRowsCallable = createReadRowsBaseCallable(settings.readRowsSettings(), rowAdapter);
    ServerStreamingCallable<Query, RowT> readRowsUserCallable = new ReadRowsUserCallable<>(readRowsCallable, requestContext);
    SpanName span = getSpanName("ReadRows");
    ServerStreamingCallable<Query, RowT> traced = new TracedServerStreamingCallable<>(readRowsUserCallable, clientContext.getTracerFactory(), span);
    return traced.withDefaultCallContext(clientContext.getDefaultCallContext());
}
Also used : ReadRowsUserCallable(com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsUserCallable) SpanName(com.google.api.gax.tracing.SpanName) TracedServerStreamingCallable(com.google.api.gax.tracing.TracedServerStreamingCallable) Query(com.google.cloud.bigtable.data.v2.models.Query) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest)

Example 18 with RequestContext

use of com.google.cloud.bigtable.data.v2.internal.RequestContext in project java-bigtable by googleapis.

the class EnhancedBigtableStub method createSampleRowKeysCallable.

/**
 * Creates a callable chain to handle SampleRowKeys RPcs. The chain will:
 *
 * <ul>
 *   <li>Convert a table id to a {@link com.google.bigtable.v2.SampleRowKeysRequest}.
 *   <li>Dispatch the request to the GAPIC's {@link BigtableStub#sampleRowKeysCallable()}.
 *   <li>Spool responses into a list.
 *   <li>Retry on failure.
 *   <li>Convert the responses into {@link KeyOffset}s.
 *   <li>Add tracing & metrics.
 * </ul>
 */
private UnaryCallable<String, List<KeyOffset>> createSampleRowKeysCallable() {
    String methodName = "SampleRowKeys";
    ServerStreamingCallable<SampleRowKeysRequest, SampleRowKeysResponse> base = GrpcRawCallableFactory.createServerStreamingCallable(GrpcCallSettings.<SampleRowKeysRequest, SampleRowKeysResponse>newBuilder().setMethodDescriptor(BigtableGrpc.getSampleRowKeysMethod()).setParamsExtractor(new RequestParamsExtractor<SampleRowKeysRequest>() {

        @Override
        public Map<String, String> extract(SampleRowKeysRequest sampleRowKeysRequest) {
            return ImmutableMap.of("table_name", sampleRowKeysRequest.getTableName(), "app_profile_id", sampleRowKeysRequest.getAppProfileId());
        }
    }).build(), settings.sampleRowKeysSettings().getRetryableCodes());
    UnaryCallable<SampleRowKeysRequest, List<SampleRowKeysResponse>> spoolable = base.all();
    UnaryCallable<SampleRowKeysRequest, List<SampleRowKeysResponse>> withStatsHeaders = new StatsHeadersUnaryCallable<>(spoolable);
    UnaryCallable<SampleRowKeysRequest, List<SampleRowKeysResponse>> withHeaderTracer = new HeaderTracerUnaryCallable<>(withStatsHeaders);
    UnaryCallable<SampleRowKeysRequest, List<SampleRowKeysResponse>> retryable = Callables.retrying(withHeaderTracer, settings.sampleRowKeysSettings(), clientContext);
    return createUserFacingUnaryCallable(methodName, new SampleRowKeysCallable(retryable, requestContext));
}
Also used : SampleRowKeysResponse(com.google.bigtable.v2.SampleRowKeysResponse) HeaderTracerUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable) SampleRowKeysRequest(com.google.bigtable.v2.SampleRowKeysRequest) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) 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 19 with RequestContext

use of com.google.cloud.bigtable.data.v2.internal.RequestContext in project java-bigtable by googleapis.

the class EnhancedBigtableStub method createBulkReadRowsCallable.

/**
 * Creates a callable chain to handle bulk ReadRows RPCs. This is meant to be used in ReadRows
 * batcher. The chain will:
 *
 * <ul>
 *   <li>Convert a {@link Query} into a {@link com.google.bigtable.v2.ReadRowsRequest}.
 *   <li>Upon receiving the response stream, it will merge the {@link
 *       com.google.bigtable.v2.ReadRowsResponse.CellChunk}s in logical rows. The actual row
 *       implementation can be configured in by the {@code rowAdapter} parameter.
 *   <li>Retry/resume on failure.
 *   <li>Filter out marker rows.
 *   <li>Construct a {@link UnaryCallable} that will buffer the entire stream into memory before
 *       completing. If the stream is empty, then the list will be empty.
 *   <li>Add tracing & metrics.
 * </ul>
 */
private <RowT> UnaryCallable<Query, List<RowT>> createBulkReadRowsCallable(RowAdapter<RowT> rowAdapter) {
    ServerStreamingCallable<ReadRowsRequest, RowT> readRowsCallable = createReadRowsBaseCallable(settings.readRowsSettings(), rowAdapter);
    ServerStreamingCallable<Query, RowT> readRowsUserCallable = new ReadRowsUserCallable<>(readRowsCallable, requestContext);
    SpanName span = getSpanName("ReadRows");
    // The TracedBatcherUnaryCallable has to be wrapped by the TracedUnaryCallable, so that
    // TracedUnaryCallable can inject a tracer for the TracedBatcherUnaryCallable to interact with
    UnaryCallable<Query, List<RowT>> tracedBatcher = new TracedBatcherUnaryCallable<>(readRowsUserCallable.all());
    UnaryCallable<Query, List<RowT>> withHeaderTracer = new HeaderTracerUnaryCallable(tracedBatcher);
    UnaryCallable<Query, List<RowT>> traced = new TracedUnaryCallable<>(withHeaderTracer, clientContext.getTracerFactory(), span);
    return traced.withDefaultCallContext(clientContext.getDefaultCallContext());
}
Also used : ReadRowsUserCallable(com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsUserCallable) SpanName(com.google.api.gax.tracing.SpanName) TracedUnaryCallable(com.google.api.gax.tracing.TracedUnaryCallable) HeaderTracerUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable) Query(com.google.cloud.bigtable.data.v2.models.Query) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) TracedBatcherUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.TracedBatcherUnaryCallable)

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