Skip to content

Commit

Permalink
Merge pull request #41 from circled-me/v2
Browse files Browse the repository at this point in the history
Delete consumed and complete segments on load + Close segment file handles
  • Loading branch information
joncrlsn authored Oct 24, 2024
2 parents 541ab71 + 173781c commit 7723fd1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Empty file removed queue
Empty file.
13 changes: 12 additions & 1 deletion queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ func (q *DQue) Close() error {
// Wake-up any waiting goroutines for blocking queue access - they should get a ErrQueueClosed
q.emptyCond.Broadcast()

// Close the first and last segments' file handles
if err = q.firstSegment.close(); err != nil {
return err
}
if q.firstSegment != q.lastSegment {
if err = q.lastSegment.close(); err != nil {
return err
}
}

// Safe-guard ourself from accidentally using segments after closing the queue
q.firstSegment = nil
q.lastSegment = nil
Expand Down Expand Up @@ -530,8 +540,9 @@ func (q *DQue) load() error {
q.firstSegment = seg
break
}
// Delete the segment as it's empty and complete
seg.delete()
// Try the next one
seg.close()
minNum++
}

Expand Down

0 comments on commit 7723fd1

Please sign in to comment.