Skip to content
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.
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 @@ -111,15 +111,19 @@ static class HashTier<T extends SnapshottableHashTable.ElementWithStartEpoch> im
@Override
public void mergeFrom(long epoch, Delta source) {
HashTier<T> other = (HashTier<T>) source;
List<T> list = new ArrayList<>();
Object[] otherElements = other.deltaTable.baseElements();
for (int slot = 0; slot < otherElements.length; slot++) {
BaseHashTable.unpackSlot(list, otherElements, slot);
for (T element : list) {
// When merging in a later hash tier, we want to keep only the elements
// that were present at our epoch.
if (element.startEpoch() <= epoch) {
deltaTable.baseAddOrReplace(element);
// As an optimization, the deltaTable might not exist for a new key
// as there is no previous value
if (other.deltaTable != null) {
List<T> list = new ArrayList<>();
Object[] otherElements = other.deltaTable.baseElements();
for (int slot = 0; slot < otherElements.length; slot++) {
BaseHashTable.unpackSlot(list, otherElements, slot);
for (T element : list) {
// When merging in a later hash tier, we want to keep only the elements
// that were present at our epoch.
if (element.startEpoch() <= epoch) {
deltaTable.baseAddOrReplace(element);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ public void testEmptyTable() {
new SnapshottableHashTable<>(registry, 1);
assertEquals(0, table.snapshottableSize(Long.MAX_VALUE));
}
@Test
public void testDeleteOnEmptyDeltaTable() {
// A simple test case to validate the behavior of the TimelineHashSet
// when the deltaTable for a snapshot is null
SnapshotRegistry registry = new SnapshotRegistry(new LogContext());
TimelineHashSet<String> set = new TimelineHashSet<>(registry, 5);

registry.getOrCreateSnapshot(100);
set.add("bar");
registry.getOrCreateSnapshot(200);
set.add("baz");
registry.revertToSnapshot(100);
assertTrue(set.isEmpty());
set.add("foo");
registry.getOrCreateSnapshot(300);
set.remove("bar");
registry.revertToSnapshot(100);
assertTrue(set.isEmpty());
}

@Test
public void testAddAndRemove() {
Expand Down