Class RootReference<K,V>

java.lang.Object
org.h2.mvstore.RootReference<K,V>

public final class RootReference<K,V> extends 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 Details

    • root

      public final Page<K,V> root
      The root page.
    • 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 Details

    • RootReference

      RootReference(Page<K,V> root, long version)
    • 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 Details

    • updateRootPage

      RootReference<K,V> updateRootPage(Page<K,V> newRootPage, long attemptCounter)
      Try to unlock.
      Parameters:
      newRootPage - the new root page
      attemptCounter - 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 version
      attempt - 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 page
      keepLocked - whether to keep it locked
      appendCounter - 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 against
      persistent - 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 String toString()
      Overrides:
      toString in class Object