This repository was archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
unref accounts from destroyed forks #19402
Closed
jeffwashington
wants to merge
2
commits into
solana-labs:v1.6
from
jeffwashington:non-clean-1.6_jwash2
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -300,7 +300,7 @@ impl AccountStorage { | |
| .and_then(|storage_map| storage_map.read().unwrap().get(&store_id).cloned()) | ||
| } | ||
|
|
||
| fn get_slot_stores(&self, slot: Slot) -> Option<SlotStores> { | ||
| pub fn get_slot_stores(&self, slot: Slot) -> Option<SlotStores> { | ||
| self.0.get(&slot).map(|result| result.value().clone()) | ||
| } | ||
|
|
||
|
|
@@ -376,6 +376,8 @@ pub struct AccountStorageEntry { | |
| approx_store_count: AtomicUsize, | ||
|
|
||
| alive_bytes: AtomicUsize, | ||
|
|
||
| pub(crate) unref_done: AtomicBool, | ||
| } | ||
|
|
||
| impl AccountStorageEntry { | ||
|
|
@@ -391,6 +393,7 @@ impl AccountStorageEntry { | |
| count_and_status: RwLock::new((0, AccountStorageStatus::Available)), | ||
| approx_store_count: AtomicUsize::new(0), | ||
| alive_bytes: AtomicUsize::new(0), | ||
| unref_done: AtomicBool::new(false), | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -407,6 +410,7 @@ impl AccountStorageEntry { | |
| count_and_status: RwLock::new((0, AccountStorageStatus::Available)), | ||
| approx_store_count: AtomicUsize::new(num_accounts), | ||
| alive_bytes: AtomicUsize::new(0), | ||
| unref_done: AtomicBool::new(false), | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -439,6 +443,7 @@ impl AccountStorageEntry { | |
| self.id.store(id, Ordering::Relaxed); | ||
| self.approx_store_count.store(0, Ordering::Relaxed); | ||
| self.alive_bytes.store(0, Ordering::Relaxed); | ||
| self.unref_done.store(false, Ordering::Relaxed); | ||
| } | ||
|
|
||
| pub fn status(&self) -> AccountStorageStatus { | ||
|
|
@@ -2619,6 +2624,16 @@ impl AccountsDb { | |
| } | ||
| remove_storages_elapsed.stop(); | ||
|
|
||
| for s in &all_removed_slot_storages { | ||
| for (_store_id, store) in s.read().unwrap().iter() { | ||
| if !store.unref_done.swap(true, Ordering::Relaxed) { | ||
| for a in store.accounts.accounts(0) { | ||
| self.accounts_index.unref_from_storage(&a.meta.pubkey); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| let num_stored_slots_removed = all_removed_slot_storages.len(); | ||
|
|
||
| let recycle_stores_write_elapsed = | ||
|
|
@@ -3071,6 +3086,10 @@ impl AccountsDb { | |
| .fetch_add(recycle_stores_write_elapsed.as_us(), Ordering::Relaxed); | ||
| } | ||
|
|
||
| pub fn flush_accounts_cache_slot(&self, slot: Slot) { | ||
| self.flush_slot_cache(slot, None::<&mut fn(&_, &_) -> bool>); | ||
| } | ||
|
|
||
| // `force_flush` flushes all the cached roots `<= requested_flush_root`. It also then | ||
| // flushes: | ||
| // 1) Any remaining roots if there are > MAX_CACHE_SLOTS remaining slots in the cache, | ||
|
|
@@ -4032,6 +4051,9 @@ impl AccountsDb { | |
| for slot in dead_slots.iter() { | ||
| if let Some(slot_storage) = self.storage.get_slot_stores(*slot) { | ||
| for store in slot_storage.read().unwrap().values() { | ||
| let already_unrefd = store.unref_done.swap(true, Ordering::Relaxed); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sakridge here's the other path I found. |
||
| assert!(!already_unrefd); | ||
|
|
||
| stores.push(store.clone()); | ||
| } | ||
| } | ||
|
|
@@ -5848,7 +5870,7 @@ pub mod tests { | |
| } | ||
| } | ||
|
|
||
| fn ref_count_for_pubkey(&self, pubkey: &Pubkey) -> RefCount { | ||
| pub fn ref_count_for_pubkey(&self, pubkey: &Pubkey) -> RefCount { | ||
| self.accounts_index.ref_count_from_storage(&pubkey) | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sakridge here's my first attempt. All tests pass with the exception of a race condition I'm debugging in:
test_store_scan_consistency_unrooted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. So if we may go through the unref path twice in some cases. This would prevent that by keeping a bool per store to prevent it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All runtime tests now pass locally. I wasn't handling
AccountStorageEntry::recycle.