Class 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 an IndexMaintainerState. A functional base class is provided by StandardIndexMaintainer. An IndexMaintainer 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
    • 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
      • update

        @Nonnull
        public abstract <M extends MessageCompletableFuture<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 or null if a new record is being created
        newRecord - the new record or null 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 of 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.
        Parameters:
        range - range of tuples to read
        continuation - any continuation from a previous invocation
        scanProperties - 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 in IndexValidator.
        Parameters:
        continuation - any continuation from a previous validation invocation
        scanProperties - skip, limit and other properties of the validation (use default values if null)
        Returns:
        a cursor over invalid index entries including reasons
      • canEvaluateRecordFunction

        public abstract boolean canEvaluateRecordFunction​(@Nonnull
                                                          IndexRecordFunction<?> function)
        Return true 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 MessageCompletableFuture<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 function
        M - the message type of the record
        Parameters:
        context - context for evaluation
        function - the record function to apply to the given record
        record - record against which to evaluate
        Returns:
        a future that completes with the result of evaluation
      • 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 evaluate
        range - the range over which to accumulate the aggregate
        isolationLevel - the isolation level at which to perform the scan
        Returns:
        a future that completes with the aggregate result
      • 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 the 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.
        Parameters:
        primaryKey - the record key of the record to check
        Returns:
        a future that will be true if some range contains the record and false 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 query
        evaluated - parameters to the key query
        Returns:
        true if this index accommodate a whereRecordsWhere
      • 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 database
        prefix - 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