Skip to content

Commit

Permalink
Merge pull request #1819 from CortexFoundation/dev
Browse files Browse the repository at this point in the history
don't double-close iterator inside pebbleIterator
  • Loading branch information
ucwong authored Nov 26, 2023
2 parents d264474 + 5d4d009 commit 0ab9e43
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ctxcdb/pebble/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,12 @@ func (b *batch) Replay(w ctxcdb.KeyValueWriter) error {

// pebbleIterator is a wrapper of underlying iterator in storage engine.
// The purpose of this structure is to implement the missing APIs.
//
// The pebble iterator is not thread-safe.
type pebbleIterator struct {
iter *pebble.Iterator
moved bool
iter *pebble.Iterator
moved bool
released bool
}

// NewIterator creates a binary-alphabetical iterator over a subset
Expand All @@ -613,7 +616,7 @@ func (d *Database) NewIterator(prefix []byte, start []byte) ctxcdb.Iterator {
UpperBound: upperBound(prefix),
})
iter.First()
return &pebbleIterator{iter: iter, moved: true}
return &pebbleIterator{iter: iter, moved: true, released: false}
}

// Next moves the iterator to the next key/value pair. It returns whether the
Expand Down Expand Up @@ -648,4 +651,9 @@ func (iter *pebbleIterator) Value() []byte {

// Release releases associated resources. Release should always succeed and can
// be called multiple times without causing error.
func (iter *pebbleIterator) Release() { iter.iter.Close() }
func (iter *pebbleIterator) Release() {
if !iter.released {
iter.iter.Close()
iter.released = true
}
}

0 comments on commit 0ab9e43

Please sign in to comment.