Skip to content

Commit 70c05c9

Browse files
nicholslcloud-java-botmutianfrelease-please[bot]sushanb
authored
feat: idle channel eviction (#2651)
* feat/idle-channel-eviction Change-Id: I62fe152c293438bf64b657b5b1fe795e22ce9c85 * create noop channel primer Change-Id: I8d4212aad0ca7613b6c33d69d925671a090d1609 * no-op channel primer changes Change-Id: I9ad5eeaacb02ace9ba3cf7c09b6846dcbc298fb8 * update ignored diffs Change-Id: I04698ba82b95c82301e4e9f436401698675d7ea9 * chore: Update generation configuration at Thu Aug 7 02:49:23 UTC 2025 (#2649) * chore: Update generation configuration at Thu Jul 31 02:47:07 UTC 2025 * chore: Update generation configuration at Fri Aug 1 02:54:57 UTC 2025 * chore: Update generation configuration at Sat Aug 2 02:42:43 UTC 2025 * chore: generate libraries at Sat Aug 2 02:43:12 UTC 2025 * chore: Update generation configuration at Tue Aug 5 02:50:25 UTC 2025 * chore: generate libraries at Tue Aug 5 02:50:52 UTC 2025 * chore: Update generation configuration at Wed Aug 6 02:48:20 UTC 2025 * chore: generate libraries at Wed Aug 6 02:48:53 UTC 2025 * chore: Update generation configuration at Thu Aug 7 02:49:23 UTC 2025 * deps: update shared dependencies (#2654) * chore(main): release 2.64.0 (#2652) * chore(main): release 2.64.0 * chore: generate libraries at Fri Aug 8 14:28:59 UTC 2025 --------- Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: cloud-java-bot <[email protected]> * feat(bigtable): lower the value for max rpc channels as channel resize is slow (1m, 2 channel) (#2656) …conservative Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-bigtable/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Rollback plan is reviewed and LGTMed - [ ] All new data plane features have a completed end to end testing plan Fixes #<issue_number_goes_here> ☕️ If you write sample code, please follow the [samples format]( https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md). * chore(main): release 2.64.1-SNAPSHOT (#2655) :robot: I have created a release *beep* *boop* --- ### Updating meta-information for bleeding-edge SNAPSHOT release. --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please). * chore(main): release 2.65.0 (#2657) * chore(main): release 2.65.0 * chore: generate libraries at Tue Aug 12 16:25:49 UTC 2025 --------- Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: cloud-java-bot <[email protected]> * chore(main): release 2.65.1-SNAPSHOT (#2658) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * more noop channel primer changes Change-Id: I3baa8e93bc614efe21f1159a708be36881120e34 * remove outdated comments Change-Id: I11e8da901a93a49009caf4caf0385fd5e3c8091b * cleanup Change-Id: Iaa30338d04ba846469fc6152e0683e53573c40ee * pr feedback Change-Id: Ie0fde53cd17b1feeaaffd15382e936a46d84c5c1 * fix: lint Change-Id: Ib8c6b56569c17997a126065a6fa00e8bb1604494 * fix: pr feedback Change-Id: Ic5f18450c5f60bcf5473e6890b41b006821ddf9d * fix: feedback Change-Id: Ib7f24524b6050ec11ca18e5dc624ca8513f99ec8 * fix: lint Change-Id: I78712b99a975fb6ec9defcdb6812e955df555e1f * move history pruning Change-Id: Ibeae2ce0b790ef2731be541a70fa829e220fa4a8 * fix: nits Change-Id: Ic812e3523a9f29dc612fbdf58ee8f9dbb8a283f4 * Apply suggestion from @mutianf Co-authored-by: Mattie Fu <[email protected]> * Apply suggestion from @mutianf Co-authored-by: Mattie Fu <[email protected]> --------- Co-authored-by: cloud-java-bot <[email protected]> Co-authored-by: Mattie Fu <[email protected]> Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: cloud-java-bot <[email protected]> Co-authored-by: Sushan Bhattarai <[email protected]>
1 parent 2127d8a commit 70c05c9

File tree

12 files changed

+590
-33
lines changed

12 files changed

+590
-33
lines changed

google-cloud-bigtable/clirr-ignored-differences.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,4 +426,34 @@
426426
<method>*create*</method>
427427
<to>*</to>
428428
</difference>
429+
<difference>
430+
<differenceType>4001</differenceType>
431+
<className>com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimer</className>
432+
<to>com/google/api/gax/grpc/ChannelPrimer</to>
433+
</difference>
434+
<difference>
435+
<differenceType>4001</differenceType>
436+
<className>com/google/cloud/bigtable/data/v2/stub/NoOpChannelPrimer</className>
437+
<to>com/google/api/gax/grpc/ChannelPrimer</to>
438+
</difference>
439+
<difference>
440+
<differenceType>7005</differenceType>
441+
<className>com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool</className>
442+
<method>*create*</method>
443+
<to>*</to>
444+
</difference>
445+
<difference>
446+
<!-- InternalApi was updated -->
447+
<differenceType>7005</differenceType>
448+
<className>com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider</className>
449+
<method>*create*</method>
450+
<to>*</to>
451+
</difference>
452+
<!-- change method return type is ok because BigtableChannelPrimer is InternalApi -->
453+
<difference>
454+
<differenceType>7006</differenceType>
455+
<className>com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimer</className>
456+
<method>*sendPrimeRequestsAsync*</method>
457+
<to>com.google.api.core.ApiFuture</to>
458+
</difference>
429459
</differences>

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

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

18+
import com.google.api.core.ApiFuture;
1819
import com.google.api.core.InternalApi;
1920
import com.google.api.core.SettableApiFuture;
20-
import com.google.api.gax.grpc.ChannelPrimer;
2121
import com.google.auth.Credentials;
2222
import com.google.bigtable.v2.BigtableGrpc;
2323
import com.google.bigtable.v2.InstanceName;
2424
import com.google.bigtable.v2.PingAndWarmRequest;
2525
import com.google.bigtable.v2.PingAndWarmResponse;
26+
import com.google.cloud.bigtable.gaxx.grpc.ChannelPrimer;
2627
import io.grpc.CallCredentials;
2728
import io.grpc.CallOptions;
2829
import io.grpc.ClientCall;
@@ -110,8 +111,7 @@ private void sendPrimeRequestsBlocking(ManagedChannel managedChannel) {
110111
}
111112
}
112113

113-
public SettableApiFuture<PingAndWarmResponse> sendPrimeRequestsAsync(
114-
ManagedChannel managedChannel) {
114+
public ApiFuture<PingAndWarmResponse> sendPrimeRequestsAsync(ManagedChannel managedChannel) {
115115
ClientCall<PingAndWarmRequest, PingAndWarmResponse> clientCall =
116116
managedChannel.newCall(
117117
BigtableGrpc.getPingAndWarmMethod(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.google.api.gax.core.BackgroundResource;
2121
import com.google.api.gax.core.CredentialsProvider;
2222
import com.google.api.gax.core.FixedCredentialsProvider;
23-
import com.google.api.gax.grpc.ChannelPrimer;
2423
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
2524
import com.google.api.gax.rpc.ClientContext;
2625
import com.google.auth.Credentials;
@@ -34,6 +33,7 @@
3433
import com.google.cloud.bigtable.data.v2.stub.metrics.MetricsProvider;
3534
import com.google.cloud.bigtable.data.v2.stub.metrics.NoopMetricsProvider;
3635
import com.google.cloud.bigtable.gaxx.grpc.BigtableTransportChannelProvider;
36+
import com.google.cloud.bigtable.gaxx.grpc.ChannelPrimer;
3737
import io.grpc.ManagedChannelBuilder;
3838
import io.grpc.opentelemetry.GrpcOpenTelemetry;
3939
import io.opentelemetry.api.OpenTelemetry;

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
*/
1616
package com.google.cloud.bigtable.data.v2.stub;
1717

18+
import com.google.api.core.ApiFuture;
1819
import com.google.api.core.InternalApi;
19-
import com.google.api.gax.grpc.ChannelPrimer;
20+
import com.google.api.core.SettableApiFuture;
21+
import com.google.bigtable.v2.PingAndWarmResponse;
22+
import com.google.cloud.bigtable.gaxx.grpc.ChannelPrimer;
2023
import io.grpc.ManagedChannel;
2124

2225
@InternalApi
@@ -28,7 +31,14 @@ static NoOpChannelPrimer create() {
2831
private NoOpChannelPrimer() {}
2932

3033
@Override
31-
public void primeChannel(ManagedChannel managedChannel) {
34+
public void primeChannel(ManagedChannel channel) {
3235
// No op
3336
}
37+
38+
@Override
39+
public ApiFuture<PingAndWarmResponse> sendPrimeRequestsAsync(ManagedChannel channel) {
40+
SettableApiFuture future = SettableApiFuture.create();
41+
future.set(PingAndWarmResponse.getDefaultInstance());
42+
return future;
43+
}
3444
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import com.google.api.core.InternalApi;
1919
import com.google.api.gax.grpc.ChannelFactory;
20-
import com.google.api.gax.grpc.ChannelPrimer;
20+
import com.google.cloud.bigtable.gaxx.grpc.ChannelPoolHealthChecker.ProbeResult;
2121
import com.google.common.annotations.VisibleForTesting;
2222
import com.google.common.base.Preconditions;
2323
import com.google.common.collect.ImmutableList;
@@ -31,9 +31,11 @@
3131
import io.grpc.MethodDescriptor;
3232
import io.grpc.Status;
3333
import java.io.IOException;
34+
import java.time.Clock;
3435
import java.util.ArrayList;
3536
import java.util.List;
3637
import java.util.concurrent.CancellationException;
38+
import java.util.concurrent.ConcurrentLinkedQueue;
3739
import java.util.concurrent.Executors;
3840
import java.util.concurrent.ScheduledExecutorService;
3941
import java.util.concurrent.TimeUnit;
@@ -64,9 +66,9 @@ public class BigtableChannelPool extends ManagedChannel {
6466

6567
private final ChannelPrimer channelPrimer;
6668
private final ScheduledExecutorService executor;
67-
6869
private final Object entryWriteLock = new Object();
6970
@VisibleForTesting final AtomicReference<ImmutableList<Entry>> entries = new AtomicReference<>();
71+
private final ChannelPoolHealthChecker channelPoolHealthChecker;
7072
private final AtomicInteger indexTicker = new AtomicInteger();
7173
private final String authority;
7274

@@ -96,6 +98,10 @@ public static BigtableChannelPool create(
9698
this.settings = settings;
9799
this.channelFactory = channelFactory;
98100
this.channelPrimer = channelPrimer;
101+
Clock systemClock = Clock.systemUTC();
102+
this.channelPoolHealthChecker =
103+
new ChannelPoolHealthChecker(entries::get, channelPrimer, executor, systemClock);
104+
this.channelPoolHealthChecker.start();
99105

100106
ImmutableList.Builder<Entry> initialListBuilder = ImmutableList.builder();
101107

@@ -445,15 +451,32 @@ static class Entry {
445451

446452
private final AtomicInteger maxOutstanding = new AtomicInteger();
447453

448-
// Flag that the channel should be closed once all of the outstanding RPC complete.
454+
/** Queue storing the last 5 minutes of probe results */
455+
@VisibleForTesting
456+
final ConcurrentLinkedQueue<ProbeResult> probeHistory = new ConcurrentLinkedQueue<>();
457+
458+
/**
459+
* Keep both # of failed and # of successful probes so that we don't have to check size() on the
460+
* ConcurrentLinkedQueue all the time
461+
*/
462+
final AtomicInteger failedProbesInWindow = new AtomicInteger();
463+
464+
final AtomicInteger successfulProbesInWindow = new AtomicInteger();
465+
466+
// Flag that the channel should be closed once all the outstanding RPCs complete.
449467
private final AtomicBoolean shutdownRequested = new AtomicBoolean();
450468
// Flag that the channel has been closed.
451469
private final AtomicBoolean shutdownInitiated = new AtomicBoolean();
452470

453-
private Entry(ManagedChannel channel) {
471+
@VisibleForTesting
472+
Entry(ManagedChannel channel) {
454473
this.channel = channel;
455474
}
456475

476+
ManagedChannel getManagedChannel() {
477+
return this.channel;
478+
}
479+
457480
int getAndResetMaxOutstanding() {
458481
return maxOutstanding.getAndSet(outstandingRpcs.get());
459482
}
@@ -468,7 +491,7 @@ private boolean retain() {
468491
// register desire to start RPC
469492
int currentOutstanding = outstandingRpcs.incrementAndGet();
470493

471-
// Rough book keeping
494+
// Rough bookkeeping
472495
int prevMax = maxOutstanding.get();
473496
if (currentOutstanding > prevMax) {
474497
maxOutstanding.incrementAndGet();

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.google.api.core.InternalApi;
1919
import com.google.api.gax.grpc.ChannelFactory;
2020
import com.google.api.gax.grpc.ChannelPoolSettings;
21-
import com.google.api.gax.grpc.ChannelPrimer;
2221
import com.google.api.gax.grpc.GrpcTransportChannel;
2322
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
2423
import com.google.api.gax.rpc.TransportChannel;

0 commit comments

Comments
 (0)