Enum LogicalClock

java.lang.Object
java.lang.Enum<LogicalClock>
com.illumon.iris.db.v2.sources.LogicalClock
All Implemented Interfaces:
Serializable, Comparable<LogicalClock>, java.lang.constant.Constable

public enum LogicalClock
extends Enum<LogicalClock>

A logical update clock that has two states, Updating and Idle.

Each time startUpdateCycle() is called, the clock transitions to the Updating state and the current value is incremented by one.

When completeUpdateCycle() is called, the clock transitions back to Idle.

  • Enum Constant Details

  • Method Details

    • values

      public static LogicalClock[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static LogicalClock valueOf​(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • getStep

      public static long getStep​(long value)
      Get the clock step for the input clock value. The step increments one time for each complete start - end cycle.
      Parameters:
      value - The clock value to get the step for
      Returns:
      The clock step associated with value
    • getState

      public static LogicalClock.State getState​(long value)
      Get the LogicalClock.State of the LogicalClock for a particular clock value.
      Parameters:
      value - The clock value
      Returns:
      The clock state associated with the input value
    • currentValue

      public final long currentValue()
      Get the current value of the clock.
    • currentStep

      public final long currentStep()
      Get the current Step of the clock.
      See Also:
      getStep(long)
    • currentState

      public final LogicalClock.State currentState()
      Get the current clock state.
      See Also:
      getState(long)
    • startUpdateCycle

      public final long startUpdateCycle()
      Increment the current value and set the clock state to updating.
      ImplNote:
      The clock must have been idle before this method is called.
    • completeUpdateCycle

      public final void completeUpdateCycle()
      Increment the current step and set the clock state to idle.
      ImplNote:
      The clock must have been updating before this method is called.
    • ensureUpdateCycleCompleted

      public final void ensureUpdateCycleCompleted​(long updatingCycleValue)
      After we complete a table refresh, we must ensure that the logical clock is idle.

      The only valid possibilities are (1) we have completed the cycle, in which case we return; or (2) we have terminated the cycle early and have the same value as at the start of our updating cycle, in which case we complete the cycle.

      If our clock is any other value; then it was changed out from under us and we throw an exception.

      Parameters:
      updatingCycleValue - the clock value at the end of startUpdateCycle()
    • resetForUnitTests

      @TestUseOnly public final void resetForUnitTests()
      Reset the clock to its initial state, in order to ensure that unit tests proceed cleanly.