Apache Lucene open-source search software
Remove SimpleFSDirectory in favor of NIOFSDirectory
Yannick Welsch8a88dd02c6cb
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 5e710ceafde..2919704cd88 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -44,6 +44,9 @@ API Changes* LUCENE-9212: Deprecated Intervals.multiterm() methods that take a bare Automatonhave been removed (Alan Woodward)+* LUCENE-9264: SimpleFSDirectory has been removed in favor of NIOFSDirectory.+ (Yannick Welsch)+Improvements* LUCENE-8757: When provided with an ExecutorService to run queries acrossdiff --git a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene50/TestBlockPostingsFormat.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene50/TestBlockPostingsFormat.javaindex 690eba8aeeb..8cfca52d856 100644--- a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene50/TestBlockPostingsFormat.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene50/TestBlockPostingsFormat.java@@ -48,7 +48,7 @@ import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexInput;import org.apache.lucene.store.IndexOutput;import org.apache.lucene.store.MMapDirectory;-import org.apache.lucene.store.SimpleFSDirectory;+import org.apache.lucene.store.NIOFSDirectory;import org.apache.lucene.util.TestUtil;/**@@ -117,7 +117,7 @@ public class TestBlockPostingsFormat extends BasePostingsFormatTestCase {}}- try (Directory d = new SimpleFSDirectory(tempDir)) {+ try (Directory d = new NIOFSDirectory(tempDir)) {// test autotry (DirectoryReader r = DirectoryReader.open(d)) {assertEquals(1, r.leaves().size());@@ -128,7 +128,7 @@ public class TestBlockPostingsFormat extends BasePostingsFormatTestCase {}}- try (Directory d = new SimpleFSDirectory(tempDir)) {+ try (Directory d = new NIOFSDirectory(tempDir)) {// test per fieldMap<String, String> readerAttributes = new HashMap<>();readerAttributes.put(BlockTreeTermsReader.FST_MODE_KEY, BlockTreeTermsReader.FSTLoadMode.OFF_HEAP.name());@@ -143,7 +143,7 @@ public class TestBlockPostingsFormat extends BasePostingsFormatTestCase {}IllegalArgumentException invalid = expectThrows(IllegalArgumentException.class, () -> {- try (Directory d = new SimpleFSDirectory(tempDir)) {+ try (Directory d = new NIOFSDirectory(tempDir)) {Map<String, String> readerAttributes = new HashMap<>();readerAttributes.put(BlockTreeTermsReader.FST_MODE_KEY, "invalid");DirectoryReader.open(d, readerAttributes);diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java b/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.javaindex d2b18199ba2..cfc501a2439 100644--- a/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java@@ -71,7 +71,6 @@ import org.apache.lucene.store.ByteBuffersDirectory;import org.apache.lucene.store.Directory;import org.apache.lucene.store.FSDirectory;import org.apache.lucene.store.NIOFSDirectory;-import org.apache.lucene.store.SimpleFSDirectory;import org.apache.lucene.util.Bits;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.IOUtils;@@ -1442,8 +1441,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {// - LuceneTestCase.FS_DIRECTORIES is private// - newFSDirectory returns BaseDirectoryWrapper// - BaseDirectoryWrapper doesn't expose delegate- Class<? extends FSDirectory> dirImpl = random().nextBoolean() ?- SimpleFSDirectory.class : NIOFSDirectory.class;+ Class<? extends FSDirectory> dirImpl = NIOFSDirectory.class;args.add("-dir-impl");args.add(dirImpl.getName());diff --git a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.javaindex c76a3c35ad4..ee9ec1e1c93 100644--- a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java+++ b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java@@ -53,13 +53,6 @@ import org.apache.lucene.util.IOUtils;** <ul>*- * <li>{@link SimpleFSDirectory} is a straightforward- * implementation using Files.newByteChannel.- * However, it has poor concurrent performance- * (multiple threads will bottleneck) as it- * synchronizes when multiple threads read from the- * same file.- ** <li>{@link NIOFSDirectory} uses java.nio's* FileChannel's positional io when reading to avoid* synchronization when reading from the same file.@@ -170,11 +163,9 @@ public abstract class FSDirectory extends BaseDirectory {* {@code IndexWriters} and create a new {@code FSDirectory} instance.** <p>Currently this returns {@link MMapDirectory} for Linux, MacOSX, Solaris,- * and Windows 64-bit JREs, {@link NIOFSDirectory} for other- * non-Windows JREs, and {@link SimpleFSDirectory} for other- * JREs on Windows. It is highly recommended that you consult the- * implementation's documentation for your platform before- * using this method.+ * and Windows 64-bit JREs, and {@link NIOFSDirectory} for other JREs.+ * It is highly recommended that you consult the implementation's documentation+ * for your platform before using this method.** <p><b>NOTE</b>: this method may suddenly change which* implementation is returned from release to release, in@@ -194,8 +185,6 @@ public abstract class FSDirectory extends BaseDirectory {public static FSDirectory open(Path path, LockFactory lockFactory) throws IOException {if (Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) {return new MMapDirectory(path, lockFactory);- } else if (Constants.WINDOWS) {- return new SimpleFSDirectory(path, lockFactory);} else {return new NIOFSDirectory(path, lockFactory);}diff --git a/lucene/core/src/java/org/apache/lucene/store/LockStressTest.java b/lucene/core/src/java/org/apache/lucene/store/LockStressTest.javaindex 8d8c042f59d..b319df46eed 100644--- a/lucene/core/src/java/org/apache/lucene/store/LockStressTest.java+++ b/lucene/core/src/java/org/apache/lucene/store/LockStressTest.java@@ -80,7 +80,7 @@ public class LockStressTest {final LockFactory lockFactory = getNewLockFactory(lockFactoryClassName);// we test the lock factory directly, so we don't need it on the directory itsself (the directory is just for testing)- final FSDirectory lockDir = new SimpleFSDirectory(lockDirPath, NoLockFactory.INSTANCE);+ final FSDirectory lockDir = new NIOFSDirectory(lockDirPath, NoLockFactory.INSTANCE);final InetSocketAddress addr = new InetSocketAddress(verifierHost, verifierPort);System.out.println("Connecting to server " + addr +" and registering as client " + myID + "...");diff --git a/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java b/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.javadeleted file mode 100644index 0d650ae78de..00000000000--- a/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java+++ /dev/null@@ -1,200 +0,0 @@-/*- * 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.- */-package org.apache.lucene.store;---import java.io.EOFException;-import java.io.IOException;-import java.nio.ByteBuffer;-import java.nio.channels.SeekableByteChannel;-import java.nio.channels.ClosedChannelException; // javadoc @link-import java.nio.file.Files;-import java.nio.file.Path;-import java.nio.file.StandardOpenOption;-import java.util.concurrent.Future;--/** A straightforward implementation of {@link FSDirectory}- * using {@link Files#newByteChannel(Path, java.nio.file.OpenOption...)}.- * However, this class has- * poor concurrent performance (multiple threads will- * bottleneck) as it synchronizes when multiple threads- * read from the same file. It's usually better to use- * {@link NIOFSDirectory} or {@link MMapDirectory} instead.- * <p>- * <b>NOTE:</b> Accessing this class either directly or- * indirectly from a thread while it's interrupted can close the- * underlying file descriptor immediately if at the same time the thread is- * blocked on IO. The file descriptor will remain closed and subsequent access- * to {@link SimpleFSDirectory} will throw a {@link ClosedChannelException}. If- * your application uses either {@link Thread#interrupt()} or- * {@link Future#cancel(boolean)} you should use the legacy {@code RAFDirectory}- * from the Lucene {@code misc} module in favor of {@link SimpleFSDirectory}.- * </p>- */-public class SimpleFSDirectory extends FSDirectory {-- /** Create a new SimpleFSDirectory for the named location.- * The directory is created at the named location if it does not yet exist.- *- * @param path the path of the directory- * @param lockFactory the lock factory to use- * @throws IOException if there is a low-level I/O error- */- public SimpleFSDirectory(Path path, LockFactory lockFactory) throws IOException {- super(path, lockFactory);- }-- /** Create a new SimpleFSDirectory for the named location and {@link FSLockFactory#getDefault()}.- * The directory is created at the named location if it does not yet exist.- *- * @param path the path of the directory- * @throws IOException if there is a low-level I/O error- */- public SimpleFSDirectory(Path path) throws IOException {- this(path, FSLockFactory.getDefault());- }-- /** Creates an IndexInput for the file with the given name. */- @Override- public IndexInput openInput(String name, IOContext context) throws IOException {- ensureOpen();- ensureCanRead(name);- Path path = directory.resolve(name);- SeekableByteChannel channel = Files.newByteChannel(path, StandardOpenOption.READ);- return new SimpleFSIndexInput("SimpleFSIndexInput(path=\"" + path + "\")", channel, context);- }-- /**- * Reads bytes with {@link SeekableByteChannel#read(ByteBuffer)}- */- static final class SimpleFSIndexInput extends BufferedIndexInput {- /**- * The maximum chunk size for reads of 16384 bytes.- */- private static final int CHUNK_SIZE = 16384;-- /** the channel we will read from */- protected final SeekableByteChannel channel;- /** is this instance a clone and hence does not own the file to close it */- boolean isClone = false;- /** start offset: non-zero in the slice case */- protected final long off;- /** end offset (start+length) */- protected final long end;-- private ByteBuffer byteBuf; // wraps the buffer for NIO-- public SimpleFSIndexInput(String resourceDesc, SeekableByteChannel channel, IOContext context) throws IOException {- super(resourceDesc, context);- this.channel = channel;- this.off = 0L;- this.end = channel.size();- }-- public SimpleFSIndexInput(String resourceDesc, SeekableByteChannel channel, long off, long length, int bufferSize) {- super(resourceDesc, bufferSize);- this.channel = channel;- this.off = off;- this.end = off + length;- this.isClone = true;- }-- @Override- public void close() throws IOException {- if (!isClone) {- channel.close();- }- }-- @Override- public SimpleFSIndexInput clone() {- SimpleFSIndexInput clone = (SimpleFSIndexInput)super.clone();- clone.isClone = true;- return clone;- }-- @Override- public IndexInput slice(String sliceDescription, long offset, long length) throws IOException {- if (offset < 0 || length < 0 || offset + length > this.length()) {- throw new IllegalArgumentException("slice() " + sliceDescription + " out of bounds: offset=" + offset + ",length=" + length + ",fileLength=" + this.length() + ": " + this);- }- return new SimpleFSIndexInput(getFullSliceDescription(sliceDescription), channel, off + offset, length, getBufferSize());- }-- @Override- public final long length() {- return end - off;- }-- @Override- protected void newBuffer(byte[] newBuffer) {- super.newBuffer(newBuffer);- byteBuf = ByteBuffer.wrap(newBuffer);- }-- @Override- protected void readInternal(byte[] b, int offset, int len) throws IOException {- final ByteBuffer bb;-- // Determine the ByteBuffer we should use- if (b == buffer) {- // Use our own pre-wrapped byteBuf:- assert byteBuf != null;- bb = byteBuf;- byteBuf.clear().position(offset);- } else {- bb = ByteBuffer.wrap(b, offset, len);- }-- synchronized(channel) {- long pos = getFilePointer() + off;-- if (pos + len > end) {- throw new EOFException("read past EOF: " + this);- }-- try {- channel.position(pos);-- int readLength = len;- while (readLength > 0) {- final int toRead = Math.min(CHUNK_SIZE, readLength);- bb.limit(bb.position() + toRead);- assert bb.remaining() == toRead;- final int i = channel.read(bb);- if (i < 0) { // be defensive here, even though we checked before hand, something could have changed- throw new EOFException("read past EOF: " + this + " off: " + offset + " len: " + len + " pos: " + pos + " chunkLen: " + toRead + " end: " + end);- }- assert i > 0 : "SeekableByteChannel.read with non zero-length bb.remaining() must always read at least one byte (Channel is in blocking mode, see spec of ReadableByteChannel)";- pos += i;- readLength -= i;- }- assert readLength == 0;- } catch (IOException ioe) {- throw new IOException(ioe.getMessage() + ": " + this, ioe);- }- }- }-- @Override- protected void seekInternal(long pos) throws IOException {- if (pos > length()) {- throw new EOFException("read past EOF: pos=" + pos + " vs length=" + length() + ": " + this);- }- }- }-}diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene84/TestLucene84PostingsFormat.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene84/TestLucene84PostingsFormat.javaindex 0be30e33612..c4d1407723f 100644--- a/lucene/core/src/test/org/apache/lucene/codecs/lucene84/TestLucene84PostingsFormat.java+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene84/TestLucene84PostingsFormat.java@@ -50,7 +50,7 @@ import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexInput;import org.apache.lucene.store.IndexOutput;import org.apache.lucene.store.MMapDirectory;-import org.apache.lucene.store.SimpleFSDirectory;+import org.apache.lucene.store.NIOFSDirectory;import org.apache.lucene.util.TestUtil;public class TestLucene84PostingsFormat extends BasePostingsFormatTestCase {@@ -116,7 +116,7 @@ public class TestLucene84PostingsFormat extends BasePostingsFormatTestCase {}}- try (Directory d = new SimpleFSDirectory(tempDir)) {+ try (Directory d = new NIOFSDirectory(tempDir)) {// test autotry (DirectoryReader r = DirectoryReader.open(d)) {assertEquals(1, r.leaves().size());@@ -127,7 +127,7 @@ public class TestLucene84PostingsFormat extends BasePostingsFormatTestCase {}}- try (Directory d = new SimpleFSDirectory(tempDir)) {+ try (Directory d = new NIOFSDirectory(tempDir)) {// test per fieldMap<String, String> readerAttributes = new HashMap<>();readerAttributes.put(BlockTreeTermsReader.FST_MODE_KEY, BlockTreeTermsReader.FSTLoadMode.OFF_HEAP.name());@@ -142,7 +142,7 @@ public class TestLucene84PostingsFormat extends BasePostingsFormatTestCase {}IllegalArgumentException invalid = expectThrows(IllegalArgumentException.class, () -> {- try (Directory d = new SimpleFSDirectory(tempDir)) {+ try (Directory d = new NIOFSDirectory(tempDir)) {Map<String, String> readerAttributes = new HashMap<>();readerAttributes.put(BlockTreeTermsReader.FST_MODE_KEY, "invalid");DirectoryReader.open(d, readerAttributes);diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.javaindex 1e79f391ebb..d6220edf376 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java@@ -95,7 +95,6 @@ import org.apache.lucene.store.MMapDirectory;import org.apache.lucene.store.MockDirectoryWrapper;import org.apache.lucene.store.NIOFSDirectory;import org.apache.lucene.store.NoLockFactory;-import org.apache.lucene.store.SimpleFSDirectory;import org.apache.lucene.store.SimpleFSLockFactory;import org.apache.lucene.util.Bits;import org.apache.lucene.util.BytesRef;@@ -2684,7 +2683,7 @@ public class TestIndexWriter extends LuceneTestCase {// MMapDirectory doesn't work because it closes its file handles after mapping!List<Closeable> toClose = new ArrayList<>();- try (FSDirectory dir = new SimpleFSDirectory(root);+ try (FSDirectory dir = new NIOFSDirectory(root);Closeable closeable = () -> IOUtils.close(toClose)) {assert closeable != null;IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()))@@ -2750,7 +2749,7 @@ public class TestIndexWriter extends LuceneTestCase {// Use WindowsFS to prevent open files from being deleted:FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));Path root = new FilterPath(path, fs);- try (FSDirectory _dir = new SimpleFSDirectory(root)) {+ try (FSDirectory _dir = new NIOFSDirectory(root)) {Directory dir = new FilterDirectory(_dir) {};IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));@@ -2792,7 +2791,7 @@ public class TestIndexWriter extends LuceneTestCase {IndexCommit indexCommit;DirectoryReader reader;// MMapDirectory doesn't work because it closes its file handles after mapping!- try (FSDirectory dir = new SimpleFSDirectory(root)) {+ try (FSDirectory dir = new NIOFSDirectory(root)) {IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random())).setIndexDeletionPolicy(NoDeletionPolicy.INSTANCE);IndexWriter w = new IndexWriter(dir, iwc);w.commit();@@ -2834,7 +2833,7 @@ public class TestIndexWriter extends LuceneTestCase {Path root = new FilterPath(path, fs);DirectoryReader reader;// MMapDirectory doesn't work because it closes its file handles after mapping!- try (FSDirectory dir = new SimpleFSDirectory(root)) {+ try (FSDirectory dir = new NIOFSDirectory(root)) {IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));IndexWriter w = new IndexWriter(dir, iwc);w.commit();diff --git a/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java b/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.javaindex 3d4607d7f7e..50a8203c39d 100644--- a/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java+++ b/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java@@ -264,7 +264,7 @@ public class TestBufferedIndexInput extends LuceneTestCase {final Random rand;public MockFSDirectory(Path path, Random rand) throws IOException {- super(new SimpleFSDirectory(path));+ super(new NIOFSDirectory(path));this.rand = rand;}diff --git a/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestDirectory.javaindex 5ed902a8c5f..7b8c146a317 100644--- a/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java+++ b/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java@@ -42,7 +42,6 @@ public class TestDirectory extends LuceneTestCase {}final List<FSDirectory> dirs0 = new ArrayList<>();- dirs0.add(new SimpleFSDirectory(path));dirs0.add(new NIOFSDirectory(path));if (hasWorkingMMapOnWindows()) {dirs0.add(new MMapDirectory(path));@@ -117,13 +116,13 @@ public class TestDirectory extends LuceneTestCase {// LUCENE-1468public void testNotDirectory() throws Throwable {Path path = createTempDir("testnotdir");- Directory fsDir = new SimpleFSDirectory(path);+ Directory fsDir = new NIOFSDirectory(path);try {IndexOutput out = fsDir.createOutput("afile", newIOContext(random()));out.close();assertTrue(slowFileExists(fsDir, "afile"));expectThrows(IOException.class, () -> {- new SimpleFSDirectory(path.resolve("afile"));+ new NIOFSDirectory(path.resolve("afile"));});} finally {fsDir.close();diff --git a/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.javaindex f241cb4dab4..801c443d066 100644--- a/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java+++ b/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java@@ -99,8 +99,8 @@ public class TestFileSwitchDirectory extends BaseDirectoryTestCase {}private Directory newFSSwitchDirectory(Path aDir, Path bDir, Set<String> primaryExtensions) throws IOException {- Directory a = new SimpleFSDirectory(aDir);- Directory b = new SimpleFSDirectory(bDir);+ Directory a = new NIOFSDirectory(aDir);+ Directory b = new NIOFSDirectory(bDir);return new FileSwitchDirectory(primaryExtensions, a, b, true);}@@ -173,7 +173,7 @@ public class TestFileSwitchDirectory extends BaseDirectoryTestCase {FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));Path indexPath = new FilterPath(path, fs);try (final FileSwitchDirectory dir = new FileSwitchDirectory(Collections.singleton("tim"),- new SimpleFSDirectory(indexPath), new SimpleFSDirectory(indexPath), true)) {+ new NIOFSDirectory(indexPath), new NIOFSDirectory(indexPath), true)) {dir.createOutput("foo.tim", IOContext.DEFAULT).close();Function<String[], Long> stripExtra = array -> Arrays.asList(array).stream().filter(f -> f.startsWith("extra") == false).count();diff --git a/lucene/core/src/test/org/apache/lucene/store/TestSimpleFSDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestSimpleFSDirectory.javadeleted file mode 100644index 15a26a0efda..00000000000--- a/lucene/core/src/test/org/apache/lucene/store/TestSimpleFSDirectory.java+++ /dev/null@@ -1,85 +0,0 @@-/*- * 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.- */-package org.apache.lucene.store;---import java.io.IOException;-import java.net.URI;-import java.nio.file.FileSystem;-import java.nio.file.Path;--import org.apache.lucene.mockfile.FilterPath;-import org.apache.lucene.mockfile.WindowsFS;-import org.apache.lucene.util.Constants;-import org.apache.lucene.util.IOUtils;--/**- * Tests SimpleFSDirectory- */-public class TestSimpleFSDirectory extends BaseDirectoryTestCase {-- @Override- protected Directory getDirectory(Path path) throws IOException {- return new SimpleFSDirectory(path);- }-- public void testRenameWithPendingDeletes() throws IOException {- Path path = createTempDir();- // irony: currently we don't emulate windows well enough to work on windows!- assumeFalse("windows is not supported", Constants.WINDOWS);- // Use WindowsFS to prevent open files from being deleted:- FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));- Path root = new FilterPath(path, fs);- Directory directory = getDirectory(root);- IndexOutput output = directory.createOutput("target.txt", IOContext.DEFAULT);- output.writeInt(1);- output.close();- IndexOutput output1 = directory.createOutput("source.txt", IOContext.DEFAULT);- output1.writeInt(2);- output1.close();-- IndexInput input = directory.openInput("target.txt", IOContext.DEFAULT);- directory.deleteFile("target.txt");- directory.rename("source.txt", "target.txt");- IndexInput input1 = directory.openInput("target.txt", IOContext.DEFAULT);- assertTrue(directory.getPendingDeletions().isEmpty());- assertEquals(1, input.readInt());- assertEquals(2, input1.readInt());- IOUtils.close(input1, input, directory);- }-- public void testCreateOutputWithPendingDeletes() throws IOException {- // irony: currently we don't emulate windows well enough to work on windows!- assumeFalse("windows is not supported", Constants.WINDOWS);- Path path = createTempDir();- // Use WindowsFS to prevent open files from being deleted:- FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));- Path root = new FilterPath(path, fs);- Directory directory = getDirectory(root);- IndexOutput output = directory.createOutput("file.txt", IOContext.DEFAULT);- output.writeInt(1);- output.close();- IndexInput input = directory.openInput("file.txt", IOContext.DEFAULT);- directory.deleteFile("file.txt");- expectThrows(IOException.class, () -> {- directory.createOutput("file.txt", IOContext.DEFAULT);- });- assertTrue(directory.getPendingDeletions().isEmpty());- assertEquals(1, input.readInt());- IOUtils.close(input, directory);- }-}diff --git a/lucene/misc/src/java/org/apache/lucene/store/RAFDirectory.java b/lucene/misc/src/java/org/apache/lucene/store/RAFDirectory.javaindex 96963ae8883..cb5fc2dfc36 100644--- a/lucene/misc/src/java/org/apache/lucene/store/RAFDirectory.java+++ b/lucene/misc/src/java/org/apache/lucene/store/RAFDirectory.java@@ -51,7 +51,7 @@ public class RAFDirectory extends FSDirectory {path.toFile(); // throw exception if we can't get a File}- /** Create a new SimpleFSDirectory for the named location and {@link FSLockFactory#getDefault()}.+ /** Create a new RAFDirectory for the named location and {@link FSLockFactory#getDefault()}.* The directory is created at the named location if it does not yet exist.** @param path the path of the directorydiff --git a/lucene/misc/src/test/org/apache/lucene/store/TestHardLinkCopyDirectoryWrapper.java b/lucene/misc/src/test/org/apache/lucene/store/TestHardLinkCopyDirectoryWrapper.javaindex 4ae44e0df1b..1fc4ccfd191 100644--- a/lucene/misc/src/test/org/apache/lucene/store/TestHardLinkCopyDirectoryWrapper.java+++ b/lucene/misc/src/test/org/apache/lucene/store/TestHardLinkCopyDirectoryWrapper.java@@ -98,8 +98,8 @@ public class TestHardLinkCopyDirectoryWrapper extends BaseDirectoryTestCase {assumeFalse("windows is not supported", Constants.WINDOWS);Path path = createTempDir();FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));- Directory dir1 = new SimpleFSDirectory(new FilterPath(path, fs));- Directory dir2 = new SimpleFSDirectory(new FilterPath(path.resolve("link"), fs));+ Directory dir1 = new NIOFSDirectory(new FilterPath(path, fs));+ Directory dir2 = new NIOFSDirectory(new FilterPath(path.resolve("link"), fs));IndexOutput target = dir1.createOutput("target.txt", IOContext.DEFAULT);target.writeInt(1);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 c2846f65320..63018fe88bb 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@@ -483,10 +483,9 @@ public abstract class LuceneTestCase extends Assert {/** Filesystem-based {@link Directory} implementations. */private static final List<String> FS_DIRECTORIES = Arrays.asList(- "SimpleFSDirectory","NIOFSDirectory",- // SimpleFSDirectory as replacement for MMapDirectory if unmapping is not supported on Windows (to make randomization stable):- hasWorkingMMapOnWindows() ? "MMapDirectory" : "SimpleFSDirectory"+ // NIOFSDirectory as replacement for MMapDirectory if unmapping is not supported on Windows (to make randomization stable):+ hasWorkingMMapOnWindows() ? "MMapDirectory" : "NIOFSDirectory");/** All {@link Directory} implementations. */diff --git a/solr/core/src/java/org/apache/solr/core/SimpleFSDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/SimpleFSDirectoryFactory.javadeleted file mode 100644index 0784d21c4e3..00000000000--- a/solr/core/src/java/org/apache/solr/core/SimpleFSDirectoryFactory.java+++ /dev/null@@ -1,42 +0,0 @@-/*- * 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.- */-package org.apache.solr.core;-import java.io.File;-import java.io.IOException;--import org.apache.lucene.store.Directory;-import org.apache.lucene.store.LockFactory;-import org.apache.lucene.store.SimpleFSDirectory;---/**- * Factory to instantiate {@link org.apache.lucene.store.SimpleFSDirectory}- *- **/-public class SimpleFSDirectoryFactory extends StandardDirectoryFactory {-- @Override- protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {- // we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:- return new SimpleFSDirectory(new File(path).toPath(), lockFactory);- }-- @Override- public boolean isAbsolute(String path) {- return new File(path).isAbsolute();- }-}diff --git a/solr/core/src/java/org/apache/solr/core/backup/repository/LocalFileSystemRepository.java b/solr/core/src/java/org/apache/solr/core/backup/repository/LocalFileSystemRepository.javaindex 01810f6f8a8..2379b0dd7be 100644--- a/solr/core/src/java/org/apache/solr/core/backup/repository/LocalFileSystemRepository.java+++ b/solr/core/src/java/org/apache/solr/core/backup/repository/LocalFileSystemRepository.java@@ -33,8 +33,8 @@ import org.apache.lucene.store.Directory;import org.apache.lucene.store.FSDirectory;import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexInput;+import org.apache.lucene.store.NIOFSDirectory;import org.apache.lucene.store.NoLockFactory;-import org.apache.lucene.store.SimpleFSDirectory;import org.apache.solr.common.util.NamedList;import org.apache.solr.core.DirectoryFactory;@@ -117,7 +117,7 @@ public class LocalFileSystemRepository implements BackupRepository {@Overridepublic IndexInput openInput(URI dirPath, String fileName, IOContext ctx) throws IOException {- try (FSDirectory dir = new SimpleFSDirectory(Paths.get(dirPath), NoLockFactory.INSTANCE)) {+ try (FSDirectory dir = new NIOFSDirectory(Paths.get(dirPath), NoLockFactory.INSTANCE)) {return dir.openInput(fileName, ctx);}}@@ -129,7 +129,7 @@ public class LocalFileSystemRepository implements BackupRepository {@Overridepublic String[] listAll(URI dirPath) throws IOException {- try (FSDirectory dir = new SimpleFSDirectory(Paths.get(dirPath), NoLockFactory.INSTANCE)) {+ try (FSDirectory dir = new NIOFSDirectory(Paths.get(dirPath), NoLockFactory.INSTANCE)) {return dir.listAll();}}@@ -141,14 +141,14 @@ public class LocalFileSystemRepository implements BackupRepository {@Overridepublic void copyFileFrom(Directory sourceDir, String fileName, URI dest) throws IOException {- try (FSDirectory dir = new SimpleFSDirectory(Paths.get(dest), NoLockFactory.INSTANCE)) {+ try (FSDirectory dir = new NIOFSDirectory(Paths.get(dest), NoLockFactory.INSTANCE)) {dir.copyFrom(sourceDir, fileName, fileName, DirectoryFactory.IOCONTEXT_NO_CACHE);}}@Overridepublic void copyFileTo(URI sourceDir, String fileName, Directory dest) throws IOException {- try (FSDirectory dir = new SimpleFSDirectory(Paths.get(sourceDir), NoLockFactory.INSTANCE)) {+ try (FSDirectory dir = new NIOFSDirectory(Paths.get(sourceDir), NoLockFactory.INSTANCE)) {dest.copyFrom(dir, fileName, fileName, DirectoryFactory.IOCONTEXT_NO_CACHE);}}diff --git a/solr/core/src/test/org/apache/solr/core/SolrCoreCheckLockOnStartupTest.java b/solr/core/src/test/org/apache/solr/core/SolrCoreCheckLockOnStartupTest.javaindex e1e43dea811..1156aad6725 100644--- a/solr/core/src/test/org/apache/solr/core/SolrCoreCheckLockOnStartupTest.java+++ b/solr/core/src/test/org/apache/solr/core/SolrCoreCheckLockOnStartupTest.java@@ -42,7 +42,7 @@ public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 {public void setUp() throws Exception {super.setUp();- System.setProperty("solr.directoryFactory", "org.apache.solr.core.SimpleFSDirectoryFactory");+ System.setProperty("solr.directoryFactory", "org.apache.solr.core.NIOFSDirectoryFactory");// test tests native and simple in the same jvm in the same exact directory:// the file will remain after the native test (it cannot safely be deleted without the risk of deleting another guys lock)// it's ok, these aren't "compatible" anyway: really this test should not re-use the same directory at all.diff --git a/solr/core/src/test/org/apache/solr/core/TestDirectoryFactory.java b/solr/core/src/test/org/apache/solr/core/TestDirectoryFactory.javaindex 72b02b3ac4a..6496b24247e 100644--- a/solr/core/src/test/org/apache/solr/core/TestDirectoryFactory.java+++ b/solr/core/src/test/org/apache/solr/core/TestDirectoryFactory.java@@ -45,7 +45,6 @@ public class TestDirectoryFactory extends SolrTestCaseJ4 {NRTCachingDirectoryFactory.class,NIOFSDirectoryFactory.class,RAMDirectoryFactory.class,- SimpleFSDirectoryFactory.class,StandardDirectoryFactory.class);/* Test that MockDirectoryFactory's exist method behaves consistent w/other impls */diff --git a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.javaindex b17e212444e..e2be8f9da5b 100644--- a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java+++ b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java@@ -29,7 +29,8 @@ import java.util.Optional;import org.apache.lucene.index.DirectoryReader;import org.apache.lucene.index.IndexCommit;import org.apache.lucene.index.IndexNotFoundException;-import org.apache.lucene.store.SimpleFSDirectory;+import org.apache.lucene.store.Directory;+import org.apache.lucene.store.NIOFSDirectory;import org.apache.lucene.util.LuceneTestCase.Slow;import org.apache.lucene.util.TestUtil;import org.apache.solr.SolrTestCaseJ4;@@ -299,7 +300,7 @@ public class TestSolrCoreSnapshots extends SolrCloudTestCase {}private List<IndexCommit> listCommits(String directory) throws Exception {- SimpleFSDirectory dir = new SimpleFSDirectory(Paths.get(directory));+ Directory dir = new NIOFSDirectory(Paths.get(directory));try {return DirectoryReader.listCommits(dir);} catch (IndexNotFoundException ex) {diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.javaindex 6f99201ac5d..8cc19d05523 100644--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java@@ -44,7 +44,7 @@ import org.apache.lucene.index.DirectoryReader;import org.apache.lucene.index.IndexReader;import org.apache.lucene.store.Directory;import org.apache.lucene.store.FSDirectory;-import org.apache.lucene.store.SimpleFSDirectory;+import org.apache.lucene.store.NIOFSDirectory;import org.apache.lucene.util.Constants;import org.apache.lucene.util.LuceneTestCase.Slow;import org.apache.lucene.util.TestUtil;@@ -1624,7 +1624,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {// confirm backups really are emptyfor (int i = 1; i <=2; i++) {final String name = "snapshot.empty_backup"+i;- try (Directory dir = new SimpleFSDirectory(new File(backupDir, name).toPath());+ try (Directory dir = new NIOFSDirectory(new File(backupDir, name).toPath());IndexReader reader = DirectoryReader.open(dir)) {assertEquals(name + " is not empty", 0, reader.numDocs());}diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.javaindex 68bf77c026c..420c7c85960 100644--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java@@ -37,7 +37,7 @@ import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.MatchAllDocsQuery;import org.apache.lucene.search.TopDocs;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.SimpleFSDirectory;+import org.apache.lucene.store.NIOFSDirectory;import org.apache.lucene.util.TestUtil;import org.apache.solr.SolrJettyTestBase;import org.apache.solr.SolrTestCaseJ4;@@ -146,8 +146,8 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {private void verify(Path backup, int nDocs) throws IOException {log.info("Verifying ndocs={} in {}", nDocs, backup);- try (Directory dir = new SimpleFSDirectory(backup);- IndexReader reader = DirectoryReader.open(dir)) {+ try (Directory dir = new NIOFSDirectory(backup);+ IndexReader reader = DirectoryReader.open(dir)) {IndexSearcher searcher = new IndexSearcher(reader);TopDocs hits = searcher.search(new MatchAllDocsQuery(), 1);assertEquals(nDocs, hits.totalHits.value);diff --git a/solr/example/example-DIH/solr/db/conf/solrconfig.xml b/solr/example/example-DIH/solr/db/conf/solrconfig.xmlindex a88b39d8519..11270930681 100644--- a/solr/example/example-DIH/solr/db/conf/solrconfig.xml+++ b/solr/example/example-DIH/solr/db/conf/solrconfig.xml@@ -109,8 +109,8 @@wraps solr.StandardDirectoryFactory and caches small files in memoryfor better NRT performance.- One can force a particular implementation via solr.MMapDirectoryFactory,- solr.NIOFSDirectoryFactory, or solr.SimpleFSDirectoryFactory.+ One can force a particular implementation via solr.MMapDirectoryFactory+ or solr.NIOFSDirectoryFactory.solr.RAMDirectoryFactory is memory based and not persistent.-->diff --git a/solr/example/example-DIH/solr/mail/conf/solrconfig.xml b/solr/example/example-DIH/solr/mail/conf/solrconfig.xmlindex 3582ecbffe6..91b99573539 100644--- a/solr/example/example-DIH/solr/mail/conf/solrconfig.xml+++ b/solr/example/example-DIH/solr/mail/conf/solrconfig.xml@@ -112,8 +112,8 @@wraps solr.StandardDirectoryFactory and caches small files in memoryfor better NRT performance.- One can force a particular implementation via solr.MMapDirectoryFactory,- solr.NIOFSDirectoryFactory, or solr.SimpleFSDirectoryFactory.+ One can force a particular implementation via solr.MMapDirectoryFactory+ or solr.NIOFSDirectoryFactory.solr.RAMDirectoryFactory is memory based and not persistent.-->diff --git a/solr/example/example-DIH/solr/solr/conf/solrconfig.xml b/solr/example/example-DIH/solr/solr/conf/solrconfig.xmlindex 81e8451e202..56e7ed68f1e 100644--- a/solr/example/example-DIH/solr/solr/conf/solrconfig.xml+++ b/solr/example/example-DIH/solr/solr/conf/solrconfig.xml@@ -109,8 +109,8 @@wraps solr.StandardDirectoryFactory and caches small files in memoryfor better NRT performance.- One can force a particular implementation via solr.MMapDirectoryFactory,- solr.NIOFSDirectoryFactory, or solr.SimpleFSDirectoryFactory.+ One can force a particular implementation via solr.MMapDirectoryFactory+ or solr.NIOFSDirectoryFactory.solr.RAMDirectoryFactory is memory based and not persistent.-->diff --git a/solr/example/files/conf/solrconfig.xml b/solr/example/files/conf/solrconfig.xmlindex 7c7a58d81b9..d16d4bf8557 100644--- a/solr/example/files/conf/solrconfig.xml+++ b/solr/example/files/conf/solrconfig.xml@@ -111,8 +111,8 @@wraps solr.StandardDirectoryFactory and caches small files in memoryfor better NRT performance.- One can force a particular implementation via solr.MMapDirectoryFactory,- solr.NIOFSDirectoryFactory, or solr.SimpleFSDirectoryFactory.+ One can force a particular implementation via solr.MMapDirectoryFactory+ or solr.NIOFSDirectoryFactory.solr.RAMDirectoryFactory is memory based and not persistent.-->diff --git a/solr/server/solr/configsets/_default/conf/solrconfig.xml b/solr/server/solr/configsets/_default/conf/solrconfig.xmlindex 548d2c53fee..db0e9068ecc 100644--- a/solr/server/solr/configsets/_default/conf/solrconfig.xml+++ b/solr/server/solr/configsets/_default/conf/solrconfig.xml@@ -100,8 +100,8 @@wraps solr.StandardDirectoryFactory and caches small files in memoryfor better NRT performance.- One can force a particular implementation via solr.MMapDirectoryFactory,- solr.NIOFSDirectoryFactory, or solr.SimpleFSDirectoryFactory.+ One can force a particular implementation via solr.MMapDirectoryFactory+ or solr.NIOFSDirectoryFactory.solr.RAMDirectoryFactory is memory based and not persistent.-->diff --git a/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml b/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xmlindex 98f75950b25..554a82e0bff 100644--- a/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml+++ b/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml@@ -112,8 +112,8 @@wraps solr.StandardDirectoryFactory and caches small files in memoryfor better NRT performance.- One can force a particular implementation via solr.MMapDirectoryFactory,- solr.NIOFSDirectoryFactory, or solr.SimpleFSDirectoryFactory.+ One can force a particular implementation via solr.MMapDirectoryFactory+ or solr.NIOFSDirectoryFactory.solr.RAMDirectoryFactory is memory based and not persistent.-->diff --git a/solr/solr-ref-guide/src/datadir-and-directoryfactory-in-solrconfig.adoc b/solr/solr-ref-guide/src/datadir-and-directoryfactory-in-solrconfig.adocindex 0af9374de25..aa6d3c42fd2 100644--- a/solr/solr-ref-guide/src/datadir-and-directoryfactory-in-solrconfig.adoc+++ b/solr/solr-ref-guide/src/datadir-and-directoryfactory-in-solrconfig.adoc@@ -36,7 +36,7 @@ element `<solrDataHome>` then the location of data directory will be `<SOLR_DATA== Specifying the DirectoryFactory For Your Index-The default {solr-javadocs}/solr-core/org/apache/solr/core/NRTCachingDirectoryFactory.html[`solr.NRTCachingDirectoryFactory`] is filesystem based, and tries to pick the best implementation for the current JVM and platform. You can force a particular implementation and/or configuration options by specifying {solr-javadocs}/solr-core/org/apache/solr/core/MMapDirectoryFactory.html[`solr.MMapDirectoryFactory`], {solr-javadocs}/solr-core/org/apache/solr/core/NIOFSDirectoryFactory.html[`solr.NIOFSDirectoryFactory`], or {solr-javadocs}/solr-core/org/apache/solr/core/SimpleFSDirectoryFactory.html[`solr.SimpleFSDirectoryFactory`].+The default {solr-javadocs}/solr-core/org/apache/solr/core/NRTCachingDirectoryFactory.html[`solr.NRTCachingDirectoryFactory`] is filesystem based, and tries to pick the best implementation for the current JVM and platform. You can force a particular implementation and/or configuration options by specifying {solr-javadocs}/solr-core/org/apache/solr/core/MMapDirectoryFactory.html[`solr.MMapDirectoryFactory`] or {solr-javadocs}/solr-core/org/apache/solr/core/NIOFSDirectoryFactory.html[`solr.NIOFSDirectoryFactory`].[source,xml]----