MCPcopy Create free account
hub / github.com/couchbase/forestdb / _fdb_iterator_next

Function _fdb_iterator_next

src/iterator.cc:829–988  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

827}
828
829static fdb_status _fdb_iterator_next(fdb_iterator *iterator)
830{
831 int cmp;
832 void *key;
833 size_t keylen;
834 uint64_t offset;
835 hbtrie_result hr = HBTRIE_RESULT_SUCCESS;
836 struct docio_handle *dhandle;
837 struct snap_wal_entry *snap_item = NULL;
838
839 if (iterator->direction == FDB_ITR_REVERSE) {
840 iterator->_offset = BLK_NOT_FOUND; // need to re-examine Trie/trees
841 if (iterator->tree_cursor) {
842 iterator->tree_cursor = avl_next(iterator->tree_cursor);
843 if (iterator->tree_cursor &&
844 iterator->status == FDB_ITR_WAL) {
845 // if the last document was returned from WAL,
846 // shift again, past curkey into next
847 iterator->tree_cursor = avl_next(iterator->tree_cursor);
848 }
849 }
850 }
851
852 if (!iterator->tree_cursor && iterator->direction != FDB_ITR_FORWARD) {
853 // In case reverse iteration went past the start, reset the
854 // cursor to the start point
855 iterator->tree_cursor = iterator->tree_cursor_start;
856 if (iterator->status == FDB_ITR_WAL &&
857 iterator->_dhandle && iterator->_get_offset != BLK_NOT_FOUND) {
858 // In this case, iterator is currently pointing to the first key
859 // (it implies that the first key is already returned).
860 // So we need to move it forward one step.
861 iterator->tree_cursor_prev = iterator->tree_cursor;
862 iterator->tree_cursor = avl_next(iterator->tree_cursor);
863 }
864 }
865
866start:
867 key = iterator->_key;
868 dhandle = iterator->handle->dhandle;
869
870 // retrieve from hb-trie
871 if (iterator->_offset == BLK_NOT_FOUND) {
872 // no key waiting for being returned
873 // get next key from hb-trie (or idtree)
874 struct docio_object _doc;
875 uint64_t _offset;
876 do {
877 hr = hbtrie_next(iterator->hbtrie_iterator, key,
878 &iterator->_keylen, (void*)&iterator->_offset);
879 btreeblk_end(iterator->handle->bhandle);
880 iterator->_offset = _endian_decode(iterator->_offset);
881 if (!(iterator->opt & FDB_ITR_NO_DELETES) ||
882 hr != HBTRIE_RESULT_SUCCESS) {
883 break;
884 }
885 // deletion check
886 memset(&_doc, 0x0, sizeof(struct docio_object));

Callers 1

Calls 5

avl_nextFunction · 0.85
hbtrie_nextFunction · 0.85
btreeblk_endFunction · 0.85
docio_read_doc_key_metaFunction · 0.85
_fdb_key_cmpFunction · 0.85

Tested by

no test coverage detected