Skip to content

Commit 58c8e08

Browse files
authored
Merge pull request #32 from kev1n80/inaccurate_depth_read_error_29
Inaccurate depth count after readError on "current" file
2 parents 84d80dc + f2ecc37 commit 58c8e08

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

diskqueue.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,8 @@ func (d *diskQueue) handleReadError() {
631631

632632
// significant state change, schedule a sync on the next iteration
633633
d.needSync = true
634+
635+
d.checkTailCorruption(d.depth)
634636
}
635637

636638
// ioLoop provides the backend for exposing a go channel (via ReadChan())

diskqueue_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,23 @@ func TestDiskQueueCorruption(t *testing.T) {
247247
dq.Put(msg)
248248

249249
Equal(t, msg, <-dq.ReadChan())
250+
251+
dq.Put(msg)
252+
dq.Put(msg)
253+
// corrupt the last file
254+
dqFn = dq.(*diskQueue).fileName(5)
255+
os.Truncate(dqFn, 100)
256+
257+
Equal(t, int64(2), dq.Depth())
258+
259+
// return one message and try reading again from corrupted file
260+
<-dq.ReadChan()
261+
262+
// give diskqueue time to handle read error
263+
time.Sleep(50 * time.Millisecond)
264+
265+
// the last log file is now considered corrupted leaving no more log messages
266+
Equal(t, int64(0), dq.Depth())
250267
}
251268

252269
type md struct {

0 commit comments

Comments
 (0)