-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(spanner): avoid double grpc-gcp wrapping for directpath fallback #13155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rahul2393
wants to merge
4
commits into
main
Choose a base branch
from
directpath-fix-1-remove-double-grpc-gcp-wrap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8d9d751
fix(spanner): avoid double grpc-gcp wrapping for directpath fallback
rahul2393 b02389f
fix lint
rahul2393 d25747f
Merge branch 'main' into directpath-fix-1-remove-double-grpc-gcp-wrap
rahul2393 3132a9d
test(spanner): add connection count test
olavloite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
...-spanner/src/test/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpcConnectionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| /* | ||
| * Copyright 2026 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.spanner.spi.v1; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assume.assumeTrue; | ||
|
|
||
| import com.google.cloud.NoCredentials; | ||
| import com.google.cloud.spanner.MockSpannerServiceImpl; | ||
| import com.google.cloud.spanner.SpannerOptions; | ||
| import com.google.common.base.Stopwatch; | ||
| import io.grpc.Attributes; | ||
| import io.grpc.ManagedChannelBuilder; | ||
| import io.grpc.Server; | ||
| import io.grpc.ServerTransportFilter; | ||
| import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder; | ||
| import java.net.InetSocketAddress; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.JUnit4; | ||
|
|
||
| @RunWith(JUnit4.class) | ||
| public class GapicSpannerRpcConnectionTest { | ||
|
|
||
| private static MockSpannerServiceImpl mockSpanner; | ||
| private static Server server; | ||
| private static InetSocketAddress address; | ||
|
|
||
| private final AtomicInteger activeNetworkConnections = new AtomicInteger(0); | ||
|
|
||
| private final ServerTransportFilter connectionCounterFilter = | ||
| new ServerTransportFilter() { | ||
| @Override | ||
| public Attributes transportReady(Attributes transportAttrs) { | ||
| activeNetworkConnections.incrementAndGet(); | ||
| return super.transportReady(transportAttrs); | ||
| } | ||
|
|
||
| @Override | ||
| public void transportTerminated(Attributes transportAttrs) { | ||
| activeNetworkConnections.decrementAndGet(); | ||
| super.transportTerminated(transportAttrs); | ||
| } | ||
| }; | ||
|
|
||
| @Before | ||
| public void startServer() throws Exception { | ||
| mockSpanner = new MockSpannerServiceImpl(); | ||
| mockSpanner.setAbortProbability(0.0D); | ||
|
|
||
| address = new InetSocketAddress("localhost", 0); | ||
| server = | ||
| NettyServerBuilder.forAddress(address) | ||
| .addService(mockSpanner) | ||
| .addTransportFilter(connectionCounterFilter) | ||
| .build() | ||
| .start(); | ||
| activeNetworkConnections.set(0); | ||
| } | ||
|
|
||
| @After | ||
| public void reset() throws InterruptedException { | ||
| if (mockSpanner != null) { | ||
| mockSpanner.reset(); | ||
| } | ||
| if (server != null) { | ||
| server.shutdown(); | ||
| server.awaitTermination(); | ||
| } | ||
| } | ||
|
|
||
| private SpannerOptions.Builder createDirectPathFallbackOptions() { | ||
| String endpoint = address.getHostString() + ":" + server.getPort(); | ||
| return SpannerOptions.newBuilder() | ||
| .setProjectId("test-project") | ||
| .setChannelConfigurator(ManagedChannelBuilder::usePlaintext) | ||
| .setEnableDirectAccess(true) | ||
| .setHost("http://" + endpoint) | ||
| .setCredentials(NoCredentials.getInstance()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDirectPathFallbackCreatesExactlyFourPhysicalSockets() { | ||
| SpannerOptions.useEnvironment(new SpannerOptions.SpannerEnvironment() {}); | ||
| GapicSpannerRpc rpc = null; | ||
| try { | ||
| SpannerOptions options = createDirectPathFallbackOptions().build(); | ||
| assumeTrue( | ||
| "GCP fallback must be enabled for this DirectPath fallback test", | ||
| options.isEnableGcpFallback()); | ||
|
|
||
| activeNetworkConnections.set(0); | ||
| rpc = new GapicSpannerRpc(options); | ||
|
|
||
| // Poll active loopback connections for up to 1000ms with an aggressive 1ms wait | ||
| Stopwatch watch = Stopwatch.createStarted(); | ||
| while (activeNetworkConnections.get() < 48 && watch.elapsed(TimeUnit.MILLISECONDS) < 1000L) { | ||
| try { | ||
| Thread.sleep(1L); | ||
| } catch (InterruptedException ignored) { | ||
| } | ||
| } | ||
|
|
||
| // Sleep for an extra 5ms after seeing 48 connections (or hitting timeout) to | ||
| // ensure we catch any additional connections that are created. | ||
| try { | ||
| Thread.sleep(5L); | ||
| } catch (InterruptedException ignored) { | ||
| } | ||
|
|
||
| // Assert that the Spanner client stubs eagerly construct exactly 3 fallback channels: | ||
| // 1. Shared pool for the Data client and PartitionedDML client stubs | ||
| // 2. Dedicated pool for the InstanceAdmin client stub | ||
| // 3. Dedicated pool for the DatabaseAdmin client stub | ||
| // Each fallback channel contains a primary and fallback pool (totaling 6 | ||
| // GcpManagedChannel pools). | ||
| // Since the default pool size is 8 channels when gRPC-GCP is enabled, they eagerly | ||
| // establish exactly 48 physical Loopback TCP connection sockets (6 pools of size 8). | ||
| assertEquals(48, activeNetworkConnections.get()); | ||
| } finally { | ||
| if (rpc != null) { | ||
| rpc.shutdown(); | ||
| } | ||
| SpannerOptions.useDefaultEnvironment(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method
createBaseChannelProviderBuilderis called here, but its definition is not included in the pull request. Additionally, the call site at line 371 (visible in context but not in the diff) still usescreateChannelProviderBuilder. IfcreateBaseChannelProviderBuilderis a new method intended to provide a base configuration without the GCP extension, please ensure its definition is included and consider if other call sites should also be updated for consistency.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's there in line 746 createBaseChannelProviderBuilder