Skip to content

Commit e653f50

Browse files
hairyhummichaelklishin
authored andcommitted
Do not fail on bind/unbind operations if the binding records are inconsistent.
If there is a record for the rabbit_durable_route table but no record for rabbit_route table, the binding operations should still proceed to create/remove bindings. This will allow the clients to fix data inconsistency that server did not fix during recovery. [#163952284] (cherry picked from commit 13985a7)
1 parent 7e57fae commit e653f50

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/rabbit_binding.erl

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545

4646
-type bind_ok_or_error() :: 'ok' | bind_errors() |
4747
rabbit_types:error(
48-
'binding_not_found' |
4948
{'binding_invalid', string(), [any()]}).
5049
-type bind_res() :: bind_ok_or_error() | rabbit_misc:thunk(bind_ok_or_error()).
5150
-type inner_fun() ::
@@ -205,19 +204,15 @@ add(Src, Dst, B, ActingUser) ->
205204
lock_resource(Src),
206205
lock_resource(Dst),
207206
[SrcDurable, DstDurable] = [durable(E) || E <- [Src, Dst]],
208-
case (SrcDurable andalso DstDurable andalso
209-
mnesia:read({rabbit_durable_route, B}) =/= []) of
210-
false -> ok = sync_route(#route{binding = B}, SrcDurable, DstDurable,
211-
fun mnesia:write/3),
212-
x_callback(transaction, Src, add_binding, B),
213-
Serial = rabbit_exchange:serial(Src),
214-
fun () ->
215-
x_callback(Serial, Src, add_binding, B),
216-
ok = rabbit_event:notify(
217-
binding_created,
218-
info(B) ++ [{user_who_performed_action, ActingUser}])
219-
end;
220-
true -> rabbit_misc:const({error, binding_not_found})
207+
ok = sync_route(#route{binding = B}, SrcDurable, DstDurable,
208+
fun mnesia:write/3),
209+
x_callback(transaction, Src, add_binding, B),
210+
Serial = rabbit_exchange:serial(Src),
211+
fun () ->
212+
x_callback(Serial, Src, add_binding, B),
213+
ok = rabbit_event:notify(
214+
binding_created,
215+
info(B) ++ [{user_who_performed_action, ActingUser}])
221216
end.
222217

223218
remove(Binding) -> remove(Binding, fun (_Src, _Dst) -> ok end, ?INTERNAL_USER).
@@ -231,7 +226,10 @@ remove(Binding, InnerFun, ActingUser) ->
231226
case mnesia:read(rabbit_route, B, write) of
232227
[] -> case mnesia:read(rabbit_durable_route, B, write) of
233228
[] -> rabbit_misc:const(ok);
234-
_ -> rabbit_misc:const({error, binding_not_found})
229+
%% We still delete the binding and run
230+
%% all post-delete functions if there is only
231+
%% a durable route in the database
232+
_ -> remove(Src, Dst, B, ActingUser)
235233
end;
236234
_ -> case InnerFun(Src, Dst) of
237235
ok -> remove(Src, Dst, B, ActingUser);

0 commit comments

Comments
 (0)