Skip to content

Commit

Permalink
address comment
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 ceb34a1 commit 6da788b
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions internal/unionstore/art/art_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ func (t *ART) SnapshotGetter() *SnapGetter {
}
}

// SnapshotIter returns an Iterator for a snapshot of MemBuffer.
func (t *ART) SnapshotIter(start, end []byte) *SnapIter {
inner, err := t.Iter(start, end)
func (t *ART) newSnapshotIterator(start, end []byte, desc bool) *SnapIter {
var (
inner *Iterator
err error
)
if desc {
inner, err = t.IterReverse(start, end)
} else {
inner, err = t.Iter(start, end)
}
if err != nil {
panic(err)
}
Expand All @@ -53,21 +60,14 @@ func (t *ART) SnapshotIter(start, end []byte) *SnapIter {
return it
}

// SnapshotIter returns an Iterator for a snapshot of MemBuffer.
func (t *ART) SnapshotIter(start, end []byte) *SnapIter {
return t.newSnapshotIterator(start, end, false)
}

// SnapshotIterReverse returns a reverse Iterator for a snapshot of MemBuffer.
func (t *ART) SnapshotIterReverse(k, lowerBound []byte) *SnapIter {
inner, err := t.IterReverse(k, lowerBound)
if err != nil {
panic(err)
}
it := &SnapIter{
Iterator: inner,
cp: t.getSnapshot(),
}
it.tree.allocator.snapshotInc()
for !it.setValue() && it.Valid() {
_ = it.Next()
}
return it
return t.newSnapshotIterator(k, lowerBound, true)
}

type SnapGetter struct {
Expand Down Expand Up @@ -114,6 +114,8 @@ func (i *SnapIter) Next() error {
return nil
}

// Close releases the resources of the iterator and related version.
// Make sure to call `Close` after the iterator is not used.
func (i *SnapIter) Close() {
i.Iterator.Close()
i.tree.allocator.snapshotDec()
Expand Down

0 comments on commit 6da788b

Please sign in to comment.