diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2011-04-05 13:27:17 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2011-04-05 13:27:17 +0100 |
commit | b010416a0a2ebf15cae4d4da211486a12f80b2aa (patch) | |
tree | 4ccb9e95d201779227737a2dff5c5e1a1b1c3cbb | |
parent | 050dc7df7081db4054191503e6b2dfe2e07ec901 (diff) | |
download | rabbitmq-server-b010416a0a2ebf15cae4d4da211486a12f80b2aa.tar.gz |
Recover and invoke callbacks for bindings in the same Tx.
-rw-r--r-- | src/rabbit_binding.erl | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/src/rabbit_binding.erl b/src/rabbit_binding.erl index 563fc0cf..7c492778 100644 --- a/src/rabbit_binding.erl +++ b/src/rabbit_binding.erl @@ -95,32 +95,29 @@ routing_key, arguments]). recover(XNames, QNames) -> - XNameSet = sets:from_list(XNames), - QNameSet = sets:from_list(QNames), XBs = rabbit_misc:execute_mnesia_transaction( fun () -> - lists:foldl( - fun (Route = #route{ - binding = B = #binding{source = Src}}, Acc) -> - case should_recover(B, XNameSet, QNameSet) of - true -> ok = sync_transient_binding( - Route, fun mnesia:write/3), - rabbit_misc:dict_cons(Src, B, Acc); - false -> Acc - end - end, dict:new(), - mnesia:select(rabbit_durable_route, [{'$1', [], ['$1']}])) + XBs = recover_internal(XNames, QNames), + callback_bindings(true, XBs), + XBs end), - rabbit_misc:execute_pre_post_mnesia_tx( - fun (Tx) -> - dict:map(fun (XName, Bindings) -> - {ok, X} = rabbit_exchange:lookup(XName), - rabbit_exchange:callback(X, add_bindings, - [Tx, X, Bindings]) - end, XBs) - end), + callback_bindings(false, XBs), ok. +recover_internal(XNames, QNames) -> + XNameSet = sets:from_list(XNames), + QNameSet = sets:from_list(QNames), + lists:foldl( + fun (Route = #route{binding = B = #binding{source = Src}}, Acc) -> + case should_recover(B, XNameSet, QNameSet) of + true -> ok = sync_transient_binding( + Route, fun mnesia:write/3), + rabbit_misc:dict_cons(Src, B, Acc); + false -> Acc + end + end, dict:new(), + mnesia:select(rabbit_durable_route, [{'$1', [], ['$1']}])). + should_recover(B = #binding{destination = Dst = #resource{ kind = Kind }}, XNameSet, QNameSet) -> case mnesia:read({rabbit_route, B}) of @@ -131,6 +128,13 @@ should_recover(B = #binding{destination = Dst = #resource{ kind = Kind }}, _ -> false end. +callback_bindings(Tx, XBs) -> + dict:map(fun (XName, Bindings) -> + {ok, X} = rabbit_exchange:lookup(XName), + rabbit_exchange:callback(X, add_bindings, + [Tx, X, Bindings]) + end, XBs). + exists(Binding) -> binding_action( Binding, fun (_Src, _Dst, B) -> |