Skip to content

Commit 376d6d8

Browse files
authored
Do not drop AllTime leaderboard if deleteBefore is Long.Max_VALUE (#3241)
Resolves: #3240 I am opting not to add a control to drop the allTime leaderboard at this time, and instead just change the `deleteBefore` behavior.
1 parent 1076496 commit 376d6d8

File tree

4 files changed

+294
-34
lines changed

4 files changed

+294
-34
lines changed

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/leaderboard/TimeWindowLeaderboard.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,15 @@ protected TimeWindowLeaderboardProto.TimeWindowLeaderboard.Builder toProto() {
154154
.setSubspaceKey(ZeroCopyByteString.wrap(subspaceKey.pack()))
155155
.setNlevels(nlevels);
156156
}
157+
158+
@Override
159+
public String toString() {
160+
return "TimeWindowLeaderboard{" +
161+
"type=" + type +
162+
", startTimestamp=" + startTimestamp +
163+
", endTimestamp=" + endTimestamp +
164+
", subspaceKey=" + subspaceKey +
165+
", nlevels=" + nlevels +
166+
'}';
167+
}
157168
}

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/leaderboard/TimeWindowLeaderboardIndexMaintainer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,10 @@ public void update() {
756756
Iterator<TimeWindowLeaderboard> iter = leaderboards.iterator();
757757
while (iter.hasNext()) {
758758
TimeWindowLeaderboard leaderboard = iter.next();
759-
if (update.getDeleteBefore() >= leaderboard.getEndTimestamp()) {
759+
// We don't want to delete the allTime leaderboard, even if the request sets `deleteBefore` to
760+
// Long.MAX_VALUE
761+
if (leaderboard.getType() != TimeWindowLeaderboard.ALL_TIME_LEADERBOARD_TYPE &&
762+
update.getDeleteBefore() >= leaderboard.getEndTimestamp()) {
760763
state.transaction.clear(indexSubspace.pack(leaderboard.getSubspaceKey()));
761764
state.transaction.clear(extraSubspace.pack(leaderboard.getSubspaceKey()));
762765
iter.remove();

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/leaderboard/TimeWindowLeaderboardWindowUpdate.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,32 @@ public class TimeWindowLeaderboardWindowUpdate extends IndexOperation {
3333
* When to completely rebuild an index.
3434
*/
3535
public enum Rebuild {
36-
ALWAYS, NEVER, IF_OVERLAPPING_CHANGED
36+
/**
37+
* Rebuild the index even if nothing has changed.
38+
* <p>
39+
* Note: This rebuild happens in a single transaction, and thus, will fail if the store is sufficiently large.
40+
* </p>
41+
*/
42+
ALWAYS,
43+
/**
44+
* Do not rebuild the index no matter what.
45+
*/
46+
NEVER,
47+
/**
48+
* Rebuild the index if it is necessary to have the leaderboards contain the records they're supposed to.
49+
* <p>
50+
* This can happen in a few situations:
51+
* <ul>
52+
* <li>If {@link #isHighScoreFirst()} is changed</li>
53+
* <li>If {@link #isAllTime()} is changed</li>
54+
* <li>If a record has been saved that has a timestamp greater than the earliest timestamp for one of
55+
* the provided specs</li>
56+
* </ul>
57+
* <p>
58+
* Note: This rebuild happens in a single transaction, and thus, will fail if the store is sufficiently large.
59+
* </p>
60+
*/
61+
IF_OVERLAPPING_CHANGED
3762
}
3863

3964
private final long updateTimestamp;
@@ -73,7 +98,8 @@ public TimeWindowLeaderboardWindowUpdate(long updateTimestamp,
7398
* Create a time window update operation.
7499
* @param updateTimestamp a timestamp to be recorded if any changes are made
75100
* @param highScoreFirst if <code>true</code>, numerically higher scores come first in the index
76-
* @param deleteBefore delete any time windows ending at this time or before
101+
* @param deleteBefore delete any time windows ending at this time or before;
102+
* this will not delete the all-time leaderboard, if there is one
77103
* @param allTime include an all-time leaderboard
78104
* @param specs specifications for time windows to create
79105
* @param rebuild completely rebuild the index using the new time windows by scanning all existing records

0 commit comments

Comments
 (0)