From 4e737ef56ebfb7a240a463026f2c7da0b61ddaa4 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Mon, 23 Aug 2010 17:22:37 +0000 Subject: [PATCH] LUCENE-2615: don't create files w/ bogus permissions; don't hardwire buffer size to 1MB git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@988216 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/contrib/CHANGES.txt | 5 ++++ .../lucene/store/DirectIOLinuxDirectory.java | 23 +++++++++---------- .../apache/lucene/store/NativePosixUtil.cpp | 6 +++-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lucene/contrib/CHANGES.txt b/lucene/contrib/CHANGES.txt index 010a2e5eacd..60a454e1817 100644 --- a/lucene/contrib/CHANGES.txt +++ b/lucene/contrib/CHANGES.txt @@ -32,6 +32,7 @@ API Changes safety, serialization, and performance problems. If you have written a custom RegexCapabilities it will need to be updated to 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 Changes diff --git a/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java b/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java index 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; } @Override public 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); } @Override public 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.cpp index 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 -#include // posix_fadvise +#include // posix_fadvise, constants for open #include // strerror #include // errno #include // pread #include // posix_madvise, madvise +#include // constants for open +#include // 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_1dir if (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);