-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
*: support fail points #2354
Merged
Merged
*: support fail points #2354
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
fcd3767
add fail point
lishuai87 97f2ad0
add grpc fail point
lishuai87 f60ecb7
add tikv-fail
lishuai87 48adf0e
Cargo: update fail
overvenus 3315d2a
*: get rid of useless closures
overvenus a42b931
Cargo: update fail
overvenus 5435fec
Merge branch 'master' into ov/raft-fail-point
overvenus 9c807b4
Fix build
overvenus e371910
Cargo, Makefile: add a feature for disabling failpoint
overvenus 4ed0993
tests: remove fail point test
overvenus 7f6cd5d
tikv-fail: support inject and recover failures
overvenus 62a43ae
*: clean up
overvenus 55b31cb
Merge branch 'master' into ov/raft-fail-point
overvenus 9b4c3cd
Cargo: update fail
overvenus 3767a8d
Address comments
overvenus 62309b9
tests: add a fail point test
overvenus 794ec70
tikv-fail: fix copyright
overvenus 28c6778
Merge branch 'master' into ov/raft-fail-point
overvenus 728109c
Address comments
overvenus 4ca4c37
Merge branch 'master' into ov/raft-fail-point
overvenus 8677a4f
Address comments
overvenus c4cbf5d
Address comments
overvenus cb577ab
Cargo: update fail
overvenus fbc0614
Merge branch 'master' into ov/raft-fail-point
overvenus 633ffa8
Address comments and test list fail points
overvenus 8b54140
Address comments
overvenus ecf3fc7
Address comments
overvenus f8e32a3
Address comments
overvenus 106d58d
Merge branch 'master' into ov/raft-fail-point
overvenus be054bc
Merge branch 'master' into ov/raft-fail-point
overvenus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
// Copyright 2017 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#![feature(plugin)] | ||
#![cfg_attr(feature = "dev", plugin(clippy))] | ||
|
||
/// Inject failures to `TikV`. | ||
/// | ||
/// TODO: Integrate into tikv-ctl. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```sh | ||
/// ./tikv-fail -a 127.0.0.1:9090 inject\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we support a failure list? |
||
// tikv::raftstore::store::store::raft_between_save=panic | ||
/// ``` | ||
/// | ||
|
||
extern crate tikv; | ||
extern crate clap; | ||
extern crate grpcio as grpc; | ||
extern crate protobuf; | ||
extern crate kvproto; | ||
|
||
use std::fs; | ||
use std::io::{BufRead, BufReader}; | ||
use std::str; | ||
use std::time::Duration; | ||
use std::sync::Arc; | ||
|
||
use clap::{App, Arg, SubCommand}; | ||
use grpc::{CallOption, ChannelBuilder, EnvBuilder}; | ||
use kvproto::debugpb; | ||
use kvproto::debugpb_grpc::DebugClient; | ||
|
||
fn main() { | ||
let app = App::new("TiKV fail point") | ||
.author("PingCAP") | ||
.about("A tool for injecting failures to TiKV and recovery") | ||
.arg( | ||
Arg::with_name("addr") | ||
.short("a") | ||
.takes_value(true) | ||
.help("set tikv ip:port"), | ||
) | ||
.subcommand( | ||
SubCommand::with_name("inject") | ||
.about("Inject failures") | ||
.arg( | ||
Arg::with_name("args") | ||
.multiple(true) | ||
.takes_value(true) | ||
.help( | ||
"Inject fail point and actions pairs.\ | ||
E.g. tikv-fail inject fail::a=off fail::b=panic", | ||
), | ||
) | ||
.arg( | ||
Arg::with_name("file") | ||
.short("f") | ||
.takes_value(true) | ||
.help("Read a file of fail points and actions to inject"), | ||
), | ||
) | ||
.subcommand( | ||
SubCommand::with_name("recover") | ||
.about("Recover failures") | ||
.arg( | ||
Arg::with_name("args") | ||
.multiple(true) | ||
.takes_value(true) | ||
.help("Recover fail points. Eg. tikv-fail recover fail::a fail::b"), | ||
) | ||
.arg( | ||
Arg::with_name("file") | ||
.short("f") | ||
.takes_value(true) | ||
.help("Recover from a file of fail points"), | ||
), | ||
) | ||
.subcommand(SubCommand::with_name("list").about("List all fail points")); | ||
let matches = app.clone().get_matches(); | ||
let addr = matches.value_of("addr").unwrap(); | ||
let addr = addr.trim_left_matches("http://"); | ||
|
||
let env = Arc::new(EnvBuilder::new().name_prefix("tikv-fail").build()); | ||
let channel = ChannelBuilder::new(env).connect(addr); | ||
let client = DebugClient::new(channel); | ||
|
||
if let Some(matches) = matches.subcommand_matches("inject") { | ||
let mut list = matches.value_of("file").map_or_else(Vec::new, read_file); | ||
if let Some(ps) = matches.values_of("args") { | ||
for pair in ps { | ||
let mut parts = pair.split('='); | ||
list.push(( | ||
parts.next().unwrap().to_owned(), | ||
parts.next().unwrap_or("").to_owned(), | ||
)) | ||
} | ||
} | ||
|
||
for (name, actions) in list { | ||
if actions.is_empty() { | ||
println!("No action for fail point {}", name); | ||
continue; | ||
} | ||
let mut inject_req = debugpb::InjectFailPointRequest::new(); | ||
inject_req.set_name(name); | ||
inject_req.set_actions(actions); | ||
|
||
let option = CallOption::default().timeout(Duration::from_secs(10)); | ||
client.inject_fail_point_opt(inject_req, option).unwrap(); | ||
} | ||
} else if let Some(matches) = matches.subcommand_matches("recover") { | ||
let mut list = matches.value_of("file").map_or_else(Vec::new, read_file); | ||
if let Some(fps) = matches.values_of("args") { | ||
for fp in fps { | ||
list.push((fp.to_owned(), "".to_owned())) | ||
} | ||
} | ||
|
||
for (name, _) in list { | ||
let mut recover_req = debugpb::RecoverFailPointRequest::new(); | ||
recover_req.set_name(name); | ||
|
||
let option = CallOption::default().timeout(Duration::from_secs(10)); | ||
client.recover_fail_point_opt(recover_req, option).unwrap(); | ||
} | ||
} else if matches.is_present("list") { | ||
let list_req = debugpb::ListFailPointsRequest::new(); | ||
let option = CallOption::default().timeout(Duration::from_secs(10)); | ||
let resp = client.list_fail_points_opt(list_req, option).unwrap(); | ||
println!("{:?}", resp.get_entries()); | ||
} | ||
} | ||
|
||
fn read_file(path: &str) -> Vec<(String, String)> { | ||
let f = fs::File::open(path).unwrap(); | ||
let f = BufReader::new(f); | ||
|
||
let mut list = vec![]; | ||
for line in f.lines() { | ||
let line = line.unwrap(); | ||
let mut parts = line.split('='); | ||
list.push(( | ||
parts.next().unwrap().to_owned(), | ||
parts.next().unwrap_or("").to_owned(), | ||
)) | ||
} | ||
list | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use
crates.io
version?