Package org.h2.mvstore
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 String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
long
The start block number within the file.(package private) int
The garbage collection priority.(package private) static final int
The length of the chunk footer.final int
The chunk id.(package private) long
The position of the root of layout map.int
The length in number of blocks.int
The last used map id.(package private) static final int
The maximum length of a chunk header, in bytes.static final int
The maximum chunk id.long
The sum of the max length of all pages.long
The sum of the length of all pages that are still alive.long
The predicted position of the next chunk.(package private) BitSet
Collection of "deleted" flags for all pages in the chunk.(package private) int
The total number of pages in this chunk.(package private) int
The number of pages that are still alive in the latest version of the store.private int
Number of live pinned pages.long
When this chunk was created, in milliseconds after the store was created.(package private) int
Offset (from the beginning of the chunk) for the table of content.long
When this chunk was no longer needed, in milliseconds after the store was created.(package private) long
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.long
The version stored in this chunk. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) 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.(package private) void
accountForWrittenPage
(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.boolean
static Chunk
fromString
(String s) Build a block from the given string.(package private) int
Calculate the fill rate in %.(package private) byte[]
(package private) static String
getMetaKey
(int chunkId) Get the metadata key for the given chunk id.int
hashCode()
private boolean
(package private) boolean
isLive()
(package private) boolean
(package private) boolean
isSaved()
(package private) ByteBuffer
readBufferForPage
(FileStore fileStore, int offset, long pos) Read a page of data into a ByteBuffer.(package private) static Chunk
readChunkHeader
(ByteBuffer buff, long start) Read the header from the byte buffer.(package private) long[]
toString()
(package private) void
writeChunkHeader
(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
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() -
equals
-
asString
Get the chunk data as a string.- Returns:
- the string
-
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
-