# Read Data: Readindex Read
__*TiKV Read*__
__*Data reading*__
__*readIndex Read*__
__*ReadIndex*__

![left](./student-guide/diagram/ReadIndexRead01_aa_001_2022051.png)

------------------------------------------------------------
When it comes to reading, TiKV first needs to guarantee linear consistency, which is called linear consistency. For example, at 10:00:00 a.m., we change key = 1, value = Tom to key = 1, value = Jack and commit, so that is, after 10:00:00 a.m., we can't read the key = 1, value = Tom.

Here, let's first discuss the situation of reading from leader. Let's take a look at a simplified process first:

Assuming we want to read key = 1,
1. The client asks PD about the region where key = 1 is
2. PD informs the Leader about the region location (TiKV node)
3. TiDB Server sends a read command to the TiKV node where the leader is located
4. The Leader node accepts the read command, read the RocksDB KV and return the data to the client

The only problem we need to solve at this point is that when we confirm the leader (step 2) until we read it (step 4), we can ensure that the node is still the leader without switching the leader role during this process.

The so-called ReadIndex Read solves this problem. Let's take a look at the specific process:
1. When TiKV receives a read request, it records the current log (raft log) sequence number, also called commit index, into a variable readIndex.
2. After that, this node initiates a heartbeat to other nodes. If most nodes return the corresponding heartbeat response (heartbeat response), then the leader can be sure that it is still the leader. On the other hand, we believe that the node at that point is no longer the leader and needs to be reread by the TiDB Server.
3. If you confirm that the current node is the leader, wait for the raft log (raft log) to be applied until the sequence number of the log (raft log), that is, the apply index, exceeds the readIndex, so that consistency reads can be safely provided.
4. Read the rocksDB of the leader node and return the result to the TiDB Server.

Here, we have introduced ReadIndex Read, and the follower read function that we will explain later is also implement with it. Let's first introduce an optimization method for readIndex Read, which is called Lease Read, or Local Read.