Skip to content

feat(bigtable): refactor channel_pool_factory as we need to maintain two channel factory one for session and another for unary#14652

Open
sushanb wants to merge 4 commits into
googleapis:mainfrom
sushanb:channel-pool-factory
Open

feat(bigtable): refactor channel_pool_factory as we need to maintain two channel factory one for session and another for unary#14652
sushanb wants to merge 4 commits into
googleapis:mainfrom
sushanb:channel-pool-factory

Conversation

@sushanb

@sushanb sushanb commented May 26, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@sushanb sushanb requested a review from nimf May 26, 2026 19:50
@sushanb sushanb requested review from a team as code owners May 26, 2026 19:50
@product-auto-label product-auto-label Bot added the api: bigtable Issues related to the Bigtable API. label May 26, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Bigtable client initialization by extracting the connection pool creation and lifecycle management into a new managedChannelPool struct and helper functions in channel_pool_factory.go. Feedback on the changes highlights a regression where the direct access dialer is unconditionally configured instead of respecting the allowDirectAccess configuration, and points out a leftover debug print statement that should be removed.

Comment thread bigtable/channel_pool_factory.go Outdated
Comment thread bigtable/channel_pool_factory.go Outdated
Comment thread bigtable/internal/transport/channel_pool_factory.go
Comment thread bigtable/internal/transport/channel_pool_factory.go
Comment thread bigtable/internal/transport/channel_pool_factory.go
Comment thread bigtable/channel_pool_factory.go Outdated
Comment thread bigtable/channel_pool_factory.go Outdated
Comment thread bigtable/channel_pool_factory.go Outdated
Comment thread bigtable/internal/transport/channel_pool_factory_test.go
Comment thread bigtable/client.go
Comment thread bigtable/client.go
@sushanb sushanb requested a review from mutianf June 4, 2026 19:11

@mutianf mutianf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some nits

)

const (
directpathEnvVar = "CBT_ENABLE_DIRECTPATH"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit maybe: directpath -> directAccess so it's consistent?

project, instance string,
config ChannelPoolConfig,
otelMeterProvider metric.MeterProvider,
o []option.ClientOption,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a comment explaining why we need 2 ClientOptions

config ChannelPoolConfig,
otelMeterProvider metric.MeterProvider,
o []option.ClientOption,
directPathOptions []option.ClientOption,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also should we rename all directpath to directAccess?


// Validate dynamic config early if enabled
if !config.DisableDynamicChannelPool {
if err := ValidateDynamicConfig(btopt.DefaultDynamicChannelPoolConfig(), defaultBigtableConnPoolSize); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this method is called "DefaultDynamicChannelPoolConfig". If it's default, can it still be invalid?
Or maybe rename it to DynamicChannelPoolConfig if we want it to be configurable?

WithFeatureFlagsMetadata(directAccessMD),
WithMetricsReporterConfig(btopt.DefaultMetricsReporterConfig()),
WithMeterProvider(otelMeterProvider),
WithDirectAccessFeatureFlagsMetadata(directAccessMD),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized this part was copied from the client.go, but maybe reordering and add a comment to explain the duplicate?

...
WithFeatureFlagsMetadata(directAccessMD),
WithDirectAccessFeatureFlagsMetadata(directAccessMD),
...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some digging I am still not convinced of the necessity for two separate feature flag fields in the BigtableChannelPool... Looking at server side implementation, traffic_director_enabled appears to be purely informational, used primarily for populating request metrics and observability data. While direct_access_requested does influence routing decisions, the server-side check for this flag is already nested within logic that only evaluates traffic originating from Traffic Director?

Consequently, there is no functional use case for 'flipping' these flags based on the transport type (Cloud Path vs. Direct Path). And I realized that the Java client is also inconsistent: the newer session-based client explicitly downgrades these flags to false upon Direct Path failure (https://github.com/googleapis/google-cloud-java/blob/ff45dd2400e65d06d1bd3e3cf7fb1cd1cb9c3074/java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/compat/ShimImpl.java#L128), whereas the classic client treats them as immutable settings once the client is initialized (https://github.com/googleapis/google-cloud-java/blob/ff45dd2400e65d06d1bd3e3cf7fb1cd1cb9c3074/java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java#L660-L661).

Since these flags represent the intrinsic capabilities and opt-in state of the client rather than the ephemeral state of a specific connection, they should remain immutable for the lifetime of the client settings in my opinion?

But maybe I missed some use case and maybe need to ask Igor to clarify the intent of these 2 feature flags.. I'll check on Monday.

And even if we do need refactor, we can do it in a separate PR so feel free to merge after addressing other nits.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok we can clean this up in a separate PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigtable Issues related to the Bigtable API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants