kafka: avoid create changefeed failures if can't get a topic from broker - #5696
Conversation
📝 WalkthroughWalkthroughKafka topic management now recognizes Kafka admin authorization failures during metadata lookup and topic creation, falls back to the configured partition count, and caches that value. Tests add authorization-failure mocks and coverage for the describe and create paths. ChangesKafka authorization fallback
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant KafkaTopicManager
participant KafkaClusterAdmin
participant TopicsCache
KafkaTopicManager->>KafkaClusterAdmin: GetTopicsMeta
KafkaClusterAdmin-->>KafkaTopicManager: Authorization failure
KafkaTopicManager->>TopicsCache: Store configured partition count
KafkaTopicManager->>KafkaClusterAdmin: CreateTopic
KafkaClusterAdmin-->>KafkaTopicManager: Authorization failure
KafkaTopicManager->>TopicsCache: Store configured partition count
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
downstreamadapter/sink/topicmanager/kafka_topic_manager.go (1)
299-307: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low valueAvoid masking non-authorization and non-existence errors.
When
GetTopicsMeta(..., false)returns an error, the current logic ignores it unless it's an authorization failure, allowing the flow to proceed tocreateTopic. While this is correct forsarama.ErrUnknownTopicOrPartition, falling through on other errors (like network timeouts) will cause an unnecessarycreateTopicattempt that will likely fail and obscure the original context.Consider explicitly returning unexpected errors to prevent masking them.
♻️ Proposed refactor
topicDetails, err = m.admin.GetTopicsMeta([]string{topicName}, false) if err != nil { if kafka.IsAdminAuthorizationFailed(err) { return m.useConfiguredPartitionNum(topicName, err), nil } + if !errors.Is(err, sarama.ErrUnknownTopicOrPartition) { + return 0, errors.Trace(err) + } } else if numPartition, ok := m.tryStoreTopicMeta(topicName, topicDetails); ok { return numPartition, nil }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@downstreamadapter/sink/topicmanager/kafka_topic_manager.go` around lines 299 - 307, Update the GetTopicsMeta error handling in the topic manager flow: preserve the existing useConfiguredPartitionNum behavior for authorization failures and allow sarama.ErrUnknownTopicOrPartition to continue toward topic creation, but return all other errors immediately instead of falling through to createTopic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@downstreamadapter/sink/topicmanager/kafka_topic_manager_test.go`:
- Around line 261-263: In TestCreateTopicWithCreateDenied, replace the
mockAdminClientWithDeniedDescribe instantiation with
mockAdminClientWithDeniedCreate so GetTopicsMeta succeeds and the test reaches
the createTopic authorization-denied path, preserving the createTopicCalled
assertion.
---
Nitpick comments:
In `@downstreamadapter/sink/topicmanager/kafka_topic_manager.go`:
- Around line 299-307: Update the GetTopicsMeta error handling in the topic
manager flow: preserve the existing useConfiguredPartitionNum behavior for
authorization failures and allow sarama.ErrUnknownTopicOrPartition to continue
toward topic creation, but return all other errors immediately instead of
falling through to createTopic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f5d4a68c-a7eb-4e7e-b2fe-b82fef6bf742
📒 Files selected for processing (3)
downstreamadapter/sink/topicmanager/kafka_topic_manager.godownstreamadapter/sink/topicmanager/kafka_topic_manager_test.gopkg/sink/kafka/admin.go
|
/test all |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: asddongmen, lidezhu The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
|
/retest |
|
In response to a cherrypick label: new pull request created to branch |
What problem does this PR solve?
Issue Number: close #5563
What is changed and how it works?
If ticdc can't get the topic from kafka broker, still create a changefeed instead of throwing an error.
Check List
Tests
changefeed createresultmaster1ErrChangeFeedNotExistsCreateTopicAndWaitUntilVisibletreated the topic as unavailable and attemptedCreateTopic; Kafka returned Topic authorization failure1ErrChangeFeedNotExistsbin/cdcfromacl-0720 @ 6225925f; this run did not use the modifieddownstreamadapterimplementationcdc server --newarch0state: normalstate: warning,ErrKafkaSendMessageafter DDLdownstreamadapterimplementation; create passed by skipping topic creation after authorization failure, but runtime write still requires TopicWriteQuestions
Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?
Release note
Summary by CodeRabbit