diff options
author | Matthew Sackman <matthew@rabbitmq.com> | 2010-10-18 17:38:36 +0100 |
---|---|---|
committer | Matthew Sackman <matthew@rabbitmq.com> | 2010-10-18 17:38:36 +0100 |
commit | 21c2f178f8a75307e3dc80c16c990d89be38d201 (patch) | |
tree | 61053a213fd9070184ce186f9c5e14b0864f9a79 /src/rabbit_msg_store_gc.erl | |
parent | 2079d264fe62d26108db8da3a5f535e04fd0e221 (diff) | |
download | rabbitmq-server-21c2f178f8a75307e3dc80c16c990d89be38d201.tar.gz |
Further abstract gc to permit different types of actions
Diffstat (limited to 'src/rabbit_msg_store_gc.erl')
-rw-r--r-- | src/rabbit_msg_store_gc.erl | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/rabbit_msg_store_gc.erl b/src/rabbit_msg_store_gc.erl index 3b98e1df..37b82cef 100644 --- a/src/rabbit_msg_store_gc.erl +++ b/src/rabbit_msg_store_gc.erl @@ -96,16 +96,16 @@ handle_call(stop, _From, State) -> {stop, normal, ok, State}. handle_cast({gc, Source, Destination}, State) -> - {noreply, attempt_gc(Source, Destination, State), hibernate}; + {noreply, attempt_action(gc, [Source, Destination], State), hibernate}; handle_cast({no_readers, File}, State = #state { pending_no_readers = Pending }) -> State1 = case dict:find(File, Pending) of error -> State; - {ok, {Source, Destination}} -> - attempt_gc( - Source, Destination, + {ok, {Action, Files}} -> + attempt_action( + Action, Files, State #state { pending_no_readers = dict:erase(File, Pending) }) end, @@ -124,20 +124,21 @@ terminate(_Reason, State) -> code_change(_OldVsn, State, _Extra) -> {ok, State}. -attempt_gc(Source, Destination, - State = #state { parent = Parent, - pending_no_readers = Pending, - msg_store_state = MsgStoreState }) -> +attempt_action(Action, Files, + State = #state { pending_no_readers = Pending, + msg_store_state = MsgStoreState }) -> case lists:filter(fun (File) -> rabbit_msg_store:has_readers(File, MsgStoreState) - end, [Source, Destination]) of - [] -> - Reclaimed = rabbit_msg_store:gc(Source, Destination, MsgStoreState), - ok = rabbit_msg_store:gc_done(Parent, Reclaimed, Source, - Destination), - State; - [File | _] -> - State #state { pending_no_readers = - dict:store(File, {Source, Destination}, Pending) - } + end, Files) of + [] -> do_action(Action, Files, State); + [File | _] -> State #state { + pending_no_readers = + dict:store(File, {Action, Files}, Pending) } end. + +do_action(gc, [Source, Destination], + State = #state { parent = Parent, + msg_store_state = MsgStoreState }) -> + Reclaimed = rabbit_msg_store:gc(Source, Destination, MsgStoreState), + ok = rabbit_msg_store:gc_done(Parent, Reclaimed, Source, Destination), + State. |