Package com.illumon.iris.db.v2.utils
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
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IndexShiftData.Builder
Helper utility to build instances ofIndexShiftData
with internally consistent data.static interface
IndexShiftData.Callback
static interface
IndexShiftData.Iterator
static interface
IndexShiftData.SingleElementShiftCallback
static class
IndexShiftData.SmartCoalescingBuilder
Helper utility to build instances ofIndexShiftData
with internally consistent data. -
Field Summary
Fields Modifier and Type Field Description static IndexShiftData
EMPTY
Immutable, re-usableIndexShiftData
for an empty set of shifts. -
Method Summary
Modifier and Type Method Description boolean
apply(Index index)
Apply all shifts to the provided index.void
apply(IndexShiftData.Callback shiftCallback)
Apply all shifts in a memmove-semantics-safe ordering through the providedshiftCallback
.IndexShiftData.Iterator
applyIterator()
static boolean
applyShift(Index index, long beginRange, long endRange, long shiftDelta)
Apply a shift to the provided index.boolean
empty()
Queries whether this IndexShiftData is empty (i.e.boolean
equals(Object obj)
SafeCloseablePair<Index,Index>
extractParallelShiftedRowsFromPostShiftIndex(ReadOnlyIndex postShiftIndex)
This method creates two parallel Index structures that contain postShiftIndex keys affected by shifts.void
forAllInIndex(ReadOnlyIndex filterIndex, IndexShiftData.SingleElementShiftCallback callback)
long
getBeginRange(int idx)
Get the inclusive begin offset of theidx
th shift.long
getEffectiveSize()
The number of keys affected by shift commands.long
getEffectiveSizeClamped(long clamp)
The number of keys affected by shift commands.long
getEndRange(int idx)
Get the inclusive end offset of theidx
th shift.long
getShiftDelta(int idx)
Get the absolute shift of theidx
th shift.IndexShiftData
intersect(ReadOnlyIndex index)
Intersects this IndexShiftData against the provided Index.boolean
nonempty()
Queries whether this IndexShiftData is non-empty (i.e.int
size()
The number of shifts embedded in the payload.String
toString()
String
toString(int maxShifts)
void
unapply(Index index)
Unapply all shifts to the provided index.void
unapply(Index index, long offset)
Unapply all shifts to the provided index.void
unapply(IndexShiftData.Callback shiftCallback)
Apply all shifts in reverse in a memmove-semantics-safe ordering through the providedshiftCallback
.static boolean
unapplyShift(Index index, long beginRange, long endRange, long shiftDelta)
Unapply a shift to the provided index.void
validate()
Verify invariants of internal data structures hold.
-
Field Details
-
EMPTY
Immutable, re-usableIndexShiftData
for an empty set of shifts.
-
-
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 theidx
th shift.- Parameters:
idx
- which pair to get offset for- Returns:
- the offset
-
getEndRange
public long getEndRange(int idx)Get the inclusive end offset of theidx
th shift.- Parameters:
idx
- which pair to get offset for- Returns:
- the offset
-
getShiftDelta
public long getShiftDelta(int idx)Get the absolute shift of theidx
th 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
-
toString
-
equals
-
apply
Apply all shifts in a memmove-semantics-safe ordering through the providedshiftCallback
. Use this to move from pre-shift keyspace to post-shift keyspace.- Parameters:
shiftCallback
- the callback that will process all shifts
-
unapply
Apply all shifts in reverse in a memmove-semantics-safe ordering through the providedshiftCallback
. Use this to move from post-shift keyspace to pre-shift keyspace.- Parameters:
shiftCallback
- the callback that will process all reverse shifts
-
apply
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 tobeginRange
- 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
Unapply all shifts to the provided index. Moves index from post-shift keyspace to pre-shift keyspace.- Parameters:
index
- the index to shift
-
unapply
Unapply all shifts to the provided index. Moves index from post-shift keyspace to pre-shift keyspace.- Parameters:
index
- the index to shiftoffset
- 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 tobeginRange
- 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
-
intersect
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.
-