Skip to content

reset max_apply_unpersisted_log_limit in become_follower#561

Merged
overvenus merged 10 commits into
tikv:masterfrom
glorv:reset-on-follower
Feb 28, 2025
Merged

reset max_apply_unpersisted_log_limit in become_follower#561
overvenus merged 10 commits into
tikv:masterfrom
glorv:reset-on-follower

Conversation

@glorv

@glorv glorv commented Feb 20, 2025

Copy link
Copy Markdown
Contributor

This PR reset the max_apply_unpersisted_log_limit value when peer role demote from leader to follower. Because the user can only notice role change event after call ready() and the committed entries are collected in the ready() so we have to do this here to ensure we only enable max_apply_unpersisted_log_limit on raft leader.

NOTE: In theory, the affect of max_apply_unpersisted_log_limit is not related the raft role. We limit it to only leader to prevent potencial corn cases. We may want to remove this restriction in the future. In that case, we should revert this PR then.

See tikv/tikv#17868 for more details.

@glorv

glorv commented Feb 20, 2025

Copy link
Copy Markdown
Contributor Author

@Connor1996 @overvenus @gengliqi PTAL, thanks~

@Connor1996 Connor1996 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we add a test to cover the case?

@glorv glorv force-pushed the reset-on-follower branch from 4247a6a to 09742ec Compare February 20, 2025 11:06
Signed-off-by: glorv <[email protected]>
Comment thread src/raft.rs Outdated
let from_role = self.state;
self.state = StateRole::Follower;
self.pending_request_snapshot = pending_request_snapshot;
// TODO: In theory, we should better control this in the caller,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

"caller" -> "user" ?

Signed-off-by: glorv <[email protected]>
@glorv

glorv commented Feb 24, 2025

Copy link
Copy Markdown
Contributor Author

@Connor1996 @hhwyt PTAL again

@Connor1996 Connor1996 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@glorv

glorv commented Feb 24, 2025

Copy link
Copy Markdown
Contributor Author

@overvenus PTAL

Comment thread src/raft.rs Outdated
@hbisheng

Copy link
Copy Markdown
Member

Would you mind putting down some context in the PR description? Otherwise it might not be obvious to future readers that this change is part of tikv/tikv#18241.

Co-authored-by: Bisheng Huang <[email protected]>
Signed-off-by: glorv <[email protected]>
}

assert_eq!(sm.state, StateRole::Follower);
// check after become follower, the limit is reset.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add some comments explaining why the reset is necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. PTAL again, thanks

@overvenus overvenus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rest LGTM

Comment thread src/raft.rs
// so we hard code this logic here currently. We may need to remove
// this hard code when we want to also support apply unpersisted log
// on follower.
self.raft_log.max_apply_unpersisted_log_limit = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please update docs of this behavior change.

Signed-off-by: glorv <[email protected]>
Signed-off-by: glorv <[email protected]>
Signed-off-by: glorv <[email protected]>
Signed-off-by: glorv <[email protected]>
@glorv glorv force-pushed the reset-on-follower branch from 4d4157c to 8f0e01d Compare February 28, 2025 06:22
@overvenus

Copy link
Copy Markdown
Member

/merge

@overvenus overvenus merged commit 0d01b20 into tikv:master Feb 28, 2025
@glorv glorv deleted the reset-on-follower branch February 28, 2025 07:52
ti-chi-bot Bot pushed a commit to tikv/tikv that referenced this pull request Feb 28, 2025
… from leader (#18241)

ref #16717, close #17868

This PR adopt the changes in tikv/raft-rs#561 that directly reset the apply_unpersisted_log_limit limit in raft when leader is demoted. It fix the bug that in the previous impl, the reset is done in "on_role_change" which is called in handle_raft_ready, in the round that leader is demoted, it still return unpersisted comitted entries as at the time, the limit is not reset.
NOTE: once we want to support this feature on follower, we need to remove the original assert as it is incorrect in this case.

Signed-off-by: glorv <[email protected]>
ti-chi-bot Bot pushed a commit to tikv/tikv that referenced this pull request Mar 4, 2025
… from leader (#18241) (#18260)

ref #16717, close #17868

This PR adopt the changes in tikv/raft-rs#561 that directly reset the apply_unpersisted_log_limit limit in raft when leader is demoted. It fix the bug that in the previous impl, the reset is done in "on_role_change" which is called in handle_raft_ready, in the round that leader is demoted, it still return unpersisted comitted entries as at the time, the limit is not reset.
NOTE: once we want to support this feature on follower, we need to remove the original assert as it is incorrect in this case.

Signed-off-by: glorv <[email protected]>

Co-authored-by: glorv <[email protected]>
ti-chi-bot Bot pushed a commit to tikv/tikv that referenced this pull request Mar 4, 2025
… from leader (#18241) (#18261)

ref #16717, close #17868

This PR adopt the changes in tikv/raft-rs#561 that directly reset the apply_unpersisted_log_limit limit in raft when leader is demoted. It fix the bug that in the previous impl, the reset is done in "on_role_change" which is called in handle_raft_ready, in the round that leader is demoted, it still return unpersisted comitted entries as at the time, the limit is not reset.
NOTE: once we want to support this feature on follower, we need to remove the original assert as it is incorrect in this case.

Signed-off-by: glorv <[email protected]>

Co-authored-by: glorv <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants