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 mr...@apache.org on 2017/07/18 12:46:10 UTC
svn commit: r1802289 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java
Author: mreutegg
Date: Tue Jul 18 12:46:10 2017
New Revision: 1802289
URL: http://svn.apache.org/viewvc?rev=1802289&view=rev
Log:
OAK-3710: Continuous revision GC
Add configuration option to DocumentNodeStoreService to run Revision GC continuously (default: false)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java?rev=1802289&r1=1802288&r2=1802289&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java Tue Jul 18 12:46:10 2017
@@ -31,6 +31,7 @@ import static org.apache.jackrabbit.oak.
import static org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_MEMORY_CACHE_SIZE;
import static org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_NODE_CACHE_PERCENTAGE;
import static org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_PREV_DOC_CACHE_PERCENTAGE;
+import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS_RESOLUTION;
import static org.apache.jackrabbit.oak.spi.blob.osgi.SplitBlobStoreService.ONLY_STANDALONE_TARGET;
import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean;
@@ -337,6 +338,11 @@ public class DocumentNodeStoreService {
)
public static final String PROP_VER_GC_MAX_AGE = "versionGcMaxAgeInSecs";
+ @Property (boolValue = false,
+ label = "Continuous Version GC Mode",
+ description = "Run Version GC continuously as a background task.")
+ public static final String PROP_VER_GC_CONTINUOUS = "versionGCContinuous";
+
public static final String PROP_REV_RECOVERY_INTERVAL = "lastRevRecoveryJobIntervalInSecs";
/**
@@ -617,6 +623,7 @@ public class DocumentNodeStoreService {
registerJMXBeans(nodeStore, mkBuilder);
registerLastRevRecoveryJob(nodeStore);
registerJournalGC(nodeStore);
+ registerVersionGCJob(nodeStore);
if (!isNodeStoreProvider()) {
observerTracker = new ObserverTracker(nodeStore);
@@ -901,16 +908,7 @@ public class DocumentNodeStoreService {
BlobGCMBean.TYPE, "Document node store blob garbage collection"));
}
- Runnable startGC = new Runnable() {
- @Override
- public void run() {
- try {
- store.getVersionGarbageCollector().gc(versionGcMaxAgeInSecs, TimeUnit.SECONDS);
- } catch (IOException e) {
- log.warn("Error occurred while executing the Version Garbage Collector", e);
- }
- }
- };
+ Runnable startGC = new RevisionGCJob(store, versionGcMaxAgeInSecs, log);
Runnable cancelGC = new Runnable() {
@Override
public void run() {
@@ -978,6 +976,15 @@ public class DocumentNodeStoreService {
true/*runOnSingleClusterNode*/, true /*use dedicated pool*/));
}
+ private void registerVersionGCJob(final DocumentNodeStore nodeStore) {
+ if (toBoolean(context.getProperties().get(PROP_VER_GC_CONTINUOUS), false)) {
+ final long versionGcMaxAgeInSecs = toLong(prop(PROP_VER_GC_MAX_AGE), DEFAULT_VER_GC_MAX_AGE);
+ addRegistration(WhiteboardUtils.scheduleWithFixedDelay(whiteboard,
+ new RevisionGCJob(nodeStore, versionGcMaxAgeInSecs, log),
+ MODIFIED_IN_SECS_RESOLUTION, true, true));
+ }
+ }
+
private String prop(String propName) {
return prop(propName, PREFIX + propName);
}
@@ -1041,4 +1048,29 @@ public class DocumentNodeStoreService {
}
};
}
+
+ static final class RevisionGCJob implements Runnable {
+
+ private final DocumentNodeStore nodeStore;
+ private final long versionGcMaxAgeInSecs;
+ private final Logger log;
+
+ RevisionGCJob(DocumentNodeStore ns,
+ long versionGcMaxAgeInSecs,
+ Logger log) {
+ this.nodeStore = ns;
+ this.versionGcMaxAgeInSecs = versionGcMaxAgeInSecs;
+ this.log = log;
+ }
+
+ @Override
+ public void run() {
+ VersionGarbageCollector gc = nodeStore.getVersionGarbageCollector();
+ try {
+ gc.gc(versionGcMaxAgeInSecs, TimeUnit.SECONDS);
+ } catch (IOException e) {
+ log.warn("Error occurred while executing the Version Garbage Collector", e);
+ }
+ }
+ }
}
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java?rev=1802289&r1=1802288&r2=1802289&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java Tue Jul 18 12:46:10 2017
@@ -39,6 +39,7 @@ import org.junit.rules.TemporaryFolder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -150,6 +151,27 @@ public class DocumentNodeStoreServiceTes
assertTrue(db.getMongo().getMongoOptions().isSocketKeepAlive());
}
+ @Test
+ public void nonContinuousRGCDefault() throws Exception {
+ Map<String, Object> config = newConfig(repoHome);
+ MockOsgi.activate(service, context.bundleContext(), config);
+ for (Runnable r : context.getServices(Runnable.class, null)) {
+ assertNotEquals(r.getClass(), DocumentNodeStoreService.RevisionGCJob.class);
+ }
+ }
+
+ @Test
+ public void continuousRGC() throws Exception {
+ Map<String, Object> config = newConfig(repoHome);
+ config.put(DocumentNodeStoreService.PROP_VER_GC_CONTINUOUS, true);
+ MockOsgi.activate(service, context.bundleContext(), config);
+ boolean jobScheduled = false;
+ for (Runnable r : context.getServices(Runnable.class, null)) {
+ jobScheduled |= r.getClass().equals(DocumentNodeStoreService.RevisionGCJob.class);
+ }
+ assertTrue(jobScheduled);
+ }
+
private static MongoDocumentStore getMongoDocumentStore(DocumentNodeStore s) {
try {
Field f = s.getClass().getDeclaredField("nonLeaseCheckingStore");