Skip to content

Fix retained snapshot completion across DataNodes - #183

Merged
jt2594838 merged 2 commits into
apache:mainfrom
VGalaxies:fix/retained-snapshot-completion-across-datanodes
Nov 25, 2026
Merged

jt2594838 merged 2 commits into
apache:mainfrom
VGalaxies:fix/retained-snapshot-completion-across-datanodes

Conversation

@VGalaxies

@VGalaxies VGalaxies commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • tracks termination per DataNode from both heartbeat and poll responses;
  • auto-unsubscribes only after every expected DataNode has reported termination;
  • revokes a DataNode's completion observation when a later heartbeat no longer reports the topic;
  • clears completion observations when the advertised DataNode topology changes.

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/consumer
  • go vet ./subscription/...

E2E tests were not run locally because they require a live IoTDB cluster; CI will cover them.

Refs apache/iotdb#19364.

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>
@VGalaxies

Copy link
Copy Markdown
Contributor Author

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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
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

Comment thread subscription/consumer/pull_consumer.go Outdated
Comment on lines +480 to +484
return strings.EqualFold(attributes[subscriptionTopicModeKey], subscriptionTopicModeSnapshot) &&
strings.EqualFold(
attributes[subscriptionTopicRetainProgressKey],
subscriptionTopicRetainProgressValue,
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 815b6b0: isRetainedSnapshotTopicLocked now trims whitespace on both mode and retain.progress.after.unsubscribe before comparing. Added TestRetainedSnapshotTrimsWhitespaceInTopicAttributes.

Comment on lines +441 to +444
subscriptionTermination{
topic: response.CommitContext.Topic,
dataNodeID: response.CommitContext.DataNodeID,
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread subscription/consumer/pull_providers.go Outdated
previous := c.providers[provider.dataNodeID]
c.providers[provider.dataNodeID] = provider
c.endpoints[provider.dataNodeID] = provider.endpoint
c.observeEndpointLocked(provider.dataNodeID, provider.endpoint)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread subscription/consumer/pull_providers.go Outdated
Comment on lines +301 to +303
for id, endpoint := range response.Endpoints {
c.observeEndpointLocked(id, endpoint)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +375 to +379
c.mu.RLock()
stable := c.topologyGeneration == topologyGeneration
c.mu.RUnlock()
if stable {
_ = c.flushPendingTerminations(operationCtx)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jt2594838
jt2594838 merged commit 38abcc2 into apache:main Nov 25, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants