Skip to content

Commit 606db74

Browse files
[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 <[email protected]> Co-authored-by: Zhangjian He <[email protected]>
1 parent b8082f6 commit 606db74

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookKeeperServerStats.java

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public interface BookKeeperServerStats {
146146
// Compaction/Garbage Collection Related Counters
147147
String ACTIVE_ENTRY_LOG_COUNT = "ACTIVE_ENTRY_LOG_TOTAL";
148148
String ACTIVE_ENTRY_LOG_SPACE_BYTES = "ACTIVE_ENTRY_LOG_SPACE_BYTES";
149+
String ENTRY_LOG_SPACE_BYTES = "ENTRY_LOG_SPACE_BYTES";
149150
String RECLAIMED_COMPACTION_SPACE_BYTES = "RECLAIMED_COMPACTION_SPACE_BYTES";
150151
String RECLAIMED_DELETION_SPACE_BYTES = "RECLAIMED_DELETION_SPACE_BYTES";
151152
String RECLAIM_FAILED_TO_DELETE = "RECLAIM_FAILED_TO_DELETE";

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public class GarbageCollectorThread implements Runnable {
9797
// Stats loggers for garbage collection operations
9898
private final GarbageCollectorStats gcStats;
9999

100+
private volatile long activeEntryLogSize;
100101
private volatile long totalEntryLogSize;
101102
private volatile int numActiveEntryLogs;
102103
private volatile double entryLogCompactRatio;
@@ -175,13 +176,15 @@ public GarbageCollectorThread(ServerConfiguration conf,
175176
this.gcWaitTime = conf.getGcWaitTime();
176177

177178
this.numActiveEntryLogs = 0;
179+
this.activeEntryLogSize = 0L;
178180
this.totalEntryLogSize = 0L;
179181
this.entryLogCompactRatio = 0.0;
180182
this.currentEntryLogUsageBuckets = new int[ENTRY_LOG_USAGE_SEGMENT_COUNT];
181183
this.garbageCollector = new ScanAndCompareGarbageCollector(ledgerManager, ledgerStorage, conf, statsLogger);
182184
this.gcStats = new GarbageCollectorStats(
183185
statsLogger,
184186
() -> numActiveEntryLogs,
187+
() -> activeEntryLogSize,
185188
() -> totalEntryLogSize,
186189
() -> garbageCollector.getNumActiveLedgers(),
187190
() -> entryLogCompactRatio,
@@ -524,6 +527,7 @@ private void doGcLedgers() {
524527
*/
525528
private void doGcEntryLogs() throws EntryLogMetadataMapException {
526529
// Get a cumulative count, don't update until complete
530+
AtomicLong activeEntryLogSizeAcc = new AtomicLong(0L);
527531
AtomicLong totalEntryLogSizeAcc = new AtomicLong(0L);
528532

529533
// Loop through all of the entry logs and remove the non-active ledgers.
@@ -550,9 +554,10 @@ private void doGcEntryLogs() throws EntryLogMetadataMapException {
550554
// schedule task
551555
LOG.warn("Failed to remove ledger from entry-log metadata {}", entryLogId, e);
552556
}
553-
totalEntryLogSizeAcc.getAndAdd(meta.getRemainingSize());
557+
activeEntryLogSizeAcc.getAndAdd(meta.getRemainingSize());
558+
totalEntryLogSizeAcc.getAndAdd(meta.getTotalSize());
554559
});
555-
560+
this.activeEntryLogSize = activeEntryLogSizeAcc.get();
556561
this.totalEntryLogSize = totalEntryLogSizeAcc.get();
557562
this.numActiveEntryLogs = entryLogMetaMap.size();
558563
}

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/stats/GarbageCollectorStats.java

+19
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static org.apache.bookkeeper.bookie.BookKeeperServerStats.COMPACT_RUNTIME;
2828
import static org.apache.bookkeeper.bookie.BookKeeperServerStats.DELETED_LEDGER_COUNT;
2929
import static org.apache.bookkeeper.bookie.BookKeeperServerStats.ENTRY_LOG_COMPACT_RATIO;
30+
import static org.apache.bookkeeper.bookie.BookKeeperServerStats.ENTRY_LOG_SPACE_BYTES;
3031
import static org.apache.bookkeeper.bookie.BookKeeperServerStats.EXTRACT_META_RUNTIME;
3132
import static org.apache.bookkeeper.bookie.BookKeeperServerStats.GC_LEDGER_RUNTIME;
3233
import static org.apache.bookkeeper.bookie.BookKeeperServerStats.MAJOR_COMPACTION_COUNT;
@@ -101,6 +102,11 @@ public class GarbageCollectorStats {
101102
help = "Current number of active entry log space bytes"
102103
)
103104
private final Gauge<Long> activeEntryLogSpaceBytesGauge;
105+
@StatsDoc(
106+
name = ENTRY_LOG_SPACE_BYTES,
107+
help = "Current number of total entry log space bytes"
108+
)
109+
private final Gauge<Long> entryLogSpaceBytesGauge;
104110
@StatsDoc(
105111
name = ACTIVE_LEDGER_COUNT,
106112
help = "Current number of active ledgers"
@@ -133,6 +139,7 @@ public class GarbageCollectorStats {
133139
public GarbageCollectorStats(StatsLogger statsLogger,
134140
Supplier<Integer> activeEntryLogCountSupplier,
135141
Supplier<Long> activeEntryLogSpaceBytesSupplier,
142+
Supplier<Long> entryLogSpaceBytesSupplier,
136143
Supplier<Integer> activeLedgerCountSupplier,
137144
Supplier<Double> entryLogCompactRatioSupplier,
138145
Supplier<int[]> usageBuckets) {
@@ -174,6 +181,18 @@ public Long getSample() {
174181
}
175182
};
176183
statsLogger.registerGauge(ACTIVE_ENTRY_LOG_SPACE_BYTES, activeEntryLogSpaceBytesGauge);
184+
this.entryLogSpaceBytesGauge = new Gauge<Long>() {
185+
@Override
186+
public Long getDefaultValue() {
187+
return 0L;
188+
}
189+
190+
@Override
191+
public Long getSample() {
192+
return entryLogSpaceBytesSupplier.get();
193+
}
194+
};
195+
statsLogger.registerGauge(ENTRY_LOG_SPACE_BYTES, entryLogSpaceBytesGauge);
177196
this.activeLedgerCountGauge = new Gauge<Integer>() {
178197
@Override
179198
public Integer getDefaultValue() {

0 commit comments

Comments
 (0)