Can TiKV create replicas?

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

Original topic: tikv可以创建副本吗

| username: TiDBer_2CPYnSMQ

My idea is: for example, there are two TiKV nodes, 5.1 and 5.2. One write request writes 123 to 5.1, and another write request writes 456 to 5.2. Then, the request to read 123 will always read from 5.1. I want to extend the replica of 5.1 to achieve load balancing. Additionally, if this is possible, can we specify a read replica (for example, if 5.1 has an extended replica on machine 5.5, can we specify that every read request for 123 goes to 5.5)?

| username: Kongdom | Original post link

I didn’t quite understand what you meant.
The TiDB cluster is load-balanced by default. For example, in a cluster with three servers 5.1, 5.2, and 5.3, with three replicas, when you write 123, the leader replica will be written to 5.1, and the follower replicas will be automatically written to 5.2 and 5.3. By default, reads are performed from the leader replica, and the leader is dynamically switched, so it is not necessarily always on 5.1.

| username: TiDBer_2CPYnSMQ | Original post link

Are the 5.1, 5.2, and 5.3 you mentioned three KV nodes?

| username: Kongdom | Original post link

Yes, there are three TiKV nodes.

| username: TiDBer_2CPYnSMQ | Original post link

Are you saying that after writing 123, 5.1kv itself stored 123, and then 5.1 also created a leader replica to store 123? Or does 5.1 only have the leader? What I mean is whether there are two storage instances on 5.1 or just one. In my context, two means 5.1 itself plus the leader, and one storage means just the leader.

| username: Kongdom | Original post link

In version 5.1, 123 is stored. In versions 5.2 and 5.3, 123 is also stored asynchronously. When retrieving data, if 5.1 is the leader, it is retrieved from 5.1; if 5.2 is the leader, it is retrieved from 5.2.
Is this understanding correct?

| username: TiDBer_2CPYnSMQ | Original post link

Understood. So how can we further understand that the leader is dynamic?

| username: Kongdom | Original post link

You can refer to this

| username: TiDBer_2CPYnSMQ | Original post link

Okay. I have this scenario where I use a LIKE query. I’m not very familiar with TiDB. For example, in MySQL, using double % can cause a full table scan, and if there are writes at the same time, it might cause a deadlock. Will this happen in TiDB?

| username: Kongdom | Original post link

No, because MVCC control is used.

| username: 特雷西-迈克-格雷迪 | Original post link

This MySQL doesn’t work either, how could it lock?

| username: TiDBer_2CPYnSMQ | Original post link

Okay. Will using double %% in TiDB’s LIKE cause a full table scan, and how is the performance of LIKE?

| username: Kongdom | Original post link

It will inevitably cause a full table scan, not recommended to use.

| username: xiaohetao | Original post link

Are you looking to implement read-write separation?
Currently, TiDB does not have complete read-write separation technology. It only has large labels, but followers will only read when the system is slow.

| username: TiDBer_2CPYnSMQ | Original post link

My idea is to read from the replica when I like, so it won’t affect the write. Can TiDB achieve this?

| username: TiDBer_2CPYnSMQ | Original post link

When I read replicas during a like operation, it won’t affect the writes. Can TiDB achieve this?

| username: xiaohetao | Original post link

TiDB currently does not have this feature.

| username: 特雷西-迈克-格雷迪 | Original post link

Reading does not affect writing.

| username: Kongdom | Original post link

If you are using read-write separation, reading from the leader won’t have any impact. If you are talking about a full table scan, reading from any replica will have an impact.

| username: 张雨齐0720 | Original post link

Partitioning the table will distribute the fields you want to scatter. However, it won’t solve the issue of a full table scan with LIKE. If the left side is not %, then it can use the index.