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 @@ -24,6 +24,7 @@
import com.google.bigtable.v2.OpenAuthorizedViewRequest;
import com.google.bigtable.v2.OpenMaterializedViewRequest;
import com.google.bigtable.v2.OpenTableRequest.Permission;
import com.google.cloud.bigtable.Version;
import com.google.cloud.bigtable.data.v2.internal.api.ChannelProviders.ChannelProvider;
import com.google.cloud.bigtable.data.v2.internal.api.ChannelProviders.ConfiguredChannelProvider;
import com.google.cloud.bigtable.data.v2.internal.channels.ChannelPool;
Expand Down Expand Up @@ -65,6 +66,8 @@ public class Client implements AutoCloseable {
// up on it so close() returns. The watchdog interval is what makes the worst case finite.
private static final Duration POOL_DRAIN_TIMEOUT = Duration.ofMinutes(6);

public static final String USER_AGENT = "bigtable-java/" + Version.VERSION;

public static final FeatureFlags BASE_FEATURE_FLAGS =
FeatureFlags.newBuilder()
.setReverseScans(false)
Expand Down Expand Up @@ -113,6 +116,19 @@ public class Client implements AutoCloseable {
// close() has already missed in its snapshot.
private boolean closed = false;

public static ChannelProvider configureChannelProvider(
ChannelProvider channelProvider, Metrics metrics) {
return new ConfiguredChannelProvider(
channelProvider,
channelBuilder ->
metrics
.configureGrpcChannel(channelBuilder)
.userAgent(USER_AGENT)
.keepAliveTime(KEEPALIVE_TIME_MS, TimeUnit.MILLISECONDS)
.keepAliveTimeout(KEEPALIVE_TIMEOUT_MS, TimeUnit.MILLISECONDS)
.maxInboundMessageSize(256 * 1024 * 1024));
}

public static Client create(ClientSettings settings) throws IOException {
FeatureFlags featureFlags =
settings.getChannelProvider().updateFeatureFlags(BASE_FEATURE_FLAGS);
Expand Down Expand Up @@ -156,14 +172,17 @@ public static Client create(ClientSettings settings) throws IOException {
metrics.start();
}

ChannelProvider channelProvider =
configureChannelProvider(settings.getChannelProvider(), metrics);

ClientConfigurationManager configManager = null;

try {
configManager =
new ClientConfigurationManager(
featureFlags,
clientInfo,
settings.getChannelProvider(),
channelProvider,
metrics.getDebugTagTracer(),
backgroundExecutor);
configManager.start().get();
Expand Down Expand Up @@ -193,7 +212,7 @@ public static Client create(ClientSettings settings) throws IOException {
Resource.createOwned(backgroundExecutor, backgroundExecutor::shutdown),
Resource.<Executor>createOwned(
userCallbackExecutor, () -> shutdownAndAwait(userCallbackExecutor)),
settings.getChannelProvider());
channelProvider);
}

/**
Expand All @@ -219,24 +238,9 @@ public Client(

defaultCallOptions = CallOptions.DEFAULT;

ChannelProvider configuredChannelProvider =
new ConfiguredChannelProvider(
channelProvider,
channelBuilder ->
metrics
.get()
.configureGrpcChannel(channelBuilder)
.keepAliveTime(KEEPALIVE_TIME_MS, TimeUnit.MILLISECONDS)
.keepAliveTimeout(KEEPALIVE_TIMEOUT_MS, TimeUnit.MILLISECONDS)
// TODO: consider localizing this for large reads
.maxInboundMessageSize(256 * 1024 * 1024));

SwitchingChannelPool switchingPool =
new SwitchingChannelPool(
configuredChannelProvider,
configManager.get(),
metrics.get(),
backgroundExecutor.get());
channelProvider, configManager.get(), metrics.get(), backgroundExecutor.get());
switchingPool.start();
this.channelPool = Resource.createOwned(switchingPool, switchingPool::close);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.bigtable.v2.FeatureFlags;
import com.google.bigtable.v2.Mutation;
import com.google.cloud.bigtable.Version;
import io.grpc.Metadata;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -35,6 +36,11 @@ public class Util {
private static final Metadata.Key<String> FEATURE_FLAGS_KEY =
Metadata.Key.of("bigtable-features", Metadata.ASCII_STRING_MARSHALLER);

private static final Metadata.Key<String> API_CLIENT_KEY =
Metadata.Key.of("x-goog-api-client", Metadata.ASCII_STRING_MARSHALLER);
private static final String API_CLIENT_VALUE =
"gl-java/" + System.getProperty("java.version") + " gccl/" + Version.VERSION;

public static Metadata composeMetadata(
FeatureFlags featureFlags, Map<String, String> headerParams) {
Metadata metadata = new Metadata();
Expand All @@ -59,6 +65,8 @@ public static Metadata composeMetadata(
.map(e -> String.format("%s=%s", e.getKey(), urlEncode(e.getValue())))
.collect(Collectors.joining("&")));

metadata.put(API_CLIENT_KEY, API_CLIENT_VALUE);

return metadata;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.google.bigtable.v2.SessionReadModifyWriteRowResponse;
import com.google.bigtable.v2.SessionReadRowResponse;
import com.google.cloud.bigtable.data.v2.internal.api.ChannelProviders.ChannelProvider;
import com.google.cloud.bigtable.data.v2.internal.api.ChannelProviders.ConfiguredChannelProvider;
import com.google.cloud.bigtable.data.v2.internal.api.Client;
import com.google.cloud.bigtable.data.v2.internal.api.Client.Resource;
import com.google.cloud.bigtable.data.v2.internal.channels.ChannelPool;
Expand Down Expand Up @@ -72,7 +71,6 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -149,7 +147,7 @@ public static Shim create(

// Channel provider for the client. DirectAccess with fallback by default.
ChannelProvider clientChannelProvider =
configureChannelProvider(
Client.configureChannelProvider(
GaxDirectAccessChannelProvider.createWithFallback(
(InstantiatingGrpcChannelProvider) transportProvider, callCreds),
metrics);
Expand All @@ -158,15 +156,15 @@ public static Shim create(
Client.BASE_FEATURE_FLAGS, clientInfo, clientChannelProvider, metrics, bgExecutor)) {
// Directpath failed, revert to basic channel provider for the client.
clientChannelProvider =
configureChannelProvider(
Client.configureChannelProvider(
new GaxBasicChannelProvider(
(InstantiatingGrpcChannelProvider) transportProvider, callCreds),
metrics);
}

// ChannelProvider for configuration manager.
ChannelProvider configChannelProvider =
configureChannelProvider(
Client.configureChannelProvider(
new GaxBasicChannelProvider(
(InstantiatingGrpcChannelProvider) transportProvider, callCreds),
metrics);
Expand Down Expand Up @@ -308,19 +306,6 @@ static Resource<Executor> selectUserCallbackExecutor(
return Resource.createOwned(owned, () -> Client.shutdownAndAwait(owned));
}

private static ChannelProvider configureChannelProvider(
ChannelProvider channelProvider, Metrics metrics) {
return new ConfiguredChannelProvider(
channelProvider,
channelBuilder ->
metrics
.configureGrpcChannel(channelBuilder)
.keepAliveTime(Client.KEEPALIVE_TIME_MS, TimeUnit.MILLISECONDS)
.keepAliveTimeout(Client.KEEPALIVE_TIMEOUT_MS, TimeUnit.MILLISECONDS)
// TODO: consider localizing this for large reads
.maxInboundMessageSize(256 * 1024 * 1024));
}

private static boolean checkDirectAccessAvailable(
FeatureFlags featureFlags,
ClientInfo clientInfo,
Expand Down
Loading