GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [fix][broker] Match namespace isolation policy brokers given as host:port by aywengo · Pull Request #26829 · apache/pulsar

Conversation

@aywengo

@aywengo aywengo commented Oct 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #15795

Motivation

Brokers are identified by broker id (host:port), which is how pulsar-admin brokers list and pulsar-admin ns-isolation-policy brokers show them. Namespace isolation policies, however, are only matched against the broker host:

  • pulsar-admin ns-isolation-policy set ... --primary hostname1:8080 is accepted but never applied, because placement matches the policy regex against hostname1 only. Topics in the namespace then can't be assigned, which is hard to troubleshoot.
  • ns-isolation-policy brokers / ns-isolation-policy broker <host:port> match policies against the full host:port, so a valid host-only policy (--primary hostname1) is reported as not applying to that broker.

Users naturally copy broker names from brokers list into policies, so both forms should work, without changing how existing host-only policies are applied.

Modifications

Policy entries are applied as follows:

  • Every entry is matched against the broker host, exactly as before.
  • An entry that contains : is also matched against host:port. A : has no other use in a host name pattern, so entries without one keep their current meaning and can't widen.
  • host:port is built with HostAndPort, so an IPv6 broker is matched as [2001:db8::1]:8080 (the entry must escape the brackets: \[2001:db8::1\]:8080). The last segment of an IPv6 address is therefore never taken for a port.

Changes:

  • NamespaceIsolationPolicy: new default methods isPrimaryBrokerId / isSecondaryBrokerId (returning false), implemented in NamespaceIsolationPolicyImpl. findPrimaryBrokers / findSecondaryBrokers also apply entries with a port, and match an IPv6 URL host without brackets as well as with them.
  • NamespaceIsolationPolicies / SimpleResourceAllocationPolicies: new isPrimaryBrokerIdInAnyPolicy, plus isPrimaryBrokerId / isSecondaryBrokerId per namespace.
  • LoadManagerShared (sync and async placement): a broker is primary/secondary if its host or its broker id matches the policy. A broker reserved by a primary entry with a port is excluded from the shared pool used by namespaces without a policy.
  • ClustersBase (ns-isolation-policy brokers/broker) and NamespaceService (namespace ownership status) apply the same rules as placement.
  • pulsar-admin ns-isolation-policy set: the --primary / --secondary help text describes the accepted forms.

Release note

Namespace isolation policy entries that contain : are now also matched against the broker id (host:port, as listed by pulsar-admin brokers list; an IPv6 broker as \[addr\]:port). Entries without : are unchanged. Existing host:port entries, which previously had no effect, will start reserving brokers after the upgrade.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • NamespaceIsolationPolicyImplTest:
    • testIsPrimaryOrSecondaryBrokerId: entries with a port (broker1:8080, ^broker1:8080$, broker1:8080|broker2:8080, broker1:80[0-9]{2}, broker1:\d+, ...) match broker ids; host entries never match through a broker id's port (broker.*[13] vs broker2:8081); IPv6 host and \[addr\]:port entries.
    • testFindBrokersWithPort: the same for findPrimaryBrokers / findSecondaryBrokers, including bracketed IPv6 URLs.
  • LoadManagerSharedTest (sync and async placement, with real stored policies):
    • testApplyNamespacePoliciesWithBrokerIdPolicy: entries with a port select only matching broker ids, including IPv6.
    • testApplyNamespacePoliciesKeepsHostRegexSemantics: existing host regex placement is unchanged, including IPv6 hosts.
    • testApplyNamespacePoliciesExcludesBrokerIdPrimaryFromSharedPool: a namespace without a policy is not placed on a broker reserved by an entry with a port.
  • AdminApi2Test#brokerNamespaceIsolationPoliciesWithBrokerId: with a host:port primary entry, the broker is reported as primary by ns-isolation-policy brokers/broker, the namespace is placed on it and its ownership status is primary; with a host-only primary entry, the broker id is reported as primary too.
  • Existing NamespaceIsolationPoliciesTest, BrokerIsolationPoliciesFilterTest, TransferShedderTest and NamespaceServiceTest pass.

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

