Configure FLUs and chains with "rc.d" style configuration #56
6 changed files with 60 additions and 34 deletions
|
@ -1,6 +1,6 @@
|
|||
%% -------------------------------------------------------------------
|
||||
%%
|
||||
%% Copyright (c) 2007-2014 Basho Technologies, Inc. All Rights Reserved.
|
||||
%% Copyright (c) 2007-2015 Basho Technologies, Inc. All Rights Reserved.
|
||||
%%
|
||||
%% This file is provided to you under the Apache License,
|
||||
%% Version 2.0 (the "License"); you may not use this file
|
||||
|
@ -78,14 +78,14 @@
|
|||
-define(MAX_CHAIN_LENGTH, 64).
|
||||
|
||||
-record(chain_def_v1, {
|
||||
name :: atom(),
|
||||
name :: atom(), % chain name
|
||||
mode :: pv1_consistency_mode(),
|
||||
full :: [p_srvr()],
|
||||
witnesses :: [p_srvr()],
|
||||
old_all :: [pv1_server()], % guard against some races
|
||||
old_witnesses :: [pv1_server()], % guard against some races
|
||||
local_run :: [pv1_server()], % must be tailored to each machine!
|
||||
local_stop :: [pv1_server()], % must be tailored to each machine!
|
||||
full = [] :: [p_srvr()],
|
||||
witnesses = [] :: [p_srvr()],
|
||||
old_all = [] :: [pv1_server()], % guard against some races
|
||||
old_witnesses=[] :: [pv1_server()], % guard against some races
|
||||
local_run = [] :: [pv1_server()], % must be tailored to each machine!
|
||||
local_stop = [] :: [pv1_server()], % must be tailored to each machine!
|
||||
props = [] :: list() % proplist for other related info
|
||||
}).
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ make_package_spec(FluName, TcpPort, DataDir, Props) ->
|
|||
permanent, ?SHUTDOWN, supervisor, []}.
|
||||
|
||||
start_flu_package(#p_srvr{name=FluName, port=TcpPort, props=Props}) ->
|
||||
DataDir = get_data_dir(Props),
|
||||
DataDir = get_data_dir(FluName, Props),
|
||||
start_flu_package(FluName, TcpPort, DataDir, Props).
|
||||
|
||||
start_flu_package(FluName, TcpPort, DataDir, Props) ->
|
||||
|
@ -177,11 +177,11 @@ get_env(Setting, Default) ->
|
|||
{ok, V} -> V
|
||||
end.
|
||||
|
||||
get_data_dir(Props) ->
|
||||
get_data_dir(FluName, Props) ->
|
||||
case proplists:get_value(data_dir, Props) of
|
||||
Path when is_list(Path) ->
|
||||
Path;
|
||||
undefined ->
|
||||
{ok, Dir} = application:get_env(machi, flu_data_dir),
|
||||
Dir
|
||||
Dir ++ "/" ++ atom_to_list(FluName)
|
||||
end.
|
||||
|
|
|
@ -205,6 +205,9 @@
|
|||
%% API
|
||||
-export([start_link/0,
|
||||
process_pending/0]).
|
||||
-ifdef(TEST).
|
||||
-compile(export_all).
|
||||
-endif. % TEST
|
||||
|
||||
%% gen_server callbacks
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
|
@ -548,8 +551,8 @@ process_pending_chain2(File, CD, RemovedFLUs, ChainConfigAction, S) ->
|
|||
[] ->
|
||||
ok;
|
||||
[_|_] ->
|
||||
%% Sleep for a little bit to allow HC to settle.
|
||||
timer:sleep(3000),
|
||||
%% %% Sleep for a little bit to allow HC to settle.
|
||||
%% timer:sleep(1000),
|
||||
[begin
|
||||
%% We may be retrying this, so be liberal with any pattern
|
||||
%% matching on return values.
|
||||
|
|
|
@ -955,7 +955,7 @@ conv_from_status({error, partial_read}) ->
|
|||
conv_from_status({error, bad_epoch}) ->
|
||||
'BAD_EPOCH';
|
||||
conv_from_status(_OOPS) ->
|
||||
io:format(user, "HEY, ~s:~w got ~w\n", [?MODULE, ?LINE, _OOPS]),
|
||||
io:format(user, "HEY, ~s:~w got ~p\n", [?MODULE, ?LINE, _OOPS]),
|
||||
'BAD_JOSS'.
|
||||
|
||||
conv_to_boolean(undefined) ->
|
||||
|
|
|
@ -273,6 +273,17 @@ make_prop_ets() ->
|
|||
|
||||
-endif. % EQC
|
||||
|
||||
make_advance_fun(FitList, FLUList, MgrList, Num) ->
|
||||
fun() ->
|
||||
[begin
|
||||
[catch machi_fitness:trigger_early_adjustment(Fit, Tgt) ||
|
||||
Fit <- FitList,
|
||||
Tgt <- FLUList ],
|
||||
[catch ?MGR:trigger_react_to_env(Mgr) || Mgr <- MgrList],
|
||||
ok
|
||||
end || _ <- lists:seq(1, Num)]
|
||||
end.
|
||||
|
||||
smoke0_test() ->
|
||||
{ok, _} = machi_partition_simulator:start_link({1,2,3}, 50, 50),
|
||||
Host = "localhost",
|
||||
|
@ -348,6 +359,7 @@ nonunanimous_setup_and_fix_test2() ->
|
|||
[machi_flu1_test:clean_up_data_dir(Dir) || {_,_,Dir} <- FluInfo],
|
||||
{ok, SupPid} = machi_flu_sup:start_link(),
|
||||
Opts = [{active_mode, false}, {initial_wedged, true}],
|
||||
ChainName = my_little_chain,
|
||||
[{ok,_}=machi_flu_psup:start_flu_package(Name, Port, Dir, Opts) ||
|
||||
{Name,Port,Dir} <- FluInfo],
|
||||
Proxies = [Proxy_a, Proxy_b, Proxy_c] =
|
||||
|
@ -356,19 +368,14 @@ nonunanimous_setup_and_fix_test2() ->
|
|||
MembersDict = machi_projection:make_members_dict(lists:sublist(P_s, 2)),
|
||||
Mgrs = [Ma,Mb,Mc] = [a_chmgr, b_chmgr, c_chmgr],
|
||||
MgrProxies = [{Ma, Proxy_a}, {Mb, Proxy_b}, {Mc, Proxy_c}],
|
||||
Advance = fun() ->
|
||||
[begin
|
||||
[catch machi_fitness:trigger_early_adjustment(Fit, Tgt) ||
|
||||
Fit <- [a_fitness,b_fitness,c_fitness],
|
||||
Tgt <- [a,b,c] ],
|
||||
[catch ?MGR:trigger_react_to_env(Mgr) ||
|
||||
{Mgr,_Proxy} <- MgrProxies],
|
||||
ok
|
||||
end || _ <- lists:seq(1, 3)]
|
||||
end,
|
||||
ok = machi_chain_manager1:set_chain_members(Ma, MembersDict),
|
||||
ok = machi_chain_manager1:set_chain_members(Mb, MembersDict),
|
||||
|
||||
Advance = make_advance_fun([a_fitness,b_fitness,c_fitness],
|
||||
[a,b,c],
|
||||
[Mgr || {Mgr,_Proxy} <- MgrProxies],
|
||||
3),
|
||||
ok = machi_chain_manager1:set_chain_members(Ma, ChainName, 0, ap_mode,
|
||||
MembersDict, []),
|
||||
ok = machi_chain_manager1:set_chain_members(Mb, ChainName, 0, ap_mode,
|
||||
MembersDict, []),
|
||||
try
|
||||
{ok, P1} = ?MGR:test_calc_projection(Ma, false),
|
||||
|
||||
|
@ -410,7 +417,7 @@ nonunanimous_setup_and_fix_test2() ->
|
|||
|
||||
MembersDict3 = machi_projection:make_members_dict(P_s),
|
||||
ok = machi_chain_manager1:set_chain_members(
|
||||
Ma, ch_not_def_yet, EpochNum_a, ap_mode, MembersDict3, []),
|
||||
Ma, ChainName, EpochNum_a, ap_mode, MembersDict3, []),
|
||||
|
||||
Advance(),
|
||||
{_, _, TheEpoch_3} = ?MGR:trigger_react_to_env(Ma),
|
||||
|
@ -424,7 +431,7 @@ nonunanimous_setup_and_fix_test2() ->
|
|||
|
||||
MembersDict4 = machi_projection:make_members_dict(tl(P_s)),
|
||||
ok = machi_chain_manager1:set_chain_members(
|
||||
Mb, ch_not_def_yet, TheEpoch_3, ap_mode, MembersDict4, []),
|
||||
Mb, ChainName, TheEpoch_3, ap_mode, MembersDict4, []),
|
||||
|
||||
Advance(),
|
||||
{ok, {true, _}} = ?FLU_PC:wedge_status(Proxy_a),
|
||||
|
@ -438,7 +445,7 @@ nonunanimous_setup_and_fix_test2() ->
|
|||
|
||||
MembersDict5 = machi_projection:make_members_dict(P_s),
|
||||
ok = machi_chain_manager1:set_chain_members(
|
||||
Mb, ch_not_def_yet, TheEpoch_4, ap_mode, MembersDict5, []),
|
||||
Mb, ChainName, TheEpoch_4, ap_mode, MembersDict5, []),
|
||||
|
||||
Advance(),
|
||||
{_, _, TheEpoch_5} = ?MGR:trigger_react_to_env(Ma),
|
||||
|
@ -462,7 +469,7 @@ nonunanimous_setup_and_fix_test2() ->
|
|||
|
||||
MembersDict7 = machi_projection:make_members_dict(tl(P_s)),
|
||||
ok = machi_chain_manager1:set_chain_members(
|
||||
Mb, ch_not_def_yet, TheEpoch_6, ap_mode, MembersDict7, []),
|
||||
Mb, ChainName, TheEpoch_6, ap_mode, MembersDict7, []),
|
||||
|
||||
Advance(),
|
||||
{_, _, TheEpoch_7} = ?MGR:trigger_react_to_env(Mb),
|
||||
|
@ -498,7 +505,7 @@ nonunanimous_setup_and_fix_test2() ->
|
|||
MembersDict9 = machi_projection:make_members_dict(P_s),
|
||||
{_, _, TheEpoch_9} = ?MGR:trigger_react_to_env(Mb),
|
||||
ok = machi_chain_manager1:set_chain_members(
|
||||
Mb, ch_not_def_yet, TheEpoch_9, ap_mode, MembersDict9, []),
|
||||
Mb, ChainName, TheEpoch_9, ap_mode, MembersDict9, []),
|
||||
Advance(),
|
||||
{_, _, TheEpoch_9b} = ?MGR:trigger_react_to_env(Mb),
|
||||
true = (TheEpoch_9b > TheEpoch_9),
|
||||
|
|
|
@ -30,6 +30,22 @@
|
|||
-define(FLU, machi_flu1).
|
||||
-define(FLU_C, machi_flu1_client).
|
||||
|
||||
get_env_vars(App, Ks) ->
|
||||
Raw = [application:get_env(App, K) || K <- Ks],
|
||||
Old = lists:zip(Ks, Raw),
|
||||
{App, Old}.
|
||||
|
||||
clean_up_env_vars({App, Old}) ->
|
||||
[case Res of
|
||||
undefined ->
|
||||
application:unset_env(App, K);
|
||||
{ok, V} ->
|
||||
application:set_env(App, K, V)
|
||||
end || {K, Res} <- Old].
|
||||
|
||||
filter_env_var({ok, V}) -> V;
|
||||
filter_env_var(Else) -> Else.
|
||||
|
||||
clean_up_data_dir(DataDir) ->
|
||||
[begin
|
||||
Fs = filelib:wildcard(DataDir ++ Glob),
|
||||
|
|
Loading…
Reference in a new issue