Skip to content
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

CreateTopics should return TOPIC_ALREADY_EXISTS if topic name already exists when validate_only is specified #7946

Closed
tmgstevens opened this issue Dec 23, 2022 · 3 comments · Fixed by #16410
Assignees
Labels
area/kafka kind/bug Something isn't working

Comments

@tmgstevens
Copy link

Version & Environment

Redpanda version: (use rpk version): 22.3.x

What went wrong?

When using the Kafka AdminClient to create topics with validate_only, we should return TOPIC_ALREADY_EXISTS if the topic name is already used. This is how it works in Apache Kafka. Unfortunately some ecosystem components use this mechanism to robustly verify if a topic already exists (because in Kafka you cannot guarantee that all brokers know about a topic immediately after it's been created),

What should have happened instead?

Redpanda should return TOPIC_ALREADY_EXISTS. We should probably review the logic to look for other error conditions that might be returned (if they aren't already).

How to reproduce the issue?

  1. Use Java AdminClient
  2. Create topic without validate_only
  3. Create topic with validate_only
    public static void createTopic(final String topic, final Properties config, boolean validateOnly) {
        final NewTopic newTopic = new NewTopic(topic, Optional.empty(), Optional.empty());

        CreateTopicsOptions cto = new CreateTopicsOptions();
        cto.validateOnly(validateOnly);

        try (final AdminClient adminClient = AdminClient.create(config)) {
            adminClient.createTopics(Collections.singletonList(newTopic), cto).all().get();
        } catch (final InterruptedException | ExecutionException e) {
            System.out.println(e.getMessage());
            if (!(e.getCause() instanceof TopicExistsException)) {
                throw new RuntimeException(e);
            }
        }
    }

Additional information

Please attach any relevant logs, backtraces, or metric charts.

@weeco
Copy link

weeco commented Dec 18, 2023

I can confirm this issue and want to share other invalid configurations that should have been rejected in a dry-run.

With Redpanda v23.2.19 I tested:

  • Invalid configurations (key that doesn't exist, bool for ints)
  • Forbidden chars in topic names
  • Topic already exists
  • Replication factor 5 (more than brokers exist)

None of these have returned a validation error, which would have been the expected behaviour. There was only one case where I was able to cause a validation error at all, which was when using a replication factor (e.g. 4). I assume this is the only check when validate_only is set to true? We should do more in-depth checks as Tristan suggested.

@oleiman
Copy link
Member

oleiman commented Jan 30, 2024

Currently working on #15722 and wanted to ask - does anybody know what Kafka returns (for partition count and replication factor specifically) in the validate_only && ALREADY_EXISTS case? I assume it's one of:

  1. The exact values provided in the request
  2. The values configured on the already-existing topic
  3. Default placeholders (p: -1, r: -1)

The reason I ask is that several clients discard the configs and numeric parameters in CreateTopic responses, so I'm curious whether the ask here includes detailed introspection of the already-existing topic vs "just give me the right error code".

cc @weeco @tmgstevens

@oleiman
Copy link
Member

oleiman commented Jan 31, 2024

I assume it's one of:

1. The exact values provided in the request
2. The values configured on the already-existing topic
3. Default placeholders (p: -1, r: -1)

Looks like the answer is (3), which I believe is how redpanda behaves already (modulo the error code). If not, it will be very straightforward to reproduce.

Here's what I tried, for posterity:

$ kcl misc raw-req -k 19
{"Version": 6, "ValidateOnly": true, "TimeoutMillis": 60000, "Topics": [{"Topic": "foobar", "NumPartitions": 1, "ReplicationFactor": 1}]}
{
  "Version": 7,
  "ThrottleMillis": 0,
  "Topics": [
    {
      "Topic": "foobar",
      "TopicID": [
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0
      ],
      "ErrorCode": 36,
      "ErrorMessage": "Topic 'foobar' already exists.",
      "ConfigErrorCode": 0,
      "NumPartitions": -1,
      "ReplicationFactor": -1,
      "Configs": [],
      "UnknownTags": {}
    }
  ],
  "UnknownTags": {}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kafka kind/bug Something isn't working
Projects
None yet
6 participants