Skip to content

KAFKA-20537: Return topic ID for existing topics - #22945

Open
lh0156 wants to merge 3 commits into
apache:trunkfrom
lh0156:agent/KAFKA-20537-return-existing-topic-id
Open

KAFKA-20537: Return topic ID for existing topics#22945
lh0156 wants to merge 3 commits into
apache:trunkfrom
lh0156:agent/KAFKA-20537-return-existing-topic-id

Conversation

@lh0156

@lh0156 lh0156 commented Jul 26, 2026

Copy link
Copy Markdown

Summary

Return the existing topic ID in the CreateTopicsResponse when a
requested topic already exists, and expose that ID through
CreateTopicsResult.topicId(topic).

Motivation

The controller already has the topic ID in the controller metadata
image, so returning it avoids an additional metadata lookup for clients
that need the ID. The AdminClient now preserves that ID independently
from the topic-creation status.

Compatibility

  • CreateTopicsResult.topicId(topic) succeeds with the existing ID for
    TOPIC_ALREADY_EXISTS.
  • CreateTopicsResult.values() and all() continue to fail with
    TopicExistsException, preserving their existing semantics.
  • Older responses without topic metadata preserve the existing
    UnsupportedVersionException behavior for metadata accessors.

Validation

  • ./gradlew :clients:test --tests org.apache.kafka.clients.admin.KafkaAdminClientTest --no-build-cache --console=plain (291 tests passed)
  • ./gradlew :metadata:test --tests org.apache.kafka.controller.ReplicationControlManagerTest --no-build-cache --console=plain (75 tests passed)
  • Checkstyle and SpotBugs completed successfully for the affected
    modules.

Reviewers: Sushant Mahajan smahajan@confluent.io

@github-actions github-actions Bot added triage PRs from the community kraft small Small PRs labels Jul 26, 2026
@smjn
smjn requested a review from Copilot July 31, 2026 04:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the controller’s CreateTopics handling so that when a requested topic already exists, the CreateTopicsResponse includes the existing topic’s ID instead of the default zero UUID, avoiding an extra metadata lookup for clients that need the ID.

Changes:

  • Populate CreatableTopicResult.topicId when the error is TOPIC_ALREADY_EXISTS.
  • Extend the ReplicationControlManagerTest#testCreateTopics assertion to validate the existing topic ID is returned on the already-exists response.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java Sets the topic ID in CreateTopicsResponseData for TOPIC_ALREADY_EXISTS results using the controller’s topicsByName mapping.
metadata/src/test/java/org/apache/kafka/controller/ReplicationControlManagerTest.java Updates testCreateTopics to expect the existing topic ID in the TOPIC_ALREADY_EXISTS response.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@smjn

smjn commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

@lh0156 Do you want to update the admin client as well to actually display the topic id which you are returning?

@github-actions github-actions Bot removed the triage PRs from the community label Aug 1, 2026
@lh0156
lh0156 force-pushed the agent/KAFKA-20537-return-existing-topic-id branch from 654b4fb to 101e8f0 Compare August 2, 2026 11:43
@lh0156

lh0156 commented Aug 2, 2026

Copy link
Copy Markdown
Author

Implemented the AdminClient follow-up in cfc1ef1.

CreateTopicsResult.topicId(topic) now completes with the existing topic ID when the controller returns TOPIC_ALREADY_EXISTS, while values() and all() retain their existing TopicExistsException behavior. For older responses without topic metadata, topicId() preserves the existing UnsupportedVersionException behavior without changing values()/all().

Added focused coverage for the existing-topic response and the unsupported-metadata compatibility path. Verification on the latest trunk:

  • :clients:test --tests org.apache.kafka.clients.admin.KafkaAdminClientTest (291 tests passed)
  • :metadata:test --tests org.apache.kafka.controller.ReplicationControlManagerTest (75 tests passed)
  • Checkstyle and SpotBugs completed successfully for the affected modules.

The two follow-up commits include Kafka's required Generated-by: OpenAI Codex (GPT-5) trailer.

@github-actions github-actions Bot added clients and removed small Small PRs labels Aug 2, 2026
@lh0156
lh0156 force-pushed the agent/KAFKA-20537-return-existing-topic-id branch from f177d63 to cfc1ef1 Compare August 2, 2026 13:17
@lh0156

lh0156 commented Aug 2, 2026

Copy link
Copy Markdown
Author

Status follow-up: the implementation and required JUnit/build checks are green. The only failing status is Gradle Build Scan / Java 25, which reports a build-scan publication error; rerunning that workflow requires repository-admin access. No code failure is indicated. The PR is ready for maintainer review once the infrastructure check is rerun or waived.

Generated-by: OpenAI Codex (GPT-5)

Signed-off-by: Yunseop Eom <62834176+lh0156@users.noreply.github.com>
@lh0156
lh0156 force-pushed the agent/KAFKA-20537-return-existing-topic-id branch from cfc1ef1 to 388dbb9 Compare August 3, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants