public class RawKVClient extends Object implements RawKVClientBase
| Modifier and Type | Class and Description |
|---|---|
class |
RawKVClient.TikvIterator |
| Modifier and Type | Field and Description |
|---|---|
static io.prometheus.client.Counter |
RAW_REQUEST_FAILURE |
static io.prometheus.client.Histogram |
RAW_REQUEST_LATENCY |
static io.prometheus.client.Counter |
RAW_REQUEST_SUCCESS |
MAX_RAW_BATCH_LIMIT, MAX_RAW_SCAN_LIMIT, RAW_BATCH_DELETE_SIZE, RAW_BATCH_GET_SIZE, RAW_BATCH_PUT_SIZE| Constructor and Description |
|---|
RawKVClient(TiSession session,
RegionStoreClient.RegionStoreClientBuilder clientBuilder) |
| Modifier and Type | Method and Description |
|---|---|
void |
batchDelete(List<com.google.protobuf.ByteString> keys)
Delete a list of raw key-value pair from TiKV if key exists
|
List<Kvrpcpb.KvPair> |
batchGet(List<com.google.protobuf.ByteString> keys)
Get a list of raw key-value pair from TiKV if key exists
|
void |
batchPut(Map<com.google.protobuf.ByteString,com.google.protobuf.ByteString> kvPairs)
Put a set of raw key-value pair to TiKV.
|
void |
batchPut(Map<com.google.protobuf.ByteString,com.google.protobuf.ByteString> kvPairs,
long ttl)
Put a set of raw key-value pair to TiKV.
|
List<List<Kvrpcpb.KvPair>> |
batchScan(List<ScanOption> ranges)
Create a new `batch scan` request.
|
List<List<com.google.protobuf.ByteString>> |
batchScanKeys(List<Pair<com.google.protobuf.ByteString,com.google.protobuf.ByteString>> ranges,
int eachLimit)
Create a new `batch scan` request with `keyOnly` option Once resolved this request will result
in a set of scanners over the given keys.
|
void |
close() |
void |
compareAndSet(com.google.protobuf.ByteString key,
Optional<com.google.protobuf.ByteString> prevValue,
com.google.protobuf.ByteString value)
Put a key-value pair if the prevValue matched the value in TiKV.
|
void |
compareAndSet(com.google.protobuf.ByteString key,
Optional<com.google.protobuf.ByteString> prevValue,
com.google.protobuf.ByteString value,
long ttl)
pair if the prevValue matched the value in TiKV.
|
void |
delete(com.google.protobuf.ByteString key)
Delete a raw key-value pair from TiKV if key exists
|
void |
deletePrefix(com.google.protobuf.ByteString key)
Delete all raw key-value pairs with the prefix `key` from TiKV
|
void |
deleteRange(com.google.protobuf.ByteString startKey,
com.google.protobuf.ByteString endKey)
Delete all raw key-value pairs in range [startKey, endKey) from TiKV
|
Optional<com.google.protobuf.ByteString> |
get(com.google.protobuf.ByteString key)
Get a raw key-value pair from TiKV if key exists
|
Optional<Long> |
getKeyTTL(com.google.protobuf.ByteString key)
Get the TTL of a raw key from TiKV if key exists
|
TiSession |
getSession()
Get the session of the current client
|
void |
ingest(List<Pair<com.google.protobuf.ByteString,com.google.protobuf.ByteString>> list)
Ingest KV pairs to RawKV using StreamKV API.
|
void |
ingest(List<Pair<com.google.protobuf.ByteString,com.google.protobuf.ByteString>> list,
Long ttl)
Ingest KV pairs to RawKV using StreamKV API.
|
void |
put(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value)
Put a raw key-value pair to TiKV
|
void |
put(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value,
long ttl)
Put a raw key-value pair to TiKV
|
Optional<com.google.protobuf.ByteString> |
putIfAbsent(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value)
Put a key-value pair if it does not exist.
|
Optional<com.google.protobuf.ByteString> |
putIfAbsent(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value,
long ttl)
Put a key-value pair with TTL if it does not exist.
|
List<Kvrpcpb.KvPair> |
scan(com.google.protobuf.ByteString startKey,
com.google.protobuf.ByteString endKey)
Scan all raw key-value pairs from TiKV in range [startKey, endKey)
|
List<Kvrpcpb.KvPair> |
scan(com.google.protobuf.ByteString startKey,
com.google.protobuf.ByteString endKey,
boolean keyOnly)
Scan all raw key-value pairs from TiKV in range [startKey, endKey)
|
List<Kvrpcpb.KvPair> |
scan(com.google.protobuf.ByteString startKey,
com.google.protobuf.ByteString endKey,
int limit)
Scan raw key-value pairs from TiKV in range [startKey, endKey)
|
List<Kvrpcpb.KvPair> |
scan(com.google.protobuf.ByteString startKey,
com.google.protobuf.ByteString endKey,
int limit,
boolean keyOnly)
Scan raw key-value pairs from TiKV in range [startKey, endKey)
|
List<Kvrpcpb.KvPair> |
scan(com.google.protobuf.ByteString startKey,
int limit)
Scan raw key-value pairs from TiKV in range [startKey, ♾)
|
List<Kvrpcpb.KvPair> |
scan(com.google.protobuf.ByteString startKey,
int limit,
boolean keyOnly)
Scan raw key-value pairs from TiKV in range [startKey, ♾)
|
Iterator<Kvrpcpb.KvPair> |
scan0(com.google.protobuf.ByteString startKey,
com.google.protobuf.ByteString endKey)
Scan all raw key-value pairs from TiKV in range [startKey, endKey)
|
Iterator<Kvrpcpb.KvPair> |
scan0(com.google.protobuf.ByteString startKey,
com.google.protobuf.ByteString endKey,
boolean keyOnly)
Scan all raw key-value pairs from TiKV in range [startKey, endKey)
|
Iterator<Kvrpcpb.KvPair> |
scan0(com.google.protobuf.ByteString startKey,
com.google.protobuf.ByteString endKey,
int limit)
Scan raw key-value pairs from TiKV in range [startKey, endKey)
|
Iterator<Kvrpcpb.KvPair> |
scan0(com.google.protobuf.ByteString startKey,
com.google.protobuf.ByteString endKey,
int limit,
boolean keyOnly)
Scan raw key-value pairs from TiKV in range [startKey, endKey)
|
Iterator<Kvrpcpb.KvPair> |
scan0(com.google.protobuf.ByteString startKey,
int limit)
Scan raw key-value pairs from TiKV in range [startKey, ♾)
|
Iterator<Kvrpcpb.KvPair> |
scan0(com.google.protobuf.ByteString startKey,
int limit,
boolean keyOnly)
Scan raw key-value pairs from TiKV in range [startKey, ♾)
|
List<Kvrpcpb.KvPair> |
scanPrefix(com.google.protobuf.ByteString prefixKey) |
List<Kvrpcpb.KvPair> |
scanPrefix(com.google.protobuf.ByteString prefixKey,
boolean keyOnly) |
List<Kvrpcpb.KvPair> |
scanPrefix(com.google.protobuf.ByteString prefixKey,
int limit,
boolean keyOnly)
Scan keys with prefix
|
Iterator<Kvrpcpb.KvPair> |
scanPrefix0(com.google.protobuf.ByteString prefixKey) |
Iterator<Kvrpcpb.KvPair> |
scanPrefix0(com.google.protobuf.ByteString prefixKey,
boolean keyOnly) |
Iterator<Kvrpcpb.KvPair> |
scanPrefix0(com.google.protobuf.ByteString prefixKey,
int limit,
boolean keyOnly)
Scan keys with prefix
|
public static final io.prometheus.client.Histogram RAW_REQUEST_LATENCY
public static final io.prometheus.client.Counter RAW_REQUEST_SUCCESS
public static final io.prometheus.client.Counter RAW_REQUEST_FAILURE
public RawKVClient(TiSession session, RegionStoreClient.RegionStoreClientBuilder clientBuilder)
public void close()
close in interface AutoCloseablepublic void put(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value)
RawKVClientBaseput in interface RawKVClientBasekey - raw keyvalue - raw valuepublic void put(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value,
long ttl)
RawKVClientBaseput in interface RawKVClientBasekey - raw keyvalue - raw valuettl - the ttl of the key (in seconds), 0 means the key will never be outdatedpublic Optional<com.google.protobuf.ByteString> putIfAbsent(com.google.protobuf.ByteString key, com.google.protobuf.ByteString value)
RawKVClientBaseTo use this API, please enable `tikv.enable_atomic_for_cas`.
putIfAbsent in interface RawKVClientBasekey - keyvalue - valuepublic Optional<com.google.protobuf.ByteString> putIfAbsent(com.google.protobuf.ByteString key, com.google.protobuf.ByteString value, long ttl)
RawKVClientBaseTo use this API, please enable `tikv.enable_atomic_for_cas`.
putIfAbsent in interface RawKVClientBasekey - keyvalue - valuettl - TTL of key (in seconds), 0 means the key will never be outdated.public void compareAndSet(com.google.protobuf.ByteString key,
Optional<com.google.protobuf.ByteString> prevValue,
com.google.protobuf.ByteString value)
throws RawCASConflictException
RawKVClientBaseTo use this API, please enable `tikv.enable_atomic_for_cas`.
compareAndSet in interface RawKVClientBasekey - keyvalue - valueRawCASConflictExceptionpublic void compareAndSet(com.google.protobuf.ByteString key,
Optional<com.google.protobuf.ByteString> prevValue,
com.google.protobuf.ByteString value,
long ttl)
throws RawCASConflictException
RawKVClientBaseTo use this API, please enable `tikv.enable_atomic_for_cas`.
compareAndSet in interface RawKVClientBasekey - keyvalue - valuettl - TTL of key (in seconds), 0 means the key will never be outdated.RawCASConflictExceptionpublic void batchPut(Map<com.google.protobuf.ByteString,com.google.protobuf.ByteString> kvPairs)
RawKVClientBasebatchPut in interface RawKVClientBasekvPairs - kvPairspublic void batchPut(Map<com.google.protobuf.ByteString,com.google.protobuf.ByteString> kvPairs, long ttl)
RawKVClientBasebatchPut in interface RawKVClientBasekvPairs - kvPairsttl - the TTL of keys to be put (in seconds), 0 means the keys will never be outdatedpublic Optional<com.google.protobuf.ByteString> get(com.google.protobuf.ByteString key)
RawKVClientBaseget in interface RawKVClientBasekey - raw keypublic List<Kvrpcpb.KvPair> batchGet(List<com.google.protobuf.ByteString> keys)
RawKVClientBasebatchGet in interface RawKVClientBasekeys - list of raw keypublic void batchDelete(List<com.google.protobuf.ByteString> keys)
RawKVClientBasebatchDelete in interface RawKVClientBasekeys - list of raw keypublic Optional<Long> getKeyTTL(com.google.protobuf.ByteString key)
RawKVClientBasegetKeyTTL in interface RawKVClientBasekey - raw keypublic List<List<com.google.protobuf.ByteString>> batchScanKeys(List<Pair<com.google.protobuf.ByteString,com.google.protobuf.ByteString>> ranges, int eachLimit)
RawKVClientBaseWARNING: This method is experimental. The `each_limit` parameter does not work as expected. It does not limit the number of results returned of each range, instead it limits the number of results in each region of each range. As a result, you may get more than each_limit key-value pairs for each range. But you should not miss any entries.
batchScanKeys in interface RawKVClientBaseranges - a list of rangespublic List<List<Kvrpcpb.KvPair>> batchScan(List<ScanOption> ranges)
RawKVClientBaseWARNING: This method is experimental. The `each_limit` parameter does not work as expected. It does not limit the number of results returned of each range, instead it limits the number of results in each region of each range. As a result, you may get more than each_limit key-value pairs for each range. But you should not miss any entries.
batchScan in interface RawKVClientBaseranges - a list of `ScanOption` for each rangepublic List<Kvrpcpb.KvPair> scan(com.google.protobuf.ByteString startKey, com.google.protobuf.ByteString endKey, int limit)
RawKVClientBasescan in interface RawKVClientBasestartKey - raw start key, inclusiveendKey - raw end key, exclusivelimit - limit of key-value pairs scanned, should be less than RawKVClientBase.MAX_RAW_SCAN_LIMITpublic List<Kvrpcpb.KvPair> scan(com.google.protobuf.ByteString startKey, com.google.protobuf.ByteString endKey, int limit, boolean keyOnly)
RawKVClientBasescan in interface RawKVClientBasestartKey - raw start key, inclusiveendKey - raw end key, exclusivelimit - limit of key-value pairs scanned, should be less than RawKVClientBase.MAX_RAW_SCAN_LIMITkeyOnly - whether to scan in key-only modepublic List<Kvrpcpb.KvPair> scan(com.google.protobuf.ByteString startKey, int limit)
RawKVClientBasescan in interface RawKVClientBasestartKey - raw start key, inclusivelimit - limit of key-value pairs scanned, should be less than RawKVClientBase.MAX_RAW_SCAN_LIMITpublic List<Kvrpcpb.KvPair> scan(com.google.protobuf.ByteString startKey, int limit, boolean keyOnly)
RawKVClientBasescan in interface RawKVClientBasestartKey - raw start key, inclusivelimit - limit of key-value pairs scanned, should be less than RawKVClientBase.MAX_RAW_SCAN_LIMITkeyOnly - whether to scan in key-only modepublic List<Kvrpcpb.KvPair> scan(com.google.protobuf.ByteString startKey, com.google.protobuf.ByteString endKey)
RawKVClientBasescan in interface RawKVClientBasestartKey - raw start key, inclusiveendKey - raw end key, exclusivepublic List<Kvrpcpb.KvPair> scan(com.google.protobuf.ByteString startKey, com.google.protobuf.ByteString endKey, boolean keyOnly)
RawKVClientBasescan in interface RawKVClientBasestartKey - raw start key, inclusiveendKey - raw end key, exclusivekeyOnly - whether to scan in key-only modepublic List<Kvrpcpb.KvPair> scanPrefix(com.google.protobuf.ByteString prefixKey, int limit, boolean keyOnly)
RawKVClientBasescanPrefix in interface RawKVClientBaseprefixKey - prefix keylimit - limit of keys retrievedkeyOnly - whether to scan in keyOnly modepublic List<Kvrpcpb.KvPair> scanPrefix(com.google.protobuf.ByteString prefixKey)
scanPrefix in interface RawKVClientBasepublic List<Kvrpcpb.KvPair> scanPrefix(com.google.protobuf.ByteString prefixKey, boolean keyOnly)
scanPrefix in interface RawKVClientBasepublic void delete(com.google.protobuf.ByteString key)
RawKVClientBasedelete in interface RawKVClientBasekey - raw key to be deletedpublic void deleteRange(com.google.protobuf.ByteString startKey,
com.google.protobuf.ByteString endKey)
RawKVClientBaseCautious, this API cannot be used concurrently, if multiple clients write keys into this range along with deleteRange API, the result will be undefined.
deleteRange in interface RawKVClientBasestartKey - raw start key to be deletedendKey - raw start key to be deletedpublic void deletePrefix(com.google.protobuf.ByteString key)
RawKVClientBaseCautious, this API cannot be used concurrently, if multiple clients write keys into this range along with deleteRange API, the result will be undefined.
deletePrefix in interface RawKVClientBasekey - prefix of keys to be deletedpublic TiSession getSession()
RawKVClientBasegetSession in interface RawKVClientBasepublic void ingest(List<Pair<com.google.protobuf.ByteString,com.google.protobuf.ByteString>> list)
list - public void ingest(List<Pair<com.google.protobuf.ByteString,com.google.protobuf.ByteString>> list, Long ttl) throws GrpcException
list - ttl - the ttl of the key (in seconds), 0 means the key will never be outdatedGrpcExceptionpublic Iterator<Kvrpcpb.KvPair> scan0(com.google.protobuf.ByteString startKey, com.google.protobuf.ByteString endKey, int limit)
startKey - raw start key, inclusiveendKey - raw end key, exclusivelimit - limit of key-value pairs scanned, should be less than RawKVClientBase.MAX_RAW_SCAN_LIMITpublic Iterator<Kvrpcpb.KvPair> scan0(com.google.protobuf.ByteString startKey, int limit)
startKey - raw start key, inclusivelimit - limit of key-value pairs scanned, should be less than RawKVClientBase.MAX_RAW_SCAN_LIMITpublic Iterator<Kvrpcpb.KvPair> scan0(com.google.protobuf.ByteString startKey, int limit, boolean keyOnly)
startKey - raw start key, inclusivelimit - limit of key-value pairs scanned, should be less than RawKVClientBase.MAX_RAW_SCAN_LIMITkeyOnly - whether to scan in key-only modepublic Iterator<Kvrpcpb.KvPair> scan0(com.google.protobuf.ByteString startKey, com.google.protobuf.ByteString endKey, int limit, boolean keyOnly)
startKey - raw start key, inclusiveendKey - raw end key, exclusivelimit - limit of key-value pairs scanned, should be less than RawKVClientBase.MAX_RAW_SCAN_LIMITkeyOnly - whether to scan in key-only modepublic Iterator<Kvrpcpb.KvPair> scan0(com.google.protobuf.ByteString startKey, com.google.protobuf.ByteString endKey)
startKey - raw start key, inclusiveendKey - raw end key, exclusivepublic Iterator<Kvrpcpb.KvPair> scanPrefix0(com.google.protobuf.ByteString prefixKey, int limit, boolean keyOnly)
prefixKey - prefix keylimit - limit of keys retrievedkeyOnly - whether to scan in keyOnly modepublic Iterator<Kvrpcpb.KvPair> scanPrefix0(com.google.protobuf.ByteString prefixKey)
public Iterator<Kvrpcpb.KvPair> scanPrefix0(com.google.protobuf.ByteString prefixKey, boolean keyOnly)
public Iterator<Kvrpcpb.KvPair> scan0(com.google.protobuf.ByteString startKey, com.google.protobuf.ByteString endKey, boolean keyOnly)
startKey - raw start key, inclusiveendKey - raw end key, exclusivekeyOnly - whether to scan in key-only modeCopyright © 2025 PingCAP. All rights reserved.