diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2012-08-07 13:40:10 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2012-08-07 13:40:10 +0100 |
commit | 28cfa44999c3dce3bde80f8b6e35b3178a3795f1 (patch) | |
tree | e7a3a18c2d94678ee445d89e350b1590820269a8 | |
parent | 1c5d42cc4f2a309ca4d5230e64ca65477cbb5fc6 (diff) | |
download | rabbitmq-server-28cfa44999c3dce3bde80f8b6e35b3178a3795f1.tar.gz |
Reify something that was previously a little bit magic.
-rw-r--r-- | src/rabbit_mirror_queue_misc.erl | 17 | ||||
-rw-r--r-- | src/rabbit_mirror_queue_slave.erl | 2 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/rabbit_mirror_queue_misc.erl b/src/rabbit_mirror_queue_misc.erl index 87be4df7..5f36a19f 100644 --- a/src/rabbit_mirror_queue_misc.erl +++ b/src/rabbit_mirror_queue_misc.erl @@ -68,11 +68,11 @@ remove_from_queue(QueueName, DeadPids) -> [] -> {error, not_found}; [Q = #amqqueue { pid = QPid, slave_pids = SPids }] -> - [QPid1 | SPids1] = Alive = - [Pid || Pid <- [QPid | SPids], - not lists:member(node(Pid), - DeadNodes) orelse - rabbit_misc:is_process_alive(Pid)], + Alive = [Pid || Pid <- [QPid | SPids], + not lists:member(node(Pid), + DeadNodes) orelse + rabbit_misc:is_process_alive(Pid)], + {QPid1, SPids1} = promote_slave(Alive), case {{QPid, SPids}, {QPid1, SPids1}} of {Same, Same} -> {ok, QPid1, []}; @@ -206,6 +206,11 @@ store_updated_slaves(Q = #amqqueue{slave_pids = SPids, %%---------------------------------------------------------------------------- +promote_slave([SPid | SPids]) -> + %% The slave pids are maintained in descending order of age, so + %% the one to promote is the oldest. + {SPid, SPids}. + suggested_queue_nodes(Q) -> {MNode0, SNodes} = actual_queue_nodes(Q), MNode = case MNode0 of @@ -227,7 +232,7 @@ suggested_queue_nodes(<<"nodes">>, Nodes0, {MNode, _SNodes}, _All) -> Nodes = [list_to_atom(binary_to_list(Node)) || Node <- Nodes0], case lists:member(MNode, Nodes) of true -> {MNode, Nodes -- [MNode]}; - false -> {hd(Nodes), tl(Nodes)} + false -> promote_slave(Nodes) end; suggested_queue_nodes(<<"at-least">>, Count, {MNode, SNodes}, All) -> SCount = Count - 1, diff --git a/src/rabbit_mirror_queue_slave.erl b/src/rabbit_mirror_queue_slave.erl index f8f83d45..3fc33f72 100644 --- a/src/rabbit_mirror_queue_slave.erl +++ b/src/rabbit_mirror_queue_slave.erl @@ -154,6 +154,8 @@ init_it(Self, Node, QueueName) -> mnesia:read({rabbit_queue, QueueName}), case [Pid || Pid <- [QPid | MPids], node(Pid) =:= Node] of [] -> + %% Add to the end, so they are in descending order of age, see + %% rabbit_mirror_queue_misc:promote_slave/1 MPids1 = MPids ++ [Self], rabbit_mirror_queue_misc:store_updated_slaves( Q1#amqqueue{slave_pids = MPids1}), |