dajac commented on code in PR #24146:
URL: https://github.com/apache/kafka/pull/24146#discussion_r4522823275
##########
server-common/src/main/java/org/apache/kafka/timeline/SnapshottableHashTable.java:
##########
@@ -429,6 +430,9 @@ public void executeRevert(long targetEpoch, Delta delta) {
}
out.clear();
}
+ // The elements of the tier are back in the current state. Drop
them from the tier
+ // so that iterating over the snapshot does not return them twice.
+ tier.deltaTable = null;
Review Comment:
Agreed, that's the better place for it. After `revertToSnapshot(E)` nothing
has changed since E, so `Snapshot.handleRevert` now clears the deltas once it
has applied them, and the next change records a fresh delta, as after a new
snapshot. This replaces the `tier.deltaTable = null` in `executeRevert`.
`TimelineObject`, `TimelineInteger` and `TimelineLong` behave as before, since
their deltas already held the current value.
##########
server-common/src/main/java/org/apache/kafka/timeline/SnapshottableHashTable.java:
##########
@@ -128,6 +128,7 @@ public void mergeFrom(long epoch, Delta source) {
deltaTable.baseAddOrReplace(element);
}
}
+ list.clear();
Review Comment:
Yes. `revertToSnapshot` deletes the later snapshots one by one, and each
deletion merges the deleted tier into the previous one through the same
`mergeFrom`. On trunk, the merged tier then stays in the snapshot we reverted
to, so iterating at it can skip elements. With your suggestion below, the
revert drops the tier once it has applied it, so the merge can no longer
produce wrong results there. Without the `list.clear()`, it would still re-add
the elements of the earlier slots, which makes the merge quadratic. I updated
the description to cover this, and to explain that `baseAddOrReplace` checks
the load factor before it looks for the element, so replacing an element can
double the table.
It is tested: `testIterateOverSnapshotAfterDeletingNextSnapshot` and
`testIterateOverSnapshotsAfterRandomOperations` fail without the
`list.clear()`. Both go through `deleteSnapshot(long)`, since after a revert
the merge bug no longer changes what the iteration returns.
Agreed on the invariant. Instead of capping the delta table, I'd rather make
`HistoricalIterator` handle a tier larger than the current table, so the
iteration no longer relies on it. I'll do it in a separate PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]