diff options
author | Matthias Radestock <matthias@lshift.net> | 2009-01-22 15:54:44 +0000 |
---|---|---|
committer | Matthias Radestock <matthias@lshift.net> | 2009-01-22 15:54:44 +0000 |
commit | 8b9db9c0f50f03ddc794fa9b21ffaacdb70f7563 (patch) | |
tree | ecece9a90926be2f8fbaf16a683b2eaa5dbd7b25 /src/rabbit_exchange.erl | |
parent | dab8b76f56b1f5dcfa55a406a5670ca946c31174 (diff) | |
download | rabbitmq-server-8b9db9c0f50f03ddc794fa9b21ffaacdb70f7563.tar.gz |
don't infer table name from record type in mnesia ops
This is in preparation for prefixing all table names with 'rabbit_' in
order to avoid conflicts with other apps running in the same VM.
This is a fairly straightforward change. The only tricky bit is the
untangling of rabbit_exchange:indexed_delete.
Diffstat (limited to 'src/rabbit_exchange.erl')
-rw-r--r-- | src/rabbit_exchange.erl | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 960e4945..c97b4adc 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -107,14 +107,14 @@ recover() -> fun () -> mnesia:foldl( fun (Exchange, Acc) -> - ok = mnesia:write(Exchange), + ok = mnesia:write(exchange, Exchange, write), Acc end, ok, durable_exchanges), mnesia:foldl( fun (Route, Acc) -> {_, ReverseRoute} = route_with_reverse(Route), - ok = mnesia:write(Route), - ok = mnesia:write(ReverseRoute), + ok = mnesia:write(route, Route, write), + ok = mnesia:write(reverse_route, ReverseRoute, write), Acc end, ok, durable_routes), ok @@ -129,7 +129,7 @@ declare(ExchangeName, Type, Durable, AutoDelete, Args) -> rabbit_misc:execute_mnesia_transaction( fun () -> case mnesia:wread({exchange, ExchangeName}) of - [] -> ok = mnesia:write(Exchange), + [] -> ok = mnesia:write(exchange, Exchange, write), if Durable -> ok = mnesia:write( durable_exchanges, Exchange, write); @@ -173,6 +173,7 @@ lookup_or_die(Name) -> list(VHostPath) -> mnesia:dirty_match_object( + exchange, #exchange{name = rabbit_misc:r(VHostPath, exchange), _ = '_'}). map(VHostPath, F) -> @@ -271,6 +272,7 @@ match_bindings(#exchange{name = Name}, Match) -> [QName || #route{binding = Binding = #binding{ queue_name = QName}} <- mnesia:dirty_match_object( + route, #route{binding = #binding{exchange_name = Name, _ = '_'}}), Match(Binding)] @@ -297,32 +299,35 @@ lookup_qpids(Queues) -> %% to be implemented for 0.91 ? delete_bindings_for_exchange(ExchangeName) -> - indexed_delete( - #route{binding = #binding{exchange_name = ExchangeName, - _ = '_'}}, - fun delete_forward_routes/1, fun mnesia:delete_object/1). + [begin + ok = mnesia:delete_object(reverse_route, reverse_route(Route), write), + ok = delete_forward_routes(Route) + end || Route <- mnesia:match_object( + route, + #route{binding = #binding{exchange_name = ExchangeName, + _ = '_'}}, + read)], + ok. delete_bindings_for_queue(QueueName) -> Exchanges = exchanges_for_queue(QueueName), - indexed_delete( - reverse_route(#route{binding = #binding{queue_name = QueueName, - _ = '_'}}), - fun mnesia:delete_object/1, fun delete_forward_routes/1), + [begin + ok = delete_forward_routes(reverse_route(Route)), + ok = mnesia:delete_object(reverse_route, Route, write) + end || Route <- mnesia:match_object( + reverse_route, + reverse_route( + #route{binding = #binding{queue_name = QueueName, + _ = '_'}}), + write)], [begin [X] = mnesia:read({exchange, ExchangeName}), ok = maybe_auto_delete(X) end || ExchangeName <- Exchanges], ok. -indexed_delete(Match, ForwardsDeleteFun, ReverseDeleteFun) -> - [begin - ok = ReverseDeleteFun(reverse_route(Route)), - ok = ForwardsDeleteFun(Route) - end || Route <- mnesia:match_object(Match)], - ok. - delete_forward_routes(Route) -> - ok = mnesia:delete_object(Route), + ok = mnesia:delete_object(route, Route, write), ok = mnesia:delete_object(durable_routes, Route, write). exchanges_for_queue(QueueName) -> @@ -342,7 +347,7 @@ has_bindings(ExchangeName) -> catch exit:{aborted, {badarg, _}} -> %% work around OTP-7025, which was fixed in R12B-1, by %% falling back on a less efficient method - case mnesia:match_object(MatchHead) of + case mnesia:match_object(route, MatchHead, read) of [] -> false; [_|_] -> true end @@ -400,8 +405,9 @@ sync_binding(ExchangeName, QueueName, RoutingKey, Arguments, Durable, Fun) -> true -> Fun(durable_routes, #route{binding = Binding}, write); false -> ok end, - [ok, ok] = [Fun(element(1, R), R, write) || - R <- tuple_to_list(route_with_reverse(Binding))], + {Route, ReverseRoute} = route_with_reverse(Binding), + ok = Fun(route, Route, write), + ok = Fun(reverse_route, ReverseRoute, write), ok. list_bindings(VHostPath) -> @@ -412,6 +418,7 @@ list_bindings(VHostPath) -> queue_name = QueueName, args = Arguments}} <- mnesia:dirty_match_object( + route, #route{binding = #binding{ exchange_name = rabbit_misc:r(VHostPath, exchange), _ = '_'}, @@ -571,7 +578,7 @@ list_exchange_bindings(ExchangeName) -> #route{binding = #binding{queue_name = QueueName, key = RoutingKey, args = Arguments}} - <- mnesia:dirty_match_object(Route)]. + <- mnesia:dirty_match_object(route, Route)]. % Refactoring is left as an exercise for the reader list_queue_bindings(QueueName) -> @@ -581,4 +588,4 @@ list_queue_bindings(QueueName) -> #route{binding = #binding{exchange_name = ExchangeName, key = RoutingKey, args = Arguments}} - <- mnesia:dirty_match_object(Route)]. + <- mnesia:dirty_match_object(route, Route)]. |