From 11b84427dfdea4827cc1947a44720eade484cc95 Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Sat, 8 Apr 2023 20:02:53 +0800 Subject: [PATCH] feat: remove repair --- Cargo.lock | 1 - ckb-bin/Cargo.toml | 5 ++--- ckb-bin/src/lib.rs | 8 +------- ckb-bin/src/subcommand/db_repair.rs | 11 ----------- ckb-bin/src/subcommand/mod.rs | 2 -- db/src/db.rs | 19 +------------------ db/src/read_only_db.rs | 12 ++---------- util/app-config/src/args.rs | 6 ------ util/app-config/src/cli.rs | 7 ------- util/app-config/src/lib.rs | 9 +-------- 10 files changed, 7 insertions(+), 73 deletions(-) delete mode 100644 ckb-bin/src/subcommand/db_repair.rs diff --git a/Cargo.lock b/Cargo.lock index dcd4a36daa..74f4414bb8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -488,7 +488,6 @@ dependencies = [ "ckb-chain-iter", "ckb-chain-spec", "ckb-channel", - "ckb-db", "ckb-instrument", "ckb-jsonrpc-types", "ckb-launcher", diff --git a/ckb-bin/Cargo.toml b/ckb-bin/Cargo.toml index 72fe0accdc..01ddd7c1db 100644 --- a/ckb-bin/Cargo.toml +++ b/ckb-bin/Cargo.toml @@ -36,7 +36,6 @@ ckb-memory-tracker = { path = "../util/memory-tracker", version = "= 0.110.0-pre ckb-chain-iter = { path = "../util/chain-iter", version = "= 0.110.0-pre" } ckb-verification-traits = { path = "../verification/traits", version = "= 0.110.0-pre" } ckb-async-runtime = { path = "../util/runtime", version = "= 0.110.0-pre" } -ckb-db = { path = "../db", version = "= 0.110.0-pre" } ckb-launcher = { path = "../util/launcher", version = "= 0.110.0-pre" } base64 = "0.21.0" tempfile.workspace = true @@ -50,5 +49,5 @@ deadlock_detection = ["ckb-util/deadlock_detection"] profiling = ["ckb-memory-tracker/profiling"] with_sentry = ["sentry", "ckb-launcher/with_sentry", "ckb-network/with_sentry", "ckb-app-config/with_sentry", "ckb-logger-service/with_sentry"] with_dns_seeding = ["ckb-network/with_dns_seeding"] -portable = ["ckb-db/portable", "ckb-launcher/portable"] -march-native = ["ckb-db/march-native", "ckb-launcher/march-native"] +portable = ["ckb-launcher/portable"] +march-native = ["ckb-launcher/march-native"] diff --git a/ckb-bin/src/lib.rs b/ckb-bin/src/lib.rs index 1f1165143b..b047a14086 100644 --- a/ckb-bin/src/lib.rs +++ b/ckb-bin/src/lib.rs @@ -73,7 +73,6 @@ pub fn run_app(version: Version) -> Result<(), ExitCode> { cli::CMD_STATS => subcommand::stats(setup.stats(matches)?, handle), cli::CMD_RESET_DATA => subcommand::reset_data(setup.reset_data(matches)?), cli::CMD_MIGRATE => subcommand::migrate(setup.migrate(matches)?), - cli::CMD_DB_REPAIR => subcommand::db_repair(setup.db_repair(matches)?), _ => unreachable!(), }; @@ -86,11 +85,6 @@ type Silent = bool; fn is_silent_logging(cmd: &str) -> Silent { matches!( cmd, - cli::CMD_EXPORT - | cli::CMD_IMPORT - | cli::CMD_STATS - | cli::CMD_MIGRATE - | cli::CMD_DB_REPAIR - | cli::CMD_RESET_DATA + cli::CMD_EXPORT | cli::CMD_IMPORT | cli::CMD_STATS | cli::CMD_MIGRATE | cli::CMD_RESET_DATA ) } diff --git a/ckb-bin/src/subcommand/db_repair.rs b/ckb-bin/src/subcommand/db_repair.rs deleted file mode 100644 index 50183672a2..0000000000 --- a/ckb-bin/src/subcommand/db_repair.rs +++ /dev/null @@ -1,11 +0,0 @@ -use ckb_app_config::{ExitCode, RepairArgs}; -use ckb_db::RocksDB; - -pub fn db_repair(args: RepairArgs) -> Result<(), ExitCode> { - RocksDB::repair(&args.config.db.path).map_err(|err| { - eprintln!("repair error: {err:?}"); - ExitCode::Failure - })?; - - Ok(()) -} diff --git a/ckb-bin/src/subcommand/mod.rs b/ckb-bin/src/subcommand/mod.rs index d7874a1327..6940ac1704 100644 --- a/ckb-bin/src/subcommand/mod.rs +++ b/ckb-bin/src/subcommand/mod.rs @@ -1,4 +1,3 @@ -mod db_repair; mod export; mod import; mod init; @@ -11,7 +10,6 @@ mod reset_data; mod run; mod stats; -pub use self::db_repair::db_repair; pub use self::export::export; pub use self::import::import; pub use self::init::init; diff --git a/db/src/db.rs b/db/src/db.rs index faa8048baf..12acfdd617 100644 --- a/db/src/db.rs +++ b/db/src/db.rs @@ -81,17 +81,6 @@ impl RocksDB { }) } - /// Repairer does best effort recovery to recover as much data as possible - /// after a disaster without compromising consistency. - /// It does not guarantee bringing the database to a time consistent state. - /// Note: Currently there is a limitation that un-flushed column families will be lost after repair. - /// This would happen even if the DB is in healthy state. - pub fn repair>(path: P) -> Result<()> { - let repair_opts = Options::default(); - OptimisticTransactionDB::repair(repair_opts, path) - .map_err(|err| internal_error(format!("failed to repair database: {err}"))) - } - /// Open a database with the given configuration and columns count. pub fn open(config: &DBConfig, columns: u32) -> Self { Self::open_with_check(config, columns).unwrap_or_else(|err| panic!("{err}")) @@ -127,13 +116,7 @@ impl RocksDB { { Ok(None) } else if err_str.starts_with("Corruption:") { - info!( - "DB corrupted: {err_str}.\n\ - Try ckb db-repair command to repair DB.\n\ - Note: Currently there is a limitation that un-flushed column families will be lost after repair.\ - This would happen even if the DB is in healthy state.\n\ - See https://github.com/facebook/rocksdb/wiki/RocksDB-Repairer for detail", - ); + info!("DB corrupted: {err_str}."); Err(internal_error(err_str)) } else { Err(internal_error(format!( diff --git a/db/src/read_only_db.rs b/db/src/read_only_db.rs index ae1d21e119..0f8dfe0bc8 100644 --- a/db/src/read_only_db.rs +++ b/db/src/read_only_db.rs @@ -29,18 +29,10 @@ impl ReadOnlyDB { |err| { let err_str = err.as_ref(); // notice: err msg difference - if err_str.starts_with("IO error: No such file or directory") - { + if err_str.starts_with("IO error: No such file or directory") { Ok(None) } else if err_str.starts_with("Corruption:") { - info!( - "DB corrupted: {}.\n\ - Try ckb db-repair command to repair DB.\n\ - Note: Currently there is a limitation that un-flushed column families will be lost after repair.\ - This would happen even if the DB is in healthy state.\n\ - See https://github.com/facebook/rocksdb/wiki/RocksDB-Repairer for detail", - err_str - ); + info!("DB corrupted: {err_str}."); Err(internal_error("DB corrupted")) } else { Err(internal_error(format!( diff --git a/util/app-config/src/args.rs b/util/app-config/src/args.rs index d7dcf2acdb..15c3264034 100644 --- a/util/app-config/src/args.rs +++ b/util/app-config/src/args.rs @@ -186,12 +186,6 @@ pub struct MigrateArgs { pub force: bool, } -/// Parsed command line arguments for `ckb db-repair`. -pub struct RepairArgs { - /// Parsed `ckb.toml`. - pub config: Box, -} - impl CustomizeSpec { /// No specified parameters for chain spec. pub fn is_unset(&self) -> bool { diff --git a/util/app-config/src/cli.rs b/util/app-config/src/cli.rs index aaf75edd8f..a63a974b86 100644 --- a/util/app-config/src/cli.rs +++ b/util/app-config/src/cli.rs @@ -32,8 +32,6 @@ pub const CMD_GEN_SECRET: &str = "gen"; pub const CMD_FROM_SECRET: &str = "from-secret"; /// Subcommand `migrate`. pub const CMD_MIGRATE: &str = "migrate"; -/// Subcommand `db-repair`. -pub const CMD_DB_REPAIR: &str = "db-repair"; /// Command line argument `--config-dir`. pub const ARG_CONFIG_DIR: &str = "config-dir"; @@ -145,7 +143,6 @@ pub fn basic_app() -> Command { .subcommand(reset_data()) .subcommand(peer_id()) .subcommand(migrate()) - .subcommand(db_repair()) } /// Parse the command line arguments by supplying the version information. @@ -374,10 +371,6 @@ fn migrate() -> Command { ) } -fn db_repair() -> Command { - Command::new(CMD_DB_REPAIR).about("Try repair ckb database") -} - fn list_hashes() -> Command { Command::new(CMD_LIST_HASHES) .about("Lists well known hashes") diff --git a/util/app-config/src/lib.rs b/util/app-config/src/lib.rs index c6b0d22700..a8fbbab64d 100644 --- a/util/app-config/src/lib.rs +++ b/util/app-config/src/lib.rs @@ -15,7 +15,7 @@ pub use app_config::{ AppConfig, CKBAppConfig, ChainConfig, LogConfig, MetricsConfig, MinerAppConfig, }; pub use args::{ - ExportArgs, ImportArgs, InitArgs, MigrateArgs, MinerArgs, PeerIDArgs, RepairArgs, ReplayArgs, + ExportArgs, ImportArgs, InitArgs, MigrateArgs, MinerArgs, PeerIDArgs, ReplayArgs, ResetDataArgs, RunArgs, StatsArgs, }; pub use configs::*; @@ -116,13 +116,6 @@ impl Setup { }) } - /// `db-repair` subcommand - pub fn db_repair(self, _matches: &ArgMatches) -> Result { - let config = self.config.into_ckb()?; - - Ok(RepairArgs { config }) - } - /// Executes `ckb miner`. pub fn miner(self, matches: &ArgMatches) -> Result { let spec = self.chain_spec()?;