-
Notifications
You must be signed in to change notification settings - Fork 227
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
PessimisticLock: Lock the specified key only if the key exists #561
Conversation
1dc10e3
to
6ccabb7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there's better to be some unit tests, which requires the lock_if_exist logic to be implemented in mocktikv
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Co-authored-by: MyonKeminta <9948422+MyonKeminta@users.noreply.github.com> Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Signed-off-by: dongxu <i@huangdx.net> Signed-off-by: dongxu <i@huangdx.net> Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Signed-off-by: dongxu <i@huangdx.net> Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Signed-off-by: cfzjywxk <lsswxrxr@163.com> Signed-off-by: cfzjywxk <lsswxrxr@163.com> Signed-off-by: TonsnakeLin <lpbgytong@163.com>
* replace kvproto Signed-off-by: ekexium <eke@fastmail.com> * support NeedConflictCheck Signed-off-by: ekexium <eke@fastmail.com> * fix mutation encoding Signed-off-by: ekexium <eke@fastmail.com> * support temporary flag Signed-off-by: ekexium <eke@fastmail.com> * update kvproto Signed-off-by: ekexium <eke@fastmail.com> * fix style Signed-off-by: ekexium <eke@fastmail.com> * add an option to enable the behavior Signed-off-by: ekexium <eke@fastmail.com> * replace AfterCheckPoint with existing canModity Signed-off-by: ekexium <eke@fastmail.com> * UpdateFlag do not unset temporary flag Signed-off-by: ekexium <eke@fastmail.com> * remove unused function Signed-off-by: ekexium <eke@fastmail.com> * update tidb dependency Signed-off-by: ekexium <eke@fastmail.com> update tidb dependency Signed-off-by: ekexium <eke@fastmail.com> * fix test Signed-off-by: ekexium <eke@fastmail.com> * do no unset flag on read Signed-off-by: ekexium <eke@fastmail.com> * update tidb dependency Signed-off-by: ekexium <eke@fastmail.com> * update comment Signed-off-by: ekexium <eke@fastmail.com> Signed-off-by: ekexium <eke@fastmail.com>
881615b
to
f3dc9f9
Compare
…ize_lock_if_exists
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Besides this case, if k1 doesn't exist, but we succeed locking k2 and k3, we'll face the same problem. If we don't want to introduce an anchor key, we can disable the feature if the primary key is not selected yet. |
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
LockOnlyIfExists request is used only for RC isolation on TiDB, I think the scene above is reasonable,right ? |
|
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
If lock failed with LockIfExists flag, I will unset the primary key and reset ttlManager |
@sticnarf @MyonKeminta PTAL, thank you!! |
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
…Lin/client-go into optimize_lock_if_exists
It seems you meant when the pessimistic lock request succeeded but the primary lock is not acquired due to not exist, instead of failing to execute the pessimistic lock request. Though you unset the primary and cancel ttlManager in the client side (which I think you can actually avoid starting the ttlManager instead of start it and then stop it), there still exists another problem. Consider the case that a lock request to [k1, k2, k3] where k1 is the primary, and k2, k3 is locked but k1 is untouched due to not exist. In this case, k2 and k3 will still be locked with their primary pointing to k1. This causes other transactions cannot determine the transaction's state correctly through the lock on k2 and k3, which I'm afraid may potentially lead to other correctness issues. |
Thanks! As @sticnarf said, I will make the LockIfExists effective only when primary key is selected |
If the use case is limited to single key point get, the current solution may suffice, because no other key may refer to a non-existing primary lock. So, another solution is to check whether only one key is passed to |
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
…Lin/client-go into optimize_lock_if_exists
txnkv/transaction/txn.go
Outdated
return errors.New("LockOnlyIfExists is set for Lock Context, but ReturnValues is not set") | ||
return &tikverr.ErrLockOnlyIfExistsNoReturnValue{ | ||
ForUpdateTs: lockCtx.ForUpdateTS, | ||
LockKey: keysInput[0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to check len(keysInput) > 0
first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if len(keysInput) == 0, it prints "{}".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if len(keysInput) == 0, would keysInput[0]
cause index out of range
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Signed-off-by: TonsnakeLin <lpbgytong@163.com>
1. current process
Currently, TiKV locks the specified keys for pessimistic lock requests whether it exists or not. TiDB sends a get request to judge whether the keys exists on the TiKV firstly, then sends a pessimistic lock request to TiKV if the key exists, It makes and additional rpc request.
2. what changed
We add a flag
LockIfExists
for pessimistic lock request and TiKV will check the flag to decide how to execute the lock process.This PR is depended on the PRs bellow.