This commit is contained in:
Michael Klishin 2016-05-09 09:27:34 +08:00
parent 2a4a1b9a94
commit 7e24f1ec13
1 changed files with 9 additions and 9 deletions

View File

@ -149,7 +149,7 @@
group,
tx_fun,
initial_childspecs,
children_order}).
child_order}).
%%----------------------------------------------------------------------------
@ -290,7 +290,7 @@ init({Group, TxFun, ChildSpecs}) ->
{ok, #state{group = Group,
tx_fun = TxFun,
initial_childspecs = ChildSpecs,
children_order = children_order(ChildSpecs)}}.
child_order = child_order_from(ChildSpecs)}}.
handle_call({init, Overall}, _From,
State = #state{overall = undefined,
@ -374,15 +374,15 @@ handle_info({'DOWN', _Ref, process, Pid, _Reason},
group = Group,
tx_fun = TxFun,
overall = O,
children_order = ChildrenOrder}) ->
child_order = ChildOrder}) ->
%% TODO load balance this
%% No guarantee pg2 will have received the DOWN before us.
R = case lists:sort(?PG2:get_members(Group)) -- [Pid] of
[O | _] -> ChildSpecs =
TxFun(fun() -> update_all(O, Pid) end),
[start(Delegate, ChildSpec)
|| ChildSpec <- restore_children_order(ChildSpecs,
ChildrenOrder)];
|| ChildSpec <- restore_child_order(ChildSpecs,
ChildOrder)];
_ -> []
end,
case errors(R) of
@ -521,13 +521,13 @@ add_proplists([{K1, _} = KV | P1], [{K2, _} | _] = P2, Acc) when K1 < K2 ->
add_proplists(P1, [KV | P2], Acc) ->
add_proplists(P1, P2, [KV | Acc]).
children_order(ChildSpecs) ->
child_order_from(ChildSpecs) ->
lists:zipwith(fun(C, N) ->
{id(C), N}
end, ChildSpecs, lists:seq(1, length(ChildSpecs))).
restore_children_order(ChildSpecs, ChildrenOrder) ->
restore_child_order(ChildSpecs, ChildOrder) ->
lists:sort(fun(A, B) ->
proplists:get_value(id(A), ChildrenOrder)
< proplists:get_value(id(B), ChildrenOrder)
proplists:get_value(id(A), ChildOrder)
< proplists:get_value(id(B), ChildOrder)
end, ChildSpecs).