-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
store: upgrade the CheckTxnStatus API #13123
Merged
Merged
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6181920
store: upgrade the CheckTxnStatus API
tiancaiamao 576c051
Merge branch 'master' into update-check-txn-status
tiancaiamao c0285ba
make golint happy
tiancaiamao e7aad0d
address comment
tiancaiamao 8da07bc
Merge branch 'master' into update-check-txn-status
tiancaiamao 8106b33
address comment
tiancaiamao 386ca77
write the rollback key in mocktikv
tiancaiamao bba8d04
tiny clean up
tiancaiamao fbc600f
address comment
tiancaiamao 5fb661a
make CI stable
tiancaiamao bbd42e3
address comment
tiancaiamao e77e17b
fix a data race
tiancaiamao 64721b2
fix data race
tiancaiamao c01bc0a
Merge branch 'master' into update-check-txn-status
tiancaiamao d4e192a
address comment
tiancaiamao 0f3ae0f
make CI stable
tiancaiamao 913e29d
Merge branch 'master' into update-check-txn-status
tiancaiamao 1aa8f9b
try to make CI stable
tiancaiamao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -882,7 +882,7 @@ func rollbackKey(db *leveldb.DB, batch *leveldb.Batch, key []byte, startTS uint6 | |
} | ||
// If current transaction's lock exist. | ||
if ok && dec.lock.startTS == startTS { | ||
if err = rollbackLock(batch, dec.lock, key, startTS); err != nil { | ||
if err = rollbackLock(batch, key, startTS); err != nil { | ||
return errors.Trace(err) | ||
} | ||
return nil | ||
|
@@ -919,7 +919,7 @@ func rollbackKey(db *leveldb.DB, batch *leveldb.Batch, key []byte, startTS uint6 | |
return nil | ||
} | ||
|
||
func rollbackLock(batch *leveldb.Batch, lock mvccLock, key []byte, startTS uint64) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This parameter is not used in the function, so I remove it |
||
func rollbackLock(batch *leveldb.Batch, key []byte, startTS uint64) error { | ||
tomb := mvccValue{ | ||
valueType: typeRollback, | ||
startTS: startTS, | ||
|
@@ -980,7 +980,7 @@ func (mvcc *MVCCLevelDB) Cleanup(key []byte, startTS, currentTS uint64) error { | |
if ok && dec.lock.startTS == startTS { | ||
// If the lock has already outdated, clean up it. | ||
if currentTS == 0 || uint64(oracle.ExtractPhysical(dec.lock.startTS))+dec.lock.ttl < uint64(oracle.ExtractPhysical(currentTS)) { | ||
if err = rollbackLock(batch, dec.lock, key, startTS); err != nil { | ||
if err = rollbackLock(batch, key, startTS); err != nil { | ||
return err | ||
} | ||
return mvcc.db.Write(batch, nil) | ||
|
@@ -1032,7 +1032,7 @@ func (mvcc *MVCCLevelDB) Cleanup(key []byte, startTS, currentTS uint64) error { | |
// primaryKey + lockTS together could locate the primary lock. | ||
// callerStartTS is the start ts of reader transaction. | ||
// currentTS is the current ts, but it may be inaccurate. Just use it to check TTL. | ||
func (mvcc *MVCCLevelDB) CheckTxnStatus(primaryKey []byte, lockTS, callerStartTS, currentTS uint64) (uint64, uint64, error) { | ||
func (mvcc *MVCCLevelDB) CheckTxnStatus(primaryKey []byte, lockTS, callerStartTS, currentTS uint64, rollbackIfNotExist bool) (uint64, uint64, error) { | ||
mvcc.mu.Lock() | ||
defer mvcc.mu.Unlock() | ||
|
||
|
@@ -1057,7 +1057,7 @@ func (mvcc *MVCCLevelDB) CheckTxnStatus(primaryKey []byte, lockTS, callerStartTS | |
|
||
// If the lock has already outdated, clean up it. | ||
if uint64(oracle.ExtractPhysical(lock.startTS))+lock.ttl < uint64(oracle.ExtractPhysical(currentTS)) { | ||
if err = rollbackLock(batch, lock, primaryKey, lockTS); err != nil { | ||
if err = rollbackLock(batch, primaryKey, lockTS); err != nil { | ||
return 0, 0, errors.Trace(err) | ||
} | ||
if err = mvcc.db.Write(batch, nil); err != nil { | ||
|
@@ -1112,9 +1112,27 @@ func (mvcc *MVCCLevelDB) CheckTxnStatus(primaryKey []byte, lockTS, callerStartTS | |
} | ||
|
||
// If current transaction is not prewritted before, it may be pessimistic lock. | ||
// When pessimistic lock rollback, it may not leave a 'rollbacked' tombstone. | ||
logutil.BgLogger().Debug("CheckTxnStatus can't find the primary lock, pessimistic rollback?") | ||
return 0, 0, nil | ||
// When pessimistic txn rollback statement, it may not leave a 'rollbacked' tombstone. | ||
|
||
// Or maybe caused by concurrent prewrite operation. | ||
// Especially in the non-block reading case, the secondary lock is likely to be | ||
// written before the primary lock. | ||
|
||
if rollbackIfNotExist { | ||
batch := &leveldb.Batch{} | ||
if err := rollbackLock(batch, primaryKey, lockTS); err != nil { | ||
return 0, 0, errors.Trace(err) | ||
} | ||
if err := mvcc.db.Write(batch, nil); err != nil { | ||
return 0, 0, errors.Trace(err) | ||
} | ||
return 0, 0, nil | ||
} | ||
|
||
return 0, 0, &ErrTxnNotFound{kvrpcpb.TxnNotFound{ | ||
StartTs: lockTS, | ||
PrimaryKey: primaryKey, | ||
}} | ||
} | ||
|
||
// TxnHeartBeat implements the MVCCStore interface. | ||
|
@@ -1220,7 +1238,7 @@ func (mvcc *MVCCLevelDB) ResolveLock(startKey, endKey []byte, startTS, commitTS | |
if commitTS > 0 { | ||
err = commitLock(batch, dec.lock, currKey, startTS, commitTS) | ||
} else { | ||
err = rollbackLock(batch, dec.lock, currKey, startTS) | ||
err = rollbackLock(batch, currKey, startTS) | ||
} | ||
if err != nil { | ||
return errors.Trace(err) | ||
|
@@ -1260,7 +1278,7 @@ func (mvcc *MVCCLevelDB) BatchResolveLock(startKey, endKey []byte, txnInfos map[ | |
if commitTS > 0 { | ||
err = commitLock(batch, dec.lock, currKey, dec.lock.startTS, commitTS) | ||
} else { | ||
err = rollbackLock(batch, dec.lock, currKey, dec.lock.startTS) | ||
err = rollbackLock(batch, currKey, dec.lock.startTS) | ||
} | ||
if err != nil { | ||
return errors.Trace(err) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
I think you need to cover the case where the last parameter is
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.
Done