Skip to content

chore(spanner): integrate CacheSubscriber into DatabaseClient lifecycle - #6573

Open
olavloite wants to merge 5 commits into
googleapis:mainfrom
olavloite:spanner-integrate-cache-subscriber
Open

chore(spanner): integrate CacheSubscriber into DatabaseClient lifecycle#6573
olavloite wants to merge 5 commits into
googleapis:mainfrom
olavloite:spanner-integrate-cache-subscriber

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Initializes and starts the proactive background CacheSubscriber when location-aware routing is enabled on DatabaseClient. Ties background subscriber task termination to the RAII Drop lifecycle of LocationRoutingState, ensuring gRPC stream cleanup when all DatabaseClient clones are dropped.

@olavloite
olavloite requested review from a team as code owners August 28, 2026 09:18
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Aug 28, 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 integrates the background CacheSubscriber into the DatabaseClient lifecycle when location-aware routing is enabled, refactoring LocationRoutingState to manage the subscriber and delegating database ID retrieval to CacheUpdater. A critical memory visibility issue was identified where replacing the atomic load of database_id with CacheUpdater::database_id() downgrades the memory ordering from Acquire to Relaxed. This breaks release-acquire synchronization and could cause threads to read stale cache entries. It is recommended to update CacheUpdater::database_id() to use Ordering::Acquire to restore proper synchronization.

Comment thread src/spanner/src/database_client.rs
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.59%. Comparing base (836e762) to head (08d4c0e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6573   +/-   ##
=======================================
  Coverage   96.59%   96.59%           
=======================================
  Files         304      304           
  Lines       91987    91909   -78     
=======================================
- Hits        88855    88780   -75     
+ Misses       3132     3129    -3     

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

Initializes and starts the proactive background CacheSubscriber when
location-aware routing is enabled on DatabaseClient. Ties background
subscriber task termination to the RAII Drop lifecycle of
LocationRoutingState, ensuring gRPC stream cleanup when all
DatabaseClient clones are dropped.
@olavloite
olavloite force-pushed the spanner-integrate-cache-subscriber branch 2 times, most recently from 3d3e00c to 84ad56d Compare August 28, 2026 12:04
@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 integrates the background CacheSubscriber into the DatabaseClient lifecycle when location-aware routing is enabled. It removes the separate database_id atomic field in LocationRoutingState in favor of retrieving it directly from CacheUpdater, which now uses Acquire ordering for loading the database ID. The PR also refactors mock tests to use a helper function create_test_mock to reduce boilerplate, and adds new lifecycle tests for the cache subscriber. There are no review comments, and the changes look solid, so I have no feedback to provide.

@olavloite
olavloite force-pushed the spanner-integrate-cache-subscriber branch from 84ad56d to 570ef73 Compare August 28, 2026 12:28
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