lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1684974 - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/CHANGES.txt lucene/core/ lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java lucene/core/src/test/org/apache/lucene/store/TestMmapDirectory.java
Date Thu, 11 Jun 2015 21:08:11 GMT
Author: rmuir
Date: Thu Jun 11 21:08:10 2015
New Revision: 1684974

URL: http://svn.apache.org/r1684974
Log:
LUCENE-6549: add preload option to MMapDirectory

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/lucene/core/   (props changed)
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/store/TestMmapDirectory.java

Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1684974&r1=1684973&r2=1684974&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Thu Jun 11 21:08:10 2015
@@ -41,6 +41,8 @@ New Features
   the per-hit polygon check when a leaf cell is fully contained by the
   polygon.  (Nick Knize, Mike McCandless)
 
+* LUCENE-6549: Add preload option to MMapDirectory. (Robert Muir)
+
 API Changes
 
 * LUCENE-6508: Simplify Lock api, there is now just 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java?rev=1684974&r1=1684973&r2=1684974&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java
Thu Jun 11 21:08:10 2015
@@ -19,6 +19,7 @@ package org.apache.lucene.store;
  
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.nio.MappedByteBuffer;
 import java.nio.channels.ClosedChannelException; // javadoc @link
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileChannel.MapMode;
@@ -86,6 +87,8 @@ import org.apache.lucene.util.Constants;
  */
 public class MMapDirectory extends FSDirectory {
   private boolean useUnmapHack = UNMAP_SUPPORTED;
+  private boolean preload;
+
   /** 
    * Default max chunk size.
    * @see #MMapDirectory(Path, LockFactory, int)
@@ -198,6 +201,24 @@ public class MMapDirectory extends FSDir
   }
   
   /**
+   * Set to {@code true} to ask mapped pages to be loaded
+   * into physical memory on init. The behavior is best-effort 
+   * and operating system dependent.
+   * @see MappedByteBuffer#load
+   */
+  public void setPreload(boolean preload) {
+    this.preload = preload;
+  }
+  
+  /**
+   * Returns {@code true} if mapped pages should be loaded.
+   * @see #setPreload
+   */
+  public boolean getPreload() {
+    return preload;
+  }
+  
+  /**
    * Returns the current mmap chunk size.
    * @see #MMapDirectory(Path, LockFactory, int)
    */
@@ -237,11 +258,16 @@ public class MMapDirectory extends FSDir
           ? chunkSize
               : (length - bufferStart)
           );
+      MappedByteBuffer buffer;
       try {
-        buffers[bufNr] = fc.map(MapMode.READ_ONLY, offset + bufferStart, bufSize);
+        buffer = fc.map(MapMode.READ_ONLY, offset + bufferStart, bufSize);
       } catch (IOException ioe) {
         throw convertMapFailedIOException(ioe, resourceDescription, bufSize);
       }
+      if (preload) {
+        buffer.load();
+      }
+      buffers[bufNr] = buffer;
       bufferStart += bufSize;
     }
     

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/store/TestMmapDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/store/TestMmapDirectory.java?rev=1684974&r1=1684973&r2=1684974&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/store/TestMmapDirectory.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/store/TestMmapDirectory.java
Thu Jun 11 21:08:10 2015
@@ -27,6 +27,8 @@ public class TestMmapDirectory extends B
 
   @Override
   protected Directory getDirectory(Path path) throws IOException {
-    return new MMapDirectory(path);
+    MMapDirectory m = new MMapDirectory(path);
+    m.setPreload(random().nextBoolean());
+    return m;
   }
 }



Mime
View raw message