mariadb/trx/trx0roll.c
marko 86b8525254 branches/innodb+: Merge revisions 3602:3931 from branches/zip:
------------------------------------------------------------------------
  r3607 | marko | 2008-12-30 22:33:31 +0200 (Tue, 30 Dec 2008) | 20 lines

  branches/zip: Remove the dependency on the MySQL HASH table implementation.
  Use the InnoDB hash table for keeping track of INNOBASE_SHARE objects.

  struct st_innobase_share: Make table_name const uchar*.  Add the member
  table_name_hash.

  innobase_open_tables: Change the type from HASH to hash_table_t*.

  innobase_get_key(): Remove.

  innobase_fold_name(): New function, for computing the fold value for the
  InnoDB hash table.

  get_share(), free_share(): Use the InnoDB hash functions.

  innobase_end(): Free innobase_open_tables before shutting down InnoDB.
  Shutting down InnoDB will invalidate all memory allocated via InnoDB.

  rb://65 approved by Heikki Tuuri.  This addresses Issue #104.
  ------------------------------------------------------------------------
  r3608 | marko | 2008-12-30 22:45:04 +0200 (Tue, 30 Dec 2008) | 22 lines

  branches/zip: When setting the PAGE_LEVEL of a compressed B-tree page
  from or to 0, compress the page at the same time.  This is necessary,
  because the column information stored on the compressed page will
  differ between leaf and non-leaf pages.  Leaf pages are identified by
  PAGE_LEVEL=0.  This bug was reported as Issue #150.

  Document the similarity between btr_page_create() and
  btr_page_empty().  Make the function signature of btr_page_empty()
  identical with btr_page_create().  (This will add the parameter "level".)

  btr_root_raise_and_insert(): Replace some code with a call to
  btr_page_empty().

  btr_attach_half_pages(): Assert that the page level has already been
  set on both block and new_block.  Do not set it again.

  btr_discard_only_page_on_level(): Document that this function is
  probably never called.  Make it work on any height tree.  (Tested on
  2-high tree by disabling btr_lift_page_up().)

  rb://68
  ------------------------------------------------------------------------
  r3612 | marko | 2009-01-02 11:02:44 +0200 (Fri, 02 Jan 2009) | 14 lines

  branches/zip: Merge c2998 from branches/6.0, so that the same InnoDB Plugin
  source tree will work both under 5.1 and 6.0.  Do not add the test case
  innodb_ctype_ldml.test, because it would not work under MySQL 5.1.

  Refuse to create tables whose columns contain collation IDs above 255.
  This removes an assertion failure that was introduced in WL#4164
  (Two-byte collation IDs).

  create_table_def(): Do not fail an assertion if a column contains a
  charset-collation ID greater than 256. Instead, issue an error and
  refuse to create the table.

  The original change (branches/6.0 r2998) was rb://51 approved by Calvin Sun.
  ------------------------------------------------------------------------
  r3613 | inaam | 2009-01-02 15:10:50 +0200 (Fri, 02 Jan 2009) | 6 lines

  branches/zip: Implement the parameter innodb_use_sys_malloc
  (false by default), for disabling InnoDB's internal memory allocator
  and using system malloc/free instead.

  rb://62 approved by Marko
  ------------------------------------------------------------------------
  r3614 | marko | 2009-01-02 15:55:12 +0200 (Fri, 02 Jan 2009) | 1 line

  branches/zip: ChangeLog: Document r3608 and r3613.
  ------------------------------------------------------------------------
  r3615 | marko | 2009-01-02 15:57:51 +0200 (Fri, 02 Jan 2009) | 1 line

  branches/zip: ChangeLog: Clarify the impact of r3608.
  ------------------------------------------------------------------------
  r3616 | marko | 2009-01-03 00:23:30 +0200 (Sat, 03 Jan 2009) | 1 line

  branches/zip: srv_suspend_mysql_thread(): Add some clarifying comments.
  ------------------------------------------------------------------------
  r3618 | marko | 2009-01-05 12:54:53 +0200 (Mon, 05 Jan 2009) | 15 lines

  branches/zip: Merge revisions 3598:3601 from branches/5.1:

    ------------------------------------------------------------------------
    r3601 | marko | 2008-12-22 16:05:19 +0200 (Mon, 22 Dec 2008) | 9 lines

    branches/5.1: Make
    SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED
    a true replacement of SET GLOBAL INNODB_LOCKS_UNSAFE_FOR_BINLOG=1.
    This fixes an error that was introduced in r370, causing
    semi-consistent read not to not unlock rows in READ COMMITTED mode.
    (Bug #41671, Issue #146)

    rb://67 approved by Heikki Tuuri
    ------------------------------------------------------------------------
  ------------------------------------------------------------------------
  r3623 | vasil | 2009-01-06 09:56:32 +0200 (Tue, 06 Jan 2009) | 7 lines

  branches/zip:

  Add patch to fix the failing main.variables mysql-test. It started failing
  after the variable innodb_use_sys_malloc was added because it matches
  '%alloc%' and the test is badly written and expects that no new variables
  like that will ever be added.
  ------------------------------------------------------------------------
  r3795 | marko | 2009-01-07 16:17:47 +0200 (Wed, 07 Jan 2009) | 7 lines

  branches/zip: row_merge_tuple_cmp(): Do not report a duplicate key value
  if any of the fields are NULL.  While the tuples are equal in the
  sorting order, SQL NULL is defined to be logically inequal to
  anything else. (Bug #41904)

  rb://70 approved by Heikki Tuuri
  ------------------------------------------------------------------------
  r3796 | marko | 2009-01-07 16:19:32 +0200 (Wed, 07 Jan 2009) | 1 line

  branches/zip: Add the tests that were forgotten from r3795.
  ------------------------------------------------------------------------
  r3797 | marko | 2009-01-07 16:22:18 +0200 (Wed, 07 Jan 2009) | 22 lines

  branches/zip: Do not call trx_allocate_for_mysql() directly, but use
  helper functions that initialize some members of the transaction struct.
  (Bug #41680)

  innobase_trx_init(): New function: initialize some fields of a
  transaction struct from a MySQL THD object.

  innobase_trx_allocate(): New function: allocate and initialize a
  transaction struct.

  check_trx_exists(): Use the above two functions.

  ha_innobase::delete_table(), ha_innobase::rename_table(),
  ha_innobase::add_index(), ha_innobase::final_drop_index():
  Use innobase_trx_allocate().

  innobase_drop_database(): In the Windows plugin, initialize the trx_t
  specially, because the THD is not available.  Otherwise, use
  innobase_trx_allocate().

  rb://69 accepted by Heikki Tuuri
  ------------------------------------------------------------------------
  r3798 | marko | 2009-01-07 16:42:42 +0200 (Wed, 07 Jan 2009) | 8 lines

  branches/zip: row_merge_drop_temp_indexes(): Do not lock the rows of
  SYS_INDEXES when looking for partially created indexes.  Use the
  transaction isolation level READ UNCOMMITTED to avoid interfering with
  locks held by incomplete transactions that will be rolled back in a
  subsequent step in the recovery.  (Issue #152)

  Approved by Heikki Tuuri
  ------------------------------------------------------------------------
  r3852 | vasil | 2009-01-08 22:10:10 +0200 (Thu, 08 Jan 2009) | 4 lines

  branches/zip:

  Add ChangeLog entries for r3795 r3796 r3797 r3798.

  ------------------------------------------------------------------------
  r3866 | marko | 2009-01-09 15:09:51 +0200 (Fri, 09 Jan 2009) | 2 lines

  branches/zip: buf_flush_try_page(): Move some common code from each
  switch case before the switch block.
  ------------------------------------------------------------------------
  r3867 | marko | 2009-01-09 15:13:14 +0200 (Fri, 09 Jan 2009) | 2 lines

  branches/zip: buf_flush_try_page(): Introduce the variable is_compressed
  for caching the result of buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE.
  ------------------------------------------------------------------------
  r3868 | marko | 2009-01-09 15:40:11 +0200 (Fri, 09 Jan 2009) | 4 lines

  branches/zip: buf_flush_insert_into_flush_list(),
  buf_flush_insert_sorted_into_flush_list(): Remove unused code.
  Change the parameter to buf_block_t* block and assert that
  block->state == BUF_BLOCK_FILE_PAGE.  This is part of Issue #155.
  ------------------------------------------------------------------------
  r3873 | marko | 2009-01-09 22:27:40 +0200 (Fri, 09 Jan 2009) | 17 lines

  branches/zip: Some non-functional changes related to Issue #155.

  buf_page_struct: Note that space and offset are also protected by
  buf_pool_mutex.  They are only assigned to by
  buf_block_set_file_page().  Thus, it suffices for buf_flush_batch() to
  hold just buf_pool_mutex when checking these fields.

  buf_flush_try_page(): Rename "locked" to "is_s_latched", per Heikki's request.

  buf_flush_batch(): Move the common statement mutex_exit(block_mutex)
  from all if-else if-else branches before the if block.  Remove the
  redundant test (buf_pool->init_flush[flush_type] == FALSE) that was
  apparently copied from buf_flush_write_complete().

  buf_flush_write_block_low(): Note why it is safe not to hold buf_pool_mutex
  or block_mutex.  Enumerate the assumptions in debug assertions.
  ------------------------------------------------------------------------
  r3874 | marko | 2009-01-09 23:09:06 +0200 (Fri, 09 Jan 2009) | 4 lines

  branches/zip: Add comments related to Issue #155.

  buf_flush_try_page(): Note why it is safe to access bpage without
  holding buf_pool_mutex or block_mutex.
  ------------------------------------------------------------------------
  r3875 | marko | 2009-01-09 23:15:12 +0200 (Fri, 09 Jan 2009) | 11 lines

  branches/zip: Non-functional change: Tighten debug assertions and
  remove dead code.

  buf_flush_ready_for_flush(), buf_flush_try_page(): Assert that
  flush_type is one of BUF_FLUSH_LRU or BUF_FLUSH_LIST.  The flush_type
  comes from buf_flush_batch(), which already asserts this.  The
  assertion holds for all calls in the source code.

  buf_flush_try_page(): Remove the dead case BUF_FLUSH_SINGLE_PAGE
  of switch (flush_type).
  ------------------------------------------------------------------------
  r3879 | marko | 2009-01-12 12:46:44 +0200 (Mon, 12 Jan 2009) | 14 lines

  branches/zip: Simplify the flushing of dirty pages from the buffer pool.

  buf_flush_try_page(): Rename to buf_flush_page(), and change the
  return type to void.  Replace the parameters space, offset with bpage,
  and remove the second page hash lookup.  Note and assert that both
  buf_pool_mutex and block_mutex must now be held upon entering the
  function.  They will still be released by this function.

  buf_flush_try_neighbors(): Replace buf_flush_try_page() with
  buf_flush_page().  Make the logic easier to follow by not negating the
  precondition of buf_flush_page().

  rb://73 approved by Sunny Bains.  This is related to Issue #157.
  ------------------------------------------------------------------------
  r3880 | marko | 2009-01-12 13:24:37 +0200 (Mon, 12 Jan 2009) | 2 lines

  branches/zip: buf_flush_page(): Fix a comment that should have been fixed
  in r3879.  Spotted by Sunny.
  ------------------------------------------------------------------------
  r3881 | marko | 2009-01-12 14:25:22 +0200 (Mon, 12 Jan 2009) | 2 lines

  branches/zip: buf_page_get_newest_modification(): Use the block mutex
  instead of the buffer pool mutex.  This is related to Issue #157.
  ------------------------------------------------------------------------
  r3882 | marko | 2009-01-12 14:40:08 +0200 (Mon, 12 Jan 2009) | 3 lines

  branches/zip: struct mtr_struct: Remove the unused field magic_n
  unless UNIV_DEBUG is defined.  mtr->magic_n is only assigned to
  and checked in UNIV_DEBUG builds.
  ------------------------------------------------------------------------
  r3883 | marko | 2009-01-12 14:48:59 +0200 (Mon, 12 Jan 2009) | 1 line

  branches/zip: Non-functional change: Use ut_d when assigning to mtr->state.
  ------------------------------------------------------------------------
  r3884 | marko | 2009-01-12 18:56:11 +0200 (Mon, 12 Jan 2009) | 16 lines

  branches/zip: Non-functional change: Add some debug assertions and comments.

  buf_page_t: Note that the LRU fields are protected by buf_pool_mutex
  only, not block->mutex or buf_pool_zip_mutex.

  buf_page_get_freed_page_clock(): Note that this is sometimes invoked
  without mutex protection.

  buf_pool_get_oldest_modification(): Note that the result may be out of
  date.

  buf_page_get_LRU_position(), buf_page_is_old(): Assert that the buffer
  pool mutex is being held.

  buf_page_release(): Assert that dirty blocks are in the flush list.
  ------------------------------------------------------------------------
  r3896 | marko | 2009-01-13 09:30:26 +0200 (Tue, 13 Jan 2009) | 2 lines

  branches/zip: buf_flush_try_neighbors(): Fix a bug
  that was introduced in r3879 (rb://73).
  ------------------------------------------------------------------------
  r3900 | marko | 2009-01-13 10:32:24 +0200 (Tue, 13 Jan 2009) | 1 line

  branches/zip: Fix some comments to say buf_pool_mutex.
  ------------------------------------------------------------------------
  r3907 | marko | 2009-01-13 11:54:01 +0200 (Tue, 13 Jan 2009) | 3 lines

  branches/zip: row_merge_create_temporary_table(): On error,
  row_create_table_for_mysql() already frees new_table.
  Do not attempt to free it again.
  ------------------------------------------------------------------------
  r3908 | marko | 2009-01-13 12:34:32 +0200 (Tue, 13 Jan 2009) | 1 line

  branches/zip: Enable HASH_ASSERT_OWNED independently of UNIV_SYNC_DEBUG.
  ------------------------------------------------------------------------
  r3914 | marko | 2009-01-13 21:46:22 +0200 (Tue, 13 Jan 2009) | 37 lines

  branches/zip: In hash table lookups, assert that the traversed items
  satisfy some conditions when UNIV_DEBUG is defined.

  HASH_SEARCH(): New parameter: ASSERTION. All users will pass an appropriate
  ut_ad() or nothing.

  dict_table_add_to_columns(): Assert that the table being added to the data
  dictionary cache is not already being pointed to by the name_hash and
  id_hash tables.

  HASH_SEARCH_ALL(): New macro, for use in dict_table_add_to_columns().

  dict_mem_table_free(): Set ut_d(table->cached = FALSE), so that we can
  check ut_ad(table->cached) when traversing the hash tables, as in
  HASH_SEARCH(name_hash, dict_sys->table_hash, ...) and
  HASH_SEARCH(id_hash, dict_sys->table_id_hash, ...).

  dict_table_get_low(), dict_table_get_on_id_low(): Assert
  ut_ad(!table || table->cached).

  fil_space_get_by_id(): Check ut_ad(space->magic_n == FIL_SPACE_MAGIC_N)
  in HASH_SEARCH(hash, fil_system->spaces, ...).

  fil_space_get_by_name(): Check ut_ad(space->magic_n == FIL_SPACE_MAGIC_N)
  in HASH_SEARCH(name_hash, fil_system->name_hash, ...).

  buf_buddy_block_free(): Check that the blocks are in valid state in
  HASH_SEARCH(hash, buf_pool->zip_hash, ...).

  buf_page_hash_get(): Check that the blocks are in valid state in
  HASH_SEARCH(hash, buf_pool->page_hash, ...).

  get_share(), free_share(): Check ut_ad(share->use_count > 0) in
  HASH_SEARCH(table_name_hash, innobase_open_tables, ...).

  This was posted as rb://75 for tracking down errors similar to Issue #153.
  ------------------------------------------------------------------------
  r3931 | marko | 2009-01-14 16:06:22 +0200 (Wed, 14 Jan 2009) | 26 lines

  branches/zip: Merge revisions 3601:3930 from branches/5.1:

    ------------------------------------------------------------------------
    r3911 | sunny | 2009-01-13 14:15:24 +0200 (Tue, 13 Jan 2009) | 13 lines

    branches/5.1: Fix Bug#38187 Error 153 when creating savepoints
    InnoDB previously treated savepoints as a stack e.g.,
      SAVEPOINT a;
      SAVEPOINT b;
      SAVEPOINT c;
      SAVEPOINT b; <- This would delete b and c.

    This fix changes the behavior to:
      SAVEPOINT a;
      SAVEPOINT b;
      SAVEPOINT c;
      SAVEPOINT b; <- Does not delete savepoint c
    ------------------------------------------------------------------------
    r3930 | marko | 2009-01-14 15:51:30 +0200 (Wed, 14 Jan 2009) | 4 lines

    branches/5.1: dict_load_table(): If dict_load_indexes() fails,
    invoke dict_table_remove_from_cache() instead of dict_mem_table_free(),
    so that the data dictionary will not point to freed data.
    (Bug #42075, Issue #153, rb://76 approved by Heikki Tuuri)
    ------------------------------------------------------------------------
  ------------------------------------------------------------------------
2009-01-14 14:25:45 +00:00

1343 lines
31 KiB
C

/******************************************************
Transaction rollback
(c) 1996 Innobase Oy
Created 3/26/1996 Heikki Tuuri
*******************************************************/
#include "trx0roll.h"
#ifdef UNIV_NONINL
#include "trx0roll.ic"
#endif
#include "fsp0fsp.h"
#include "mach0data.h"
#include "trx0rseg.h"
#include "trx0trx.h"
#include "trx0undo.h"
#include "trx0rec.h"
#include "que0que.h"
#include "usr0sess.h"
#include "srv0que.h"
#include "srv0start.h"
#include "row0undo.h"
#include "row0mysql.h"
#include "lock0lock.h"
#include "pars0pars.h"
/* This many pages must be undone before a truncate is tried within rollback */
#define TRX_ROLL_TRUNC_THRESHOLD 1
/* In crash recovery, the current trx to be rolled back */
static trx_t* trx_roll_crash_recv_trx = NULL;
/* In crash recovery we set this to the undo n:o of the current trx to be
rolled back. Then we can print how many % the rollback has progressed. */
static ib_int64_t trx_roll_max_undo_no;
/* Auxiliary variable which tells the previous progress % we printed */
static ulint trx_roll_progress_printed_pct;
/***********************************************************************
Rollback a transaction used in MySQL. */
UNIV_INTERN
int
trx_general_rollback_for_mysql(
/*===========================*/
/* out: error code or DB_SUCCESS */
trx_t* trx, /* in: transaction handle */
ibool partial,/* in: TRUE if partial rollback requested */
trx_savept_t* savept) /* in: pointer to savepoint undo number, if
partial rollback requested */
{
#ifndef UNIV_HOTBACKUP
mem_heap_t* heap;
que_thr_t* thr;
roll_node_t* roll_node;
/* Tell Innobase server that there might be work for
utility threads: */
srv_active_wake_master_thread();
trx_start_if_not_started(trx);
heap = mem_heap_create(512);
roll_node = roll_node_create(heap);
roll_node->partial = partial;
if (partial) {
roll_node->savept = *savept;
}
trx->error_state = DB_SUCCESS;
thr = pars_complete_graph_for_exec(roll_node, trx, heap);
ut_a(thr == que_fork_start_command(que_node_get_parent(thr)));
que_run_threads(thr);
mutex_enter(&kernel_mutex);
while (trx->que_state != TRX_QUE_RUNNING) {
mutex_exit(&kernel_mutex);
os_thread_sleep(100000);
mutex_enter(&kernel_mutex);
}
mutex_exit(&kernel_mutex);
mem_heap_free(heap);
ut_a(trx->error_state == DB_SUCCESS);
/* Tell Innobase server that there might be work for
utility threads: */
srv_active_wake_master_thread();
return((int) trx->error_state);
#else /* UNIV_HOTBACKUP */
/* This function depends on MySQL code that is not included in
InnoDB Hot Backup builds. Besides, this function should never
be called in InnoDB Hot Backup. */
ut_error;
return(DB_FAIL);
#endif /* UNIV_HOTBACKUP */
}
/***********************************************************************
Rollback a transaction used in MySQL. */
UNIV_INTERN
int
trx_rollback_for_mysql(
/*===================*/
/* out: error code or DB_SUCCESS */
trx_t* trx) /* in: transaction handle */
{
int err;
if (trx->conc_state == TRX_NOT_STARTED) {
return(DB_SUCCESS);
}
trx->op_info = "rollback";
/* If we are doing the XA recovery of prepared transactions, then
the transaction object does not have an InnoDB session object, and we
set a dummy session that we use for all MySQL transactions. */
err = trx_general_rollback_for_mysql(trx, FALSE, NULL);
trx->op_info = "";
return(err);
}
/***********************************************************************
Rollback the latest SQL statement for MySQL. */
UNIV_INTERN
int
trx_rollback_last_sql_stat_for_mysql(
/*=================================*/
/* out: error code or DB_SUCCESS */
trx_t* trx) /* in: transaction handle */
{
int err;
if (trx->conc_state == TRX_NOT_STARTED) {
return(DB_SUCCESS);
}
trx->op_info = "rollback of SQL statement";
err = trx_general_rollback_for_mysql(trx, TRUE,
&(trx->last_sql_stat_start));
/* The following call should not be needed, but we play safe: */
trx_mark_sql_stat_end(trx);
trx->op_info = "";
return(err);
}
/***********************************************************************
Frees a single savepoint struct. */
UNIV_INTERN
void
trx_roll_savepoint_free(
/*=====================*/
trx_t* trx, /* in: transaction handle */
trx_named_savept_t* savep) /* in: savepoint to free */
{
ut_a(savep != NULL);
ut_a(UT_LIST_GET_LEN(trx->trx_savepoints) > 0);
UT_LIST_REMOVE(trx_savepoints, trx->trx_savepoints, savep);
mem_free(savep->name);
mem_free(savep);
}
/***********************************************************************
Frees savepoint structs starting from savep, if savep == NULL then
free all savepoints. */
void
trx_roll_savepoints_free(
/*=====================*/
trx_t* trx, /* in: transaction handle */
trx_named_savept_t* savep) /* in: free all savepoints > this one;
if this is NULL, free all savepoints
of trx */
{
trx_named_savept_t* next_savep;
if (savep == NULL) {
savep = UT_LIST_GET_FIRST(trx->trx_savepoints);
} else {
savep = UT_LIST_GET_NEXT(trx_savepoints, savep);
}
while (savep != NULL) {
next_savep = UT_LIST_GET_NEXT(trx_savepoints, savep);
trx_roll_savepoint_free(trx, savep);
savep = next_savep;
}
}
/***********************************************************************
Rolls back a transaction back to a named savepoint. Modifications after the
savepoint are undone but InnoDB does NOT release the corresponding locks
which are stored in memory. If a lock is 'implicit', that is, a new inserted
row holds a lock where the lock information is carried by the trx id stored in
the row, these locks are naturally released in the rollback. Savepoints which
were set after this savepoint are deleted. */
UNIV_INTERN
ulint
trx_rollback_to_savepoint_for_mysql(
/*================================*/
/* out: if no savepoint
of the name found then
DB_NO_SAVEPOINT,
otherwise DB_SUCCESS */
trx_t* trx, /* in: transaction handle */
const char* savepoint_name, /* in: savepoint name */
ib_int64_t* mysql_binlog_cache_pos) /* out: the MySQL binlog cache
position corresponding to this
savepoint; MySQL needs this
information to remove the
binlog entries of the queries
executed after the savepoint */
{
trx_named_savept_t* savep;
ulint err;
savep = UT_LIST_GET_FIRST(trx->trx_savepoints);
while (savep != NULL) {
if (0 == ut_strcmp(savep->name, savepoint_name)) {
/* Found */
break;
}
savep = UT_LIST_GET_NEXT(trx_savepoints, savep);
}
if (savep == NULL) {
return(DB_NO_SAVEPOINT);
}
if (trx->conc_state == TRX_NOT_STARTED) {
ut_print_timestamp(stderr);
fputs(" InnoDB: Error: transaction has a savepoint ", stderr);
ut_print_name(stderr, trx, FALSE, savep->name);
fputs(" though it is not started\n", stderr);
return(DB_ERROR);
}
/* We can now free all savepoints strictly later than this one */
trx_roll_savepoints_free(trx, savep);
*mysql_binlog_cache_pos = savep->mysql_binlog_cache_pos;
trx->op_info = "rollback to a savepoint";
err = trx_general_rollback_for_mysql(trx, TRUE, &(savep->savept));
/* Store the current undo_no of the transaction so that we know where
to roll back if we have to roll back the next SQL statement: */
trx_mark_sql_stat_end(trx);
trx->op_info = "";
return(err);
}
/***********************************************************************
Creates a named savepoint. If the transaction is not yet started, starts it.
If there is already a savepoint of the same name, this call erases that old
savepoint and replaces it with a new. Savepoints are deleted in a transaction
commit or rollback. */
UNIV_INTERN
ulint
trx_savepoint_for_mysql(
/*====================*/
/* out: always DB_SUCCESS */
trx_t* trx, /* in: transaction handle */
const char* savepoint_name, /* in: savepoint name */
ib_int64_t binlog_cache_pos) /* in: MySQL binlog cache
position corresponding to this
connection at the time of the
savepoint */
{
trx_named_savept_t* savep;
ut_a(trx);
ut_a(savepoint_name);
trx_start_if_not_started(trx);
savep = UT_LIST_GET_FIRST(trx->trx_savepoints);
while (savep != NULL) {
if (0 == ut_strcmp(savep->name, savepoint_name)) {
/* Found */
break;
}
savep = UT_LIST_GET_NEXT(trx_savepoints, savep);
}
if (savep) {
/* There is a savepoint with the same name: free that */
UT_LIST_REMOVE(trx_savepoints, trx->trx_savepoints, savep);
mem_free(savep->name);
mem_free(savep);
}
/* Create a new savepoint and add it as the last in the list */
savep = mem_alloc(sizeof(trx_named_savept_t));
savep->name = mem_strdup(savepoint_name);
savep->savept = trx_savept_take(trx);
savep->mysql_binlog_cache_pos = binlog_cache_pos;
UT_LIST_ADD_LAST(trx_savepoints, trx->trx_savepoints, savep);
return(DB_SUCCESS);
}
/***********************************************************************
Releases only the named savepoint. Savepoints which were set after this
savepoint are left as is. */
UNIV_INTERN
ulint
trx_release_savepoint_for_mysql(
/*============================*/
/* out: if no savepoint
of the name found then
DB_NO_SAVEPOINT,
otherwise DB_SUCCESS */
trx_t* trx, /* in: transaction handle */
const char* savepoint_name) /* in: savepoint name */
{
trx_named_savept_t* savep;
savep = UT_LIST_GET_FIRST(trx->trx_savepoints);
/* Search for the savepoint by name and free if found. */
while (savep != NULL) {
if (0 == ut_strcmp(savep->name, savepoint_name)) {
trx_roll_savepoint_free(trx, savep);
return(DB_SUCCESS);
}
savep = UT_LIST_GET_NEXT(trx_savepoints, savep);
}
return(DB_NO_SAVEPOINT);
}
/***********************************************************************
Determines if this transaction is rolling back an incomplete transaction
in crash recovery. */
UNIV_INTERN
ibool
trx_is_recv(
/*========*/
/* out: TRUE if trx is an incomplete
transaction that is being rolled back
in crash recovery */
const trx_t* trx) /* in: transaction */
{
return(trx == trx_roll_crash_recv_trx);
}
/***********************************************************************
Returns a transaction savepoint taken at this point in time. */
UNIV_INTERN
trx_savept_t
trx_savept_take(
/*============*/
/* out: savepoint */
trx_t* trx) /* in: transaction */
{
trx_savept_t savept;
savept.least_undo_no = trx->undo_no;
return(savept);
}
/***********************************************************************
Roll back an active transaction. */
static
void
trx_rollback_active(
/*================*/
trx_t* trx) /* in/out: transaction */
{
mem_heap_t* heap;
que_fork_t* fork;
que_thr_t* thr;
roll_node_t* roll_node;
dict_table_t* table;
ib_int64_t rows_to_undo;
const char* unit = "";
ibool dictionary_locked = FALSE;
heap = mem_heap_create(512);
fork = que_fork_create(NULL, NULL, QUE_FORK_RECOVERY, heap);
fork->trx = trx;
thr = que_thr_create(fork, heap);
roll_node = roll_node_create(heap);
thr->child = roll_node;
roll_node->common.parent = thr;
mutex_enter(&kernel_mutex);
trx->graph = fork;
ut_a(thr == que_fork_start_command(fork));
trx_roll_crash_recv_trx = trx;
trx_roll_max_undo_no = ut_conv_dulint_to_longlong(trx->undo_no);
trx_roll_progress_printed_pct = 0;
rows_to_undo = trx_roll_max_undo_no;
if (rows_to_undo > 1000000000) {
rows_to_undo = rows_to_undo / 1000000;
unit = "M";
}
ut_print_timestamp(stderr);
fprintf(stderr,
" InnoDB: Rolling back trx with id " TRX_ID_FMT ", %lu%s"
" rows to undo\n",
TRX_ID_PREP_PRINTF(trx->id),
(ulong) rows_to_undo, unit);
mutex_exit(&kernel_mutex);
trx->mysql_thread_id = os_thread_get_curr_id();
trx->mysql_process_no = os_proc_get_number();
if (trx_get_dict_operation(trx) != TRX_DICT_OP_NONE) {
row_mysql_lock_data_dictionary(trx);
dictionary_locked = TRUE;
}
que_run_threads(thr);
mutex_enter(&kernel_mutex);
while (trx->que_state != TRX_QUE_RUNNING) {
mutex_exit(&kernel_mutex);
fprintf(stderr,
"InnoDB: Waiting for rollback of trx id %lu to end\n",
(ulong) ut_dulint_get_low(trx->id));
os_thread_sleep(100000);
mutex_enter(&kernel_mutex);
}
mutex_exit(&kernel_mutex);
if (trx_get_dict_operation(trx) != TRX_DICT_OP_NONE
&& !ut_dulint_is_zero(trx->table_id)) {
/* If the transaction was for a dictionary operation, we
drop the relevant table, if it still exists */
fprintf(stderr,
"InnoDB: Dropping table with id %lu %lu"
" in recovery if it exists\n",
(ulong) ut_dulint_get_high(trx->table_id),
(ulong) ut_dulint_get_low(trx->table_id));
table = dict_table_get_on_id_low(trx->table_id);
if (table) {
ulint err;
fputs("InnoDB: Table found: dropping table ", stderr);
ut_print_name(stderr, trx, TRUE, table->name);
fputs(" in recovery\n", stderr);
err = row_drop_table_for_mysql(table->name, trx, TRUE);
trx_commit_for_mysql(trx);
ut_a(err == (int) DB_SUCCESS);
}
}
if (dictionary_locked) {
row_mysql_unlock_data_dictionary(trx);
}
fprintf(stderr, "\nInnoDB: Rolling back of trx id " TRX_ID_FMT
" completed\n",
TRX_ID_PREP_PRINTF(trx->id));
mem_heap_free(heap);
trx_roll_crash_recv_trx = NULL;
}
/***********************************************************************
Rollback or clean up any incomplete transactions which were
encountered in crash recovery. If the transaction already was
committed, then we clean up a possible insert undo log. If the
transaction was not yet committed, then we roll it back.
Note: this is done in a background thread. */
UNIV_INTERN
os_thread_ret_t
trx_rollback_or_clean_all_recovered(
/*================================*/
/* out: a dummy parameter */
void* arg __attribute__((unused)))
/* in: a dummy parameter required by
os_thread_create */
{
trx_t* trx;
mutex_enter(&kernel_mutex);
if (UT_LIST_GET_FIRST(trx_sys->trx_list)) {
fprintf(stderr,
"InnoDB: Starting in background the rollback"
" of uncommitted transactions\n");
} else {
goto leave_function;
}
mutex_exit(&kernel_mutex);
loop:
mutex_enter(&kernel_mutex);
for (trx = UT_LIST_GET_FIRST(trx_sys->trx_list); trx;
trx = UT_LIST_GET_NEXT(trx_list, trx)) {
if (!trx->is_recovered) {
continue;
}
switch (trx->conc_state) {
case TRX_NOT_STARTED:
case TRX_PREPARED:
continue;
case TRX_COMMITTED_IN_MEMORY:
mutex_exit(&kernel_mutex);
fprintf(stderr,
"InnoDB: Cleaning up trx with id "
TRX_ID_FMT "\n",
TRX_ID_PREP_PRINTF(trx->id));
trx_cleanup_at_db_startup(trx);
goto loop;
case TRX_ACTIVE:
mutex_exit(&kernel_mutex);
trx_rollback_active(trx);
goto loop;
}
}
ut_print_timestamp(stderr);
fprintf(stderr,
" InnoDB: Rollback of non-prepared transactions completed\n");
leave_function:
mutex_exit(&kernel_mutex);
/* We count the number of threads in os_thread_exit(). A created
thread should always use that to exit and not use return() to exit. */
os_thread_exit(NULL);
OS_THREAD_DUMMY_RETURN;
}
/***********************************************************************
Creates an undo number array. */
UNIV_INTERN
trx_undo_arr_t*
trx_undo_arr_create(void)
/*=====================*/
{
trx_undo_arr_t* arr;
mem_heap_t* heap;
ulint i;
heap = mem_heap_create(1024);
arr = mem_heap_alloc(heap, sizeof(trx_undo_arr_t));
arr->infos = mem_heap_alloc(heap, sizeof(trx_undo_inf_t)
* UNIV_MAX_PARALLELISM);
arr->n_cells = UNIV_MAX_PARALLELISM;
arr->n_used = 0;
arr->heap = heap;
for (i = 0; i < UNIV_MAX_PARALLELISM; i++) {
(trx_undo_arr_get_nth_info(arr, i))->in_use = FALSE;
}
return(arr);
}
/***********************************************************************
Frees an undo number array. */
UNIV_INTERN
void
trx_undo_arr_free(
/*==============*/
trx_undo_arr_t* arr) /* in: undo number array */
{
ut_ad(arr->n_used == 0);
mem_heap_free(arr->heap);
}
/***********************************************************************
Stores info of an undo log record to the array if it is not stored yet. */
static
ibool
trx_undo_arr_store_info(
/*====================*/
/* out: FALSE if the record already existed in the
array */
trx_t* trx, /* in: transaction */
dulint undo_no)/* in: undo number */
{
trx_undo_inf_t* cell;
trx_undo_inf_t* stored_here;
trx_undo_arr_t* arr;
ulint n_used;
ulint n;
ulint i;
n = 0;
arr = trx->undo_no_arr;
n_used = arr->n_used;
stored_here = NULL;
for (i = 0;; i++) {
cell = trx_undo_arr_get_nth_info(arr, i);
if (!cell->in_use) {
if (!stored_here) {
/* Not in use, we may store here */
cell->undo_no = undo_no;
cell->in_use = TRUE;
arr->n_used++;
stored_here = cell;
}
} else {
n++;
if (0 == ut_dulint_cmp(cell->undo_no, undo_no)) {
if (stored_here) {
stored_here->in_use = FALSE;
ut_ad(arr->n_used > 0);
arr->n_used--;
}
ut_ad(arr->n_used == n_used);
return(FALSE);
}
}
if (n == n_used && stored_here) {
ut_ad(arr->n_used == 1 + n_used);
return(TRUE);
}
}
}
/***********************************************************************
Removes an undo number from the array. */
static
void
trx_undo_arr_remove_info(
/*=====================*/
trx_undo_arr_t* arr, /* in: undo number array */
dulint undo_no)/* in: undo number */
{
trx_undo_inf_t* cell;
ulint n_used;
ulint n;
ulint i;
n_used = arr->n_used;
n = 0;
for (i = 0;; i++) {
cell = trx_undo_arr_get_nth_info(arr, i);
if (cell->in_use
&& 0 == ut_dulint_cmp(cell->undo_no, undo_no)) {
cell->in_use = FALSE;
ut_ad(arr->n_used > 0);
arr->n_used--;
return;
}
}
}
/***********************************************************************
Gets the biggest undo number in an array. */
static
dulint
trx_undo_arr_get_biggest(
/*=====================*/
/* out: biggest value, ut_dulint_zero if
the array is empty */
trx_undo_arr_t* arr) /* in: undo number array */
{
trx_undo_inf_t* cell;
ulint n_used;
dulint biggest;
ulint n;
ulint i;
n = 0;
n_used = arr->n_used;
biggest = ut_dulint_zero;
for (i = 0;; i++) {
cell = trx_undo_arr_get_nth_info(arr, i);
if (cell->in_use) {
n++;
if (ut_dulint_cmp(cell->undo_no, biggest) > 0) {
biggest = cell->undo_no;
}
}
if (n == n_used) {
return(biggest);
}
}
}
/***************************************************************************
Tries truncate the undo logs. */
UNIV_INTERN
void
trx_roll_try_truncate(
/*==================*/
trx_t* trx) /* in: transaction */
{
trx_undo_arr_t* arr;
dulint limit;
dulint biggest;
ut_ad(mutex_own(&(trx->undo_mutex)));
ut_ad(mutex_own(&((trx->rseg)->mutex)));
trx->pages_undone = 0;
arr = trx->undo_no_arr;
limit = trx->undo_no;
if (arr->n_used > 0) {
biggest = trx_undo_arr_get_biggest(arr);
if (ut_dulint_cmp(biggest, limit) >= 0) {
limit = ut_dulint_add(biggest, 1);
}
}
if (trx->insert_undo) {
trx_undo_truncate_end(trx, trx->insert_undo, limit);
}
if (trx->update_undo) {
trx_undo_truncate_end(trx, trx->update_undo, limit);
}
}
/***************************************************************************
Pops the topmost undo log record in a single undo log and updates the info
about the topmost record in the undo log memory struct. */
static
trx_undo_rec_t*
trx_roll_pop_top_rec(
/*=================*/
/* out: undo log record, the page s-latched */
trx_t* trx, /* in: transaction */
trx_undo_t* undo, /* in: undo log */
mtr_t* mtr) /* in: mtr */
{
page_t* undo_page;
ulint offset;
trx_undo_rec_t* prev_rec;
page_t* prev_rec_page;
ut_ad(mutex_own(&(trx->undo_mutex)));
undo_page = trx_undo_page_get_s_latched(undo->space, undo->zip_size,
undo->top_page_no, mtr);
offset = undo->top_offset;
/* fprintf(stderr, "Thread %lu undoing trx %lu undo record %lu\n",
os_thread_get_curr_id(), ut_dulint_get_low(trx->id),
ut_dulint_get_low(undo->top_undo_no)); */
prev_rec = trx_undo_get_prev_rec(undo_page + offset,
undo->hdr_page_no, undo->hdr_offset,
mtr);
if (prev_rec == NULL) {
undo->empty = TRUE;
} else {
prev_rec_page = page_align(prev_rec);
if (prev_rec_page != undo_page) {
trx->pages_undone++;
}
undo->top_page_no = page_get_page_no(prev_rec_page);
undo->top_offset = prev_rec - prev_rec_page;
undo->top_undo_no = trx_undo_rec_get_undo_no(prev_rec);
}
return(undo_page + offset);
}
/************************************************************************
Pops the topmost record when the two undo logs of a transaction are seen
as a single stack of records ordered by their undo numbers. Inserts the
undo number of the popped undo record to the array of currently processed
undo numbers in the transaction. When the query thread finishes processing
of this undo record, it must be released with trx_undo_rec_release. */
UNIV_INTERN
trx_undo_rec_t*
trx_roll_pop_top_rec_of_trx(
/*========================*/
/* out: undo log record copied to heap, NULL
if none left, or if the undo number of the
top record would be less than the limit */
trx_t* trx, /* in: transaction */
dulint limit, /* in: least undo number we need */
dulint* roll_ptr,/* out: roll pointer to undo record */
mem_heap_t* heap) /* in: memory heap where copied */
{
trx_undo_t* undo;
trx_undo_t* ins_undo;
trx_undo_t* upd_undo;
trx_undo_rec_t* undo_rec;
trx_undo_rec_t* undo_rec_copy;
dulint undo_no;
ibool is_insert;
trx_rseg_t* rseg;
ulint progress_pct;
mtr_t mtr;
rseg = trx->rseg;
try_again:
mutex_enter(&(trx->undo_mutex));
if (trx->pages_undone >= TRX_ROLL_TRUNC_THRESHOLD) {
mutex_enter(&(rseg->mutex));
trx_roll_try_truncate(trx);
mutex_exit(&(rseg->mutex));
}
ins_undo = trx->insert_undo;
upd_undo = trx->update_undo;
if (!ins_undo || ins_undo->empty) {
undo = upd_undo;
} else if (!upd_undo || upd_undo->empty) {
undo = ins_undo;
} else if (ut_dulint_cmp(upd_undo->top_undo_no,
ins_undo->top_undo_no) > 0) {
undo = upd_undo;
} else {
undo = ins_undo;
}
if (!undo || undo->empty
|| (ut_dulint_cmp(limit, undo->top_undo_no) > 0)) {
if ((trx->undo_no_arr)->n_used == 0) {
/* Rollback is ending */
mutex_enter(&(rseg->mutex));
trx_roll_try_truncate(trx);
mutex_exit(&(rseg->mutex));
}
mutex_exit(&(trx->undo_mutex));
return(NULL);
}
if (undo == ins_undo) {
is_insert = TRUE;
} else {
is_insert = FALSE;
}
*roll_ptr = trx_undo_build_roll_ptr(is_insert, (undo->rseg)->id,
undo->top_page_no,
undo->top_offset);
mtr_start(&mtr);
undo_rec = trx_roll_pop_top_rec(trx, undo, &mtr);
undo_no = trx_undo_rec_get_undo_no(undo_rec);
ut_ad(ut_dulint_cmp(ut_dulint_add(undo_no, 1), trx->undo_no) == 0);
/* We print rollback progress info if we are in a crash recovery
and the transaction has at least 1000 row operations to undo. */
if (trx == trx_roll_crash_recv_trx && trx_roll_max_undo_no > 1000) {
progress_pct = 100 - (ulint)
((ut_conv_dulint_to_longlong(undo_no) * 100)
/ trx_roll_max_undo_no);
if (progress_pct != trx_roll_progress_printed_pct) {
if (trx_roll_progress_printed_pct == 0) {
fprintf(stderr,
"\nInnoDB: Progress in percents:"
" %lu", (ulong) progress_pct);
} else {
fprintf(stderr,
" %lu", (ulong) progress_pct);
}
fflush(stderr);
trx_roll_progress_printed_pct = progress_pct;
}
}
trx->undo_no = undo_no;
if (!trx_undo_arr_store_info(trx, undo_no)) {
/* A query thread is already processing this undo log record */
mutex_exit(&(trx->undo_mutex));
mtr_commit(&mtr);
goto try_again;
}
undo_rec_copy = trx_undo_rec_copy(undo_rec, heap);
mutex_exit(&(trx->undo_mutex));
mtr_commit(&mtr);
return(undo_rec_copy);
}
/************************************************************************
Reserves an undo log record for a query thread to undo. This should be
called if the query thread gets the undo log record not using the pop
function above. */
UNIV_INTERN
ibool
trx_undo_rec_reserve(
/*=================*/
/* out: TRUE if succeeded */
trx_t* trx, /* in: transaction */
dulint undo_no)/* in: undo number of the record */
{
ibool ret;
mutex_enter(&(trx->undo_mutex));
ret = trx_undo_arr_store_info(trx, undo_no);
mutex_exit(&(trx->undo_mutex));
return(ret);
}
/***********************************************************************
Releases a reserved undo record. */
UNIV_INTERN
void
trx_undo_rec_release(
/*=================*/
trx_t* trx, /* in: transaction */
dulint undo_no)/* in: undo number */
{
trx_undo_arr_t* arr;
mutex_enter(&(trx->undo_mutex));
arr = trx->undo_no_arr;
trx_undo_arr_remove_info(arr, undo_no);
mutex_exit(&(trx->undo_mutex));
}
/*************************************************************************
Starts a rollback operation. */
UNIV_INTERN
void
trx_rollback(
/*=========*/
trx_t* trx, /* in: transaction */
trx_sig_t* sig, /* in: signal starting the rollback */
que_thr_t** next_thr)/* in/out: next query thread to run;
if the value which is passed in is
a pointer to a NULL pointer, then the
calling function can start running
a new query thread; if the passed value is
NULL, the parameter is ignored */
{
que_t* roll_graph;
que_thr_t* thr;
/* que_thr_t* thr2; */
ut_ad(mutex_own(&kernel_mutex));
ut_ad((trx->undo_no_arr == NULL) || ((trx->undo_no_arr)->n_used == 0));
/* Initialize the rollback field in the transaction */
if (sig->type == TRX_SIG_TOTAL_ROLLBACK) {
trx->roll_limit = ut_dulint_zero;
} else if (sig->type == TRX_SIG_ROLLBACK_TO_SAVEPT) {
trx->roll_limit = (sig->savept).least_undo_no;
} else if (sig->type == TRX_SIG_ERROR_OCCURRED) {
trx->roll_limit = trx->last_sql_stat_start.least_undo_no;
} else {
ut_error;
}
ut_a(ut_dulint_cmp(trx->roll_limit, trx->undo_no) <= 0);
trx->pages_undone = 0;
if (trx->undo_no_arr == NULL) {
trx->undo_no_arr = trx_undo_arr_create();
}
/* Build a 'query' graph which will perform the undo operations */
roll_graph = trx_roll_graph_build(trx);
trx->graph = roll_graph;
trx->que_state = TRX_QUE_ROLLING_BACK;
thr = que_fork_start_command(roll_graph);
ut_ad(thr);
/* thr2 = que_fork_start_command(roll_graph);
ut_ad(thr2); */
if (next_thr && (*next_thr == NULL)) {
*next_thr = thr;
/* srv_que_task_enqueue_low(thr2); */
} else {
srv_que_task_enqueue_low(thr);
/* srv_que_task_enqueue_low(thr2); */
}
}
/********************************************************************
Builds an undo 'query' graph for a transaction. The actual rollback is
performed by executing this query graph like a query subprocedure call.
The reply about the completion of the rollback will be sent by this
graph. */
UNIV_INTERN
que_t*
trx_roll_graph_build(
/*=================*/
/* out, own: the query graph */
trx_t* trx) /* in: trx handle */
{
mem_heap_t* heap;
que_fork_t* fork;
que_thr_t* thr;
/* que_thr_t* thr2; */
ut_ad(mutex_own(&kernel_mutex));
heap = mem_heap_create(512);
fork = que_fork_create(NULL, NULL, QUE_FORK_ROLLBACK, heap);
fork->trx = trx;
thr = que_thr_create(fork, heap);
/* thr2 = que_thr_create(fork, heap); */
thr->child = row_undo_node_create(trx, thr, heap);
/* thr2->child = row_undo_node_create(trx, thr2, heap); */
return(fork);
}
/*************************************************************************
Finishes error processing after the necessary partial rollback has been
done. */
static
void
trx_finish_error_processing(
/*========================*/
trx_t* trx) /* in: transaction */
{
trx_sig_t* sig;
trx_sig_t* next_sig;
ut_ad(mutex_own(&kernel_mutex));
sig = UT_LIST_GET_FIRST(trx->signals);
while (sig != NULL) {
next_sig = UT_LIST_GET_NEXT(signals, sig);
if (sig->type == TRX_SIG_ERROR_OCCURRED) {
trx_sig_remove(trx, sig);
}
sig = next_sig;
}
trx->que_state = TRX_QUE_RUNNING;
}
/*************************************************************************
Finishes a partial rollback operation. */
static
void
trx_finish_partial_rollback_off_kernel(
/*===================================*/
trx_t* trx, /* in: transaction */
que_thr_t** next_thr)/* in/out: next query thread to run;
if the value which is passed in is a pointer
to a NULL pointer, then the calling function
can start running a new query thread; if this
parameter is NULL, it is ignored */
{
trx_sig_t* sig;
ut_ad(mutex_own(&kernel_mutex));
sig = UT_LIST_GET_FIRST(trx->signals);
/* Remove the signal from the signal queue and send reply message
to it */
trx_sig_reply(sig, next_thr);
trx_sig_remove(trx, sig);
trx->que_state = TRX_QUE_RUNNING;
}
/********************************************************************
Finishes a transaction rollback. */
UNIV_INTERN
void
trx_finish_rollback_off_kernel(
/*===========================*/
que_t* graph, /* in: undo graph which can now be freed */
trx_t* trx, /* in: transaction */
que_thr_t** next_thr)/* in/out: next query thread to run;
if the value which is passed in is
a pointer to a NULL pointer, then the
calling function can start running
a new query thread; if this parameter is
NULL, it is ignored */
{
trx_sig_t* sig;
trx_sig_t* next_sig;
ut_ad(mutex_own(&kernel_mutex));
ut_a(trx->undo_no_arr == NULL || trx->undo_no_arr->n_used == 0);
/* Free the memory reserved by the undo graph */
que_graph_free(graph);
sig = UT_LIST_GET_FIRST(trx->signals);
if (sig->type == TRX_SIG_ROLLBACK_TO_SAVEPT) {
trx_finish_partial_rollback_off_kernel(trx, next_thr);
return;
} else if (sig->type == TRX_SIG_ERROR_OCCURRED) {
trx_finish_error_processing(trx);
return;
}
#ifdef UNIV_DEBUG
if (lock_print_waits) {
fprintf(stderr, "Trx %lu rollback finished\n",
(ulong) ut_dulint_get_low(trx->id));
}
#endif /* UNIV_DEBUG */
trx_commit_off_kernel(trx);
/* Remove all TRX_SIG_TOTAL_ROLLBACK signals from the signal queue and
send reply messages to them */
trx->que_state = TRX_QUE_RUNNING;
while (sig != NULL) {
next_sig = UT_LIST_GET_NEXT(signals, sig);
if (sig->type == TRX_SIG_TOTAL_ROLLBACK) {
trx_sig_reply(sig, next_thr);
trx_sig_remove(trx, sig);
}
sig = next_sig;
}
}
/*************************************************************************
Creates a rollback command node struct. */
UNIV_INTERN
roll_node_t*
roll_node_create(
/*=============*/
/* out, own: rollback node struct */
mem_heap_t* heap) /* in: mem heap where created */
{
roll_node_t* node;
node = mem_heap_alloc(heap, sizeof(roll_node_t));
node->common.type = QUE_NODE_ROLLBACK;
node->state = ROLL_NODE_SEND;
node->partial = FALSE;
return(node);
}
/***************************************************************
Performs an execution step for a rollback command node in a query graph. */
UNIV_INTERN
que_thr_t*
trx_rollback_step(
/*==============*/
/* out: query thread to run next, or NULL */
que_thr_t* thr) /* in: query thread */
{
roll_node_t* node;
ulint sig_no;
trx_savept_t* savept;
node = thr->run_node;
ut_ad(que_node_get_type(node) == QUE_NODE_ROLLBACK);
if (thr->prev_node == que_node_get_parent(node)) {
node->state = ROLL_NODE_SEND;
}
if (node->state == ROLL_NODE_SEND) {
mutex_enter(&kernel_mutex);
node->state = ROLL_NODE_WAIT;
if (node->partial) {
sig_no = TRX_SIG_ROLLBACK_TO_SAVEPT;
savept = &(node->savept);
} else {
sig_no = TRX_SIG_TOTAL_ROLLBACK;
savept = NULL;
}
/* Send a rollback signal to the transaction */
trx_sig_send(thr_get_trx(thr), sig_no, TRX_SIG_SELF, thr,
savept, NULL);
thr->state = QUE_THR_SIG_REPLY_WAIT;
mutex_exit(&kernel_mutex);
return(NULL);
}
ut_ad(node->state == ROLL_NODE_WAIT);
thr->run_node = que_node_get_parent(node);
return(thr);
}