Class TrackingPageIO


  • public class TrackingPageIO
    extends PageIO
    We use dedicated page for tracking pages updates. Also we divide such 'tracking' pages on two half, first is used for check that page was changed or not (during incremental snapshot), second - to accumulate changed for next snapshot. You cannot test change for not started snapshot! because it will cause of preparation for snapshot. Implementation. For each page there is own bit in both half. Tracking page is used for tracking N page after it. N depends on page size (how many bytes we can use for tracking). +-----------------------------------------+-----------------------------------------+ | left half | right half | +---------+-----------+----+------------------------------------+----+------------------------------------+ | HEADER | Last |size| |size| | | |SnapshotTag|2b. | tracking bits |2b. | tracking bits | +---------+--------- -+----+------------------------------------+----+------------------------------------+
    • Constructor Detail

      • TrackingPageIO

        protected TrackingPageIO​(int ver)
        Parameters:
        ver - Page format version.
    • Method Detail

      • markChanged

        public long markChanged​(ByteBuffer buf,
                                long pageId,
                                long nextSnapshotTag,
                                long lastSuccessfulSnapshotTag,
                                int pageSize)
        Will mark pageId as changed for next (!) snapshotId
        Parameters:
        buf - Buffer.
        pageId - Page id.
        nextSnapshotTag - Tag of next snapshot.
        pageSize - Page size.
        Returns:
        -1 if everything is ok, otherwise last saved tag.
      • isCorrupted

        public boolean isCorrupted​(ByteBuffer buf)
        Parameters:
        buf - Buffer.
        Returns:
        Was tracking page marked as corrupted or not.
      • resetCorruptFlag

        public void resetCorruptFlag​(ByteBuffer buf)
        Reset corrupted flag to false.
        Parameters:
        buf - Buffer.
      • resetCorruptFlag

        public void resetCorruptFlag​(long addr)
        Reset corrupted flag to false.
        Parameters:
        addr - Buffer.
      • wasChanged

        public boolean wasChanged​(ByteBuffer buf,
                                  long pageId,
                                  long curSnapshotTag,
                                  long lastSuccessfulSnapshotTag,
                                  int pageSize)
                           throws TrackingPageIsCorruptedException
        Parameters:
        buf - Buffer.
        pageId - Page id.
        curSnapshotTag - Snapshot tag.
        lastSuccessfulSnapshotTag - Last successful snapshot id.
        pageSize - Page size.
        Returns:
        Was that pageId marked as changed between previous snapshot finish and current snapshot start or not.
        Throws:
        TrackingPageIsCorruptedException - if this tracking page was marked as corrupted.
      • countOfChangedPage

        public short countOfChangedPage​(ByteBuffer buf,
                                        long snapshotTag,
                                        int pageSize)
        Parameters:
        buf - Buffer.
        snapshotTag - Snapshot tag.
        pageSize - Page size.
        Returns:
        Count of pages which were marked as change for given snapshotTag.
      • trackingPageFor

        public long trackingPageFor​(long pageId,
                                    int pageSize)
        Parameters:
        pageId - Page id.
        pageSize - Page size.
        Returns:
        Page id of tracking page which set pageId belongs to.
      • countOfPageToTrack

        public int countOfPageToTrack​(int pageSize)
        Parameters:
        pageSize - Page size.
        Returns:
        How many page we can track with 1 page.
      • findNextChangedPage

        @Nullable
        public @Nullable Long findNextChangedPage​(ByteBuffer buf,
                                                  long start,
                                                  long curSnapshotTag,
                                                  long lastSuccessfulSnapshotTag,
                                                  int pageSize)
                                           throws TrackingPageIsCorruptedException
        Parameters:
        buf - Buffer.
        start - Start.
        curSnapshotTag - Snapshot id.
        lastSuccessfulSnapshotTag - Last successful snapshot id.
        pageSize - Page size.
        Returns:
        Passed pageId if it was changed or next closest one, if there is no changed page null will be returned.
        Throws:
        TrackingPageIsCorruptedException - if this tracking page was marked as corrupted.
      • getFreeSpace

        public int getFreeSpace​(int pageSize,
                                long pageAddr)
        Count of bytes that is currently free in this page and possibly can be used to place additional payload.
        Specified by:
        getFreeSpace in class PageIO
        Parameters:
        pageSize - Page size.
        pageAddr - Page address.
        Returns:
        Free space.