Top Description Inners Fields Constructors Methods
org.h2.mvstore

public abstract Class Page<K, V>

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Known Direct Subclasses
org.h2.mvstore.Page.NonLeaf, org.h2.mvstore.Page.Leaf
Static Imports
org.h2.engine.Constants.MEMORY_ARRAY, .Constants.MEMORY_OBJECT, .Constants.MEMORY_POINTER, org.h2.mvstore.DataUtils.PAGE_TYPE_LEAF

A page (a node or a leaf).

For b-tree nodes, the key at a given index is larger than the largest key of the child at the same index.

Serialized format: length of a serialized page in bytes (including this field): int check value: short page number (0-based sequential number within a chunk): varInt map id: varInt number of keys: varInt type: byte (0: leaf, 1: node; +2: compressed) children of the non-leaf node (1 more than keys) compressed: bytes saved (varInt) keys values of the leaf node (one for each key)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
Page.Leaf<K, V>

private static class
public static class
Page.PageReference<K, V>

A pointer to a page, either in-memory or using a page position.

Field Summary

Modifier and TypeField and Description
private int
cachedCompare

The last result of a find operation is cached.

private int
diskSpaceUsed

Amount of used disk space by this page only in persistent case.

private static final int
IN_MEMORY

Marker value for memory field, meaning that memory accounting is replaced by key count.

private K[]
keys

The keys.

public final MVMap<K, V>
map

Map this page belongs to

private int
memory

The estimated memory used in persistent case, IN_MEMORY marker value otherwise.

pack-priv static final int
PAGE_LEAF_MEMORY

The estimated number of bytes used per empty leaf page.

private static final int
PAGE_MEMORY

The estimated number of bytes used per base page.

pack-priv static final int
PAGE_MEMORY_CHILD

The estimated number of bytes used per child entry.

pack-priv static final int
PAGE_NODE_MEMORY

The estimated number of bytes used per empty internal page object.

public int
pageNo

Sequential 0-based number of the page within containing chunk.

private volatile long
pos

Position of this page's saved image within a Chunk or 0 if this page has not been saved yet or 1 if this page has not been saved yet, but already removed This "removed" flag is to keep track of pages that concurrently changed while they are being stored, in which case the live bookkeeping needs to be aware of this fact.

private static final AtomicLongFieldUpdater<Page<K, V>>
posUpdater

Updater for pos field, which can be updated when page is saved, but can be concurrently marked as removed

private static final Page.PageReference<K, V>[]

Constructor Summary

AccessConstructor and Description
pack-priv
Page(MVMap<K, V> map)

pack-priv
Page(MVMap<K, V> map, Page<K, V> source)

pack-priv
Page(MVMap<K, V> map, K[] keys)

Method Summary

Modifier and TypeMethod and Description
pack-priv final void
addMemory(int
additional memory size.
mem
)

Increase estimated memory used in persistent case.

pack-priv int

Returns:

the value or null
binarySearch
(K
the key
key
)

Search the key in this page using a binary search.

protected int

Returns:

memory in bytes
calculateMemory
()

Calculate estimated memory used in persistent case.

protected final Page<K, V>
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.

pack-priv abstract Page<K, V>

Returns:

the page
copy
(MVMap<K, V>
new map to own resulting page
map
,
boolean
whether cloned Page should have no child references or keep originals
eraseChildrenRefs
)

Create a copy of this page with potentially different owning map.

public final Page<K, V>

Returns:

a mutable copy of this page
copy
()

Create a copy of this page.

pack-priv static <
key type
K
,
value type
V
>
Page<K, V>

Returns:

the new page
createEmptyLeaf
(MVMap<K, V>
the map
map
)

Create a new, empty leaf page.

pack-priv static <
key type
K
,
value type
V
>
Page<K, V>

Returns:

the new page
createEmptyNode
(MVMap<K, V>
the map
map
)

Create a new, empty internal node page.

public final K[]

Returns:

values array
createKeyStorage
(int
number of entries
size
)

Create array for keys storage.

pack-priv static <
key type
K
,
value type
V
>
Page<K, V>

Returns:

the page
createLeaf
(MVMap<K, V>
the map
map
,
K[]
the keys
keys
,
V[]
the values
values
,
int
the memory used in bytes
memory
)

Create a new leaf page.

public static <
the key class
K
,
the value class
V
>
Page<K, V>

Returns:

the page
createNode
(MVMap<K, V>
the map
map
,
K[]
the keys
keys
,
Page.PageReference<K, V>[]
the child page positions
children
,
long
the total number of keys
totalCount
,
int
the memory used in bytes
memory
)

Create a new non-leaf page.

public static <
the key class
K
,
the value class
V
>
Page.PageReference<K, V>[]

Returns:

the array
createRefStorage
(int
the number of entries
size
)

Create an array of page references.

pack-priv final V[]

Returns:

values array
createValueStorage
(int
number of entries
size
)

Create array for values storage.

protected void
dump(StringBuilder
append buffer
buff
)

Dump debug data for this page.

pack-priv abstract void
expand(int
number of mappings to be added
extraKeyCount
,
K[]
to be added
extraKeys
,
V[]
to be added
extraValues
)

Append additional key/value mappings to this Page.

pack-priv final void
expandKeys(int
number of extra key entries to create
extraKeyCount
,
K[]
extra key values
extraKeys
)

Expand the keys array.

pack-priv static <
key type
K
,
value type
V
>
V

