From cccade42b3ea73dc8be39c659d1b5e8f950b341b Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang <93241502+yhchiang-sol@users.noreply.github.com> Date: Mon, 19 Sep 2022 21:52:13 -0700 Subject: [PATCH] Optimize get_slots_since() using the batched version of multi_get() (#27686) #### Problem The current implementation of get_slots_since() invokes multiple rocksdb::get(). As a result, each get() operation may end up requiring one disk read. This leads to poor performance of get_slots_since described in #24878. #### Summary of Changes This PR makes get_slots_since() use the batched version of multi_get() instead, which allows multiple get operations to be processed in batch so that they can be answered with fewer disk reads. --- ledger/src/blockstore.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 78b87ee257..16cdd9224c 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -2972,12 +2972,10 @@ impl Blockstore { // Returns slots connecting to any element of the list `slots`. pub fn get_slots_since(&self, slots: &[u64]) -> Result>> { - // Return error if there was a database error during lookup of any of the - // slot indexes let slot_metas: Result>> = - slots.iter().map(|slot| self.meta(*slot)).collect(); - + self.meta_cf.multi_get(slots.to_vec()).into_iter().collect(); let slot_metas = slot_metas?; + let result: HashMap> = slots .iter() .zip(slot_metas)