Skip to content

raftstore: fix reset follow apply_unpersisted_log_limit when demoting from leader#18241

Merged
ti-chi-bot[bot] merged 7 commits intotikv:masterfrom
glorv:reset-follower
Feb 28, 2025
Merged

raftstore: fix reset follow apply_unpersisted_log_limit when demoting from leader#18241
ti-chi-bot[bot] merged 7 commits intotikv:masterfrom
glorv:reset-follower

Conversation

@glorv
Copy link
Contributor

@glorv glorv commented Feb 21, 2025

What is changed and how it works?

Issue Number: Close #17868, ref #16717

What's Changed:

NOTE: this PR depends on PR tikv/raft-rs#561

This PR adopt the changes in https://github.com/tikv/raft-rs/pull/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.

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Release note

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the dco. labels Feb 21, 2025
@glorv
Copy link
Contributor Author

glorv commented Feb 21, 2025

/hold waiting tikv/raft-rs#561.

@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Feb 21, 2025
@glorv
Copy link
Contributor Author

glorv commented Feb 21, 2025

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 21, 2025

@glorv: GitHub didn't allow me to request PR reviews from the following users: hhwyt.

Note that only tikv members and repo collaborators can review this PR, and authors cannot review their own PRs.

Details

In response to this:

/cc @Connor1996 @overvenus @LykxSassinator @hbisheng @hhwyt

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 kubernetes-sigs/prow repository.

Signed-off-by: glorv <glorvs@163.com>
Signed-off-by: glorv <glorvs@163.com>
mem_size_change -=
(bytes_capacity(&e.data) + bytes_capacity(&e.context)) as i64;
}
// NOTE: if we are going to support apply unpersisted entries on follower,
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to move this line to the line before the "assert" line.

must_get_equal(&cluster.get_engine(3), b"k150", b"v150");
}

// Test the consistency of EntryCache when partioned leader constains
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Test the consistency of EntryCache when partioned leader constains
// Test the consistency of EntryCache when partitioned leader constains

}

// Test the consistency of EntryCache when partioned leader constains
// uncommitted propose, after the partion is recovered, it can replicate raft
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// uncommitted propose, after the partion is recovered, it can replicate raft
// uncommitted propose, after the partition is recovered, it can replicate raft

let mut msg = dropped_append.lock().unwrap().clone();
assert_eq!(msg.get_message().to, 1);
// Advance the committed index of the Append msg to trigger the corner case.
// I don't find an easy way to trigger this kind of msg, so direct modify the
Copy link
Contributor

Choose a reason for hiding this comment

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

A practical solution 👍

@hhwyt
Copy link
Contributor

hhwyt commented Feb 21, 2025

typo in the PR descrption: "on_role_change" -> "on_role_changed"

Signed-off-by: glorv <glorvs@163.com>
Signed-off-by: glorv <glorvs@163.com>
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

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Feb 24, 2025
Copy link
Contributor

@LykxSassinator LykxSassinator left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@hbisheng hbisheng left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +170 to +176
// Test the consistency of EntryCache when partitioned leader constains
// uncommitted propose, and after the partition is recovered, it can replicate
// raft entries for new leader correctly. This case test the corner scenario
// that partitioned leader receive a new Append msg for new elected leader and
// the new entries are already committed and overlap with existing entries
// uncomitted entries in the entry cache, it may cause panic if handles
// incorrectly. See issue https://github.com/tikv/tikv/issues/17868 for more details.
Copy link
Member

Choose a reason for hiding this comment

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

i'm just a spell-checking bot 🤖

Suggested change
// Test the consistency of EntryCache when partitioned leader constains
// uncommitted propose, and after the partition is recovered, it can replicate
// raft entries for new leader correctly. This case test the corner scenario
// that partitioned leader receive a new Append msg for new elected leader and
// the new entries are already committed and overlap with existing entries
// uncomitted entries in the entry cache, it may cause panic if handles
// incorrectly. See issue https://github.com/tikv/tikv/issues/17868 for more details.
// Test the consistency of EntryCache when partitioned leader contains
// uncommitted propose, and after the partition is recovered, it can replicate
// raft entries for new leader correctly. This case tests the corner scenario
// that partitioned leader receives a new Append msg from new elected leader and
// the new entries are already committed and overlap with existing
// uncommitted entries in the entry cache, it may cause panic if handled
// incorrectly. See issue https://github.com/tikv/tikv/issues/17868 for more details.

block_on_timeout(ch, Duration::from_millis(100)).unwrap_err();

let fp = "pause_on_peer_collect_message";
// pause peer 1 to wait for leader timeout, should new leader
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
// pause peer 1 to wait for leader timeout, should new leader
// pause peer 1 to wait for leader timeout

Copy link
Member

@overvenus overvenus left a comment

Choose a reason for hiding this comment

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

LGTM, wait for raft-rs change.

let cached_last = cached.range.end - 1;
// TODO: if we are going to support apply unpersisted entries on
// follower, this assert will not longer be correct.
assert!(cached_last < trunc_to_idx);
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
assert!(cached_last < trunc_to_idx);
assert!(cached_last < trunc_to_idx, "cached_last: {}, trunc_to_idx: {}", cached_last, trunc_to_idx);

Signed-off-by: glorv <glorvs@163.com>
@glorv
Copy link
Contributor Author

glorv commented Feb 28, 2025

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 28, 2025
@glorv
Copy link
Contributor Author

glorv commented Feb 28, 2025

@hbisheng @LykxSassinator PTAL again as tikv/raft-rs#561 is merged.

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 28, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 28, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-02-24 08:38:43.780110821 +0000 UTC m=+258671.733269080: ☑️ agreed by Connor1996.
  • 2025-02-28 08:22:31.554072313 +0000 UTC m=+603299.507230564: ☑️ agreed by hbisheng.

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 28, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Connor1996, hbisheng, LykxSassinator

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

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [Connor1996,LykxSassinator]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot merged commit 14622f3 into tikv:master Feb 28, 2025
8 checks passed
@ti-chi-bot ti-chi-bot bot added this to the Pool milestone Feb 28, 2025
@glorv glorv added needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. labels Feb 28, 2025
@glorv glorv deleted the reset-follower branch February 28, 2025 08:46
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #18260.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #18261.

ti-chi-bot bot pushed a commit 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 <glorvs@163.com>

Co-authored-by: glorv <glorvs@163.com>
ti-chi-bot bot pushed a commit 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 <glorvs@163.com>

Co-authored-by: glorv <glorvs@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TiKV panic with "assertion failed: cached_last < trunc_to_idx"

7 participants