Disk size limit#6
Conversation
Depth impl
…ed when DiskQueue needs to make space.
…. Test that DiskQueue never surpasses the disk size limit.
…finds a bad file or does not.
…k if we need to make disk space.
…Bytes, writeMsgs, and readMsgs in handReadError.
CatherineF-dev
left a comment
There was a problem hiding this comment.
If d.writeFileNum++ >= 1000000 or >= MAX_INT64, it might be an issue.
If the retention_size is not big enough, d.writeFileNum would increase quickly.
Since the d.writeFileNum is always increasing, it would be over MAX_INT64 in the future.
func (d *diskQueue) fileName(fileNum int64) string {
return fmt.Sprintf(path.Join(d.dataPath, "%s.diskqueue.%06d.dat"), d.name, fileNum)
}
Unfortunately, this seems like a limitation in NSQIO's design, which relies on writeFileNum to be greater than or equal to readFileNum. I was wondering if we could overcome this limitation by "resetting" DiskQueue once all of the data in the queue has been read. |
| } | ||
|
|
||
| // update depth with the remaining number of messages | ||
| d.depth -= totalMessages - d.readMessages |
There was a problem hiding this comment.
If d.readMessages is not sync well, d.readMessages is small and d.depth might be negative.
Could we add a check here?
d.depth -= totalMessages - d.readMessages
if d.depth < 0 {
d.logf(ERROR, "DISKQUEUE(%s) d.depth = %d is negative", d.name, d.depth)
d.depth = 0
}There was a problem hiding this comment.
In that case, what if we only do that subtraction if totalMessages is greater than d.readMessages and less than d.depth.
if totalMessages > d.readMessages && totalMessages < d.depth {
// update depth with the remaining number of messages
d.depth -= totalMessages - d.readMessages
}
This way, we still have a rough estimate of what the total depth is. In the situation where the depth is 1,000 and a file has 100 messages. I think it would be better to have a rough estimate as to what the depth is rather than set it to 0. Plus, this is what happens when we encounter a bad file or a file that may have been truncated: we do not subtract depth by anything and proceed with an estimated number.
There was a problem hiding this comment.
We have decided that there are two problems: 1) when the current depth is a negative number and 2) when totalMessages is a negative number. I think we should approach the second problem with my suggestion
and the first problem by adding your check when we create a new DiskQueue object.
However, we will hold off on making these changes until we find the real issue of the negative number.
CatherineF-dev
left a comment
There was a problem hiding this comment.
Good job!! Thanks Kevin!
I like the "moveToNextReadFile", which is shared by readOne() and removeReadFile().
Indeed, removeReadFile() is like readOne() without putting data to readChan.
|
fmt.Println(fmt.Sprintf( "%s.diskqueue.%06d.dat", "1", 10000000000)) = 10000000000 Need to change how to read here https://github.com/kev1n80/go-diskqueue/blob/master/diskqueue.go#L189 |
Implementation
Testing
Note
Half of the PR is code for testing