diff options
Diffstat (limited to 'src/third_party/wiredtiger/src/btree/bt_cursor.c')
-rw-r--r-- | src/third_party/wiredtiger/src/btree/bt_cursor.c | 153 |
1 files changed, 70 insertions, 83 deletions
diff --git a/src/third_party/wiredtiger/src/btree/bt_cursor.c b/src/third_party/wiredtiger/src/btree/bt_cursor.c index 11201846a38..111222809f0 100644 --- a/src/third_party/wiredtiger/src/btree/bt_cursor.c +++ b/src/third_party/wiredtiger/src/btree/bt_cursor.c @@ -367,14 +367,11 @@ __wt_cursor_valid(WT_CURSOR_BTREE *cbt, WT_UPDATE **updp, bool *valid) * Column-store search from a cursor. */ static inline int -__cursor_col_search(WT_CURSOR_BTREE *cbt, WT_REF *leaf, bool *leaf_foundp) +__cursor_col_search(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt, WT_REF *leaf) { WT_DECL_RET; - WT_SESSION_IMPL *session; - session = (WT_SESSION_IMPL *)cbt->iface.session; - WT_WITH_PAGE_INDEX( - session, ret = __wt_col_search(cbt, cbt->iface.recno, leaf, false, leaf_foundp)); + WT_WITH_PAGE_INDEX(session, ret = __wt_col_search(session, cbt->iface.recno, leaf, cbt, false)); return (ret); } @@ -383,14 +380,12 @@ __cursor_col_search(WT_CURSOR_BTREE *cbt, WT_REF *leaf, bool *leaf_foundp) * Row-store search from a cursor. */ static inline int -__cursor_row_search(WT_CURSOR_BTREE *cbt, bool insert, WT_REF *leaf, bool *leaf_foundp) +__cursor_row_search(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt, WT_REF *leaf, bool insert) { WT_DECL_RET; - WT_SESSION_IMPL *session; - session = (WT_SESSION_IMPL *)cbt->iface.session; WT_WITH_PAGE_INDEX( - session, ret = __wt_row_search(cbt, &cbt->iface.key, insert, leaf, false, leaf_foundp)); + session, ret = __wt_row_search(session, &cbt->iface.key, leaf, cbt, insert, false)); return (ret); } @@ -399,9 +394,10 @@ __cursor_row_search(WT_CURSOR_BTREE *cbt, bool insert, WT_REF *leaf, bool *leaf_ * Column-store modify from a cursor, with a separate value. */ static inline int -__cursor_col_modify_v(WT_CURSOR_BTREE *cbt, WT_ITEM *value, u_int modify_type) +__cursor_col_modify_v( + WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt, WT_ITEM *value, u_int modify_type) { - return (__wt_col_modify(cbt, cbt->iface.recno, value, NULL, modify_type, false)); + return (__wt_col_modify(session, cbt, cbt->iface.recno, value, NULL, modify_type, false)); } /* @@ -409,9 +405,10 @@ __cursor_col_modify_v(WT_CURSOR_BTREE *cbt, WT_ITEM *value, u_int modify_type) * Row-store modify from a cursor, with a separate value. */ static inline int -__cursor_row_modify_v(WT_CURSOR_BTREE *cbt, WT_ITEM *value, u_int modify_type) +__cursor_row_modify_v( + WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt, WT_ITEM *value, u_int modify_type) { - return (__wt_row_modify(cbt, &cbt->iface.key, value, NULL, modify_type, false)); + return (__wt_row_modify(session, cbt, &cbt->iface.key, value, NULL, modify_type, false)); } /* @@ -419,9 +416,10 @@ __cursor_row_modify_v(WT_CURSOR_BTREE *cbt, WT_ITEM *value, u_int modify_type) * Column-store modify from a cursor. */ static inline int -__cursor_col_modify(WT_CURSOR_BTREE *cbt, u_int modify_type) +__cursor_col_modify(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt, u_int modify_type) { - return (__wt_col_modify(cbt, cbt->iface.recno, &cbt->iface.value, NULL, modify_type, false)); + return ( + __wt_col_modify(session, cbt, cbt->iface.recno, &cbt->iface.value, NULL, modify_type, false)); } /* @@ -429,9 +427,10 @@ __cursor_col_modify(WT_CURSOR_BTREE *cbt, u_int modify_type) * Row-store modify from a cursor. */ static inline int -__cursor_row_modify(WT_CURSOR_BTREE *cbt, u_int modify_type) +__cursor_row_modify(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt, u_int modify_type) { - return (__wt_row_modify(cbt, &cbt->iface.key, &cbt->iface.value, NULL, modify_type, false)); + return ( + __wt_row_modify(session, cbt, &cbt->iface.key, &cbt->iface.value, NULL, modify_type, false)); } /* @@ -485,8 +484,8 @@ __wt_btcur_search_uncommitted(WT_CURSOR_BTREE *cbt, WT_UPDATE **updp) session = (WT_SESSION_IMPL *)cursor->session; *updp = upd = NULL; /* -Wuninitialized */ - WT_RET(btree->type == BTREE_ROW ? __cursor_row_search(cbt, false, NULL, NULL) : - __cursor_col_search(cbt, NULL, NULL)); + WT_RET(btree->type == BTREE_ROW ? __cursor_row_search(session, cbt, NULL, false) : + __cursor_col_search(session, cbt, NULL)); /* * Ideally exact match should be found, as this transaction has searched for updates done by @@ -525,7 +524,7 @@ __wt_btcur_search(WT_CURSOR_BTREE *cbt) WT_DECL_RET; WT_SESSION_IMPL *session; WT_UPDATE *upd; - bool leaf_found, valid; + bool valid; btree = cbt->btree; cursor = &cbt->iface; @@ -556,18 +555,18 @@ __wt_btcur_search(WT_CURSOR_BTREE *cbt) if (__cursor_page_pinned(cbt, true)) { __wt_txn_cursor_op(session); - WT_ERR(btree->type == BTREE_ROW ? __cursor_row_search(cbt, false, cbt->ref, &leaf_found) : - __cursor_col_search(cbt, cbt->ref, &leaf_found)); + WT_ERR(btree->type == BTREE_ROW ? __cursor_row_search(session, cbt, cbt->ref, false) : + __cursor_col_search(session, cbt, cbt->ref)); /* Return, if prepare conflict encountered. */ - if (leaf_found && cbt->compare == 0) + if (cbt->compare == 0) WT_ERR(__wt_cursor_valid(cbt, &upd, &valid)); } if (!valid) { WT_ERR(__cursor_func_init(cbt, true)); - WT_ERR(btree->type == BTREE_ROW ? __cursor_row_search(cbt, false, NULL, NULL) : - __cursor_col_search(cbt, NULL, NULL)); + WT_ERR(btree->type == BTREE_ROW ? __cursor_row_search(session, cbt, NULL, false) : + __cursor_col_search(session, cbt, NULL)); /* Return, if prepare conflict encountered. */ if (cbt->compare == 0) @@ -575,7 +574,7 @@ __wt_btcur_search(WT_CURSOR_BTREE *cbt) } if (valid) - ret = __cursor_kv_return(cbt, upd); + ret = __cursor_kv_return(session, cbt, upd); else if (__cursor_fix_implicit(btree, cbt)) { /* * Creating a record past the end of the tree in a fixed-length column-store implicitly @@ -592,7 +591,7 @@ __wt_btcur_search(WT_CURSOR_BTREE *cbt) #ifdef HAVE_DIAGNOSTIC if (ret == 0) - WT_ERR(__wt_cursor_key_order_init(cbt)); + WT_ERR(__wt_cursor_key_order_init(session, cbt)); #endif err: @@ -617,7 +616,7 @@ __wt_btcur_search_near(WT_CURSOR_BTREE *cbt, int *exactp) WT_SESSION_IMPL *session; WT_UPDATE *upd; int exact; - bool leaf_found, valid; + bool valid; btree = cbt->btree; cursor = &cbt->iface; @@ -655,7 +654,7 @@ __wt_btcur_search_near(WT_CURSOR_BTREE *cbt, int *exactp) if (btree->type == BTREE_ROW && __cursor_page_pinned(cbt, true)) { __wt_txn_cursor_op(session); - WT_ERR(__cursor_row_search(cbt, true, cbt->ref, &leaf_found)); + WT_ERR(__cursor_row_search(session, cbt, cbt->ref, true)); /* * Search-near is trickier than search when searching an already pinned page. If search @@ -664,13 +663,13 @@ __wt_btcur_search_near(WT_CURSOR_BTREE *cbt, int *exactp) * append lists (there may be no page slots or we might be legitimately positioned after the * last page slot). Ignore those cases, it makes things too complicated. */ - if (leaf_found && cbt->slot != 0 && cbt->slot != cbt->ref->page->entries - 1) + if (cbt->slot != 0 && cbt->slot != cbt->ref->page->entries - 1) WT_ERR(__wt_cursor_valid(cbt, &upd, &valid)); } if (!valid) { WT_ERR(__cursor_func_init(cbt, true)); - WT_ERR(btree->type == BTREE_ROW ? __cursor_row_search(cbt, true, NULL, NULL) : - __cursor_col_search(cbt, NULL, NULL)); + WT_ERR(btree->type == BTREE_ROW ? __cursor_row_search(session, cbt, NULL, true) : + __cursor_col_search(session, cbt, NULL)); WT_ERR(__wt_cursor_valid(cbt, &upd, &valid)); } @@ -691,7 +690,7 @@ __wt_btcur_search_near(WT_CURSOR_BTREE *cbt, int *exactp) */ if (valid) { exact = cbt->compare; - ret = __cursor_kv_return(cbt, upd); + ret = __cursor_kv_return(session, cbt, upd); } else if (__cursor_fix_implicit(btree, cbt)) { cbt->recno = cursor->recno; cbt->v = 0; @@ -737,7 +736,7 @@ err: #ifdef HAVE_DIAGNOSTIC if (ret == 0) - WT_TRET(__wt_cursor_key_order_init(cbt)); + WT_TRET(__wt_cursor_key_order_init(session, cbt)); #endif if (ret != 0) { @@ -807,8 +806,8 @@ __wt_btcur_insert(WT_CURSOR_BTREE *cbt) * Correct to an exact match so we can update whatever we're pointing at. */ cbt->compare = 0; - ret = btree->type == BTREE_ROW ? __cursor_row_modify(cbt, WT_UPDATE_STANDARD) : - __cursor_col_modify(cbt, WT_UPDATE_STANDARD); + ret = btree->type == BTREE_ROW ? __cursor_row_modify(session, cbt, WT_UPDATE_STANDARD) : + __cursor_col_modify(session, cbt, WT_UPDATE_STANDARD); if (ret == 0) goto done; @@ -835,7 +834,7 @@ retry: WT_ERR(__cursor_func_init(cbt, true)); if (btree->type == BTREE_ROW) { - WT_ERR(__cursor_row_search(cbt, true, NULL, NULL)); + WT_ERR(__cursor_row_search(session, cbt, NULL, true)); /* * If not overwriting, fail if the key exists, else insert the key/value pair. */ @@ -845,7 +844,7 @@ retry: WT_ERR(WT_DUPLICATE_KEY); } - ret = __cursor_row_modify(cbt, WT_UPDATE_STANDARD); + ret = __cursor_row_modify(session, cbt, WT_UPDATE_STANDARD); } else if (append_key) { /* * Optionally insert a new record (ignoring the application's record number). The real @@ -853,11 +852,11 @@ retry: */ cbt->iface.recno = WT_RECNO_OOB; cbt->compare = 1; - WT_ERR(__cursor_col_search(cbt, NULL, NULL)); - WT_ERR(__cursor_col_modify(cbt, WT_UPDATE_STANDARD)); + WT_ERR(__cursor_col_search(session, cbt, NULL)); + WT_ERR(__cursor_col_modify(session, cbt, WT_UPDATE_STANDARD)); cursor->recno = cbt->recno; } else { - WT_ERR(__cursor_col_search(cbt, NULL, NULL)); + WT_ERR(__cursor_col_search(session, cbt, NULL)); /* * If not overwriting, fail if the key exists. Creating a record past the end of the tree in @@ -873,7 +872,7 @@ retry: WT_ERR(WT_DUPLICATE_KEY); } - WT_ERR(__cursor_col_modify(cbt, WT_UPDATE_STANDARD)); + WT_ERR(__cursor_col_modify(session, cbt, WT_UPDATE_STANDARD)); } err: @@ -953,7 +952,7 @@ __wt_btcur_insert_check(WT_CURSOR_BTREE *cbt) retry: WT_ERR(__cursor_func_init(cbt, true)); - WT_ERR(__cursor_row_search(cbt, true, NULL, NULL)); + WT_ERR(__cursor_row_search(session, cbt, NULL, true)); /* Just check for conflicts. */ ret = __curfile_update_check(cbt); @@ -1028,8 +1027,8 @@ __wt_btcur_remove(WT_CURSOR_BTREE *cbt, bool positioned) * Correct to an exact match so we can remove whatever we're pointing at. */ cbt->compare = 0; - ret = btree->type == BTREE_ROW ? __cursor_row_modify(cbt, WT_UPDATE_TOMBSTONE) : - __cursor_col_modify(cbt, WT_UPDATE_TOMBSTONE); + ret = btree->type == BTREE_ROW ? __cursor_row_modify(session, cbt, WT_UPDATE_TOMBSTONE) : + __cursor_col_modify(session, cbt, WT_UPDATE_TOMBSTONE); if (ret == 0) goto done; goto err; @@ -1050,7 +1049,7 @@ retry: WT_ERR(__cursor_func_init(cbt, true)); if (btree->type == BTREE_ROW) { - ret = __cursor_row_search(cbt, false, NULL, NULL); + ret = __cursor_row_search(session, cbt, NULL, false); if (ret == WT_NOTFOUND) goto search_notfound; WT_ERR(ret); @@ -1064,9 +1063,9 @@ retry: if (!valid) goto search_notfound; - ret = __cursor_row_modify(cbt, WT_UPDATE_TOMBSTONE); + ret = __cursor_row_modify(session, cbt, WT_UPDATE_TOMBSTONE); } else { - ret = __cursor_col_search(cbt, NULL, NULL); + ret = __cursor_col_search(session, cbt, NULL); if (ret == WT_NOTFOUND) goto search_notfound; WT_ERR(ret); @@ -1094,7 +1093,7 @@ retry: */ cbt->recno = cursor->recno; } else - ret = __cursor_col_modify(cbt, WT_UPDATE_TOMBSTONE); + ret = __cursor_col_modify(session, cbt, WT_UPDATE_TOMBSTONE); } err: @@ -1112,7 +1111,7 @@ err: */ if (positioned) { if (searched) - WT_TRET(__wt_key_return(cbt)); + WT_TRET(__wt_key_return(session, cbt)); } else { F_CLR(cursor, WT_CURSTD_KEY_SET); WT_TRET(__cursor_reset(cbt)); @@ -1175,7 +1174,7 @@ __btcur_update(WT_CURSOR_BTREE *cbt, WT_ITEM *value, u_int modify_type) WT_DECL_RET; WT_SESSION_IMPL *session; uint64_t yield_count, sleep_usecs; - bool leaf_found, valid; + bool valid; btree = cbt->btree; cursor = &cbt->iface; @@ -1204,8 +1203,8 @@ __btcur_update(WT_CURSOR_BTREE *cbt, WT_ITEM *value, u_int modify_type) * Correct to an exact match so we can update whatever we're pointing at. */ cbt->compare = 0; - ret = btree->type == BTREE_ROW ? __cursor_row_modify_v(cbt, value, modify_type) : - __cursor_col_modify_v(cbt, value, modify_type); + ret = btree->type == BTREE_ROW ? __cursor_row_modify_v(session, cbt, value, modify_type) : + __cursor_col_modify_v(session, cbt, value, modify_type); if (ret == 0) goto done; @@ -1228,22 +1227,12 @@ __btcur_update(WT_CURSOR_BTREE *cbt, WT_ITEM *value, u_int modify_type) WT_ERR(__cursor_localvalue(cursor)); __cursor_state_save(cursor, &state); - /* If our caller configures for a local search and we have a page pinned, do that search. */ - if (F_ISSET(cursor, WT_CURSTD_UPDATE_LOCAL) && __cursor_page_pinned(cbt, true)) { - __wt_txn_cursor_op(session); - - WT_ERR(btree->type == BTREE_ROW ? __cursor_row_search(cbt, true, cbt->ref, &leaf_found) : - __cursor_col_search(cbt, cbt->ref, &leaf_found)); - if (leaf_found) - goto update_local; - } - retry: WT_ERR(__cursor_func_init(cbt, true)); - WT_ERR(btree->type == BTREE_ROW ? __cursor_row_search(cbt, true, NULL, NULL) : - __cursor_col_search(cbt, NULL, NULL)); -update_local: + if (btree->type == BTREE_ROW) { + WT_ERR(__cursor_row_search(session, cbt, NULL, true)); + /* * If not overwriting, check for conflicts and fail if the key does not exist. */ @@ -1255,8 +1244,10 @@ update_local: if (!valid) WT_ERR(WT_NOTFOUND); } - ret = __cursor_row_modify_v(cbt, value, modify_type); + ret = __cursor_row_modify_v(session, cbt, value, modify_type); } else { + WT_ERR(__cursor_col_search(session, cbt, NULL)); + /* * If not overwriting, fail if the key doesn't exist. If we find an update for the key, * check for conflicts. Update the record if it exists. Creating a record past the end of @@ -1271,7 +1262,7 @@ update_local: if ((cbt->compare != 0 || !valid) && !__cursor_fix_implicit(btree, cbt)) WT_ERR(WT_NOTFOUND); } - ret = __cursor_col_modify_v(cbt, value, modify_type); + ret = __cursor_col_modify_v(session, cbt, value, modify_type); } err: @@ -1294,7 +1285,7 @@ done: /* * WT_CURSOR.update returns a key and a value. */ - ret = __cursor_kv_return(cbt, cbt->modify_update); + ret = __cursor_kv_return(session, cbt, cbt->modify_update); break; case WT_UPDATE_RESERVE: /* @@ -1307,7 +1298,7 @@ done: * WT_CURSOR.modify has already created the return value and our job is to leave it * untouched. */ - ret = __wt_key_return(cbt); + ret = __wt_key_return(session, cbt); break; case WT_UPDATE_BIRTHMARK: case WT_UPDATE_TOMBSTONE: @@ -1631,14 +1622,12 @@ __wt_btcur_equals(WT_CURSOR_BTREE *a_arg, WT_CURSOR_BTREE *b_arg, int *equalp) * Discard a cursor range from row-store or variable-width column-store tree. */ static int -__cursor_truncate( - WT_CURSOR_BTREE *start, WT_CURSOR_BTREE *stop, int (*rmfunc)(WT_CURSOR_BTREE *, u_int)) +__cursor_truncate(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *start, WT_CURSOR_BTREE *stop, + int (*rmfunc)(WT_SESSION_IMPL *, WT_CURSOR_BTREE *, u_int)) { WT_DECL_RET; - WT_SESSION_IMPL *session; uint64_t yield_count, sleep_usecs; - session = (WT_SESSION_IMPL *)start->iface.session; yield_count = sleep_usecs = 0; /* @@ -1661,7 +1650,7 @@ retry: WT_ASSERT(session, F_MASK((WT_CURSOR *)start, WT_CURSTD_KEY_SET) == WT_CURSTD_KEY_INT); for (;;) { - WT_ERR(rmfunc(start, WT_UPDATE_TOMBSTONE)); + WT_ERR(rmfunc(session, start, WT_UPDATE_TOMBSTONE)); if (stop != NULL && __cursor_equals(start, stop)) return (0); @@ -1686,15 +1675,13 @@ err: * Discard a cursor range from fixed-width column-store tree. */ static int -__cursor_truncate_fix( - WT_CURSOR_BTREE *start, WT_CURSOR_BTREE *stop, int (*rmfunc)(WT_CURSOR_BTREE *, u_int)) +__cursor_truncate_fix(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *start, WT_CURSOR_BTREE *stop, + int (*rmfunc)(WT_SESSION_IMPL *, WT_CURSOR_BTREE *, u_int)) { WT_DECL_RET; - WT_SESSION_IMPL *session; uint64_t yield_count, sleep_usecs; const uint8_t *value; - session = (WT_SESSION_IMPL *)start->iface.session; yield_count = sleep_usecs = 0; /* @@ -1720,7 +1707,7 @@ retry: for (;;) { value = (const uint8_t *)start->iface.value.data; if (*value != 0) - WT_ERR(rmfunc(start, WT_UPDATE_TOMBSTONE)); + WT_ERR(rmfunc(session, start, WT_UPDATE_TOMBSTONE)); if (stop != NULL && __cursor_equals(start, stop)) return (0); @@ -1768,10 +1755,10 @@ __wt_btcur_range_truncate(WT_CURSOR_BTREE *start, WT_CURSOR_BTREE *stop) switch (btree->type) { case BTREE_COL_FIX: - WT_ERR(__cursor_truncate_fix(start, stop, __cursor_col_modify)); + WT_ERR(__cursor_truncate_fix(session, start, stop, __cursor_col_modify)); break; case BTREE_COL_VAR: - WT_ERR(__cursor_truncate(start, stop, __cursor_col_modify)); + WT_ERR(__cursor_truncate(session, start, stop, __cursor_col_modify)); break; case BTREE_ROW: /* @@ -1783,7 +1770,7 @@ __wt_btcur_range_truncate(WT_CURSOR_BTREE *start, WT_CURSOR_BTREE *stop) * setting up the truncate so we're good to go: if that ever changes, we'd need to do * something here to ensure a fully instantiated cursor. */ - WT_ERR(__cursor_truncate(start, stop, __cursor_row_modify)); + WT_ERR(__cursor_truncate(session, start, stop, __cursor_row_modify)); break; } |