If the box was checked, please highlight the changes

  • 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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot AI balanced review requested due to automatic review settings October 6, 2026 20:22
Copilot started reviewing on behalf of aywengo October 6, 2026 20:23
View session
Copilot AI reviewed Oct 6, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

IPv6 URL hosts retain brackets, preventing copied broker IDs from matching in broker discovery methods.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
  • Medium severity Normalize bracketed IPv6 hosts before building broker IDs · New
What changed in this PR

Enables namespace isolation policies to match brokers by either host or host:port.

Changes:

  • Adds host/port-aware policy matching.
  • Updates synchronous and asynchronous broker filtering.
  • Adds broker-ID, port, and IPv6 tests.
File Description
NamespaceIsolationPolicyImpl.java Adds host/port matching and URL port handling.
NamespaceIsolationPolicyImplTest.java Tests port-aware and IPv6 matching.
LoadManagerShared.java Checks policies against hosts and broker IDs.
BrokerIsolationPoliciesFilterTest.java Tests asynchronous broker-ID filtering.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...ommon/src/main/java/org/apache/pulsar/common/policies/impl/NamespaceIsolationPolicyImpl.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@aywengo
aywengo force-pushed the fix-ns-isolation-broker-port branch 2 times, most recently from c8b6f59 to b32aa98 Compare October 10, 2026 18:48
codelipenghui
codelipenghui reviewed Oct 10, 2026
View reviewed changes
Comment thread ...ommon/src/main/java/org/apache/pulsar/common/policies/impl/NamespaceIsolationPolicyImpl.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LoadManagerShared.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@aywengo
aywengo requested a balanced review from Copilot October 11, 2026 06:59
Copilot started reviewing on behalf of aywengo October 11, 2026 07:00
View session
Copilot AI reviewed Oct 11, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

🟡 Changes recommended

IPv6 IDs, reporting paths, and shared-pool isolation remain incorrect for port-specific policies.

3 open findings
  • High severity Apply broker-ID-aware shared checks to uncontrolled namespaces · New
  • Medium severity Use consistent host and broker-ID checks in isolation reporting · New
  • Medium severity Support exact IPv6 broker IDs in isolation matching · New
1 resolved since last review
  • Medium severity Normalize bracketed IPv6 hosts before building broker IDs

🧠 Review effort: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LoadManagerShared.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pulsar-common/src/main/java/org/apache/pulsar/common/policies/NamespaceIsolationPolicy.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...ommon/src/main/java/org/apache/pulsar/common/policies/impl/NamespaceIsolationPolicyImpl.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@aywengo
aywengo requested a balanced review from Copilot October 11, 2026 07:37
Copilot started reviewing on behalf of aywengo October 11, 2026 07:38
View session
Copilot AI reviewed Oct 11, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

🟡 Changes recommended

Anchored host-port regexes are misclassified as host-only and therefore never applied.

2 open findings
  • Medium severity Accept trailing $ anchors in host-port regex classification · New
  • Medium severity Use consistent host and broker-ID checks in isolation reporting
2 resolved since last review
  • High severity Apply broker-ID-aware shared checks to uncontrolled namespaces
  • Medium severity Support exact IPv6 broker IDs in isolation matching

🧠 Review effort: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...ommon/src/main/java/org/apache/pulsar/common/policies/impl/NamespaceIsolationPolicyImpl.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@aywengo
aywengo requested a balanced review from Copilot October 11, 2026 09:51
Copilot started reviewing on behalf of aywengo October 11, 2026 09:52
View session
Copilot AI reviewed Oct 11, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

🔵 Needs a closer look

IPv6 URL normalization and port-specific matching against IPv6 hosts can currently produce incorrect policy results.

0 open findings

2 resolved since last review
  • Medium severity Accept trailing $ anchors in host-port regex classification
  • Medium severity Use consistent host and broker-ID checks in isolation reporting
Previously missed (1)

In code that hasn't changed since last review

Medium severity Normalize bracketed IPv6 hosts before broker matching

pulsar-common/​src/​main/​java/​org/​apache/​pulsar/​common/​policies/​impl/​NamespaceIsolationPolicyImpl.java:65

URL#getHost() keeps brackets around IPv6 literals, so the explicitly supported host-only IPv6 policy 2001:db8::1 does not match http://[2001:db8::1]:8080 in either findPrimaryBrokers or findSecondaryBrokers. Normalize the URL host before applying both host and broker-ID matching.

This issue also appears on line 137 of the same file.

🧠 Review effort: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
aywengo added 5 commits October 11, 2026 11:57
@aywengo
[fix][broker] Match namespace isolation policy brokers given as host:…
88ddbd0
…port

Brokers are identified as host:port (e.g. in `pulsar-admin brokers list`
and `pulsar-admin ns-isolation-policy brokers`), but namespace isolation
policies were only ever matched against the broker host. As a result a
policy with `--primary hostname1:8080` was accepted but never applied,
and the `ns-isolation-policy brokers/broker` admin endpoints reported no
policy for brokers that did match a host-only policy.

- NamespaceIsolationPolicyImpl: match a broker against the full value
  first and, if it has a numeric port suffix, against the host part.
  findPrimaryBrokers/findSecondaryBrokers now also consider host:port.
- LoadManagerShared: check isolation policies against both the broker
  host and the broker id (host:port).

Fixes apache#15795
@aywengo
Match bracketed IPv6 broker URLs against bare broker ids
b28a46c
URL#getHost returns IPv6 literals in brackets while broker ids use the bare
address, so findPrimaryBrokers/findSecondaryBrokers now match the bare form
and keep matching the bracketed form for backward compatibility.
@aywengo
Match port-specific policy entries against broker ids only
2601167
Address review feedback: matching the full broker id against every policy
regex, and stripping a trailing port from any value, changed how existing
host regexes are applied (e.g. `broker.*[13]` matched `broker2:8081`, and
the last segment of an IPv6 host was taken for a port).

Host regexes are now matched against the broker host exactly as before.
Only policy entries that name a specific port (`host:port`) are matched
against the broker id, through new isPrimaryBrokerId/isSecondaryBrokerId
methods. Such entries never matched before, so existing policies keep
their current placement.
@aywengo
Keep port-specific primaries out of the shared pool and apply them in…
4d2bfab
… reporting

- A broker reserved as primary by a port-specific entry (host:port) was
  still considered shared for namespaces without an isolation policy,
  because the shared-pool check only looked at the broker host. The load
  manager now also excludes such brokers from the shared pool.
- `ns-isolation-policy brokers/broker` and the namespace ownership status
  now match host entries against the broker host and port-specific entries
  against the broker id, the same way placement does.
- Placement tests use SimpleResourceAllocationPolicies with real stored
  policies instead of a partial mock.
@aywengo
Treat anchored host:port policy entries as port-specific
cd2cdb1
Allow an optional trailing $ so entries such as ^broker1:8080$ are matched
against the broker id instead of being treated as host-only.
@aywengo
aywengo force-pushed the fix-ns-isolation-broker-port branch from 80da8b4 to cd2cdb1 Compare October 11, 2026 09:57
@aywengo
aywengo requested a review from codelipenghui October 11, 2026 18:43
lhotari
lhotari reviewed Oct 12, 2026
View reviewed changes

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for working on #15795 and for iterating on the earlier feedback. Matching port-specific entries against the broker id keeps existing host-only policies unchanged. The shared-pool exclusion, the ClustersBase and ownership-status handling, and the placement tests with real policies are good additions.

Placement works for the entry forms that HOST_PORT_REGEX recognises. The main point is that it recognises only a few shapes. Other port entries, and any IPv6 entry, silently never match. A simpler rule would handle all of them: treat any entry that contains : as possibly port-specific, and also match it against the bracketed host:port form.

