mirror of https://github.com/apache/lucene.git
Remove SimpleFSDirectory in favor of NIOFSDirectory
This commit is contained in:
parent
a030207a5e
commit
8a88dd02c6
|
@ -44,6 +44,9 @@ API Changes
|
|||
* LUCENE-9212: Deprecated Intervals.multiterm() methods that take a bare Automaton
|
||||
have 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 across
|
||||
|
|
|
@ -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 auto
|
||||
try (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 field
|
||||
Map<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);
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 + "...");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 auto
|
||||
try (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 field
|
||||
Map<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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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-1468
|
||||
public 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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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 directory
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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 {
|
|||
|
||||
@Override
|
||||
public 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 {
|
|||
|
||||
@Override
|
||||
public 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 {
|
|||
|
||||
@Override
|
||||
public 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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 empty
|
||||
for (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());
|
||||
}
|
||||
|
|
|
@ -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,7 +146,7 @@ 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);
|
||||
try (Directory dir = new NIOFSDirectory(backup);
|
||||
IndexReader reader = DirectoryReader.open(dir)) {
|
||||
IndexSearcher searcher = new IndexSearcher(reader);
|
||||
TopDocs hits = searcher.search(new MatchAllDocsQuery(), 1);
|
||||
|
|
|
@ -109,8 +109,8 @@
|
|||
wraps solr.StandardDirectoryFactory and caches small files in memory
|
||||
for 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.
|
||||
-->
|
||||
|
|
|
@ -112,8 +112,8 @@
|
|||
wraps solr.StandardDirectoryFactory and caches small files in memory
|
||||
for 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.
|
||||
-->
|
||||
|
|
|
@ -109,8 +109,8 @@
|
|||
wraps solr.StandardDirectoryFactory and caches small files in memory
|
||||
for 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.
|
||||
-->
|
||||
|
|
|
@ -111,8 +111,8 @@
|
|||
wraps solr.StandardDirectoryFactory and caches small files in memory
|
||||
for 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.
|
||||
-->
|
||||
|
|
|
@ -100,8 +100,8 @@
|
|||
wraps solr.StandardDirectoryFactory and caches small files in memory
|
||||
for 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.
|
||||
-->
|
||||
|
|
|
@ -112,8 +112,8 @@
|
|||
wraps solr.StandardDirectoryFactory and caches small files in memory
|
||||
for 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.
|
||||
-->
|
||||
|
|
|
@ -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]
|
||||
----
|
||||
|
|
Loading…
Reference in New Issue