As the topic suggests, how can I implement a batch operation in TiKV that includes both put and delete operations?
Currently, the only solution I can think of is using batchPut along with TTL operations, but how do I set the expiration time for the keys to be deleted?
In TiKV, you can use the RawKV interface to perform Put and Delete operations. Here is a simple example demonstrating how to perform Put and Delete operations in a Batch operation:
You answered about setting a batch TTL for all keys. What I want to know is how to set an expiration TTL for a single key, equivalent to the effect of delete.
I don’t quite understand.
Do you mean that you want to batch put, but one or several keys in this batch are the ones you don’t want?
Or even the unwanted key is not in the batch you are putting?
Because you are not using transactional KV access, you have to complete batch put + delete in one call, is that what you mean?
Well, it should be this. Another question, can the transaction interface and RawKv interface be called simultaneously? That is, can a project have both RawClient and transaction Client? Will this have any impact?
However, this document hasn’t been updated for a long time, and the statements in the TiKV configuration are different.
* Data is divided into ranges based on usage, supporting the coexistence of a single TiDB cluster, transactional KV, and RawKV applications.
I understand that by configuring api-version=2 here, it can achieve coexistence whether TiDB uses TiKV for storage or clients access through txn or raw mode.
Of course, I haven’t actually tried this configuration.
Let’s wait and see if any other experts can provide an explanation.
Then let’s not mix them for now. Actually, as I initially asked, if we can only choose RawKv, the BatchPut of RawKv is atomic, and all key-values in BatchPut can have a TTL. If we can set the TTL of the key we want to delete to -1 (expired), it can actually achieve the effect of using a transactional batch; for example:
That’s not all; the key point is that TiKV’s TTL is disabled by default. Enabling it requires setting api-version=2. There’s also a long section of red warning text.
It seems quite difficult to manage without upgrading.
The application team will have to find a solution.