Search in sources :

Example 1 with RawCASRequest

use of org.tikv.kvproto.Kvrpcpb.RawCASRequest in project client-java by tikv.

the class RegionStoreClient method rawCompareAndSet.

public void rawCompareAndSet(BackOffer backOffer, ByteString key, Optional<ByteString> prevValue, ByteString value, long ttl) throws RawCASConflictException {
    Long clusterId = pdClient.getClusterId();
    Histogram.Timer requestTimer = GRPC_RAW_REQUEST_LATENCY.labels("client_grpc_raw_put_if_absent", clusterId.toString()).startTimer();
    try {
        Supplier<RawCASRequest> factory = () -> RawCASRequest.newBuilder().setContext(makeContext(storeType, backOffer.getSlowLog())).setKey(key).setValue(value).setPreviousValue(prevValue.orElse(ByteString.EMPTY)).setPreviousNotExist(!prevValue.isPresent()).setTtl(ttl).build();
        RegionErrorHandler<RawCASResponse> handler = new RegionErrorHandler<RawCASResponse>(regionManager, this, resp -> resp.hasRegionError() ? resp.getRegionError() : null);
        RawCASResponse resp = callWithRetry(backOffer, TikvGrpc.getRawCompareAndSwapMethod(), factory, handler);
        rawCompareAndSetHelper(key, prevValue, resp);
    } finally {
        requestTimer.observeDuration();
    }
}
Also used : Histogram(io.prometheus.client.Histogram) RawCASRequest(org.tikv.kvproto.Kvrpcpb.RawCASRequest) RawCASResponse(org.tikv.kvproto.Kvrpcpb.RawCASResponse) RegionErrorHandler(org.tikv.common.operation.RegionErrorHandler)

Example 2 with RawCASRequest

use of org.tikv.kvproto.Kvrpcpb.RawCASRequest 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

RawCASRequest (org.tikv.kvproto.Kvrpcpb.RawCASRequest)2 RawCASResponse (org.tikv.kvproto.Kvrpcpb.RawCASResponse)2 KVErrorHandler (com.pingcap.tikv.operation.KVErrorHandler)1 Histogram (io.prometheus.client.Histogram)1 RegionErrorHandler (org.tikv.common.operation.RegionErrorHandler)1