diff options
author | Matthias Radestock <matthias@rabbitmq.com> | 2011-10-01 09:16:17 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@rabbitmq.com> | 2011-10-01 09:16:17 +0100 |
commit | 5387c383d72937f892efcddc69c6a5c87d37e0c3 (patch) | |
tree | 5b551fee0c0968118265f4f0a1d05b0c3758160a | |
parent | f8482cda9fb7cc32db784c41ccffb0a3970fa9b5 (diff) | |
download | rabbitmq-server-5387c383d72937f892efcddc69c6a5c87d37e0c3.tar.gz |
refactor: eliminate gratuitous differences in 'confirm' code
-rw-r--r-- | src/rabbit_amqqueue_process.erl | 22 | ||||
-rw-r--r-- | src/rabbit_mirror_queue_slave.erl | 12 |
2 files changed, 17 insertions, 17 deletions
diff --git a/src/rabbit_amqqueue_process.erl b/src/rabbit_amqqueue_process.erl index d1b37a41..f72369fe 100644 --- a/src/rabbit_amqqueue_process.erl +++ b/src/rabbit_amqqueue_process.erl @@ -454,17 +454,17 @@ deliver_from_queue_deliver(AckRequired, false, State) -> confirm_messages([], State) -> State; confirm_messages(MsgIds, State = #q{msg_id_to_channel = MTC}) -> - {CMs, MTC1} = lists:foldl( - fun(MsgId, {CMs, MTC0}) -> - case dict:find(MsgId, MTC0) of - {ok, {ChPid, MsgSeqNo}} -> - {rabbit_misc:gb_trees_cons(ChPid, MsgSeqNo, - CMs), - dict:erase(MsgId, MTC0)}; - _ -> - {CMs, MTC0} - end - end, {gb_trees:empty(), MTC}, MsgIds), + {CMs, MTC1} = + lists:foldl( + fun(MsgId, {CMs, MTC0}) -> + case dict:find(MsgId, MTC0) of + {ok, {ChPid, MsgSeqNo}} -> + {rabbit_misc:gb_trees_cons(ChPid, MsgSeqNo, CMs), + dict:erase(MsgId, MTC0)}; + _ -> + {CMs, MTC0} + end + end, {gb_trees:empty(), MTC}, MsgIds), gb_trees_foreach(fun rabbit_channel:confirm/2, CMs), State#q{msg_id_to_channel = MTC1}. diff --git a/src/rabbit_mirror_queue_slave.erl b/src/rabbit_mirror_queue_slave.erl index 1101f220..337740d7 100644 --- a/src/rabbit_mirror_queue_slave.erl +++ b/src/rabbit_mirror_queue_slave.erl @@ -390,9 +390,9 @@ needs_confirming(_Delivery, _State) -> immediately. confirm_messages(MsgIds, State = #state { msg_id_status = MS }) -> - {MS1, CMs} = + {CMs, MS1} = lists:foldl( - fun (MsgId, {MSN, CMsN} = Acc) -> + fun (MsgId, {CMsN, MSN} = Acc) -> %% We will never see 'discarded' here case dict:find(MsgId, MSN) of error -> @@ -402,12 +402,12 @@ confirm_messages(MsgIds, State = #state { msg_id_status = MS }) -> {ok, {published, ChPid}} -> %% Still not seen it from the channel, just %% record that it's been confirmed. - {dict:store(MsgId, {confirmed, ChPid}, MSN), CMsN}; + {CMsN, dict:store(MsgId, {confirmed, ChPid}, MSN)}; {ok, {published, ChPid, MsgSeqNo}} -> %% Seen from both GM and Channel. Can now %% confirm. - {dict:erase(MsgId, MSN), - rabbit_misc:gb_trees_cons(ChPid, MsgSeqNo, CMsN)}; + {rabbit_misc:gb_trees_cons(ChPid, MsgSeqNo, CMsN), + dict:erase(MsgId, MSN)}; {ok, {confirmed, _ChPid}} -> %% It's already been confirmed. This is %% probably it's been both sync'd to disk @@ -416,7 +416,7 @@ confirm_messages(MsgIds, State = #state { msg_id_status = MS }) -> %% channel. Nothing to do here. Acc end - end, {MS, gb_trees:empty()}, MsgIds), + end, {gb_trees:empty(), MS}, MsgIds), [ok = rabbit_channel:confirm(ChPid, MsgSeqNos) || {ChPid, MsgSeqNos} <- gb_trees:to_list(CMs)], State #state { msg_id_status = MS1 }. |