Skip to content

Commit

Permalink
MB-51738: [BP] Define this_node() to handle distribution crash
Browse files Browse the repository at this point in the history
This change defines the this_node() function which handles the case
where the distribution has stopped and the node() function returns
nonode@nohost by keeping the distribution node name in a persistent
term.

Change-Id: I0e474a289a004dcc254f7201caef0db3015e932d
Reviewed-on: https://review.couchbase.org/c/ns_server/+/184893
Well-Formed: Restriction Checker
Reviewed-by: Timofey Barmin <timofey.barmin@couchbase.com>
Tested-by: Steve Watanabe <steve.watanabe@couchbase.com>
  • Loading branch information
stevewatanabe committed Jan 13, 2023
1 parent edd9b79 commit c91c6f9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/dist_manager.erl
Expand Up @@ -23,6 +23,7 @@

-export([adjust_my_address/4, save_address_config/1,
ip_config_path/0, using_user_supplied_address/0, reset_address/0,
this_node/0,
wait_for_node/1, fixup_config/1, need_fixup/0, get_rename_txn_pid/0]).

%% used by babysitter and ns_couchdb
Expand Down Expand Up @@ -155,7 +156,7 @@ save_address_config(#state{my_ip = MyIP,
end.

save_node(NodeName, Path) ->
?log_info("saving node to ~p", [Path]),
?log_info("saving node name '~p' to ~p", [NodeName, Path]),
misc:atomic_write_file(Path, NodeName ++ "\n").

save_node(NodeName) ->
Expand Down Expand Up @@ -248,6 +249,10 @@ bringup(MyIP, UserSupplied) ->
Rv = decode_status(net_kernel:start([MyNodeName, longnames])),
net_kernel:set_net_ticktime(misc:get_env_default(set_net_ticktime, 60)),

ThisNode = node(),
false = (ThisNode =:= 'nonode@nohost'),
persistent_term:put({?MODULE, node}, ThisNode),

ok = configure_net_kernel(),
ns_server:setup_node_names(),

Expand Down Expand Up @@ -284,6 +289,9 @@ wait_for_node(NodeFun, Time, Try) ->
wait_for_node(NodeFun, Time, Try - 1)
end.

this_node() ->
persistent_term:get({?MODULE, node}, 'nonode@nohost').

configure_net_kernel() ->
Verbosity = misc:get_env_default(ns_server, net_kernel_verbosity, 0),
RV = net_kernel:verbose(Verbosity),
Expand Down

0 comments on commit c91c6f9

Please sign in to comment.