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

KAFKA-14946: fix NPE when merging the deltatable #13653

Merged
merged 2 commits into from May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -122,6 +122,9 @@ public void mergeFrom(long epoch, Delta source) {
// When merging in a later hash tier, we want to keep only the elements
// that were present at our epoch.
if (element.startEpoch() <= epoch) {
if (deltaTable == null) {
deltaTable = new BaseHashTable<>(1);
}
deltaTable.baseAddOrReplace(element);
}
}
Expand Down
Expand Up @@ -110,11 +110,37 @@ public void testDeleteOnEmptyDeltaTable() {
set.add("bar");
registry.getOrCreateSnapshot(200);
set.add("baz");

// The deltatable of epoch 200 is null, it should not throw exception while reverting (deltatable merge)
registry.revertToSnapshot(100);
assertTrue(set.isEmpty());
set.add("foo");
registry.getOrCreateSnapshot(300);
// After reverting to epoch 100, "bar" is not existed anymore
set.remove("bar");
// No deltatable merging is needed because nothing change in snapshot epoch 300
registry.revertToSnapshot(100);
assertTrue(set.isEmpty());

set.add("qux");
registry.getOrCreateSnapshot(400);
assertEquals(1, set.size());
set.add("fred");
set.add("thud");
registry.getOrCreateSnapshot(500);
assertEquals(3, set.size());

// remove the value in epoch 101(after epoch 100), it'll create an entry in deltatable in the snapshot of epoch 500 for the deleted value in epoch 101
set.remove("qux");
assertEquals(2, set.size());
// When reverting to snapshot of epoch 400, we'll merge the deltatable in epoch 500 with the one in epoch 400.
// The deltatable in epoch 500 has an entry created above, but the deltatable in epoch 400 is null.
// It should not throw exception while reverting (deltatable merge)
registry.revertToSnapshot(400);
// After reverting, the deltatable in epoch 500 should merge to the current epoch
assertEquals(1, set.size());

// When reverting to epoch 100, the deltatable in epoch 400 won't be merged because the entry change is epoch 101(after epoch 100)
registry.revertToSnapshot(100);
assertTrue(set.isEmpty());
}
Expand Down