From 8c9df30e28a3b95efe537afe9930de2150999441 Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Mon, 4 Mar 2019 22:56:46 -0800 Subject: [PATCH] libs/db: Add cleveldb.Stats() (#3379) Fixes: #3378 * Add stats to cleveldb implementation * update changelog * remote TODO also - sort keys - preallocate memory * fix const initializer []string literal is not a constant * add test --- CHANGELOG_PENDING.md | 9 +++++++++ libs/db/c_level_db.go | 14 +++++++++++--- libs/db/c_level_db_test.go | 9 +++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index fe9a87d8a..cbb4077c7 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -30,6 +30,15 @@ Special thanks to external contributors on this release: ### IMPROVEMENTS: - [libs/common] \#3238 exit with zero (0) code upon receiving SIGTERM/SIGINT +- [libs/db] \#3378 CLevelDB#Stats now returns the following properties: + - leveldb.num-files-at-level{n} + - leveldb.stats + - leveldb.sstables + - leveldb.blockpool + - leveldb.cachedblock + - leveldb.openedtables + - leveldb.alivesnaps + - leveldb.aliveiters ### BUG FIXES: diff --git a/libs/db/c_level_db.go b/libs/db/c_level_db.go index 7f74b2a71..e411dfdd0 100644 --- a/libs/db/c_level_db.go +++ b/libs/db/c_level_db.go @@ -128,10 +128,18 @@ func (db *CLevelDB) Print() { // Implements DB. func (db *CLevelDB) Stats() map[string]string { - // TODO: Find the available properties for the C LevelDB implementation - keys := []string{} + keys := []string{ + "leveldb.aliveiters", + "leveldb.alivesnaps", + "leveldb.blockpool", + "leveldb.cachedblock", + "leveldb.num-files-at-level{n}", + "leveldb.openedtables", + "leveldb.sstables", + "leveldb.stats", + } - stats := make(map[string]string) + stats := make(map[string]string, len(keys)) for _, key := range keys { str := db.db.PropertyValue(key) stats[key] = str diff --git a/libs/db/c_level_db_test.go b/libs/db/c_level_db_test.go index eab3dfc41..e71dee0c1 100644 --- a/libs/db/c_level_db_test.go +++ b/libs/db/c_level_db_test.go @@ -99,3 +99,12 @@ func TestCLevelDBBackend(t *testing.T) { _, ok := db.(*CLevelDB) assert.True(t, ok) } + +func TestCLevelDBStats(t *testing.T) { + name := fmt.Sprintf("test_%x", cmn.RandStr(12)) + dir := os.TempDir() + db := NewDB(name, LevelDBBackend, dir) + defer cleanupDBDir(dir, name) + + assert.NotEmpty(t, db.Stats()) +}