| 2060 | } |
| 2061 | |
| 2062 | LIBFDB_API |
| 2063 | fdb_status fdb_iterator_next(fdb_iterator *iterator) |
| 2064 | { |
| 2065 | if (!iterator) { |
| 2066 | return FDB_RESULT_INVALID_HANDLE; |
| 2067 | } |
| 2068 | |
| 2069 | fdb_status result = FDB_RESULT_SUCCESS; |
| 2070 | |
| 2071 | if (!atomic_cas_uint8_t(&iterator->handle->handle_busy, 0, 1)) { |
| 2072 | return FDB_RESULT_HANDLE_BUSY; |
| 2073 | } |
| 2074 | |
| 2075 | if (iterator->hbtrie_iterator) { |
| 2076 | while ((result = _fdb_iterator_next(iterator)) == |
| 2077 | FDB_RESULT_KEY_NOT_FOUND); |
| 2078 | } else { |
| 2079 | while ((result = _fdb_iterator_seq_next(iterator)) == |
| 2080 | FDB_RESULT_KEY_NOT_FOUND); |
| 2081 | } |
| 2082 | if (result == FDB_RESULT_SUCCESS) { |
| 2083 | iterator->direction = FDB_ITR_FORWARD; |
| 2084 | } else { |
| 2085 | iterator->_dhandle = NULL; // fail fdb_iterator_get also |
| 2086 | if (iterator->direction != FDB_ITR_DIR_NONE) { |
| 2087 | iterator->direction = FDB_ITR_DIR_NONE; |
| 2088 | if ((iterator->seqtree_iterator || iterator->seqtrie_iterator) && |
| 2089 | iterator->status == FDB_ITR_IDX) { |
| 2090 | iterator->_offset = BLK_NOT_FOUND; |
| 2091 | } |
| 2092 | if (iterator->tree_cursor) { |
| 2093 | if (iterator->status == FDB_ITR_WAL) { // move 2 steps |
| 2094 | iterator->tree_cursor = |
| 2095 | avl_prev(iterator->tree_cursor_prev); |
| 2096 | } else { |
| 2097 | // move 1 step if last doc was returned from the main index |
| 2098 | iterator->tree_cursor = avl_prev(iterator->tree_cursor); |
| 2099 | } |
| 2100 | iterator->tree_cursor_prev = iterator->tree_cursor; |
| 2101 | } |
| 2102 | } |
| 2103 | } |
| 2104 | |
| 2105 | atomic_cas_uint8_t(&iterator->handle->handle_busy, 1, 0); |
| 2106 | atomic_incr_uint64_t(&iterator->handle->op_stats->num_iterator_moves); |
| 2107 | return result; |
| 2108 | } |
| 2109 | |
| 2110 | // DOC returned by this function must be freed by fdb_doc_free |
| 2111 | // if it was allocated because the incoming doc was pointing to NULL |
nothing calls this directly
no test coverage detected