summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mem3.erl18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/mem3.erl b/src/mem3.erl
index 29140471..55a8a541 100644
--- a/src/mem3.erl
+++ b/src/mem3.erl
@@ -77,14 +77,20 @@ state() ->
gen_server:call(?SERVER, state).
--spec states() -> {ok, [mem_state()]}.
+%% @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 states() -> [{mem_state() | bad_nodes | non_member_nodes, [node()]}].
states() ->
{ok, Nodes} = mem3:nodes(),
- case rpc:multicall(Nodes, ?MODULE, state, []) of
- {States, []} -> {ok, lists:map(fun({ok,S}) -> S end, States)};
- {Good, Bad} -> {error, {[{good,Good},{bad,Bad}]}}
- end.
-
+ AllNodes = [node()|erlang:nodes()],
+ {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].
-spec start_gossip() -> ok.
start_gossip() ->