diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2013-10-28 17:08:55 +0000 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2013-10-28 17:08:55 +0000 |
commit | 2a004a1006a960411f203cc3280592ef4a227bc0 (patch) | |
tree | 673ef2a8acd1b0113f96920b34c82528aa5e2c93 | |
parent | 3777b5c641be257d62d9a4c1a7736bb6aed1c436 (diff) | |
download | rabbitmq-server-2a004a1006a960411f203cc3280592ef4a227bc0.tar.gz |
Use mnesia:async_dirty/1 to reduce copypasta.
-rw-r--r-- | src/rabbit_amqqueue.erl | 12 | ||||
-rw-r--r-- | src/rabbit_exchange.erl | 12 | ||||
-rw-r--r-- | src/rabbit_policy.erl | 52 | ||||
-rw-r--r-- | src/rabbit_runtime_parameters.erl | 9 |
4 files changed, 39 insertions, 46 deletions
diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 8a84c9f4..96bf8f12 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -23,7 +23,8 @@ 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]). --export([list/0, list/1, info_keys/0, info/1, info/2, info_all/1, info_all/2]). +-export([list/0, list/1, list_tx/1, + info_keys/0, info/1, info/2, info_all/1, info_all/2]). -export([force_event_refresh/0, notify_policy_changed/1]). -export([consumers/1, consumers_all/1, consumer_info_keys/0]). -export([basic_get/4, basic_consume/10, basic_cancel/4, notify_decorators/1]). @@ -103,6 +104,7 @@ (name(), pid(), qfun(A)) -> A | rabbit_types:channel_exit()). -spec(list/0 :: () -> [rabbit_types:amqqueue()]). -spec(list/1 :: (rabbit_types:vhost()) -> [rabbit_types:amqqueue()]). +-spec(list_tx/1 :: (rabbit_types:vhost()) -> [rabbit_types:amqqueue()]). -spec(info_keys/0 :: () -> rabbit_types:info_keys()). -spec(info/1 :: (rabbit_types:amqqueue()) -> rabbit_types:infos()). -spec(info/2 :: @@ -466,10 +468,12 @@ check_dlxrk_arg({Type, _}, _Args) -> list() -> mnesia:dirty_match_object(rabbit_queue, #amqqueue{_ = '_'}). -list(VHostPath) -> - mnesia:dirty_match_object( +list(VHostPath) -> mnesia:async_dirty(fun () -> list_tx(VHostPath) end). + +list_tx(VHostPath) -> + mnesia:match_object( rabbit_queue, - #amqqueue{name = rabbit_misc:r(VHostPath, queue), _ = '_'}). + #amqqueue{name = rabbit_misc:r(VHostPath, queue), _ = '_'}, read). info_keys() -> rabbit_amqqueue_process:info_keys(). diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index fc131519..52d542df 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -20,7 +20,8 @@ -export([recover/0, policy_changed/2, callback/4, declare/6, assert_equivalence/6, assert_args_equivalence/2, check_type/1, - lookup/1, lookup_or_die/1, list/1, lookup_scratch/2, update_scratch/3, + lookup/1, lookup_or_die/1, list/1, list_tx/1, + lookup_scratch/2, update_scratch/3, info_keys/0, info/1, info/2, info_all/1, info_all/2, route/2, delete/2, validate_binding/2]). %% these must be run inside a mnesia tx @@ -62,6 +63,7 @@ (name()) -> rabbit_types:exchange() | rabbit_types:channel_exit()). -spec(list/1 :: (rabbit_types:vhost()) -> [rabbit_types:exchange()]). +-spec(list_tx/1 :: (rabbit_types:vhost()) -> [rabbit_types:exchange()]). -spec(lookup_scratch/2 :: (name(), atom()) -> rabbit_types:ok(term()) | rabbit_types:error('not_found')). @@ -244,10 +246,12 @@ lookup_or_die(Name) -> {error, not_found} -> rabbit_misc:not_found(Name) end. -list(VHostPath) -> - mnesia:dirty_match_object( +list(VHostPath) -> mnesia:async_dirty(fun () -> list_tx(VHostPath) end). + +list_tx(VHostPath) -> + mnesia:match_object( rabbit_exchange, - #exchange{name = rabbit_misc:r(VHostPath, exchange), _ = '_'}). + #exchange{name = rabbit_misc:r(VHostPath, exchange), _ = '_'}, read). lookup_scratch(Name, App) -> case lookup(Name) of diff --git a/src/rabbit_policy.erl b/src/rabbit_policy.erl index db6d042b..6e75792e 100644 --- a/src/rabbit_policy.erl +++ b/src/rabbit_policy.erl @@ -167,11 +167,18 @@ list() -> list(VHost) -> list0(VHost, fun ident/1). +list_tx(VHost) -> + list0_tx(VHost, fun ident/1). + list_formatted(VHost) -> order_policies(list0(VHost, fun format/1)). list0(VHost, DefnFun) -> - [p(P, DefnFun) || P <- rabbit_runtime_parameters:list(VHost, <<"policy">>)]. + mnesia:async_dirty(fun () -> list0_tx(VHost, DefnFun) end). + +list0_tx(VHost, DefnFun) -> + [p(P, DefnFun) || + P <- rabbit_runtime_parameters:list_tx(VHost, <<"policy">>)]. order_policies(PropList) -> lists:sort(fun (A, B) -> pget(priority, A) < pget(priority, B) end, @@ -209,45 +216,18 @@ notify_clear(VHost, <<"policy">>, _Name) -> %%---------------------------------------------------------------------------- update_policies(VHost) -> - F = fun() -> - Policies = list_tx(VHost), - Xs = mnesia:match_object( - rabbit_exchange, - #exchange{name = rabbit_misc:r(VHost, exchange), - _ = '_'}, - read), - Qs = mnesia:match_object( - rabbit_queue, - #amqqueue{name = rabbit_misc:r(VHost, queue), - _ = '_'}, - read), - {[update_exchange(X, Policies) || X <- Xs], - [update_queue(Q, Policies) || Q <- Qs]} - end, - {Xs, Qs} = rabbit_misc:execute_mnesia_transaction(F), + {Xs, Qs} = rabbit_misc:execute_mnesia_transaction( + fun() -> + Policies = list_tx(VHost), + {[update_exchange(X, Policies) || + X <- rabbit_exchange:list_tx(VHost)], + [update_queue(Q, Policies) || + Q <- rabbit_amqqueue:list_tx(VHost)]} + end), [catch notify(X) || X <- Xs], [catch notify(Q) || Q <- Qs], ok. -list_tx(VHost) -> - [p(P, fun ident/1) || P <- list_p(VHost, <<"policy">>)]. - -list_p(VHost, Component) -> - case VHost of - '_' -> ok; - _ -> rabbit_vhost:assert(VHost) - end, - Match = #runtime_parameters{key = {VHost, Component, '_'}, _ = '_'}, - [p_p(P) || #runtime_parameters{key = {_VHost, Comp, _Name}} = P <- - mnesia:match_object(rabbit_runtime_parameters, Match, read), - Comp =/= <<"policy">> orelse Component =:= <<"policy">>]. - -p_p(#runtime_parameters{key = {VHost, Component, Name}, value = Value}) -> - [{vhost, VHost}, - {component, Component}, - {name, Name}, - {value, Value}]. - update_exchange(X = #exchange{name = XName, policy = OldPolicy}, Policies) -> case match(XName, Policies) of OldPolicy -> no_change; diff --git a/src/rabbit_runtime_parameters.erl b/src/rabbit_runtime_parameters.erl index c13c333e..4e4be6bc 100644 --- a/src/rabbit_runtime_parameters.erl +++ b/src/rabbit_runtime_parameters.erl @@ -19,7 +19,7 @@ -include("rabbit.hrl"). -export([parse_set/4, set/4, set_any/4, clear/3, clear_any/3, list/0, list/1, - list_component/1, list/2, list_formatted/1, lookup/3, + list_component/1, list/2, list_tx/2, list_formatted/1, lookup/3, value/3, value/4, info_keys/0]). %%---------------------------------------------------------------------------- @@ -43,6 +43,8 @@ -spec(list_component/1 :: (binary()) -> [rabbit_types:infos()]). -spec(list/2 :: (rabbit_types:vhost() | '_', binary() | '_') -> [rabbit_types:infos()]). +-spec(list_tx/2 :: (rabbit_types:vhost() | '_', binary() | '_') + -> [rabbit_types:infos()]). -spec(list_formatted/1 :: (rabbit_types:vhost()) -> [rabbit_types:infos()]). -spec(lookup/3 :: (rabbit_types:vhost(), binary(), binary()) -> rabbit_types:infos() | 'not_found'). @@ -140,13 +142,16 @@ list(VHost) -> list(VHost, '_'). list_component(Component) -> list('_', Component). list(VHost, Component) -> + mnesia:async_dirty(fun () -> list_tx(VHost, Component) end). + +list_tx(VHost, Component) -> case VHost of '_' -> ok; _ -> rabbit_vhost:assert(VHost) end, Match = #runtime_parameters{key = {VHost, Component, '_'}, _ = '_'}, [p(P) || #runtime_parameters{key = {_VHost, Comp, _Name}} = P <- - mnesia:dirty_match_object(?TABLE, Match), + mnesia:match_object(?TABLE, Match, read), Comp =/= <<"policy">> orelse Component =:= <<"policy">>]. list_formatted(VHost) -> |