Skip to content

Commit c46d490

Browse files
committed
fix for snapshot iter
Signed-off-by: ekexium <[email protected]>
1 parent 1a6d100 commit c46d490

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

internal/unionstore/art/art_iterator.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ type Iterator struct {
8080

8181
// only when seqNo == art.seqNo, the iterator is valid.
8282
seqNo int
83+
// ignoreSeqNo is used to ignore the seqNo check, used for snapshot iter before its full deprecation.
84+
ignoreSeqNo bool
8385
}
8486

85-
func (it *Iterator) Valid() bool { return it.valid && it.seqNo == it.tree.SeqNo }
87+
func (it *Iterator) Valid() bool { return it.valid && (it.seqNo == it.tree.SeqNo || it.ignoreSeqNo) }
8688
func (it *Iterator) Key() []byte { return it.currLeaf.GetKey() }
8789
func (it *Iterator) Flags() kv.KeyFlags { return it.currLeaf.GetKeyFlags() }
8890
func (it *Iterator) Value() []byte {
@@ -106,7 +108,7 @@ func (it *Iterator) Next() error {
106108
// iterate is finished
107109
return errors.New("Art: iterator is finished")
108110
}
109-
if it.seqNo != it.tree.SeqNo {
111+
if !it.ignoreSeqNo && it.seqNo != it.tree.SeqNo {
110112
return errors.New(fmt.Sprintf("seqNo mismatch: iter=%d, art=%d", it.seqNo, it.tree.SeqNo))
111113
}
112114
if it.currAddr == it.endAddr {

internal/unionstore/art/art_snapshot.go

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func (t *ART) newSnapshotIterator(start, end []byte, desc bool) *SnapIter {
4949
if err != nil {
5050
panic(err)
5151
}
52+
inner.ignoreSeqNo = true
5253
it := &SnapIter{
5354
Iterator: inner,
5455
cp: t.getSnapshot(),

internal/unionstore/memdb_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ func TestSnapshotReaderWithWrite(t *testing.T) {
13361336
h := db.Staging()
13371337
defer db.Release(h)
13381338

1339-
iter := db.BatchedSnapshotIter([]byte{0, 0}, []byte{0, 255}, false)
1339+
iter := db.SnapshotIter([]byte{0, 0}, []byte{0, 255})
13401340
assert.Equal(t, iter.Key(), []byte{0, 0})
13411341

13421342
db.Set([]byte{0, byte(num)}, []byte{0, byte(num)}) // ART: node4/node16/node48 is freed and wait to be reused.

0 commit comments

Comments
 (0)