Skip to content

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

Open
olavloite wants to merge 2 commits into
googleapis:mainfrom
olavloite:spanner-channel-pool-affinity
Open

chore(spanner): implement transaction affinity resolution, R/W counting, and CAS conflict handling in channel pool#6737
olavloite wants to merge 2 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 96.96%. Comparing base (9d8ef68) to head (0acb196).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6737      +/-   ##
==========================================
+ Coverage   96.94%   96.96%   +0.02%     
==========================================
  Files         315      315              
  Lines      105078   105470     +392     
==========================================
+ Hits       101864   102271     +407     
+ Misses       3214     3199      -15     

☔ 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
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.

1 participant