Search in sources :

Example 1 with KVErrorHandler

use of org.tikv.common.operation.KVErrorHandler in project client-java by tikv.

the class RegionStoreClient method scan.

public List<KvPair> scan(BackOffer backOffer, ByteString startKey, long version, boolean keyOnly) {
    boolean forWrite = false;
    while (true) {
        // we should refresh region
        region = regionManager.getRegionByKey(startKey, backOffer);
        Supplier<ScanRequest> request = () -> ScanRequest.newBuilder().setContext(makeContext(getResolvedLocks(version), this.storeType, backOffer.getSlowLog())).setStartKey(startKey).setVersion(version).setKeyOnly(keyOnly).setLimit(getConf().getScanBatchSize()).build();
        KVErrorHandler<ScanResponse> handler = new KVErrorHandler<>(regionManager, this, lockResolverClient, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> null, resolveLockResult -> addResolvedLocks(version, resolveLockResult.getResolvedLocks()), version, forWrite);
        ScanResponse resp = callWithRetry(backOffer, TikvGrpc.getKvScanMethod(), request, handler);
        if (isScanSuccess(backOffer, resp)) {
            return doScan(resp);
        }
    }
}
Also used : RawScanRequest(org.tikv.kvproto.Kvrpcpb.RawScanRequest) ScanRequest(org.tikv.kvproto.Kvrpcpb.ScanRequest) RawScanResponse(org.tikv.kvproto.Kvrpcpb.RawScanResponse) ScanResponse(org.tikv.kvproto.Kvrpcpb.ScanResponse) KVErrorHandler(org.tikv.common.operation.KVErrorHandler)

Example 2 with KVErrorHandler

use of org.tikv.common.operation.KVErrorHandler in project client-java by tikv.

the class RegionStoreClient method get.

/**
 * Fetch a value according to a key
 *
 * @param backOffer backOffer
 * @param key key to fetch
 * @param version key version
 * @return value
 * @throws TiClientInternalException TiSpark Client exception, unexpected
 * @throws KeyException Key may be locked
 */
public ByteString get(BackOffer backOffer, ByteString key, long version) throws TiClientInternalException, KeyException {
    boolean forWrite = false;
    Supplier<GetRequest> factory = () -> GetRequest.newBuilder().setContext(makeContext(getResolvedLocks(version), this.storeType, backOffer.getSlowLog())).setKey(key).setVersion(version).build();
    KVErrorHandler<GetResponse> handler = new KVErrorHandler<>(regionManager, this, lockResolverClient, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> resp.hasError() ? resp.getError() : null, resolveLockResult -> addResolvedLocks(version, resolveLockResult.getResolvedLocks()), version, forWrite);
    GetResponse resp = callWithRetry(backOffer, TikvGrpc.getKvGetMethod(), factory, handler);
    handleGetResponse(resp);
    return resp.getValue();
}
Also used : RawBatchGetRequest(org.tikv.kvproto.Kvrpcpb.RawBatchGetRequest) GetRequest(org.tikv.kvproto.Kvrpcpb.GetRequest) RawGetRequest(org.tikv.kvproto.Kvrpcpb.RawGetRequest) BatchGetRequest(org.tikv.kvproto.Kvrpcpb.BatchGetRequest) KVErrorHandler(org.tikv.common.operation.KVErrorHandler) BatchGetResponse(org.tikv.kvproto.Kvrpcpb.BatchGetResponse) GetResponse(org.tikv.kvproto.Kvrpcpb.GetResponse) RawBatchGetResponse(org.tikv.kvproto.Kvrpcpb.RawBatchGetResponse) RawGetResponse(org.tikv.kvproto.Kvrpcpb.RawGetResponse)

Example 3 with KVErrorHandler

use of org.tikv.common.operation.KVErrorHandler in project client-java by tikv.

the class RegionStoreClient method txnHeartBeat.

/**
 * TXN Heart Beat: update primary key ttl
 */
public void txnHeartBeat(BackOffer bo, ByteString primaryLock, long startTs, long ttl) {
    boolean forWrite = false;
    while (true) {
        Supplier<TxnHeartBeatRequest> factory = () -> TxnHeartBeatRequest.newBuilder().setContext(makeContext(storeType, bo.getSlowLog())).setStartVersion(startTs).setPrimaryLock(primaryLock).setAdviseLockTtl(ttl).build();
        KVErrorHandler<TxnHeartBeatResponse> handler = new KVErrorHandler<>(regionManager, this, lockResolverClient, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> resp.hasError() ? resp.getError() : null, resolveLockResult -> null, startTs, forWrite);
        TxnHeartBeatResponse resp = callWithRetry(bo, TikvGrpc.getKvTxnHeartBeatMethod(), factory, handler);
        if (isTxnHeartBeatSuccess(resp)) {
            return;
        }
    }
}
Also used : TxnHeartBeatRequest(org.tikv.kvproto.Kvrpcpb.TxnHeartBeatRequest) TxnHeartBeatResponse(org.tikv.kvproto.Kvrpcpb.TxnHeartBeatResponse) KVErrorHandler(org.tikv.common.operation.KVErrorHandler)

