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: make apply before persist compatible with online unsafe recovery #16651

Merged
merged 7 commits into from Apr 11, 2024

Conversation

glorv
Copy link
Contributor

@glorv glorv commented Mar 14, 2024

What is changed and how it works?

Issue Number: ref #16717, close #16796

The unit test in this pr depends on #16626

What's Changed:

Before enter force-leader, if local applied_index > last_index, first force commit and truncate raft index to applied index. This can ensure the raft state is compatible with apply_state.

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

Copy link
Contributor

ti-chi-bot bot commented Mar 14, 2024

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • Connor1996
  • v01dstar

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.

@@ -1647,6 +1652,26 @@ where
return;
}

// apply is ahead of raft, need to force raft commit to applied index.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a comment that explains under what circumstances, applied index could be larger than last commit?

@glorv glorv marked this pull request as ready for review April 9, 2024 05:55
@@ -4365,6 +4386,30 @@ where
}
}

fn force_compact(&mut self, ctx: &mut ApplyContext<EK>, term: u64, compact_index: u64) {
Copy link
Member

Choose a reason for hiding this comment

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

maybe call it unsafe_force_compact

@@ -4365,6 +4386,30 @@ where
}
}

fn force_compact(&mut self, ctx: &mut ApplyContext<EK>, term: u64, compact_index: u64) {
assert_eq!(self.delegate.apply_state.applied_index, compact_index);
if self.delegate.apply_state.get_truncated_state().index != compact_index {
Copy link
Member

Choose a reason for hiding this comment

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

!= -> <?

let raft_engine = self.fsm.peer.get_store().raft_engine();
let mut batch = raft_engine.log_batch(2);
raft_engine
.gc(self.region_id(), first_index, last_index, &mut batch)
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't introduce other io operation in raftstore thread

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After discussing offline, we decide to keep the current code to make the logic simpler. We maybe enhance it in the future if this operation is still a thing.

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 the status/LGT1 Status: PR - There is already 1 approval label Apr 10, 2024
Signed-off-by: glorv <glorvs@163.com>
Copy link
Contributor

@v01dstar v01dstar 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 status/LGT2 Status: PR - There are already 2 approvals and removed status/LGT1 Status: PR - There is already 1 approval labels Apr 10, 2024
@glorv
Copy link
Contributor Author

glorv commented Apr 11, 2024

/merge

Copy link
Contributor

ti-chi-bot bot commented Apr 11, 2024

@glorv: 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.

Copy link
Contributor

ti-chi-bot bot commented Apr 11, 2024

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

Commit hash: 36581b3

@ti-chi-bot ti-chi-bot bot added the status/can-merge Status: Can merge to base branch label Apr 11, 2024
@ti-chi-bot ti-chi-bot bot merged commit 57615b2 into tikv:master Apr 11, 2024
7 checks passed
@ti-chi-bot ti-chi-bot bot added this to the Pool milestone Apr 11, 2024
@glorv glorv deleted the unsafe-recovery branch April 11, 2024 03:11
@ti-chi-bot
Copy link
Member

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

@ti-chi-bot
Copy link
Member

@glorv: new pull request could not be created: failed to create pull request against tikv/tikv#release-8.1 from head ti-chi-bot:cherry-pick-16651-to-release-8.1: status code 422 not one of [201], body: {"message":"Validation Failed","errors":[{"resource":"PullRequest","code":"custom","message":"A pull request already exists for ti-chi-bot:cherry-pick-16651-to-release-8.1."}],"documentation_url":"https://docs.github.com/rest/pulls/pulls#create-a-pull-request"}

In response to this:

/cherry-pick release-8.1

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 bot pushed a commit that referenced this pull request Apr 11, 2024
…covery (#16651) (#16801)

ref #16717, close #16796

Before enter force-leader, if local applied_index > last_index, first force commit and truncate raft index to applied index. This can ensure the raft state is compatible with apply_state.

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
needs-cherry-pick-release-8.1 release-note-none size/XL 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.

Apply raft log before persistence is not compatible with online unsafe recovery
4 participants