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

Check for and report db corruption before attempting repair #2304

Merged
merged 1 commit into from
Jul 27, 2023
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
16 changes: 15 additions & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use {
TableDefinition, WriteTransaction,
},
std::collections::HashMap,
std::io::{BufWriter, Write},
std::io::{BufWriter, Read, Write},
std::sync::atomic::{self, AtomicBool},
};

Expand Down Expand Up @@ -169,6 +169,20 @@ 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 database = match Database::builder()
Expand Down