File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -473,6 +473,29 @@ func (d *diskQueue) retrieveMetaData() error {
473473 d .nextReadFileNum = d .readFileNum
474474 d .nextReadPos = d .readPos
475475
476+ // if the metadata was not sync'd at the last shutdown of nsqd
477+ // then the actual file size might actually be larger than the writePos,
478+ // in which case the safest thing to do is skip to the next file for
479+ // writes, and let the reader salvage what it can from the messages in the
480+ // diskqueue beyond the metadata's likely also stale readPos
481+ fileName = d .fileName (d .writeFileNum )
482+ fileInfo , err := os .Stat (fileName )
483+ if err != nil {
484+ return err
485+ }
486+ fileSize := fileInfo .Size ()
487+ if d .writePos < fileSize {
488+ d .logf (WARN ,
489+ "DISKQUEUE(%s) %s metadata writePos %d < file size of %d, skipping to new file" ,
490+ d .name , fileName , d .writePos , fileSize )
491+ d .writeFileNum += 1
492+ d .writePos = 0
493+ if d .writeFile != nil {
494+ d .writeFile .Close ()
495+ d .writeFile = nil
496+ }
497+ }
498+
476499 return nil
477500}
478501
You can’t perform that action at this time.
0 commit comments