From 8c28f9b63ed948b9958d6d8f703dd9bfa420a480 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Thu, 22 Jul 2021 11:56:23 -0600 Subject: [PATCH] Exclude stubbed ProgramCosts column from compaction (#18840) --- ledger/src/blockstore_db.rs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/ledger/src/blockstore_db.rs b/ledger/src/blockstore_db.rs index 5268813e48..ba43ae26f5 100644 --- a/ledger/src/blockstore_db.rs +++ b/ledger/src/blockstore_db.rs @@ -22,7 +22,7 @@ use solana_sdk::{ }; use solana_storage_proto::convert::generated; use std::{ - collections::HashMap, + collections::{HashMap, HashSet}, ffi::{CStr, CString}, fs, marker::PhantomData, @@ -421,9 +421,9 @@ impl Rocks { // this is only needed for LedgerCleanupService. so guard with PrimaryOnly (i.e. running solana-validator) if matches!(access_type, AccessType::PrimaryOnly) { for cf_name in cf_names { - // this special column family must be excluded from LedgerCleanupService's rocksdb + // these special column families must be excluded from LedgerCleanupService's rocksdb // compactions - if cf_name == TransactionStatusIndex::NAME { + if excludes_from_compaction(cf_name) { continue; } @@ -1319,9 +1319,7 @@ fn get_cf_options( // TransactionStatusIndex must be excluded from LedgerCleanupService's rocksdb // compactions.... - if matches!(access_type, AccessType::PrimaryOnly) - && C::NAME != columns::TransactionStatusIndex::NAME - { + if matches!(access_type, AccessType::PrimaryOnly) && !excludes_from_compaction(C::NAME) { options.set_compaction_filter_factory(PurgedSlotFilterFactory:: { oldest_slot: oldest_slot.clone(), name: CString::new(format!("purged_slot_filter_factory({})", C::NAME)).unwrap(), @@ -1361,6 +1359,18 @@ fn get_db_options(access_type: &AccessType) -> Options { options } +fn excludes_from_compaction(cf_name: &str) -> bool { + // list of Column Families must be excluded from compaction: + let no_compaction_cfs: HashSet<&'static str> = vec![ + columns::TransactionStatusIndex::NAME, + columns::ProgramCosts::NAME, + ] + .into_iter() + .collect(); + + no_compaction_cfs.get(cf_name).is_some() +} + #[cfg(test)] pub mod tests { use super::*; @@ -1413,4 +1423,14 @@ pub mod tests { CompactionDecision::Keep ); } + + #[test] + fn test_excludes_from_compaction() { + // currently there are two CFs are excluded from compaction: + assert!(excludes_from_compaction( + columns::TransactionStatusIndex::NAME + )); + assert!(excludes_from_compaction(columns::ProgramCosts::NAME)); + assert!(!excludes_from_compaction("something else")); + } }