From 7d1edace34fbbf64b1195295d22e021daa4cff85 Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Mon, 2 Jun 2025 15:25:35 -0400 Subject: [PATCH 01/16] integrate channel pool Change-Id: I8b8da7b1a5d7a6afb2f227809a3e003163060ebe --- .../data/v2/stub/BigtableClientContext.java | 55 +++++++ .../gaxx/grpc/BigtableChannelPool.java | 6 +- .../BigtableTransportChannelProvider.java | 149 ++++++++++++++++++ 3 files changed, 207 insertions(+), 3 deletions(-) create mode 100644 google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java index 1ea4723ed331..8872b1988661 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java @@ -20,8 +20,18 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.CredentialsProvider; import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.api.gax.grpc.ChannelPoolSettings; +import com.google.api.gax.rpc.TransportChannel; +import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPoolSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPool; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.grpc.ChannelFactory; +import com.google.cloud.bigtable.gaxx.grpc.BigtableTransportChannelProvider; +import io.grpc.ManagedChannel; +import io.grpc.netty.shaded.io.netty.channel.ChannelFactory; import com.google.auth.Credentials; import com.google.auth.oauth2.ServiceAccountJwtAccessCredentials; import com.google.cloud.bigtable.data.v2.BigtableDataSettings; @@ -32,11 +42,15 @@ import com.google.cloud.bigtable.data.v2.stub.metrics.ErrorCountPerConnectionMetricTracker; import com.google.cloud.bigtable.data.v2.stub.metrics.MetricsProvider; import com.google.cloud.bigtable.data.v2.stub.metrics.NoopMetricsProvider; +import java.util.function.Supplier; import io.grpc.ManagedChannelBuilder; import io.grpc.opentelemetry.GrpcOpenTelemetry; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.sdk.OpenTelemetrySdk; import java.io.IOException; +import io.grpc.ManagedChannel; +import io.grpc.Channel; +import com.google.api.gax.grpc.GrpcTransportChannel; import java.net.URI; import java.net.URISyntaxException; import java.util.logging.Level; @@ -61,6 +75,47 @@ public static BigtableClientContext create(EnhancedBigtableStubSettings settings throws IOException { EnhancedBigtableStubSettings.Builder builder = settings.toBuilder(); + TransportChannelProvider transportChannelProvider = settings.getTransportChannelProvider(); + if (transportChannelProvider instanceof InstantiatingGrpcChannelProvider) { + InstantiatingGrpcChannelProvider provider = (InstantiatingGrpcChannelProvider) transportChannelProvider; + ChannelPoolSettings originalPoolSettings = ((InstantiatingGrpcChannelProvider) transportChannelProvider).getChannelPoolSettings(); + + BigtableChannelPoolSettings btPoolSettings = BigtableChannelPoolSettings.builder() + .setInitialChannelCount(originalPoolSettings.getInitialChannelCount()) + .setMinChannelCount(originalPoolSettings.getMinChannelCount()) + .setMaxChannelCount(originalPoolSettings.getMaxChannelCount()) + .setMinRpcsPerChannel(originalPoolSettings.getMinRpcsPerChannel()) + .setMaxRpcsPerChannel(originalPoolSettings.getMaxRpcsPerChannel()) + .setPreemptiveRefreshEnabled(originalPoolSettings.isPreemptiveRefreshEnabled()) + .build(); + + Supplier channelSupplier = + ()->{ + try { + Channel channel = (Channel) transportChannelProvider.getTransportChannel(); + return (ManagedChannel) channel; + } catch (IllegalStateException | IOException e) { + throw new IllegalStateException(e); + } + }; + + ChannelFactory channelFactory = + new ChannelFactory() { + @Override + public ManagedChannel createSingleChannel() { + return channelSupplier.get(); + } + }; + + BigtableChannelPool btChannelPool = BigtableChannelPool.create(btPoolSettings,channelFactory); + + BigtableTransportChannelProvider btTransportProvider = BigtableTransportChannelProvider.create( + (InstantiatingGrpcChannelProvider) transportChannelProvider, + (TransportChannel) btChannelPool); + + builder.setTransportChannelProvider(btTransportProvider); + } + // Set up credentials patchCredentials(builder); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java index aae154b7b57a..be5ea8c8d42c 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java @@ -53,7 +53,7 @@ * *

Package-private for internal use. */ -class BigtableChannelPool extends ManagedChannel { +public class BigtableChannelPool extends ManagedChannel { @VisibleForTesting static final Logger LOG = Logger.getLogger(BigtableChannelPool.class.getName()); @@ -68,7 +68,7 @@ class BigtableChannelPool extends ManagedChannel { private final AtomicInteger indexTicker = new AtomicInteger(); private final String authority; - static BigtableChannelPool create( + public static BigtableChannelPool create( BigtableChannelPoolSettings settings, ChannelFactory channelFactory) throws IOException { return new BigtableChannelPool( settings, channelFactory, Executors.newSingleThreadScheduledExecutor()); @@ -82,7 +82,7 @@ static BigtableChannelPool create( * @param executor periodically refreshes the channels */ @VisibleForTesting - BigtableChannelPool( + public BigtableChannelPool( BigtableChannelPoolSettings settings, ChannelFactory channelFactory, ScheduledExecutorService executor) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java new file mode 100644 index 000000000000..b3c94da0dc75 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java @@ -0,0 +1,149 @@ +/* + * Copyright 2017 Google LLC + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google LLC nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.google.cloud.bigtable.gaxx.grpc; + + import com.google.api.core.InternalExtensionOnly; + import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; + import com.google.auth.Credentials; + import com.google.common.base.Preconditions; + import java.io.IOException; + import java.util.Map; + import java.util.concurrent.Executor; + import java.util.concurrent.ScheduledExecutorService; + import com.google.api.gax.rpc.TransportChannel; + import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; + import com.google.api.gax.rpc.TransportChannelProvider; + import jdk.internal.net.http.websocket.Transport; + + +/** An instance of TransportChannelProvider that always provides the same TransportChannel. */ +@InternalExtensionOnly +public class BigtableTransportChannelProvider implements TransportChannelProvider { + + private final InstantiatingGrpcChannelProvider ogGrpcChannelProvider; + private final TransportChannel transportChannel; + + private BigtableTransportChannelProvider( + InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider, TransportChannel transportChannel) { + this.ogGrpcChannelProvider = instantiatingGrpcChannelProvider; + this.transportChannel = Preconditions.checkNotNull(transportChannel); + } + + @Override + public boolean shouldAutoClose() { + return ogGrpcChannelProvider.shouldAutoClose(); + } + + @Override + public boolean needsExecutor() { + return ogGrpcChannelProvider.needsExecutor(); + } + + @Override + public BigtableTransportChannelProvider withExecutor(ScheduledExecutorService executor) { + return withExecutor((Executor) executor); + } + + @Override + public BigtableTransportChannelProvider withExecutor(Executor executor) { + InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) ogGrpcChannelProvider.withExecutor(executor); + return new BigtableTransportChannelProvider(newChannelProvider, this.transportChannel); + } + + @Override + public boolean needsHeaders() { + return this.ogGrpcChannelProvider.needsHeaders(); + } + + @Override + public BigtableTransportChannelProvider withHeaders(Map headers) { + InstantiatingGrpcChannelProvider newChannelProvider = + (InstantiatingGrpcChannelProvider) + ogGrpcChannelProvider.withHeaders(headers); + return new BigtableTransportChannelProvider(newChannelProvider, this.transportChannel); + } + + @Override + public boolean needsEndpoint() { + return false; + } + + @Override + public TransportChannelProvider withEndpoint(String endpoint) { + InstantiatingGrpcChannelProvider newChannelProvider = + (InstantiatingGrpcChannelProvider) ogGrpcChannelProvider.withEndpoint(endpoint); + return new BigtableTransportChannelProvider(newChannelProvider, this.transportChannel); + } + + /** + * @deprecated FixedTransportChannelProvider doesn't support ChannelPool configuration + */ + @Deprecated + @Override + public boolean acceptsPoolSize() { + return ogGrpcChannelProvider.acceptsPoolSize(); + } + + /** + * @deprecated FixedTransportChannelProvider doesn't support ChannelPool configuration + */ + @Deprecated + @Override + public TransportChannelProvider withPoolSize(int size) { + InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) ogGrpcChannelProvider.withPoolSize(size); + return new BigtableTransportChannelProvider(newChannelProvider, this.transportChannel); + } + + @Override + public TransportChannel getTransportChannel() throws IOException { + return transportChannel; + } + + @Override + public String getTransportName() { + return transportChannel.getTransportName(); + } + + @Override + public boolean needsCredentials() { + return ogGrpcChannelProvider.needsCredentials(); + } + + @Override + public TransportChannelProvider withCredentials(Credentials credentials) { + InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) ogGrpcChannelProvider.withCredentials(credentials); + return new BigtableTransportChannelProvider(newChannelProvider, this.transportChannel); + } + + /** Creates a FixedTransportChannelProvider. */ + public static BigtableTransportChannelProvider create(InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider, TransportChannel transportChannel) { + return new BigtableTransportChannelProvider(instantiatingGrpcChannelProvider, TransportChannel transportChannel); + } +} \ No newline at end of file From ba498f06bb67ab72765251a0cb75e2a128ab6023 Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Thu, 5 Jun 2025 16:32:03 -0400 Subject: [PATCH 02/16] move channel pool creation into getTransportChannel() Change-Id: I0e4e1f056960ae55d2f89a372e92231133e61528 --- .../data/v2/stub/BigtableClientContext.java | 67 +++++++------- .../BigtableTransportChannelProvider.java | 87 +++++++++++-------- 2 files changed, 78 insertions(+), 76 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java index 8872b1988661..d77188d7ce1b 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Google LLC + * 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. @@ -27,11 +27,9 @@ import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPool; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.rpc.ClientContext; -import com.google.api.gax.rpc.TransportChannelProvider; import com.google.api.gax.grpc.ChannelFactory; import com.google.cloud.bigtable.gaxx.grpc.BigtableTransportChannelProvider; import io.grpc.ManagedChannel; -import io.grpc.netty.shaded.io.netty.channel.ChannelFactory; import com.google.auth.Credentials; import com.google.auth.oauth2.ServiceAccountJwtAccessCredentials; import com.google.cloud.bigtable.data.v2.BigtableDataSettings; @@ -48,9 +46,7 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.sdk.OpenTelemetrySdk; import java.io.IOException; -import io.grpc.ManagedChannel; import io.grpc.Channel; -import com.google.api.gax.grpc.GrpcTransportChannel; import java.net.URI; import java.net.URISyntaxException; import java.util.logging.Level; @@ -77,41 +73,36 @@ public static BigtableClientContext create(EnhancedBigtableStubSettings settings TransportChannelProvider transportChannelProvider = settings.getTransportChannelProvider(); if (transportChannelProvider instanceof InstantiatingGrpcChannelProvider) { - InstantiatingGrpcChannelProvider provider = (InstantiatingGrpcChannelProvider) transportChannelProvider; - ChannelPoolSettings originalPoolSettings = ((InstantiatingGrpcChannelProvider) transportChannelProvider).getChannelPoolSettings(); - - BigtableChannelPoolSettings btPoolSettings = BigtableChannelPoolSettings.builder() - .setInitialChannelCount(originalPoolSettings.getInitialChannelCount()) - .setMinChannelCount(originalPoolSettings.getMinChannelCount()) - .setMaxChannelCount(originalPoolSettings.getMaxChannelCount()) - .setMinRpcsPerChannel(originalPoolSettings.getMinRpcsPerChannel()) - .setMaxRpcsPerChannel(originalPoolSettings.getMaxRpcsPerChannel()) - .setPreemptiveRefreshEnabled(originalPoolSettings.isPreemptiveRefreshEnabled()) - .build(); - - Supplier channelSupplier = - ()->{ - try { - Channel channel = (Channel) transportChannelProvider.getTransportChannel(); - return (ManagedChannel) channel; - } catch (IllegalStateException | IOException e) { - throw new IllegalStateException(e); - } - }; - - ChannelFactory channelFactory = - new ChannelFactory() { - @Override - public ManagedChannel createSingleChannel() { - return channelSupplier.get(); - } - }; - - BigtableChannelPool btChannelPool = BigtableChannelPool.create(btPoolSettings,channelFactory); + // InstantiatingGrpcChannelProvider provider = (InstantiatingGrpcChannelProvider) transportChannelProvider; + // ChannelPoolSettings originalPoolSettings = ((InstantiatingGrpcChannelProvider) transportChannelProvider).getChannelPoolSettings(); + // InstantiatingGrpcChannelProvider singleChannelProvider = provider.toBuilder().setChannelPoolSettings(ChannelPoolSettings.staticallySized(1)).needsHeadsrs(false).build(); + // + // + // BigtableChannelPoolSettings btPoolSettings = BigtableChannelPoolSettings.builder() + // .setInitialChannelCount(originalPoolSettings.getInitialChannelCount()) + // .setMinChannelCount(originalPoolSettings.getMinChannelCount()) + // .setMaxChannelCount(originalPoolSettings.getMaxChannelCount()) + // .setMinRpcsPerChannel(originalPoolSettings.getMinRpcsPerChannel()) + // .setMaxRpcsPerChannel(originalPoolSettings.getMaxRpcsPerChannel()) + // .setPreemptiveRefreshEnabled(originalPoolSettings.isPreemptiveRefreshEnabled()) + // .build(); + // + // Supplier channelSupplier = + // ()->{ + // try { + // Channel channel = (Channel) singleChannelProvider.getTransportChannel(); + // return (ManagedChannel) channel; + // } catch (IllegalStateException | IOException e) { + // throw new IllegalStateException(e); + // } + // }; + // + // ChannelFactory channelFactory = channelSupplier::get; + // + // BigtableChannelPool btChannelPool = BigtableChannelPool.create(btPoolSettings,channelFactory); BigtableTransportChannelProvider btTransportProvider = BigtableTransportChannelProvider.create( - (InstantiatingGrpcChannelProvider) transportChannelProvider, - (TransportChannel) btChannelPool); + (InstantiatingGrpcChannelProvider) transportChannelProvider); builder.setTransportChannelProvider(btTransportProvider); } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java index b3c94da0dc75..441bc3229947 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java @@ -1,46 +1,35 @@ /* - * Copyright 2017 Google LLC + * Copyright 2025 Google LLC * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: + * 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 * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google LLC nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. + * https://www.apache.org/licenses/LICENSE-2.0 * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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.InternalExtensionOnly; + import com.google.api.gax.grpc.ChannelFactory; + import com.google.api.gax.grpc.ChannelPoolSettings; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.auth.Credentials; import com.google.common.base.Preconditions; + import io.grpc.Channel; + import io.grpc.ManagedChannel; import java.io.IOException; import java.util.Map; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; import com.google.api.gax.rpc.TransportChannel; - import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.rpc.TransportChannelProvider; - import jdk.internal.net.http.websocket.Transport; + import java.util.function.Supplier; /** An instance of TransportChannelProvider that always provides the same TransportChannel. */ @@ -48,12 +37,10 @@ public class BigtableTransportChannelProvider implements TransportChannelProvider { private final InstantiatingGrpcChannelProvider ogGrpcChannelProvider; - private final TransportChannel transportChannel; private BigtableTransportChannelProvider( - InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider, TransportChannel transportChannel) { - this.ogGrpcChannelProvider = instantiatingGrpcChannelProvider; - this.transportChannel = Preconditions.checkNotNull(transportChannel); + InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider) { + this.ogGrpcChannelProvider = Preconditions.checkNotNull(instantiatingGrpcChannelProvider); } @Override @@ -74,7 +61,7 @@ public BigtableTransportChannelProvider withExecutor(ScheduledExecutorService ex @Override public BigtableTransportChannelProvider withExecutor(Executor executor) { InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) ogGrpcChannelProvider.withExecutor(executor); - return new BigtableTransportChannelProvider(newChannelProvider, this.transportChannel); + return new BigtableTransportChannelProvider(newChannelProvider); } @Override @@ -87,7 +74,7 @@ public BigtableTransportChannelProvider withHeaders(Map headers) InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) ogGrpcChannelProvider.withHeaders(headers); - return new BigtableTransportChannelProvider(newChannelProvider, this.transportChannel); + return new BigtableTransportChannelProvider(newChannelProvider); } @Override @@ -99,7 +86,7 @@ public boolean needsEndpoint() { public TransportChannelProvider withEndpoint(String endpoint) { InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) ogGrpcChannelProvider.withEndpoint(endpoint); - return new BigtableTransportChannelProvider(newChannelProvider, this.transportChannel); + return new BigtableTransportChannelProvider(newChannelProvider); } /** @@ -118,12 +105,36 @@ public boolean acceptsPoolSize() { @Override public TransportChannelProvider withPoolSize(int size) { InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) ogGrpcChannelProvider.withPoolSize(size); - return new BigtableTransportChannelProvider(newChannelProvider, this.transportChannel); + return new BigtableTransportChannelProvider(newChannelProvider); } @Override public TransportChannel getTransportChannel() throws IOException { - return transportChannel; + ChannelPoolSettings ogPoolSettings = ogGrpcChannelProvider.getChannelPoolSettings(); + InstantiatingGrpcChannelProvider singleChannelProvider = ogGrpcChannelProvider.toBuilder().setChannelPoolSettings(ChannelPoolSettings.staticallySized(1)).build(); + + BigtableChannelPoolSettings btPoolSettings = BigtableChannelPoolSettings.builder() + .setInitialChannelCount(ogPoolSettings.getInitialChannelCount()) + .setMinChannelCount(ogPoolSettings.getMinChannelCount()) + .setMaxChannelCount(ogPoolSettings.getMaxChannelCount()) + .setMinRpcsPerChannel(ogPoolSettings.getMinRpcsPerChannel()) + .setMaxRpcsPerChannel(ogPoolSettings.getMaxRpcsPerChannel()) + .setPreemptiveRefreshEnabled(ogPoolSettings.isPreemptiveRefreshEnabled()) + .build(); + Supplier channelSupplier = ()-> { + try { + Channel channel = (Channel) singleChannelProvider.getTransportChannel(); + return (ManagedChannel) channel; + } catch (IllegalStateException | IOException e) { + throw new IllegalStateException(e); + } + }; + + ChannelFactory channelFactory = channelSupplier::get; + + BigtableChannelPool btChannelPool = BigtableChannelPool.create(btPoolSettings,channelFactory); + + return (TransportChannel) btChannelPool; } @Override @@ -139,11 +150,11 @@ public boolean needsCredentials() { @Override public TransportChannelProvider withCredentials(Credentials credentials) { InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) ogGrpcChannelProvider.withCredentials(credentials); - return new BigtableTransportChannelProvider(newChannelProvider, this.transportChannel); + return new BigtableTransportChannelProvider(newChannelProvider); } /** Creates a FixedTransportChannelProvider. */ - public static BigtableTransportChannelProvider create(InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider, TransportChannel transportChannel) { - return new BigtableTransportChannelProvider(instantiatingGrpcChannelProvider, TransportChannel transportChannel); + public static BigtableTransportChannelProvider create(InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider) { + return new BigtableTransportChannelProvider(instantiatingGrpcChannelProvider); } } \ No newline at end of file From 98b0c43478b036790746f8d2669eb87443517dad Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Tue, 10 Jun 2025 10:30:39 -0400 Subject: [PATCH 03/16] Cleanup transport channel provider and add thread safety Change-Id: I4867ac58e1aa77f65b9b14eb666c1e1bb3d24cc5 --- .../BigtableTransportChannelProvider.java | 108 +++++++++++------- 1 file changed, 67 insertions(+), 41 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java index 441bc3229947..262705b28265 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java @@ -18,10 +18,10 @@ import com.google.api.core.InternalExtensionOnly; 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.auth.Credentials; import com.google.common.base.Preconditions; - import io.grpc.Channel; import io.grpc.ManagedChannel; import java.io.IOException; import java.util.Map; @@ -34,23 +34,25 @@ /** An instance of TransportChannelProvider that always provides the same TransportChannel. */ @InternalExtensionOnly -public class BigtableTransportChannelProvider implements TransportChannelProvider { +public final class BigtableTransportChannelProvider implements TransportChannelProvider { - private final InstantiatingGrpcChannelProvider ogGrpcChannelProvider; + private final InstantiatingGrpcChannelProvider delegate; + private final Object lock = new Object(); + private volatile TransportChannel transportChannel; private BigtableTransportChannelProvider( InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider) { - this.ogGrpcChannelProvider = Preconditions.checkNotNull(instantiatingGrpcChannelProvider); + delegate = Preconditions.checkNotNull(instantiatingGrpcChannelProvider); } @Override public boolean shouldAutoClose() { - return ogGrpcChannelProvider.shouldAutoClose(); + return delegate.shouldAutoClose(); } @Override public boolean needsExecutor() { - return ogGrpcChannelProvider.needsExecutor(); + return delegate.needsExecutor(); } @Override @@ -60,96 +62,120 @@ public BigtableTransportChannelProvider withExecutor(ScheduledExecutorService ex @Override public BigtableTransportChannelProvider withExecutor(Executor executor) { - InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) ogGrpcChannelProvider.withExecutor(executor); + InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) delegate.withExecutor(executor); return new BigtableTransportChannelProvider(newChannelProvider); } @Override public boolean needsHeaders() { - return this.ogGrpcChannelProvider.needsHeaders(); + return delegate.needsHeaders(); } @Override public BigtableTransportChannelProvider withHeaders(Map headers) { InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) - ogGrpcChannelProvider.withHeaders(headers); + delegate.withHeaders(headers); return new BigtableTransportChannelProvider(newChannelProvider); } @Override public boolean needsEndpoint() { - return false; + return delegate.needsEndpoint(); } @Override public TransportChannelProvider withEndpoint(String endpoint) { InstantiatingGrpcChannelProvider newChannelProvider = - (InstantiatingGrpcChannelProvider) ogGrpcChannelProvider.withEndpoint(endpoint); + (InstantiatingGrpcChannelProvider) delegate.withEndpoint(endpoint); return new BigtableTransportChannelProvider(newChannelProvider); } - /** - * @deprecated FixedTransportChannelProvider doesn't support ChannelPool configuration - */ + @Deprecated @Override public boolean acceptsPoolSize() { - return ogGrpcChannelProvider.acceptsPoolSize(); + return delegate.acceptsPoolSize(); } - /** - * @deprecated FixedTransportChannelProvider doesn't support ChannelPool configuration - */ + @Deprecated @Override public TransportChannelProvider withPoolSize(int size) { - InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) ogGrpcChannelProvider.withPoolSize(size); + InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) delegate.withPoolSize(size); return new BigtableTransportChannelProvider(newChannelProvider); } @Override public TransportChannel getTransportChannel() throws IOException { - ChannelPoolSettings ogPoolSettings = ogGrpcChannelProvider.getChannelPoolSettings(); - InstantiatingGrpcChannelProvider singleChannelProvider = ogGrpcChannelProvider.toBuilder().setChannelPoolSettings(ChannelPoolSettings.staticallySized(1)).build(); - - BigtableChannelPoolSettings btPoolSettings = BigtableChannelPoolSettings.builder() - .setInitialChannelCount(ogPoolSettings.getInitialChannelCount()) - .setMinChannelCount(ogPoolSettings.getMinChannelCount()) - .setMaxChannelCount(ogPoolSettings.getMaxChannelCount()) - .setMinRpcsPerChannel(ogPoolSettings.getMinRpcsPerChannel()) - .setMaxRpcsPerChannel(ogPoolSettings.getMaxRpcsPerChannel()) - .setPreemptiveRefreshEnabled(ogPoolSettings.isPreemptiveRefreshEnabled()) - .build(); - Supplier channelSupplier = ()-> { + TransportChannel result = transportChannel; + if (result == null){ + synchronized(lock) { + result = transportChannel; + if (result == null) { + transportChannel = result = createTransportChannel(); + } + } + } + return result; + } + + private TransportChannel createTransportChannel() throws IOException { + // 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(); + + // Supplier channelSupplier = + ChannelFactory channelFactory = () -> { + // () -> { try { - Channel channel = (Channel) singleChannelProvider.getTransportChannel(); - return (ManagedChannel) channel; - } catch (IllegalStateException | IOException e) { - throw new IllegalStateException(e); + // Each call creates a new underlying channel for the pool. + GrpcTransportChannel channel = (GrpcTransportChannel) singleChannelProvider.getTransportChannel(); + return (ManagedChannel) channel.getChannel(); + } catch (IOException e) { + throw new java.io.UncheckedIOException(e); } }; + // ChannelFactory channelFactory = () -> (ManagedChannel) channelSupplier.get(); - ChannelFactory channelFactory = channelSupplier::get; + // Transfer pooling settings from the original delegate to the BigtableChannelPool. + ChannelPoolSettings ogPoolSettings = delegate.getChannelPoolSettings(); + BigtableChannelPoolSettings btPoolSettings = + BigtableChannelPoolSettings.builder() + .setInitialChannelCount(ogPoolSettings.getInitialChannelCount()) + .setMinChannelCount(ogPoolSettings.getMinChannelCount()) + .setMaxChannelCount(ogPoolSettings.getMaxChannelCount()) + .setMinRpcsPerChannel(ogPoolSettings.getMinRpcsPerChannel()) + .setMaxRpcsPerChannel(ogPoolSettings.getMaxRpcsPerChannel()) + .setPreemptiveRefreshEnabled(ogPoolSettings.isPreemptiveRefreshEnabled()) + .build(); - BigtableChannelPool btChannelPool = BigtableChannelPool.create(btPoolSettings,channelFactory); + BigtableChannelPool btChannelPool = + BigtableChannelPool.create(btPoolSettings, channelFactory); - return (TransportChannel) btChannelPool; + return GrpcTransportChannel.create(btChannelPool); } @Override public String getTransportName() { - return transportChannel.getTransportName(); + return "bigtable"; } @Override public boolean needsCredentials() { - return ogGrpcChannelProvider.needsCredentials(); + return delegate.needsCredentials(); } @Override public TransportChannelProvider withCredentials(Credentials credentials) { - InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) ogGrpcChannelProvider.withCredentials(credentials); + InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) delegate.withCredentials(credentials); return new BigtableTransportChannelProvider(newChannelProvider); } From a65f5a1269cf68ed4aef4a876e9e4fd23600bf62 Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Tue, 10 Jun 2025 11:20:11 -0400 Subject: [PATCH 04/16] remove comments Change-Id: I028776c18221c909b0bcdfffff62a1d77ee7f469 --- .../data/v2/stub/BigtableClientContext.java | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java index d77188d7ce1b..41edde5f6dff 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java @@ -73,34 +73,6 @@ public static BigtableClientContext create(EnhancedBigtableStubSettings settings TransportChannelProvider transportChannelProvider = settings.getTransportChannelProvider(); if (transportChannelProvider instanceof InstantiatingGrpcChannelProvider) { - // InstantiatingGrpcChannelProvider provider = (InstantiatingGrpcChannelProvider) transportChannelProvider; - // ChannelPoolSettings originalPoolSettings = ((InstantiatingGrpcChannelProvider) transportChannelProvider).getChannelPoolSettings(); - // InstantiatingGrpcChannelProvider singleChannelProvider = provider.toBuilder().setChannelPoolSettings(ChannelPoolSettings.staticallySized(1)).needsHeadsrs(false).build(); - // - // - // BigtableChannelPoolSettings btPoolSettings = BigtableChannelPoolSettings.builder() - // .setInitialChannelCount(originalPoolSettings.getInitialChannelCount()) - // .setMinChannelCount(originalPoolSettings.getMinChannelCount()) - // .setMaxChannelCount(originalPoolSettings.getMaxChannelCount()) - // .setMinRpcsPerChannel(originalPoolSettings.getMinRpcsPerChannel()) - // .setMaxRpcsPerChannel(originalPoolSettings.getMaxRpcsPerChannel()) - // .setPreemptiveRefreshEnabled(originalPoolSettings.isPreemptiveRefreshEnabled()) - // .build(); - // - // Supplier channelSupplier = - // ()->{ - // try { - // Channel channel = (Channel) singleChannelProvider.getTransportChannel(); - // return (ManagedChannel) channel; - // } catch (IllegalStateException | IOException e) { - // throw new IllegalStateException(e); - // } - // }; - // - // ChannelFactory channelFactory = channelSupplier::get; - // - // BigtableChannelPool btChannelPool = BigtableChannelPool.create(btPoolSettings,channelFactory); - BigtableTransportChannelProvider btTransportProvider = BigtableTransportChannelProvider.create( (InstantiatingGrpcChannelProvider) transportChannelProvider); From 29a3810103e12bbb5cf5265ecc1a60333078b4a1 Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Wed, 11 Jun 2025 18:24:09 -0400 Subject: [PATCH 05/16] fix Change-Id: I1e68454c1361104b66a51d509a2115067ce267ae --- .../data/v2/stub/BigtableClientContext.java | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java index 41edde5f6dff..a5708125ff5c 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java @@ -20,16 +20,10 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.CredentialsProvider; import com.google.api.gax.core.FixedCredentialsProvider; -import com.google.api.gax.grpc.ChannelPoolSettings; -import com.google.api.gax.rpc.TransportChannel; -import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPoolSettings; import com.google.api.gax.rpc.TransportChannelProvider; -import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPool; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.rpc.ClientContext; -import com.google.api.gax.grpc.ChannelFactory; import com.google.cloud.bigtable.gaxx.grpc.BigtableTransportChannelProvider; -import io.grpc.ManagedChannel; import com.google.auth.Credentials; import com.google.auth.oauth2.ServiceAccountJwtAccessCredentials; import com.google.cloud.bigtable.data.v2.BigtableDataSettings; @@ -40,13 +34,11 @@ import com.google.cloud.bigtable.data.v2.stub.metrics.ErrorCountPerConnectionMetricTracker; import com.google.cloud.bigtable.data.v2.stub.metrics.MetricsProvider; import com.google.cloud.bigtable.data.v2.stub.metrics.NoopMetricsProvider; -import java.util.function.Supplier; import io.grpc.ManagedChannelBuilder; import io.grpc.opentelemetry.GrpcOpenTelemetry; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.sdk.OpenTelemetrySdk; import java.io.IOException; -import io.grpc.Channel; import java.net.URI; import java.net.URISyntaxException; import java.util.logging.Level; @@ -71,13 +63,16 @@ public static BigtableClientContext create(EnhancedBigtableStubSettings settings throws IOException { EnhancedBigtableStubSettings.Builder builder = settings.toBuilder(); - TransportChannelProvider transportChannelProvider = settings.getTransportChannelProvider(); - if (transportChannelProvider instanceof InstantiatingGrpcChannelProvider) { - BigtableTransportChannelProvider btTransportProvider = BigtableTransportChannelProvider.create( - (InstantiatingGrpcChannelProvider) transportChannelProvider); - - builder.setTransportChannelProvider(btTransportProvider); - } + // TransportChannelProvider transportChannelProvider = settings.getTransportChannelProvider(); + // if (transportChannelProvider instanceof InstantiatingGrpcChannelProvider) { + // + // + // + // BigtableTransportChannelProvider btTransportProvider = BigtableTransportChannelProvider.create( + // (InstantiatingGrpcChannelProvider) transportChannelProvider); + // + // builder.setTransportChannelProvider(btTransportProvider); + // } // Set up credentials patchCredentials(builder); @@ -112,6 +107,7 @@ public static BigtableClientContext create(EnhancedBigtableStubSettings settings ? ((InstantiatingGrpcChannelProvider) builder.getTransportChannelProvider()).toBuilder() : null; + @Nullable OpenTelemetrySdk internalOtel = null; @Nullable ErrorCountPerConnectionMetricTracker errorCountPerConnectionMetricTracker = null; @@ -149,7 +145,13 @@ public static BigtableClientContext create(EnhancedBigtableStubSettings settings builder.getHeaderProvider().getHeaders())); } - builder.setTransportChannelProvider(transportProvider.build()); + + BigtableTransportChannelProvider btTransportProvider = BigtableTransportChannelProvider.create( + (InstantiatingGrpcChannelProvider) transportProvider.build()); + + builder.setTransportChannelProvider(btTransportProvider); + + //builder.setTransportChannelProvider(transportProvider.build()); } ClientContext clientContext = ClientContext.create(builder.build()); From bccb0ec167815d04025daa62cafcc64c607ad413 Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Thu, 12 Jun 2025 09:44:38 -0400 Subject: [PATCH 06/16] cleanup Change-Id: If2c94d93cec5903795cd723a9b7b26bd36efaf79 --- .../data/v2/stub/BigtableClientContext.java | 23 +---- .../BigtableTransportChannelProvider.java | 86 +++++++++---------- 2 files changed, 44 insertions(+), 65 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java index a5708125ff5c..9e8cd19aa90b 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java @@ -20,10 +20,8 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.CredentialsProvider; import com.google.api.gax.core.FixedCredentialsProvider; -import com.google.api.gax.rpc.TransportChannelProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.rpc.ClientContext; -import com.google.cloud.bigtable.gaxx.grpc.BigtableTransportChannelProvider; import com.google.auth.Credentials; import com.google.auth.oauth2.ServiceAccountJwtAccessCredentials; import com.google.cloud.bigtable.data.v2.BigtableDataSettings; @@ -34,6 +32,7 @@ import com.google.cloud.bigtable.data.v2.stub.metrics.ErrorCountPerConnectionMetricTracker; import com.google.cloud.bigtable.data.v2.stub.metrics.MetricsProvider; import com.google.cloud.bigtable.data.v2.stub.metrics.NoopMetricsProvider; +import com.google.cloud.bigtable.gaxx.grpc.BigtableTransportChannelProvider; import io.grpc.ManagedChannelBuilder; import io.grpc.opentelemetry.GrpcOpenTelemetry; import io.opentelemetry.api.OpenTelemetry; @@ -63,17 +62,6 @@ public static BigtableClientContext create(EnhancedBigtableStubSettings settings throws IOException { EnhancedBigtableStubSettings.Builder builder = settings.toBuilder(); - // TransportChannelProvider transportChannelProvider = settings.getTransportChannelProvider(); - // if (transportChannelProvider instanceof InstantiatingGrpcChannelProvider) { - // - // - // - // BigtableTransportChannelProvider btTransportProvider = BigtableTransportChannelProvider.create( - // (InstantiatingGrpcChannelProvider) transportChannelProvider); - // - // builder.setTransportChannelProvider(btTransportProvider); - // } - // Set up credentials patchCredentials(builder); @@ -107,7 +95,6 @@ public static BigtableClientContext create(EnhancedBigtableStubSettings settings ? ((InstantiatingGrpcChannelProvider) builder.getTransportChannelProvider()).toBuilder() : null; - @Nullable OpenTelemetrySdk internalOtel = null; @Nullable ErrorCountPerConnectionMetricTracker errorCountPerConnectionMetricTracker = null; @@ -145,13 +132,11 @@ public static BigtableClientContext create(EnhancedBigtableStubSettings settings builder.getHeaderProvider().getHeaders())); } - - BigtableTransportChannelProvider btTransportProvider = BigtableTransportChannelProvider.create( - (InstantiatingGrpcChannelProvider) transportProvider.build()); + BigtableTransportChannelProvider btTransportProvider = + BigtableTransportChannelProvider.create( + (InstantiatingGrpcChannelProvider) transportProvider.build()); builder.setTransportChannelProvider(btTransportProvider); - - //builder.setTransportChannelProvider(transportProvider.build()); } ClientContext clientContext = ClientContext.create(builder.build()); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java index 262705b28265..b2a43ca3bee2 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java @@ -15,22 +15,20 @@ */ package com.google.cloud.bigtable.gaxx.grpc; - import com.google.api.core.InternalExtensionOnly; - 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.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; - import com.google.api.gax.rpc.TransportChannel; - import com.google.api.gax.rpc.TransportChannelProvider; - import java.util.function.Supplier; - +import com.google.api.core.InternalExtensionOnly; +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 always provides the same TransportChannel. */ @InternalExtensionOnly @@ -57,12 +55,13 @@ public boolean needsExecutor() { @Override public BigtableTransportChannelProvider withExecutor(ScheduledExecutorService executor) { - return withExecutor((Executor) executor); + return withExecutor((Executor) executor); } @Override public BigtableTransportChannelProvider withExecutor(Executor executor) { - InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) delegate.withExecutor(executor); + InstantiatingGrpcChannelProvider newChannelProvider = + (InstantiatingGrpcChannelProvider) delegate.withExecutor(executor); return new BigtableTransportChannelProvider(newChannelProvider); } @@ -74,8 +73,7 @@ public boolean needsHeaders() { @Override public BigtableTransportChannelProvider withHeaders(Map headers) { InstantiatingGrpcChannelProvider newChannelProvider = - (InstantiatingGrpcChannelProvider) - delegate.withHeaders(headers); + (InstantiatingGrpcChannelProvider) delegate.withHeaders(headers); return new BigtableTransportChannelProvider(newChannelProvider); } @@ -91,26 +89,25 @@ public TransportChannelProvider withEndpoint(String 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); + InstantiatingGrpcChannelProvider newChannelProvider = + (InstantiatingGrpcChannelProvider) delegate.withPoolSize(size); return new BigtableTransportChannelProvider(newChannelProvider); } @Override public TransportChannel getTransportChannel() throws IOException { TransportChannel result = transportChannel; - if (result == null){ - synchronized(lock) { + if (result == null) { + synchronized (lock) { result = transportChannel; if (result == null) { transportChannel = result = createTransportChannel(); @@ -128,22 +125,18 @@ private TransportChannel createTransportChannel() throws IOException { // 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(); - - // Supplier channelSupplier = - ChannelFactory channelFactory = () -> { - // () -> { - try { - // Each call creates a new underlying channel for the pool. - GrpcTransportChannel channel = (GrpcTransportChannel) singleChannelProvider.getTransportChannel(); - return (ManagedChannel) channel.getChannel(); - } catch (IOException e) { - throw new java.io.UncheckedIOException(e); - } - }; - // ChannelFactory channelFactory = () -> (ManagedChannel) channelSupplier.get(); + 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); + } + }; // Transfer pooling settings from the original delegate to the BigtableChannelPool. ChannelPoolSettings ogPoolSettings = delegate.getChannelPoolSettings(); @@ -157,8 +150,7 @@ private TransportChannel createTransportChannel() throws IOException { .setPreemptiveRefreshEnabled(ogPoolSettings.isPreemptiveRefreshEnabled()) .build(); - BigtableChannelPool btChannelPool = - BigtableChannelPool.create(btPoolSettings, channelFactory); + BigtableChannelPool btChannelPool = BigtableChannelPool.create(btPoolSettings, channelFactory); return GrpcTransportChannel.create(btChannelPool); } @@ -175,12 +167,14 @@ public boolean needsCredentials() { @Override public TransportChannelProvider withCredentials(Credentials credentials) { - InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider) delegate.withCredentials(credentials); + InstantiatingGrpcChannelProvider newChannelProvider = + (InstantiatingGrpcChannelProvider) delegate.withCredentials(credentials); return new BigtableTransportChannelProvider(newChannelProvider); } /** Creates a FixedTransportChannelProvider. */ - public static BigtableTransportChannelProvider create(InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider) { + public static BigtableTransportChannelProvider create( + InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider) { return new BigtableTransportChannelProvider(instantiatingGrpcChannelProvider); } -} \ No newline at end of file +} From 542de27543491e0923cc9485bba23a12fb53685e Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Fri, 13 Jun 2025 15:29:48 -0400 Subject: [PATCH 07/16] factor out conversion util Change-Id: I8fc15d7d028c773385cd557aa6d2fb3a2453a1da --- .../gaxx/grpc/BigtableChannelPool.java | 11 +-- .../BigtableTransportChannelProvider.java | 28 ++---- .../gaxx/utils/ChannelPoolSettingsCopier.java | 24 +++++ .../gaxx/utils/ChannelPoolCopyTest.java | 91 +++++++++++++++++++ 4 files changed, 127 insertions(+), 27 deletions(-) create mode 100644 google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolSettingsCopier.java create mode 100644 google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java index be5ea8c8d42c..05c631480b5c 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java @@ -46,13 +46,12 @@ /** * A {@link ManagedChannel} that will send requests round-robin via a set of channels. * - *

In addition to spreading requests over a set of child connections, the pool will also actively - * manage the lifecycle of the channels. Currently lifecycle management is limited to pre-emptively - * replacing channels every hour. In the future it will dynamically size the pool based on number of - * outstanding requests. + *

Spreads over a set of child connections, and actively manages lifecycle of connections. + * Dynamically resizes pool based on number of outstanding connections. * - *

Package-private for internal use. + *

Internal API */ +@InternalApi("") public class BigtableChannelPool extends ManagedChannel { @VisibleForTesting static final Logger LOG = Logger.getLogger(BigtableChannelPool.class.getName()); @@ -82,7 +81,7 @@ public static BigtableChannelPool create( * @param executor periodically refreshes the channels */ @VisibleForTesting - public BigtableChannelPool( + BigtableChannelPool( BigtableChannelPoolSettings settings, ChannelFactory channelFactory, ScheduledExecutorService executor) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java index b2a43ca3bee2..8abdffb5793f 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java @@ -15,7 +15,7 @@ */ package com.google.cloud.bigtable.gaxx.grpc; -import com.google.api.core.InternalExtensionOnly; +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; @@ -23,6 +23,8 @@ import com.google.api.gax.rpc.TransportChannel; import com.google.api.gax.rpc.TransportChannelProvider; import com.google.auth.Credentials; +import com.google.cloud.bigtable.gaxx.utils.ChannelPoolSettingsCopier; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import io.grpc.ManagedChannel; import java.io.IOException; @@ -31,12 +33,11 @@ import java.util.concurrent.ScheduledExecutorService; /** An instance of TransportChannelProvider that always provides the same TransportChannel. */ -@InternalExtensionOnly +@InternalApi public final class BigtableTransportChannelProvider implements TransportChannelProvider { private final InstantiatingGrpcChannelProvider delegate; - private final Object lock = new Object(); - private volatile TransportChannel transportChannel; + private TransportChannel transportChannel; private BigtableTransportChannelProvider( InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider) { @@ -106,13 +107,8 @@ public TransportChannelProvider withPoolSize(int size) { @Override public TransportChannel getTransportChannel() throws IOException { TransportChannel result = transportChannel; - if (result == null) { - synchronized (lock) { - result = transportChannel; - if (result == null) { + if (transportChannel == null) { transportChannel = result = createTransportChannel(); - } - } } return result; } @@ -138,17 +134,7 @@ private TransportChannel createTransportChannel() throws IOException { } }; - // Transfer pooling settings from the original delegate to the BigtableChannelPool. - ChannelPoolSettings ogPoolSettings = delegate.getChannelPoolSettings(); - BigtableChannelPoolSettings btPoolSettings = - BigtableChannelPoolSettings.builder() - .setInitialChannelCount(ogPoolSettings.getInitialChannelCount()) - .setMinChannelCount(ogPoolSettings.getMinChannelCount()) - .setMaxChannelCount(ogPoolSettings.getMaxChannelCount()) - .setMinRpcsPerChannel(ogPoolSettings.getMinRpcsPerChannel()) - .setMaxRpcsPerChannel(ogPoolSettings.getMaxRpcsPerChannel()) - .setPreemptiveRefreshEnabled(ogPoolSettings.isPreemptiveRefreshEnabled()) - .build(); + BigtableChannelPoolSettings btPoolSettings = ChannelPoolSettingsCopier.toBigtableChannelPoolSettings(delegate.getChannelPoolSettings()); BigtableChannelPool btChannelPool = BigtableChannelPool.create(btPoolSettings, channelFactory); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolSettingsCopier.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolSettingsCopier.java new file mode 100644 index 000000000000..b7a015c9f6c3 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolSettingsCopier.java @@ -0,0 +1,24 @@ +package com.google.cloud.bigtable.gaxx.utils; + +import com.google.api.gax.grpc.ChannelPoolSettings; +import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPoolSettings; + +/** + * Utility class to convert ChannelPoolSettings to BigtableChannelPoolSettings. + */ +public class ChannelPoolSettingsCopier { + public static BigtableChannelPoolSettings toBigtableChannelPoolSettings(ChannelPoolSettings original) { + if (original == null) { + return null; + } + + return BigtableChannelPoolSettings.builder() + .setMinRpcsPerChannel(original.getMinRpcsPerChannel()) + .setMaxRpcsPerChannel(original.getMaxRpcsPerChannel()) + .setMinChannelCount(original.getMinChannelCount()) + .setMaxChannelCount(original.getMaxChannelCount()) + .setInitialChannelCount(original.getInitialChannelCount()) + .setPreemptiveRefreshEnabled(original.isPreemptiveRefreshEnabled()) + .build(); + } +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java new file mode 100644 index 000000000000..8a93569eae05 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java @@ -0,0 +1,91 @@ +package com.google.cloud.bigtable.gaxx.utils; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.api.gax.grpc.ChannelPoolSettings; +import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPoolSettings; +import java.lang.reflect.Modifier; +import java.util.List; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.stream.Collectors; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +@RunWith(JUnit4.class) +public class ChannelPoolCopyTest { + @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); + + @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 = + ChannelPoolSettingsCopier.toBigtableChannelPoolSettings(originalSettings); + assertSettingsCopiedCorrectly(originalSettings, copiedSettings); + } + + @Test + public void testToBigtableChannelPoolSettingsDefaultValuesCopiesCorrectly() throws Exception { + // 1. Arrange + ChannelPoolSettings originalSettings = ChannelPoolSettings.builder().build(); + + // 2. Act + BigtableChannelPoolSettings copiedSettings = + ChannelPoolSettingsCopier.toBigtableChannelPoolSettings(originalSettings); + + // 3. Assert + assertSettingsCopiedCorrectly(originalSettings, copiedSettings); + } + + @Test + public void testToBigtableChannelPoolSettingsNullInputReturnsNull() { + ChannelPoolSettings originalSettings = null; + BigtableChannelPoolSettings copiedSettings = + ChannelPoolSettingsCopier.toBigtableChannelPoolSettings(originalSettings); + assertThat(copiedSettings).isNull(); + } + + private void assertSettingsCopiedCorrectly( + ChannelPoolSettings originalSettings, BigtableChannelPoolSettings copiedSettings) + throws Exception { + Class originalSettingsClass = ChannelPoolSettings.class; + + // Get all public abstract methods from ChannelPoolSettings that start with "get" or "is" + // and exclude methods from Object.class + List originalPoolGetters = Arrays.stream(ChannelPoolSettings.class.getMethods()) + .filter(method -> Modifier.isPublic(method.getModifiers()) + && Modifier.isAbstract(method.getModifiers()) + && (method.getName().startsWith("get") || method.getName().startsWith("is")) + && method.getDeclaringClass() != Object.class) // Filter out java.lang.Object.getClass() + .collect(Collectors.toList()); + + for (Method getterMethod : originalPoolGetters) { + try { + Object originalValue = getterMethod.invoke(originalSettings); + Method correspondingMethod = BigtableChannelPoolSettings.class.getMethod(getterMethod.getName()); + Object copiedValue = correspondingMethod.invoke(copiedSettings); + + assertThat(copiedValue).isEqualTo(originalValue); + } catch (ReflectiveOperationException e) { + throw new AssertionError( + String.format("Reflection error accessing method '%s': %s", getterMethod.getName(), e.getMessage()), e); + } catch (Exception e) { // Catch any other unexpected exceptions + throw new Exception( + String.format("Unexpected error during comparison for method '%s': %s", getterMethod.getName(), e.getMessage()), e); + } + } + } +} \ No newline at end of file From 76b1c3ec457bf4b3a9b736ad2d00f11af0b5aa77 Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Sun, 15 Jun 2025 19:31:23 -0400 Subject: [PATCH 08/16] consolidate channel pool copying into BigtableChannelPoolSettings, refine test Change-Id: I90bb9d20a10e9b930507bf260b8bb77e2628abe2 --- .../grpc/BigtableChannelPoolSettings.java | 13 ++++ .../BigtableTransportChannelProvider.java | 4 +- .../gaxx/utils/ChannelPoolCopyTest.java | 65 ++++++++----------- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettings.java index 9ea4973900a9..a16df8f7b2cb 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettings.java @@ -17,6 +17,8 @@ import com.google.api.core.BetaApi; import com.google.auto.value.AutoValue; +import com.google.api.gax.grpc.ChannelPoolSettings; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import java.time.Duration; @@ -112,6 +114,17 @@ boolean isStaticSize() { public abstract Builder toBuilder(); + public static BigtableChannelPoolSettings copyFrom(ChannelPoolSettings externalSettings) { + return BigtableChannelPoolSettings.builder() + .setMinRpcsPerChannel(externalSettings.getMinRpcsPerChannel()) + .setMaxRpcsPerChannel(externalSettings.getMaxRpcsPerChannel()) + .setMinChannelCount(externalSettings.getMinChannelCount()) + .setMaxChannelCount(externalSettings.getMaxChannelCount()) + .setInitialChannelCount(externalSettings.getInitialChannelCount()) + .setPreemptiveRefreshEnabled(externalSettings.isPreemptiveRefreshEnabled()) + .build(); + } + public static BigtableChannelPoolSettings staticallySized(int size) { return builder() .setInitialChannelCount(size) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java index 8abdffb5793f..67c4dfe1ea95 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java @@ -23,8 +23,6 @@ import com.google.api.gax.rpc.TransportChannel; import com.google.api.gax.rpc.TransportChannelProvider; import com.google.auth.Credentials; -import com.google.cloud.bigtable.gaxx.utils.ChannelPoolSettingsCopier; -import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import io.grpc.ManagedChannel; import java.io.IOException; @@ -134,7 +132,7 @@ private TransportChannel createTransportChannel() throws IOException { } }; - BigtableChannelPoolSettings btPoolSettings = ChannelPoolSettingsCopier.toBigtableChannelPoolSettings(delegate.getChannelPoolSettings()); + BigtableChannelPoolSettings btPoolSettings = BigtableChannelPoolSettings.copyFrom(delegate.getChannelPoolSettings()); BigtableChannelPool btChannelPool = BigtableChannelPool.create(btPoolSettings, channelFactory); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java index 8a93569eae05..91fc403b49ad 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java @@ -5,7 +5,8 @@ import com.google.api.gax.grpc.ChannelPoolSettings; import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPoolSettings; import java.lang.reflect.Modifier; -import java.util.List; +import java.util.Set; +import com.google.common.collect.ImmutableSet; import java.lang.reflect.Method; import java.util.Arrays; import java.util.stream.Collectors; @@ -32,60 +33,48 @@ public void testToBigtableChannelPoolSettingsAllFieldsSetCopiesCorrectly() throw .setPreemptiveRefreshEnabled(true) .build(); - BigtableChannelPoolSettings copiedSettings = - ChannelPoolSettingsCopier.toBigtableChannelPoolSettings(originalSettings); + BigtableChannelPoolSettings copiedSettings = BigtableChannelPoolSettings.copyFrom(originalSettings); assertSettingsCopiedCorrectly(originalSettings, copiedSettings); } @Test public void testToBigtableChannelPoolSettingsDefaultValuesCopiesCorrectly() throws Exception { - // 1. Arrange ChannelPoolSettings originalSettings = ChannelPoolSettings.builder().build(); - - // 2. Act - BigtableChannelPoolSettings copiedSettings = - ChannelPoolSettingsCopier.toBigtableChannelPoolSettings(originalSettings); - - // 3. Assert + BigtableChannelPoolSettings copiedSettings = BigtableChannelPoolSettings.copyFrom(originalSettings); assertSettingsCopiedCorrectly(originalSettings, copiedSettings); } - @Test - public void testToBigtableChannelPoolSettingsNullInputReturnsNull() { - ChannelPoolSettings originalSettings = null; - BigtableChannelPoolSettings copiedSettings = - ChannelPoolSettingsCopier.toBigtableChannelPoolSettings(originalSettings); - assertThat(copiedSettings).isNull(); - } + // @Test + // public void testToBigtableChannelPoolSettingsNullInputReturnsNull() { + // ChannelPoolSettings originalSettings = null; + // BigtableChannelPoolSettings copiedSettings = + // ChannelPoolSettingsCopier.toBigtableChannelPoolSettings(originalSettings); + // assertThat(copiedSettings).isNull(); + // } private void assertSettingsCopiedCorrectly( ChannelPoolSettings originalSettings, BigtableChannelPoolSettings copiedSettings) throws Exception { - Class originalSettingsClass = ChannelPoolSettings.class; - // Get all public abstract methods from ChannelPoolSettings that start with "get" or "is" - // and exclude methods from Object.class - List originalPoolGetters = Arrays.stream(ChannelPoolSettings.class.getMethods()) + Set supportedGetters = ImmutableSet.of("getMinRpcsPerChannel", "getMaxRpcsPerChannel", "getMinChannelCount", "getMaxChannelCount", "getInitialChannelCount", "isPreemptiveRefreshEnabled", "isStaticSize"); + + Set actualGetters = Arrays.stream(ChannelPoolSettings.class.getDeclaredMethods()) .filter(method -> Modifier.isPublic(method.getModifiers()) && Modifier.isAbstract(method.getModifiers()) - && (method.getName().startsWith("get") || method.getName().startsWith("is")) - && method.getDeclaringClass() != Object.class) // Filter out java.lang.Object.getClass() - .collect(Collectors.toList()); + && (method.getName().startsWith("get") || method.getName().startsWith("is"))) + .map(Method::getName) + .collect(Collectors.toSet()); - for (Method getterMethod : originalPoolGetters) { - try { - Object originalValue = getterMethod.invoke(originalSettings); - Method correspondingMethod = BigtableChannelPoolSettings.class.getMethod(getterMethod.getName()); - Object copiedValue = correspondingMethod.invoke(copiedSettings); + // If this fails then we need to add support for the additional attributes on the gax ChannelPool + // Relevant things to update the copier and the other tests in this file + assertThat(supportedGetters).containsAtLeastElementsIn(actualGetters); - assertThat(copiedValue).isEqualTo(originalValue); - } catch (ReflectiveOperationException e) { - throw new AssertionError( - String.format("Reflection error accessing method '%s': %s", getterMethod.getName(), e.getMessage()), e); - } catch (Exception e) { // Catch any other unexpected exceptions - throw new Exception( - String.format("Unexpected error during comparison for method '%s': %s", getterMethod.getName(), e.getMessage()), e); - } - } + 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()); } } \ No newline at end of file From 6f6e8f954f052ef78c66f1027043e550a2ef7483 Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Sun, 15 Jun 2025 19:32:03 -0400 Subject: [PATCH 09/16] remove ChannelPoolSettingsCopier Change-Id: I7beff1ffdde48c3417f5d2b362e0ad556ba0669c --- .../gaxx/utils/ChannelPoolSettingsCopier.java | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolSettingsCopier.java diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolSettingsCopier.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolSettingsCopier.java deleted file mode 100644 index b7a015c9f6c3..000000000000 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolSettingsCopier.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.google.cloud.bigtable.gaxx.utils; - -import com.google.api.gax.grpc.ChannelPoolSettings; -import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPoolSettings; - -/** - * Utility class to convert ChannelPoolSettings to BigtableChannelPoolSettings. - */ -public class ChannelPoolSettingsCopier { - public static BigtableChannelPoolSettings toBigtableChannelPoolSettings(ChannelPoolSettings original) { - if (original == null) { - return null; - } - - return BigtableChannelPoolSettings.builder() - .setMinRpcsPerChannel(original.getMinRpcsPerChannel()) - .setMaxRpcsPerChannel(original.getMaxRpcsPerChannel()) - .setMinChannelCount(original.getMinChannelCount()) - .setMaxChannelCount(original.getMaxChannelCount()) - .setInitialChannelCount(original.getInitialChannelCount()) - .setPreemptiveRefreshEnabled(original.isPreemptiveRefreshEnabled()) - .build(); - } -} From 02583c327673be3340583ac35c3945581d222573 Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Sun, 15 Jun 2025 19:40:11 -0400 Subject: [PATCH 10/16] lint Change-Id: I92463834cdc294436608a7184054a2c6324d8f48 --- .../grpc/BigtableChannelPoolSettings.java | 3 +- .../BigtableTransportChannelProvider.java | 5 +- .../gaxx/utils/ChannelPoolCopyTest.java | 62 +++++++++++++------ 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettings.java index a16df8f7b2cb..e94a7665e81e 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettings.java @@ -16,9 +16,8 @@ package com.google.cloud.bigtable.gaxx.grpc; import com.google.api.core.BetaApi; -import com.google.auto.value.AutoValue; import com.google.api.gax.grpc.ChannelPoolSettings; -import com.google.common.annotations.VisibleForTesting; +import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; import java.time.Duration; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java index 67c4dfe1ea95..b09d450c5d25 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java @@ -106,7 +106,7 @@ public TransportChannelProvider withPoolSize(int size) { public TransportChannel getTransportChannel() throws IOException { TransportChannel result = transportChannel; if (transportChannel == null) { - transportChannel = result = createTransportChannel(); + transportChannel = result = createTransportChannel(); } return result; } @@ -132,7 +132,8 @@ private TransportChannel createTransportChannel() throws IOException { } }; - BigtableChannelPoolSettings btPoolSettings = BigtableChannelPoolSettings.copyFrom(delegate.getChannelPoolSettings()); + BigtableChannelPoolSettings btPoolSettings = + BigtableChannelPoolSettings.copyFrom(delegate.getChannelPoolSettings()); BigtableChannelPool btChannelPool = BigtableChannelPool.create(btPoolSettings, channelFactory); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java index 91fc403b49ad..f2b2fba0df9d 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java @@ -4,11 +4,11 @@ import com.google.api.gax.grpc.ChannelPoolSettings; import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPoolSettings; -import java.lang.reflect.Modifier; -import java.util.Set; 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.Rule; import org.junit.Test; @@ -33,14 +33,16 @@ public void testToBigtableChannelPoolSettingsAllFieldsSetCopiesCorrectly() throw .setPreemptiveRefreshEnabled(true) .build(); - BigtableChannelPoolSettings copiedSettings = BigtableChannelPoolSettings.copyFrom(originalSettings); + BigtableChannelPoolSettings copiedSettings = + BigtableChannelPoolSettings.copyFrom(originalSettings); assertSettingsCopiedCorrectly(originalSettings, copiedSettings); } @Test public void testToBigtableChannelPoolSettingsDefaultValuesCopiesCorrectly() throws Exception { ChannelPoolSettings originalSettings = ChannelPoolSettings.builder().build(); - BigtableChannelPoolSettings copiedSettings = BigtableChannelPoolSettings.copyFrom(originalSettings); + BigtableChannelPoolSettings copiedSettings = + BigtableChannelPoolSettings.copyFrom(originalSettings); assertSettingsCopiedCorrectly(originalSettings, copiedSettings); } @@ -56,25 +58,45 @@ private void assertSettingsCopiedCorrectly( ChannelPoolSettings originalSettings, BigtableChannelPoolSettings copiedSettings) throws Exception { - Set supportedGetters = ImmutableSet.of("getMinRpcsPerChannel", "getMaxRpcsPerChannel", "getMinChannelCount", "getMaxChannelCount", "getInitialChannelCount", "isPreemptiveRefreshEnabled", "isStaticSize"); + Set supportedGetters = + ImmutableSet.of( + "getMinRpcsPerChannel", + "getMaxRpcsPerChannel", + "getMinChannelCount", + "getMaxChannelCount", + "getInitialChannelCount", + "isPreemptiveRefreshEnabled", + "isStaticSize"); - Set 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()); + Set 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 + // If this fails then we need to add support for the additional attributes on the gax + // ChannelPool // Relevant things to update the copier and the other tests in this file 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()); + 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()); } -} \ No newline at end of file +} From c6adaae4fcaf5c7f0e6002e8b838fd5da7c4adce Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Sun, 15 Jun 2025 19:50:22 -0400 Subject: [PATCH 11/16] cleanup Change-Id: I14bb659b6e390b50b0a8b43eba920864d0dc6ef3 --- .../bigtable/gaxx/utils/ChannelPoolCopyTest.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java index f2b2fba0df9d..cdc61f4493a2 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java @@ -46,14 +46,6 @@ public void testToBigtableChannelPoolSettingsDefaultValuesCopiesCorrectly() thro assertSettingsCopiedCorrectly(originalSettings, copiedSettings); } - // @Test - // public void testToBigtableChannelPoolSettingsNullInputReturnsNull() { - // ChannelPoolSettings originalSettings = null; - // BigtableChannelPoolSettings copiedSettings = - // ChannelPoolSettingsCopier.toBigtableChannelPoolSettings(originalSettings); - // assertThat(copiedSettings).isNull(); - // } - private void assertSettingsCopiedCorrectly( ChannelPoolSettings originalSettings, BigtableChannelPoolSettings copiedSettings) throws Exception { @@ -80,8 +72,7 @@ private void assertSettingsCopiedCorrectly( .collect(Collectors.toSet()); // If this fails then we need to add support for the additional attributes on the gax - // ChannelPool - // Relevant things to update the copier and the other tests in this file + // ChannelPool by updating the BigtableChannelPoolSettings.copyFrom method assertThat(supportedGetters).containsAtLeastElementsIn(actualGetters); assertThat(originalSettings.getInitialChannelCount()) From 81ee7cc3116d5dd2ff0ff11790de65b20f84b67c Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Mon, 16 Jun 2025 10:47:21 -0400 Subject: [PATCH 12/16] rename test, return different channel every time Change-Id: Ifd84786b224109b73b6acb13fd08c3f892a48f12 --- .../gaxx/grpc/BigtableTransportChannelProvider.java | 7 +------ .../BigtableChannelPoolSettingsTest.java} | 5 ++--- 2 files changed, 3 insertions(+), 9 deletions(-) rename google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/{utils/ChannelPoolCopyTest.java => grpc/BigtableChannelPoolSettingsTest.java} (95%) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java index b09d450c5d25..313c64953747 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java @@ -35,7 +35,6 @@ public final class BigtableTransportChannelProvider implements TransportChannelProvider { private final InstantiatingGrpcChannelProvider delegate; - private TransportChannel transportChannel; private BigtableTransportChannelProvider( InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider) { @@ -104,11 +103,7 @@ public TransportChannelProvider withPoolSize(int size) { @Override public TransportChannel getTransportChannel() throws IOException { - TransportChannel result = transportChannel; - if (transportChannel == null) { - transportChannel = result = createTransportChannel(); - } - return result; + return createTransportChannel(); } private TransportChannel createTransportChannel() throws IOException { diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettingsTest.java similarity index 95% rename from google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java rename to google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettingsTest.java index cdc61f4493a2..cbea0c4e47f9 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/utils/ChannelPoolCopyTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettingsTest.java @@ -1,9 +1,8 @@ -package com.google.cloud.bigtable.gaxx.utils; +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.cloud.bigtable.gaxx.grpc.BigtableChannelPoolSettings; import com.google.common.collect.ImmutableSet; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -18,7 +17,7 @@ import org.mockito.junit.MockitoRule; @RunWith(JUnit4.class) -public class ChannelPoolCopyTest { +public class BigtableChannelPoolSettingsTest { @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); @Test From 6e1321a336d6516f930a34670c66d09c3b50e31b Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Mon, 16 Jun 2025 10:58:52 -0400 Subject: [PATCH 13/16] rename createTransportChannel to getTransportChannel Change-Id: I65972734a494cbf5cece251edfb871d493a48d1c --- .../bigtable/gaxx/grpc/BigtableTransportChannelProvider.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java index 313c64953747..77c5e9ec1d88 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java @@ -103,10 +103,6 @@ public TransportChannelProvider withPoolSize(int size) { @Override public TransportChannel getTransportChannel() throws IOException { - return createTransportChannel(); - } - - private TransportChannel createTransportChannel() throws IOException { // This provider's main purpose is to replace the default GAX ChannelPool // with a custom BigtableChannelPool, reusing the delegate's configuration. From 34d1bd4df159bb40bc91a3ada99df7c43eaa94b0 Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Mon, 16 Jun 2025 12:07:15 -0400 Subject: [PATCH 14/16] nits Change-Id: I340c377678834ff07b1c4b43afbc89edfe645b39 --- .../google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java | 2 +- .../bigtable/gaxx/grpc/BigtableTransportChannelProvider.java | 5 +++-- .../bigtable/gaxx/grpc/BigtableChannelPoolSettingsTest.java | 4 ---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java index 05c631480b5c..0d2c15a15533 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java @@ -51,7 +51,7 @@ * *

Internal API */ -@InternalApi("") +@InternalApi public class BigtableChannelPool extends ManagedChannel { @VisibleForTesting static final Logger LOG = Logger.getLogger(BigtableChannelPool.class.getName()); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java index 77c5e9ec1d88..d20766f8b18e 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java @@ -30,7 +30,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; -/** An instance of TransportChannelProvider that always provides the same TransportChannel. */ +/** An instance of TransportChannelProvider that provides a TransportChannel through a supplied InstantiatingGrpcChannelProvider. */ @InternalApi public final class BigtableTransportChannelProvider implements TransportChannelProvider { @@ -101,6 +101,7 @@ public TransportChannelProvider withPoolSize(int size) { return new BigtableTransportChannelProvider(newChannelProvider); } + /**Expected to only be called once when BigtableClientContext is created*/ @Override public TransportChannel getTransportChannel() throws IOException { // This provider's main purpose is to replace the default GAX ChannelPool @@ -148,7 +149,7 @@ public TransportChannelProvider withCredentials(Credentials credentials) { return new BigtableTransportChannelProvider(newChannelProvider); } - /** Creates a FixedTransportChannelProvider. */ + /** Creates a BigtableTransportChannelProvider. */ public static BigtableTransportChannelProvider create( InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider) { return new BigtableTransportChannelProvider(instantiatingGrpcChannelProvider); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettingsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettingsTest.java index cbea0c4e47f9..b601b0d955ba 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettingsTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettingsTest.java @@ -9,16 +9,12 @@ import java.util.Arrays; import java.util.Set; import java.util.stream.Collectors; -import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; @RunWith(JUnit4.class) public class BigtableChannelPoolSettingsTest { - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); @Test public void testToBigtableChannelPoolSettingsAllFieldsSetCopiesCorrectly() throws Exception { From 33a586a60bb66d6305d4bf1d079157d8d42b23ea Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Mon, 16 Jun 2025 12:09:19 -0400 Subject: [PATCH 15/16] lint Change-Id: Ia7c4441caf4e0e4b74858c4209ba7a9f9cd96347 --- .../gaxx/grpc/BigtableTransportChannelProvider.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java index d20766f8b18e..abbf12763675 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java @@ -30,7 +30,10 @@ import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; -/** An instance of TransportChannelProvider that provides a TransportChannel through a supplied InstantiatingGrpcChannelProvider. */ +/** + * An instance of TransportChannelProvider that provides a TransportChannel through a supplied + * InstantiatingGrpcChannelProvider. + */ @InternalApi public final class BigtableTransportChannelProvider implements TransportChannelProvider { @@ -101,7 +104,7 @@ public TransportChannelProvider withPoolSize(int size) { return new BigtableTransportChannelProvider(newChannelProvider); } - /**Expected to only be called once when BigtableClientContext is created*/ + /** Expected to only be called once when BigtableClientContext is created */ @Override public TransportChannel getTransportChannel() throws IOException { // This provider's main purpose is to replace the default GAX ChannelPool From d43c796931379584d799d1b555c52e5e94712f87 Mon Sep 17 00:00:00 2001 From: Liz Nichols Date: Mon, 16 Jun 2025 15:15:11 -0400 Subject: [PATCH 16/16] add copyright Change-Id: I0bdea5e891b27f87972b0cf4f7023f10136f627a --- .../grpc/BigtableChannelPoolSettingsTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettingsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettingsTest.java index b601b0d955ba..28d5a437386e 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettingsTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolSettingsTest.java @@ -1,3 +1,18 @@ +/* + * 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 static com.google.common.truth.Truth.assertThat;