forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 383
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
Return back stale out-of-pool scheduler by timeout #1690
Merged
ryoqun
merged 5 commits into
anza-xyz:master
from
ryoqun:stale-taken-scheduler-returning
Jun 13, 2024
Merged
Changes from 1 commit
Commits
Show all changes
5 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 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 |
---|---|---|
|
@@ -347,6 +347,13 @@ impl SchedulerStatus { | |
}; | ||
result_with_timings | ||
} | ||
|
||
fn active_scheduler(&self) -> &InstalledSchedulerBox { | ||
let SchedulerStatus::Active(active_scheduler) = self else { | ||
panic!("not active: {self:?}"); | ||
}; | ||
active_scheduler | ||
} | ||
} | ||
|
||
/// Very thin wrapper around Arc<Bank> | ||
|
@@ -519,15 +526,15 @@ impl BankWithSchedulerInner { | |
); | ||
Err(SchedulerAborted) | ||
} | ||
SchedulerStatus::Stale(_pool, _result_with_timings) => { | ||
SchedulerStatus::Stale(pool, _result_with_timings) => { | ||
let pool = pool.clone(); | ||
drop(scheduler); | ||
|
||
let context = SchedulingContext::new(self.bank.clone()); | ||
let mut scheduler = self.scheduler.write().unwrap(); | ||
trace!("with_active_scheduler: {:?}", scheduler); | ||
scheduler.transition_from_stale_to_active(|scheduler_pool, result_with_timings| { | ||
scheduler_pool.register_timeout_listener(self.do_create_timeout_listener()); | ||
let scheduler = scheduler_pool.take_resumed_scheduler(context, result_with_timings); | ||
scheduler.transition_from_stale_to_active(|pool, result_with_timings| { | ||
let scheduler = pool.take_resumed_scheduler(context, result_with_timings); | ||
info!( | ||
"with_active_scheduler: bank (slot: {}) got active, taking scheduler (id: {})", | ||
self.bank.slot(), | ||
|
@@ -537,15 +544,20 @@ impl BankWithSchedulerInner { | |
}); | ||
drop(scheduler); | ||
|
||
self.with_active_scheduler(f) | ||
let scheduler = self.scheduler.read().unwrap(); | ||
// Re-register a new timeout listener only after acquiring the read lock; | ||
// Otherwise, the listener would again put scheduler into Stale before the read | ||
// lock, causing panic below. | ||
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. oops forgot to mention this is extremely rare race condition... |
||
pool.register_timeout_listener(self.do_create_timeout_listener()); | ||
f(scheduler.active_scheduler()) | ||
} | ||
SchedulerStatus::Unavailable => unreachable!("no installed scheduler"), | ||
} | ||
} | ||
|
||
fn do_create_timeout_listener(self: &Arc<Self>) -> TimeoutListener { | ||
let weak_bank = Arc::downgrade(self); | ||
TimeoutListener::new(move |scheduler_pool| { | ||
TimeoutListener::new(move |pool| { | ||
let Some(bank) = weak_bank.upgrade() else { | ||
return; | ||
}; | ||
|
@@ -568,7 +580,7 @@ impl BankWithSchedulerInner { | |
bank.bank.slot(), | ||
id, | ||
); | ||
(scheduler_pool, result_with_timings) | ||
(pool, result_with_timings) | ||
}); | ||
trace!("timeout_listener: {:?}", scheduler); | ||
}) | ||
|
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.
why do we need to clone the pool?
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.
because this
pool
is borrowed and we need to re-lockscheduler
with the write access: