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 interface
IndexCopier.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 void
close()
void
copyDone()
boolean
deleteFile(Directory dir, java.lang.String fileName, boolean copiedFromRemote)
void
doneCopy(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile file, long start)
void
foundInvalidFile()
int
getCopyInProgressCount()
java.lang.String[]
getCopyInProgressDetails()
java.lang.String
getCopyInProgressSize()
int
getDeletedFilesCount()
int
getDownloadCount()
java.lang.String
getDownloadSize()
long
getDownloadTime()
java.lang.String
getGarbageCollectedSize()
java.lang.String[]
getGarbageDetails()
java.lang.String
getGarbageSize()
java.io.File
getIndexDir(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition definition, java.lang.String indexPath, java.lang.String dirName)
javax.management.openmbean.TabularData
getIndexPathMapping()
int
getInvalidFileCount()
long
getLocalIndexDirSize()
java.lang.String
getLocalIndexSize()
int
getMaxCopyInProgressCount()
int
getMaxScheduledForCopyCount()
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.int
getReaderLocalReadCount()
int
getReaderRemoteReadCount()
int
getScheduledForCopyCount()
java.lang.String
getSkippedFromUploadSize()
int
getUploadCount()
java.lang.String
getUploadSize()
long
getUploadTime()
int
getWriterLocalReadCount()
int
getWriterRemoteReadCount()
boolean
isClosed()
boolean
isCopyInProgress(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile file)
static boolean
isFileModifiedBefore(java.lang.String name, Directory localDir, long millis)
boolean
isPrefetchEnabled()
void
readFromLocal(boolean reader)
void
readFromRemote(boolean reader)
void
scheduledForCopy()
void
skippedUpload(long skippedFilesSize)
long
startCopy(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile file)
void
waitForCopyCompletion(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexFile file, long timeoutMillis)
Waits for maximum oftimeoutMillis
while checking iffile
isn't being copied already.Directory
wrapForRead(java.lang.String indexPath, LuceneIndexDefinition definition, Directory remote, java.lang.String dirName)
Directory
wrapForWrite(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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in 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 filenames
on the file system. The parameterlocalDir
is 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
-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 FSlocalDir
-Directory
implementation to be used to get the filemillis
- timestamp to compare file's modified timestamp against- Returns:
true
if file referred to bename
is 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 oftimeoutMillis
while checking iffile
isn't being copied already. The method can return beforetimeoutMillis
if it got interrupted. So, if required then the caller should check usingisCopyInProgress
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()
-
getIndexPathMapping
public javax.management.openmbean.TabularData getIndexPathMapping()
- Specified by:
getIndexPathMapping
in interfaceCopyOnReadStatsMBean
-
isPrefetchEnabled
public boolean isPrefetchEnabled()
- Specified by:
isPrefetchEnabled
in interfaceCopyOnReadStatsMBean
-
getReaderLocalReadCount
public int getReaderLocalReadCount()
- Specified by:
getReaderLocalReadCount
in interfaceCopyOnReadStatsMBean
-
getReaderRemoteReadCount
public int getReaderRemoteReadCount()
- Specified by:
getReaderRemoteReadCount
in interfaceCopyOnReadStatsMBean
-
getWriterLocalReadCount
public int getWriterLocalReadCount()
- Specified by:
getWriterLocalReadCount
in interfaceCopyOnReadStatsMBean
-
getWriterRemoteReadCount
public int getWriterRemoteReadCount()
- Specified by:
getWriterRemoteReadCount
in interfaceCopyOnReadStatsMBean
-
getInvalidFileCount
public int getInvalidFileCount()
-
getDownloadSize
public java.lang.String getDownloadSize()
- Specified by:
getDownloadSize
in interfaceCopyOnReadStatsMBean
-
getDownloadTime
public long getDownloadTime()
- Specified by:
getDownloadTime
in interfaceCopyOnReadStatsMBean
-
getDownloadCount
public int getDownloadCount()
- Specified by:
getDownloadCount
in interfaceCopyOnReadStatsMBean
-
getUploadCount
public int getUploadCount()
- Specified by:
getUploadCount
in interfaceCopyOnReadStatsMBean
-
getUploadSize
public java.lang.String getUploadSize()
- Specified by:
getUploadSize
in interfaceCopyOnReadStatsMBean
-
getUploadTime
public long getUploadTime()
- Specified by:
getUploadTime
in interfaceCopyOnReadStatsMBean
-
getLocalIndexSize
public java.lang.String getLocalIndexSize()
- Specified by:
getLocalIndexSize
in interfaceCopyOnReadStatsMBean
-
getLocalIndexDirSize
public long getLocalIndexDirSize()
- Specified by:
getLocalIndexDirSize
in interfaceCopyOnReadStatsMBean
-
getGarbageDetails
public java.lang.String[] getGarbageDetails()
- Specified by:
getGarbageDetails
in interfaceCopyOnReadStatsMBean
-
getGarbageSize
public java.lang.String getGarbageSize()
- Specified by:
getGarbageSize
in interfaceCopyOnReadStatsMBean
-
getScheduledForCopyCount
public int getScheduledForCopyCount()
- Specified by:
getScheduledForCopyCount
in interfaceCopyOnReadStatsMBean
-
getCopyInProgressCount
public int getCopyInProgressCount()
- Specified by:
getCopyInProgressCount
in interfaceCopyOnReadStatsMBean
-
getCopyInProgressSize
public java.lang.String getCopyInProgressSize()
- Specified by:
getCopyInProgressSize
in interfaceCopyOnReadStatsMBean
-
getMaxCopyInProgressCount
public int getMaxCopyInProgressCount()
- Specified by:
getMaxCopyInProgressCount
in interfaceCopyOnReadStatsMBean
-
getMaxScheduledForCopyCount
public int getMaxScheduledForCopyCount()
- Specified by:
getMaxScheduledForCopyCount
in interfaceCopyOnReadStatsMBean
-
getSkippedFromUploadSize
public java.lang.String getSkippedFromUploadSize()
- Specified by:
getSkippedFromUploadSize
in interfaceCopyOnReadStatsMBean
-
getCopyInProgressDetails
public java.lang.String[] getCopyInProgressDetails()
- Specified by:
getCopyInProgressDetails
in interfaceCopyOnReadStatsMBean
-
getDeletedFilesCount
public int getDeletedFilesCount()
- Specified by:
getDeletedFilesCount
in interfaceCopyOnReadStatsMBean
-
getGarbageCollectedSize
public java.lang.String getGarbageCollectedSize()
- Specified by:
getGarbageCollectedSize
in interfaceCopyOnReadStatsMBean
-
-