This repository was archived by the owner on May 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
chore: integrate channel pool fixes #2599
Merged
gcf-merge-on-green
merged 19 commits into
googleapis:main
from
nicholsl:integrate-channel-pool
Jun 16, 2025
Merged
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7d1edac
integrate channel pool
nicholsl ba498f0
move channel pool creation into getTransportChannel()
nicholsl 72adb99
Merge branch 'googleapis:main' into integrate-channel-pool
nicholsl 98b0c43
Cleanup transport channel provider and add thread safety
nicholsl a65f5a1
remove comments
nicholsl 29a3810
fix
nicholsl e365916
Merge branch 'googleapis:main' into integrate-channel-pool
nicholsl bccb0ec
cleanup
nicholsl 542de27
factor out conversion util
nicholsl 76b1c3e
consolidate channel pool copying into BigtableChannelPoolSettings, re…
nicholsl 6f6e8f9
remove ChannelPoolSettingsCopier
nicholsl 02583c3
lint
nicholsl c6adaae
cleanup
nicholsl 81ee7cc
rename test, return different channel every time
nicholsl 6e1321a
rename createTransportChannel to getTransportChannel
nicholsl 34d1bd4
nits
nicholsl 33a586a
lint
nicholsl d43c796
add copyright
nicholsl 87e5c1a
Merge branch 'main' into integrate-channel-pool
mutianf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
...e/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| /* | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.google.cloud.bigtable.gaxx.grpc; | ||
|
|
||
| import com.google.api.core.InternalApi; | ||
| import com.google.api.gax.grpc.ChannelFactory; | ||
| import com.google.api.gax.grpc.ChannelPoolSettings; | ||
| import com.google.api.gax.grpc.GrpcTransportChannel; | ||
| import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; | ||
| import com.google.api.gax.rpc.TransportChannel; | ||
| import com.google.api.gax.rpc.TransportChannelProvider; | ||
| import com.google.auth.Credentials; | ||
| import com.google.common.base.Preconditions; | ||
| import io.grpc.ManagedChannel; | ||
| import java.io.IOException; | ||
| import java.util.Map; | ||
| import java.util.concurrent.Executor; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
|
|
||
| /** An instance of TransportChannelProvider that provides a TransportChannel through a supplied InstantiatingGrpcChannelProvider. */ | ||
| @InternalApi | ||
| public final class BigtableTransportChannelProvider implements TransportChannelProvider { | ||
|
nicholsl marked this conversation as resolved.
|
||
|
|
||
| private final InstantiatingGrpcChannelProvider delegate; | ||
|
|
||
| private BigtableTransportChannelProvider( | ||
| InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider) { | ||
| delegate = Preconditions.checkNotNull(instantiatingGrpcChannelProvider); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean shouldAutoClose() { | ||
| return delegate.shouldAutoClose(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean needsExecutor() { | ||
| return delegate.needsExecutor(); | ||
| } | ||
|
|
||
| @Override | ||
| public BigtableTransportChannelProvider withExecutor(ScheduledExecutorService executor) { | ||
| return withExecutor((Executor) executor); | ||
|
igorbernstein2 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @Override | ||
| public BigtableTransportChannelProvider withExecutor(Executor executor) { | ||
| InstantiatingGrpcChannelProvider newChannelProvider = | ||
| (InstantiatingGrpcChannelProvider) delegate.withExecutor(executor); | ||
| return new BigtableTransportChannelProvider(newChannelProvider); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean needsHeaders() { | ||
| return delegate.needsHeaders(); | ||
| } | ||
|
|
||
| @Override | ||
| public BigtableTransportChannelProvider withHeaders(Map<String, String> headers) { | ||
| InstantiatingGrpcChannelProvider newChannelProvider = | ||
| (InstantiatingGrpcChannelProvider) delegate.withHeaders(headers); | ||
| return new BigtableTransportChannelProvider(newChannelProvider); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean needsEndpoint() { | ||
| return delegate.needsEndpoint(); | ||
| } | ||
|
|
||
| @Override | ||
| public TransportChannelProvider withEndpoint(String endpoint) { | ||
| InstantiatingGrpcChannelProvider newChannelProvider = | ||
| (InstantiatingGrpcChannelProvider) delegate.withEndpoint(endpoint); | ||
| return new BigtableTransportChannelProvider(newChannelProvider); | ||
| } | ||
|
|
||
| @Deprecated | ||
| @Override | ||
| public boolean acceptsPoolSize() { | ||
| return delegate.acceptsPoolSize(); | ||
| } | ||
|
|
||
| @Deprecated | ||
| @Override | ||
| public TransportChannelProvider withPoolSize(int size) { | ||
| InstantiatingGrpcChannelProvider newChannelProvider = | ||
| (InstantiatingGrpcChannelProvider) delegate.withPoolSize(size); | ||
| return new BigtableTransportChannelProvider(newChannelProvider); | ||
| } | ||
|
|
||
| /**Expected to only be called once when BigtableClientContext is created*/ | ||
| @Override | ||
| public TransportChannel getTransportChannel() throws IOException { | ||
|
mutianf marked this conversation as resolved.
|
||
| // This provider's main purpose is to replace the default GAX ChannelPool | ||
| // with a custom BigtableChannelPool, reusing the delegate's configuration. | ||
|
|
||
| // To create our pool, we need a factory for raw gRPC channels. | ||
| // We achieve this by configuring our delegate to not use its own pooling | ||
| // (by setting pool size to 1) and then calling getTransportChannel() on it. | ||
| InstantiatingGrpcChannelProvider singleChannelProvider = | ||
| delegate.toBuilder().setChannelPoolSettings(ChannelPoolSettings.staticallySized(1)).build(); | ||
|
|
||
| ChannelFactory channelFactory = | ||
| () -> { | ||
| try { | ||
| GrpcTransportChannel channel = | ||
| (GrpcTransportChannel) singleChannelProvider.getTransportChannel(); | ||
| return (ManagedChannel) channel.getChannel(); | ||
| } catch (IOException e) { | ||
| throw new java.io.UncheckedIOException(e); | ||
| } | ||
| }; | ||
|
|
||
| BigtableChannelPoolSettings btPoolSettings = | ||
| BigtableChannelPoolSettings.copyFrom(delegate.getChannelPoolSettings()); | ||
|
|
||
| BigtableChannelPool btChannelPool = BigtableChannelPool.create(btPoolSettings, channelFactory); | ||
|
|
||
| return GrpcTransportChannel.create(btChannelPool); | ||
| } | ||
|
|
||
| @Override | ||
| public String getTransportName() { | ||
| return "bigtable"; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean needsCredentials() { | ||
| return delegate.needsCredentials(); | ||
| } | ||
|
|
||
| @Override | ||
| public TransportChannelProvider withCredentials(Credentials credentials) { | ||
| InstantiatingGrpcChannelProvider newChannelProvider = | ||
| (InstantiatingGrpcChannelProvider) delegate.withCredentials(credentials); | ||
| return new BigtableTransportChannelProvider(newChannelProvider); | ||
| } | ||
|
|
||
| /** Creates a BigtableTransportChannelProvider. */ | ||
| public static BigtableTransportChannelProvider create( | ||
| InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider) { | ||
| return new BigtableTransportChannelProvider(instantiatingGrpcChannelProvider); | ||
| } | ||
| } | ||
88 changes: 88 additions & 0 deletions
88
...le/src/test/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettingsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package com.google.cloud.bigtable.gaxx.grpc; | ||
|
|
||
| import static com.google.common.truth.Truth.assertThat; | ||
|
|
||
| import com.google.api.gax.grpc.ChannelPoolSettings; | ||
| import com.google.common.collect.ImmutableSet; | ||
| import java.lang.reflect.Method; | ||
| import java.lang.reflect.Modifier; | ||
| import java.util.Arrays; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.JUnit4; | ||
|
|
||
| @RunWith(JUnit4.class) | ||
| public class BigtableChannelPoolSettingsTest { | ||
|
|
||
| @Test | ||
| public void testToBigtableChannelPoolSettingsAllFieldsSetCopiesCorrectly() throws Exception { | ||
| ChannelPoolSettings originalSettings = | ||
| ChannelPoolSettings.builder() | ||
| .setMinRpcsPerChannel(10) | ||
| .setMaxRpcsPerChannel(50) | ||
| .setMinChannelCount(5) | ||
| .setMaxChannelCount(100) | ||
| .setInitialChannelCount(20) | ||
| .setPreemptiveRefreshEnabled(true) | ||
| .build(); | ||
|
|
||
| BigtableChannelPoolSettings copiedSettings = | ||
| BigtableChannelPoolSettings.copyFrom(originalSettings); | ||
| assertSettingsCopiedCorrectly(originalSettings, copiedSettings); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToBigtableChannelPoolSettingsDefaultValuesCopiesCorrectly() throws Exception { | ||
| ChannelPoolSettings originalSettings = ChannelPoolSettings.builder().build(); | ||
| BigtableChannelPoolSettings copiedSettings = | ||
| BigtableChannelPoolSettings.copyFrom(originalSettings); | ||
| assertSettingsCopiedCorrectly(originalSettings, copiedSettings); | ||
| } | ||
|
|
||
| private void assertSettingsCopiedCorrectly( | ||
| ChannelPoolSettings originalSettings, BigtableChannelPoolSettings copiedSettings) | ||
| throws Exception { | ||
|
|
||
| Set<String> supportedGetters = | ||
| ImmutableSet.of( | ||
| "getMinRpcsPerChannel", | ||
| "getMaxRpcsPerChannel", | ||
| "getMinChannelCount", | ||
| "getMaxChannelCount", | ||
| "getInitialChannelCount", | ||
| "isPreemptiveRefreshEnabled", | ||
| "isStaticSize"); | ||
|
|
||
| Set<String> actualGetters = | ||
| Arrays.stream(ChannelPoolSettings.class.getDeclaredMethods()) | ||
| .filter( | ||
| method -> | ||
| Modifier.isPublic(method.getModifiers()) | ||
| && Modifier.isAbstract(method.getModifiers()) | ||
| && (method.getName().startsWith("get") | ||
| || method.getName().startsWith("is"))) | ||
| .map(Method::getName) | ||
| .collect(Collectors.toSet()); | ||
|
|
||
| // If this fails then we need to add support for the additional attributes on the gax | ||
| // ChannelPool by updating the BigtableChannelPoolSettings.copyFrom method | ||
| assertThat(supportedGetters).containsAtLeastElementsIn(actualGetters); | ||
|
|
||
| assertThat(originalSettings.getInitialChannelCount()) | ||
| .isEqualTo(copiedSettings.getInitialChannelCount()); | ||
| assertThat(originalSettings.getMaxChannelCount()) | ||
| .isEqualTo(copiedSettings.getMaxChannelCount()); | ||
| assertThat(originalSettings.getMinChannelCount()) | ||
| .isEqualTo(copiedSettings.getMinChannelCount()); | ||
| assertThat(originalSettings.getMaxRpcsPerChannel()) | ||
| .isEqualTo(copiedSettings.getMaxRpcsPerChannel()); | ||
| assertThat(originalSettings.getMinRpcsPerChannel()) | ||
| .isEqualTo(copiedSettings.getMinRpcsPerChannel()); | ||
| assertThat(originalSettings.getInitialChannelCount()) | ||
| .isEqualTo(copiedSettings.getInitialChannelCount()); | ||
| assertThat(originalSettings.isPreemptiveRefreshEnabled()) | ||
| .isEqualTo(copiedSettings.isPreemptiveRefreshEnabled()); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.