From 46e28a70353d611dacda79be5f8b5a160e83c42c Mon Sep 17 00:00:00 2001 From: Andronik Date: Wed, 24 Aug 2022 16:54:50 +0200 Subject: [PATCH] kvdb-rocksdb: do not attepmt to repair --- kvdb-rocksdb/src/lib.rs | 52 +++-------------------------------------- 1 file changed, 3 insertions(+), 49 deletions(-) diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index 16de2a192..beb137f56 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -12,14 +12,13 @@ mod stats; use std::{ cmp, collections::HashMap, - error, fs, io, + error, io, path::{Path, PathBuf}, - result, }; use parity_util_mem::MallocSizeOf; use rocksdb::{ - BlockBasedOptions, ColumnFamily, ColumnFamilyDescriptor, Error, Options, ReadOptions, WriteBatch, WriteOptions, DB, + BlockBasedOptions, ColumnFamily, ColumnFamilyDescriptor, Options, ReadOptions, WriteBatch, WriteOptions, DB, }; use kvdb::{DBKeyValue, DBOp, DBTransaction, DBValue, KeyValueDB}; @@ -319,24 +318,6 @@ pub struct Database { stats: stats::RunningDbStats, } -#[inline] -fn check_for_corruption>(path: P, res: result::Result) -> io::Result { - if let Err(ref s) = res { - if is_corrupted(s) { - warn!("DB corrupted: {}. Repair will be triggered on next restart", s); - let _ = fs::File::create(path.as_ref().join(Database::CORRUPTION_FILE_NAME)); - } - } - - res.map_err(other_io_err) -} - -fn is_corrupted(err: &Error) -> bool { - err.as_ref().starts_with("Corruption:") || - err.as_ref() - .starts_with("Invalid argument: You have to open all column families") -} - /// Generate the options for RocksDB, based on the given `DatabaseConfig`. fn generate_options(config: &DatabaseConfig) -> Options { let mut opts = Options::default(); @@ -395,8 +376,6 @@ fn generate_block_based_options(config: &DatabaseConfig) -> io::Result = (0..config.columns).map(|c| format!("col{}", c)).collect(); let write_opts = WriteOptions::default(); let read_opts = generate_read_options(); @@ -471,18 +442,6 @@ impl Database { Ok(match db { Ok(db) => db, - Err(ref s) if is_corrupted(s) => { - warn!("DB corrupted: {}, attempting repair", s); - DB::repair(&opts, path.as_ref()).map_err(other_io_err)?; - - let cf_descriptors: Vec<_> = (0..config.columns) - .map(|i| { - ColumnFamilyDescriptor::new(column_names[i as usize], config.column_config(&block_opts, i)) - }) - .collect(); - - DB::open_cf_descriptors(&opts, path, cf_descriptors).map_err(other_io_err)? - }, Err(s) => return Err(other_io_err(s)), }) } @@ -499,11 +458,6 @@ impl Database { Ok(match db { Ok(db) => db, - Err(ref s) if is_corrupted(s) => { - warn!("DB corrupted: {}, attempting repair", s); - DB::repair(&opts, path.as_ref()).map_err(other_io_err)?; - DB::open_cf_as_secondary(&opts, path, secondary_path, column_names).map_err(other_io_err)? - }, Err(s) => return Err(other_io_err(s)), }) } @@ -555,7 +509,7 @@ impl Database { } self.stats.tally_bytes_written(stats_total_bytes as u64); - check_for_corruption(&self.path, cfs.db.write_opt(batch, &self.write_opts)) + cfs.db.write_opt(batch, &self.write_opts).map_err(other_io_err) } /// Get value by key.