summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSverker Eriksson <sverker@erlang.org>2022-02-09 20:43:27 +0100
committerSverker Eriksson <sverker@erlang.org>2022-02-09 20:43:27 +0100
commit6c13313ff9d4ba623745331caadcdc27a8f07ed4 (patch)
treef1044037ee0cceaab40745fb4d6169c73aa59cfe
parentee8a55eddef69f4e7d085feed23edb6f2cda82cf (diff)
parentceec312cf53a1d9d9bbd7fbe1946952211ac9a2c (diff)
downloaderlang-6c13313ff9d4ba623745331caadcdc27a8f07ed4.tar.gz
Merge branch 'maint'
-rw-r--r--erts/doc/src/erl_cmd.xml34
-rw-r--r--lib/kernel/doc/src/net_kernel.xml9
-rw-r--r--lib/kernel/src/net_kernel.erl14
-rw-r--r--system/doc/reference_manual/distributed.xml62
4 files changed, 86 insertions, 33 deletions
diff --git a/erts/doc/src/erl_cmd.xml b/erts/doc/src/erl_cmd.xml
index 316ebea123..3c8fe79dba 100644
--- a/erts/doc/src/erl_cmd.xml
+++ b/erts/doc/src/erl_cmd.xml
@@ -473,29 +473,11 @@ $ <input>erl \
instead.</p>
<p>If <c>Name</c> is set to <em><c>undefined</c></em> the node will
be started in a special mode optimized to be the temporary client
- of another node. When enabled the node will request a
- <seeguide marker="erl_dist_protocol#DFLAG_NAME_ME">dynamic
- node name</seeguide> from the first node it connects to. In addition
- these distribution settings will be set:
+ of another node. The node will then request a dynamic node
+ name from the first node it connects to. Read more in
+ <seeguide marker="system/reference_manual:distributed#dyn_node_name">
+ Dynamic Node Name</seeguide>.
</p>
- <pre><seeapp marker="kernel:kernel_app#dist_listen">-dist_listen false</seeapp> <seecom marker="#hidden">-hidden</seecom> <seeapp marker="kernel:kernel_app#dist_auto_connect">-dist_auto_connect never</seeapp></pre>
- <p>Because <c>-dist_auto_connect</c> is set to <c>never</c>, the system will have
- to manually call <seemfa marker="kernel:net_kernel#connect_node/1">
- <c>net_kernel:connect_node/1</c></seemfa> in order to start the distribution.
- If the distribution channel is closed, when a node uses a dynamic
- node name, the node will stop the distribution and a new call to
- <seemfa marker="kernel:net_kernel#connect_node/1">
- <c>net_kernel:connect_node/1</c></seemfa> has to be made. Note that the node
- name may change if the distribution is dropped and then set up again.
- </p>
- <note>
- <p>
- The <em>dynamic node name</em> feature is supported from
- OTP 23. Both the temporary client node and the first
- connected peer node (supplying the dynamic node name) must
- be at least OTP 23 for it to work.
- </p>
- </note>
<warning>
<p>
Starting a distributed node without also specifying
@@ -665,6 +647,14 @@ $ <input>erl \
exist between nodes running with flag <c><![CDATA[-sname]]></c>
and those running with flag <c><![CDATA[-name]]></c>, as node
names must be unique in distributed Erlang systems.</p>
+ <p>
+ If <c>Name</c> is set to <em><c>undefined</c></em> the node will
+ be started in a special mode optimized to be the temporary client
+ of another node. The node will then request a dynamic node
+ name from the first node it connects to. Read more in
+ <seeguide marker="system/reference_manual:distributed#dyn_node_name">
+ Dynamic Node Name</seeguide>.
+ </p>
<warning>
<p>
Starting a distributed node without also specifying
diff --git a/lib/kernel/doc/src/net_kernel.xml b/lib/kernel/doc/src/net_kernel.xml
index 5d3eceb4e0..b51217fadc 100644
--- a/lib/kernel/doc/src/net_kernel.xml
+++ b/lib/kernel/doc/src/net_kernel.xml
@@ -359,7 +359,14 @@ $ <input>erl -sname foobar</input></pre>
starting <c>net_kernel</c> and other necessary processes.</p>
<p>Notice that the argument is a list with exactly one, two, or
three arguments. <c>NameType</c> defaults to <c>longnames</c>
- and <c>Ticktime</c> to <c>15000</c>.</p>
+ and <c>Ticktime</c> to <c>15000</c>.
+ </p>
+ <p>
+ If <c>Name</c> is set to <em><c>undefined</c></em> the distribution
+ will be started to request a dynamic node name from the first node it
+ connects to. See <seeguide marker="system/reference_manual:distributed#dyn_node_name">
+ Dynamic Node Name</seeguide>.
+ </p>
</desc>
</func>
diff --git a/lib/kernel/src/net_kernel.erl b/lib/kernel/src/net_kernel.erl
index 0628e35bcd..cc1856b771 100644
--- a/lib/kernel/src/net_kernel.erl
+++ b/lib/kernel/src/net_kernel.erl
@@ -193,10 +193,6 @@ nodename() -> request(nodename).
-spec stop() -> ok | {error, Reason} when
Reason :: not_allowed | not_found.
stop() ->
- case persistent_term:get(net_kernel, undefined) of
- undefined -> ok;
- _ -> persistent_term:erase(net_kernel)
- end,
erl_distribution:stop().
-type node_info() ::
@@ -729,6 +725,16 @@ code_change(_OldVsn, State, _Extra) ->
%% ------------------------------------------------------------
terminate(Reason, State) ->
+ case State of
+ #state{supervisor = {restart, _}} ->
+ ok;
+ _ ->
+ case persistent_term:get(net_kernel, undefined) of
+ undefined -> ok;
+ _ -> persistent_term:erase(net_kernel)
+ end
+ end,
+
case Reason of
no_network ->
ok;
diff --git a/system/doc/reference_manual/distributed.xml b/system/doc/reference_manual/distributed.xml
index df0c64f9ec..8361900499 100644
--- a/system/doc/reference_manual/distributed.xml
+++ b/system/doc/reference_manual/distributed.xml
@@ -59,14 +59,18 @@
<section>
<title>Nodes</title>
- <p>A <em>node</em> is an executing Erlang runtime system that has
- been given a name, using the command-line flag <c>-name</c>
- (long names) or <c>-sname</c> (short names).</p>
+ <p>
+ A <em>node</em> is an executing Erlang runtime system that has
+ been given a name, using the command-line flag
+ <seecom marker="erts:erl#name"><c>-name</c></seecom> (long names) or
+ <seecom marker="erts:erl#sname"><c>-sname</c></seecom> (short names).
+ </p>
<p>The format of the node name is an atom <c>name@host</c>.
<c>name</c> is the name given by the user. <c>host</c> is
the full host name if long names are used, or the first part of
- the host name if short names are used. <c>node()</c> returns
- the name of the node.</p>
+ the host name if short names are used. Function
+ <seemfa marker="erts:erlang#node/0"><c>node()</c></seemfa>
+ returns the name of the node.</p>
<p><em>Example:</em></p>
<pre>
% <input>erl -name dilbert</input>
@@ -76,6 +80,21 @@
% <input>erl -sname dilbert</input>
(dilbert@uab)1> <input>node().</input>
dilbert@uab</pre>
+
+ <p>
+ The node name can also be given in runtime by calling
+ <seemfa marker="kernel:net_kernel#start/1"><c>net_kernel:start/1</c></seemfa>.
+ </p>
+ <p><em>Example:</em></p>
+ <pre>
+% <input>erl</input>
+1> <input>node().</input>
+nonode@nohost
+2> <input>net_kernel:start([dilbert,shortnames]).</input>
+{ok,&lt;0.102.0&gt;}
+(dilbert@uab)3> <input>node().</input>
+dilbert@uab</pre>
+
<note>
<p>A node with a long node name cannot communicate with a node
with a short node name.</p>
@@ -124,7 +143,38 @@ dilbert@uab</pre>
<c>nodes(connected)</c> must be used. This means, for example,
that the hidden node is not added to the set of nodes that
<c>global</c> is keeping track of.</p>
- <p>This feature was added in Erlang 5.0/OTP R7.</p>
+ </section>
+
+ <section>
+ <marker id="dyn_node_name"/>
+ <title>Dynamic Node Name</title>
+ <p>
+ If the node name is set to <em><c>undefined</c></em> the node will
+ be started in a special mode to be the temporary client
+ of another node. The node will then request a dynamic node
+ name from the first node it connects to. In addition these
+ distribution settings will be set:
+ </p>
+ <pre><seeapp marker="kernel:kernel_app#dist_listen">-dist_listen false</seeapp> <seecom marker="erts:erl#hidden">-hidden</seecom> <seeapp marker="kernel:kernel_app#dist_auto_connect">-dist_auto_connect never</seeapp></pre>
+ <p>
+ As <c>-dist_auto_connect</c> is set to <c>never</c>,
+ <seemfa marker="kernel:net_kernel#connect_node/1"><c>net_kernel:connect_node/1</c></seemfa>
+ must be called in order to setup connections. If the first established
+ connection is closed (which gave the node its dynamic name), then any
+ other connections will also be closed and the node will lose its dynamic
+ node name. A new call to
+ <seemfa marker="kernel:net_kernel#connect_node/1"><c>net_kernel:connect_node/1</c></seemfa>
+ can be made to get a new dynamic node name. The node name may
+ change if the distribution is dropped and then set up again.
+ </p>
+ <note>
+ <p>
+ The <em>dynamic node name</em> feature is supported from OTP 23.
+ Both the temporary client node and the first connected peer node
+ (supplying the dynamic node name) must be at least OTP 23 for it to
+ work.
+ </p>
+ </note>
</section>
<section>