Apache Lucene open-source search software
LUCENE-2615: don't create files w/ bogus permissions; don't hardwire buffer size to 1MB
Michael McCandless4e737ef56ebf
diff --git a/lucene/contrib/CHANGES.txt b/lucene/contrib/CHANGES.txtindex 010a2e5eacd..60a454e1817 100644--- a/lucene/contrib/CHANGES.txt+++ b/lucene/contrib/CHANGES.txt@@ -32,6 +32,7 @@ API Changessafety, serialization, and performance problems. If you havewritten a custom RegexCapabilities it will need to be updatedto the new API. (Robert Muir, Uwe Schindler)+======================= Lucene 3.x (not yet released) =======================Changes in backwards compatibility policy@@ -109,6 +110,10 @@ Bug fixes* LUCENE-2524: FastVectorHighlighter: use mod for getting colored tag.(Koji Sekiguchi)++* LUCENE-2615: Fix DirectIOLinuxDirectory to not assign bogus+ permissions to newly created files, and to not silently hardwire+ buffer size to 1 MB. (Mark Miller, Robert Muir, Mike McCandless)API Changesdiff --git a/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java b/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.javaindex aad15bd93e7..7b0ed9518dd 100644--- a/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java+++ b/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java@@ -46,37 +46,36 @@ public class DirectIOLinuxDirectory extends FSDirectory {private final static long ALIGN = 512;private final static long ALIGN_NOT_MASK = ~(ALIGN-1);+ private final int forcedBufferSize;+/** Create a new NIOFSDirectory for the named location.** @param path the path of the directory* @param lockFactory the lock factory to use, or null for the default* ({@link NativeFSLockFactory});+ * @param forcedBufferSize if this is 0, just use Lucene's+ * default buffer size; else, force this buffer size.+ * For best performance, force the buffer size to+ * something fairly large (eg 1 MB), but note that this+ * will eat up the JRE's direct buffer storage space* @throws IOException*/- public DirectIOLinuxDirectory(File path, LockFactory lockFactory) throws IOException {+ public DirectIOLinuxDirectory(File path, LockFactory lockFactory, int forcedBufferSize) throws IOException {super(path, lockFactory);- }-- /** Create a new NIOFSDirectory for the named location and {@link NativeFSLockFactory}.- *- * @param path the path of the directory- * @throws IOException- */- public DirectIOLinuxDirectory(File path) throws IOException {- super(path, null);+ this.forcedBufferSize = forcedBufferSize;}@Overridepublic IndexInput openInput(String name, int bufferSize) throws IOException {ensureOpen();- return new DirectIOLinuxIndexInput(new File(getDirectory(), name), bufferSize);+ return new DirectIOLinuxIndexInput(new File(getDirectory(), name), forcedBufferSize == 0 ? bufferSize : forcedBufferSize);}@Overridepublic IndexOutput createOutput(String name) throws IOException {ensureOpen();ensureCanWrite(name);- return new DirectIOLinuxIndexOutput(new File(getDirectory(), name), 4096);+ return new DirectIOLinuxIndexOutput(new File(getDirectory(), name), forcedBufferSize == 0 ? BufferedIndexOutput.BUFFER_SIZE : forcedBufferSize);}private final static class DirectIOLinuxIndexOutput extends IndexOutput {diff --git a/lucene/contrib/misc/src/java/org/apache/lucene/store/NativePosixUtil.cpp b/lucene/contrib/misc/src/java/org/apache/lucene/store/NativePosixUtil.cppindex 28f6dbf86a1..ced785fff6d 100644--- a/lucene/contrib/misc/src/java/org/apache/lucene/store/NativePosixUtil.cpp+++ b/lucene/contrib/misc/src/java/org/apache/lucene/store/NativePosixUtil.cpp@@ -1,9 +1,11 @@#include <jni.h>-#include <fcntl.h> // posix_fadvise+#include <fcntl.h> // posix_fadvise, constants for open#include <string.h> // strerror#include <errno.h> // errno#include <unistd.h> // pread#include <sys/mman.h> // posix_madvise, madvise+#include <sys/types.h> // constants for open+#include <sys/stat.h> // constants for open// java -cp .:lib/junit-4.7.jar:./build/classes/test:./build/classes/java:./build/classes/demo -Dlucene.version=2.9-dev -DtempDir=build -ea org.junit.runner.JUnitCore org.apache.lucene.index.TestDoc@@ -97,7 +99,7 @@ JNIEXPORT jobject JNICALL Java_org_apache_lucene_store_NativePosixUtil_open_1dirif (readOnly) {fd = open(fname, O_RDONLY | O_DIRECT);} else {- fd = open(fname, O_RDWR | O_CREAT | O_DIRECT);+ fd = open(fname, O_RDWR | O_CREAT | O_DIRECT, 0666);}//printf("open %s -> %d; ro %d\n", fname, fd, readOnly); fflush(stdout);