From 8e2da2b13d1bcd743a52f25f27e0c12c632325aa Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 31 Jan 2022 23:27:07 -0800 Subject: [PATCH 1/2] Print progress while indexing --- src/index.rs | 24 +++++++++++++++++++++++- src/main.rs | 3 ++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/index.rs b/src/index.rs index f62eeee241..57498ad7c8 100644 --- a/src/index.rs +++ b/src/index.rs @@ -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, @@ -179,7 +196,12 @@ impl Index { count += 1; } - log::info!("Inserted {} blocks…", count); + log::info!( + "Processed blockfile {} of {} containing {} blocks…", + i + 1, + blockfiles, + count + ); tx.commit()?; } diff --git a/src/main.rs b/src/main.rs index 974b1dc494..44d75a9106 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, From 9ed9e965d4de575d1be5dd3a14091425765c8d6c Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 31 Jan 2022 23:33:51 -0800 Subject: [PATCH 2/2] Improve printing --- src/index.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/index.rs b/src/index.rs index 57498ad7c8..bfc9909efc 100644 --- a/src/index.rs +++ b/src/index.rs @@ -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, }; @@ -196,12 +196,7 @@ impl Index { count += 1; } - log::info!( - "Processed blockfile {} of {} containing {} blocks…", - i + 1, - blockfiles, - count - ); + log::info!("{}/{}: Processed {} blocks…", i + 1, blockfiles, count); tx.commit()?; }