Repository navigation
Conversation
Caideyipi
left a comment
There was a problem hiding this comment.
One actionable issue found; see the inline review comment.
| terminateEvent, | ||
| e); | ||
| } | ||
| terminateEvent.decreaseReferenceCount(SubscriptionPrefetchingQueue.class.getName(), true); |
There was a problem hiding this comment.
[P2] Preserve the drain barrier for non-marking terminators. This branch is used outside snapshot mode, including the historical-plus-realtime path. Previously, the terminator stayed pending until both inFlightEvents and prefetchingQueue drained; releasing it immediately lets prefetch continue into realtime events while historical replay events may still be unacknowledged, so live events can be polled before replay completion. Please retain the drain/retry check when shouldMark is false.
There was a problem hiding this comment.
Thanks for catching this! Addressed in df8194d: restored the drain and retry barrier for non-marking PipeTerminateEvents (currentNonMarkingTerminateEvent) in SubscriptionPrefetchingQueue. Both tryPrefetch and tryPrefetchV2 now pause prefetching subsequent realtime events until batches.emitAll succeeds and both inFlightEvents and prefetchingQueue are drained, and retry on poll/ack/nack/prefetch paths. Added regression test SubscriptionRetainedInitialReplayTest#testNonMarkingTerminateEventPreservesDrainBarrierBeforeRealtimePrefetch.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #19364 +/- ##
============================================
- Coverage 50.53% 50.50% -0.04%
Complexity 129 129
============================================
Files 5786 5786
Lines 425745 426059 +314
Branches 56465 56549 +84
============================================
+ Hits 215163 215190 +27
- Misses 210582 210869 +287 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
Critical membership races and incomplete endpoint discovery can trigger premature global unsubscribe, while leadership transfer with outstanding acknowledgements can leave subscription queues permanently incomplete.
3 open issues
What changed in this PR
This PR coordinates retained snapshot completion across DataNodes and local DataRegions so subscription consumers wait for all historical data before automatically unsubscribing.
Changes:
- Adds a client-side completion barrier across known DataNode providers.
- Aggregates local DataRegion termination events and handles DataNodes with no local tasks.
- Prevents disconnect-triggered unsubscribe from bypassing the barrier and adds regression coverage.
| File | Description |
|---|---|
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/subscription/receiver/SubscriptionReceiverV1Test.java |
Tests disconnect handling for retained snapshots. |
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/subscription/agent/SubscriptionRetainedInitialReplayTest.java |
Tests regional completion, acknowledgement barriers, and zero-task nodes. |
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/agent/task/PipeDataNodeTaskAgentTest.java |
Tests expected-region checks for zero-task completion. |
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/receiver/SubscriptionReceiverV1.java |
Skips disconnect-triggered unsubscribe for retained snapshots. |
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/SubscriptionPrefetchingQueue.java |
Aggregates regional termination and waits for outstanding deliveries. |
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/SubscriptionBroker.java |
Reports completion for running snapshots without local tasks. |
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/terminate/PipeTerminateEvent.java |
Exposes region identity and completion-marking behavior. |
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/PipeDataNodeTaskAgent.java |
Exposes expected regions and zero-local-task checks. |
iotdb-client/subscription/src/test/java/org/apache/iotdb/session/subscription/consumer/base/SubscriptionConsumerMultiProviderPollTest.java |
Tests completion across multiple providers. |
iotdb-client/subscription/src/main/java/org/apache/iotdb/session/subscription/consumer/base/AbstractSubscriptionProviders.java |
Tracks cluster membership and routes heartbeat completion signals. |
iotdb-client/subscription/src/main/java/org/apache/iotdb/session/subscription/consumer/base/AbstractSubscriptionConsumer.java |
Coordinates provider termination and skips polling completed providers. |
Review effort: Balanced
| final Set<Integer> expectedDataNodeIds = getExpectedDataNodeIds(); | ||
| synchronized (topicTerminationLock) { |
There was a problem hiding this comment.
Addressed in 4d3bee9: handleProviderTopicTermination now holds providers.acquireReadLock() across reading providers.getExpectedDataNodeIds() / providers.getTopologyGeneration() and checking topicTerminationLock, and validates that topologyGeneration is unchanged before issuing unsubscribe(); syncInternal also clears termination state and increments topologyGeneration whenever cluster membership changes. Added regression test SubscriptionConsumerMultiProviderPollTest#testRetainedSnapshotTerminationDoesNotUseStaleMembershipAcrossConcurrentSync.
| final Set<Integer> ids = new HashSet<>(knownClusterDataNodeIds); | ||
| ids.addAll(subscriptionProviders.keySet()); | ||
| return ids; |
There was a problem hiding this comment.
Addressed in 4d3bee9: AbstractSubscriptionProviders.getExpectedDataNodeIds() now returns Collections.emptySet() when knownClusterDataNodeIds is empty so an unproven cluster topology cannot trigger premature global unsubscribe if initial endpoint discovery fails. Added regression test SubscriptionConsumerMultiProviderPollTest#testRetainedSnapshotTerminationWaitsWhenEndpointDiscoveryFailsDuringOpen.
|
|
||
| final PipeTerminateEvent lastTerminateEvent = | ||
| pendingTerminateEvents.get(pendingTerminateEvents.size() - 1); | ||
| lastTerminateEvent.addOnCommittedHook(this::markCompleted); |
There was a problem hiding this comment.
Addressed in 4d3bee9: SubscriptionPrefetchingQueue now tracks per-region termination events, validates expected regions against active committer keys (PipeEventCommitManager.isCurrentCommitterKey), attaches completion hooks to each expected region's event (tracking awaitingCompletionCommitterKeys and committedTerminateDataRegionIds), and handles both zero-expected-region completion and concurrent committer deregistration. Added regression test SubscriptionRetainedInitialReplayTest#testRetainedSnapshotCompletesAfterLastRegionLosesLeadershipWithOutstandingAck.
…adership loss completion
|




Problem
For retained snapshot topics (
mode=snapshotwithretain-progress-after-unsubscribe=true) in a multi-DataNode / multi-DataRegion cluster, completion and auto-unsubscription had four gaps:TERMINATIONsignal from the first DataNode immediately triggered globalunsubscribe(topicName)on ConfigNode, cutting off historical TsFile streaming on other DataNodes that had not finished yet.SubscriptionPrefetchingQueuemarked a snapshot queue completed upon receiving the firstPipeTerminateEvent, without waiting for all expected local DataRegions of the subscription pipe to terminate.PipeTask/ prefetching queue) never emittedTERMINATION, keeping a multi-provider consumer waiting indefinitely.handleExit()bypassing the multi-DataNode barrier: when a consumer connection to one locally completed (or zero-region) DataNode disconnected,SubscriptionReceiverV1#unsubscribeCompleteTopics()immediately called globalunsubscribeon ConfigNode while other DataNodes were still streaming historical data.Fix
TERMINATIONbarrier (AbstractSubscriptionConsumer,AbstractSubscriptionProviders):terminatedDataNodeIdsByTopic) and wait until all expected DataNode providers have reportedTERMINATIONbefore auto-unsubscribing on ConfigNode.TERMINATIONaggregation (PipeTerminateEvent,PipeDataNodeTaskAgent,SubscriptionPrefetchingQueue):getExpectedDataRegionIds(...)onPipeDataNodeTaskAgentand aggregatePipeTerminateEventregion completions inSubscriptionPrefetchingQueueuntil every expected local DataRegion has terminated before marking the queue completed.PipeDataNodeTaskAgent,SubscriptionBroker):PipeDataNodeTaskAgent#isRunningSubscriptionPipeWithoutLocalTasks(pipeName, isTableModel)checking both empty localPipeTasks andgetExpectedDataRegionIds(pipeMeta).isEmpty()(so failed local task creation is never misclassified as completed), allowingSubscriptionBrokerto emitTERMINATIONfor DataNodes with no local regions.SubscriptionReceiverV1):handleExit()/unsubscribeCompleteTopics()for retained snapshot topics (isSnapshotMode() && isProgressRetainedAfterUnsubscribe()), letting client-side multi-DataNode coordination handle global unsubscription.Tests
SubscriptionConsumerMultiProviderPollTest(iotdb-client/subscription): 36/36 pass (including multi-provider retained snapshot barrier tests).PipeDataNodeTaskAgentTest: 21/21 pass (includingtestIsRunningSubscriptionPipeWithoutLocalTasksChecksExpectedRegions).SubscriptionReceiverV1Test: 30/30 pass (includingtestHandleExitSkipsAutoUnsubscribeForRetainedSnapshotTopics).SubscriptionRetainedInitialReplayTest: 9/11 pass (all new multi-region and zero-local-task retained snapshot tests pass; 2 unrelated pre-existingClassCastExceptionerrors onmasterinassertDownloadedTabletPagesReplayTheirRows:226).spotless:applyand-P with-zh-localefull-amtest-compile(28 modules).