Class FileDeleter

java.lang.Object
org.apache.lucene.util.FileDeleter

public final class FileDeleter extends Object
This class provides ability to track the reference counts of a set of index files and delete them when their counts decreased to 0.

This class is NOT thread-safe, the user should make sure the thread-safety themselves

NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
  • Constructor Details

    • FileDeleter

      public FileDeleter(Directory directory, BiConsumer<FileDeleter.MsgType,String> messenger)
      Create a new FileDeleter with a messenger consumes various verbose messages
      Parameters:
      directory - the index directory
      messenger - two arguments will be passed in, FileDeleter.MsgType and the actual message in String. Can be null if the user do not want debug infos
  • Method Details

    • incRef

      public void incRef(Collection<String> fileNames)
    • incRef

      public void incRef(String fileName)
    • decRef

      public void decRef(Collection<String> fileNames) throws IOException
      Decrease ref counts for all provided files, delete them if ref counts down to 0, even on exception. Throw first exception hit, if any
      Throws:
      IOException
    • initRefCount

      public void initRefCount(String fileName)
      if the file is not yet recorded, this method will create a new RefCount object with count 0
    • getRefCount

      public int getRefCount(String fileName)
      get ref count for a provided file, if the file is not yet recorded, this method will return 0
    • getAllFiles

      public Set<String> getAllFiles()
      get all files, some of them may have ref count 0
    • exists

      public boolean exists(String fileName)
      return true only if file is touched and also has larger than 0 ref count
    • getUnrefedFiles

      public Set<String> getUnrefedFiles()
      get files that are touched but not incref'ed
    • deleteFilesIfNoRef

      public void deleteFilesIfNoRef(Collection<String> files) throws IOException
      delete only files that are unref'ed
      Throws:
      IOException
    • forceDelete

      public void forceDelete(String fileName) throws IOException
      Throws:
      IOException
    • deleteFileIfNoRef

      public void deleteFileIfNoRef(String fileName) throws IOException
      Throws:
      IOException