Skip to content

Less coarse-grained locking for bindings add/remove operations #1900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/rabbit_binding.erl
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ add(Binding, InnerFun, ActingUser) ->
fun (Src, Dst, B) ->
case rabbit_exchange:validate_binding(Src, B) of
ok ->
lock_resource(Src),
lock_resource(Dst),
lock_resource(Src, read),
lock_resource(Dst, read),
%% this argument is used to check queue exclusivity;
%% in general, we want to fail on that in preference to
%% anything else
Expand All @@ -174,8 +174,6 @@ add(Binding, InnerFun, ActingUser) ->
end, fun not_found_or_absent_errs/1).

add(Src, Dst, B, ActingUser) ->
lock_resource(Src),
lock_resource(Dst),
[SrcDurable, DstDurable] = [durable(E) || E <- [Src, Dst]],
ok = sync_route(#route{binding = B}, SrcDurable, DstDurable,
fun mnesia:write/3),
Expand All @@ -198,8 +196,8 @@ remove(Binding, InnerFun, ActingUser) ->
binding_action(
Binding,
fun (Src, Dst, B) ->
lock_resource(Src),
lock_resource(Dst),
lock_resource(Src, read),
lock_resource(Dst, read),
case mnesia:read(rabbit_route, B, write) of
[] -> case mnesia:read(rabbit_durable_route, B, write) of
[] -> rabbit_misc:const(ok);
Expand All @@ -216,8 +214,6 @@ remove(Binding, InnerFun, ActingUser) ->
end, fun absent_errs_only/1).

remove(Src, Dst, B, ActingUser) ->
lock_resource(Src),
lock_resource(Dst),
ok = sync_route(#route{binding = B}, durable(Src), durable(Dst),
fun delete/3),
Deletions = maybe_auto_delete(
Expand Down Expand Up @@ -536,9 +532,11 @@ remove_for_destination(DstName, OnlyDurable, Fun) ->

%% Instead of locking entire table on remove operations we can lock the
%% affected resource only.
lock_resource(Name) ->
lock_resource(Name) -> lock_resource(Name, write).

lock_resource(Name, LockKind) ->
mnesia:lock({global, Name, mnesia:table_info(rabbit_route, where_to_write)},
write).
LockKind).

%% Requires that its input binding list is sorted in exchange-name
%% order, so that the grouping of bindings (for passing to
Expand Down