Skip to content

Commit

Permalink
Update redb recovery detection to use public API
Browse files Browse the repository at this point in the history
  • Loading branch information
cberner committed Oct 25, 2023
1 parent ea1c7c8 commit 3a31e34
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 35 deletions.
20 changes: 1 addition & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mime_guess = "2.0.4"
miniscript = "10.0.0"
mp4 = "0.14.0"
ord-bitcoincore-rpc = "0.17.1"
redb = "1.0.5"
redb = { git = "/~https://github.com/cberner/redb", branch = "repair_callback" }
regex = "1.6.0"
rss = "2.0.1"
rust-embed = "8.0.0"
Expand Down
26 changes: 11 additions & 15 deletions src/index.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::cell::Cell;
use {
self::{
entry::{
Expand All @@ -21,7 +22,7 @@ use {
TableDefinition, WriteTransaction,
},
std::collections::HashMap,
std::io::{BufWriter, Read, Write},
std::io::{BufWriter, Write},
};

pub(crate) use self::entry::RuneEntry;
Expand Down Expand Up @@ -188,20 +189,6 @@ impl Index {
}
};

if let Ok(mut file) = fs::OpenOptions::new().read(true).open(&path) {
// use cberner's quick hack to check the redb recovery bit
// /~https://github.com/cberner/redb/issues/639#issuecomment-1628037591
const MAGICNUMBER: [u8; 9] = [b'r', b'e', b'd', b'b', 0x1A, 0x0A, 0xA9, 0x0D, 0x0A];
const RECOVERY_REQUIRED: u8 = 2;

let mut buffer = [0; MAGICNUMBER.len() + 1];
file.read_exact(&mut buffer).unwrap();

if buffer[MAGICNUMBER.len()] & RECOVERY_REQUIRED != 0 {
println!("Index file {:?} needs recovery. This can take a long time, especially for the --index-sats index.", path);
}
}

log::info!("Setting DB cache size to {} bytes", db_cache_size);

let durability = if cfg!(test) {
Expand All @@ -213,8 +200,17 @@ impl Index {
let index_runes;
let index_sats;

let message_displayed = Cell::new(false);
let path2 = path.clone();

let database = match Database::builder()
.set_cache_size(db_cache_size)
.set_repair_callback(move |_| {
if !message_displayed.get() {
message_displayed.set(true);
println!("Index file {:?} needs recovery. This can take a long time, especially for the --index-sats index.", path2);
}
})
.open(&path)
{
Ok(database) => {
Expand Down

0 comments on commit 3a31e34

Please sign in to comment.