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)
| 456 | // will not be able to see those writes. Only writes performed before an iterator was created can be |
| 457 | // viewed. |
| 458 | func (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 |