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();
}
}
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);
}
Aggregations