Skip to content

chore(spanner): implement transaction affinity resolution, R/W counting, and CAS conflict handling in channel pool - #6737

Merged
olavloite merged 3 commits into
googleapis:mainfrom
olavloite:spanner-channel-pool-affinity
Sep 14, 2026
Merged

olavloite merged 3 commits into
googleapis:mainfrom
olavloite:spanner-channel-pool-affinity

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Implements transaction affinity resolution and concurrency handling for multi-statement transactions inside ChannelPool.

Key changes:

  • Tracks active Read/Write transactions on channels using RAII guards so channels undergoing scale-down draining are kept alive until in-flight transactions complete.
  • Implements affinity resolution supporting hard stickiness (Read/Write transactions follow their pinned channel even when draining) and soft stickiness (Read-Only transactions prefer warmth but cleanly fail over to active channels).
  • Handles concurrent CAS races when multiple statements attempt to pin the same transaction at once, ensuring all statements consistently route to the winning channel.

@olavloite
olavloite requested review from a team as code owners September 8, 2026 14:49
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Sep 8, 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 Spanner channel pool and transaction affinity management. Key changes include tracking RwTransactionAffinityGuard within TransactionAffinity to manage active read/write transaction counts, introducing a robust compare-and-swap (CAS) conflict resolution mechanism (resolve_cas_conflict) for concurrent transaction pinning, simplifying ChannelEntry by removing redundant fields, and implementing Deref for ChannelLease. The feedback identifies an unresolved rustdoc link in the documentation of default_channel referencing ChannelPool::next_channel instead of pick_channel, which should be corrected to prevent CI build failures.

Comment thread src/spanner/src/channel_pool/pool.rs Outdated
@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.03%. Comparing base (0b4b459) to head (dfca786).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6737      +/-   ##
==========================================
+ Coverage   97.00%   97.03%   +0.03%     
==========================================
  Files         326      326              
  Lines      107038   107430     +392     
==========================================
+ Hits       103827   104241     +414     
+ Misses       3211     3189      -22     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ng, and CAS conflict handling in channel pool
@olavloite
olavloite force-pushed the spanner-channel-pool-affinity branch from 077f898 to dd6ede2 Compare September 8, 2026 15:38
@olavloite

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 and robustifies the Spanner channel pool's transaction affinity and channel leasing mechanisms. Key changes include introducing RwTransactionAffinityGuard management within TransactionAffinity to prevent premature channel reclamation during active read-write transactions, implementing transparent Deref to Channel for ChannelLease, and refactoring the compare-and-swap (CAS) conflict resolution logic in ChannelPool::resolve_affinity into a dedicated, loop-based resolve_cas_conflict method. Additionally, ChannelEntry was simplified by removing the redundant logical_channel_id field in favor of a getter, and extensive unit tests were added to verify the new guard behaviors and CAS resolution paths. I have no further feedback to provide as the changes are well-structured, idiomatic, and thoroughly tested.

@olavloite
olavloite requested a review from rahul2393 September 8, 2026 18:00
@olavloite
olavloite merged commit 0be0238 into googleapis:main Sep 14, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants