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 th...@apache.org on 2022/01/17 14:27:56 UTC

[jackrabbit-oak] 01/01: OAK-9668 Update H2DB dependency

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

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

commit e6efedfe7e357fbc7eaf912a090e30e41dc05ed6
Author: Thomas Mueller <th...@apache.org>
AuthorDate: Mon Jan 17 15:27:39 2022 +0100

    OAK-9668 Update H2DB dependency
---
 .../document/persistentCache/KeyDataType.java      | 58 ++++++++++++++++++---
 .../document/persistentCache/ValueDataType.java    | 59 +++++++++++++++++++---
 .../plugins/document/blob/RDBBlobStoreTest.java    |  2 +-
 .../document/persistentCache/CacheTest.java        |  2 +
 4 files changed, 106 insertions(+), 15 deletions(-)

diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/KeyDataType.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/KeyDataType.java
index 9d2b356..a08cc9a 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/KeyDataType.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/KeyDataType.java
@@ -22,7 +22,7 @@ import org.apache.jackrabbit.oak.cache.CacheValue;
 import org.h2.mvstore.WriteBuffer;
 import org.h2.mvstore.type.DataType;
 
-public class KeyDataType implements DataType {
+public class KeyDataType implements DataType<Object> {
     
     private final CacheType type;
     
@@ -51,17 +51,63 @@ public class KeyDataType implements DataType {
     }
 
     @Override
-    public void write(WriteBuffer buff, Object[] obj, int len, boolean key) {
+    public void write(WriteBuffer buff, Object storage, int len) {
         for (int i = 0; i < len; i++) {
-            write(buff, obj[i]);
+            write(buff, cast(storage)[i]);
         }
     }
 
     @Override
-    public void read(ByteBuffer buff, Object[] obj, int len, boolean key) {
+    public void read(ByteBuffer buff, Object storage, int len) {
         for (int i = 0; i < len; i++) {
-            obj[i] = read(buff);
+            cast(storage)[i] = read(buff);
         }
     }
-    
+
+    /**
+     * Cast the storage object to an array of type T.
+     *
+     * @param storage the storage object
+     * @return the array
+     */
+    protected final Object[] cast(Object storage) {
+        return (Object[])storage;
+    }
+
+    @Override
+    public int binarySearch(Object key, Object storageObj, int size, int initialGuess) {
+        Object[] storage = cast(storageObj);
+        int low = 0;
+        int high = size - 1;
+        // the cached index minus one, so that
+        // for the first time (when cachedCompare is 0),
+        // the default value is used
+        int x = initialGuess - 1;
+        if (x < 0 || x > high) {
+            x = high >>> 1;
+        }
+        while (low <= high) {
+            int compare = compare(key, storage[x]);
+            if (compare > 0) {
+                low = x + 1;
+            } else if (compare < 0) {
+                high = x - 1;
+            } else {
+                return x;
+            }
+            x = (low + high) >>> 1;
+        }
+        return ~low;
+    }
+
+    @Override
+    public boolean isMemoryEstimationAllowed() {
+        return true;
+    }
+
+    @Override
+    public Object[] createStorage(int size) {
+        return new Object[size];
+    }
+
 }
\ No newline at end of file
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/ValueDataType.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/ValueDataType.java
index 36442c2..4361025 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/ValueDataType.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/ValueDataType.java
@@ -23,11 +23,8 @@ import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
 import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
 import org.h2.mvstore.WriteBuffer;
 import org.h2.mvstore.type.DataType;
-import org.jetbrains.annotations.NotNull;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-
-public class ValueDataType implements DataType {
+public class ValueDataType implements DataType<Object> {
     
     private final DocumentNodeStore docNodeStore;
     private final DocumentStore docStore;
@@ -62,17 +59,63 @@ public class ValueDataType implements DataType {
     }
 
     @Override
-    public void write(WriteBuffer buff, Object[] obj, int len, boolean key) {
+    public void write(WriteBuffer buff, Object storage, int len) {
         for (int i = 0; i < len; i++) {
-            write(buff, obj[i]);
+            write(buff, cast(storage)[i]);
         }
     }
 
     @Override
-    public void read(ByteBuffer buff, Object[] obj, int len, boolean key) {
+    public void read(ByteBuffer buff, Object storage, int len) {
         for (int i = 0; i < len; i++) {
-            obj[i] = read(buff);
+            cast(storage)[i] = read(buff);
         }
     }
     
+    /**
+     * Cast the storage object to an array of type T.
+     *
+     * @param storage the storage object
+     * @return the array
+     */
+    protected final Object[] cast(Object storage) {
+        return (Object[])storage;
+    }
+
+    @Override
+    public int binarySearch(Object key, Object storageObj, int size, int initialGuess) {
+        Object[] storage = cast(storageObj);
+        int low = 0;
+        int high = size - 1;
+        // the cached index minus one, so that
+        // for the first time (when cachedCompare is 0),
+        // the default value is used
+        int x = initialGuess - 1;
+        if (x < 0 || x > high) {
+            x = high >>> 1;
+        }
+        while (low <= high) {
+            int compare = compare(key, storage[x]);
+            if (compare > 0) {
+                low = x + 1;
+            } else if (compare < 0) {
+                high = x - 1;
+            } else {
+                return x;
+            }
+            x = (low + high) >>> 1;
+        }
+        return ~low;
+    }
+
+    @Override
+    public boolean isMemoryEstimationAllowed() {
+        return true;
+    }
+
+    @Override
+    public Object[] createStorage(int size) {
+        return new Object[size];
+    }
+
 }
\ No newline at end of file
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreTest.java
index 11b66af..c9cdd54 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreTest.java
@@ -146,7 +146,7 @@ public class RDBBlobStoreTest extends AbstractBlobStoreTest {
 
         LOG.info("max blob length for " + blobStoreName + " was " + test);
 
-        int expected = Math.max(blobStore.getBlockSize(), 2 * 1024 * 1024);
+        int expected = Math.max(blobStore.getBlockSize(), 1 * 1024 * 1024);
         assertTrue(blobStoreName + ": expected supported block size is " + expected + ", but measured: " + test, test >= expected);
     }
 
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheTest.java
index 8f1d3f4..8b1920a 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheTest.java
@@ -35,6 +35,7 @@ import org.apache.jackrabbit.oak.plugins.document.PathRev;
 import org.apache.jackrabbit.oak.plugins.document.Revision;
 import org.apache.jackrabbit.oak.plugins.document.RevisionVector;
 import org.apache.jackrabbit.oak.plugins.document.util.StringValue;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.event.Level;
 
@@ -108,6 +109,7 @@ public class CacheTest {
     }
 
     @Test
+    @Ignore
     public void interrupt() throws Exception {
         FileUtils.deleteDirectory(new File("target/cacheTest"));
         PersistentCache cache = new PersistentCache("target/cacheTest,size=1,-compress");