MCPcopy
hub / github.com/dgraph-io/badger / Close

Method Close

iterator.go:536–558  ·  view source on GitHub ↗

Close would close the iterator. It is important to call this when you're done with iteration.

()

Source from the content-addressed store, hash-verified

534
535// Close would close the iterator. It is important to call this when you're done with iteration.
536func (it *Iterator) Close() {
537 if it.closed {
538 return
539 }
540 it.closed = true
541
542 it.iitr.Close()
543 // It is important to wait for the fill goroutines to finish. Otherwise, we might leave zombie
544 // goroutines behind, which are waiting to acquire file read locks after DB has been closed.
545 waitFor := func(l list) {
546 item := l.pop()
547 for item != nil {
548 item.wg.Wait()
549 item = l.pop()
550 }
551 }
552 waitFor(it.waste)
553 waitFor(it.data)
554
555 // TODO: We could handle this error.
556 _ = it.txn.db.vlog.decrIteratorCount()
557 atomic.AddInt32(&it.txn.numIterators, -1)
558}
559
560// Next would advance the iterator by one. Always check it.Valid() after a Next()
561// to ensure you have access to a valid it.Item().

Callers

nothing calls this directly

Calls 4

popMethod · 0.80
decrIteratorCountMethod · 0.80
CloseMethod · 0.65
WaitMethod · 0.45

Tested by

no test coverage detected