Skip to content
Open
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
5 changes: 4 additions & 1 deletion crates/blockchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::{Duration, SystemTime};

use ethlambda_network_api::{BlockChainToP2PRef, InitP2P};
use ethlambda_state_transition::is_proposer;
use ethlambda_storage::Store;
use ethlambda_storage::{ALL_TABLES, Store};
use ethlambda_types::{
ShortRoot,
attestation::{Attestation, AttestationData, SignedAggregatedAttestation, SignedAttestation},
Expand Down Expand Up @@ -285,6 +285,9 @@ impl BlockChainServer {
metrics::update_latest_justified_slot(self.store.latest_justified().slot);
metrics::update_latest_finalized_slot(self.store.latest_finalized().slot);
metrics::update_validators_count(self.key_manager.validator_ids().len() as u64);
for table in ALL_TABLES {
metrics::update_table_bytes(table.name(), self.store.estimate_table_bytes(table));
}
Ok(())
}

Expand Down
15 changes: 15 additions & 0 deletions crates/blockchain/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,21 @@ pub fn time_committee_signatures_aggregation() -> TimingGuard {
TimingGuard::new(&LEAN_COMMITTEE_SIGNATURES_AGGREGATION_TIME_SECONDS)
}

/// Update a table byte size gauge.
pub fn update_table_bytes(table_name: &str, bytes: u64) {
static LEAN_TABLE_BYTES: std::sync::LazyLock<IntGaugeVec> = std::sync::LazyLock::new(|| {
register_int_gauge_vec!(
"lean_table_bytes",
"Byte size of a storage table (key + value bytes)",
&["table"]
)
.unwrap()
});
LEAN_TABLE_BYTES
.with_label_values(&[table_name])
.set(bytes as i64);
}

/// Update the gossip signatures gauge.
pub fn update_gossip_signatures(count: usize) {
static LEAN_GOSSIP_SIGNATURES: std::sync::LazyLock<IntGauge> = std::sync::LazyLock::new(|| {
Expand Down
16 changes: 16 additions & 0 deletions crates/storage/src/api/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,19 @@ pub const ALL_TABLES: [Table; 8] = [
Table::Metadata,
Table::LiveChain,
];

impl Table {
/// Human-readable name for metrics labels.
pub fn name(self) -> &'static str {
match self {
Table::BlockHeaders => "block_headers",
Table::BlockBodies => "block_bodies",
Table::BlockSignatures => "block_signatures",
Table::States => "states",
Table::GossipSignatures => "gossip_signatures",
Table::AttestationDataByRoot => "attestation_data_by_root",
Table::Metadata => "metadata",
Table::LiveChain => "live_chain",
}
}
}
7 changes: 7 additions & 0 deletions crates/storage/src/api/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ pub trait StorageBackend: Send + Sync {

/// Begin a write batch.
fn begin_write(&self) -> Result<Box<dyn StorageWriteBatch + 'static>, Error>;

/// Estimated live data size in bytes for a table.
/// Returns 0 if the backend does not support this (e.g. in-memory).
fn estimate_table_bytes(&self, table: Table) -> u64 {
let _ = table;
0
}
}

/// A read-only view of the storage.
Expand Down
19 changes: 19 additions & 0 deletions crates/storage/src/backend/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ impl StorageBackend for RocksDBBackend {
batch: WriteBatch::default(),
}))
}

fn estimate_table_bytes(&self, table: Table) -> u64 {
let Some(cf) = self.db.cf_handle(cf_name(table)) else {
return 0;
};
let sst_bytes = self
.db
.property_int_value_cf(&cf, "rocksdb.estimate-live-data-size")
.ok()
.flatten()
.unwrap_or(0);
let memtable_bytes = self
.db
.property_int_value_cf(&cf, "rocksdb.cur-size-all-mem-tables")
.ok()
.flatten()
.unwrap_or(0);
sst_bytes + memtable_bytes
}
}

/// Read-only view into RocksDB.
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ pub mod backend;
mod store;
mod types;

pub use api::{StorageBackend, StorageReadView, StorageWriteBatch, Table};
pub use api::{ALL_TABLES, StorageBackend, StorageReadView, StorageWriteBatch, Table};
pub use store::{ForkCheckpoints, SignatureKey, Store};
pub use types::{StoredAggregatedPayload, StoredSignature};
5 changes: 5 additions & 0 deletions crates/storage/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,11 @@ impl Store {
self.gossip_signatures_count.load(Ordering::Relaxed)
}

/// Estimated live data size in bytes for a table, as reported by the backend.
pub fn estimate_table_bytes(&self, table: Table) -> u64 {
self.backend.estimate_table_bytes(table)
}

/// Delete specific gossip signatures by key.
pub fn delete_gossip_signatures(&mut self, keys: &[SignatureKey]) {
if keys.is_empty() {
Expand Down
Loading