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 Directory and then touches the index with IndexWriter to make sure any unused files are deleted.
Inheritance
Implements
Namespace: Lucene.Net.Replicator
Assembly: Lucene.Net.Replicator.dll
Syntax
public class IndexReplicationHandler : object, IReplicationHandler
Remarks
NOTE: This handler assumes that IndexWriter is not opened by another process on the index directory. In fact, opening an 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 IndexWriter, except the one that is open on the source index, from which you replicate.
This handler notifies the application via a provided
Constructors
| Improve this Doc View SourceIndexReplicationHandler(Directory, Func<Nullable<Boolean>>)
Constructor with the given index directory and callback to notify when the indexes were updated.
Declaration
public IndexReplicationHandler(Directory indexDirectory, Func<bool?> callback)
Parameters
Type | Name | Description |
---|---|---|
Directory | indexDirectory | |
Func<System.Nullable<System.Boolean>> | callback |
Fields
| Improve this Doc View SourceINFO_STREAM_COMPONENT
The component used to log messages to the Default InfoStream.
Declaration
public const string INFO_STREAM_COMPONENT = null
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 |
---|---|
IDictionary<System.String, IList<RevisionFile>> |
CurrentVersion
Declaration
public virtual string CurrentVersion { get; }
Property Value
Type | Description |
---|---|
System.String |
InfoStream
Gets or sets the InfoStream to use for logging messages.
Declaration
public virtual InfoStream InfoStream { get; set; }
Property Value
Type | Description |
---|---|
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 |
---|---|---|
Directory | directory | |
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 |
---|---|---|
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
Directory to the
target
Directory, if they are not the same.
Declaration
public static void CopyFiles(Directory source, Directory target, IList<string> files)
Parameters
Type | Name | Description |
---|---|---|
Directory | source | |
Directory | target | |
IList<System.String> | files |
GetLastCommit(Directory)
Returns the last IndexCommit found in the Directory, or
null
if there are no commits.
Declaration
public static IndexCommit GetLastCommit(Directory directory)
Parameters
Type | Name | Description |
---|---|---|
Directory | directory |
Returns
Type | Description |
---|---|
IndexCommit |
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 |
---|---|---|
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 | |
IDictionary<System.String, IList<RevisionFile>> | revisionFiles | |
IDictionary<System.String, IList<System.String>> | copiedFiles | |
IDictionary<System.String, 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 | |
Directory | directory |