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

raftstore-v2: support tablet split #13709

Merged
merged 57 commits into from Nov 14, 2022
Merged

Conversation

SpadeA-Tang
Copy link
Member

@SpadeA-Tang SpadeA-Tang commented Nov 1, 2022

What is changed and how it works?

Issue Number: Ref #12842

What's Changed:

Subsequent PR of #13689 which implements propose and execute tablet split

This PR implements on apply result as well as create/initialize split peers.
In v1, split create and register PeerFsm directly which causes some race condition problems as the 
PeerFsm can also be created by raft message.

Now in v2, the PeerFsm creation entrance has been unified which means split does not create it directly. 
Instread, it first sends an AcrossPeerMsg to the store where the store first creates an unintialized PeerFsm 
and then sends the msg to the relevant peer. It includes the information to intialize the peer.

Todo:

  • Implement FreezeAndClone to substitute the CreateCheckpoint API.
  • Only when parent receives all the responses can the apply index be updated.
  • Consider more when the split peers is already initialized.
  • Use DeleteFilesInRange and compaction filter to delete data not in the region.

Check List

Tests

  • Unit test
  • Integration test

Release note

None

SpadeA-Tang and others added 27 commits October 27, 2022 13:25
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Nov 1, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • tabokie
  • tonyxuqqi

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
@ti-chi-bot ti-chi-bot added the status/LGT1 Status: PR - There is already 1 approval label Nov 10, 2022
//! - todo
//! On Apply Result:
//! - on_ready_split_region: Update the relevant in memory meta info of the
//! parent peer, and wrap and send to the store the relevant info needed to
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
//! parent peer, and wrap and send to the store the relevant info needed to
//! parent peer, then send to the store the relevant info needed to

@@ -63,14 +72,23 @@ pub struct SplitResult {
pub derived_index: usize,
pub tablet_index: u64,
}
pub struct SplitInit {
/// Split region
pub region: metapb::Region,
Copy link
Member

Choose a reason for hiding this comment

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

Why need to be public?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's accessed in life.rs

ER: RaftEngine,
{
let region_id = msg.as_ref().region.id;
let mut raft_msg = RaftMessage::default();
Copy link
Member

Choose a reason for hiding this comment

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

You can put it into Box directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any difference?

Copy link
Member

Choose a reason for hiding this comment

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

Avoid copy.

// difference is due to v2 only performs read by local reader and
// raftstore is just a place to renew the lease. If the lease in raftstore is
// not expired, it may not renew lease.
self.leader_lease.expire();
Copy link
Member

Choose a reason for hiding this comment

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

No, v2 should be the same as v1. expire is just used to forbid on-going read. All local reader should use the new lease as the epoch change.

Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
components/raftstore-v2/src/batch/store.rs Outdated Show resolved Hide resolved
components/raftstore-v2/src/fsm/store.rs Outdated Show resolved Hide resolved
components/raftstore-v2/src/fsm/store.rs Outdated Show resolved Hide resolved
components/raftstore-v2/src/raft/peer.rs Outdated Show resolved Hide resolved
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
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.

Overall workflow LGTM

@@ -195,6 +202,7 @@ impl fmt::Debug for StoreMsg {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
StoreMsg::RaftMessage(_) => write!(fmt, "Raft Message"),
StoreMsg::SplitInit(_) => write!(fmt, "Peer Creation"),
Copy link
Member

Choose a reason for hiding this comment

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

Wrong message.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch.

@@ -167,6 +170,9 @@ impl fmt::Debug for PeerMsg {
},
PeerMsg::ApplyRes(res) => write!(fmt, "ApplyRes {:?}", res),
PeerMsg::Start => write!(fmt, "Startup"),
PeerMsg::SplitInit(_) => {
write!(fmt, "Across peer msg")
Copy link
Member

Choose a reason for hiding this comment

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

Wrong message.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch.

raft_msg.set_region_epoch(msg.region.get_region_epoch().clone());
// Set the peer_id be INVALID_ID so that the message will not be sent to the
// peer after the creation.
raft_msg.mut_from_peer().set_id(raft::INVALID_ID);
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 just raft_msg.take_from_peer();?

ctx.router
.force_send(region_id, PeerMsg::SplitInit(msg))
.unwrap_or_else(|e| {
panic!(
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 OK to return error. It's possible the peer is destroyed right before force send.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch.

region: &metapb::Region,
key: &[u8],
) -> RaftCmdResponse {
let mut req = RaftCmdRequest::default();
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 router.new_request_for?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

assert!(!resp.get_header().has_error(), "{:?}", resp);
}

fn must_put_error(store_id: u64, router: &mut TestRouter, region: &metapb::Region, key: &[u8]) {
Copy link
Member

Choose a reason for hiding this comment

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

Better implement these inline, it's hard to read to jump back and forth.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
///
/// This will update the region of the peer, caller must ensure the region
/// has been preserved in a durable device.
pub fn set_region(
Copy link
Member

Choose a reason for hiding this comment

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

Is this supposed to be put here? Seems only simple getter/setters are placed in this file.

Copy link
Member Author

Choose a reason for hiding this comment

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

So, which file you think 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.

I don't know really, just a thought.

components/raftstore-v2/src/raft/peer.rs Show resolved Hide resolved
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
pub fn reset_region_buckets(&mut self) {
if self.region_buckets.is_some() {
self.last_region_buckets = self.region_buckets.take();
self.region_buckets = None;
Copy link
Member

Choose a reason for hiding this comment

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

unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch.

@ti-chi-bot ti-chi-bot added status/LGT2 Status: PR - There are already 2 approvals and removed status/LGT1 Status: PR - There is already 1 approval labels Nov 14, 2022
Signed-off-by: SpadeA-Tang <u6748471@anu.edu.au>
@tabokie
Copy link
Member

tabokie commented Nov 14, 2022

/merge

@ti-chi-bot
Copy link
Member

@tabokie: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 2bc0a98

@ti-chi-bot ti-chi-bot added the status/can-merge Status: Can merge to base branch label Nov 14, 2022
@ti-chi-bot ti-chi-bot merged commit 23dba4f into tikv:master Nov 14, 2022
@ti-chi-bot ti-chi-bot added this to the Pool milestone Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution Type: PR - From contributors release-note-none size/XXL status/can-merge Status: Can merge to base branch status/LGT2 Status: PR - There are already 2 approvals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants