Class IndexFileDeleter

java.lang.Object
org.apache.lucene.index.IndexFileDeleter
All Implemented Interfaces:
Closeable, AutoCloseable

final class IndexFileDeleter extends Object implements Closeable
  • Field Details

  • Constructor Details

    • IndexFileDeleter

      public IndexFileDeleter(String[] files, Directory directoryOrig, Directory directory, IndexDeletionPolicy policy, SegmentInfos segmentInfos, InfoStream infoStream, IndexWriter writer, boolean initialIndexExists, boolean isReaderInit) throws IOException
      Initialize the deleter: find all previous commits in the Directory, incref the files they reference, call the policy to let it delete commits. This will remove any files not referenced by any of the commits.
      Throws:
      IOException - if there is a low-level IO error
  • Method Details

    • locked

      private boolean locked()
    • inflateGens

      static void inflateGens(SegmentInfos infos, Collection<String> files, InfoStream infoStream)
      Set all gens beyond what we currently see in the directory, to avoid double-write in cases where the previous IndexWriter did not gracefully close/rollback (e.g. os/machine crashed or lost power).
    • ensureOpen

      void ensureOpen() throws AlreadyClosedException
      Throws:
      AlreadyClosedException
    • isClosed

      boolean isClosed()
    • deleteCommits

      private void deleteCommits() throws IOException
      Remove the CommitPoints in the commitsToDelete List by DecRef'ing all files from each SegmentInfos.
      Throws:
      IOException
    • refresh

      void refresh() throws IOException
      Writer calls this when it has hit an error and had to roll back, to tell us that there may now be unreferenced files in the filesystem. So we re-list the filesystem and delete such files. If segmentName is non-null, we will only delete files corresponding to that segment.
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • revisitPolicy

      void revisitPolicy() throws IOException
      Revisits the IndexDeletionPolicy by calling its IndexDeletionPolicy.onCommit(List) again with the known commits. This is useful in cases where a deletion policy which holds onto index commits is used. The application may know that some commits are not held by the deletion policy anymore and call IndexWriter.deleteUnusedFiles(), which will attempt to delete the unused commits again.
      Throws:
      IOException
    • checkpoint

      public void checkpoint(SegmentInfos segmentInfos, boolean isCommit) throws IOException
      For definition of "check point" see IndexWriter comments: "Clarification: Check Points (and commits)". Writer calls this when it has made a "consistent change" to the index, meaning new files are written to the index and the in-memory SegmentInfos have been modified to point to those files. This may or may not be a commit (segments_N may or may not have been written). We simply incref the files referenced by the new SegmentInfos and decref the files we had previously seen (if any). If this is a commit, we also call the policy to give it a chance to remove other commits. If any commits are removed, we decref their files as well.
      Throws:
      IOException
    • incRef

      void incRef(SegmentInfos segmentInfos, boolean isCommit) throws IOException
      Throws:
      IOException
    • incRef

      void incRef(Collection<String> files)
    • incRef

      void incRef(String fileName)
    • decRef

      void decRef(Collection<String> files) throws IOException
      Decrefs all provided files, even on exception; throws first exception hit, if any.
      Throws:
      IOException
    • decRef

      private boolean decRef(String fileName)
      Returns true if the file should now be deleted.
    • decRef

      void decRef(SegmentInfos segmentInfos) throws IOException
      Throws:
      IOException
    • exists

      public boolean exists(String fileName)
    • getRefCount

      private IndexFileDeleter.RefCount getRefCount(String fileName)
    • deleteNewFiles

      void deleteNewFiles(Collection<String> files) throws IOException
      Deletes the specified files, but only if they are new (have not yet been incref'd).
      Throws:
      IOException
    • deleteFiles

      private void deleteFiles(Collection<String> names) throws IOException
      Throws:
      IOException
    • deleteFile

      private void deleteFile(String fileName) throws IOException
      Throws:
      IOException