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 AutoCloseable
public void put(com.google.protobuf.ByteString key, com.google.protobuf.ByteString value)
RawKVClientBase
put
in interface RawKVClientBase
key
- raw keyvalue
- raw valuepublic void put(com.google.protobuf.ByteString key, com.google.protobuf.ByteString value, long ttl)
RawKVClientBase
put
in interface RawKVClientBase
key
- 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)
RawKVClientBase
To use this API, please enable `tikv.enable_atomic_for_cas`.
putIfAbsent
in interface RawKVClientBase
key
- keyvalue
- valuepublic Optional<com.google.protobuf.ByteString> putIfAbsent(com.google.protobuf.ByteString key, com.google.protobuf.ByteString value, long ttl)
RawKVClientBase
To use this API, please enable `tikv.enable_atomic_for_cas`.
putIfAbsent
in interface RawKVClientBase
key
- 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
RawKVClientBase
To use this API, please enable `tikv.enable_atomic_for_cas`.
compareAndSet
in interface RawKVClientBase
key
- keyvalue
- valueRawCASConflictException
public void compareAndSet(com.google.protobuf.ByteString key, Optional<com.google.protobuf.ByteString> prevValue, com.google.protobuf.ByteString value, long ttl) throws RawCASConflictException
RawKVClientBase
To use this API, please enable `tikv.enable_atomic_for_cas`.
compareAndSet
in interface RawKVClientBase
key
- keyvalue
- valuettl
- TTL of key (in seconds), 0 means the key will never be outdated.RawCASConflictException
public void batchPut(Map<com.google.protobuf.ByteString,com.google.protobuf.ByteString> kvPairs)
RawKVClientBase
batchPut
in interface RawKVClientBase
kvPairs
- kvPairspublic void batchPut(Map<com.google.protobuf.ByteString,com.google.protobuf.ByteString> kvPairs, long ttl)
RawKVClientBase
batchPut
in interface RawKVClientBase
kvPairs
- 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)
RawKVClientBase
get
in interface RawKVClientBase
key
- raw keypublic List<Kvrpcpb.KvPair> batchGet(List<com.google.protobuf.ByteString> keys)
RawKVClientBase
batchGet
in interface RawKVClientBase
keys
- list of raw keypublic void batchDelete(List<com.google.protobuf.ByteString> keys)
RawKVClientBase
batchDelete
in interface RawKVClientBase
keys
- list of raw keypublic Optional<Long> getKeyTTL(com.google.protobuf.ByteString key)
RawKVClientBase
getKeyTTL
in interface RawKVClientBase
key
- raw keypublic List<List<com.google.protobuf.ByteString>> batchScanKeys(List<Pair<com.google.protobuf.ByteString,com.google.protobuf.ByteString>> ranges, int eachLimit)
RawKVClientBase
WARNING: 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 RawKVClientBase
ranges
- a list of rangespublic List<List<Kvrpcpb.KvPair>> batchScan(List<ScanOption> ranges)
RawKVClientBase
WARNING: 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 RawKVClientBase
ranges
- a list of `ScanOption` for each rangepublic List<Kvrpcpb.KvPair> scan(com.google.protobuf.ByteString startKey, com.google.protobuf.ByteString endKey, int limit)
RawKVClientBase
scan
in interface RawKVClientBase
startKey
- raw start key, inclusiveendKey
- raw end key, exclusivelimit
- limit of key-value pairs scanned, should be less than RawKVClientBase.MAX_RAW_SCAN_LIMIT
public List<Kvrpcpb.KvPair> scan(com.google.protobuf.ByteString startKey, com.google.protobuf.ByteString endKey, int limit, boolean keyOnly)
RawKVClientBase
scan
in interface RawKVClientBase
startKey
- raw start key, inclusiveendKey
- raw end key, exclusivelimit
- limit of key-value pairs scanned, should be less than RawKVClientBase.MAX_RAW_SCAN_LIMIT
keyOnly
- whether to scan in key-only modepublic List<Kvrpcpb.KvPair> scan(com.google.protobuf.ByteString startKey, int limit)
RawKVClientBase
scan
in interface RawKVClientBase
startKey
- raw start key, inclusivelimit
- limit of key-value pairs scanned, should be less than RawKVClientBase.MAX_RAW_SCAN_LIMIT
public List<Kvrpcpb.KvPair> scan(com.google.protobuf.ByteString startKey, int limit, boolean keyOnly)
RawKVClientBase
scan
in interface RawKVClientBase
startKey
- raw start key, inclusivelimit
- limit of key-value pairs scanned, should be less than RawKVClientBase.MAX_RAW_SCAN_LIMIT
keyOnly
- whether to scan in key-only modepublic List<Kvrpcpb.KvPair> scan(com.google.protobuf.ByteString startKey, com.google.protobuf.ByteString endKey)
RawKVClientBase
scan
in interface RawKVClientBase
startKey
- raw start key, inclusiveendKey
- raw end key, exclusivepublic List<Kvrpcpb.KvPair> scan(com.google.protobuf.ByteString startKey, com.google.protobuf.ByteString endKey, boolean keyOnly)
RawKVClientBase
scan
in interface RawKVClientBase
startKey
- 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)
RawKVClientBase
scanPrefix
in interface RawKVClientBase
prefixKey
- prefix keylimit
- limit of keys retrievedkeyOnly
- whether to scan in keyOnly modepublic List<Kvrpcpb.KvPair> scanPrefix(com.google.protobuf.ByteString prefixKey)
scanPrefix
in interface RawKVClientBase
public List<Kvrpcpb.KvPair> scanPrefix(com.google.protobuf.ByteString prefixKey, boolean keyOnly)
scanPrefix
in interface RawKVClientBase
public void delete(com.google.protobuf.ByteString key)
RawKVClientBase
delete
in interface RawKVClientBase
key
- raw key to be deletedpublic void deleteRange(com.google.protobuf.ByteString startKey, com.google.protobuf.ByteString endKey)
RawKVClientBase
Cautious, 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 RawKVClientBase
startKey
- raw start key to be deletedendKey
- raw start key to be deletedpublic void deletePrefix(com.google.protobuf.ByteString key)
RawKVClientBase
Cautious, 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 RawKVClientBase
key
- prefix of keys to be deletedpublic TiSession getSession()
RawKVClientBase
getSession
in interface RawKVClientBase
public 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 outdatedGrpcException
public 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_LIMIT
public 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_LIMIT
public 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_LIMIT
keyOnly
- 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_LIMIT
keyOnly
- 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 © 2024 PingCAP. All rights reserved.