From 7939fdc3e550642791e0f9912e4966ee6fb253b3 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang <93241502+yhchiang-sol@users.noreply.github.com> Date: Wed, 16 Feb 2022 00:29:11 -0800 Subject: [PATCH] Minor refactor on Shreds column family descriptor construction. (#23103) --- ledger/src/blockstore_db.rs | 75 ++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/ledger/src/blockstore_db.rs b/ledger/src/blockstore_db.rs index 3b43c0079b5ea5..1b6d2a9ed39f4e 100644 --- a/ledger/src/blockstore_db.rs +++ b/ledger/src/blockstore_db.rs @@ -318,40 +318,18 @@ impl Rocks { new_cf_descriptor::(&access_type, &oldest_slot), new_cf_descriptor::(&access_type, &oldest_slot), new_cf_descriptor::(&access_type, &oldest_slot), - match options.shred_storage_type { - ShredStorageType::RocksLevel => { - new_cf_descriptor::(&access_type, &oldest_slot) - } - ShredStorageType::RocksFifo => { - if options.shred_data_cf_size > FIFO_WRITE_BUFFER_SIZE { - new_cf_descriptor_fifo::(&options.shred_data_cf_size) - } else { - warn!( - "shred_data_cf_size is must be greater than {} for RocksFifo.", - FIFO_WRITE_BUFFER_SIZE - ); - warn!("Fall back to ShredStorageType::RocksLevel for cf::ShredData."); - new_cf_descriptor::(&access_type, &oldest_slot) - } - } - }, - match options.shred_storage_type { - ShredStorageType::RocksLevel => { - new_cf_descriptor::(&access_type, &oldest_slot) - } - ShredStorageType::RocksFifo => { - if options.shred_code_cf_size > FIFO_WRITE_BUFFER_SIZE { - new_cf_descriptor_fifo::(&options.shred_code_cf_size) - } else { - warn!( - "shred_code_cf_size is must be greater than {} for RocksFifo.", - FIFO_WRITE_BUFFER_SIZE - ); - warn!("Fall back to ShredStorageType::RocksLevel for cf::ShredCode."); - new_cf_descriptor::(&access_type, &oldest_slot) - } - } - }, + new_cf_descriptor_shreds::( + &options.shred_storage_type, + &access_type, + &oldest_slot, + &options.shred_data_cf_size, + ), + new_cf_descriptor_shreds::( + &options.shred_storage_type, + &access_type, + &oldest_slot, + &options.shred_code_cf_size, + ), new_cf_descriptor::(&access_type, &oldest_slot), new_cf_descriptor::(&access_type, &oldest_slot), new_cf_descriptor::(&access_type, &oldest_slot), @@ -1437,6 +1415,35 @@ fn get_cf_options( options } +/// Constructs and returns a ColumnFamilyDescriptor based on the +/// specified ShredStorageType. +fn new_cf_descriptor_shreds( + storage_type: &ShredStorageType, + access_type: &AccessType, + oldest_slot: &OldestSlot, + max_cf_size: &u64, +) -> ColumnFamilyDescriptor { + match storage_type { + ShredStorageType::RocksLevel => new_cf_descriptor::(access_type, oldest_slot), + ShredStorageType::RocksFifo => { + if *max_cf_size > FIFO_WRITE_BUFFER_SIZE { + new_cf_descriptor_fifo::(max_cf_size) + } else { + warn!( + "{} cf_size must be greater than {} when using ShredStorageType::RocksFifo.", + C::NAME, + FIFO_WRITE_BUFFER_SIZE + ); + warn!( + "Fall back to ShredStorageType::RocksLevel for cf::{}.", + C::NAME + ); + new_cf_descriptor::(access_type, oldest_slot) + } + } + } +} + fn new_cf_descriptor_fifo( max_cf_size: &u64, ) -> ColumnFamilyDescriptor {