summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Sackman <matthew@lshift.net>2010-01-08 17:53:06 +0000
committerMatthew Sackman <matthew@lshift.net>2010-01-08 17:53:06 +0000
commite4b3284c281268c7cdf86117bbc2f1c79f55142b (patch)
treecafd2ed5853ab1292fb55c21917ab252cf2f785b
parentc9daa780ac0b11a7a19d756d2d97f8a64865c92c (diff)
downloadrabbitmq-server-git-e4b3284c281268c7cdf86117bbc2f1c79f55142b.tar.gz
Correct the closing mech. Sadly I'm currently scanning the whole table every time, which is bad. I might change that to scan every, say, 1000 reads
-rw-r--r--src/rabbit_msg_store.erl39
1 files changed, 17 insertions, 22 deletions
diff --git a/src/rabbit_msg_store.erl b/src/rabbit_msg_store.erl
index 3a6450596f..b66564bb06 100644
--- a/src/rabbit_msg_store.erl
+++ b/src/rabbit_msg_store.erl
@@ -270,26 +270,14 @@ read(MsgId, CState) ->
false ->
%% ok, we're definitely safe to
%% continue - a GC can't start up
- %% now
- Self = self(),
- CState1 =
- case ets:lookup(?FILE_HANDLES_ETS_NAME,
- {File, self()}) of
- [{Key, close}] ->
- CState2 =
- close_handle(File, CState),
- true = ets:insert(
- ?FILE_HANDLES_ETS_NAME,
- {Key, open}),
- CState2;
- [{_Key, open}] ->
- CState;
- [] ->
- true = ets:insert_new(
- ?FILE_HANDLES_ETS_NAME,
- {{File, Self}, open}),
- CState
- end,
+ %% now, and isn't running, so
+ %% nothing will tell us from now
+ %% on to close the handle if it's
+ %% already open.
+ %% this is fine to fail (already exists)
+ ets:insert_new(?FILE_HANDLES_ETS_NAME,
+ {{File, self()}, open}),
+ CState1 = close_all_indicated(CState),
{Hdl, CState3} =
get_read_handle(File, CState1),
{ok, Offset} =
@@ -331,6 +319,13 @@ read(MsgId, CState) ->
end
end.
+close_all_indicated(CState) ->
+ Objs = ets:match_object(?FILE_HANDLES_ETS_NAME, {{'_', self()}, close}),
+ lists:foldl(fun ({Key = {File, _Self}, close}, CStateM) ->
+ true = ets:delete(?FILE_HANDLES_ETS_NAME, Key),
+ close_handle(File, CStateM)
+ end, CState, Objs).
+
contains(MsgId) -> gen_server2:call(?SERVER, {contains, MsgId}, infinity).
remove(MsgIds) -> gen_server2:cast(?SERVER, {remove, MsgIds}).
release(MsgIds) -> gen_server2:cast(?SERVER, {release, MsgIds}).
@@ -1119,7 +1114,7 @@ maybe_compact(State) ->
mark_handle_to_close(File) ->
lists:foldl(
- fun ({Key, opened}, true) ->
+ fun ({Key, open}, true) ->
try
true = ets:update_element(?FILE_HANDLES_ETS_NAME,
Key, {2, close})
@@ -1127,7 +1122,7 @@ mark_handle_to_close(File) ->
true
end
end,
- true, ets:match_object(?FILE_HANDLES_ETS_NAME, {{File, '_'}, opened})).
+ true, ets:match_object(?FILE_HANDLES_ETS_NAME, {{File, '_'}, open})).
find_files_to_gc(_N, '$end_of_table') ->
undefined;