Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: RawKVClient#batchPut不能写入
[TiDB Usage Environment]
[TiDB Version]
5.4.3
tikv-client-java: 3.3.8
[Encountered Issue: Phenomenon and Impact]
Due to the large amount of data, the batchPut API was chosen for data writing using a custom Flink sink. However, experiments showed that it could not write, and the task was blocked.
The error reported is as follows:
org.tikv.common.exception.TiKVException: TimeOut Exceeded for current operation.
at org.tikv.common.util.ClientUtils.getTasks(ClientUtils.java:181)
at org.tikv.raw.RawKVClient.doSendBatchPut(RawKVClient.java:756)
at org.tikv.raw.RawKVClient.batchPut(RawKVClient.java:260)
Using put can write, setting the key to a timestamp string allows batchPut to write.
After searching, it was found that the key needs to be ordered. Even after sorting the key using TreeMap, it still cannot write.
The code is as follows:
private void insert() {
TreeMap<String, String> orderedPairs = new TreeMap<>();
for (FurionSceneResult element : elements) {
// String key = String.format(tikvKey, element.getPrimaryKey(), element.getSceneId()) ;// Cannot write
String key = "key_" + System.currentTimeMillis();// Can write
String value = element.toHbaseString();
orderedPairs.put(key, value);
}
Map<ByteString, ByteString> kvPairs = new HashMap<>();
for (String key : orderedPairs.keySet()) {
kvPairs.put(ByteString.copyFromUtf8(key), ByteString.copyFromUtf8(orderedPairs.get(key)));
}
tiKVClient.batchPut(kvPairs, TTL);
log.info("==================== batchPut success ====================");
elements.clear();
}
[Resource Configuration]
PD Node: cpu: “32” memory: 48Gi
KV Node: cpu: “16” memory: 32Gi
16 KV Nodes