summaryrefslogtreecommitdiff
path: root/src/mem3.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mem3.erl')
-rw-r--r--src/mem3.erl20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/mem3.erl b/src/mem3.erl
index 2b8f0188..4f7c6ade 100644
--- a/src/mem3.erl
+++ b/src/mem3.erl
@@ -1,8 +1,11 @@
-module(mem3).
-author('Brad Anderson <brad@cloudant.com>').
--export([start/0, stop/0, restart/0]).
+-export([start/0, stop/0, restart/0, state/0]).
+-include("mem3.hrl").
+
+-define(SERVER, mem3_server).
start() ->
application:start(mem3).
@@ -13,3 +16,18 @@ stop() ->
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]. \ No newline at end of file