How do RocksDB Raft and RocksDB KV Region work together in TiKV?

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

Original topic: TiKV的rocksdb raft与rocksdb kv region之间是如何工作的?

| username: alfred

【TiDB Usage Environment】Production\Test Environment\POC
【TiDB Version】
【Encountered Issue】
【Reproduction Path】What operations were performed that led to the issue
【Issue Phenomenon and Impact】

| username: ddhe9527 | Original post link

You can refer to this post

| username: alfred | Original post link

Is RocksDB Raft used to store the WAL logs of TiKV Leader, and then synchronize the WAL to the follower’s RocksDB Raft through the Raft protocol, and then apply it to the RocksDB KV region?

| username: alfred | Original post link

So the Raft protocol exists between the RocksDB Raft of TiKV nodes, rather than between the RocksDB KV regions?

| username: ddhe9527 | Original post link

The order is reversed. First, replicate the data to the majority through the Raft log, and then write to the KVDB. At this point, writing to the memtable will also write to the WAL.

| username: ddhe9527 | Original post link

Raft exists among multiple replicas of the same region, and each region is an independent Raft group.

| username: Raymond | Original post link

So, may I ask if both memtable and Immutable Memtable exist in RocksDB KV?

| username: ddhe9527 | Original post link

Memtable and Immutable Memtable are both in-memory components of RocksDB.

| username: alfred | Original post link

Each TiKV node has 2 RocksDB instances, namely the RocksDB Raft instance and the RocksDB KV Region instance on the TiKV node, and both have their own WAL, memtable, and Immutable Memtable components. According to the course, the RocksDB Raft instances on each TiKV node synchronize transaction operation logs through the Raft protocol to ensure distributed consistency, and then apply them to the RocksDB KV Region instance. So, do the RocksDB KV Region instances also have the Raft protocol?

| username: alfred | Original post link

Each TiKV node has 2 RocksDB instances, namely the RocksDB Raft instance and the RocksDB KV Region instance, each with its own WAL, memtable, and Immutable Memtable components. According to the course, the RocksDB Raft instances on each TiKV node synchronize transaction operation logs through the Raft protocol to ensure distributed consistency, and then apply them to the RocksDB KV Region instance. So, do the RocksDB KV Region instances also use the Raft protocol?

| username: ddhe9527 | Original post link

In the entire Raft process, both RocksDB Raft and RocksDB KV need to participate. The final step, apply, involves applying the Raft log from RocksDB Raft to RocksDB KV. Only then is the entire Raft process complete.