This is an automated email from the ASF dual-hosted git repository.
maplefu pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new 9442e7fe6 feat(info): expose RocksDB level file count and pending
compaction bytes via info (#3181)
9442e7fe6 is described below
commit 9442e7fe6ed7a24ad318c2fa659cf10b4730cc2b
Author: sryan yuan <[email protected]>
AuthorDate: Wed Sep 17 22:23:56 2025 +0800
feat(info): expose RocksDB level file count and pending compaction bytes
via info (#3181)
This PR implements:
1. **LSM-tree health analysis** by monitoring level file counts
(detects abnormal file distribution patterns)
2. **Proactive write stall prevention** through pending compaction bytes
tracking
Example output after changes:
```
num_files_at_level[metadata]:[0,0,0,0,0,0,1]
estimate_compaction_pending_bytes[metadata]:0
```
---------
Co-authored-by: yxj25245 <[email protected]>
---
src/server/server.cc | 20 ++++++++++++++++++++
tests/gocase/unit/info/info_test.go | 13 +++++++++++++
2 files changed, 33 insertions(+)
diff --git a/src/server/server.cc b/src/server/server.cc
index acd253745..6ca401438 100644
--- a/src/server/server.cc
+++ b/src/server/server.cc
@@ -1024,6 +1024,26 @@ Server::InfoEntries Server::GetRocksDBInfo() {
cf_stats_map["memtable-limit-delays"]);
entries.emplace_back("memtable_count_limit_stop[" + cf_handle->GetName() +
"]",
cf_stats_map["memtable-limit-stops"]);
+
+ // Get the SST file count in all levels
+ std::string sst_file_at_level = "[";
+ for (int level = 0; level < KVROCKS_MAX_LSM_LEVEL; level++) {
+ std::string sst_file_count;
+ db->GetProperty(cf_handle,
rocksdb::DB::Properties::kNumFilesAtLevelPrefix + std::to_string(level),
+ &sst_file_count);
+ if (level != 0) {
+ sst_file_at_level += ",";
+ }
+ sst_file_at_level += sst_file_count;
+ }
+ entries.emplace_back("num_files_at_level[" + cf_handle->GetName() + "]",
sst_file_at_level + "]");
+
+ // Get the estimate pending compaction bytes for the current column family
+ std::string estimate_pending_compaction_bytes;
+ db->GetProperty(cf_handle,
rocksdb::DB::Properties::kEstimatePendingCompactionBytes,
+ &estimate_pending_compaction_bytes);
+ entries.emplace_back("estimate_pending_compaction_bytes[" +
cf_handle->GetName() + "]",
+ estimate_pending_compaction_bytes);
}
auto rocksdb_stats = storage->GetDB()->GetDBOptions().statistics;
diff --git a/tests/gocase/unit/info/info_test.go
b/tests/gocase/unit/info/info_test.go
index 56b28d35a..a853dac8d 100644
--- a/tests/gocase/unit/info/info_test.go
+++ b/tests/gocase/unit/info/info_test.go
@@ -134,6 +134,19 @@ func TestInfo(t *testing.T) {
require.Contains(t, info.Val(), "# Server")
require.Contains(t, info.Val(), "# CPU")
})
+
+ t.Run("get rocksdb level file counts and estimate pending compaction
bytes by INFO", func(t *testing.T) {
+ _, err := rdb.Do(ctx, "SET", "A", "KVROCKS").Result()
+ require.NoError(t, err)
+ _, err = rdb.Do(ctx, "FLUSHMEMTABLE").Result()
+ require.NoError(t, err)
+
+ r := util.FindInfoEntry(rdb,
"num_files_at_level\\[metadata\\]", "rocksdb")
+ require.Equal(t, "[1,0,0,0,0,0,0]", r)
+
+ r = util.FindInfoEntry(rdb,
"estimate_pending_compaction_bytes\\[metadata\\]", "rocksdb")
+ require.NotEqual(t, "", r)
+ })
}
func TestKeyspaceHitMiss(t *testing.T) {