From cd25fee1bfd046afe92c83df243ac69dfca2bffe Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Thu, 10 Jun 2010 09:22:01 -0400 Subject: more detailed report for mem3:states() --- src/mem3.erl | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src') 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() -> -- cgit v1.2.3