Class NativeUnixDirectory
- java.lang.Object
-
- org.apache.lucene.store.Directory
-
- org.apache.lucene.store.BaseDirectory
-
- org.apache.lucene.store.FSDirectory
-
- org.apache.lucene.store.NativeUnixDirectory
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class NativeUnixDirectory extends FSDirectory
ADirectory
implementation for all Unixes that uses DIRECT I/O to bypass OS level IO caching during merging. For all other cases (searching, writing) we delegate to the provided Directory instance.See Overview for more details.
To use this you must compile NativePosixUtil.cpp (exposes Linux-specific APIs through JNI) for your platform, by running
ant build-native-unix
, and then putting the resultinglibNativePosixUtil.so
(fromlucene/build/native
) onto your dynamic linker search path.WARNING: this code is very new and quite easily could contain horrible bugs. For example, here's one known issue: if you use seek in
IndexOutput
, and then write more than one buffer's worth of bytes, then the file will be wrong. Lucene does not do this today (only writes small number of bytes after seek), but that may change.This directory passes Solr and Lucene tests on Linux and OS X; other Unixes should work but have not been tested! Use at your own risk.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
NativeUnixDirectory.NativeUnixIndexInput
private static class
NativeUnixDirectory.NativeUnixIndexOutput
-
Nested classes/interfaces inherited from class org.apache.lucene.store.FSDirectory
FSDirectory.FSIndexOutput
-
-
Field Summary
Fields Modifier and Type Field Description private static long
ALIGN
private static long
ALIGN_NOT_MASK
static int
DEFAULT_MERGE_BUFFER_SIZE
Default buffer size before writing to disk (256 KB); larger means less IO load but more RAM and direct buffer storage space consumed during merging.static long
DEFAULT_MIN_BYTES_DIRECT
Default min expected merge size before direct IO is used (10 MB):private Directory
delegate
private int
mergeBufferSize
private long
minBytesDirect
-
Fields inherited from class org.apache.lucene.store.FSDirectory
directory
-
Fields inherited from class org.apache.lucene.store.BaseDirectory
isOpen, lockFactory
-
-
Constructor Summary
Constructors Constructor Description NativeUnixDirectory(java.nio.file.Path path, int mergeBufferSize, long minBytesDirect, LockFactory lockFactory, Directory delegate)
Create a new NIOFSDirectory for the named location.NativeUnixDirectory(java.nio.file.Path path, Directory delegate)
Create a new NIOFSDirectory for the named location withFSLockFactory.getDefault()
.NativeUnixDirectory(java.nio.file.Path path, LockFactory lockFactory, Directory delegate)
Create a new NIOFSDirectory for the named location.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IndexOutput
createOutput(java.lang.String name, IOContext context)
Creates a new, empty file in the directory and returns anIndexOutput
instance for appending data to this file.IndexInput
openInput(java.lang.String name, IOContext context)
Opens a stream for reading an existing file.-
Methods inherited from class org.apache.lucene.store.FSDirectory
close, createTempOutput, deleteFile, deletePendingFiles, ensureCanRead, fileLength, fsync, getDirectory, getPendingDeletions, listAll, listAll, open, open, rename, sync, syncMetaData, toString
-
Methods inherited from class org.apache.lucene.store.BaseDirectory
ensureOpen, obtainLock
-
Methods inherited from class org.apache.lucene.store.Directory
copyFrom, getTempFileName, openChecksumInput
-
-
-
-
Field Detail
-
ALIGN
private static final long ALIGN
- See Also:
- Constant Field Values
-
ALIGN_NOT_MASK
private static final long ALIGN_NOT_MASK
- See Also:
- Constant Field Values
-
DEFAULT_MERGE_BUFFER_SIZE
public static final int DEFAULT_MERGE_BUFFER_SIZE
Default buffer size before writing to disk (256 KB); larger means less IO load but more RAM and direct buffer storage space consumed during merging.- See Also:
- Constant Field Values
-
DEFAULT_MIN_BYTES_DIRECT
public static final long DEFAULT_MIN_BYTES_DIRECT
Default min expected merge size before direct IO is used (10 MB):- See Also:
- Constant Field Values
-
mergeBufferSize
private final int mergeBufferSize
-
minBytesDirect
private final long minBytesDirect
-
delegate
private final Directory delegate
-
-
Constructor Detail
-
NativeUnixDirectory
public NativeUnixDirectory(java.nio.file.Path path, int mergeBufferSize, long minBytesDirect, LockFactory lockFactory, Directory delegate) throws java.io.IOException
Create a new NIOFSDirectory for the named location.- Parameters:
path
- the path of the directorylockFactory
- to usemergeBufferSize
- Size of buffer to use for merging. SeeDEFAULT_MERGE_BUFFER_SIZE
.minBytesDirect
- Merges, or files to be opened for reading, smaller than this will not use direct IO. SeeDEFAULT_MIN_BYTES_DIRECT
delegate
- fallback Directory for non-merges- Throws:
java.io.IOException
- If there is a low-level I/O error
-
NativeUnixDirectory
public NativeUnixDirectory(java.nio.file.Path path, LockFactory lockFactory, Directory delegate) throws java.io.IOException
Create a new NIOFSDirectory for the named location.- Parameters:
path
- the path of the directorylockFactory
- the lock factory to usedelegate
- fallback Directory for non-merges- Throws:
java.io.IOException
- If there is a low-level I/O error
-
NativeUnixDirectory
public NativeUnixDirectory(java.nio.file.Path path, Directory delegate) throws java.io.IOException
Create a new NIOFSDirectory for the named location withFSLockFactory.getDefault()
.- Parameters:
path
- the path of the directorydelegate
- fallback Directory for non-merges- Throws:
java.io.IOException
- If there is a low-level I/O error
-
-
Method Detail
-
openInput
public IndexInput openInput(java.lang.String name, IOContext context) throws java.io.IOException
Description copied from class:Directory
Opens a stream for reading an existing file. This method must throw eitherNoSuchFileException
orFileNotFoundException
ifname
points to a non-existing file.
-
createOutput
public IndexOutput createOutput(java.lang.String name, IOContext context) throws java.io.IOException
Description copied from class:Directory
Creates a new, empty file in the directory and returns anIndexOutput
instance for appending data to this file. This method must throwFileAlreadyExistsException
if the file already exists.- Overrides:
createOutput
in classFSDirectory
- Parameters:
name
- the name of the file to create.- Throws:
java.io.IOException
- in case of I/O error
-
-