@@ -4,15 +4,17 @@ use super::wasmtime::WasmtimeRuntime;
44use super :: { Scheduler , UpdateDatabaseResult } ;
55use crate :: database_logger:: DatabaseLogger ;
66use crate :: db:: datastore:: traits:: Program ;
7+ use crate :: db:: db_metrics:: data_size:: DATA_SIZE_METRICS ;
78use crate :: db:: db_metrics:: DB_METRICS ;
89use crate :: db:: relational_db:: { self , DiskSizeFn , RelationalDB , Txdata } ;
9- use crate :: db:: { self , db_metrics } ;
10+ use crate :: db:: { self } ;
1011use crate :: energy:: { EnergyMonitor , EnergyQuanta , NullEnergyMonitor } ;
1112use crate :: messages:: control_db:: { Database , HostType } ;
1213use crate :: module_host_context:: ModuleCreationContext ;
1314use crate :: replica_context:: ReplicaContext ;
1415use crate :: subscription:: module_subscription_actor:: ModuleSubscriptions ;
1516use crate :: util:: { asyncify, spawn_rayon} ;
17+ use crate :: worker_metrics:: WORKER_METRICS ;
1618use anyhow:: { anyhow, ensure, Context } ;
1719use async_trait:: async_trait;
1820use durability:: { Durability , EmptyHistory } ;
@@ -441,7 +443,7 @@ impl HostController {
441443 let module = host. module . borrow ( ) . clone ( ) ;
442444 module. exit ( ) . await ;
443445 let table_names = module. info ( ) . module_def . tables ( ) . map ( |t| t. name . deref ( ) ) ;
444- db_metrics :: data_size :: remove_database_gauges ( & module. info ( ) . database_identity , table_names) ;
446+ remove_database_gauges ( & module. info ( ) . database_identity , table_names) ;
445447 }
446448 }
447449
@@ -981,3 +983,32 @@ pub async fn extract_schema(program_bytes: Box<[u8]>, host_type: HostType) -> an
981983
982984 Ok ( module_info. module_def )
983985}
986+
987+ // Remove all gauges associated with a database.
988+ // This is useful if a database is being deleted.
989+ pub fn remove_database_gauges < ' a , I > ( db : & Identity , table_names : I )
990+ where
991+ I : IntoIterator < Item = & ' a str > ,
992+ {
993+ // Remove the per-table gauges.
994+ for table_name in table_names {
995+ let _ = DATA_SIZE_METRICS
996+ . data_size_table_num_rows
997+ . remove_label_values ( db, table_name) ;
998+ let _ = DATA_SIZE_METRICS
999+ . data_size_table_bytes_used_by_rows
1000+ . remove_label_values ( db, table_name) ;
1001+ let _ = DATA_SIZE_METRICS
1002+ . data_size_table_num_rows_in_indexes
1003+ . remove_label_values ( db, table_name) ;
1004+ let _ = DATA_SIZE_METRICS
1005+ . data_size_table_bytes_used_by_index_keys
1006+ . remove_label_values ( db, table_name) ;
1007+ }
1008+ // Remove the per-db gauges.
1009+ let _ = DATA_SIZE_METRICS . data_size_blob_store_num_blobs . remove_label_values ( db) ;
1010+ let _ = DATA_SIZE_METRICS
1011+ . data_size_blob_store_bytes_used_by_blobs
1012+ . remove_label_values ( db) ;
1013+ let _ = WORKER_METRICS . wasm_memory_bytes . remove_label_values ( db) ;
1014+ }
0 commit comments