Apache Lucene open-source search software
LUCENE-5161: set sane default readChunkSizes, make the setter work, and test the chunking
Robert Muir51314afdd40d
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 7c28a8800e8..f49c7c0b210 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -112,6 +112,10 @@ Bug Fixesseek/lookup which can cause sideeffects if done on a cached FST root arc.(Simon Willnauer)+* LUCENE-5161: Fix default chunk sizes in FSDirectory.java to not be unnecessarily large,+ and fix setReadChunkSize to always work regardless of whether the machine is 32bit+ or 64bit. (Uwe Schindler, Robert Muir)+API Changes* LUCENE-5094: Add ramBytesUsed() to MultiDocValues.OrdinalMap.diff --git a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.javaindex 1c739bd2831..33b99845287 100644--- a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java+++ b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java@@ -112,12 +112,9 @@ import org.apache.lucene.util.Constants;public abstract class FSDirectory extends Directory {/**- * Default read chunk size. This is a conditional default: on 32bit JVMs, it defaults to 100 MB. On 64bit JVMs, it's- * <code>Integer.MAX_VALUE</code>.- *- * @see #setReadChunkSize+ * Default read chunk size: 2*{@link BufferedIndexInput#MERGE_BUFFER_SIZE}.*/- public static final int DEFAULT_READ_CHUNK_SIZE = Constants.JRE_IS_64BIT ? Integer.MAX_VALUE : 100 * 1024 * 1024;+ public static final int DEFAULT_READ_CHUNK_SIZE = BufferedIndexInput.MERGE_BUFFER_SIZE * 2;protected final File directory; // The underlying filesystem directoryprotected final Set<String> staleFiles = synchronizedSet(new HashSet<String>()); // Files written, but not yet sync'ed@@ -370,20 +367,13 @@ public abstract class FSDirectory extends Directory {* already-opened {@link IndexInput}s. You should call* this before attempting to open an index on the* directory.</p>- *- * <p> <b>NOTE</b>: This value should be as large as- * possible to reduce any possible performance impact. If- * you still encounter an incorrect OutOfMemoryError,- * trying lowering the chunk size.</p>*/public final void setReadChunkSize(int chunkSize) {// LUCENE-1566if (chunkSize <= 0) {throw new IllegalArgumentException("chunkSize must be positive");}- if (!Constants.JRE_IS_64BIT) {- this.chunkSize = chunkSize;- }+ this.chunkSize = chunkSize;}/**diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.javaindex 985c1d205e7..90fc51b7458 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java@@ -20,6 +20,7 @@ package org.apache.lucene.util;import java.io.*;import java.lang.annotation.*;import java.lang.reflect.Constructor;+import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.util.*;import java.util.concurrent.*;@@ -1135,9 +1136,10 @@ public abstract class LuceneTestCase extends Assert {FSDirectory d = null;try {d = CommandLineUtil.newFSDirectory(clazz, file);- } catch (Exception e) {- d = FSDirectory.open(file);+ } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {+ Rethrow.rethrow(e);}+ d.setReadChunkSize(_TestUtil.nextInt(random(), 8, 32678));return d;}