Skip to content

Commit cb60eb0

Browse files
committed
Prioritise delete calls
Without this change, if the compaction was lagging behind, we could have file deletion requests queued behind compaction requests, leading to many unnecessary compactions.
1 parent 989003d commit cb60eb0

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

deps/rabbit/src/rabbit_msg_store.erl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,10 +1998,21 @@ delete_file_if_empty(File, State = #msstate {
19981998
%% We do not try to look at messages that are not the last because we do not want to
19991999
%% accidentally write over messages that were moved earlier.
20002000

2001-
compact_file(File, State = #gc_state { index_ets = IndexEts,
2002-
file_summary_ets = FileSummaryEts,
2003-
dir = Dir,
2004-
msg_store = Server }) ->
2001+
compact_file(File, State = #gc_state { file_summary_ets = FileSummaryEts }) ->
2002+
case ets:lookup(FileSummaryEts, File) of
2003+
[] ->
2004+
rabbit_log:debug("File ~tp has already been deleted; no need to compact",
2005+
[File]),
2006+
ok;
2007+
[#file_summary{file_size = FileSize}] ->
2008+
compact_file(File, FileSize, State)
2009+
end.
2010+
2011+
compact_file(File, FileSize,
2012+
State = #gc_state { index_ets = IndexEts,
2013+
file_summary_ets = FileSummaryEts,
2014+
dir = Dir,
2015+
msg_store = Server }) ->
20052016
%% Get metadata about the file. Will be used to calculate
20062017
%% how much data was reclaimed as a result of compaction.
20072018
[#file_summary{file_size = FileSize}] = ets:lookup(FileSummaryEts, File),

deps/rabbit/src/rabbit_msg_store_gc.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
-export([start_link/1, compact/2, truncate/4, delete/2, stop/1]).
1313

1414
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
15-
terminate/2, code_change/3]).
15+
terminate/2, code_change/3, prioritise_cast/3]).
1616

1717
-record(state,
1818
{ pending,
@@ -51,6 +51,9 @@ delete(Server, File) ->
5151
stop(Server) ->
5252
gen_server2:call(Server, stop, infinity).
5353

54+
prioritise_cast({delete, _}, _Len, _State) -> 5;
55+
prioritise_cast(_, _Len, _State) -> 0.
56+
5457
%%----------------------------------------------------------------------------
5558

5659
init([MsgStoreState]) ->

0 commit comments

Comments
 (0)