Class IndexCopier
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.index.lucene.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceIndexCopier.COWDirectoryTracker
-
Field Summary
Fields Modifier and Type Field Description static java.util.Set<java.lang.String>REMOTE_ONLY-
Fields inherited from interface org.apache.jackrabbit.oak.plugins.index.lucene.CopyOnReadStatsMBean
TYPE
-
-
Constructor Summary
Constructors Constructor Description IndexCopier(java.util.concurrent.Executor executor, java.io.File indexRootDir)IndexCopier(java.util.concurrent.Executor executor, java.io.File indexRootDir, boolean prefetchEnabled)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidcopyDone()booleandeleteFile(Directory dir, java.lang.String fileName, boolean copiedFromRemote)voiddoneCopy(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile file, long start)voidfoundInvalidFile()intgetCopyInProgressCount()java.lang.String[]getCopyInProgressDetails()java.lang.StringgetCopyInProgressSize()intgetDeletedFilesCount()intgetDownloadCount()java.lang.StringgetDownloadSize()longgetDownloadTime()java.lang.StringgetGarbageCollectedSize()java.lang.String[]getGarbageDetails()java.lang.StringgetGarbageSize()java.io.FilegetIndexDir(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition definition, java.lang.String indexPath, java.lang.String dirName)javax.management.openmbean.TabularDatagetIndexPathMapping()intgetInvalidFileCount()longgetLocalIndexDirSize()java.lang.StringgetLocalIndexSize()intgetMaxCopyInProgressCount()intgetMaxScheduledForCopyCount()static longgetNewestLocalFSTimestampFor(java.util.Set<java.lang.String> names, Directory localDir)This method would return the latest modification timestamp from the set of filenameson the file system.intgetReaderLocalReadCount()intgetReaderRemoteReadCount()intgetScheduledForCopyCount()java.lang.StringgetSkippedFromUploadSize()intgetUploadCount()java.lang.StringgetUploadSize()longgetUploadTime()intgetWriterLocalReadCount()intgetWriterRemoteReadCount()booleanisClosed()booleanisCopyInProgress(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile file)static booleanisFileModifiedBefore(java.lang.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(java.lang.String indexPath, LuceneIndexDefinition definition, Directory remote, java.lang.String dirName)DirectorywrapForWrite(LuceneIndexDefinition definition, Directory remote, boolean reindexMode, java.lang.String dirName, IndexCopier.COWDirectoryTracker cowDirectoryTracker)
-
-
-
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
-
wrapForWrite
public Directory wrapForWrite(LuceneIndexDefinition definition, Directory remote, boolean reindexMode, java.lang.String dirName, IndexCopier.COWDirectoryTracker cowDirectoryTracker) throws java.io.IOException
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.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 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(java.lang.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 javax.management.openmbean.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 java.lang.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 java.lang.String getUploadSize()
- Specified by:
getUploadSizein interfaceCopyOnReadStatsMBean
-
getUploadTime
public long getUploadTime()
- Specified by:
getUploadTimein interfaceCopyOnReadStatsMBean
-
getLocalIndexSize
public java.lang.String getLocalIndexSize()
- Specified by:
getLocalIndexSizein interfaceCopyOnReadStatsMBean
-
getLocalIndexDirSize
public long getLocalIndexDirSize()
- Specified by:
getLocalIndexDirSizein interfaceCopyOnReadStatsMBean
-
getGarbageDetails
public java.lang.String[] getGarbageDetails()
- Specified by:
getGarbageDetailsin interfaceCopyOnReadStatsMBean
-
getGarbageSize
public java.lang.String getGarbageSize()
- Specified by:
getGarbageSizein interfaceCopyOnReadStatsMBean
-
getScheduledForCopyCount
public int getScheduledForCopyCount()
- Specified by:
getScheduledForCopyCountin interfaceCopyOnReadStatsMBean
-
getCopyInProgressCount
public int getCopyInProgressCount()
- Specified by:
getCopyInProgressCountin interfaceCopyOnReadStatsMBean
-
getCopyInProgressSize
public java.lang.String getCopyInProgressSize()
- Specified by:
getCopyInProgressSizein interfaceCopyOnReadStatsMBean
-
getMaxCopyInProgressCount
public int getMaxCopyInProgressCount()
- Specified by:
getMaxCopyInProgressCountin interfaceCopyOnReadStatsMBean
-
getMaxScheduledForCopyCount
public int getMaxScheduledForCopyCount()
- Specified by:
getMaxScheduledForCopyCountin interfaceCopyOnReadStatsMBean
-
getSkippedFromUploadSize
public java.lang.String getSkippedFromUploadSize()
- Specified by:
getSkippedFromUploadSizein interfaceCopyOnReadStatsMBean
-
getCopyInProgressDetails
public java.lang.String[] getCopyInProgressDetails()
- Specified by:
getCopyInProgressDetailsin interfaceCopyOnReadStatsMBean
-
getDeletedFilesCount
public int getDeletedFilesCount()
- Specified by:
getDeletedFilesCountin interfaceCopyOnReadStatsMBean
-
getGarbageCollectedSize
public java.lang.String getGarbageCollectedSize()
- Specified by:
getGarbageCollectedSizein interfaceCopyOnReadStatsMBean
-
-