15
15
import java .util .Map ;
16
16
import java .util .concurrent .ConcurrentHashMap ;
17
17
import java .util .concurrent .ConcurrentLinkedQueue ;
18
+ import java .util .concurrent .atomic .AtomicInteger ;
18
19
import java .util .stream .Collectors ;
19
20
import java .util .concurrent .locks .Lock ;
20
21
import java .util .concurrent .locks .ReentrantLock ;
@@ -97,8 +98,9 @@ public class MultiClusterPooledConnectionProvider implements ConnectionProvider
97
98
private final ConcurrentLinkedQueue <HealthStatusChangeEvent > pendingHealthStatusChanges = new ConcurrentLinkedQueue <>();
98
99
99
100
// Failback mechanism fields
101
+ private static final AtomicInteger failbackThreadCounter = new AtomicInteger (1 );
100
102
private final ScheduledExecutorService failbackScheduler = Executors .newSingleThreadScheduledExecutor (r -> {
101
- Thread t = new Thread (r , "failback-scheduler" );
103
+ Thread t = new Thread (r , "jedis- failback-" + failbackThreadCounter . getAndIncrement () );
102
104
t .setDaemon (true );
103
105
return t ;
104
106
});
@@ -333,7 +335,11 @@ private void processPendingHealthStatusChanges() {
333
335
synchronized (pendingHealthStatusChanges ) {
334
336
// Process all queued events
335
337
while ((event = pendingHealthStatusChanges .poll ()) != null ) {
336
- processStatusChangeEvent (event );
338
+ Endpoint endpoint = event .getEndpoint ();
339
+ boolean latestInTheQueue = !pendingHealthStatusChanges .stream ().anyMatch (e -> e .getEndpoint ().equals (endpoint ));
340
+ if (latestInTheQueue ) {
341
+ processStatusChangeEvent (event );
342
+ }
337
343
}
338
344
}
339
345
}
@@ -345,7 +351,7 @@ private void processPendingHealthStatusChanges() {
345
351
private void processStatusChangeEvent (HealthStatusChangeEvent eventArgs ) {
346
352
Endpoint endpoint = eventArgs .getEndpoint ();
347
353
HealthStatus newStatus = eventArgs .getNewStatus ();
348
- log .info ("Health status changed for {} from {} to {}" , endpoint , eventArgs .getOldStatus (), newStatus );
354
+ log .debug ("Health status changed for {} from {} to {}" , endpoint , eventArgs .getOldStatus (), newStatus );
349
355
350
356
Cluster clusterWithHealthChange = multiClusterMap .get (endpoint );
351
357
@@ -394,7 +400,7 @@ private Cluster waitForInitialHealthyCluster() {
394
400
status = statusTracker .waitForHealthStatus (endpoint );
395
401
} else {
396
402
// No health check configured - assume healthy
397
- log .info ("No health check configured for cluster {}, deafulting to HEALTHY" , endpoint );
403
+ log .info ("No health check configured for cluster {}, defaulting to HEALTHY" , endpoint );
398
404
status = HealthStatus .HEALTHY ;
399
405
}
400
406
0 commit comments