Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion accounts-db/src/accounts_index/account_map_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use {

/// one entry in the in-mem accounts index
/// Represents the value for an account key in the in-memory accounts index
#[derive(Debug, Default)]
#[derive(Debug)]
pub struct AccountMapEntry<T> {
/// number of alive slots that contain >= 1 instances of account data for this pubkey
/// where alive represents a slot that has not yet been removed by clean via AccountsDB::clean_stored_dead_slots() for containing no up to date account information
Expand All @@ -34,6 +34,16 @@ impl<T: IndexValue> AccountMapEntry<T> {
meta,
}
}

#[cfg(test)]
pub(super) fn empty_for_tests() -> Self {
Self {
slot_list: RwLock::default(),
ref_count: AtomicRefCount::default(),
meta: AccountMapEntryMeta::default(),
}
}

pub fn ref_count(&self) -> RefCount {
self.ref_count.load(Ordering::Acquire)
}
Expand Down
6 changes: 3 additions & 3 deletions accounts-db/src/accounts_index/in_mem_accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2211,7 +2211,7 @@ mod tests {

{
// add an entry with an empty slot list
let val = Arc::new(AccountMapEntry::<u64>::default());
let val = Arc::new(AccountMapEntry::<u64>::empty_for_tests());
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could possibly create entry with new(defaults...), but I think having function encapsulates this use case better and hides what exact values are used for initialization

map.insert(key, val);
let entry = map.entry(key);
assert_matches!(entry, Entry::Occupied(_));
Expand All @@ -2225,7 +2225,7 @@ mod tests {

{
// add an entry with a NON empty slot list - it will NOT get removed
let val = Arc::new(AccountMapEntry::<u64>::default());
let val = Arc::new(AccountMapEntry::<u64>::empty_for_tests());
val.slot_list.write().unwrap().push((1, 1));
map.insert(key, val);
// does NOT remove it since it has a non-empty slot list
Expand All @@ -2238,7 +2238,7 @@ mod tests {

#[test]
fn test_lock_and_update_slot_list() {
let test = AccountMapEntry::<u64>::default();
let test = AccountMapEntry::<u64>::empty_for_tests();
let info = 65;
let mut reclaims = ReclaimsSlotList::new();
// first upsert, should increase
Expand Down
Loading