Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test of range clear vs set #3237

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4706,6 +4706,7 @@ private void maybeLogIndexesNeedingRebuilding(@Nonnull Map<Index, CompletableFut
@SuppressWarnings("PMD.CloseResource")
void clearIndexData(@Nonnull Index index) {
context.clear(Range.startsWith(indexSubspace(index).pack())); // startsWith to handle ungrouped aggregate indexes
// clearIndexData clears the secondary index with:
context.clear(indexSecondarySubspace(index).range());
IndexingRangeSet.forIndexBuild(this, index).clear();
// clear even if non-unique in case the index was previously unique
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ protected CompletableFuture<TimeWindowLeaderboard> oldestLeaderboardMatching(int
@Nonnull
protected CompletableFuture<TimeWindowLeaderboardDirectory> loadDirectory() {
final Subspace extraSubspace = getSecondarySubspace();
// TimeWindow Leaderboard sets secondary subspace directly via `subspace.pack()`
return state.transaction.get(extraSubspace.pack()).thenApply(bytes -> {
if (bytes == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand Down Expand Up @@ -676,6 +677,33 @@ public void contextExecutor() {
}
}

@Test
void clearAndRead() {
final FDBDatabase database = dbExtension.getDatabase();

final Subspace subspace = new Subspace(Tuple.from("A", 1, "boo"));
final byte[] value = Tuple.from("here").pack();
try (FDBRecordContext context = database.openContext()) {
context.ensureActive().set(subspace.pack(), value);
context.commit();
}


try (FDBRecordContext context = database.openContext()) {
assertArrayEquals(value, context.ensureActive().get(subspace.pack()).join());

assertArrayEquals(new byte[] { 0x02, 'A', 0x0, 21, 0x01, 0x02, 'b', 'o', 'o', 0x0}, subspace.pack());
assertArrayEquals(new byte[] { 0x02, 'A', 0x0, 21, 0x01, 0x02, 'b', 'o', 'o', 0x0, 0x0}, subspace.range().begin);
assertArrayEquals(new byte[] { 0x02, 'A', 0x0, 21, 0x01, 0x02, 'b', 'o', 'o', 0x0, -1}, subspace.range().end);

context.clear(subspace.range());

assertNotNull(context.ensureActive().get(subspace.pack()).join()); // <== should this fail
context.commit();
}

}

static class ThreadIdRestoringExecutor extends TaskNotifyingExecutor {
private int threadId;

Expand Down
Loading