How to check the total number of keys in the current database after setting up a three-node TiKV cluster and enabling the enable-ttl mode?

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

Original topic: 建了一个三节点的 TiKV 集群,开启了 enable-ttl 模式,怎么查看当前数据库内 key 的总数呢

| username: Doslin

[TiDB Usage Environment] Testing
[TiDB Version] v7.1.0
[Reproduction Path] What operations were performed to cause the issue
The cluster started running from 2023-06-08 17:00, with storage.enable-ttl: true and storage.ttl-check-poll-interval: 12h configured.
I randomly used BatchPutWithTTL to write 3 million key-value pairs before 2023-06-08 19:00, all set with a 10-hour expiration time.
When I checked the Dashboard TiKV-Details RocksDB - kv/raft Total keys on the Grafana panel at 2023-06-09 09:00, I found that the number did not decrease.

  1. Through which management tools can I see the current total number of surviving keys?
  2. What is the key expiration management strategy in TiKV?

[Encountered Issue: Issue Phenomenon and Impact]
[Resource Configuration]
[Attachments: Screenshots/Logs/Monitoring]


| username: Timber | Original post link

Write a script to use the Iter method of the tikv client to scan the kv stored in tikv.