Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions crates/core/src/db/db_metrics/data_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use prometheus::IntGaugeVec;
use spacetimedb_lib::Identity;
use spacetimedb_metrics::metrics_group;

use crate::worker_metrics::WORKER_METRICS;

metrics_group!(
#[non_exhaustive]
pub struct DbDataSize {
Expand Down Expand Up @@ -42,32 +40,3 @@ metrics_group!(
);

pub static DATA_SIZE_METRICS: Lazy<DbDataSize> = Lazy::new(DbDataSize::new);

// Remove all gauges associated with a database.
// This is useful if a database is being deleted.
pub fn remove_database_gauges<'a, I>(db: &Identity, table_names: I)
where
I: IntoIterator<Item = &'a str>,
{
// Remove the per-table gauges.
for table_name in table_names {
let _ = DATA_SIZE_METRICS
.data_size_table_num_rows
.remove_label_values(db, table_name);
let _ = DATA_SIZE_METRICS
.data_size_table_bytes_used_by_rows
.remove_label_values(db, table_name);
let _ = DATA_SIZE_METRICS
.data_size_table_num_rows_in_indexes
.remove_label_values(db, table_name);
let _ = DATA_SIZE_METRICS
.data_size_table_bytes_used_by_index_keys
.remove_label_values(db, table_name);
}
// Remove the per-db gauges.
let _ = DATA_SIZE_METRICS.data_size_blob_store_num_blobs.remove_label_values(db);
let _ = DATA_SIZE_METRICS
.data_size_blob_store_bytes_used_by_blobs
.remove_label_values(db);
let _ = WORKER_METRICS.wasm_memory_bytes.remove_label_values(db);
}
35 changes: 33 additions & 2 deletions crates/core/src/host/host_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ use super::wasmtime::WasmtimeRuntime;
use super::{Scheduler, UpdateDatabaseResult};
use crate::database_logger::DatabaseLogger;
use crate::db::datastore::traits::Program;
use crate::db::db_metrics::data_size::DATA_SIZE_METRICS;
use crate::db::db_metrics::DB_METRICS;
use crate::db::relational_db::{self, DiskSizeFn, RelationalDB, Txdata};
use crate::db::{self, db_metrics};
use crate::db::{self};
use crate::energy::{EnergyMonitor, EnergyQuanta, NullEnergyMonitor};
use crate::messages::control_db::{Database, HostType};
use crate::module_host_context::ModuleCreationContext;
use crate::replica_context::ReplicaContext;
use crate::subscription::module_subscription_actor::ModuleSubscriptions;
use crate::util::{asyncify, spawn_rayon};
use crate::worker_metrics::WORKER_METRICS;
use anyhow::{anyhow, ensure, Context};
use async_trait::async_trait;
use durability::{Durability, EmptyHistory};
Expand Down Expand Up @@ -441,7 +443,7 @@ impl HostController {
let module = host.module.borrow().clone();
module.exit().await;
let table_names = module.info().module_def.tables().map(|t| t.name.deref());
db_metrics::data_size::remove_database_gauges(&module.info().database_identity, table_names);
remove_database_gauges(&module.info().database_identity, table_names);
}
}

Expand Down Expand Up @@ -981,3 +983,32 @@ pub async fn extract_schema(program_bytes: Box<[u8]>, host_type: HostType) -> an

Ok(module_info.module_def)
}

// Remove all gauges associated with a database.
// This is useful if a database is being deleted.
pub fn remove_database_gauges<'a, I>(db: &Identity, table_names: I)
where
I: IntoIterator<Item = &'a str>,
{
// Remove the per-table gauges.
for table_name in table_names {
let _ = DATA_SIZE_METRICS
.data_size_table_num_rows
.remove_label_values(db, table_name);
let _ = DATA_SIZE_METRICS
.data_size_table_bytes_used_by_rows
.remove_label_values(db, table_name);
let _ = DATA_SIZE_METRICS
.data_size_table_num_rows_in_indexes
.remove_label_values(db, table_name);
let _ = DATA_SIZE_METRICS
.data_size_table_bytes_used_by_index_keys
.remove_label_values(db, table_name);
}
// Remove the per-db gauges.
let _ = DATA_SIZE_METRICS.data_size_blob_store_num_blobs.remove_label_values(db);
let _ = DATA_SIZE_METRICS
.data_size_blob_store_bytes_used_by_blobs
.remove_label_values(db);
let _ = WORKER_METRICS.wasm_memory_bytes.remove_label_values(db);
}
Loading