Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions dev/proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ if [ -d $proto_dir ]; then
fi

repos=("https://github.com/pingcap/kvproto" "https://github.com/pingcap/raft-rs" "https://github.com/pingcap/tipb")
commits=(3056ca36e6f2a71a9fc7ba7135e6b119fd977553 b9891b673573fad77ebcf9bbe0969cf945841926 c4d518eb1d60c21f05b028b36729e64610346dac)
commits=(971c6f2217153da745d51886f94d7b701dec9799 b9891b673573fad77ebcf9bbe0969cf945841926 c4d518eb1d60c21f05b028b36729e64610346dac)

for i in "${!repos[@]}"; do
for i in "${!repos[@]}"; do
repo_name=$(basename ${repos[$i]})
git_command="git -C $repo_name"

Expand Down
39 changes: 36 additions & 3 deletions src/main/java/org/tikv/txn/LockResolverClientV4.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.tikv.kvproto.TikvGrpc;
import org.tikv.kvproto.TikvGrpc.TikvBlockingStub;
import org.tikv.kvproto.TikvGrpc.TikvFutureStub;
import org.tikv.txn.exception.PrimaryMismatchException;
import org.tikv.txn.exception.TxnNotFoundException;
import org.tikv.txn.exception.WriteConflictException;

Expand Down Expand Up @@ -114,7 +115,22 @@
Set<Long> pushed = new HashSet<>(locks.size());

for (Lock l : locks) {
TxnStatus status = getTxnStatusFromLock(bo, l, callerStartTS);

TxnStatus status = null;

try {
status = getTxnStatusFromLock(bo, l, callerStartTS);
} catch (PrimaryMismatchException e) {

Check warning on line 123 in src/main/java/org/tikv/txn/LockResolverClientV4.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tikv/txn/LockResolverClientV4.java#L123

Added line #L123 was not covered by tests
if (l.getLockType() != Kvrpcpb.Op.PessimisticLock) {
logger.info(
String.format(

Check warning on line 126 in src/main/java/org/tikv/txn/LockResolverClientV4.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tikv/txn/LockResolverClientV4.java#L125-L126

Added lines #L125 - L126 were not covered by tests
"unexpected primaryMismatch error occurred on a non-pessimistic lock, lock: %s",
l));
throw e;

Check warning on line 129 in src/main/java/org/tikv/txn/LockResolverClientV4.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tikv/txn/LockResolverClientV4.java#L129

Added line #L129 was not covered by tests
}
// Pessimistic rollback the pessimistic lock as it points to an invalid primary.
status = new TxnStatus();

Check warning on line 132 in src/main/java/org/tikv/txn/LockResolverClientV4.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tikv/txn/LockResolverClientV4.java#L132

Added line #L132 was not covered by tests
}

if (status.getTtl() == 0) {
Set<RegionVerID> cleanRegion =
Expand Down Expand Up @@ -231,7 +247,13 @@
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 @@ -271,12 +293,16 @@
ByteString primary,
Long callerStartTS,
Long currentTS,
boolean rollbackIfNotExist) {
boolean rollbackIfNotExist,
Lock lock) {
TxnStatus status = getResolved(txnID);
if (status != null) {
return status;
}

boolean resolvingPessimisticLock =
(lock != null && lock.getLockType() == Kvrpcpb.Op.PessimisticLock);

// CheckTxnStatus may meet the following cases:
// 1. LOCK
// 1.1 Lock expired -- orphan lock, fail to update TTL, crash recovery etc.
Expand All @@ -295,6 +321,7 @@
.setCallerStartTs(callerStartTS)
.setCurrentTs(currentTS)
.setRollbackIfNotExist(rollbackIfNotExist)
.setVerifyIsPrimary(true)
.build();
};

Expand Down Expand Up @@ -338,6 +365,12 @@
throw new TxnNotFoundException();
}

if (resolvingPessimisticLock && keyError.hasPrimaryMismatch()) {
logger.info(
String.format("getTxnStatus was called on secondary lock. err: %s", keyError));
throw new PrimaryMismatchException();

Check warning on line 371 in src/main/java/org/tikv/txn/LockResolverClientV4.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tikv/txn/LockResolverClientV4.java#L369-L371

Added lines #L369 - L371 were not covered by tests
}

logger.error(String.format("unexpected cleanup err: %s, tid: %d", keyError, txnID));
throw new KeyException(keyError);
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/tikv/txn/exception/PrimaryMismatchException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2023 TiKV Project Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.tikv.txn.exception;

public class PrimaryMismatchException extends RuntimeException {}

Check warning on line 20 in src/main/java/org/tikv/txn/exception/PrimaryMismatchException.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tikv/txn/exception/PrimaryMismatchException.java#L20

Added line #L20 was not covered by tests