Skip to content

Commit f9c47f6

Browse files
committed
CQ shared: Unlock files after truncation instead of compaction
1 parent 4258b65 commit f9c47f6

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

deps/rabbit/src/rabbit_msg_store.erl

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@
149149
-type gc_state() :: #gc_state { dir :: file:filename(),
150150
index_ets :: ets:tid(),
151151
file_summary_ets :: ets:tid(),
152-
file_handles_ets :: ets:tid(),
153-
msg_store :: server()
152+
file_handles_ets :: ets:tid()
154153
}.
155154

156155
-type server() :: pid() | atom().
@@ -760,8 +759,7 @@ init([VHost, Type, BaseDir, ClientRefs, StartupFunState]) ->
760759
#gc_state { dir = Dir,
761760
index_ets = IndexEts,
762761
file_summary_ets = FileSummaryEts,
763-
file_handles_ets = FileHandlesEts,
764-
msg_store = self()
762+
file_handles_ets = FileHandlesEts
765763
}),
766764

767765
CreditDiscBound = rabbit_misc:get_env(rabbit, msg_store_credit_disc_bound,
@@ -814,7 +812,6 @@ prioritise_call(Msg, _From, _Len, _State) ->
814812

815813
prioritise_cast(Msg, _Len, _State) ->
816814
case Msg of
817-
{compacted_file, _File} -> 8;
818815
{client_dying, _Pid} -> 7;
819816
_ -> 0
820817
end.
@@ -914,16 +911,7 @@ handle_cast({remove, CRef, MsgIds}, State) ->
914911
ignore -> State2
915912
end
916913
end, State, MsgIds),
917-
noreply(State1);
918-
919-
handle_cast({compacted_file, File},
920-
State = #msstate { file_summary_ets = FileSummaryEts }) ->
921-
%% This can return false if the file gets deleted immediately
922-
%% after compaction ends, but before we can process this message.
923-
%% So this will become a no-op and we can ignore the return value.
924-
_ = ets:update_element(FileSummaryEts, File,
925-
{#file_summary.locked, false}),
926-
noreply(State).
914+
noreply(State1).
927915

928916
handle_info(sync, State) ->
929917
noreply(internal_sync(State));
@@ -2011,8 +1999,7 @@ compact_file(File, State = #gc_state { file_summary_ets = FileSummaryEts }) ->
20111999
compact_file(File, FileSize,
20122000
State = #gc_state { index_ets = IndexEts,
20132001
file_summary_ets = FileSummaryEts,
2014-
dir = Dir,
2015-
msg_store = Server }) ->
2002+
dir = Dir }) ->
20162003
%% Get metadata about the file. Will be used to calculate
20172004
%% how much data was reclaimed as a result of compaction.
20182005
[#file_summary{file_size = FileSize}] = ets:lookup(FileSummaryEts, File),
@@ -2048,8 +2035,6 @@ compact_file(File, FileSize,
20482035
Reclaimed = FileSize - TruncateSize,
20492036
?LOG_DEBUG("Compacted segment file number ~tp; ~tp bytes can now be reclaimed",
20502037
[File, Reclaimed]),
2051-
%% Tell the message store to update its state.
2052-
gen_server2:cast(Server, {compacted_file, File}),
20532038
%% Tell the GC process to truncate the file.
20542039
%%
20552040
%% We will truncate later when there are no readers. We want current
@@ -2158,6 +2143,8 @@ truncate_file(File, Size, ThresholdTimestamp, #gc_state{ file_summary_ets = File
21582143
ok = file:close(Fd),
21592144
true = ets:update_element(FileSummaryEts, File,
21602145
{#file_summary.file_size, Size}),
2146+
true = ets:update_element(FileSummaryEts, File,
2147+
{#file_summary.locked, false}),
21612148
?LOG_DEBUG("Truncated file number ~tp; new size ~tp bytes", [File, Size]),
21622149
ok
21632150
end

0 commit comments

Comments
 (0)