Skip to content

Commit

Permalink
Merge branch 'main' into breaking-enha-rocksdb
Browse files Browse the repository at this point in the history
  • Loading branch information
carneiro-cw authored Dec 18, 2024
2 parents bb81337 + 4bec71a commit 0b69539
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ dev = []
# Enable runtime metrics collection.
metrics = ["dep:metrics-exporter-prometheus"]

# Enable runtime rocksdb metrics collection.
rocks_metrics = ["metrics"]

# Enable runtime tracing/spans collection.
tracing = []

Expand Down
4 changes: 2 additions & 2 deletions src/eth/storage/permanent/rocks/rocks_cf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rocksdb::DB;
use serde::Deserialize;
use serde::Serialize;

#[cfg(feature = "metrics")]
#[cfg(feature = "rocks_metrics")]
use crate::infra::metrics;

/// A RocksDB Column Family (CF) reference.
Expand Down Expand Up @@ -232,7 +232,7 @@ where
}
}

#[cfg(feature = "metrics")]
#[cfg(feature = "rocks_metrics")]
pub fn export_metrics(&self) {
let handle = self.handle();
let cur_size_active_mem_table = self
Expand Down
2 changes: 1 addition & 1 deletion src/eth/storage/permanent/rocks/rocks_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl DbConfig {
block_based_options.set_bloom_filter(15.5, false);

// due to the nature of our application enabling rocks metrics decreases point lookup performance by 5x.
#[cfg(feature = "metrics")]
#[cfg(feature = "rocks_metrics")]
{
opts.enable_statistics();
opts.set_statistics_level(rocksdb::statistics::StatsLevel::ExceptTimeForMutex);
Expand Down
6 changes: 6 additions & 0 deletions src/eth/storage/permanent/rocks/rocks_permanent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ impl PermanentStorage for RocksPermanentStorage {
}

fn save_block(&self, block: Block) -> anyhow::Result<()> {
#[cfg(feature = "rocks_metrics")]
{
self.state.export_metrics().inspect_err(|e| {
tracing::error!(reason = ?e, "failed to export metrics in RocksPermanent");
})?;
}
self.state.save_block(block).inspect_err(|e| {
tracing::error!(reason = ?e, "failed to save block in RocksPermanent");
})
Expand Down
18 changes: 10 additions & 8 deletions src/eth/storage/permanent/rocks/rocks_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,19 @@ use crate::eth::primitives::Slot;
use crate::eth::primitives::SlotIndex;
use crate::eth::primitives::TransactionMined;
use crate::ext::OptionExt;
#[cfg(feature = "metrics")]
use crate::infra::metrics;
use crate::log_and_err;
use crate::utils::GIGABYTE;

cfg_if::cfg_if! {
if #[cfg(feature = "metrics")] {
if #[cfg(feature = "rocks_metrics")] {
use parking_lot::Mutex;

use rocksdb::statistics::Histogram;
use rocksdb::statistics::Ticker;

use crate::infra::metrics::{self, Count, HistogramInt, Sum};
use crate::infra::metrics::{Count, HistogramInt, Sum};
}
}

Expand Down Expand Up @@ -115,13 +117,13 @@ pub struct RocksStorageState {
pub blocks_by_number: RocksCfRef<BlockNumberRocksdb, CfBlocksByNumberValue>,
blocks_by_hash: RocksCfRef<HashRocksdb, CfBlocksByHashValue>,
/// Last collected stats for a histogram
#[cfg(feature = "metrics")]
#[cfg(feature = "rocks_metrics")]
prev_stats: Mutex<HashMap<HistogramInt, (Sum, Count)>>,
/// Options passed at DB creation, stored for metrics
///
/// a newly created `rocksdb::Options` object is unique, with an underlying pointer identifier inside of it, and is used to access
/// the DB metrics, `Options` can be cloned, but two equal `Options` might not retrieve the same metrics
#[cfg(feature = "metrics")]
#[cfg(feature = "rocks_metrics")]
db_options: Options,
shutdown_timeout: Duration,
enable_sync_write: bool,
Expand All @@ -133,7 +135,7 @@ impl RocksStorageState {

let cf_options_map = generate_cf_options_map(cache_multiplier);

#[cfg_attr(not(feature = "metrics"), allow(unused_variables))]
#[cfg_attr(not(feature = "rocks_metrics"), allow(unused_variables))]
let (db, db_options) = create_or_open_db(&path, &cf_options_map).context("when trying to create (or open) rocksdb")?;

if db.path().to_str().is_none() {
Expand All @@ -152,9 +154,9 @@ impl RocksStorageState {
transactions: new_cf_ref(&db, "transactions", &cf_options_map)?,
blocks_by_number: new_cf_ref(&db, "blocks_by_number", &cf_options_map)?,
blocks_by_hash: new_cf_ref(&db, "blocks_by_hash", &cf_options_map)?,
#[cfg(feature = "metrics")]
#[cfg(feature = "rocks_metrics")]
prev_stats: Mutex::default(),
#[cfg(feature = "metrics")]
#[cfg(feature = "rocks_metrics")]
db_options,
db,
shutdown_timeout,
Expand Down Expand Up @@ -514,7 +516,7 @@ impl RocksStorageState {
}
}

#[cfg(feature = "metrics")]
#[cfg(feature = "rocks_metrics")]
impl RocksStorageState {
pub fn export_metrics(&self) -> Result<()> {
let db_get = self.db_options.get_histogram_data(Histogram::DbGet);
Expand Down

0 comments on commit 0b69539

Please sign in to comment.