Skip to content

Commit 88945e3

Browse files
gerhardmichaelklishin
authored andcommitted
Delete bindings from mnesia without full table scan
mnesia:match_object/3 scans the entire table and can take many seconds on a loaded node. This is especially bad when there are many bindings which need to be deleted. If the object is in the table then delete it, otherwise carry on. Prior to this change, it was observed that there is a high % of lock collisions in rabbit_topic_trie_binding table: ``` lock id #tries #collisions collisions [%] time [us] duration [%] histogram [log2(us)] ----- --- ------- ------------ --------------- ---------- ------------- --------------------- db_tab rabbit_topic_trie_binding 258465 13627 5.2723 1389904 0.0370 | ...XXxxXx.......... | ``` mnesia:match_object/3 uses a table index if it exists, but in the case of rabbit_topic_trie_binding, there is no table index, so a full table scan used to be performed. For more context, see #1513 Partner-in-crime: @essen
1 parent f2ab0b4 commit 88945e3

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/rabbit_binding.erl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,8 @@ binding_action(Binding = #binding{source = SrcName,
331331
Fun(Src, Dst, Binding#binding{args = SortedArgs})
332332
end, ErrFun).
333333

334-
delete_object(Tab, Record, LockKind) ->
335-
%% this 'guarded' delete prevents unnecessary writes to the mnesia
336-
%% disk log
337-
case mnesia:match_object(Tab, Record, LockKind) of
338-
[] -> ok;
339-
[_] -> mnesia:delete_object(Tab, Record, LockKind)
340-
end.
334+
delete_object(Table, Record, LockKind) ->
335+
mnesia:delete_object(Table, Record, LockKind).
341336

342337
sync_route(Route, true, true, Fun) ->
343338
ok = Fun(rabbit_durable_route, Route, write),

0 commit comments

Comments
 (0)