Class 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 System.IO.FileStream, which is ideal for writing without using much RAM. However, it has poor concurrent performance (multiple threads will bottleneck) as it synchronizes when multiple threads read from the same file.
- NIOFSDirectory uses System.IO.FileStream's positional seeking, which makes it slightly less efficient than using SimpleFSDirectory during reading, with similar write performance.
- 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 runtime, or you are running on a 32 bit runtime but your index sizes are small enough to fit into the virtual memory space.
Unfortunately, because of system peculiarities, there is no single overall best implementation. Therefore, we've added the Open(String) method (or one of its overloads), 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 Open(String) (or one of its overloads). 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.
NOTE: Unlike in Java, it is not recommended to use
System.Threading.Thread.Interrupt in .NET
in conjunction with an open FSDirectory because it is not guaranteed to exit atomically.
Any lock
statement or System.Threading.Monitor.Enter(System.Object) call can throw a
System.Threading.ThreadInterruptedException, which makes shutting down unpredictable.
To exit parallel tasks safely, we recommend using System.Threading.Tasks.Tasks
and "interrupt" them with System.Threading.CancellationTokens.
Inheritance
Implements
Inherited Members
Namespace: Lucene.Net.Store
Assembly: Lucene.Net.dll
Syntax
public abstract class FSDirectory : BaseDirectory, IDisposable
Constructors
| Improve this Doc View SourceFSDirectory(DirectoryInfo)
Declaration
protected FSDirectory(DirectoryInfo dir)
Parameters
Type | Name | Description |
---|---|---|
System.IO.DirectoryInfo | dir |
FSDirectory(DirectoryInfo, LockFactory)
Create a new FSDirectory for the named location (ctor for subclasses).
Declaration
protected FSDirectory(DirectoryInfo path, LockFactory lockFactory)
Parameters
Type | Name | Description |
---|---|---|
System.IO.DirectoryInfo | path | the path of the directory |
LockFactory | lockFactory | the lock factory to use, or null for the default (NativeFSLockFactory); |
Exceptions
Type | Condition |
---|---|
System.IO.IOException | if there is a low-level I/O error |
Fields
| Improve this Doc View SourceDEFAULT_READ_CHUNK_SIZE
Default read chunk size: 8192 bytes (this is the size up to which the runtime does not allocate additional arrays while reading/writing)
Declaration
[Obsolete("this constant is no longer used since Lucene 4.5.")]
public const int DEFAULT_READ_CHUNK_SIZE = 8192
Field Value
Type | Description |
---|---|
System.Int32 |
m_directory
Declaration
protected readonly DirectoryInfo m_directory
Field Value
Type | Description |
---|---|
System.IO.DirectoryInfo |
Properties
| Improve this Doc View SourceDirectory
the underlying filesystem directory
Declaration
public virtual DirectoryInfo Directory { get; }
Property Value
Type | Description |
---|---|
System.IO.DirectoryInfo |
ReadChunkSize
this setting has no effect anymore.
Declaration
[Obsolete("this is no longer used since Lucene 4.5.")]
public int ReadChunkSize { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceCreateOutput(String, IOContext)
Creates an IndexOutput for the file with the given name.
Declaration
public override IndexOutput CreateOutput(string name, IOContext context)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | |
IOContext | context |
Returns
Type | Description |
---|---|
IndexOutput |
Overrides
| Improve this Doc View SourceDeleteFile(String)
Removes an existing file in the directory.
Declaration
public override void DeleteFile(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
Overrides
| Improve this Doc View SourceDispose(Boolean)
Closes the store to future operations.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
Overrides
| Improve this Doc View SourceEnsureCanWrite(String)
Declaration
protected virtual void EnsureCanWrite(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
FileExists(String)
Returns true iff a file with the given name exists.
Declaration
[Obsolete("this method will be removed in 5.0")]
public override bool FileExists(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
| Improve this Doc View SourceFileLength(String)
Returns the length in bytes of a file in the directory.
Declaration
public override long FileLength(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
Returns
Type | Description |
---|---|
System.Int64 |
Overrides
| Improve this Doc View SourceGetLockID()
Declaration
public override string GetLockID()
Returns
Type | Description |
---|---|
System.String |
Overrides
| Improve this Doc View SourceListAll()
Lists all files (not subdirectories) in the directory.
Declaration
public override string[] ListAll()
Returns
Type | Description |
---|---|
System.String[] |
Overrides
See Also
| Improve this Doc View SourceListAll(DirectoryInfo)
Lists all files (not subdirectories) in the
directory. This method never returns null
(throws
System.IO.IOException instead).
Declaration
public static string[] ListAll(DirectoryInfo dir)
Parameters
Type | Name | Description |
---|---|---|
System.IO.DirectoryInfo | dir |
Returns
Type | Description |
---|---|
System.String[] |
Exceptions
Type | Condition |
---|---|
System.IO.DirectoryNotFoundException | if the directory does not exist, or does exist but is not a directory or is invalid (for example, it is on an unmapped drive). |
System.Security.SecurityException | The caller does not have the required permission. |
OnIndexOutputClosed(FSDirectory.FSIndexOutput)
Declaration
protected virtual void OnIndexOutputClosed(FSDirectory.FSIndexOutput io)
Parameters
Type | Name | Description |
---|---|---|
FSDirectory.FSIndexOutput | io |
Open(DirectoryInfo)
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 runtimes, NIOFSDirectory for other non-Windows runtimes, and SimpleFSDirectory for other runtimes 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 runtimes.
See FSDirectory.
Declaration
public static FSDirectory Open(DirectoryInfo path)
Parameters
Type | Name | Description |
---|---|---|
System.IO.DirectoryInfo | path |
Returns
Type | Description |
---|---|
FSDirectory |
Open(DirectoryInfo, LockFactory)
Just like Open(DirectoryInfo), but allows you to also specify a custom LockFactory.
Declaration
public static FSDirectory Open(DirectoryInfo path, LockFactory lockFactory)
Parameters
Type | Name | Description |
---|---|---|
System.IO.DirectoryInfo | path | |
LockFactory | lockFactory |
Returns
Type | Description |
---|---|
FSDirectory |
Open(String)
Just like Open(DirectoryInfo), but allows you to specify the directory as a System.String.
Declaration
public static FSDirectory Open(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path (to a directory) to open |
Returns
Type | Description |
---|---|
FSDirectory | An open FSDirectory |
Open(String, LockFactory)
Just like Open(DirectoryInfo, LockFactory), but allows you to specify the directory as a System.String.
Declaration
public static FSDirectory Open(string path, LockFactory lockFactory)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path (to a directory) to open |
LockFactory | lockFactory |
Returns
Type | Description |
---|---|
FSDirectory | An open FSDirectory |
SetLockFactory(LockFactory)
Declaration
public override void SetLockFactory(LockFactory lockFactory)
Parameters
Type | Name | Description |
---|---|---|
LockFactory | lockFactory |
Overrides
| Improve this Doc View SourceSync(ICollection<String>)
Declaration
public override void Sync(ICollection<string> names)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.ICollection<System.String> | names |
Overrides
| Improve this Doc View SourceToString()
For debug output.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |