zhaizhibo commented on code in PR #24639:
URL: https://github.com/apache/pulsar/pull/24639#discussion_r2284350240
##########
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:
The original logic's `operationTimeoutMs` were named with `_Ms` suffix but
used with `TimeUnit.SECONDS`, so I updated them to use `TimeUnit.MILLISECONDS`,
please review.
--
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]