1 package org.apache.lucene.index;
 
   4  * Licensed to the Apache Software Foundation (ASF) under one or more
 
   5  * contributor license agreements.  See the NOTICE file distributed with
 
   6  * this work for additional information regarding copyright ownership.
 
   7  * The ASF licenses this file to You under the Apache License, Version 2.0
 
   8  * (the "License"); you may not use this file except in compliance with
 
   9  * the License.  You may obtain a copy of the License at
 
  11  *     http://www.apache.org/licenses/LICENSE-2.0
 
  13  * Unless required by applicable law or agreed to in writing, software
 
  14  * distributed under the License is distributed on an "AS IS" BASIS,
 
  15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  16  * See the License for the specific language governing permissions and
 
  17  * limitations under the License.
 
  20 import java.util.List;
 
  21 import java.io.IOException;
 
  24  * <p>Expert: policy for deletion of stale {@link IndexCommit index commits}. 
 
  26  * <p>Implement this interface, and pass it to one
 
  27  * of the {@link IndexWriter} or {@link IndexReader}
 
  28  * constructors, to customize when older
 
  29  * {@link IndexCommit point-in-time commits}
 
  30  * are deleted from the index directory.  The default deletion policy
 
  31  * is {@link KeepOnlyLastCommitDeletionPolicy}, which always
 
  32  * removes old commits as soon as a new commit is done (this
 
  33  * matches the behavior before 2.2).</p>
 
  35  * <p>One expected use case for this (and the reason why it
 
  36  * was first created) is to work around problems with an
 
  37  * index directory accessed via filesystems like NFS because
 
  38  * NFS does not provide the "delete on last close" semantics
 
  39  * that Lucene's "point in time" search normally relies on.
 
  40  * By implementing a custom deletion policy, such as "a
 
  41  * commit is only removed once it has been stale for more
 
  42  * than X minutes", you can give your readers time to
 
  43  * refresh to the new commit before {@link IndexWriter}
 
  44  * removes the old commits.  Note that doing so will
 
  45  * increase the storage requirements of the index.  See <a
 
  47  * href="http://issues.apache.org/jira/browse/LUCENE-710">LUCENE-710</a>
 
  51 public interface IndexDeletionPolicy {
 
  54    * <p>This is called once when a writer is first
 
  55    * instantiated to give the policy a chance to remove old
 
  58    * <p>The writer locates all index commits present in the 
 
  59    * index directory and calls this method.  The policy may 
 
  60    * choose to delete some of the commit points, doing so by
 
  61    * calling method {@link IndexCommit#delete delete()} 
 
  62    * of {@link IndexCommit}.</p>
 
  64    * <p><u>Note:</u> the last CommitPoint is the most recent one,
 
  65    * i.e. the "front index state". Be careful not to delete it,
 
  66    * unless you know for sure what you are doing, and unless 
 
  67    * you can afford to lose the index content while doing that. 
 
  69    * @param commits List of current 
 
  70    * {@link IndexCommit point-in-time commits},
 
  71    *  sorted by age (the 0th one is the oldest commit).
 
  73   public void onInit(List<? extends IndexCommit> commits) throws IOException;
 
  76    * <p>This is called each time the writer completed a commit.
 
  77    * This gives the policy a chance to remove old commit points
 
  78    * with each commit.</p>
 
  80    * <p>The policy may now choose to delete old commit points 
 
  81    * by calling method {@link IndexCommit#delete delete()} 
 
  82    * of {@link IndexCommit}.</p>
 
  84    * <p>This method is only called when {@link
 
  85    * IndexWriter#commit} or {@link IndexWriter#close} is
 
  86    * called, or possibly not at all if the {@link
 
  87    * IndexWriter#rollback} is called.
 
  89    * <p><u>Note:</u> the last CommitPoint is the most recent one,
 
  90    * i.e. the "front index state". Be careful not to delete it,
 
  91    * unless you know for sure what you are doing, and unless 
 
  92    * you can afford to lose the index content while doing that.
 
  94    * @param commits List of {@link IndexCommit},
 
  95    *  sorted by age (the 0th one is the oldest commit).
 
  97   public void onCommit(List<? extends IndexCommit> commits) throws IOException;