open column families after reparing db corruption (#3017)

This commit is contained in:
Robert Habermeier 2016-10-31 18:21:44 +01:00 committed by Arkadiy Paronyan
parent 8599a11a0b
commit 5d41d38dff

View File

@ -312,6 +312,8 @@ impl Database {
opts.set_target_file_size_multiplier(config.compaction.file_size_multiplier); opts.set_target_file_size_multiplier(config.compaction.file_size_multiplier);
let mut cf_options = Vec::with_capacity(config.columns.unwrap_or(0) as usize); let mut cf_options = Vec::with_capacity(config.columns.unwrap_or(0) as usize);
let cfnames: Vec<_> = (0..config.columns.unwrap_or(0)).map(|c| format!("col{}", c)).collect();
let cfnames: Vec<&str> = cfnames.iter().map(|n| n as &str).collect();
for col in 0 .. config.columns.unwrap_or(0) { for col in 0 .. config.columns.unwrap_or(0) {
let mut opts = Options::new(); let mut opts = Options::new();
@ -342,8 +344,6 @@ impl Database {
let mut cfs: Vec<Column> = Vec::new(); let mut cfs: Vec<Column> = Vec::new();
let db = match config.columns { let db = match config.columns {
Some(columns) => { Some(columns) => {
let cfnames: Vec<_> = (0..columns).map(|c| format!("col{}", c)).collect();
let cfnames: Vec<&str> = cfnames.iter().map(|n| n as &str).collect();
match DB::open_cf(&opts, path, &cfnames, &cf_options) { match DB::open_cf(&opts, path, &cfnames, &cf_options) {
Ok(db) => { Ok(db) => {
cfs = cfnames.iter().map(|n| db.cf_handle(n) cfs = cfnames.iter().map(|n| db.cf_handle(n)
@ -365,13 +365,18 @@ impl Database {
}, },
None => DB::open(&opts, path) None => DB::open(&opts, path)
}; };
let db = match db { let db = match db {
Ok(db) => db, Ok(db) => db,
Err(ref s) if s.starts_with("Corruption:") => { Err(ref s) if s.starts_with("Corruption:") => {
info!("{}", s); info!("{}", s);
info!("Attempting DB repair for {}", path); info!("Attempting DB repair for {}", path);
try!(DB::repair(&opts, path)); try!(DB::repair(&opts, path));
try!(DB::open(&opts, path))
match cfnames.is_empty() {
true => try!(DB::open(&opts, path)),
false => try!(DB::open_cf(&opts, path, &cfnames, &cf_options))
}
}, },
Err(s) => { return Err(s); } Err(s) => { return Err(s); }
}; };