Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class SnapshotDeletionPolicy

    An IndexDeletionPolicy that wraps any other IndexDeletionPolicy and adds the ability to hold and later release snapshots of an index. While a snapshot is held, the IndexWriter will not remove any files associated with it even if the index is otherwise being actively, arbitrarily changed. Because we wrap another arbitrary IndexDeletionPolicy, this gives you the freedom to continue using whatever IndexDeletionPolicy you would normally want to use with your index.

    This class maintains all snapshots in-memory, and so the information is not persisted and not protected against system failures. If persistence is important, you can use PersistentSnapshotDeletionPolicy.

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Inheritance
    object
    IndexDeletionPolicy
    SnapshotDeletionPolicy
    PersistentSnapshotDeletionPolicy
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Lucene.Net.Index
    Assembly: Lucene.Net.dll
    Syntax
    public class SnapshotDeletionPolicy : IndexDeletionPolicy

    Constructors

    SnapshotDeletionPolicy(IndexDeletionPolicy)

    Sole constructor, taking the incoming IndexDeletionPolicy to wrap.

    Declaration
    public SnapshotDeletionPolicy(IndexDeletionPolicy primary)
    Parameters
    Type Name Description
    IndexDeletionPolicy primary

    Fields

    m_indexCommits

    Used to map gen to IndexCommit.

    Declaration
    protected IDictionary<long, IndexCommit> m_indexCommits
    Field Value
    Type Description
    IDictionary<long, IndexCommit>

    m_lastCommit

    Most recently committed IndexCommit.

    Declaration
    protected IndexCommit m_lastCommit
    Field Value
    Type Description
    IndexCommit

    m_refCounts

    Records how many snapshots are held against each commit generation

    Declaration
    protected IDictionary<long, int> m_refCounts
    Field Value
    Type Description
    IDictionary<long, int>

    Properties

    SnapshotCount

    Returns the total number of snapshots currently held.

    Declaration
    public virtual int SnapshotCount { get; }
    Property Value
    Type Description
    int

    Methods

    Clone()

    An IndexDeletionPolicy that wraps any other IndexDeletionPolicy and adds the ability to hold and later release snapshots of an index. While a snapshot is held, the IndexWriter will not remove any files associated with it even if the index is otherwise being actively, arbitrarily changed. Because we wrap another arbitrary IndexDeletionPolicy, this gives you the freedom to continue using whatever IndexDeletionPolicy you would normally want to use with your index.

    This class maintains all snapshots in-memory, and so the information is not persisted and not protected against system failures. If persistence is important, you can use PersistentSnapshotDeletionPolicy.

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Declaration
    public override object Clone()
    Returns
    Type Description
    object
    Overrides
    IndexDeletionPolicy.Clone()

    GetIndexCommit(long)

    Retrieve an IndexCommit from its generation; returns null if this IndexCommit is not currently snapshotted

    Declaration
    public virtual IndexCommit GetIndexCommit(long gen)
    Parameters
    Type Name Description
    long gen
    Returns
    Type Description
    IndexCommit

    GetSnapshots()

    Returns all IndexCommits held by at least one snapshot.

    Declaration
    public virtual IList<IndexCommit> GetSnapshots()
    Returns
    Type Description
    IList<IndexCommit>

    IncRef(IndexCommit)

    Increments the refCount for this IndexCommit.

    Declaration
    protected virtual void IncRef(IndexCommit ic)
    Parameters
    Type Name Description
    IndexCommit ic

    OnCommit<T>(IList<T>)

    this is called each time the writer completed a commit. this gives the policy a chance to remove old commit points with each commit.

    The policy may now choose to delete old commit points by calling method Delete() of IndexCommit.

    This method is only called when Commit()} or Dispose() is called, or possibly not at all if the Rollback()} method is called.

    Note: the last CommitPoint is the most recent one, i.e. the "front index state". Be careful not to delete it, unless you know for sure what you are doing, and unless you can afford to lose the index content while doing that.

    Declaration
    public override void OnCommit<T>(IList<T> commits) where T : IndexCommit
    Parameters
    Type Name Description
    IList<T> commits

    List of IndexCommits, sorted by age (the 0th one is the oldest commit).

    Type Parameters
    Name Description
    T
    Overrides
    IndexDeletionPolicy.OnCommit<T>(IList<T>)

    OnInit<T>(IList<T>)

    this is called once when a writer is first instantiated to give the policy a chance to remove old commit points.

    The writer locates all index commits present in the index directory and calls this method. The policy may choose to delete some of the commit points, doing so by calling method Delete().

    Note: the last CommitPoint is the most recent one, i.e. the "front index state". Be careful not to delete it, unless you know for sure what you are doing, and unless you can afford to lose the index content while doing that.

    Declaration
    public override void OnInit<T>(IList<T> commits) where T : IndexCommit
    Parameters
    Type Name Description
    IList<T> commits

    List of current point-in-time commits (IndexCommit), sorted by age (the 0th one is the oldest commit). Note that for a new index this method is invoked with an empty list.

    Type Parameters
    Name Description
    T
    Overrides
    IndexDeletionPolicy.OnInit<T>(IList<T>)

    Release(IndexCommit)

    Release a snapshotted commit.

    Declaration
    public virtual void Release(IndexCommit commit)
    Parameters
    Type Name Description
    IndexCommit commit

    the commit previously returned by Snapshot()

    ReleaseGen(long)

    Release a snapshot by generation.

    Declaration
    protected virtual void ReleaseGen(long gen)
    Parameters
    Type Name Description
    long gen

    Snapshot()

    Snapshots the last commit and returns it. Once a commit is 'snapshotted,' it is protected from deletion (as long as this IndexDeletionPolicy is used). The snapshot can be removed by calling Release(IndexCommit) followed by a call to DeleteUnusedFiles().

    NOTE: while the snapshot is held, the files it references will not be deleted, which will consume additional disk space in your index. If you take a snapshot at a particularly bad time (say just before you call ForceMerge(int)) then in the worst case this could consume an extra 1X of your total index size, until you release the snapshot.
    Declaration
    public virtual IndexCommit Snapshot()
    Returns
    Type Description
    IndexCommit

    the IndexCommit that was snapshotted.

    Exceptions
    Type Condition
    InvalidOperationException

    if this index does not have any commits yet

    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.