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

Add for_update_ts check to PrewriteRequest #1096

Merged

Conversation

MyonKeminta
Copy link
Contributor

@MyonKeminta MyonKeminta commented Mar 30, 2023

Ref: tikv/tikv#14311

Naming suggestions are welcome...

Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
@MyonKeminta MyonKeminta marked this pull request as ready for review April 6, 2023 06:12
@ekexium
Copy link
Contributor

ekexium commented Apr 6, 2023

Maybe it would be better to rename check to constraint?
I'm not quite sure if allowing for_update_ts < expected is a good idea. It makes things a bit difficult to reason about. If we do, then the name could be something like max_allowed... or ...upper_bound

@MyonKeminta
Copy link
Contributor Author

Maybe it would be better to rename check to constraint? I'm not quite sure if allowing for_update_ts < expected is a good idea. It makes things a bit difficult to reason about. If we do, then the name could be something like max_allowed... or ...upper_bound

The reason of allowing "<" is that it can guarantee there are no not-detected write conflict. The detail was discussed in the issue tikv/tikv#14311 . Does that make sense to you?

@ekexium
Copy link
Contributor

ekexium commented Apr 6, 2023

Yeah I've checked that.
There is a loss of pessimistic lock in the example you gave, so it is acceptable to return a PesLockNotFound error.
IMO if simply rejecting for_update_ts < expected cannot cause correctness problems and is much unlikely to happen (at least in normal environmetns), but can reduce the cognitive load (for everyone reading this piece of code and wondering the same question), then it is worth considering.

@MyonKeminta
Copy link
Contributor Author

@cfzjywxk PTAL, how's your opinion?

@cfzjywxk
Copy link
Contributor

cfzjywxk commented Apr 6, 2023

Permitting for_update_ts < expected creates confusion and requires additional effort to ensure its accuracy. Perhaps we could implement an exact check and reject the replayed pessimistic lock immediately, as this occurrence is infrequent.

If testing reveals scenarios that were not previously considered and may result in a significant number of replayed pessimistic locks, maybe we could take them into further consideration.

@@ -120,6 +128,9 @@ message PrewriteRequest {
uint64 max_commit_ts = 14;
// The level of assertion to use on this prewrte request.
AssertionLevel assertion_level = 15;
// for_update_ts constriants that should be checked when prewriting a pessimistic transaction.
// See https://github.com/tikv/tikv/issues/14311
repeated ForUpdateTSConstraint for_update_ts_constraints = 16;
Copy link
Contributor

Choose a reason for hiding this comment

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

As the fair lock mode supports only single key lock now, does it mean for a transaction the maximum length of this array is txn.total_statment_number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. It's possible that a statement calls LockKeys more than once and locks one key in each call.

@MyonKeminta
Copy link
Contributor Author

Ok let's ignore the "<" case and only allow exactly equal. I'll change the name back to expected_for_update_ts.

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

@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

@MyonKeminta MyonKeminta merged commit ce835ae into pingcap:master Apr 6, 2023
3 checks passed
@MyonKeminta MyonKeminta deleted the m/prewrite-check-for-update-ts branch April 6, 2023 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants