apache/pulsar · error · RestException

Can't create topic ${topicName} with "-partition-" followed

Error message

Can't create topic ${topicName} with "-partition-" followed by a number smaller than number of partition of partitioned topic ${partitionTopicName.getLocalName()}

What it means

validateGlobalNamespaceName-style guard in topic-name validation: a topic whose name embeds '-partition-<n>' would collide with an existing partitioned topic's partition index space, so creation is refused with 409.

Source

Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:4836

        CompletableFuture<Void> ret = CompletableFuture.completedFuture(null);
        if (topicName.contains(PARTITIONED_TOPIC_SUFFIX)) {
            try {
                // First check if what's after suffix "-partition-" is number or not, if not number then can create.
                int partitionIndex = topicName.indexOf(PARTITIONED_TOPIC_SUFFIX);
                long suffix = Long.parseLong(topicName.substring(partitionIndex
                        + PARTITIONED_TOPIC_SUFFIX.length()));
                TopicName partitionTopicName = TopicName.get(domain(),
                        namespaceName, topicName.substring(0, partitionIndex));
                ret = getPartitionedTopicMetadataAsync(partitionTopicName, false, false)
                        .thenAccept(metadata -> {
                            // Partition topic index is 0 to (number of partition - 1)
                            if (metadata.partitions > 0 && suffix >= (long) metadata.partitions) {
                                log.warn()
                                        .attr("topic", topicName)
                                        .attr("partitionedTopic", partitionTopicName.getLocalName())
                                        .log("Can't create topic with -partition- followed by"
                                                + " a number smaller than partition count");
                                throw new RestException(Status.PRECONDITION_FAILED,
                                        "Can't create topic " + topicName + " with \"-partition-\" followed by"
                                                + " a number smaller than number of partition of partitioned topic "
                                                + partitionTopicName.getLocalName());
                            } else if (metadata.partitions == 0) {
                                log.warn()
                                        .attr("topic", topicName)
                                        .attr("partitionedTopic", partitionTopicName.getLocalName())
                                        .log("Can't create topic with -partition- followed by"
                                                + " numeric value without a partitioned topic");
                                throw new RestException(Status.PRECONDITION_FAILED,
                                        "Can't create topic " + topicName + " with \"-partition-\" followed by"
                                                + " numeric value if there isn't a partitioned topic "
                                                + partitionTopicName.getLocalName() + " created.");
                            }
                            // If there is a  partitioned topic with the same name and numeric suffix is smaller
                            // than the number of partition for that partitioned topic, validation will pass.
                        });
            } catch (NumberFormatException e) {

View on GitHub (pinned to 820761864e)

Solutions

  1. Choose a topic name without a '-partition-' + number suffix
  2. If a real partition is intended, create it via the partitioned topic API
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:4836 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/0cde8733e7fe4e2a. Report an issue: GitHub.