Skip to content

Commit

Permalink
chore: Trace errors instead of dropping them (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Jan 9, 2023
1 parent 33727e7 commit b3a8d33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/rolldb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl RollDB {
let db = DB::open_cf(&opts, path, [blocks::CF_NAME, CHAIN_CF, wal::CF_NAME])
.map_err(|_| Error::IO)?;

let wal_seq = wal::find_lastest_seq(&db)?.into();
let wal_seq = wal::find_latest_seq(&db)?.into();

Ok(Self { db, wal_seq })
}
Expand Down
14 changes: 10 additions & 4 deletions src/rolldb/wal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ impl<'a> Iterator for CrawlIterator<'a> {

fn next(&mut self) -> Option<Result<Value, super::Error>> {
match self.0.next() {
Some(Ok((key, value))) => Some(Value::try_from(value)),
Some(Err(err)) => Some(Err(super::Error::IO)),
Some(Ok((_, value))) => Some(Value::try_from(value)),
Some(Err(err)) => {
tracing::error!(?err);
Some(Err(super::Error::IO))
}
None => None,
}
}
Expand All @@ -126,13 +129,16 @@ pub fn crawl_backwards(db: &DB) -> CrawlIterator {
CrawlIterator(inner)
}

pub fn find_lastest_seq(db: &DB) -> Result<Key, super::Error> {
pub fn find_latest_seq(db: &DB) -> Result<Key, super::Error> {
let cf = wal_cf(db);
let mut iter = db.iterator_cf(cf, IteratorMode::End);

match iter.next() {
Some(Ok((key, _))) => Ok(Key::try_from(key)?),
Some(Err(err)) => Err(super::Error::IO),
Some(Err(err)) => {
tracing::error!(?err);
Err(super::Error::IO)
}
None => Ok(Key(0)),
}
}
Expand Down

0 comments on commit b3a8d33

Please sign in to comment.