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

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


The following commit(s) were added to refs/heads/issue/oak-10812 by this push:
     new 2b23590218 OAK-10812: DocumentNodeStore#diffManyChildren(...) may 
produce incorrect results in readonly mode
2b23590218 is described below

commit 2b23590218f5c81d914c665bf8ea8bd824f60587
Author: Manfred Baedke <manfred.bae...@gmail.com>
AuthorDate: Thu May 16 16:19:38 2024 +0200

    OAK-10812: DocumentNodeStore#diffManyChildren(...) may produce incorrect 
results in readonly mode
    
    Added test case.
---
 .../oak/plugins/document/DocumentNodeStore.java    |  2 +-
 .../oak/plugins/document/ClusterTest.java          | 46 ++++++++++++++++++++--
 2 files changed, 43 insertions(+), 5 deletions(-)

diff --git 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
index 481cccbe82..95703e3c0f 100644
--- 
a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
+++ 
b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
@@ -3477,7 +3477,7 @@ public final class DocumentNodeStore
         return diff;
     }
 
-    private void diffManyChildren(JsopWriter w, Path path,
+    void diffManyChildren(JsopWriter w, Path path,
                                   RevisionVector fromRev,
                                   RevisionVector toRev) {
         long minTimestamp = Utils.getMinTimestampForDiff(
diff --git 
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterTest.java
 
b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterTest.java
index 0002b76ef9..3416d15cdd 100644
--- 
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterTest.java
+++ 
b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterTest.java
@@ -32,6 +32,9 @@ import com.mongodb.client.MongoDatabase;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.commons.json.JsopBuilder;
+import org.apache.jackrabbit.oak.commons.json.JsopStream;
+import org.apache.jackrabbit.oak.commons.json.JsopWriter;
 import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
 import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
 import org.apache.jackrabbit.oak.spi.blob.BlobStore;
@@ -49,6 +52,7 @@ import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -60,8 +64,7 @@ public class ClusterTest {
     @Rule
     public MongoConnectionFactory connectionFactory = new 
MongoConnectionFactory();
 
-    private static final boolean MONGO_DB = false;
-    // private static final boolean MONGO_DB = true;
+    private static final boolean MONGO_DB = true;
 
     private List<DocumentMK> mks = Lists.newArrayList();
     private MemoryDocumentStore ds;
@@ -351,6 +354,35 @@ public class ClusterTest {
         mk2.commit("/", "+\"a\": {}", null, null);
     }
 
+    @Test
+    @Ignore("OAK-10812")
+    public void diffManyChildrenReadOnlyMode() throws Exception {
+        DocumentMK mk1 = createMK(1, 0);
+        DocumentMK mk2 = createMK(2, 0);
+        NodeBuilder builder = mk1.getNodeStore().getRoot().builder();
+        builder.child("foo1").child("bar1");
+        merge(mk1.getNodeStore(), builder);
+        mk1.runBackgroundOperations();
+        mk2.runBackgroundOperations();
+        RevisionVector fromRev = 
mk1.getNodeStore().getRoot().getLastRevision();
+        Thread.sleep(1000);
+        builder = mk1.getNodeStore().getRoot().builder();
+        builder.getChildNode("foo1").getChildNode("bar1").setProperty("test", 
"test");
+        merge(mk1.getNodeStore(), builder);
+        disposeMK(mk1);
+        Thread.sleep(1000);
+        mk1 = createMK(1, 0);
+        DocumentMK mk1ro = createMK(1, 0, true);
+        DocumentNodeStore ns1ro = mk1ro.getNodeStore();
+        RevisionVector toRev = ns1ro.getRoot().getLastRevision();
+        Thread.sleep(5000);
+        JsopWriter w1 = new JsopStream();
+        ns1ro.diffManyChildren(w1, ns1ro.getRoot().getPath(), fromRev, toRev);
+        JsopWriter w2 = new JsopStream();
+        mk1.getNodeStore().diffManyChildren(w2, ns1ro.getRoot().getPath(), 
fromRev, toRev);
+        assertEquals(w1.toString(), w2.toString());
+    }
+
     @Test
     public void fromExternalChange() throws Exception {
         final List<DocumentNodeState> rootStates1 = Lists.newArrayList();
@@ -419,10 +451,12 @@ public class ClusterTest {
         return createMK(clusterId, 10);
     }
 
-    private DocumentMK createMK(int clusterId, int asyncDelay) {
+    private DocumentMK createMK(int clusterId, int asyncDelay, boolean 
readonly) {
         if (MONGO_DB) {
             MongoConnection connection = connectionFactory.getConnection();
-            return register(new DocumentMK.Builder()
+            DocumentMK.Builder builder = new DocumentMK.Builder();
+            if (readonly) { builder.setReadOnlyMode(); };
+            return register(builder
                     .setMongoDB(connection.getMongoClient(), 
connection.getDBName())
                     .setClusterId(clusterId).setAsyncDelay(asyncDelay).open());
         } else {
@@ -436,6 +470,10 @@ public class ClusterTest {
         }
     }
 
+    private DocumentMK createMK(int clusterId, int asyncDelay) {
+        return createMK(clusterId, asyncDelay, false);
+    }
+
     private DocumentMK createMK(int clusterId, int asyncDelay,
                              DocumentStore ds, BlobStore bs) {
         return register(new DocumentMK.Builder().setDocumentStore(ds)

Reply via email to