DiskIdx: reuse disk bucket file if possible (#33379)
This commit is contained in:
parent
1840fd7ab3
commit
e92d90b674
|
@ -19,7 +19,9 @@ use {
|
||||||
solana_sdk::pubkey::Pubkey,
|
solana_sdk::pubkey::Pubkey,
|
||||||
std::{
|
std::{
|
||||||
collections::hash_map::DefaultHasher,
|
collections::hash_map::DefaultHasher,
|
||||||
|
fs,
|
||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
|
num::NonZeroU64,
|
||||||
ops::RangeBounds,
|
ops::RangeBounds,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::{
|
sync::{
|
||||||
|
@ -119,18 +121,44 @@ impl<'b, T: Clone + Copy + PartialEq + std::fmt::Debug + 'static> Bucket<T> {
|
||||||
max_search: MaxSearch,
|
max_search: MaxSearch,
|
||||||
stats: Arc<BucketMapStats>,
|
stats: Arc<BucketMapStats>,
|
||||||
count: Arc<AtomicU64>,
|
count: Arc<AtomicU64>,
|
||||||
restartable_bucket: RestartableBucket,
|
mut restartable_bucket: RestartableBucket,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let (index, _file_name) = BucketStorage::new(
|
let reuse_path = std::mem::take(&mut restartable_bucket.path);
|
||||||
Arc::clone(&drives),
|
let elem_size = NonZeroU64::new(std::mem::size_of::<IndexEntry<T>>() as u64).unwrap();
|
||||||
1,
|
let (index, random) = reuse_path
|
||||||
std::mem::size_of::<IndexEntry<T>>() as u64,
|
.and_then(|path| {
|
||||||
max_search,
|
// try to re-use the file this bucket was using last time we were running
|
||||||
Arc::clone(&stats.index),
|
restartable_bucket.get().and_then(|(_file_name, random)| {
|
||||||
count,
|
let result = BucketStorage::load_on_restart(
|
||||||
);
|
path.clone(),
|
||||||
stats.index.resize_grow(0, index.capacity_bytes());
|
elem_size,
|
||||||
let random = thread_rng().gen();
|
max_search,
|
||||||
|
Arc::clone(&stats.index),
|
||||||
|
count.clone(),
|
||||||
|
)
|
||||||
|
.map(|index| (index, random));
|
||||||
|
if result.is_none() {
|
||||||
|
// we couldn't re-use it, so delete it
|
||||||
|
_ = fs::remove_file(path);
|
||||||
|
}
|
||||||
|
result
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
// no file to re-use, so create a new file
|
||||||
|
let (index, file_name) = BucketStorage::new(
|
||||||
|
Arc::clone(&drives),
|
||||||
|
1,
|
||||||
|
elem_size.into(),
|
||||||
|
max_search,
|
||||||
|
Arc::clone(&stats.index),
|
||||||
|
count,
|
||||||
|
);
|
||||||
|
stats.index.resize_grow(0, index.capacity_bytes());
|
||||||
|
let random = thread_rng().gen();
|
||||||
|
restartable_bucket.set_file(file_name, random);
|
||||||
|
(index, random)
|
||||||
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
random,
|
random,
|
||||||
|
|
Loading…
Reference in New Issue