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 2021/11/11 14:58:07 UTC

[jackrabbit-oak] branch 1.6 updated: OAK-9562: Missing _bin when node is recreated after revision GC

This is an automated email from the ASF dual-hosted git repository.

mreutegg pushed a commit to branch 1.6
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/1.6 by this push:
     new be2832d  OAK-9562: Missing _bin when node is recreated after revision GC
     new 73df789  Merge pull request #415 from mreutegg/OAK-9562-1.6
be2832d is described below

commit be2832d7b9e91f8a1820172a0125df1efda66991
Author: Marcel Reutegger <ma...@gmail.com>
AuthorDate: Thu Nov 11 15:56:49 2021 +0100

    OAK-9562: Missing _bin when node is recreated after revision GC
---
 .../jackrabbit/oak/plugins/document/Commit.java    |   8 +-
 .../document/BlobReferenceIteratorTest.java        | 100 ++++++++++++++++++++-
 2 files changed, 97 insertions(+), 11 deletions(-)

diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
index e05408a..c0bd74f 100644
--- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
+++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
@@ -223,14 +223,8 @@ public class Commit {
      * Update the binary status in the update op.
      */
     private void updateBinaryStatus() {
-        DocumentStore store = this.nodeStore.getDocumentStore();
-
         for (String path : this.nodesWithBinaries) {
-            NodeDocument nd = store.getIfCached(Collection.NODES, Utils.getIdFromPath(path));
-            if ((nd == null) || !nd.hasBinary()) {
-                UpdateOp updateParentOp = getUpdateOperationForNode(path);
-                NodeDocument.setHasBinary(updateParentOp);
-            }
+            NodeDocument.setHasBinary(getUpdateOperationForNode(path));
         }
     }
 
diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BlobReferenceIteratorTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BlobReferenceIteratorTest.java
index df29bb2..f6a0cab 100644
--- a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BlobReferenceIteratorTest.java
+++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BlobReferenceIteratorTest.java
@@ -22,14 +22,20 @@ package org.apache.jackrabbit.oak.plugins.document;
 import java.io.IOException;
 import java.util.HashSet;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob;
+import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions;
+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.NodeBuilder;
+import org.apache.jackrabbit.oak.stats.Clock;
+import org.hamcrest.Matchers;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -37,14 +43,25 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
 import static org.apache.jackrabbit.oak.plugins.document.MongoBlobGCTest.randomStream;
+import static org.apache.jackrabbit.oak.plugins.document.TestUtils.merge;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
 
 @RunWith(Parameterized.class)
 public class BlobReferenceIteratorTest {
-    private DocumentStoreFixture fixture;
+
+    private final DocumentStoreFixture fixture;
+
+    private Clock clock;
 
     private DocumentNodeStore store;
 
+    private DocumentNodeStore store2;
+
     public BlobReferenceIteratorTest(DocumentStoreFixture fixture) {
         this.fixture = fixture;
     }
@@ -67,9 +84,23 @@ public class BlobReferenceIteratorTest {
     }
 
     @Before
-    public void setUp() throws InterruptedException {
-        store = new DocumentMK.Builder()
-                .setDocumentStore(fixture.createDocumentStore())
+    public void setUp() throws Exception {
+        if (fixture instanceof DocumentStoreFixture.RDBFixture) {
+            ((DocumentStoreFixture.RDBFixture) fixture).setRDBOptions(
+                    new RDBOptions().tablePrefix("T" + Long.toHexString(System.currentTimeMillis())).dropTablesOnClose(true));
+        }
+        clock = new Clock.Virtual();
+        clock.waitUntil(System.currentTimeMillis());
+        Revision.setClock(clock);
+        store = newDocumentNodeStore(1);
+    }
+
+    private DocumentNodeStore newDocumentNodeStore(int clusterId) {
+        return new DocumentMK.Builder()
+                .setLeaseCheck(false)
+                .clock(clock)
+                .setDocumentStore(wrap(fixture.createDocumentStore(clusterId)))
+                .setClusterId(clusterId)
                 .setAsyncDelay(0)
                 .getNodeStore();
     }
@@ -77,6 +108,11 @@ public class BlobReferenceIteratorTest {
     @After
     public void tearDown() throws Exception {
         store.dispose();
+        if (store2 != null) {
+            store2.dispose();
+        }
+        fixture.dispose();
+        Revision.resetClockToDefault();
     }
 
     @Test
@@ -96,4 +132,60 @@ public class BlobReferenceIteratorTest {
         assertEquals(blobs.size(), collectedBlobs.size());
         assertEquals(new HashSet<ReferencedBlob>(blobs), new HashSet<ReferencedBlob>(collectedBlobs));
     }
+
+    @Test
+    public void recreateNodeAfterRevisionGC() throws Exception {
+        assumeTrue(fixture.hasSinglePersistence());
+
+        String id = Utils.getIdFromPath("/test");
+
+        NodeBuilder builder = store.getRoot().builder();
+        Blob b = builder.createBlob(new RandomStream(100, 42));
+        builder.child("test").setProperty("binary", b);
+        merge(store, builder);
+
+        builder = store.getRoot().builder();
+        builder.child("test").remove();
+        merge(store, builder);
+
+        // create a second node store
+        store2 = newDocumentNodeStore(2);
+        assertFalse(store2.getRoot().hasChildNode("test"));
+        NodeDocument doc = store2.getDocumentStore().find(Collection.NODES, id);
+        assertNotNull(doc);
+
+        // wait 60 minutes
+        clock.waitUntil(clock.getTime() + TimeUnit.MINUTES.toMillis(60));
+
+        // clean up garbage docs older than 30 minutes
+        VersionGarbageCollector gc = store.getVersionGarbageCollector();
+        VersionGCStats stats = gc.gc(30, TimeUnit.MINUTES);
+        assertThat(stats.deletedDocGCCount, Matchers.equalTo(1));
+
+        // recreate node via store2
+        builder = store2.getRoot().builder();
+        builder.child("test").setProperty("binary", b);
+        merge(store2, builder);
+
+        // make sure we do not fetch from cache
+        doc = store2.getDocumentStore().find(Collection.NODES, id, 0);
+        assertNotNull(doc);
+        assertTrue(doc.hasBinary());
+    }
+
+    private static DocumentStore wrap(DocumentStore ds) {
+        return new DocumentStoreTestWrapper(ds);
+    }
+
+    private static class DocumentStoreTestWrapper extends DocumentStoreWrapper {
+
+        private DocumentStoreTestWrapper(DocumentStore store) {
+            super(store);
+        }
+
+        @Override
+        public void dispose() {
+            // ignore
+        }
+    }
 }