diff options
| author | Michael Klishin <mklishin@pivotal.io> | 2019-02-16 15:48:26 +0300 |
|---|---|---|
| committer | Michael Klishin <mklishin@pivotal.io> | 2019-02-16 15:48:26 +0300 |
| commit | 391eb24d1f2fd0d2dc381d2e078496bb9d0d2348 (patch) | |
| tree | 4361903e79cffd431387629e8c5cfd900a4d8631 /src | |
| parent | 7521ab498a4954eac580e0cf19affd1b9e8ae3d6 (diff) | |
| parent | 111773916b2543541414ec5bd9084b97caaf9e5b (diff) | |
| download | rabbitmq-server-git-391eb24d1f2fd0d2dc381d2e078496bb9d0d2348.tar.gz | |
Merge branch 'master' into rabbitmq-server-1873-binding-recovery
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_binding.erl | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/src/rabbit_binding.erl b/src/rabbit_binding.erl index ab3bc6c819..05db4188ba 100644 --- a/src/rabbit_binding.erl +++ b/src/rabbit_binding.erl @@ -49,7 +49,6 @@ -type bind_ok_or_error() :: 'ok' | bind_errors() | rabbit_types:error( - 'binding_not_found' | {'binding_invalid', string(), [any()]}). -type bind_res() :: bind_ok_or_error() | rabbit_misc:thunk(bind_ok_or_error()). -type inner_fun() :: @@ -178,19 +177,15 @@ add(Src, Dst, B, ActingUser) -> lock_resource(Src), lock_resource(Dst), [SrcDurable, DstDurable] = [durable(E) || E <- [Src, Dst]], - case (SrcDurable andalso DstDurable andalso - mnesia:read({rabbit_durable_route, B}) =/= []) of - false -> ok = sync_route(#route{binding = B}, SrcDurable, DstDurable, - fun mnesia:write/3), - x_callback(transaction, Src, add_binding, B), - Serial = rabbit_exchange:serial(Src), - fun () -> - x_callback(Serial, Src, add_binding, B), - ok = rabbit_event:notify( - binding_created, - info(B) ++ [{user_who_performed_action, ActingUser}]) - end; - true -> rabbit_misc:const({error, binding_not_found}) + ok = sync_route(#route{binding = B}, SrcDurable, DstDurable, + fun mnesia:write/3), + x_callback(transaction, Src, add_binding, B), + Serial = rabbit_exchange:serial(Src), + fun () -> + x_callback(Serial, Src, add_binding, B), + ok = rabbit_event:notify( + binding_created, + info(B) ++ [{user_who_performed_action, ActingUser}]) end. -spec remove(rabbit_types:binding()) -> bind_res(). @@ -208,7 +203,10 @@ remove(Binding, InnerFun, ActingUser) -> case mnesia:read(rabbit_route, B, write) of [] -> case mnesia:read(rabbit_durable_route, B, write) of [] -> rabbit_misc:const(ok); - _ -> rabbit_misc:const({error, binding_not_found}) + %% We still delete the binding and run + %% all post-delete functions if there is only + %% a durable route in the database + _ -> remove(Src, Dst, B, ActingUser) end; _ -> case InnerFun(Src, Dst) of ok -> remove(Src, Dst, B, ActingUser); @@ -275,9 +273,8 @@ list_for_source(SrcName) -> -spec list_for_destination (rabbit_types:binding_destination()) -> bindings(). -list_for_destination(DstName) -> - implicit_for_destination(DstName) ++ - mnesia:async_dirty( +list_for_destination(DstName = #resource{virtual_host = VHostPath}) -> + AllBindings = mnesia:async_dirty( fun() -> Route = #route{binding = #binding{destination = DstName, _ = '_'}}, @@ -285,7 +282,11 @@ list_for_destination(DstName) -> #reverse_route{reverse_binding = B} <- mnesia:match_object(rabbit_reverse_route, reverse_route(Route), read)] - end). + end), + Filtered = lists:filter(fun(#binding{source = S}) -> + S =/= ?DEFAULT_EXCHANGE(VHostPath) + end, AllBindings), + implicit_for_destination(DstName) ++ Filtered. implicit_bindings(VHostPath) -> DstQueues = rabbit_amqqueue:list_names(VHostPath), |
