Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
Classes | Public Member Functions | Static Public Attributes | Properties | List of all members
Lucene.Net.Store.MMapDirectory Class Reference

File-based Directory implementation that uses mmap for reading, and SimpleFSDirectory.SimpleFSIndexOutput for writing. More...

Inherits Lucene.Net.Store.FSDirectory.

Classes

class  MultiMMapIndexInput
 

Public Member Functions

 MMapDirectory (System.IO.DirectoryInfo path, LockFactory lockFactory)
 Create a new MMapDirectory for the named location.
 
 MMapDirectory (System.IO.DirectoryInfo path)
 Create a new MMapDirectory for the named location and the default lock factory.
 
override IndexInput OpenInput (System.String name, int bufferSize)
 Creates an IndexInput for the file with the given name.
 
override IndexOutput CreateOutput (System.String name)
 Creates an IndexOutput for the file with the given name.
 
- Public Member Functions inherited from Lucene.Net.Store.FSDirectory
override System.String[] ListAll ()
 Lists all files (not subdirectories) in the directory.
 
override bool FileExists (System.String name)
 Returns true iff a file with the given name exists.
 
override long FileModified (System.String name)
 Returns the time the named file was last modified.
 
override void TouchFile (System.String name)
 Set the modified time of an existing file to now.
 
override long FileLength (System.String name)
 Returns the length in bytes of a file in the directory.
 
override void DeleteFile (System.String name)
 Removes an existing file in the directory.
 
override void Sync (System.String name)
 Ensure that any writes to this file are moved to stable storage. Lucene uses this to properly commit changes to the index, to prevent a machine/OS crash from corrupting the index.
 
override IndexInput OpenInput (System.String name)
 Returns a stream reading an existing file.
 
override string GetLockId ()
 Return a string identifier that uniquely differentiates this Directory instance from other Directory instances. This ID should be the same if two Directory instances (even in different JVMs and/or on different machines) are considered "the same index". This is how locking "scopes" to the right index.
 
override System.String ToString ()
 For debug output.
 
- Public Member Functions inherited from Lucene.Net.Store.Directory
virtual Lock MakeLock (System.String name)
 Construct a Lock.
 
virtual void ClearLock (System.String name)
 Attempt to clear (forcefully unlock and remove) the specified lock. Only call this at a time when you are certain this lock is no longer in use.
 
void Close ()
 
void Dispose ()
 Closes the store.
 
virtual void SetLockFactory (LockFactory lockFactory)
 Set the LockFactory that this Directory instance should use for its locking implementation. Each * instance of LockFactory should only be used for one directory (ie, do not share a single instance across multiple Directories).
 
override string ToString ()
 
void EnsureOpen ()
 <throws> AlreadyClosedException if this Directory is closed </throws>
 

Static Public Attributes

static bool UNMAP_SUPPORTED
 true, if this platform supports unmapping mmaped files.
 
- Static Public Attributes inherited from Lucene.Net.Store.FSDirectory
static readonly int DEFAULT_READ_CHUNK_SIZE = Constants.JRE_IS_64BIT ? int.MaxValue: 100 * 1024 * 1024
 Default read chunk size. This is a conditional default: on 32bit JVMs, it defaults to 100 MB. On 64bit JVMs, it's Integer.MAX_VALUE.
 

Properties

virtual bool UseUnmap [get, set]
 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 IndexInput is closed while another thread is still accessing it (SIGSEGV).
 
virtual int MaxChunkSize [get, set]
 Gets or sets the maximum chunk size (default is int.MaxValue for 64 bit JVMs and 256 MiBytes for 32 bit JVMs) used for memory mapping. Especially on 32 bit platform, the address space can be very fragmented, so large index files cannot be mapped. Using a lower chunk size makes the directory implementation a little bit slower (as the correct chunk must be resolved on each seek) but the chance is higher that mmap does not fail. On 64 bit Java platforms, this parameter should always be int.MaxValue, as the adress space is big enough.
 
- Properties inherited from Lucene.Net.Store.FSDirectory
virtual DirectoryInfo Directory [get]
 
