@@ -837,13 +837,16 @@ segment_entries_foldr(Fun, Init,
837837% %
838838% % Does not do any combining with the journal at all.
839839load_segment (KeepAcked , # segment { path = Path }) ->
840+ Empty = {array_new (), 0 },
840841 case rabbit_file :is_file (Path ) of
841- false -> { array_new (), 0 } ;
842+ false -> Empty ;
842843 true -> {ok , Hdl } = file_handle_cache :open (Path , ? READ_AHEAD_MODE , []),
843844 {ok , 0 } = file_handle_cache :position (Hdl , bof ),
844- {ok , SegData } = file_handle_cache :read (
845- Hdl , ? SEGMENT_TOTAL_SIZE ),
846- Res = load_segment_entries (KeepAcked , SegData , array_new (), 0 ),
845+ Res = case file_handle_cache :read (Hdl , ? SEGMENT_TOTAL_SIZE ) of
846+ {ok , SegData } -> load_segment_entries (
847+ KeepAcked , SegData , Empty );
848+ eof -> Empty
849+ end ,
847850 ok = file_handle_cache :close (Hdl ),
848851 Res
849852 end .
@@ -853,15 +856,15 @@ load_segment_entries(KeepAcked,
853856 IsPersistentNum :1 , RelSeq :? REL_SEQ_BITS ,
854857 PubRecordBody :? PUB_RECORD_BODY_BYTES /binary ,
855858 SegData /binary >>,
856- SegEntries , UnackedCount ) ->
859+ { SegEntries , UnackedCount } ) ->
857860 {MsgId , MsgProps } = parse_pub_record_body (PubRecordBody ),
858861 Obj = {{MsgId , MsgProps , 1 == IsPersistentNum }, no_del , no_ack },
859862 SegEntries1 = array :set (RelSeq , Obj , SegEntries ),
860- load_segment_entries (KeepAcked , SegData , SegEntries1 , UnackedCount + 1 );
863+ load_segment_entries (KeepAcked , SegData , { SegEntries1 , UnackedCount + 1 } );
861864load_segment_entries (KeepAcked ,
862865 <<? REL_SEQ_ONLY_PREFIX :? REL_SEQ_ONLY_PREFIX_BITS ,
863866 RelSeq :? REL_SEQ_BITS , SegData /binary >>,
864- SegEntries , UnackedCount ) ->
867+ { SegEntries , UnackedCount } ) ->
865868 {UnackedCountDelta , SegEntries1 } =
866869 case array :get (RelSeq , SegEntries ) of
867870 {Pub , no_del , no_ack } ->
@@ -871,10 +874,10 @@ load_segment_entries(KeepAcked,
871874 {_Pub , del , no_ack } ->
872875 {- 1 , array :reset (RelSeq , SegEntries )}
873876 end ,
874- load_segment_entries (KeepAcked , SegData , SegEntries1 ,
875- UnackedCount + UnackedCountDelta );
876- load_segment_entries (_KeepAcked , _SegData , SegEntries , UnackedCount ) ->
877- { SegEntries , UnackedCount } .
877+ load_segment_entries (KeepAcked , SegData ,
878+ { SegEntries1 , UnackedCount + UnackedCountDelta } );
879+ load_segment_entries (_KeepAcked , _SegData , Res ) ->
880+ Res .
878881
879882array_new () ->
880883 array :new ([{default , undefined }, fixed , {size , ? SEGMENT_ENTRY_COUNT }]).
0 commit comments