@@ -199,29 +199,30 @@ recover(#resource{ virtual_host = VHost } = Name, Terms, IsMsgStoreClean,
199
199
State }
200
200
end .
201
201
202
- recover_segments (State = # mqistate { dir = Dir }, Terms , IsMsgStoreClean ,
202
+ recover_segments (State0 = # mqistate { dir = Dir }, Terms , IsMsgStoreClean ,
203
203
ContainsCheckFun , OnSyncFun , OnSyncMsgFun , CountersRef ) ->
204
204
SegmentFiles = rabbit_file :wildcard (" .*\\ " ++ ? SEGMENT_EXTENSION , Dir ),
205
- case SegmentFiles of
206
- % % No segments found. We try to see if there are segment files
207
- % % from the old index.
205
+ State = case SegmentFiles of
206
+ % % No segments found.
208
207
[] ->
209
- case rabbit_file :wildcard (" .*\\ .idx" , Dir ) of
210
- % % We are recovering a dirty queue that was using the old index.
211
- [_ |_ ] ->
212
- recover_index_v1_dirty (State , Terms , IsMsgStoreClean ,
213
- ContainsCheckFun , OnSyncFun , OnSyncMsgFun ,
214
- CountersRef );
215
- % % Otherwise keep default values.
216
- [] ->
217
- State
218
- end ;
208
+ State0 ;
219
209
% % Count unackeds in the segments.
220
210
_ ->
221
211
Segments = lists :sort ([
222
212
list_to_integer (filename :basename (F , ? SEGMENT_EXTENSION ))
223
213
|| F <- SegmentFiles ]),
224
- recover_segments (State , ContainsCheckFun , CountersRef , Segments )
214
+ recover_segments (State0 , ContainsCheckFun , CountersRef , Segments )
215
+ end ,
216
+ % % We always try to see if there are segment files from the old index as well.
217
+ case rabbit_file :wildcard (" .*\\ .idx" , Dir ) of
218
+ % % We are recovering a dirty queue that was using the old index.
219
+ [_ |_ ] ->
220
+ recover_index_v1_dirty (State , Terms , IsMsgStoreClean ,
221
+ ContainsCheckFun , OnSyncFun , OnSyncMsgFun ,
222
+ CountersRef );
223
+ % % Otherwise keep default values.
224
+ [] ->
225
+ State
225
226
end .
226
227
227
228
recover_segments (State , _ , _ , []) ->
@@ -384,7 +385,7 @@ recover_index_v1_loop(State0 = #mqistate{ queue_name = Name },
384
385
MsgId = case MsgOrId of
385
386
Msg = # basic_message { id = MsgId0 } ->
386
387
% % We must do a synchronous write to avoid overloading the message store.
387
- rabbit_msg_store :sync_write (MsgId0 , Msg , MSClient ),
388
+ rabbit_msg_store :blocking_write (MsgId0 , Msg , MSClient ),
388
389
MsgId0 ;
389
390
MsgId0 ->
390
391
MsgId0
@@ -395,6 +396,7 @@ recover_index_v1_loop(State0 = #mqistate{ queue_name = Name },
395
396
publish (MsgId , SeqId , Props , IsPersistent , IsDelivered , infinity , State1 )
396
397
end , State0 , Messages ),
397
398
State = flush (State2 ),
399
+ rabbit_msg_store :force_sync (MSClient ),
398
400
% % We have written everything to disk. We can delete the old segment file
399
401
% % to free up much needed space, to avoid doubling disk usage during the upgrade.
400
402
rabbit_queue_index :delete_segment_file_for_seq_id (LoSeqId , V1State ),
@@ -997,17 +999,17 @@ queue_index_walker_reader(#resource{ virtual_host = VHost } = Name, Gatherer) ->
997
999
? DEBUG (" ~0p ~0p " , [Name , Gatherer ]),
998
1000
VHostDir = rabbit_vhost :msg_store_dir_path (VHost ),
999
1001
Dir = queue_dir (VHostDir , Name ),
1002
+ SegmentFiles = rabbit_file :wildcard (" .*\\ " ++ ? SEGMENT_EXTENSION , Dir ),
1003
+ _ = [queue_index_walker_segment (filename :join (Dir , F ), Gatherer ) || F <- SegmentFiles ],
1000
1004
% % When there are files belonging to the old index, we go through
1001
- % % the old index walker function. We will upgrade to the new index
1002
- % % in the recover step.
1005
+ % % the old index walker function as well.
1003
1006
case rabbit_file :wildcard (" .*\\ .idx" , Dir ) of
1004
1007
[_ |_ ] ->
1005
1008
rabbit_queue_index :queue_index_walker_reader (Name , Gatherer );
1006
1009
[] ->
1007
- SegmentFiles = rabbit_file :wildcard (" .*\\ " ++ ? SEGMENT_EXTENSION , Dir ),
1008
- _ = [queue_index_walker_segment (filename :join (Dir , F ), Gatherer ) || F <- SegmentFiles ],
1009
- ok = gatherer :finish (Gatherer )
1010
- end .
1010
+ ok
1011
+ end ,
1012
+ ok = gatherer :finish (Gatherer ).
1011
1013
1012
1014
queue_index_walker_segment (F , Gatherer ) ->
1013
1015
? DEBUG (" ~0p ~0p " , [F , Gatherer ]),
0 commit comments