From 606db747eae9856fed0aeb3f16ef01e7c9254e26 Mon Sep 17 00:00:00 2001 From: YingQun Zhong Date: Tue, 18 Feb 2025 09:41:17 +0800 Subject: [PATCH] [improve] add metrics: total_entry_log_space_bytes (#4507) ### Motivation add metric `TOTAL_ENTRY_LOG_SPACE_BYTES` As a supplement to metric `ACTIVE_ENTRY_LOG_SPACE_BYTES` This allows us to easily analyze the proportion of valid data in the cluster entry log. ### Changes 1. add metric `TOTAL_ENTRY_LOG_SPACE_BYTES` in GarbageCollectorStats. 2. Standardize totalEntryLogSize and activeEntryLogSize naming. Signed-off-by: Zhangjian He Co-authored-by: Zhangjian He --- .../bookie/BookKeeperServerStats.java | 1 + .../bookie/GarbageCollectorThread.java | 9 +++++++-- .../bookie/stats/GarbageCollectorStats.java | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookKeeperServerStats.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookKeeperServerStats.java index d9505b44a83..cc1d3a4ad60 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookKeeperServerStats.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookKeeperServerStats.java @@ -146,6 +146,7 @@ public interface BookKeeperServerStats { // Compaction/Garbage Collection Related Counters String ACTIVE_ENTRY_LOG_COUNT = "ACTIVE_ENTRY_LOG_TOTAL"; String ACTIVE_ENTRY_LOG_SPACE_BYTES = "ACTIVE_ENTRY_LOG_SPACE_BYTES"; + String ENTRY_LOG_SPACE_BYTES = "ENTRY_LOG_SPACE_BYTES"; String RECLAIMED_COMPACTION_SPACE_BYTES = "RECLAIMED_COMPACTION_SPACE_BYTES"; String RECLAIMED_DELETION_SPACE_BYTES = "RECLAIMED_DELETION_SPACE_BYTES"; String RECLAIM_FAILED_TO_DELETE = "RECLAIM_FAILED_TO_DELETE"; diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java index 25c42e8e4e6..f9bdef9d565 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java @@ -97,6 +97,7 @@ public class GarbageCollectorThread implements Runnable { // Stats loggers for garbage collection operations private final GarbageCollectorStats gcStats; + private volatile long activeEntryLogSize; private volatile long totalEntryLogSize; private volatile int numActiveEntryLogs; private volatile double entryLogCompactRatio; @@ -175,6 +176,7 @@ public GarbageCollectorThread(ServerConfiguration conf, this.gcWaitTime = conf.getGcWaitTime(); this.numActiveEntryLogs = 0; + this.activeEntryLogSize = 0L; this.totalEntryLogSize = 0L; this.entryLogCompactRatio = 0.0; this.currentEntryLogUsageBuckets = new int[ENTRY_LOG_USAGE_SEGMENT_COUNT]; @@ -182,6 +184,7 @@ public GarbageCollectorThread(ServerConfiguration conf, this.gcStats = new GarbageCollectorStats( statsLogger, () -> numActiveEntryLogs, + () -> activeEntryLogSize, () -> totalEntryLogSize, () -> garbageCollector.getNumActiveLedgers(), () -> entryLogCompactRatio, @@ -524,6 +527,7 @@ private void doGcLedgers() { */ private void doGcEntryLogs() throws EntryLogMetadataMapException { // Get a cumulative count, don't update until complete + AtomicLong activeEntryLogSizeAcc = new AtomicLong(0L); AtomicLong totalEntryLogSizeAcc = new AtomicLong(0L); // Loop through all of the entry logs and remove the non-active ledgers. @@ -550,9 +554,10 @@ private void doGcEntryLogs() throws EntryLogMetadataMapException { // schedule task LOG.warn("Failed to remove ledger from entry-log metadata {}", entryLogId, e); } - totalEntryLogSizeAcc.getAndAdd(meta.getRemainingSize()); + activeEntryLogSizeAcc.getAndAdd(meta.getRemainingSize()); + totalEntryLogSizeAcc.getAndAdd(meta.getTotalSize()); }); - + this.activeEntryLogSize = activeEntryLogSizeAcc.get(); this.totalEntryLogSize = totalEntryLogSizeAcc.get(); this.numActiveEntryLogs = entryLogMetaMap.size(); } diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/stats/GarbageCollectorStats.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/stats/GarbageCollectorStats.java index 0b88a5effec..f579036df08 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/stats/GarbageCollectorStats.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/stats/GarbageCollectorStats.java @@ -27,6 +27,7 @@ import static org.apache.bookkeeper.bookie.BookKeeperServerStats.COMPACT_RUNTIME; import static org.apache.bookkeeper.bookie.BookKeeperServerStats.DELETED_LEDGER_COUNT; import static org.apache.bookkeeper.bookie.BookKeeperServerStats.ENTRY_LOG_COMPACT_RATIO; +import static org.apache.bookkeeper.bookie.BookKeeperServerStats.ENTRY_LOG_SPACE_BYTES; import static org.apache.bookkeeper.bookie.BookKeeperServerStats.EXTRACT_META_RUNTIME; import static org.apache.bookkeeper.bookie.BookKeeperServerStats.GC_LEDGER_RUNTIME; import static org.apache.bookkeeper.bookie.BookKeeperServerStats.MAJOR_COMPACTION_COUNT; @@ -101,6 +102,11 @@ public class GarbageCollectorStats { help = "Current number of active entry log space bytes" ) private final Gauge activeEntryLogSpaceBytesGauge; + @StatsDoc( + name = ENTRY_LOG_SPACE_BYTES, + help = "Current number of total entry log space bytes" + ) + private final Gauge entryLogSpaceBytesGauge; @StatsDoc( name = ACTIVE_LEDGER_COUNT, help = "Current number of active ledgers" @@ -133,6 +139,7 @@ public class GarbageCollectorStats { public GarbageCollectorStats(StatsLogger statsLogger, Supplier activeEntryLogCountSupplier, Supplier activeEntryLogSpaceBytesSupplier, + Supplier entryLogSpaceBytesSupplier, Supplier activeLedgerCountSupplier, Supplier entryLogCompactRatioSupplier, Supplier usageBuckets) { @@ -174,6 +181,18 @@ public Long getSample() { } }; statsLogger.registerGauge(ACTIVE_ENTRY_LOG_SPACE_BYTES, activeEntryLogSpaceBytesGauge); + this.entryLogSpaceBytesGauge = new Gauge() { + @Override + public Long getDefaultValue() { + return 0L; + } + + @Override + public Long getSample() { + return entryLogSpaceBytesSupplier.get(); + } + }; + statsLogger.registerGauge(ENTRY_LOG_SPACE_BYTES, entryLogSpaceBytesGauge); this.activeLedgerCountGauge = new Gauge() { @Override public Integer getDefaultValue() {