diff options
author | Vlad Alexandru Ionescu <vlad@rabbitmq.com> | 2010-10-14 20:26:19 +0100 |
---|---|---|
committer | Vlad Alexandru Ionescu <vlad@rabbitmq.com> | 2010-10-14 20:26:19 +0100 |
commit | 45a97a0535d43f2556cb8caa39af0ff00538ea5c (patch) | |
tree | 3193173e5ff818ea54063653ced094d8c868bfd7 | |
parent | c16511e8f20b16da1617f2f7a50613b85afbdc8c (diff) | |
download | rabbitmq-server-45a97a0535d43f2556cb8caa39af0ff00538ea5c.tar.gz |
fixing merge conflicts
-rw-r--r-- | include/rabbit.hrl | 2 | ||||
-rw-r--r-- | src/rabbit_exchange_type_topic.erl | 45 | ||||
-rw-r--r-- | src/rabbit_router.erl | 3 | ||||
-rw-r--r-- | src/rabbit_tests.erl | 36 |
4 files changed, 36 insertions, 50 deletions
diff --git a/include/rabbit.hrl b/include/rabbit.hrl index 59e39d92..282be001 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -67,7 +67,7 @@ -record(topic_trie_binding, {trie_binding, value = const}). -record(trie_edge, {exchange_name, node_id, word}). --record(trie_binding, {exchange_name, node_id, queue_name}). +-record(trie_binding, {exchange_name, node_id, destination}). -record(listener, {node, protocol, host, port}). diff --git a/src/rabbit_exchange_type_topic.erl b/src/rabbit_exchange_type_topic.erl index 89598958..3b0f1505 100644 --- a/src/rabbit_exchange_type_topic.erl +++ b/src/rabbit_exchange_type_topic.erl @@ -47,25 +47,17 @@ {requires, rabbit_exchange_type_registry}, {enables, kernel_ready}]}). --export([which_matches/2]). - --ifdef(use_specs). - --spec(which_matches/2 :: - (rabbit_exchange:name(), rabbit_router:routing_key()) -> - [rabbit_amqqueue:name()]). - --endif. - %%---------------------------------------------------------------------------- description() -> [{name, <<"topic">>}, {description, <<"AMQP topic exchange, as per the AMQP specification">>}]. -route(#exchange{name = X}, Delivery = - #delivery{message = #basic_message{routing_key = Key}}) -> - which_matches(X, Key). +%% NB: This may return duplicate results in some situations (that's ok) +route(#exchange{name = X}, + #delivery{message = #basic_message{routing_key = Key}}) -> + Words = split_topic_key(Key), + mnesia:async_dirty(fun trie_match/2, [X, Words]). validate(_X) -> ok. create(_X) -> ok. @@ -77,10 +69,10 @@ delete(#exchange{name = X}, _Bs) -> end), ok. -add_binding(_Exchange, #binding{exchange_name = X, key = K, queue_name = Q}) -> +add_binding(_Exchange, #binding{source = X, key = K, destination = D}) -> rabbit_misc:execute_mnesia_transaction( fun () -> FinalNode = follow_down_create(X, split_topic_key(K)), - trie_add_binding(X, FinalNode, Q) + trie_add_binding(X, FinalNode, D) end), ok. @@ -89,21 +81,16 @@ remove_bindings(_X, Bs) -> fun () -> lists:foreach(fun remove_binding/1, Bs) end), ok. -remove_binding(#binding{exchange_name = X, key = K, queue_name = Q}) -> +remove_binding(#binding{source = X, key = K, destination = D}) -> Path = follow_down_get_path(X, split_topic_key(K)), {FinalNode, _} = hd(Path), - trie_remove_binding(X, FinalNode, Q), + trie_remove_binding(X, FinalNode, D), remove_path_if_empty(X, Path), ok. assert_args_equivalence(X, Args) -> rabbit_exchange:assert_args_equivalence(X, Args). -%% NB: This function may return duplicate results in some situations (that's ok) -which_matches(X, Key) -> - Words = split_topic_key(Key), - mnesia:async_dirty(fun trie_match/2, [X, Words]). - %%---------------------------------------------------------------------------- trie_match(X, Words) -> @@ -188,7 +175,7 @@ trie_bindings(X, Node) -> MatchHead = #topic_trie_binding{ trie_binding = #trie_binding{exchange_name = X, node_id = Node, - queue_name = '$1'}}, + destination = '$1'}}, mnesia:select(rabbit_topic_trie_binding, [{MatchHead, [], ['$1']}]). trie_add_edge(X, FromNode, ToNode, W) -> @@ -205,17 +192,17 @@ trie_edge_op(X, FromNode, ToNode, W, Op) -> node_id = ToNode}, write). -trie_add_binding(X, Node, Q) -> - trie_binding_op(X, Node, Q, fun mnesia:write/3). +trie_add_binding(X, Node, D) -> + trie_binding_op(X, Node, D, fun mnesia:write/3). -trie_remove_binding(X, Node, Q) -> - trie_binding_op(X, Node, Q, fun mnesia:delete_object/3). +trie_remove_binding(X, Node, D) -> + trie_binding_op(X, Node, D, fun mnesia:delete_object/3). -trie_binding_op(X, Node, Q, Op) -> +trie_binding_op(X, Node, D, Op) -> ok = Op(rabbit_topic_trie_binding, #topic_trie_binding{trie_binding = #trie_binding{exchange_name = X, node_id = Node, - queue_name = Q}}, + destination = D}}, write). trie_has_any_children(X, Node) -> diff --git a/src/rabbit_router.erl b/src/rabbit_router.erl index 05bda8b0..00df1ce1 100644 --- a/src/rabbit_router.erl +++ b/src/rabbit_router.erl @@ -84,9 +84,6 @@ deliver(QNames, Delivery) -> check_delivery(Delivery#delivery.mandatory, Delivery#delivery.immediate, {Routed, Handled}). -deliver_by_queue_names(Qs, Delivery) -> - deliver(lookup_qpids(Qs), Delivery). - %% TODO: Maybe this should be handled by a cursor instead. %% TODO: This causes a full scan for each entry with the same source match_bindings(SrcName, Match) -> diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index 641fb6fb..4b3059be 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -592,12 +592,12 @@ test_topic_matching() -> %% add some bindings Bindings = lists:map( - fun({Key, Q}) -> - #binding{exchange_name = XName, - key = list_to_binary(Key), - queue_name = #resource{virtual_host = <<"/">>, - kind = queue, - name = list_to_binary(Q)}} + fun ({Key, Q}) -> + #binding{source = XName, + key = list_to_binary(Key), + destination = #resource{virtual_host = <<"/">>, + kind = queue, + name = list_to_binary(Q)}} end, [{"a.b.c", "t1"}, {"a.*.c", "t2"}, {"a.#.b", "t3"}, @@ -624,7 +624,7 @@ test_topic_matching() -> {"#.#.#", "t24"}, {"*", "t25"}, {"#.b.#", "t26"}]), - lists:foreach(fun(B) -> rabbit_exchange_type_topic:add_binding(X, B) end, + lists:foreach(fun (B) -> rabbit_exchange_type_topic:add_binding(X, B) end, Bindings), %% test some matches @@ -678,17 +678,19 @@ test_topic_matching() -> test_topic_expect_match(X, [{"a.b.c", []}, {"b.b.c", []}, {"", []}]), passed. -test_topic_expect_match(#exchange{name = XName}, List) -> +test_topic_expect_match(X, List) -> lists:foreach( - fun({Key, Expected}) -> - Res = rabbit_exchange_type_topic:which_matches( - XName, list_to_binary(Key)), - ExpectedRes = lists:map( - fun(Q) -> #resource{virtual_host = <<"/">>, - kind = queue, - name = list_to_binary(Q)} - end, Expected), - true = (lists:usort(ExpectedRes) =:= lists:usort(Res)) + fun ({Key, Expected}) -> + BinKey = list_to_binary(Key), + Res = rabbit_exchange_type_topic:route( + X, #delivery{message = #basic_message{routing_key = + BinKey}}), + ExpectedRes = lists:map( + fun (Q) -> #resource{virtual_host = <<"/">>, + kind = queue, + name = list_to_binary(Q)} + end, Expected), + true = (lists:usort(ExpectedRes) =:= lists:usort(Res)) end, List). test_app_management() -> |