2009-02-17 10:05:45 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
|
|
|
|
Copyright (c) 1997, 2009, Innobase Oy. All Rights Reserved.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
|
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/******************************************************
|
|
|
|
Undo modify of a row
|
|
|
|
|
|
|
|
Created 2/27/1997 Heikki Tuuri
|
|
|
|
*******************************************************/
|
|
|
|
|
|
|
|
#include "row0umod.h"
|
|
|
|
|
|
|
|
#ifdef UNIV_NONINL
|
|
|
|
#include "row0umod.ic"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "dict0dict.h"
|
|
|
|
#include "dict0boot.h"
|
|
|
|
#include "trx0undo.h"
|
|
|
|
#include "trx0roll.h"
|
|
|
|
#include "btr0btr.h"
|
|
|
|
#include "mach0data.h"
|
|
|
|
#include "row0undo.h"
|
|
|
|
#include "row0vers.h"
|
|
|
|
#include "trx0trx.h"
|
|
|
|
#include "trx0rec.h"
|
|
|
|
#include "row0row.h"
|
|
|
|
#include "row0upd.h"
|
|
|
|
#include "que0que.h"
|
|
|
|
#include "log0log.h"
|
|
|
|
|
|
|
|
/* Considerations on undoing a modify operation.
|
|
|
|
(1) Undoing a delete marking: all index records should be found. Some of
|
|
|
|
them may have delete mark already FALSE, if the delete mark operation was
|
|
|
|
stopped underway, or if the undo operation ended prematurely because of a
|
|
|
|
system crash.
|
|
|
|
(2) Undoing an update of a delete unmarked record: the newer version of
|
|
|
|
an updated secondary index entry should be removed if no prior version
|
|
|
|
of the clustered index record requires its existence. Otherwise, it should
|
|
|
|
be delete marked.
|
|
|
|
(3) Undoing an update of a delete marked record. In this kind of update a
|
|
|
|
delete marked clustered index record was delete unmarked and possibly also
|
|
|
|
some of its fields were changed. Now, it is possible that the delete marked
|
|
|
|
version has become obsolete at the time the undo is started. */
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Checks if also the previous version of the clustered index record was
|
|
|
|
modified or inserted by the same transaction, and its undo number is such
|
|
|
|
that it should be undone in the same rollback. */
|
|
|
|
UNIV_INLINE
|
|
|
|
ibool
|
|
|
|
row_undo_mod_undo_also_prev_vers(
|
|
|
|
/*=============================*/
|
|
|
|
/* out: TRUE if also previous modify or
|
|
|
|
insert of this row should be undone */
|
2006-02-23 19:25:29 +00:00
|
|
|
undo_node_t* node, /* in: row undo node */
|
2005-10-27 07:29:40 +00:00
|
|
|
dulint* undo_no)/* out: the undo number */
|
|
|
|
{
|
|
|
|
trx_undo_rec_t* undo_rec;
|
|
|
|
trx_t* trx;
|
|
|
|
|
|
|
|
trx = node->trx;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (0 != ut_dulint_cmp(node->new_trx_id, trx->id)) {
|
|
|
|
|
|
|
|
*undo_no = ut_dulint_zero;
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_rec = trx_undo_get_undo_rec_low(node->new_roll_ptr, node->heap);
|
|
|
|
|
|
|
|
*undo_no = trx_undo_rec_get_undo_no(undo_rec);
|
|
|
|
|
|
|
|
return(ut_dulint_cmp(trx->roll_limit, *undo_no) <= 0);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/***************************************************************
|
|
|
|
Undoes a modify in a clustered index record. */
|
|
|
|
static
|
|
|
|
ulint
|
|
|
|
row_undo_mod_clust_low(
|
|
|
|
/*===================*/
|
|
|
|
/* out: DB_SUCCESS, DB_FAIL, or error code:
|
|
|
|
we may run out of file space */
|
|
|
|
undo_node_t* node, /* in: row undo node */
|
|
|
|
que_thr_t* thr, /* in: query thread */
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
mtr_t* mtr, /* in: mtr; must be committed before
|
|
|
|
latching any further pages */
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint mode) /* in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE */
|
|
|
|
{
|
|
|
|
btr_pcur_t* pcur;
|
|
|
|
btr_cur_t* btr_cur;
|
|
|
|
ulint err;
|
|
|
|
ibool success;
|
|
|
|
|
|
|
|
pcur = &(node->pcur);
|
|
|
|
btr_cur = btr_pcur_get_btr_cur(pcur);
|
|
|
|
|
|
|
|
success = btr_pcur_restore_position(mode, pcur, mtr);
|
|
|
|
|
|
|
|
ut_ad(success);
|
|
|
|
|
|
|
|
if (mode == BTR_MODIFY_LEAF) {
|
|
|
|
|
|
|
|
err = btr_cur_optimistic_update(BTR_NO_LOCKING_FLAG
|
2006-08-29 09:30:31 +00:00
|
|
|
| BTR_NO_UNDO_LOG_FLAG
|
|
|
|
| BTR_KEEP_SYS_FLAG,
|
|
|
|
btr_cur, node->update,
|
|
|
|
node->cmpl_info, thr, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
} else {
|
2007-03-28 19:35:52 +00:00
|
|
|
mem_heap_t* heap = NULL;
|
|
|
|
big_rec_t* dummy_big_rec;
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(mode == BTR_MODIFY_TREE);
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
err = btr_cur_pessimistic_update(
|
|
|
|
BTR_NO_LOCKING_FLAG
|
|
|
|
| BTR_NO_UNDO_LOG_FLAG
|
|
|
|
| BTR_KEEP_SYS_FLAG,
|
2007-03-28 19:35:52 +00:00
|
|
|
btr_cur, &heap, &dummy_big_rec, node->update,
|
2006-09-19 10:14:07 +00:00
|
|
|
node->cmpl_info, thr, mtr);
|
2007-03-28 19:35:52 +00:00
|
|
|
|
|
|
|
ut_a(!dummy_big_rec);
|
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/***************************************************************
|
|
|
|
Removes a clustered index record after undo if possible. */
|
|
|
|
static
|
|
|
|
ulint
|
|
|
|
row_undo_mod_remove_clust_low(
|
|
|
|
/*==========================*/
|
|
|
|
/* out: DB_SUCCESS, DB_FAIL, or error code:
|
|
|
|
we may run out of file space */
|
|
|
|
undo_node_t* node, /* in: row undo node */
|
|
|
|
que_thr_t* thr __attribute__((unused)), /* in: query thread */
|
|
|
|
mtr_t* mtr, /* in: mtr */
|
|
|
|
ulint mode) /* in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE */
|
|
|
|
{
|
|
|
|
btr_pcur_t* pcur;
|
|
|
|
btr_cur_t* btr_cur;
|
|
|
|
ulint err;
|
|
|
|
ibool success;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
pcur = &(node->pcur);
|
|
|
|
btr_cur = btr_pcur_get_btr_cur(pcur);
|
|
|
|
|
|
|
|
success = btr_pcur_restore_position(mode, pcur, mtr);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find out if we can remove the whole clustered index record */
|
|
|
|
|
|
|
|
if (node->rec_type == TRX_UNDO_UPD_DEL_REC
|
2006-08-29 09:30:31 +00:00
|
|
|
&& !row_vers_must_preserve_del_marked(node->new_trx_id, mtr)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* Ok, we can remove */
|
|
|
|
} else {
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (mode == BTR_MODIFY_LEAF) {
|
|
|
|
success = btr_cur_optimistic_delete(btr_cur, mtr);
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
err = DB_SUCCESS;
|
|
|
|
} else {
|
|
|
|
err = DB_FAIL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ut_ad(mode == BTR_MODIFY_TREE);
|
|
|
|
|
|
|
|
/* Note that since this operation is analogous to purge,
|
|
|
|
we can free also inherited externally stored fields:
|
branches/zip: In the rollback of incomplete transactions after crash
recovery, tolerate clustered index records whose externally stored
columns have not been written. This should remove the assertion failures
that were reported as Mantis issue#58, issue#62, issue#64.
trx_is_recv(): New function: TRUE if this transaction is rolling back
an incomplete transaction in crash recovery.
enum trx_rbmode: Rollback modes: no rollback, normal rollback, crash recovery.
btr_cur_pessimistic_delete(), btr_free_externally_stored_field(),
btr_rec_free_externally_stored_fields():
Replace the ibool parameter with enum trx_rbmode.
btr_free_externally_stored_field(): If field_ref is zero, return
but assert ut_a(rbmode == RB_RECOVERY). Unless InnoDB has crashed
while inserting a clustered index record, field_ref should not be zero.
btr_rec_free_updated_extern_fields(): Add the parameter enum trx_rbmode.
btr_cur_pessimistic_update(): Pass the rbmode parameter to
btr_rec_free_updated_extern_fields().
row_undo_ins(), row_undo_mod_upd_del_sec(): If row_build_index_entry()
fails, assert trx_is_recv() and skip this secondary index.
row_undo_mod_upd_del_sec(): Empty the heap at the end of each loop
iteration in order to conserve memory and to reduce the number of
low-level memory allocations.
2008-08-06 08:48:34 +00:00
|
|
|
hence the RB_NONE in the call below */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/zip: In the rollback of incomplete transactions after crash
recovery, tolerate clustered index records whose externally stored
columns have not been written. This should remove the assertion failures
that were reported as Mantis issue#58, issue#62, issue#64.
trx_is_recv(): New function: TRUE if this transaction is rolling back
an incomplete transaction in crash recovery.
enum trx_rbmode: Rollback modes: no rollback, normal rollback, crash recovery.
btr_cur_pessimistic_delete(), btr_free_externally_stored_field(),
btr_rec_free_externally_stored_fields():
Replace the ibool parameter with enum trx_rbmode.
btr_free_externally_stored_field(): If field_ref is zero, return
but assert ut_a(rbmode == RB_RECOVERY). Unless InnoDB has crashed
while inserting a clustered index record, field_ref should not be zero.
btr_rec_free_updated_extern_fields(): Add the parameter enum trx_rbmode.
btr_cur_pessimistic_update(): Pass the rbmode parameter to
btr_rec_free_updated_extern_fields().
row_undo_ins(), row_undo_mod_upd_del_sec(): If row_build_index_entry()
fails, assert trx_is_recv() and skip this secondary index.
row_undo_mod_upd_del_sec(): Empty the heap at the end of each loop
iteration in order to conserve memory and to reduce the number of
low-level memory allocations.
2008-08-06 08:48:34 +00:00
|
|
|
btr_cur_pessimistic_delete(&err, FALSE, btr_cur, RB_NONE, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* The delete operation may fail if we have little
|
|
|
|
file space left: TODO: easiest to crash the database
|
|
|
|
and restart with more file space */
|
|
|
|
}
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/***************************************************************
|
|
|
|
Undoes a modify in a clustered index record. Sets also the node state for the
|
|
|
|
next round of undo. */
|
|
|
|
static
|
|
|
|
ulint
|
|
|
|
row_undo_mod_clust(
|
|
|
|
/*===============*/
|
|
|
|
/* out: DB_SUCCESS or error code: we may run
|
|
|
|
out of file space */
|
|
|
|
undo_node_t* node, /* in: row undo node */
|
|
|
|
que_thr_t* thr) /* in: query thread */
|
|
|
|
{
|
|
|
|
btr_pcur_t* pcur;
|
|
|
|
mtr_t mtr;
|
|
|
|
ulint err;
|
|
|
|
ibool success;
|
|
|
|
ibool more_vers;
|
|
|
|
dulint new_undo_no;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(node && thr);
|
|
|
|
|
|
|
|
/* Check if also the previous version of the clustered index record
|
|
|
|
should be undone in this same rollback operation */
|
|
|
|
|
|
|
|
more_vers = row_undo_mod_undo_also_prev_vers(node, &new_undo_no);
|
|
|
|
|
|
|
|
pcur = &(node->pcur);
|
|
|
|
|
|
|
|
mtr_start(&mtr);
|
|
|
|
|
|
|
|
/* Try optimistic processing of the record, keeping changes within
|
|
|
|
the index page */
|
|
|
|
|
|
|
|
err = row_undo_mod_clust_low(node, thr, &mtr, BTR_MODIFY_LEAF);
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
btr_pcur_commit_specify_mtr(pcur, &mtr);
|
|
|
|
|
|
|
|
/* We may have to modify tree structure: do a pessimistic
|
|
|
|
descent down the index tree */
|
|
|
|
|
|
|
|
mtr_start(&mtr);
|
|
|
|
|
|
|
|
err = row_undo_mod_clust_low(node, thr, &mtr, BTR_MODIFY_TREE);
|
|
|
|
}
|
|
|
|
|
|
|
|
btr_pcur_commit_specify_mtr(pcur, &mtr);
|
|
|
|
|
|
|
|
if (err == DB_SUCCESS && node->rec_type == TRX_UNDO_UPD_DEL_REC) {
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
mtr_start(&mtr);
|
|
|
|
|
|
|
|
err = row_undo_mod_remove_clust_low(node, thr, &mtr,
|
2006-08-29 09:30:31 +00:00
|
|
|
BTR_MODIFY_LEAF);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
btr_pcur_commit_specify_mtr(pcur, &mtr);
|
|
|
|
|
|
|
|
/* We may have to modify tree structure: do a
|
|
|
|
pessimistic descent down the index tree */
|
|
|
|
|
|
|
|
mtr_start(&mtr);
|
|
|
|
|
|
|
|
err = row_undo_mod_remove_clust_low(node, thr, &mtr,
|
2006-08-29 09:30:31 +00:00
|
|
|
BTR_MODIFY_TREE);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
btr_pcur_commit_specify_mtr(pcur, &mtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
node->state = UNDO_NODE_FETCH_NEXT;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
|
|
|
trx_undo_rec_release(node->trx, node->undo_no);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (more_vers && err == DB_SUCCESS) {
|
|
|
|
|
|
|
|
/* Reserve the undo log record to the prior version after
|
|
|
|
committing &mtr: this is necessary to comply with the latching
|
|
|
|
order, as &mtr may contain the fsp latch which is lower in
|
|
|
|
the latch hierarchy than trx->undo_mutex. */
|
|
|
|
|
|
|
|
success = trx_undo_rec_reserve(node->trx, new_undo_no);
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
node->state = UNDO_NODE_PREV_VERS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Delete marks or removes a secondary index entry if found. */
|
|
|
|
static
|
|
|
|
ulint
|
|
|
|
row_undo_mod_del_mark_or_remove_sec_low(
|
|
|
|
/*====================================*/
|
|
|
|
/* out: DB_SUCCESS, DB_FAIL, or
|
|
|
|
DB_OUT_OF_FILE_SPACE */
|
|
|
|
undo_node_t* node, /* in: row undo node */
|
|
|
|
que_thr_t* thr, /* in: query thread */
|
|
|
|
dict_index_t* index, /* in: index */
|
|
|
|
dtuple_t* entry, /* in: index entry */
|
|
|
|
ulint mode) /* in: latch mode BTR_MODIFY_LEAF or
|
2006-02-23 19:25:29 +00:00
|
|
|
BTR_MODIFY_TREE */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
ibool found;
|
|
|
|
btr_pcur_t pcur;
|
|
|
|
btr_cur_t* btr_cur;
|
|
|
|
ibool success;
|
|
|
|
ibool old_has;
|
|
|
|
ulint err;
|
|
|
|
mtr_t mtr;
|
|
|
|
mtr_t mtr_vers;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
log_free_check();
|
|
|
|
mtr_start(&mtr);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
found = row_search_index_entry(index, entry, mode, &pcur, &mtr);
|
|
|
|
|
|
|
|
btr_cur = btr_pcur_get_btr_cur(&pcur);
|
|
|
|
|
|
|
|
if (!found) {
|
2008-11-28 14:18:43 +00:00
|
|
|
/* In crash recovery, the secondary index record may
|
|
|
|
be missing if the UPDATE did not have time to insert
|
|
|
|
the secondary index records before the crash. When we
|
|
|
|
are undoing that UPDATE in crash recovery, the record
|
2008-12-05 08:02:54 +00:00
|
|
|
may be missing.
|
|
|
|
|
|
|
|
In normal processing, if an update ends in a deadlock
|
|
|
|
before it has inserted all updated secondary index
|
|
|
|
records, then the undo will not find those records. */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
btr_pcur_close(&pcur);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We should remove the index record if no prior version of the row,
|
|
|
|
which cannot be purged yet, requires its existence. If some requires,
|
|
|
|
we should delete mark the record. */
|
|
|
|
|
|
|
|
mtr_start(&mtr_vers);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
success = btr_pcur_restore_position(BTR_SEARCH_LEAF, &(node->pcur),
|
2006-08-29 09:30:31 +00:00
|
|
|
&mtr_vers);
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_a(success);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
old_has = row_vers_old_has_index_entry(FALSE,
|
2006-08-29 09:30:31 +00:00
|
|
|
btr_pcur_get_rec(&(node->pcur)),
|
|
|
|
&mtr_vers, index, entry);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (old_has) {
|
|
|
|
err = btr_cur_del_mark_set_sec_rec(BTR_NO_LOCKING_FLAG,
|
2006-08-29 09:30:31 +00:00
|
|
|
btr_cur, TRUE, thr, &mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(err == DB_SUCCESS);
|
|
|
|
} else {
|
|
|
|
/* Remove the index record */
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
if (mode == BTR_MODIFY_LEAF) {
|
2005-10-27 07:29:40 +00:00
|
|
|
success = btr_cur_optimistic_delete(btr_cur, &mtr);
|
|
|
|
if (success) {
|
|
|
|
err = DB_SUCCESS;
|
|
|
|
} else {
|
|
|
|
err = DB_FAIL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ut_ad(mode == BTR_MODIFY_TREE);
|
|
|
|
|
branches/zip: In the rollback of incomplete transactions after crash
recovery, tolerate clustered index records whose externally stored
columns have not been written. This should remove the assertion failures
that were reported as Mantis issue#58, issue#62, issue#64.
trx_is_recv(): New function: TRUE if this transaction is rolling back
an incomplete transaction in crash recovery.
enum trx_rbmode: Rollback modes: no rollback, normal rollback, crash recovery.
btr_cur_pessimistic_delete(), btr_free_externally_stored_field(),
btr_rec_free_externally_stored_fields():
Replace the ibool parameter with enum trx_rbmode.
btr_free_externally_stored_field(): If field_ref is zero, return
but assert ut_a(rbmode == RB_RECOVERY). Unless InnoDB has crashed
while inserting a clustered index record, field_ref should not be zero.
btr_rec_free_updated_extern_fields(): Add the parameter enum trx_rbmode.
btr_cur_pessimistic_update(): Pass the rbmode parameter to
btr_rec_free_updated_extern_fields().
row_undo_ins(), row_undo_mod_upd_del_sec(): If row_build_index_entry()
fails, assert trx_is_recv() and skip this secondary index.
row_undo_mod_upd_del_sec(): Empty the heap at the end of each loop
iteration in order to conserve memory and to reduce the number of
low-level memory allocations.
2008-08-06 08:48:34 +00:00
|
|
|
/* No need to distinguish RB_RECOVERY here, because we
|
|
|
|
are deleting a secondary index record: the distinction
|
|
|
|
between RB_NORMAL and RB_RECOVERY only matters when
|
|
|
|
deleting a record that contains externally stored
|
|
|
|
columns. */
|
|
|
|
ut_ad(!dict_index_is_clust(index));
|
2005-10-27 07:29:40 +00:00
|
|
|
btr_cur_pessimistic_delete(&err, FALSE, btr_cur,
|
branches/zip: In the rollback of incomplete transactions after crash
recovery, tolerate clustered index records whose externally stored
columns have not been written. This should remove the assertion failures
that were reported as Mantis issue#58, issue#62, issue#64.
trx_is_recv(): New function: TRUE if this transaction is rolling back
an incomplete transaction in crash recovery.
enum trx_rbmode: Rollback modes: no rollback, normal rollback, crash recovery.
btr_cur_pessimistic_delete(), btr_free_externally_stored_field(),
btr_rec_free_externally_stored_fields():
Replace the ibool parameter with enum trx_rbmode.
btr_free_externally_stored_field(): If field_ref is zero, return
but assert ut_a(rbmode == RB_RECOVERY). Unless InnoDB has crashed
while inserting a clustered index record, field_ref should not be zero.
btr_rec_free_updated_extern_fields(): Add the parameter enum trx_rbmode.
btr_cur_pessimistic_update(): Pass the rbmode parameter to
btr_rec_free_updated_extern_fields().
row_undo_ins(), row_undo_mod_upd_del_sec(): If row_build_index_entry()
fails, assert trx_is_recv() and skip this secondary index.
row_undo_mod_upd_del_sec(): Empty the heap at the end of each loop
iteration in order to conserve memory and to reduce the number of
low-level memory allocations.
2008-08-06 08:48:34 +00:00
|
|
|
RB_NORMAL, &mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* The delete operation may fail if we have little
|
|
|
|
file space left: TODO: easiest to crash the database
|
|
|
|
and restart with more file space */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
btr_pcur_commit_specify_mtr(&(node->pcur), &mtr_vers);
|
|
|
|
btr_pcur_close(&pcur);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Delete marks or removes a secondary index entry if found.
|
|
|
|
NOTE that if we updated the fields of a delete-marked secondary index record
|
|
|
|
so that alphabetically they stayed the same, e.g., 'abc' -> 'aBc', we cannot
|
|
|
|
return to the original values because we do not know them. But this should
|
|
|
|
not cause problems because in row0sel.c, in queries we always retrieve the
|
|
|
|
clustered index record or an earlier version of it, if the secondary index
|
|
|
|
record through which we do the search is delete-marked. */
|
|
|
|
static
|
|
|
|
ulint
|
|
|
|
row_undo_mod_del_mark_or_remove_sec(
|
|
|
|
/*================================*/
|
|
|
|
/* out: DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
|
|
|
|
undo_node_t* node, /* in: row undo node */
|
|
|
|
que_thr_t* thr, /* in: query thread */
|
|
|
|
dict_index_t* index, /* in: index */
|
|
|
|
dtuple_t* entry) /* in: index entry */
|
|
|
|
{
|
|
|
|
ulint err;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
err = row_undo_mod_del_mark_or_remove_sec_low(node, thr, index,
|
2006-08-29 09:30:31 +00:00
|
|
|
entry, BTR_MODIFY_LEAF);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (err == DB_SUCCESS) {
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
err = row_undo_mod_del_mark_or_remove_sec_low(node, thr, index,
|
2006-08-29 09:30:31 +00:00
|
|
|
entry, BTR_MODIFY_TREE);
|
2006-02-23 19:25:29 +00:00
|
|
|
return(err);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Delete unmarks a secondary index entry which must be found. It might not be
|
|
|
|
delete-marked at the moment, but it does not harm to unmark it anyway. We also
|
|
|
|
need to update the fields of the secondary index record if we updated its
|
|
|
|
fields but alphabetically they stayed the same, e.g., 'abc' -> 'aBc'. */
|
|
|
|
static
|
|
|
|
ulint
|
|
|
|
row_undo_mod_del_unmark_sec_and_undo_update(
|
|
|
|
/*========================================*/
|
|
|
|
/* out: DB_FAIL or DB_SUCCESS or
|
|
|
|
DB_OUT_OF_FILE_SPACE */
|
|
|
|
ulint mode, /* in: search mode: BTR_MODIFY_LEAF or
|
|
|
|
BTR_MODIFY_TREE */
|
|
|
|
que_thr_t* thr, /* in: query thread */
|
|
|
|
dict_index_t* index, /* in: index */
|
|
|
|
dtuple_t* entry) /* in: index entry */
|
|
|
|
{
|
|
|
|
mem_heap_t* heap;
|
|
|
|
btr_pcur_t pcur;
|
|
|
|
upd_t* update;
|
|
|
|
ulint err = DB_SUCCESS;
|
|
|
|
big_rec_t* dummy_big_rec;
|
|
|
|
mtr_t mtr;
|
|
|
|
trx_t* trx = thr_get_trx(thr);
|
|
|
|
|
2007-08-29 08:45:34 +00:00
|
|
|
/* Ignore indexes that are being created. */
|
2007-08-31 09:58:22 +00:00
|
|
|
if (UNIV_UNLIKELY(*index->name == TEMP_INDEX_PREFIX)) {
|
2007-04-04 11:05:33 +00:00
|
|
|
|
2007-08-29 08:45:34 +00:00
|
|
|
return(DB_SUCCESS);
|
2007-04-04 11:05:33 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-09-24 10:47:45 +00:00
|
|
|
log_free_check();
|
|
|
|
mtr_start(&mtr);
|
|
|
|
|
2007-08-29 08:45:34 +00:00
|
|
|
if (UNIV_UNLIKELY(!row_search_index_entry(index, entry,
|
|
|
|
mode, &pcur, &mtr))) {
|
2005-10-27 07:29:40 +00:00
|
|
|
fputs("InnoDB: error in sec index entry del undo in\n"
|
2006-08-29 09:30:31 +00:00
|
|
|
"InnoDB: ", stderr);
|
2005-10-27 07:29:40 +00:00
|
|
|
dict_index_name_print(stderr, trx, index);
|
|
|
|
fputs("\n"
|
2006-08-29 09:30:31 +00:00
|
|
|
"InnoDB: tuple ", stderr);
|
2005-10-27 07:29:40 +00:00
|
|
|
dtuple_print(stderr, entry);
|
|
|
|
fputs("\n"
|
2006-08-29 09:30:31 +00:00
|
|
|
"InnoDB: record ", stderr);
|
2005-10-27 07:29:40 +00:00
|
|
|
rec_print(stderr, btr_pcur_get_rec(&pcur), index);
|
|
|
|
putc('\n', stderr);
|
|
|
|
trx_print(stderr, trx, 0);
|
|
|
|
fputs("\n"
|
2006-08-29 09:30:31 +00:00
|
|
|
"InnoDB: Submit a detailed bug report"
|
|
|
|
" to http://bugs.mysql.com\n", stderr);
|
2005-10-27 07:29:40 +00:00
|
|
|
} else {
|
|
|
|
btr_cur_t* btr_cur = btr_pcur_get_btr_cur(&pcur);
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
err = btr_cur_del_mark_set_sec_rec(BTR_NO_LOCKING_FLAG,
|
2006-08-29 09:30:31 +00:00
|
|
|
btr_cur, FALSE, thr, &mtr);
|
2006-02-23 19:25:29 +00:00
|
|
|
ut_a(err == DB_SUCCESS);
|
2005-10-27 07:29:40 +00:00
|
|
|
heap = mem_heap_create(100);
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
update = row_upd_build_sec_rec_difference_binary(
|
|
|
|
index, entry, btr_cur_get_rec(btr_cur), trx, heap);
|
2006-02-23 19:25:29 +00:00
|
|
|
if (upd_get_n_fields(update) == 0) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* Do nothing */
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
} else if (mode == BTR_MODIFY_LEAF) {
|
2006-02-23 19:25:29 +00:00
|
|
|
/* Try an optimistic updating of the record, keeping
|
2005-10-27 07:29:40 +00:00
|
|
|
changes within the page */
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
err = btr_cur_optimistic_update(
|
|
|
|
BTR_KEEP_SYS_FLAG | BTR_NO_LOCKING_FLAG,
|
|
|
|
btr_cur, update, 0, thr, &mtr);
|
2006-02-10 15:06:17 +00:00
|
|
|
switch (err) {
|
|
|
|
case DB_OVERFLOW:
|
|
|
|
case DB_UNDERFLOW:
|
|
|
|
case DB_ZIP_OVERFLOW:
|
|
|
|
err = DB_FAIL;
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
} else {
|
|
|
|
ut_a(mode == BTR_MODIFY_TREE);
|
2006-09-19 10:14:07 +00:00
|
|
|
err = btr_cur_pessimistic_update(
|
|
|
|
BTR_KEEP_SYS_FLAG | BTR_NO_LOCKING_FLAG,
|
2007-03-28 19:35:52 +00:00
|
|
|
btr_cur, &heap, &dummy_big_rec,
|
2006-09-19 10:14:07 +00:00
|
|
|
update, 0, thr, &mtr);
|
2007-03-28 19:35:52 +00:00
|
|
|
ut_a(!dummy_big_rec);
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
|
|
|
|
|
|
|
btr_pcur_close(&pcur);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Undoes a modify in secondary indexes when undo record type is UPD_DEL. */
|
|
|
|
static
|
|
|
|
ulint
|
|
|
|
row_undo_mod_upd_del_sec(
|
|
|
|
/*=====================*/
|
|
|
|
/* out: DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
|
|
|
|
undo_node_t* node, /* in: row undo node */
|
|
|
|
que_thr_t* thr) /* in: query thread */
|
|
|
|
{
|
|
|
|
mem_heap_t* heap;
|
|
|
|
dtuple_t* entry;
|
|
|
|
dict_index_t* index;
|
branches/zip: In the rollback of incomplete transactions after crash
recovery, tolerate clustered index records whose externally stored
columns have not been written. This should remove the assertion failures
that were reported as Mantis issue#58, issue#62, issue#64.
trx_is_recv(): New function: TRUE if this transaction is rolling back
an incomplete transaction in crash recovery.
enum trx_rbmode: Rollback modes: no rollback, normal rollback, crash recovery.
btr_cur_pessimistic_delete(), btr_free_externally_stored_field(),
btr_rec_free_externally_stored_fields():
Replace the ibool parameter with enum trx_rbmode.
btr_free_externally_stored_field(): If field_ref is zero, return
but assert ut_a(rbmode == RB_RECOVERY). Unless InnoDB has crashed
while inserting a clustered index record, field_ref should not be zero.
btr_rec_free_updated_extern_fields(): Add the parameter enum trx_rbmode.
btr_cur_pessimistic_update(): Pass the rbmode parameter to
btr_rec_free_updated_extern_fields().
row_undo_ins(), row_undo_mod_upd_del_sec(): If row_build_index_entry()
fails, assert trx_is_recv() and skip this secondary index.
row_undo_mod_upd_del_sec(): Empty the heap at the end of each loop
iteration in order to conserve memory and to reduce the number of
low-level memory allocations.
2008-08-06 08:48:34 +00:00
|
|
|
ulint err = DB_SUCCESS;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
heap = mem_heap_create(1024);
|
|
|
|
|
|
|
|
while (node->index != NULL) {
|
|
|
|
index = node->index;
|
|
|
|
|
2006-09-26 11:50:54 +00:00
|
|
|
entry = row_build_index_entry(node->row, node->ext,
|
|
|
|
index, heap);
|
branches/zip: In the rollback of incomplete transactions after crash
recovery, tolerate clustered index records whose externally stored
columns have not been written. This should remove the assertion failures
that were reported as Mantis issue#58, issue#62, issue#64.
trx_is_recv(): New function: TRUE if this transaction is rolling back
an incomplete transaction in crash recovery.
enum trx_rbmode: Rollback modes: no rollback, normal rollback, crash recovery.
btr_cur_pessimistic_delete(), btr_free_externally_stored_field(),
btr_rec_free_externally_stored_fields():
Replace the ibool parameter with enum trx_rbmode.
btr_free_externally_stored_field(): If field_ref is zero, return
but assert ut_a(rbmode == RB_RECOVERY). Unless InnoDB has crashed
while inserting a clustered index record, field_ref should not be zero.
btr_rec_free_updated_extern_fields(): Add the parameter enum trx_rbmode.
btr_cur_pessimistic_update(): Pass the rbmode parameter to
btr_rec_free_updated_extern_fields().
row_undo_ins(), row_undo_mod_upd_del_sec(): If row_build_index_entry()
fails, assert trx_is_recv() and skip this secondary index.
row_undo_mod_upd_del_sec(): Empty the heap at the end of each loop
iteration in order to conserve memory and to reduce the number of
low-level memory allocations.
2008-08-06 08:48:34 +00:00
|
|
|
if (UNIV_UNLIKELY(!entry)) {
|
|
|
|
/* The database must have crashed after
|
|
|
|
inserting a clustered index record but before
|
|
|
|
writing all the externally stored columns of
|
|
|
|
that record. Because secondary index entries
|
|
|
|
are inserted after the clustered index record,
|
|
|
|
we may assume that the secondary index record
|
|
|
|
does not exist. However, this situation may
|
|
|
|
only occur during the rollback of incomplete
|
|
|
|
transactions. */
|
|
|
|
ut_a(trx_is_recv(thr_get_trx(thr)));
|
|
|
|
} else {
|
|
|
|
err = row_undo_mod_del_mark_or_remove_sec(
|
|
|
|
node, thr, index, entry);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/zip: In the rollback of incomplete transactions after crash
recovery, tolerate clustered index records whose externally stored
columns have not been written. This should remove the assertion failures
that were reported as Mantis issue#58, issue#62, issue#64.
trx_is_recv(): New function: TRUE if this transaction is rolling back
an incomplete transaction in crash recovery.
enum trx_rbmode: Rollback modes: no rollback, normal rollback, crash recovery.
btr_cur_pessimistic_delete(), btr_free_externally_stored_field(),
btr_rec_free_externally_stored_fields():
Replace the ibool parameter with enum trx_rbmode.
btr_free_externally_stored_field(): If field_ref is zero, return
but assert ut_a(rbmode == RB_RECOVERY). Unless InnoDB has crashed
while inserting a clustered index record, field_ref should not be zero.
btr_rec_free_updated_extern_fields(): Add the parameter enum trx_rbmode.
btr_cur_pessimistic_update(): Pass the rbmode parameter to
btr_rec_free_updated_extern_fields().
row_undo_ins(), row_undo_mod_upd_del_sec(): If row_build_index_entry()
fails, assert trx_is_recv() and skip this secondary index.
row_undo_mod_upd_del_sec(): Empty the heap at the end of each loop
iteration in order to conserve memory and to reduce the number of
low-level memory allocations.
2008-08-06 08:48:34 +00:00
|
|
|
if (err != DB_SUCCESS) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/zip: In the rollback of incomplete transactions after crash
recovery, tolerate clustered index records whose externally stored
columns have not been written. This should remove the assertion failures
that were reported as Mantis issue#58, issue#62, issue#64.
trx_is_recv(): New function: TRUE if this transaction is rolling back
an incomplete transaction in crash recovery.
enum trx_rbmode: Rollback modes: no rollback, normal rollback, crash recovery.
btr_cur_pessimistic_delete(), btr_free_externally_stored_field(),
btr_rec_free_externally_stored_fields():
Replace the ibool parameter with enum trx_rbmode.
btr_free_externally_stored_field(): If field_ref is zero, return
but assert ut_a(rbmode == RB_RECOVERY). Unless InnoDB has crashed
while inserting a clustered index record, field_ref should not be zero.
btr_rec_free_updated_extern_fields(): Add the parameter enum trx_rbmode.
btr_cur_pessimistic_update(): Pass the rbmode parameter to
btr_rec_free_updated_extern_fields().
row_undo_ins(), row_undo_mod_upd_del_sec(): If row_build_index_entry()
fails, assert trx_is_recv() and skip this secondary index.
row_undo_mod_upd_del_sec(): Empty the heap at the end of each loop
iteration in order to conserve memory and to reduce the number of
low-level memory allocations.
2008-08-06 08:48:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
branches/zip: In the rollback of incomplete transactions after crash
recovery, tolerate clustered index records whose externally stored
columns have not been written. This should remove the assertion failures
that were reported as Mantis issue#58, issue#62, issue#64.
trx_is_recv(): New function: TRUE if this transaction is rolling back
an incomplete transaction in crash recovery.
enum trx_rbmode: Rollback modes: no rollback, normal rollback, crash recovery.
btr_cur_pessimistic_delete(), btr_free_externally_stored_field(),
btr_rec_free_externally_stored_fields():
Replace the ibool parameter with enum trx_rbmode.
btr_free_externally_stored_field(): If field_ref is zero, return
but assert ut_a(rbmode == RB_RECOVERY). Unless InnoDB has crashed
while inserting a clustered index record, field_ref should not be zero.
btr_rec_free_updated_extern_fields(): Add the parameter enum trx_rbmode.
btr_cur_pessimistic_update(): Pass the rbmode parameter to
btr_rec_free_updated_extern_fields().
row_undo_ins(), row_undo_mod_upd_del_sec(): If row_build_index_entry()
fails, assert trx_is_recv() and skip this secondary index.
row_undo_mod_upd_del_sec(): Empty the heap at the end of each loop
iteration in order to conserve memory and to reduce the number of
low-level memory allocations.
2008-08-06 08:48:34 +00:00
|
|
|
mem_heap_empty(heap);
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
node->index = dict_table_get_next_index(node->index);
|
|
|
|
}
|
|
|
|
|
|
|
|
mem_heap_free(heap);
|
|
|
|
|
branches/zip: In the rollback of incomplete transactions after crash
recovery, tolerate clustered index records whose externally stored
columns have not been written. This should remove the assertion failures
that were reported as Mantis issue#58, issue#62, issue#64.
trx_is_recv(): New function: TRUE if this transaction is rolling back
an incomplete transaction in crash recovery.
enum trx_rbmode: Rollback modes: no rollback, normal rollback, crash recovery.
btr_cur_pessimistic_delete(), btr_free_externally_stored_field(),
btr_rec_free_externally_stored_fields():
Replace the ibool parameter with enum trx_rbmode.
btr_free_externally_stored_field(): If field_ref is zero, return
but assert ut_a(rbmode == RB_RECOVERY). Unless InnoDB has crashed
while inserting a clustered index record, field_ref should not be zero.
btr_rec_free_updated_extern_fields(): Add the parameter enum trx_rbmode.
btr_cur_pessimistic_update(): Pass the rbmode parameter to
btr_rec_free_updated_extern_fields().
row_undo_ins(), row_undo_mod_upd_del_sec(): If row_build_index_entry()
fails, assert trx_is_recv() and skip this secondary index.
row_undo_mod_upd_del_sec(): Empty the heap at the end of each loop
iteration in order to conserve memory and to reduce the number of
low-level memory allocations.
2008-08-06 08:48:34 +00:00
|
|
|
return(err);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Undoes a modify in secondary indexes when undo record type is DEL_MARK. */
|
|
|
|
static
|
|
|
|
ulint
|
|
|
|
row_undo_mod_del_mark_sec(
|
|
|
|
/*======================*/
|
|
|
|
/* out: DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
|
|
|
|
undo_node_t* node, /* in: row undo node */
|
|
|
|
que_thr_t* thr) /* in: query thread */
|
|
|
|
{
|
|
|
|
mem_heap_t* heap;
|
|
|
|
dtuple_t* entry;
|
|
|
|
dict_index_t* index;
|
|
|
|
ulint err;
|
|
|
|
|
|
|
|
heap = mem_heap_create(1024);
|
|
|
|
|
|
|
|
while (node->index != NULL) {
|
|
|
|
index = node->index;
|
|
|
|
|
2006-09-26 11:50:54 +00:00
|
|
|
entry = row_build_index_entry(node->row, node->ext,
|
|
|
|
index, heap);
|
2007-11-27 09:11:45 +00:00
|
|
|
ut_a(entry);
|
2006-09-19 10:14:07 +00:00
|
|
|
err = row_undo_mod_del_unmark_sec_and_undo_update(
|
|
|
|
BTR_MODIFY_LEAF, thr, index, entry);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (err == DB_FAIL) {
|
2006-09-19 10:14:07 +00:00
|
|
|
err = row_undo_mod_del_unmark_sec_and_undo_update(
|
|
|
|
BTR_MODIFY_TREE, thr, index, entry);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
|
|
|
mem_heap_free(heap);
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
node->index = dict_table_get_next_index(node->index);
|
|
|
|
}
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
mem_heap_free(heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Undoes a modify in secondary indexes when undo record type is UPD_EXIST. */
|
|
|
|
static
|
|
|
|
ulint
|
|
|
|
row_undo_mod_upd_exist_sec(
|
|
|
|
/*=======================*/
|
|
|
|
/* out: DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
|
|
|
|
undo_node_t* node, /* in: row undo node */
|
|
|
|
que_thr_t* thr) /* in: query thread */
|
|
|
|
{
|
|
|
|
mem_heap_t* heap;
|
|
|
|
dtuple_t* entry;
|
|
|
|
dict_index_t* index;
|
|
|
|
ulint err;
|
|
|
|
|
|
|
|
if (node->cmpl_info & UPD_NODE_NO_ORD_CHANGE) {
|
|
|
|
/* No change in secondary indexes */
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
heap = mem_heap_create(1024);
|
|
|
|
|
|
|
|
while (node->index != NULL) {
|
|
|
|
index = node->index;
|
|
|
|
|
|
|
|
if (row_upd_changes_ord_field_binary(node->row, node->index,
|
2006-08-29 09:30:31 +00:00
|
|
|
node->update)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* Build the newest version of the index entry */
|
2006-09-26 11:50:54 +00:00
|
|
|
entry = row_build_index_entry(node->row, node->ext,
|
|
|
|
index, heap);
|
2007-11-27 09:11:45 +00:00
|
|
|
ut_a(entry);
|
2005-10-27 07:29:40 +00:00
|
|
|
/* NOTE that if we updated the fields of a
|
|
|
|
delete-marked secondary index record so that
|
|
|
|
alphabetically they stayed the same, e.g.,
|
|
|
|
'abc' -> 'aBc', we cannot return to the original
|
|
|
|
values because we do not know them. But this should
|
|
|
|
not cause problems because in row0sel.c, in queries
|
|
|
|
we always retrieve the clustered index record or an
|
|
|
|
earlier version of it, if the secondary index record
|
|
|
|
through which we do the search is delete-marked. */
|
|
|
|
|
|
|
|
err = row_undo_mod_del_mark_or_remove_sec(node, thr,
|
2006-08-29 09:30:31 +00:00
|
|
|
index,
|
|
|
|
entry);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We may have to update the delete mark in the
|
|
|
|
secondary index record of the previous version of
|
|
|
|
the row. We also need to update the fields of
|
|
|
|
the secondary index record if we updated its fields
|
|
|
|
but alphabetically they stayed the same, e.g.,
|
|
|
|
'abc' -> 'aBc'. */
|
2008-01-16 10:10:32 +00:00
|
|
|
mem_heap_empty(heap);
|
|
|
|
entry = row_build_index_entry(node->undo_row,
|
|
|
|
node->undo_ext,
|
|
|
|
index, heap);
|
|
|
|
ut_a(entry);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
err = row_undo_mod_del_unmark_sec_and_undo_update(
|
|
|
|
BTR_MODIFY_LEAF, thr, index, entry);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (err == DB_FAIL) {
|
2006-09-19 10:14:07 +00:00
|
|
|
err = row_undo_mod_del_unmark_sec_and_undo_update(
|
|
|
|
BTR_MODIFY_TREE, thr, index, entry);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
node->index = dict_table_get_next_index(node->index);
|
|
|
|
}
|
|
|
|
|
|
|
|
mem_heap_free(heap);
|
|
|
|
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Parses the row reference and other info in a modify undo log record. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
row_undo_mod_parse_undo_rec(
|
|
|
|
/*========================*/
|
|
|
|
undo_node_t* node, /* in: row undo node */
|
|
|
|
que_thr_t* thr) /* in: query thread */
|
|
|
|
{
|
|
|
|
dict_index_t* clust_index;
|
|
|
|
byte* ptr;
|
|
|
|
dulint undo_no;
|
|
|
|
dulint table_id;
|
|
|
|
dulint trx_id;
|
|
|
|
dulint roll_ptr;
|
|
|
|
ulint info_bits;
|
|
|
|
ulint type;
|
|
|
|
ulint cmpl_info;
|
|
|
|
ibool dummy_extern;
|
|
|
|
trx_t* trx;
|
|
|
|
|
|
|
|
ut_ad(node && thr);
|
|
|
|
trx = thr_get_trx(thr);
|
|
|
|
ptr = trx_undo_rec_get_pars(node->undo_rec, &type, &cmpl_info,
|
2006-08-29 09:30:31 +00:00
|
|
|
&dummy_extern, &undo_no, &table_id);
|
2005-10-27 07:29:40 +00:00
|
|
|
node->rec_type = type;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
node->table = dict_table_get_on_id(table_id, trx);
|
|
|
|
|
|
|
|
/* TODO: other fixes associated with DROP TABLE + rollback in the
|
|
|
|
same table by another user */
|
|
|
|
|
|
|
|
if (node->table == NULL) {
|
2006-02-23 19:25:29 +00:00
|
|
|
/* Table was dropped */
|
|
|
|
return;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (node->table->ibd_file_missing) {
|
|
|
|
/* We skip undo operations to missing .ibd files */
|
|
|
|
node->table = NULL;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
clust_index = dict_table_get_first_index(node->table);
|
|
|
|
|
|
|
|
ptr = trx_undo_update_rec_get_sys_cols(ptr, &trx_id, &roll_ptr,
|
2006-08-29 09:30:31 +00:00
|
|
|
&info_bits);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
ptr = trx_undo_rec_get_row_ref(ptr, clust_index, &(node->ref),
|
2006-08-29 09:30:31 +00:00
|
|
|
node->heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
trx_undo_update_rec_get_update(ptr, clust_index, type, trx_id,
|
2006-08-29 09:30:31 +00:00
|
|
|
roll_ptr, info_bits, trx,
|
|
|
|
node->heap, &(node->update));
|
2005-10-27 07:29:40 +00:00
|
|
|
node->new_roll_ptr = roll_ptr;
|
|
|
|
node->new_trx_id = trx_id;
|
|
|
|
node->cmpl_info = cmpl_info;
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/***************************************************************
|
|
|
|
Undoes a modify operation on a row of a table. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint
|
|
|
|
row_undo_mod(
|
|
|
|
/*=========*/
|
|
|
|
/* out: DB_SUCCESS or error code */
|
|
|
|
undo_node_t* node, /* in: row undo node */
|
|
|
|
que_thr_t* thr) /* in: query thread */
|
|
|
|
{
|
|
|
|
ulint err;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(node && thr);
|
|
|
|
ut_ad(node->state == UNDO_NODE_MODIFY);
|
|
|
|
|
|
|
|
row_undo_mod_parse_undo_rec(node, thr);
|
|
|
|
|
2008-01-14 14:18:21 +00:00
|
|
|
if (!node->table || !row_undo_search_clust_to_pcur(node)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
/* It is already undone, or will be undone by another query
|
|
|
|
thread, or table was dropped */
|
2006-02-23 19:25:29 +00:00
|
|
|
|
|
|
|
trx_undo_rec_release(node->trx, node->undo_no);
|
2005-10-27 07:29:40 +00:00
|
|
|
node->state = UNDO_NODE_FETCH_NEXT;
|
|
|
|
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
node->index = dict_table_get_next_index(
|
|
|
|
dict_table_get_first_index(node->table));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (node->rec_type == TRX_UNDO_UPD_EXIST_REC) {
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
err = row_undo_mod_upd_exist_sec(node, thr);
|
|
|
|
|
|
|
|
} else if (node->rec_type == TRX_UNDO_DEL_MARK_REC) {
|
|
|
|
|
|
|
|
err = row_undo_mod_del_mark_sec(node, thr);
|
|
|
|
} else {
|
|
|
|
ut_ad(node->rec_type == TRX_UNDO_UPD_DEL_REC);
|
|
|
|
err = row_undo_mod_upd_del_sec(node, thr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
err = row_undo_mod_clust(node, thr);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
return(err);
|
|
|
|
}
|