C# Class Lucene.Net.Store.FSDirectory

Base class for Directory implementations that store index files in the file system. There are currently three core subclasses: SimpleFSDirectory is a straightforward implementation using java.io.RandomAccessFile. However, it has poor concurrent performance (multiple threads will bottleneck) as it synchronizes when multiple threads read from the same file. NIOFSDirectory uses java.nio's FileChannel's positional io when reading to avoid synchronization when reading from the same file. Unfortunately, due to a Windows-only Sun JRE bug this is a poor choice for Windows, but on all other platforms this is the preferred choice. Applications using System.Threading.Thread.Interrupt() or Future#cancel(boolean) (on Java 1.5) should use SimpleFSDirectory instead. See NIOFSDirectory java doc for details. MMapDirectory uses memory-mapped IO when reading. This is a good choice if you have plenty of virtual memory relative to your index size, eg if you are running on a 64 bit JRE, or you are running on a 32 bit JRE but your index sizes are small enough to fit into the virtual memory space. Java has currently the limitation of not being able to unmap files from user code. The files are unmapped, when GC releases the byte buffers. 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 a (possibly dangerous) workaround mentioned in the bug report, which may fail on non-Sun JVMs. Applications using System.Threading.Thread.Interrupt() or Future#cancel(boolean) (on Java 1.5) should use SimpleFSDirectory instead. See MMapDirectory java doc for details. Unfortunately, because of system peculiarities, there is no single overall best implementation. Therefore, we've added the Open(System.IO.DirectoryInfo) method, to allow Lucene to choose the best FSDirectory implementation given your environment, and the known limitations of each implementation. For users who have no reason to prefer a specific implementation, it's best to simply use FSDirectory.Open(System.IO.DirectoryInfo) . For all others, you should instantiate the desired implementation directly.

The locking implementation is by default NativeFSLockFactory , but can be changed by passing in a custom LockFactory instance.

Inheritance: Directory
显示文件 Open project: apache/lucenenet Class Usage Examples

Protected Properties

Property Type Description
StaleFiles ISet
directory System.IO.DirectoryInfo

Private Properties

Property Type Description

Public Methods

Method Description
CreateOutput ( string name, IOContext context ) : Lucene.Net.Store.IndexOutput

Creates an IndexOutput for the file with the given name.

DeleteFile ( string name ) : void

Removes an existing file in the directory.

Dispose ( ) : void

Closes the store to future operations.

FileExists ( string name ) : bool

Returns true iff a file with the given name exists.

FileLength ( string name ) : long

Returns the length in bytes of a file in the directory.

ListAll ( ) : string[]

Lists all files (not subdirectories) in the directory.

ListAll ( DirectoryInfo dir ) : string[]

Lists all files (not subdirectories) in the directory. this method never returns null (throws System.IO.IOException instead).

Open ( DirectoryInfo path ) : FSDirectory

Creates an FSDirectory instance, trying to pick the best implementation given the current environment. The directory returned uses the NativeFSLockFactory.

Currently this returns MMapDirectory for most Solaris and Windows 64-bit JREs, NIOFSDirectory for other non-Windows JREs, and SimpleFSDirectory for other JREs on Windows. It is highly recommended that you consult the implementation's documentation for your platform before using this method.

NOTE: this method may suddenly change which implementation is returned from release to release, in the event that higher performance defaults become possible; if the precise implementation is important to your application, please instantiate it directly, instead. For optimal performance you should consider using MMapDirectory on 64 bit JVMs.

See above

Open ( DirectoryInfo path, Lucene.Net.Store.LockFactory lockFactory ) : FSDirectory

Just like #open(File), but allows you to also specify a custom LockFactory.

Sync ( ICollection names ) : void
ToString ( ) : string

For debug output.

Protected Methods

Method Description
EnsureCanWrite ( string name ) : void
FSDirectory ( DirectoryInfo dir ) : System
FSDirectory ( DirectoryInfo path, Lucene.Net.Store.LockFactory lockFactory ) : System

Create a new FSDirectory for the named location (ctor for subclasses).

Fsync ( String name, bool isDir = false ) : void

OnIndexOutputClosed ( Lucene.Net.Store.FSIndexOutput io ) : void

Method Details

CreateOutput() public method

Creates an IndexOutput for the file with the given name.
public CreateOutput ( string name, IOContext context ) : Lucene.Net.Store.IndexOutput
name string
context IOContext
return Lucene.Net.Store.IndexOutput

DeleteFile() public method

Removes an existing file in the directory.
public DeleteFile ( string name ) : void
name string
return void

Dispose() public method

Closes the store to future operations.
public Dispose ( ) : void
return void

EnsureCanWrite() protected method

protected EnsureCanWrite ( string name ) : void
name string
return void

FSDirectory() protected method

protected FSDirectory ( DirectoryInfo dir ) : System
dir System.IO.DirectoryInfo
return System

FSDirectory() protected method

Create a new FSDirectory for the named location (ctor for subclasses).
if there is a low-level I/O error
protected FSDirectory ( DirectoryInfo path, Lucene.Net.Store.LockFactory lockFactory ) : System
path System.IO.DirectoryInfo the path of the directory
lockFactory Lucene.Net.Store.LockFactory the lock factory to use, or null for the default /// ();
return System

FileExists() public method

Returns true iff a file with the given name exists.
public FileExists ( string name ) : bool
name string
return bool

FileLength() public method

Returns the length in bytes of a file in the directory.
public FileLength ( string name ) : long
name string
return long

Fsync() protected method

protected Fsync ( String name, bool isDir = false ) : void
name String
isDir bool
return void

ListAll() public method

Lists all files (not subdirectories) in the directory.
public ListAll ( ) : string[]
return string[]

ListAll() public static method

Lists all files (not subdirectories) in the directory. this method never returns null (throws System.IO.IOException instead).
if the directory /// does not exist, or does exist but is not a /// directory. if list() returns null
public static ListAll ( DirectoryInfo dir ) : string[]
dir System.IO.DirectoryInfo
return string[]

OnIndexOutputClosed() protected method

protected OnIndexOutputClosed ( Lucene.Net.Store.FSIndexOutput io ) : void
io Lucene.Net.Store.FSIndexOutput
return void

Open() public static method

Creates an FSDirectory instance, trying to pick the best implementation given the current environment. The directory returned uses the NativeFSLockFactory.

Currently this returns MMapDirectory for most Solaris and Windows 64-bit JREs, NIOFSDirectory for other non-Windows JREs, and SimpleFSDirectory for other JREs on Windows. It is highly recommended that you consult the implementation's documentation for your platform before using this method.

NOTE: this method may suddenly change which implementation is returned from release to release, in the event that higher performance defaults become possible; if the precise implementation is important to your application, please instantiate it directly, instead. For optimal performance you should consider using MMapDirectory on 64 bit JVMs.

See above

public static Open ( DirectoryInfo path ) : FSDirectory
path System.IO.DirectoryInfo
return FSDirectory

Open() public static method

Just like #open(File), but allows you to also specify a custom LockFactory.
public static Open ( DirectoryInfo path, Lucene.Net.Store.LockFactory lockFactory ) : FSDirectory
path System.IO.DirectoryInfo
lockFactory Lucene.Net.Store.LockFactory
return FSDirectory

Sync() public method

public Sync ( ICollection names ) : void
names ICollection
return void

ToString() public method

For debug output.
public ToString ( ) : string
return string

Property Details

StaleFiles protected_oe property

protected ISet StaleFiles
return ISet

directory protected_oe property

protected DirectoryInfo,System.IO directory
return System.IO.DirectoryInfo