Skip to content

Commit be64ee5

Browse files
author
Rishabh Kumar
committed
OAK-11452 : added metric for fullGcGeneration as well
1 parent b4d5054 commit be64ee5

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollector.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,15 @@ public interface FullGCStatsCollector {
166166
* @param maxAge the maximum age to set for the FullGC process
167167
*/
168168
void maxAge(long maxAge);
169+
170+
/**
171+
* Sets the full garbage collection generation value.
172+
* <p>
173+
* This method is called to update the current full GC generation being tracked.
174+
* The generation value is used to reset the full GC process when incremented,
175+
* allowing it to run from the beginning with fresh state.
176+
*
177+
* @param generation the full GC generation value to set
178+
*/
179+
void fullGCGeneration(long generation);
169180
}

oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollectorImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class FullGCStatsCollectorImpl implements FullGCStatsCollector {
6868
static final String PROGRESS_SIZE = "PROGRESS_SIZE";
6969
static final String EMBEDDED_VERIFICATION_ENABLED = "EMBEDDED_VERIFICATION_ENABLED";
7070
static final String MAX_AGE = "MAX_AGE";
71+
static final String FULL_GC_GENERATION = "FULL_GC_GENERATION";
7172

7273
private final StatisticsProvider provider;
7374

@@ -104,6 +105,7 @@ class FullGCStatsCollectorImpl implements FullGCStatsCollector {
104105
private GaugeStats<Integer> progressSize;
105106
private GaugeStats<Boolean> embeddedVerificationEnabled;
106107
private GaugeStats<Long> maxAge;
108+
private GaugeStats<Long> fullGCGeneration;
107109

108110
FullGCStatsCollectorImpl(StatisticsProvider provider) {
109111
this(provider, false);
@@ -245,6 +247,11 @@ public void maxAge(long maxAge) {
245247
this.maxAge = gauge(provider, MAX_AGE, () -> maxAge);
246248
}
247249

250+
@Override
251+
public void fullGCGeneration(long generation) {
252+
this.fullGCGeneration = gauge(provider, FULL_GC_GENERATION, () -> generation);
253+
}
254+
248255
@Override
249256
public String toString() {
250257
return "FullGCStatsCollectorImpl{" +
@@ -255,6 +262,7 @@ public String toString() {
255262
", progressSize=" + getValue(progressSize, "0") +
256263
", embeddedVerificationEnabled=" + getValue(embeddedVerificationEnabled, "false") +
257264
", maxAge=" + getValue(maxAge, "0") +
265+
", fullGCGeneration=" + getValue(fullGCGeneration, "0") +
258266
", readDoc=" + readDoc.getCount() +
259267
", candidateRevisions=" + mapToString(candidateRevisions) +
260268
", candidateInternalRevisions=" + mapToString(candidateInternalRevisions) +

oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public class VersionGarbageCollector {
167167
static final String SETTINGS_COLLECTION_FULL_GC_DRY_RUN_DOCUMENT_ID_PROP = "fullGCDryRunId";
168168

169169
private static FullGCMode fullGcMode = GAP_ORPHANS_EMPTYPROPS;
170+
private final long fullGcGen;
170171

171172
static FullGCMode getFullGcMode() {
172173
return fullGcMode;
@@ -306,7 +307,7 @@ private void persistFullGcGen(long fullGcGeneration) {
306307
this.options = new VersionGCOptions();
307308

308309
setFullGcMode(fullGCMode);
309-
long fullGcGen = fullGCEnabled ? resetFullGcIfGenChange(fullGcGeneration) : fullGcGeneration;
310+
this.fullGcGen = fullGCEnabled ? resetFullGcIfGenChange(fullGcGeneration) : fullGcGeneration;
310311
AUDIT_LOG.info("<init> VersionGarbageCollector created with fullGcMode: {}, maxFullGcAgeInMillis: {}, batchSize: {}, progressSize: {}, delayFactor: {}, fullGcGeneration: {}",
311312
fullGcMode, fullGcMaxAgeInMillis, fullGCBatchSize, fullGCProgressSize, fullGCDelayFactor, fullGcGen);
312313
}
@@ -345,6 +346,7 @@ public void setStatisticsProvider(StatisticsProvider provider, boolean pushMetri
345346
this.fullGCStats.progressSize(fullGCProgressSize);
346347
this.fullGCStats.maxAge(fullGcMaxAgeInMillis);
347348
this.fullGCStats.verificationEnabled(this.embeddedVerification);
349+
this.fullGCStats.fullGCGeneration(this.fullGcGen);
348350
}
349351

350352
public void setFullGCMetricsExporter(FullGCMetricsExporter exporter) {

oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/FullGCStatsCollectorImplTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.ENABLED;
5353
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.FULL_GC;
5454
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.FULL_GC_ACTIVE_TIMER;
55+
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.FULL_GC_GENERATION;
5556
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.FULL_GC_TIMER;
5657
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.FAILURE_COUNTER;
5758
import static org.apache.jackrabbit.oak.plugins.document.FullGCStatsCollectorImpl.MAX_AGE;
@@ -273,6 +274,20 @@ public void getMaxAge() throws IllegalAccessException {
273274
assertEquals(86400L, (long)updated.getValue());
274275
}
275276

277+
@Test
278+
@SuppressWarnings("unchecked")
279+
public void getFullGCGeneration() throws IllegalAccessException {
280+
stats.fullGCGeneration(3);
281+
final Gauge<Long> gauge = getGauge(FULL_GC_GENERATION);
282+
assertEquals(3L, (long)gauge.getValue());
283+
assertEquals(3L, (long)((GaugeStats<Long>) readField(stats, "fullGCGeneration", true)).getValue());
284+
285+
// update the value
286+
stats.fullGCGeneration(5);
287+
final Gauge<Long> updated = getGauge(FULL_GC_GENERATION);
288+
assertEquals(3L, (long)updated.getValue());
289+
}
290+
276291
@Test
277292
public void getFullGcOsgiConfigs() {
278293
stats.maxAge(86400);
@@ -282,6 +297,7 @@ public void getFullGcOsgiConfigs() {
282297
stats.batchSize(500);
283298
stats.delayFactor(5.0);
284299
stats.mode(4);
300+
stats.fullGCGeneration(2);
285301

286302
// update the value
287303
assertTrue(stats.toString().contains("maxAge=86400"));
@@ -291,6 +307,7 @@ public void getFullGcOsgiConfigs() {
291307
assertTrue(stats.toString().contains("batchSize=500"));
292308
assertTrue(stats.toString().contains("delayFactor=5.0"));
293309
assertTrue(stats.toString().contains("mode=4"));
310+
assertTrue(stats.toString().contains("fullGCGeneration=2"));
294311
}
295312

296313
@Test

0 commit comments

Comments
 (0)