Top Description Inners Fields Constructors Methods
org.h2.mvstore

public abstract Class Chunk<C extends Chunk<C>>

extends Object
Class Inheritance
Known Direct Subclasses
org.h2.mvstore.MFChunk, org.h2.mvstore.SFChunk
Imports
java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.util.BitSet, .Comparator, .Map, org.h2.util.StringUtils

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 and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
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
private static final String
public volatile long
block

The start block number within the file.

public volatile ByteBuffer
buffer

ByteBuffer holding this Chunk's serialized content before it gets saved to file store.

pack-priv int
collectPriority

The garbage collection priority.

public final int
id

The chunk id.

pack-priv long
layoutRootPos

The position of the root of layout map.

public int
len

The length in number of blocks.

public int
mapId

The last used map id.

pack-priv static final int
MAX_HEADER_LENGTH

The maximum length of a chunk header, in bytes.

public static final int
MAX_ID

The maximum chunk id.

public long
maxLen

The sum of the max length of all pages.

public long
maxLenLive

The sum of the length of all pages that are still alive.

public long
next

The predicted position of the next chunk.

pack-priv BitSet
occupancy

Collection of "deleted" flags for all pages in the chunk.

pack-priv int
pageCount

The total number of pages in this chunk.

pack-priv int
pageCountLive

The number of pages that are still alive in the latest version of the store.

private int
pinCount

Number of live pinned pages.

public long
time

When this chunk was created, in milliseconds since the store was created.

pack-priv int
tocPos

Byte offset (from the beginning of the chunk) for the table of content (ToC).

public long
unused

When this chunk was no longer needed, in milliseconds after the store was created.

pack-priv 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.

public long
version

The version stored in this chunk.

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
Chunk(Map<String, String> map, boolean full)

pack-priv
Chunk(int id)

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean

Returns:

true if all of the pages, this chunk contains, were already removed, and false otherwise
accountForRemovedPage
(int
sequential page number within the chunk
pageNo
,
int
on disk of the removed page
pageLength
,
boolean
whether removed page was pinned
pinned
,
long
is a moment in time (since creation of the store), when removal is recorded, and retention period starts
now
,
long
at which page was removed
version
)

Modifies internal state to reflect the fact that one the pages within this chunk was removed from the map.

pack-priv void
accountForWrittenPage(int
size of the page
pageLengthOnDisk
,
boolean
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
singleWriter
)

Modifies internal state to reflect the fact that one more page is stored within this chunk.

public final String

Returns:

the string
asString
()

Get the chunk metadata as a string to be stored in a layout map.

protected void
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

pack-priv int

Returns:

estimated size of the header
estimateHeaderSize
()

Write the chunk header.

pack-priv int

Returns:

the fill rate
getFillRate
()

Calculate the fill rate in %.

pack-priv byte[]
public String
private byte[]
pack-priv static String

Returns:

the metadata key
getMetaKey
(int
the chunk id
chunkId
)

Get the metadata key for the given chunk id.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

pack-priv boolean
private boolean
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv ByteBuffer

Returns:

ByteBuffer containing page data.
readBufferForPage
(FileStore<C>
to use
fileStore
,
int
of the page data
offset
,
long
page pos
pos
)

Read a page of data into a ByteBuffer.

pack-priv static String

Returns:

the chunk
readChunkHeader
(ByteBuffer
the source buffer
buff
)

Read the header from the byte buffer.

protected abstract ByteBuffer
readFully(FileStore<C> fileStore, long filePos, int length)

pack-priv long[]
readToC(FileStore<C> fileStore)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

pack-priv void
writeChunkHeader(WriteBuffer
the target buffer
buff
,
int
length of the area reserved for the header
maxLength
)

Write the chunk header.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

ATTR_BLOCKback to summary
private static final String ATTR_BLOCK
ATTR_CHUNKback to summary
private static final String ATTR_CHUNK
ATTR_FLETCHERback to summary
private static final String ATTR_FLETCHER
ATTR_LENback to summary
private static final String ATTR_LEN
ATTR_LIVE_MAXback to summary
private static final String ATTR_LIVE_MAX
ATTR_LIVE_PAGESback to summary
private static final String ATTR_LIVE_PAGES
ATTR_MAPback to summary
private static final String ATTR_MAP
ATTR_MAXback to summary
private static final String ATTR_MAX
ATTR_NEXTback to summary
private static final String ATTR_NEXT
ATTR_OCCUPANCYback to summary
private static final String ATTR_OCCUPANCY
ATTR_PAGESback to summary
private static final String ATTR_PAGES
ATTR_PIN_COUNTback to summary
private static final String ATTR_PIN_COUNT
ATTR_ROOTback to summary
private static final String ATTR_ROOT
ATTR_TIMEback to summary
private static final String ATTR_TIME
ATTR_TOCback to summary
private static final String ATTR_TOC
ATTR_UNUSEDback to summary
private static final String ATTR_UNUSED
ATTR_UNUSED_AT_VERSIONback to summary
private static final String ATTR_UNUSED_AT_VERSION
ATTR_VERSIONback to summary
private static final String ATTR_VERSION
blockback to summary
public volatile long block

The start block number within the file.

bufferback to summary
public volatile ByteBuffer buffer

ByteBuffer holding this Chunk's serialized content before it gets saved to file store. This allows to release pages of this Chunk earlier, allowing them to be garbage collected.

collectPriorityback to summary
pack-priv int collectPriority

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

idback to summary
public final int id

The chunk id.

layoutRootPosback to summary
pack-priv long layoutRootPos

The position of the root of layout map.

lenback to summary
public int len

