Repository navigation
[Fix][Zeta] Fix IMap file data comparison contract - #11465
Conversation
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks for working on this. I rechecked the latest head ca20619343ba against the actual WAL replay path, and I do see one blocker before merge.
- The new comparator fixes the
compareTocontract, but it also changes same-timestamp replay semantics in a way that can recover the wrong final state for a key.WALReadersorts all records first (WALReader.java:64and:90) and then keeps the first surviving record for each key (WALReader.java:67-79and:94-110).IMapFileStorageonly stamps records withSystem.currentTimeMillis()(IMapFileStorage.java:292and:301), so two updates to the same key in the same millisecond are a real case.- With the new tie-break in
IMapDataComparator.java:40-65, equal-timestamp records are no longer ordered by append order. They are ordered bydeleted, key class / bytes, and value class / bytes instead.
That means a same-millisecond sequence like put(A) -> put(B) or delete -> put for the same key can now replay the wrong winner after sorting, because the winner is whichever record sorts first by the comparator, not whichever record was appended last in the WAL.
So from my side the merge blocker is: please preserve the real append order for equal-timestamp records (for example with an explicit WAL sequence / offset, or another stable last-write tie-break), and then add a regression test for same-key same-millisecond replay. The current tests only prove the comparator contract; they do not cover the restore semantics above.
Current gate facts on Thursday, July 16, 2026:
- the branch is behind
dev(ahead_by=1,behind_by=29, compare statusdiverged) Buildis still in progress
But the replay-semantics issue above is the source-level blocker from my side.
|
Thanks @DanielLeens, you're right — the content-based tie-break broke same-millisecond replay semantics. Fixed in What changed
Tests
All 11 tests in the module pass; spotless is clean. |
dybyte
left a comment
There was a problem hiding this comment.
Thanks for the update. I think the new sequence ID fixes ordering within a single WALWriter, but I am not sure it is comparable across regions.
Each WALWriter owns an independent counter starting from zero, while WALReader collects records recursively from multiple region directories. Therefore, two records for the same key may have the same timestamp but sequence IDs produced by different writers. In that case, a larger sequence ID does not necessarily represent a later write.
The assumption that equal-timestamp records must come from the same writer appears to cover file rotation and restart, but not concurrently active storage instances or ownership migration between regions.
Also, since replay only needs to select the latest record for each key, would it be clearer to order records by key identity first, and then by timestamp within the same key?
For example:
keyClassName -> key bytes -> timestamp descending -> cross-writer comparable version descending
The version could be something such as an ownership epoch combined with a writer-local sequence. This would avoid comparing timestamps and local sequence IDs across unrelated keys, while still ensuring that the newest record appears first within each key.
valueClassName and value bytes do not appear to represent replay order. They seem useful only as deterministic total-order fallbacks, if such fallbacks are required.
|
@dybyte you're right, and I traced it through the code to confirm the reachability. Sharing what I found. The cross-region path is real. Why it corrupts the winner, concretely. In the comparator the equal-timestamp chain is Scope note (being honest about likelihood). Triggering an actual wrong state still needs the narrow window of a same-key write in the same millisecond across two regions. The correctness gap is real; the trigger is a low-probability boundary (restart/migration timing), not a common path. On the fix. Your key-identity-first ordering with a cross-writer-comparable version (ownership epoch + writer-local sequence) is the correct general solution, but it's a larger change (persisting an epoch, touching |
SEZ9
left a comment
There was a problem hiding this comment.
Thanks for working on this. I re-reviewed the latest head 6811bc3d828c from scratch.
Findings
Issue 1: Config/option changes without doc updates
- Why it matters: Consider updating docs/example configs for the new/changed options.
- Severity: Low
Review conclusion
Conclusion: can merge; the notes below are non-blocking
2. Suggested (non-blocking) follow-ups
- Issue 1: Config/option changes without doc updates
Nice work — thanks again for the contribution. Happy to discuss any of the above.
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks for the update. I re-reviewed the complete current diff and the IMap WAL write/recovery path. One persisted-ordering issue still blocks merge.
Blocking finding
Issue 1: WAL sequence numbers are not globally ordered across storage regions
- Location:
IMapFileStorage.java:147-166,235-238,WALWriter.java:46,59-61,WALReader.java:84-105, andIMapDataComparator.java:42-60 - Each
WALWriterstarts its sequence at zero, while each storage initialization can write a new region and recovery merges records from all regions. For equal timestamps, independent regions can therefore contain equal sequence values; the comparator then falls through to content/delete ordering, while the reader globally sorts and keeps the first record per key. - Risk: restart or ownership migration can replay an older value, or the wrong side of a value/delete pair. This confirms @dybyte's existing cross-region finding, which remains unresolved.
- Suggested fix: persist an ordering key that is monotonic across regions, or make region generation part of the ordering and prove last-write-wins recovery with equal-timestamp value/update/delete tests across multiple regions.
Severity: High. Merge gate: blocking. The current Build failure is a separate gate and cannot clear the recovery problem. Happy to re-review an updated head.
@nielifeng I think either approach is reasonable. |
|
@dybyte @DanielLeens The cross-region WAL ordering blocker is addressed in the latest head What changed:
Regression coverage now includes:
Verification:
Could you please re-review the latest head? |
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks for working on this! I re-reviewed the complete current-head diff and the relevant runtime path. The direction makes sense, but I found the following blocker that needs to be resolved before merge:
- Blocker 1 — +1 to dybyte's ordering concern for the supported object-store path. Epoch reservation relies on temp-file creation plus rename, but S3/OSS rename is copy/delete rather than portable CAS. Concurrent writers can reserve the same epoch, and writer-id ordering is not write ordering. Please use an atomic conditional-create/CAS mechanism or a durable globally comparable mutation token.
The current Build is failing; CI remains a separate gate and does not change the source verdict above. The current failed lanes include Run / unit-test (11, ubuntu-latest), Run / engine-v2-it (11, ubuntu-latest), Run / kafka-connector-it (11, ubuntu-latest). Please retrigger or inspect those exact job logs after the source update.
Please address these together on the next head; I’ll re-review the full updated diff once it is ready.
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks for working on this! I re-reviewed the complete current-head diff and the relevant runtime path. The direction makes sense, but I found the following blocker that needs to be resolved before merge:
- Blocker 1 — +1 to dybyte's ordering concern for the supported object-store path. Epoch reservation relies on temp-file creation plus rename, but S3/OSS rename is copy/delete rather than portable CAS. Concurrent writers can reserve the same epoch, and writer-id ordering is not write ordering. Please use an atomic conditional-create/CAS mechanism or a durable globally comparable mutation token.
The current Build is failing; CI remains a separate gate and does not change the source verdict above. The current failed lanes include Run / unit-test (11, ubuntu-latest), Run / engine-v2-it (11, ubuntu-latest), Run / kafka-connector-it (11, ubuntu-latest). Please retrigger or inspect those exact job logs after the source update.
Please address these together on the next head; I’ll re-review the full updated diff once it is ready.
04a142f to
07496ae
Compare
|
Updated head This PR is now scoped to the minimal fix discussed in review: key identity first, timestamp descending within a key, then deterministic tombstone/value fallbacks to satisfy the Verification on current |
SEZ9
left a comment
There was a problem hiding this comment.
Thanks for working on this. I re-reviewed the latest head 07496ae8a186 from scratch.
What this PR fixes
- User pain:
IMapFileData.compareTo(andIMapData.compareTo) never returned0and wasn't antisymmetric (o.timestamp - this.timestamp > 0 ? 1 : -1), so TimSort inCollections.sortcould throwIllegalArgumentException: Comparison method violates its general contract!during WAL recovery, failing IMap restore on Zeta restart. - Fix approach: Introduce a shared
IMapDataComparatorthat produces a deterministic total order (keyClassName → key bytes → timestamp desc → deleted flag → valueClassName → value bytes) and wire it into bothIMapData.compareToandIMapFileData.compareTo, with new unit tests for antisymmetry, zero-on-equal, and mass-collision sorting. - One-line summary: The comparator fix itself is sound and well-tested, but the PR is internally inconsistent — the description says the writer-epoch/sequence design was removed, yet
WALWriterstill stampswriterEpoch/writerId/sequenceIdonto records (calling setters not shown as added toIMapFileDatain this diff), and the newtestReplayKeepsLastWriteForSameKeySameTimestampasserts last-append-wins semantics (e.g. put-after-delete resurrectsrecreated-key) that the comparator alone cannot deliver, since it deterministically orders tombstones before puts at equal timestamps; this needs to be reconciled before merge, plus the existing doc-gap finding stands.
Runtime chain I rechecked
WAL recovery path (where the broken comparator was hit):
FileStorage.loadAll()
-> WALReader.loadAllData(parentPath, searchKeys) WALReader.java
-> readAllData(parentPath) collects List<IMapFileData> across WAL region files
-> Collections.sort(fileDataList) / list.sort(...) (previously threw TimSort contract violation)
-> IMapFileData.compareTo(o) IMapFileData.java:49
-> IMapDataComparator.compare(...) IMapDataComparator.java:27
-> compareNullableString(keyClassName) IMapDataComparator.java:39
-> compareBytes(key) IMapDataComparator.java:44
-> Long.compare(rightTimestamp, leftTimestamp) IMapDataComparator.java:49 (descending, newest first)
-> Boolean.compare(rightDeleted, leftDeleted) IMapDataComparator.java:58 (tombstone before put)
-> compareNullableString(valueClassName) / compareBytes(value) IMapDataComparator.java:63-68
-> per-key, first record after sort wins in loadAllData's dedup, so same-key same-timestamp collisions now resolve to the tombstone — which contradicts testReplayKeepsLastWriteForSameKeySameTimestamp's 'recreated-key' expectation unless sequenceId is consulted somewhere not in this diff
WAL write path (new epoch/sequence stamping):
IMapDataOperation via WALDisruptor consumer (single thread)
-> WALWriter.write(IMapFileData) WALWriter.java:70
-> data.setWriterEpoch(writerEpoch) / data.setWriterId(writerId) / data.setSequenceId(sequenceGenerator.incrementAndGet()) WALWriter.java:71-73 (setters/fields not added to IMapFileData in this diff — likely compile break or dead design the description claims was removed)
-> IFileWriter.write(data) (OrcWriter/ProtobufWALWriter via DiscoveryWalFileFactory)
Findings
Issue 1: Config/option changes without doc updates
- Why it matters: Consider updating docs/example configs for the new/changed options.
- Severity: Low
Review conclusion
Conclusion: can merge; the notes below are non-blocking
2. Suggested (non-blocking) follow-ups
- Issue 1: Config/option changes without doc updates
Nice work — thanks again for the contribution. Happy to discuss any of the above.
dybyte
left a comment
There was a problem hiding this comment.
Could we add a small WALReader regression test confirming that a tombstone wins for the same key and timestamp? The comparator-level test already covers the ordering, but an end-to-end test would document and protect the intended replay behavior.
|
@dybyte Added the requested WALReader regression coverage in The new
The test uses an isolated WAL directory and cleans it up after the suite. Verification:
Could you please re-review the latest head? |
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks for the contribution! I rechecked the complete current-head diff, deletion ledger, existing reviewer findings, and the relevant runtime path. I do not see a source-level blocker in this version.
The previous source concern is resolved on 63500bb037ab: the local writer-epoch approach was removed and the current diff uses a deterministic shared comparator.
The source verdict is clear, but the required Build is still pending. Please let the current checks finish; a write-capable maintainer may still need to complete the approval gate afterward.
|
CI follow-up: the approved source head remains unchanged at 63500bb. The failed Build spans unrelated connector integration lanes plus the Windows unit lane, while the focused WALReader and full imap-storage-file verification already passed locally. I re-ran failed jobs only; workflow 29817282445 is now queued as attempt 2. No business-code change was made. |
|
CI follow-up for head Attempt 2 completed with only two unrelated connector E2E failures:
All source/unit/style jobs and the other connector lanes completed successfully. I re-ran failed jobs only; workflow |
Purpose
Fixes #11462.
IMapFileData.compareTonever returned0when timestamps were equal, which violated theComparablecontract and could makeCollections.sortfail in WAL recovery.Changes
0for identical records.IMapDataandIMapFileData.FileSystemdoes not provide a portable atomic CAS primitive across HDFS, S3, and OSS; object-store rename cannot safely allocate a global epoch.Ordering scope
This fix guarantees a deterministic total order and prevents the TimSort contract failure. For a same-key, same-millisecond collision it deterministically places a tombstone before a value. It does not claim general last-write-wins ordering for independently active writers, because that would require a portable durable global mutation token that the supported Hadoop filesystems do not expose.
Tests
Verified with:
./mvnw -o -pl seatunnel-engine/seatunnel-engine-storage/imap-storage-plugins/imap-storage-file test ./mvnw -o -pl seatunnel-engine/seatunnel-engine-storage/imap-storage-plugins/imap-storage-file -DskipTests verifyResult: 13 tests, 0 failures, 0 errors, 1 credential-dependent OSS test skipped; module verify passed.