feat(cubestore): Sync tables cache instead of reset#10686
Conversation
Instead of resetting the entire tables cache on every write operation, introduce CachedTables with update_table_by_id_or_reset and remove_by_table_id_or_reset methods for surgical in-place mutations. table_ready, seal_table, update_location_download_size, and drop_table now sync the cache without forcing a full reload from RocksDB.
|
Claude finished @ovr's task in 3m 24s —— View job Code Review: feat(cubestore): Sync tables cache instead of reset
SummaryGood optimization. The new The schema-level operations ( Key FindingsPerformance — Correctness — Testing — no unit tests for
Minor Nits
Thread SafetyThe OverallThe design is sound and the abstraction is clean. The main actionable items are: (1) move |
| let tables = Arc::make_mut(cached); | ||
| let Some(idx) = tables.iter().position(|tp| tp.table.get_id() == table_id) else { | ||
| *guard = None; | ||
| return; | ||
| }; |
There was a problem hiding this comment.
suggestion (performance): Same Arc::make_mut-before-lookup issue as update_table_by_id_or_reset. When dropping a non-ready table (not in cache), this clones the entire vec needlessly:
| let tables = Arc::make_mut(cached); | |
| let Some(idx) = tables.iter().position(|tp| tp.table.get_id() == table_id) else { | |
| *guard = None; | |
| return; | |
| }; | |
| let Some(idx) = cached.iter().position(|tp| tp.table.get_id() == table_id) else { | |
| *guard = None; | |
| return; | |
| }; | |
| let tables = Arc::make_mut(cached); |
| pub struct CachedTables { | ||
| tables: Mutex<Option<Arc<Vec<TablePath>>>>, | ||
| } |
There was a problem hiding this comment.
nit: Clippy will flag new_without_default here. Consider deriving or implementing Default:
| pub struct CachedTables { | |
| tables: Mutex<Option<Arc<Vec<TablePath>>>>, | |
| } | |
| pub struct CachedTables { | |
| tables: Mutex<Option<Arc<Vec<TablePath>>>>, | |
| } | |
| impl Default for CachedTables { | |
| fn default() -> Self { | |
| Self::new() | |
| } | |
| } |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #10686 +/- ##
=======================================
Coverage 58.01% 58.01%
=======================================
Files 215 215
Lines 16648 16648
Branches 3347 3347
=======================================
Hits 9659 9659
Misses 6499 6499
Partials 490 490
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…le_by_id_or_reset Track the index from position() and use swap_remove(idx) O(1) instead of retain O(n) when removing a non-ready entry after in-place mutation.
Instead of resetting the entire tables cache on every write operation, introduce CachedTables with update_table_by_id_or_reset and remove_by_table_id_or_reset methods for surgical in-place mutations. table_ready, seal_table, update_location_download_size, and drop_table now sync the cache without forcing a full reload from RocksDB.