Class IndexShiftData

java.lang.Object
com.illumon.iris.db.v2.utils.IndexShiftData
All Implemented Interfaces:
Serializable

public final class IndexShiftData
extends Object
implements Serializable
A set of sorted shifts. To apply shifts without losing data, use apply(Callback). The callback will be invoked with shifts in an order that will preserve data when applied immediately using memmove semantics. Internally the shifts are ordered by rangeStart. The IndexShiftData.Builder will verify that no two ranges overlap before or after shifting and assert that the constructed IndexShiftData will be valid.
See Also:
Serialized Form
  • Field Details

  • Method Details

    • size

      public int size()
      The number of shifts embedded in the payload.
      Returns:
      the number of shifts
    • getEffectiveSize

      public long getEffectiveSize()
      The number of keys affected by shift commands.
      Returns:
      number of keys affected by shifts
    • getEffectiveSizeClamped

      public long getEffectiveSizeClamped​(long clamp)
      The number of keys affected by shift commands.
      Parameters:
      clamp - the maximum size to return
      Returns:
      number of keys affected by shifts
    • getBeginRange

      public long getBeginRange​(int idx)
      Get the inclusive begin offset of the idxth shift.
      Parameters:
      idx - which pair to get offset for
      Returns:
      the offset
    • getEndRange

      public long getEndRange​(int idx)
      Get the inclusive end offset of the idxth shift.
      Parameters:
      idx - which pair to get offset for
      Returns:
      the offset
    • getShiftDelta

      public long getShiftDelta​(int idx)
      Get the absolute shift of the idxth shift.
      Parameters:
      idx - which pair to get shift for
      Returns:
      the shift
    • validate

      public void validate()
      Verify invariants of internal data structures hold.
    • empty

      public boolean empty()
      Queries whether this IndexShiftData is empty (i.e. has no shifts).
      Returns:
      true if the size() of this is zero, false if the size is greater than zero
    • nonempty

      public boolean nonempty()
      Queries whether this IndexShiftData is non-empty (i.e. has at least one shift).
      Returns:
      true if the size() of this Index greater than zero, false if the size is zero
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString​(int maxShifts)
    • equals

      public boolean equals​(Object obj)
      Overrides:
      equals in class Object
    • apply

      public void apply​(@NotNull IndexShiftData.Callback shiftCallback)
      Apply all shifts in a memmove-semantics-safe ordering through the provided shiftCallback. Use this to move from pre-shift keyspace to post-shift keyspace.
      Parameters:
      shiftCallback - the callback that will process all shifts
    • unapply

      public void unapply​(@NotNull IndexShiftData.Callback shiftCallback)
      Apply all shifts in reverse in a memmove-semantics-safe ordering through the provided shiftCallback. Use this to move from post-shift keyspace to pre-shift keyspace.
      Parameters:
      shiftCallback - the callback that will process all reverse shifts
    • apply

      public boolean apply​(@NotNull Index index)
      Apply all shifts to the provided index. Moves index from pre-shift keyspace to post-shift keyspace.
      Parameters:
      index - the index to shift
      Returns:
      true if the parameter index was modified.
    • applyShift

      public static boolean applyShift​(@NotNull Index index, long beginRange, long endRange, long shiftDelta)
      Apply a shift to the provided index. Moves index from pre-shift keyspace to post-shift keyspace.
      Parameters:
      index - The index to apply the shift to
      beginRange - start of range (inclusive)
      endRange - end of range (inclusive)
      shiftDelta - amount range has moved by
      Returns:
      Whether there was any overlap found to shift
    • unapply

      public void unapply​(@NotNull Index index)
      Unapply all shifts to the provided index. Moves index from post-shift keyspace to pre-shift keyspace.
      Parameters:
      index - the index to shift
    • unapply

      public void unapply​(@NotNull Index index, long offset)
      Unapply all shifts to the provided index. Moves index from post-shift keyspace to pre-shift keyspace.
      Parameters:
      index - the index to shift
      offset - an additional offset to apply to all shifts (such as when applying to a wrapped table)
    • unapplyShift

      public static boolean unapplyShift​(@NotNull Index index, long beginRange, long endRange, long shiftDelta)
      Unapply a shift to the provided index. Moves index from post-shift keyspace to pre-shift keyspace.
      Parameters:
      index - The index to apply the shift to
      beginRange - start of range (inclusive)
      endRange - end of range (inclusive)
      shiftDelta - amount range has moved by
      Returns:
      Whether there was any overlap found to shift
    • forAllInIndex

      public void forAllInIndex​(@NotNull ReadOnlyIndex filterIndex, @NotNull IndexShiftData.SingleElementShiftCallback callback)
    • applyIterator

      public IndexShiftData.Iterator applyIterator()
    • intersect

      public IndexShiftData intersect​(@NotNull ReadOnlyIndex index)
      Intersects this IndexShiftData against the provided Index.
      Parameters:
      index - the index to test for intersections (pre-shift keyspace)
      Returns:
      an IndexShiftData containing only non-empty shifts
    • extractParallelShiftedRowsFromPostShiftIndex

      public SafeCloseablePair<Index,​Index> extractParallelShiftedRowsFromPostShiftIndex​(@NotNull ReadOnlyIndex postShiftIndex)
      This method creates two parallel Index structures that contain postShiftIndex keys affected by shifts. The two Indexes have the same size. An element at position k in the first index is the pre-shift key for the same row whose post-shift key is at position k in the second index.
      Parameters:
      postShiftIndex - The index of keys that were shifted in post-shift keyspace. It should not contain rows that did not exist prior to the shift.
      Returns:
      A SafeCloseablePair of preShiftedKeys and postShiftedKeys that intersect this IndexShiftData with postShiftIndex.