Class SplitIndexFileHelper
- java.lang.Object
-
- com.atlassian.confluence.upgrade.upgradetask.splitindex.SplitIndexFileHelper
-
public final class SplitIndexFileHelper extends Object
Manager to help with copying files and getting statistics or reporting on sizes.- Since:
- 7.9.0
-
-
Constructor Summary
Constructors Constructor Description SplitIndexFileHelper(@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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static 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.Map<String,FileInfo>
collectIndexFileInfos()
Gets the size of a Directory by sizing all the files.static Map<String,FileInfo>
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
createEmptyIndexIfNone()
If there is an index, this will just open it and do nothing.File
getIndex()
SplitIndexPhase
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
hasFiles(File location)
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
overrideWithEmptyIndex()
This will create an empty index in the directory, regardless if the index existed here or not.void
purgeAllFiles()
deletes all files in the folder where this SplitIndexFileManager is pointed at.void
purgeChanges()
void
purgeContent()
static org.apache.lucene.index.DirectoryReader
refresh(org.apache.lucene.index.DirectoryReader reader)
Refreshes a reader so the written changes become visible.@NonNull IndexInfo
refreshIndexInfo()
Force refresh of the indexInfo.void
removePhase()
Removes the state filevoid
setPhase(@NonNull SplitIndexPhase phase)
Sets the phase in the index (writes state file)
-
-
-
Constructor Detail
-
SplitIndexFileHelper
public SplitIndexFileHelper(@NonNull String location, @NonNull String name)
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
public SplitIndexFileHelper(@NonNull File index, @NonNull String name)
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 Detail
-
getIndex
public File getIndex()
-
collectIndexFileInfos
public Map<String,FileInfo> 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
public SplitIndexPhase getPhase()
Tries to read the phase file if it exists- Returns:
- SplitIndexPhase or null
-
setPhase
public void setPhase(@NonNull SplitIndexPhase phase)
Sets the phase in the index (writes state file)- Parameters:
phase
- SplitIndexPhase
-
removePhase
public void removePhase()
Removes the state file
-
collectIndexFileInfos
public static Map<String,FileInfo> collectIndexFileInfos(@NonNull File folder)
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
public static void copyFilesToFolder(@NonNull Collection<FileInfo> source, @NonNull File target)
Copies all the files in the FileInfo list to the target folder- Parameters:
source
- Collection of FileInfotarget
- File target location
-
getTotalSize
public static long getTotalSize(@NonNull Collection<FileInfo> files)
Sums the sizes of the files in the FileInfo list- Parameters:
files
- List of FileInfo- Returns:
- long
-
bytesToHumanReadable
public static 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. Ends at TB.- Parameters:
bytes
- long size in bytes- Returns:
- String human readable size
-
refreshIndexInfo
public @NonNull IndexInfo 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
public static boolean isLuceneIndex(@NonNull File location)
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
public static boolean hasFiles(File location)
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
public static long getTotalZipEntriesSize(File zipFile) throws IOException
Returns the total size in bytes of the entries for given archive- Parameters:
zipFile
- file with zip archive- Throws:
IOException
-
getTotalZipEntriesSize
public static long getTotalZipEntriesSize(ZipEntry[] entries)
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
public void purgeAllFiles() throws UpgradeException
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
-
-