solana_core/
drop_bank_service.rs

1use {
2    crossbeam_channel::Receiver,
3    solana_measure::measure::Measure,
4    solana_runtime::installed_scheduler_pool::BankWithScheduler,
5    std::thread::{self, Builder, JoinHandle},
6};
7
8pub struct DropBankService {
9    thread_hdl: JoinHandle<()>,
10}
11
12impl DropBankService {
13    pub fn new(bank_receiver: Receiver<Vec<BankWithScheduler>>) -> Self {
14        let thread_hdl = Builder::new()
15            .name("solDropBankSrvc".to_string())
16            .spawn(move || {
17                for banks in bank_receiver.iter() {
18                    let len = banks.len();
19                    let mut dropped_banks_time = Measure::start("drop_banks");
20                    // Drop BankWithScheduler with no alive lock to avoid deadlocks. That's because
21                    // BankWithScheduler::drop() could block on transaction execution if unified
22                    // scheduler is installed. As a historical context, it's dropped early inside
23                    // the replaying stage not here and that caused a deadlock for BankForks.
24                    drop(banks);
25                    dropped_banks_time.stop();
26                    if dropped_banks_time.as_ms() > 10 {
27                        datapoint_info!(
28                            "handle_new_root-dropped_banks",
29                            ("elapsed_ms", dropped_banks_time.as_ms(), i64),
30                            ("len", len, i64)
31                        );
32                    }
33                }
34            })
35            .unwrap();
36        Self { thread_hdl }
37    }
38
39    pub fn join(self) -> thread::Result<()> {
40        self.thread_hdl.join()
41    }
42}