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

## Class FilePageStore

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore

All Implemented Interfaces:
  Closeable, AutoCloseable, PageStore

Direct Known Subclasses:
  FilePageStoreV2

    public class FilePageStore
    extends Object
    implements PageStore

FilePageStore is a PageStore implementation that uses regular files to store pages.

Actual read and write operations are performed with `FileIO` abstract interface, list of its implementations is a good source of information about functionality in Ignite Native Persistence.

On a physical level each instance of FilePageStore corresponds to a partition file assigned to the local node or to index file of a particular cache if any secondary indexes were created.

Instances of FilePageStore are managed by `FilePageStoreManager` for regular cache operations like assignment of new partition to the local node or checkpoint event and by `IgniteSnapshotManager` during snapshot creation.

### Field Summary

Fields
`protected DataStorageConfiguration` `dbCfg` Database configuration.
`protected FileIO` `fileIO` I/O interface for read/write operations with file
`static int` `HEADER_SIZE` Allocated field offset.
`protected int` `pageSize`
`static int` `VERSION` File version.

### Fields inherited from interface org.apache.ignite.internal.pagemem.store.PageStore

`TYPE_DATA, TYPE_IDX`

### Constructor Summary

Constructors
Constructor and Description
`FilePageStore(byte type, IgniteOutClosure<Path> pathProvider, FileIOFactory factory, DataStorageConfiguration cfg, LongConsumer allocatedTracker)`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addWriteListener(PageWriteListener lsnr)`
`long` `allocatePage()` Allocates next page index.
`void` `beginRecover()` Starts recover process.
`void` `close()`
`void` `ensure()`
`boolean` `exists()` Checks if page exists.
`void` `finishRecover()` Ends recover process.
`int` `getBlockSize()`
`String` `getFileAbsolutePath()`
`int` `getPageSize()`
`long` `getSparseSize()`
`ByteBuffer` `header(byte type, int pageSize)` Creates header for current version file store.
`int` `headerSize()` Size of page store header.
`void` `init()`
`long` `pageOffset(long pageId)` Gets page offset within the store file.
`int` `pages()` Gets number of allocated pages.
`void` `punchHole(long pageId, int usefulBytes)` Should free all the extra storage space after the given number of useful bytes in the given page.
`boolean` `read(long pageId, ByteBuffer pageBuf, boolean keepCrc)` Reads a page.
`void` `readHeader(ByteBuffer buf)` Reads a header.
`void` `removeWriteListener(PageWriteListener lsnr)`
`long` `size()`
`void` `stop(boolean delete)`
`void` `sync()` Sync method used to ensure that the given pages are guaranteed to be written to the store.
`void` `truncate(int tag)` Truncates and deletes partition file.
`int` `version()` Page store version.
`void` `write(long pageId, ByteBuffer pageBuf, int tag, boolean calculateCrc)` Writes a page.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### VERSION

    public static final int VERSION

File version.

See Also:
  Constant Field Values

#### HEADER_SIZE

    public static final int HEADER_SIZE

Allocated field offset.

See Also:
  Constant Field Values

#### dbCfg

    protected final DataStorageConfiguration dbCfg

Database configuration.

#### fileIO

    protected volatile FileIO fileIO

I/O interface for read/write operations with file

#### pageSize

    protected final int pageSize

### Constructor Detail

#### FilePageStore

    public FilePageStore(byte type,
                         IgniteOutClosure<Path> pathProvider,
                         FileIOFactory factory,
                         DataStorageConfiguration cfg,
                         LongConsumer allocatedTracker)

### Method Detail

#### addWriteListener

    public void addWriteListener(PageWriteListener lsnr)

Specified by:
  `addWriteListener` in interface `PageStore`
Parameters:
  `lsnr` - Page write listener to set.

#### removeWriteListener

    public void removeWriteListener(PageWriteListener lsnr)

Specified by:
  `removeWriteListener` in interface `PageStore`
Parameters:
  `lsnr` - Page write listener to remove.

#### getPageSize

    public int getPageSize()

Specified by:
  `getPageSize` in interface `PageStore`
Returns:
  Page size in bytes.

#### getBlockSize

    public int getBlockSize()

Specified by:
  `getBlockSize` in interface `PageStore`
Returns:
  Storage block size or negative value if unknown or not supported.

#### size

    public long size()

Specified by:
  `size` in interface `PageStore`
Returns:
  Size of the storage in bytes. May differ from `PageStore.pages()` * `PageStore.getPageSize()` due to delayed writes or due to other implementation specific details.

#### getSparseSize

    public long getSparseSize()

Specified by:
  `getSparseSize` in interface `PageStore`
Returns:
  Size of the storage adjusted for sparsity in bytes or negative value if not supported. Should be less than or equal to `PageStore.size()`.
See Also:
  `PageStore.punchHole(long, int)`

#### punchHole

    public void punchHole(long pageId,
                          int usefulBytes)

Should free all the extra storage space after the given number of useful bytes in the given page.

Specified by:
  `punchHole` in interface `PageStore`
Parameters:
  `pageId` - Page id.
  `usefulBytes` - Number of meaningful bytes from the beginning of the page.

#### exists

    public boolean exists()

Checks if page exists.

Specified by:
  `exists` in interface `PageStore`
Returns:
  `True` if page exists.

#### headerSize

    public int headerSize()

Size of page store header.

#### version

    public int version()

Page store version.

Specified by:
  `version` in interface `PageStore`
Returns:
  Page store version.

#### header

    public ByteBuffer header(byte type,
                             int pageSize)

Creates header for current version file store. Doesn't init the store.

Parameters:
  `type` - Type.
  `pageSize` - Page size.
Returns:
  Byte buffer instance.

#### stop

    public void stop(boolean delete)
              throws StorageException

Specified by:
  `stop` in interface `PageStore`
Parameters:
  `delete` - `True` to delete file.
Throws:
  `StorageException` - If failed.

#### close

    public void close()
               throws IOException

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Throws:
  `IOException`

#### truncate

    public void truncate(int tag)
                  throws StorageException

Truncates and deletes partition file.

Specified by:
  `truncate` in interface `PageStore`
Parameters:
  `tag` - New partition tag.
Throws:
  `StorageException` - If failed.

#### beginRecover

    public void beginRecover()

Starts recover process.

Specified by:
  `beginRecover` in interface `PageStore`

#### finishRecover

    public void finishRecover()
                       throws StorageException

Ends recover process.

Specified by:
  `finishRecover` in interface `PageStore`
Throws:
  `StorageException` - If failed.

#### read

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

Reads a page.

Specified by:
  `read` in interface `PageStore`
Parameters:
  `pageId` - Page ID.
  `pageBuf` - Page buffer to read into.
  `keepCrc` - by default reading zeroes CRC which was on file, but you can keep it in pageBuf if set keepCrc
Returns:
  `true` if page has been read successfully, `false` if page hasn't been written yet.
Throws:
  `IgniteCheckedException` - If reading failed (IO error occurred).

#### readHeader

    public void readHeader(ByteBuffer buf)
                    throws IgniteCheckedException

Reads a header.

Specified by:
  `readHeader` in interface `PageStore`
Parameters:
  `buf` - Buffer to write to.
Throws:
  `IgniteCheckedException` - If failed.

#### init

    public void init()
              throws StorageException

Throws:
  `StorageException` - If failed to initialize store file.

#### write

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

Writes a page.

Specified by:
  `write` in interface `PageStore`
Parameters:
  `pageId` - Page ID.
  `pageBuf` - Page buffer to write.
  `tag` - Partition file version, 1-based incrementing counter. For outdated pages `tag` has lower value, and write does nothing.
  `calculateCrc` - if `False` crc calculation will be forcibly skipped.
Throws:
  `IgniteCheckedException` - If page writing failed (IO error occurred).

#### pageOffset

    public long pageOffset(long pageId)

Gets page offset within the store file.

Specified by:
  `pageOffset` in interface `PageStore`
Parameters:
  `pageId` - Page ID.
Returns:
  Page offset.

#### sync

    public void sync()
              throws StorageException

Sync method used to ensure that the given pages are guaranteed to be written to the store.

Specified by:
  `sync` in interface `PageStore`
Throws:
  `StorageException`

#### ensure

    public void ensure()
                throws IgniteCheckedException

Specified by:
  `ensure` in interface `PageStore`
Throws:
  `IgniteCheckedException` - If sync failed (IO error occurred).

#### allocatePage

    public long allocatePage()
                      throws IgniteCheckedException

Allocates next page index.

Specified by:
  `allocatePage` in interface `PageStore`
Returns:
  Next page index.
Throws:
  `IgniteCheckedException` - If failed to allocate.

#### getFileAbsolutePath

    public String getFileAbsolutePath()

Returns:
  File absolute path.

#### pages

    public int pages()

Gets number of allocated pages.

Specified by:
  `pages` in interface `PageStore`
Returns:
  Number of allocated pages.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.10.0
Release Date | : March 10 2021