public class PersistentSnapshotDeletionPolicy extends SnapshotDeletionPolicy
SnapshotDeletionPolicy
which adds a persistence layer so that
snapshots can be maintained across the life of an application. The snapshots
are persisted in a Directory
and are committed as soon as
snapshot()
or release(IndexCommit)
is called.
NOTE: Sharing PersistentSnapshotDeletionPolicy
s that write to
the same directory across IndexWriter
s will corrupt snapshots. You
should make sure every IndexWriter
has its own
PersistentSnapshotDeletionPolicy
and that they all write to a
different Directory
. It is OK to use the same
Directory that holds the index.
This class adds a release(long)
method to
release commits from a previous snapshot's IndexCommit.getGeneration()
.
Modifier and Type | Field and Description |
---|---|
static String |
SNAPSHOTS_PREFIX
Prefix used for the save file.
|
indexCommits, lastCommit, refCounts
Constructor and Description |
---|
PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary,
Directory dir)
PersistentSnapshotDeletionPolicy wraps another
IndexDeletionPolicy to enable flexible
snapshotting, passing IndexWriterConfig.OpenMode.CREATE_OR_APPEND
by default. |
PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary,
Directory dir,
IndexWriterConfig.OpenMode mode)
PersistentSnapshotDeletionPolicy wraps another
IndexDeletionPolicy to enable flexible snapshotting. |
Modifier and Type | Method and Description |
---|---|
String |
getLastSaveFile()
Returns the file name the snapshots are currently
saved to, or null if no snapshots have been saved.
|
void |
release(IndexCommit commit)
Deletes a snapshotted commit.
|
void |
release(long gen)
Deletes a snapshotted commit by generation.
|
IndexCommit |
snapshot()
Snapshots the last commit.
|
getIndexCommit, getSnapshotCount, getSnapshots, incRef, onCommit, onInit, releaseGen
public static final String SNAPSHOTS_PREFIX
public PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory dir) throws IOException
PersistentSnapshotDeletionPolicy
wraps another
IndexDeletionPolicy
to enable flexible
snapshotting, passing IndexWriterConfig.OpenMode.CREATE_OR_APPEND
by default.primary
- the IndexDeletionPolicy
that is used on non-snapshotted
commits. Snapshotted commits, by definition, are not deleted until
explicitly released via release(org.apache.lucene.index.IndexCommit)
.dir
- the Directory
which will be used to persist the snapshots
information.IOException
public PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory dir, IndexWriterConfig.OpenMode mode) throws IOException
PersistentSnapshotDeletionPolicy
wraps another
IndexDeletionPolicy
to enable flexible snapshotting.primary
- the IndexDeletionPolicy
that is used on non-snapshotted
commits. Snapshotted commits, by definition, are not deleted until
explicitly released via release(org.apache.lucene.index.IndexCommit)
.dir
- the Directory
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.IOException
public IndexCommit snapshot() throws IOException
snapshot
in class SnapshotDeletionPolicy
IndexCommit
that was snapshotted.IOException
SnapshotDeletionPolicy.snapshot()
public void release(IndexCommit commit) throws IOException
release
in class SnapshotDeletionPolicy
commit
- the commit previously returned by SnapshotDeletionPolicy.snapshot()
IOException
SnapshotDeletionPolicy.release(org.apache.lucene.index.IndexCommit)
public void release(long gen) throws IOException
public String getLastSaveFile()
Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.