Change slot_meta_iterator() to return an iterator not a cursor (#4303)

automerge
This commit is contained in:
carllin
2019-05-15 18:28:23 -07:00
committed by Grimes
parent d8735df1de
commit abd7f6b090
2 changed files with 15 additions and 11 deletions

View File

@ -1,7 +1,6 @@
//! The `block_tree` module provides functions for parallel verification of the //! The `block_tree` module provides functions for parallel verification of the
//! Proof of History ledger as well as iterative read, append write, and random //! Proof of History ledger as well as iterative read, append write, and random
//! access read to a persistent file-based ledger. //! access read to a persistent file-based ledger.
use crate::entry::Entry; use crate::entry::Entry;
use crate::erasure::{self, Session}; use crate::erasure::{self, Session};
use crate::packet::{Blob, SharedBlob, BLOB_HEADER_SIZE}; use crate::packet::{Blob, SharedBlob, BLOB_HEADER_SIZE};
@ -47,7 +46,7 @@ macro_rules! db_imports {
pub use db::columns; pub use db::columns;
pub type Database = db::Database<$db>; pub type Database = db::Database<$db>;
pub type Cursor<C> = db::Cursor<$db, C>; pub type Cursor<C> = db::Cursor<$db, C>;
pub type LedgerColumn<C> = db::LedgerColumn<$db, C>; pub type LedgerColumn<C> = db::LedgerColumn<$db, C>;
pub type WriteBatch = db::WriteBatch<$db>; pub type WriteBatch = db::WriteBatch<$db>;
type BatchProcessor = db::BatchProcessor<$db>; type BatchProcessor = db::BatchProcessor<$db>;
@ -183,10 +182,15 @@ impl Blocktree {
self.orphans_cf.get(slot) self.orphans_cf.get(slot)
} }
pub fn slot_meta_iterator(&self, slot: u64) -> Result<Cursor<cf::SlotMeta>> { pub fn slot_meta_iterator(&self, slot: u64) -> Result<impl Iterator<Item = (u64, SlotMeta)>> {
let mut db_iterator = self.db.cursor::<cf::SlotMeta>()?; let meta_iter = self.db.iter::<cf::SlotMeta>(Some(slot))?;
db_iterator.seek(slot); Ok(meta_iter.map(|(slot, slot_meta_bytes)| {
Ok(db_iterator) (
slot,
deserialize(&slot_meta_bytes)
.unwrap_or_else(|_| panic!("Could not deserialize SlotMeta for slot {}", slot)),
)
}))
} }
pub fn slot_data_iterator( pub fn slot_data_iterator(

View File

@ -285,17 +285,17 @@ impl RepairService {
let last_confirmed_epoch = epoch_schedule.get_stakers_epoch(root); let last_confirmed_epoch = epoch_schedule.get_stakers_epoch(root);
let last_epoch_slot = epoch_schedule.get_last_slot_in_epoch(last_confirmed_epoch); let last_epoch_slot = epoch_schedule.get_last_slot_in_epoch(last_confirmed_epoch);
let mut meta_iter = blocktree let meta_iter = blocktree
.slot_meta_iterator(root + 1) .slot_meta_iterator(root + 1)
.expect("Couldn't get db iterator"); .expect("Couldn't get db iterator");
while meta_iter.valid() && meta_iter.key().unwrap() <= last_epoch_slot { for (current_slot, meta) in meta_iter {
let current_slot = meta_iter.key().unwrap(); if current_slot > last_epoch_slot {
let meta = meta_iter.value().unwrap(); break;
}
if meta.is_full() { if meta.is_full() {
slots_in_gossip.insert(current_slot); slots_in_gossip.insert(current_slot);
} }
meta_iter.next();
} }
} }