Repository navigation
Conversation
|
Initial independent review summary
|
| if (!isWriterRuntimeActive(replayActiveWriterNodeIds, writerNodeId) | ||
| && state.caughtUp | ||
| && !(state.wasRuntimeActive && hasUnreadAppliedProgress)) { | ||
| && !hasUnreadAppliedProgress) { |
There was a problem hiding this comment.
major iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/consensus/ConsensusPrefetchingQueue.java:2184 — Retired writer with unreachable applied frontier blocks ordered replay forever
The skip decision now also holds a Long.MIN_VALUE barrier for non-runtime-active writers while state.consumedLocalSeq < safe.getLocalSeq(), but consumedLocalSeq only grows by reading that writer's WAL records. When those records are no longer readable (WAL pruned by getSafelyDeletedSearchIndex / topic retention, or broken files), the retired writer blocks every other writer's head permanently; the previous !(state.wasRuntimeActive && hasUnreadAppliedProgress) form skipped these caught-up write
…[truncated]
Fix: Only hold the applied-frontier barrier while the missing sequence is still replayable: skip the writer (or fall back to its safe time) once its applied seq cannot be reached from the readable WAL, e.g. compare against the per-writer tail/recovery pro
…[truncated]
There was a problem hiding this comment.
I did not apply the suggested local WAL-tail comparison. A local WAL search position is not a verified upper bound for a remote writer localSeq, and a read error cannot distinguish temporary visibility delay from permanent loss; using either to release the barrier could skip a delayed record and violate ordering. This case needs an authoritative per-writer replayability/retention watermark or a handoff guarantee that the retired writer can no longer apply records. Is there an existing source for that guarantee? I am leaving this thread open pending that invariant.
| continue; | ||
| } | ||
| final Map<Integer, SafeFrontier> safeFrontiers = | ||
| serverImpl.getWriterSafeFrontierTracker().snapshotSafeFrontiers(); |
There was a problem hiding this comment.
minor iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/consensus/ConsensusPrefetchingQueue.java:2152 — Per-entry synchronized safe-frontier snapshot on the replay hot path
snapshotSafeFrontiers() moved from once per round to once per delivered entry inside the while loop. It is synchronized on the shared WriterSafeFrontierTracker and copies every tracked writer plus one SafeFrontier each, while recordAppliedProgress takes the same monitor on the consensus write path under stateMachineLock; with the default subscriptionConsensusBatchMaxWalEntries=1024 this adds up to ~1024 monitor acquisitions and map copies per round per queue.
Fix: Cache the snapshot and refresh it only when applied progress changes (e.g. add a version counter bumped by recordAppliedProgress, or compare per-writer localSeq before re-snapshotting).
There was a problem hiding this comment.
Addressed in 00f800d. Added a monotonically increasing safe-frontier version for writer registration, applied-sequence advances, and effective safe-time advances. The queue reuses the copied snapshot while that version is unchanged and refreshes it only when the version changes. The targeted tracker and queue tests pass.
| continue; | ||
| } | ||
| final Map<Integer, SafeFrontier> safeFrontiers = | ||
| serverImpl.getWriterSafeFrontierTracker().snapshotSafeFrontiers(); |
There was a problem hiding this comment.
[P1] Guard against progress advancing after this snapshot
This is still a point-in-time snapshot. recordAppliedProgress() can advance a retired writer after this call returns while the independent WAL reader has already reported caught up and cannot yet see the record. The decision below then sees no unread progress and can omit that writer barrier, allowing a newer writer entry to be emitted first. The added regression advances progress after the initial snapshot, before this refresh, so it does not cover this post-refresh window. Please ensure the frontier used to release a retired writer remains valid through the ordering decision, and add a test that advances the sequence after this snapshot.
There was a problem hiding this comment.
The version recheck and post-snapshot regression are in 00f800d. Clarification: the check detects progress advances between snapshot acquisition and the final validation, but it is not atomic with the subsequent selection/publication, so a concurrent advance after validation is not excluded. I am leaving this thread open; fully closing that interval needs a coordination or handoff-sealing guarantee. Is there an existing API or invariant for that?
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #19450 +/- ##
============================================
- Coverage 50.64% 50.64% -0.01%
Complexity 137 137
============================================
Files 5788 5788
Lines 427345 427349 +4
Branches 56808 56808
============================================
- Hits 216449 216430 -19
- Misses 210896 210919 +23 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Review-comment update
|
| frontiers.add(WriterFrontier.forBarrier(writerNodeId, safePt)); | ||
| } | ||
| } | ||
| if (safeFrontierSnapshotVersion |
There was a problem hiding this comment.
major iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/consensus/ConsensusPrefetchingQueue.java:2194 — Frontier-version guard aborts the whole delivery round on any concurrent applied progress
safeFrontierVersion is bumped by every applied record on the write path (IoTConsensusServerImpl.recordAppliedProgress:354). The guard runs once per emitted entry and on any bump discards the selection and returns RESCHEDULE_LATER(100ms) even when every frontier is a plain head and no retired-writer release used the snapshot, so a region with active ingestion drops rounds (no entry delivered, no linger flush) whenever progress advances inside the decision window.
Fix: Re-refresh the snapshot and continue the loop as drainWriterEntries does at lines 4015-4023 instead of returning a 100ms delayed reschedule, and only apply this guard when a retired-writer release was decided from the snapshot.
|
|
||
| private Map<Integer, SafeFrontier> refreshSafeFrontierSnapshot() { | ||
| final WriterSafeFrontierTracker tracker = serverImpl.getWriterSafeFrontierTracker(); | ||
| final long version = tracker.getSafeFrontierVersion(); |
There was a problem hiding this comment.
minor iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/consensus/ConsensusPrefetchingQueue.java:2327 — Cached safe-frontier version is read before the snapshot copy, so the stamp always lags the data
getSafeFrontierVersion() is read outside the monitor before the synchronized snapshotSafeFrontiers() copy, so safeFrontierSnapshotVersion is at most the copy's version. A bump during the copy leaves the returned map already holding the newer progress while the stamp lags, which forces a spurious re-copy on the next call and a guaranteed mismatch at the line 2194 guard (which then aborts the round).
Fix: Capture the version and copy the states under the same monitor, as snapshotEffectiveSafePtsWithVersion() does, and stamp the copy with that atomically read version.



Summary
Example
Before: preferred writer 1 has an entry at physical time 2000, while retired writer 5 has applied local sequence 1 at physical time 1000 but that record is not yet visible to WAL replay. Writer 1 must remain blocked until writer 5's record becomes visible and is delivered first. Conversely, once writer 5 is caught up with no unread applied progress and no usable safe time, it must not block writer 1 indefinitely.
After: the queue keeps the barrier while writer 5's applied sequence is unread, then delivers writer 5 before writer 1 when the WAL record appears; it releases the barrier when the retired writer is caught up and has no unread frontier.
Validation
mvn spotless:apply -pl iotdb-core/datanodepassed.git diff --checkpassed.PipeDataNodeTaskAgent.java:127and:228, before any tests ran. An earlier run with 16 of 17 tests passing predates the final fixture adjustment.