Skip to content

Commit

Permalink
[fix] FIx ArrayIndexOutOfBoundsException when using SameAuthParamsLoo…
Browse files Browse the repository at this point in the history
…kupAutoClusterFailover
  • Loading branch information
poorbarcode committed Sep 23, 2024
1 parent 9012422 commit 8057c39
Showing 1 changed file with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,36 @@ public void initialize(PulsarClient client) {
this.executor = EventLoopUtil.newEventLoopGroup(1, false,
new ExecutorProvider.ExtendedThreadFactory("broker-service-url-check"));
scheduledCheckTask = executor.scheduleAtFixedRate(() -> {
if (closed) {
return;
}
checkPulsarServices();
int firstHealthyPulsarService = firstHealthyPulsarService();
if (firstHealthyPulsarService == currentPulsarServiceIndex) {
return;
}
if (firstHealthyPulsarService < 0) {
int failoverTo = findFailoverTo();
if (failoverTo < 0) {
// No healthy pulsar service to connect.
log.error("Failed to choose a pulsar service to connect, no one pulsar service is healthy. Current"
+ " pulsar service: [{}] {}. States: {}, Counters: {}", currentPulsarServiceIndex,
pulsarServiceUrlArray[currentPulsarServiceIndex], Arrays.toString(pulsarServiceStateArray),
Arrays.toString(checkCounterArray));
try {
if (closed) {
return;
}
checkPulsarServices();
int firstHealthyPulsarService = firstHealthyPulsarService();
if (firstHealthyPulsarService == currentPulsarServiceIndex) {
return;
}
if (firstHealthyPulsarService < 0) {
int failoverTo = findFailoverTo();
if (failoverTo < 0) {
// No healthy pulsar service to connect.
log.error(
"Failed to choose a pulsar service to connect, no one pulsar service is healthy."
+ " Current pulsar service: [{}] {}. States: {}, Counters: {}",
currentPulsarServiceIndex,
pulsarServiceUrlArray[currentPulsarServiceIndex],
Arrays.toString(pulsarServiceStateArray),
Arrays.toString(checkCounterArray));
} else {
// Failover to low priority pulsar service.
updateServiceUrl(failoverTo);
}
} else {
// Failover to low priority pulsar service.
updateServiceUrl(failoverTo);
// Back to high priority pulsar service.
updateServiceUrl(firstHealthyPulsarService);
}
} else {
// Back to high priority pulsar service.
updateServiceUrl(firstHealthyPulsarService);
} catch (Exception ex) {
log.error("Failed to re-check cluster status", ex);
}
}, checkHealthyIntervalMs, checkHealthyIntervalMs, TimeUnit.MILLISECONDS);
}
Expand Down Expand Up @@ -123,7 +130,7 @@ private int firstHealthyPulsarService() {
}

private int findFailoverTo() {
for (int i = currentPulsarServiceIndex + 1; i <= pulsarServiceUrlArray.length; i++) {
for (int i = currentPulsarServiceIndex + 1; i < pulsarServiceUrlArray.length; i++) {
if (probeAvailable(i)) {
return i;
}
Expand Down

0 comments on commit 8057c39

Please sign in to comment.