Class PersistentSnapshotDeletionPolicy
- java.lang.Object
-
- org.apache.lucene.index.SnapshotDeletionPolicy
-
- org.apache.lucene.index.PersistentSnapshotDeletionPolicy
-
- All Implemented Interfaces:
IndexDeletionPolicy
public class PersistentSnapshotDeletionPolicy extends SnapshotDeletionPolicy
ASnapshotDeletionPolicy
which adds a persistence layer so that snapshots can be maintained across the life of an application. The snapshots are persisted in aDirectory
and are committed as soon assnapshot(String)
orrelease(String)
is called.NOTE: this class receives a
Directory
to persist the data into a Lucene index. It is highly recommended to use a dedicated directory (and on stable storage as well) for persisting the snapshots' information, and not reuse the content index directory, or otherwise conflicts and index corruptions will occur.NOTE: you should call
close()
when you're done using this class for safetyness (it will close theIndexWriter
instance used).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.lucene.index.SnapshotDeletionPolicy
SnapshotDeletionPolicy.SnapshotCommitPoint
-
-
Field Summary
-
Fields inherited from class org.apache.lucene.index.SnapshotDeletionPolicy
lastCommit
-
-
Constructor Summary
Constructors Constructor Description PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory dir, IndexWriterConfig.OpenMode mode, Version matchVersion)
PersistentSnapshotDeletionPolicy
wraps anotherIndexDeletionPolicy
to enable flexible snapshotting.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the index which writes the snapshots to the directory.void
onInit(List<? extends IndexCommit> commits)
This is called once when a writer is first instantiated to give the policy a chance to remove old commit points.static Map<String,String>
readSnapshotsInfo(Directory dir)
Reads the snapshots information from the givenDirectory
.void
release(String id)
Deletes a snapshotted commit by ID.IndexCommit
snapshot(String id)
Snapshots the last commit using the given ID.-
Methods inherited from class org.apache.lucene.index.SnapshotDeletionPolicy
checkSnapshotted, getSnapshot, getSnapshots, isSnapshotted, onCommit, registerSnapshotInfo, wrapCommits
-
-
-
-
Constructor Detail
-
PersistentSnapshotDeletionPolicy
public PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory dir, IndexWriterConfig.OpenMode mode, Version matchVersion) throws CorruptIndexException, LockObtainFailedException, IOException
PersistentSnapshotDeletionPolicy
wraps anotherIndexDeletionPolicy
to enable flexible snapshotting.- Parameters:
primary
- theIndexDeletionPolicy
that is used on non-snapshotted commits. Snapshotted commits, by definition, are not deleted until explicitly released viarelease(String)
.dir
- theDirectory
which will be used to persist the snapshots information.mode
- specifies whether a new index should be created, deleting all existing snapshots information (immediately), or open an existing index, initializing the class with the snapshots information.matchVersion
- specifies theVersion
that should be used when opening the IndexWriter.- Throws:
CorruptIndexException
LockObtainFailedException
IOException
-
-
Method Detail
-
readSnapshotsInfo
public static Map<String,String> readSnapshotsInfo(Directory dir) throws IOException
Reads the snapshots information from the givenDirectory
. This method can be used if the snapshots information is needed, however you cannot instantiate the deletion policy (because e.g., some other process keeps a lock on the snapshots directory).- Throws:
IOException
-
onInit
public void onInit(List<? extends IndexCommit> commits) throws IOException
Description copied from interface:IndexDeletionPolicy
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()
ofIndexCommit
.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.
- Specified by:
onInit
in interfaceIndexDeletionPolicy
- Overrides:
onInit
in classSnapshotDeletionPolicy
- Parameters:
commits
- List of currentpoint-in-time commits
, sorted by age (the 0th one is the oldest commit).- Throws:
IOException
-
snapshot
public IndexCommit snapshot(String id) throws IOException
Snapshots the last commit using the given ID. Once this method returns, the snapshot information is persisted in the directory.- Overrides:
snapshot
in classSnapshotDeletionPolicy
- Parameters:
id
- a unique identifier of the commit that is being snapshotted.- Returns:
- the
IndexCommit
that was snapshotted. - Throws:
IOException
- See Also:
SnapshotDeletionPolicy.snapshot(String)
-
release
public void release(String id) throws IOException
Deletes a snapshotted commit by ID. Once this method returns, the snapshot information is committed to the directory.- Overrides:
release
in classSnapshotDeletionPolicy
- Parameters:
id
- a unique identifier of the commit that is un-snapshotted.- Throws:
IOException
- See Also:
SnapshotDeletionPolicy.release(String)
-
close
public void close() throws CorruptIndexException, IOException
Closes the index which writes the snapshots to the directory.- Throws:
CorruptIndexException
IOException
-
-