Skip to content

Commit

Permalink
Merge pull request #40 from circled-me/v2
Browse files Browse the repository at this point in the history
Make sure the first segment is not empty or it's not complete (is current)
  • Loading branch information
joncrlsn authored Oct 23, 2024
2 parents c2ef48c + cba597b commit 541ab71
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Empty file added queue
Empty file.
19 changes: 14 additions & 5 deletions queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,19 +520,28 @@ func (q *DQue) load() error {
if maxNum > 0 {

// We found files
seg, err := openQueueSegment(q.fullPath, minNum, q.turbo, q.builder)
if err != nil {
return errors.Wrap(err, "unable to create queue segment in "+q.fullPath)
for {
seg, err := openQueueSegment(q.fullPath, minNum, q.turbo, q.builder)
if err != nil {
return errors.Wrap(err, "unable to create queue segment in "+q.fullPath)
}
// Make sure the first segment is not empty or it's not complete (i.e. is current)
if seg.size() > 0 || seg.sizeOnDisk() < q.config.ItemsPerSegment {
q.firstSegment = seg
break
}
// Try the next one
seg.close()
minNum++
}
q.firstSegment = seg

if minNum == maxNum {
// We have only one segment so the
// first and last are the same instance (in this case)
q.lastSegment = q.firstSegment
} else {
// We have multiple segments
seg, err = openQueueSegment(q.fullPath, maxNum, q.turbo, q.builder)
seg, err := openQueueSegment(q.fullPath, maxNum, q.turbo, q.builder)
if err != nil {
return errors.Wrap(err, "unable to create segment for "+q.fullPath)
}
Expand Down

0 comments on commit 541ab71

Please sign in to comment.