write cache: hashmap to set (#23866)
This commit is contained in:
committed by
GitHub
parent
9e61fe7583
commit
260f899eda
@ -4698,27 +4698,20 @@ impl AccountsDb {
|
|||||||
self.max_clean_root(requested_flush_root)
|
self.max_clean_root(requested_flush_root)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Use HashMap because HashSet doesn't provide Entry api
|
let mut written_accounts = HashSet::new();
|
||||||
let mut written_accounts = HashMap::new();
|
|
||||||
|
|
||||||
// If `should_clean` is None, then`should_flush_f` is also None, which will cause
|
// If `should_clean` is None, then`should_flush_f` is also None, which will cause
|
||||||
// `flush_slot_cache` to flush all accounts to storage without cleaning any accounts.
|
// `flush_slot_cache` to flush all accounts to storage without cleaning any accounts.
|
||||||
let mut should_flush_f = should_clean.map(|(account_bytes_saved, num_accounts_saved)| {
|
let mut should_flush_f = should_clean.map(|(account_bytes_saved, num_accounts_saved)| {
|
||||||
move |&pubkey: &Pubkey, account: &AccountSharedData| {
|
move |&pubkey: &Pubkey, account: &AccountSharedData| {
|
||||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
// if not in hashset, then not flushed previously, so flush it
|
||||||
let should_flush = match written_accounts.entry(pubkey) {
|
let should_flush = written_accounts.insert(pubkey);
|
||||||
Vacant(vacant_entry) => {
|
if !should_flush {
|
||||||
vacant_entry.insert(());
|
|
||||||
true
|
|
||||||
}
|
|
||||||
Occupied(_occupied_entry) => {
|
|
||||||
*account_bytes_saved += account.data().len();
|
*account_bytes_saved += account.data().len();
|
||||||
*num_accounts_saved += 1;
|
*num_accounts_saved += 1;
|
||||||
// If a later root already wrote this account, no point
|
// If a later root already wrote this account, no point
|
||||||
// in flushing it
|
// in flushing it
|
||||||
false
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
should_flush
|
should_flush
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user