Search in sources :

Example 6 with Chain

use of com.google.bigtable.v2.RowFilter.Chain in project java-bigtable-hbase by googleapis.

the class TestSingleColumnValueFilterAdapter method assertColumnSpecification.

// Assert that the given family, qualifier and versions are applied
// via the given Chain.
private static void assertColumnSpecification(byte[] family, byte[] qualifier, boolean latestOnly, RowFilter filter) throws IOException {
    Chain chain = filter.getChain();
    Assert.assertEquals(Bytes.toString(family), chain.getFilters(0).getFamilyNameRegexFilter());
    Assert.assertArrayEquals(qualifier, chain.getFilters(1).getColumnQualifierRegexFilter().toByteArray());
    if (latestOnly) {
        Assert.assertEquals(FILTERS.limit().cellsPerColumn(1).toProto(), chain.getFilters(2));
    }
}
Also used : Chain(com.google.bigtable.v2.RowFilter.Chain)

Example 7 with Chain

use of com.google.bigtable.v2.RowFilter.Chain 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 8 with Chain

use of com.google.bigtable.v2.RowFilter.Chain 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 9 with Chain

use of com.google.bigtable.v2.RowFilter.Chain in project java-bigtable by googleapis.

the class EnhancedBigtableStub method createMutateRowsBaseCallable.

/**
 * Internal helper to create the base MutateRows callable chain. The chain is responsible for
 * retrying individual entry in case of error.
 *
 * <p>NOTE: the caller is responsible for adding tracing & metrics.
 *
 * @see MutateRowsRetryingCallable for more details
 */
private UnaryCallable<MutateRowsRequest, Void> createMutateRowsBaseCallable() {
    ServerStreamingCallable<MutateRowsRequest, MutateRowsResponse> base = GrpcRawCallableFactory.createServerStreamingCallable(GrpcCallSettings.<MutateRowsRequest, MutateRowsResponse>newBuilder().setMethodDescriptor(BigtableGrpc.getMutateRowsMethod()).setParamsExtractor(new RequestParamsExtractor<MutateRowsRequest>() {

        @Override
        public Map<String, String> extract(MutateRowsRequest mutateRowsRequest) {
            return ImmutableMap.of("table_name", mutateRowsRequest.getTableName(), "app_profile_id", mutateRowsRequest.getAppProfileId());
        }
    }).build(), settings.bulkMutateRowsSettings().getRetryableCodes());
    ServerStreamingCallable<MutateRowsRequest, MutateRowsResponse> withStatsHeaders = new StatsHeadersServerStreamingCallable<>(base);
    RetryAlgorithm<Void> retryAlgorithm = new RetryAlgorithm<>(new ApiResultRetryAlgorithm<Void>(), new ExponentialRetryAlgorithm(settings.bulkMutateRowsSettings().getRetrySettings(), clientContext.getClock()));
    RetryingExecutorWithContext<Void> retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor());
    return new MutateRowsRetryingCallable(clientContext.getDefaultCallContext(), withStatsHeaders, retryingExecutor, settings.bulkMutateRowsSettings().getRetryableCodes());
}
Also used : RetryAlgorithm(com.google.api.gax.retrying.RetryAlgorithm) ExponentialRetryAlgorithm(com.google.api.gax.retrying.ExponentialRetryAlgorithm) ApiResultRetryAlgorithm(com.google.cloud.bigtable.gaxx.retrying.ApiResultRetryAlgorithm) ExponentialRetryAlgorithm(com.google.api.gax.retrying.ExponentialRetryAlgorithm) StatsHeadersServerStreamingCallable(com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersServerStreamingCallable) ScheduledRetryingExecutor(com.google.api.gax.retrying.ScheduledRetryingExecutor) MutateRowsResponse(com.google.bigtable.v2.MutateRowsResponse) MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) MutateRowsRetryingCallable(com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsRetryingCallable)

Example 10 with Chain

use of com.google.bigtable.v2.RowFilter.Chain in project java-bigtable-hbase by googleapis.

the class TestKeyOnlyFilterAdapter method stripValuesIsApplied.

@Test
public void stripValuesIsApplied() throws IOException {
    KeyOnlyFilter filter = new KeyOnlyFilter();
    Filters.Filter expectedFilter = filterAdapter.adapt(emptyScanContext, filter);
    Chain chain = expectedFilter.toProto().getChain();
    Assert.assertTrue(chain.getFilters(0).getStripValueTransformer() || chain.getFilters(1).getStripValueTransformer());
    Filters.Filter filters = filterAdapter.adapt(emptyScanContext, filter);
    Filters f = Filters.FILTERS;
    Assert.assertEquals(filters.toProto(), f.chain().filter(f.limit().cellsPerColumn(1)).filter(f.value().strip()).toProto());
}
Also used : Chain(com.google.bigtable.v2.RowFilter.Chain) KeyOnlyFilter(org.apache.hadoop.hbase.filter.KeyOnlyFilter) Filters(com.google.cloud.bigtable.data.v2.models.Filters) Test(org.junit.Test)

Aggregations

ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)7 RowFilter (com.google.bigtable.v2.RowFilter)6 HeaderTracerUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable)6 Test (org.junit.Test)6 ColumnRange (com.google.bigtable.v2.ColumnRange)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 ColumnsWithinFamilyRead (com.spotify.bigtable.read.ReadColumns.ColumnsWithinFamilyRead)5 Map (java.util.Map)5 StatsHeadersUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersUnaryCallable)4 ByteString (com.google.protobuf.ByteString)4 SpanName (com.google.api.gax.tracing.SpanName)3 TracedUnaryCallable (com.google.api.gax.tracing.TracedUnaryCallable)2 CheckAndMutateRowRequest (com.google.bigtable.v2.CheckAndMutateRowRequest)2 CheckAndMutateRowResponse (com.google.bigtable.v2.CheckAndMutateRowResponse)2 MutateRowsRequest (com.google.bigtable.v2.MutateRowsRequest)2 Chain (com.google.bigtable.v2.RowFilter.Chain)2 Query (com.google.cloud.bigtable.data.v2.models.Query)2 TracedBatcherUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.TracedBatcherUnaryCallable)2 ReadRowsUserCallable (com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsUserCallable)2 ImmutableList (com.google.common.collect.ImmutableList)2