Skip to content

Commit

Permalink
feat: remove metadata caches on db and table delete (#25599)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiltontj authored Nov 28, 2024
1 parent 81715fb commit b7fd8e2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions influxdb3_cache/src/meta_cache/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,23 @@ impl MetaCacheProvider {
Ok(())
}

/// Delete all caches for a given database
pub fn delete_caches_for_db(&self, db_id: &DbId) {
self.cache_map.write().remove(db_id);
}

/// Delete all caches for a given database and table
pub fn delete_caches_for_db_and_table(&self, db_id: &DbId, table_id: &TableId) {
let mut lock = self.cache_map.write();
let Some(db) = lock.get_mut(db_id) else {
return;
};
db.remove(table_id);
if db.is_empty() {
lock.remove(db_id);
}
}

/// Write the contents of a WAL file to the cache by iterating over its database and table
/// batches to find entries that belong in the cache.
pub fn write_wal_contents_to_cache(&self, wal_contents: &WalContents) {
Expand Down
6 changes: 6 additions & 0 deletions influxdb3_write/src/write_buffer/queryable_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,18 @@ impl BufferState {
self.db_to_table.remove(&db_definition.database_id);
last_cache_provider
.delete_caches_for_db(&db_definition.database_id);
meta_cache_provider
.delete_caches_for_db(&db_definition.database_id);
}
CatalogOp::DeleteTable(table_definition) => {
last_cache_provider.delete_caches_for_table(
&table_definition.database_id,
&table_definition.table_id,
);
meta_cache_provider.delete_caches_for_db_and_table(
&table_definition.database_id,
&table_definition.table_id,
);
if let Some(table_buffer_map) =
self.db_to_table.get_mut(&table_definition.database_id)
{
Expand Down

0 comments on commit b7fd8e2

Please sign in to comment.