@@ -279,12 +279,44 @@ func (d *diskQueue) skipToNextRWFile() error {
279
279
return err
280
280
}
281
281
282
+ func (d * diskQueue ) readRollFile () {
283
+ d .nextReadFileNum ++
284
+ d .nextReadPos = 0
285
+
286
+ oldReadFileNum := d .readFileNum
287
+ d .readFileNum = d .nextReadFileNum
288
+ d .readPos = d .nextReadPos
289
+
290
+ // sync every time we start reading from a new file
291
+ d .needSync = true
292
+
293
+ fn := d .fileName (oldReadFileNum )
294
+ err := os .Remove (fn )
295
+ if err != nil {
296
+ d .logf (ERROR , "DISKQUEUE(%s) failed to Remove(%s) - %s" , d .name , fn , err )
297
+ }
298
+
299
+ d .checkTailCorruption (d .depth )
300
+ }
301
+
282
302
// readOne performs a low level filesystem read for a single []byte
283
303
// while advancing read positions and rolling files, if necessary
284
304
func (d * diskQueue ) readOne () ([]byte , error ) {
285
305
var err error
286
306
var msgSize int32
287
307
308
+ // we only consider rotating if we're reading a "complete" file
309
+ // and since we cannot know the size at which it was rotated, we
310
+ // rely on maxBytesPerFileRead rather than maxBytesPerFile
311
+ if d .readFileNum <= d .writeFileNum && d .nextReadPos >= d .maxBytesPerFileRead && d .readFile != nil {
312
+ if d .readFile != nil {
313
+ d .readFile .Close ()
314
+ d .readFile = nil
315
+ }
316
+
317
+ d .readRollFile ()
318
+ }
319
+
288
320
if d .readFile == nil {
289
321
curFileName := d .fileName (d .readFileNum )
290
322
d .readFile , err = os .OpenFile (curFileName , os .O_RDONLY , 0600 )
@@ -346,19 +378,6 @@ func (d *diskQueue) readOne() ([]byte, error) {
346
378
d .nextReadPos = d .readPos + totalBytes
347
379
d .nextReadFileNum = d .readFileNum
348
380
349
- // we only consider rotating if we're reading a "complete" file
350
- // and since we cannot know the size at which it was rotated, we
351
- // rely on maxBytesPerFileRead rather than maxBytesPerFile
352
- if d .readFileNum <= d .writeFileNum && d .nextReadPos >= d .maxBytesPerFileRead {
353
- if d .readFile != nil {
354
- d .readFile .Close ()
355
- d .readFile = nil
356
- }
357
-
358
- d .nextReadFileNum ++
359
- d .nextReadPos = 0
360
- }
361
-
362
381
return readBuf , nil
363
382
}
364
383
0 commit comments