org.apache.ignite.internal.processors.cache.persistence.file

## 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, GridCacheSharedManager, IgniteChangeGlobalStateSupport

    public class FilePageStoreManager
    extends GridCacheSharedManagerAdapter
    implements IgnitePageStoreManager

File page store manager.

### Field Summary

Fields
`static String` `CACHE_DATA_FILENAME`
`static String` `CACHE_DIR_PREFIX`
`static String` `CACHE_GRP_DIR_PREFIX`
`static String` `FILE_SUFFIX` File suffix.
`static String` `INDEX_FILE_NAME`
`static String` `PART_FILE_PREFIX` Partition file prefix.
`static String` `PART_FILE_TEMPLATE`

### Fields inherited from class org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter

`cctx, diagnosticLog, log`

### Constructor Summary

Constructors
Constructor and Description
`FilePageStoreManager(GridKernalContext ctx)`

### Method Summary

Methods
`long` `allocatePage(int grpId, int partId, byte flags)` Allocates a page for the given page space.
`void` `beginRecover()` Invoked before starting checkpoint recover.
`File` `cacheWorkDir(CacheConfiguration ccfg)`
`void` `ensure(int grpId, int partId)`
`boolean` `exists(int grpId, int partId)` Checks if partition store exists.
`void` `finishRecover()` Invoked after checkpoint recover is finished.
`PageStore` `getStore(int grpId, int partId)`
`boolean` `hasIndexStore(int grpId)`
`void` `initializeForCache(CacheGroupDescriptor grpDesc, StoredCacheData cacheData)` Callback called when a cache is starting.
`long` `metaPageId(int grpId)` Gets meta page ID for specified cache.
`void` `onActivate(GridKernalContext kctx)` Called when cluster performing activation.
`void` `onDeActivate(GridKernalContext kctx)` Called when cluster performing deactivation.
`void` `onPartitionCreated(int grpId, int partId)` Callback called when a partition is created on the local node.
`void` `onPartitionDestroyed(int grpId, int partId, int tag)` Callback called when a partition for the given cache is evicted from the local node.
`long` `pageOffset(int grpId, long pageId)` Gets page offset within the page store file.
`int` `pages(int grpId, int partId)` Gets total number of allocated pages for the given space.
`void` `read(int grpId, long pageId, ByteBuffer pageBuf)` Reads a page for the given cache ID.
`void` `read(int cacheId, long pageId, ByteBuffer pageBuf, boolean keepCrc)` Will preserve crc in buffer if keepCrc is true.
`Map<String,StoredCacheData>` `readCacheConfigurations()`
`void` `readHeader(int grpId, int partId, ByteBuffer buf)` Reads a header of a page store.
`void` `shutdownForCacheGroup(CacheGroupContext grp, boolean destroy)` Callback called when a cache is stopping.
`void` `start0()`
`void` `stop0(boolean cancel)`
`void` `storeCacheData(StoredCacheData cacheData)`
`void` `sync(int grpId, int partId)` Makes sure that all previous writes to the store has been written to disk.
`File` `workDir()`
`void` `write(int grpId, long pageId, ByteBuffer pageBuf, int tag)` Writes the page for the given cache ID.
`PageStore` `writeInternal(int cacheId, long pageId, ByteBuffer pageBuf, int tag)`

### Methods inherited from class org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter

`context, isStopping, kernalStartInfo, kernalStopInfo, log, onDisconnected, onKernalStop, onKernalStop0, 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, onKernalStop, printMemoryStats, start, stop`

### Field Detail

#### FILE_SUFFIX

    public static final String FILE_SUFFIX

File suffix.

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_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

### Constructor Detail

#### FilePageStoreManager

    public FilePageStoreManager(GridKernalContext ctx)

Parameters:
  `ctx` - Kernal context.

### Method Detail

#### start0

    public void start0()
                throws IgniteCheckedException

Overrides:
  `start0` in class `GridCacheSharedManagerAdapter`
Throws:
  `IgniteCheckedException` - If failed.

#### stop0

    public void stop0(boolean cancel)

