diff options
| author | Matthias Radestock <matthias@lshift.net> | 2010-05-02 19:16:41 +0100 |
|---|---|---|
| committer | Matthias Radestock <matthias@lshift.net> | 2010-05-02 19:16:41 +0100 |
| commit | 122fc41988c068d2925b95804aeab8bf4c167dd9 (patch) | |
| tree | 0520d1b79a3437f8a1ccde37c4074d8730f7f8a7 /src | |
| parent | 9fb731afcc9758cd445acc870d27900fbfd338e8 (diff) | |
| download | rabbitmq-server-git-122fc41988c068d2925b95804aeab8bf4c167dd9.tar.gz | |
cancel queue's timers on shutdown
This is cleaner, though not strictly necessary.
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_amqqueue_process.erl | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/rabbit_amqqueue_process.erl b/src/rabbit_amqqueue_process.erl index 02254b4e7f..eb103ec92d 100644 --- a/src/rabbit_amqqueue_process.erl +++ b/src/rabbit_amqqueue_process.erl @@ -130,8 +130,9 @@ code_change(_OldVsn, State, _Extra) -> %%---------------------------------------------------------------------------- -terminate_shutdown(Fun, State = #q{backing_queue = BQ, - backing_queue_state = BQS}) -> +terminate_shutdown(Fun, State) -> + State1 = #q{backing_queue = BQ, backing_queue_state = BQS} = + stop_sync_timer(stop_rate_timer(State)), case BQS of undefined -> State; _ -> ok = rabbit_memory_monitor:deregister(self()), @@ -143,7 +144,7 @@ terminate_shutdown(Fun, State = #q{backing_queue = BQ, BQ:tx_rollback(Txn, BQSN), BQSN1 end, BQS, all_ch_record()), - State#q{backing_queue_state = Fun(BQS1)} + State1#q{backing_queue_state = Fun(BQS1)} end. reply(Reply, NewState) -> @@ -156,23 +157,28 @@ noreply(NewState) -> {NewState1, Timeout} = next_state(NewState), {noreply, NewState1, Timeout}. -next_state(State = #q{backing_queue = BQ, backing_queue_state = BQS}) -> - set_sync_timer(ensure_rate_timer(State), BQ:needs_sync(BQS)). +next_state(State) -> + State1 = #q{backing_queue = BQ, backing_queue_state = BQS} = + ensure_rate_timer(State), + case BQ:needs_sync(BQS)of + true -> {ensure_sync_timer(State1), 0}; + false -> {stop_sync_timer(State1), hibernate} + end. -set_sync_timer(State = #q{sync_timer_ref = undefined}, false) -> - {State, hibernate}; -set_sync_timer(State = #q{sync_timer_ref = undefined, - backing_queue = BQ}, true) -> +ensure_sync_timer(State = #q{sync_timer_ref = undefined, backing_queue = BQ}) -> {ok, TRef} = timer:apply_after( ?SYNC_INTERVAL, rabbit_amqqueue, maybe_run_queue_via_backing_queue, [self(), fun (BQS) -> BQ:sync(BQS) end]), - {State#q{sync_timer_ref = TRef}, 0}; -set_sync_timer(State = #q{sync_timer_ref = TRef}, false) -> + State#q{sync_timer_ref = TRef}; +ensure_sync_timer(State) -> + State. + +stop_sync_timer(State = #q{sync_timer_ref = undefined}) -> + State; +stop_sync_timer(State = #q{sync_timer_ref = TRef}) -> {ok, cancel} = timer:cancel(TRef), - {State#q{sync_timer_ref = undefined}, hibernate}; -set_sync_timer(State, _Fun) -> - {State, 0}. + State#q{sync_timer_ref = undefined}. ensure_rate_timer(State = #q{rate_timer_ref = undefined}) -> {ok, TRef} = timer:apply_after( |
