From e5bc8b00aea5d565c592d0831c99022cf88c6c26 Mon Sep 17 00:00:00 2001 From: James Blair Date: Fri, 16 Feb 2024 21:08:20 +1300 Subject: [PATCH] mvcc: Printing etcd backend database related metrics inside scheduleCompaction function Backporting commit 21bbc82 to etcd 3.4 To improve traceability of backend database usage, Added below parameter related to backend database usage metrics inside scheduledCompaction function. current-db-size-bytes current-db-size current-db-size-in-use-bytes current-db-size-in-use Signed-off-by: James Blair --- mvcc/kvstore_compaction.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mvcc/kvstore_compaction.go b/mvcc/kvstore_compaction.go index 4c6b062b4..963ebe950 100644 --- a/mvcc/kvstore_compaction.go +++ b/mvcc/kvstore_compaction.go @@ -18,6 +18,7 @@ import ( "encoding/binary" "time" + humanize "github.com/dustin/go-humanize" "go.uber.org/zap" ) @@ -52,11 +53,16 @@ func (s *store) scheduleCompaction(compactMainRev int64, keep map[revision]struc revToBytes(revision{main: compactMainRev}, rbytes) tx.UnsafePut(metaBucketName, finishedCompactKeyName, rbytes) tx.Unlock() + size, sizeInUse := s.b.Size(), s.b.SizeInUse() if s.lg != nil { s.lg.Info( "finished scheduled compaction", zap.Int64("compact-revision", compactMainRev), zap.Duration("took", time.Since(totalStart)), + zap.Int64("current-db-size-bytes", size), + zap.String("current-db-size", humanize.Bytes(uint64(size))), + zap.Int64("current-db-size-in-use-bytes", sizeInUse), + zap.String("current-db-size-in-use", humanize.Bytes(uint64(sizeInUse))), ) } else { plog.Infof("finished scheduled compaction at %d (took %v)", compactMainRev, time.Since(totalStart))