-
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
tikv-ctl: set a region to tombstone. #2394
Conversation
src/raftstore/store/debug.rs
Outdated
epoch: RegionEpoch, | ||
peers: RepeatedField<Peer>, | ||
) -> Result<()> { | ||
let db = &self.engines.kv_engine; |
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.
we must guarantee that the peers can't contain the local peer now.
src/raftstore/store/debug.rs
Outdated
@@ -219,6 +220,31 @@ impl Debugger { | |||
compact_range(db, handle, start, end, false); | |||
Ok(()) | |||
} | |||
|
|||
/// Set a region to tombstone by manual. | |||
pub fn set_region_tombstone( |
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 using a meta::Region directly as the argument.
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.
How about the region info in PD is updated? For example, if the region split it will have a new [start_key, end_key).
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.
It's also weird the range doesn't match the epoch.
@BusyJay PTAL, thanks. |
src/bin/tikv-ctl.rs
Outdated
{ | ||
Some(mut meta_region) => { | ||
let epoch = meta_region.take_region_epoch(); | ||
let peers = meta_region.take_peers(); |
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.
Should check if peers contains target peer.
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.
This logic is in Debugger::set_region_tombstone
, because here we can't get self store_id
.
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.
we can get store id with store_ident
key
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.
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.
Yes, we do this in Debugger::set_region_tombstone
.
src/raftstore/store/debug.rs
Outdated
Some(mut region_state) => { | ||
let conf_ver = region.get_region_epoch().get_conf_ver(); | ||
if conf_ver == region_state.get_region().get_region_epoch().get_conf_ver() { | ||
return Err(box_err!("The conf_ver hasn't changed.")); |
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.
can we meet this case?
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.
remove-peer
in pd-ctl is asynchonrous so that we may run tikv-ctl tombstone
command before the config really change. So I think add this check is better.
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.
If this is happening then it can't pass the check at L231.
src/bin/tikv-ctl.rs
Outdated
@@ -323,6 +324,29 @@ trait DebugExecutor { | |||
self.do_compact(db, cf, from, to); | |||
} | |||
|
|||
fn set_region_tombstone(&self, region: u64, endpoints: Vec<String>) { |
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.
region_id
is better.
src/bin/tikv-ctl.rs
Outdated
@@ -323,6 +324,29 @@ trait DebugExecutor { | |||
self.do_compact(db, cf, from, to); | |||
} | |||
|
|||
fn set_region_tombstone(&self, region: u64, endpoints: Vec<String>) { | |||
let debugger = self.get_local_debugger().unwrap_or_else(|| { |
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 add set_region_tombstone
to the trait?
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.
Fixed.
src/bin/tikv-ctl.rs
Outdated
.use_delimiter(true) | ||
.require_delimiter(true) | ||
.value_delimiter(",") | ||
.help("the pd url"), |
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.
I don't think it's a url.
src/raftstore/store/debug.rs
Outdated
.iter() | ||
.any(|peer| peer.get_store_id() == store_id) | ||
{ | ||
return Err(box_err!("The peer is still in new peers list")); |
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.
What if there is a new replica (same store id but different region id) on this store?
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.
We compare this peer's store_id with peers having the specified region. So I think if remove-peer
really finished, we can got false
here, which is expected.
src/raftstore/store/debug.rs
Outdated
Some(mut region_state) => { | ||
let conf_ver = region.get_region_epoch().get_conf_ver(); | ||
if conf_ver == region_state.get_region().get_region_epoch().get_conf_ver() { | ||
return Err(box_err!("The conf_ver hasn't changed.")); |
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.
If this is happening then it can't pass the check at L231.
src/raftstore/store/debug.rs
Outdated
if conf_ver == region_state.get_region().get_region_epoch().get_conf_ver() { | ||
return Err(box_err!("The conf_ver hasn't changed.")); | ||
} | ||
region_state.set_state(PeerState::Tombstone); |
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.
Can you reuse write_peer_state
instead?
@BusyJay , PTAL again, thanks. |
@BusyJay PTAL again thanks. |
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.
rest LGTM
src/raftstore/store/debug.rs
Outdated
|
||
if new_conf_ver > old_conf_ver && scheduled { | ||
let wb = WriteBatch::new(); | ||
box_try!(write_peer_state(db, &wb, ®ion, PeerState::Tombstone)); |
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.
Use old_region
just as GC message does.
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.
LGTM
/run-all-test |
No description provided.