Class FailoverManager
Two responsibilities that belong together because they share the same question - "is there somewhere else to go?" - and must agree:
- per-operation recovery:
onFailure(ClusterRegistry.Cluster, OperationKind, Throwable, int)turns a failure plus the configuredMultiClusterGigaSpace.FailoverPolicyinto anFailoverManager.Actionthe caller carries out; - topology promotion: when a cluster turns unhealthy, the roles it holds move on - the active (write) role by priority order, and a pinned read-active role, independently, to the next cluster that is not taking the writes.
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceWhat the caller should do about a failed operation.static interfaceTold when a cluster fails, so the proxy can update its membership lists and fire the corresponding events.static interfaceNotified when the active cluster changes, so the proxy can inform its own listeners.static interfaceNotified when the cluster servingREAD_ACTIVEreads changes - because a pinned read cluster failed over, or because reads were following the active cluster and it moved. -
Constructor Summary
ConstructorsConstructorDescriptionFailoverManager(ClusterRegistry registry, Supplier<MultiClusterConfig> config, HealthMonitor health) FailoverManager(ClusterRegistry registry, Supplier<MultiClusterConfig> config, HealthMonitor health, RetryPolicy retryPolicy) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoidPromotes the next healthy cluster in priority order, as the control API'sfailoverToNextCluster().moveReadRoleAwayFromUnreachable(String deadCluster, Throwable cause) Moves a pinned read role off a cluster that cannot be reached, and reports whereREAD_ACTIVEreads go now.nextAvailableCluster(String excluding) The next cluster in priority order that may take traffic, skipping one - normally the cluster that just failed.onFailure(ClusterRegistry.Cluster cluster, OperationKind kind, Throwable cause, int attempt) Decides how to recover from a failed operation.promoteAwayFromUnreachable(String deadCluster, Throwable cause) Moves the active role off a cluster that cannot be reached, and reports where it went.voidsetMembershipListener(FailoverManager.MembershipListener membershipListener) Wires the membership hook.
-
Constructor Details
-
FailoverManager
public FailoverManager(ClusterRegistry registry, Supplier<MultiClusterConfig> config, HealthMonitor health) -
FailoverManager
public FailoverManager(ClusterRegistry registry, Supplier<MultiClusterConfig> config, HealthMonitor health, RetryPolicy retryPolicy)
-
-
Method Details
-
setMembershipListener
Wires the membership hook. Called once, when the proxy assembles its parts. -
addPromotionListener
-
addReadRoleListener
-
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 tokind- what the operation was doing, since a read has more options than a mutationcause- the failureattempt- 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_ACTIVEread 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
deadClusteris 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 whereREAD_ACTIVEreads go now. The read-role counterpart ofpromoteAwayFromUnreachable(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_ACTIVEreads, or empty if the read role could not move anddeadClusterstill holds it
-
nextAvailableCluster
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'sfailoverToNextCluster(). 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
-