Skip to content

Commit

Permalink
Remove Blockstore fifo compaction code (#3469)
Browse files Browse the repository at this point in the history
The use of fifo compaction in Blockstore has been deprecated at the CLI
level of agave-validator. That is, --rocksdb-shred-compaction does not
accept the value of `fifo` any longer.

This change fully removes the fifo compaction code from Blockstore and
related structs
  • Loading branch information
steviez authored Nov 6, 2024
1 parent 22443e7 commit 01b96b4
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 460 deletions.
11 changes: 2 additions & 9 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use {
MAX_REPLAY_WAKE_UP_SIGNALS,
},
blockstore_metric_report_service::BlockstoreMetricReportService,
blockstore_options::BlockstoreOptions,
blockstore_options::{BlockstoreOptions, BLOCKSTORE_DIRECTORY_ROCKS_LEVEL},
blockstore_processor::{self, TransactionStatusSender},
entry_notifier_interface::EntryNotifierArc,
entry_notifier_service::{EntryNotifierSender, EntryNotifierService},
Expand Down Expand Up @@ -2339,14 +2339,7 @@ fn cleanup_blockstore_incorrect_shred_versions(
// not critical, so swallow errors from backup blockstore operations.
let backup_folder = format!(
"{}_backup_{}_{}_{}",
config
.blockstore_options
.column_options
.shred_storage_type
.blockstore_directory(),
incorrect_shred_version,
start_slot,
end_slot
BLOCKSTORE_DIRECTORY_ROCKS_LEVEL, incorrect_shred_version, start_slot, end_slot
);
match Blockstore::open_with_options(
&blockstore.ledger_path().join(backup_folder),
Expand Down
20 changes: 3 additions & 17 deletions ledger-tool/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use {
crate::{
error::{LedgerToolError, Result},
ledger_path::canonicalize_ledger_path,
ledger_utils::{get_program_ids, get_shred_storage_type},
ledger_utils::get_program_ids,
output::{output_ledger, output_slot, CliDuplicateSlotProof, SlotBounds, SlotInfo},
},
chrono::{DateTime, Utc},
Expand All @@ -21,7 +21,7 @@ use {
ancestor_iterator::AncestorIterator,
blockstore::{Blockstore, PurgeType},
blockstore_db::{self, Column, ColumnName, Database},
blockstore_options::{AccessType, BLOCKSTORE_DIRECTORY_ROCKS_FIFO},
blockstore_options::AccessType,
shred::Shred,
},
solana_sdk::{
Expand Down Expand Up @@ -669,22 +669,8 @@ fn do_blockstore_process_command(ledger_path: &Path, matches: &ArgMatches<'_>) -
let target_db = PathBuf::from(value_t_or_exit!(arg_matches, "target_db", String));

let source = crate::open_blockstore(&ledger_path, arg_matches, AccessType::Secondary);

// Check if shred storage type can be inferred; if not, a new
// ledger is being created. open_blockstore() will attempt to
// to infer shred storage type as well, but this check provides
// extra insight to user on how to create a FIFO ledger.
let _ = get_shred_storage_type(
&target_db,
&format!(
"No --target-db ledger at {:?} was detected, default compaction \
(RocksLevel) will be used. Fifo compaction can be enabled for a new \
ledger by manually creating {BLOCKSTORE_DIRECTORY_ROCKS_FIFO} directory \
within the specified --target_db directory.",
&target_db
),
);
let target = crate::open_blockstore(&target_db, arg_matches, AccessType::Primary);

for (slot, _meta) in source.slot_meta_iterator(starting_slot)? {
if slot > ending_slot {
break;
Expand Down
27 changes: 1 addition & 26 deletions ledger-tool/src/ledger_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use {
blockstore::{Blockstore, BlockstoreError},
blockstore_options::{
AccessType, BlockstoreOptions, BlockstoreRecoveryMode, LedgerColumnOptions,
ShredStorageType,
},
blockstore_processor::{
self, BlockstoreProcessorError, ProcessOptions, TransactionStatusSender,
Expand Down Expand Up @@ -442,24 +441,14 @@ pub fn open_blockstore(
.map(BlockstoreRecoveryMode::from);
let force_update_to_open = matches.is_present("force_update_to_open");
let enforce_ulimit_nofile = !matches.is_present("ignore_ulimit_nofile_error");
let shred_storage_type = get_shred_storage_type(
ledger_path,
&format!(
"Shred storage type cannot be inferred for ledger at {ledger_path:?}, using default \
RocksLevel",
),
);

match Blockstore::open_with_options(
ledger_path,
BlockstoreOptions {
access_type: access_type.clone(),
recovery_mode: wal_recovery_mode.clone(),
enforce_ulimit_nofile,
column_options: LedgerColumnOptions {
shred_storage_type,
..LedgerColumnOptions::default()
},
column_options: LedgerColumnOptions::default(),
},
) {
Ok(blockstore) => blockstore,
Expand Down Expand Up @@ -515,20 +504,6 @@ pub fn open_blockstore(
}
}

pub fn get_shred_storage_type(ledger_path: &Path, message: &str) -> ShredStorageType {
// TODO: the following shred_storage_type inference must be updated once
// the rocksdb options can be constructed via load_options_file() as the
// value picked by passing None for `max_shred_storage_size` could affect
// the persisted rocksdb options file.
match ShredStorageType::from_ledger_path(ledger_path, None) {
Some(s) => s,
None => {
info!("{}", message);
ShredStorageType::RocksLevel
}
}
}

/// Open blockstore with temporary primary access to allow necessary,
/// persistent changes to be made to the blockstore (such as creation of new
/// column family(s)). Then, continue opening with `original_access_type`
Expand Down
34 changes: 5 additions & 29 deletions ledger-tool/tests/basic.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use {
assert_cmd::prelude::*,
solana_ledger::{
blockstore, blockstore::Blockstore, blockstore_options::ShredStorageType,
create_new_tmp_ledger_auto_delete, create_new_tmp_ledger_fifo_auto_delete,
blockstore, blockstore::Blockstore, create_new_tmp_ledger_auto_delete,
genesis_utils::create_genesis_config, get_tmp_ledger_path_auto_delete,
},
std::{
fs,
path::Path,
process::{Command, Output},
},
Expand Down Expand Up @@ -46,13 +44,6 @@ fn nominal_default() {
nominal_test_helper(ledger_path.path().to_str().unwrap());
}

#[test]
fn nominal_fifo() {
let genesis_config = create_genesis_config(100).genesis_config;
let (ledger_path, _blockhash) = create_new_tmp_ledger_fifo_auto_delete!(&genesis_config);
nominal_test_helper(ledger_path.path().to_str().unwrap());
}

fn insert_test_shreds(ledger_path: &Path, ending_slot: u64) {
let blockstore = Blockstore::open(ledger_path).unwrap();
let (shreds, _) = blockstore::make_many_slot_entries(
Expand All @@ -63,25 +54,18 @@ fn insert_test_shreds(ledger_path: &Path, ending_slot: u64) {
blockstore.insert_shreds(shreds, None, false).unwrap();
}

fn ledger_tool_copy_test(src_shred_compaction: &str, dst_shred_compaction: &str) {
#[test]
fn ledger_tool_copy_test() {
let genesis_config = create_genesis_config(100).genesis_config;

let (ledger_path, _blockhash) = match src_shred_compaction {
"fifo" => create_new_tmp_ledger_fifo_auto_delete!(&genesis_config),
_ => create_new_tmp_ledger_auto_delete!(&genesis_config),
};
let (ledger_path, _blockhash) = create_new_tmp_ledger_auto_delete!(&genesis_config);

const LEDGER_TOOL_COPY_TEST_SHRED_COUNT: u64 = 25;
const LEDGER_TOOL_COPY_TEST_ENDING_SLOT: u64 = LEDGER_TOOL_COPY_TEST_SHRED_COUNT + 1;
insert_test_shreds(ledger_path.path(), LEDGER_TOOL_COPY_TEST_ENDING_SLOT);
let ledger_path = ledger_path.path().to_str().unwrap();

let target_ledger_path = get_tmp_ledger_path_auto_delete!();
if dst_shred_compaction == "fifo" {
let rocksdb_fifo_path = target_ledger_path
.path()
.join(ShredStorageType::rocks_fifo(None).blockstore_directory());
fs::create_dir_all(rocksdb_fifo_path).unwrap();
}
let target_ledger_path = target_ledger_path.path().to_str().unwrap();
let output = run_ledger_tool(&[
"-l",
Expand All @@ -103,11 +87,3 @@ fn ledger_tool_copy_test(src_shred_compaction: &str, dst_shred_compaction: &str)
assert!(!src_slot_output.stdout.is_empty());
}
}

#[test]
fn copy_test() {
ledger_tool_copy_test("level", "level");
ledger_tool_copy_test("level", "fifo");
ledger_tool_copy_test("fifo", "level");
ledger_tool_copy_test("fifo", "fifo");
}
80 changes: 4 additions & 76 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use {
blockstore_meta::*,
blockstore_metrics::BlockstoreRpcApiMetrics,
blockstore_options::{
AccessType, BlockstoreOptions, LedgerColumnOptions, BLOCKSTORE_DIRECTORY_ROCKS_FIFO,
BLOCKSTORE_DIRECTORY_ROCKS_LEVEL,
AccessType, BlockstoreOptions, LedgerColumnOptions, BLOCKSTORE_DIRECTORY_ROCKS_LEVEL,
},
blockstore_processor::BlockstoreProcessorError,
leader_schedule_cache::LeaderScheduleCache,
Expand Down Expand Up @@ -336,12 +335,7 @@ impl Blockstore {

fn do_open(ledger_path: &Path, options: BlockstoreOptions) -> Result<Blockstore> {
fs::create_dir_all(ledger_path)?;
let blockstore_path = ledger_path.join(
options
.column_options
.shred_storage_type
.blockstore_directory(),
);
let blockstore_path = ledger_path.join(BLOCKSTORE_DIRECTORY_ROCKS_LEVEL);

adjust_ulimit_nofile(options.enforce_ulimit_nofile)?;

Expand Down Expand Up @@ -497,9 +491,7 @@ impl Blockstore {
pub fn destroy(ledger_path: &Path) -> Result<()> {
// Database::destroy() fails if the root directory doesn't exist
fs::create_dir_all(ledger_path)?;
Database::destroy(&Path::new(ledger_path).join(BLOCKSTORE_DIRECTORY_ROCKS_LEVEL)).and(
Database::destroy(&Path::new(ledger_path).join(BLOCKSTORE_DIRECTORY_ROCKS_FIFO)),
)
Database::destroy(&Path::new(ledger_path).join(BLOCKSTORE_DIRECTORY_ROCKS_LEVEL))
}

/// Returns the SlotMeta of the specified slot.
Expand Down Expand Up @@ -4866,7 +4858,7 @@ pub fn create_new_ledger(
genesis_config.write(ledger_path)?;

// Fill slot 0 with ticks that link back to the genesis_config to bootstrap the ledger.
let blockstore_dir = column_options.shred_storage_type.blockstore_directory();
let blockstore_dir = BLOCKSTORE_DIRECTORY_ROCKS_LEVEL;
let blockstore = Blockstore::open_with_options(
ledger_path,
BlockstoreOptions {
Expand Down Expand Up @@ -5047,23 +5039,6 @@ macro_rules! create_new_tmp_ledger_with_size {
};
}

#[macro_export]
macro_rules! create_new_tmp_ledger_fifo {
($genesis_config:expr) => {
$crate::blockstore::create_new_ledger_from_name(
$crate::tmp_ledger_name!(),
$genesis_config,
$crate::macro_reexports::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
$crate::blockstore_options::LedgerColumnOptions {
shred_storage_type: $crate::blockstore_options::ShredStorageType::RocksFifo(
$crate::blockstore_options::BlockstoreRocksFifoOptions::new_for_tests(),
),
..$crate::blockstore_options::LedgerColumnOptions::default()
},
)
};
}

#[macro_export]
macro_rules! create_new_tmp_ledger_auto_delete {
($genesis_config:expr) => {
Expand All @@ -5076,23 +5051,6 @@ macro_rules! create_new_tmp_ledger_auto_delete {
};
}

#[macro_export]
macro_rules! create_new_tmp_ledger_fifo_auto_delete {
($genesis_config:expr) => {
$crate::blockstore::create_new_ledger_from_name_auto_delete(
$crate::tmp_ledger_name!(),
$genesis_config,
$crate::macro_reexports::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
$crate::blockstore_options::LedgerColumnOptions {
shred_storage_type: $crate::blockstore_options::ShredStorageType::RocksFifo(
$crate::blockstore_options::BlockstoreRocksFifoOptions::new_for_tests(),
),
..$crate::blockstore_options::LedgerColumnOptions::default()
},
)
};
}

pub(crate) fn verify_shred_slots(slot: Slot, parent: Slot, root: Slot) -> bool {
if slot == 0 && parent == 0 && root == 0 {
return true; // valid write to slot zero.
Expand Down Expand Up @@ -5390,7 +5348,6 @@ pub mod tests {
use {
super::*,
crate::{
blockstore_options::{BlockstoreRocksFifoOptions, ShredStorageType},
genesis_utils::{create_genesis_config, GenesisConfigInfo},
leader_schedule::{FixedSchedule, LeaderSchedule},
shred::{max_ticks_per_n_shreds, ShredFlags, LEGACY_SHRED_DATA_CAPACITY},
Expand Down Expand Up @@ -5486,35 +5443,6 @@ pub mod tests {
);
}

#[test]
fn test_create_new_ledger_with_options_fifo() {
solana_logger::setup();
let mint_total = 1_000_000_000_000;
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(mint_total);
let (ledger_path, _blockhash) = create_new_tmp_ledger_fifo_auto_delete!(&genesis_config);
let blockstore = Blockstore::open_with_options(
ledger_path.path(),
BlockstoreOptions {
column_options: LedgerColumnOptions {
shred_storage_type: ShredStorageType::RocksFifo(
BlockstoreRocksFifoOptions::new_for_tests(),
),
..LedgerColumnOptions::default()
},
..BlockstoreOptions::default()
},
)
.unwrap();

let ticks = create_ticks(genesis_config.ticks_per_slot, 0, genesis_config.hash());
let entries = blockstore.get_slot_entries(0, 0).unwrap();

assert_eq!(ticks, entries);
assert!(Path::new(ledger_path.path())
.join(BLOCKSTORE_DIRECTORY_ROCKS_FIFO)
.exists());
}

#[test]
fn test_insert_get_bytes() {
// Create enough entries to ensure there are at least two shreds created
Expand Down
Loading

0 comments on commit 01b96b4

Please sign in to comment.