Search in sources :

Example 1 with GrpcCallContext

use of com.google.api.gax.grpc.GrpcCallContext in project java-bigtable-hbase by googleapis.

the class DataClientVeneerApi method createScanCallContext.

// Support 2 bigtable-hbase features not directly available in veneer:
// - per attempt deadlines - vener doesn't implement deadlines for attempts. To workaround this,
// the timeouts are set per call in the ApiCallContext. However this creates a separate issue of
// over running the operation deadline, so gRPC deadline is also set.
private GrpcCallContext createScanCallContext() {
    GrpcCallContext ctx = GrpcCallContext.createDefault();
    OperationTimeouts callSettings = clientOperationTimeouts.getScanTimeouts();
    if (callSettings.getOperationTimeout().isPresent()) {
        ctx = ctx.withCallOptions(CallOptions.DEFAULT.withDeadline(Deadline.after(callSettings.getOperationTimeout().get().toMillis(), TimeUnit.MILLISECONDS)));
    }
    if (callSettings.getAttemptTimeout().isPresent()) {
        ctx = ctx.withTimeout(callSettings.getAttemptTimeout().get());
    }
    return ctx;
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) ClientOperationTimeouts(com.google.cloud.bigtable.hbase.wrappers.veneer.BigtableHBaseVeneerSettings.ClientOperationTimeouts) OperationTimeouts(com.google.cloud.bigtable.hbase.wrappers.veneer.BigtableHBaseVeneerSettings.OperationTimeouts)

Example 2 with GrpcCallContext

use of com.google.api.gax.grpc.GrpcCallContext in project java-bigtable-hbase by googleapis.

the class DataClientVeneerApi method createReadRowCallContext.

// Point reads are implemented using a streaming ReadRows RPC. So timeouts need to be managed
// similar to scans below.
private ApiCallContext createReadRowCallContext() {
    GrpcCallContext ctx = GrpcCallContext.createDefault();
    OperationTimeouts callSettings = clientOperationTimeouts.getUnaryTimeouts();
    if (callSettings.getAttemptTimeout().isPresent()) {
        ctx = ctx.withTimeout(callSettings.getAttemptTimeout().get());
    }
    // Fix it by settings the underlying grpc deadline
    if (callSettings.getOperationTimeout().isPresent()) {
        ctx = ctx.withCallOptions(CallOptions.DEFAULT.withDeadline(Deadline.after(callSettings.getOperationTimeout().get().toMillis(), TimeUnit.MILLISECONDS)));
    }
    return ctx;
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) ClientOperationTimeouts(com.google.cloud.bigtable.hbase.wrappers.veneer.BigtableHBaseVeneerSettings.ClientOperationTimeouts) OperationTimeouts(com.google.cloud.bigtable.hbase.wrappers.veneer.BigtableHBaseVeneerSettings.OperationTimeouts)

Example 3 with GrpcCallContext

use of com.google.api.gax.grpc.GrpcCallContext in project java-bigtable by googleapis.

the class EnhancedBigtableStubTest method testCallContextPropagatedInMutationBatcher.

@Test
public void testCallContextPropagatedInMutationBatcher() throws IOException, InterruptedException, ExecutionException {
    EnhancedBigtableStubSettings settings = defaultSettings.toBuilder().setRefreshingChannel(true).setPrimedTableIds("table1", "table2").build();
    try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings)) {
        // clear the previous contexts
        contextInterceptor.contexts.clear();
        // Override the timeout
        GrpcCallContext clientCtx = GrpcCallContext.createDefault().withTimeout(Duration.ofMinutes(10));
        // Send a batch
        try (Batcher<RowMutationEntry, Void> batcher = stub.newMutateRowsBatcher("table1", clientCtx)) {
            batcher.add(RowMutationEntry.create("key").deleteRow()).get();
        }
        // Ensure that the server got the overriden deadline
        Context serverCtx = contextInterceptor.contexts.poll();
        assertThat(serverCtx).isNotNull();
        assertThat(serverCtx.getDeadline()).isAtLeast(Deadline.after(8, TimeUnit.MINUTES));
    }
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) Context(io.grpc.Context) RequestContext(com.google.cloud.bigtable.data.v2.internal.RequestContext) GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) Test(org.junit.Test)

Example 4 with GrpcCallContext

use of com.google.api.gax.grpc.GrpcCallContext in project java-bigtable by googleapis.

the class EnhancedBigtableStubTest method testCallContextPropagatedInReadBatcher.

@Test
public void testCallContextPropagatedInReadBatcher() throws IOException, InterruptedException, ExecutionException {
    EnhancedBigtableStubSettings settings = defaultSettings.toBuilder().setRefreshingChannel(true).setPrimedTableIds("table1", "table2").build();
    try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings)) {
        // clear the previous contexts
        contextInterceptor.contexts.clear();
        // Override the timeout
        GrpcCallContext clientCtx = GrpcCallContext.createDefault().withTimeout(Duration.ofMinutes(10));
        // Send a batch
        try (Batcher<ByteString, Row> batcher = stub.newBulkReadRowsBatcher(Query.create("table1"), clientCtx)) {
            batcher.add(ByteString.copyFromUtf8("key")).get();
        }
        // Ensure that the server got the overriden deadline
        Context serverCtx = contextInterceptor.contexts.poll();
        assertThat(serverCtx).isNotNull();
        assertThat(serverCtx.getDeadline()).isAtLeast(Deadline.after(8, TimeUnit.MINUTES));
    }
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) Context(io.grpc.Context) RequestContext(com.google.cloud.bigtable.data.v2.internal.RequestContext) GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) ByteString(com.google.protobuf.ByteString) Row(com.google.cloud.bigtable.data.v2.models.Row) Test(org.junit.Test)

Aggregations

GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)4 RequestContext (com.google.cloud.bigtable.data.v2.internal.RequestContext)2 ClientOperationTimeouts (com.google.cloud.bigtable.hbase.wrappers.veneer.BigtableHBaseVeneerSettings.ClientOperationTimeouts)2 OperationTimeouts (com.google.cloud.bigtable.hbase.wrappers.veneer.BigtableHBaseVeneerSettings.OperationTimeouts)2 Context (io.grpc.Context)2 Test (org.junit.Test)2 Row (com.google.cloud.bigtable.data.v2.models.Row)1 RowMutationEntry (com.google.cloud.bigtable.data.v2.models.RowMutationEntry)1 ByteString (com.google.protobuf.ByteString)1