Class FilePageStoreManager
- java.lang.Object
-
- org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter
-
- org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager
-
- All Implemented Interfaces:
IgnitePageStoreManager,PageStoreCollection,GridCacheSharedManager,PageReadWriteManager,IgniteChangeGlobalStateSupport
public class FilePageStoreManager extends GridCacheSharedManagerAdapter implements IgnitePageStoreManager, PageStoreCollection
File page store manager.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classFilePageStoreManager.LongOperationAsyncExecutorSynchronization wrapper for long operations that should be executed asynchronously and operations that can not be executed in parallel with long operation.
-
Field Summary
Fields Modifier and Type Field Description static StringCACHE_DATA_FILENAMEstatic StringCACHE_DATA_TMP_FILENAMEstatic StringCACHE_DIR_PREFIXstatic StringCACHE_GRP_DIR_PREFIXstatic StringCORRUPTED_DATA_FILES_MNTC_TASK_NAMEUnique name for corrupted data files maintenance task.static Predicate<File>DATA_DIR_FILTERstatic StringDFLT_STORE_DIRstatic StringFILE_SUFFIXFile suffix.static StringINDEX_FILE_NAMEstatic StringINDEX_FILE_PREFIXstatic StringPART_FILE_PREFIXPartition file prefix.static StringPART_FILE_TEMPLATEstatic PathMatcherTMP_FILE_MATCHERMatcher for searching of *.tmp files.static StringTMP_SUFFIXSuffix for tmp filesstatic StringZIP_SUFFIXSuffix for zip files-
Fields inherited from class org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter
cctx, diagnosticLog, log
-
-
Constructor Summary
Constructors Constructor Description FilePageStoreManager(GridKernalContext ctx)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description longallocatePage(int grpId, int partId, byte flags)Allocates a page for the given page space.voidbeginRecover()Invoked before starting checkpoint recover.static File[]cacheDataFiles(File root)static List<File>cacheDirectories(File dir, Predicate<String> names)static FilecacheDirectory(File dir, int grpId)static StringcacheDirName(boolean isSharedGroup, String cacheOrGroupName)StringcacheDirName(int grpId)static StringcacheDirName(CacheConfiguration<?,?> ccfg)static StringcacheGroupName(File dir)static List<File>cachePartitionFiles(File cacheDir)static List<File>cachePartitionFiles(File cacheDir, String ext)FilecacheWorkDir(boolean isSharedGroup, String cacheOrGroupName)static FilecacheWorkDir(File storeWorkDir, String cacheDirName)FilecacheWorkDir(CacheConfiguration<?,?> ccfg)static booleancheckAndInitCacheWorkDir(File cacheWorkDir, IgniteLogger log)voidcleanupPageStoreIfMatch(Predicate<Integer> cacheGrpPred, boolean cleanFiles)Cleanup cache store whether it matches the provided predicate and if matched store was previously initizlized.voidcleanupPersistentSpace()Cleanup persistent space for all caches except metastore.voidcleanupPersistentSpace(CacheConfiguration cacheConfiguration)Cleanup persistent space for cache.EncryptedFileIOFactoryencryptedFileIoFactory(FileIOFactory plainFileIOFactory, int cacheGrpId)EncryptedFileIOFactoryencryptedFileIoFactory(FileIOFactory plainFileIOFactory, int cacheGrpId, EncryptionCacheKeyProvider encrKeyProvider)voidensure(int grpId, int partId)booleanexists(int grpId, int partId)Checks if partition store exists.voidfinishRecover()Invoked after checkpoint recover is finished.FileVersionCheckingFactorygetPageStoreFactory(int grpId, boolean encrypted)FileVersionCheckingFactorygetPageStoreFactory(int grpId, EncryptionCacheKeyProvider encrKeyProvider)FileIOFactorygetPageStoreFileIoFactory()static @NotNull FilegetPartitionFile(File workDir, String cacheDirName, int partId)static StringgetPartitionFileName(int partId)PathgetPath(boolean isSharedGroup, String cacheOrGroupName, int partId)PageStoregetStore(int grpId, int partId)Collection<PageStore>getStores(int grpId)booleanhasIndexStore(int grpId)voidinitializeForCache(CacheGroupDescriptor grpDesc, CacheConfiguration<?,?> ccfg)Callback called when a cache is starting.voidinitializeForMetastorage()Initializes disk cache store structures.voidonActivate(GridKernalContext kctx)Called when cluster performing activation.voidonDeActivate(GridKernalContext kctx)Called when cluster performing deactivation.voidonKernalStop0(boolean cancel)longpageOffset(int grpId, long pageId)Gets page offset within the page store file.intpages(int grpId, int partId)Gets total number of allocated pages for the given space.longpagesAllocated(int grpId)Calculates number of pages currently allocated for given cache group.intpageSize()static intpartId(String partFileName)voidread(int grpId, long pageId, ByteBuffer pageBuf, boolean keepCrc)Reads a page for the given cache ID.voidreadHeader(int grpId, int partId, ByteBuffer buf)Reads a header of a page store.voidsetPageStoreFileIOFactories(FileIOFactory pageStoreFileIoFactory, FileIOFactory pageStoreV1FileIoFactory)voidshutdownForCacheGroup(CacheGroupContext grp, boolean destroy)Callback called when a cache is stopping.voidstart0()voidstop0(boolean cancel)voidsync(int grpId, int partId)Makes sure that all previous writes to the store has been written to disk.voidtruncate(int grpId, int partId, int tag)Callback called when a partition for the given cache is evicted from the local node.FileworkDir()PageStorewrite(int grpId, long pageId, ByteBuffer pageBuf, int tag, boolean calculateCrc)Writes the page for the given cache ID.-
Methods inherited from class org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter
context, isStopping, kernalStartInfo, kernalStopInfo, onDisconnected, onKernalStart, onKernalStart0, onKernalStop, onReconnected, printMemoryStats, start, startInfo, stop, stopInfo, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.ignite.internal.processors.cache.GridCacheSharedManager
onDisconnected, onKernalStart, onKernalStop, onReconnected, printMemoryStats, start, stop
-
-
-
-
Field Detail
-
FILE_SUFFIX
public static final String FILE_SUFFIX
File suffix.- See Also:
- Constant Field Values
-
ZIP_SUFFIX
public static final String ZIP_SUFFIX
Suffix for zip files- See Also:
- Constant Field Values
-
TMP_SUFFIX
public static final String TMP_SUFFIX
Suffix for tmp files- See Also:
- Constant Field Values
-
PART_FILE_PREFIX
public static final String PART_FILE_PREFIX
Partition file prefix.- See Also:
- Constant Field Values
-
INDEX_FILE_PREFIX
public static final String INDEX_FILE_PREFIX
- See Also:
- Constant Field Values
-
INDEX_FILE_NAME
public static final String INDEX_FILE_NAME
- See Also:
- Constant Field Values
-
PART_FILE_TEMPLATE
public static final String PART_FILE_TEMPLATE
- See Also:
- Constant Field Values
-
CACHE_DIR_PREFIX
public static final String CACHE_DIR_PREFIX
- See Also:
- Constant Field Values
-
CACHE_GRP_DIR_PREFIX
public static final String CACHE_GRP_DIR_PREFIX
- See Also:
- Constant Field Values
-
CACHE_DATA_FILENAME
public static final String CACHE_DATA_FILENAME
- See Also:
- Constant Field Values
-
CACHE_DATA_TMP_FILENAME
public static final String CACHE_DATA_TMP_FILENAME
- See Also:
- Constant Field Values
-
DFLT_STORE_DIR
public static final String DFLT_STORE_DIR
- See Also:
- Constant Field Values
-
TMP_FILE_MATCHER
public static final PathMatcher TMP_FILE_MATCHER
Matcher for searching of *.tmp files.
-
CORRUPTED_DATA_FILES_MNTC_TASK_NAME
public static final String CORRUPTED_DATA_FILES_MNTC_TASK_NAME
Unique name for corrupted data files maintenance task.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FilePageStoreManager
public FilePageStoreManager(GridKernalContext ctx)
- Parameters:
ctx- Kernal context.
-
-
Method Detail
-
start0
public void start0() throws IgniteCheckedException- Overrides:
start0in classGridCacheSharedManagerAdapter- Throws:
IgniteCheckedException- If failed.
-
cleanupPersistentSpace
public void cleanupPersistentSpace(CacheConfiguration cacheConfiguration) throws IgniteCheckedException
Cleanup persistent space for cache.- Specified by:
cleanupPersistentSpacein interfaceIgnitePageStoreManager- Parameters:
cacheConfiguration- Cache configuration of cache which should be cleanup.- Throws:
IgniteCheckedException
-
cleanupPersistentSpace
public void cleanupPersistentSpace() throws IgniteCheckedExceptionCleanup persistent space for all caches except metastore.- Specified by:
cleanupPersistentSpacein interfaceIgnitePageStoreManager- Throws:
IgniteCheckedException
-
cleanupPageStoreIfMatch
public void cleanupPageStoreIfMatch(Predicate<Integer> cacheGrpPred, boolean cleanFiles)
Cleanup cache store whether it matches the provided predicate and if matched store was previously initizlized.- Specified by:
cleanupPageStoreIfMatchin interfaceIgnitePageStoreManager- Parameters:
cacheGrpPred- Predicate to match by id cache group stores to clean.cleanFiles-Trueto delete all persisted files related to particular store.
-
stop0
public void stop0(boolean cancel)
- Overrides:
stop0in classGridCacheSharedManagerAdapter- Parameters:
cancel- Cancel flag.
-
onKernalStop0
public void onKernalStop0(boolean cancel)
- Overrides:
onKernalStop0in classGridCacheSharedManagerAdapter- Parameters:
cancel- Cancel flag.
-
onActivate
public void onActivate(GridKernalContext kctx) throws IgniteCheckedException
Called when cluster performing activation.- Specified by:
onActivatein interfaceIgniteChangeGlobalStateSupport- Parameters:
kctx- Kernal context.- Throws:
IgniteCheckedException- If failed.
-
onDeActivate
public void onDeActivate(GridKernalContext kctx)
Called when cluster performing deactivation.- Specified by:
onDeActivatein interfaceIgniteChangeGlobalStateSupport- Parameters:
kctx- Kernal context.
-
beginRecover
public void beginRecover()
Invoked before starting checkpoint recover.- Specified by:
beginRecoverin interfaceIgnitePageStoreManager
-
finishRecover
public void finishRecover() throws IgniteCheckedExceptionInvoked after checkpoint recover is finished.- Specified by:
finishRecoverin interfaceIgnitePageStoreManager- Throws:
IgniteCheckedException
-
initializeForCache
public void initializeForCache(CacheGroupDescriptor grpDesc, CacheConfiguration<?,?> ccfg) throws IgniteCheckedException
Callback called when a cache is starting.- Specified by:
initializeForCachein interfaceIgnitePageStoreManager- Parameters:
grpDesc- Cache group descriptor.ccfg- Cache configuration.- Throws:
IgniteCheckedException- If failed to handle cache start callback.
-
initializeForMetastorage
public void initializeForMetastorage() throws IgniteCheckedExceptionInitializes disk cache store structures.- Specified by:
initializeForMetastoragein interfaceIgnitePageStoreManager- Throws:
IgniteCheckedException
-
shutdownForCacheGroup
public void shutdownForCacheGroup(CacheGroupContext grp, boolean destroy) throws IgniteCheckedException
Callback called when a cache is stopping. After this callback is invoked, no data associated with the given cache will be stored on disk.- Specified by:
shutdownForCacheGroupin interfaceIgnitePageStoreManager- Parameters:
grp- Cache group being stopped.destroy- Flag indicating if the cache is being destroyed and data should be cleaned.- Throws:
IgniteCheckedException- If failed to handle cache destroy callback.
-
truncate
public void truncate(int grpId, int partId, int tag) throws IgniteCheckedExceptionCallback called when a partition for the given cache is evicted from the local node. After this callback is invoked, no data associated with the partition will be stored on disk.- Specified by:
truncatein interfaceIgnitePageStoreManager- Parameters:
grpId- Cache group ID of the evicted partition.partId- Partition ID.tag- Partition tag (growing 1-based partition file version).- Throws:
IgniteCheckedException- If failed to handle partition destroy callback.
-
read
public void read(int grpId, long pageId, ByteBuffer pageBuf, boolean keepCrc) throws IgniteCheckedExceptionReads a page for the given cache ID. Cache ID may be0if the page is a meta page.- Specified by:
readin interfacePageReadWriteManager- Parameters:
grpId- Cache group ID.pageId- PageID to read.pageBuf- Page buffer to write to.keepCrc- Keep CRC flag.- Throws:
IgniteCheckedException- If failed to read the page.
-
exists
public boolean exists(int grpId, int partId) throws IgniteCheckedExceptionChecks if partition store exists.- Specified by:
existsin interfaceIgnitePageStoreManager- Parameters:
grpId- Cache group ID.partId- Partition ID.- Returns:
Trueif partition store exists.- Throws:
IgniteCheckedException- If failed.
-
readHeader
public void readHeader(int grpId, int partId, ByteBuffer buf) throws IgniteCheckedExceptionReads a header of a page store.- Specified by:
readHeaderin interfaceIgnitePageStoreManager- Parameters:
grpId- Cache group ID.partId- Partition ID.buf- Buffer to write to.- Throws:
IgniteCheckedException- If failed.
-
write
public PageStore write(int grpId, long pageId, ByteBuffer pageBuf, int tag, boolean calculateCrc) throws IgniteCheckedException
Writes the page for the given cache ID. Cache ID may be0if the page is a meta page.- Specified by:
writein interfaceIgnitePageStoreManager- Specified by:
writein interfacePageReadWriteManager- Parameters:
grpId- Cache group ID.pageId- Page ID.pageBuf- Page buffer to write.- Throws:
IgniteCheckedException- If failed to write page.
-
pageOffset
public long pageOffset(int grpId, long pageId) throws IgniteCheckedExceptionGets page offset within the page store file.- Specified by:
pageOffsetin interfaceIgnitePageStoreManager- Parameters:
grpId- Cache group ID.pageId- Page ID.- Returns:
- Page offset.
- Throws:
IgniteCheckedException- If failed.
-
getPageStoreFactory
public FileVersionCheckingFactory getPageStoreFactory(int grpId, boolean encrypted)
- Parameters:
grpId- Cache group id.encrypted-trueif cache group encryption enabled.- Returns:
- Factory to create page stores.
-
getPageStoreFactory
public FileVersionCheckingFactory getPageStoreFactory(int grpId, EncryptionCacheKeyProvider encrKeyProvider)
- Parameters:
grpId- Cache group id.encrKeyProvider- Encryption keys provider for encrypted IO. Ifnull, no encryption is used.- Returns:
- Factory to create page stores with certain encryption keys provider.
-
encryptedFileIoFactory
public EncryptedFileIOFactory encryptedFileIoFactory(FileIOFactory plainFileIOFactory, int cacheGrpId, EncryptionCacheKeyProvider encrKeyProvider)
- Parameters:
plainFileIOFactory- Not-encrypting file io factory.cacheGrpId- Cache group id.encrKeyProvider- Encryption keys provider for encrypted IO. Ifnull, no encryption is used.- Returns:
- Encrypted file IO factory.
-
encryptedFileIoFactory
public EncryptedFileIOFactory encryptedFileIoFactory(FileIOFactory plainFileIOFactory, int cacheGrpId)
- Returns:
- Encrypted file IO factory with stored internal encryption keys.
-
getPartitionFile
@NotNull public static @NotNull File getPartitionFile(File workDir, String cacheDirName, int partId)
- Parameters:
workDir- Cache work directory.cacheDirName- Cache directory name.partId- Partition id.- Returns:
- Partition file.
-
getPartitionFileName
public static String getPartitionFileName(int partId)
- Parameters:
partId- Partition id.- Returns:
- File name.
-
checkAndInitCacheWorkDir
public static boolean checkAndInitCacheWorkDir(File cacheWorkDir, IgniteLogger log) throws IgniteCheckedException
- Parameters:
cacheWorkDir- Cache work directory.- Throws:
IgniteCheckedException
-
sync
public void sync(int grpId, int partId) throws IgniteCheckedExceptionMakes sure that all previous writes to the store has been written to disk.- Specified by:
syncin interfaceIgnitePageStoreManager- Parameters:
grpId- Cache group ID to sync.partId- Partition ID to sync.- Throws:
IgniteCheckedException- If IO error occurred while running sync.
-
ensure
public void ensure(int grpId, int partId) throws IgniteCheckedException- Specified by:
ensurein interfaceIgnitePageStoreManager- Parameters:
grpId- Cache group ID.partId- Partition ID.- Throws:
IgniteCheckedException- If failed.
-
allocatePage
public long allocatePage(int grpId, int partId, byte flags) throws IgniteCheckedExceptionAllocates a page for the given page space.- Specified by:
allocatePagein interfaceIgnitePageStoreManager- Specified by:
allocatePagein interfacePageReadWriteManager- Parameters:
grpId- Cache group ID.partId- Partition ID. Used only ifflagsis not equal toPageIdAllocator.FLAG_IDX.flags- Page allocation flags.- Returns:
- Allocated page ID.
- Throws:
IgniteCheckedException- If IO exception occurred while allocating a page ID.
-
pages
public int pages(int grpId, int partId) throws IgniteCheckedExceptionGets total number of allocated pages for the given space.- Specified by:
pagesin interfaceIgnitePageStoreManager- Parameters:
grpId- Cache group ID.partId- Partition ID.- Returns:
- Number of allocated pages.
- Throws:
IgniteCheckedException- If failed.
-
cacheDirectories
public static List<File> cacheDirectories(File dir, Predicate<String> names)
- Parameters:
dir- Directory to check.names- Cache group names to filter.- Returns:
- Files that match cache or cache group pattern.
-
cacheDirectory
public static File cacheDirectory(File dir, int grpId)
- Parameters:
dir- Directory to check.grpId- Cache group id- Returns:
- Files that match cache or cache group pattern.
-
partId
public static int partId(String partFileName)
- Parameters:
partFileName- Partition file name.- Returns:
- Partition id.
-
cachePartitionFiles
public static List<File> cachePartitionFiles(File cacheDir)
- Parameters:
cacheDir- Cache directory to check.- Returns:
- List of cache partitions in given directory.
-
cachePartitionFiles
public static List<File> cachePartitionFiles(File cacheDir, String ext)
- Parameters:
cacheDir- Cache directory to check.ext- File extension.- Returns:
- List of cache partitions in given directory.
-
cacheGroupName
public static String cacheGroupName(File dir)
- Parameters:
dir- Cache directory on disk.- Returns:
- Cache or cache group name.
-
cacheDataFiles
public static File[] cacheDataFiles(File root)
- Parameters:
root- Root directory.- Returns:
- Array of cache data files.
-
hasIndexStore
public boolean hasIndexStore(int grpId)
- Specified by:
hasIndexStorein interfaceIgnitePageStoreManager- Parameters:
grpId- Cache group ID.- Returns:
Trueif index store for given cache group existed before node started.
-
pagesAllocated
public long pagesAllocated(int grpId)
Calculates number of pages currently allocated for given cache group.- Specified by:
pagesAllocatedin interfaceIgnitePageStoreManager- Parameters:
grpId- cache group id.- Returns:
- number of pages.
-
workDir
public File workDir()
- Returns:
- Store work dir. Includes consistent-id based folder
-
cacheWorkDir
public File cacheWorkDir(CacheConfiguration<?,?> ccfg)
- Parameters:
ccfg- Cache configuration.- Returns:
- Store dir for given cache.
-
cacheWorkDir
public File cacheWorkDir(boolean isSharedGroup, String cacheOrGroupName)
- Parameters:
isSharedGroup-Trueif cache is sharing the same `underlying` cache.cacheOrGroupName- Cache name.- Returns:
- Store directory for given cache.
-
cacheWorkDir
public static File cacheWorkDir(File storeWorkDir, String cacheDirName)
- Parameters:
cacheDirName- Cache directory name.- Returns:
- Store directory for given cache.
-
cacheDirName
public static String cacheDirName(boolean isSharedGroup, String cacheOrGroupName)
- Parameters:
isSharedGroup-Trueif cache is sharing the same `underlying` cache.cacheOrGroupName- Cache name.- Returns:
- The full cache directory name.
-
cacheDirName
public static String cacheDirName(CacheConfiguration<?,?> ccfg)
- Parameters:
ccfg- Cache configuration.- Returns:
- The full cache directory name.
-
cacheDirName
public String cacheDirName(int grpId) throws IgniteCheckedException
- Parameters:
grpId- Group id.- Returns:
- Name of cache group directory.
- Throws:
IgniteCheckedException- If cache group doesn't exist.
-
getStores
public Collection<PageStore> getStores(int grpId) throws IgniteCheckedException
- Specified by:
getStoresin interfacePageStoreCollection- Parameters:
grpId- Cache group ID.- Returns:
- Collection of related page stores.
- Throws:
IgniteCheckedException- If failed.
-
getStore
public PageStore getStore(int grpId, int partId) throws IgniteCheckedException
- Specified by:
getStorein interfacePageStoreCollection- Parameters:
grpId- Cache group ID.partId- Partition ID.- Returns:
- Page store for the corresponding parameters.
- Throws:
IgniteCheckedException- If cache or partition with the given ID was not created. Note: visible for testing.
-
setPageStoreFileIOFactories
public void setPageStoreFileIOFactories(FileIOFactory pageStoreFileIoFactory, FileIOFactory pageStoreV1FileIoFactory)
- Parameters:
pageStoreFileIoFactory- File IO factory to override default, may be used for blocked read-write.pageStoreV1FileIoFactory- File IO factory for reading V1 page store and for fast touching page files (non blocking).
-
getPageStoreFileIoFactory
public FileIOFactory getPageStoreFileIoFactory()
- Returns:
- File IO factory currently selected for page store.
-
pageSize
public int pageSize()
- Returns:
- Durable memory page size in bytes.
-
-