BewareMyPower opened a new pull request, #23298:
URL: https://github.com/apache/pulsar/pull/23298
### Motivation
It's observed in our test environment many times after restarting the only
broker with the extensible load manager's broker registry service.
```
2024-09-12T14:00:20,557+0000 [main] ERROR
org.apache.pulsar.broker.loadbalance.extensions.ExtensibleLoadManagerImpl -
Failed to start the extensible load balance and close broker registry
org.apache.pulsar.broker.loadbalance.extensions.BrokerRegistryImpl@6d6c4775.
org.apache.pulsar.broker.PulsarServerException:
org.apache.pulsar.metadata.api.MetadataStoreException$LockBusyException:
Resource at /loadbalance/brokers/<broker-id>:8080 is already locked
at
org.apache.pulsar.broker.loadbalance.extensions.BrokerRegistryImpl.start(BrokerRegistryImpl.java:112)
~
at
org.apache.pulsar.broker.loadbalance.extensions.ExtensibleLoadManagerImpl.start(ExtensibleLoadManagerImpl.java:370)
at
org.apache.pulsar.broker.loadbalance.extensions.ExtensibleLoadManagerWrapper.start(ExtensibleLoadManagerWrapper.java:50)
at
org.apache.pulsar.broker.PulsarService.startLoadManagementService(PulsarService.java:1426)
at
org.apache.pulsar.broker.PulsarService.start(PulsarService.java:986)
...
Caused by:
org.apache.pulsar.metadata.api.MetadataStoreException$LockBusyException:
Resource at /loadbalance/brokers/<broker-id>:8080 is already locked
at
org.apache.pulsar.metadata.api.MetadataStoreException.unwrap(MetadataStoreException.java:186)
~
at
org.apache.pulsar.broker.loadbalance.extensions.BrokerRegistryImpl.register(BrokerRegistryImpl.java:131)
~
at
org.apache.pulsar.broker.loadbalance.extensions.BrokerRegistryImpl.start(BrokerRegistryImpl.java:110)
~
... 16 more
```
The "Resource xxx is already locked" is usually caused by a
`BadVersionException`. It might be a bug with `LockManager`, but there are no
more information to analyze.
Actually, it's not a good use case of `LockManager` here. The broker
registry only:
1. Put it's own broker's lookup data under the of
`/loadbalance/brokers/<broker-id>` when starting (in the main thread)
2. Delete its own broker id from when closing.
3. Query any broker's lookup data from the `/loadbalance/brokers/<broker-id>`
4. List all children nodes of `/loadbalance/brokers`.
Currently, step 1 and 2 are performed by the distribution lock implemented
by `LockManager`. However, there should be no race condition because the broker
id is the unique identifier of a broker. There is no case that a broker starts
or closes concurrently. In addition, it's meaningless to pass a version
explicitly to the metadata store.
Regarding step 3 and 4, they are simply wrapping the `MetadataCache`'s
methods. They are actually never related to something like "lock" though
they're named `listLocks` and `readLock`.
### Modifications
- Add a `put` method to `MetadataCache`, which just calls
`MetadataStore#put` with `Optional.empty()` underlying.
- Replace `LockManager` with `MetadataCache` in `BrokerRegistryImpl`.
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc` <!-- Your PR contains doc changes. -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update
later -->
- [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->
### Matching PR in forked repository
PR in forked repository: <!-- ENTER URL HERE -->
<!--
After opening this PR, the build in apache/pulsar will fail and instructions
will
be provided for opening a PR in the PR author's forked repository.
apache/pulsar pull requests should be first tested in your own fork since
the
apache/pulsar CI based on GitHub Actions has constrained resources and quota.
GitHub Actions provides separate quota for pull requests that are executed
in
a forked repository.
The tests will be run in the forked repository until all PR review comments
have
been handled, the tests pass and the PR is approved by a reviewer.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]