The length in number of blocks.

mapIdback to summary
public int mapId

The last used map id.

MAX_HEADER_LENGTHback to summary
pack-priv static final int MAX_HEADER_LENGTH

The maximum length of a chunk header, in bytes. chunk:ffffffff,len:ffffffff,pages:ffffffff,pinCount:ffffffff,max:ffffffffffffffff,map:ffffffff, root:ffffffffffffffff,time:ffffffffffffffff,version:ffffffffffffffff,next:ffffffffffffffff,toc:ffffffff

MAX_IDback to summary
public static final int MAX_ID

The maximum chunk id.

maxLenback to summary
public long maxLen

The sum of the max length of all pages.

maxLenLiveback to summary
public long maxLenLive

The sum of the length of all pages that are still alive.

nextback to summary
public long next

The predicted position of the next chunk.

occupancyback to summary
pack-priv BitSet occupancy

Collection of "deleted" flags for all pages in the chunk.

pageCountback to summary
pack-priv int pageCount

The total number of pages in this chunk.

pageCountLiveback to summary
pack-priv int pageCountLive

The number of pages that are still alive in the latest version of the store.

pinCountback to summary
private int pinCount

Number of live pinned pages.

timeback to summary
public long time

When this chunk was created, in milliseconds since the store was created.

tocPosback to summary
pack-priv int tocPos

Byte offset (from the beginning of the chunk) for the table of content (ToC). 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
unusedback to summary
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).

unusedAtVersionback to summary
pack-priv 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.

versionback to summary
public long version

The version stored in this chunk.

Constructor Detail

Chunkback to summary
pack-priv Chunk(String s)
Chunkback to summary
pack-priv Chunk(Map<String, String> map, boolean full)
Chunkback to summary
pack-priv Chunk(int id)

Method Detail

accountForRemovedPageback to summary
pack-priv 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:int

sequential page number within the chunk

pageLength:int

on disk of the removed page

pinned:boolean

whether removed page was pinned

now:long

is a moment in time (since creation of the store), when removal is recorded, and retention period starts

version:long

at which page was removed

Returns:boolean

true if all of the pages, this chunk contains, were already removed, and false otherwise

accountForWrittenPageback to summary
pack-priv void accountForWrittenPage(int pageLengthOnDisk, boolean singleWriter)

Modifies internal state to reflect the fact that one more page is stored within this chunk.

Parameters
pageLengthOnDisk:int

size of the page

singleWriter:boolean

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

asStringback to summary
public final String asString()

Get the chunk metadata as a string to be stored in a layout map.

Returns:String

the string

dumpback to summary
protected void dump(StringBuilder buff)
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@SuppressWarnings:unchecked
@Override
estimateHeaderSizeback to summary
pack-priv int estimateHeaderSize()

Write the chunk header.

Returns:int

estimated size of the header

getFillRateback to summary
pack-priv int getFillRate()

Calculate the fill rate in %. 0 means empty, 100 means full.

Returns:int

the fill rate

getFooterBytesback to summary
pack-priv byte[] getFooterBytes()
getHeaderback to summary
public String getHeader()
getHeaderBytesback to summary
private byte[] getHeaderBytes()
getMetaKeyback to summary
pack-priv static String getMetaKey(int chunkId)

Get the metadata key for the given chunk id.

Parameters
chunkId:int

the chunk id

Returns:String

the metadata key

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isAllocatedback to summary
pack-priv boolean isAllocated()
isEvacuatableback to summary
private boolean isEvacuatable()
isLiveback to summary
pack-priv boolean isLive()
isRewritableback to summary
pack-priv boolean isRewritable()
isSavedback to summary
pack-priv boolean isSaved()
readBufferForPageback to summary
pack-priv ByteBuffer readBufferForPage(FileStore<C> fileStore, int offset, long pos)

Read a page of data into a ByteBuffer.

Parameters
fileStore:FileStore<C>

to use

offset:int

of the page data

pos:long

page pos

Returns:ByteBuffer

ByteBuffer containing page data.

readChunkHeaderback to summary
pack-priv static String readChunkHeader(ByteBuffer buff)

Read the header from the byte buffer.

Parameters
buff:ByteBuffer

the source buffer

Returns:String

the chunk

Exceptions
MVStoreException:
if buff does not contain a chunk header
readFullyback to summary
protected abstract ByteBuffer readFully(FileStore<C> fileStore, long filePos, int length)
readToCback to summary
pack-priv long[] readToC(FileStore<C> fileStore)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
writeChunkHeaderback to summary
pack-priv void writeChunkHeader(WriteBuffer buff, int maxLength)

Write the chunk header.

Parameters
buff:WriteBuffer

the target buffer

maxLength:int

length of the area reserved for the header

org.h2.mvstore back to summary

public final Class Chunk.PositionComparator<C extends Chunk<C>>

extends Object
implements Comparator<C extends Chunk<C>>
Class Inheritance
All Implemented Interfaces
java.util.Comparator

Field Summary

Modifier and TypeField and Description
public static final Comparator<? extends Chunk<?>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
compare(C
the first object to be compared.
one
,
C
the second object to be compared.
two
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public static <C extends Chunk<C>> Comparator<C>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
public static final Comparator<? extends Chunk<?>> INSTANCE

Constructor Detail

PositionComparatorback to summary
private PositionComparator()

Method Detail

compareback to summary
public int compare(C one, C two)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
one:C

the first object to be compared.

two:C

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Annotations
@Override
instanceback to summary
public static <C extends Chunk<C>> Comparator<C> instance()
Annotations
@SuppressWarnings:unchecked