summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2012-10-31 23:37:06 +0000
committerMatthias Radestock <matthias@rabbitmq.com>2012-10-31 23:37:06 +0000
commit5effb392824fd27d2e3fea03004875283d36fbca (patch)
tree9c15559acef90ec4229f35f111a9cf0e95159457
parent3f7001b1961a911168396b12484dcdad9b88d17d (diff)
downloadrabbitmq-server-bug25164.tar.gz
refactor: s/lookup_absent/not_found_or_absentbug25164
and s/not_found_or_absent/not_found_or_absent_dirty and make the signatures match
-rw-r--r--src/rabbit_amqqueue.erl32
-rw-r--r--src/rabbit_binding.erl6
2 files changed, 17 insertions, 21 deletions
diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl
index 2876550e..621da633 100644
--- a/src/rabbit_amqqueue.erl
+++ b/src/rabbit_amqqueue.erl
@@ -18,7 +18,7 @@
-export([start/0, stop/0, declare/5, delete_immediately/1, delete/3, purge/1]).
-export([pseudo_queue/2]).
--export([lookup/1, lookup_absent/1, with/2, with/3, with_or_die/2,
+-export([lookup/1, not_found_or_absent/1, with/2, with/3, with_or_die/2,
assert_equivalence/5,
check_exclusive_access/2, with_exclusive_access_or_die/3,
stat/1, deliver/2, deliver_flow/2, requeue/3, ack/3, reject/4]).
@@ -83,9 +83,7 @@
(name()) -> rabbit_types:ok(rabbit_types:amqqueue()) |
rabbit_types:error('not_found');
([name()]) -> [rabbit_types:amqqueue()]).
--spec(lookup_absent/1 ::
- (name()) -> rabbit_types:ok(rabbit_types:amqqueue()) |
- rabbit_types:error('not_found')).
+-spec(not_found_or_absent/1 :: (name()) -> not_found_or_absent()).
-spec(with/2 :: (name(), qfun(A)) ->
A | rabbit_types:error(not_found_or_absent())).
-spec(with/3 :: (name(), qfun(A), fun((not_found_or_absent()) -> B)) -> A | B).
@@ -241,14 +239,12 @@ internal_declare(Q = #amqqueue{name = QueueName}, false) ->
fun () ->
case mnesia:wread({rabbit_queue, QueueName}) of
[] ->
- case lookup_absent(QueueName) of
- {error, not_found} ->
- Q1 = rabbit_policy:set(Q),
- ok = store_queue(Q1),
- B = add_default_binding(Q1),
- fun () -> B(), Q1 end;
- {ok, Q1} ->
- rabbit_misc:const({absent, Q1})
+ case not_found_or_absent(QueueName) of
+ not_found -> Q1 = rabbit_policy:set(Q),
+ ok = store_queue(Q1),
+ B = add_default_binding(Q1),
+ fun () -> B(), Q1 end;
+ {absent, _Q} = R -> rabbit_misc:const(R)
end;
[ExistingQ = #amqqueue{pid = QPid}] ->
case rabbit_misc:is_process_alive(QPid) of
@@ -302,15 +298,15 @@ lookup(Names) when is_list(Names) ->
lookup(Name) ->
rabbit_misc:dirty_read({rabbit_queue, Name}).
-lookup_absent(Name) ->
+not_found_or_absent(Name) ->
%% NB: we assume that the caller has already performed a lookup on
%% rabbit_queue and not found anything
case mnesia:read({rabbit_durable_queue, Name}) of
- [] -> {error, not_found};
- [Q] -> {ok, Q} %% Q exists on stopped node
+ [] -> not_found;
+ [Q] -> {absent, Q} %% Q exists on stopped node
end.
-not_found_or_absent(Name) ->
+not_found_or_absent_dirty(Name) ->
%% We should read from both tables inside a tx, to get a
%% consistent view. But the chances of an inconsistency are small,
%% and only affect the error kind.
@@ -328,13 +324,13 @@ with(Name, F, E) ->
rabbit_misc:with_exit_handler(
fun () ->
case rabbit_misc:is_process_alive(QPid) of
- true -> E(not_found_or_absent(Name));
+ true -> E(not_found_or_absent_dirty(Name));
false -> timer:sleep(25),
with(Name, F, E)
end
end, fun () -> F(Q) end);
{error, not_found} ->
- E(not_found_or_absent(Name))
+ E(not_found_or_absent_dirty(Name))
end.
with(Name, F) -> with(Name, F, fun (E) -> {error, E} end).
diff --git a/src/rabbit_binding.erl b/src/rabbit_binding.erl
index 1375facb..2d486651 100644
--- a/src/rabbit_binding.erl
+++ b/src/rabbit_binding.erl
@@ -353,9 +353,9 @@ table_for_resource(#resource{kind = queue}) -> rabbit_queue.
not_found_or_absent(#resource{kind = exchange} = Name) ->
{not_found, Name};
not_found_or_absent(#resource{kind = queue} = Name) ->
- case rabbit_amqqueue:lookup_absent(Name) of
- {error, not_found} -> {not_found, Name};
- {ok, Q} -> {absent, Q}
+ case rabbit_amqqueue:not_found_or_absent(Name) of
+ not_found -> {not_found, Name};
+ {absent, _Q} = R -> R
end.
contains(Table, MatchHead) ->