Repository navigation
chore: default local datacenter when using ephemeral adapter endpoint - #433
Merged
Merged
Conversation
… adapter on build failure
Infer the local datacenter from the server for zero-configuration sessions, clean up the in-process adapter if session creation fails, and fix configuration edge cases without weakening security checks. Specifically: - Treat internally generated adapter endpoints as implicit contact points so the driver infers the local datacenter instead of hardcoding "datacenter1", while keeping named execution profiles, custom configuration loaders, and reloading intact. - Stop the started in-process adapter if building the CQL session fails synchronously or asynchronously. - Honor a caller-supplied class loader when checking default configuration. - Allow matching programmatic and configuration loopback contact points that refer to the same address and port, while still rejecting conflicting or multiple contact points. - Intentionally keep the strict single-address check from the earlier security hardening: configuration contact points that resolve to multiple addresses on dual-stack machines (such as "localhost:9042") continue to be rejected.
olavloite
approved these changes
Nov 20, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
SpannerCqlSessionto bind an OS-assigned ephemeral loopback port and register that endpoint inprogrammaticContactPoints, zero-configuration callers (such as the README Quickstart example that omit bothaddContactPoint(...)andwithLocalDatacenter(...)) fail withIllegalStateException: Since you provided explicit contact points, the local DC must be explicitly set.Solution
SpannerCqlSessionBuilder.buildContext(...)to compose the caller'sDriverConfigLoaderwith a fallbackOptionsMapsettingTypedDriverOption.LOAD_BALANCING_LOCAL_DATACENTERto"datacenter1"only when the caller provided neither a contact point (userContactPoint == null && !configContactPointProvided) nor a programmatic local datacenter, preserving config precedence and builder reuse without mutatingprogrammaticArgumentsBuilder.SpannerCqlSessionBuilderTestverifying default local datacenter fallback, preservation of programmatic and config-supplied local datacenter values, and preservation of driver behavior when an explicit contact point is supplied.