diff options
author | iilyak <iilyak@ca.ibm.com> | 2018-08-30 05:10:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-30 05:10:43 -0700 |
commit | cf7e92deab53e2cfbf5912816e646fb7e7d1067c (patch) | |
tree | 81f9b21be7a177cb0e556c19e0b8e305dfe42284 | |
parent | 50be214f0c8d7d0d7e632eac59caed9604c0b703 (diff) | |
parent | dff0b9703b211e80b3c1fd93b9a5688dbdf6685d (diff) | |
download | couchdb-cf7e92deab53e2cfbf5912816e646fb7e7d1067c.tar.gz |
Merge pull request #1590 from cloudant/add-mem3-ping
Implement convinience `mem3:ping/2` function
-rw-r--r-- | src/mem3/src/mem3.erl | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mem3/src/mem3.erl b/src/mem3/src/mem3.erl index 7033faf4b..de633006a 100644 --- a/src/mem3/src/mem3.erl +++ b/src/mem3/src/mem3.erl @@ -21,6 +21,7 @@ -export([live_shards/2]). -export([belongs/2, owner/3]). -export([get_placement/1]). +-export([ping/1, ping/2]). %% For mem3 use only. -export([name/1, node/1, range/1, engine/1]). @@ -28,6 +29,8 @@ -include_lib("mem3/include/mem3.hrl"). -include_lib("couch/include/couch_db.hrl"). +-define(PING_TIMEOUT_IN_MS, 60000). + start() -> application:start(mem3). @@ -331,6 +334,27 @@ engine(Opts) when is_list(Opts) -> [] end. +%% Check whether a node is up or down +%% side effect: set up a connection to Node if there not yet is one. + +-spec ping(Node :: atom()) -> pong | pang. + +ping(Node) -> + ping(Node, ?PING_TIMEOUT_IN_MS). + +-spec ping(Node :: atom(), Timeout :: pos_integer()) -> pong | pang. + +ping(Node, Timeout) when is_atom(Node) -> + %% The implementation of the function is copied from + %% lib/kernel/src/net_adm.erl with addition of a Timeout + case catch gen:call({net_kernel, Node}, + '$gen_call', {is_auth, node()}, Timeout) of + {ok, yes} -> pong; + _ -> + erlang:disconnect_node(Node), + pang + end. + -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). |