Author: chetanm
Date: Tue Mar 25 07:44:32 2014
New Revision: 1581268
URL: http://svn.apache.org/r1581268
Log:
OAK-1341 - DocumentNodeStore: Implement revision garbage collection (WIP)
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
(with props)
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorTest.java
(with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1581268&r1=1581267&r2=1581268&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
Tue Mar 25 07:44:32 2014
@@ -282,6 +282,8 @@ public final class DocumentNodeStore
private final Checkpoints checkpoints;
+ private final VersionGarbageCollector versionGarbageCollector;
+
public DocumentNodeStore(DocumentMK.Builder builder) {
this.blobStore = builder.getBlobStore();
if (builder.isUseSimpleRevision()) {
@@ -311,6 +313,7 @@ public final class DocumentNodeStore
this.revisionComparator = new Revision.RevisionComparator(clusterId);
this.branches = new UnmergedBranches(getRevisionComparator());
this.asyncDelay = builder.getAsyncDelay();
+ this.versionGarbageCollector = new VersionGarbageCollector(this);
this.missing = new DocumentNodeState(this, "MISSING", new Revision(0,
0, 0)) {
@Override
public int getMemory() {
@@ -1645,4 +1648,8 @@ public final class DocumentNodeStore
public Checkpoints getCheckpoints() {
return checkpoints;
}
+
+ public VersionGarbageCollector getVersionGarbageCollector() {
+ return versionGarbageCollector;
+ }
}
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java?rev=1581268&r1=1581267&r2=1581268&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java
Tue Mar 25 07:44:32 2014
@@ -198,6 +198,13 @@ public class Revision {
return new Revision(timestamp, c, clusterId, isBranch);
}
+ /**
+ * Provides a readable string for given timestamp
+ */
+ public static String timestampToString(long timestamp){
+ return (new Timestamp(timestamp) + "00").substring(0, 23);
+ }
+
@Override
public String toString() {
return toStringBuilder(new StringBuilder()).toString();
@@ -235,7 +242,7 @@ public class Revision {
buff.append("revision: \"").append(toString()).append("\"");
buff.append(", clusterId: ").append(clusterId);
buff.append(", time: \"").
- append((new Timestamp(timestamp) + "00").substring(0, 23)).
+ append(timestampToString(timestamp)).
append("\"");
if (counter > 0) {
buff.append(", counter: ").append(counter);
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java?rev=1581268&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
Tue Mar 25 07:44:32 2014
@@ -0,0 +1,63 @@
+/*
+ * 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 java.util.concurrent.TimeUnit;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class VersionGarbageCollector {
+ private final DocumentNodeStore nodeStore;
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private volatile long maxRevisionAge = TimeUnit.DAYS.toMillis(1);
+
+ VersionGarbageCollector(DocumentNodeStore nodeStore) {
+ this.nodeStore = nodeStore;
+ }
+
+ public VersionGCStats gc() {
+ VersionGCStats stats = new VersionGCStats();
+ long oldestRevTimeStamp = nodeStore.getClock().getTime() -
maxRevisionAge;
+
+ //Check for any registered checkpoint which prevent the GC from running
+ Revision checkpoint =
nodeStore.getCheckpoints().getOldestRevisionToKeep();
+ if (checkpoint != null && checkpoint.getTimestamp() <
oldestRevTimeStamp) {
+ log.info("Ignoring version gc as valid checkpoint [{}] found while
" +
+ "need to collect versions older than [{}]",
checkpoint.toReadableString(),
+ oldestRevTimeStamp
+ );
+ stats.ignoredGCDueToCheckPoint = true;
+ return stats;
+ }
+
+ return stats;
+ }
+
+ public void setMaxRevisionAge(long maxRevisionAge) {
+ this.maxRevisionAge = maxRevisionAge;
+ }
+
+ public static class VersionGCStats {
+ boolean ignoredGCDueToCheckPoint;
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorTest.java?rev=1581268&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorTest.java
Tue Mar 25 07:44:32 2014
@@ -0,0 +1,64 @@
+/*
+ * 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.stats.Clock;
+import org.junit.Before;
+import org.junit.Test;
+
+import static
org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class VersionGarbageCollectorTest {
+ private Clock clock;
+
+ private DocumentNodeStore store;
+
+ private VersionGarbageCollector gc;
+
+ @Before
+ public void setUp() throws InterruptedException {
+ clock = new Clock.Virtual();
+ store = new DocumentMK.Builder().clock(clock).getNodeStore();
+ gc = store.getVersionGarbageCollector();
+
+ //Baseline the clock
+ clock.waitUntil(Revision.getCurrentTimestamp());
+ }
+
+ @Test
+ public void gcIgnoredForCheckpoint() throws Exception {
+ long expiryTime = 100, maxAge = 20;
+
+ Revision cp = Revision.fromString(store.checkpoint(expiryTime));
+ gc.setMaxRevisionAge(maxAge);
+
+ //Fast forward time to future but before expiry of checkpoint
+ clock.waitUntil(cp.getTimestamp() + maxAge);
+ VersionGCStats stats = gc.gc();
+ assertTrue(stats.ignoredGCDueToCheckPoint);
+
+ //Fast forward time to future such that checkpoint get expired
+ clock.waitUntil(clock.getTime() + expiryTime + 1);
+ stats = gc.gc();
+ assertFalse("GC should be performed", stats.ignoredGCDueToCheckPoint);
+ }
+}
\ No newline at end of file
Propchange:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorTest.java
------------------------------------------------------------------------------
svn:eol-style = native