Configure FLUs and chains with "rc.d" style configuration #56

Merged
slfritchie merged 43 commits from slf/flu-config-rcd-style into master 2015-12-18 06:46:05 +00:00
4 changed files with 110 additions and 28 deletions
Showing only changes of commit ef10ebed22 - Show all commits

View file

@ -80,8 +80,8 @@
-record(chain_def_v1, {
name :: atom(),
mode :: pv1_consistency_mode(),
upi :: [pv1_server()],
witnesses :: [pv1_server()]
upi :: [p_srvr()],
witnesses :: [p_srvr()]
}).
-endif. % !MACHI_PROJECTION_HRL

View file

@ -120,20 +120,20 @@ sanitize_chain_def_rec(Whole, {Acc, D}) ->
{Acc, D}
end.
perhaps_bootstrap_chains([], _FLUs) ->
perhaps_bootstrap_chains([], _LocalFLUs_at_zero) ->
ok;
perhaps_bootstrap_chains([CD|ChainDefs], FLUs) ->
perhaps_bootstrap_chains([CD|ChainDefs], LocalFLUs_at_zero) ->
#chain_def_v1{upi=UPI, witnesses=Witnesses} = CD,
AllNames = [Name || #p_srvr{name=Name} <- UPI ++ Witnesses],
case ordsets:intersection(ordsets:from_list(AllNames),
ordsets:from_list(FLUs)) of
ordsets:from_list(LocalFLUs_at_zero)) of
[] ->
io:format(user, "TODO: no local flus in ~P\n", [CD, 10]),
ok;
[FLU1|_] ->
bootstrap_chain(CD, FLU1)
end,
perhaps_bootstrap_chains(ChainDefs, FLUs).
perhaps_bootstrap_chains(ChainDefs, LocalFLUs_at_zero).
bootstrap_chain(CD, FLU) ->
io:format(user, "TODO: config ~p as bootstrap member of ~p\n", [FLU, CD]),

View file

@ -95,11 +95,13 @@ init([{MyFluName}|Args]) ->
handle_call({get_unfit_list}, _From, #state{active_unfit=ActiveUnfit}=S) ->
Reply = ActiveUnfit,
io:format(user, "get_unfit_list ~p: ~p\n", [S#state.my_flu_name, Reply]),
{reply, Reply, S};
handle_call({update_local_down_list, Down, MembersDict}, _From,
#state{my_flu_name=MyFluName, pending_map=OldMap,
local_down=OldDown, members_dict=OldMembersDict,
admin_down=AdminDown}=S) ->
io:format(user, "update_local_down_list: ~w: down ~w md ~W\n", [S#state.my_flu_name, Down, MembersDict, 10]),
NewMap = store_in_map(OldMap, MyFluName, erlang:now(), Down,
AdminDown, [props_yo]),
S2 = if Down == OldDown, MembersDict == OldMembersDict ->

View file

@ -332,7 +332,11 @@ smoke1_test2() ->
ok = machi_partition_simulator:stop()
end.
nonunanimous_setup_and_fix_test() ->
nonunanimous_setup_and_fix_test_() ->
os:cmd("rm -f /tmp/moomoo.*"),
{timeout, 1*60, fun() -> nonunanimous_setup_and_fix_test2() end}.
nonunanimous_setup_and_fix_test2() ->
machi_partition_simulator:start_link({1,2,3}, 100, 0),
TcpPort = 62877,
FluInfo = [{a,TcpPort+0,"./data.a"}, {b,TcpPort+1,"./data.b"},
@ -342,8 +346,7 @@ nonunanimous_setup_and_fix_test() ->
[machi_flu1_test:clean_up_data_dir(Dir) || {_,_,Dir} <- FluInfo],
{ok, SupPid} = machi_flu_sup:start_link(),
Opts = [{active_mode, false}],
%% {ok, Mb} = ?MGR:start_link(b, MembersDict, [{active_mode, false}]++XX),
Opts = [{active_mode, false}, {initial_wedged, true}],
[{ok,_}=machi_flu_psup:start_flu_package(Name, Port, Dir, Opts) ||
{Name,Port,Dir} <- FluInfo],
Proxies = [Proxy_a, Proxy_b, Proxy_c] =
@ -351,8 +354,17 @@ nonunanimous_setup_and_fix_test() ->
%% MembersDict = machi_projection:make_members_dict(P_s),
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 ?MGR:trigger_react_to_env(Mgr),
ok
end || _ <- lists:seq(1, 7),
{Mgr,Proxy} <- MgrProxies]
end,
ok = machi_chain_manager1:set_chain_members(Ma, MembersDict),
ok = machi_chain_manager1:set_chain_members(Mb, MembersDict),
try
{ok, P1} = ?MGR:test_calc_projection(Ma, false),
@ -390,18 +402,14 @@ nonunanimous_setup_and_fix_test() ->
P2 = P2pb#projection_v1{dbg2=[]},
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% io:format(user, "\n+ Add a 3rd member to the chain.\n", []),
%% io:format(user, "\nSTEP: Add a 3rd member to the chain.\n", []),
io:format(user, "\nNOTE: One INFO REPORT will follow.\n", []),
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, []),
[begin
{_rr1, _rr2, TheEpoch} = ?MGR:trigger_react_to_env(Mgr),
ok
end || _ <- lists:seq(1, 7),
{Mgr,Proxy} <- [{Ma, Proxy_a}, {Mb, Proxy_b}, {Mc, Proxy_c}]],
Advance(),
{_, _, TheEpoch_3} = ?MGR:trigger_react_to_env(Ma),
{_, _, TheEpoch_3} = ?MGR:trigger_react_to_env(Mb),
{_, _, TheEpoch_3} = ?MGR:trigger_react_to_env(Mc),
@ -409,42 +417,114 @@ nonunanimous_setup_and_fix_test() ->
?FLU_PC:read_latest_projection(Pxy, private) || Pxy <- Proxies],
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% io:format(user, "\n+ Remove 'a' from the chain.\n", []),
%% io:format(user, "STEP: Remove 'a' from the chain.\n", []),
io:format(user, "NOTE: One INFO REPORT will follow.\n", []),
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, []),
[begin
_ = ?MGR:trigger_react_to_env(Mgr),
ok
end || _ <- lists:seq(1, 7),
{Mgr,Proxy} <- [{Ma, Proxy_a}, {Mb, Proxy_b}, {Mc, Proxy_c}]],
%% {_, _, TheEpoch_4} = ?MGR:trigger_react_to_env(Ma),
Advance(),
{ok, {true, _}} = ?FLU_PC:wedge_status(Proxy_a),
{_, _, TheEpoch_4} = ?MGR:trigger_react_to_env(Mb),
{_, _, TheEpoch_4} = ?MGR:trigger_react_to_env(Mc),
[{ok, #projection_v1{upi=[b], repairing=[c]}} =
?FLU_PC:read_latest_projection(Pxy, private) || Pxy <- tl(Proxies)],
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% io:format(user, "\n+ Add a to the chain again.\n", []),
%% io:format(user, "STEP: Add a to the chain again (a is running).\n", []),
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, []),
[begin
{_rr1, _rr2, TheEpoch} = ?MGR:trigger_react_to_env(Mgr),
ok
end || _ <- lists:seq(1, 7),
{Mgr,Proxy} <- [{Ma, Proxy_a}, {Mb, Proxy_b}, {Mc, Proxy_c}]],
Advance(),
{_, _, TheEpoch_5} = ?MGR:trigger_react_to_env(Ma),
{_, _, TheEpoch_5} = ?MGR:trigger_react_to_env(Mb),
{_, _, TheEpoch_5} = ?MGR:trigger_react_to_env(Mc),
[{ok, #projection_v1{upi=[b], repairing=[a,c]}} =
?FLU_PC:read_latest_projection(Pxy, private) || Pxy <- Proxies],
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
io:format(user, "STEP: Stop a while a chain member, advance b&c.\n", []),
ok = machi_flu_psup:stop_flu_package(a),
Advance(),
{_, _, TheEpoch_6} = ?MGR:trigger_react_to_env(Mb),
{_, _, TheEpoch_6} = ?MGR:trigger_react_to_env(Mc),
[{ok, #projection_v1{upi=[b], repairing=[c]}} =
?FLU_PC:read_latest_projection(Pxy, private) || Pxy <- tl(Proxies)],
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
io:format(user, "STEP: Remove 'a' from the chain.\n", []),
io:format(user, "NOTE: One INFO REPORT will follow.\n", []),
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, []),
Advance(),
{_, _, TheEpoch_7} = ?MGR:trigger_react_to_env(Mb),
{_, _, TheEpoch_7} = ?MGR:trigger_react_to_env(Mc),
[{ok, #projection_v1{upi=[b], repairing=[c]}} =
?FLU_PC:read_latest_projection(Pxy, private) || Pxy <- tl(Proxies)],
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
io:format(user, "STEP: Start a, advance.\n", []),
[{ok,_}=machi_flu_psup:start_flu_package(Name, Port, Dir, Opts) ||
{Name,Port,Dir} <- [hd(FluInfo)]],
Advance(),
{ok, {true, _}} = ?FLU_PC:wedge_status(Proxy_a),
{ok, {false, EpochID_8}} = ?FLU_PC:wedge_status(Proxy_b),
{ok, {false, EpochID_8}} = ?FLU_PC:wedge_status(Proxy_c),
[{ok, #projection_v1{upi=[b], repairing=[c]}} =
?FLU_PC:read_latest_projection(Pxy, private) || Pxy <- tl(Proxies)],
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
io:format(user, "STEP: Stop a, delete a's data, leave it stopped\n", []),
ok = machi_flu_psup:stop_flu_package(a),
Advance(),
{_,_,Dir_a} = hd(FluInfo),
[machi_flu1_test:clean_up_data_dir(Dir) || {_,_,Dir} <- [hd(FluInfo)]],
{ok, {false, _}} = ?FLU_PC:wedge_status(Proxy_b),
{ok, {false, _}} = ?FLU_PC:wedge_status(Proxy_c),
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
io:format(user, "STEP: Add a to the chain again (a is stopped).\n", []),
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, []),
Advance(),
[begin
{ok, Pqq} = ?FLU_PC:read_latest_projection(Pxy, private),
io:format(user, "At ~w: ~w\n", [Pxy, machi_projection:make_summary(Pqq#projection_v1{dbg2=[]})])
end || Pxy <- tl(Proxies)],
{_, _, TheEpoch_9b} = ?MGR:trigger_react_to_env(Mb),
true = (TheEpoch_9b > TheEpoch_9),
[{ok,_}=machi_flu_psup:start_flu_package(Name, Port, Dir, Opts) ||
{Name,Port,Dir} <- [hd(FluInfo)]],
Advance(),
os:cmd("touch /tmp/moomoo.c"),
[begin
Qzx = ?MGR:trigger_react_to_env(Mgr),
io:format(user, "dbg: ~w: ~w\n", [Mgr, Qzx]),
ok
end || _ <- lists:seq(1,1),
{Mgr,Proxy} <- MgrProxies],
[begin
{ok, Pqq} = ?FLU_PC:read_latest_projection(Pxy, private),
io:format(user, "At ~w: ~w\n", [Pxy, machi_projection:make_summary(Pqq#projection_v1{dbg2=[]})])
end || Pxy <- Proxies],
[io:format(user, "Unfit @ ~w: ~p\n", [Xii, machi_fitness:get_unfit_list(machi_fitness)]) || Xii <- [a_fitness, b_fitness, c_fitness] ],
{ok, {true, {0,_}}} = ?FLU_PC:wedge_status(Proxy_a),
{_, _, TheEpoch_9c} = ?MGR:trigger_react_to_env(Ma),
{_, _, TheEpoch_9c} = ?MGR:trigger_react_to_env(Mb),
{_, _, TheEpoch_9c} = ?MGR:trigger_react_to_env(Mc),
[{ok, #projection_v1{upi=[b], repairing=[a,c]}} =
?FLU_PC:read_latest_projection(Pxy, private) || Pxy <- Proxies],
ok
after
exit(SupPid, normal),