4

I want to simulate the behavior of erl -sname example -hidden but dynamically. How can I drop a node out of visibility in a cluster?

See the comments by @mwt at @Yasir Arsanukaev for additional clarification of what I'm trying to do.

1 Answer 1

5

Try erlang:disconnect_node/1:

(bar@dt)1> nodes().
[]
(bar@dt)2> net_adm:ping('foo@dt').          
pong
(bar@dt)3> nodes().               
[foo@dt]
(bar@dt)4> erlang:disconnect_node('foo@dt').
true
(bar@dt)5> nodes().                         
[]

Or if you want a node to remove itself from other nodes' nodes():

(bar@dt)1> nodes().
[foo@dt]
(bar@dt)2> rpc:eval_everywhere(erlang, disconnect_node, [node()]).
abcast
(bar@dt)3> nodes().
[]

If the node was started with key -hidden:

(bar@dt)1> nodes(hidden).
[foo@dt]
(bar@dt)2> rpc:eval_everywhere(nodes(hidden), erlang, disconnect_node, [node()]).
abcast
(bar@dt)3> nodes(hidden).
[]
5
  • Unfortunately, this doesn't go as far as I was hoping. When you start a node as hidden and then ping it, it won't show up in nodes(). Using the method above, if you ping again after disconnecting, the nodes shows up in nodes() again.
    – mwt
    May 22, 2010 at 5:15
  • @mwt: nodes/1 has other arguments you can choose from: visible, hidden, connected, this, known. And the purpose of ping/1 is to try to "..set up a connection to Node. Returns pang if it fails, or pong if it is successful." I think you may implement the desired behaviour using these primitives. May 22, 2010 at 6:09
  • Perhaps, but I don't quite see how yet. Right now, I have a cluster. Whenever a new node joins, it tries to connect to every node in the cluster by pinging them. If one of those nodes were -hidden, the ping would not connect the new node to the hidden node, which is what I want. However, merely disconnecting the node I want to make hidden allows it be connected by direct pinging, whereupon it shows up in nodes() again. Now, if there's a way to change the state of a node whereby calling nodes() with any argument still excludes it, even after direct pinging, I'd like to know what that way is.
    – mwt
    May 22, 2010 at 6:40
  • Above, when I said "calling nodes() with any argument" I meant "calling nodes() with some argument". For example, if there's a way to cause a node to NOT show up in nodes(visible), and it still won't show up even if the nodes net_adm:ping() one another, then that's perfect, cos that's similar to -hidden behavior.
    – mwt
    May 22, 2010 at 6:49
  • Finally marked this accepted after 13 years. :) What I wanted is impossible, but also easy enough to work around in other ways. Dec 28, 2023 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.