Skip to content

Commit

Permalink
reproduce
Browse files Browse the repository at this point in the history
Signed-off-by: you06 <[email protected]>
  • Loading branch information
you06 committed Nov 19, 2024
1 parent 8b0547a commit c9d1300
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions internal/unionstore/memdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1327,3 +1327,38 @@ func TestSelectValueHistory(t *testing.T) {
check(t, newRbtDBWithContext())
check(t, newArtDBWithContext())
}

func TestSnapshotReaderWithWrite(t *testing.T) {
check := func(db MemBuffer) {
db.Set([]byte{0, 1}, []byte{0, 1})
db.Set([]byte{0, 2}, []byte{0, 2})
db.Set([]byte{0, 3}, []byte{0, 3})
db.Set([]byte{0, 4}, []byte{0, 4})
h := db.Staging()
defer db.Release(h)

iter := db.SnapshotIter([]byte{0, 1}, []byte{0, 255})
assert.Equal(t, iter.Key(), []byte{0, 1})

db.Set([]byte{0, 5}, []byte{0, 5}) // node4 is freed and wait to be reused.

// reuse the node4
db.Set([]byte{1, 1}, []byte{1, 1})
db.Set([]byte{1, 2}, []byte{1, 2})
db.Set([]byte{1, 3}, []byte{1, 3})
db.Set([]byte{1, 4}, []byte{1, 4})

assert.Equal(t, iter.Key(), []byte{0, 1})
iter.Next()
assert.Equal(t, iter.Key(), []byte{0, 2})
iter.Next()
assert.Equal(t, iter.Key(), []byte{0, 3})
iter.Next()
assert.Equal(t, iter.Key(), []byte{0, 4})
iter.Next()
assert.False(t, iter.Valid())
}

check(newRbtDBWithContext())
check(newArtDBWithContext())
}

0 comments on commit c9d1300

Please sign in to comment.