/** * Delete an item from the cache * @param trx the transaction to use * @param key the key of the item to delete * @param nkey the length of the key * @return true if we should go ahead and commit the transaction * or false if we should roll back (if the key didn't exists) */ static bool do_delete_item(ib_trx_t trx, const void* key, size_t nkey) { ib_crsr_t cursor= NULL; bool retval= false; if (do_locate_item(trx, key, nkey, &cursor)) { checked(ib_cursor_lock(cursor, IB_LOCK_X)); checked(ib_cursor_delete_row(cursor)); retval= true; } /* Release resources */ /* FALLTHROUGH */ error_exit: if (cursor != NULL) ib_cursor_close(cursor); return retval; }
/** * Try to get an item from the database * * @param trx the transaction to use * @param key the key to get * @param nkey the lenght of the key * @return a pointer to the item if I found it in the database */ static struct item* do_get_item(ib_trx_t trx, const void* key, size_t nkey) { ib_crsr_t cursor= NULL; ib_tpl_t tuple= NULL; struct item* retval= NULL; if (do_locate_item(trx, key, nkey, &cursor)) { tuple= ib_clust_read_tuple_create(cursor); if (tuple == NULL) { fprintf(stderr, "Failed to create read tuple\n"); goto error_exit; } checked(ib_cursor_read_row(cursor, tuple)); ib_col_meta_t meta; ib_ulint_t datalen= ib_col_get_meta(tuple, data_col_idx, &meta); ib_ulint_t flaglen= ib_col_get_meta(tuple, flags_col_idx, &meta); ib_ulint_t caslen= ib_col_get_meta(tuple, cas_col_idx, &meta); ib_ulint_t explen= ib_col_get_meta(tuple, exp_col_idx, &meta); const void *dataptr= ib_col_get_value(tuple, data_col_idx); retval= create_item(key, nkey, dataptr, datalen, 0, 0); if (retval == NULL) { fprintf(stderr, "Failed to allocate memory\n"); goto error_exit; } if (flaglen != 0) { ib_u32_t val; checked(ib_tuple_read_u32(tuple, flags_col_idx, &val)); retval->flags= (uint32_t)val; } if (caslen != 0) { ib_u64_t val; checked(ib_tuple_read_u64(tuple, cas_col_idx, &val)); retval->cas= (uint64_t)val; } if (explen != 0) { ib_u32_t val; checked(ib_tuple_read_u32(tuple, exp_col_idx, &val)); retval->exp= (time_t)val; } } /* Release resources */ /* FALLTHROUGH */ error_exit: if (tuple != NULL) ib_tuple_delete(tuple); if (cursor != NULL) { ib_err_t cursor_error; cursor_error= ib_cursor_close(cursor); (void) cursor_error; } return retval; }