Repository navigation
Conversation
Wait for every expected DataNode to report termination before auto-unsubscribing a retained snapshot topic. Track per-DataNode completion from both heartbeat and poll terminations, revoke stale completion observations when a heartbeat no longer reports the topic, and clear observations when the advertised topology changes. Add unit tests for the completion barrier, heartbeat invalidation, and topology changes. Co-Authored-By: Claude <noreply@anthropic.com>
|
E2E is currently blocked by an unrelated build failure while cloning and building apache/iotdb master: the Maven testCompile phase cannot resolve Guava's directExecutor/newDirectExecutorService in DriverSchedulerTest and DriverContextTest. The Go build/test jobs pass. I will re-run E2E once the upstream master build is healthy. |
There was a problem hiding this comment.
🟡 Changes recommended
Critical parsing and completion-tracking flaws can prematurely unsubscribe incomplete retained snapshots when configuration values contain whitespace or completion state becomes stale during concurrent updates and provider changes.
5 open issues
Trim retained-progress and mode values before comparison · New Reject stale poll terminations after heartbeat or topology changes · New Invalidate completion observations when a provider reconnects · New Invalidate stale completions when advertised membership shrinks · New Revalidate unsubscribe eligibility after barrier invalidation · New
What changed in this PR
This PR ports the retained-snapshot completion barrier to the Go subscription client, pairing with the server-side completion notices in apache/iotdb#19364.
Changes:
- Tracks completion per DataNode from heartbeat and poll responses before automatically unsubscribing retained snapshots.
- Revokes completion observations on heartbeat and topology changes, and clears them during subscription updates and seeks.
- Adds focused tests and documents the updated completion behavior.
| File | Description |
|---|---|
subscription/README.md |
Documents the retained-snapshot completion barrier. |
subscription/consumer/pull_providers.go |
Integrates heartbeat completion tracking and topology invalidation. |
subscription/consumer/pull_progress.go |
Clears completion observations after a successful seek. |
subscription/consumer/pull_flow.go |
Carries DataNode IDs with poll terminations. |
subscription/consumer/pull_consumer.go |
Adds per-topic completion state and barrier checks. |
subscription/consumer/pull_consumer_test.go |
Tests completion, revocation, and topology changes. |
subscription/consumer/provider_retry_test.go |
Initializes completion state in the test helper. |
subscription/consumer/consumer.go |
Updates the AllConsumed() API documentation. |
Review effort: Balanced
| return strings.EqualFold(attributes[subscriptionTopicModeKey], subscriptionTopicModeSnapshot) && | ||
| strings.EqualFold( | ||
| attributes[subscriptionTopicRetainProgressKey], | ||
| subscriptionTopicRetainProgressValue, | ||
| ) |
There was a problem hiding this comment.
Addressed in 815b6b0: isRetainedSnapshotTopicLocked now trims whitespace on both mode and retain.progress.after.unsubscribe before comparing. Added TestRetainedSnapshotTrimsWhitespaceInTopicAttributes.
| subscriptionTermination{ | ||
| topic: response.CommitContext.Topic, | ||
| dataNodeID: response.CommitContext.DataNodeID, | ||
| }, |
There was a problem hiding this comment.
Addressed in 815b6b0: subscriptionTermination now carries the provider pointer, provider.epoch, topologyGeneration, and completionGeneration, and stagePendingTerminationsLocked rejects superseded poll or heartbeat observations under c.mu. Added TestRetainedSnapshotRejectsStalePollTerminationAfterHeartbeatOrTopologyChange.
| previous := c.providers[provider.dataNodeID] | ||
| c.providers[provider.dataNodeID] = provider | ||
| c.endpoints[provider.dataNodeID] = provider.endpoint | ||
| c.observeEndpointLocked(provider.dataNodeID, provider.endpoint) |
There was a problem hiding this comment.
Addressed in 815b6b0: publishProvider now assigns a monotonic provider.epoch and clears completion observations (incrementing topologyGeneration) whenever an existing provider for a DataNode is replaced, even if its endpoint address is unchanged; handleProviderError and Close also clear completion states. Added TestRetainedSnapshotInvalidatesOnProviderReconnectWithSameAddress.
| for id, endpoint := range response.Endpoints { | ||
| c.observeEndpointLocked(id, endpoint) | ||
| } |
There was a problem hiding this comment.
Addressed in 815b6b0: observeHeartbeatEndpointsLocked detects when a non-empty heartbeat endpoint map omits a previously known DataNode, invalidates completion observations and advances topologyGeneration without blindly dropping endpoints, and triggers requestRecovery() (while skipping staging retained-snapshot completions from that shrinking heartbeat). Added TestRetainedSnapshotHeartbeatShrinkInvalidatesWithoutDroppingEndpoints.
| c.mu.RLock() | ||
| stable := c.topologyGeneration == topologyGeneration | ||
| c.mu.RUnlock() | ||
| if stable { | ||
| _ = c.flushPendingTerminations(operationCtx) |
There was a problem hiding this comment.
Addressed in 815b6b0: flushPendingTerminations and changeSubscriptionsWithBarrier now capture subscriptionTerminationBarrier (topologyGeneration and completionGeneration) and revalidate retained-snapshot barrier eligibility under c.mu before marking pendingUnsubscribes and before each provider subscribe RPC attempt. Added TestRetainedSnapshotBarrierFilterDropsRevokedPendingUnsubscribe.

Summary
Port the client-side retained-snapshot completion barrier from apache/iotdb#19364 to the Go subscription client.
For retained snapshot topics (
mode=snapshot,retain.progress.after.unsubscribe=true), the Go pull consumer now:Non-retained topics keep the existing immediate termination behavior. A pending or failed auto-unsubscribe keeps
AllConsumed()false, as before.This pairing relies on the server-side completion notice for DataNodes that have no local snapshot tasks, which is added by apache/iotdb#19364. Without that server change, a retained snapshot topic spanning multiple DataNodes can wait for a node that never reports completion.
Validation
go test ./subscription/...go test -race ./subscription/consumergo vet ./subscription/...E2E tests were not run locally because they require a live IoTDB cluster; CI will cover them.
Refs apache/iotdb#19364.