Search in sources :

Example 11 with BigtableDataSettings

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings in project java-bigtable-hbase by googleapis.

the class TestBigtableHBaseVeneerSettings method testVerifyRetrySettings.

@Ignore("Re-enable this test once veneer default align with hbase")
@Test
public void testVerifyRetrySettings() throws IOException {
    BigtableDataSettings dataSettings = BigtableHBaseVeneerSettings.create(configuration).getDataSettings();
    BigtableDataSettings defaultDataSettings = BigtableDataSettings.newBuilder().setProjectId("project-id").setInstanceId("instance-id").build();
    assertEquals(defaultDataSettings.getStubSettings().readRowsSettings().getRetryableCodes(), dataSettings.getStubSettings().readRowsSettings().getRetryableCodes());
    // Unary operation's RetrySettings & RetryCodes of retryable methods.
    assertRetriableOperation(defaultDataSettings.getStubSettings().readRowSettings(), dataSettings.getStubSettings().readRowSettings());
    assertRetriableOperation(defaultDataSettings.getStubSettings().mutateRowSettings(), dataSettings.getStubSettings().mutateRowSettings());
    assertRetriableOperation(defaultDataSettings.getStubSettings().sampleRowKeysSettings(), dataSettings.getStubSettings().sampleRowKeysSettings());
    // Non-streaming operation's verifying RetrySettings & RetryCodes of non-retryable methods.
    assertNonRetriableOperation(defaultDataSettings.getStubSettings().readModifyWriteRowSettings(), dataSettings.getStubSettings().readModifyWriteRowSettings());
    assertNonRetriableOperation(defaultDataSettings.getStubSettings().checkAndMutateRowSettings(), dataSettings.getStubSettings().checkAndMutateRowSettings());
}
Also used : BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with BigtableDataSettings

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings in project java-bigtable-hbase by googleapis.

the class SharedDataClientWrapperFactory method createDataClient.

synchronized DataClientWrapper createDataClient(BigtableHBaseVeneerSettings settings) throws IOException {
    Preconditions.checkArgument(!settings.getDataSettings().isRefreshingChannel(), "Channel refreshing is not compatible with cached channel pools");
    Key key = Key.createFromSettings(settings.getDataSettings());
    // Get or create ClientContext that will contained the shared resources
    ClientContext sharedCtx = cachedContexts.get(key);
    if (sharedCtx == null) {
        EnhancedBigtableStubSettings stubSettings = settings.getDataSettings().getStubSettings();
        sharedCtx = ClientContext.create(stubSettings);
        cachedContexts.put(key, sharedCtx);
        refCounts.put(key, 0);
        int channelPoolSize = BigtableVeneerApi.getChannelPoolSize(stubSettings);
        for (int i = 0; i < channelPoolSize; i++) {
            BigtableClientMetrics.counter(MetricLevel.Info, "grpc.channel.active").inc();
        }
        channelPoolSizes.put(key, channelPoolSize);
    }
    // Increment the count
    refCounts.put(key, refCounts.get(key) + 1);
    try {
        // Patch settings to use shared resources
        Builder builder = settings.getDataSettings().toBuilder();
        builder.stubSettings().setTransportChannelProvider(FixedTransportChannelProvider.create(sharedCtx.getTransportChannel())).setCredentialsProvider(FixedCredentialsProvider.create(sharedCtx.getCredentials())).setExecutorProvider(FixedExecutorProvider.create(sharedCtx.getExecutor())).setStreamWatchdogProvider(FixedWatchdogProvider.create(sharedCtx.getStreamWatchdog())).setHeaderProvider(FixedHeaderProvider.create(sharedCtx.getHeaders())).setClock(sharedCtx.getClock());
        BigtableDataSettings data = builder.build();
        // Create a reference counted client wrapper
        return new SharedDataClientWrapper(this, key, new DataClientVeneerApi(BigtableDataClient.create(data), settings.getClientTimeouts()));
    } catch (IOException | RuntimeException e) {
        release(key);
        throw e;
    }
}
Also used : EnhancedBigtableStubSettings(com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings) ClientContext(com.google.api.gax.rpc.ClientContext) Builder(com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder) IOException(java.io.IOException) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings)

Example 13 with BigtableDataSettings

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings in project java-bigtable-hbase by googleapis.

the class BigtableHBaseVeneerSettings method buildBigtableDataSettings.

// ************** Private Helpers **************
private BigtableDataSettings buildBigtableDataSettings(ClientOperationTimeouts clientTimeouts) throws IOException {
    BigtableDataSettings.Builder dataBuilder;
    // Configure the Data connection
    Optional<String> emulatorEndpoint = Optional.fromNullable(configuration.get(BIGTABLE_EMULATOR_HOST_KEY));
    if (emulatorEndpoint.isPresent()) {
        int split = emulatorEndpoint.get().lastIndexOf(':');
        String host = emulatorEndpoint.get().substring(0, split);
        int port = Integer.parseInt(emulatorEndpoint.get().substring(split + 1));
        dataBuilder = BigtableDataSettings.newBuilderForEmulator(host, port);
    } else {
        dataBuilder = BigtableDataSettings.newBuilder();
        configureConnection(dataBuilder.stubSettings(), BIGTABLE_HOST_KEY);
        configureCredentialProvider(dataBuilder.stubSettings());
    }
    configureHeaderProvider(dataBuilder.stubSettings());
    // Configure the target
    dataBuilder.setProjectId(getProjectId()).setInstanceId(getInstanceId());
    String appProfileId = configuration.get(APP_PROFILE_ID_KEY);
    if (!Strings.isNullOrEmpty(appProfileId)) {
        dataBuilder.setAppProfileId(appProfileId);
    }
    // Configure metrics
    configureMetricsBridge(dataBuilder);
    // Configure RPCs - this happens in two parts:
    // - most of the timeouts are defined here
    // - attempt timeouts for readRows is set in DataClientVeneerApi to workaround lack of attempt
    // timeouts for streaming RPCs
    // Complex RPC method settings
    configureBulkMutationSettings(dataBuilder.stubSettings().bulkMutateRowsSettings(), clientTimeouts.getBulkMutateTimeouts());
    configureBulkReadRowsSettings(dataBuilder.stubSettings().bulkReadRowsSettings(), clientTimeouts.getScanTimeouts());
    configureReadRowsSettings(dataBuilder.stubSettings().readRowsSettings(), clientTimeouts.getScanTimeouts());
    // RPC methods - simple
    configureNonRetryableCallSettings(dataBuilder.stubSettings().checkAndMutateRowSettings(), clientTimeouts.getUnaryTimeouts());
    configureNonRetryableCallSettings(dataBuilder.stubSettings().readModifyWriteRowSettings(), clientTimeouts.getUnaryTimeouts());
    configureRetryableCallSettings(dataBuilder.stubSettings().mutateRowSettings(), clientTimeouts.getUnaryTimeouts());
    configureRetryableCallSettings(dataBuilder.stubSettings().readRowSettings(), clientTimeouts.getUnaryTimeouts());
    configureRetryableCallSettings(dataBuilder.stubSettings().sampleRowKeysSettings(), clientTimeouts.getUnaryTimeouts());
    return dataBuilder.build();
}
Also used : Builder(com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings)

Example 14 with BigtableDataSettings

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

the class HeaderTracerCallableTest method setUp.

