GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |
GeezerVison is showing github.com — [cleanup][test] Remove PortManager and use kernel-assigned ports everywhere by merlimat · Pull Request #25694 · apache/pulsar Conversation
Contributor
Motivation
The class has outlived its usefulness — modern BookKeeper identifies bookies by ModificationsRemoved
Refactored
Behavior change
Verifying this changeLocally exercised the affected tests:
Full Does this pull request potentially affect one of the following parts:
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…ywhere `PortManager` (in pulsar-common) and the inner `BasePortManager` of `LocalBookkeeperEnsemble` allocated "free" ports via `ServerSocket(0)` and tracked them in a JVM-level lock set. The lock was JVM-only, so the OS-level port could still be grabbed by another process between allocation and bind, producing flaky `BindException`s in tests. The class has outlived its usefulness — modern BookKeeper identifies bookies by `bookieId`, not host:port, so port 0 (kernel-assigned) is fine across the board. Removed: - `pulsar-common/...PortManager.java` and its test. - `pulsar-package-management/...test/PortManager.java` (unused duplicate). - `BasePortManager` inner class in `LocalBookkeeperEnsemble`. - `bkBasePort` constructor variants of `LocalBookkeeperEnsemble` (no callers left after the standalone change). - `--bookkeeper-port` CLI option from `PulsarStandalone` (and its setter, getter, builder method, plus 3 test calls). Multi-bookie standalone now always uses kernel-assigned ports — bookies are identified by `bookieId`. - `useDynamicBrokerPorts()` toggle in `MultiBrokerBaseTest` (now always true in spirit; ports come from `getBrokerListenPort()` after start). - `bkPort` field in `BKCluster.BKClusterConf`. Refactored: - `BKCluster`: bookies bind to port 0; `bookieId` is derived from the data dir hash so multiple cluster instances on a shared metadata store don't collide on cookie validation, while restarts on the same dir keep cookies stable. The unused cookie-parsing port-recovery logic is dropped. - `MultiBrokerBaseTest`: `mainBrokerPort` and `additionalBrokerPorts` are populated post-start from `pulsar.getBrokerListenPort()` instead of pre-allocated. - `PulsarTestContext.handlePreallocatePorts`: inlined `ServerSocket(0)` allocation. Still needed by tests that build advertised-listener URLs before the broker starts. - 17 test files: `PortManager.nextLockedFreePort()` calls replaced with `0` (let kernel pick) or inline `ServerSocket(0)` (only where pre-allocation is genuinely needed, e.g. for advertised-listener URLs). - `PulsarStandaloneTest.testStandaloneWithRocksDB`: assertion switched from `getBookiePort()` (now returns kernel-assigned ports that change per restart) to `getBookieId()` (the persistent identity). Behavior change: `--bookkeeper-port` is gone from `pulsar standalone`. Bookies get kernel-assigned ports — no impact for normal usage since clients only connect to the broker. Now that all callers pass () -> 0, the supplier is dead weight. Remove it from LocalBookkeeperEnsemble entirely; bookies always bind to port 0. Updated all 41 call sites accordingly.
dao-jun
approved these changes
lhotari
reviewed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's still a need for To avoid collisions for assigned ports across multiple processes, Proposal: reserve a block per JVM starting at a fixed offset. Each instance claims block On release,
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsUh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Address review feedback: PortManager is still useful for tests that need to know a port BEFORE binding (advertised-listener URLs, znode pre-creation, unavailable-node URL synthesis). The old implementation suffered from the JVM-level lock not preventing OS-level collisions, since it allocated inside the kernel's ephemeral range. The restored PortManager addresses both problems: - Allocates from outside the ephemeral range (Linux default 32768-60999) by reserving a 1000-port block per JVM. Each JVM claims a block by binding a lock ServerSocket on the block's base port for the JVM's lifetime; other JVMs that hit the same range observe the bind failure and pick the next. - Released ports do not return to the pool immediately. They sit in a pending-release set until a fresh bind to the port succeeds, which avoids handing out a port that's still in TIME_WAIT. Wired PortManager back into the call sites that genuinely need pre-allocation: - ServiceUrlQuarantineTest (broker port + 40 unavailable-node ports). - ExtensibleLoadManagerImplWithAdvertisedListenersTest (advertised listeners). - ModularLoadManagerImplTest.testOwnBrokerZnodeByMultipleBroker (znode pre-creation). - AdvertisedListenersTest (advertised listeners per broker). - SimpleProtocolHandlerTestsBase / SimpleProxyExtensionTestBase (handler listener address). - PulsarTestContext.handlePreallocatePorts (preallocatePorts(true) preserved). Everything else still uses port 0 with kernel assignment.
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. …Socket(0) version …-manager # Conflicts: # pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/ShadowTopicRealBkTest.java
lhotari
approved these changes
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsTwo distinct issues surfaced on https://github.com/apache/pulsar/actions/runs/25449522387: 1. BookKeeperClusterTestCase (3 copies in pulsar-metadata, managed-ledger, pulsar-package-management) now starts bookies on port 0. Multiple bookies ended up sharing the cookie identity 127.0.0.1:0, breaking cookie validation on the second bookie. This code path (unlike BKCluster, which uses bookieId in metadata) needs the bookie to be reachable by host:port for the test client's address resolver to work — bookieId-only registration leads to UnknownHostException when clients try to dial the bookie. Fix: route through PortManager.nextLockedFreePort() again for these cases. This is exactly the use case lhotari called out in the PR review. 2. PulsarFunctionTlsTest configured both brokers with WebServicePortTls=0. PulsarService.initializeWorkerConfigFromBrokerConfig builds the workerId from "{cluster}-fw-{host}-{configuredPort}", which means both brokers got the same workerId, the function-worker membership manager never elected a leader, and the test timed out waiting for one. Fix: pre-allocate WebServicePortTls via PortManager so each broker gets a unique configured port (and therefore a unique workerId). Uh oh!
There was an error while loading. Please reload this page.
3 of 11 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabelsProjectsDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. 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. |