Package org.h2.mvstore
Class RootReference<K,V>
- java.lang.Object
-
- org.h2.mvstore.RootReference<K,V>
-
public final class RootReference<K,V> extends java.lang.ObjectClass 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
Fields Modifier and Type Field Description private byteappendCounterSize of the occupied part of the append buffer.private byteholdCountCounter of reentrant locks.private longownerIdLock owner thread id.(package private) RootReference<K,V>previousReference to the previous root in the chain.Page<K,V>rootThe root page.(package private) longupdateAttemptCounterCounter for attempted root updates.(package private) longupdateCounterCounter for successful root updates.longversionThe version used for writing.
-
Constructor Summary
Constructors Modifier Constructor Description (package private)RootReference(Page<K,V> root, long version)privateRootReference(RootReference<K,V> r, int attempt)privateRootReference(RootReference<K,V> r, long version, int attempt)privateRootReference(RootReference<K,V> r, Page<K,V> root, boolean keepLocked, int appendCounter)privateRootReference(RootReference<K,V> r, Page<K,V> root, long updateAttemptCounter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleancanUpdate()(package private) intgetAppendCounter()longgetTotalCount()(package private) longgetVersion()(package private) booleanhasChangesSince(long version, boolean persistent)Does the root have changes since the specified version?private booleanisFree()(package private) booleanisLocked()booleanisLockedByCurrentThread()booleanneedFlush()Whether flushing is needed.(package private) voidremoveUnusedOldVersions(long oldestVersionToKeep)Removed old versions that are not longer used.java.lang.StringtoString()(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 Detail
-
version
public final long version
The version used for writing.
-
holdCount
private final byte holdCount
Counter of reentrant locks.
-
ownerId
private final long ownerId
Lock owner thread id.
-
previous
volatile RootReference<K,V> 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 updateCounter
Counter for successful root updates.
-
updateAttemptCounter
final long updateAttemptCounter
Counter for attempted root updates.
-
appendCounter
private final byte appendCounter
Size of the occupied part of the append buffer.
-
-
Constructor Detail
-
RootReference
private RootReference(RootReference<K,V> r, Page<K,V> root, long updateAttemptCounter)
-
RootReference
private RootReference(RootReference<K,V> r, int attempt)
-
RootReference
private RootReference(RootReference<K,V> r, Page<K,V> root, boolean keepLocked, int appendCounter)
-
RootReference
private RootReference(RootReference<K,V> r, long version, int attempt)
-
-
Method Detail
-
updateRootPage
RootReference<K,V> updateRootPage(Page<K,V> newRootPage, long attemptCounter)
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
RootReference<K,V> tryLock(int attemptCounter)
Try to lock.- Parameters:
attemptCounter- the number of attempts so far- Returns:
- the new, locked, root reference, or null if not successful
-
tryUnlockAndUpdateVersion
RootReference<K,V> tryUnlockAndUpdateVersion(long version, int attempt)
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
RootReference<K,V> updatePageAndLockedStatus(Page<K,V> page, boolean keepLocked, int appendCounter)
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
private RootReference<K,V> tryUpdate(RootReference<K,V> updatedRootReference)
-
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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-