Skip to content

chore(spanner): add key_recipe_cache - #6280

Open
olavloite wants to merge 1 commit into
googleapis:mainfrom
olavloite:spanner-key-recipe-cache
Open

chore(spanner): add key_recipe_cache#6280
olavloite wants to merge 1 commit into
googleapis:mainfrom
olavloite:spanner-key-recipe-cache

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Adds a cache for KeyRecipe.

@olavloite
olavloite requested review from a team as code owners August 5, 2026 09:51
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Aug 5, 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 introduces KeyRecipeCache, a thread-safe, concurrent cache for Spanner key recipes, separated by target type (tables, indexes, and queries) to enable zero-allocation lookups. The review feedback focuses on optimizing lock hold times and reducing lock contention within the cache. Specifically, it is recommended to perform deallocations of overwritten or cleared cache entries outside of the write lock by using std::mem::take and explicitly dropping the lock guard.

Comment thread src/spanner/src/routing/key_recipe_cache.rs
Comment thread src/spanner/src/routing/key_recipe_cache.rs
Comment thread src/spanner/src/routing/key_recipe_cache.rs
@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.25%. Comparing base (35b9590) to head (f88bee9).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #6280    +/-   ##
========================================
  Coverage   96.24%   96.25%            
========================================
  Files         280      281     +1     
  Lines       72146    72299   +153     
========================================
+ Hits        69440    69593   +153     
  Misses       2706     2706            

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

@olavloite
olavloite force-pushed the spanner-key-recipe-cache branch from 43e623e to 4b38fa2 Compare August 5, 2026 15:03
@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 introduces KeyRecipeCache, a thread-safe, concurrent cache for Spanner key recipes (tables, indexes, and queries) backed by an RwLock over separate hash maps, along with comprehensive unit tests. The review feedback suggests refactoring the cache implementation by importing RwLockReadGuard and RwLockWriteGuard and introducing private helper methods read_store and write_store to centralize lock acquisition and error handling, which reduces code duplication across getter and setter methods.

Comment thread src/spanner/src/routing/key_recipe_cache.rs Outdated
Comment thread src/spanner/src/routing/key_recipe_cache.rs
@olavloite
olavloite force-pushed the spanner-key-recipe-cache branch from 4b38fa2 to f88bee9 Compare August 5, 2026 16:21
@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 introduces a thread-safe KeyRecipeCache to store table, index, and query key recipes, enabling local binary routing key encoding. The cache is backed by an RwLock over separate hash maps to support concurrent, non-blocking reads, and includes comprehensive unit tests. The review feedback suggests renaming the getter methods (get_table_recipe, get_index_recipe, and get_query_recipe) to omit the get_ prefix, in accordance with the repository's style guide and idiomatic Rust conventions.

Comment thread src/spanner/src/routing/key_recipe_cache.rs
Comment thread src/spanner/src/routing/key_recipe_cache.rs
Comment thread src/spanner/src/routing/key_recipe_cache.rs
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