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 byteSize of the occupied part of the append buffer.private final byteCounter of reentrant locks.private final longLock owner thread id.(package private) RootReference<K, V> Reference to the previous root in the chain.The root page.(package private) final longCounter for attempted root updates.(package private) final longCounter for successful root updates.final longThe version used for writing. -
Constructor Summary
ConstructorsModifierConstructorDescription(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
Modifier and TypeMethodDescriptionprivate boolean(package private) intlong(package private) long(package private) booleanhasChangesSince(long version, boolean persistent) Does the root have changes since the specified version?private booleanisFree()(package private) booleanisLocked()booleanbooleanWhether flushing is needed.(package private) voidremoveUnusedOldVersions(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
-
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
-
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
-