Package org.h2.mvstore
Class Chunk
- java.lang.Object
-
- org.h2.mvstore.Chunk
-
public final class Chunk extends java.lang.ObjectA 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 Modifier and Type Class Description static classChunk.PositionComparator
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringATTR_BLOCKprivate static java.lang.StringATTR_CHUNKprivate static java.lang.StringATTR_FLETCHERprivate static java.lang.StringATTR_LENprivate static java.lang.StringATTR_LIVE_MAXprivate static java.lang.StringATTR_LIVE_PAGESprivate static java.lang.StringATTR_MAPprivate static java.lang.StringATTR_MAXprivate static java.lang.StringATTR_NEXTprivate static java.lang.StringATTR_OCCUPANCYprivate static java.lang.StringATTR_PAGESprivate static java.lang.StringATTR_PIN_COUNTprivate static java.lang.StringATTR_ROOTprivate static java.lang.StringATTR_TIMEprivate static java.lang.StringATTR_TOCprivate static java.lang.StringATTR_UNUSEDprivate static java.lang.StringATTR_UNUSED_AT_VERSIONprivate static java.lang.StringATTR_VERSIONlongblockThe start block number within the file.(package private) intcollectPriorityThe garbage collection priority.(package private) static intFOOTER_LENGTHThe length of the chunk footer.intidThe chunk id.(package private) longlayoutRootPosThe position of the root of layout map.intlenThe length in number of blocks.intmapIdThe last used map id.(package private) static intMAX_HEADER_LENGTHThe maximum length of a chunk header, in bytes.static intMAX_IDThe maximum chunk id.longmaxLenThe sum of the max length of all pages.longmaxLenLiveThe sum of the length of all pages that are still alive.longnextThe predicted position of the next chunk.(package private) java.util.BitSetoccupancyCollection of "deleted" flags for all pages in the chunk.(package private) intpageCountThe total number of pages in this chunk.(package private) intpageCountLiveThe number of pages that are still alive in the latest version of the store.private intpinCountNumber of live pinned pages.longtimeWhen this chunk was created, in milliseconds after the store was created.(package private) inttocPosOffset (from the beginning of the chunk) for the table of content.longunusedWhen this chunk was no longer needed, in milliseconds after the store was created.(package private) longunusedAtVersionVersion of the store at which chunk become unused and therefore can be considered "dead" and collected after this version is no longer in use.longversionThe version stored in this chunk.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (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.java.lang.StringasString()Get the chunk data as a string.booleanequals(java.lang.Object o)static ChunkfromString(java.lang.String s)Build a block from the given string.(package private) intgetFillRate()Calculate the fill rate in %.(package private) byte[]getFooterBytes()(package private) static java.lang.StringgetMetaKey(int chunkId)Get the metadata key for the given chunk id.inthashCode()private booleanisEvacuatable()(package private) booleanisLive()(package private) booleanisRewritable()(package private) booleanisSaved()(package private) java.nio.ByteBufferreadBufferForPage(FileStore fileStore, int offset, long pos)Read a page of data into a ByteBuffer.(package private) static ChunkreadChunkHeader(java.nio.ByteBuffer buff, long start)Read the header from the byte buffer.(package private) long[]readToC(FileStore fileStore)java.lang.StringtoString()(package private) voidwriteChunkHeader(WriteBuffer buff, int minLength)Write the chunk header.
-
-
-
Field Detail
-
MAX_ID
public static final int MAX_ID
The maximum chunk id.- See Also:
- Constant Field Values
-
MAX_HEADER_LENGTH
static final int MAX_HEADER_LENGTH
The maximum length of a chunk header, in bytes.- See Also:
- Constant Field Values
-
FOOTER_LENGTH
static final int FOOTER_LENGTH
The length of the chunk footer. The longest footer is: chunk:ffffffff,block:ffffffffffffffff, version:ffffffffffffffff,fletcher:ffffffff- See Also:
- Constant Field Values
-
ATTR_CHUNK
private static final java.lang.String ATTR_CHUNK
- See Also:
- Constant Field Values
-
ATTR_BLOCK
private static final java.lang.String ATTR_BLOCK
- See Also:
- Constant Field Values
-
ATTR_LEN
private static final java.lang.String ATTR_LEN
- See Also:
- Constant Field Values
-
ATTR_MAP
private static final java.lang.String ATTR_MAP
- See Also:
- Constant Field Values
-
ATTR_MAX
private static final java.lang.String ATTR_MAX
- See Also:
- Constant Field Values
-
ATTR_NEXT
private static final java.lang.String ATTR_NEXT
- See Also:
- Constant Field Values
-
ATTR_PAGES
private static final java.lang.String ATTR_PAGES
- See Also:
- Constant Field Values
-
ATTR_ROOT
private static final java.lang.String ATTR_ROOT
- See Also:
- Constant Field Values
-
ATTR_TIME
private static final java.lang.String ATTR_TIME
- See Also:
- Constant Field Values
-
ATTR_VERSION
private static final java.lang.String ATTR_VERSION
- See Also:
- Constant Field Values
-
ATTR_LIVE_MAX
private static final java.lang.String ATTR_LIVE_MAX
- See Also:
- Constant Field Values
-
ATTR_LIVE_PAGES
private static final java.lang.String ATTR_LIVE_PAGES
- See Also:
- Constant Field Values
-
ATTR_UNUSED
private static final java.lang.String ATTR_UNUSED
- See Also:
- Constant Field Values
-
ATTR_UNUSED_AT_VERSION
private static final java.lang.String ATTR_UNUSED_AT_VERSION
- See Also:
- Constant Field Values
-
ATTR_PIN_COUNT
private static final java.lang.String ATTR_PIN_COUNT
- See Also:
- Constant Field Values
-
ATTR_TOC
private static final java.lang.String ATTR_TOC
- See Also:
- Constant Field Values
-
ATTR_OCCUPANCY
private static final java.lang.String ATTR_OCCUPANCY
- See Also:
- Constant Field Values
-
ATTR_FLETCHER
private static final java.lang.String ATTR_FLETCHER
- See Also:
- Constant Field Values
-
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:
for field format details
-
occupancy
java.util.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.
-
-
Method Detail
-
readChunkHeader
static Chunk readChunkHeader(java.nio.ByteBuffer buff, long start)
Read the header from the byte buffer.- Parameters:
buff- the source bufferstart- 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 bufferminLength- the minimum length
-
getMetaKey
static java.lang.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(java.lang.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:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
asString
public java.lang.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
java.nio.ByteBuffer readBufferForPage(FileStore fileStore, int offset, long pos)
Read a page of data into a ByteBuffer.- Parameters:
fileStore- to useoffset- of the page datapos- 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 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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-