Search in sources :

Example 11 with KVErrorHandler

use of com.pingcap.tikv.operation.KVErrorHandler in project tispark by pingcap.

the class RegionStoreClient method rawBatchPut.

public void rawBatchPut(BackOffer backOffer, List<KvPair> kvPairs, long ttl, boolean atomic) {
    if (kvPairs.isEmpty()) {
        return;
    }
    Supplier<RawBatchPutRequest> factory = () -> RawBatchPutRequest.newBuilder().setContext(region.getContext()).addAllPairs(kvPairs).setTtl(ttl).setForCas(atomic).build();
    KVErrorHandler<RawBatchPutResponse> handler = new KVErrorHandler<>(regionManager, this, resp -> resp.hasRegionError() ? resp.getRegionError() : null);
    RawBatchPutResponse resp = callWithRetry(backOffer, TikvGrpc.getRawBatchPutMethod(), factory, handler);
    handleRawBatchPut(resp);
}
Also used : RawBatchPutRequest(org.tikv.kvproto.Kvrpcpb.RawBatchPutRequest) KVErrorHandler(com.pingcap.tikv.operation.KVErrorHandler) RawBatchPutResponse(org.tikv.kvproto.Kvrpcpb.RawBatchPutResponse)

Example 12 with KVErrorHandler

use of com.pingcap.tikv.operation.KVErrorHandler in project tispark by pingcap.

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(region.getContext(getResolvedLocks(version))).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(com.pingcap.tikv.operation.KVErrorHandler) RawBatchGetResponse(org.tikv.kvproto.Kvrpcpb.RawBatchGetResponse) BatchGetResponse(org.tikv.kvproto.Kvrpcpb.BatchGetResponse) GetResponse(org.tikv.kvproto.Kvrpcpb.GetResponse) RawGetResponse(org.tikv.kvproto.Kvrpcpb.RawGetResponse)

Example 13 with KVErrorHandler

use of com.pingcap.tikv.operation.KVErrorHandler in project tispark by pingcap.

the class RegionStoreClient method rawBatchGet.

public List<KvPair> rawBatchGet(BackOffer backoffer, List<ByteString> keys) {
    if (keys.isEmpty()) {
        return new ArrayList<>();
    }
    Supplier<RawBatchGetRequest> factory = () -> RawBatchGetRequest.newBuilder().setContext(region.getContext()).addAllKeys(keys).build();
    KVErrorHandler<RawBatchGetResponse> handler = new KVErrorHandler<>(regionManager, this, resp -> resp.hasRegionError() ? resp.getRegionError() : null);
    RawBatchGetResponse resp = callWithRetry(backoffer, TikvGrpc.getRawBatchGetMethod(), factory, handler);
    return handleRawBatchGet(resp);
}
Also used : RawBatchGetRequest(org.tikv.kvproto.Kvrpcpb.RawBatchGetRequest) ArrayList(java.util.ArrayList) RawBatchGetResponse(org.tikv.kvproto.Kvrpcpb.RawBatchGetResponse) KVErrorHandler(com.pingcap.tikv.operation.KVErrorHandler)

Example 14 with KVErrorHandler

use of com.pingcap.tikv.operation.KVErrorHandler in project tispark by pingcap.

the class RegionStoreClient method batchGet.

public List<KvPair> batchGet(BackOffer backOffer, List<ByteString> keys, long version) {
    boolean forWrite = false;
    Supplier<BatchGetRequest> request = () -> BatchGetRequest.newBuilder().setContext(region.getContext(getResolvedLocks(version))).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);
    try {
        return handleBatchGetResponse(backOffer, resp, version);
    } catch (TiKVException e) {
        if ("locks not resolved, retry".equals(e.getMessage())) {
            backOffer.doBackOff(BackOffFunction.BackOffFuncType.BoTxnLock, e);
            return batchGet(backOffer, keys, version);
        } else {
            throw e;
        }
    }
}
Also used : RawBatchGetRequest(org.tikv.kvproto.Kvrpcpb.RawBatchGetRequest) BatchGetRequest(org.tikv.kvproto.Kvrpcpb.BatchGetRequest) RawBatchGetResponse(org.tikv.kvproto.Kvrpcpb.RawBatchGetResponse) BatchGetResponse(org.tikv.kvproto.Kvrpcpb.BatchGetResponse) TiKVException(com.pingcap.tikv.exception.TiKVException) KVErrorHandler(com.pingcap.tikv.operation.KVErrorHandler)

Example 15 with KVErrorHandler

use of com.pingcap.tikv.operation.KVErrorHandler in project tispark by pingcap.

the class RegionStoreClient method rawGetKeyTTL.

public Long rawGetKeyTTL(BackOffer backOffer, ByteString key) {
    Supplier<RawGetKeyTTLRequest> factory = () -> RawGetKeyTTLRequest.newBuilder().setContext(region.getContext()).setKey(key).build();
    KVErrorHandler<RawGetKeyTTLResponse> handler = new KVErrorHandler<>(regionManager, this, resp -> resp.hasRegionError() ? resp.getRegionError() : null);
    RawGetKeyTTLResponse resp = callWithRetry(backOffer, TikvGrpc.getRawGetKeyTTLMethod(), factory, handler);
    return rawGetKeyTTLHelper(resp);
}
Also used : RawGetKeyTTLRequest(org.tikv.kvproto.Kvrpcpb.RawGetKeyTTLRequest) RawGetKeyTTLResponse(org.tikv.kvproto.Kvrpcpb.RawGetKeyTTLResponse) KVErrorHandler(com.pingcap.tikv.operation.KVErrorHandler)

Aggregations

KVErrorHandler (com.pingcap.tikv.operation.KVErrorHandler)27 TiClientInternalException (com.pingcap.tikv.exception.TiClientInternalException)10 KeyException (com.pingcap.tikv.exception.KeyException)9 RegionException (com.pingcap.tikv.exception.RegionException)8 Kvrpcpb (org.tikv.kvproto.Kvrpcpb)7 RawBatchGetRequest (org.tikv.kvproto.Kvrpcpb.RawBatchGetRequest)5 AbstractRegionStoreClient (com.pingcap.tikv.region.AbstractRegionStoreClient)4 RegionStoreClient (com.pingcap.tikv.region.RegionStoreClient)4 TiRegion (com.pingcap.tikv.region.TiRegion)4 ArrayList (java.util.ArrayList)4 BatchGetRequest (org.tikv.kvproto.Kvrpcpb.BatchGetRequest)4 RawBatchGetResponse (org.tikv.kvproto.Kvrpcpb.RawBatchGetResponse)4 RawGetRequest (org.tikv.kvproto.Kvrpcpb.RawGetRequest)4 RawScanRequest (org.tikv.kvproto.Kvrpcpb.RawScanRequest)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 BatchGetResponse (org.tikv.kvproto.Kvrpcpb.BatchGetResponse)3 GetRequest (org.tikv.kvproto.Kvrpcpb.GetRequest)3 PrewriteRequest (org.tikv.kvproto.Kvrpcpb.PrewriteRequest)3