Skip to content

Commit

Permalink
Add return to version
Browse files Browse the repository at this point in the history
ref tikv#11555
Signed-off-by: longfangsong <[email protected]>
  • Loading branch information
longfangsong committed Jan 7, 2022
1 parent 1559189 commit 7fe7b9f
Show file tree
Hide file tree
Showing 9 changed files with 421 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ procinfo = { git = "https://github.com/tikv/procinfo-rs", rev = "5125fc1a69496b7
# When you modify TiKV cooperatively with kvproto, this will be useful to submit the PR to TiKV and the PR to
# kvproto at the same time.
# After the PR to kvproto is merged, remember to comment this out and run `cargo update -p kvproto`.
# [patch.'https://github.com/pingcap/kvproto']
# kvproto = {git = "https://github.com/your_github_id/kvproto", branch="your_branch"}
[patch.'https://github.com/pingcap/kvproto']
kvproto = {git = "https://github.com/longfangsong/kvproto", rev = "b7f0ce4e3945d2f5c7081372dd7d23487c1a659b"}

[workspace]
# See https://github.com/rust-lang/rfcs/blob/master/text/2957-cargo-features2.md
Expand Down
4 changes: 4 additions & 0 deletions cmd/tikv-ctl/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@ pub enum Cmd {
/// PD endpoints
pd: String,
},
ResetToVersion {
#[structopt(short="v")]
version: u64
},
#[structopt(external_subcommand)]
External(Vec<String>),
}
Expand Down
13 changes: 13 additions & 0 deletions cmd/tikv-ctl/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,8 @@ pub trait DebugExecutor {
fn dump_store_info(&self);

fn dump_cluster_info(&self);

fn reset_to_version(&self, version: u64);
}

impl DebugExecutor for DebugClient {
Expand Down Expand Up @@ -839,6 +841,13 @@ impl DebugExecutor for DebugClient {
.unwrap_or_else(|e| perror_and_exit("DebugClient::get_cluster_info", e));
println!("{}", resp.get_cluster_id())
}

fn reset_to_version(&self, version: u64) {
let mut req = ResetToVersionRequest::default();
req.set_ts(version);
self.reset_to_version(&ResetToVersionRequest::default())
.unwrap_or_else(|e| perror_and_exit("DebugClient::reset_to_version", e));
}
}

impl<ER: RaftEngine> DebugExecutor for Debugger<ER> {
Expand Down Expand Up @@ -1069,6 +1078,10 @@ impl<ER: RaftEngine> DebugExecutor for Debugger<ER> {
println!("cluster id: {}", ident.get_cluster_id());
}
}

fn reset_to_version(&self, version: u64) {
Debugger::reset_to_version(self, version);
}
}

fn handle_engine_error(err: EngineError) -> ! {
Expand Down
5 changes: 3 additions & 2 deletions cmd/tikv-ctl/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Copyright 2016 TiKV Project Authors. Licensed under Apache-2.0.

#![feature(once_cell)]

#[macro_use]
Expand Down Expand Up @@ -472,6 +470,9 @@ fn main() {
Cmd::Cluster {} => {
debug_executor.dump_cluster_info();
}
Cmd::ResetToVersion { version } => {
debug_executor.reset_to_version(version);
}
_ => {
unreachable!()
}
Expand Down
8 changes: 8 additions & 0 deletions src/server/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use tikv_util::worker::Worker;
use txn_types::Key;

use crate::config::ConfigController;
use crate::server::reset_to_version::ResetToVersionManager;
use crate::storage::mvcc::{Lock, LockType, TimeStamp, Write, WriteRef, WriteType};

pub use crate::storage::mvcc::MvccInfoIterator;
Expand Down Expand Up @@ -117,6 +118,7 @@ impl From<BottommostLevelCompaction> for debugpb::BottommostLevelCompaction {
#[derive(Clone)]
pub struct Debugger<ER: RaftEngine> {
engines: Engines<RocksEngine, ER>,
reset_to_version_manager: ResetToVersionManager,
cfg_controller: ConfigController,
}

Expand All @@ -125,8 +127,10 @@ impl<ER: RaftEngine> Debugger<ER> {
engines: Engines<RocksEngine, ER>,
cfg_controller: ConfigController,
) -> Debugger<ER> {
let reset_to_version_manager = ResetToVersionManager::new(engines.kv.clone());
Debugger {
engines,
reset_to_version_manager,
cfg_controller,
}
}
Expand Down Expand Up @@ -882,6 +886,10 @@ impl<ER: RaftEngine> Debugger<ER> {
props.append(&mut props1);
Ok(props)
}

pub fn reset_to_version(&self, version: u64) {
self.reset_to_version_manager.start(version.into());
}
}

fn dump_default_cf_properties(
Expand Down
1 change: 1 addition & 0 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod node;
mod proxy;
pub mod raftkv;
pub mod resolve;
mod reset_to_version;
pub mod server;
pub mod service;
pub mod snap;
Expand Down
Loading

0 comments on commit 7fe7b9f

Please sign in to comment.