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

reset max_apply_unpersisted_log_limit in become_follower #561

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

glorv
Copy link
Contributor

@glorv glorv commented Feb 20, 2025

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
Copy link
Contributor Author

glorv commented Feb 20, 2025

@Connor1996 @overvenus @gengliqi PTAL, thanks~

Copy link
Member

@Connor1996 Connor1996 left a comment

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]>
src/raft.rs Outdated
@@ -1152,6 +1152,12 @@ impl<T: Storage> Raft<T> {
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

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
Copy link
Contributor Author

glorv commented Feb 24, 2025

@Connor1996 @hhwyt PTAL again

Copy link
Member

@Connor1996 Connor1996 left a comment

Choose a reason for hiding this comment

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

LGTM

@glorv
Copy link
Contributor Author

glorv commented Feb 24, 2025

@overvenus PTAL

@hbisheng
Copy link
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]>

for _ in 0..=sm.election_timeout() {
sm.tick();
}

assert_eq!(sm.state, StateRole::Follower);
// check after become follower, the limit is reset.
Copy link
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
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

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