views:

73

answers:

1

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.

+2  A: 

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).
[]
Yasir Arsanukaev
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
@mwt: [`nodes/1`](http://www.erlang.org/doc/man/erlang.html#nodes-1) has other arguments you can choose from: `visible`, `hidden`, `connected`, `this`, `known`. And the purpose of [`ping/1`](http://www.erlang.org/doc/man/net_adm.html#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.
Yasir Arsanukaev
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
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