apache/pulsar · error · RestException

Desired partitions %s can't be less than the current partiti

Error message

Desired partitions %s can't be less than the current partitions %s.

What it means

internalUpdatePartitionedTopicAsync pre-check failure (422): the requested partition count is lower than the topic's current partition count. Partition counts can only grow because decrementing would require deleting partitions/topics, which is not supported.

Source

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

     * already exist and number of new partitions must be greater than existing number of partitions. Decrementing
     * number of partitions requires deletion of topic which is not supported.
     *
     * @exception RestException Unprocessable entity, status code: 422. throw it when some pre-check failed.
     * @exception RestException Internal Server Error, status code: 500. throw it when get unknown Exception
     */
    protected @NonNull CompletableFuture<Void> internalUpdatePartitionedTopicAsync(int expectPartitions,
                                                                                   boolean updateLocal,
                                                                                   boolean force) {
        PulsarService pulsarService = pulsar();
        return pulsarService.getBrokerService().fetchPartitionedTopicMetadataAsync(topicName)
            .thenCompose(partitionedTopicMetadata -> {
                int currentMetadataPartitions = partitionedTopicMetadata.partitions;
                if (currentMetadataPartitions <= 0) {
                    throw new RestException(Status.CONFLICT /* Unprocessable entity*/,
                            String.format("Topic %s is not the partitioned topic.", topicName));
                }
                if (expectPartitions < currentMetadataPartitions) {
                    throw new RestException(422 /* Unprocessable entity*/,
                            String.format("Desired partitions %s can't be less than the current partitions %s.",
                                    expectPartitions, currentMetadataPartitions));
                }
                int brokerMaximumPartitionsPerTopic = pulsarService.getConfiguration()
                        .getMaxNumPartitionsPerPartitionedTopic();
                if (brokerMaximumPartitionsPerTopic > 0 && expectPartitions > brokerMaximumPartitionsPerTopic) {
                    throw new RestException(422 /* Unprocessable entity*/,
                            String.format("Desired partitions %s can't be greater than the maximum partitions per"
                                            + " topic %s.",
                                    expectPartitions, brokerMaximumPartitionsPerTopic));
                }
                final PulsarAdmin admin;
                try {
                    admin = pulsarService.getAdminClient();
                } catch (PulsarServerException ex) {
                    throw new RestException(Status.INTERNAL_SERVER_ERROR, Throwables.getRootCause(ex));
                }
                final CompletableFuture<Void> checkFuture;

View on GitHub (pinned to 820761864e)

Solutions

  1. Request a partition count greater than or equal to the current count
  2. To shrink, delete and recreate the partitioned topic (data loss) after draining it
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:387 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/6b7cf5a197bba696. Report an issue: GitHub.