forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 965
Refactors AccountsBackgroundService if a snapshot request was not handled #6418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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 |
|---|---|---|
|
|
@@ -143,7 +143,7 @@ pub struct SnapshotRequestHandler { | |
| } | ||
|
|
||
| impl SnapshotRequestHandler { | ||
| // Returns the latest requested snapshot block height and storages | ||
| // Returns the latest requested snapshot slot and storages | ||
| #[allow(clippy::type_complexity)] | ||
| pub fn handle_snapshot_requests( | ||
| &self, | ||
|
|
@@ -492,7 +492,7 @@ pub struct AbsRequestHandlers { | |
| } | ||
|
|
||
| impl AbsRequestHandlers { | ||
| // Returns the latest requested snapshot block height, if one exists | ||
| // Returns the latest requested snapshot slot, if one exists | ||
| #[allow(clippy::type_complexity)] | ||
| pub fn handle_snapshot_requests( | ||
| &self, | ||
|
|
@@ -629,26 +629,38 @@ impl AccountsBackgroundService { | |
| break; | ||
| } | ||
| } | ||
| } else if previous_clean_time.elapsed() > CLEAN_INTERVAL { | ||
| // Note that the flush will do an internal clean of the | ||
| // cache up to bank.slot(), so should be safe as long | ||
| // as any later snapshots that are taken are of | ||
| // slots >= bank.slot() | ||
| bank.force_flush_accounts_cache(); | ||
| bank.clean_accounts(); | ||
jeffwashington marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| last_cleaned_slot = bank.slot(); | ||
| previous_clean_time = Instant::now(); | ||
| bank.shrink_ancient_slots(); | ||
| bank.shrink_candidate_slots(); | ||
| previous_shrink_time = Instant::now(); | ||
| } else { | ||
| // Note that the flush will do an internal clean of the | ||
| // cache up to bank.slot(), so should be safe as long | ||
| // as any later snapshots that are taken are of | ||
| // slots >= bank.slot() | ||
| bank.flush_accounts_cache_if_needed(); | ||
jeffwashington marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // we didn't handle a snapshot request, so do flush/clean/shrink | ||
|
|
||
HaoranYi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // see the comments in Bank::clean_accounts() for why we sub 1 here | ||
| let max_clean_slot_inclusive = bank.slot().saturating_sub(1); | ||
|
Comment on lines
+635
to
+636
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. The next PR will change this max clean slot, and that'll be the final fix for the underlying issue. So we'll want to feel pretty good about this refactor first. |
||
|
|
||
| let duration_since_previous_clean = previous_clean_time.elapsed(); | ||
| let should_clean = duration_since_previous_clean > CLEAN_INTERVAL; | ||
|
|
||
| // if we're cleaning, then force flush, otherwise be lazy | ||
| let force_flush = should_clean; | ||
| bank.rc | ||
| .accounts | ||
| .accounts_db | ||
| .flush_accounts_cache(force_flush, Some(max_clean_slot_inclusive)); | ||
|
|
||
| if should_clean { | ||
| bank.clean_accounts(); | ||
| last_cleaned_slot = max_clean_slot_inclusive; | ||
| previous_clean_time = Instant::now(); | ||
| } | ||
|
|
||
| let duration_since_previous_shrink = previous_shrink_time.elapsed(); | ||
| if duration_since_previous_shrink > SHRINK_INTERVAL { | ||
| let should_shrink = duration_since_previous_shrink > SHRINK_INTERVAL; | ||
roryharr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // To avoid pathological interactions between the clean and shrink | ||
| // timers, call shrink for either should_shrink or should_clean. | ||
| if should_shrink || should_clean { | ||
| if should_clean { | ||
| // We used to only squash (aka shrink ancients) when we also | ||
| // cleaned, so keep that same behavior here for now. | ||
| bank.shrink_ancient_slots(); | ||
| } | ||
| bank.shrink_candidate_slots(); | ||
| previous_shrink_time = Instant::now(); | ||
| } | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.