/* * __curbulk_insert_row -- * Row-store bulk cursor insert, with key-sort checks. */ static int __curbulk_insert_row(WT_CURSOR *cursor) { WT_BTREE *btree; WT_CURSOR_BULK *cbulk; WT_DECL_RET; WT_SESSION_IMPL *session; int cmp; cbulk = (WT_CURSOR_BULK *)cursor; btree = cbulk->cbt.btree; /* * Bulk cursor inserts are updates, but don't need auto-commit * transactions because they are single-threaded and not visible * until the bulk cursor is closed. */ CURSOR_API_CALL(cursor, session, insert, btree); WT_STAT_FAST_DATA_INCR(session, cursor_insert_bulk); WT_CURSOR_CHECKKEY(cursor); WT_CURSOR_CHECKVALUE(cursor); /* * If this isn't the first key inserted, compare it against the last key * to ensure the application doesn't accidentally corrupt the table. */ if (!cbulk->first_insert) { WT_ERR(__wt_compare(session, btree->collator, &cursor->key, &cbulk->last, &cmp)); if (cmp <= 0) WT_ERR(__bulk_row_keycmp_err(cbulk)); } else cbulk->first_insert = false; /* Save a copy of the key for the next comparison. */ WT_ERR(__wt_buf_set(session, &cbulk->last, cursor->key.data, cursor->key.size)); ret = __wt_bulk_insert_row(session, cbulk); err: API_END_RET(session, ret); }
/* * __wt_bulk_insert -- * Bulk insert, called once per item. */ int __wt_bulk_insert(WT_CURSOR_BULK *cbulk) { WT_BTREE *btree; WT_CURSOR *cursor; WT_SESSION_IMPL *session; int cmp; session = (WT_SESSION_IMPL *)cbulk->cbt.iface.session; btree = S2BT(session); cursor = &cbulk->cbt.iface; switch (btree->type) { case BTREE_COL_FIX: WT_RET(__wt_rec_col_fix_bulk_insert(cbulk)); break; case BTREE_COL_VAR: /* * If this isn't the first value inserted, compare it against * the last value and increment the RLE count. * * Instead of a "first time" variable, I'm using the RLE count, * because it is set to 0 exactly once, the first time through * the code. */ if (cbulk->rle != 0) { if (cbulk->cmp.size == cursor->value.size && memcmp(cbulk->cmp.data, cursor->value.data, cursor->value.size) == 0) { ++cbulk->rle; break; } WT_RET(__wt_rec_col_var_bulk_insert(cbulk)); } WT_RET(__wt_buf_set(session, &cbulk->cmp, cursor->value.data, cursor->value.size)); cbulk->rle = 1; break; case BTREE_ROW: /* * If this isn't the first value inserted, compare it against * the last key to ensure the application doesn't accidentally * corrupt the table. * * Instead of a "first time" variable, I'm using the RLE count, * because it is set to 0 exactly once, the first time through * the code. */ if (cbulk->rle != 0) { WT_RET(WT_LEX_CMP(session, btree->collator, &cursor->key, &cbulk->cmp, cmp)); if (cmp <= 0) return (__bulk_row_keycmp_err(cbulk)); } WT_RET(__wt_buf_set(session, &cbulk->cmp, cursor->key.data, cursor->key.size)); cbulk->rle = 1; WT_RET(__wt_rec_row_bulk_insert(cbulk)); break; WT_ILLEGAL_VALUE(session); } WT_STAT_FAST_DATA_INCR(session, cursor_insert_bulk); return (0); }