Top Description Fields Constructors Methods
io.vertx.core.impl

public Class HAManager

extends Object
Class Inheritance
Imports
io.vertx.core.*, io.vertx.core.impl.logging.Logger, .LoggerFactory, io.vertx.core.json.JsonArray, .JsonObject, io.vertx.core.spi.cluster.ClusterManager, .NodeListener, java.util.*, java.util.concurrent.ConcurrentLinkedQueue, .CountDownLatch, .TimeUnit, java.util.concurrent.atomic.AtomicReference, java.util.function.Consumer

Handles HA We compute failover and whether there is a quorum synchronously as we receive nodeAdded and nodeRemoved events from the cluster manager. It's vital that this is done synchronously as the cluster manager only guarantees that the set of nodes retrieved from getNodes() is the same for each node in the cluster when processing the exact same nodeAdded/nodeRemoved event. As HA modules are deployed, if a quorum has been attained they are deployed immediately, otherwise the deployment information is added to a list. Periodically we check the value of attainedQuorum and if true we deploy any HA deploymentIDs waiting for a quorum. If false, we check if there are any HA deploymentIDs current deployed, and if so undeploy them, and add them to the list of deploymentIDs waiting for a quorum. By doing this check periodically we can avoid race conditions resulting in modules being deployed after a quorum has been lost, and without having to resort to exclusive locking which is actually quite tricky here, and prone to deadlock· We maintain a clustered map where the key is the node id and the value is some stringified JSON which describes the group of the cluster and an array of the HA modules deployed on that node. There is an entry in the map for each node of the cluster. When a node joins the cluster or an HA module is deployed or undeployed that entry is updated. When a node leaves the cluster cleanly, it removes it's own entry before leaving. When the cluster manager sends us an event to say a node has left the cluster we check if its entry in the cluster map is there, and if so we infer a clean close has happened and no failover will occur. If the map entry is there it implies the node died suddenly. In that case each node of the cluster must compute whether it is the failover node for the failed node. First each node of the cluster determines whether it is in the same group as the failed node, if not then it will not be a candidate for the failover node. Nodes in the cluster only failover to other nodes in the same group. If the node is in the same group then the node takes the UUID of the failed node, computes the hash-code and chooses a node from the list of nodes in the cluster by taking the hash-code modulo the number of nodes as an index to the list of nodes. The cluster manager guarantees each node in the cluster sees the same set of nodes for each membership event that is processed. Therefore it is guaranteed that each node in the cluster will compute the same value. It is critical that any cluster manager implementation provides this guarantee! Once the value has been computed, it is compared to the current node, and if it is the same the current node assumes failover for the failed node. During failover the failover node deploys all the HA modules from the failed node, as described in the JSON with the same values of config and instances. Once failover is complete the failover node removes the cluster map entry for the failed node. If the failover node itself fails while it is processing failover for another node, then this is also checked by other nodes when they detect the failure of the second node.
Author
Tim Fox

Field Summary

Modifier and TypeField and Description
private volatile boolean
private long
private final ClusterManager
private final Map<String, String>
private final DeploymentManager
private volatile boolean
private volatile FailoverCompleteHandler
private final String
private final JsonObject
haInfo

References Deprecated JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.
private volatile boolean
private static final Logger
private final String
private static final long
private final int
private long
private volatile boolean
private final Queue<Runnable>
private final VerticleManager
private final VertxInternal

Constructor Summary

AccessConstructor and Description
public
HAManager(VertxInternal vertx, DeploymentManager deploymentManager, VerticleManager verticleFactoryManager, ClusterManager clusterManager, Map<String, String> clusterMap, int quorumSize, String group)

Method Summary

Modifier and TypeMethod and Description
public void
addDataToAHAInfo(String key, JsonObject value)
References Deprecated JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.

private void
private void
addToHA(String deploymentID, String verticleName, DeploymentOptions deploymentOptions)

private void
addToHADeployList(final String verticleName, final DeploymentOptions deploymentOptions, final Handler<AsyncResult<String>> doneHandler)

private void
checkFailover(String failedNodeID, JsonObject theHAInfo)
References Deprecated JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.

private void
private void
private synchronized void
checkQuorumWhenAdded(final String nodeID, final long start)

private String
chooseHashedNode(String group, int hashCode)

private void
public void
deployVerticle(final String verticleName, DeploymentOptions deploymentOptions, final Handler<AsyncResult<String>> doneHandler)

private void
doDeployVerticle(final String verticleName, DeploymentOptions deploymentOptions, final Handler<AsyncResult<String>> doneHandler)

public void
failDuringFailover(boolean fail)

pack-priv void
init()

Initialize the ha manager, i.e register the node listener to propagates the node events and start the quorum timer.

public boolean
private synchronized void
nodeAdded(final String nodeID)

private synchronized void
nodeLeft(String leftNodeID)

private void
processFailover(JsonObject failedVerticle)
References Deprecated JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.

public void
private void
public void
public void
public void
stop()

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attainedQuorumback to summary
private volatile boolean attainedQuorum
checkQuorumTimerIDback to summary
private long checkQuorumTimerID
clusterManagerback to summary
private final ClusterManager clusterManager
clusterMapback to summary
private final Map<String, String> clusterMap
deploymentManagerback to summary
private final DeploymentManager deploymentManager
failDuringFailoverback to summary
private volatile boolean failDuringFailover
failoverCompleteHandlerback to summary
private volatile FailoverCompleteHandler failoverCompleteHandler
groupback to summary
private final String group
haInfoback to summary
private final JsonObject haInfo

References Deprecated

JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

killedback to summary
private volatile boolean killed
logback to summary
private static final Logger log
nodeIDback to summary
private final String nodeID
QUORUM_CHECK_PERIODback to summary
private static final long QUORUM_CHECK_PERIOD
quorumSizeback to summary
private final int quorumSize
quorumTimerIDback to summary
private long quorumTimerID
stoppedback to summary
private volatile boolean stopped
toDeployOnQuorumback to summary
private final Queue<Runnable> toDeployOnQuorum
verticleFactoryManagerback to summary
private final VerticleManager verticleFactoryManager
vertxback to summary
private final VertxInternal vertx

Constructor Detail

HAManagerback to summary
public HAManager(VertxInternal vertx, DeploymentManager deploymentManager, VerticleManager verticleFactoryManager, ClusterManager clusterManager, Map<String, String> clusterMap, int quorumSize, String group)

Method Detail

addDataToAHAInfoback to summary
public void addDataToAHAInfo(String key, JsonObject value)

References Deprecated

JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

addHaInfoIfLostback to summary
private void addHaInfoIfLost()
addToHAback to summary
private void addToHA(String deploymentID, String verticleName, DeploymentOptions deploymentOptions)
addToHADeployListback to summary
private void addToHADeployList(final String verticleName, final DeploymentOptions deploymentOptions, final Handler<AsyncResult<String>> doneHandler)
checkFailoverback to summary
private void checkFailover(String failedNodeID, JsonObject theHAInfo)

References Deprecated

JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

checkHADeploymentsback to summary
private void checkHADeployments()
checkQuorumback to summary
private void checkQuorum()
checkQuorumWhenAddedback to summary
private synchronized void checkQuorumWhenAdded(final String nodeID, final long start)
chooseHashedNodeback to summary
private String chooseHashedNode(String group, int hashCode)
deployHADeploymentsback to summary
private void deployHADeployments()
deployVerticleback to summary
public void deployVerticle(final String verticleName, DeploymentOptions deploymentOptions, final Handler<AsyncResult<String>> doneHandler)
doDeployVerticleback to summary
private void doDeployVerticle(final String verticleName, DeploymentOptions deploymentOptions, final Handler<AsyncResult<String>> doneHandler)
failDuringFailoverback to summary
public void failDuringFailover(boolean fail)
initback to summary
pack-priv void init()

Initialize the ha manager, i.e register the node listener to propagates the node events and start the quorum timer. The quorum will be checked as well.

isKilledback to summary
public boolean isKilled()
nodeAddedback to summary
private synchronized void nodeAdded(final String nodeID)
nodeLeftback to summary
private synchronized void nodeLeft(String leftNodeID)
processFailoverback to summary
private void processFailover(JsonObject failedVerticle)

References Deprecated

JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

removeFromHAback to summary
public void removeFromHA(String depID)
runOnContextAndWaitback to summary
private void runOnContextAndWait(Runnable runnable)
setFailoverCompleteHandlerback to summary
public void setFailoverCompleteHandler(FailoverCompleteHandler failoverCompleteHandler)
simulateKillback to summary
public void simulateKill()
stopback to summary
public void stop()
undeployHADeploymentsback to summary
private void undeployHADeployments()