debugger: fix compacting raftdb with tikv-ctl
close tikv/tikv#13515
@@ -120,6 +120,10 @@ impl From<BottommostLevelCompaction> for debugpb::BottommostLevelCompaction {
}
}
+trait InnerRocksEngineExtractor {
+ fn get_db_from_type(&self, db: DbType) -> Result<&RocksEngine>;
+}
+
#[derive(Clone)]
pub struct Debugger<ER: RaftEngine> {
engines: Engines<RocksEngine, ER>,
@@ -127,6 +131,26 @@ pub struct Debugger<ER: RaftEngine> {
cfg_controller: ConfigController,
}
+impl<ER: RaftEngine> InnerRocksEngineExtractor for Debugger<ER> {
+ default fn get_db_from_type(&self, db: DbType) -> Result<&RocksEngine> {
+ match db {
+ DbType::Kv => Ok(&self.engines.kv),
+ DbType::Raft => Err(box_err!("Get raft db is not allowed")),
+ _ => Err(box_err!("invalid DB type")),
+ }
+ }
+}
+
+impl InnerRocksEngineExtractor for Debugger<RocksEngine> {
+ fn get_db_from_type(&self, db: DbType) -> Result<&RocksEngine> {
+ match db {
+ DbType::Kv => Ok(&self.engines.kv),
+ DbType::Raft => Ok(&self.engines.raft),
+ _ => Err(box_err!("invalid DB type")),
+ }
+ }
+}
+
impl<ER: RaftEngine> Debugger<ER> {
pub fn new(
engines: Engines<RocksEngine, ER>,
@@ -163,14 +187,6 @@ impl<ER: RaftEngine> Debugger<ER> {
Ok(regions)
}
- fn get_db_from_type(&self, db: DbType) -> Result<&RocksEngine> {
- match db {
- DbType::Kv => Ok(&self.engines.kv),
- DbType::Raft => Err(box_err!("Get raft db is not allowed")),
- _ => Err(box_err!("invalid DB type")),
- }
- }
-
pub fn get(&self, db: DbType, cf: &str, key: &[u8]) -> Result<Vec<u8>> {
validate_db_and_cf(db, cf)?;
let db = self.get_db_from_type(db)?;
@@ -2272,4 +2288,14 @@ mod tests {
.get_api_version()
)
}
+
+ #[test]
+ fn test_compact() {
+ let debugger = new_debugger();
+ let compact = |db, cf| debugger.compact(db, cf, &[0], &[0xFF], 1, Some("skip").into());
+ compact(DbType::Kv, CF_DEFAULT).unwrap();
+ compact(DbType::Kv, CF_LOCK).unwrap();
+ compact(DbType::Kv, CF_WRITE).unwrap();
+ compact(DbType::Raft, CF_DEFAULT).unwrap();
+ }
}
