Class ConstructSnapshot

java.lang.Object
io.deephaven.engine.table.impl.remote.ConstructSnapshot

public class ConstructSnapshot extends Object
A Set of static utilities for computing values from a table while avoiding the use of an update graph lock. This class supports snapshots in both position space and key space.
  • Field Details

    • SNAPSHOT_CHUNK_SIZE

      public static final int SNAPSHOT_CHUNK_SIZE
  • Constructor Details

    • ConstructSnapshot

      public ConstructSnapshot()
  • Method Details

    • state

      public static ConstructSnapshot.State state()
      Get the currently active snapshot state.
      Returns:
      the currently active snapshot state
    • concurrentAttemptInconsistent

      public static boolean concurrentAttemptInconsistent()
      Test that determines whether the currently active concurrent snapshot attempt has become inconsistent. Always returns false if there is no snapshot attempt active, or if there is a locked attempt active (necessarily at lower depth than the lowest concurrent attempt).

      Equivalent to state().concurrentAttemptInconsistent().

      Returns:
      Whether the clock or sources have changed in such a way as to make the currently active concurrent snapshot attempt inconsistent
      See Also:
    • failIfConcurrentAttemptInconsistent

      public static void failIfConcurrentAttemptInconsistent()
      Check that fails if the currently active concurrent snapshot attempt has become inconsistent. This is a no-op if there is no snapshot attempt active, or if there is a locked attempt active (necessarily at lower depth than the lowest concurrent attempt).

      Equivalent to state().failIfConcurrentAttemptInconsistent().

      Throws:
      ConstructSnapshot.SnapshotInconsistentException - If the currently active concurrent snapshot attempt has become inconsistent
      See Also:
    • maybeWaitForSatisfaction

      public static void maybeWaitForSatisfaction(@Nullable NotificationQueue.Dependency dependency)
      Wait for a dependency to become satisfied on the current cycle if we're trying to use current values for the currently active concurrent snapshot attempt. This is a no-op if there is no snapshot attempt active, or if there is a locked attempt active (necessarily at lower depth than the lowest concurrent attempt).

      Equivalent to state().maybeWaitForSatisfaction(dependency).

      Parameters:
      dependency - The dependency, which may be null to avoid redundant checks in calling code
      Throws:
      ConstructSnapshot.SnapshotInconsistentException - If we cannot wait for this dependency on the current step because the step changed
      See Also:
    • getConcurrentAttemptClockValue

      public static long getConcurrentAttemptClockValue()
      Return the currently active concurrent snapshot attempt's "before" clock value, or zero if there is no concurrent attempt active.

      Equivalent to state().getConcurrentAttemptClockValue().

      Returns:
      The concurrent snapshot attempt's "before" clock value, or zero
      See Also:
    • appendConcurrentAttemptClockInfo

      public static LogOutput appendConcurrentAttemptClockInfo(@NotNull @NotNull LogOutput logOutput)
      Append clock info that pertains to the concurrent attempt state to logOutput.

      Equivalent to state().appendConcurrentAttemptClockInfo(logOutput).

      Parameters:
      logOutput - The LogOutput
      Returns:
      logOutput
      See Also:
    • constructBackplaneSnapshot

      public static BarrageMessage constructBackplaneSnapshot(@NotNull @NotNull Object logIdentityObject, @NotNull @NotNull BaseTable<?> table)
      Create a snapshot of the specified table including all columns and rows. Note that this method is notification-oblivious, i.e. it makes no attempt to ensure that notifications are not missed.
      Parameters:
      logIdentityObject - An object used to prepend to log rows.
      table - the table to snapshot.
      Returns:
      a snapshot of the entire base table.
    • constructBackplaneSnapshotInPositionSpace

      public static BarrageMessage constructBackplaneSnapshotInPositionSpace(@NotNull @NotNull Object logIdentityObject, @NotNull @NotNull BaseTable<?> table, @Nullable @Nullable BitSet columnsToSnapshot, @Nullable @Nullable RowSequence positionsToSnapshot, @Nullable @Nullable RowSequence reversePositionsToSnapshot)
      Create a snapshot of the specified table using a set of requested columns and positions. Note that this method uses a RowSet that is in position space, and that it is notification-oblivious, i.e. it makes no attempt to ensure that notifications are not missed.
      Parameters:
      logIdentityObject - An object used to prepend to log rows.
      table - the table to snapshot.
      columnsToSnapshot - A BitSet of columns to include, null for all
      positionsToSnapshot - RowSet of positions within the table to include, null for all
      Returns:
      a snapshot of the entire base table.
    • constructBackplaneSnapshotInPositionSpace

      public static BarrageMessage constructBackplaneSnapshotInPositionSpace(@NotNull @NotNull Object logIdentityObject, @NotNull @NotNull BaseTable<?> table, @Nullable @Nullable BitSet columnsToSnapshot, @Nullable @Nullable RowSequence positionsToSnapshot, @Nullable @Nullable RowSequence reversePositionsToSnapshot, @NotNull @NotNull ConstructSnapshot.SnapshotControl control)
      Create a snapshot of the specified table using a set of requested columns and positions. Note that this method uses a RowSet that is in position space.
      Parameters:
      logIdentityObject - An object used to prepend to log rows.
      table - the table to snapshot.
      columnsToSnapshot - A BitSet of columns to include, null for all
      positionsToSnapshot - A RowSequence of positions within the table to include, null for all
      reversePositionsToSnapshot - A RowSequence of reverse positions within the table to include, null for all
      control - A ConstructSnapshot.SnapshotControl to define the parameters and consistency for this snapshot
      Returns:
      a snapshot of the entire base table.
    • makeSnapshotControl

      public static ConstructSnapshot.SnapshotControl makeSnapshotControl(@NotNull @NotNull UpdateGraph updateGraph, @NotNull @NotNull ConstructSnapshot.UsePreviousValues usePreviousValues, @NotNull @NotNull ConstructSnapshot.SnapshotConsistent snapshotConsistent, @Nullable @Nullable ConstructSnapshot.SnapshotCompletedConsistently snapshotCompletedConsistently)
      Make a ConstructSnapshot.SnapshotControl from individual function objects.
      Parameters:
      updateGraph - The UpdateGraph for the snapshot
      usePreviousValues - The ConstructSnapshot.UsePreviousValues to use
      snapshotConsistent - The ConstructSnapshot.SnapshotConsistent to use
      snapshotCompletedConsistently - The ConstructSnapshot.SnapshotCompletedConsistently to use, or null to use snapshotConsistent
    • makeSnapshotControl

      public static ConstructSnapshot.SnapshotControl makeSnapshotControl(boolean notificationAware, boolean refreshing, @NotNull @NotNull NotificationStepSource source)
      Make a default ConstructSnapshot.SnapshotControl for a single source.
      Parameters:
      notificationAware - Whether the result should be concerned with not missing notifications
      refreshing - Whether the data source (usually a Table table) is refreshing (vs static)
      source - The source
      Returns:
      An appropriate ConstructSnapshot.SnapshotControl
    • makeSnapshotControl

      public static ConstructSnapshot.SnapshotControl makeSnapshotControl(boolean notificationAware, boolean refreshing, @NotNull @NotNull NotificationStepSource... sources)
      Make a default ConstructSnapshot.SnapshotControl for one or more sources.
      Parameters:
      notificationAware - Whether the result should be concerned with not missing notifications
      refreshing - Whether any of the data sources (usually tables) are refreshing (vs static)
      sources - The sources
      Returns:
      An appropriate ConstructSnapshot.SnapshotControl
    • callDataSnapshotFunction

      public static long callDataSnapshotFunction(@NotNull @NotNull String logPrefix, @NotNull @NotNull ConstructSnapshot.SnapshotControl control, @NotNull @NotNull ConstructSnapshot.SnapshotFunction function)
      Invokes the snapshot function in a loop until it succeeds with provably consistent results, or until MAX_CONCURRENT_ATTEMPTS or MAX_CONCURRENT_ATTEMPT_DURATION_MILLIS are exceeded. Falls back to acquiring a shared update graph lock for a final attempt.
      Parameters:
      logPrefix - A prefix for our log messages
      control - A ConstructSnapshot.SnapshotControl to define the parameters and consistency for this snapshot
      function - The function to execute
      Returns:
      The logical clock step that applied to this snapshot
    • callDataSnapshotFunction

      public static long callDataSnapshotFunction(@NotNull @NotNull LogOutputAppendable logPrefix, @NotNull @NotNull ConstructSnapshot.SnapshotControl control, @NotNull @NotNull ConstructSnapshot.SnapshotFunction function)
      Invokes the snapshot function in a loop until it succeeds with provably consistent results, or until MAX_CONCURRENT_ATTEMPTS or MAX_CONCURRENT_ATTEMPT_DURATION_MILLIS are exceeded. Falls back to acquiring a shared update graph lock for a final attempt.

      The supplied ConstructSnapshot.SnapshotControl's usePreviousValues will be invoked at the start of any snapshot attempt, and its snapshotCompletedConsistently will be invoked at the end of any snapshot attempt that is not provably inconsistent.

      If the supplied ConstructSnapshot.SnapshotControl provides a null UpdateGraph, then this method will perform a static snapshot without locks or retrying. In this case, the ConstructSnapshot.SnapshotControl's usePreviousValues must return false, snapshotCompletedConsistently must return true, and the NULL_CLOCK_VALUE will be supplied to usePreviousValues and snapshotCompletedConsistently.

      Parameters:
      logPrefix - A prefix for our log messages
      control - A ConstructSnapshot.SnapshotControl to define the parameters and consistency for this snapshot
      function - The function to execute
      Returns:
      The logical clock step that applied to this snapshot; -1L for static snapshots