Skip to content

Commit b70f83e

Browse files
chore: decompose stubsettings into perOpSettings & BtClientContext
This avoids any overlap between the 2 classes being passed to a stub and avoids setting inconsistencies Change-Id: I22beae49e1e4118930c7ed9636576a42d397f7ce
1 parent e67d869 commit b70f83e

File tree

8 files changed

+82
-105
lines changed

8 files changed

+82
-105
lines changed

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import com.google.cloud.bigtable.data.v2.models.sql.PreparedStatement;
5555
import com.google.cloud.bigtable.data.v2.models.sql.ResultSet;
5656
import com.google.cloud.bigtable.data.v2.models.sql.SqlType;
57-
import com.google.cloud.bigtable.data.v2.stub.BigtableClientContext;
5857
import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub;
5958
import com.google.cloud.bigtable.data.v2.stub.sql.SqlServerStream;
6059
import com.google.common.util.concurrent.MoreExecutors;
@@ -180,17 +179,6 @@ public static BigtableDataClient create(BigtableDataSettings settings) throws IO
180179
return new BigtableDataClient(stub);
181180
}
182181

183-
/**
184-
* Constructs an instance of BigtableDataClient with the provided client context. This is used by
185-
* {@link BigtableDataClientFactory} and the client context will not be closed unless {@link
186-
* BigtableDataClientFactory#close()} is called.
187-
*/
188-
static BigtableDataClient createWithClientContext(
189-
BigtableDataSettings settings, BigtableClientContext context) throws IOException {
190-
EnhancedBigtableStub stub = new EnhancedBigtableStub(settings.getStubSettings(), context);
191-
return new BigtableDataClient(stub);
192-
}
193-
194182
@InternalApi("Visible for testing")
195183
BigtableDataClient(EnhancedBigtableStub stub) {
196184
this.stub = stub;

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactory.java

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import com.google.api.core.BetaApi;
1919
import com.google.bigtable.v2.InstanceName;
2020
import com.google.cloud.bigtable.data.v2.stub.BigtableClientContext;
21+
import com.google.cloud.bigtable.data.v2.stub.ClientOperationSettings;
22+
import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub;
2123
import java.io.IOException;
2224
import javax.annotation.Nonnull;
2325

@@ -61,9 +63,8 @@
6163
*/
6264
@BetaApi("This feature is currently experimental and can change in the future")
6365
public final class BigtableDataClientFactory implements AutoCloseable {
64-
65-
private final BigtableDataSettings defaultSettings;
6666
private final BigtableClientContext sharedClientContext;
67+
private final ClientOperationSettings perOpSettings;
6768

6869
/**
6970
* Create a instance of this factory.
@@ -75,13 +76,14 @@ public static BigtableDataClientFactory create(BigtableDataSettings defaultSetti
7576
throws IOException {
7677
BigtableClientContext sharedClientContext =
7778
BigtableClientContext.create(defaultSettings.getStubSettings());
78-
return new BigtableDataClientFactory(sharedClientContext, defaultSettings);
79+
ClientOperationSettings perOpSettings = defaultSettings.getStubSettings().getPerOpSettings();
80+
return new BigtableDataClientFactory(sharedClientContext, perOpSettings);
7981
}
8082

8183
private BigtableDataClientFactory(
82-
BigtableClientContext sharedClientContext, BigtableDataSettings defaultSettings) {
84+
BigtableClientContext sharedClientContext, ClientOperationSettings perOpSettings) {
8385
this.sharedClientContext = sharedClientContext;
84-
this.defaultSettings = defaultSettings;
86+
this.perOpSettings = perOpSettings;
8587
}
8688

8789
/**
@@ -109,7 +111,7 @@ public BigtableDataClient createDefault() {
109111
sharedClientContext.createChild(
110112
sharedClientContext.getInstanceName(), sharedClientContext.getAppProfileId());
111113

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

137-
return BigtableDataClient.createWithClientContext(settings, ctx);
135+
return new BigtableDataClient(new EnhancedBigtableStub(perOpSettings, ctx));
138136
}
139137

140138
/**
@@ -148,18 +146,10 @@ public BigtableDataClient createForAppProfile(@Nonnull String appProfileId) thro
148146
*/
149147
public BigtableDataClient createForInstance(@Nonnull String projectId, @Nonnull String instanceId)
150148
throws IOException {
151-
BigtableDataSettings settings =
152-
defaultSettings.toBuilder()
153-
.setProjectId(projectId)
154-
.setInstanceId(instanceId)
155-
.setDefaultAppProfileId()
156-
.build();
157149
BigtableClientContext ctx =
158-
sharedClientContext.createChild(
159-
InstanceName.of(settings.getProjectId(), settings.getInstanceId()),
160-
settings.getAppProfileId());
150+
sharedClientContext.createChild(InstanceName.of(projectId, instanceId), "");
161151

162-
return BigtableDataClient.createWithClientContext(settings, ctx);
152+
return new BigtableDataClient(new EnhancedBigtableStub(perOpSettings, ctx));
163153
}
164154

165155
/**
@@ -174,17 +164,9 @@ public BigtableDataClient createForInstance(@Nonnull String projectId, @Nonnull
174164
public BigtableDataClient createForInstance(
175165
@Nonnull String projectId, @Nonnull String instanceId, @Nonnull String appProfileId)
176166
throws IOException {
177-
BigtableDataSettings settings =
178-
defaultSettings.toBuilder()
179-
.setProjectId(projectId)
180-
.setInstanceId(instanceId)
181-
.setAppProfileId(appProfileId)
182-
.build();
183167
BigtableClientContext ctx =
184-
sharedClientContext.createChild(
185-
InstanceName.of(settings.getProjectId(), settings.getInstanceId()),
186-
settings.getAppProfileId());
168+
sharedClientContext.createChild(InstanceName.of(projectId, instanceId), appProfileId);
187169

188-
return BigtableDataClient.createWithClientContext(settings, ctx);
170+
return new BigtableDataClient(new EnhancedBigtableStub(perOpSettings, ctx));
189171
}
190172
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/ClientOperationSettings.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.google.cloud.bigtable.data.v2.stub;
1717

18+
import com.google.api.core.InternalApi;
1819
import com.google.api.gax.batching.BatchingSettings;
1920
import com.google.api.gax.batching.FlowControlSettings;
2021
import com.google.api.gax.batching.FlowController;
@@ -45,7 +46,8 @@
4546
import java.util.Set;
4647
import org.threeten.bp.Duration;
4748

48-
class ClientOperationSettings {
49+
@InternalApi
50+
public class ClientOperationSettings {
4951
private static final Set<StatusCode.Code> IDEMPOTENT_RETRY_CODES =
5052
ImmutableSet.of(StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE);
5153

0 commit comments

Comments
 (0)