Skip to content

Commit 41fa66f

Browse files
committed
Removed a reference to ExecutionCounters in the datastore module
1 parent 917fd66 commit 41fa66f

2 files changed

Lines changed: 12 additions & 21 deletions

File tree

crates/core/src/db/datastore/locking_tx_datastore/datastore.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ use super::{
66
tx::TxId,
77
tx_state::TxState,
88
};
9-
use crate::execution_context::{Workload, WorkloadType};
10-
use crate::{
11-
db::datastore::{
12-
locking_tx_datastore::state_view::{IterByColRangeMutTx, IterMutTx, IterTx},
13-
traits::{InsertFlags, UpdateFlags},
14-
},
15-
subscription::ExecutionCounters,
9+
use crate::db::datastore::{
10+
locking_tx_datastore::state_view::{IterByColRangeMutTx, IterMutTx, IterTx},
11+
traits::{InsertFlags, UpdateFlags},
1612
};
13+
use crate::execution_context::{Workload, WorkloadType};
1714
use crate::{
1815
db::{
1916
datastore::{
@@ -33,7 +30,6 @@ use crate::{
3330
};
3431
use anyhow::{anyhow, Context};
3532
use core::{cell::RefCell, ops::RangeBounds};
36-
use enum_map::EnumMap;
3733
use parking_lot::{Mutex, RwLock};
3834
use spacetimedb_commitlog::payload::{txdata, Txdata};
3935
use spacetimedb_data_structures::map::{HashCollectionExt, HashMap};
@@ -71,9 +67,6 @@ pub struct Locking {
7167
sequence_state: Arc<Mutex<SequencesState>>,
7268
/// The identity of this database.
7369
pub(crate) database_identity: Identity,
74-
75-
/// A map from workload types to their cached prometheus counters.
76-
workload_type_to_exec_counters: Arc<EnumMap<WorkloadType, ExecutionCounters>>,
7770
}
7871

7972
impl MemoryUsage for Locking {
@@ -82,7 +75,6 @@ impl MemoryUsage for Locking {
8275
committed_state,
8376
sequence_state,
8477
database_identity,
85-
workload_type_to_exec_counters: _,
8678
} = self;
8779
std::mem::size_of_val(&**committed_state)
8880
+ committed_state.read().heap_usage()
@@ -94,14 +86,10 @@ impl MemoryUsage for Locking {
9486

9587
impl Locking {
9688
pub fn new(database_identity: Identity, page_pool: PagePool) -> Self {
97-
let workload_type_to_exec_counters =
98-
Arc::new(EnumMap::from_fn(|ty| ExecutionCounters::new(&ty, &database_identity)));
99-
10089
Self {
10190
committed_state: Arc::new(RwLock::new(CommittedState::new(page_pool))),
10291
sequence_state: <_>::default(),
10392
database_identity,
104-
workload_type_to_exec_counters,
10593
}
10694
}
10795

@@ -318,10 +306,6 @@ impl Locking {
318306

319307
tx.alter_table_access(table_id, access)
320308
}
321-
322-
pub(crate) fn exec_counters_for(&self, workload_type: WorkloadType) -> &ExecutionCounters {
323-
&self.workload_type_to_exec_counters[workload_type]
324-
}
325309
}
326310

327311
impl DataRow for Locking {

crates/core/src/db/relational_db.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::messages::control_db::HostType;
2323
use crate::subscription::ExecutionCounters;
2424
use crate::util::{asyncify, spawn_rayon};
2525
use anyhow::{anyhow, Context};
26+
use enum_map::EnumMap;
2627
use fs2::FileExt;
2728
use futures::channel::mpsc;
2829
use futures::StreamExt;
@@ -107,6 +108,9 @@ pub struct RelationalDB {
107108
// We want to release the file lock last.
108109
// TODO(noa): is this lockfile still necessary now that we have data-dir?
109110
_lock: LockFile,
111+
112+
/// A map from workload types to their cached prometheus counters.
113+
workload_type_to_exec_counters: Arc<EnumMap<WorkloadType, ExecutionCounters>>,
110114
}
111115

112116
#[derive(Clone)]
@@ -224,6 +228,8 @@ impl RelationalDB {
224228
let (durability, disk_size_fn) = durability.unzip();
225229
let snapshot_worker =
226230
snapshot_repo.map(|repo| SnapshotWorker::new(inner.committed_state.clone(), repo.clone()));
231+
let workload_type_to_exec_counters =
232+
Arc::new(EnumMap::from_fn(|ty| ExecutionCounters::new(&ty, &database_identity)));
227233

228234
Self {
229235
inner,
@@ -237,6 +243,7 @@ impl RelationalDB {
237243
disk_size_fn,
238244

239245
_lock: lock,
246+
workload_type_to_exec_counters,
240247
}
241248
}
242249

@@ -735,7 +742,7 @@ impl RelationalDB {
735742

736743
/// Returns the execution counters for `workload_type` for this database.
737744
pub fn exec_counters_for(&self, workload_type: WorkloadType) -> &ExecutionCounters {
738-
self.inner.exec_counters_for(workload_type)
745+
&self.workload_type_to_exec_counters[workload_type]
739746
}
740747

741748
/// Begin a transaction.

0 commit comments

Comments
 (0)