Class IndexReplicationHandler
A IReplicationHandler for replication of an index. Implements RevisionReady(String, IDictionary<String, IList<RevisionFile>>, IDictionary<String, IList<String>>, IDictionary<String, Directory>) by copying the files pointed by the client resolver to the index Lucene.Net.Store.Directory and then touches the index with Lucene.Net.Index.IndexWriter to make sure any unused files are deleted.
Inheritance
Implements
Inherited Members
Namespace: Lucene.Net.Replicator
Assembly: Lucene.Net.Replicator.dll
Syntax
public class IndexReplicationHandler : IReplicationHandler
Remarks
NOTE: This handler assumes that Lucene.Net.Index.IndexWriter is not opened by another process on the index directory. In fact, opening an Lucene.Net.Index.IndexWriter on the same directory to which files are copied can lead to undefined behavior, where some or all the files will be deleted, override other files or simply create a mess. When you replicate an index, it is best if the index is never modified by Lucene.Net.Index.IndexWriter, except the one that is open on the source index, from which you replicate.
This handler notifies the application via a provided System.Action when an updated index commit was made available for it.
Note
This API is experimental and might change in incompatible ways in the next release.
Constructors
| Improve this Doc View SourceIndexReplicationHandler(Directory, Action)
Constructor with the given index directory and callback to notify when the indexes were updated.
Declaration
public IndexReplicationHandler(Directory indexDirectory, Action callback)
Parameters
Type | Name | Description |
---|---|---|
Lucene.Net.Store.Directory | indexDirectory | |
System.Action | callback |
Fields
| Improve this Doc View SourceINFO_STREAM_COMPONENT
The component used to log messages to the Lucene.Net.Util.InfoStream.Default Lucene.Net.Util.InfoStream.
Declaration
public const string INFO_STREAM_COMPONENT = "IndexReplicationHandler"
Field Value
Type | Description |
---|---|
System.String |
Properties
| Improve this Doc View SourceCurrentRevisionFiles
Declaration
public virtual IDictionary<string, IList<RevisionFile>> CurrentRevisionFiles { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IDictionary<System.String, System.Collections.Generic.IList<RevisionFile>> |
CurrentVersion
Declaration
public virtual string CurrentVersion { get; }
Property Value
Type | Description |
---|---|
System.String |
InfoStream
Gets or sets the Lucene.Net.Util.InfoStream to use for logging messages.
Declaration
public virtual InfoStream InfoStream { get; set; }
Property Value
Type | Description |
---|---|
Lucene.Net.Util.InfoStream |
Methods
| Improve this Doc View SourceCleanupFilesOnFailure(Directory, IList<String>)
Cleanup the index directory by deleting all given files. Called when file copy or sync failed.
Declaration
public static void CleanupFilesOnFailure(Directory directory, IList<string> files)
Parameters
Type | Name | Description |
---|---|---|
Lucene.Net.Store.Directory | directory | |
System.Collections.Generic.IList<System.String> | files |
CleanupOldIndexFiles(Directory, String)
Cleans up the index directory from old index files. This method uses the
last commit found by GetLastCommit(Directory). If it matches the
expected segmentsFile
, then all files not referenced by this commit point
are deleted.
Declaration
public static void CleanupOldIndexFiles(Directory directory, string segmentsFile)
Parameters
Type | Name | Description |
---|---|---|
Lucene.Net.Store.Directory | directory | |
System.String | segmentsFile |
Remarks
NOTE: This method does a best effort attempt to clean the index directory. It suppresses any exceptions that occur, as this can be retried the next time.
CopyFiles(Directory, Directory, IList<String>)
Copies the provided list of files from the source
Lucene.Net.Store.Directory to the
target
Lucene.Net.Store.Directory, if they are not the same.
Declaration
public static void CopyFiles(Directory source, Directory target, IList<string> files)
Parameters
Type | Name | Description |
---|---|---|
Lucene.Net.Store.Directory | source | |
Lucene.Net.Store.Directory | target | |
System.Collections.Generic.IList<System.String> | files |
Exceptions
Type | Condition |
---|---|
System.IO.IOException |
GetLastCommit(Directory)
Returns the last Lucene.Net.Index.IndexCommit found in the Lucene.Net.Store.Directory, or
null
if there are no commits.
Declaration
public static IndexCommit GetLastCommit(Directory directory)
Parameters
Type | Name | Description |
---|---|---|
Lucene.Net.Store.Directory | directory |
Returns
Type | Description |
---|---|
Lucene.Net.Index.IndexCommit |
Exceptions
Type | Condition |
---|---|
System.IO.IOException |
GetSegmentsFile(IList<String>, Boolean)
Verifies that the last file is segments_N and fails otherwise. It also removes and returns the file from the list, because it needs to be handled last, after all files. This is important in order to guarantee that if a reader sees the new segments_N, all other segment files are already on stable storage.
The reason why the code fails instead of putting segments_N file last is that this indicates an error in the IRevision implementation.
Declaration
public static string GetSegmentsFile(IList<string> files, bool allowEmpty)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<System.String> | files | |
System.Boolean | allowEmpty |
Returns
Type | Description |
---|---|
System.String |
RevisionReady(String, IDictionary<String, IList<RevisionFile>>, IDictionary<String, IList<String>>, IDictionary<String, Directory>)
Declaration
public virtual void RevisionReady(string version, IDictionary<string, IList<RevisionFile>> revisionFiles, IDictionary<string, IList<string>> copiedFiles, IDictionary<string, Directory> sourceDirectory)
Parameters
Type | Name | Description |
---|---|---|
System.String | version | |
System.Collections.Generic.IDictionary<System.String, System.Collections.Generic.IList<RevisionFile>> | revisionFiles | |
System.Collections.Generic.IDictionary<System.String, System.Collections.Generic.IList<System.String>> | copiedFiles | |
System.Collections.Generic.IDictionary<System.String, Lucene.Net.Store.Directory> | sourceDirectory |
WriteSegmentsGen(String, Directory)
Writes SEGMENTS_GEN file to the directory, reading
the generation from the given segmentsFile
. If it is null
,
this method deletes segments.gen from the directory.
Declaration
public static void WriteSegmentsGen(string segmentsFile, Directory directory)
Parameters
Type | Name | Description |
---|---|---|
System.String | segmentsFile | |
Lucene.Net.Store.Directory | directory |