-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
raftstore: change the condition of proposing rollback merge #6584
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9b9f2d9
fix merge bug
gengliqi 08fff10
Merge branch 'master' into fix-merge-bug-5
gengliqi 403b228
format
gengliqi de6ad47
Merge branch 'master' into fix-merge-bug-5
gengliqi 11ea3a7
fix compile error
gengliqi 1c53a53
reset cargo.lock
gengliqi c3dac7b
merge master
gengliqi 2db59be
add one more failpoint test
gengliqi a3face3
Merge branch 'master' into fix-merge-bug-5
gengliqi 83e0379
merge master
gengliqi 3192d32
format
gengliqi 0ae7a9e
merge master
gengliqi 994b869
add log
gengliqi 8afa140
only permit merging state
gengliqi a90159b
Merge branch 'master' into fix-merge-bug-5
sre-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -889,6 +889,7 @@ impl<'a, T: Transport, C: PdClient> PeerFsmDelegate<'a, T, C> { | |
} | ||
|
||
if msg.has_merge_target() { | ||
fail_point!("on_has_merge_target", |_| Ok(())); | ||
if self.need_gc_merge(&msg)? { | ||
self.on_stale_merge(); | ||
} | ||
|
@@ -950,7 +951,9 @@ impl<'a, T: Transport, C: PdClient> PeerFsmDelegate<'a, T, C> { | |
self.reset_raft_tick(GroupState::Ordered); | ||
} | ||
ExtraMessageType::MsgWantRollbackMerge => { | ||
unimplemented!("remove this after #6584 merged") | ||
self.fsm | ||
.peer | ||
.maybe_add_want_rollback_merge_peer(msg.get_from_peer().get_id(), &extra_msg); | ||
} | ||
} | ||
} | ||
|
@@ -1905,18 +1908,64 @@ impl<'a, T: Transport, C: PdClient> PeerFsmDelegate<'a, T, C> { | |
} | ||
|
||
fn on_check_merge(&mut self) { | ||
if self.fsm.stopped || self.fsm.peer.pending_merge_state.is_none() { | ||
if self.fsm.stopped | ||
|| self.fsm.peer.pending_remove | ||
|| self.fsm.peer.pending_merge_state.is_none() | ||
{ | ||
return; | ||
} | ||
self.register_merge_check_tick(); | ||
fail_point!( | ||
"on_check_merge_not_1001", | ||
self.fsm.peer_id() != 1001, | ||
|_| {} | ||
); | ||
if let Err(e) = self.schedule_merge() { | ||
info!( | ||
"failed to schedule merge, rollback"; | ||
"region_id" => self.fsm.region_id(), | ||
"peer_id" => self.fsm.peer_id(), | ||
"err" => %e, | ||
); | ||
self.rollback_merge(); | ||
if self.fsm.peer.is_leader() { | ||
self.fsm | ||
.peer | ||
.add_want_rollback_merge_peer(self.fsm.peer_id()); | ||
if self.fsm.peer.want_rollback_merge_peers.len() | ||
>= raft::majority( | ||
self.fsm | ||
.peer | ||
.raft_group | ||
.status() | ||
.progress | ||
.unwrap() | ||
.voter_ids() | ||
.len(), | ||
) | ||
{ | ||
info!( | ||
"failed to schedule merge, rollback"; | ||
"region_id" => self.fsm.region_id(), | ||
"peer_id" => self.fsm.peer_id(), | ||
"err" => %e, | ||
); | ||
self.rollback_merge(); | ||
} | ||
} else if !self.fsm.peer.peer.get_is_learner() { | ||
info!( | ||
"want to rollback merge"; | ||
"region_id" => self.fsm.region_id(), | ||
"peer_id" => self.fsm.peer_id(), | ||
"leader_id" => self.fsm.peer.leader_id(), | ||
"err" => %e, | ||
); | ||
if self.fsm.peer.leader_id() != raft::INVALID_ID { | ||
self.ctx.need_flush_trans = true; | ||
self.fsm.peer.send_want_rollback_merge( | ||
self.fsm | ||
.peer | ||
.pending_merge_state | ||
.as_ref() | ||
.unwrap() | ||
.get_commit(), | ||
&mut self.ctx.trans, | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -2084,7 +2133,10 @@ impl<'a, T: Transport, C: PdClient> PeerFsmDelegate<'a, T, C> { | |
self.fsm.peer.tag, pending_commit, commit | ||
); | ||
} | ||
// Clear merge releted data | ||
self.fsm.peer.pending_merge_state = None; | ||
self.fsm.peer.want_rollback_merge_peers.clear(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should clear when applying snapshot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After applying a snapshot, |
||
|
||
if let Some(r) = region { | ||
let mut meta = self.ctx.store_meta.lock().unwrap(); | ||
meta.set_region(&self.ctx.coprocessor_host, r, &mut self.fsm.peer); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 to ensure peers in
want_rollback_merge_peers
matches the currentpeer_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.
It can be ensured. If a peer can be added to
want_rollback_merge_peers
, it must be in currentpeer_list
because itsPrepareMerge
commit index is the same as the leader's.