-
Notifications
You must be signed in to change notification settings - Fork 233
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 aggressive-locking mechanism and support locking with conflict #528
Add aggressive-locking mechanism and support locking with conflict #528
Conversation
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
f11b130
to
552885c
Compare
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
7241c1c
to
7736f37
Compare
Signed-off-by: MyonKeminta <[email protected]>
7736f37
to
1078efa
Compare
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
/race-test |
/run-race-test |
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
The tests look not sufficient to me now, but this PR is large enough. Considering that this PR is not expected to affect the original logic, I think I can add more tests in further PRs. |
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
…simistic-lock-optimization
Signed-off-by: MyonKeminta <[email protected]>
txnkv/transaction/pessimistic.go
Outdated
if err != nil { | ||
return true, err | ||
} | ||
if regionErr != nil { | ||
// For other region error and the fake region error, backoff because | ||
// there's something wrong. | ||
// For the real EpochNotMatch error, don't backoff. | ||
if regionErr.GetEpochNotMatch() == nil || locate.IsFakeRegionError(regionErr) { | ||
err = bo.Backoff(retry.BoRegionMiss, errors.New(regionErr.String())) | ||
if err != nil { | ||
return true, err | ||
} | ||
} | ||
same, err := batch.relocate(bo, c.store.GetRegionCache()) | ||
if err != nil { | ||
return true, err | ||
} | ||
if same { | ||
return false, nil | ||
} | ||
err = c.pessimisticLockMutations(bo, action.LockCtx, action.wakeUpMode, batch.mutations) | ||
return true, err | ||
} | ||
if resp.Resp == nil { | ||
return true, errors.WithStack(tikverr.ErrBodyMissing) | ||
} |
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.
There seem to be some duplicates with the implementation in handlePessimisticLockResponseForceMode
, could it be abstracted to a single function?
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.
Ok. Btw I just realize that some of the code to handle the partially-successful cases is not removed. I'll remove them.
txnkv/transaction/pessimistic.go
Outdated
var locks []*txnlock.Lock | ||
for _, keyErr := range keyErrs { | ||
// Check already exists error | ||
if alreadyExist := keyErr.GetAlreadyExist(); alreadyExist != nil { | ||
e := &tikverr.ErrKeyExist{AlreadyExist: alreadyExist} | ||
return true, c.extractKeyExistsErr(e) | ||
} | ||
if deadlock := keyErr.Deadlock; deadlock != nil { | ||
return true, errors.WithStack(&tikverr.ErrDeadlock{Deadlock: deadlock}) | ||
} | ||
|
||
// Extract lock from key error | ||
lock, err1 := txnlock.ExtractLockFromKeyErr(keyErr) | ||
if err1 != nil { | ||
return true, err1 | ||
} | ||
locks = append(locks, lock) | ||
} |
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.
There seem to be some duplicates with the implementation in handlePessimisticLockResponseForceMode
, could it be abstracted to a single function?
@@ -594,6 +650,185 @@ func (txn *KVTxn) LockKeysWithWaitTime(ctx context.Context, lockWaitTime int64, | |||
return txn.LockKeys(ctx, lockCtx, keysInput...) | |||
} | |||
|
|||
// StartAggressiveLocking makes the transaction enters aggressive locking state. |
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.
The aggressive locked keys processing functions are complex, we may need more SQL tests to verify it's working as expected.
txnkv/transaction/pessimistic.go
Outdated
|
||
if retryMutations != nil && retryMutations.Len() < batch.mutations.Len() { | ||
// The request may be partially succeeded. Replace the request with remaining mutations. | ||
// The primary lock (if it's in this request) must have been succeeded. |
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.
Where is it ensured? (Though it's not important when we only enable this mode for single key)
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.
TiKV should ensure it. But since this kind of code is useless in current version, I'm now removing them.
… happen currently Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
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: MyonKeminta <[email protected]>
@sticnarf PTAL |
Requires: tikv/tikv#12749
This PR adapts to the new behavior of acquire_pessimistic_lock requests in the PR above.
This PR is experimental and still under development.