From be19b98d8229d049846fa7dd167aafb511da0195 Mon Sep 17 00:00:00 2001 From: ethqunzhong Date: Mon, 23 Sep 2024 16:26:57 +0800 Subject: [PATCH 1/2] add metrics: total_entry_log_space_bytes --- .../bookie/BookKeeperServerStats.java | 1 + .../bookie/GarbageCollectorThread.java | 10 ++++++++-- .../bookie/stats/GarbageCollectorStats.java | 19 +++++++++++++++++++ 3 files changed, 28 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..f284a7e5f74 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 TOTAL_ENTRY_LOG_SPACE_BYTES = "TOTAL_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 5126e79802b..66b2a593c52 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,8 +527,10 @@ 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. entryLogMetaMap.forEach((entryLogId, meta) -> { try { @@ -550,9 +555,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..fd4068d1410 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 @@ -35,6 +35,7 @@ import static org.apache.bookkeeper.bookie.BookKeeperServerStats.RECLAIMED_DELETION_SPACE_BYTES; import static org.apache.bookkeeper.bookie.BookKeeperServerStats.RECLAIM_FAILED_TO_DELETE; import static org.apache.bookkeeper.bookie.BookKeeperServerStats.THREAD_RUNTIME; +import static org.apache.bookkeeper.bookie.BookKeeperServerStats.TOTAL_ENTRY_LOG_SPACE_BYTES; import java.util.function.Supplier; import lombok.Getter; @@ -101,6 +102,11 @@ public class GarbageCollectorStats { help = "Current number of active entry log space bytes" ) private final Gauge activeEntryLogSpaceBytesGauge; + @StatsDoc( + name = TOTAL_ENTRY_LOG_SPACE_BYTES, + help = "Current number of total entry log space bytes" + ) + private final Gauge totalEntryLogSpaceBytesGauge; @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 totalEntryLogSpaceBytesSupplier, Supplier activeLedgerCountSupplier, Supplier entryLogCompactRatioSupplier, Supplier usageBuckets) { @@ -174,6 +181,18 @@ public Long getSample() { } }; statsLogger.registerGauge(ACTIVE_ENTRY_LOG_SPACE_BYTES, activeEntryLogSpaceBytesGauge); + this.totalEntryLogSpaceBytesGauge = new Gauge() { + @Override + public Long getDefaultValue() { + return 0L; + } + + @Override + public Long getSample() { + return totalEntryLogSpaceBytesSupplier.get(); + } + }; + statsLogger.registerGauge(TOTAL_ENTRY_LOG_SPACE_BYTES, totalEntryLogSpaceBytesGauge); this.activeLedgerCountGauge = new Gauge() { @Override public Integer getDefaultValue() { From 419409dca3dbee18ca838a5ed3f7db34d051105e Mon Sep 17 00:00:00 2001 From: ethqunzhong Date: Mon, 23 Sep 2024 16:39:48 +0800 Subject: [PATCH 2/2] remove Non-essential modification --- .../org/apache/bookkeeper/bookie/GarbageCollectorThread.java | 1 - 1 file changed, 1 deletion(-) 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 66b2a593c52..02dd6519613 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 @@ -530,7 +530,6 @@ private void doGcEntryLogs() throws EntryLogMetadataMapException { AtomicLong activeEntryLogSizeAcc = new AtomicLong(0L); AtomicLong totalEntryLogSizeAcc = new AtomicLong(0L); - // Loop through all of the entry logs and remove the non-active ledgers. entryLogMetaMap.forEach((entryLogId, meta) -> { try {