From 1797a6f7f357acd75e65ea968f3de84ceec86528 Mon Sep 17 00:00:00 2001 From: Michal Kuratczyk Date: Mon, 26 May 2025 09:47:11 +0200 Subject: [PATCH] Don't scan for valid messages when deleting Looking for valid messages before deleting a message store file was an old check for extra safety. However, it is a bottleneck under intense workload: it can take a few seconds to delete a file (a vast majority of that spent scanning for messages), while new files can be created faster than that. That leads to the disk usage growing, even if the number of messages in the queues is not. We are not aware of any situations where this check actually found valid messages in a file that was requested to be deleted. This is a well tested code path a this point, so let's just remove the extra check. --- deps/rabbit/src/rabbit_msg_store.erl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/deps/rabbit/src/rabbit_msg_store.erl b/deps/rabbit/src/rabbit_msg_store.erl index 482e9cfa4f..52a08fefc1 100644 --- a/deps/rabbit/src/rabbit_msg_store.erl +++ b/deps/rabbit/src/rabbit_msg_store.erl @@ -2123,9 +2123,9 @@ truncate_file(File, Size, ThresholdTimestamp, #gc_state{ file_summary_ets = File -spec delete_file(non_neg_integer(), gc_state()) -> ok | defer. -delete_file(File, State = #gc_state { file_summary_ets = FileSummaryEts, - file_handles_ets = FileHandlesEts, - dir = Dir }) -> +delete_file(File, #gc_state { file_summary_ets = FileSummaryEts, + file_handles_ets = FileHandlesEts, + dir = Dir }) -> case ets:match_object(FileHandlesEts, {{'_', File}, '_'}, 1) of {[_|_], _Cont} -> rabbit_log:debug("Asked to delete file ~p but it has active readers. Deferring.", @@ -2134,7 +2134,6 @@ delete_file(File, State = #gc_state { file_summary_ets = FileSummaryEts, _ -> [#file_summary{ valid_total_size = 0, file_size = FileSize }] = ets:lookup(FileSummaryEts, File), - [] = scan_and_vacuum_message_file(File, State), ok = file:delete(form_filename(Dir, filenum_to_name(File))), true = ets:delete(FileSummaryEts, File), rabbit_log:debug("Deleted empty file number ~tp; reclaimed ~tp bytes", [File, FileSize]),