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.
This commit is contained in:
Michal Kuratczyk 2025-05-26 09:47:11 +02:00
parent 7289487702
commit 1797a6f7f3
No known key found for this signature in database
1 changed files with 3 additions and 4 deletions

View File

@ -2123,7 +2123,7 @@ 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,
delete_file(File, #gc_state { file_summary_ets = FileSummaryEts,
file_handles_ets = FileHandlesEts,
dir = Dir }) ->
case ets:match_object(FileHandlesEts, {{'_', File}, '_'}, 1) of
@ -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]),