@@ -378,7 +378,7 @@ private Cluster waitForInitialHealthyCluster() {
378
378
379
379
log .info ("Selecting initial cluster from {} configured clusters" , sortedClusters .size ());
380
380
381
- // Select clusters in weight order
381
+ // Select cluster in weight order
382
382
for (Map .Entry <Endpoint , Cluster > entry : sortedClusters ) {
383
383
Endpoint endpoint = entry .getKey ();
384
384
Cluster cluster = entry .getValue ();
@@ -519,6 +519,21 @@ public void setActiveCluster(Endpoint endpoint) {
519
519
setActiveCluster (cluster , true );
520
520
}
521
521
522
+ public void forceActiveCluster (Endpoint endpoint , long forcedActiveDuration ) {
523
+ Cluster cluster = multiClusterMap .get (endpoint );
524
+ cluster .clearGracePeriod ();
525
+ if (!cluster .isHealthy ()) {
526
+ throw new JedisValidationException ("Provided endpoint: " + endpoint
527
+ + " is not healthy. Please consider a healthy endpoint from the configuration" );
528
+ }
529
+ multiClusterMap .entrySet ().stream ().forEach (entry -> {
530
+ if (entry .getKey () != endpoint ) {
531
+ entry .getValue ().setGracePeriod (forcedActiveDuration );
532
+ }
533
+ });
534
+ setActiveCluster (endpoint );
535
+ }
536
+
522
537
private boolean setActiveCluster (Cluster cluster , boolean validateConnection ) {
523
538
// Cluster cluster = clusterEntry.getValue();
524
539
// Field-level synchronization is used to avoid the edge case in which
@@ -710,7 +725,17 @@ public boolean isInGracePeriod() {
710
725
* Sets the grace period for this cluster
711
726
*/
712
727
public void setGracePeriod () {
713
- gracePeriodEndsAt = System .currentTimeMillis () + multiClusterClientConfig .getGracePeriod ();
728
+ setGracePeriod (multiClusterClientConfig .getGracePeriod ());
729
+ }
730
+
731
+ public void setGracePeriod (long gracePeriod ) {
732
+ long endTime = System .currentTimeMillis () + gracePeriod ;
733
+ if (endTime < gracePeriodEndsAt ) return ;
734
+ gracePeriodEndsAt = endTime ;
735
+ }
736
+
737
+ public void clearGracePeriod () {
738
+ gracePeriodEndsAt = 0 ;
714
739
}
715
740
716
741
/**
0 commit comments