Class IndexDeletionPolicyWrapper

java.lang.Object
org.apache.lucene.index.IndexDeletionPolicy
org.apache.solr.core.IndexDeletionPolicyWrapper

public final class IndexDeletionPolicyWrapper extends org.apache.lucene.index.IndexDeletionPolicy
A wrapper for an IndexDeletionPolicy instance.

Provides features for looking up IndexCommit given a version. Allows reserving index commit points for certain amounts of time to support features such as index replication or snapshotting directly out of a live index directory.

NOTE: The Object.clone() method returns this in order to make this IndexDeletionPolicy instance trackable across IndexWriter instantiations. This is correct because each core has its own IndexDeletionPolicy and never has more than one open IndexWriter.

See Also:
  • IndexDeletionPolicy
  • Constructor Summary

    Constructors
    Constructor
    Description
    IndexDeletionPolicyWrapper(org.apache.lucene.index.IndexDeletionPolicy deletionPolicy, SolrSnapshotMetaDataManager snapshotMgr)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.lucene.index.IndexCommit
    Atomically Saves (via reference counting) & Returns the specified commit if available.
    org.apache.lucene.index.IndexCommit
    Atomically Saves (via reference counting) & Returns the most recent commit point.
    Map<Long,org.apache.lucene.index.IndexCommit>
    Returns a Map of all currently known commits, keyed by their generation.
    static long
    getCommitTimestamp(org.apache.lucene.index.IndexCommit commit)
    Helper method for unpacking the timestamp info from the user data
    org.apache.lucene.index.IndexCommit
    Returns the most recent commit point.
    org.apache.lucene.index.IndexDeletionPolicy
     
    void
    onCommit(List<? extends org.apache.lucene.index.IndexCommit> list)
    Internal use for Lucene...
    void
    onInit(List<? extends org.apache.lucene.index.IndexCommit> list)
    Internal use for Lucene...
    void
    Release a previously saved commit point.
    void
    releaseCommitPoint(org.apache.lucene.index.IndexCommit commit)
    Release a previously saved commit point.
    void
    saveCommitPoint(Long generation)
    Permanently prevent this commit point from being deleted (if it has not already) using a reference count.
    void
    setReserveDuration(Long indexGen, long reserveTime)
    Set the duration for which commit point is to be reserved by the deletion policy.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • IndexDeletionPolicyWrapper

      public IndexDeletionPolicyWrapper(org.apache.lucene.index.IndexDeletionPolicy deletionPolicy, SolrSnapshotMetaDataManager snapshotMgr)
  • Method Details

    • getLatestCommit

      public org.apache.lucene.index.IndexCommit getLatestCommit()
      Returns the most recent commit point.

      NOTE: This method makes no guarantee that the commit returned still exists as the moment this method completes. Callers are encouraged to use getAndSaveLatestCommit() instead.

      Returns:
      the most recent commit point, or null if there have not been any commits
      See Also:
    • getAndSaveLatestCommit

      public org.apache.lucene.index.IndexCommit getAndSaveLatestCommit()
      Atomically Saves (via reference counting) & Returns the most recent commit point.

      If the return value is non-null, then the caller MUST call releaseCommitPoint(org.apache.lucene.index.IndexCommit) when finished using it in order to decrement the reference count, or the commit will be preserved in the Directory forever.

      Returns:
      the most recent commit point, or null if there have not been any commits
      See Also:
    • getAndSaveCommitPoint

      public org.apache.lucene.index.IndexCommit getAndSaveCommitPoint(Long generation)
      Atomically Saves (via reference counting) & Returns the specified commit if available.

      If the return value is non-null, then the caller MUST call releaseCommitPoint(org.apache.lucene.index.IndexCommit) when finished using it in order to decrement the reference count, or the commit will be preserved in the Directory forever.

      Returns:
      the commit point with the specified generation, or null if not available
      See Also:
    • getWrappedDeletionPolicy

      public org.apache.lucene.index.IndexDeletionPolicy getWrappedDeletionPolicy()
    • setReserveDuration

      public void setReserveDuration(Long indexGen, long reserveTime)
      Set the duration for which commit point is to be reserved by the deletion policy.

      NOTE: This method does not make any guarantees that the specified index generation exists, or that the specified generation has not already ben deleted. The only guarantee is that if the specified generation exists now, or is created at some point in the future, then it will be reserved for at least the specified reserveTime.

      Parameters:
      indexGen - gen of the commit point to be reserved
      reserveTime - duration in milliseconds (relative to 'now') for which the commit point is to be reserved
    • saveCommitPoint

      public void saveCommitPoint(Long generation)
      Permanently prevent this commit point from being deleted (if it has not already) using a reference count.

      NOTE: Callers MUST call releaseCommitPoint(org.apache.lucene.index.IndexCommit) when finished using it in order to decrement the reference count, or the commit will be preserved in the Directory forever.

      Parameters:
      generation - the generation of the IndexCommit to save until released
      Throws:
      IllegalStateException - if generation is already too old to be saved
      See Also:
    • releaseCommitPoint

      public void releaseCommitPoint(org.apache.lucene.index.IndexCommit commit)
      Release a previously saved commit point.

      This is a convenience wrapper around releaseCommitPoint(Long) that will ignore null input.

    • releaseCommitPoint

      public void releaseCommitPoint(Long generation)
      Release a previously saved commit point.

      This method does not enforce that the specified generation has previously been saved, or even that it's 'non-null'. But if both are true then it will decrement the reference count for the specified generation.

    • onInit

      public void onInit(List<? extends org.apache.lucene.index.IndexCommit> list) throws IOException
      Internal use for Lucene... do not explicitly call.

      This Impl passes the list of commits to the delegate Policy AFTER wrapping each commit in a proxy class that only proxies IndexCommit.delete() if they are not already saved.

      Specified by:
      onInit in class org.apache.lucene.index.IndexDeletionPolicy
      Throws:
      IOException
    • onCommit

      public void onCommit(List<? extends org.apache.lucene.index.IndexCommit> list) throws IOException
      Internal use for Lucene... do not explicitly call.

      This Impl passes the list of commits to the delegate Policy AFTER wrapping each commit in a proxy class that only proxies IndexCommit.delete() if they are not already saved.

      Specified by:
      onCommit in class org.apache.lucene.index.IndexDeletionPolicy
      Throws:
      IOException
    • getCommits

      public Map<Long,org.apache.lucene.index.IndexCommit> getCommits()
      Returns a Map of all currently known commits, keyed by their generation.

      NOTE: This map instance may change between commits and commit points may be deleted. This API is intended for "informational purposes" only, to provide an "at the moment" view of the current list of known commits. Callers that need to ensure commits exist for an extended period must wrap this call and all subsequent usage of the results in a synchronization block.

      Returns:
      a Map of generation to commit points
    • getCommitTimestamp

      public static long getCommitTimestamp(org.apache.lucene.index.IndexCommit commit) throws IOException
      Helper method for unpacking the timestamp info from the user data
      Throws:
      IOException
      See Also: