Skip to content

[fix][admin] Allow defaultNumPartitions for non-partitioned autoTopicCreation override#25163

Open
ChimdumebiNebolisa wants to merge 3 commits intoapache:masterfrom
ChimdumebiNebolisa:fix-24998-allow-defaultNumPartitions
Open

[fix][admin] Allow defaultNumPartitions for non-partitioned autoTopicCreation override#25163
ChimdumebiNebolisa wants to merge 3 commits intoapache:masterfrom
ChimdumebiNebolisa:fix-24998-allow-defaultNumPartitions

Conversation

@ChimdumebiNebolisa
Copy link
Copy Markdown

@ChimdumebiNebolisa ChimdumebiNebolisa commented Jan 19, 2026

Fixes #24998

Motivation

The current namespace autoTopicCreation override validation rejects defaultNumPartitions when topicType=non-partitioned. This forces clients and IaC tooling to conditionally omit a field based on topic type, which makes the API less consistent and more error-prone.

Modifications

  • Relaxed AutoTopicCreationOverride validation to allow defaultNumPartitions to be set when topicType=non-partitioned (value is accepted and persisted).
  • Kept runtime behavior unchanged: defaultNumPartitions is still only used for partitioned auto-creation.
  • Updated unit test expectations and added a broker test to verify the value is ignored during non-partitioned topic creation.

Verifying this change

This change added tests and can be verified as follows:

  • mvn -pl pulsar-common -Dtest=AutoTopicCreationOverrideTest test
  • mvn -pl pulsar-broker -am -Dtest=AdminApi2Test#testAutoTopicCreationOverrideNonPartitionedDefaultNumPartitionsIgnored -Dsurefire.failIfNoSpecifiedTests=false test

Does this pull request potentially affect one of the following parts:

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc-not-needed

Note: Updated validateOverride to preserve topic type validation and allow defaultNumPartitions for NON_PARTITIONED topics only when the value is null, 0, or 1. Updated unit tests to cover 0, 1, and to reject 2.

@ChimdumebiNebolisa ChimdumebiNebolisa force-pushed the fix-24998-allow-defaultNumPartitions branch from 6a10c6a to 7a13f42 Compare January 19, 2026 13:19
@ChimdumebiNebolisa
Copy link
Copy Markdown
Author

Updated validateOverride to keep topic type validation and allow defaultNumPartitions for NON_PARTITIONED only when null, 0, or 1. Updated unit tests to cover 0, 1, and reject 2.

@lhotari lhotari changed the title [fix][admin] Allow defaultNumPartitions for non-partitioned autoTopicCreation override (Fixes #24998) [fix][admin] Allow defaultNumPartitions for non-partitioned autoTopicCreation override Jan 20, 2026
@lhotari
Copy link
Copy Markdown
Member

lhotari commented Jan 20, 2026

Updated validateOverride to keep topic type validation and allow defaultNumPartitions for NON_PARTITIONED only when null, 0, or 1. Updated unit tests to cover 0, 1, and reject 2.

Please add this information to the PR description.

Copy link
Copy Markdown
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the contribution @ChimdumebiNebolisa

Comment on lines +2470 to +2475
AutoTopicCreationOverride overridePolicy = AutoTopicCreationOverride.builder()
.allowAutoTopicCreation(true)
.topicType(TopicType.NON_PARTITIONED.toString())
.defaultNumPartitions(5)
.build();
admin.namespaces().setAutoTopicCreation(namespaceName, overridePolicy);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shouldn't this fail?

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.

API usability: defaultNumPartitions validation is too strict for non-partitioned topic type

2 participants