lhotari commented on code in PR #24639:
URL: https://github.com/apache/pulsar/pull/24639#discussion_r2284152978
##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/MetadataStoreCacheLoader.java:
##########
@@ -61,26 +65,23 @@ public MetadataStoreCacheLoader(PulsarResources
pulsarResources, int operationTi
* @throws Exception
*/
public void init() throws Exception {
- loadReportResources.getStore().registerListener((n) -> {
- if (LOADBALANCE_BROKERS_ROOT.equals(n.getPath()) &&
NotificationType.ChildrenChanged.equals(n.getType())) {
-
loadReportResources.getChildrenAsync(LOADBALANCE_BROKERS_ROOT).thenApplyAsync((brokerNodes)->{
- updateBrokerList(brokerNodes).thenRun(() -> {
- log.info("Successfully updated broker info {}",
brokerNodes);
- }).exceptionally(ex -> {
+ Supplier<CompletableFuture<Void>> tryUpdate = () -> {
+ return
loadReportResources.getChildrenAsync(LOADBALANCE_BROKERS_ROOT)
+ .thenComposeAsync(this::updateBrokerList)
+ .exceptionally(ex -> {
log.warn("Error updating broker info after broker list
changed", ex);
return null;
});
- return null;
- }).exceptionally(ex -> {
- log.warn("Error updating broker info after broker list
changed", ex);
- return null;
- });
+ };
+ loadReportResources.getStore().registerListener((n) -> {
+ if (LOADBALANCE_BROKERS_ROOT.equals(n.getPath()) &&
NotificationType.ChildrenChanged.equals(n.getType())) {
+ sequencer.sequential(tryUpdate);
}
});
-
- // Do initial fetch of brokers list
-
updateBrokerList(loadReportResources.getChildren(LOADBALANCE_BROKERS_ROOT)).get(operationTimeoutMs,
- TimeUnit.SECONDS);
+ if (loadReportResources.getStore() instanceof MetadataStoreExtended) {
+ ((MetadataStoreExtended)
loadReportResources.getStore()).registerSessionListener(sessionEvent ->
+ sequencer.sequential(tryUpdate));
+ }
Review Comment:
Preserve the original logic to perform the initial fetch of brokers list
synchronously when `init` is called:
```suggestion
}
// Do initial fetch of brokers list
tryUpdate().get(operationTimeoutMs, TimeUnit.SECONDS);
```
--
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]