Skip to content

Commit 32e9de1

Browse files
rishabhdaimRishabh Kumar
andauthored
OAK-11433 : added OSGi config for setting max revision age for full gc (#2032)
* OAK-11433 : added OSGi config for setting max revision age for full gc * OAK-11433 : removed un-used var --------- Co-authored-by: Rishabh Kumar <diam@adobe.com>
1 parent 0063f98 commit 32e9de1

File tree

15 files changed

+203
-82
lines changed

15 files changed

+203
-82
lines changed

oak-run-commons/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static VersionGarbageCollector createVersionGC(final DocumentNodeStore no
7474
boolean isFullGCDryRun, final DocumentNodeStoreBuilder<?> builder) {
7575
return new VersionGarbageCollector(nodeStore, gcSupport, isFullGCEnabled(builder), isFullGCDryRun,
7676
isEmbeddedVerificationEnabled(builder), builder.getFullGCMode(), builder.getFullGCDelayFactor(),
77-
builder.getFullGCBatchSize(), builder.getFullGCProgressSize());
77+
builder.getFullGCBatchSize(), builder.getFullGCProgressSize(), builder.getFullGcMaxAgeMillis());
7878
}
7979

8080
public static DocumentNodeState readNode(DocumentNodeStore documentNodeStore, Path path, RevisionVector rootRevision) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@
349349
"property 'oak.documentstore.fullGCEnabled'")
350350
boolean fullGCEnabled() default DEFAULT_FULL_GC_ENABLED;
351351

