Class 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 Detail

      • HEADER_SIZE

        public static final int HEADER_SIZE
        Allocated field offset.
        See Also:
        Constant Field Values
      • 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,
                             int pageSize,
                             LongConsumer allocatedTracker)
        Parameters:
        type - Type of stored pages.
        pathProvider - Store path.
        factory - Factory producing an IO accessor.
        pageSize - Page size.
        allocatedTracker - Allocation tracker.
    • Method Detail

      • 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.
      • 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.
      • beginRecover

        public void beginRecover()
        Starts recover process.
        Specified by:
        beginRecover in interface PageStore
      • 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).
      • read

        public boolean read​(long pageId,
                            ByteBuffer pageBuf,
                            boolean checkCrc,
                            boolean keepCrc)
                     throws IgniteCheckedException
        Parameters:
        pageId - Page ID.
        pageBuf - Page buffer to read into.
        checkCrc - Check CRC on page.
        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).
      • 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.
      • 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.