Skip to content

Commit 312d9d7

Browse files
committed
make compatible to private
1 parent 57efabd commit 312d9d7

5 files changed

Lines changed: 28 additions & 14 deletions

File tree

crates/core/src/host/host_controller.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,12 @@ impl Host {
904904
db::Storage::Disk => {
905905
// Replay from the local state.
906906
let history = relational_db::local_history(&replica_dir, &runtime).await?;
907-
let persistence = persistence.persistence(database.database_identity, replica_id).await?;
907+
let persistence_db = db::persistence::Database {
908+
id: database.id,
909+
database_identity: database.database_identity,
910+
owner_identity: database.owner_identity,
911+
};
912+
let persistence = persistence.persistence(&persistence_db, replica_id).await?;
908913
// Loading a database from persistent storage involves heavy
909914
// blocking I/O. `asyncify` to avoid blocking the async worker.
910915
let (db, clients) = asyncify({

crates/core/src/subscription/module_subscription_actor.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,12 @@ impl ModuleSubscriptions {
17441744
}
17451745
}
17461746
}
1747+
if update_metrics.bytes_sent_to_clients > 0 {
1748+
WORKER_METRICS
1749+
.bytes_sent_to_clients
1750+
.with_label_values(&WorkloadType::Subscribe, &self.relational_db.database_identity())
1751+
.inc_by(update_metrics.bytes_sent_to_clients as u64);
1752+
}
17471753
read_tx.metrics.merge(update_metrics);
17481754
Ok(Ok(CommitAndBroadcastEventSuccess {
17491755
tx_offset: extra_tx_offset,

crates/core/src/worker_metrics/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ metrics_group!(
4343
#[labels(database_identity: Identity, protocol: str)]
4444
pub websocket_request_msg_size: HistogramVec,
4545

46+
#[name = spacetime_num_bytes_sent_to_clients_total]
47+
#[help = "The cumulative number of bytes sent to clients"]
48+
#[labels(workload: WorkloadType, db: Identity)]
49+
pub bytes_sent_to_clients: IntCounterVec,
50+
4651
#[name = jemalloc_active_bytes]
4752
#[help = "Number of bytes in jemallocs heap"]
4853
#[labels(node_id: str)]

crates/engine/src/db/persistence.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ pub type Durability = dyn spacetimedb_durability::Durability<TxData = Txdata>;
8585
/// configured or the database is in follower state.
8686
pub type DiskSizeFn = Arc<dyn Fn() -> io::Result<SizeOnDisk> + Send + Sync>;
8787

88+
#[derive(Clone, Copy, Debug)]
89+
pub struct Database {
90+
pub id: u64,
91+
pub database_identity: Identity,
92+
pub owner_identity: Identity,
93+
}
94+
8895
/// Persistence services for a database.
8996
pub struct Persistence {
9097
/// The [Durability] to use, for persisting transactions.
@@ -182,7 +189,7 @@ impl Persistence {
182189
/// This is an `async_trait` to allow it to be used as a trait object.
183190
#[async_trait]
184191
pub trait PersistenceProvider: Send + Sync {
185-
async fn persistence(&self, database_identity: Identity, replica_id: u64) -> anyhow::Result<Persistence>;
192+
async fn persistence(&self, database: &Database, replica_id: u64) -> anyhow::Result<Persistence>;
186193
}
187194

188195
/// The standard [PersistenceProvider] for non-replicated databases.
@@ -215,7 +222,8 @@ impl LocalPersistenceProvider {
215222

216223
#[async_trait]
217224
impl PersistenceProvider for LocalPersistenceProvider {
218-
async fn persistence(&self, database_identity: Identity, replica_id: u64) -> anyhow::Result<Persistence> {
225+
async fn persistence(&self, database: &Database, replica_id: u64) -> anyhow::Result<Persistence> {
226+
let database_identity = database.database_identity;
219227
let replica_dir = self.data_dir.replica(replica_id);
220228
let snapshot_dir = replica_dir.snapshots();
221229
let runtime = Handle::tokio_current();

crates/engine/src/metrics.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use once_cell::sync::Lazy;
2-
use prometheus::{GaugeVec, HistogramVec, IntCounter, IntCounterVec, IntGaugeVec};
2+
use prometheus::{GaugeVec, HistogramVec, IntCounter, IntGaugeVec};
33
use spacetimedb_datastore::{
44
db_metrics::DB_METRICS, execution_context::WorkloadType, locking_tx_datastore::datastore::MetricsRecorder,
55
};
@@ -8,11 +8,6 @@ use spacetimedb_metrics::metrics_group;
88

99
metrics_group!(
1010
pub struct EngineMetrics {
11-
#[name = spacetime_num_bytes_sent_to_clients_total]
12-
#[help = "The cumulative number of bytes sent to clients"]
13-
#[labels(txn_type: WorkloadType, db: Identity)]
14-
pub bytes_sent_to_clients: IntCounterVec,
15-
1611
#[name = spacetime_replay_total_time_seconds]
1712
#[help = "Total time spent replaying a database upon restart, including snapshot read, snapshot restore and commitlog replay"]
1813
#[labels(db: Identity)]
@@ -121,7 +116,6 @@ pub struct ExecutionCounters {
121116
rdb_num_rows_scanned: IntCounter,
122117
rdb_num_bytes_scanned: IntCounter,
123118
rdb_num_bytes_written: IntCounter,
124-
bytes_sent_to_clients: IntCounter,
125119
delta_queries_matched: IntCounter,
126120
delta_queries_evaluated: IntCounter,
127121
duplicate_rows_evaluated: IntCounter,
@@ -135,7 +129,6 @@ impl ExecutionCounters {
135129
rdb_num_rows_scanned: DB_METRICS.rdb_num_rows_scanned.with_label_values(workload, db),
136130
rdb_num_bytes_scanned: DB_METRICS.rdb_num_bytes_scanned.with_label_values(workload, db),
137131
rdb_num_bytes_written: DB_METRICS.rdb_num_bytes_written.with_label_values(workload, db),
138-
bytes_sent_to_clients: ENGINE_METRICS.bytes_sent_to_clients.with_label_values(workload, db),
139132
delta_queries_matched: DB_METRICS.delta_queries_matched.with_label_values(db),
140133
delta_queries_evaluated: DB_METRICS.delta_queries_evaluated.with_label_values(db),
141134
duplicate_rows_evaluated: DB_METRICS.duplicate_rows_evaluated.with_label_values(db),
@@ -156,9 +149,6 @@ impl ExecutionCounters {
156149
if metrics.bytes_written > 0 {
157150
self.rdb_num_bytes_written.inc_by(metrics.bytes_written as u64);
158151
}
159-
if metrics.bytes_sent_to_clients > 0 {
160-
self.bytes_sent_to_clients.inc_by(metrics.bytes_sent_to_clients as u64);
161-
}
162152
if metrics.delta_queries_matched > 0 {
163153
self.delta_queries_matched.inc_by(metrics.delta_queries_matched);
164154
}

0 commit comments

Comments
 (0)