Fork me on GitHub
  • API

    Show / Hide Table of Contents

    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
    object
    IndexReplicationHandler
    Implements
    IReplicationHandler
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    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 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

    IndexReplicationHandler(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
    Directory indexDirectory
    Action callback
    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 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.

    Fields

    INFO_STREAM_COMPONENT

    The component used to log messages to the Lucene.Net.Util.InfoStream.DefaultLucene.Net.Util.InfoStream.

    Declaration
    public const string INFO_STREAM_COMPONENT = "IndexReplicationHandler"
    Field Value
    Type Description
    string
    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 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.

    Properties

    CurrentRevisionFiles

    Returns the current revision version held by the handler.

    Declaration
    public virtual IDictionary<string, IList<RevisionFile>> CurrentRevisionFiles { get; }
    Property Value
    Type Description
    IDictionary<string, IList<RevisionFile>>
    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 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.

    CurrentVersion

    Returns the current revision files held by the handler.

    Declaration
    public virtual string CurrentVersion { get; }
    Property Value
    Type Description
    string
    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 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.

    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
    InfoStream
    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 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.

    Methods

    CleanupFilesOnFailure(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<string> files
    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 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.

    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
    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 sourceLucene.Net.Store.Directory to the targetLucene.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
    Directory source
    Directory target
    IList<string> files
    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 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.

    Exceptions
    Type Condition
    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
    Directory directory
    Returns
    Type Description
    IndexCommit
    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 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.

    Exceptions
    Type Condition
    IOException

    GetSegmentsFile(IList<string>, bool)

    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<string> files
    bool allowEmpty
    Returns
    Type Description
    string
    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 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.

    RevisionReady(string, IDictionary<string, IList<RevisionFile>>, IDictionary<string, IList<string>>, IDictionary<string, Directory>)

    Called when a new revision was obtained and is available (i.e. all needed files were successfully copied).

    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
    string version

    The version of the IRevision that was copied

    IDictionary<string, IList<RevisionFile>> revisionFiles

    The files contained by this IRevision

    IDictionary<string, IList<string>> copiedFiles

    The files that were actually copied

    IDictionary<string, Directory> sourceDirectory

    A mapping from a source of files to the Lucene.Net.Store.Directory they were copied into

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

    Exceptions
    Type Condition
    IOException

    WriteSegmentsGen(string, Directory)

    Writes Lucene.Net.Index.IndexFileNames.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
    string segmentsFile
    Directory directory
    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 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.

    Implements

    IReplicationHandler
    Back to top Copyright © 2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.