Returns:

the value, or null if not found
get
(Page<K, V>
the root page
p
,
K
the key
key
)

Get the value for the given key, or null if not found.

public abstract CursorPos<K, V>

Returns:

new head of the CursorPos chain
getAppendCursorPos
(CursorPos<K, V>
presumably pointing to this Page (null if real root), to build upon
cursorPos
)

Extend path from a given CursorPos chain to "append point" in a B-tree, rooted at this Page.

public abstract Page<K, V>

Returns:

the child page
getChildPage
(int
the index
index
)

Get the child page at the given index.

public abstract long

Returns:

the position
getChildPagePos
(int
the index
index
)

Get the position of the child.

pack-priv abstract long

Returns:

the descendant count
getCounts
(int
the child index
index
)

Get the number of key-value pairs for a given child.

public final long

Returns:

amount of used disk space in persistent case
getDiskSpaceUsed
(boolean
true to return quick approximation
approximate
)

Amount of used disk space in persistent case including child pages.

private long
private long
getDiskSpaceUsedApproximation(int maxLevel, boolean f)

public K

Returns:

the key
getKey
(int
the index
index
)

Get the key at the given index.

public final int

Returns:

the number of keys
getKeyCount
()

Get the number of keys in this page.

public final int

Returns:

id
getMapId
()

Get the id of the page's owner map

public final int
public abstract int
public final long

Returns:

the position
getPos
()

Get the position of the page

public abstract CursorPos<K, V>

Returns:

new head of the CursorPos chain
getPrependCursorPos
(CursorPos<K, V>
presumably pointing to this Page (null if real root), to build upon
cursorPos
)

Extend path from a given CursorPos chain to "prepend point" in a B-tree, rooted at this Page.

public abstract int
public abstract long

Returns:

the number of key-value pairs
getTotalCount
()

Get the total number of key-value pairs, including child pages.

public abstract V

Returns:

the value
getValue
(int
the index
index
)

Get the value at the given index.

private void
initMemoryAccount(int memoryCount)

pack-priv final void
insertKey(int
index to insert at
index
,
K
the key value
key
)

Insert a key into the key array

public abstract void
insertLeaf(int
the index
index
,
K
the key
key
,
V
the value
value
)

Insert a key-value pair into this leaf.

public abstract void
insertNode(int
the index
index
,
K
the key
key
,
Page<K, V>
the child page
childPage
)

Insert a child page into this node.

public boolean
public final boolean

Returns:

true if it is a leaf
isLeaf
()

Check whether this is a leaf page.

protected final boolean
public final boolean
public final boolean
private boolean

Returns:

true if it was marked by this call or has been marked already, false if page has been saved already.
markAsRemoved
()

Mark this page as removed "in memory".

pack-priv static <
key type
K
,
value type
V
>
Page<K, V>

Returns:

the page
read
(ByteBuffer
ByteBuffer containing serialized page info
buff
,
long
the position
pos
,
MVMap<K, V>
the map
map
)

Read a page.

private void
read(ByteBuffer
the buffer to read from
buff
)

Read the page from the buffer.

protected abstract void
readPayLoad(ByteBuffer
the buffer
buff
)

Read the page payload from the buffer.

pack-priv final void
recalculateMemory()

Recalculate estimated memory used in persistent case.

pack-priv abstract void
releaseSavedPages()

Unlink the children recursively after all data is written.

public void
remove(int
the index
index
)

Remove the key and value (or child) at the given index.

public abstract int

Returns:

adjustment for "unsaved memory" amount
removeAllRecursive
(long
at which page got removed
version
)

Remove all page data recursively.

public final int

Returns:

amount (negative), by which "unsaved memory" should be adjusted, if page is unsaved one, and 0 for page that was already saved, or in case of non-persistent map
removePage
(long
at which page was removed
version
)

Make accounting changes (chunk occupancy or "unsaved" RAM), related to this page removal.

public abstract void
setChild(int
the index
index
,
Page<K, V>
the new child page
c
)

Replace the child page.

public void
setComplete()

Called when done with copying page.

public final void
setKey(int
the index
index
,
K
the new key
key
)

Replace the key at an index in this page.

public abstract V

Returns:

the old value
setValue
(int
the index
index
,
V
the new value
value
)

Replace the value at an index in this page.

pack-priv abstract Page<K, V>

Returns:

the page with the entries after the split index
split
(int
the split index
at
)

Split the page.

pack-priv final K[]

Returns:

the second array.
splitKeys
(int
size of the first array.
aCount
,
int
size of the second array/
bCount
)

Split the current keys array into two arrays.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

protected final int

Returns:

the position of the buffer, where serialized child page references (if any) begin
write
(FileStore<?>.PageSerializationManager
which provides a target buffer and can be queried for various attributes related to serialization
pageSerializationManager
)

Serializes this page into provided buffer, which represents content of the specified chunk to be persisted and updates the "position" of the page.

protected abstract void
writeChildren(WriteBuffer
the target buffer
buff
,
boolean
true if the descendant counts should be written
withCounts
)

Write page children to the buff.

pack-priv abstract void
writeUnsavedRecursive(FileStore.PageSerializationManager
which provides a target buffer and can be queried for various attributes related to serialization
pageSerializationManager
)

Store this page and all children that are changed, in reverse order, and update the position and the children.

protected abstract void
writeValues(WriteBuffer
the target buffer
buff
)

Write values that the buffer contains to the buff.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait