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

txn: fix the resolved txn status cache for pessimistic txn #1868 (#1871) #1872

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,13 @@ private TxnStatus getTxnStatusFromLock(BackOffer bo, Lock lock, long callerStart
while (true) {
try {
return getTxnStatus(
bo, lock.getTxnID(), lock.getPrimary(), callerStartTS, currentTS, rollbackIfNotExist);
bo,
lock.getTxnID(),
lock.getPrimary(),
callerStartTS,
currentTS,
rollbackIfNotExist,
lock);
} catch (TxnNotFoundException e) {
// If the error is something other than txnNotFoundErr, throw the error (network
// unavailable, tikv down, backoff timeout etc) to the caller.
Expand Down Expand Up @@ -294,7 +300,8 @@ private TxnStatus getTxnStatus(
ByteString primary,
Long callerStartTS,
Long currentTS,
boolean rollbackIfNotExist) {
boolean rollbackIfNotExist,
Lock lock) {
TxnStatus status = getResolved(txnID);
if (status != null) {
return status;
Expand Down Expand Up @@ -378,7 +385,25 @@ private TxnStatus getTxnStatus(
status.setTtl(resp.getLockTtl());
} else {
status.setCommitTS(resp.getCommitVersion());
saveResolved(txnID, status);

// If the transaction is still valid with ttl greater than zero, do nothing.
// If its status is certain:
// If transaction is already committed, the result could be cached.
// Otherwise:
// If l.LockType is pessimistic lock type:
// - if its primary lock is pessimistic too, the check txn status result should
// not be cached.
// - if its primary lock is prewrite lock type, the check txn status could be
// cached, todo.
// If l.lockType is prewrite lock type:
// - always cache the check txn status result.
// For prewrite locks, their primary keys should ALWAYS be the correct one and will NOT
// change.
if (status.isCommitted()
|| (lock != null
&& lock.getLockType() != org.tikv.kvproto.Kvrpcpb.Op.PessimisticLock)) {
saveResolved(txnID, status);
}
}

return status;
Expand Down