Overview | Package | Class | Use | Tree | Deprecated | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.lucene.index
Class PersistentSnapshotDeletionPolicy

    java.lang.Object
      org.apache.lucene.index.IndexDeletionPolicy
          org.apache.lucene.index.SnapshotDeletionPolicy
              org.apache.lucene.index.PersistentSnapshotDeletionPolicy

All Implemented Interfaces:
  Closeable, Cloneable

    public class PersistentSnapshotDeletionPolicy

extends SnapshotDeletionPolicy
implements Closeable

A `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(String)` or `release(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 corruption will occur.

NOTE: you should call `close()` when you're done using this class for safety (it will close the `IndexWriter` instance used).

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

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
`PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory dir, IndexWriterConfig.OpenMode mode, Version matchVersion)` `PersistentSnapshotDeletionPolicy` wraps another `IndexDeletionPolicy` to enable flexible snapshotting.

Method Summary
`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 given `Directory`.
`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, clone, getSnapshot, getSnapshots, isSnapshotted, onCommit, registerSnapshotInfo, wrapCommits`

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### PersistentSnapshotDeletionPolicy

    public PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary,
                                            Directory dir,
                                            IndexWriterConfig.OpenMode mode,
                                            Version matchVersion)
                                     throws IOException

  `PersistentSnapshotDeletionPolicy` wraps another `IndexDeletionPolicy` to enable flexible snapshotting.

  Parameters:
    `primary` - the `IndexDeletionPolicy` that is used on non-snapshotted commits. Snapshotted commits, by definition, are not deleted until explicitly released via `release(String)`.
    `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.
    `matchVersion` - specifies the `Version` that should be used when opening the IndexWriter.
  Throws:
    `IOException`

Method Detail

### readSnapshotsInfo

    public static Map<String,String> readSnapshotsInfo(Directory dir)
                                                throws IOException

  Reads the snapshots information from the given `Directory`. 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 class: `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()` of `IndexCommit`.

  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.

  Overrides:
    `onInit` in class `SnapshotDeletionPolicy`
  Parameters:
    `commits` - List of current `point-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 class `SnapshotDeletionPolicy`
  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 class `SnapshotDeletionPolicy`
  Parameters:
    `id` - a unique identifier of the commit that is un-snapshotted.
  Throws:
    `IOException`
  See Also:
    `SnapshotDeletionPolicy.release(String)`

### close

    public void close()
               throws IOException

  Closes the index which writes the snapshots to the directory.

  Specified by:
    `close` in interface `Closeable`
  Throws:
    `IOException`

Overview | Package | Class | Use | Tree | Deprecated | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.