Skip to content

Commit 9d47f3a

Browse files
Merge branch 'master' into tyler/datastore-error
Signed-off-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
2 parents f4910d6 + afc9e5b commit 9d47f3a

2 files changed

Lines changed: 33 additions & 33 deletions

File tree

crates/core/src/db/db_metrics/data_size.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use prometheus::IntGaugeVec;
33
use spacetimedb_lib::Identity;
44
use spacetimedb_metrics::metrics_group;
55

6-
use crate::worker_metrics::WORKER_METRICS;
7-
86
metrics_group!(
97
#[non_exhaustive]
108
pub struct DbDataSize {
@@ -42,32 +40,3 @@ metrics_group!(
4240
);
4341

4442
pub static DATA_SIZE_METRICS: Lazy<DbDataSize> = Lazy::new(DbDataSize::new);
45-
46-
// Remove all gauges associated with a database.
47-
// This is useful if a database is being deleted.
48-
pub fn remove_database_gauges<'a, I>(db: &Identity, table_names: I)
49-
where
50-
I: IntoIterator<Item = &'a str>,
51-
{
52-
// Remove the per-table gauges.
53-
for table_name in table_names {
54-
let _ = DATA_SIZE_METRICS
55-
.data_size_table_num_rows
56-
.remove_label_values(db, table_name);
57-
let _ = DATA_SIZE_METRICS
58-
.data_size_table_bytes_used_by_rows
59-
.remove_label_values(db, table_name);
60-
let _ = DATA_SIZE_METRICS
61-
.data_size_table_num_rows_in_indexes
62-
.remove_label_values(db, table_name);
63-
let _ = DATA_SIZE_METRICS
64-
.data_size_table_bytes_used_by_index_keys
65-
.remove_label_values(db, table_name);
66-
}
67-
// Remove the per-db gauges.
68-
let _ = DATA_SIZE_METRICS.data_size_blob_store_num_blobs.remove_label_values(db);
69-
let _ = DATA_SIZE_METRICS
70-
.data_size_blob_store_bytes_used_by_blobs
71-
.remove_label_values(db);
72-
let _ = WORKER_METRICS.wasm_memory_bytes.remove_label_values(db);
73-
}

crates/core/src/host/host_controller.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ use super::wasmtime::WasmtimeRuntime;
44
use super::{Scheduler, UpdateDatabaseResult};
55
use crate::database_logger::DatabaseLogger;
66
use crate::db::datastore::traits::Program;
7+
use crate::db::db_metrics::data_size::DATA_SIZE_METRICS;
78
use crate::db::db_metrics::DB_METRICS;
89
use crate::db::relational_db::{self, DiskSizeFn, RelationalDB, Txdata};
9-
use crate::db::{self, db_metrics};
10+
use crate::db::{self};
1011
use crate::energy::{EnergyMonitor, EnergyQuanta, NullEnergyMonitor};
1112
use crate::messages::control_db::{Database, HostType};
1213
use crate::module_host_context::ModuleCreationContext;
1314
use crate::replica_context::ReplicaContext;
1415
use crate::subscription::module_subscription_actor::ModuleSubscriptions;
1516
use crate::util::{asyncify, spawn_rayon};
17+
use crate::worker_metrics::WORKER_METRICS;
1618
use anyhow::{anyhow, ensure, Context};
1719
use async_trait::async_trait;
1820
use 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

Comments
 (0)