Class IndexMaintainer
- java.lang.Object
-
- com.apple.foundationdb.record.provider.foundationdb.IndexMaintainer
-
- Direct Known Subclasses:
NoOpIndexMaintainer
,StandardIndexMaintainer
@API(MAINTAINED) public abstract class IndexMaintainer extends Object
Object responsible for translating record saves and deletes into updates to a secondary index. This class is essentially an interface, implementing only the storage of anIndexMaintainerState
. A functional base class is provided byStandardIndexMaintainer
. AnIndexMaintainer
instance is associated with a particular record store and index meta-data. Implementers should assume that the same maintainer might be used to perform multiple record updates, even though this never happens today.- See Also:
IndexMaintainerFactory
-
-
Field Summary
Fields Modifier and Type Field Description protected IndexMaintainerState
state
-
Constructor Summary
Constructors Modifier Constructor Description protected
IndexMaintainer(IndexMaintainerState state)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract CompletableFuture<Boolean>
addedRangeWithKey(Tuple primaryKey)
Whether this key has been added to some range within theRangeSet
associated with this index.abstract boolean
canDeleteWhere(QueryToKeyMatcher matcher, Key.Evaluated evaluated)
Get whether this index scan delete records matching a particular key query.abstract boolean
canEvaluateAggregateFunction(IndexAggregateFunction function)
Get whether this index can be used to evaluate the given aggregate function.abstract boolean
canEvaluateRecordFunction(IndexRecordFunction<?> function)
Returntrue
if this index be used to evaluate the given record function.abstract CompletableFuture<Void>
deleteWhere(Transaction tr, Tuple prefix)
Clear index storage associated with the given key prefix.abstract CompletableFuture<Tuple>
evaluateAggregateFunction(IndexAggregateFunction function, TupleRange range, IsolationLevel isolationLevel)
Evaluate an aggregate function over the given range using this index.abstract <T,M extends Message>
CompletableFuture<T>evaluateRecordFunction(EvaluationContext context, IndexRecordFunction<T> function, FDBRecord<M> record)
Evaluate a record function on the given record.Subspace
getIndexSubspace()
Returns the subspace in which the index data is stored.Subspace
getSecondarySubspace()
Returns the secondary subspace in which the index data is stored.abstract boolean
isIdempotent()
Whether updating or removing a record on this index is idempotent.abstract CompletableFuture<IndexOperationResult>
performOperation(IndexOperation operation)
Perform a type-specific operation on index.abstract RecordCursor<IndexEntry>
scan(IndexScanType scanType, TupleRange range, byte[] continuation, ScanProperties scanProperties)
Scan entries in the index.abstract RecordCursor<IndexEntry>
scanUniquenessViolations(TupleRange range, byte[] continuation, ScanProperties scanProperties)
Scans through the list of uniqueness violations within the database.protected CompletableFuture<Tuple>
unsupportedAggregateFunction(IndexAggregateFunction function)
protected <T> CompletableFuture<T>
unsupportedRecordFunction(IndexRecordFunction<T> function)
abstract <M extends Message>
CompletableFuture<Void>update(FDBIndexableRecord<M> oldRecord, FDBIndexableRecord<M> newRecord)
Update associated index for a changed record.abstract RecordCursor<InvalidIndexEntry>
validateEntries(byte[] continuation, ScanProperties scanProperties)
Validates the integrity of the index entries.
-
-
-
Field Detail
-
state
protected final IndexMaintainerState state
-
-
Constructor Detail
-
IndexMaintainer
protected IndexMaintainer(IndexMaintainerState state)
-
-
Method Detail
-
getIndexSubspace
@Nonnull public Subspace getIndexSubspace()
Returns the subspace in which the index data is stored.- Returns:
- subspace for index data
-
getSecondarySubspace
@Nonnull public Subspace getSecondarySubspace()
Returns the secondary subspace in which the index data is stored.- Returns:
- secondary subspace for index data
-
scan
@Nonnull public abstract RecordCursor<IndexEntry> scan(@Nonnull IndexScanType scanType, @Nonnull TupleRange range, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
Scan entries in the index.- Parameters:
scanType
- thetype
of scan to performrange
- the range to scancontinuation
- any continuation from a previous scan invocationscanProperties
- skip, limit and other properties of the scan- Returns:
- a cursor over index entries in the given range
-
update
@Nonnull public abstract <M extends Message> CompletableFuture<Void> update(@Nullable FDBIndexableRecord<M> oldRecord, @Nullable FDBIndexableRecord<M> newRecord)
Update associated index for a changed record.- Type Parameters:
M
- type of message- Parameters:
oldRecord
- the previous stored record ornull
if a new record is being creatednewRecord
- the new record ornull
if an old record is being deleted- Returns:
- a future that is complete when the record update is done
-
scanUniquenessViolations
@Nonnull public abstract RecordCursor<IndexEntry> scanUniquenessViolations(@Nonnull TupleRange range, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
Scans through the list of uniqueness violations within the database. It will return a cursor ofIndexEntry
instances where thegetKey()
will return the primary key of the record causing a problem andgetValue()
will return the index value that is being duplicated.- Parameters:
range
- range of tuples to readcontinuation
- any continuation from a previous invocationscanProperties
- row limit and other scan properties- Returns:
- a cursor that will return primary key-index key pairs indicating uniqueness violations
-
validateEntries
@API(EXPERIMENTAL) @Nonnull public abstract RecordCursor<InvalidIndexEntry> validateEntries(@Nullable byte[] continuation, @Nullable ScanProperties scanProperties)
Validates the integrity of the index entries. The definition of exactly what validations are performed is up to the implementation of the index. It is not responsible for metadata validation, which is defined inIndexValidator
.- Parameters:
continuation
- any continuation from a previous validation invocationscanProperties
- skip, limit and other properties of the validation (use default values ifnull
)- Returns:
- a cursor over invalid index entries including reasons
-
canEvaluateRecordFunction
public abstract boolean canEvaluateRecordFunction(@Nonnull IndexRecordFunction<?> function)
Returntrue
if this index be used to evaluate the given record function.- Parameters:
function
- requested function- Returns:
true
if this index can be used to evaluate the given function
-
evaluateRecordFunction
@Nonnull public abstract <T,M extends Message> CompletableFuture<T> evaluateRecordFunction(@Nonnull EvaluationContext context, @Nonnull IndexRecordFunction<T> function, @Nonnull FDBRecord<M> record)
Evaluate a record function on the given record.- Type Parameters:
T
- the result type of the functionM
- the message type of the record- Parameters:
context
- context for evaluationfunction
- the record function to apply to the given recordrecord
- record against which to evaluate- Returns:
- a future that completes with the result of evaluation
-
unsupportedRecordFunction
@Nonnull protected <T> CompletableFuture<T> unsupportedRecordFunction(@Nonnull IndexRecordFunction<T> function)
-
canEvaluateAggregateFunction
public abstract boolean canEvaluateAggregateFunction(@Nonnull IndexAggregateFunction function)
Get whether this index can be used to evaluate the given aggregate function.- Parameters:
function
- the requested aggregate function- Returns:
true
if this index be used to evaluate the given aggregate function
-
evaluateAggregateFunction
@Nonnull public abstract CompletableFuture<Tuple> evaluateAggregateFunction(@Nonnull IndexAggregateFunction function, @Nonnull TupleRange range, @Nonnull IsolationLevel isolationLevel)
Evaluate an aggregate function over the given range using this index.- Parameters:
function
- the aggregate function to evaluaterange
- the range over which to accumulate the aggregateisolationLevel
- the isolation level at which to perform the scan- Returns:
- a future that completes with the aggregate result
-
unsupportedAggregateFunction
@Nonnull protected CompletableFuture<Tuple> unsupportedAggregateFunction(@Nonnull IndexAggregateFunction function)
-
isIdempotent
public abstract boolean isIdempotent()
Whether updating or removing a record on this index is idempotent. In principle, all index updates in the normal case are idempotent as long as the index update and the record insertion or deletion is atomic. However, certain indexes (mostly aggregate indexes) have the property that the index update on its own are not idempotent.- Returns:
- whether updating this index is idempotent
-
addedRangeWithKey
@Nonnull public abstract CompletableFuture<Boolean> addedRangeWithKey(@Nonnull Tuple primaryKey)
Whether this key has been added to some range within theRangeSet
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.- Parameters:
primaryKey
- the record key of the record to check- Returns:
- a future that will be
true
if some range contains the record andfalse
otherwise
-
canDeleteWhere
public abstract boolean canDeleteWhere(@Nonnull QueryToKeyMatcher matcher, @Nonnull Key.Evaluated evaluated)
Get whether this index scan delete records matching a particular key query.- Parameters:
matcher
- the key queryevaluated
- parameters to the key query- Returns:
true
if this index accommodate awhereRecordsWhere
-
deleteWhere
public abstract CompletableFuture<Void> deleteWhere(@Nonnull Transaction tr, @Nonnull Tuple prefix)
Clear index storage associated with the given key prefix.- Parameters:
tr
- transaction in which to access the databaseprefix
- prefix of primary key to clear- Returns:
- a future that is complete when the given prefix has been cleared from this index
-
performOperation
public abstract CompletableFuture<IndexOperationResult> performOperation(@Nonnull IndexOperation operation)
Perform a type-specific operation on index. Allowed operations will vary by index type.- Parameters:
operation
- the requested operation- Returns:
- a future that completes with the result of the operation
-
-