use of org.tikv.kvproto.Kvrpcpb.CleanupResponse in project client-java by tikv.
the class LockResolverClientV2 method getTxnStatus.
private Long getTxnStatus(BackOffer bo, Long txnID, ByteString primary) {
Long status = getResolved(txnID);
if (status != null) {
return status;
}
while (true) {
// refresh region
region = regionManager.getRegionByKey(primary);
Supplier<CleanupRequest> factory = () -> CleanupRequest.newBuilder().setContext(region.getLeaderContext()).setKey(primary).setStartVersion(txnID).build();
KVErrorHandler<CleanupResponse> handler = new KVErrorHandler<>(regionManager, this, this, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> resp.hasError() ? resp.getError() : null, resolveLockResult -> null, 0L, false);
CleanupResponse resp = callWithRetry(bo, TikvGrpc.getKvCleanupMethod(), factory, handler);
status = 0L;
if (resp == null) {
logger.error("getKvCleanupMethod failed without a cause");
regionManager.onRequestFail(region);
bo.doBackOff(BoRegionMiss, new TiClientInternalException("getKvCleanupMethod failed without a cause"));
continue;
}
if (resp.hasRegionError()) {
bo.doBackOff(BoRegionMiss, new RegionException(resp.getRegionError()));
continue;
}
if (resp.hasError()) {
logger.error(String.format("unexpected cleanup err: %s, tid: %d", resp.getError(), txnID));
throw new KeyException(resp.getError());
}
if (resp.getCommitVersion() != 0) {
status = resp.getCommitVersion();
}
saveResolved(txnID, status);
return status;
}
}
use of org.tikv.kvproto.Kvrpcpb.CleanupResponse in project tispark by pingcap.
the class LockResolverClientV3 method getTxnStatus.
private TxnStatus getTxnStatus(BackOffer bo, Long txnID, ByteString primary, Long currentTS) {
TxnStatus status = getResolved(txnID);
if (status != null) {
return status;
}
Supplier<CleanupRequest> factory = () -> {
TiRegion primaryKeyRegion = regionManager.getRegionByKey(primary);
return CleanupRequest.newBuilder().setContext(primaryKeyRegion.getContext()).setKey(primary).setStartVersion(txnID).setCurrentTs(currentTS).build();
};
status = new TxnStatus();
while (true) {
// new RegionStoreClient for PrimaryKey
RegionStoreClient primaryKeyRegionStoreClient = clientBuilder.build(primary);
TiRegion primaryKeyRegion = primaryKeyRegionStoreClient.getRegion();
KVErrorHandler<CleanupResponse> handler = new KVErrorHandler<>(regionManager, primaryKeyRegionStoreClient, primaryKeyRegionStoreClient.lockResolverClient, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> resp.hasError() ? resp.getError() : null, resolveLockResult -> null, 0L, false);
CleanupResponse resp = primaryKeyRegionStoreClient.callWithRetry(bo, TikvGrpc.getKvCleanupMethod(), factory, handler);
if (resp == null) {
logger.error("getKvCleanupMethod failed without a cause");
regionManager.onRequestFail(primaryKeyRegion);
bo.doBackOff(BoRegionMiss, new TiClientInternalException("getKvCleanupMethod failed without a cause"));
continue;
}
if (resp.hasRegionError()) {
bo.doBackOff(BoRegionMiss, new RegionException(resp.getRegionError()));
continue;
}
if (resp.hasError()) {
Kvrpcpb.KeyError keyError = resp.getError();
// the TTL.
if (keyError.hasLocked()) {
Kvrpcpb.LockInfo lockInfo = keyError.getLocked();
return new TxnStatus(lockInfo.getLockTtl(), 0L);
}
logger.error(String.format("unexpected cleanup err: %s, tid: %d", keyError, txnID));
throw new KeyException(keyError);
}
if (resp.getCommitVersion() != 0) {
status = new TxnStatus(0L, resp.getCommitVersion());
}
saveResolved(txnID, status);
return status;
}
}
use of org.tikv.kvproto.Kvrpcpb.CleanupResponse in project tispark by pingcap.
the class LockResolverClientV2 method getTxnStatus.
private Long getTxnStatus(BackOffer bo, Long txnID, ByteString primary) {
Long status = getResolved(txnID);
if (status != null) {
return status;
}
while (true) {
// refresh region
region = regionManager.getRegionByKey(primary);
Supplier<CleanupRequest> factory = () -> CleanupRequest.newBuilder().setContext(region.getContext()).setKey(primary).setStartVersion(txnID).build();
KVErrorHandler<CleanupResponse> handler = new KVErrorHandler<>(regionManager, this, this, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> resp.hasError() ? resp.getError() : null, resolveLockResult -> null, 0L, false);
CleanupResponse resp = callWithRetry(bo, TikvGrpc.getKvCleanupMethod(), factory, handler);
status = 0L;
if (resp == null) {
logger.error("getKvCleanupMethod failed without a cause");
regionManager.onRequestFail(region);
bo.doBackOff(BoRegionMiss, new TiClientInternalException("getKvCleanupMethod failed without a cause"));
continue;
}
if (resp.hasRegionError()) {
bo.doBackOff(BoRegionMiss, new RegionException(resp.getRegionError()));
continue;
}
if (resp.hasError()) {
logger.error(String.format("unexpected cleanup err: %s, tid: %d", resp.getError(), txnID));
throw new KeyException(resp.getError());
}
if (resp.getCommitVersion() != 0) {
status = resp.getCommitVersion();
}
saveResolved(txnID, status);
return status;
}
}
use of org.tikv.kvproto.Kvrpcpb.CleanupResponse in project client-java by tikv.
the class LockResolverClientV3 method getTxnStatus.
private TxnStatus getTxnStatus(BackOffer bo, Long txnID, ByteString primary, Long currentTS) {
TxnStatus status = getResolved(txnID);
if (status != null) {
return status;
}
Supplier<CleanupRequest> factory = () -> {
TiRegion primaryKeyRegion = regionManager.getRegionByKey(primary);
return CleanupRequest.newBuilder().setContext(primaryKeyRegion.getLeaderContext()).setKey(primary).setStartVersion(txnID).setCurrentTs(currentTS).build();
};
status = new TxnStatus();
while (true) {
TiRegion primaryKeyRegion = regionManager.getRegionByKey(primary);
// new RegionStoreClient for PrimaryKey
RegionStoreClient primaryKeyRegionStoreClient = clientBuilder.build(primary);
KVErrorHandler<CleanupResponse> handler = new KVErrorHandler<>(regionManager, primaryKeyRegionStoreClient, primaryKeyRegionStoreClient.lockResolverClient, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> resp.hasError() ? resp.getError() : null, resolveLockResult -> null, 0L, false);
CleanupResponse resp = primaryKeyRegionStoreClient.callWithRetry(bo, TikvGrpc.getKvCleanupMethod(), factory, handler);
if (resp == null) {
logger.error("getKvCleanupMethod failed without a cause");
regionManager.onRequestFail(primaryKeyRegion);
bo.doBackOff(BoRegionMiss, new TiClientInternalException("getKvCleanupMethod failed without a cause"));
continue;
}
if (resp.hasRegionError()) {
bo.doBackOff(BoRegionMiss, new RegionException(resp.getRegionError()));
continue;
}
if (resp.hasError()) {
Kvrpcpb.KeyError keyError = resp.getError();
// the TTL.
if (keyError.hasLocked()) {
Kvrpcpb.LockInfo lockInfo = keyError.getLocked();
return new TxnStatus(lockInfo.getLockTtl(), 0L);
}
logger.error(String.format("unexpected cleanup err: %s, tid: %d", keyError, txnID));
throw new KeyException(keyError);
}
if (resp.getCommitVersion() != 0) {
status = new TxnStatus(0L, resp.getCommitVersion());
}
saveResolved(txnID, status);
return status;
}
}
Aggregations