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 1 commit 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 1 commit into
googleapis:mainfrom
sushanb:channel-pool-factory

Conversation

@sushanb
Copy link
Copy Markdown
Contributor

@sushanb sushanb commented May 26, 2026

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
Copy link
Copy Markdown
Contributor

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

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 on lines +122 to +153
directAccessDialerOptions := make([]option.ClientOption, len(o))
copy(directAccessDialerOptions, o)
directAccessDialerOptions = append(directAccessDialerOptions, directPathOptions...)
directAccessDialerOptions = append(directAccessDialerOptions, internaloption.AllowHardBoundTokens("ALTS"))

directAccessDialer := func() (*btransport.BigtableConn, error) {
grpcConn, err := gtransport.Dial(ctx, directAccessDialerOptions...)
if err != nil {
return nil, err
}
return btransport.NewBigtableConn(grpcConn), nil
}

return btransport.NewBigtableChannelPool(ctx,
connPoolSize,
btopt.BigtableLoadBalancingStrategy(),
func() (*btransport.BigtableConn, error) {
grpcConn, err := gtransport.Dial(ctx, o...)
if err != nil {
return nil, err
}
return btransport.NewBigtableConn(grpcConn), nil
},
clientCreationTimestamp,
btransport.WithInstanceName(fullInstanceName),
btransport.WithAppProfile(config.AppProfile),
btransport.WithFeatureFlagsMetadata(directAccessMD),
btransport.WithMetricsReporterConfig(btopt.DefaultMetricsReporterConfig()),
btransport.WithMeterProvider(metricsTracerFactory.otelMeterProvider),
btransport.WithDirectAccessFeatureFlagsMetadata(directAccessMD),
btransport.WithDirectAccessDialer(directAccessDialer),
)
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.

high

The direct access dialer is currently being set up and passed unconditionally. In the original implementation, this was only done if allowDirectAccess (i.e., isDirectAccessEnabled(config)) was true. We should preserve this behavior to avoid unnecessary connection setups and potential errors when direct access is disabled.

	poolOpts := []btransport.BigtableChannelPoolOption{
		btransport.WithInstanceName(fullInstanceName),
		btransport.WithAppProfile(config.AppProfile),
		btransport.WithFeatureFlagsMetadata(directAccessMD),
		btransport.WithMetricsReporterConfig(btopt.DefaultMetricsReporterConfig()),
		btransport.WithMeterProvider(metricsTracerFactory.otelMeterProvider),
		btransport.WithDirectAccessFeatureFlagsMetadata(directAccessMD),
	}

	if isDirectAccessEnabled(config) {
		directAccessDialerOptions := make([]option.ClientOption, len(o))
		copy(directAccessDialerOptions, o)
		directAccessDialerOptions = append(directAccessDialerOptions, directPathOptions...)
		directAccessDialerOptions = append(directAccessDialerOptions, internaloption.AllowHardBoundTokens("ALTS"))

		directAccessDialer := func() (*btransport.BigtableConn, error) {
			grpcConn, err := gtransport.Dial(ctx, directAccessDialerOptions...)
			if err != nil {
				return nil, err
			}
			return btransport.NewBigtableConn(grpcConn), nil
		}
		poolOpts = append(poolOpts, btransport.WithDirectAccessDialer(directAccessDialer))
	}

	return btransport.NewBigtableChannelPool(ctx,
		connPoolSize,
		btopt.BigtableLoadBalancingStrategy(),
		func() (*btransport.BigtableConn, error) {
			grpcConn, err := gtransport.Dial(ctx, o...)
			if err != nil {
				return nil, err
			}
			return btransport.NewBigtableConn(grpcConn), nil
		},
		clientCreationTimestamp,
		poolOpts...,
	)

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.

Same question here. How do we disable DP?

directAccessMD metadata.MD,
clientCreationTimestamp time.Time,
) (*btransport.BigtableChannelPool, error) {
fmt.Printf(">>> createBigtableChannelPool called for project=%s, instance=%s <<<\n", project, instance)
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.

medium

This is a leftover debug print statement and should be removed before merging.

project, instance string,
config ClientConfig,
metricsTracerFactory *builtinMetricsTracerFactory,
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.

what's the difference between o and directPathOpetions? aren't they both option.ClientOption?

m.pool = pool

// Validate dynamic config early if enabled
if !config.DisableDynamicChannelPool {
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: can we rename this variable to EnableDynamicChannelPool? ! config.Disable feels harder to understand :/

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.

Oh, I guess this was added before..

}

// connection recycler
if !config.DisableConnectionRecycler {
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.

same nit here, can we rename it to EnableConnectionRecycler instead?

Comment on lines +122 to +153
directAccessDialerOptions := make([]option.ClientOption, len(o))
copy(directAccessDialerOptions, o)
directAccessDialerOptions = append(directAccessDialerOptions, directPathOptions...)
directAccessDialerOptions = append(directAccessDialerOptions, internaloption.AllowHardBoundTokens("ALTS"))

directAccessDialer := func() (*btransport.BigtableConn, error) {
grpcConn, err := gtransport.Dial(ctx, directAccessDialerOptions...)
if err != nil {
return nil, err
}
return btransport.NewBigtableConn(grpcConn), nil
}

return btransport.NewBigtableChannelPool(ctx,
connPoolSize,
btopt.BigtableLoadBalancingStrategy(),
func() (*btransport.BigtableConn, error) {
grpcConn, err := gtransport.Dial(ctx, o...)
if err != nil {
return nil, err
}
return btransport.NewBigtableConn(grpcConn), nil
},
clientCreationTimestamp,
btransport.WithInstanceName(fullInstanceName),
btransport.WithAppProfile(config.AppProfile),
btransport.WithFeatureFlagsMetadata(directAccessMD),
btransport.WithMetricsReporterConfig(btopt.DefaultMetricsReporterConfig()),
btransport.WithMeterProvider(metricsTracerFactory.otelMeterProvider),
btransport.WithDirectAccessFeatureFlagsMetadata(directAccessMD),
btransport.WithDirectAccessDialer(directAccessDialer),
)
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.

Same question here. How do we disable DP?

clientCreationTimestamp,
btransport.WithInstanceName(fullInstanceName),
btransport.WithAppProfile(config.AppProfile),
btransport.WithFeatureFlagsMetadata(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.

nit: should we rename directAccessMD to featureFlagsMD? directAccessMD suggests that it's always using direct access which may not be the case?

btransport.WithFeatureFlagsMetadata(directAccessMD),
btransport.WithMetricsReporterConfig(btopt.DefaultMetricsReporterConfig()),
btransport.WithMeterProvider(metricsTracerFactory.otelMeterProvider),
btransport.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.

what's the difference between this and WithFeatureFlagsMetadata?

},
metricsTracerFactory,
o,
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.

the direct access options in this test is nil, do we need to verify it's not going through DP or something?

Comment thread bigtable/client.go
// Use the regular ConnPool
// For regular ConnPool the Direct Access is off by default so we need to check the env var again.
if enabled, _ := strconv.ParseBool(os.Getenv(directpathEnvVar)); enabled {
o = append(o, directPathOptions...)
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.

Hmm, not sure if I understand the logic here. directpath options is appended to the options only when we're not enabling the bigtable channel pool? Should this if statement be outside of if !enableBigtableConnPool?

Comment thread bigtable/client.go
config,
metricsTracerFactory,
o,
directPathOptions,
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.

if directPathOptions is appended to o, why do we need to pass it in again?

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.

2 participants