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

txn: Add batch-resumed mode for acquire_pessimistic_lock storage command #13687

Conversation

MyonKeminta
Copy link
Contributor

@MyonKeminta MyonKeminta commented Oct 28, 2022

What is changed and how it works?

Issue Number: Ref #13298

Requires: #13680

What's Changed:

Add batch-resumed mode for acquire_pessimistic_lock storage command.

Now the storage command `AcquirePessimisticLock` contains an enum to determine whether it's executing a normal request or it's a batch of requests resumed after waiting for another lock.

……but I doubt that whether it would be better if I add a new command instead of making AcquirePessimisticLock an enum inside

Related changes

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

Check List

Tests

  • It will be covered by tests after another PR that makes use of it.

Side effects

  • Performance regression
    • Consumes more CPU

Release note

None

Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Oct 28, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • cfzjywxk
  • sticnarf

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.

Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
@MyonKeminta MyonKeminta changed the base branch from feature/pessimistic-lock-opt to master November 2, 2022 06:16
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
@sticnarf
Copy link
Contributor

sticnarf commented Nov 4, 2022

……but I doubt that whether it would be better if I add a new command instead of making AcquirePessimisticLock an enum inside

I think it looks better to add a new command. Is there any difficulty doing this way?

@MyonKeminta
Copy link
Contributor Author

……but I doubt that whether it would be better if I add a new command instead of making AcquirePessimisticLock an enum inside

I think it looks better to add a new command. Is there any difficulty doing this way?

No. At first I was trying to reuse most of the code, but finally it looks totally different. I'll split it into two commands.

Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Comment on lines 186 to 192
($field: ident: enum_match { $( $arm: pat => $expr: expr ), * }) => {
fn gen_lock(&self) -> crate::storage::txn::latch::Lock {
match &self.$field {
$( $arm => crate::storage::txn::latch::Lock::new($expr) ),*
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this rule used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sorry. This is not used now and I forgot to delete it.

Comment on lines 89 to 97
if let Some(txn) = txn {
if !txn.is_empty() {
modifies.extend(txn.into_modifies());
}
}
txn = Some(MvccTxn::new(
params.start_ts,
context.concurrency_manager.clone(),
));
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
if let Some(txn) = txn {
if !txn.is_empty() {
modifies.extend(txn.into_modifies());
}
}
txn = Some(MvccTxn::new(
params.start_ts,
context.concurrency_manager.clone(),
));
if let Some(txn) = txn.replace(MvccTxn::new(...)) {
if !txn.is_empty() {
modifies.extend(txn.into_modifies());
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

replace is a bit simpler. Same for the reader below.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is !txn.is_empty() necessary? IMO the code will look a bit simpler if removing the if.

Comment on lines 130 to 135
if old_value.resolved() {
let key = key.append_ts(txn.start_ts);
// MutationType is unknown in AcquirePessimisticLock stage.
let mutation_type = None;
old_values.insert(key, (old_value, mutation_type));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems we can extract this common code from acquire_pessimistic_lock, acquire_pessimistic_lock_resumed and prewrite.

Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
@sticnarf
Copy link
Contributor

Please fix the conflict.

@MyonKeminta
Copy link
Contributor Author

I'll fix conflicts after #13777 is merged.

@MyonKeminta MyonKeminta requested review from sticnarf and TonsnakeLin and removed request for TonsnakeLin November 15, 2022 06:35
@ti-chi-bot ti-chi-bot added the status/LGT1 Status: PR - There is already 1 approval label Nov 15, 2022
@ti-chi-bot
Copy link
Member

@TonsnakeLin: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments.

In response to this:

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
Collaborator

@cfzjywxk cfzjywxk left a comment

Choose a reason for hiding this comment

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

LGTM

src/storage/mod.rs Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added status/LGT2 Status: PR - There are already 2 approvals and removed status/LGT1 Status: PR - There is already 1 approval labels Nov 16, 2022
@MyonKeminta
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

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

@ti-chi-bot
Copy link
Member

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

Commit hash: d3f0931

@ti-chi-bot ti-chi-bot added the status/can-merge Status: Can merge to base branch label Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none size/XXL 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.

None yet

5 participants