summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mem3.erl20
-rw-r--r--src/mem3_server.erl18
2 files changed, 20 insertions, 18 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
diff --git a/src/mem3_server.erl b/src/mem3_server.erl
index addcb591..0d76344d 100644
--- a/src/mem3_server.erl
+++ b/src/mem3_server.erl
@@ -20,7 +20,7 @@
%% API
-export([start_link/0, start_link/1, stop/0, stop/1, reset/0]).
--export([join/3, clock/0, state/0, states/0, nodes/0, fullnodes/0,
+-export([join/3, clock/0, state/0, nodes/0, fullnodes/0,
start_gossip/0]).
%% for testing more than anything else
@@ -76,22 +76,6 @@ clock() ->
state() ->
gen_server:call(?SERVER, 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(),
- 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() ->
gen_server:call(?SERVER, start_gossip).