nsqio / go-diskqueue

A Go package providing a filesystem-backed FIFO queue
MIT License
471 stars 101 forks source link

write to next file if writePos == maxBytesPerFile #8

Closed SwanSpouse closed 4 years ago

SwanSpouse commented 4 years ago

when d.writePos == maxBytesPerFile, "writeOne" func continues to write a message to current file, this will make current file one message larger than expected.

ploxiln commented 4 years ago

Makes sense, thanks.

(It seems like it would be even more correct to see if the current message will fit under the maxBytesPerFile before writing it, because even with this change there will usually be some trailing bytes of the last message which go past maxBytesPerFile in typical usage. But that can be a later improvement IMHO.)

SwanSpouse commented 4 years ago

there will usually be some trailing bytes of the last message which go past maxBytesPerFile in typical usage

About this question, if we want current message fits under themaxBytesPerFile, we should make sure that maxMsgSize is smaller than maxBytesPerFile in dq's constructor.