diff options
| author | Matthias Radestock <matthias@rabbitmq.com> | 2012-11-29 14:00:16 +0000 |
|---|---|---|
| committer | Matthias Radestock <matthias@rabbitmq.com> | 2012-11-29 14:00:16 +0000 |
| commit | e29c8a6e7a24215179bc316612d9afa885b8805a (patch) | |
| tree | 7c6d8b3390aec751e3aa766a17f2ebeec00fa2bc | |
| parent | 8548e950572a59635d3253c68f6f4f39e0516551 (diff) | |
| download | rabbitmq-server-git-e29c8a6e7a24215179bc316612d9afa885b8805a.tar.gz | |
extract logging
| -rw-r--r-- | src/rabbit_mirror_queue_master.erl | 17 | ||||
| -rw-r--r-- | src/rabbit_mirror_queue_sync.erl | 30 |
2 files changed, 21 insertions, 26 deletions
diff --git a/src/rabbit_mirror_queue_master.erl b/src/rabbit_mirror_queue_master.erl index d8737938ca..3d7f902c5a 100644 --- a/src/rabbit_mirror_queue_master.erl +++ b/src/rabbit_mirror_queue_master.erl @@ -131,20 +131,21 @@ sync_mirrors(State = #state { name = QName, gm = GM, backing_queue = BQ, backing_queue_state = BQS }) -> - rabbit_log:info("Synchronising ~s: ~p messages to synchronise~n", - [rabbit_misc:rs(QName), BQ:len(BQS)]), + Log = fun (Fmt, Params) -> + rabbit_log:info("Synchronising ~s: " ++ Fmt ++ "~n", + [rabbit_misc:rs(QName) | Params]) + end, + Log("~p messages to synchronise", [BQ:len(BQS)]), {ok, #amqqueue{slave_pids = SPids}} = rabbit_amqqueue:lookup(QName), Ref = make_ref(), - Syncer = rabbit_mirror_queue_sync:master_prepare(Ref, QName, SPids), + Syncer = rabbit_mirror_queue_sync:master_prepare(Ref, Log, SPids), gm:broadcast(GM, {sync_start, Ref, Syncer, SPids}), S = fun(BQSN) -> State#state{backing_queue_state = BQSN} end, - case rabbit_mirror_queue_sync:master_go(Syncer, Ref, QName, BQ, BQS) of + case rabbit_mirror_queue_sync:master_go(Syncer, Ref, Log, BQ, BQS) of {shutdown, R, BQS1} -> {stop, R, S(BQS1)}; - {sync_died, R, BQS1} -> rabbit_log:info("Synchronising ~s: ~p~n", - [rabbit_misc:rs(QName), R]), + {sync_died, R, BQS1} -> Log("~p", [R]), {ok, S(BQS1)}; - {ok, BQS1} -> rabbit_log:info("Synchronising ~s: complete~n", - [rabbit_misc:rs(QName)]), + {ok, BQS1} -> Log("complete", []), {ok, S(BQS1)} end. diff --git a/src/rabbit_mirror_queue_sync.erl b/src/rabbit_mirror_queue_sync.erl index d838d63603..bddfb9dcfe 100644 --- a/src/rabbit_mirror_queue_sync.erl +++ b/src/rabbit_mirror_queue_sync.erl @@ -53,12 +53,12 @@ %% --------------------------------------------------------------------------- %% Master -master_prepare(Ref, QName, SPids) -> +master_prepare(Ref, Log, SPids) -> MPid = self(), - spawn_link(fun () -> syncer(Ref, QName, MPid, SPids) end). + spawn_link(fun () -> syncer(Ref, Log, MPid, SPids) end). -master_go(Syncer, Ref, QName, BQ, BQS) -> - SendArgs = {Syncer, Ref, QName, rabbit_misc:get_parent()}, +master_go(Syncer, Ref, Log, BQ, BQS) -> + SendArgs = {Syncer, Ref, Log, rabbit_misc:get_parent()}, {Acc, BQS1} = BQ:fold(fun (Msg, MsgProps, {I, Last}) -> master_send(SendArgs, I, Last, Msg, MsgProps) @@ -73,11 +73,10 @@ master_go(Syncer, Ref, QName, BQ, BQS) -> _ -> {ok, BQS1} end. -master_send({Syncer, Ref, QName, Parent}, I, Last, Msg, MsgProps) -> +master_send({Syncer, Ref, Log, Parent}, I, Last, Msg, MsgProps) -> Acc = {I + 1, case timer:now_diff(erlang:now(), Last) > ?SYNC_PROGRESS_INTERVAL of - true -> rabbit_log:info("Synchronising ~s: ~p messages~n", - [rabbit_misc:rs(QName), I]), + true -> Log("~p messages", [I]), erlang:now(); false -> Last end}, @@ -98,22 +97,17 @@ master_send({Syncer, Ref, QName, Parent}, I, Last, Msg, MsgProps) -> %% --------------------------------------------------------------------------- %% Syncer -syncer(Ref, QName, MPid, SPids) -> +syncer(Ref, Log, MPid, SPids) -> SPidsMRefs = [{SPid, erlang:monitor(process, SPid)} || SPid <- SPids], %% We wait for a reply from the slaves so that we know they are in %% a receive block and will thus receive messages we send to them %% *without* those messages ending up in their gen_server2 pqueue. case foreach_slave(SPidsMRefs, Ref, fun sync_receive_ready/3) of - [] -> - rabbit_log:info("Synchronising ~s: all slaves already synced~n", - [rabbit_misc:rs(QName)]); - SPidsMRefs1 -> - rabbit_log:info("Synchronising ~s: ~p to sync~n", - [rabbit_misc:rs(QName), - [rabbit_misc:pid_to_string(S) || - {S, _} <- SPidsMRefs1]]), - SPidsMRefs2 = syncer_loop({Ref, MPid}, SPidsMRefs1), - foreach_slave(SPidsMRefs2, Ref, fun sync_send_complete/3) + [] -> Log("all slaves already synced", []); + SPidsMRefs1 -> Log("~p to sync", [[rabbit_misc:pid_to_string(S) || + {S, _} <- SPidsMRefs1]]), + SPidsMRefs2 = syncer_loop({Ref, MPid}, SPidsMRefs1), + foreach_slave(SPidsMRefs2, Ref, fun sync_send_complete/3) end, unlink(MPid). |