352+
@AttributeDefinition(
353+
name = "Full GC Max Age (in secs)",
354+
description = "Version Garbage Collector (Full GC) logic will only consider those nodes for Full GC which " +
355+
"are not accessed recently (currentTime - lastModifiedTime > fullGcMaxAgeInSecs). For " +
356+
"example as per default only those document which have not been *updated* 24 hrs ago will be " +
357+
"considered for Full GC.")
358+
long fullGcMaxAgeInSecs() default DocumentNodeStoreService.DEFAULT_FULL_GC_MAX_AGE;
359+
352360
@AttributeDefinition(
353361
name = "Document Node Store Embedded Verification for Full GC",
354362
description = "Boolean value indicating whether Embedded Verification (i.e. verify the document after " +

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ public DocumentNodeStore(DocumentNodeStoreBuilder<?> builder) {
656656
this.versionGarbageCollector = new VersionGarbageCollector(
657657
this, builder.createVersionGCSupport(), isFullGCEnabled(builder), false,
658658
isEmbeddedVerificationEnabled(builder), builder.getFullGCMode(), builder.getFullGCDelayFactor(),
659-
builder.getFullGCBatchSize(), builder.getFullGCProgressSize());
659+
builder.getFullGCBatchSize(), builder.getFullGCProgressSize(), builder.getFullGcMaxAgeMillis());
660660
this.versionGarbageCollector.setStatisticsProvider(builder.getStatisticsProvider());
661661
this.versionGarbageCollector.setGCMonitor(builder.getGCMonitor());
662662
this.versionGarbageCollector.setFullGCPaths(builder.getFullGCIncludePaths(), builder.getFullGCExcludePaths());

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public class DocumentNodeStoreBuilder<T extends DocumentNodeStoreBuilder<T>> {
181181
private Set<String> fullGCExcludePaths = Set.of();
182182
private boolean embeddedVerificationEnabled = DocumentNodeStoreService.DEFAULT_EMBEDDED_VERIFICATION_ENABLED;
183183
private int fullGCMode = DocumentNodeStoreService.DEFAULT_FULL_GC_MODE;
184+
private long fullGcMaxAgeMillis = TimeUnit.SECONDS.toMillis(DocumentNodeStoreService.DEFAULT_FULL_GC_MAX_AGE);
184185
private int fullGCBatchSize = DocumentNodeStoreService.DEFAULT_FGC_BATCH_SIZE;
185186
private int fullGCProgressSize = DocumentNodeStoreService.DEFAULT_FGC_PROGRESS_SIZE;
186187
private double fullGCDelayFactor = DocumentNodeStoreService.DEFAULT_FGC_DELAY_FACTOR;
@@ -360,6 +361,26 @@ public int getFullGCMode() {
360361
return this.fullGCMode;
361362
}
362363

364+
/**
365+
* The maximum age for nodes in milliseconds. Older entries are candidates for full gc
366+
* @param v max age in millis
367+
* @return builder object
368+
*/
369+
public T setFullGcMaxAgeMillis(long v) {
370+
this.fullGcMaxAgeMillis = v;
371+
return thisBuilder();
372+
}
373+
374+
/**
375+
* The maximum age for nodes in milliseconds. Older entries
376+
* are candidates for Full GC.
377+
*
378+
* @return maximum age for nodes entries in milliseconds.
379+
*/
380+
public long getFullGcMaxAgeMillis() {
381+
return this.fullGcMaxAgeMillis;
382+
}
383+
363384
public T setFullGCBatchSize(int v) {
364385
this.fullGCBatchSize = v;
365386
return thisBuilder();

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ public class DocumentNodeStoreService {
165165
*/
166166
static final long DEFAULT_VER_GC_MAX_AGE = 24 * 60 * 60; //TimeUnit.DAYS.toSeconds(1);
167167

168+
/**
169+
* Nodes older than this time would be garbage collected by Full GC
170+
*/
171+
static final long DEFAULT_FULL_GC_MAX_AGE = 24 * 60 * 60; //TimeUnit.DAYS.toSeconds(1);
172+
168173

169174
/**
170175
* Blob modified before this time duration would be considered for Blob GC
@@ -523,6 +528,7 @@ private void configureBuilder(DocumentNodeStoreBuilder<?> builder) {
523528
setFullGCExcludePaths(config.fullGCExcludePaths()).
524529
setEmbeddedVerificationEnabled(config.embeddedVerificationEnabled()).
525530
setFullGCMode(config.fullGCMode()).
531+
setFullGcMaxAgeMillis(TimeUnit.SECONDS.toMillis(config.fullGcMaxAgeInSecs())).
526532
setFullGCBatchSize(config.fullGCBatchSize()).
527533
setFullGCProgressSize(config.fullGCProgressSize()).
528534
setFullGCDelayFactor(config.fullGCDelayFactor()).

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ public class VersionGCRecommendations {
104104
* @param gcMonitor monitor class for messages
105105
* @param fullGCEnabled whether fullGC is enabled or not
106106
* @param isFullGCDryRun whether fullGC is running in dryRun mode or not
107+
* @param fullGcMaxAgeMs the maximum age for revisions to be collected by fullGC
107108
*/
108109
VersionGCRecommendations(long maxRevisionAgeMs, Checkpoints checkpoints, boolean checkpointCleanup, Clock clock,
109110
VersionGCSupport vgc, VersionGCOptions options, GCMonitor gcMonitor,
110-
boolean fullGCEnabled, boolean isFullGCDryRun) {
111+
boolean fullGCEnabled, boolean isFullGCDryRun, long fullGcMaxAgeMs) {
111112
boolean ignoreDueToCheckPoint;
112113
boolean ignoreFullGCDueToCheckPoint;
113114
long deletedOnceCount = 0;
@@ -185,9 +186,11 @@ public class VersionGCRecommendations {
185186
}
186187
}
187188

189+
TimeInterval keepFullGc = new TimeInterval(clock.getTime() - fullGcMaxAgeMs, Long.MAX_VALUE);
190+
188191
TimeInterval scopeFullGC = new TimeInterval(isFullGCDryRun ? oldestModifiedDryRunDocTimeStamp.get() :
189192
oldestModifiedDocTimeStamp.get(), MAX_VALUE);
190-
scopeFullGC = scopeFullGC.notLaterThan(keep.fromMs);
193+
scopeFullGC = scopeFullGC.notLaterThan(keepFullGc.fromMs);
191194

192195
suggestedIntervalMs = (long) settings.get(SETTINGS_COLLECTION_REC_INTERVAL_PROP);
193196
if (suggestedIntervalMs > 0) {
@@ -248,7 +251,7 @@ public class VersionGCRecommendations {
248251
this.scopeFullGC = scopeFullGC;
249252
this.fullGCId = isFullGCDryRun ? oldestModifiedDryRunDocId : oldestModifiedDocId;
250253
this.scopeIsComplete = scope.toMs >= keep.fromMs;
251-
this.fullGCScopeIsComplete = scopeFullGC.toMs >= keep.fromMs;
254+
this.fullGCScopeIsComplete = scopeFullGC.toMs >= keepFullGc.fromMs;
252255
this.maxCollect = collectLimit;
253256
this.suggestedIntervalMs = suggestedIntervalMs;
254257
this.deleteCandidateCount = deletedOnceCount;

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
import static org.apache.jackrabbit.oak.plugins.document.Document.ID;
8484
import static org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService.DEFAULT_FGC_BATCH_SIZE;
8585
import static org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService.DEFAULT_FGC_PROGRESS_SIZE;
86+
import static org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService.DEFAULT_FULL_GC_MAX_AGE;
8687
import static org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService.DEFAULT_FULL_GC_MODE;
8788
import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.BRANCH_COMMITS;
8889
import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.COLLISIONS;
@@ -179,6 +180,7 @@ static void setFullGcMode(int fullGcMode) {
179180
private final boolean isFullGCDryRun;
180181
private final boolean embeddedVerification;
181182
private final double fullGCDelayFactor;
183+
private long fullGcMaxAgeInMillis;
182184
private final int fullGCBatchSize;
183185
private final int fullGCProgressSize;
184186
private Set<String> fullGCIncludePaths = Collections.emptySet();
@@ -196,7 +198,7 @@ static void setFullGcMode(int fullGcMode) {
196198
final boolean isFullGCDryRun,
197199
final boolean embeddedVerification) {
198200
this(nodeStore, gcSupport, fullGCEnabled, isFullGCDryRun, embeddedVerification, DEFAULT_FULL_GC_MODE,
199-
0, DEFAULT_FGC_BATCH_SIZE, DEFAULT_FGC_PROGRESS_SIZE);
201+
0, DEFAULT_FGC_BATCH_SIZE, DEFAULT_FGC_PROGRESS_SIZE, SECONDS.toMillis(DEFAULT_FULL_GC_MAX_AGE));
200202
}
201203

202204
VersionGarbageCollector(DocumentNodeStore nodeStore,
@@ -207,21 +209,23 @@ static void setFullGcMode(int fullGcMode) {
207209
final int fullGCMode,
208210
final double fullGCDelayFactor,
209211
final int fullGCBatchSize,
210-
final int fullGCProgressSize) {
212+
final int fullGCProgressSize,
213+
final long fullGcMaxAgeInMillis) {
211214
this.nodeStore = nodeStore;
212215
this.versionStore = gcSupport;
213216
this.ds = gcSupport.getDocumentStore();
214217
this.fullGCEnabled = fullGCEnabled;
215218
this.isFullGCDryRun = isFullGCDryRun;
216219
this.embeddedVerification = embeddedVerification;
217220
this.fullGCDelayFactor = fullGCDelayFactor;
221+
this.fullGcMaxAgeInMillis = fullGcMaxAgeInMillis;
218222
this.fullGCBatchSize = Math.min(fullGCBatchSize, fullGCProgressSize);
219223
this.fullGCProgressSize = fullGCProgressSize;
220224
this.options = new VersionGCOptions();
221225

222226
setFullGcMode(fullGCMode);
223-
AUDIT_LOG.info("<init> VersionGarbageCollector created with fullGcMode: {}, batchSize: {}, progressSize: {}, delayFactor: {}",
224-
fullGcMode, fullGCBatchSize, fullGCProgressSize, fullGCDelayFactor);
227+
AUDIT_LOG.info("<init> VersionGarbageCollector created with fullGcMode: {}, maxFullGcAgeInMillis: {}, batchSize: {}, progressSize: {}, delayFactor: {}",
228+
fullGcMode, fullGcMaxAgeInMillis, fullGCBatchSize, fullGCProgressSize, fullGCDelayFactor);
225229
}
226230

227231
/**
@@ -239,6 +243,10 @@ void setFullGCPaths(@NotNull Set<String> includes, @NotNull Set<String> excludes
239243
AUDIT_LOG.info("Full GC paths set to include: {} and exclude: {} in mode {}", includes, excludes, fullGcMode);
240244
}
241245

246+
void setFullGcMaxAge(final long fullGcMaxAge, final TimeUnit unit) {
247+
this.fullGcMaxAgeInMillis = unit.toMillis(fullGcMaxAge);
248+
}
249+
242250
public void setStatisticsProvider(StatisticsProvider provider) {
243251
this.gcStats = new RevisionGCStats(provider);
244252
this.fullGCStats = new FullGCStatsCollectorImpl(provider);
@@ -353,7 +361,7 @@ public VersionGCInfo getInfo(long maxRevisionAge, TimeUnit unit)
353361
long now = nodeStore.getClock().getTime();
354362
VersionGCRecommendations rec = new VersionGCRecommendations(maxRevisionAgeInMillis, nodeStore.getCheckpoints(),
355363
!nodeStore.isReadOnlyMode(), nodeStore.getClock(), versionStore, options, gcMonitor, fullGCEnabled,
356-
isFullGCDryRun);
364+
isFullGCDryRun, fullGcMaxAgeInMillis);
357365
int estimatedIterations = -1;
358366
if (rec.suggestedIntervalMs > 0) {
359367
estimatedIterations = (int)Math.ceil((double) (now - rec.scope.toMs) / rec.suggestedIntervalMs);
@@ -734,7 +742,7 @@ private VersionGCStats gc(long maxRevisionAgeInMillis) throws IOException {
734742
stats.active.start();
735743
VersionGCRecommendations rec = new VersionGCRecommendations(maxRevisionAgeInMillis, nodeStore.getCheckpoints(),
736744
!nodeStore.isReadOnlyMode(), nodeStore.getClock(), versionStore, options, gcMonitor, fullGCEnabled,
737-
isFullGCDryRun);
745+
isFullGCDryRun, fullGcMaxAgeInMillis);
738746
GCPhases phases = new GCPhases(cancel, stats, gcMonitor);
739747
try {
740748
if (!isFullGCDryRun) {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ public int getFullGCMode() {
170170
// fullGC modes are not supported for RDB
171171
return 0;
172172
}
173+
174+
@Override
175+
public RDBDocumentNodeStoreBuilder setFullGcMaxAgeMillis(long v) {
176+
// fullGC modes are not supported for RDB
177+
log.warn("FullGC Max Age is not supported for RDB");
178+
return thisBuilder();
179+
}
180+
181+
@Override
182+
public long getFullGcMaxAgeMillis() {
183+
// fullGC max age is not supported for RDB
184+
return 0;
185+
}
173186

174187
@Override
175188
public RDBDocumentNodeStoreBuilder setDocStoreFullGCFeature(@Nullable Feature docStoreFullGC) {

0 commit comments

Comments
 (0)