/* * __wt_update_serial_func -- * Server function to add an WT_UPDATE entry in the page array. */ int __wt_update_serial_func(WT_SESSION_IMPL *session, void *args) { WT_PAGE *page; WT_UPDATE **new_upd, *upd, **upd_entry, **upd_obsolete; uint32_t write_gen; __wt_update_unpack( args, &page, &write_gen, &upd_entry, &new_upd, &upd, &upd_obsolete); /* Check the page's write-generation. */ WT_RET(__wt_page_write_gen_check(session, page, write_gen)); upd->next = *upd_entry; /* * Publish: there must be a barrier to ensure the new entry's next * pointer is set before we update the linked list. */ WT_PUBLISH(*upd_entry, upd); __wt_update_upd_taken(session, args, page); /* * If the page needs an update array (column-store pages and inserts on * row-store pages do not use the update array), our caller passed us * one of the correct size. Check the page still needs one (the write * generation test should have caught that, though). * * NOTE: it is important to do this after publishing that the update is * set. Code can assume that if the array is set, it is non-empty. */ if (new_upd != NULL && page->u.row.upd == NULL) { page->u.row.upd = new_upd; __wt_update_new_upd_taken(session, args, page); } /* Discard obsolete WT_UPDATE structures. */ *upd_obsolete = __wt_update_obsolete_check(session, upd->next); __wt_page_and_tree_modify_set(session, page); return (0); }
/* * __wt_insert_serial_func -- * Server function to add an WT_INSERT entry to the page. */ int __wt_insert_serial_func(WT_SESSION_IMPL *session, void *args) { WT_INSERT *new_ins, ***ins_stack; WT_INSERT_HEAD *inshead, **insheadp, **new_inslist, *new_inshead; WT_PAGE *page; uint32_t write_gen; u_int i, skipdepth; __wt_insert_unpack(args, &page, &write_gen, &insheadp, &ins_stack, &new_inslist, &new_inshead, &new_ins, &skipdepth); /* Check the page's write-generation. */ WT_RET(__wt_page_write_gen_check(session, page, write_gen)); /* * Publish: First, point the new WT_INSERT item's skiplist references * to the next elements in the insert list, then flush memory. Second, * update the skiplist elements that reference the new WT_INSERT item, * this ensures the list is never inconsistent. */ if ((inshead = *insheadp) == NULL) inshead = new_inshead; for (i = 0; i < skipdepth; i++) new_ins->next[i] = *ins_stack[i]; WT_WRITE_BARRIER(); for (i = 0; i < skipdepth; i++) { if (inshead->tail[i] == NULL || ins_stack[i] == &inshead->tail[i]->next[i]) inshead->tail[i] = new_ins; *ins_stack[i] = new_ins; } __wt_insert_new_ins_taken(session, args, page); /* * If the insert head does not yet have an insert list, our caller * passed us one. * * NOTE: it is important to do this after the item has been added to * the list. Code can assume that if the list is set, it is non-empty. */ if (*insheadp == NULL) { WT_PUBLISH(*insheadp, new_inshead); __wt_insert_new_inshead_taken(session, args, page); } /* * If the page does not yet have an insert array, our caller passed * us one. * * NOTE: it is important to do this after publishing the list entry. * Code can assume that if the array is set, it is non-empty. */ if (page->type == WT_PAGE_ROW_LEAF) { if (page->u.row.ins == NULL) { page->u.row.ins = new_inslist; __wt_insert_new_inslist_taken(session, args, page); } } else if (page->modify->update == NULL) { page->modify->update = new_inslist; __wt_insert_new_inslist_taken(session, args, page); } __wt_page_and_tree_modify_set(session, page); return (0); }
/* * __wt_col_append_serial_func -- * Server function to append an WT_INSERT entry to the tree. */ int __wt_col_append_serial_func(WT_SESSION_IMPL *session, void *args) { WT_BTREE *btree; WT_INSERT *ins, *new_ins, ***ins_stack, **next_stack; WT_INSERT_HEAD *inshead, **insheadp, **new_inslist, *new_inshead; WT_PAGE *page; uint64_t recno; uint32_t write_gen; u_int i, skipdepth; btree = S2BT(session); __wt_col_append_unpack(args, &page, &write_gen, &insheadp, &ins_stack, &next_stack, &new_inslist, &new_inshead, &new_ins, &skipdepth); /* Check the page's write-generation. */ WT_RET(__wt_page_write_gen_check(session, page, write_gen)); if ((inshead = *insheadp) == NULL) inshead = new_inshead; /* * If the application specified a record number, there's a race: the * application may have searched for the record, not found it, then * called into the append code, and another thread might have added * the record. Fortunately, we're in the right place because if the * record didn't exist at some point, it can only have been created * on this list. Search for the record, if specified. */ if ((recno = WT_INSERT_RECNO(new_ins)) == 0) recno = WT_INSERT_RECNO(new_ins) = ++btree->last_recno; ins = __col_insert_search(inshead, ins_stack, next_stack, recno); /* If we find the record number, there's been a race. */ if (ins != NULL && WT_INSERT_RECNO(ins) == recno) WT_RET(WT_RESTART); /* * Publish: First, point the new WT_INSERT item's skiplist references * to the next elements in the insert list, then flush memory. Second, * update the skiplist elements that reference the new WT_INSERT item, * this ensures the list is never inconsistent. */ for (i = 0; i < skipdepth; i++) new_ins->next[i] = *ins_stack[i]; WT_WRITE_BARRIER(); for (i = 0; i < skipdepth; i++) { if (inshead->tail[i] == NULL || ins_stack[i] == &inshead->tail[i]->next[i]) inshead->tail[i] = new_ins; *ins_stack[i] = new_ins; } __wt_col_append_new_ins_taken(args); /* * If the insert head does not yet have an insert list, our caller * passed us one. * * NOTE: it is important to do this after the item has been added to * the list. Code can assume that if the list is set, it is non-empty. */ if (*insheadp == NULL) { WT_PUBLISH(*insheadp, new_inshead); __wt_col_append_new_inshead_taken(args); } /* * If the page does not yet have an insert array, our caller passed * us one. * * NOTE: it is important to do this after publishing the list entry. * Code can assume that if the array is set, it is non-empty. */ if (page->modify->append == NULL) { page->modify->append = new_inslist; __wt_col_append_new_inslist_taken(args); } /* * If we don't find the record, check to see if we extended the file, * and update the last record number. */ if (recno > btree->last_recno) btree->last_recno = recno; __wt_page_and_tree_modify_set(session, page); return (0); }