Package org.h2.mvstore
Class RootReference<K,V>
java.lang.Object
org.h2.mvstore.RootReference<K,V>
Class RootReference is an immutable structure to represent state of the MVMap as a whole
(not related to a particular B-Tree node).
Single structure would allow for non-blocking atomic state change.
The most important part of it is a reference to the root node.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte
Size of the occupied part of the append buffer.private final byte
Counter of reentrant locks.private final long
Lock owner thread id.(package private) RootReference
<K, V> Reference to the previous root in the chain.The root page.(package private) final long
Counter for attempted root updates.(package private) final long
Counter for successful root updates.final long
The version used for writing. -
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
RootReference
(Page<K, V> root, long version) private
RootReference
(RootReference<K, V> r, int attempt) private
RootReference
(RootReference<K, V> r, long version, int attempt) private
RootReference
(RootReference<K, V> r, Page<K, V> root, boolean keepLocked, int appendCounter) private
RootReference
(RootReference<K, V> r, Page<K, V> root, long updateAttemptCounter) -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
(package private) int
long
(package private) long
(package private) boolean
hasChangesSince
(long version, boolean persistent) Does the root have changes since the specified version?private boolean
isFree()
(package private) boolean
isLocked()
boolean
boolean
Whether flushing is needed.(package private) void
removeUnusedOldVersions
(long oldestVersionToKeep) Removed old versions that are not longer used.toString()
(package private) RootReference
<K, V> tryLock
(int attemptCounter) Try to lock.(package private) RootReference
<K, V> tryUnlockAndUpdateVersion
(long version, int attempt) Try to unlock, and if successful update the versionprivate RootReference
<K, V> tryUpdate
(RootReference<K, V> updatedRootReference) (package private) RootReference
<K, V> updatePageAndLockedStatus
(Page<K, V> page, boolean keepLocked, int appendCounter) Update the page, possibly keeping it locked.(package private) RootReference
<K, V> updateRootPage
(Page<K, V> newRootPage, long attemptCounter) Try to unlock.
-
Field Details
-
root
The root page. -
version
public final long versionThe version used for writing. -
holdCount
private final byte holdCountCounter of reentrant locks. -
ownerId
private final long ownerIdLock owner thread id. -
previous
Reference to the previous root in the chain. That is the last root of the previous version, which had any data changes. Versions without any data changes are dropped from the chain, as it built. -
updateCounter
final long updateCounterCounter for successful root updates. -
updateAttemptCounter
final long updateAttemptCounterCounter for attempted root updates. -
appendCounter
private final byte appendCounterSize of the occupied part of the append buffer.
-
-
Constructor Details
-
RootReference
-
RootReference
-
RootReference
-
RootReference
-
RootReference
-
-
Method Details
-
updateRootPage
Try to unlock.- Parameters:
newRootPage
- the new root pageattemptCounter
- the number of attempts so far- Returns:
- the new, unlocked, root reference, or null if not successful
-
tryLock
Try to lock.- Parameters:
attemptCounter
- the number of attempts so far- Returns:
- the new, locked, root reference, or null if not successful
-
tryUnlockAndUpdateVersion
Try to unlock, and if successful update the version- Parameters:
version
- the versionattempt
- the number of attempts so far- Returns:
- the new, unlocked and updated, root reference, or null if not successful
-
updatePageAndLockedStatus
Update the page, possibly keeping it locked.- Parameters:
page
- the pagekeepLocked
- whether to keep it lockedappendCounter
- number of items in append buffer- Returns:
- the new root reference, or null if not successful
-
removeUnusedOldVersions
void removeUnusedOldVersions(long oldestVersionToKeep) Removed old versions that are not longer used.- Parameters:
oldestVersionToKeep
- the oldest version that needs to be retained
-
isLocked
boolean isLocked() -
isFree
private boolean isFree() -
canUpdate
private boolean canUpdate() -
isLockedByCurrentThread
public boolean isLockedByCurrentThread() -
tryUpdate
-
getVersion
long getVersion() -
hasChangesSince
boolean hasChangesSince(long version, boolean persistent) Does the root have changes since the specified version?- Parameters:
version
- to check againstpersistent
- whether map is backed by persistent storage- Returns:
- true if this root has unsaved changes
-
getAppendCounter
int getAppendCounter() -
needFlush
public boolean needFlush()Whether flushing is needed.- Returns:
- true if yes
-
getTotalCount
public long getTotalCount() -
toString
-