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.
Inheritance
Namespace: Lucene.Net.Index
Assembly: Lucene.Net.dll
Syntax
public class SnapshotDeletionPolicy : IndexDeletionPolicy
Constructors
| Improve this Doc View SourceSnapshotDeletionPolicy(IndexDeletionPolicy)
Sole constructor, taking the incoming IndexDeletionPolicy to wrap.
Declaration
public SnapshotDeletionPolicy(IndexDeletionPolicy primary)
Parameters
Type | Name | Description |
---|---|---|
IndexDeletionPolicy | primary |
Fields
| Improve this Doc View Sourcem_indexCommits
Used to map gen to IndexCommit.
Declaration
protected IDictionary<long?, IndexCommit> m_indexCommits
Field Value
Type | Description |
---|---|
IDictionary<System.Nullable<System.Int64>, 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<System.Int64, System.Int32> |
Properties
| Improve this Doc View SourceSnapshotCount
Returns the total number of snapshots currently held.
Declaration
public virtual int SnapshotCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceClone()
Declaration
public override object Clone()
Returns
Type | Description |
---|---|
System.Object |
Overrides
| Improve this Doc View SourceGetIndexCommit(Int64)
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 |
---|---|---|
System.Int64 | 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>)
Declaration
public override void OnCommit<T>(IList<T> commits)
where T : IndexCommit
Parameters
Type | Name | Description |
---|---|---|
IList<T> | commits |
Type Parameters
Name | Description |
---|---|
T |
Overrides
OnInit<T>(IList<T>)
Declaration
public override void OnInit<T>(IList<T> commits)
where T : IndexCommit
Parameters
Type | Name | Description |
---|---|---|
IList<T> | commits |
Type Parameters
Name | Description |
---|---|
T |
Overrides
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(Int64)
Release a snapshot by generation.
Declaration
protected virtual void ReleaseGen(long gen)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | 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(Int32)) 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. |