summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2014-09-16 10:46:22 +0100
committerSimon MacMullen <simon@rabbitmq.com>2014-09-16 10:46:22 +0100
commit1c0e3c5594736e970381bf65b5adf49cb03f00fc (patch)
tree66278484c48c42a7771c5b4f0abd7b55cc54e843
parentdefe31cc00085d4a0da526a5cfa0bfb43e2ab23f (diff)
parentc766e3029191e99fdf89e6120c8e034381ddc890 (diff)
downloadrabbitmq-server-1c0e3c5594736e970381bf65b5adf49cb03f00fc.tar.gz
Merge in defaultbug26366
-rw-r--r--src/rabbit_amqqueue.erl18
-rw-r--r--src/rabbit_exchange.erl19
-rw-r--r--src/rabbit_misc.erl31
3 files changed, 39 insertions, 29 deletions
diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl
index 7cf15e70..66f04381 100644
--- a/src/rabbit_amqqueue.erl
+++ b/src/rabbit_amqqueue.erl
@@ -413,16 +413,14 @@ with_or_die(Name, F) ->
({absent, Q, Reason}) -> rabbit_misc:absent(Q, Reason)
end).
-assert_equivalence(#amqqueue{durable = Durable,
- auto_delete = AutoDelete} = Q,
- Durable, AutoDelete, RequiredArgs, Owner) ->
- assert_args_equivalence(Q, RequiredArgs),
- check_exclusive_access(Q, Owner, strict);
-assert_equivalence(#amqqueue{name = QueueName},
- _Durable, _AutoDelete, _RequiredArgs, _Owner) ->
- rabbit_misc:protocol_error(
- precondition_failed, "parameters for ~s not equivalent",
- [rabbit_misc:rs(QueueName)]).
+assert_equivalence(#amqqueue{name = QName,
+ durable = Durable,
+ auto_delete = AD} = Q,
+ Durable1, AD1, Args1, Owner) ->
+ rabbit_misc:assert_field_equivalence(Durable, Durable1, QName, durable),
+ rabbit_misc:assert_field_equivalence(AD, AD1, QName, auto_delete),
+ assert_args_equivalence(Q, Args1),
+ check_exclusive_access(Q, Owner, strict).
check_exclusive_access(Q, Owner) -> check_exclusive_access(Q, Owner, lax).
diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl
index f184174c..5448cb01 100644
--- a/src/rabbit_exchange.erl
+++ b/src/rabbit_exchange.erl
@@ -214,19 +214,18 @@ check_type(TypeBin) ->
end
end.
-assert_equivalence(X = #exchange{ durable = Durable,
+assert_equivalence(X = #exchange{ name = XName,
+ durable = Durable,
auto_delete = AutoDelete,
internal = Internal,
type = Type},
- Type, Durable, AutoDelete, Internal, RequiredArgs) ->
- (type_to_module(Type)):assert_args_equivalence(X, RequiredArgs);
-assert_equivalence(#exchange{ name = Name },
- _Type, _Durable, _Internal, _AutoDelete, _Args) ->
- rabbit_misc:protocol_error(
- precondition_failed,
- "cannot redeclare ~s with different type, durable, "
- "internal or autodelete value",
- [rabbit_misc:rs(Name)]).
+ ReqType, ReqDurable, ReqAutoDelete, ReqInternal, ReqArgs) ->
+ AFE = fun rabbit_misc:assert_field_equivalence/4,
+ AFE(Type, ReqType, XName, type),
+ AFE(Durable, ReqDurable, XName, durable),
+ AFE(AutoDelete, ReqAutoDelete, XName, auto_delete),
+ AFE(Internal, ReqInternal, XName, internal),
+ (type_to_module(Type)):assert_args_equivalence(X, ReqArgs).
assert_args_equivalence(#exchange{ name = Name, arguments = Args },
RequiredArgs) ->
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index 77ac5c44..c5b566de 100644
--- a/src/rabbit_misc.erl
+++ b/src/rabbit_misc.erl
@@ -22,7 +22,7 @@
-export([die/1, frame_error/2, amqp_error/4, quit/1,
protocol_error/3, protocol_error/4, protocol_error/1]).
-export([not_found/1, absent/2]).
--export([type_class/1, assert_args_equivalence/4]).
+-export([type_class/1, assert_args_equivalence/4, assert_field_equivalence/4]).
-export([dirty_read/1]).
-export([table_lookup/2, set_table_value/4]).
-export([r/3, r/2, r_arg/4, rs/1]).
@@ -126,6 +126,9 @@
rabbit_framing:amqp_table(),
rabbit_types:r(any()), [binary()]) ->
'ok' | rabbit_types:connection_exit()).
+-spec(assert_field_equivalence/4 ::
+ (any(), any(), rabbit_types:r(any()), atom()) ->
+ 'ok' | rabbit_types:connection_exit()).
-spec(dirty_read/1 ::
({atom(), any()}) -> rabbit_types:ok_or_error2(any(), 'not_found')).
-spec(table_lookup/2 ::
@@ -321,11 +324,6 @@ assert_args_equivalence(Orig, New, Name, Keys) ->
assert_args_equivalence1(Orig, New, Name, Key) ->
{Orig1, New1} = {table_lookup(Orig, Key), table_lookup(New, Key)},
- FailureFun = fun () ->
- protocol_error(precondition_failed, "inequivalent arg '~s'"
- "for ~s: received ~s but current is ~s",
- [Key, rs(Name), val(New1), val(Orig1)])
- end,
case {Orig1, New1} of
{Same, Same} ->
ok;
@@ -333,12 +331,22 @@ assert_args_equivalence1(Orig, New, Name, Key) ->
case type_class(OrigType) == type_class(NewType) andalso
OrigVal == NewVal of
true -> ok;
- false -> FailureFun()
+ false -> assert_field_equivalence(OrigVal, NewVal, Name, Key)
end;
{_, _} ->
- FailureFun()
+ assert_field_equivalence(Orig, New, Name, Key)
end.
+assert_field_equivalence(_Orig, _Orig, _Name, _Key) ->
+ ok;
+assert_field_equivalence(Orig, New, Name, Key) ->
+ equivalence_fail(Orig, New, Name, Key).
+
+equivalence_fail(Orig, New, Name, Key) ->
+ protocol_error(precondition_failed, "inequivalent arg '~s' "
+ "for ~s: received ~s but current is ~s",
+ [Key, rs(Name), val(New), val(Orig)]).
+
val(undefined) ->
"none";
val({Type, Value}) ->
@@ -346,7 +354,12 @@ val({Type, Value}) ->
true -> "~s";
false -> "~w"
end,
- format("the value '" ++ ValFmt ++ "' of type '~s'", [Value, Type]).
+ format("the value '" ++ ValFmt ++ "' of type '~s'", [Value, Type]);
+val(Value) ->
+ format(case is_binary(Value) of
+ true -> "'~s'";
+ false -> "'~w'"
+ end, [Value]).
%% Normally we'd call mnesia:dirty_read/1 here, but that is quite
%% expensive due to general mnesia overheads (figuring out table types