Class Chunk
java.lang.Object
org.h2.mvstore.Chunk
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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final StringlongThe start block number within the file.(package private) intThe garbage collection priority.(package private) static final intThe length of the chunk footer.final intThe chunk id.(package private) longThe position of the root of layout map.intThe length in number of blocks.intThe last used map id.(package private) static final intThe maximum length of a chunk header, in bytes.static final intThe maximum chunk id.longThe sum of the max length of all pages.longThe sum of the length of all pages that are still alive.longThe predicted position of the next chunk.(package private) BitSetCollection of "deleted" flags for all pages in the chunk.(package private) intThe total number of pages in this chunk.(package private) intThe number of pages that are still alive in the latest version of the store.private intNumber of live pinned pages.longWhen this chunk was created, in milliseconds after the store was created.(package private) intOffset (from the beginning of the chunk) for the table of content.longWhen this chunk was no longer needed, in milliseconds after the store was created.(package private) longVersion of the store at which chunk become unused and therefore can be considered "dead" and collected after this version is no longer in use.longThe version stored in this chunk. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) booleanaccountForRemovedPage(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.(package private) voidaccountForWrittenPage(int pageLengthOnDisk, boolean singleWriter) Modifies internal state to reflect the fact that one more page is stored within this chunk.asString()Get the chunk data as a string.booleanstatic ChunkfromString(String s) Build a block from the given string.(package private) intCalculate the fill rate in %.(package private) byte[](package private) static StringgetMetaKey(int chunkId) Get the metadata key for the given chunk id.inthashCode()private boolean(package private) booleanisLive()(package private) boolean(package private) booleanisSaved()(package private) ByteBufferreadBufferForPage(FileStore fileStore, int offset, long pos) Read a page of data into a ByteBuffer.(package private) static ChunkreadChunkHeader(ByteBuffer buff, long start) Read the header from the byte buffer.(package private) long[]toString()(package private) voidwriteChunkHeader(WriteBuffer buff, int minLength) Write the chunk header.
-
Field Details
-
MAX_ID
public static final int MAX_IDThe maximum chunk id.- See Also:
-
MAX_HEADER_LENGTH
static final int MAX_HEADER_LENGTHThe maximum length of a chunk header, in bytes.- See Also:
-
FOOTER_LENGTH
static final int FOOTER_LENGTHThe length of the chunk footer. The longest footer is: chunk:ffffffff,block:ffffffffffffffff, version:ffffffffffffffff,fletcher:ffffffff- See Also:
-
ATTR_CHUNK
- See Also:
-
ATTR_BLOCK
- See Also:
-
ATTR_LEN
- See Also:
-
ATTR_MAP
- See Also:
-
ATTR_MAX
- See Also:
-
ATTR_NEXT
- See Also:
-
ATTR_PAGES
- See Also:
-
ATTR_ROOT
- See Also:
-
ATTR_TIME
- See Also:
-
ATTR_VERSION
- See Also:
-
ATTR_LIVE_MAX
- See Also:
-
ATTR_LIVE_PAGES
- See Also:
-
ATTR_UNUSED
- See Also:
-
ATTR_UNUSED_AT_VERSION
- See Also:
-
ATTR_PIN_COUNT
- See Also:
-
ATTR_TOC
- See Also:
-
ATTR_OCCUPANCY
- See Also:
-
ATTR_FLETCHER
- See Also:
-
id
public final int idThe chunk id. -
block
public volatile long blockThe start block number within the file. -
len
public int lenThe length in number of blocks. -
pageCount
int pageCountThe total number of pages in this chunk. -
pageCountLive
int pageCountLiveThe number of pages that are still alive in the latest version of the store. -
tocPos
int tocPosOffset (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 occupancyCollection of "deleted" flags for all pages in the chunk. -
maxLen
public long maxLenThe sum of the max length of all pages. -
maxLenLive
public long maxLenLiveThe sum of the length of all pages that are still alive. -
collectPriority
int collectPriorityThe garbage collection priority. Priority 0 means it needs to be collected, a high value means low priority. -
layoutRootPos
long layoutRootPosThe position of the root of layout map. -
version
public long versionThe version stored in this chunk. -
time
public long timeWhen this chunk was created, in milliseconds after the store was created. -
unused
public long unusedWhen 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 unusedAtVersionVersion 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 mapIdThe last used map id. -
next
public long nextThe predicted position of the next chunk. -
pinCount
private int pinCountNumber of live pinned pages.
-
-
Constructor Details
-
Chunk
-
Chunk
-
Chunk
-
Chunk
Chunk(int id)
-
-
Method Details
-
readChunkHeader
Read the header from the byte buffer.- Parameters:
buff- the source bufferstart- the start of the chunk in the file- Returns:
- the chunk
-
writeChunkHeader
Write the chunk header.- Parameters:
buff- the target bufferminLength- the minimum length
-
getMetaKey
Get the metadata key for the given chunk id.- Parameters:
chunkId- the chunk id- Returns:
- the metadata key
-
fromString
-
getFillRate
int getFillRate()Calculate the fill rate in %. 0 means empty, 100 means full.- Returns:
- the fill rate
-
hashCode
-
equals
-
asString
-
isSaved
boolean isSaved() -
isLive
boolean isLive() -
isRewritable
boolean isRewritable() -
isEvacuatable
private boolean isEvacuatable() -
readBufferForPage
Read a page of data into a ByteBuffer.- Parameters:
fileStore- to useoffset- of the page datapos- page pos- Returns:
- ByteBuffer containing page data.
-
readToC
-
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 pagesingleWriter- 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 chunkpageLength- on disk of the removed pagepinned- whether removed page was pinnednow- is a moment in time (since creation of the store), when removal is recorded, and retention period startsversion- at which page was removed- Returns:
- true if all of the pages, this chunk contains, were already removed, and false otherwise
-
toString
-