-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
support split v2 #1747
Conversation
src/raftstore/store/store.rs
Outdated
for peer in right.get_peers() { | ||
right: metapb::Region, | ||
left_derive: bool) { | ||
let new_region = if left_derive { |
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.
let (new_region, origin_region) = if left_derive {
(right.clone(), left.clone())
} else {
(left.clone(), right.clone())
}
seem that we should also handle https://github.com/pingcap/tikv/blob/614b7e083c4cee7e27d960436c5207cd6908e265/src/raftstore/store/store.rs#L1274 carefully |
src/raftstore/store/store.rs
Outdated
if let Some(left) = self.region_peers.get(®ion_id) { | ||
campaigned = new_peer.maybe_campaign(left, &mut self.pending_raft_groups); | ||
if let Some(origin_peer) = self.region_peers.get(®ion_id) { | ||
campaigned = |
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.
@BusyJay Can we remove this mechanism after we implement split v2?
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.
The left region may still need to campaign fastly.
@siddontang Yes, so we modify |
src/raftstore/store/store.rs
Outdated
// 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>)) |
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.
do we have any test to cover the tow cases for 1 -> 1 + 2 and 1 -> 2 + 1?
any update @zhangjinpeng1987 |
src/raftstore/store/peer.rs
Outdated
@@ -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; |
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 guess this can only check Admin Split command, for other commands, we also can meet stale problems.
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.
Please refresh change code.
src/raftstore/store/config.rs
Outdated
@@ -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, |
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.
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, |
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 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); |
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.
Unnecessary.
PTAL |
Please fix CI. |
src/raftstore/store/store.rs
Outdated
// 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 { |
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 extract the logic and check individually? I am concerned the correctness here.
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.
test_split_stale_epoch
do that thing exactly.
src/raftstore/store/store.rs
Outdated
} | ||
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 { |
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.
/cc @disksing
Please review the logic here.
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.
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(|(_, ®ion_id)| region_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.
any update?
@disksing PTAL |
LGTM. |
src/raftstore/store/store.rs
Outdated
// 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(®ion_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.
seem must exist here?
Rest LGTM |
src/raftstore/store/store.rs
Outdated
if right_derive { | ||
self.region_peers.get_mut(®ion_id).unwrap().size_diff_hint = self.cfg | ||
.region_check_size_diff; | ||
|
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 empty line.
} else { | ||
Excluded(enc_end_key(region)) | ||
}; | ||
self.region_ranges.range((start, Unbounded::<Key>)).next().map(|(_, ®ion_id)| region_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.
Should it be range(Unbound::<key>, start).rev()
for right_derive_when_split == true
?
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.
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, |
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.
s/right_derive_when_split/derive_right_part_when_split/
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.
right_derive_when_split is ok
Rest LGTM |
Any update? @zhangjinpeng1987 |
…zhangjinpeng/split-v2
Signed-off-by: Ping Yu <[email protected]>
@BusyJay @siddontang PTAL