Skip to content

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

Merged
lhotari merged 9 commits into
apache:masterfrom
ChimdumebiNebolisa:fix-24998-allow-defaultNumPartitions
Sep 12, 2026
Merged

lhotari merged 9 commits into
apache:masterfrom
ChimdumebiNebolisa:fix-24998-allow-defaultNumPartitions

Conversation

@ChimdumebiNebolisa

@ChimdumebiNebolisa ChimdumebiNebolisa commented Jan 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #24998

Motivation

The namespace autoTopicCreation override validation rejects defaultNumPartitions whenever topicType=non-partitioned. This forces clients and infrastructure-as-code tools to conditionally omit the field, making shared configuration templates harder to maintain.

The relaxation is intentionally narrow. For non-partitioned overrides, defaultNumPartitions may be null, 0, or 1. Values greater than 1 remain invalid.

Accepted values are persisted as submitted but ignored during runtime topic creation. Auto-created topics therefore remain non-partitioned.

Modifications

  • Updated AutoTopicCreationOverrideImpl.validateOverride to allow defaultNumPartitions for NON_PARTITIONED only when the value is null, 0, or 1.
  • Added unit coverage confirming that 0 and 1 are accepted and 2 is rejected.
  • Added broker-level coverage confirming that:
    • an accepted value of 1 is persisted but ignored when the topic is auto-created
    • a value of 5 is rejected by the admin REST API with HTTP 412

Verifying this change

./gradlew :pulsar-common:test \
  --tests "org.apache.pulsar.common.policies.data.AutoTopicCreationOverrideTest" \
  -PtestRetryCount=0

./gradlew :pulsar-broker:test \
  --tests "org.apache.pulsar.broker.admin.AdminApi2Test.testAutoTopicCreationOverrideNonPartitionedDefaultNumPartitionsIgnored" \
  --tests "org.apache.pulsar.broker.admin.AdminApi2Test.testAutoTopicCreationOverrideNonPartitionedDefaultNumPartitionsRejected" \
  -PtestRetryCount=0

./gradlew quickCheck

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

@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
Contributor 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

lhotari commented Jan 20, 2026

Copy link
Copy Markdown
Member

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.

@lhotari lhotari left a comment

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.

LGTM, thanks for the contribution @ChimdumebiNebolisa

@lhotari lhotari left a comment

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.

The updated tests now match the intended narrow validation: non-partitioned overrides accept null, 0, or 1, while the REST-level test verifies that 5 is rejected with HTTP 412. The accepted value is also verified as persisted but ignored at topic creation, producing a non-partitioned topic. I found no remaining issue in the current 125-line PR diff. The tracker delta contains unrelated upstream merges since the previous approval, so those were excluded in favor of the canonical three-file PR diff.

@ChimdumebiNebolisa

Copy link
Copy Markdown
Contributor Author

Fixed the Broker Group 3 CI failure in 1bdd1b6 by updating the stale validation-message assertion.

The exact failing test now passes locally, and git diff --check is clean.

The new CI runs are awaiting maintainer approval.

@lhotari
lhotari merged commit 93aa6b8 into apache:master Sep 12, 2026
43 checks passed
@lhotari lhotari modified the milestones: 5.0.0-M1, 5.0.0-M2 Sep 12, 2026
lhotari pushed a commit that referenced this pull request Sep 14, 2026
lhotari pushed a commit that referenced this pull request Sep 14, 2026
Radiancebobo pushed a commit to Radiancebobo/pulsar that referenced this pull request Oct 8, 2026
nodece pushed a commit to apache/pulsar-client-go that referenced this pull request Oct 20, 2026
…ior changes (#1545)

* [fix][test] Make TestSetTopicAutoCreation tolerant of broker error message changes

The test asserted exact broker error strings, which broke when Pulsar
changed the messages:

- apache/pulsar#25163 (shipped in 4.2.5) relaxed the non-partitioned
  autoTopicCreation override validation and changed the rejection text from
  "[defaultNumPartitions] is not allowed to be set when the type is
  non-partition." to "[defaultNumPartitions] must be null, 0 or 1 when the
  type is non-partitioned."
- 5.0.0 changed the missing-tenant error from "Tenant does not exist" to
  "Namespace does not exist".

Replace the single exact-match `errReason` with an `errReasons` slice and
assert containment, so the test passes against both old and new broker
versions instead of being brittle to broker wording changes.

Verified against Pulsar 4.2.4, 4.2.5 and 5.0.0.

Co-Authored-By: CodeBuddy Code <[email protected]>

* [fix][test] Authenticate transaction metadata request as super-user

TestTxn_TCClient read transaction metadata through the raw admin HTTP helper
(httpGet -> httpDo), which calls the plain-text web service without any
credentials, so the broker authenticates it as the "anonymous" role.

apache/pulsar#26773 ("Improve transaction admin checks", shipped in 4.2.5 and
5.0.0) added validateSuperUserAccess() to the transaction metadata admin
endpoint (GET /admin/v3/transactions/transactionMetadata/{mostSigBits}/{leastSigBits}).
The unauthenticated request is now rejected with HTTP 401, so transactionStats
fails and the test panics on the nil stats map.

Add an httpGetWithTLS helper that calls the TLS web service using the test
client certificate, whose CN ("admin") is a super-user role in standalone.conf,
and use it for the transaction metadata request.

Verified against Pulsar 4.2.4, 4.2.5 and 5.0.0.

Co-Authored-By: CodeBuddy Code <[email protected]>

* [fix][test] Make TestPartitionState tolerant of removed stats field

apache/pulsar#26687 (PIP-379: Remove the classic Shared and Key_Shared
dispatcher implementations, shipped in 5.0.0) removed
consumersAfterMarkDeletePosition from the subscription stats. The broker no
longer serializes the field, so it unmarshals to a nil map instead of the
empty map the test asserted.

Assert the map is empty, which holds both for the old behavior (empty map)
and the new one (absent/nil).

Verified against Pulsar 4.2.4, 4.2.5 and 5.0.0.

Co-Authored-By: CodeBuddy Code <[email protected]>

* [fix][test] Address review feedback on admin test helpers

- httpGetWithTLS: give the HTTPS test client a 30s timeout so a stalled
  broker/network path cannot hang the test run.
- TestSetTopicAutoCreation: replace the unchecked `err.(rest.Error)` type
  assertion (which panics on transport/TLS errors) with `require.ErrorAs`.

Co-Authored-By: CodeBuddy Code <[email protected]>

* [fix][test] Cache the TLS admin HTTP client in test helper

Build the HTTPS client (key pair, CA pool) once via sync.Once and reuse it
across calls instead of rebuilding it on every request.

Co-Authored-By: CodeBuddy Code <[email protected]>

---------

Co-authored-by: CodeBuddy Code <[email protected]>
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Nov 6, 2026
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Nov 16, 2026
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