iilyak closed pull request #1590: Implement convinience `mem3:ping/2` function
URL: https://github.com/apache/couchdb/pull/1590
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/mem3/src/mem3.erl b/src/mem3/src/mem3.erl
index 7033faf4bf..de633006a4 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").


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to