Class SplitIndexFileHelper
java.lang.Object
com.atlassian.confluence.upgrade.upgradetask.splitindex.SplitIndexFileHelper
Manager to help with copying files and getting statistics or reporting on sizes.
- Since:
- 7.9.0
-
Constructor Summary
ConstructorsConstructorDescriptionSplitIndexFileHelper
(@NonNull File index, @NonNull String name) Creates an instance of the SplitIndexFileManager to manage the files of the index located at indexLocationSplitIndexFileHelper
(@NonNull String location, @NonNull String name) Creates an instance of the SplitIndexFileManager to manage the files of the index located at indexLocation -
Method Summary
Modifier and TypeMethodDescriptionstatic String
bytesToHumanReadable
(long bytes) Formats bytes in a human readable form, rounds up and tries not to give too many decimals if size is above 100 E.g., 1000 becomes 1000 bytes, 1024 becomes 1 KB, 982.12 MB becomes 983 MB etc.Gets the size of a Directory by sizing all the files.collectIndexFileInfos
(@NonNull File folder) Gets the size of a Directory by sizing all the files.static void
copyFilesToFolder
(@NonNull Collection<FileInfo> source, @NonNull File target) Copies all the files in the FileInfo list to the target foldervoid
If there is an index, this will just open it and do nothing.getIndex()
getPhase()
Tries to read the phase file if it existsstatic long
getTotalSize
(@NonNull Collection<FileInfo> files) Sums the sizes of the files in the FileInfo liststatic long
getTotalZipEntriesSize
(File zipFile) Returns the total size in bytes of the entries for given archivestatic long
getTotalZipEntriesSize
(ZipEntry[] entries) Returns the total size in bytes of the entries for given archivestatic boolean
Checks if there are files in a directory (excludes subfolders!) so will count only real filesstatic boolean
isLuceneIndex
(@NonNull File location) Checks if a File is a Lucene index.void
This will create an empty index in the directory, regardless if the index existed here or not.void
deletes all files in the folder where this SplitIndexFileManager is pointed at.void
void
static org.apache.lucene.index.DirectoryReader
refresh
(org.apache.lucene.index.DirectoryReader reader) Refreshes a reader so the written changes become visible.@NonNull IndexInfo
Force refresh of the indexInfo.void
Removes the state filevoid
setPhase
(@NonNull SplitIndexPhase phase) Sets the phase in the index (writes state file)
-
Constructor Details
-
SplitIndexFileHelper
Creates an instance of the SplitIndexFileManager to manage the files of the index located at indexLocation- Parameters:
location
- String location of the index.name
- String name of the index (for logging purposes)
-
SplitIndexFileHelper
Creates an instance of the SplitIndexFileManager to manage the files of the index located at indexLocation- Parameters:
index
- File location of the index.name
- String name of the index (for logging purposes)
-
-
Method Details
-
getIndex
-
collectIndexFileInfos
Gets the size of a Directory by sizing all the files. Any subfolder is a separate index so is not included- Returns:
- long total Size
-
getPhase
Tries to read the phase file if it exists- Returns:
- SplitIndexPhase or null
-
setPhase
Sets the phase in the index (writes state file)- Parameters:
phase
- SplitIndexPhase
-
removePhase
public void removePhase()Removes the state file -
collectIndexFileInfos
Gets the size of a Directory by sizing all the files. Any subfolder is a separate index so is not included- Parameters:
folder
- File- Returns:
- long total Size
-
copyFilesToFolder
Copies all the files in the FileInfo list to the target folder- Parameters:
source
- Collection of FileInfotarget
- File target location
-
getTotalSize
Sums the sizes of the files in the FileInfo list- Parameters:
files
- List of FileInfo- Returns:
- long
-
bytesToHumanReadable
Formats bytes in a human readable form, rounds up and tries not to give too many decimals if size is above 100 E.g., 1000 becomes 1000 bytes, 1024 becomes 1 KB, 982.12 MB becomes 983 MB etc. Ends at TB.- Parameters:
bytes
- long size in bytes- Returns:
- String human readable size
-
refreshIndexInfo
Force refresh of the indexInfo. Will do a best effort to give information. For instance, it will find if the folder is empty. If it's not empty it will find if it's the correct version, and if it's the correct version, it will give you counts about the documents.- Returns:
- IndexInfo IndexInfo
-
isLuceneIndex
Checks if a File is a Lucene index. This will return true for any version of the index files. Please use refreshIndexInfo- Parameters:
location
- File- Returns:
- boolean true if the file exists and is a Lucene index
-
hasFiles
Checks if there are files in a directory (excludes subfolders!) so will count only real files- Parameters:
location
- File- Returns:
- boolean true if the directory has files
-
purgeContent
public void purgeContent() -
purgeChanges
public void purgeChanges() -
createEmptyIndexIfNone
public void createEmptyIndexIfNone()If there is an index, this will just open it and do nothing. If there is no index, this will create an empty one with a segment.seg and segment_1 file. -
overrideWithEmptyIndex
public void overrideWithEmptyIndex()This will create an empty index in the directory, regardless if the index existed here or not. -
getTotalZipEntriesSize
Returns the total size in bytes of the entries for given archive- Parameters:
zipFile
- file with zip archive- Throws:
IOException
-
getTotalZipEntriesSize
Returns the total size in bytes of the entries for given archive- Parameters:
entries
- ZipEntry[]
-
refresh
public static org.apache.lucene.index.DirectoryReader refresh(org.apache.lucene.index.DirectoryReader reader) throws IOException Refreshes a reader so the written changes become visible.- Parameters:
reader
- DirectoryReader- Returns:
- DirectoryReader
- Throws:
IOException
- when something goes wrong inside lucene code.
-
purgeAllFiles
deletes all files in the folder where this SplitIndexFileManager is pointed at. This is used when we detect an older lucene index file format. This can happen when someone upgrades confluence from a version prior to 5.2 (which was not using lucene 4.0+). In this case we empty the index folder and thus force a full reindex.- Throws:
UpgradeException
-