Class MMapDirectory
File-based Directory implementation that uses mmap for reading, and SimpleFSDirectory.SimpleFSIndexOutput for writing.
NOTE: memory mapping uses up a portion of the virtual memory address space in your process equal to the size of the file being mapped. Before using this class, be sure your have plenty of virtual address space, e.g. by using a 64 bit JRE, or a 32 bit JRE with indexes that are guaranteed to fit within the address space. On 32 bit platforms also consult MaxChunkSize if you have problems with mmap failing because of fragmented address space. If you get an OutOfMemoryException, it is recommened to reduce the chunk size, until it works.
Due to this bug in Sun's JRE, MMapDirectory's Close() is unable to close the underlying OS file handle. Only when GC finally collects the underlying objects, which could be quite some time later, will the file handle be closed.
This will consume additional transient disk usage: on Windows, attempts to delete or overwrite the files will result in an exception; on other platforms, which typically have a "delete on last close" semantics, while such operations will succeed, the bytes are still consuming space on disk. For many applications this limitation is not a problem (e.g. if you have plenty of disk space, and you don't rely on overwriting files on Windows) but it's still an important limitation to be aware of.
This class supplies the workaround mentioned in the bug report
(disabled by default, see UseUnmap), which may fail on
non-Sun JVMs. It forcefully unmaps the buffer on close by using
an undocumented internal cleanup functionality.
UNMAP_SUPPORTED is true
, if the workaround
can be enabled (with no guarantees).
Inherited Members
Namespace:
Assembly: Lucene.Net.NetCore.dll
Syntax
public class MMapDirectory : FSDirectory
Constructors
Name | Description |
---|---|
MMapDirectory(IO.DirectoryInfo) | Create a new MMapDirectory for the named location and the default lock factory. |
MMapDirectory(IO.DirectoryInfo, LockFactory) | Create a new MMapDirectory for the named location. |
Fields
Name | Description |
---|---|
UNMAP_SUPPORTED |
|
Properties
Name | Description |
---|---|
MaxChunkSize | Gets or sets the maximum chunk size (default is |
UseUnmap | Enables or disables the workaround for unmapping the buffers from address space after closing IndexInput, that is mentioned in the bug report. This hack may fail on non-Sun JVMs. It forcefully unmaps the buffer on close by using an undocumented internal cleanup functionality. NOTE: Enabling this is completely unsupported
by Java and may lead to JVM crashs if |
Methods
Name | Description |
---|---|
CreateOutput(String) | Creates an IndexOutput for the file with the given name. |
OpenInput(String, Int32) | Creates an IndexInput for the file with the given name. |