diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2014-09-15 13:13:33 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2014-09-15 13:13:33 +0100 |
commit | c766e3029191e99fdf89e6120c8e034381ddc890 (patch) | |
tree | a10a4eebdde70b6cff84368a7df85197d7654daa | |
parent | 894b6d98993b48ce763d68efc8a6947d20775ad1 (diff) | |
parent | 1642d52183224568471c1210a1ee2b550b44dd6b (diff) | |
download | rabbitmq-server-c766e3029191e99fdf89e6120c8e034381ddc890.tar.gz |
Merge in default
-rw-r--r-- | src/rabbit_amqqueue.erl | 18 | ||||
-rw-r--r-- | src/rabbit_exchange.erl | 19 | ||||
-rw-r--r-- | src/rabbit_misc.erl | 31 |
3 files changed, 39 insertions, 29 deletions
diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 54431bcc..63a9529a 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -421,16 +421,14 @@ crashed_or_recovering(#amqqueue{pid = QPid, slave_pids = []}) -> crashed_or_recovering(_Q) -> recovering. -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 |