View Source Cluster Task
Precondition
Fully Connected Cluster
Because it depends on
global's name registration service. The name server must maintains a fully connected network.For example, if node N1 connects to node N2 (which is already connected to N3), the global name servers on the nodes N1 and N3 ensure that also N1 and N3 are connected. In other words, command-line flag
-connect_all falsecan not be used.Same Global Configuration
All node's
global_quorum_sizeandglobal_jobsmust keep the same value. This ensures that the global task manager can transfer between nodes when the network splits.
Configuration
global_jobsthe same format as
local_jobs, default is[]. This means only run local jobs without running global task manager and monitor processes.global_quorum_sizeecron application live on at least
global_quorum_sizenodes in the same cluster, can be regarded as a healthy cluster.Global task manager only running on a healthy cluster.
If you want to guarantee always no more than one global task manager even when the cluster has network split, you should set it to "half plus one". For example:
Run on majority:
ABC3 nodes in one cluster.global_quorum_size=2.- (
ABC) cluster split into 2 part(AB=|=C). - the global task manager would run on
ABcluster(ABis the healthy cluster now). Cnode only running local jobs without global jobs.
Run on majority
ABC3 nodes in one cluster.global_quorum_size=2.- (
ABC) cluster split into 3 part(A=|=B=|=C). - every node only running local jobs without global jobs(all nodes is unhealthy).
Run on every node if brain split.
ABCnodes in one cluster.global_quorum_size=1.- (
ABC) cluster split into 3 part(A=|=B=|=C). - the global task manager would run on every nodes(we have three healthy cluster now).
- But the global task manager only running one in the same cluster.
Implementation
- The top supervisor
ecron_supstart at first. - Nothing will happen if the
global_jobsis empty. ecron_supwould start_linkecron_monitorworker (gen_server) ifglobal_jobsis not empty.ecron_monitorsubscribes node's up/down messages by net_kernel:monitor_nodes(true), when it initializes.- Enter
ecron_monitormain loop:- Checking if there is enough
ecronprocess in the cluster(global_quorum_size). - Trying to terminate global_job manager process when cluster's
ecronnumber less thanglobal_quorum_size. - Otherwise, trying to start a global_job manager process, This gen_server register by global:register_name/2.
- All the nodes are rushing to register this global jobs manager process, only one node will success, other node's
ecron_monitorwould link this process if the process already exists. - The
ecron_monitorshould receive notification, when node down/up or the global_job manager has terminated. - Goto step 5 again, When notified.
- Checking if there is enough
NodeA NodeB NodeC
supervisor supervisor supervisor
| | | |
monitor monitor | monitor
\ | | /
\ [link] | /
\ | | /
[link]-----GlobalJob-----[link]NodeB has won the race and spawn global manager process, other node's ecron_monitor only link to this manager.