The other comments are small follow-ups: a few missing regression tests, docs for the accepted entry form, and a misleading code comment in isPrimaryBrokerIdInAnyPolicy.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mercury-nightly reacted with heart emoji
All reactions
  • ❤️ 1 reaction
Comment thread ...ommon/src/main/java/org/apache/pulsar/common/policies/impl/NamespaceIsolationPolicyImpl.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/ClustersBase.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...rc/main/java/org/apache/pulsar/broker/loadbalance/impl/SimpleResourceAllocationPolicies.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@aywengo
Match any policy entry containing ':' against host:port
eef3131
Address review feedback: recognising port-specific entries by their regex
shape missed valid entries such as `broker1:8080|broker2:8080`,
`broker1:80[0-9]{2}` and any IPv6 entry, which then silently never matched.

- An entry that contains ':' is now matched against both the broker host and
  host:port. Entries without ':' keep their current meaning.
- host:port is built with HostAndPort, so an IPv6 broker uses the bracketed
  form, e.g. `\[2001:db8::1\]:8080`, and the last address segment is never
  taken for a port.
- findPrimaryBrokers/findSecondaryBrokers also match the bare IPv6 host.
- Document the accepted forms in the --primary/--secondary help text.
- Drop the misleading fail-closed comment in isPrimaryBrokerIdInAnyPolicy.
- Add AdminApi2Test coverage for reporting and ownership status with a
  host:port primary entry.
lhotari
lhotari approved these changes Oct 14, 2026
View reviewed changes

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM. The : rule is in, and I traced each shape from my earlier review through the new code. They all match now. The three open points are addressed. I did not run the build or the tests.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mercury-nightly reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@lhotari lhotari added release/4.2.6 release/4.0.15 labels Oct 14, 2026
@lhotari

lhotari commented Oct 14, 2026

Copy link
Copy Markdown
Member

@codelipenghui please review

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

codelipenghui
codelipenghui approved these changes Oct 15, 2026
View reviewed changes
@codelipenghui
codelipenghui merged commit 25fe96c into apache:master Oct 15, 2026
44 checks passed

Uh oh!

There was an error while loading. Please reload this page.

lhotari pushed a commit that referenced this pull request Oct 15, 2026
@aywengo @lhotari
[fix][broker] Match namespace isolation policy brokers given as host:…
a8837f4
…port (#26829)

(cherry picked from commit 25fe96c)
@lhotari lhotari added release/5.0.1 cherry-picked/branch-5.0 labels Oct 15, 2026
lhotari pushed a commit that referenced this pull request Oct 16, 2026
@aywengo @lhotari
[fix][broker] Match namespace isolation policy brokers given as host:…
04ce506
…port (#26829)

(cherry picked from commit 25fe96c)
@lhotari lhotari added cherry-picked/branch-4.2 cherry-picked/branch-4.0 labels Oct 17, 2026
@merlimat merlimat mentioned this pull request Oct 24, 2026
[Bug] ns-isolation-policy takes a long time take effect #20886
Closed
1 of 2 tasks
scmi-c8y pushed a commit to scmi-c8y/pulsar that referenced this pull request Oct 30, 2026
@aywengo @lhotari
[fix][broker] Match namespace isolation policy brokers given as host:…
b55d00b
…port (apache#26829)

(cherry picked from commit 25fe96c)
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Nov 16, 2026
@aywengo @nodece
[fix][broker] Match namespace isolation policy brokers given as host:…
8aabd7c
…port (apache#26829)

(cherry picked from commit 25fe96c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@lhotari lhotari lhotari approved these changes
Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@codelipenghui codelipenghui codelipenghui approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 release/4.0.15 release/4.2.6 release/5.0.1

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

在配置ns-isolation-policy 的时候broker的配置不能采用hostname:端口

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@aywengo @lhotari @codelipenghui
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.