Class IndexCopier

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, CopyOnReadStatsMBean

    public class IndexCopier
    extends java.lang.Object
    implements CopyOnReadStatsMBean, java.io.Closeable
    Copies index files to/from the local disk and the datastore.
    • Field Detail

      • REMOTE_ONLY

        public static final java.util.Set<java.lang.String> REMOTE_ONLY
    • Constructor Detail

      • IndexCopier

        public IndexCopier​(java.util.concurrent.Executor executor,
                           java.io.File indexRootDir)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • IndexCopier

        public IndexCopier​(java.util.concurrent.Executor executor,
                           java.io.File indexRootDir,
                           boolean prefetchEnabled)
                    throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • wrapForRead

        public Directory wrapForRead​(java.lang.String indexPath,
                                     LuceneIndexDefinition definition,
                                     Directory remote,
                                     java.lang.String dirName)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • isClosed

        public boolean isClosed()
      • getIndexDir

        public java.io.File getIndexDir​(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition definition,
                                        java.lang.String indexPath,
                                        java.lang.String dirName)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • deleteFile

        public boolean deleteFile​(Directory dir,
                                  java.lang.String fileName,
                                  boolean copiedFromRemote)
      • getNewestLocalFSTimestampFor

        public static long getNewestLocalFSTimestampFor​(java.util.Set<java.lang.String> names,
                                                        Directory localDir)
        This method would return the latest modification timestamp from the set of filenames on the file system. The parameter localDir is expected to be an instance of FSDirectory (or wrapped one in FilterDirectory. If this assumption doesn't hold, the method would return -1. Each of file names are expected to be existing in localDir. If this fails the method shall return -1. In case of any error while computing modified timestamps on the file system, the method shall return -1.
        Parameters:
        names - file names to evaluate on local FS
        localDir - Directory implementation to be used to get the files
        Returns:
        latest timestamp or -1 (with logs) in case of any doubt
      • isFileModifiedBefore

        public static boolean isFileModifiedBefore​(java.lang.String name,
                                                   Directory localDir,
                                                   long millis)
        Parameters:
        name - file name to evaluate on local FS
        localDir - Directory implementation to be used to get the file
        millis - timestamp to compare file's modified timestamp against
        Returns:
        true if file referred to be name is modified before millis; false otherwise
      • startCopy

        public long startCopy​(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile file)
      • isCopyInProgress

        public boolean isCopyInProgress​(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile file)
      • waitForCopyCompletion

        public void waitForCopyCompletion​(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile file,
                                          long timeoutMillis)
        Waits for maximum of timeoutMillis while checking if file isn't being copied already. The method can return before timeoutMillis if it got interrupted. So, if required then the caller should check using isCopyInProgress and wait again.
        Parameters:
        file -
        timeoutMillis -
      • doneCopy

        public void doneCopy​(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile file,
                             long start)
      • skippedUpload

        public void skippedUpload​(long skippedFilesSize)
      • scheduledForCopy

        public void scheduledForCopy()
      • copyDone

        public void copyDone()
      • readFromRemote

        public void readFromRemote​(boolean reader)
      • readFromLocal

        public void readFromLocal​(boolean reader)
      • foundInvalidFile

        public void foundInvalidFile()
      • getInvalidFileCount

        public int getInvalidFileCount()