Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up tests by using redb::Durability::None #621

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ impl Index {

let tx = database.begin_write()?;

#[cfg(test)]
let tx = {
let mut tx = tx;
tx.set_durability(redb::Durability::None);
tx
};

tx.open_table(HEIGHT_TO_HASH)?;
tx.open_table(ORDINAL_TO_SATPOINT)?;
tx.open_table(OUTPOINT_TO_ORDINAL_RANGES)?;
Expand All @@ -142,7 +149,7 @@ impl Index {
}

pub(crate) fn print_info(&self) -> Result {
let wtx = self.database.begin_write()?;
let wtx = self.begin_write()?;

let blocks_indexed = wtx
.open_table(HEIGHT_TO_HASH)?
Expand Down Expand Up @@ -194,7 +201,7 @@ impl Index {
}

pub(crate) fn index(&self) -> Result {
let mut wtx = self.database.begin_write()?;
let mut wtx = self.begin_write()?;

let height = wtx
.open_table(HEIGHT_TO_HASH)?
Expand All @@ -215,7 +222,7 @@ impl Index {

if i > 0 && i % 1000 == 0 {
wtx.commit()?;
wtx = self.database.begin_write()?;
wtx = self.begin_write()?;
}

if done || INTERRUPTS.load(atomic::Ordering::Relaxed) > 0 {
Expand Down Expand Up @@ -368,6 +375,16 @@ impl Index {
Ok(rtx::Rtx(self.database.begin_read()?))
}

fn begin_write(&self) -> Result<redb::WriteTransaction> {
if cfg!(test) {
let mut tx = self.database.begin_write()?;
tx.set_durability(redb::Durability::None);
Ok(tx)
} else {
Ok(self.database.begin_write()?)
}
}

pub(crate) fn height(&self) -> Result<Height> {
Ok(Height(self.begin_read()?.height()?))
}
Expand Down