Overrides:
  `stop0` in class `GridCacheSharedManagerAdapter`
Parameters:
  `cancel` - Cancel flag.

#### onActivate

    public void onActivate(GridKernalContext kctx)
                    throws IgniteCheckedException

Called when cluster performing activation.

Specified by:
  `onActivate` in interface `IgniteChangeGlobalStateSupport`
Parameters:
  `kctx` - Kernal context.
Throws:
  `IgniteCheckedException` - If failed.

#### onDeActivate

    public void onDeActivate(GridKernalContext kctx)

Called when cluster performing deactivation.

Specified by:
  `onDeActivate` in interface `IgniteChangeGlobalStateSupport`
Parameters:
  `kctx` - Kernal context.

#### beginRecover

    public void beginRecover()

Invoked before starting checkpoint recover.

Specified by:
  `beginRecover` in interface `IgnitePageStoreManager`

#### finishRecover

    public void finishRecover()

Invoked after checkpoint recover is finished.

Specified by:
  `finishRecover` in interface `IgnitePageStoreManager`

#### initializeForCache

    public void initializeForCache(CacheGroupDescriptor grpDesc,
                          StoredCacheData cacheData)
                            throws IgniteCheckedException

Callback called when a cache is starting.

Specified by:
  `initializeForCache` in interface `IgnitePageStoreManager`
Parameters:
  `grpDesc` - Cache group descriptor.
  `cacheData` - Cache data of the cache being started.
Throws:
  `IgniteCheckedException` - If failed to handle cache start callback.

#### storeCacheData

    public void storeCacheData(StoredCacheData cacheData)
                        throws IgniteCheckedException

Specified by:
  `storeCacheData` in interface `IgnitePageStoreManager`
Parameters:
  `cacheData` - Cache configuration.
Throws:
  `IgniteCheckedException` - If failed.

#### 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:
  `shutdownForCacheGroup` in interface `IgnitePageStoreManager`
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.

#### onPartitionCreated

    public void onPartitionCreated(int grpId,
                          int partId)
                            throws IgniteCheckedException

Callback called when a partition is created on the local node.

Specified by:
  `onPartitionCreated` in interface `IgnitePageStoreManager`
Parameters:
  `grpId` - Cache group ID where the partition is being created.
  `partId` - ID of the partition being created.
Throws:
  `IgniteCheckedException` - If failed to handle partition create callback.

#### onPartitionDestroyed

    public void onPartitionDestroyed(int grpId,
                            int partId,
                            int tag)
                              throws IgniteCheckedException

Callback 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:
  `onPartitionDestroyed` in interface `IgnitePageStoreManager`
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)
              throws IgniteCheckedException

Reads a page for the given cache ID. Cache ID may be `0` if the page is a meta page.

Specified by:
  `read` in interface `IgnitePageStoreManager`
Parameters:
  `grpId` - Cache group ID.
  `pageId` - PageID to read.
  `pageBuf` - Page buffer to write to.
Throws:
  `IgniteCheckedException` - If failed to read the page.

#### read

    public void read(int cacheId,
            long pageId,
            ByteBuffer pageBuf,
            boolean keepCrc)
              throws IgniteCheckedException

Will preserve crc in buffer if keepCrc is true.

Parameters:
  `cacheId` - Cache ID.
  `pageId` - Page ID.
  `pageBuf` - Page buffer.
  `keepCrc` - Keep CRC flag.
Throws:
  `IgniteCheckedException` - If failed.

#### exists

    public boolean exists(int grpId,
                 int partId)
                   throws IgniteCheckedException

Checks if partition store exists.

Specified by:
  `exists` in interface `IgnitePageStoreManager`
Parameters:
  `grpId` - Cache group ID.
  `partId` - Partition ID.
Returns:
  `True` if partition store exists.
Throws:
  `IgniteCheckedException` - If failed.

#### readHeader

    public void readHeader(int grpId,
                  int partId,
                  ByteBuffer buf)
                    throws IgniteCheckedException

Reads a header of a page store.

