Move Blockstore::blockstore_directory() to ShredStorageType (#26179)
#### Summary of Changes Blockstore::blockstore_directory() function takes a ShredStorageType and returns a path. As it's a ShredStorageType related function, moving it under ShredStorageType as a member function is a better fit. In addition, as we start doing automatic shred compaction type selection under ledger-tool, it becomes more convenient to reuse the function and const under blockstore_options namespace instead of blockstore.
This commit is contained in:
parent
f284bba53b
commit
493108f026
|
@ -11,7 +11,8 @@ use {
|
||||||
},
|
},
|
||||||
blockstore_meta::*,
|
blockstore_meta::*,
|
||||||
blockstore_options::{
|
blockstore_options::{
|
||||||
AccessType, BlockstoreOptions, LedgerColumnOptions, ShredStorageType,
|
AccessType, BlockstoreOptions, BlockstoreRocksFifoOptions, LedgerColumnOptions,
|
||||||
|
ShredStorageType,
|
||||||
},
|
},
|
||||||
leader_schedule_cache::LeaderScheduleCache,
|
leader_schedule_cache::LeaderScheduleCache,
|
||||||
next_slots_iterator::NextSlotsIterator,
|
next_slots_iterator::NextSlotsIterator,
|
||||||
|
@ -84,9 +85,6 @@ pub use {
|
||||||
rocksdb::properties as RocksProperties,
|
rocksdb::properties as RocksProperties,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const BLOCKSTORE_DIRECTORY_ROCKS_LEVEL: &str = "rocksdb";
|
|
||||||
pub const BLOCKSTORE_DIRECTORY_ROCKS_FIFO: &str = "rocksdb_fifo";
|
|
||||||
|
|
||||||
// get_max_thread_count to match number of threads in the old code.
|
// get_max_thread_count to match number of threads in the old code.
|
||||||
// see: https://github.com/solana-labs/solana/pull/24853
|
// see: https://github.com/solana-labs/solana/pull/24853
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
@ -226,14 +224,6 @@ impl Blockstore {
|
||||||
&self.ledger_path
|
&self.ledger_path
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The directory under `ledger_path` to the underlying blockstore.
|
|
||||||
pub fn blockstore_directory(shred_storage_type: &ShredStorageType) -> &str {
|
|
||||||
match shred_storage_type {
|
|
||||||
ShredStorageType::RocksLevel => BLOCKSTORE_DIRECTORY_ROCKS_LEVEL,
|
|
||||||
ShredStorageType::RocksFifo(_) => BLOCKSTORE_DIRECTORY_ROCKS_FIFO,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Opens a Ledger in directory, provides "infinite" window of shreds
|
/// Opens a Ledger in directory, provides "infinite" window of shreds
|
||||||
pub fn open(ledger_path: &Path) -> Result<Blockstore> {
|
pub fn open(ledger_path: &Path) -> Result<Blockstore> {
|
||||||
Self::do_open(ledger_path, BlockstoreOptions::default())
|
Self::do_open(ledger_path, BlockstoreOptions::default())
|
||||||
|
@ -245,9 +235,12 @@ impl Blockstore {
|
||||||
|
|
||||||
fn do_open(ledger_path: &Path, options: BlockstoreOptions) -> Result<Blockstore> {
|
fn do_open(ledger_path: &Path, options: BlockstoreOptions) -> Result<Blockstore> {
|
||||||
fs::create_dir_all(&ledger_path)?;
|
fs::create_dir_all(&ledger_path)?;
|
||||||
let blockstore_path = ledger_path.join(Self::blockstore_directory(
|
let blockstore_path = ledger_path.join(
|
||||||
&options.column_options.shred_storage_type,
|
options
|
||||||
));
|
.column_options
|
||||||
|
.shred_storage_type
|
||||||
|
.blockstore_directory(),
|
||||||
|
);
|
||||||
|
|
||||||
adjust_ulimit_nofile(options.enforce_ulimit_nofile)?;
|
adjust_ulimit_nofile(options.enforce_ulimit_nofile)?;
|
||||||
|
|
||||||
|
@ -434,9 +427,15 @@ impl Blockstore {
|
||||||
pub fn destroy(ledger_path: &Path) -> Result<()> {
|
pub fn destroy(ledger_path: &Path) -> Result<()> {
|
||||||
// Database::destroy() fails if the root directory doesn't exist
|
// Database::destroy() fails if the root directory doesn't exist
|
||||||
fs::create_dir_all(ledger_path)?;
|
fs::create_dir_all(ledger_path)?;
|
||||||
Database::destroy(&Path::new(ledger_path).join(BLOCKSTORE_DIRECTORY_ROCKS_LEVEL)).and(
|
Database::destroy(
|
||||||
Database::destroy(&Path::new(ledger_path).join(BLOCKSTORE_DIRECTORY_ROCKS_FIFO)),
|
&Path::new(ledger_path).join(ShredStorageType::RocksLevel.blockstore_directory()),
|
||||||
)
|
)
|
||||||
|
.and(Database::destroy(
|
||||||
|
&Path::new(ledger_path).join(
|
||||||
|
ShredStorageType::RocksFifo(BlockstoreRocksFifoOptions::default())
|
||||||
|
.blockstore_directory(),
|
||||||
|
),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the SlotMeta of the specified slot.
|
/// Returns the SlotMeta of the specified slot.
|
||||||
|
@ -3825,7 +3824,7 @@ pub fn create_new_ledger(
|
||||||
genesis_config.write(ledger_path)?;
|
genesis_config.write(ledger_path)?;
|
||||||
|
|
||||||
// Fill slot 0 with ticks that link back to the genesis_config to bootstrap the ledger.
|
// Fill slot 0 with ticks that link back to the genesis_config to bootstrap the ledger.
|
||||||
let blockstore_dir = Blockstore::blockstore_directory(&column_options.shred_storage_type);
|
let blockstore_dir = column_options.shred_storage_type.blockstore_directory();
|
||||||
let blockstore = Blockstore::open_with_options(
|
let blockstore = Blockstore::open_with_options(
|
||||||
ledger_path,
|
ledger_path,
|
||||||
BlockstoreOptions {
|
BlockstoreOptions {
|
||||||
|
@ -4385,9 +4384,7 @@ pub mod tests {
|
||||||
|
|
||||||
assert_eq!(ticks, entries);
|
assert_eq!(ticks, entries);
|
||||||
assert!(Path::new(ledger_path.path())
|
assert!(Path::new(ledger_path.path())
|
||||||
.join(Blockstore::blockstore_directory(
|
.join(ShredStorageType::RocksLevel.blockstore_directory())
|
||||||
&ShredStorageType::RocksLevel,
|
|
||||||
))
|
|
||||||
.exists());
|
.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4416,26 +4413,13 @@ pub mod tests {
|
||||||
|
|
||||||
assert_eq!(ticks, entries);
|
assert_eq!(ticks, entries);
|
||||||
assert!(Path::new(ledger_path.path())
|
assert!(Path::new(ledger_path.path())
|
||||||
.join(Blockstore::blockstore_directory(
|
.join(
|
||||||
&ShredStorageType::RocksFifo(BlockstoreRocksFifoOptions::default())
|
ShredStorageType::RocksFifo(BlockstoreRocksFifoOptions::default())
|
||||||
))
|
.blockstore_directory()
|
||||||
|
)
|
||||||
.exists());
|
.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_rocksdb_directory() {
|
|
||||||
assert_eq!(
|
|
||||||
Blockstore::blockstore_directory(&ShredStorageType::RocksLevel),
|
|
||||||
BLOCKSTORE_DIRECTORY_ROCKS_LEVEL
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
Blockstore::blockstore_directory(&ShredStorageType::RocksFifo(
|
|
||||||
BlockstoreRocksFifoOptions::default()
|
|
||||||
)),
|
|
||||||
BLOCKSTORE_DIRECTORY_ROCKS_FIFO
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_insert_get_bytes() {
|
fn test_insert_get_bytes() {
|
||||||
// Create enough entries to ensure there are at least two shreds created
|
// Create enough entries to ensure there are at least two shreds created
|
||||||
|
|
|
@ -135,6 +135,9 @@ impl Default for ShredStorageType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const BLOCKSTORE_DIRECTORY_ROCKS_LEVEL: &str = "rocksdb";
|
||||||
|
const BLOCKSTORE_DIRECTORY_ROCKS_FIFO: &str = "rocksdb_fifo";
|
||||||
|
|
||||||
impl ShredStorageType {
|
impl ShredStorageType {
|
||||||
/// Returns ShredStorageType::RocksFifo where the specified
|
/// Returns ShredStorageType::RocksFifo where the specified
|
||||||
/// `shred_storage_size` is equally allocated to shred_data_cf_size
|
/// `shred_storage_size` is equally allocated to shred_data_cf_size
|
||||||
|
@ -142,6 +145,14 @@ impl ShredStorageType {
|
||||||
pub fn rocks_fifo(shred_storage_size: u64) -> ShredStorageType {
|
pub fn rocks_fifo(shred_storage_size: u64) -> ShredStorageType {
|
||||||
ShredStorageType::RocksFifo(BlockstoreRocksFifoOptions::new(shred_storage_size))
|
ShredStorageType::RocksFifo(BlockstoreRocksFifoOptions::new(shred_storage_size))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The directory under `ledger_path` to the underlying blockstore.
|
||||||
|
pub fn blockstore_directory(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
ShredStorageType::RocksLevel => BLOCKSTORE_DIRECTORY_ROCKS_LEVEL,
|
||||||
|
ShredStorageType::RocksFifo(_) => BLOCKSTORE_DIRECTORY_ROCKS_FIFO,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -210,3 +221,15 @@ impl BlockstoreCompressionType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_rocksdb_directory() {
|
||||||
|
assert_eq!(
|
||||||
|
ShredStorageType::RocksLevel.blockstore_directory(),
|
||||||
|
BLOCKSTORE_DIRECTORY_ROCKS_LEVEL
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
ShredStorageType::RocksFifo(BlockstoreRocksFifoOptions::default()).blockstore_directory(),
|
||||||
|
BLOCKSTORE_DIRECTORY_ROCKS_FIFO
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue