Skip to content
Open
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 @@ -33,6 +33,7 @@
import com.google.cloud.bigtable.data.v2.internal.csm.MetricsImpl;
import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo;
import com.google.cloud.bigtable.data.v2.internal.dp.AlwaysEnabledDirectAccessChecker;
import com.google.cloud.bigtable.data.v2.internal.dp.ClassicDirectAccessChecker;
import com.google.cloud.bigtable.data.v2.internal.dp.DirectAccessChecker;
import com.google.cloud.bigtable.data.v2.internal.dp.NoopDirectAccessChecker;
import com.google.cloud.bigtable.data.v2.stub.metrics.CustomOpenTelemetryMetricsProvider;
Expand Down Expand Up @@ -170,9 +171,14 @@ public static BigtableClientContext create(
directAccessChecker = AlwaysEnabledDirectAccessChecker.INSTANCE;
break;
case FORCED_OFF:
case DEFAULT:
directAccessChecker = NoopDirectAccessChecker.INSTANCE;
break;
case DEFAULT:
default:
directAccessChecker =
new ClassicDirectAccessChecker(
metrics.getDirectPathCompatibleTracer(), channelPrimer, backgroundExecutor);
break;
}

BigtableTransportChannelProvider btTransportProvider =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public String getProjectId() {

@InternalApi
public DirectPathConfig getDirectPathConfig() {
return DIRECT_PATH_CONFIG;
return this.directPathConfig;
}

/** Returns the target instance id. */
Expand Down Expand Up @@ -637,7 +637,7 @@ private Builder() {

// TODO: flip the bit setDirectAccessRequested and setTrafficDirectorEnabled once we make
// client compatible by default.
boolean isDirectPathRequested = directPathConfig == DirectPathConfig.FORCED_ON;
boolean isDirectPathRequested = directPathConfig != DirectPathConfig.FORCED_OFF;
featureFlags =
FeatureFlags.newBuilder()
.setReverseScans(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,103 @@ public void testCreateWithRefreshingChannel() throws Exception {
.setInstanceId(DEFAULT_INSTANCE_ID)
.setAppProfileId(DEFAULT_APP_PROFILE_ID)
.setRefreshingChannel(true);
builder
.stubSettings()
.setCredentialsProvider(credentialsProvider)
.setStreamWatchdogProvider(watchdogProvider)
.setBackgroundExecutorProvider(executorProvider);
InstantiatingGrpcChannelProvider channelProvider =
(InstantiatingGrpcChannelProvider) builder.stubSettings().getTransportChannelProvider();
InstantiatingGrpcChannelProvider.Builder channelProviderBuilder = channelProvider.toBuilder();
channelProviderBuilder.setChannelPoolSettings(ChannelPoolSettings.staticallySized(poolSize));
builder.stubSettings().setTransportChannelProvider(channelProviderBuilder.build());

BigtableDataClientFactory factory = BigtableDataClientFactory.create(builder.build());
factory.createDefault();
factory.createForAppProfile("other-appprofile");
factory.createForInstance("other-project", "other-instance");

// Make sure that only 1 instance is created by each provider
// getCredentials was called twice, in patchCredentials and when creating the fixed credentials
// in BigtableClientContext
Mockito.verify(credentialsProvider, Mockito.times(2)).getCredentials();
Mockito.verify(executorProvider, Mockito.times(1)).getExecutor();
Mockito.verify(watchdogProvider, Mockito.times(1)).getWatchdog();
assertThat(warmedChannels).hasSize(poolSize + 1);
assertThat(warmedChannels.values()).doesNotContain(false);

// Wait for all the connections to close asynchronously
factory.close();
long sleepTimeMs = 1000;
Thread.sleep(sleepTimeMs);
// Verify that all the channels are closed
assertThat(terminateAttributes).hasSize(poolSize + 1);
}

@Test
public void testCreateWithRefreshingChannelWithDirectAccessByDefault() throws Exception {
int poolSize = 3;
// TODO: remove the suppression when setRefreshingChannel can be removed
@SuppressWarnings("deprecation")
BigtableDataSettings.Builder builder =
BigtableDataSettings.newBuilderForEmulator(server.getPort())
.setProjectId(DEFAULT_PROJECT_ID)
.setInstanceId(DEFAULT_INSTANCE_ID)
.setAppProfileId(DEFAULT_APP_PROFILE_ID)
.setRefreshingChannel(true);
builder
.stubSettings()
.setCredentialsProvider(credentialsProvider)
.setStreamWatchdogProvider(watchdogProvider)
.setBackgroundExecutorProvider(executorProvider)
.setDirectPathConfig(EnhancedBigtableStubSettings.DirectPathConfig.DEFAULT);
InstantiatingGrpcChannelProvider channelProvider =
(InstantiatingGrpcChannelProvider) builder.stubSettings().getTransportChannelProvider();
InstantiatingGrpcChannelProvider.Builder channelProviderBuilder = channelProvider.toBuilder();
channelProviderBuilder.setChannelPoolSettings(ChannelPoolSettings.staticallySized(poolSize));
builder.stubSettings().setTransportChannelProvider(channelProviderBuilder.build());

BigtableDataClientFactory factory = BigtableDataClientFactory.create(builder.build());
factory.createDefault();
factory.createForAppProfile("other-appprofile");
factory.createForInstance("other-project", "other-instance");

// Make sure that only 1 instance is created by each provider
// getCredentials was called twice, in patchCredentials and when creating the fixed credentials
// in BigtableClientContext
Mockito.verify(credentialsProvider, Mockito.times(2)).getCredentials();
Mockito.verify(executorProvider, Mockito.times(1)).getExecutor();
Mockito.verify(watchdogProvider, Mockito.times(1)).getWatchdog();
assertThat(warmedChannels).hasSize(poolSize + 1);
assertThat(warmedChannels.values()).doesNotContain(false);

// Wait for all the connections to close asynchronously
factory.close();
long sleepTimeMs = 1000;
Thread.sleep(sleepTimeMs);
// Verify that all the channels are closed
// If we have DEFAULT, it will add one channel temporily
assertThat(terminateAttributes).hasSize(poolSize + 1);
}

@Test
public void testCreateWithRefreshingChannelDisableDirectAccess() throws Exception {
int poolSize = 3;
// TODO: remove the suppression when setRefreshingChannel can be removed
@SuppressWarnings("deprecation")
BigtableDataSettings.Builder builder =
BigtableDataSettings.newBuilderForEmulator(server.getPort())
.setProjectId(DEFAULT_PROJECT_ID)
.setInstanceId(DEFAULT_INSTANCE_ID)
.setAppProfileId(DEFAULT_APP_PROFILE_ID)
.setRefreshingChannel(true);

builder
.stubSettings()
.setCredentialsProvider(credentialsProvider)
.setStreamWatchdogProvider(watchdogProvider)
.setBackgroundExecutorProvider(executorProvider)
.setDirectPathConfig(EnhancedBigtableStubSettings.DirectPathConfig.FORCED_ON);
.setDirectPathConfig(EnhancedBigtableStubSettings.DirectPathConfig.FORCED_OFF);
InstantiatingGrpcChannelProvider channelProvider =
(InstantiatingGrpcChannelProvider) builder.stubSettings().getTransportChannelProvider();
InstantiatingGrpcChannelProvider.Builder channelProviderBuilder = channelProvider.toBuilder();
Expand All @@ -295,6 +386,7 @@ public void testCreateWithRefreshingChannel() throws Exception {
long sleepTimeMs = 1000;
Thread.sleep(sleepTimeMs);
// Verify that all the channels are closed
// If we have DEFAULT, it will add one channel temporily
assertThat(terminateAttributes).hasSize(poolSize);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,14 @@ public void testChannelPrimerConfigured() throws IOException {
// TODO: remove the suppression once setRefreshingChannel can be removed
@SuppressWarnings("deprecation")
EnhancedBigtableStubSettings settings =
defaultSettings.toBuilder().setRefreshingChannel(true).build();
defaultSettings.toBuilder()
.setRefreshingChannel(true)
.setDirectPathConfig(EnhancedBigtableStubSettings.DirectPathConfig.DEFAULT)
.build();

try (EnhancedBigtableStub ignored = EnhancedBigtableStub.create(settings)) {
// direct access checker ping
assertThat(fakeDataService.pingRequests).hasSize(1);
assertThat(fakeDataService.pingRequests).hasSize(2);
}
}

Expand Down
Loading