Class DefragmentationFileUtils
- java.lang.Object
-
- org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationFileUtils
-
public class DefragmentationFileUtils extends Object
Everything related to file management during defragmentation process.
-
-
Constructor Summary
Constructors Constructor Description DefragmentationFileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidbatchRenameDefragmentedCacheGroupPartitions(File workDir, IgniteLogger log)Failure-tolerant batch rename of defragmented partition files.static voidbeforeInitPageStores(File workDir, IgniteLogger log)Performs cleanup of work dir before initializing file page stores.static FiledefragmentationCompletionMarkerFile(File workDir)Return defragmentation completion marker file.static FiledefragmentedIndexFile(File workDir)Return file namedindex-dfrg.binin given folder.static FiledefragmentedIndexTmpFile(File workDir)Return file namedindex-dfrg.bin.tmpin given folder.static FiledefragmentedPartFile(File workDir, int partId)Return file namedpart-dfrg-%d.binin given folder.static FiledefragmentedPartMappingFile(File workDir, int partId)Return file namedpart-map-%d.binin given folder.static FiledefragmentedPartTmpFile(File workDir, int partId)Return file namedpart-dfrg-%d.bin.tmpin given folder.static voiddeleteLeftovers(File workDir)Deletes all defragmentation related file from work directory, except for completion marker.static voidrenameTempIndexFile(File workDir)Rename temporary index defragmentation file to a finalized one.static voidrenameTempPartitionFile(File workDir, int partId)Rename temporary partition defragmentation file to a finalized one.static booleanskipAlreadyDefragmentedCacheGroup(File workDir, int grpId, IgniteLogger log)Checks whether cache group defragmentation completed or not.static booleanskipAlreadyDefragmentedPartition(File workDir, int grpId, int partId, IgniteLogger log)Checks whether partition has already been defragmented or not.static voidwriteDefragmentationCompletionMarker(FileIOFactory ioFactory, File workDir, IgniteLogger log)Creates empty completion marker file in given directory.
-
-
-
Method Detail
-
beforeInitPageStores
public static void beforeInitPageStores(File workDir, IgniteLogger log) throws IgniteCheckedException
Performs cleanup of work dir before initializing file page stores. Will finish batch renaming if defragmentation was completed or delete garbage if it wasn't.- Parameters:
workDir- Cache group working directory.log- Logger to write messages.- Throws:
IgniteCheckedException- IfIOExceptionoccurred.
-
deleteLeftovers
public static void deleteLeftovers(File workDir)
Deletes all defragmentation related file from work directory, except for completion marker.- Parameters:
workDir- Cache group working directory.
-
skipAlreadyDefragmentedCacheGroup
public static boolean skipAlreadyDefragmentedCacheGroup(File workDir, int grpId, IgniteLogger log) throws IgniteException
Checks whether cache group defragmentation completed or not. Completes it if all that's left is renaming.- Parameters:
workDir- Cache group working directory.grpId- Cache group Id of cache group belonging to the given working directory.log- Logger to write messages.- Returns:
trueif given cache group is already defragmented.- Throws:
IgniteException- IfIOExceptionoccurred.- See Also:
defragmentationCompletionMarkerFile(File)
-
skipAlreadyDefragmentedPartition
public static boolean skipAlreadyDefragmentedPartition(File workDir, int grpId, int partId, IgniteLogger log) throws IgniteException
Checks whether partition has already been defragmented or not. Cleans corrupted data if previous failed defragmentation attempt was found.- Parameters:
workDir- Cache group working directory.grpId- Cache group Id of cache group belonging to the given working directory.partId- Partition index to check.log- Logger to write messages.- Returns:
trueif given partition is already defragmented.- Throws:
IgniteException- IfIOExceptionoccurred.- See Also:
defragmentedPartTmpFile(File, int),defragmentedPartFile(File, int),defragmentedPartMappingFile(File, int)
-
batchRenameDefragmentedCacheGroupPartitions
public static void batchRenameDefragmentedCacheGroupPartitions(File workDir, IgniteLogger log) throws IgniteException
Failure-tolerant batch rename of defragmented partition files. Deletes all link mapping files old partition and index files, renaming defragmentated files in the process. Can be run on the same folder multiple times if failed for some reason. Does something only if completion marker is present in the folder. This marker won't be deleted in the end. Deletion of the marker must be done outside of defragmentation mode to prevent cache groups to be defragmentated several times in case of failures.- Parameters:
workDir- Cache group working directory.log- Logger to write messages.- Throws:
IgniteException- IfIOExceptionoccurred.- See Also:
writeDefragmentationCompletionMarker(FileIOFactory, File, IgniteLogger)
-
defragmentedIndexTmpFile
public static File defragmentedIndexTmpFile(File workDir)
Return file namedindex-dfrg.bin.tmpin given folder. It will be used for storing defragmented index partition during the process.- Parameters:
workDir- Cache group working directory.- Returns:
- File.
- See Also:
defragmentedIndexFile(File)
-
defragmentedIndexFile
public static File defragmentedIndexFile(File workDir)
Return file namedindex-dfrg.binin given folder. It will be used for storing defragmented index partition when the process is over.- Parameters:
workDir- Cache group working directory.- Returns:
- File.
- See Also:
defragmentedIndexTmpFile(File)
-
renameTempIndexFile
public static void renameTempIndexFile(File workDir) throws IgniteException
Rename temporary index defragmentation file to a finalized one.- Parameters:
workDir- Cache group working directory.- Throws:
IgniteException- IfIOExceptionoccurred.- See Also:
defragmentedIndexTmpFile(File),defragmentedIndexFile(File)
-
defragmentedPartTmpFile
public static File defragmentedPartTmpFile(File workDir, int partId)
Return file namedpart-dfrg-%d.bin.tmpin given folder. It will be used for storing defragmented data partition during the process.- Parameters:
workDir- Cache group working directory.partId- Partition index, will be substituted into file name.- Returns:
- File.
- See Also:
defragmentedPartFile(File, int)
-
defragmentedPartFile
public static File defragmentedPartFile(File workDir, int partId)
Return file namedpart-dfrg-%d.binin given folder. It will be used for storing defragmented data partition when the process is over.- Parameters:
workDir- Cache group working directory.partId- Partition index, will be substituted into file name.- Returns:
- File.
- See Also:
defragmentedPartTmpFile(File, int)
-
renameTempPartitionFile
public static void renameTempPartitionFile(File workDir, int partId) throws IgniteException
Rename temporary partition defragmentation file to a finalized one.- Parameters:
workDir- Cache group working directory.partId- Partition index.- Throws:
IgniteException- IfIOExceptionoccurred.- See Also:
defragmentedPartTmpFile(File, int),defragmentedPartFile(File, int)
-
defragmentedPartMappingFile
public static File defragmentedPartMappingFile(File workDir, int partId)
Return file namedpart-map-%d.binin given folder. It will be used for storing defragmention links mapping for given partition during and after defragmentation process. No temporary counterpart is required here.- Parameters:
workDir- Cache group working directory.partId- Partition index, will be substituted into file name.- Returns:
- File.
- See Also:
LinkMap
-
defragmentationCompletionMarkerFile
public static File defragmentationCompletionMarkerFile(File workDir)
Return defragmentation completion marker file. This file can only be created when all partitions and index are defragmented and renamed from their original*.tmpversions. Presence of this file signals that no data will be lost if original partitions are deleted and batch rename process can be safely initiated.- Parameters:
workDir- Cache group working directory.- Returns:
- File.
- See Also:
writeDefragmentationCompletionMarker(FileIOFactory, File, IgniteLogger),batchRenameDefragmentedCacheGroupPartitions(File, IgniteLogger)
-
writeDefragmentationCompletionMarker
public static void writeDefragmentationCompletionMarker(FileIOFactory ioFactory, File workDir, IgniteLogger log) throws IgniteException
Creates empty completion marker file in given directory.- Parameters:
ioFactory- File IO factory.workDir- Cache group working directory.log- Logger to write messages.- Throws:
IgniteException- IfIOExceptionoccurred.- See Also:
defragmentationCompletionMarkerFile(File)
-
-