Skip to content

CreateTopics Extension #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 52 commits into
base: kafka-produce
Choose a base branch
from
Draft

CreateTopics Extension #46

wants to merge 52 commits into from

Conversation

ryan-gang
Copy link
Contributor

Introduce two new markdown files outlining the structure and error cases for the CreateTopics API in Kafka. The first file provides a logical progression of stages for implementing the API, while the second file details early error cases that can be handled with request parsing and response encoding. This aligns with existing documentation practices and enhances clarity for future development.

@ryan-gang ryan-gang self-assigned this Jul 14, 2025
Copy link

coderabbitai bot commented Jul 14, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ryan-gang ryan-gang changed the base branch from main to kafka-produce July 16, 2025 16:59
@ryan-gang ryan-gang changed the title Create Topics Extensiin CreateTopics Extension Jul 16, 2025
rohitpaulk and others added 16 commits July 17, 2025 12:13
…ve protocol inspector links and clarifying APIVersions requirements.
…xistent topics, including error response details and interactive protocol inspector links
…s for invalid topics, including error response details
…lid partitions, detailing error responses and adding interactive protocol inspector links
…uction process, including validation steps, log file format, and updated response fields
…uction by consolidating validation, storage, and response steps into a single sentence
… format and add interactive protocol inspector link for cluster metadata topic's log file
…le records in a single RecordBatch, including validation, storage, and updated response fields
…e partitions, including validation, response structure, and log file requirements
…le topics and partitions, including validation, response structure, and offset management
…ng on baseOffset and log_start_offset handling in Kafka
…cluding multiple stages for handling various production scenarios such as invalid topics, partitions, and batch production
@ryan-gang ryan-gang force-pushed the create-topics branch 2 times, most recently from 5c8a486 to b3c0cd6 Compare July 17, 2025 06:46
… invalid topics and partitions, enhancing clarity on error handling and response structure
…tions in a single request, including validation, independent offset management, and nested response structure
…f invalid topics or partitions, enhancing consistency in error response messaging
… handling and response structure, ensuring consistency and accuracy
… and consistency in topic and partition handling
ryan-gang added 16 commits July 18, 2025 15:58
Introduce the first stage description for the CreateTopics API, detailing the inclusion of the API in the APIVersions response. This stage outlines the necessary tests and notes for implementation, setting the groundwork for subsequent stages.
…mentation

Introduce detailed stage descriptions for the CreateTopics API, covering various scenarios such as invalid topic names, existing topics, and authorization checks. This addition enhances the documentation for implementing the API and provides clear guidelines for error handling and validation processes.
…ion and testing

Enhance the stage description for the CreateTopics API by providing a clearer structure, including a dedicated section for the API and its tests. Update the MaxVersion requirement for the CreateTopics API and add links to interactive protocol inspectors for better guidance on request and response structures.
…eTopics API

Introduce a new stage description that outlines the handling of `CreateTopics` requests with invalid topic names. This includes validation rules, expected error responses, and testing procedures to ensure compliance with Kafka's naming conventions.
…teTopics API

Introduce a new stage description that details the handling of `CreateTopics` requests with reserved topic names. This includes validation rules, expected error responses, and testing procedures to ensure compliance with Kafka's naming conventions, particularly focusing on the `__cluster_metadata` topic and other system-reserved names.
…ics API

Introduce a new stage description that details the process for detecting existing topics in the CreateTopics API. This includes validation steps, expected error responses, and testing procedures to ensure proper handling of the `TOPIC_ALREADY_EXISTS` error code. Additionally, links to interactive protocol inspectors for request and response structures are provided to aid in understanding the implementation.
Introduce a new stage description that outlines the process for successfully creating topics with valid parameters in the CreateTopics API. This includes detailed steps for topic creation, validation of parameters, and the expected response structure. Additionally, links to interactive protocol inspectors for request and response structures are provided, along with testing procedures to ensure proper implementation.
Introduce a new stage description that outlines the process for handling multiple topics in a single CreateTopics request. This includes detailed steps for validation, creation, and response handling for each topic, as well as testing procedures to ensure correct implementation. Links to interactive protocol inspectors for request and response structures are also provided.
Introduce a new stage description that outlines the process for handling CreateTopics requests with the `validate_only` flag. This includes detailed validation steps, expected responses, and testing procedures to ensure correct implementation without side effects. Links to interactive protocol inspectors for request and response structures are also provided.
… in CreateTopics API

Introduce a new stage description that outlines the process for successfully creating topics with valid parameters in the CreateTopics API. This includes detailed steps for validation, metadata persistence, directory creation, and expected responses. Additionally, links to interactive protocol inspectors for request and response structures are provided, along with testing procedures to ensure proper implementation.
Update all stage descriptions for the CreateTopics API to reference version 6 instead of version 7. This includes adjustments to the interactive protocol inspector links and the testing procedures to ensure consistency across all stages. The changes clarify the expected request and response structures for the API.
Introduce new stage descriptions for the CreateTopics API, covering various scenarios including handling invalid topic names, partition values, replication factors, and authorization checks. This update enhances the documentation by providing clear guidelines for validation, error handling, and expected responses, ensuring a thorough understanding of the CreateTopics functionality.
…cs API

Update the stage description for handling multiple topics in a single CreateTopics request to improve clarity. The title has been modified to specify "single CreateTopics request," ensuring better understanding of the functionality being documented.
Introduce multiple new stages for the CreateTopics API, focusing on various scenarios such as creating topics with valid, invalid, reserved, and existing names, as well as validation-only mode and batch creation. This update enhances the documentation and provides clear guidelines for implementing the CreateTopics functionality.
Adjust the MaxVersion for the CreateTopics API in the stage description to reflect the correct version 6, ensuring consistency with previous updates and clarifying the expected API behavior.
… description

Clarify the instructions for implementing basic topic name validation by specifying that error responses for invalid topic names can be hard-coded. Additionally, note that checks against existing topics and system topics will be addressed in later stages. Update the testing command to include the server properties file for better clarity.
…xisting topic names

Introduce a new stage that outlines the process for validating topic existence in the CreateTopics API. This includes error handling for existing and reserved topic names, along with detailed testing procedures and links to interactive protocol inspectors for better understanding of the topic metadata structure.
Clarify the handling of CreateTopics requests in validation mode by updating the stage description. Changes include improved wording for validation steps, specifying that no topic metadata is written to the log file, and enhancing the testing command for better clarity.
…reateTopics API

Introduce new stage descriptions for handling CreateTopics requests, detailing the processes for creating a single topic and multiple topics in a single request. The updates include validation steps, metadata handling, and testing procedures, along with links to interactive protocol inspectors for enhanced understanding of the request and response structures.
Enhance the documentation for the CreateTopics API by clarifying the handling of metadata. Specifically, update the descriptions to indicate that both `TOPIC_RECORD` and `PARTITION_RECORD` are not written to the `__cluster_metadata` log file during topic creation. Additionally, refine the steps for writing `PARTITION_RECORD`s to ensure clarity on their creation for each partition. Adjust the testing command details to reflect the correct parameters for topic creation requests.
…ics API

Refine the documentation for handling multiple topics in a CreateTopics request. Update the steps to clarify the writing of `PARTITION_RECORD`s to the `__cluster_metadata` log file for each partition and adjust the testing command to include the server properties file. Ensure that the handling of mixed success/failure scenarios is clearly articulated.
…es in topic creation handling

Revise the documentation for the CreateTopics API stages, including updates to the handling of existing topic names and validation-only mode. Consolidate stages for clarity, ensuring that error codes and success cases are accurately described. Adjust the sequence of stages to improve the flow of topic creation scenarios.
@ryan-gang ryan-gang requested a review from rohitpaulk July 19, 2025 07:52
Copy link
Member

@rohitpaulk rohitpaulk left a comment

Choose a reason for hiding this comment

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

Notes added

all-stages.md Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove this extra file, stick to the md & definition files.

final-stages.md Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Remove this too


- You'll need to parse the `CreateTopics` request in this stage to get the topic names.
- The official docs for the `CreateTopics` request can be found [here](https://kafka.apache.org/protocol.html#The_Messages_CreateTopics).
- Topic name validation logic is in the Kafka source code at `clients/src/main/java/org/apache/kafka/common/internals/Topic.java`.
Copy link
Member

Choose a reason for hiding this comment

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

Use a GitHub permalink here

Reserved topic names include:
- `__cluster_metadata` - KRaft metadata topic

If the topic name is reserved, the broker returns an error code of `42` (INVALID_REQUEST), with the `error_message` field containing `Creation of internal topic __cluster_metadata is prohibited.`.
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove the "reserved topics" thing altogether - doesn't seem worth doing

We've also created an interactive protocol inspector for the `__cluster_metadata` topic's log file:
- 🔎 [__cluster_metadata topic's log file](https://binspec.org/kafka-cluster-metadata)

This would help you understand the structure of the `TOPIC_RECORD` record inside the `__cluster_metadata` topic's log file.
Copy link
Member

Choose a reason for hiding this comment

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

Let's try to link directly to the TOPIC_RECORD bytes here

2. Checks that the topic doesn't already exist (from previous stages)
3. Validates partition count and replication factor parameters
4. Creates a new topic UUID (for successful topics)
5. Writes a `TOPIC_RECORD` to the `__cluster_metadata` topic's log file (for successful topics)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
5. Writes a `TOPIC_RECORD` to the `__cluster_metadata` topic's log file (for successful topics)
5. Writes `TOPIC_RECORD`s to the `__cluster_metadata` topic's log file

Copy link
Member

Choose a reason for hiding this comment

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

(Shorter, and the "successful topics" case is obvious)

7. Creates partition directories in the log directory (for successful topics)
8. Returns individual results for each topic in the response array

Mixed success/failure scenarios are handled gracefully - if one topic fails validation, it doesn't prevent other valid topics from being created.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Mixed success/failure scenarios are handled gracefully - if one topic fails validation, it doesn't prevent other valid topics from being created.
If one topic fails validation, it doesn't prevent other valid topics from being created.

@@ -0,0 +1,50 @@
In this stage, you'll add support for handling `CreateTopics` requests with multiple topics.
Copy link
Member

Choose a reason for hiding this comment

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

On second though, let's remove this stage altogether - unlike producing multiple messages, creating multiple topics doesn't seem like a very common use-case. Simpler to just remove - we can add it back when we have skippable tests


- slug: "ve7"
primary_extension_slug: "creating-topics"
name: "CreateTopics with Invalid Topic Name"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name: "CreateTopics with Invalid Topic Name"
name: "CreateTopics with an invalid topic"

(Remove unnecessary capitalization, and shorten)


- slug: "fl3"
primary_extension_slug: "creating-topics"
name: "CreateTopics with Multiple Topics"
Copy link
Member

Choose a reason for hiding this comment

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

@ryan-gang you really need to pay more attention to detail re: consistency. Why is the above stage name "CreateTopics with a single topic", and this is "CreateTopics with Multiple Topics"? What's the reason for different capitalization?

@ryan-gang ryan-gang marked this pull request as draft July 28, 2025 16:32
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.

2 participants