Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import com.google.cloud.bigtable.data.v2.models.sql.PreparedStatement;
import com.google.cloud.bigtable.data.v2.models.sql.ResultSet;
import com.google.cloud.bigtable.data.v2.models.sql.SqlType;
import com.google.cloud.bigtable.data.v2.stub.BigtableClientContext;
import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub;
import com.google.cloud.bigtable.data.v2.stub.sql.SqlServerStream;
import com.google.common.util.concurrent.MoreExecutors;
Expand Down Expand Up @@ -180,17 +179,6 @@ public static BigtableDataClient create(BigtableDataSettings settings) throws IO
return new BigtableDataClient(stub);
}

/**
* Constructs an instance of BigtableDataClient with the provided client context. This is used by
* {@link BigtableDataClientFactory} and the client context will not be closed unless {@link
* BigtableDataClientFactory#close()} is called.
*/
static BigtableDataClient createWithClientContext(
BigtableDataSettings settings, BigtableClientContext context) throws IOException {
EnhancedBigtableStub stub = new EnhancedBigtableStub(settings.getStubSettings(), context);
return new BigtableDataClient(stub);
}

@InternalApi("Visible for testing")
BigtableDataClient(EnhancedBigtableStub stub) {
this.stub = stub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.google.api.core.BetaApi;
import com.google.bigtable.v2.InstanceName;
import com.google.cloud.bigtable.data.v2.stub.BigtableClientContext;
import com.google.cloud.bigtable.data.v2.stub.ClientOperationSettings;
import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub;
import java.io.IOException;
import javax.annotation.Nonnull;

Expand Down Expand Up @@ -61,9 +63,8 @@
*/
@BetaApi("This feature is currently experimental and can change in the future")
public final class BigtableDataClientFactory implements AutoCloseable {

private final BigtableDataSettings defaultSettings;
private final BigtableClientContext sharedClientContext;
private final ClientOperationSettings perOpSettings;

/**
* Create a instance of this factory.
Expand All @@ -75,13 +76,14 @@ public static BigtableDataClientFactory create(BigtableDataSettings defaultSetti
throws IOException {
BigtableClientContext sharedClientContext =
BigtableClientContext.create(defaultSettings.getStubSettings());
return new BigtableDataClientFactory(sharedClientContext, defaultSettings);
ClientOperationSettings perOpSettings = defaultSettings.getStubSettings().getPerOpSettings();
return new BigtableDataClientFactory(sharedClientContext, perOpSettings);
}

private BigtableDataClientFactory(
BigtableClientContext sharedClientContext, BigtableDataSettings defaultSettings) {
BigtableClientContext sharedClientContext, ClientOperationSettings perOpSettings) {
this.sharedClientContext = sharedClientContext;
this.defaultSettings = defaultSettings;
this.perOpSettings = perOpSettings;
}

/**
Expand Down Expand Up @@ -109,7 +111,7 @@ public BigtableDataClient createDefault() {
sharedClientContext.createChild(
sharedClientContext.getInstanceName(), sharedClientContext.getAppProfileId());

return BigtableDataClient.createWithClientContext(defaultSettings, ctx);
return new BigtableDataClient(new EnhancedBigtableStub(perOpSettings, ctx));
} catch (IOException e) {
// Should never happen because the connection has been established already
throw new RuntimeException(
Expand All @@ -127,14 +129,10 @@ public BigtableDataClient createDefault() {
* release all resources, first close all of the created clients and then this factory instance.
*/
public BigtableDataClient createForAppProfile(@Nonnull String appProfileId) throws IOException {
BigtableDataSettings settings =
defaultSettings.toBuilder().setAppProfileId(appProfileId).build();
BigtableClientContext ctx =
sharedClientContext.createChild(
InstanceName.of(settings.getProjectId(), settings.getInstanceId()),
settings.getAppProfileId());
sharedClientContext.createChild(sharedClientContext.getInstanceName(), appProfileId);

return BigtableDataClient.createWithClientContext(settings, ctx);
return new BigtableDataClient(new EnhancedBigtableStub(perOpSettings, ctx));
}

/**
Expand All @@ -148,18 +146,10 @@ public BigtableDataClient createForAppProfile(@Nonnull String appProfileId) thro
*/
public BigtableDataClient createForInstance(@Nonnull String projectId, @Nonnull String instanceId)
throws IOException {
BigtableDataSettings settings =
defaultSettings.toBuilder()
.setProjectId(projectId)
.setInstanceId(instanceId)
.setDefaultAppProfileId()
.build();
BigtableClientContext ctx =
sharedClientContext.createChild(
InstanceName.of(settings.getProjectId(), settings.getInstanceId()),
settings.getAppProfileId());
sharedClientContext.createChild(InstanceName.of(projectId, instanceId), "");
Comment thread
igorbernstein2 marked this conversation as resolved.

return BigtableDataClient.createWithClientContext(settings, ctx);
return new BigtableDataClient(new EnhancedBigtableStub(perOpSettings, ctx));
}

/**
Expand All @@ -174,17 +164,9 @@ public BigtableDataClient createForInstance(@Nonnull String projectId, @Nonnull
public BigtableDataClient createForInstance(
@Nonnull String projectId, @Nonnull String instanceId, @Nonnull String appProfileId)
throws IOException {
BigtableDataSettings settings =
defaultSettings.toBuilder()
.setProjectId(projectId)
.setInstanceId(instanceId)
.setAppProfileId(appProfileId)
.build();
BigtableClientContext ctx =
sharedClientContext.createChild(
InstanceName.of(settings.getProjectId(), settings.getInstanceId()),
settings.getAppProfileId());
sharedClientContext.createChild(InstanceName.of(projectId, instanceId), appProfileId);

return BigtableDataClient.createWithClientContext(settings, ctx);
return new BigtableDataClient(new EnhancedBigtableStub(perOpSettings, ctx));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.cloud.bigtable.data.v2.stub;

import com.google.api.core.InternalApi;
import com.google.api.gax.batching.BatchingSettings;
import com.google.api.gax.batching.FlowControlSettings;
import com.google.api.gax.batching.FlowController;
Expand Down Expand Up @@ -45,7 +46,8 @@
import java.util.Set;
import org.threeten.bp.Duration;

class ClientOperationSettings {
@InternalApi
public class ClientOperationSettings {
private static final Set<StatusCode.Code> IDEMPOTENT_RETRY_CODES =
ImmutableSet.of(StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE);

Expand Down
Loading
Loading