Repository navigation
[Subscription] Unblock replay after leader-only writer handoff #19450
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -410,6 +410,8 @@ public class ConsensusPrefetchingQueue { | |
| // converting or retaining their Tablets, so a long writer prefix cannot exhaust the memory | ||
| // needed to find an older record from another writer. | ||
| private final Map<Integer, WriterReplayState> orderedWriterReplay = new ConcurrentHashMap<>(); | ||
| private Map<Integer, SafeFrontier> safeFrontierSnapshot; | ||
| private long safeFrontierSnapshotVersion = Long.MIN_VALUE; | ||
| private long orderedReplayStartSearchIndex = Long.MIN_VALUE; | ||
| private int orderedWriterRoundRobinStart; | ||
| private final AtomicLong orderedRequestBytes = new AtomicLong(); | ||
|
|
@@ -2111,12 +2113,9 @@ private PrefetchRoundResult driveOrderedWriterReplay( | |
| lingerBatch.reset(); | ||
| } | ||
| } | ||
| final Map<Integer, SafeFrontier> safeFrontiers = | ||
| serverImpl.getWriterSafeFrontierTracker().snapshotSafeFrontiers(); | ||
| for (final int writerNodeId : replayActiveWriterNodeIds) { | ||
| getOrCreateWriterReplay(writerNodeId).wasRuntimeActive = true; | ||
| } | ||
| safeFrontiers.keySet().forEach(this::getOrCreateWriterReplay); | ||
| final Map<Integer, SafeFrontier> initialSafeFrontiers = refreshSafeFrontierSnapshot(); | ||
| replayActiveWriterNodeIds.forEach(this::getOrCreateWriterReplay); | ||
| initialSafeFrontiers.keySet().forEach(this::getOrCreateWriterReplay); | ||
| recoveryWriterProgressByWriter.keySet().forEach(id -> getOrCreateWriterReplay(id.getNodeId())); | ||
| realtimeEntriesByWriter.keySet().forEach(this::getOrCreateWriterReplay); | ||
| for (final IndexedConsensusRequest request : pendingEntries) { | ||
|
|
@@ -2150,6 +2149,13 @@ private PrefetchRoundResult driveOrderedWriterReplay( | |
| if (orderedWriterReplay.size() != writerCount && remainingEntryBudget[0] > 0) { | ||
| continue; | ||
| } | ||
| final Map<Integer, SafeFrontier> safeFrontiers = refreshSafeFrontierSnapshot(); | ||
| final int writerCountBeforeFrontierRefresh = orderedWriterReplay.size(); | ||
| safeFrontiers.keySet().forEach(this::getOrCreateWriterReplay); | ||
| if (orderedWriterReplay.size() != writerCountBeforeFrontierRefresh | ||
| && remainingEntryBudget[0] > 0) { | ||
| continue; | ||
| } | ||
| if (replayActiveWriterNodeIds != activeWriterNodeIds) { | ||
| return PrefetchRoundResult.rescheduleNow(); | ||
| } | ||
|
|
@@ -2175,7 +2181,7 @@ private PrefetchRoundResult driveOrderedWriterReplay( | |
| Objects.nonNull(safe) && state.consumedLocalSeq < safe.getLocalSeq(); | ||
| if (!isWriterRuntimeActive(replayActiveWriterNodeIds, writerNodeId) | ||
| && state.caughtUp | ||
| && !(state.wasRuntimeActive && hasUnreadAppliedProgress)) { | ||
| && !hasUnreadAppliedProgress) { | ||
| continue; | ||
| } | ||
| final long safePt = | ||
|
|
@@ -2185,6 +2191,10 @@ private PrefetchRoundResult driveOrderedWriterReplay( | |
| frontiers.add(WriterFrontier.forBarrier(writerNodeId, safePt)); | ||
| } | ||
| } | ||
| if (safeFrontierSnapshotVersion | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. major 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. |
||
| != serverImpl.getWriterSafeFrontierTracker().getSafeFrontierVersion()) { | ||
| return PrefetchRoundResult.rescheduleAfter(WRITER_BARRIER_RETRY_SLEEP_MS); | ||
| } | ||
| final WriterFrontier next = frontiers.peek(); | ||
| if (Objects.isNull(next) || next.isBarrier) { | ||
| lastBlockedWriterFrontier = next; | ||
|
|
@@ -2312,6 +2322,16 @@ private WriterReplayState getOrCreateWriterReplay(final int writerNodeId) { | |
| }); | ||
| } | ||
|
|
||
| private Map<Integer, SafeFrontier> refreshSafeFrontierSnapshot() { | ||
| final WriterSafeFrontierTracker tracker = serverImpl.getWriterSafeFrontierTracker(); | ||
| final long version = tracker.getSafeFrontierVersion(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor 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. |
||
| if (Objects.isNull(safeFrontierSnapshot) || safeFrontierSnapshotVersion != version) { | ||
| safeFrontierSnapshot = tracker.snapshotSafeFrontiers(); | ||
| safeFrontierSnapshotVersion = version; | ||
| } | ||
| return safeFrontierSnapshot; | ||
| } | ||
|
|
||
| private boolean fillOrderedWriterHead( | ||
| final int writerNodeId, | ||
| final WriterReplayState state, | ||
|
|
@@ -2460,7 +2480,6 @@ private static final class WriterReplayState { | |
| private IndexedConsensusRequest head; | ||
| private boolean fromPending; | ||
| private boolean caughtUp; | ||
| private boolean wasRuntimeActive; | ||
|
|
||
| private WriterReplayState(final ProgressWALIterator iterator, final long consumedLocalSeq) { | ||
| this.iterator = iterator; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 foreverThe 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.