-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
*: support pessimistic transaction (experimental feature) #10297
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10297 +/- ##
==========================================
Coverage ? 77.012%
==========================================
Files ? 412
Lines ? 86232
Branches ? 0
==========================================
Hits ? 66409
Misses ? 14754
Partials ? 5069 |
/run-all-tests |
b0ef687
to
41d79c7
Compare
/run-all-tests tidb-test=pr/795 |
|
||
func (s *testSessionSuite) TestPessimisticTxn(c *C) { | ||
if !config.GetGlobalConfig().PessimisticTxn.Enable { | ||
c.Skip("pessimistic transaction is not enabled") |
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 default conf is false, this test will never run?!
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.
Yes.
LGTM |
The make dev test takes too long and seems something wrong in this pr |
store/tikv/2pc.go
Outdated
@@ -130,7 +160,9 @@ func newTwoPhaseCommitter(txn *tikvTxn, connID uint64) (*twoPhaseCommitter, erro | |||
} | |||
delCnt++ | |||
} | |||
keys = append(keys, k) | |||
if isPessimistic && !bytes.Equal(k, c.primaryKey) { |
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 should be?
if isPessimistic && !bytes.Equal(k, c.primaryKey) { | |
if !isPessimistic || !bytes.Equal(k, c.primaryKey) { |
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.
after dig, maybe old one is ok too, c.primaryKey always be null if isPessimistic=true
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.
ping @coocood
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.
@lysu I know, but add isPessimistic
is more explicit that this code is only related to pessimistic lock.
rest LGTM for pessimistic disabled logic |
} | ||
|
||
for _, pair := range txn.assertions { | ||
mutation, ok := mutations[string(pair.key)] | ||
if !ok { | ||
logutil.Logger(context.Background()).Error("ASSERTION FAIL!!! assertion exists but no mutation?", | ||
zap.Stringer("assertion", pair)) | ||
// It's possible when a transaction inserted a key then deleted it later. |
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.
@tiancaiamao is this reasonable?
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
…tic-txn Conflicts: go.mod go.sum store/mockstore/mocktikv/mvcc_leveldb.go
make check always hang for very long time |
/run-all-tests |
What problem does this PR solve?
Avoid transaction failure caused by write conflict, especially when the transaction cannot be retried automatically.
What is changed and how it works?
BEGIN LOCK
syntax to start a new pessimistic transaction.INSERT
/UPDATE
/DELETE
/SELECT FOR UPDATE
.Check List
Tests
Code changes
Side effects
Related changes