Skip to content

Commit

Permalink
QQ: handle missing_key crash for appended segments.
Browse files Browse the repository at this point in the history
If a channel/session process has opened a segment that later was appended
to the index maintained in memory does not know of the newly appended entries
and thus would generate a missing_key error.
  • Loading branch information
kjnilsson committed Dec 6, 2024
1 parent e5c0afd commit 83bb7f0
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions deps/rabbit/src/rabbit_fifo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3016,9 +3016,19 @@ incr_msg(Msg0, DelFailed, Anns) ->
end.

exec_read(Flru0, ReadPlan, Msgs) ->
{Entries, Flru} = ra_log_read_plan:execute(ReadPlan, Flru0),
%% return a list in original order
{lists:map(fun ({MsgId, ?MSG(Idx, Header)}) ->
Cmd = maps:get(Idx, Entries),
{MsgId, {Header, get_msg(Cmd)}}
end, Msgs), Flru}.
try ra_log_read_plan:execute(ReadPlan, Flru0) of
{Entries, Flru} ->
%% return a list in original order
{lists:map(fun ({MsgId, ?MSG(Idx, Header)}) ->
Cmd = maps:get(Idx, Entries),
{MsgId, {Header, get_msg(Cmd)}}
end, Msgs), Flru}
catch exit:{missing_key, _}
when Flru0 =/= undefined ->
%% this segment has most likely been appended to but the
%% cached index doesn't know about new items and need to be
%% re-generated
_ = ra_flru:evict_all(Flru0),
%% retry without segment cache
exec_read(undefined, ReadPlan, Msgs)
end.

0 comments on commit 83bb7f0

Please sign in to comment.