You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by da...@apache.org on 2023/08/31 08:33:11 UTC
[jackrabbit-oak] 01/03: OAK-10378 : added metrics to collect detailedGC cycle & deleted properties data
This is an automated email from the ASF dual-hosted git repository.
daim pushed a commit to branch OAK-10378
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit eaf52462fd10223a1295a5ea2cc2078235aa77e9
Author: Rishabh Kumar <di...@adobe.com>
AuthorDate: Mon Aug 21 15:03:53 2023 +0530
OAK-10378 : added metrics to collect detailedGC cycle & deleted properties data
---
.../document/DetailedRevisionGCStatsCollector.java | 40 ++++++
.../DetailedRevisionGCStatsCollectorImpl.java | 146 +++++++++++++++++++
.../plugins/document/VersionGarbageCollector.java | 42 +++++-
.../DetailedRevisionGCStatsCollectorImplTest.java | 160 +++++++++++++++++++++
.../oak/plugins/document/VersionGCStatsTest.java | 22 ++-
5 files changed, 391 insertions(+), 19 deletions(-)
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DetailedRevisionGCStatsCollector.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DetailedRevisionGCStatsCollector.java
new file mode 100644
index 0000000000..7c85a73e66
--- /dev/null
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DetailedRevisionGCStatsCollector.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document;
+
+import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats;
+
+/**
+ * Collector interface for {@link DocumentNodeStore} Detailed revision garbage collection
+ * statistics.
+ */
+public interface DetailedRevisionGCStatsCollector {
+
+ void documentRead();
+
+ void deletedPropertiesRead(long numProps);
+
+ void propertiesDeleted(long numProps);
+
+ void documentsUpdated(long numDocs);
+
+ void started();
+
+ void finished(VersionGCStats stats);
+}
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DetailedRevisionGCStatsCollectorImpl.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DetailedRevisionGCStatsCollectorImpl.java
new file mode 100644
index 0000000000..d88f6b309d
--- /dev/null
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DetailedRevisionGCStatsCollectorImpl.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document;
+
+import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats;
+import org.apache.jackrabbit.oak.stats.CounterStats;
+import org.apache.jackrabbit.oak.stats.MeterStats;
+import org.apache.jackrabbit.oak.stats.StatisticsProvider;
+import org.apache.jackrabbit.oak.stats.TimerStats;
+
+import static java.util.concurrent.TimeUnit.MICROSECONDS;
+import static org.apache.jackrabbit.oak.stats.StatsOptions.DEFAULT;
+import static org.apache.jackrabbit.oak.stats.StatsOptions.METRICS_ONLY;
+
+/**
+ * {@link DocumentNodeStore} Detailed revision garbage collection statistics.
+ */
+class DetailedRevisionGCStatsCollectorImpl implements DetailedRevisionGCStatsCollector {
+
+ static final String DETAILED_GC = "DetailedGC";
+ static final String READ_DOC = "READ_DOC";
+ static final String READ_DELETED_PROPERTY = "READ_DELETED_PROPERTY";
+ static final String DELETED_PROPERTY = "DELETED_PROPERTY";
+ static final String UPDATED_DOC = "UPDATED_DOC";
+ static final String DETAILED_GC_ACTIVE_TIMER = "DETAILED_GC_ACTIVE_TIMER";
+ static final String DETAILED_GC_TIMER = "DETAILED_GC_TIMER";
+ static final String COLLECT_DETAILED_GARBAGE_TIMER = "COLLECT_DETAILED_GARBAGE_TIMER";
+ static final String COLLECT_DELETED_PROPS_TIMER = "COLLECT_DELETED_PROPS_TIMER";
+ static final String COLLECT_DELETED_OLD_REVS_TIMER = "COLLECT_DELETED_OLD_REVS_TIMER";
+ static final String COLLECT_UNMERGED_BC_TIMER = "COLLECT_UNMERGED_BC_TIMER";
+ static final String DELETE_DETAILED_GC_DOCS_TIMER = "DELETE_DETAILED_GC_DOCS_TIMER";
+
+ static final String COUNTER = "COUNTER";
+ static final String FAILURE_COUNTER = "FAILURE";
+
+ private final MeterStats readDoc;
+ private final MeterStats readDeletedProperty;
+ private final MeterStats deletedProperty;
+ private final MeterStats updatedDoc;
+ private final TimerStats detailedGCActiveTimer;
+ private final TimerStats detailedGCTimer;
+ private final TimerStats collectDetailedGarbageTimer;
+ private final TimerStats collectDeletedPropsTimer;
+ private final TimerStats collectDeletedOldRevsTimer;
+ private final TimerStats collectUnmergedBCTimer;
+ private final TimerStats deleteDetailedGCDocsTimer;
+
+ private final CounterStats counter;
+ private final CounterStats failureCounter;
+
+ DetailedRevisionGCStatsCollectorImpl(StatisticsProvider provider) {
+
+ readDoc = meter(provider, READ_DOC);
+ readDeletedProperty = meter(provider, READ_DELETED_PROPERTY);
+ deletedProperty = meter(provider, DELETED_PROPERTY);
+ updatedDoc = meter(provider, UPDATED_DOC);
+
+ detailedGCActiveTimer = timer(provider, DETAILED_GC_ACTIVE_TIMER);
+ detailedGCTimer = timer(provider, DETAILED_GC_TIMER);
+ collectDetailedGarbageTimer = timer(provider, COLLECT_DETAILED_GARBAGE_TIMER);
+ collectDeletedPropsTimer = timer(provider, COLLECT_DELETED_PROPS_TIMER);
+ collectDeletedOldRevsTimer = timer(provider, COLLECT_DELETED_OLD_REVS_TIMER);
+ collectUnmergedBCTimer = timer(provider, COLLECT_UNMERGED_BC_TIMER);
+ deleteDetailedGCDocsTimer = timer(provider, DELETE_DETAILED_GC_DOCS_TIMER);
+
+ counter = counter(provider, COUNTER);
+ failureCounter = counter(provider, FAILURE_COUNTER);
+ }
+
+ //---------------------< DetailedRevisionGCStatsCollector >-------------------------
+
+ @Override
+ public void documentRead() {
+ readDoc.mark();
+ }
+
+ @Override
+ public void deletedPropertiesRead(long numProps) {
+ readDeletedProperty.mark(numProps);
+ }
+
+ @Override
+ public void propertiesDeleted(long numProps) {
+ deletedProperty.mark(numProps);
+ }
+
+ @Override
+ public void documentsUpdated(long numDocs) {
+ updatedDoc.mark(numDocs);
+ }
+
+ @Override
+ public void started() {
+ counter.inc();
+ }
+
+ @Override
+ public void finished(VersionGCStats stats) {
+ detailedGCActiveTimer.update(stats.detailedGCActiveElapsed, MICROSECONDS);
+ detailedGCTimer.update(stats.detailedGCDocsElapsed, MICROSECONDS);
+ collectDetailedGarbageTimer.update(stats.collectDetailedGarbageElapsed, MICROSECONDS);
+ collectDeletedPropsTimer.update(stats.collectDeletedPropsElapsed, MICROSECONDS);
+ collectDeletedOldRevsTimer.update(stats.collectDeletedOldRevsElapsed, MICROSECONDS);
+ collectUnmergedBCTimer.update(stats.collectUnmergedBCElapsed, MICROSECONDS);
+ deleteDetailedGCDocsTimer.update(stats.deleteDetailedGCDocsElapsed, MICROSECONDS);
+ if (!stats.success) {
+ failureCounter.inc();
+ }
+ }
+
+
+ //----------------------------< internal >----------------------------------
+
+ private static MeterStats meter(StatisticsProvider provider, String name) {
+ return provider.getMeter(qualifiedName(name), DEFAULT);
+ }
+
+ private static TimerStats timer(StatisticsProvider provider, String name) {
+ return provider.getTimer(qualifiedName(name), METRICS_ONLY);
+ }
+
+ private static CounterStats counter(StatisticsProvider provider, String name) {
+ return provider.getCounterStats(qualifiedName(name), METRICS_ONLY);
+ }
+
+ private static String qualifiedName(String metricName) {
+ return DETAILED_GC + "." + metricName;
+ }
+
+}
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
index a32ded6c5b..45ba3bebce 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
@@ -78,6 +78,7 @@ import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_I
import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType.COMMIT_ROOT_ONLY;
import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType.DEFAULT_LEAF;
import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType.DEFAULT_NO_BRANCH;
+import static org.apache.jackrabbit.oak.stats.StatisticsProvider.NOOP;
import static org.slf4j.helpers.MessageFormatter.arrayFormat;
public class VersionGarbageCollector {
@@ -129,7 +130,8 @@ public class VersionGarbageCollector {
private final AtomicReference<GCJob> collector = newReference();
private VersionGCOptions options;
private GCMonitor gcMonitor = GCMonitor.EMPTY;
- private RevisionGCStats gcStats = new RevisionGCStats(StatisticsProvider.NOOP);
+ private RevisionGCStats gcStats = new RevisionGCStats(NOOP);
+ private DetailedRevisionGCStatsCollector detailedGCStats = new DetailedRevisionGCStatsCollectorImpl(NOOP);
VersionGarbageCollector(DocumentNodeStore nodeStore,
VersionGCSupport gcSupport,
@@ -143,6 +145,7 @@ public class VersionGarbageCollector {
void setStatisticsProvider(StatisticsProvider provider) {
this.gcStats = new RevisionGCStats(provider);
+ this.detailedGCStats = new DetailedRevisionGCStatsCollectorImpl(provider);
}
@NotNull
@@ -161,6 +164,9 @@ public class VersionGarbageCollector {
VersionGCStats overall = new VersionGCStats();
overall.active.start();
gcStats.started();
+ if (detailedGCEnabled) {
+ detailedGCStats.started();
+ }
boolean success = false;
try {
long averageDurationMs = 0;
@@ -186,6 +192,9 @@ public class VersionGarbageCollector {
collector.set(null);
overall.success = success;
gcStats.finished(overall);
+ if (detailedGCEnabled) {
+ detailedGCStats.finished(overall);
+ }
if (overall.iterationCount > 1) {
gcMonitor.info("Revision garbage collection finished after {} iterations - aggregate statistics: {}",
overall.iterationCount, overall);
@@ -289,6 +298,7 @@ public class VersionGarbageCollector {
int deletedPropsGCCount;
final TimeDurationFormatter df = TimeDurationFormatter.forLogging();
final Stopwatch active = Stopwatch.createUnstarted();
+ final Stopwatch detailedGCActive = Stopwatch.createUnstarted();
final Stopwatch collectDeletedDocs = Stopwatch.createUnstarted();
final Stopwatch checkDeletedDocs = Stopwatch.createUnstarted();
final Stopwatch detailedGCDocs = Stopwatch.createUnstarted();
@@ -298,12 +308,14 @@ public class VersionGarbageCollector {
final Stopwatch updateResurrectedDocuments = Stopwatch.createUnstarted();
final Stopwatch deleteDeletedDocs = Stopwatch.createUnstarted();
final Stopwatch collectAndDeleteSplitDocs = Stopwatch.createUnstarted();
+ final Stopwatch collectDetailedGarbage = Stopwatch.createUnstarted();
final Stopwatch collectDeletedProps = Stopwatch.createUnstarted();
final Stopwatch collectDeletedOldRevs = Stopwatch.createUnstarted();
final Stopwatch collectUnmergedBC = Stopwatch.createUnstarted();
- long activeElapsed, collectDeletedDocsElapsed, checkDeletedDocsElapsed, deleteDeletedDocsElapsed, collectAndDeleteSplitDocsElapsed,
- deleteSplitDocsElapsed, sortDocIdsElapsed, updateResurrectedDocumentsElapsed, detailedGCDocsElapsed, collectDeletedPropsElapsed,
- deleteDetailedGCDocsElapsed, collectDeletedOldRevsElapsed, collectUnmergedBCElapsed;
+ long activeElapsed, detailedGCActiveElapsed, collectDeletedDocsElapsed, checkDeletedDocsElapsed, deleteDeletedDocsElapsed,
+ collectAndDeleteSplitDocsElapsed, deleteSplitDocsElapsed, sortDocIdsElapsed, updateResurrectedDocumentsElapsed,
+ detailedGCDocsElapsed, collectDetailedGarbageElapsed, collectDeletedPropsElapsed, deleteDetailedGCDocsElapsed,
+ collectDeletedOldRevsElapsed, collectUnmergedBCElapsed;
@Override
public String toString() {
@@ -342,6 +354,7 @@ public class VersionGarbageCollector {
df.format(collectAndDeleteSplitDocs.elapsed(MICROSECONDS), MICROSECONDS),
df.format(detailedGCDocs.elapsed(MICROSECONDS), MICROSECONDS),
df.format(deleteDetailedGCDocs.elapsed(MICROSECONDS), MICROSECONDS),
+ df.format(collectDetailedGarbage.elapsed(MICROSECONDS), MICROSECONDS),
df.format(collectDeletedProps.elapsed(MICROSECONDS), MICROSECONDS),
df.format(collectDeletedOldRevs.elapsed(MICROSECONDS), MICROSECONDS),
df.format(collectUnmergedBC.elapsed(MICROSECONDS), MICROSECONDS),
@@ -361,6 +374,7 @@ public class VersionGarbageCollector {
", updatedDetailedGCDocsCount=" + updatedDetailedGCDocsCount +
", deletedPropsGCCount=" + deletedPropsGCCount +
", iterationCount=" + iterationCount +
+ ", timeDetailedGCActive=" + df.format(detailedGCActiveElapsed, MICROSECONDS) +
", timeActive=" + df.format(activeElapsed, MICROSECONDS) +
", " + timings + "}";
}
@@ -385,6 +399,7 @@ public class VersionGarbageCollector {
if (run.iterationCount > 0) {
// run is cumulative with times in elapsed fields
this.activeElapsed += run.activeElapsed;
+ this.detailedGCActiveElapsed += run.detailedGCActiveElapsed;
this.collectDeletedDocsElapsed += run.collectDeletedDocsElapsed;
this.checkDeletedDocsElapsed += run.checkDeletedDocsElapsed;
this.deleteDeletedDocsElapsed += run.deleteDeletedDocsElapsed;
@@ -394,12 +409,14 @@ public class VersionGarbageCollector {
this.updateResurrectedDocumentsElapsed += run.updateResurrectedDocumentsElapsed;
this.detailedGCDocsElapsed += run.detailedGCDocsElapsed;
this.deleteDetailedGCDocsElapsed += run.deleteDetailedGCDocsElapsed;
+ this.collectDetailedGarbageElapsed += run.collectDetailedGarbageElapsed;
this.collectDeletedPropsElapsed += run.collectDeletedPropsElapsed;
this.collectDeletedOldRevsElapsed += run.collectDeletedOldRevsElapsed;
this.collectUnmergedBCElapsed += run.collectUnmergedBCElapsed;
} else {
// single run -> read from stop watches
this.activeElapsed += run.active.elapsed(MICROSECONDS);
+ this.detailedGCActiveElapsed += run.detailedGCActive.elapsed(MICROSECONDS);
this.collectDeletedDocsElapsed += run.collectDeletedDocs.elapsed(MICROSECONDS);
this.checkDeletedDocsElapsed += run.checkDeletedDocs.elapsed(MICROSECONDS);
this.deleteDeletedDocsElapsed += run.deleteDeletedDocs.elapsed(MICROSECONDS);
@@ -409,6 +426,7 @@ public class VersionGarbageCollector {
this.updateResurrectedDocumentsElapsed += run.updateResurrectedDocuments.elapsed(MICROSECONDS);
this.detailedGCDocsElapsed += run.detailedGCDocs.elapsed(MICROSECONDS);
this.deleteDetailedGCDocsElapsed += run.deleteDetailedGCDocs.elapsed(MICROSECONDS);
+ this.collectDetailedGarbageElapsed += run.collectDetailedGarbage.elapsed(MICROSECONDS);
this.collectDeletedPropsElapsed += run.collectDeletedProps.elapsed(MICROSECONDS);
this.collectDeletedOldRevsElapsed += run.collectDeletedOldRevs.elapsed(MICROSECONDS);
this.collectUnmergedBCElapsed += run.collectUnmergedBC.elapsed(MICROSECONDS);
@@ -424,6 +442,7 @@ public class VersionGarbageCollector {
SORTING,
SPLITS_CLEANUP,
DETAILED_GC,
+ DETAILED_GC_COLLECT_GARBAGE,
DETAILED_GC_COLLECT_PROPS,
DETAILED_GC_COLLECT_OLD_REVS,
DETAILED_GC_COLLECT_UNMERGED_BC,
@@ -457,6 +476,7 @@ public class VersionGarbageCollector {
this.watches.put(GCPhase.SPLITS_CLEANUP, stats.collectAndDeleteSplitDocs);
this.watches.put(GCPhase.UPDATING, stats.updateResurrectedDocuments);
this.watches.put(GCPhase.DETAILED_GC, stats.detailedGCDocs);
+ this.watches.put(GCPhase.DETAILED_GC_COLLECT_GARBAGE, stats.collectDetailedGarbage);
this.watches.put(GCPhase.DETAILED_GC_COLLECT_PROPS, stats.collectDeletedProps);
this.watches.put(GCPhase.DETAILED_GC_COLLECT_OLD_REVS, stats.collectDeletedOldRevs);
this.watches.put(GCPhase.DETAILED_GC_COLLECT_UNMERGED_BC, stats.collectUnmergedBC);
@@ -586,6 +606,7 @@ public class VersionGarbageCollector {
// now run detailed GC if enabled
if (detailedGCEnabled) {
+ stats.detailedGCActive.start();
if (rec.ignoreDetailedGCDueToCheckPoint) {
phases.stats.ignoredDetailedGCDueToCheckPoint = true;
monitor.skipped("Checkpoint prevented detailed revision garbage collection");
@@ -610,6 +631,9 @@ public class VersionGarbageCollector {
rec.evaluate(stats);
monitor.info("Revision garbage collection finished in {}. {}",
TimeDurationFormatter.forLogging().format(phases.elapsed.elapsed(MICROSECONDS), MICROSECONDS), stats);
+ if (detailedGCEnabled) {
+ stats.detailedGCActive.stop();
+ }
stats.active.stop();
return stats;
}
@@ -670,9 +694,9 @@ public class VersionGarbageCollector {
lastDoc = doc;
// collect the data to delete in next step
- if (phases.start(GCPhase.COLLECTING)) {
+ if (phases.start(GCPhase.DETAILED_GC_COLLECT_GARBAGE)) {
gc.collectGarbage(doc, phases);
- phases.stop(GCPhase.COLLECTING);
+ phases.stop(GCPhase.DETAILED_GC_COLLECT_GARBAGE);
}
final Long modified = lastDoc.getModified();
@@ -841,6 +865,7 @@ public class VersionGarbageCollector {
public void collectGarbage(final NodeDocument doc, final GCPhases phases) {
+ detailedGCStats.documentRead();
monitor.info("Collecting Detailed Garbage for doc [{}]", doc.getId());
final UpdateOp op = new UpdateOp(requireNonNull(doc.getId()), false);
@@ -894,6 +919,7 @@ public class VersionGarbageCollector {
.sum();
deletedPropsCountMap.put(doc.getId(), deletedPropsGCCount);
+ detailedGCStats.deletedPropertiesRead(deletedPropsGCCount);
if (log.isDebugEnabled()) {
log.debug("Collected {} deleted properties for document {}", deletedPropsGCCount, doc.getId());
@@ -955,6 +981,10 @@ public class VersionGarbageCollector {
updateOpList.clear();
deletedPropsCountMap.clear();
garbageDocsCount = 0;
+
+ // save stats
+ detailedGCStats.propertiesDeleted(deletedProps);
+ detailedGCStats.documentsUpdated(updatedDocs);
} finally {
delayOnModifications(timer.stop().elapsed(MILLISECONDS), cancel);
}
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DetailedRevisionGCStatsCollectorImplTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DetailedRevisionGCStatsCollectorImplTest.java
new file mode 100644
index 0000000000..a18a624ab7
--- /dev/null
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DetailedRevisionGCStatsCollectorImplTest.java
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.Timer;
+import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
+import org.apache.jackrabbit.oak.plugins.metric.MetricStatisticsProvider;
+import org.apache.jackrabbit.oak.stats.MeterStats;
+import org.junit.After;
+import org.junit.Test;
+
+import java.util.concurrent.ScheduledExecutorService;
+
+import static java.lang.management.ManagementFactory.getPlatformMBeanServer;
+import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.NANOSECONDS;
+import static org.apache.commons.lang3.reflect.FieldUtils.readField;
+import static org.apache.jackrabbit.oak.plugins.document.DetailedRevisionGCStatsCollectorImpl.COLLECT_DELETED_OLD_REVS_TIMER;
+import static org.apache.jackrabbit.oak.plugins.document.DetailedRevisionGCStatsCollectorImpl.COLLECT_DELETED_PROPS_TIMER;
+import static org.apache.jackrabbit.oak.plugins.document.DetailedRevisionGCStatsCollectorImpl.COLLECT_DETAILED_GARBAGE_TIMER;
+import static org.apache.jackrabbit.oak.plugins.document.DetailedRevisionGCStatsCollectorImpl.COLLECT_UNMERGED_BC_TIMER;
+import static org.apache.jackrabbit.oak.plugins.document.DetailedRevisionGCStatsCollectorImpl.COUNTER;
+import static org.apache.jackrabbit.oak.plugins.document.DetailedRevisionGCStatsCollectorImpl.DELETED_PROPERTY;
+import static org.apache.jackrabbit.oak.plugins.document.DetailedRevisionGCStatsCollectorImpl.DELETE_DETAILED_GC_DOCS_TIMER;
+import static org.apache.jackrabbit.oak.plugins.document.DetailedRevisionGCStatsCollectorImpl.DETAILED_GC;
+import static org.apache.jackrabbit.oak.plugins.document.DetailedRevisionGCStatsCollectorImpl.DETAILED_GC_ACTIVE_TIMER;
+import static org.apache.jackrabbit.oak.plugins.document.DetailedRevisionGCStatsCollectorImpl.DETAILED_GC_TIMER;
+import static org.apache.jackrabbit.oak.plugins.document.DetailedRevisionGCStatsCollectorImpl.FAILURE_COUNTER;
+import static org.apache.jackrabbit.oak.plugins.document.DetailedRevisionGCStatsCollectorImpl.READ_DELETED_PROPERTY;
+import static org.apache.jackrabbit.oak.plugins.document.DetailedRevisionGCStatsCollectorImpl.READ_DOC;
+import static org.apache.jackrabbit.oak.plugins.document.DetailedRevisionGCStatsCollectorImpl.UPDATED_DOC;
+import static org.junit.Assert.*;
+
+/**
+ * Unit Cases for {@link DetailedRevisionGCStatsCollectorImpl}
+ */
+public class DetailedRevisionGCStatsCollectorImplTest {
+
+ private final ScheduledExecutorService executor = newSingleThreadScheduledExecutor();
+ private final MetricStatisticsProvider statsProvider = new MetricStatisticsProvider(getPlatformMBeanServer(), executor);
+ private final DetailedRevisionGCStatsCollectorImpl stats = new DetailedRevisionGCStatsCollectorImpl(statsProvider);
+
+ @After
+ public void shutDown(){
+ statsProvider.close();
+ new ExecutorCloser(executor).close();
+ }
+
+ @Test
+ public void getReadDocCount() throws IllegalAccessException {
+ final Meter m = getMeter(READ_DOC);
+ long count = m.getCount();
+ stats.documentRead();
+ assertEquals(count + 1, m.getCount());
+ assertEquals(count + 1, ((MeterStats) readField(stats, "readDoc", true)).getCount());
+ }
+
+ @Test
+ public void getDeletedPropertiesReadCount() throws IllegalAccessException {
+ Meter m = getMeter(READ_DELETED_PROPERTY);
+ long count = m.getCount();
+ stats.deletedPropertiesRead(17);
+ assertEquals(count + 17, m.getCount());
+ assertEquals(count + 17, ((MeterStats) readField(stats, "readDeletedProperty", true)).getCount());
+ }
+
+ @Test
+ public void getPropertiesDeletedCount() throws IllegalAccessException {
+ Meter m = getMeter(DELETED_PROPERTY);
+ long count = m.getCount();
+ stats.propertiesDeleted(10);
+ assertEquals(count + 10, m.getCount());
+ assertEquals(count + 10, ((MeterStats) readField(stats, "deletedProperty", true)).getCount());
+ }
+
+ @Test
+ public void getDocumentsUpdatedCount() throws IllegalAccessException {
+ Meter m = getMeter(UPDATED_DOC);
+ long count = m.getCount();
+ stats.documentsUpdated(10);
+ assertEquals(count + 10, m.getCount());
+ assertEquals(count + 10, ((MeterStats) readField(stats, "updatedDoc", true)).getCount());
+ }
+
+ @Test
+ public void timers() {
+ final VersionGarbageCollector.VersionGCStats vgcs = new VersionGarbageCollector.VersionGCStats();
+ vgcs.detailedGCActiveElapsed = MILLISECONDS.toMicros(2);
+ vgcs.detailedGCDocsElapsed = MILLISECONDS.toMicros(3);
+ vgcs.collectDetailedGarbageElapsed = MILLISECONDS.toMicros(5);
+ vgcs.collectDeletedPropsElapsed = MILLISECONDS.toMicros(7);
+ vgcs.collectDeletedOldRevsElapsed = MILLISECONDS.toMicros(11);
+ vgcs.collectUnmergedBCElapsed = MILLISECONDS.toMicros(13);
+ vgcs.deleteDetailedGCDocsElapsed = MILLISECONDS.toMicros(15);
+ vgcs.detailedGCActive.start();
+
+ stats.finished(vgcs);
+ assertTimer(2, DETAILED_GC_ACTIVE_TIMER);
+ assertTimer(3, DETAILED_GC_TIMER);
+ assertTimer(5, COLLECT_DETAILED_GARBAGE_TIMER);
+ assertTimer(7, COLLECT_DELETED_PROPS_TIMER);
+ assertTimer(11, COLLECT_DELETED_OLD_REVS_TIMER);
+ assertTimer(13, COLLECT_UNMERGED_BC_TIMER);
+ assertTimer(15, DELETE_DETAILED_GC_DOCS_TIMER);
+ }
+
+ @Test
+ public void counters() {
+ Counter counter = getCounter(COUNTER);
+ Counter failureCounter = getCounter(FAILURE_COUNTER);
+
+ VersionGarbageCollector.VersionGCStats vgcs = new VersionGarbageCollector.VersionGCStats();
+ stats.started();
+ stats.finished(vgcs);
+ assertEquals(1, counter.getCount());
+ assertEquals(0, failureCounter.getCount());
+
+ vgcs.success = false;
+ stats.started();
+ stats.finished(vgcs);
+ assertEquals(2, counter.getCount());
+ assertEquals(1, failureCounter.getCount());
+ }
+
+ private void assertTimer(long expected, String name) {
+ assertEquals(expected, NANOSECONDS.toMillis(getTimer(name).getSnapshot().getMax()));
+ }
+
+ private Timer getTimer(String name) {
+ return statsProvider.getRegistry().getTimers().get(DETAILED_GC + "." + name);
+ }
+
+ private Meter getMeter(String name) {
+ return statsProvider.getRegistry().getMeters().get(DETAILED_GC + "." + name);
+ }
+
+ private Counter getCounter(String name) {
+ return statsProvider.getRegistry().getCounters().get(DETAILED_GC + "." + name);
+ }
+
+}
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCStatsTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCStatsTest.java
index 1515ea9312..a1e889fe18 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCStatsTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCStatsTest.java
@@ -31,21 +31,11 @@ import static org.junit.Assert.assertEquals;
public class VersionGCStatsTest {
- private static final Callable START = new Callable() {
- @Override
- public void call(Stopwatch watch) {
- watch.start();
- }
- };
+ private static final Callable START = Stopwatch::start;
- private static final Callable STOP = new Callable() {
- @Override
- public void call(Stopwatch watch) {
- watch.stop();
- }
- };
+ private static final Callable STOP = Stopwatch::stop;
- private VersionGCStats stats = new VersionGCStats();
+ private final VersionGCStats stats = new VersionGCStats();
@Before
public void before() throws Exception {
@@ -61,6 +51,7 @@ public class VersionGCStatsTest {
VersionGCStats cumulative = new VersionGCStats();
cumulative.addRun(stats);
assertEquals(stats.active.elapsed(MICROSECONDS), cumulative.activeElapsed);
+ assertEquals(stats.detailedGCActive.elapsed(MICROSECONDS), cumulative.detailedGCActiveElapsed);
assertEquals(stats.collectDeletedDocs.elapsed(MICROSECONDS), cumulative.collectDeletedDocsElapsed);
assertEquals(stats.checkDeletedDocs.elapsed(MICROSECONDS), cumulative.checkDeletedDocsElapsed);
assertEquals(stats.deleteDeletedDocs.elapsed(MICROSECONDS), cumulative.deleteDeletedDocsElapsed);
@@ -69,6 +60,7 @@ public class VersionGCStatsTest {
assertEquals(stats.updateResurrectedDocuments.elapsed(MICROSECONDS), cumulative.updateResurrectedDocumentsElapsed);
assertEquals(stats.detailedGCDocs.elapsed(MICROSECONDS), cumulative.detailedGCDocsElapsed);
assertEquals(stats.deleteDetailedGCDocs.elapsed(MICROSECONDS), cumulative.deleteDetailedGCDocsElapsed);
+ assertEquals(stats.collectDetailedGarbage.elapsed(MICROSECONDS), cumulative.collectDetailedGarbageElapsed);
assertEquals(stats.collectDeletedProps.elapsed(MICROSECONDS), cumulative.collectDeletedPropsElapsed);
assertEquals(stats.collectDeletedOldRevs.elapsed(MICROSECONDS), cumulative.collectDeletedOldRevsElapsed);
assertEquals(stats.collectUnmergedBC.elapsed(MICROSECONDS), cumulative.collectUnmergedBCElapsed);
@@ -82,6 +74,7 @@ public class VersionGCStatsTest {
cumulative.addRun(cumulative);
// now the stats must have doubled
assertEquals(stats.active.elapsed(MICROSECONDS) * 2, cumulative.activeElapsed);
+ assertEquals(stats.detailedGCActive.elapsed(MICROSECONDS) * 2, cumulative.detailedGCActiveElapsed);
assertEquals(stats.collectDeletedDocs.elapsed(MICROSECONDS) * 2, cumulative.collectDeletedDocsElapsed);
assertEquals(stats.checkDeletedDocs.elapsed(MICROSECONDS) * 2, cumulative.checkDeletedDocsElapsed);
assertEquals(stats.deleteDeletedDocs.elapsed(MICROSECONDS) * 2, cumulative.deleteDeletedDocsElapsed);
@@ -90,6 +83,7 @@ public class VersionGCStatsTest {
assertEquals(stats.updateResurrectedDocuments.elapsed(MICROSECONDS) * 2, cumulative.updateResurrectedDocumentsElapsed);
assertEquals(stats.detailedGCDocs.elapsed(MICROSECONDS) * 2, cumulative.detailedGCDocsElapsed);
assertEquals(stats.deleteDetailedGCDocs.elapsed(MICROSECONDS) * 2, cumulative.deleteDetailedGCDocsElapsed);
+ assertEquals(stats.collectDetailedGarbage.elapsed(MICROSECONDS) * 2, cumulative.collectDetailedGarbageElapsed);
assertEquals(stats.collectDeletedProps.elapsed(MICROSECONDS) * 2, cumulative.collectDeletedPropsElapsed);
assertEquals(stats.collectDeletedOldRevs.elapsed(MICROSECONDS) * 2, cumulative.collectDeletedOldRevsElapsed);
assertEquals(stats.collectUnmergedBC.elapsed(MICROSECONDS) * 2, cumulative.collectUnmergedBCElapsed);
@@ -97,6 +91,7 @@ public class VersionGCStatsTest {
private void forEachStopwatch(VersionGCStats stats, Callable c) {
c.call(stats.active);
+ c.call(stats.detailedGCActive);
c.call(stats.collectDeletedDocs);
c.call(stats.checkDeletedDocs);
c.call(stats.deleteDeletedDocs);
@@ -105,6 +100,7 @@ public class VersionGCStatsTest {
c.call(stats.updateResurrectedDocuments);
c.call(stats.detailedGCDocs);
c.call(stats.deleteDetailedGCDocs);
+ c.call(stats.collectDetailedGarbage);
c.call(stats.collectDeletedProps);
c.call(stats.collectDeletedOldRevs);
c.call(stats.collectUnmergedBC);