RawKVClient#batchPut cannot write

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: RawKVClient#batchPut不能写入

| username: TiDBer_lYUbxL7V

[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

| username: xfworld | Original post link

How about directly using the client’s batchPut API for writing? Without going through Flink.

| username: TiDBer_lYUbxL7V | Original post link

Sure.
I don’t think it has anything to do with Flink. The problem lies with the key. I can’t write in the normal business key, but it works with a timestamp.
To add, the key is a 34-character string, with a batch size of 1000.

| username: xfworld | Original post link

A key is just a description of a key-value pair. How it is generated and used is entirely up to you.

Since there are processing issues with Flink’s custom sink, it is recommended to track it closely.

The RawKV API has undergone numerous stress tests and several iterations of versions, making it very mature.

| username: TiDBer_lYUbxL7V | Original post link

Single put insertion is also very slow.

Simulated key, a real user primary key + timestamp, 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());
            String key = String.format(tikvKey, "xxxxxxxxb_xxxxTuxxxsWV6Jxxxx", element.getSceneId());
            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();
    }

It can be written, and the speed is very fast.

I would like to ask, personally guessing, the user base is in the tens of millions per day, and the scene is 1000, so there will be a lot of keys, which will cause slow region finding. How does the key here affect the writing process?

| username: xfworld | Original post link

Here are some hot issues you can refer to for troubleshooting:

For performance-related issues, you can refer to the following documents for troubleshooting:

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.