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.Object
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
Fields Modifier and Type Field Description private byte
appendCounter
Size of the occupied part of the append buffer.private byte
holdCount
Counter of reentrant locks.private long
ownerId
Lock owner thread id.(package private) RootReference<K,V>
previous
Reference to the previous root in the chain.Page<K,V>
root
The root page.(package private) long
updateAttemptCounter
Counter for attempted root updates.(package private) long
updateCounter
Counter for successful root updates.long
version
The version used for writing.
-
Constructor Summary
Constructors Modifier Constructor Description (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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
canUpdate()
(package private) int
getAppendCounter()
long
getTotalCount()
(package private) long
getVersion()
(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
isLockedByCurrentThread()
boolean
needFlush()
Whether flushing is needed.(package private) void
removeUnusedOldVersions(long oldestVersionToKeep)
Removed old versions that are not longer used.java.lang.String
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 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:
toString
in classjava.lang.Object
-
-