kafka: improve stability when creating many topics with Kafka v4 - #6081
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (11)
💤 Files with no reviewable changes (3)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughKafka metadata handling now distinguishes retryable and unretryable errors. Topic visibility controls cache timing. The Kafka factory reuses one client, and sink shutdown follows an ordered lifecycle. ChangesKafka sink coordination
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: ⚪ Minimal · up to This change is merge-ready after normal checks and review; no actionable merge-blocking risk remains. Sequence Diagram(s)sequenceDiagram
participant TopicManager
participant KafkaAdmin
participant TopicCache
TopicManager->>KafkaAdmin: Create topic
loop Until metadata is visible
TopicManager->>KafkaAdmin: GetTopicsMeta
KafkaAdmin-->>TopicManager: Metadata or classified error
end
TopicManager->>TopicCache: Store partition count
sequenceDiagram
participant Sink
participant TopicManager
participant saramaAdminClient
participant Producers
Sink->>Sink: Mark abnormal
Sink->>TopicManager: Close
Sink->>saramaAdminClient: Close admin and shared client
Sink->>Producers: Close producer facades
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Linked Issues checkExplanation The changes address [ ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
/test all |
There was a problem hiding this comment.
Pull request overview
This PR improves Kafka topic-creation robustness in TiCDC’s Kafka sink by treating newly-created topics as potentially not yet visible in metadata, retrying transient Kafka metadata errors, and only caching a topic after Kafka confirms it is visible.
Changes:
- Update
GetTopicsMetato return topic-level errors (includingUnknownTopicOrPartition) when topic errors are not ignored, while preserving the previous “best-effort discovery” behavior when errors are ignored. - Introduce
IsRetryableTopicMetadataErrorto classify transient Kafka metadata errors as retryable and use it to drive bounded retries when waiting for topic visibility. - Ensure the topic manager’s cache is only updated after the topic becomes visible (and add/adjust unit tests to validate caching + retry behavior).
Validation:
- Not run here (code review only; no CI execution available in this environment).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/sink/kafka/admin.go | Makes topic metadata error handling stricter when not ignoring topic errors; adds retryable-metadata error classifier. |
| pkg/sink/kafka/sarama_admin_test.go | Adds unit coverage for the stricter unknown-topic error behavior and for retryable metadata error classification. |
| downstreamadapter/sink/topicmanager/kafka_topic_manager.go | Adds retryable-error classification to topic visibility wait; caches topic only after visibility. |
| downstreamadapter/sink/topicmanager/kafka_topic_manager_test.go | Adds tests ensuring cache isn’t written before visibility and retry behavior honors cancellation / stops on non-retryable errors. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
/test all |
|
/retest |
This reverts commit 4a42703.
|
/unhold |
|
/hold |
|
/retest |
1 similar comment
|
/retest |
|
/unhold |
|
/retest |
|
/test all |
|
/test pull-cdc-pulsar-integration-heavy |
1 similar comment
|
/test pull-cdc-pulsar-integration-heavy |
|
/test all |
|
/retest |
|
In response to a cherrypick label: new pull request created to branch |
|
@3AceShowHand: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
What problem does this PR solve?
Issue Number: close #6076
Kafka may acknowledge topic creation before every broker can return the new topic in metadata. This visibility window becomes easier to hit when a changefeed dynamically creates thousands of topics.
TiCDC previously suppressed
UnknownTopicOrPartitionfromGetTopicsMetaeven when the caller requested strict error handling. The topic manager could then read a missing metadata entry as zero partitions, cache the topic as ready, and start producing too early. The producer failure triggered repeated sink recovery and backoff, which could stall the changefeed checkpoint.What is changed and how it works?
GetTopicsMetareturn topic-level errors, includingUnknownTopicOrPartition, whenignoreTopicErrorisfalse. Discovery calls withignoreTopicError=truecontinue to return metadata for valid topics.Together, these changes keep topic creation in the metadata-validation phase until Kafka confirms visibility and prevent the sink from accepting new DML events after shutdown begins.
Check List
Tests
GOTOOLCHAIN=go1.25.12 GOMAXPROCS=2 go test -p 1 -vet=off ./pkg/sink/kafka ./downstreamadapter/sink/topicmanager -count=1Questions
Will it cause performance regression or break compatibility?
Newly created topics may wait for up to the existing six metadata attempts during Kafka's visibility window; deterministic errors still return after the first attempt.
Do you need to update user documentation, design documentation or monitoring documentation?
Release note