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 md...@apache.org on 2018/09/18 09:33:32 UTC

svn commit: r1841211 - /jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileAccess.java

Author: mduerig
Date: Tue Sep 18 09:33:32 2018
New Revision: 1841211

URL: http://svn.apache.org/viewvc?rev=1841211&view=rev
Log:
OAK-7762: Store segments off heap when memory mapping is disabled
Use -Daccess.off.heap=true to enable

Modified:
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileAccess.java

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileAccess.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileAccess.java?rev=1841211&r1=1841210&r2=1841211&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileAccess.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileAccess.java Tue Sep 18 09:33:32 2018
@@ -19,6 +19,7 @@
 package org.apache.jackrabbit.oak.segment.file.tar;
 
 import static com.google.common.base.Preconditions.checkState;
+import static java.lang.Boolean.getBoolean;
 import static java.nio.channels.FileChannel.MapMode.READ_ONLY;
 import static org.apache.jackrabbit.oak.commons.IOUtils.readFully;
 
@@ -35,6 +36,8 @@ import java.nio.channels.FileChannel;
  */
 abstract class FileAccess {
 
+    private static final boolean OFF_HEAP = getBoolean("access.off.heap");
+
     abstract boolean isMemoryMapped();
 
     abstract int length() throws IOException;
@@ -113,7 +116,12 @@ abstract class FileAccess {
         @Override
         public synchronized ByteBuffer read(int position, int length)
                 throws IOException {
-            ByteBuffer entry = ByteBuffer.allocate(length);
+            ByteBuffer entry;
+            if (OFF_HEAP) {
+                entry = ByteBuffer.allocateDirect(length);
+            } else {
+                entry = ByteBuffer.allocate(length);
+            }
             if (readFully(channel, position, entry) < length) {
                 throw new EOFException();
             }