Skip to content

Commit 5a34b20

Browse files
committed
Fix missing reassign of dirty ID
1 parent 86f7b40 commit 5a34b20

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

internal/buffer_list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ func (l *BufferList) insertOrAppend(offset uint64, data []byte, state BufferStat
441441
l.at.Delete(prev.offset + prev.length)
442442
allocated += prev.Append(data)
443443
prev.onDisk = false
444+
prev.dirtyID = dirtyID
444445
l.at.Set(prev.offset+prev.length, prev)
445446
l.queue(prev)
446447
return
@@ -645,7 +646,7 @@ func (l *BufferList) DebugCheckHoles(s string) {
645646
if len(h) > 0 {
646647
fmt.Printf("Debug: holes detected%s: %#v\n", s, h)
647648
l.at.Ascend(0, func(end uint64, b *FileBuffer) bool {
648-
fmt.Printf("%x-%x s%v z%v\n", b.offset, b.offset+b.length, b.state, b.zero)
649+
fmt.Printf("%x-%x s%v z%v d%v\n", b.offset, b.offset+b.length, b.state, b.zero, b.dirtyID)
649650
return true
650651
})
651652
panic("holes detected")

internal/buffer_list_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,32 @@ func (s *BufferListTest) TestAppend(t *C) {
3636
t.Assert(l.Add(0, filledBuf(1024, 1), BUF_DIRTY, true), Equals, int64(1024))
3737
t.Assert(l.Add(1024, filledBuf(1024, 2), BUF_DIRTY, true), Equals, int64(1024))
3838
t.Assert(l.Add(1536, filledBuf(1024, 3), BUF_DIRTY, true), Equals, int64(1024))
39-
data, _, err := l.GetData(0, 2048, true)
39+
data, ids, err := l.GetData(0, 2048, true)
4040
t.Assert(err, IsNil)
41+
t.Assert(len(ids), Equals, 1)
42+
var oldId uint64
43+
for id := range ids {
44+
oldId = id
45+
}
4146
t.Assert(len(data), Equals, 1)
4247
t.Assert(len(data[0]), Equals, 2048)
4348
t.Assert(data[0][0:1024], DeepEquals, filledBuf(1024, 1))
4449
t.Assert(data[0][1024:1536], DeepEquals, filledBuf(512, 2))
4550
t.Assert(data[0][1536:], DeepEquals, filledBuf(512, 3))
51+
// Then modify one of the buffers again and recheck that dirty ID is reassigned
52+
t.Assert(l.Add(1536, filledBuf(1024, 4), BUF_DIRTY, true), Equals, int64(0))
53+
l.SetState(0, 2048, ids, BUF_CLEAN)
54+
data, ids, err = l.GetData(0, 2048, true)
55+
t.Assert(len(ids), Equals, 1)
56+
for id := range ids {
57+
t.Assert(id, Not(Equals), oldId)
58+
}
59+
t.Assert(err, IsNil)
60+
t.Assert(len(data), Equals, 1)
61+
t.Assert(len(data[0]), Equals, 2048)
62+
t.Assert(data[0][0:1024], DeepEquals, filledBuf(1024, 1))
63+
t.Assert(data[0][1024:1536], DeepEquals, filledBuf(512, 2))
64+
t.Assert(data[0][1536:], DeepEquals, filledBuf(512, 4))
4665
}
4766

4867
func (s *BufferListTest) TestGetHoles(t *C) {

0 commit comments

Comments
 (0)