1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| -export([ join/1, leave/0, force_leave/1, status/0 ]).
-export([ prepare/1, heal/1, reboot/0 ]).
-spec(join(node()) -> ok | ignore | {error, any()}).
join(Node) when Node =:= node() -> ignore; join(Node) when is_atom(Node) -> case {ekka_mnesia:is_node_in_cluster(Node), ekka_node:is_running(Node, ekka)} of {false, true} -> prepare(join), ok = ekka_mnesia:join_cluster(Node), reboot(); {false, false} -> {error, {node_down, Node}}; {true, _} -> {error, {already_in_cluster, Node}} end.
-spec(leave() -> ok | {error, any()}). leave() -> case ekka_mnesia:running_nodes() -- [node()] of [_|_] -> prepare(leave), ok = ekka_mnesia:leave_cluster(), reboot(); [] -> {error, node_not_in_cluster} end.
-spec(force_leave(node()) -> ok | ignore | {error, term()}).
force_leave(Node) when Node =:= node() -> ignore; force_leave(Node) -> case ekka_mnesia:is_node_in_cluster(Node) andalso rpc:call(Node, ?MODULE, prepare, [leave]) of ok -> case ekka_mnesia:remove_from_cluster(Node) of ok -> rpc:call(Node, ?MODULE, reboot, []); Error -> Error end; false -> {error, node_not_in_cluster}; {badrpc, nodedown} -> ekka_membership:announce({force_leave, Node}), ekka_mnesia:remove_from_cluster(Node); {badrpc, Reason} -> {error, Reason} end.
status() -> ekka_mnesia:cluster_status().
|