@API(value=MAINTAINED) public abstract class StandardIndexMaintainer extends IndexMaintainer
IndexMaintainer
implementation.Modifier and Type | Field and Description |
---|---|
protected static int |
TOO_LARGE_VALUE_MESSAGE_LIMIT |
state
Modifier | Constructor and Description |
---|---|
protected |
StandardIndexMaintainer(IndexMaintainerState state) |
Modifier and Type | Method and Description |
---|---|
CompletableFuture<Boolean> |
addedRangeWithKey(Tuple primaryKey)
Whether this key has been added to some range within the
RangeSet
associated with this index. |
protected static boolean |
canDeleteWhere(IndexMaintainerState state,
QueryToKeyMatcher.Match match,
Key.Evaluated evaluated) |
boolean |
canDeleteWhere(QueryToKeyMatcher matcher,
Key.Evaluated evaluated)
Get whether this index scan delete records matching a particular key query.
|
boolean |
canEvaluateAggregateFunction(IndexAggregateFunction function)
Get whether this index can be used to evaluate the given aggregate function.
|
boolean |
canEvaluateRecordFunction(IndexRecordFunction<?> function)
Return
true if this index be used to evaluate the given record function. |
protected <M extends Message> |
checkKeyValueSizes(FDBIndexableRecord<M> savedRecord,
Tuple valueKey,
Tuple value,
byte[] keyBytes,
byte[] valueBytes) |
protected List<IndexEntry> |
commonKeys(List<IndexEntry> oldIndexEntries,
List<IndexEntry> newIndexEntries) |
protected Tuple |
decodeValue(byte[] value)
Decode value portion of key value pair.
|
CompletableFuture<Void> |
deleteWhere(Transaction tr,
Tuple prefix)
Clear index storage associated with the given key prefix.
|
CompletableFuture<Tuple> |
evaluateAggregateFunction(IndexAggregateFunction function,
TupleRange range,
IsolationLevel isolationLevel)
Evaluate an aggregate function over the given range using this index.
|
protected <M extends Message> |
evaluateIndex(FDBRecord<M> record)
Apply the key and value expressions to a
record . |
<T,M extends Message> |
evaluateRecordFunction(EvaluationContext context,
IndexRecordFunction<T> function,
FDBRecord<M> record)
Evaluate a record function on the given record.
|
protected <M extends Message> |
filteredIndexEntries(FDBIndexableRecord<M> savedRecord)
Filter out index keys according to
IndexMaintenanceFilter . |
protected Executor |
getExecutor() |
protected int |
getGroupedCount() |
protected int |
getGroupingCount() |
protected FDBStoreTimer |
getTimer() |
protected Tuple |
indexEntryKey(Tuple valueKey,
Tuple primaryKey)
The entire index key to be used, including both the indexed value(s) and the primary key(s), with redundancy
removed.
|
boolean |
isIdempotent()
Whether updating or removing a record on this index is idempotent.
|
protected static <T> List<T> |
makeMutable(List<T> list) |
CompletableFuture<IndexOperationResult> |
performOperation(IndexOperation operation)
Perform a type-specific operation on index.
|
protected void |
saveIndexEntryAsKeyValue(IndexEntry keyValue)
Manually save an index entry, for example when rebuilding in place with a different storage format.
|
protected RecordCursor<IndexEntry> |
scan(TupleRange range,
byte[] continuation,
ScanProperties scanProperties)
Scan the primary index tree for the given range.
|
RecordCursor<IndexEntry> |
scanUniquenessViolations(TupleRange range,
byte[] continuation,
ScanProperties scanProperties)
Scans through the list of uniqueness violations within the database.
|
boolean |
skipUpdateForUnchangedKeys() |
protected static String |
trimTooLargeTuple(Tuple tuple) |
protected IndexEntry |
unpackKeyValue(KeyValue kv)
Convert stored key value pair into an index entry.
|
protected IndexEntry |
unpackKeyValue(Subspace subspace,
KeyValue kv)
Convert stored key value pair located in the given subspace into an index entry.
|
<M extends Message> |
update(FDBIndexableRecord<M> oldRecord,
FDBIndexableRecord<M> newRecord)
Update associated index for a changed record.
|
protected <M extends Message> |
updateIndexKeys(FDBIndexableRecord<M> savedRecord,
boolean remove,
List<IndexEntry> indexEntries)
Update index according to record keys.
|
protected <M extends Message> |
updateIndexKeysFunction(FDBIndexableRecord<M> savedRecord,
boolean remove,
List<IndexEntry> indexEntries) |
protected <M extends Message> |
updateOneKey(FDBIndexableRecord<M> savedRecord,
boolean remove,
IndexEntry indexEntry)
Store a single key in the index.
|
void |
updateUniquenessViolations(Tuple valueKey,
Tuple primaryKey,
Tuple existingKey,
boolean remove)
Remove or add a uniqueness violation within the database.
|
RecordCursor<InvalidIndexEntry> |
validateEntries(byte[] continuation,
ScanProperties scanProperties)
Validate the integrity of the index (such as identifying index entries that do not point to records or
identifying records that do not point to valid index entries).
|
protected RecordCursor<InvalidIndexEntry> |
validateOrphanEntries(byte[] continuation,
ScanProperties scanProperties)
Validate entries in the index.
|
getIndexSubspace, getSecondarySubspace, scan, unsupportedAggregateFunction, unsupportedRecordFunction
protected static final int TOO_LARGE_VALUE_MESSAGE_LIMIT
protected StandardIndexMaintainer(IndexMaintainerState state)
@Nullable protected FDBStoreTimer getTimer()
protected RecordCursor<IndexEntry> scan(@Nonnull TupleRange range, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
range
- range of index keys to scancontinuation
- any continuation from previous scanscanProperties
- any limits on the scan@Nonnull protected IndexEntry unpackKeyValue(@Nonnull KeyValue kv)
kv
- a raw key-value from the database@Nonnull protected IndexEntry unpackKeyValue(@Nonnull Subspace subspace, @Nonnull KeyValue kv)
subspace
- the database subspace for the indexkv
- a raw key-value within subspace
@Nonnull protected Tuple decodeValue(@Nonnull byte[] value)
value
- the raw value portion of a key value pairpublic boolean skipUpdateForUnchangedKeys()
@Nonnull public <M extends Message> CompletableFuture<Void> update(@Nullable FDBIndexableRecord<M> oldRecord, @Nullable FDBIndexableRecord<M> newRecord)
IndexMaintainer
update
in class IndexMaintainer
M
- type of messageoldRecord
- the previous stored record or null
if a new record is being creatednewRecord
- the new record or null
if an old record is being deleted@Nullable protected <M extends Message> List<IndexEntry> filteredIndexEntries(@Nullable FDBIndexableRecord<M> savedRecord)
IndexMaintenanceFilter
.
Keys that do not pass the filter will not be stored / removed from the index.M
- the message type of the recordsavedRecord
- record for key evaluation@Nonnull protected List<IndexEntry> commonKeys(@Nonnull List<IndexEntry> oldIndexEntries, @Nonnull List<IndexEntry> newIndexEntries)
@Nonnull protected <M extends Message> Function<Void,CompletableFuture<Void>> updateIndexKeysFunction(@Nonnull FDBIndexableRecord<M> savedRecord, boolean remove, @Nonnull List<IndexEntry> indexEntries)
protected <M extends Message> CompletableFuture<Void> updateIndexKeys(@Nonnull FDBIndexableRecord<M> savedRecord, boolean remove, @Nonnull List<IndexEntry> indexEntries)
M
- the message type of the recordsavedRecord
- the record being indexedremove
- true
if removing from indexindexEntries
- the result of evaluateIndex(FDBRecord)
protected <M extends Message> void updateOneKey(@Nonnull FDBIndexableRecord<M> savedRecord, boolean remove, @Nonnull IndexEntry indexEntry)
M
- the message type of the recordsavedRecord
- the record being indexedremove
- true
if removing from indexindexEntry
- the entry for the index to be updated@Nonnull public void updateUniquenessViolations(@Nonnull Tuple valueKey, @Nonnull Tuple primaryKey, @Nullable Tuple existingKey, boolean remove)
IndexMaintainer
updateUniquenessViolations
in class IndexMaintainer
valueKey
- the indexed key that is (apparently) not uniqueprimaryKey
- the primary key of one record that is causing a violationexistingKey
- the primary key of another record that is causing a violation (or null
if none specified)remove
- true
if removing the violation and false
if adding it@Nonnull public RecordCursor<IndexEntry> scanUniquenessViolations(@Nonnull TupleRange range, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
IndexMaintainer
IndexEntry
instances where the
getKey()
will return the primary key
of the record causing a problem and getValue()
will return the index value that is being duplicated.scanUniquenessViolations
in class IndexMaintainer
range
- range of tuples to readcontinuation
- any continuation from a previous invocationscanProperties
- row limit and other scan properties@Nonnull public RecordCursor<InvalidIndexEntry> validateEntries(@Nullable byte[] continuation, @Nullable ScanProperties scanProperties)
StandardIndexMaintainer
class is a no-op (performs no validation) and should be overridden by
implementing classes.validateEntries
in class IndexMaintainer
continuation
- any continuation from a previous validation invocationscanProperties
- skip, limit and other properties of the validation (use default values if null
)@Nonnull protected RecordCursor<InvalidIndexEntry> validateOrphanEntries(@Nullable byte[] continuation, @Nullable ScanProperties scanProperties)
continuation
- any continuation from a previous validation invocationscanProperties
- skip, limit and other properties of the validation (use default values if null
)protected <M extends Message> void checkKeyValueSizes(@Nonnull FDBIndexableRecord<M> savedRecord, @Nonnull Tuple valueKey, @Nonnull Tuple value, @Nonnull byte[] keyBytes, @Nonnull byte[] valueBytes)
@Nonnull protected Tuple indexEntryKey(@Nonnull Tuple valueKey, @Nonnull Tuple primaryKey)
valueKey
- the indexed value(s) for the entryprimaryKey
- the primary key for the recordprotected void saveIndexEntryAsKeyValue(IndexEntry keyValue)
keyValue
- the entry to savepublic boolean canEvaluateRecordFunction(@Nonnull IndexRecordFunction<?> function)
IndexMaintainer
true
if this index be used to evaluate the given record function.canEvaluateRecordFunction
in class IndexMaintainer
function
- requested functiontrue
if this index can be used to evaluate the given function@Nonnull public <T,M extends Message> CompletableFuture<T> evaluateRecordFunction(@Nonnull EvaluationContext context, @Nonnull IndexRecordFunction<T> function, @Nonnull FDBRecord<M> record)
IndexMaintainer
evaluateRecordFunction
in class IndexMaintainer
T
- the result type of the functionM
- the message type of the recordcontext
- context for evaluationfunction
- the record function to apply to the given recordrecord
- record against which to evaluatepublic boolean canEvaluateAggregateFunction(@Nonnull IndexAggregateFunction function)
IndexMaintainer
canEvaluateAggregateFunction
in class IndexMaintainer
function
- the requested aggregate functiontrue
if this index be used to evaluate the given aggregate function@Nonnull public CompletableFuture<Tuple> evaluateAggregateFunction(@Nonnull IndexAggregateFunction function, @Nonnull TupleRange range, @Nonnull IsolationLevel isolationLevel)
IndexMaintainer
evaluateAggregateFunction
in class IndexMaintainer
function
- the aggregate function to evaluaterange
- the range over which to accumulate the aggregateisolationLevel
- the isolation level at which to perform the scanprotected int getGroupingCount()
protected int getGroupedCount()
public boolean isIdempotent()
IndexMaintainer
isIdempotent
in class IndexMaintainer
@Nonnull public CompletableFuture<Boolean> addedRangeWithKey(@Nonnull Tuple primaryKey)
IndexMaintainer
RangeSet
associated with this index. This is used within the context of seeing if one should update a non-idempotent
write-only index with a new key. If the key is in some range, then it means that one should update the index
as it is based off of stale data. If the key is not in some range, then it means that one should not update
the index, as the rebuild job will handle it later.addedRangeWithKey
in class IndexMaintainer
primaryKey
- the record key of the record to checktrue
if some range contains the record and false
otherwiseprotected static boolean canDeleteWhere(@Nonnull IndexMaintainerState state, @Nonnull QueryToKeyMatcher.Match match, @Nonnull Key.Evaluated evaluated)
public boolean canDeleteWhere(@Nonnull QueryToKeyMatcher matcher, @Nonnull Key.Evaluated evaluated)
IndexMaintainer
canDeleteWhere
in class IndexMaintainer
matcher
- the key queryevaluated
- parameters to the key querytrue
if this index accommodate a whereRecordsWhere
public CompletableFuture<Void> deleteWhere(Transaction tr, @Nonnull Tuple prefix)
IndexMaintainer
deleteWhere
in class IndexMaintainer
tr
- transaction in which to access the databaseprefix
- prefix of primary key to clearpublic CompletableFuture<IndexOperationResult> performOperation(@Nonnull IndexOperation operation)
IndexMaintainer
performOperation
in class IndexMaintainer
operation
- the requested operation@Nonnull protected <M extends Message> List<IndexEntry> evaluateIndex(@Nonnull FDBRecord<M> record)
record
.M
- the message type of the recordrecord
- the record from which the index will extract its key and value