Search in sources :

Example 1 with CleanupResponse

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;
    }
}
Also used : CleanupResponse(org.tikv.kvproto.Kvrpcpb.CleanupResponse) TiClientInternalException(org.tikv.common.exception.TiClientInternalException) CleanupRequest(org.tikv.kvproto.Kvrpcpb.CleanupRequest) KVErrorHandler(org.tikv.common.operation.KVErrorHandler) RegionException(org.tikv.common.exception.RegionException) KeyException(org.tikv.common.exception.KeyException)

Example 2 with CleanupResponse

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;
    }
}
Also used : Kvrpcpb(org.tikv.kvproto.Kvrpcpb) KVErrorHandler(com.pingcap.tikv.operation.KVErrorHandler) RegionException(com.pingcap.tikv.exception.RegionException) KeyException(com.pingcap.tikv.exception.KeyException) CleanupResponse(org.tikv.kvproto.Kvrpcpb.CleanupResponse) TiClientInternalException(com.pingcap.tikv.exception.TiClientInternalException) TiRegion(com.pingcap.tikv.region.TiRegion) CleanupRequest(org.tikv.kvproto.Kvrpcpb.CleanupRequest) RegionStoreClient(com.pingcap.tikv.region.RegionStoreClient) AbstractRegionStoreClient(com.pingcap.tikv.region.AbstractRegionStoreClient)

Example 3 with CleanupResponse

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;
    }
}
Also used : CleanupResponse(org.tikv.kvproto.Kvrpcpb.CleanupResponse) TiClientInternalException(com.pingcap.tikv.exception.TiClientInternalException) CleanupRequest(org.tikv.kvproto.Kvrpcpb.CleanupRequest) KVErrorHandler(com.pingcap.tikv.operation.KVErrorHandler) RegionException(com.pingcap.tikv.exception.RegionException) KeyException(com.pingcap.tikv.exception.KeyException)

Example 4 with CleanupResponse

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;
    }
}
Also used : Kvrpcpb(org.tikv.kvproto.Kvrpcpb) KVErrorHandler(org.tikv.common.operation.KVErrorHandler) RegionException(org.tikv.common.exception.RegionException) KeyException(org.tikv.common.exception.KeyException) CleanupResponse(org.tikv.kvproto.Kvrpcpb.CleanupResponse) TiClientInternalException(org.tikv.common.exception.TiClientInternalException) CleanupRequest(org.tikv.kvproto.Kvrpcpb.CleanupRequest)

Aggregations

CleanupRequest (org.tikv.kvproto.Kvrpcpb.CleanupRequest)4 CleanupResponse (org.tikv.kvproto.Kvrpcpb.CleanupResponse)4 KeyException (com.pingcap.tikv.exception.KeyException)2 RegionException (com.pingcap.tikv.exception.RegionException)2 TiClientInternalException (com.pingcap.tikv.exception.TiClientInternalException)2 KVErrorHandler (com.pingcap.tikv.operation.KVErrorHandler)2 KeyException (org.tikv.common.exception.KeyException)2 RegionException (org.tikv.common.exception.RegionException)2 TiClientInternalException (org.tikv.common.exception.TiClientInternalException)2 KVErrorHandler (org.tikv.common.operation.KVErrorHandler)2 Kvrpcpb (org.tikv.kvproto.Kvrpcpb)2 AbstractRegionStoreClient (com.pingcap.tikv.region.AbstractRegionStoreClient)1 RegionStoreClient (com.pingcap.tikv.region.RegionStoreClient)1 TiRegion (com.pingcap.tikv.region.TiRegion)1