@API(value=EXPERIMENTAL) public class TimeWindowLeaderboardIndexMaintainer extends StandardIndexMaintainer
TIME_WINDOW_LEADERBOARD
index type.for details of how this works.
Modifier and Type | Class and Description |
---|---|
protected class |
TimeWindowLeaderboardIndexMaintainer.UpdateState |
TOO_LARGE_VALUE_MESSAGE_LIMIT
state
Constructor and Description |
---|
TimeWindowLeaderboardIndexMaintainer(IndexMaintainerState state) |
Modifier and Type | Method and Description |
---|---|
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 List<IndexEntry> |
commonKeys(List<IndexEntry> oldIndexKeys,
List<IndexEntry> newIndexKeys) |
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.
|
<T,M extends Message> |
evaluateRecordFunction(EvaluationContext context,
IndexRecordFunction<T> function,
FDBRecord<M> record)
Evaluate a record function on the given record.
|
protected CompletableFuture<IndexEntry> |
getIndexEntry(IndexEntry rawEntry,
int groupPrefixSize,
TimeWindowLeaderboardDirectory directory) |
protected CompletableFuture<Map<Tuple,Collection<com.apple.foundationdb.record.provider.foundationdb.leaderboard.TimeWindowLeaderboardIndexMaintainer.OrderedScoreIndexKey>>> |
groupOrderedScoreIndexKeys(Iterable<IndexEntry> indexEntries,
TimeWindowLeaderboardDirectory directory,
boolean includesGroup)
Group the given
indexKeys by group of size groupPrefixSize , ordering within each
group by score, taking highScoreFirst into account from the directory
or any sub-directory (if includesGroup is true ). |
protected CompletableFuture<Boolean> |
isHighScoreFirst(TimeWindowLeaderboardDirectory directory,
Tuple group) |
protected CompletableFuture<TimeWindowLeaderboardDirectory> |
loadDirectory() |
protected CompletableFuture<TimeWindowLeaderboardSubDirectory> |
loadSubDirectory(TimeWindowLeaderboardDirectory directory,
Tuple group) |
protected static Tuple |
negateScoreForHighScoreFirst(Tuple entry,
int position)
Negate the score element so that it sorts in reverse order to support high score first.
|
protected TupleRange |
negateScoreRange(TupleRange range)
Negate the score part of the given range, which is after the group prefix and before the timestamp and any
other tiebreakers.
|
protected CompletableFuture<TimeWindowLeaderboard> |
oldestLeaderboardMatching(int type,
long timestamp) |
CompletableFuture<IndexOperationResult> |
performOperation(IndexOperation operation)
Perform a type-specific operation on index.
|
protected void |
saveDirectory(TimeWindowLeaderboardDirectory directory) |
protected void |
saveSubDirectory(TimeWindowLeaderboardSubDirectory subdirectory) |
RecordCursor<IndexEntry> |
scan(IndexScanType scanType,
TupleRange rankRange,
byte[] continuation,
ScanProperties scanProperties)
Scan entries in the index.
|
protected RecordCursor<IndexEntry> |
scanLeaderboard(TimeWindowLeaderboard leaderboard,
boolean highScoreFirst,
TupleRange scoreRange,
byte[] continuation,
ScanProperties scanProperties) |
protected RecordCursor<IndexEntry> |
scanLeaderboard(TimeWindowLeaderboard leaderboard,
TupleRange range,
byte[] continuation,
ScanProperties scanProperties) |
<M extends Message> |
timeWindowRankAndEntry(EvaluationContext context,
TimeWindowForFunction timeWindow,
FDBRecord<M> record) |
<M extends Message> |
timeWindowRankAndEntry(FDBRecord<M> record,
int type,
long timestamp) |
protected CompletableFuture<Collection<Tuple>> |
trimScores(TimeWindowLeaderboardDirectory directory,
Collection<Tuple> scores,
boolean includesGroup) |
protected <M extends Message> |
updateIndexKeys(FDBIndexableRecord<M> savedRecord,
boolean remove,
List<IndexEntry> indexEntries)
Update index according to record keys.
|
addedRangeWithKey, canDeleteWhere, canDeleteWhere, checkKeyValueSizes, decodeValue, evaluateIndex, filteredIndexEntries, getExecutor, getGroupedCount, getGroupingCount, getTimer, indexEntryKey, isIdempotent, makeMutable, saveIndexEntryAsKeyValue, scan, scanUniquenessViolations, skipUpdateForUnchangedKeys, trimTooLargeTuple, unpackKeyValue, unpackKeyValue, update, updateIndexKeysFunction, updateOneKey, updateUniquenessViolations, validateEntries, validateMissingEntries, validateOrphanEntries
getIndexSubspace, getSecondarySubspace, unsupportedAggregateFunction, unsupportedRecordFunction
public TimeWindowLeaderboardIndexMaintainer(IndexMaintainerState state)
@Nonnull protected CompletableFuture<TimeWindowLeaderboard> oldestLeaderboardMatching(int type, long timestamp)
@Nonnull protected CompletableFuture<TimeWindowLeaderboardDirectory> loadDirectory()
protected void saveDirectory(TimeWindowLeaderboardDirectory directory)
@Nonnull protected CompletableFuture<TimeWindowLeaderboardSubDirectory> loadSubDirectory(@Nonnull TimeWindowLeaderboardDirectory directory, @Nonnull Tuple group)
protected void saveSubDirectory(@Nonnull TimeWindowLeaderboardSubDirectory subdirectory)
@Nonnull public RecordCursor<IndexEntry> scan(@Nonnull IndexScanType scanType, @Nonnull TupleRange rankRange, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
IndexMaintainer
scan
in class IndexMaintainer
scanType
- the type
of scan to performrankRange
- the range to scancontinuation
- any continuation from a previous scan invocationscanProperties
- skip, limit and other properties of the scanprotected RecordCursor<IndexEntry> scanLeaderboard(@Nonnull TimeWindowLeaderboard leaderboard, boolean highScoreFirst, @Nonnull TupleRange scoreRange, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
protected RecordCursor<IndexEntry> scanLeaderboard(@Nonnull TimeWindowLeaderboard leaderboard, @Nonnull TupleRange range, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
protected TupleRange negateScoreRange(@Nonnull TupleRange range)
range
- the range of scores in normal orderprotected CompletableFuture<IndexEntry> getIndexEntry(@Nonnull IndexEntry rawEntry, int groupPrefixSize, @Nonnull TimeWindowLeaderboardDirectory directory)
protected CompletableFuture<Boolean> isHighScoreFirst(@Nonnull TimeWindowLeaderboardDirectory directory, @Nonnull Tuple group)
protected static Tuple negateScoreForHighScoreFirst(@Nonnull Tuple entry, int position)
entry
- original entryposition
- position in Tuple
of the score value@Nonnull protected List<IndexEntry> commonKeys(@Nonnull List<IndexEntry> oldIndexKeys, @Nonnull List<IndexEntry> newIndexKeys)
commonKeys
in class StandardIndexMaintainer
protected <M extends Message> CompletableFuture<Void> updateIndexKeys(@Nonnull FDBIndexableRecord<M> savedRecord, boolean remove, @Nonnull List<IndexEntry> indexEntries)
StandardIndexMaintainer
updateIndexKeys
in class StandardIndexMaintainer
M
- the message type of the recordsavedRecord
- the record being indexedremove
- true
if removing from indexindexEntries
- the result of StandardIndexMaintainer.evaluateIndex(FDBRecord)
public boolean canEvaluateRecordFunction(@Nonnull IndexRecordFunction<?> function)
IndexMaintainer
true
if this index be used to evaluate the given record function.canEvaluateRecordFunction
in class StandardIndexMaintainer
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 StandardIndexMaintainer
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 StandardIndexMaintainer
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 StandardIndexMaintainer
function
- the aggregate function to evaluaterange
- the range over which to accumulate the aggregateisolationLevel
- the isolation level at which to perform the scan@Nonnull public <M extends Message> CompletableFuture<org.apache.commons.lang3.tuple.Pair<Long,Tuple>> timeWindowRankAndEntry(@Nonnull EvaluationContext context, @Nonnull TimeWindowForFunction timeWindow, @Nonnull FDBRecord<M> record)
@Nonnull public <M extends Message> CompletableFuture<org.apache.commons.lang3.tuple.Pair<Long,Tuple>> timeWindowRankAndEntry(@Nonnull FDBRecord<M> record, int type, long timestamp)
public CompletableFuture<Void> deleteWhere(Transaction tr, @Nonnull Tuple prefix)
IndexMaintainer
deleteWhere
in class StandardIndexMaintainer
tr
- transaction in which to access the databaseprefix
- prefix of primary key to clear@Nonnull public CompletableFuture<IndexOperationResult> performOperation(@Nonnull IndexOperation operation)
IndexMaintainer
performOperation
in class StandardIndexMaintainer
operation
- the requested operationprotected CompletableFuture<Collection<Tuple>> trimScores(@Nullable TimeWindowLeaderboardDirectory directory, @Nonnull Collection<Tuple> scores, boolean includesGroup)
protected CompletableFuture<Map<Tuple,Collection<com.apple.foundationdb.record.provider.foundationdb.leaderboard.TimeWindowLeaderboardIndexMaintainer.OrderedScoreIndexKey>>> groupOrderedScoreIndexKeys(@Nonnull Iterable<IndexEntry> indexEntries, @Nonnull TimeWindowLeaderboardDirectory directory, boolean includesGroup)
indexKeys
by group of size groupPrefixSize
, ordering within each
group by score, taking highScoreFirst
into account from the directory
or any sub-directory (if includesGroup
is true
).indexEntries
- index entries to be added to the indexdirectory
- leaderboard directory used to decide whether higher scores are better (earlier in the list)includesGroup
- whether index entries also include the group key(s)