org.apache.lucene.store

## Class NativeUnixDirectory

- java.lang.Object
- - org.apache.lucene.store.Directory
  - - org.apache.lucene.store.FSDirectory
    - - org.apache.lucene.store.NativeUnixDirectory

All Implemented Interfaces:
  Closeable, AutoCloseable

    public class NativeUnixDirectory
    extends FSDirectory

A `Directory` 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 resulting `libNativePosixUtil.so` (from `lucene/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.

WARNING: This API is experimental and might change in incompatible ways in the next release.

### Nested Class Summary

### Nested classes/interfaces inherited from class org.apache.lucene.store.FSDirectory

`FSDirectory.FSIndexInput, FSDirectory.FSIndexOutput`

### Nested classes/interfaces inherited from class org.apache.lucene.store.Directory

`Directory.IndexInputSlicer`

### Field Summary

Fields
`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):

### Fields inherited from class org.apache.lucene.store.FSDirectory

`DEFAULT_READ_CHUNK_SIZE, directory, staleFiles`

### Fields inherited from class org.apache.lucene.store.Directory

`isOpen, lockFactory`

### Constructor Summary

Constructors
Constructor and Description
`NativeUnixDirectory(File path, Directory delegate)` Create a new NIOFSDirectory for the named location.
`NativeUnixDirectory(File path, int mergeBufferSize, long minBytesDirect, Directory delegate)` Create a new NIOFSDirectory for the named location.

### Method Summary

Methods
`IndexOutput` `createOutput(String name, IOContext context)`
`IndexInput` `openInput(String name, IOContext context)`

### Methods inherited from class org.apache.lucene.store.FSDirectory

`close, deleteFile, ensureCanWrite, fileExists, fileLength, fileModified, fsync, getDirectory, getLockID, getReadChunkSize, listAll, listAll, onIndexOutputClosed, open, open, setLockFactory, setReadChunkSize, sync, toString`

### Methods inherited from class org.apache.lucene.store.Directory

`clearLock, copy, createSlicer, ensureOpen, getLockFactory, makeLock`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### 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

### Constructor Detail

#### NativeUnixDirectory

    public NativeUnixDirectory(File path,
                       int mergeBufferSize,
                       long minBytesDirect,
                       Directory delegate)
                        throws IOException

Create a new NIOFSDirectory for the named location.

Parameters:
  `path` - the path of the directory
  `mergeBufferSize` - Size of buffer to use for merging. See `DEFAULT_MERGE_BUFFER_SIZE`.
  `minBytesDirect` - Merges, or files to be opened for reading, smaller than this will not use direct IO. See `DEFAULT_MIN_BYTES_DIRECT`
  `delegate` - fallback Directory for non-merges
Throws:
  `IOException` - If there is a low-level I/O error

#### NativeUnixDirectory

    public NativeUnixDirectory(File path,
                       Directory delegate)
                        throws IOException

Create a new NIOFSDirectory for the named location.

Parameters:
  `path` - the path of the directory
  `delegate` - fallback Directory for non-merges
Throws:
  `IOException` - If there is a low-level I/O error

### Method Detail

#### openInput

    public IndexInput openInput(String name,
                       IOContext context)
                         throws IOException

Specified by:
  `openInput` in class `Directory`
Throws:
  `IOException`

#### createOutput

    public IndexOutput createOutput(String name,
                           IOContext context)
                             throws IOException

Overrides:
  `createOutput` in class `FSDirectory`
Throws:
  `IOException`