From 29947ba86738a783a961f01965079f19402c4dd7 Mon Sep 17 00:00:00 2001 From: steviez Date: Fri, 17 Nov 2023 10:18:08 -0600 Subject: [PATCH] Consolidate repeated code in Rocks::open() (#34131) The function matches the access type and calls a different RocksDB function depending on whether we have primary or secondary access. But, lots of the code is the same for these two paths so de-duplicate the repeated sections. --- ledger/src/blockstore_db.rs | 53 ++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/ledger/src/blockstore_db.rs b/ledger/src/blockstore_db.rs index 0b2b144455..3e1d8812f6 100644 --- a/ledger/src/blockstore_db.rs +++ b/ledger/src/blockstore_db.rs @@ -419,46 +419,39 @@ impl Rocks { } let oldest_slot = OldestSlot::default(); let column_options = options.column_options.clone(); + let cf_descriptors = Self::cf_descriptors(&options, &oldest_slot); // Open the database let db = match access_type { - AccessType::Primary | AccessType::PrimaryForMaintenance => Rocks { - db: DB::open_cf_descriptors( - &db_options, - path, - Self::cf_descriptors(&options, &oldest_slot), - )?, - access_type, - oldest_slot, - column_options, - write_batch_perf_status: PerfSamplingStatus::default(), - }, + AccessType::Primary | AccessType::PrimaryForMaintenance => { + DB::open_cf_descriptors(&db_options, path, cf_descriptors)? + } AccessType::Secondary => { let secondary_path = path.join("solana-secondary"); - info!( - "Opening Rocks with secondary (read only) access at: {:?}", - secondary_path + "Opening Rocks with secondary (read only) access at: {secondary_path:?}. \ + This secondary access could temporarily degrade other accesses, such as \ + by solana-validator" ); - info!("This secondary access could temporarily degrade other accesses, such as by solana-validator"); - - Rocks { - db: DB::open_cf_descriptors_as_secondary( - &db_options, - path, - &secondary_path, - Self::cf_descriptors(&options, &oldest_slot), - )?, - access_type, - oldest_slot, - column_options, - write_batch_perf_status: PerfSamplingStatus::default(), - } + DB::open_cf_descriptors_as_secondary( + &db_options, + path, + &secondary_path, + cf_descriptors, + )? } }; - db.configure_compaction(); + let rocks = Rocks { + db, + access_type, + oldest_slot, + column_options, + write_batch_perf_status: PerfSamplingStatus::default(), + }; - Ok(db) + rocks.configure_compaction(); + + Ok(rocks) } fn cf_descriptors(