Example 4 with KVErrorHandler

use of org.tikv.common.operation.KVErrorHandler in project client-java by tikv.

the class RegionStoreClient method batchGet.

public List<KvPair> batchGet(BackOffer backOffer, Iterable<ByteString> keys, long version) {
    boolean forWrite = false;
    Supplier<BatchGetRequest> request = () -> BatchGetRequest.newBuilder().setContext(makeContext(getResolvedLocks(version), this.storeType, backOffer.getSlowLog())).addAllKeys(keys).setVersion(version).build();
    KVErrorHandler<BatchGetResponse> handler = new KVErrorHandler<>(regionManager, this, lockResolverClient, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> null, resolveLockResult -> addResolvedLocks(version, resolveLockResult.getResolvedLocks()), version, forWrite);
    BatchGetResponse resp = callWithRetry(backOffer, TikvGrpc.getKvBatchGetMethod(), request, handler);
    return handleBatchGetResponse(backOffer, resp, version);
}
Also used : RawBatchGetRequest(org.tikv.kvproto.Kvrpcpb.RawBatchGetRequest) BatchGetRequest(org.tikv.kvproto.Kvrpcpb.BatchGetRequest) BatchGetResponse(org.tikv.kvproto.Kvrpcpb.BatchGetResponse) RawBatchGetResponse(org.tikv.kvproto.Kvrpcpb.RawBatchGetResponse) KVErrorHandler(org.tikv.common.operation.KVErrorHandler)

Example 5 with KVErrorHandler

use of org.tikv.common.operation.KVErrorHandler in project client-java by tikv.

the class RegionStoreClient method splitRegion.

/**
 * Send SplitRegion request to tikv split a region at splitKey. splitKey must between current
 * region's start key and end key.
 *
 * @param splitKeys is the split points for a specific region.
 * @return a split region info.
 */
public List<Metapb.Region> splitRegion(Iterable<ByteString> splitKeys) {
    Supplier<SplitRegionRequest> request = () -> SplitRegionRequest.newBuilder().setContext(makeContext(storeType, SlowLogEmptyImpl.INSTANCE)).addAllSplitKeys(splitKeys).setIsRawKv(conf.isRawKVMode()).build();
    KVErrorHandler<SplitRegionResponse> handler = new KVErrorHandler<>(regionManager, this, null, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> null, resolveLockResult -> null, 0L, false);
    SplitRegionResponse resp = callWithRetry(ConcreteBackOffer.newGetBackOff(pdClient.getClusterId()), TikvGrpc.getSplitRegionMethod(), request, handler);
    if (resp == null) {
        this.regionManager.onRequestFail(region);
        throw new TiClientInternalException("SplitRegion Response failed without a cause");
    }
    if (resp.hasRegionError()) {
        throw new TiClientInternalException(String.format("failed to split region %d because %s", region.getId(), resp.getRegionError().toString()));
    }
    return resp.getRegionsList();
}
Also used : SplitRegionResponse(org.tikv.kvproto.Kvrpcpb.SplitRegionResponse) TiClientInternalException(org.tikv.common.exception.TiClientInternalException) SplitRegionRequest(org.tikv.kvproto.Kvrpcpb.SplitRegionRequest) KVErrorHandler(org.tikv.common.operation.KVErrorHandler)

Aggregations

KVErrorHandler (org.tikv.common.operation.KVErrorHandler)15 TiClientInternalException (org.tikv.common.exception.TiClientInternalException)8 KeyException (org.tikv.common.exception.KeyException)7 RegionException (org.tikv.common.exception.RegionException)7 Kvrpcpb (org.tikv.kvproto.Kvrpcpb)5 BatchGetRequest (org.tikv.kvproto.Kvrpcpb.BatchGetRequest)3 RawBatchGetRequest (org.tikv.kvproto.Kvrpcpb.RawBatchGetRequest)3 BatchGetResponse (org.tikv.kvproto.Kvrpcpb.BatchGetResponse)2 CleanupRequest (org.tikv.kvproto.Kvrpcpb.CleanupRequest)2 CleanupResponse (org.tikv.kvproto.Kvrpcpb.CleanupResponse)2 CommitRequest (org.tikv.kvproto.Kvrpcpb.CommitRequest)2 GetRequest (org.tikv.kvproto.Kvrpcpb.GetRequest)2 PrewriteRequest (org.tikv.kvproto.Kvrpcpb.PrewriteRequest)2 RawBatchGetResponse (org.tikv.kvproto.Kvrpcpb.RawBatchGetResponse)2 RawGetRequest (org.tikv.kvproto.Kvrpcpb.RawGetRequest)2 RawScanRequest (org.tikv.kvproto.Kvrpcpb.RawScanRequest)2 ScanRequest (org.tikv.kvproto.Kvrpcpb.ScanRequest)2 SplitRegionRequest (org.tikv.kvproto.Kvrpcpb.SplitRegionRequest)2 TxnHeartBeatRequest (org.tikv.kvproto.Kvrpcpb.TxnHeartBeatRequest)2 DAGRequest (com.pingcap.tidb.tipb.DAGRequest)1