Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: raft-engine的存储空间占用大小超过预期
【TiDB Usage Environment】Test Environment
【TiDB Version】
select version();
+--------------------+
| version() |
+--------------------+
| 8.0.11-TiDB-v7.4.0 |
+--------------------+
【Reproduction Path】
Repeatedly creating and deleting tables in a database.
【Encountered Problem: Phenomenon and Impact】
The space size of the raft-engine folder under the TiKV storage path exceeds expectations.
> du -h --max-depth=1
36G ./raft-engine
31G ./tablets
4.0K ./import
4.0K ./tablet_snap
66G .
Checking the files in the raft-engine folder, a large number of files were found. The result sorted by time is shown in the figure below, with about 130 files.
The relevant configuration of the TiDB cluster is as follows:
MySQL [(none)]> show config where name like '%raftstore.raft-log-gc%';
+---------+-------------------+-----------------------------------------------------+--------+
| Type | Instance | Name | Value |
+---------+-------------------+-----------------------------------------------------+--------+
| tikv | 49.52.27.20:20162 | raftstore.raft-log-gc-count-limit | 10000 |
| tikv | 49.52.27.20:20162 | raftstore.raft-log-gc-size-limit | 200MiB |
| tikv | 49.52.27.20:20162 | raftstore.raft-log-gc-threshold | 50 |
| tikv | 49.52.27.20:20162 | raftstore.raft-log-gc-tick-interval | 3s |
| tikv | 49.52.27.20:20161 | raftstore.raft-log-gc-count-limit | 10000 |
| tikv | 49.52.27.20:20161 | raftstore.raft-log-gc-size-limit | 200MiB |
| tikv | 49.52.27.20:20161 | raftstore.raft-log-gc-threshold | 50 |
| tikv | 49.52.27.20:20161 | raftstore.raft-log-gc-tick-interval | 3s |
| tikv | 49.52.27.20:20160 | raftstore.raft-log-gc-count-limit | 10000 |
| tikv | 49.52.27.20:20160 | raftstore.raft-log-gc-size-limit | 200MiB |
| tikv | 49.52.27.20:20160 | raftstore.raft-log-gc-threshold | 50 |
| tikv | 49.52.27.20:20160 | raftstore.raft-log-gc-tick-interval | 3s |
| tiflash | 49.52.27.20:3930 | raftstore-proxy.raftstore.raft-log-gc-count-limit | 73728 |
| tiflash | 49.52.27.20:3930 | raftstore-proxy.raftstore.raft-log-gc-size-limit | 72MiB |
| tiflash | 49.52.27.20:3930 | raftstore-proxy.raftstore.raft-log-gc-threshold | 50 |
| tiflash | 49.52.27.20:3930 | raftstore-proxy.raftstore.raft-log-gc-tick-interval | 3s |
+---------+-------------------+-----------------------------------------------------+--------+
Among them, raftstore.raft-log-gc-size-limit is 200MiB, which is much smaller than the actual 36G. raftstore.raft-log-gc-tick-interval is 3s, but the time difference of the raftlog in the directory reaches the minute level, so the extra raftlog should be able to be deleted.
Currently, the logs have been temporarily cleared through tiup clean --all, but I would like to know how the space of the raft-engine directory limited by the TiDB configuration items is calculated and how to limit the space usage of the raft-engine directory. Thank you!
Additionally, the configuration file of the cluster tikv is as follows:
tikv:
log.file.max-backups: 10
log.level: error
readpool.coprocessor.use-unified-pool: true
readpool.storage.use-unified-pool: false
rocksdb.max-total-wal-size: 1
storage.engine: partitioned-raft-kv