@@ -152,6 +152,7 @@ func NewWithDiskSpace(name string, dataPath string,
152
152
minMsgSize : minMsgSize ,
153
153
maxMsgSize : maxMsgSize ,
154
154
readChan : make (chan []byte ),
155
+ peekChan : make (chan []byte ),
155
156
depthChan : make (chan int64 ),
156
157
writeChan : make (chan []byte ),
157
158
writeResponseChan : make (chan error ),
@@ -648,23 +649,6 @@ func (d *diskQueue) writeOne(data []byte) error {
648
649
return fmt .Errorf ("invalid message write size (%d) minMsgSize=%d maxMsgSize=%d" , dataLen , d .minMsgSize , d .maxMsgSize )
649
650
}
650
651
651
- if d .enableDiskLimitation {
652
- expectedBytesIncrease := totalBytes
653
- // check if we will reach or surpass file size limit
654
- if d .writePos + totalBytes + numFileMsgBytes >= d .maxBytesPerFile {
655
- reachedFileSizeLimit = true
656
- expectedBytesIncrease += numFileMsgBytes
657
- }
658
-
659
- // free disk space if needed
660
- err = d .checkDiskSpace (expectedBytesIncrease )
661
- if err != nil {
662
- return err
663
- }
664
- } else if d .writePos + totalBytes >= d .maxBytesPerFile {
665
- reachedFileSizeLimit = true
666
- }
667
-
668
652
// will not wrap-around if maxBytesPerFile + maxMsgSize < Int64Max
669
653
if d .writePos > 0 && d .writePos + totalBytes > d .maxBytesPerFile {
670
654
if d .readFileNum == d .writeFileNum {
@@ -685,6 +669,7 @@ func (d *diskQueue) writeOne(data []byte) error {
685
669
d .writeFile = nil
686
670
}
687
671
}
672
+
688
673
if d .writeFile == nil {
689
674
curFileName := d .fileName (d .writeFileNum )
690
675
d .writeFile , err = os .OpenFile (curFileName , os .O_RDWR | os .O_CREATE , 0600 )
@@ -704,6 +689,23 @@ func (d *diskQueue) writeOne(data []byte) error {
704
689
}
705
690
}
706
691
692
+ if d .enableDiskLimitation {
693
+ expectedBytesIncrease := totalBytes
694
+ // check if we will reach or surpass file size limit
695
+ if d .writePos + totalBytes + numFileMsgBytes >= d .maxBytesPerFile {
696
+ reachedFileSizeLimit = true
697
+ expectedBytesIncrease += numFileMsgBytes
698
+ }
699
+
700
+ // free disk space if needed
701
+ err = d .checkDiskSpace (expectedBytesIncrease )
702
+ if err != nil {
703
+ return err
704
+ }
705
+ } else if d .writePos + totalBytes >= d .maxBytesPerFile {
706
+ reachedFileSizeLimit = true
707
+ }
708
+
707
709
d .writeBuf .Reset ()
708
710
err = binary .Write (& d .writeBuf , binary .BigEndian , dataLen )
709
711
if err != nil {
0 commit comments