AcctIdx: introduce startup to bucket map (#20004)

This commit is contained in:
Jeff Washington (jwash) 2021-09-18 12:55:57 -05:00 committed by GitHub
parent bed0049a51
commit db40d06a39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -2,7 +2,7 @@ use crate::accounts_index::{AccountsIndexConfig, IndexValue};
use crate::bucket_map_holder_stats::BucketMapHolderStats;
use crate::waitable_condvar::WaitableCondvar;
use std::fmt::Debug;
use std::sync::atomic::{AtomicU8, AtomicUsize, Ordering};
use std::sync::atomic::{AtomicBool, AtomicU8, AtomicUsize, Ordering};
use std::sync::Mutex;
pub type Age = u8;
@ -16,6 +16,12 @@ pub struct BucketMapHolder<T: IndexValue> {
pub wait_dirty_bucket: WaitableCondvar,
next_bucket_to_flush: Mutex<usize>,
bins: usize,
/// startup is a special time for flush to focus on moving everything to disk as fast and efficiently as possible
/// with less thread count limitations. LRU and access patterns are not important. Freeing memory
/// and writing to disk in parallel are.
/// Note startup is an optimization and is not required for correctness.
startup: AtomicBool,
_phantom: std::marker::PhantomData<T>,
}
@ -36,6 +42,15 @@ impl<T: IndexValue> BucketMapHolder<T> {
assert!(previous >= self.bins); // we should not have increased age before previous age was fully flushed
}
/// used by bg processes to determine # active threads and how aggressively to flush
pub fn get_startup(&self) -> bool {
self.startup.load(Ordering::Relaxed)
}
pub fn set_startup(&self, value: bool) {
self.startup.store(value, Ordering::Relaxed)
}
pub fn current_age(&self) -> Age {
self.age.load(Ordering::Relaxed)
}
@ -57,6 +72,7 @@ impl<T: IndexValue> BucketMapHolder<T> {
wait_dirty_bucket: WaitableCondvar::default(),
next_bucket_to_flush: Mutex::new(0),
bins,
startup: AtomicBool::default(),
_phantom: std::marker::PhantomData::<T>::default(),
}
}