int ReadChunkSize [get, set]
 The maximum number of bytes to read at once from the underlying file during IndexInput.ReadBytes(byte[],int,int).
 
- Properties inherited from Lucene.Net.Store.Directory
virtual LockFactory LockFactory [get]
 Get the LockFactory that this Directory instance is using for its locking implementation. Note that this may be null for Directory implementations that provide their own locking implementation.
 
bool isOpen_ForNUnit [get]
 

Additional Inherited Members

- Static Public Member Functions inherited from Lucene.Net.Store.FSDirectory
static FSDirectory Open (string path)
 Creates an FSDirectory instance, trying to pick the best implementation given the current environment. The directory returned uses the NativeFSLockFactory.
 
static FSDirectory Open (System.IO.DirectoryInfo path)
 Creates an FSDirectory instance, trying to pick the best implementation given the current environment. The directory returned uses the NativeFSLockFactory.
 
static FSDirectory Open (System.IO.DirectoryInfo path, LockFactory lockFactory)
 Just like Open(System.IO.DirectoryInfo), but allows you to also specify a custom LockFactory.
 
static System.String[] ListAll (System.IO.DirectoryInfo dir)
 Lists all files (not subdirectories) in the directory. This method never returns null (throws System.IO.IOException instead).
 
static long FileModified (System.IO.FileInfo directory, System.String name)
 Returns the time the named file was last modified.
 
- Protected Member Functions inherited from Lucene.Net.Store.FSDirectory
override void Dispose (bool disposing)
 

Detailed Description

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 IndexInput.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).

Definition at line 62 of file MMapDirectory.cs.

Constructor & Destructor Documentation

Lucene.Net.Store.MMapDirectory.MMapDirectory ( System.IO.DirectoryInfo  path,
LockFactory  lockFactory 
)

Create a new MMapDirectory for the named location.

Parameters
paththe path of the directory
lockFactorythe lock factory to use, or null for the default.

<throws> IOException </throws>

Definition at line 116 of file MMapDirectory.cs.

Lucene.Net.Store.MMapDirectory.MMapDirectory ( System.IO.DirectoryInfo  path)

Create a new MMapDirectory for the named location and the default lock factory.

Parameters
paththe path of the directory

<throws> IOException </throws>

Definition at line 128 of file MMapDirectory.cs.

Member Function Documentation

override IndexOutput Lucene.Net.Store.MMapDirectory.CreateOutput ( System.String  name)
virtual

Creates an IndexOutput for the file with the given name.

Implements Lucene.Net.Store.Directory.

Definition at line 506 of file MMapDirectory.cs.

override IndexInput Lucene.Net.Store.MMapDirectory.OpenInput ( System.String  name,
int  bufferSize 
)
virtual

Creates an IndexInput for the file with the given name.

Reimplemented from Lucene.Net.Store.Directory.

Definition at line 490 of file MMapDirectory.cs.

Member Data Documentation

bool Lucene.Net.Store.MMapDirectory.UNMAP_SUPPORTED
static

true, if this platform supports unmapping mmaped files.

Definition at line 138 of file MMapDirectory.cs.

Property Documentation

virtual int Lucene.Net.Store.MMapDirectory.MaxChunkSize
getset

Gets or sets the maximum chunk size (default is int.MaxValue for 64 bit JVMs and 256 MiBytes for 32 bit JVMs) used for memory mapping. Especially on 32 bit platform, the address space can be very fragmented, so large index files cannot be mapped. Using a lower chunk size makes the directory implementation a little bit slower (as the correct chunk must be resolved on each seek) but the chance is higher that mmap does not fail. On 64 bit Java platforms, this parameter should always be int.MaxValue, as the adress space is big enough.

Definition at line 197 of file MMapDirectory.cs.

virtual bool Lucene.Net.Store.MMapDirectory.UseUnmap
getset

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 IndexInput is closed while another thread is still accessing it (SIGSEGV).

<throws> IllegalArgumentException if UNMAP_SUPPORTED </throws>

is false and the workaround cannot be enabled.

Definition at line 153 of file MMapDirectory.cs.


The documentation for this class was generated from the following file: