Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit bf0003b

Browse files
committed
int commit
1 parent 90b72e0 commit bf0003b

7 files changed

Lines changed: 260 additions & 73 deletions

File tree

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.cloud.bigtable.gaxx.grpc.ChannelPrimer;
2727
import io.grpc.CallCredentials;
2828
import io.grpc.CallOptions;
29+
import io.grpc.Channel;
2930
import io.grpc.ClientCall;
3031
import io.grpc.Deadline;
3132
import io.grpc.ManagedChannel;
@@ -88,21 +89,21 @@ static BigtableChannelPrimer create(
8889
}
8990

9091
@Override
91-
public void primeChannel(ManagedChannel managedChannel) {
92+
public void primeChannel(Channel channel) {
9293
try {
93-
primeChannelUnsafe(managedChannel);
94+
primeChannelUnsafe(channel);
9495
} catch (IOException | RuntimeException e) {
9596
LOG.log(Level.WARNING, "Unexpected error while trying to prime a channel", e);
9697
}
9798
}
9899

99-
private void primeChannelUnsafe(ManagedChannel managedChannel) throws IOException {
100-
sendPrimeRequestsBlocking(managedChannel);
100+
private void primeChannelUnsafe(Channel channel) throws IOException {
101+
sendPrimeRequestsBlocking(channel);
101102
}
102103

103-
private void sendPrimeRequestsBlocking(ManagedChannel managedChannel) {
104+
private void sendPrimeRequestsBlocking(Channel channel) {
104105
try {
105-
sendPrimeRequestsAsync(managedChannel).get(1, TimeUnit.MINUTES);
106+
sendPrimeRequestsAsync(channel).get(1, TimeUnit.MINUTES);
106107
} catch (Throwable e) {
107108
// TODO: Not sure if we should swallow the error here. We are pre-emptively swapping
108109
// channels if the new
@@ -112,7 +113,7 @@ private void sendPrimeRequestsBlocking(ManagedChannel managedChannel) {
112113
}
113114

114115
@Override
115-
public ApiFuture<PingAndWarmResponse> sendPrimeRequestsAsync(ManagedChannel managedChannel) {
116+
public ApiFuture<PingAndWarmResponse> sendPrimeRequestsAsync(Channel managedChannel) {
116117
ClientCall<PingAndWarmRequest, PingAndWarmResponse> clientCall =
117118
managedChannel.newCall(
118119
BigtableGrpc.getPingAndWarmMethod(),

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

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,25 @@ public ClientOperationSettings getPerOpSettings() {
242242
return perOpSettings;
243243
}
244244

245+
/** Applies common pool, message size, and keep-alive settings to the provided builder. */
246+
private static InstantiatingGrpcChannelProvider.Builder commonTraits(
247+
InstantiatingGrpcChannelProvider.Builder builder) {
248+
return builder
249+
.setChannelPoolSettings(
250+
ChannelPoolSettings.builder()
251+
.setInitialChannelCount(10)
252+
.setMinRpcsPerChannel(1)
253+
// Keep it conservative as we scale the channel size every 1min
254+
// and delta is 2 channels.
255+
.setMaxRpcsPerChannel(25)
256+
.setPreemptiveRefreshEnabled(true)
257+
.build())
258+
.setMaxInboundMessageSize(MAX_MESSAGE_SIZE)
259+
.setKeepAliveTime(Duration.ofSeconds(30)) // sends ping in this interval
260+
.setKeepAliveTimeout(
261+
Duration.ofSeconds(10)); // wait this long before considering the connection dead
262+
}
263+
245264
/** Returns a builder for the default ChannelProvider for this service. */
246265
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
247266
InstantiatingGrpcChannelProvider.Builder grpcTransportProviderBuilder =
@@ -261,22 +280,27 @@ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProvi
261280
Collections.singletonList(InstantiatingGrpcChannelProvider.HardBoundTokenTypes.ALTS));
262281
}
263282
}
264-
return grpcTransportProviderBuilder
265-
.setChannelPoolSettings(
266-
ChannelPoolSettings.builder()
267-
.setInitialChannelCount(10)
268-
.setMinRpcsPerChannel(1)
269-
// Keep it conservative as we scale the channel size every 1min
270-
// and delta is 2 channels.
271-
.setMaxRpcsPerChannel(25)
272-
.setPreemptiveRefreshEnabled(true)
273-
.build())
274-
.setMaxInboundMessageSize(MAX_MESSAGE_SIZE)
275-
.setKeepAliveTime(Duration.ofSeconds(30)) // sends ping in this interval
276-
.setKeepAliveTimeout(
277-
Duration.ofSeconds(10)); // wait this long before considering the connection dead
283+
return commonTraits(grpcTransportProviderBuilder);
278284
}
279285

286+
/** Applies Direct Access traits (DirectPath & ALTS) to an existing builder. */
287+
public static InstantiatingGrpcChannelProvider.Builder applyDirectAccessTraits(
288+
InstantiatingGrpcChannelProvider.Builder builder) {
289+
290+
builder
291+
.setAttemptDirectPathXds()
292+
.setAttemptDirectPath(true)
293+
.setAllowNonDefaultServiceAccount(true);
294+
295+
if (!DIRECT_PATH_BOUND_TOKEN_DISABLED) {
296+
builder.setAllowHardBoundTokenTypes(
297+
Collections.singletonList(InstantiatingGrpcChannelProvider.HardBoundTokenTypes.ALTS));
298+
}
299+
300+
return builder;
301+
}
302+
303+
280304
@SuppressWarnings("WeakerAccess")
281305
public static TransportChannelProvider defaultTransportChannelProvider() {
282306
return defaultGrpcTransportProviderBuilder().build();

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
package com.google.cloud.bigtable.data.v2.stub;
1717

1818
import com.google.api.core.ApiFuture;
19+
import com.google.api.core.ApiFutures;
1920
import com.google.api.core.InternalApi;
20-
import com.google.api.core.SettableApiFuture;
2121
import com.google.bigtable.v2.PingAndWarmResponse;
2222
import com.google.cloud.bigtable.gaxx.grpc.ChannelPrimer;
23-
import io.grpc.ManagedChannel;
23+
import io.grpc.Channel;
2424

2525
@InternalApi
2626
public class NoOpChannelPrimer implements ChannelPrimer {
@@ -31,14 +31,12 @@ static NoOpChannelPrimer create() {
3131
private NoOpChannelPrimer() {}
3232

3333
@Override
34-
public void primeChannel(ManagedChannel channel) {
34+
public void primeChannel(Channel channel) {
3535
// No op
3636
}
3737

3838
@Override
39-
public ApiFuture<PingAndWarmResponse> sendPrimeRequestsAsync(ManagedChannel channel) {
40-
SettableApiFuture future = SettableApiFuture.create();
41-
future.set(PingAndWarmResponse.getDefaultInstance());
42-
return future;
39+
public ApiFuture<PingAndWarmResponse> sendPrimeRequestsAsync(Channel channel) {
40+
return ApiFutures.immediateFuture(PingAndWarmResponse.getDefaultInstance());
4341
}
4442
}

0 commit comments

Comments
 (0)