Class FailoverManager

java.lang.Object
org.openspaces.core.multicluster.internal.health.FailoverManager

public final class FailoverManager extends Object
Decides what to do when an operation fails, and promotes a new active cluster when the current one dies.

Two responsibilities that belong together because they share the same question - "is there somewhere else to go?" - and must agree:

Promotion is single-flight through ClusterRegistry.compareAndSetActive(String, String): when a site dies, every in-flight operation fails at once, and each one asks for failover. Without the compare-and-set they would promote in turn - one per failing request - and the proxy would walk through every cluster it has.

  • Constructor Details

  • Method Details

    • setMembershipListener

      public void setMembershipListener(FailoverManager.MembershipListener membershipListener)
      Wires the membership hook. Called once, when the proxy assembles its parts.
    • addPromotionListener

      public void addPromotionListener(FailoverManager.PromotionListener listener)
    • addReadRoleListener

      public void addReadRoleListener(FailoverManager.ReadRoleListener listener)
    • onFailure

      public FailoverManager.Action onFailure(ClusterRegistry.Cluster cluster, OperationKind kind, Throwable cause, int attempt)
      Decides how to recover from a failed operation.
      Parameters:
      cluster - the cluster the operation was sent to
      kind - what the operation was doing, since a read has more options than a mutation
      cause - the failure
      attempt - how many attempts have already failed, starting at 1
    • promoteAwayFromUnreachable

      public Optional<ClusterRegistry.Cluster> promoteAwayFromUnreachable(String deadCluster, Throwable cause)
      Moves the active role off a cluster that cannot be reached, and reports where it went.

      Called by the read path when a READ_ACTIVE read finds the active cluster unavailable. That read has exactly one cluster it is allowed to use, so an unreachable active cluster is a dead end rather than a balancing problem: promoting here lets the read be served instead of failing until a mutation or an operator notices. Single-flight and idempotent, like every other promotion - a burst of reads arriving on a dead cluster causes one promotion between them.

      Returns:
      the cluster that now holds the active role, or empty if there was nothing to promote and deadCluster is still active
    • moveReadRoleAwayFromUnreachable

      public Optional<ClusterRegistry.Cluster> moveReadRoleAwayFromUnreachable(String deadCluster, Throwable cause)
      Moves a pinned read role off a cluster that cannot be reached, and reports where READ_ACTIVE reads go now. The read-role counterpart of promoteAwayFromUnreachable(String, Throwable), used by the read path when the pinned read cluster is the one that is down: the write role is left where it is.
      Returns:
      the cluster now serving READ_ACTIVE reads, or empty if the read role could not move and deadCluster still holds it
    • nextAvailableCluster

      public Optional<ClusterRegistry.Cluster> nextAvailableCluster(String excluding)
      The next cluster in priority order that may take traffic, skipping one - normally the cluster that just failed. Does not change the topology: the caller decides whether this is a promotion or a one-off detour.
    • failoverToNextCluster

      public void failoverToNextCluster()
      Promotes the next healthy cluster in priority order, as the control API's failoverToNextCluster(). A quiesced cluster is skipped even when its quiesce does not count against health: it is alive, but promoting it would send the traffic somewhere that refuses it.
      Throws:
      NoAvailableClusterException - if nothing healthy is left