@@ -1913,21 +1913,25 @@ delete_file(File, State = #gc_state { file_summary_ets = FileSummaryEts,
1913
1913
ok
1914
1914
end .
1915
1915
1916
- load_and_vacuum_message_file (File , State ) ->
1917
- Messages0 = index_select_all_from_file (File , State ),
1918
- % % Cleanup messages that have 0 ref_count.
1919
- Messages = lists :foldl (fun
1920
- (Entry = # msg_location { ref_count = 0 }, Acc ) ->
1921
- ok = index_delete_object (Entry , State ),
1922
- Acc ;
1923
- (Entry , Acc ) ->
1924
- [Entry |Acc ]
1925
- end , [], Messages0 ),
1926
- lists :keysort (# msg_location .offset , Messages ).
1927
-
1928
- index_select_all_from_file (File , # gc_state { index_module = Index ,
1929
- index_state = State }) ->
1930
- Index :select_all_from_file (File , State ).
1916
+ load_and_vacuum_message_file (File , State = # gc_state { dir = Dir }) ->
1917
+ % % Messages here will be end-of-file at start-of-list
1918
+ {ok , Messages , _FileSize } =
1919
+ scan_file_for_valid_messages (Dir , filenum_to_name (File )),
1920
+ % % foldl will reverse so will end up with msgs in ascending offset order
1921
+ lists :foldl (
1922
+ fun ({MsgId , TotalSize , Offset }, Acc ) ->
1923
+ case index_lookup (MsgId , State ) of
1924
+ # msg_location { file = File , total_size = TotalSize ,
1925
+ offset = Offset , ref_count = 0 } = Entry ->
1926
+ ok = index_delete_object (Entry , State ),
1927
+ Acc ;
1928
+ # msg_location { file = File , total_size = TotalSize ,
1929
+ offset = Offset } = Entry ->
1930
+ [ Entry | Acc ];
1931
+ _ ->
1932
+ Acc
1933
+ end
1934
+ end , [], Messages ).
1931
1935
1932
1936
scan_and_vacuum_message_file (File , State = # gc_state { dir = Dir }) ->
1933
1937
% % Messages here will be end-of-file at start-of-list
0 commit comments