Skip to content

Commit

Permalink
Log progress while indexing (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Feb 1, 2022
1 parent 31fdd5e commit 810fe84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 19 additions & 2 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Index {
};

let index = Self {
database: unsafe { Database::open("index.redb", 4096 * 1024 * 1024 * 10)? },
database: unsafe { Database::open("index.redb", 50 << 30)? },
blocksdir,
};

Expand Down Expand Up @@ -138,6 +138,23 @@ impl Index {
}

fn index_blockfile(&self) -> Result {
let mut blockfiles = 0;
loop {
match File::open(self.blocksdir.join(format!("blk{:05}.dat", blockfiles))) {
Ok(_) => {}
Err(err) => {
if err.kind() == io::ErrorKind::NotFound {
break;
} else {
return Err(err.into());
}
}
}
blockfiles += 1;
}

log::info!("Indexing {} blockfiles…", blockfiles);

for i in 0.. {
let blocks = match fs::read(self.blocksdir.join(format!("blk{:05}.dat", i))) {
Ok(blocks) => blocks,
Expand Down Expand Up @@ -179,7 +196,7 @@ impl Index {
count += 1;
}

log::info!("Inserted {} blocks…", count);
log::info!("{}/{}: Processed {} blocks…", i + 1, blockfiles, count);

tx.commit()?;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use {
cmp::Ordering,
collections::VecDeque,
fmt::{self, Display, Formatter},
fs, io,
fs::{self, File},
io,
ops::{Add, AddAssign, Deref, Range, Sub},
path::{Path, PathBuf},
process,
Expand Down

0 comments on commit 810fe84

Please sign in to comment.