Class Chunk

java.lang.Object
org.h2.mvstore.Chunk

public final class Chunk extends Object
A chunk of data, containing one or multiple pages.

Minimum chunk size is usually 4096 bytes, and it grows in those fixed increments (blocks). Chunk's length and it's position in the underlying filestore are multiples of that increment (block size), therefore they both are measured in blocks, instead of bytes. There are at most 67 million (2^26) chunks, and each chunk is at most 2 GB large.

  • Field Details

    • MAX_ID

      public static final int MAX_ID
      The maximum chunk id.
      See Also:
    • MAX_HEADER_LENGTH

      static final int MAX_HEADER_LENGTH
      The maximum length of a chunk header, in bytes.
      See Also:
    • ATTR_CHUNK

      private static final String ATTR_CHUNK
      See Also:
    • ATTR_BLOCK

      private static final String ATTR_BLOCK
      See Also:
    • ATTR_LEN

      private static final String ATTR_LEN
      See Also:
    • ATTR_MAP

      private static final String ATTR_MAP
      See Also:
    • ATTR_MAX

      private static final String ATTR_MAX
      See Also:
    • ATTR_NEXT

      private static final String ATTR_NEXT
      See Also:
    • ATTR_PAGES

      private static final String ATTR_PAGES
      See Also:
    • ATTR_ROOT

      private static final String ATTR_ROOT
      See Also:
    • ATTR_TIME

      private static final String ATTR_TIME
      See Also:
    • ATTR_VERSION

      private static final String ATTR_VERSION
      See Also:
    • ATTR_LIVE_MAX

      private static final String ATTR_LIVE_MAX
      See Also:
    • ATTR_LIVE_PAGES

      private static final String ATTR_LIVE_PAGES
      See Also:
    • ATTR_UNUSED

      private static final String ATTR_UNUSED
      See Also:
    • ATTR_UNUSED_AT_VERSION

      private static final String ATTR_UNUSED_AT_VERSION
      See Also:
    • ATTR_PIN_COUNT

      private static final String ATTR_PIN_COUNT
      See Also:
    • ATTR_TOC

      private static final String ATTR_TOC
      See Also:
    • ATTR_OCCUPANCY

      private static final String ATTR_OCCUPANCY
      See Also:
    • ATTR_FLETCHER

      private static final String ATTR_FLETCHER
      See Also:
    • id

      public final int id
      The chunk id.
    • block

      public volatile long block
      The start block number within the file.
    • len

      public int len
      The length in number of blocks.
    • pageCount

      int pageCount
      The total number of pages in this chunk.
    • pageCountLive

      int pageCountLive
      The number of pages that are still alive in the latest version of the store.
    • tocPos

      int tocPos
      Offset (from the beginning of the chunk) for the table of content. Table of content is holding a value of type "long" for each page in the chunk. This value consists of map id, page offset, page length and page type. Format is the same as page's position id, but with map id replacing chunk id.
      See Also:
    • occupancy

      BitSet occupancy
      Collection of "deleted" flags for all pages in the chunk.
    • maxLen

      public long maxLen
      The sum of the max length of all pages.
    • maxLenLive

      public long maxLenLive
      The sum of the length of all pages that are still alive.
    • collectPriority

      int collectPriority
      The garbage collection priority. Priority 0 means it needs to be collected, a high value means low priority.
    • layoutRootPos

      long layoutRootPos
      The position of the root of layout map.
    • version

      public long version
      The version stored in this chunk.
    • time

      public long time
      When this chunk was created, in milliseconds after the store was created.
    • unused

      public long unused
      When this chunk was no longer needed, in milliseconds after the store was created. After this, the chunk is kept alive a bit longer (in case it is referenced in older versions).
    • unusedAtVersion

      long unusedAtVersion
      Version of the store at which chunk become unused and therefore can be considered "dead" and collected after this version is no longer in use.
    • mapId

      public int mapId
      The last used map id.
    • next

      public long next
      The predicted position of the next chunk.
    • pinCount

      private int pinCount
      Number of live pinned pages.
  • Constructor Details

  • Method Details

    • readChunkHeader

      static Chunk readChunkHeader(ByteBuffer buff, long start)
      Read the header from the byte buffer.
      Parameters:
      buff - the source buffer
      start - the start of the chunk in the file
      Returns:
      the chunk
    • writeChunkHeader

      void writeChunkHeader(WriteBuffer buff, int minLength)
      Write the chunk header.
      Parameters:
      buff - the target buffer
      minLength - the minimum length
    • getMetaKey

      static String getMetaKey(int chunkId)
      Get the metadata key for the given chunk id.
      Parameters:
      chunkId - the chunk id
      Returns:
      the metadata key
    • fromString

      public static Chunk fromString(String s)
      Build a block from the given string.
      Parameters:
      s - the string
      Returns:
      the block
    • getFillRate

      int getFillRate()
      Calculate the fill rate in %. 0 means empty, 100 means full.
      Returns:
      the fill rate
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • asString

      public String asString()
      Get the chunk data as a string.
      Returns:
      the string
    • getFooterBytes

      byte[] getFooterBytes()
    • isSaved

      boolean isSaved()
    • isLive

      boolean isLive()
    • isRewritable

      boolean isRewritable()
    • isEvacuatable

      private boolean isEvacuatable()
    • readBufferForPage

      ByteBuffer readBufferForPage(FileStore fileStore, int offset, long pos)
      Read a page of data into a ByteBuffer.
      Parameters:
      fileStore - to use
      offset - of the page data
      pos - page pos
      Returns:
      ByteBuffer containing page data.
    • readToC

      long[] readToC(FileStore fileStore)
    • accountForWrittenPage

      void accountForWrittenPage(int pageLengthOnDisk, boolean singleWriter)
      Modifies internal state to reflect the fact that one more page is stored within this chunk.
      Parameters:
      pageLengthOnDisk - size of the page
      singleWriter - indicates whether page belongs to append mode capable map (single writer map). Such pages are "pinned" to the chunk, they can't be evacuated (moved to a different chunk) while
    • accountForRemovedPage

      boolean accountForRemovedPage(int pageNo, int pageLength, boolean pinned, long now, long version)
      Modifies internal state to reflect the fact that one the pages within this chunk was removed from the map.
      Parameters:
      pageNo - sequential page number within the chunk
      pageLength - on disk of the removed page
      pinned - whether removed page was pinned
      now - is a moment in time (since creation of the store), when removal is recorded, and retention period starts
      version - at which page was removed
      Returns:
      true if all of the pages, this chunk contains, were already removed, and false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object