Class IndexCopier
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.index.lucene.IndexCopier
-
- All Implemented Interfaces:
Closeable,AutoCloseable,CopyOnReadStatsMBean
public class IndexCopier extends Object implements CopyOnReadStatsMBean, Closeable
Copies index files to/from the local disk and the datastore.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceIndexCopier.COWDirectoryTracker
-
Field Summary
Fields Modifier and Type Field Description static Set<String>REMOTE_ONLY-
Fields inherited from interface org.apache.jackrabbit.oak.plugins.index.lucene.CopyOnReadStatsMBean
TYPE
-
-
Constructor Summary
Constructors Constructor Description IndexCopier(Executor executor, File indexRootDir)IndexCopier(Executor executor, File indexRootDir, boolean prefetchEnabled)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidcopyDone()booleandeleteFile(Directory dir, String fileName, boolean copiedFromRemote)voiddoneCopy(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile file, long start)voidfoundInvalidFile()intgetCopyInProgressCount()String[]getCopyInProgressDetails()StringgetCopyInProgressSize()intgetDeletedFilesCount()intgetDownloadCount()StringgetDownloadSize()longgetDownloadTime()StringgetGarbageCollectedSize()String[]getGarbageDetails()StringgetGarbageSize()FilegetIndexDir(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition definition, String indexPath, String dirName)TabularDatagetIndexPathMapping()intgetInvalidFileCount()longgetLocalIndexDirSize()StringgetLocalIndexSize()intgetMaxCopyInProgressCount()intgetMaxScheduledForCopyCount()static longgetNewestLocalFSTimestampFor(Set<String> names, Directory localDir)This method would return the latest modification timestamp from the set of filenameson the file system.intgetReaderLocalReadCount()intgetReaderRemoteReadCount()intgetScheduledForCopyCount()StringgetSkippedFromUploadSize()intgetUploadCount()StringgetUploadSize()longgetUploadTime()intgetWriterLocalReadCount()intgetWriterRemoteReadCount()booleanisClosed()booleanisCopyInProgress(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile file)static booleanisFileModifiedBefore(String name, Directory localDir, long millis)booleanisPrefetchEnabled()voidreadFromLocal(boolean reader)voidreadFromRemote(boolean reader)voidscheduledForCopy()voidskippedUpload(long skippedFilesSize)longstartCopy(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile file)voidwaitForCopyCompletion(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile file, long timeoutMillis)Waits for maximum oftimeoutMilliswhile checking iffileisn't being copied already.DirectorywrapForRead(String indexPath, LuceneIndexDefinition definition, Directory remote, String dirName)DirectorywrapForWrite(LuceneIndexDefinition definition, Directory remote, boolean reindexMode, String dirName, IndexCopier.COWDirectoryTracker cowDirectoryTracker)
-
-
-
Constructor Detail
-
IndexCopier
public IndexCopier(Executor executor, File indexRootDir) throws IOException
- Throws:
IOException
-
IndexCopier
public IndexCopier(Executor executor, File indexRootDir, boolean prefetchEnabled) throws IOException
- Throws:
IOException
-
-
Method Detail
-
wrapForRead
public Directory wrapForRead(String indexPath, LuceneIndexDefinition definition, Directory remote, String dirName) throws IOException
- Throws:
IOException
-
wrapForWrite
public Directory wrapForWrite(LuceneIndexDefinition definition, Directory remote, boolean reindexMode, String dirName, IndexCopier.COWDirectoryTracker cowDirectoryTracker) throws IOException
- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
isClosed
public boolean isClosed()
-
getIndexDir
public File getIndexDir(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition definition, String indexPath, String dirName) throws IOException
- Throws:
IOException
-
getNewestLocalFSTimestampFor
public static long getNewestLocalFSTimestampFor(Set<String> names, Directory localDir)
This method would return the latest modification timestamp from the set of filenameson the file system. The parameterlocalDiris expected to be an instance ofFSDirectory(or wrapped one inFilterDirectory. If this assumption doesn't hold, the method would return -1. Each of file names are expected to be existing inlocalDir. 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 FSlocalDir-Directoryimplementation to be used to get the files- Returns:
- latest timestamp or -1 (with logs) in case of any doubt
-
isFileModifiedBefore
public static boolean isFileModifiedBefore(String name, Directory localDir, long millis)
- Parameters:
name- file name to evaluate on local FSlocalDir-Directoryimplementation to be used to get the filemillis- timestamp to compare file's modified timestamp against- Returns:
trueif file referred to benameis modified beforemillis; 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 oftimeoutMilliswhile checking iffileisn't being copied already. The method can return beforetimeoutMillisif it got interrupted. So, if required then the caller should check usingisCopyInProgressand 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()
-
getIndexPathMapping
public TabularData getIndexPathMapping()
- Specified by:
getIndexPathMappingin interfaceCopyOnReadStatsMBean
-
isPrefetchEnabled
public boolean isPrefetchEnabled()
- Specified by:
isPrefetchEnabledin interfaceCopyOnReadStatsMBean
-
getReaderLocalReadCount
public int getReaderLocalReadCount()
- Specified by:
getReaderLocalReadCountin interfaceCopyOnReadStatsMBean
-
getReaderRemoteReadCount
public int getReaderRemoteReadCount()
- Specified by:
getReaderRemoteReadCountin interfaceCopyOnReadStatsMBean
-
getWriterLocalReadCount
public int getWriterLocalReadCount()
- Specified by:
getWriterLocalReadCountin interfaceCopyOnReadStatsMBean
-
getWriterRemoteReadCount
public int getWriterRemoteReadCount()
- Specified by:
getWriterRemoteReadCountin interfaceCopyOnReadStatsMBean
-
getInvalidFileCount
public int getInvalidFileCount()
-
getDownloadSize
public String getDownloadSize()
- Specified by:
getDownloadSizein interfaceCopyOnReadStatsMBean
-
getDownloadTime
public long getDownloadTime()
- Specified by:
getDownloadTimein interfaceCopyOnReadStatsMBean
-
getDownloadCount
public int getDownloadCount()
- Specified by:
getDownloadCountin interfaceCopyOnReadStatsMBean
-
getUploadCount
public int getUploadCount()
- Specified by:
getUploadCountin interfaceCopyOnReadStatsMBean
-
getUploadSize
public String getUploadSize()
- Specified by:
getUploadSizein interfaceCopyOnReadStatsMBean
-
getUploadTime
public long getUploadTime()
- Specified by:
getUploadTimein interfaceCopyOnReadStatsMBean
-
getLocalIndexSize
public String getLocalIndexSize()
- Specified by:
getLocalIndexSizein interfaceCopyOnReadStatsMBean
-
getLocalIndexDirSize
public long getLocalIndexDirSize()
- Specified by:
getLocalIndexDirSizein interfaceCopyOnReadStatsMBean
-
getGarbageDetails
public String[] getGarbageDetails()
- Specified by:
getGarbageDetailsin interfaceCopyOnReadStatsMBean
-
getGarbageSize
public String getGarbageSize()
- Specified by:
getGarbageSizein interfaceCopyOnReadStatsMBean
-
getScheduledForCopyCount
public int getScheduledForCopyCount()
- Specified by:
getScheduledForCopyCountin interfaceCopyOnReadStatsMBean
-
getCopyInProgressCount
public int getCopyInProgressCount()
- Specified by:
getCopyInProgressCountin interfaceCopyOnReadStatsMBean
-
getCopyInProgressSize
public String getCopyInProgressSize()
- Specified by:
getCopyInProgressSizein interfaceCopyOnReadStatsMBean
-
getMaxCopyInProgressCount
public int getMaxCopyInProgressCount()
- Specified by:
getMaxCopyInProgressCountin interfaceCopyOnReadStatsMBean
-
getMaxScheduledForCopyCount
public int getMaxScheduledForCopyCount()
- Specified by:
getMaxScheduledForCopyCountin interfaceCopyOnReadStatsMBean
-
getSkippedFromUploadSize
public String getSkippedFromUploadSize()
- Specified by:
getSkippedFromUploadSizein interfaceCopyOnReadStatsMBean
-
getCopyInProgressDetails
public String[] getCopyInProgressDetails()
- Specified by:
getCopyInProgressDetailsin interfaceCopyOnReadStatsMBean
-
getDeletedFilesCount
public int getDeletedFilesCount()
- Specified by:
getDeletedFilesCountin interfaceCopyOnReadStatsMBean
-
getGarbageCollectedSize
public String getGarbageCollectedSize()
- Specified by:
getGarbageCollectedSizein interfaceCopyOnReadStatsMBean
-
-