@Before
public void setUp() throws Exception {
    RpcViews.registerBigtableClientGfeViews(localStats.getViewManager());
    // Create a server that'll inject a server-timing header with a random number and a stub that
    // connects to this server.
    fakeServerTiming = new AtomicInteger(new Random().nextInt(1000) + 1);
    server = FakeServiceBuilder.create(fakeService).intercept(new ServerInterceptor() {

        @Override
        public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> serverCall, Metadata metadata, ServerCallHandler<ReqT, RespT> serverCallHandler) {
            return serverCallHandler.startCall(new SimpleForwardingServerCall<ReqT, RespT>(serverCall) {

                @Override
                public void sendHeaders(Metadata headers) {
                    headers.put(Metadata.Key.of("server-timing", Metadata.ASCII_STRING_MARSHALLER), String.format("gfet4t7; dur=%d", fakeServerTiming.get()));
                    super.sendHeaders(headers);
                }
            }, metadata);
        }
    }).start();
    BigtableDataSettings settings = BigtableDataSettings.newBuilderForEmulator(server.getPort()).setProjectId(PROJECT_ID).setInstanceId(INSTANCE_ID).setAppProfileId(APP_PROFILE_ID).build();
    EnhancedBigtableStubSettings stubSettings = EnhancedBigtableStub.finalizeSettings(settings.getStubSettings(), Tags.getTagger(), localStats.getStatsRecorder());
    attempts = stubSettings.readRowsSettings().getRetrySettings().getMaxAttempts();
    stub = new EnhancedBigtableStub(stubSettings, ClientContext.create(stubSettings));
    // Create another server without injecting the server-timing header and another stub that
    // connects to it.
    serverNoHeader = FakeServiceBuilder.create(fakeService).start();
    BigtableDataSettings noHeaderSettings = BigtableDataSettings.newBuilderForEmulator(serverNoHeader.getPort()).setProjectId(PROJECT_ID).setInstanceId(INSTANCE_ID).setAppProfileId(APP_PROFILE_ID).build();
    EnhancedBigtableStubSettings noHeaderStubSettings = EnhancedBigtableStub.finalizeSettings(noHeaderSettings.getStubSettings(), Tags.getTagger(), localStats.getStatsRecorder());
    noHeaderStub = new EnhancedBigtableStub(noHeaderStubSettings, ClientContext.create(noHeaderStubSettings));
}
Also used : Metadata(io.grpc.Metadata) SimpleForwardingServerCall(io.grpc.ForwardingServerCall.SimpleForwardingServerCall) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) EnhancedBigtableStubSettings(com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerInterceptor(io.grpc.ServerInterceptor) EnhancedBigtableStub(com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub) Before(org.junit.Before)

Example 15 with BigtableDataSettings

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

the class BigtableDataSettingsTest method testToString.

@Test
public void testToString() {
    BigtableDataSettings settings = BigtableDataSettings.newBuilder().setProjectId("our-project-2-12").setInstanceId("our-instance-85").setAppProfileId("our-appProfile-06").enableBatchMutationLatencyBasedThrottling(10).build();
    EnhancedBigtableStubSettings stubSettings = settings.getStubSettings();
    assertThat(settings.toString()).isEqualTo("BigtableDataSettings{stubSettings=" + stubSettings.toString() + "}");
}
Also used : EnhancedBigtableStubSettings(com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings) Test(org.junit.Test)

Aggregations

BigtableDataSettings (com.google.cloud.bigtable.data.v2.BigtableDataSettings)21 Test (org.junit.Test)12 BigtableTableAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings)5 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)5 InstantiatingGrpcChannelProvider (com.google.api.gax.grpc.InstantiatingGrpcChannelProvider)3 EnhancedBigtableStubSettings (com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings)3 Before (org.junit.Before)3 NoCredentialsProvider (com.google.api.gax.core.NoCredentialsProvider)2 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)2 BigtableInstanceAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings)2 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)2 Builder (com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder)2 Row (com.google.cloud.bigtable.data.v2.models.Row)2 ByteString (com.google.protobuf.ByteString)2 IOException (java.io.IOException)2 Ignore (org.junit.Ignore)2 ApiFunction (com.google.api.core.ApiFunction)1 BatcherImpl (com.google.api.gax.batching.BatcherImpl)1 BatchingSettings (com.google.api.gax.batching.BatchingSettings)1 FlowControlEventStats (com.google.api.gax.batching.FlowControlEventStats)1