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

support split v2 #1747

Merged
merged 23 commits into from
Apr 24, 2017
Merged

support split v2 #1747

merged 23 commits into from
Apr 24, 2017

Conversation

zhangjinpeng87
Copy link
Member

for peer in right.get_peers() {
right: metapb::Region,
left_derive: bool) {
let new_region = if left_derive {
Copy link
Contributor

Choose a reason for hiding this comment

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

let (new_region, origin_region) = if left_derive {
    (right.clone(), left.clone())
} else {
    (left.clone(), right.clone())
}

@siddontang
Copy link
Contributor

if let Some(left) = self.region_peers.get(&region_id) {
campaigned = new_peer.maybe_campaign(left, &mut self.pending_raft_groups);
if let Some(origin_peer) = self.region_peers.get(&region_id) {
campaigned =
Copy link
Member Author

Choose a reason for hiding this comment

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

@BusyJay Can we remove this mechanism after we implement split v2?

Copy link
Contributor

@siddontang siddontang Apr 10, 2017

Choose a reason for hiding this comment

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

The left region may still need to campaign fastly.

@zhangjinpeng87
Copy link
Member Author

@siddontang Yes, so we modify Excluded(enc_end_key(parent_region)) to Included(enc_start_key(parent_region)) to find the two new regions and add them to new_regions.

// received by the TiKV driver is newer than the meta cached in the driver, the meta is
// updated.
if let Some((_, &next_region_id)) = self.region_ranges
.range((Excluded(enc_end_key(peer.region())), Unbounded::<Key>))
.range((Included(enc_start_key(peer.region())), Unbounded::<Key>))
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have any test to cover the tow cases for 1 -> 1 + 2 and 1 -> 2 + 1?

@siddontang
Copy link
Contributor

any update @zhangjinpeng1987

@@ -1337,13 +1337,17 @@ impl Peer {

pub fn check_epoch(region: &metapb::Region, req: &RaftCmdRequest) -> Result<()> {
let (mut check_ver, mut check_conf_ver) = (false, false);
let mut left_derive = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this can only check Admin Split command, for other commands, we also can meet stale problems.

Copy link
Member Author

Choose a reason for hiding this comment

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

Please refresh change code.

@@ -130,6 +130,9 @@ pub struct Config {
pub raft_store_max_leader_lease: TimeDuration,

pub use_sst_file_snapshot: bool,

// Left region derive origin region id when split.
pub left_derive_when_split: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

is it better to name right_derive here because the request uses right_derive.

@@ -147,19 +147,22 @@ pub struct Runner<C> {
ch: RetryableSendCh<Msg, C>,
region_max_size: u64,
split_size: u64,
left_derive: bool,
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 necessary here.

@@ -133,6 +133,7 @@ mod test {
req.set_cmd_type(AdminCmdType::Split);
let mut split_req = SplitRequest::new();
split_req.set_split_key(key.to_vec());
split_req.set_right_derive(true);
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary.

@zhangjinpeng87
Copy link
Member Author

PTAL

@BusyJay
Copy link
Member

BusyJay commented Apr 17, 2017

Please fix CI.

// received by the TiKV driver is newer than the meta cached in the driver, the meta is
// updated.
if let Some((_, &next_region_id)) = self.region_ranges
let new_region_id = if self.cfg.right_derive_when_split {
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 extract the logic and check individually? I am concerned the correctness here.

Copy link
Member Author

Choose a reason for hiding this comment

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

test_split_stale_epoch do that thing exactly.

}
return Err(Error::StaleEpoch(msg, new_regions));
}
res
}

pub fn find_sibling_region(&self, region: &metapb::Region) -> Option<u64> {
if self.cfg.right_derive_when_split {
Copy link
Contributor

Choose a reason for hiding this comment

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

/cc @disksing

Please review the logic here.

Copy link
Contributor

Choose a reason for hiding this comment

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

let start = if self.cfg.right_derive_when_split {
    Included(enc_start_key(region)
} else { 
    Excluded(enc_end_key(region)
};
self.region_ranges.range(start, Unbounded::<Key>).next().map(|(_, &region_id)| region_id)

Copy link
Contributor

Choose a reason for hiding this comment

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

any update?

@siddontang
Copy link
Contributor

Rest LGTM

PTAL @BusyJay @disksing

@zhangjinpeng87
Copy link
Member Author

@disksing PTAL

@disksing
Copy link
Contributor

LGTM.

// To prevent from big region, the right region need run split
// check again after split.
if right_derive {
if let Some(peer) = self.region_peers.get_mut(&region_id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

seem must exist here?

@siddontang
Copy link
Contributor

Rest LGTM
PTAL @hhkbp2

if right_derive {
self.region_peers.get_mut(&region_id).unwrap().size_diff_hint = self.cfg
.region_check_size_diff;

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove empty line.

} else {
Excluded(enc_end_key(region))
};
self.region_ranges.range((start, Unbounded::<Key>)).next().map(|(_, &region_id)| region_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be range(Unbound::<key>, start).rev() for right_derive_when_split == true?

Copy link
Member Author

Choose a reason for hiding this comment

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

NO

@@ -130,6 +130,9 @@ pub struct Config {
pub raft_store_max_leader_lease: TimeDuration,

pub use_sst_file_snapshot: bool,

// Right region derive origin region id when split.
pub right_derive_when_split: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

s/right_derive_when_split/derive_right_part_when_split/

Copy link
Member Author

Choose a reason for hiding this comment

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

right_derive_when_split is ok

@hhkbp2
Copy link
Contributor

hhkbp2 commented Apr 24, 2017

Rest LGTM

@siddontang
Copy link
Contributor

Any update? @zhangjinpeng1987

@zhangjinpeng87 zhangjinpeng87 merged commit a273d36 into master Apr 24, 2017
@zhangjinpeng87 zhangjinpeng87 deleted the zhangjinpeng/split-v2 branch April 24, 2017 09:53
iosmanthus pushed a commit to iosmanthus/tikv that referenced this pull request Oct 17, 2024
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.

5 participants