Author: mreutegg Date: Tue Apr 29 13:34:16 2014 New Revision: 1590980 URL: http://svn.apache.org/r1590980 Log: OAK-1779: Stale cache after MongoMK GC
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/VersionGarbageCollector.java jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorTest.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=1590980&r1=1590979&r2=1590980&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 Apr 29 13:34:16 2014 @@ -589,6 +589,10 @@ public final class DocumentNodeStore return docChildrenCacheStats; } + void invalidateDocChildrenCache() { + docChildrenCache.invalidateAll(); + } + public int getPendingWriteCount() { return unsavedLastRevisions.getPaths().size(); } Modified: 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=1590980&r1=1590979&r2=1590980&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java Tue Apr 29 13:34:16 2014 @@ -121,6 +121,7 @@ public class VersionGarbageCollector { log.debug(sb.toString()); } nodeStore.getDocumentStore().remove(Collection.NODES, docIdsToDelete); + nodeStore.invalidateDocChildrenCache(); stats.deletedDocGCCount += docIdsToDelete.size(); } Modified: 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=1590980&r1=1590979&r2=1590980&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorTest.java (original) +++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorTest.java Tue Apr 29 13:34:16 2014 @@ -23,6 +23,7 @@ import java.io.IOException; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.TimeUnit; import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; @@ -38,9 +39,12 @@ import static org.junit.Assert.assertTru import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.apache.jackrabbit.oak.spi.commit.CommitInfo; import org.apache.jackrabbit.oak.spi.commit.EmptyHook; +import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; import org.apache.jackrabbit.oak.stats.Clock; import org.junit.After; @@ -257,6 +261,43 @@ public class VersionGarbageCollectorTest assertNotNull(test); } + // OAK-1779 + @Test + public void cacheConsistency() throws Exception { + long maxAge = 1; //hrs + long delta = TimeUnit.MINUTES.toMillis(10); + + Set<String> names = Sets.newHashSet(); + NodeBuilder b1 = store.getRoot().builder(); + for (int i = 0; i < 10; i++) { + String name = "test-" + i; + b1.child(name); + names.add(name); + } + store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY); + + for (ChildNodeEntry entry : store.getRoot().getChildNodeEntries()) { + entry.getNodeState(); + } + + b1 = store.getRoot().builder(); + b1.getChildNode("test-7").remove(); + names.remove("test-7"); + + store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY); + + clock.waitUntil(clock.getTime() + TimeUnit.HOURS.toMillis(maxAge) + delta); + + VersionGCStats stats = gc.gc(maxAge, TimeUnit.HOURS); + assertEquals(1, stats.deletedDocGCCount); + + Set<String> children = Sets.newHashSet(); + for (ChildNodeEntry entry : store.getRoot().getChildNodeEntries()) { + children.add(entry.getName()); + } + assertEquals(names, children); + } + private NodeDocument getDoc(String path){ return store.getDocumentStore().find(NODES, Utils.getIdFromPath(path), 0); }