Skip to content
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

Merged
merged 11 commits into from
Oct 22, 2017
Merged

tikv-ctl: set a region to tombstone. #2394

merged 11 commits into from
Oct 22, 2017

Conversation

hicqu
Copy link
Contributor

@hicqu hicqu commented Oct 18, 2017

No description provided.

epoch: RegionEpoch,
peers: RepeatedField<Peer>,
) -> Result<()> {
let db = &self.engines.kv_engine;
Copy link
Contributor

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.

@@ -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(
Copy link
Contributor

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.

Copy link
Contributor Author

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).

Copy link
Member

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.

@hicqu hicqu changed the title tikv-ctl: set a region to tombstone. jobstikv-ctl: set a region to tombstone. Oct 19, 2017
@hicqu
Copy link
Contributor Author

hicqu commented Oct 19, 2017

@BusyJay PTAL, thanks.

{
Some(mut meta_region) => {
let epoch = meta_region.take_region_epoch();
let peers = meta_region.take_peers();
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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.

@hicqu hicqu changed the title jobstikv-ctl: set a region to tombstone. tikv-ctl: set a region to tombstone. Oct 19, 2017
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."));
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@@ -323,6 +324,29 @@ trait DebugExecutor {
self.do_compact(db, cf, from, to);
}

fn set_region_tombstone(&self, region: u64, endpoints: Vec<String>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

region_id is better.

@@ -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(|| {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

.use_delimiter(true)
.require_delimiter(true)
.value_delimiter(",")
.help("the pd url"),
Copy link
Member

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.

.iter()
.any(|peer| peer.get_store_id() == store_id)
{
return Err(box_err!("The peer is still in new peers list"));
Copy link
Member

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?

Copy link
Contributor Author

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.

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."));
Copy link
Member

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.

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);
Copy link
Member

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?

@hicqu
Copy link
Contributor Author

hicqu commented Oct 20, 2017

@BusyJay , PTAL again, thanks.

@hicqu
Copy link
Contributor Author

hicqu commented Oct 20, 2017

@BusyJay PTAL again thanks.

Copy link
Member

@BusyJay BusyJay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest LGTM


if new_conf_ver > old_conf_ver && scheduled {
let wb = WriteBatch::new();
box_try!(write_peer_state(db, &wb, &region, PeerState::Tombstone));
Copy link
Member

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.

Copy link
Contributor

@siddontang siddontang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hicqu
Copy link
Contributor Author

hicqu commented Oct 22, 2017

/run-all-test

@hicqu hicqu merged commit 7763bca into master Oct 22, 2017
@hicqu hicqu deleted the qupeng/debug-tombstone branch October 22, 2017 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants