diff options
| author | Diana Corbacho <diana.corbacho@erlang-solutions.com> | 2016-01-07 11:03:27 +0100 |
|---|---|---|
| committer | Diana Corbacho <diana.corbacho@erlang-solutions.com> | 2016-01-07 11:03:27 +0100 |
| commit | 203ac917ab6736d1d09b4c7a14121b309529e947 (patch) | |
| tree | 556b95fdfde42470c1974804d262b945f8b18049 /src | |
| parent | 0c4d9a0d88e15394889e69a426cf3a8fce149257 (diff) | |
| download | rabbitmq-server-git-203ac917ab6736d1d09b4c7a14121b309529e947.tar.gz | |
Set deleting exchange status
* Avoids race condition between declare and delete
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_exchange.erl | 52 | ||||
| -rw-r--r-- | src/rabbit_exchange_parameters.erl | 40 |
2 files changed, 73 insertions, 19 deletions
diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 9502f3a78a..842aff9b19 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -166,24 +166,32 @@ declare(XName, Type, Durable, AutoDelete, Internal, Args) -> XT = type_to_module(Type), %% We want to upset things if it isn't ok ok = XT:validate(X), - rabbit_misc:execute_mnesia_transaction( - fun () -> - case mnesia:wread({rabbit_exchange, XName}) of - [] -> - {new, store(X)}; - [ExistingX] -> - {existing, ExistingX} - end - end, - fun ({new, Exchange}, Tx) -> - ok = callback(X, create, map_create_tx(Tx), [Exchange]), - rabbit_event:notify_if(not Tx, exchange_created, info(Exchange)), - Exchange; - ({existing, Exchange}, _Tx) -> - Exchange; - (Err, _Tx) -> - Err - end). + case rabbit_runtime_parameters:lookup(XName#resource.virtual_host, + <<"exchange-delete">>, + XName#resource.name) of + not_found -> + rabbit_misc:execute_mnesia_transaction( + fun () -> + case mnesia:wread({rabbit_exchange, XName}) of + [] -> + {new, store(X)}; + [ExistingX] -> + {existing, ExistingX} + end + end, + fun ({new, Exchange}, Tx) -> + ok = callback(X, create, map_create_tx(Tx), [Exchange]), + rabbit_event:notify_if(not Tx, exchange_created, info(Exchange)), + Exchange; + ({existing, Exchange}, _Tx) -> + Exchange; + (Err, _Tx) -> + Err + end); + _ -> + rabbit_log:warning("Delete in progress ~p.~n.", [XName]), + X + end. map_create_tx(true) -> transaction; map_create_tx(false) -> none. @@ -427,6 +435,9 @@ delete(XName, IfUnused) -> true -> fun conditional_delete/2; false -> fun unconditional_delete/2 end, + rabbit_runtime_parameters:set(XName#resource.virtual_host, + <<"exchange-delete">>, + XName#resource.name, true, none), call_with_exchange( XName, fun (X) -> @@ -438,7 +449,10 @@ delete(XName, IfUnused) -> {error, _InUseOrNotFound} = E -> rabbit_misc:const(E) end - end). + end), + rabbit_runtime_parameters:clear(XName#resource.virtual_host, + <<"exchange-delete">>, + XName#resource.name). validate_binding(X = #exchange{type = XType}, Binding) -> Module = type_to_module(XType), diff --git a/src/rabbit_exchange_parameters.erl b/src/rabbit_exchange_parameters.erl new file mode 100644 index 0000000000..793c06007a --- /dev/null +++ b/src/rabbit_exchange_parameters.erl @@ -0,0 +1,40 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is GoPivotal, Inc. +%% Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved. +%% + +-module(rabbit_exchange_parameters). + +-behaviour(rabbit_runtime_parameter). + +-export([register/0]). +-export([validate/5, notify/4, notify_clear/3]). + +-rabbit_boot_step({?MODULE, + [{description, "exchange parameters"}, + {mfa, {rabbit_exchange_parameters, register, []}}, + {requires, rabbit_registry}, + {enables, recovery}]}). + +register() -> + rabbit_registry:register(runtime_parameter, <<"exchange-delete">>, ?MODULE). + +validate(_VHost, <<"exchange-delete">>, _Name, _Term, _User) -> + ok. + +notify(_VHost, <<"exchange-delete">>, _Name, _Term) -> + ok. + +notify_clear(_VHost, <<"exchange-delete">>, _Name) -> + ok. |
