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

Method NewIterator

iterator.go:458–487  ·  view source on GitHub ↗

NewIterator returns a new iterator. Depending upon the options, either only keys, or both key-value pairs would be fetched. The keys are returned in lexicographically sorted order. Using prefetch is recommended if you're doing a long running iteration, for performance. Multiple Iterators: For a rea

(opt IteratorOptions)

Source from the content-addressed store, hash-verified

456// will not be able to see those writes. Only writes performed before an iterator was created can be
457// viewed.
458func (txn *Txn) NewIterator(opt IteratorOptions) *Iterator {
459 if txn.discarded {
460 panic("Transaction has already been discarded")
461 }
462
463 // Keep track of the number of active iterators.
464 atomic.AddInt32(&txn.numIterators, 1)
465
466 // TODO: If Prefix is set, only pick those memtables which have keys with
467 // the prefix.
468 tables, decr := txn.db.getMemTables()
469 defer decr()
470 txn.db.vlog.incrIteratorCount()
471 var iters []y.Iterator
472 if itr := txn.newPendingWritesIterator(opt.Reverse); itr != nil {
473 iters = append(iters, itr)
474 }
475 for i := 0; i < len(tables); i++ {
476 iters = append(iters, tables[i].NewUniIterator(opt.Reverse))
477 }
478 iters = txn.db.lc.appendIterators(iters, &opt) // This will increment references.
479
480 res := &Iterator{
481 txn: txn,
482 iitr: table.NewMergeIterator(iters, opt.Reverse),
483 opt: opt,
484 readTs: txn.readTs,
485 }
486 return res
487}
488
489// NewKeyIterator is just like NewIterator, but allows the user to iterate over all versions of a
490// single key. Internally, it sets the Prefix option in provided opt, and uses that prefix to

Callers 15

produceKVsMethod · 0.95
NewKeyIteratorMethod · 0.95
deleteMoveKeysForMethod · 0.45
TestWriteBatchFunction · 0.45
TestIteratePrefixFunction · 0.45
numKeysFunction · 0.45
numKeysManagedFunction · 0.45
TestWriteBatchManagedFunction · 0.45

Calls 6

NewMergeIteratorFunction · 0.92
getMemTablesMethod · 0.80
incrIteratorCountMethod · 0.80
NewUniIteratorMethod · 0.80
appendIteratorsMethod · 0.45

Tested by 15

TestWriteBatchFunction · 0.36
TestIteratePrefixFunction · 0.36
numKeysFunction · 0.36
numKeysManagedFunction · 0.36
TestWriteBatchManagedFunction · 0.36
TestWriteBatchDuplicateFunction · 0.36
TestConcurrentWriteFunction · 0.36
TestGetMoreFunction · 0.36