Skip to content

Commit 44b932a

Browse files
committed
Improve readability of the code and update code from nsqio#29 issue 29
1 parent e9fe0b0 commit 44b932a

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

diskqueue.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ func (d *diskQueue) getAllBadFileInfo() ([]os.FileInfo, error) {
553553
}
554554

555555
// get the accurate total non-"bad" file size
556-
func (d *diskQueue) updateTotalDiskSpaceUsed() error {
556+
func (d *diskQueue) updateTotalDiskSpaceUsed() {
557557
d.totalDiskSpaceUsed = maxMetaDataFileSize
558558

559559
updateTotalDiskSpaceUsed := func(fileInfo os.FileInfo) error {
@@ -565,7 +565,10 @@ func (d *diskQueue) updateTotalDiskSpaceUsed() error {
565565
return nil
566566
}
567567

568-
return d.walkDiskQueueDir(updateTotalDiskSpaceUsed)
568+
err := d.walkDiskQueueDir(updateTotalDiskSpaceUsed)
569+
if err != nil {
570+
d.logf(ERROR, "DISKQUEUE(%s) failed to update write bytes - %s", d.name, err)
571+
}
569572
}
570573

571574
func (d *diskQueue) freeDiskSpace(expectedBytesIncrease int64) error {
@@ -936,6 +939,11 @@ func (d *diskQueue) handleReadError() {
936939
}
937940
d.writeFileNum++
938941
d.writePos = 0
942+
943+
if d.enableDiskLimitation {
944+
d.totalDiskSpaceUsed = 0
945+
d.writeMessages = 0
946+
}
939947
}
940948

941949
badFn := d.fileName(d.readFileNum)
@@ -952,27 +960,18 @@ func (d *diskQueue) handleReadError() {
952960
d.name, badFn, badRenameFn)
953961
}
954962

955-
if d.enableDiskLimitation {
956-
if d.readFileNum == d.writeFileNum {
957-
// we moved on to the next writeFile
958-
d.totalDiskSpaceUsed = 0
959-
d.writeMessages = 0
960-
} else {
961-
if err != nil {
962-
d.logf(ERROR, "DISKQUEUE(%s) failed to update write bytes - %s", d.name, err)
963-
}
964-
}
965-
966-
d.readMessages = 0
967-
}
968-
969963
d.readFileNum++
970964
d.readPos = 0
971965
d.nextReadFileNum = d.readFileNum
972966
d.nextReadPos = 0
967+
if d.enableDiskLimitation {
968+
d.readMessages = 0
969+
}
973970

974971
// significant state change, schedule a sync on the next iteration
975972
d.needSync = true
973+
974+
d.checkTailCorruption(d.depth)
976975
}
977976

978977
// ioLoop provides the backend for exposing a go channel (via ReadChan())

0 commit comments

Comments
 (0)