Skip to content

server, storage: make flashback compatible with resolved_ts#13823

Merged
ti-chi-bot merged 20 commits intotikv:masterfrom
JmPotato:flashback_resolved_ts
Nov 29, 2022
Merged

server, storage: make flashback compatible with resolved_ts#13823
ti-chi-bot merged 20 commits intotikv:masterfrom
JmPotato:flashback_resolved_ts

Conversation

@JmPotato
Copy link
Member

@JmPotato JmPotato commented Nov 18, 2022

Signed-off-by: JmPotato ghzpotato@gmail.com

What is changed and how it works?

Issue Number: ref #13787. Should merge after pingcap/kvproto#1016.

What's Changed:

- Prewrite and commit `self.start_key` independently to prevent `resolved_ts` from advancing during the flashback process.
- Roll back all keys before prewriting `self.start_key`  during the preparing flashback.
- Add a test case for CDC compatibility.

The whole process now looks like these:

In PrepareFlashback, we will:

  • Roll back all locks.
  • Prewrite the self.start_key.

In FinishFlashback, we will:

  • Flashback all writes with 1PC.
  • Commit the self.start_key.

Check List

Tests

  • Unit test
  • Integration test

Release note

None.

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Nov 18, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • Connor1996
  • overvenus

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.

Details

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added 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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 18, 2022
@JmPotato
Copy link
Member Author

/cc @overvenus @Connor1996 @sticnarf

Please help review this PR, thx a lot.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 18, 2022
@JmPotato JmPotato force-pushed the flashback_resolved_ts branch from 1cd8f03 to c7276ac Compare November 18, 2022 14:55
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 18, 2022
@JmPotato JmPotato requested a review from sticnarf November 21, 2022 13:40
@JmPotato JmPotato force-pushed the flashback_resolved_ts branch from b4cc9d4 to 95d4bb1 Compare November 22, 2022 05:23
@ti-chi-bot ti-chi-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 22, 2022
@JmPotato JmPotato requested review from HuSharp and sticnarf November 22, 2022 05:25
Comment on lines +89 to +97
/// 2. Read-and-flashback writes phase:
/// - Scan all the latest writes and their corresponding values at
/// `self.version`.
/// - Write the old MVCC version writes again for all these keys with
/// `self.commit_ts` excluding the `self.start_key` .
/// 3. Read-and-rollback locks phase:
/// - Scan all locks.
/// - Rollback all these locks excluding the `self.start_key` lock we write
/// at the first phase.
Copy link
Contributor

@sticnarf sticnarf Nov 22, 2022

Choose a reason for hiding this comment

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

I notice you swap the order of FlashbackLock and FlashbackWrite. Is there a reason for that?

Is it possible that some lock exists while you are writing the new flashbacked records? If so, it seems a bit weird... And I just start wondering what will happen if there is a lock on the start_key before flashback begins...

Copy link
Member Author

Choose a reason for hiding this comment

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

At first, I wanted to clean up the "placeholder" lock by finally cleaning the lock. Now that we have changed the way, I will change it back. Thx for pointing this out.

Copy link
Member Author

Choose a reason for hiding this comment

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

And I just start wondering what will happen if there is a lock on the start_key before flashback begins...

Since all the other read/write transactions will be blocked and fail during the flashback, I think this kind of lock doesn't have any side effects. 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm just not sure how CDC will react if a lock is rewritten with a different start ts...

Copy link
Member Author

Choose a reason for hiding this comment

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

I have adjusted the whole process, now it works more reasonably I think.

In PrepareFlashback, we will:

  • Roll back all locks.
  • Prewrite the self.start_key.

In FinishFlashback, we will:

  • Flashback all writes with 1PC.
  • Commit the self.start_key.

As for the lock, after discussing with @overvenus, as long as the lock is roll backed normally, it won't be a bother to CDC. Also, since we checked the minimal store resolved_ts with the flashback version before sending the request, so it won't break any half-committed transaction either.

@JmPotato JmPotato requested review from HuSharp and sticnarf November 22, 2022 07:38
Copy link
Contributor

@sticnarf sticnarf left a comment

Choose a reason for hiding this comment

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

LGTM

@JmPotato
Copy link
Member Author

@overvenus @Connor1996 PTAL also, thx.

@ti-chi-bot ti-chi-bot added the status/LGT2 Indicates that a PR has LGTM 2. label Nov 28, 2022
@Connor1996
Copy link
Member

/merge

@ti-chi-bot
Copy link
Member

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

Details

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
Copy link
Member

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

DetailsCommit hash: 470a674

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 29, 2022
@JmPotato
Copy link
Member Author

/hold

@ti-chi-bot ti-chi-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 29, 2022
Signed-off-by: JmPotato <ghzpotato@gmail.com>
@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Nov 29, 2022
@JmPotato
Copy link
Member Author

/unhold

@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 29, 2022
Signed-off-by: JmPotato <ghzpotato@gmail.com>
@JmPotato
Copy link
Member Author

/test

Signed-off-by: JmPotato <ghzpotato@gmail.com>
Signed-off-by: JmPotato <ghzpotato@gmail.com>
}

#[inline(always)]
pub fn get_value(&mut self, key: &Key, start_ts: TimeStamp) -> Result<Option<Value>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

SnapshotReader typically uses its own start_ts for something. If it doesn't need the start_ts of SnapshotReader itself, I suggest to just use the inner MvccReader directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed. PTAL.

BTW, your suggestion made me realize that there is a mix of SnapshotReader and MvccReader in the flashback commands, and I think we can open another separate PR to improve this situation, after this PR is merged, of course.

Copy link
Member

Choose a reason for hiding this comment

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

address this comment at #13860 @sticnarf @JmPotato

Signed-off-by: JmPotato <ghzpotato@gmail.com>
@JmPotato JmPotato requested a review from sticnarf November 29, 2022 13:48
@sticnarf
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

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

Details

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
Copy link
Member

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

DetailsCommit hash: da39377

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 29, 2022
@ti-chi-bot ti-chi-bot merged commit c1aceb0 into tikv:master Nov 29, 2022
@ti-chi-bot ti-chi-bot added this to the Pool milestone Nov 29, 2022
@JmPotato JmPotato deleted the flashback_resolved_ts branch November 29, 2022 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants