Skip to content

Commit 10e0979

Browse files
author
Matthew Sackman
committed
Avoid unnecessary mnesia lookup and significantly simplify queue declaration code
1 parent 3cbacf0 commit 10e0979

File tree

1 file changed

+24
-33
lines changed

1 file changed

+24
-33
lines changed

src/rabbit_channel.erl

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -726,42 +726,33 @@ handle_method(#'queue.declare'{queue = QueueNameBin,
726726
end,
727727
%% We use this in both branches, because queue_declare may yet return an
728728
%% existing queue.
729-
Finish = fun (#amqqueue{name = QueueName,
730-
durable = Durable1,
731-
auto_delete = AutoDelete1} = Q)
732-
when Durable =:= Durable1, AutoDelete =:= AutoDelete1 ->
733-
check_exclusive_access(Q, Owner, strict),
734-
check_configure_permitted(QueueName, State),
735-
%% We need to notify the reader within the channel
736-
%% process so that we can be sure there are no
737-
%% outstanding exclusive queues being declared as the
738-
%% connection shuts down.
739-
case Owner of
740-
none -> ok;
741-
_ -> ok = rabbit_reader_queue_collector:register_exclusive_queue(CollectorPid, Q)
742-
end,
743-
Q;
744-
%% non-equivalence trumps exclusivity arbitrarily
745-
(#amqqueue{name = QueueName}) ->
746-
rabbit_misc:protocol_error(
747-
precondition_failed,
748-
"parameters for ~s not equivalent",
749-
[rabbit_misc:rs(QueueName)])
750-
end,
751-
Q = case rabbit_amqqueue:with(
752-
rabbit_misc:r(VHostPath, queue, QueueNameBin),
753-
Finish) of
754-
{error, not_found} ->
755-
ActualNameBin =
756-
case QueueNameBin of
729+
ActualNameBin = case QueueNameBin of
757730
<<>> -> rabbit_guid:binstring_guid("amq.gen");
758731
Other -> check_name('queue', Other)
759732
end,
760-
QueueName = rabbit_misc:r(VHostPath, queue, ActualNameBin),
761-
Finish(rabbit_amqqueue:declare(QueueName, Durable, AutoDelete,
762-
Args, Owner));
763-
#amqqueue{} = Other ->
764-
Other
733+
QueueName = rabbit_misc:r(VHostPath, queue, ActualNameBin),
734+
Q = case rabbit_amqqueue:declare(QueueName, Durable, AutoDelete,
735+
Args, Owner) of
736+
#amqqueue{name = QueueName,
737+
durable = Durable1,
738+
auto_delete = AutoDelete1} = Q1
739+
when Durable =:= Durable1, AutoDelete =:= AutoDelete1 ->
740+
check_exclusive_access(Q1, Owner, strict),
741+
check_configure_permitted(QueueName, State),
742+
%% We need to notify the reader within the channel
743+
%% process so that we can be sure there are no
744+
%% outstanding exclusive queues being declared as the
745+
%% connection shuts down.
746+
case Owner of
747+
none -> ok;
748+
_ -> ok = rabbit_reader_queue_collector:register_exclusive_queue(CollectorPid, Q1)
749+
end,
750+
Q1;
751+
%% non-equivalence trumps exclusivity arbitrarily
752+
#amqqueue{name = QueueName} ->
753+
rabbit_misc:protocol_error(
754+
precondition_failed, "parameters for ~s not equivalent",
755+
[rabbit_misc:rs(QueueName)])
765756
end,
766757
return_queue_declare_ok(State, NoWait, Q);
767758

0 commit comments

Comments
 (0)