diff --git a/influxdb3_cache/src/meta_cache/provider.rs b/influxdb3_cache/src/meta_cache/provider.rs index 740d7c89cb6..7231773055c 100644 --- a/influxdb3_cache/src/meta_cache/provider.rs +++ b/influxdb3_cache/src/meta_cache/provider.rs @@ -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) { diff --git a/influxdb3_write/src/write_buffer/queryable_buffer.rs b/influxdb3_write/src/write_buffer/queryable_buffer.rs index d0eaa339002..977477edb90 100644 --- a/influxdb3_write/src/write_buffer/queryable_buffer.rs +++ b/influxdb3_write/src/write_buffer/queryable_buffer.rs @@ -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) {