Skip to content

chore(spanner): Auto-enable location API and dynamic channel pool for experimental hosts#12679

Open
rahul2393 wants to merge 2 commits intomainfrom
make-dcp-enabled-for-bypass
Open

chore(spanner): Auto-enable location API and dynamic channel pool for experimental hosts#12679
rahul2393 wants to merge 2 commits intomainfrom
make-dcp-enabled-for-bypass

Conversation

@rahul2393
Copy link
Copy Markdown
Contributor

@rahul2393 rahul2393 commented Apr 4, 2026

  • Auto-enable location API for experimental hosts: When setExperimentalHost() is used,
    enableLocationApi now defaults to true. Users can still explicitly opt out by setting
    GOOGLE_SPANNER_EXPERIMENTAL_LOCATION_API=false.

  • Auto-enable dynamic channel pool for experimental hosts: When setExperimentalHost() is
    used and the user has not explicitly called enableDynamicChannelPool() or
    disableDynamicChannelPool(), dynamic channel pooling is enabled by default
    (subject to existing grpc-gcp and numChannels constraints).

  • Merge custom GcpChannelPoolOptions with Spanner defaults: Previously, providing custom
    GcpChannelPoolOptions (e.g., only setting maxSize, minSize, initSize) would leave
    dynamic scaling parameters (minRpcPerChannel, maxRpcPerChannel, scaleDownInterval) at
    zero, silently breaking channel scale-up. Now, any unset fields in user-provided options are
    filled in from Spanner's defaults via mergeWithDefaultChannelPoolOptions().

… experimental hosts, and merge default dynamic

channel pool options with user-provided options

When an experimental host is configured, automatically enable the location API
(unless explicitly disabled via GOOGLE_SPANNER_EXPERIMENTAL_LOCATION_API=false)
and dynamic channel pool (unless explicitly disabled via disableDynamicChannelPool()).

Also fix an issue where setting custom GcpChannelPoolOptions without specifying
dynamic scaling parameters (minRpcPerChannel, maxRpcPerChannel, scaleDownInterval)
would reset them to zero, preventing channel scale-up. Custom options are now merged
with Spanner defaults so unset fields retain their default values.
@rahul2393 rahul2393 requested review from a team as code owners April 4, 2026 04:07
@rahul2393 rahul2393 requested a review from sakthivelmanii April 4, 2026 04:08
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 updates the default configuration for the Dynamic Channel Pool (DCP) in SpannerOptions, increasing the maximum RPCs per channel and maximum channels while decreasing initial and minimum channel counts. It introduces a merging mechanism for user-provided pool options and automatically enables DCP and the Location API when an experimental host is configured. Review feedback points out a logic error in environment variable parsing for the Location API and a potential invariant violation in the pool options merging logic that could lead to runtime exceptions.

Comment on lines +225 to +239
if (userOptions.getMinRpcPerChannel() <= 0
|| userOptions.getMaxRpcPerChannel() <= 0
|| userOptions.getScaleDownInterval() == null
|| userOptions.getScaleDownInterval().isZero()) {
merged.setDynamicScaling(
userOptions.getMinRpcPerChannel() > 0
? userOptions.getMinRpcPerChannel()
: defaults.getMinRpcPerChannel(),
userOptions.getMaxRpcPerChannel() > 0
? userOptions.getMaxRpcPerChannel()
: defaults.getMaxRpcPerChannel(),
userOptions.getScaleDownInterval() != null && !userOptions.getScaleDownInterval().isZero()
? userOptions.getScaleDownInterval()
: defaults.getScaleDownInterval());
}
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

The merging logic for dynamic scaling parameters can lead to an invalid state where minRpcPerChannel is greater than maxRpcPerChannel, which will cause an IllegalArgumentException when the options are built. For example, if a user provides a custom maxRpcPerChannel of 10 but leaves minRpcPerChannel unset (0), the merged result will have minRpcPerChannel=15 (the default) and maxRpcPerChannel=10.

Consider ensuring that the merged values maintain the invariant minRpcPerChannel <= maxRpcPerChannel by capping the minimum or bumping the maximum during the merge.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant