Skip to content

Commit

Permalink
MB-31912: Merge remote-tracking branch vulcan.
Browse files Browse the repository at this point in the history
The following are the changes:

d0ada77 MB-31912: Change the format used to store config...
faf9455 MB-31912: Update dump-guts to use dist_cfg file...
7bf29c42 Merge remote-tracking branch vulcan.

Change-Id: Ia65a64736d9544acdc4a81af2346fcc6da81a35b
  • Loading branch information
ajityagaty committed Nov 13, 2018
2 parents f8cd4dd + faf9455 commit 8ec1337
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
4 changes: 2 additions & 2 deletions deps/ns_babysitter/src/ns_babysitter.erl
Expand Up @@ -65,9 +65,9 @@ start(_, _) ->

save_dist_config() ->
DCfgFile = dist_manager:dist_config_path(path_config:component_path(data)),
DType = misc:get_proto_dist_type(),
filelib:ensure_dir(DCfgFile),
misc:atomic_write_file(DCfgFile, DType).
dist_manager:store_dist_config(DCfgFile, misc:get_proto_dist_type(),
undefined).

maybe_write_file(Env, Content, Name) ->
case application:get_env(Env) of
Expand Down
28 changes: 27 additions & 1 deletion scripts/dump-guts
Expand Up @@ -607,7 +607,7 @@ main_with_everything(StaticTerms, NSConfig, CouchInisPList, Node) ->
IndexerMDD = filename:join(DataDir, "crash"),

UsersStoragePath = filename:join([DataDir, "config", "users.dets"]),
{_, Ipv6} = lists:keyfind(ipv6, 1, StaticTerms),
Ipv6 = is_net_config_ipv6(filename:join([DataDir, "config", "dist_cfg"])),

Pairs = OtherPorts ++
[{ns_config, iolist_to_binary(io_lib:format("~p", [sanitize_config(NSConfig)]))},
Expand Down Expand Up @@ -644,6 +644,32 @@ main_with_everything(StaticTerms, NSConfig, CouchInisPList, Node) ->
%% not sure why but output to tty is sometimes truncated otherwise
timer:sleep(100).

is_net_config_ipv6(DistCfgPath) ->
RV = case file:consult(DistCfgPath) of
{error, enoent} ->
undefined;
{ok, Val} ->
lists:keyfind(dist_type, 1, Val);
Error ->
Error
end,

case RV of
{error, _} = Err ->
io:format(standard_error,
"Failed to read dist_cfg file '~s': ~p~n",
[filename:absname(DistCfgPath), Err]),
init:stop(1);
X when X =:= undefined; X =:= false ->
false;
Cfg ->
Mode = case Cfg of
{dist_type, M, _} -> M;
{dist_type, M} -> M
end,
Mode =:= inet6_tcp
end.

read_ns_log(Path) ->
{ok, B} = file:read_file(Path),
B1 = zlib:uncompress(B),
Expand Down
33 changes: 27 additions & 6 deletions src/dist_manager.erl
Expand Up @@ -28,7 +28,8 @@

-export([adjust_my_address/3, read_address_config/0, save_address_config/1,
ip_config_path/0, using_user_supplied_address/0, reset_address/0,
wait_for_node/1, dist_config_path/1, update_dist_config/1]).
wait_for_node/1, dist_config_path/1, store_dist_config/3,
update_dist_config/1]).

%% used by the service init script.
-export([get_proto_dist_type/1]).
Expand Down Expand Up @@ -61,6 +62,19 @@ using_user_supplied_address() ->
reset_address() ->
gen_server:call(?MODULE, reset_address).

store_dist_config(DCfgFile, Cfg) ->
Data = io_lib:format("~p.~n", [Cfg]),
misc:atomic_write_file(DCfgFile, Data).

store_dist_config(DCfgFile, CurrDistType, undefined) ->
Cfg = {dist_type, list_to_atom(CurrDistType)},
store_dist_config(DCfgFile, Cfg);
store_dist_config(DCfgFile, CurrDistType, NewDistType) ->
Cfg = {dist_type,
list_to_atom(CurrDistType),
list_to_atom(NewDistType)},
store_dist_config(DCfgFile, Cfg).

update_dist_config(NewAFamily) ->
CurrDistType = misc:get_proto_dist_type(),
NewDistType = case NewAFamily of
Expand All @@ -75,7 +89,7 @@ update_dist_config(NewAFamily) ->
DCfgFile = dist_config_path(path_config:component_path(data)),
?log_debug("Saving new networking mode (~s) to config file: ~s",
[NewDistType, DCfgFile]),
misc:atomic_write_file(DCfgFile, CurrDistType ++ "," ++ NewDistType)
store_dist_config(DCfgFile, CurrDistType, NewDistType)
end.

%% This function will be called by the init script to determine
Expand All @@ -85,16 +99,23 @@ get_proto_dist_type(Params) ->
DCfgFile = dist_config_path(DataDir),

ExitStatus =
case read_from_file(DCfgFile) of
case file:consult(DCfgFile) of
{error, enoent} ->
io:format("inet_tcp"),
0;
{error, Err} ->
io:format("Couldn't determine proto_dist value. Failed to "
"read from `~s` file: ~p", [DCfgFile, Err]),
1;
undefined ->
{ok, []} ->
io:format("inet_tcp"),
0;
Cfg ->
Modes = string:tokens(Cfg, ","),
{ok, Val} ->
DistCfg = lists:keyfind(dist_type, 1, Val),
Modes = case DistCfg of
{dist_type, C, N} -> [C, N];
{dist_type, C} -> [C]
end,
RV = case StartStop of
"start" -> lists:last(Modes);
"stop" -> hd(Modes)
Expand Down

0 comments on commit 8ec1337

Please sign in to comment.