Search in sources :

Example 1 with KVErrorHandler

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

the class RegionStoreClient method commit.

/**
 * Commit batch keys
 *
 * @param backOffer backOffer
 * @param keys keys to commit
 * @param startTs start version
 * @param commitTs commit version
 */
public void commit(BackOffer backOffer, Iterable<ByteString> keys, long startTs, long commitTs) throws KeyException {
    boolean forWrite = true;
    Supplier<CommitRequest> factory = () -> CommitRequest.newBuilder().setStartVersion(startTs).setCommitVersion(commitTs).addAllKeys(keys).setContext(region.getContext()).build();
    KVErrorHandler<CommitResponse> handler = new KVErrorHandler<>(regionManager, this, lockResolverClient, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> resp.hasError() ? resp.getError() : null, resolveLockResult -> null, startTs, forWrite);
    CommitResponse resp = callWithRetry(backOffer, TikvGrpc.getKvCommitMethod(), factory, handler);
    handleCommitResponse(resp);
}
Also used : CommitRequest(org.tikv.kvproto.Kvrpcpb.CommitRequest) CommitResponse(org.tikv.kvproto.Kvrpcpb.CommitResponse) KVErrorHandler(com.pingcap.tikv.operation.KVErrorHandler)

Example 2 with KVErrorHandler

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

the class RegionStoreClient method rawDelete.

public void rawDelete(BackOffer backOffer, ByteString key) {
    Supplier<RawDeleteRequest> factory = () -> RawDeleteRequest.newBuilder().setContext(region.getContext()).setKey(key).build();
    KVErrorHandler<RawDeleteResponse> handler = new KVErrorHandler<>(regionManager, this, resp -> resp.hasRegionError() ? resp.getRegionError() : null);
    RawDeleteResponse resp = callWithRetry(backOffer, TikvGrpc.getRawDeleteMethod(), factory, handler);
    rawDeleteHelper(resp, region);
}
Also used : RawDeleteRequest(org.tikv.kvproto.Kvrpcpb.RawDeleteRequest) RawDeleteResponse(org.tikv.kvproto.Kvrpcpb.RawDeleteResponse) KVErrorHandler(com.pingcap.tikv.operation.KVErrorHandler)

Example 3 with KVErrorHandler

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

the class RegionStoreClient method rawGet.

// APIs for Raw Scan/Put/Get/Delete
public ByteString rawGet(BackOffer backOffer, ByteString key) {
    Supplier<RawGetRequest> factory = () -> RawGetRequest.newBuilder().setContext(region.getContext()).setKey(key).build();
    KVErrorHandler<RawGetResponse> handler = new KVErrorHandler<>(regionManager, this, resp -> resp.hasRegionError() ? resp.getRegionError() : null);
    RawGetResponse resp = callWithRetry(backOffer, TikvGrpc.getRawGetMethod(), factory, handler);
    return rawGetHelper(resp);
}
Also used : RawGetResponse(org.tikv.kvproto.Kvrpcpb.RawGetResponse) RawGetRequest(org.tikv.kvproto.Kvrpcpb.RawGetRequest) KVErrorHandler(com.pingcap.tikv.operation.KVErrorHandler)

Example 4 with KVErrorHandler

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

the class RegionStoreClient method coprocessStreaming.

// TODO: wait for future fix
// coprocessStreaming doesn't handle split error
// future work should handle it and do the resolve
// locks correspondingly
public Iterator<SelectResponse> coprocessStreaming(DAGRequest req, List<Coprocessor.KeyRange> ranges, long startTs) {
    boolean forWrite = false;
    Supplier<Coprocessor.Request> reqToSend = () -> Coprocessor.Request.newBuilder().setContext(region.getContext(getResolvedLocks(startTs))).setTp(REQ_TYPE_DAG.getValue()).setData(req.toByteString()).addAllRanges(ranges).build();
    KVErrorHandler<StreamingResponse> handler = new KVErrorHandler<>(regionManager, this, lockResolverClient, // TODO: handle all errors in streaming response
    StreamingResponse::getFirstRegionError, resp -> null, resolveLockResult -> addResolvedLocks(startTs, resolveLockResult.getResolvedLocks()), startTs, forWrite);
    StreamingResponse responseIterator = this.callServerStreamingWithRetry(ConcreteBackOffer.newCopNextMaxBackOff(), TikvGrpc.getCoprocessorStreamMethod(), reqToSend, handler);
    return doCoprocessor(responseIterator);
}
Also used : StreamingResponse(com.pingcap.tikv.streaming.StreamingResponse) RawPutRequest(org.tikv.kvproto.Kvrpcpb.RawPutRequest) ScanRequest(org.tikv.kvproto.Kvrpcpb.ScanRequest) RawScanRequest(org.tikv.kvproto.Kvrpcpb.RawScanRequest) RawBatchGetRequest(org.tikv.kvproto.Kvrpcpb.RawBatchGetRequest) RawGetKeyTTLRequest(org.tikv.kvproto.Kvrpcpb.RawGetKeyTTLRequest) RawDeleteRangeRequest(org.tikv.kvproto.Kvrpcpb.RawDeleteRangeRequest) RawDeleteRequest(org.tikv.kvproto.Kvrpcpb.RawDeleteRequest) GetRequest(org.tikv.kvproto.Kvrpcpb.GetRequest) RawBatchDeleteRequest(org.tikv.kvproto.Kvrpcpb.RawBatchDeleteRequest) TxnHeartBeatRequest(org.tikv.kvproto.Kvrpcpb.TxnHeartBeatRequest) RawGetRequest(org.tikv.kvproto.Kvrpcpb.RawGetRequest) RawCASRequest(org.tikv.kvproto.Kvrpcpb.RawCASRequest) PrewriteRequest(org.tikv.kvproto.Kvrpcpb.PrewriteRequest) CommitRequest(org.tikv.kvproto.Kvrpcpb.CommitRequest) BatchGetRequest(org.tikv.kvproto.Kvrpcpb.BatchGetRequest) DAGRequest(com.pingcap.tidb.tipb.DAGRequest) RawBatchPutRequest(org.tikv.kvproto.Kvrpcpb.RawBatchPutRequest) SplitRegionRequest(org.tikv.kvproto.Kvrpcpb.SplitRegionRequest) KVErrorHandler(com.pingcap.tikv.operation.KVErrorHandler)

Example 5 with KVErrorHandler

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

the class RegionStoreClient method rawPutIfAbsent.

public ByteString rawPutIfAbsent(BackOffer backOffer, ByteString key, ByteString value, long ttl) {
    Supplier<RawCASRequest> factory = () -> RawCASRequest.newBuilder().setContext(region.getContext()).setKey(key).setValue(value).setPreviousNotExist(true).setTtl(ttl).build();
    KVErrorHandler<RawCASResponse> handler = new KVErrorHandler<>(regionManager, this, resp -> resp.hasRegionError() ? resp.getRegionError() : null);
    RawCASResponse resp = callWithRetry(backOffer, TikvGrpc.getRawCompareAndSwapMethod(), factory, handler);
    return rawPutIfAbsentHelper(resp);
}
Also used : RawCASRequest(org.tikv.kvproto.Kvrpcpb.RawCASRequest) RawCASResponse(org.tikv.kvproto.Kvrpcpb.RawCASResponse) 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