AcctIdx: move background() to AccountsIndexStorage (#19948)

This commit is contained in:
Jeff Washington (jwash) 2021-09-16 17:52:06 -05:00 committed by GitHub
parent 9f66965eac
commit 58f25a8752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 18 deletions

View File

@ -3,6 +3,7 @@ use crate::bucket_map_holder::BucketMapHolder;
use crate::in_mem_accounts_index::InMemAccountsIndex; use crate::in_mem_accounts_index::InMemAccountsIndex;
use crate::waitable_condvar::WaitableCondvar; use crate::waitable_condvar::WaitableCondvar;
use std::fmt::Debug; use std::fmt::Debug;
use std::time::Duration;
use std::{ use std::{
sync::{ sync::{
atomic::{AtomicBool, Ordering}, atomic::{AtomicBool, Ordering},
@ -51,16 +52,16 @@ impl<T: IndexValue> AccountsIndexStorage<T> {
.map(|bin| Arc::new(InMemAccountsIndex::new(&storage, bin))) .map(|bin| Arc::new(InMemAccountsIndex::new(&storage, bin)))
.collect(); .collect();
let storage_ = storage.clone(); let storage_ = Arc::clone(&storage);
let exit = Arc::new(AtomicBool::default()); let exit = Arc::new(AtomicBool::default());
let exit_ = exit.clone(); let exit_ = Arc::clone(&exit);
let wait = Arc::new(WaitableCondvar::default()); let wait = Arc::new(WaitableCondvar::default());
let wait_ = wait.clone(); let wait_ = Arc::clone(&wait);
let handle = Some( let handle = Some(
Builder::new() Builder::new()
.name("solana-index-flusher".to_string()) .name("solana-index-flusher".to_string())
.spawn(move || { .spawn(move || {
storage_.background(exit_, wait_); Self::background(storage_, exit_, wait_);
}) })
.unwrap(), .unwrap(),
); );
@ -77,4 +78,19 @@ impl<T: IndexValue> AccountsIndexStorage<T> {
pub fn storage(&self) -> &Arc<BucketMapHolder<T>> { pub fn storage(&self) -> &Arc<BucketMapHolder<T>> {
&self.storage &self.storage
} }
// intended to execute in a bg thread
pub fn background(
storage: Arc<BucketMapHolder<T>>,
exit: Arc<AtomicBool>,
wait: Arc<WaitableCondvar>,
) {
loop {
wait.wait_timeout(Duration::from_millis(10000)); // account index stats every 10 s
if exit.load(Ordering::Relaxed) {
break;
}
storage.stats.report_stats();
}
}
} }

View File

@ -1,10 +1,6 @@
use crate::accounts_index::IndexValue; use crate::accounts_index::IndexValue;
use crate::bucket_map_holder_stats::BucketMapHolderStats; use crate::bucket_map_holder_stats::BucketMapHolderStats;
use crate::waitable_condvar::WaitableCondvar;
use std::fmt::Debug; use std::fmt::Debug;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
// will eventually hold the bucket map // will eventually hold the bucket map
pub struct BucketMapHolder<T: IndexValue> { pub struct BucketMapHolder<T: IndexValue> {
@ -25,14 +21,4 @@ impl<T: IndexValue> BucketMapHolder<T> {
_phantom: std::marker::PhantomData::<T>::default(), _phantom: std::marker::PhantomData::<T>::default(),
} }
} }
// intended to execute in a bg thread
pub fn background(&self, exit: Arc<AtomicBool>, wait: Arc<WaitableCondvar>) {
loop {
wait.wait_timeout(Duration::from_millis(10000)); // account index stats every 10 s
if exit.load(Ordering::Relaxed) {
break;
}
self.stats.report_stats();
}
}
} }