feat: remove metadata caches on db and table delete (#25599)

pull/25604/head
Trevor Hilton 2024-11-28 11:35:29 -05:00 committed by GitHub
parent 81715fbfea
commit b7fd8e2386
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View File

@ -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) {

View File

@ -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)
{