Specified by:
  `readHeader` in interface `IgnitePageStoreManager`
Parameters:
  `grpId` - Cache group ID.
  `partId` - Partition ID.
  `buf` - Buffer to write to.
Throws:
  `IgniteCheckedException` - If failed.

#### write

    public void write(int grpId,
             long pageId,
             ByteBuffer pageBuf,
             int tag)
               throws IgniteCheckedException

Writes the page for the given cache ID. Cache ID may be `0` if the page is a meta page.

Specified by:
  `write` in interface `IgnitePageStoreManager`
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 IgniteCheckedException

Gets page offset within the page store file.

Specified by:
  `pageOffset` in interface `IgnitePageStoreManager`
Parameters:
  `grpId` - Cache group ID.
  `pageId` - Page ID.
Returns:
  Page offset.
Throws:
  `IgniteCheckedException` - If failed.

#### writeInternal

    public PageStore writeInternal(int cacheId,
                          long pageId,
                          ByteBuffer pageBuf,
                          int tag)
                            throws IgniteCheckedException

Parameters:
  `cacheId` - Cache ID to write.
  `pageId` - Page ID.
  `pageBuf` - Page buffer.
  `tag` - Partition tag (growing 1-based partition file version). Used to validate page is not outdated
Returns:
  PageStore to which the page has been written.
Throws:
  `IgniteCheckedException` - If IO error occurred.

#### sync

    public void sync(int grpId,
            int partId)
              throws IgniteCheckedException

Makes sure that all previous writes to the store has been written to disk.

Specified by:
  `sync` in interface `IgnitePageStoreManager`
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:
  `ensure` in interface `IgnitePageStoreManager`
Parameters:
  `grpId` - Cache group ID.
  `partId` - Partition ID.
Throws:
  `IgniteCheckedException` - If failed.

#### allocatePage

    public long allocatePage(int grpId,
                    int partId,
                    byte flags)
                      throws IgniteCheckedException

Allocates a page for the given page space.

Specified by:
  `allocatePage` in interface `IgnitePageStoreManager`
Parameters:
  `grpId` - Cache group ID.
  `partId` - Partition ID. Used only if `flags` is equal to `PageIdAllocator.FLAG_DATA`.
  `flags` - Page allocation flags.
Returns:
  Allocated page ID.
Throws:
  `IgniteCheckedException` - If IO exception occurred while allocating a page ID.

#### metaPageId

    public long metaPageId(int grpId)

Gets meta page ID for specified cache.

Specified by:
  `metaPageId` in interface `IgnitePageStoreManager`
Parameters:
  `grpId` - Cache group ID.
Returns:
  Meta page ID.

#### pages

    public int pages(int grpId,
            int partId)
              throws IgniteCheckedException

Gets total number of allocated pages for the given space.

Specified by:
  `pages` in interface `IgnitePageStoreManager`
Parameters:
  `grpId` - Cache group ID.
  `partId` - Partition ID.
Returns:
  Number of allocated pages.
Throws:
  `IgniteCheckedException` - If failed.

#### readCacheConfigurations

    public Map<String,StoredCacheData> readCacheConfigurations()
                                                        throws IgniteCheckedException

Specified by:
  `readCacheConfigurations` in interface `IgnitePageStoreManager`
Returns:
  Saved cache configurations.
Throws:
  `IgniteCheckedException` - If failed.

#### hasIndexStore

    public boolean hasIndexStore(int grpId)

Specified by:
  `hasIndexStore` in interface `IgnitePageStoreManager`
Parameters:
  `grpId` - Cache group ID.
Returns:
  `True` if index store for given cache group existed before node started.

#### workDir

    public File workDir()

Returns:
  Store work dir.

#### cacheWorkDir

    public File cacheWorkDir(CacheConfiguration ccfg)

Parameters:
  `ccfg` - Cache configuration.
Returns:
  Store dir for given cache.

#### getStore

    public PageStore getStore(int grpId,
                     int partId)
                       throws IgniteCheckedException

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.

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.2.0
Release Date | : September 15 2017