Skip to content

Commit f7e4fa9

Browse files
committed
Use delete instead of delete_object and read instead of match_object in bindings where possible.
Route table key contains all the route information, which makes delete equivalent to delete_object. But it's faster. For the same reason match_object with a full object is equivalent to read.
1 parent c1fb658 commit f7e4fa9

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/rabbit_binding.erl

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ recover_semi_durable_route(Gatherer, R = #route{binding = B}, ToRecover) ->
145145
recover_semi_durable_route_txn(R = #route{binding = B}, X) ->
146146
rabbit_misc:execute_mnesia_transaction(
147147
fun () ->
148-
case mnesia:match_object(rabbit_semi_durable_route, R, read) of
148+
case mnesia:read(rabbit_semi_durable_route, B, read) of
149149
[] -> no_recover;
150150
_ -> ok = sync_transient_route(R, fun mnesia:write/3),
151151
rabbit_exchange:serial(X)
@@ -232,7 +232,7 @@ remove(Src, Dst, B, ActingUser) ->
232232
lock_resource(Src),
233233
lock_resource(Dst),
234234
ok = sync_route(#route{binding = B}, durable(Src), durable(Dst),
235-
fun mnesia:delete_object/3),
235+
fun delete/3),
236236
Deletions = maybe_auto_delete(
237237
B#binding.source, [B], new_deletions(), false),
238238
process_deletions(Deletions, ActingUser).
@@ -406,21 +406,33 @@ remove_routes(Routes) ->
406406
%% This partitioning allows us to suppress unnecessary delete
407407
%% operations on disk tables, which require an fsync.
408408
{RamRoutes, DiskRoutes} =
409-
lists:partition(fun (R) -> mnesia:match_object(
410-
rabbit_durable_route, R, read) == [] end,
409+
lists:partition(fun (R) -> mnesia:read(
410+
rabbit_durable_route, R#route.binding, read) == [] end,
411411
Routes),
412+
{RamOnlyRoutes, SemiDurableRoutes} =
413+
lists:partition(fun (R) -> mnesia:read(
414+
rabbit_semi_durable_route, R#route.binding, read) == [] end,
415+
RamRoutes),
412416
%% Of course the destination might not really be durable but it's
413417
%% just as easy to try to delete it from the semi-durable table
414418
%% than check first
415-
[ok = sync_route(R, false, true, fun mnesia:delete_object/3) ||
416-
R <- RamRoutes],
417-
[ok = sync_route(R, true, true, fun mnesia:delete_object/3) ||
419+
[ok = sync_route(R, true, true, fun delete/3) ||
418420
R <- DiskRoutes],
421+
[ok = sync_route(R, false, true, fun delete/3) ||
422+
R <- SemiDurableRoutes],
423+
[ok = sync_route(R, false, false, fun delete/3) ||
424+
R <- RamOnlyRoutes],
419425
[R#route.binding || R <- Routes].
420426

427+
428+
delete(Tab, #route{binding = B}, LockKind) ->
429+
mnesia:delete(Tab, B, LockKind);
430+
delete(Tab, #reverse_route{reverse_binding = B}, LockKind) ->
431+
mnesia:delete(Tab, B, LockKind).
432+
421433
remove_transient_routes(Routes) ->
422434
[begin
423-
ok = sync_transient_route(R, fun mnesia:delete_object/3),
435+
ok = sync_transient_route(R, fun delete/3),
424436
R#route.binding
425437
end || R <- Routes].
426438

0 commit comments

Comments
 (0)