You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2010/08/27 23:49:11 UTC

svn commit: r990281 - in /lucene/dev/trunk/lucene: CHANGES.txt src/java/org/apache/lucene/store/MMapDirectory.java src/test/org/apache/lucene/store/TestMultiMMap.java

Author: rmuir
Date: Fri Aug 27 21:49:11 2010
New Revision: 990281

URL: http://svn.apache.org/viewvc?rev=990281&view=rev
Log:
LUCENE-2627: MMapDirectory bug when file size is exact multiple of chunk size

Added:
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestMultiMMap.java   (with props)
Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=990281&r1=990280&r2=990281&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Fri Aug 27 21:49:11 2010
@@ -493,6 +493,9 @@ Bug fixes
 * LUCENE-2616: FastVectorHighlighter: out of alignment when the first value is
   empty in multiValued field (Koji Sekiguchi)
 
+* LUCENE-2627: Fixed bug in MMapDirectory chunking when a file is an
+  exact multiple of the chunk size.  (Robert Muir)
+
 New features
 
 * LUCENE-2128: Parallelized fetching document frequencies during weight

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java?rev=990281&r1=990280&r2=990281&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java Fri Aug 27 21:49:11 2010
@@ -309,7 +309,7 @@ public class MMapDirectory extends FSDir
            + raf.toString());
       
       int nrBuffers = (int) (length / maxBufSize);
-      if (((long) nrBuffers * maxBufSize) < length) nrBuffers++;
+      if (((long) nrBuffers * maxBufSize) <= length) nrBuffers++;
       
       this.buffers = new ByteBuffer[nrBuffers];
       this.bufSizes = new int[nrBuffers];

Added: lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestMultiMMap.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestMultiMMap.java?rev=990281&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestMultiMMap.java (added)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestMultiMMap.java Fri Aug 27 21:49:11 2010
@@ -0,0 +1,86 @@
+package org.apache.lucene.store;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.util.Random;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util._TestUtil;
+
+/**
+ * Tests MMapDirectory's MultiMMapIndexInput
+ * <p>
+ * Because Java's ByteBuffer uses an int to address the
+ * values, it's necessary to access a file >
+ * Integer.MAX_VALUE in size using multiple byte buffers.
+ */
+public class TestMultiMMap extends LuceneTestCase {
+  File workDir;
+  
+  @Override
+  protected void setUp() throws Exception {
+      super.setUp();
+      workDir = new File(TEMP_DIR, "TestMultiMMap");
+      workDir.mkdirs();
+  }
+  
+  public void testRandomChunkSizes() throws Exception {
+    Random random = newRandom();
+    for (int i = 0; i < 10*RANDOM_MULTIPLIER; i++)
+      assertChunking(random, _TestUtil.nextInt(random, 1, 1000*RANDOM_MULTIPLIER));
+  }
+  
+  private void assertChunking(Random random, int chunkSize) throws Exception {
+    File path = File.createTempFile("mmap" + chunkSize, "tmp", workDir);
+    path.delete();
+    path.mkdirs();
+    MMapDirectory dir = new MMapDirectory(path);
+    dir.setMaxChunkSize(chunkSize);
+    // we will map a lot, try to turn on the unmap hack
+    if (MMapDirectory.UNMAP_SUPPORTED)
+      dir.setUseUnmap(true);
+    RandomIndexWriter writer = new RandomIndexWriter(random, dir);
+    Document doc = new Document();
+    Field docid = new Field("docid", "0", Field.Store.YES, Field.Index.NOT_ANALYZED);
+    Field junk = new Field("junk", "", Field.Store.YES, Field.Index.NOT_ANALYZED);
+    doc.add(docid);
+    doc.add(junk);
+    
+    int numDocs = 1000*RANDOM_MULTIPLIER;
+    for (int i = 0; i < numDocs; i++) {
+      docid.setValue("" + i);
+      junk.setValue(_TestUtil.randomUnicodeString(random));
+      writer.addDocument(doc);
+    }
+    IndexReader reader = writer.getReader();
+    writer.close();
+    
+    int numAsserts = 100*RANDOM_MULTIPLIER;
+    for (int i = 0; i < numAsserts; i++) {
+      int docID = random.nextInt(numDocs);
+      assertEquals("" + docID, reader.document(docID).get("docid"));
+    }
+    reader.close();
+    dir.close();
+  }
+}

Propchange: lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/TestMultiMMap.java
------------------------------------------------------------------------------
    svn:eol-style = native