Package com.illumon.iris.db.v2.utils
Class IndexShiftData.Builder
java.lang.Object
com.illumon.iris.db.v2.utils.IndexShiftData.Builder
- Enclosing class:
- IndexShiftData
public static class IndexShiftData.Builder extends Object
Helper utility to build instances of
IndexShiftData
with internally consistent data.
No other ranges should be added to this builder after build()
is invoked.-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
Modifier and Type Method Description void
appendShiftData(IndexShiftData innerShiftData, long prevOffset, long prevCardinality, long currOffset, long currCardinality)
Use this method to append shifts that propagate from a parent table to a subset of a dependent table.IndexShiftData
build()
Make final modifications to theIndexShiftData
and return it.long
getMinimumValidBeginForNextDelta(long nextShiftDelta)
long
lastShiftEnd()
Gets the last index assigned to a shift.void
limitPreviousShiftFor(long nextShiftBegin, long nextShiftDelta)
This method adjusts the previous shift so that the upcoming shift will not be considered overlapping.boolean
nonempty()
void
shiftRange(long beginRange, long endRange, long shiftDelta)
Shift a range of keys.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
nonempty
public boolean nonempty()- Returns:
- true iff there is at least one shift appended to this builder
-
lastShiftEnd
public long lastShiftEnd()Gets the last index assigned to a shift.- Returns:
- The greatest index assigned to a shift or -1 if no shifts exist yet.
-
shiftRange
public void shiftRange(long beginRange, long endRange, long shiftDelta)Shift a range of keys. The shift must be consistent with previously added shifts.- Parameters:
beginRange
- first key to shift (inclusive)endRange
- last key to shift (inclusive)shiftDelta
- offset to shift by; may be negative
-
getMinimumValidBeginForNextDelta
public long getMinimumValidBeginForNextDelta(long nextShiftDelta) -
build
Make final modifications to theIndexShiftData
and return it.- Returns:
- the built IndexShiftData
-
appendShiftData
public void appendShiftData(IndexShiftData innerShiftData, long prevOffset, long prevCardinality, long currOffset, long currCardinality)Use this method to append shifts that propagate from a parent table to a subset of a dependent table. The canonical use-case is merge, where tables are shifted in key-space so that they do not overlap each other. If one of these merged tables has a shift, then it must propagate these shifts to the merged table in the appropriately shifted key space. This method also supports shifting the entire range in addition to propagating upstream shifts. For example, if a table needs more keyspace, then any tables slotted to the right (in a greater keyspace) will need to shift out of the way to free up the keyspace for the table. This method assumes that 1) the upstream shift data is valid and 2) shifts can be truncated when they extend beyond the table's known range.- Parameters:
innerShiftData
- the upstream shifts oriented in upstream keyspace [0, innerRange)prevOffset
- the previous offset where this sub-table beganprevCardinality
- the cardinality of the keyspace previously allocated to this tablecurrOffset
- the new offset where this sub-table begins (may be equal to prevOffset)currCardinality
- the cardinality of the keyspace currently allocated to this table
-
limitPreviousShiftFor
public void limitPreviousShiftFor(long nextShiftBegin, long nextShiftDelta)This method adjusts the previous shift so that the upcoming shift will not be considered overlapping. This is useful if the previous shift included empty space for efficiency, but would intersect with our new shift.- Parameters:
nextShiftBegin
- The first real-key that needs to shift in the upcoming shift.nextShiftDelta
- The delta that applies to the upcoming shift.
-