summaryrefslogtreecommitdiff
path: root/src/rabbit_msg_store_gc.erl
diff options
context:
space:
mode:
authorMatthew Sackman <matthew@rabbitmq.com>2010-10-18 17:38:36 +0100
committerMatthew Sackman <matthew@rabbitmq.com>2010-10-18 17:38:36 +0100
commit21c2f178f8a75307e3dc80c16c990d89be38d201 (patch)
tree61053a213fd9070184ce186f9c5e14b0864f9a79 /src/rabbit_msg_store_gc.erl
parent2079d264fe62d26108db8da3a5f535e04fd0e221 (diff)
downloadrabbitmq-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.erl37
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.