Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Rename: strip redundant prefix from trait methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoqun committed Apr 28, 2023
1 parent 090610f commit 21b7250
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4587,7 +4587,7 @@ pub mod tests {
.expect_wait_for_termination()
.times(1)
.returning(|_| None);
mocked_scheduler.expect_scheduler_pool().returning(move || {
mocked_scheduler.expect_pool().returning(move || {
let mut mocked_pool = MockInstalledSchedulerPool::new();
mocked_pool
.expect_return_to_pool()
Expand Down
14 changes: 7 additions & 7 deletions runtime/src/installed_scheduler_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ pub trait InstalledSchedulerPool: Send + Sync + Debug {
#[allow(unused_attributes)]
// Send + Sync is needed to be a field of Bank
pub trait InstalledScheduler: Send + Sync + Debug {
fn scheduler_id(&self) -> SchedulerId;
fn scheduler_pool(&self) -> InstalledSchedulerPoolArc;
fn id(&self) -> SchedulerId;
fn pool(&self) -> InstalledSchedulerPoolArc;

// Calling this is illegal as soon as schedule_termiantion is called on &self.
fn schedule_execution(&self, sanitized_tx: &SanitizedTransaction, index: usize);
Expand All @@ -120,8 +120,8 @@ pub trait InstalledScheduler: Send + Sync + Debug {
// suppress false clippy complaints arising from mockall-derive:
// warning: the following explicit lifetimes could be elided: 'a
#[allow(clippy::needless_lifetimes)]
fn scheduling_context<'a>(&'a self) -> Option<&'a SchedulingContext>;
fn replace_scheduling_context(&mut self, context: SchedulingContext);
fn context<'a>(&'a self) -> Option<&'a SchedulingContext>;
fn replace_context(&mut self, context: SchedulingContext);
}

pub type InstalledSchedulerPoolArc = Arc<dyn InstalledSchedulerPool>;
Expand Down Expand Up @@ -264,7 +264,7 @@ impl Bank {
.expect("not poisoned")
.0
.as_ref()
.and_then(|scheduler| scheduler.scheduling_context())
.and_then(|scheduler| scheduler.context())
.is_some()
}

Expand Down Expand Up @@ -309,7 +309,7 @@ impl Bank {
.and_then(|scheduler| scheduler.wait_for_termination(&reason));
if !matches!(reason, WaitReason::ReinitializedForRecentBlockhash) {
let scheduler = scheduler.take().expect("scheduler after waiting");
scheduler.scheduler_pool().return_to_pool(scheduler);
scheduler.pool().return_to_pool(scheduler);
}
result_with_timings
} else {
Expand Down Expand Up @@ -395,7 +395,7 @@ mod tests {
.returning(|_| None);
}

mock.expect_scheduler_pool()
mock.expect_pool()
.times(1)
.in_sequence(&mut seq)
.returning(move || setup_mocked_scheduler_pool(&mut seq));
Expand Down
33 changes: 15 additions & 18 deletions scheduler-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ impl InstalledSchedulerPool for SchedulerPool {
// returned recently
let maybe_scheduler = schedulers.pop();
if let Some(mut scheduler) = maybe_scheduler {
scheduler.replace_scheduling_context(context);
scheduler.replace_context(context);
scheduler
} else {
Box::new(PooledScheduler::spawn(self.self_arc(), context))
}
}

fn return_to_pool(&self, scheduler: InstalledSchedulerBox) {
assert!(scheduler.scheduling_context().is_none());
assert!(scheduler.context().is_none());

self.schedulers
.lock()
Expand Down Expand Up @@ -112,11 +112,11 @@ impl PooledScheduler {
}
}
impl InstalledScheduler for PooledScheduler {
fn scheduler_id(&self) -> SchedulerId {
fn id(&self) -> SchedulerId {
self.id
}

fn scheduler_pool(&self) -> InstalledSchedulerPoolArc {
fn pool(&self) -> InstalledSchedulerPoolArc {
self.pool.clone()
}

Expand Down Expand Up @@ -186,11 +186,11 @@ impl InstalledScheduler for PooledScheduler {
}
}

fn scheduling_context(&self) -> Option<&SchedulingContext> {
fn context(&self) -> Option<&SchedulingContext> {
self.context.as_ref()
}

fn replace_scheduling_context(&mut self, context: SchedulingContext) {
fn replace_context(&mut self, context: SchedulingContext) {
self.context = Some(context);
*self.result_with_timings.lock().expect("not poisoned") = None;
}
Expand Down Expand Up @@ -251,9 +251,9 @@ mod tests {
let context = &SchedulingContext::new(SchedulingMode::BlockVerification, bank);

let mut scheduler1 = pool.take_from_pool(context.clone());
let scheduler_id1 = scheduler1.scheduler_id();
let scheduler_id1 = scheduler1.id();
let mut scheduler2 = pool.take_from_pool(context.clone());
let scheduler_id2 = scheduler2.scheduler_id();
let scheduler_id2 = scheduler2.id();
assert_ne!(scheduler_id1, scheduler_id2);

assert_matches!(
Expand All @@ -268,9 +268,9 @@ mod tests {
pool.return_to_pool(scheduler2);

let scheduler3 = pool.take_from_pool(context.clone());
assert_eq!(scheduler_id2, scheduler3.scheduler_id());
assert_eq!(scheduler_id2, scheduler3.id());
let scheduler4 = pool.take_from_pool(context.clone());
assert_eq!(scheduler_id1, scheduler4.scheduler_id());
assert_eq!(scheduler_id1, scheduler4.id());
}

#[test]
Expand All @@ -284,12 +284,12 @@ mod tests {

let mut scheduler = pool.take_from_pool(context.clone());

assert!(scheduler.scheduling_context().is_some());
assert!(scheduler.context().is_some());
assert_matches!(
scheduler.wait_for_termination(&WaitReason::ReinitializedForRecentBlockhash),
None
);
assert!(scheduler.scheduling_context().is_none());
assert!(scheduler.context().is_none());
}

#[test]
Expand All @@ -308,19 +308,16 @@ mod tests {
&SchedulingContext::new(SchedulingMode::BlockVerification, new_bank.clone());

let mut scheduler = pool.take_from_pool(old_context.clone());
let scheduler_id = scheduler.scheduler_id();
let scheduler_id = scheduler.id();
assert_matches!(
scheduler.wait_for_termination(&WaitReason::TerminatedToFreeze),
None
);
pool.return_to_pool(scheduler);

let scheduler = pool.take_from_pool(new_context.clone());
assert_eq!(scheduler_id, scheduler.scheduler_id());
assert!(Arc::ptr_eq(
scheduler.scheduling_context().unwrap().bank(),
new_bank
));
assert_eq!(scheduler_id, scheduler.id());
assert!(Arc::ptr_eq(scheduler.context().unwrap().bank(), new_bank));
}

#[test]
Expand Down

0 comments on commit 21b7250

Please sign in to comment.