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
|
-module(mem3).
-author('Brad Anderson <brad@cloudant.com>').
-export([start/0, stop/0, restart/0, state/0]).
-include("mem3.hrl").
-define(SERVER, mem3_server).
start() ->
application:start(mem3).
stop() ->
application:stop(mem3).
restart() ->
stop(),
start().
%% @doc Detailed report of cluster-wide membership state. Queries the state
%% on all member nodes and builds a dictionary with unique states as the
%% key and the nodes holding that state as the value. Also reports member
%% nodes which fail to respond and nodes which are connected but are not
%% cluster members. Useful for debugging.
-spec state() -> [{mem_state() | bad_nodes | non_member_nodes, [node()]}].
state() ->
{ok, Nodes} = mem3:nodes(),
AllNodes = erlang:nodes([this, visible]),
{Replies, BadNodes} = gen_server:multi_call(Nodes, ?SERVER, state),
Dict = lists:foldl(fun({Node, {ok,State}}, D) ->
orddict:append(State, Node, D)
end, orddict:new(), Replies),
[{non_member_nodes, AllNodes -- Nodes}, {bad_nodes, BadNodes} | Dict].
|