diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2011-07-05 18:30:53 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2011-07-05 18:30:53 +0100 |
commit | 4090592bac7107e5a4480def2432b2638ce5618e (patch) | |
tree | e86090bbb455d6d12b594806a489e510e10ef41f | |
parent | 6757adac1ca87455fb9c89ecf1219f5d0ae645ab (diff) | |
download | rabbitmq-server-4090592bac7107e5a4480def2432b2638ce5618e.tar.gz |
Inline rabbit_misc:table_filter, then fiddle with it until it's actually right. To say this could do with some beautification is an understatement.
-rw-r--r-- | src/rabbit_binding.erl | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/src/rabbit_binding.erl b/src/rabbit_binding.erl index 5873537c..21251dae 100644 --- a/src/rabbit_binding.erl +++ b/src/rabbit_binding.erl @@ -105,25 +105,41 @@ recover(XNames, QNames) -> (_Route, false) -> ok end, rabbit_durable_route), - rabbit_misc:table_filter( - fun (#route{binding = #binding{destination = Dst = - #resource{kind = Kind}}}) -> - sets:is_element(Dst, case Kind of - exchange -> XNameSet; - queue -> QNameSet - end) - end, - fun (R = #route{binding = B = #binding{source = Src}}, Tx) -> - {ok, X} = rabbit_exchange:lookup(Src), - Serial = case Tx of - true -> ok = sync_transient_route( - R, fun mnesia:write/3), - transaction; - false -> rabbit_exchange:serial(X) - end, - rabbit_exchange:callback(X, add_binding, [Serial, X, B]) - end, - rabbit_semi_durable_route), + lists:foldl( + fun (R = #route{binding = B = #binding{source = Src, + destination = Dst = + #resource{kind = Kind}}}, Acc) -> + case rabbit_misc:execute_mnesia_transaction( + fun () -> + case mnesia:match_object( + rabbit_semi_durable_route, R, read) =/= [] + andalso sets:is_element( + Dst, case Kind of + exchange -> XNameSet; + queue -> QNameSet + end) of + false -> false; + true -> {ok, X} = rabbit_exchange:lookup(Src), + {true, rabbit_exchange:serial(X)} + end + end, + fun (false, _Tx) -> + false; + ({true, Serial0}, Tx) -> + Serial = case Tx of + true -> ok = sync_transient_route( + R, fun mnesia:write/3), + transaction; + false -> Serial0 + end, + {ok, X} = rabbit_exchange:lookup(Src), + rabbit_exchange:callback(X, add_binding, [Serial, X, B]), + true + end) of + false -> Acc; + true -> [R | Acc] + end + end, [], rabbit_misc:dirty_read_all(rabbit_semi_durable_route)), ok. exists(Binding) -> |