2014-02-26 19:11:54 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
|
2016-06-21 14:21:03 +02:00
|
|
|
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
|
MDEV-12091 Shutdown fails to wait for rollback of recovered transactions to finish
In the 10.1 InnoDB Plugin, a call os_event_free(buf_flush_event) was
misplaced. The event could be triggered by rollback of resurrected
transactions while shutdown was in progress. This bug was caught
by cmake -DWITH_ASAN testing. This call was only present in the
10.1 InnoDB Plugin, not in other versions, or in XtraDB.
That said, the bug affects all InnoDB versions. Shutdown assumes the
cessation of any page-dirtying activity, including the activity of
the background rollback thread. InnoDB only waited for the background
rollback to finish as part of a slow shutdown (innodb_fast_shutdown=0).
The default is a clean shutdown (innodb_fast_shutdown=1). In a scenario
where InnoDB is killed, restarted, and shut down soon enough, the data
files could become corrupted.
logs_empty_and_mark_files_at_shutdown(): Wait for the
rollback to finish, except if innodb_fast_shutdown=2
(crash-like shutdown) was requested.
trx_rollback_or_clean_recovered(): Before choosing the next
recovered transaction to roll back, terminate early if non-slow
shutdown was initiated. Roll back everything on slow shutdown
(innodb_fast_shutdown=0).
srv_innodb_monitor_mutex: Declare as static, because the mutex
is only used within one module.
In 10.2, os_event_destroy() sets the event to a NULL pointer,
while os_event_free() in earlier versions did not do that.
2017-03-10 16:01:02 +02:00
|
|
|
Copyright (c) 2016, 2017, MariaDB Corporation.
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
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.,
|
|
|
|
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
|
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************//**
|
|
|
|
@file trx/trx0roll.cc
|
|
|
|
Transaction rollback
|
|
|
|
|
|
|
|
Created 3/26/1996 Heikki Tuuri
|
|
|
|
*******************************************************/
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
#include "ha_prototypes.h"
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
#include "trx0roll.h"
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
#include <mysql/service_wsrep.h>
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
#include "fsp0fsp.h"
|
2016-08-12 11:17:45 +03:00
|
|
|
#include "lock0lock.h"
|
2014-02-26 19:11:54 +01:00
|
|
|
#include "mach0data.h"
|
2016-08-12 11:17:45 +03:00
|
|
|
#include "pars0pars.h"
|
2014-02-26 19:11:54 +01:00
|
|
|
#include "que0que.h"
|
|
|
|
#include "read0read.h"
|
|
|
|
#include "row0mysql.h"
|
2016-08-12 11:17:45 +03:00
|
|
|
#include "row0undo.h"
|
2014-02-26 19:11:54 +01:00
|
|
|
#include "srv0mon.h"
|
2016-08-12 11:17:45 +03:00
|
|
|
#include "srv0start.h"
|
|
|
|
#include "trx0rec.h"
|
|
|
|
#include "trx0rseg.h"
|
2014-02-26 19:11:54 +01:00
|
|
|
#include "trx0sys.h"
|
2016-08-12 11:17:45 +03:00
|
|
|
#include "trx0trx.h"
|
|
|
|
#include "trx0undo.h"
|
|
|
|
#include "usr0sess.h"
|
|
|
|
#include "ha_prototypes.h"
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/** This many pages must be undone before a truncate is tried within
|
|
|
|
rollback */
|
2016-08-12 11:17:45 +03:00
|
|
|
static const ulint TRX_ROLL_TRUNC_THRESHOLD = 1;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2015-02-18 16:20:46 +01:00
|
|
|
/** true if trx_rollback_or_clean_all_recovered() thread is active */
|
|
|
|
bool trx_rollback_or_clean_is_active;
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/** In crash recovery, the current trx to be rolled back; NULL otherwise */
|
|
|
|
static const 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 undo_no_t trx_roll_max_undo_no;
|
|
|
|
|
|
|
|
/** Auxiliary variable which tells the previous progress % we printed */
|
|
|
|
static ulint trx_roll_progress_printed_pct;
|
|
|
|
|
|
|
|
/****************************************************************//**
|
|
|
|
Finishes a transaction rollback. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
trx_rollback_finish(
|
|
|
|
/*================*/
|
|
|
|
trx_t* trx); /*!< in: transaction */
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Rollback a transaction used in MySQL. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
trx_rollback_to_savepoint_low(
|
|
|
|
/*==========================*/
|
|
|
|
trx_t* trx, /*!< in: transaction handle */
|
|
|
|
trx_savept_t* savept) /*!< in: pointer to savepoint undo number, if
|
|
|
|
partial rollback requested, or NULL for
|
|
|
|
complete rollback */
|
|
|
|
{
|
|
|
|
que_thr_t* thr;
|
|
|
|
mem_heap_t* heap;
|
|
|
|
roll_node_t* roll_node;
|
|
|
|
|
|
|
|
heap = mem_heap_create(512);
|
|
|
|
|
|
|
|
roll_node = roll_node_create(heap);
|
|
|
|
|
|
|
|
if (savept != NULL) {
|
|
|
|
roll_node->partial = TRUE;
|
|
|
|
roll_node->savept = *savept;
|
2016-08-12 11:17:45 +03:00
|
|
|
check_trx_state(trx);
|
|
|
|
} else {
|
2014-02-26 19:11:54 +01:00
|
|
|
assert_trx_nonlocking_or_in_list(trx);
|
|
|
|
}
|
|
|
|
|
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (trx_is_rseg_updated(trx)) {
|
|
|
|
|
|
|
|
ut_ad(trx->rsegs.m_redo.rseg != 0
|
|
|
|
|| trx->rsegs.m_noredo.rseg != 0);
|
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
thr = pars_complete_graph_for_exec(roll_node, trx, heap, NULL);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
ut_a(thr == que_fork_start_command(
|
|
|
|
static_cast<que_fork_t*>(que_node_get_parent(thr))));
|
|
|
|
|
|
|
|
que_run_threads(thr);
|
|
|
|
|
|
|
|
ut_a(roll_node->undo_thr != NULL);
|
|
|
|
que_run_threads(roll_node->undo_thr);
|
|
|
|
|
|
|
|
/* Free the memory reserved by the undo graph. */
|
|
|
|
que_graph_free(static_cast<que_t*>(
|
|
|
|
roll_node->undo_thr->common.parent));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (savept == NULL) {
|
|
|
|
trx_rollback_finish(trx);
|
|
|
|
MONITOR_INC(MONITOR_TRX_ROLLBACK);
|
|
|
|
} else {
|
|
|
|
trx->lock.que_state = TRX_QUE_RUNNING;
|
|
|
|
MONITOR_INC(MONITOR_TRX_ROLLBACK_SAVEPOINT);
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_a(trx->error_state == DB_SUCCESS);
|
|
|
|
ut_a(trx->lock.que_state == TRX_QUE_RUNNING);
|
|
|
|
|
|
|
|
mem_heap_free(heap);
|
|
|
|
|
2014-11-18 17:41:12 +01:00
|
|
|
/* There might be work for utility threads.*/
|
|
|
|
srv_active_wake_master_thread();
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
MONITOR_DEC(MONITOR_TRX_ACTIVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Rollback a transaction to a given savepoint or do a complete rollback.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return error code or DB_SUCCESS */
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
|
|
|
trx_rollback_to_savepoint(
|
|
|
|
/*======================*/
|
|
|
|
trx_t* trx, /*!< in: transaction handle */
|
|
|
|
trx_savept_t* savept) /*!< in: pointer to savepoint undo number, if
|
|
|
|
partial rollback requested, or NULL for
|
|
|
|
complete rollback */
|
|
|
|
{
|
|
|
|
ut_ad(!trx_mutex_own(trx));
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_start_if_not_started_xa(trx, true);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
trx_rollback_to_savepoint_low(trx, savept);
|
|
|
|
|
|
|
|
return(trx->error_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Rollback a transaction used in MySQL.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return error code or DB_SUCCESS */
|
2014-02-26 19:11:54 +01:00
|
|
|
static
|
|
|
|
dberr_t
|
|
|
|
trx_rollback_for_mysql_low(
|
|
|
|
/*=======================*/
|
|
|
|
trx_t* trx) /*!< in/out: transaction */
|
|
|
|
{
|
|
|
|
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. */
|
|
|
|
|
|
|
|
trx_rollback_to_savepoint_low(trx, NULL);
|
|
|
|
|
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
ut_a(trx->error_state == DB_SUCCESS);
|
|
|
|
|
|
|
|
return(trx->error_state);
|
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Rollback a transaction used in MySQL
|
|
|
|
@param[in, out] trx transaction
|
|
|
|
@return error code or DB_SUCCESS */
|
|
|
|
static
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_rollback_low(
|
|
|
|
trx_t* trx)
|
2014-02-26 19:11:54 +01:00
|
|
|
{
|
|
|
|
/* We are reading trx->state without holding trx_sys->mutex
|
|
|
|
here, because the rollback should be invoked for a running
|
|
|
|
active MySQL transaction (or recovered prepared transaction)
|
|
|
|
that is associated with the current thread. */
|
|
|
|
|
|
|
|
switch (trx->state) {
|
2016-08-12 11:17:45 +03:00
|
|
|
case TRX_STATE_FORCED_ROLLBACK:
|
2014-02-26 19:11:54 +01:00
|
|
|
case TRX_STATE_NOT_STARTED:
|
2016-08-12 11:17:45 +03:00
|
|
|
trx->will_lock = 0;
|
2014-02-26 19:11:54 +01:00
|
|
|
ut_ad(trx->in_mysql_trx_list);
|
2016-09-06 09:43:16 +03:00
|
|
|
return(DB_SUCCESS);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
case TRX_STATE_ACTIVE:
|
|
|
|
ut_ad(trx->in_mysql_trx_list);
|
|
|
|
assert_trx_nonlocking_or_in_list(trx);
|
|
|
|
return(trx_rollback_for_mysql_low(trx));
|
|
|
|
|
|
|
|
case TRX_STATE_PREPARED:
|
|
|
|
ut_ad(!trx_is_autocommit_non_locking(trx));
|
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled
differently from persistent tables. Because temporary tables are
private to a connection, concurrency control and multi-versioning
(MVCC) are not applicable. For performance reasons, purge is
disabled as well. Rollback is supported for temporary tables;
that is why we have the temporary undo logs in the first place.
Because MVCC and purge are disabled for temporary tables, we should
discard all temporary undo logs already at transaction commit,
just like we discard the persistent insert_undo logs. Before this
change, update_undo logs were being preserved.
trx_temp_undo_t: A wrapper for temporary undo logs, comprising
a rollback segment and a single temporary undo log.
trx_rsegs_t::m_noredo: Use trx_temp_undo_t.
(Instead of insert_undo, update_undo, there will be a single undo.)
trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove.
trx_undo_add_page(): Remove the parameter undo_ptr.
Acquire and release the rollback segment mutex inside the function.
trx_undo_free_last_page(): Remove the parameter trx.
trx_undo_truncate_end(): Remove the parameter trx, and add the
parameter is_temp. Clean up the code a bit.
trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo.
trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup().
Replace the parameter undo_ptr with undo.
This will discard the temporary undo or insert_undo log at
commit/rollback.
trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup():
Remove 3 parameters. Always operate on the persistent update_undo.
trx_serialise(): Renamed from trx_serialisation_number_get().
trx_write_serialisation_history(): Simplify the code flow.
If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO.
trx_commit_in_memory(): Simplify the logic, and add assertions.
trx_undo_page_report_modify(): Keep a direct reference to the
persistent update_undo log.
trx_undo_report_row_operation(): Simplify some code.
Always assign TRX_UNDO_INSERT for temporary undo logs.
trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs.
trx_roll_try_truncate(): Remove the parameter undo_ptr.
Try to truncate all 3 undo logs of the transaction.
trx_roll_pop_top_rec_of_trx_low(): Remove.
trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter
trx->roll_limit. Clear roll_limit when exhausting the undo logs.
Consider all 3 undo logs at once, prioritizing the persistent
undo logs.
row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx()
reset the trx->roll_limit.
2017-03-09 23:20:51 +02:00
|
|
|
if (trx_is_redo_rseg_updated(trx)) {
|
2016-08-12 11:17:45 +03:00
|
|
|
/* Change the undo log state back from
|
|
|
|
TRX_UNDO_PREPARED to TRX_UNDO_ACTIVE
|
|
|
|
so that if the system gets killed,
|
|
|
|
recovery will perform the rollback. */
|
|
|
|
trx_undo_ptr_t* undo_ptr = &trx->rsegs.m_redo;
|
|
|
|
mtr_t mtr;
|
|
|
|
mtr.start();
|
|
|
|
mutex_enter(&trx->rsegs.m_redo.rseg->mutex);
|
|
|
|
if (undo_ptr->insert_undo != NULL) {
|
|
|
|
trx_undo_set_state_at_prepare(
|
|
|
|
trx, undo_ptr->insert_undo,
|
|
|
|
true, &mtr);
|
|
|
|
}
|
|
|
|
if (undo_ptr->update_undo != NULL) {
|
|
|
|
trx_undo_set_state_at_prepare(
|
|
|
|
trx, undo_ptr->update_undo,
|
|
|
|
true, &mtr);
|
|
|
|
}
|
|
|
|
mutex_exit(&trx->rsegs.m_redo.rseg->mutex);
|
|
|
|
/* Persist the XA ROLLBACK, so that crash
|
|
|
|
recovery will replay the rollback in case
|
|
|
|
the redo log gets applied past this point. */
|
|
|
|
mtr.commit();
|
|
|
|
ut_ad(mtr.commit_lsn() > 0);
|
|
|
|
}
|
|
|
|
#ifdef ENABLED_DEBUG_SYNC
|
|
|
|
if (trx->mysql_thd == NULL) {
|
|
|
|
/* We could be executing XA ROLLBACK after
|
|
|
|
XA PREPARE and a server restart. */
|
|
|
|
} else if (!trx_is_redo_rseg_updated(trx)) {
|
|
|
|
/* innobase_close_connection() may roll back a
|
|
|
|
transaction that did not generate any
|
|
|
|
persistent undo log. The DEBUG_SYNC
|
|
|
|
would cause an assertion failure for a
|
|
|
|
disconnected thread.
|
|
|
|
|
|
|
|
NOTE: InnoDB will not know about the XID
|
|
|
|
if no persistent undo log was generated. */
|
|
|
|
} else {
|
|
|
|
DEBUG_SYNC_C("trx_xa_rollback");
|
|
|
|
}
|
|
|
|
#endif /* ENABLED_DEBUG_SYNC */
|
2014-02-26 19:11:54 +01:00
|
|
|
return(trx_rollback_for_mysql_low(trx));
|
|
|
|
|
|
|
|
case TRX_STATE_COMMITTED_IN_MEMORY:
|
2016-08-12 11:17:45 +03:00
|
|
|
check_trx_state(trx);
|
2014-02-26 19:11:54 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_error;
|
|
|
|
return(DB_CORRUPTION);
|
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/*******************************************************************//**
|
|
|
|
Rollback a transaction used in MySQL.
|
|
|
|
@return error code or DB_SUCCESS */
|
|
|
|
dberr_t
|
|
|
|
trx_rollback_for_mysql(
|
|
|
|
/*===================*/
|
|
|
|
trx_t* trx) /*!< in/out: transaction */
|
|
|
|
{
|
|
|
|
/* Avoid the tracking of async rollback killer
|
|
|
|
thread to enter into InnoDB. */
|
|
|
|
if (TrxInInnoDB::is_async_rollback(trx)) {
|
|
|
|
|
|
|
|
return(trx_rollback_low(trx));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
TrxInInnoDB trx_in_innodb(trx, true);
|
|
|
|
|
|
|
|
return(trx_rollback_low(trx));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/*******************************************************************//**
|
|
|
|
Rollback the latest SQL statement for MySQL.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return error code or DB_SUCCESS */
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
|
|
|
trx_rollback_last_sql_stat_for_mysql(
|
|
|
|
/*=================================*/
|
|
|
|
trx_t* trx) /*!< in/out: transaction */
|
|
|
|
{
|
|
|
|
dberr_t err;
|
|
|
|
|
|
|
|
/* We are reading trx->state without holding trx_sys->mutex
|
|
|
|
here, because the statement rollback should be invoked for a
|
|
|
|
running active MySQL transaction that is associated with the
|
|
|
|
current thread. */
|
|
|
|
ut_ad(trx->in_mysql_trx_list);
|
|
|
|
|
|
|
|
switch (trx->state) {
|
2016-08-12 11:17:45 +03:00
|
|
|
case TRX_STATE_FORCED_ROLLBACK:
|
2014-02-26 19:11:54 +01:00
|
|
|
case TRX_STATE_NOT_STARTED:
|
|
|
|
return(DB_SUCCESS);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
case TRX_STATE_ACTIVE:
|
|
|
|
assert_trx_nonlocking_or_in_list(trx);
|
|
|
|
|
|
|
|
trx->op_info = "rollback of SQL statement";
|
|
|
|
|
|
|
|
err = trx_rollback_to_savepoint(
|
|
|
|
trx, &trx->last_sql_stat_start);
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (trx->fts_trx != NULL) {
|
2014-02-26 19:11:54 +01:00
|
|
|
fts_savepoint_rollback_last_stmt(trx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The following call should not be needed,
|
|
|
|
but we play it safe: */
|
|
|
|
trx_mark_sql_stat_end(trx);
|
|
|
|
|
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
return(err);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
case TRX_STATE_PREPARED:
|
|
|
|
case TRX_STATE_COMMITTED_IN_MEMORY:
|
|
|
|
/* The statement rollback is only allowed on an ACTIVE
|
|
|
|
transaction, not a PREPARED or COMMITTED one. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_error;
|
|
|
|
return(DB_CORRUPTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Search for a savepoint using name.
|
|
|
|
@return savepoint if found else NULL */
|
|
|
|
static
|
|
|
|
trx_named_savept_t*
|
|
|
|
trx_savepoint_find(
|
|
|
|
/*===============*/
|
|
|
|
trx_t* trx, /*!< in: transaction */
|
|
|
|
const char* name) /*!< in: savepoint name */
|
|
|
|
{
|
|
|
|
trx_named_savept_t* savep;
|
|
|
|
|
|
|
|
for (savep = UT_LIST_GET_FIRST(trx->trx_savepoints);
|
|
|
|
savep != NULL;
|
|
|
|
savep = UT_LIST_GET_NEXT(trx_savepoints, savep)) {
|
|
|
|
|
|
|
|
if (0 == ut_strcmp(savep->name, name)) {
|
|
|
|
return(savep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Frees a single savepoint struct. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
trx_roll_savepoint_free(
|
|
|
|
/*=====================*/
|
|
|
|
trx_t* trx, /*!< in: transaction handle */
|
|
|
|
trx_named_savept_t* savep) /*!< in: savepoint to free */
|
|
|
|
{
|
2016-08-12 11:17:45 +03:00
|
|
|
UT_LIST_REMOVE(trx->trx_savepoints, savep);
|
|
|
|
|
|
|
|
ut_free(savep->name);
|
|
|
|
ut_free(savep);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Frees savepoint structs starting from savep. */
|
|
|
|
void
|
|
|
|
trx_roll_savepoints_free(
|
|
|
|
/*=====================*/
|
|
|
|
trx_t* trx, /*!< in: transaction handle */
|
|
|
|
trx_named_savept_t* savep) /*!< in: free all savepoints starting
|
|
|
|
with this savepoint i*/
|
|
|
|
{
|
|
|
|
while (savep != NULL) {
|
|
|
|
trx_named_savept_t* next_savep;
|
|
|
|
|
|
|
|
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.
|
|
|
|
@return if no savepoint of the name found then DB_NO_SAVEPOINT,
|
|
|
|
otherwise DB_SUCCESS */
|
2016-06-21 14:21:03 +02:00
|
|
|
static MY_ATTRIBUTE((nonnull, warn_unused_result))
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
|
|
|
trx_rollback_to_savepoint_for_mysql_low(
|
|
|
|
/*====================================*/
|
|
|
|
trx_t* trx, /*!< in/out: transaction */
|
|
|
|
trx_named_savept_t* savep, /*!< in/out: savepoint */
|
2016-08-12 11:17:45 +03:00
|
|
|
int64_t* mysql_binlog_cache_pos)
|
2014-02-26 19:11:54 +01:00
|
|
|
/*!< 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 */
|
|
|
|
{
|
|
|
|
dberr_t err;
|
|
|
|
|
|
|
|
ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE));
|
|
|
|
ut_ad(trx->in_mysql_trx_list);
|
|
|
|
|
|
|
|
/* Free all savepoints strictly later than savep. */
|
|
|
|
|
|
|
|
trx_roll_savepoints_free(
|
|
|
|
trx, UT_LIST_GET_NEXT(trx_savepoints, savep));
|
|
|
|
|
|
|
|
*mysql_binlog_cache_pos = savep->mysql_binlog_cache_pos;
|
|
|
|
|
|
|
|
trx->op_info = "rollback to a savepoint";
|
|
|
|
|
|
|
|
err = trx_rollback_to_savepoint(trx, &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 = "";
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
#ifdef WITH_WSREP
|
|
|
|
if (wsrep_on(trx->mysql_thd) &&
|
|
|
|
trx->lock.was_chosen_as_deadlock_victim) {
|
|
|
|
trx->lock.was_chosen_as_deadlock_victim = FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-26 19:11:54 +01:00
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
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.
|
|
|
|
@return if no savepoint of the name found then DB_NO_SAVEPOINT,
|
|
|
|
otherwise DB_SUCCESS */
|
|
|
|
dberr_t
|
|
|
|
trx_rollback_to_savepoint_for_mysql(
|
|
|
|
/*================================*/
|
|
|
|
trx_t* trx, /*!< in: transaction handle */
|
|
|
|
const char* savepoint_name, /*!< in: savepoint name */
|
2016-08-12 11:17:45 +03:00
|
|
|
int64_t* mysql_binlog_cache_pos) /*!< out: the MySQL binlog cache
|
2014-02-26 19:11:54 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
/* We are reading trx->state without holding trx_sys->mutex
|
|
|
|
here, because the savepoint rollback should be invoked for a
|
|
|
|
running active MySQL transaction that is associated with the
|
|
|
|
current thread. */
|
|
|
|
ut_ad(trx->in_mysql_trx_list);
|
|
|
|
|
|
|
|
savep = trx_savepoint_find(trx, savepoint_name);
|
|
|
|
|
|
|
|
if (savep == NULL) {
|
|
|
|
return(DB_NO_SAVEPOINT);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (trx->state) {
|
|
|
|
case TRX_STATE_NOT_STARTED:
|
2016-08-12 11:17:45 +03:00
|
|
|
case TRX_STATE_FORCED_ROLLBACK:
|
|
|
|
|
|
|
|
ib::error() << "Transaction has a savepoint "
|
|
|
|
<< savep->name
|
|
|
|
<< " though it is not started";
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
return(DB_ERROR);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
case TRX_STATE_ACTIVE:
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
return(trx_rollback_to_savepoint_for_mysql_low(
|
|
|
|
trx, savep, mysql_binlog_cache_pos));
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
case TRX_STATE_PREPARED:
|
|
|
|
case TRX_STATE_COMMITTED_IN_MEMORY:
|
|
|
|
/* The savepoint rollback is only allowed on an ACTIVE
|
|
|
|
transaction, not a PREPARED or COMMITTED one. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_error;
|
|
|
|
return(DB_CORRUPTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
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.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return always DB_SUCCESS */
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
|
|
|
trx_savepoint_for_mysql(
|
|
|
|
/*====================*/
|
|
|
|
trx_t* trx, /*!< in: transaction handle */
|
|
|
|
const char* savepoint_name, /*!< in: savepoint name */
|
2016-08-12 11:17:45 +03:00
|
|
|
int64_t binlog_cache_pos) /*!< in: MySQL binlog cache
|
2014-02-26 19:11:54 +01:00
|
|
|
position corresponding to this
|
|
|
|
connection at the time of the
|
|
|
|
savepoint */
|
|
|
|
{
|
|
|
|
trx_named_savept_t* savep;
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_start_if_not_started_xa(trx, false);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
savep = trx_savepoint_find(trx, savepoint_name);
|
|
|
|
|
|
|
|
if (savep) {
|
|
|
|
/* There is a savepoint with the same name: free that */
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
UT_LIST_REMOVE(trx->trx_savepoints, savep);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_free(savep->name);
|
|
|
|
ut_free(savep);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a new savepoint and add it as the last in the list */
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
savep = static_cast<trx_named_savept_t*>(
|
|
|
|
ut_malloc_nokey(sizeof(*savep)));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
savep->name = mem_strdup(savepoint_name);
|
|
|
|
|
|
|
|
savep->savept = trx_savept_take(trx);
|
|
|
|
|
|
|
|
savep->mysql_binlog_cache_pos = binlog_cache_pos;
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
UT_LIST_ADD_LAST(trx->trx_savepoints, savep);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Releases only the named savepoint. Savepoints which were set after this
|
|
|
|
savepoint are left as is.
|
|
|
|
@return if no savepoint of the name found then DB_NO_SAVEPOINT,
|
|
|
|
otherwise DB_SUCCESS */
|
|
|
|
dberr_t
|
|
|
|
trx_release_savepoint_for_mysql(
|
|
|
|
/*============================*/
|
|
|
|
trx_t* trx, /*!< in: transaction handle */
|
|
|
|
const char* savepoint_name) /*!< in: savepoint name */
|
|
|
|
{
|
|
|
|
trx_named_savept_t* savep;
|
|
|
|
|
2016-12-02 16:25:47 +02:00
|
|
|
ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE, true)
|
|
|
|
|| trx_state_eq(trx, TRX_STATE_PREPARED, true));
|
2014-02-26 19:11:54 +01:00
|
|
|
ut_ad(trx->in_mysql_trx_list);
|
|
|
|
|
|
|
|
savep = trx_savepoint_find(trx, savepoint_name);
|
|
|
|
|
|
|
|
if (savep != NULL) {
|
|
|
|
trx_roll_savepoint_free(trx, savep);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(savep != NULL ? DB_SUCCESS : DB_NO_SAVEPOINT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Determines if this transaction is rolling back an incomplete transaction
|
|
|
|
in crash recovery.
|
|
|
|
@return TRUE if trx is an incomplete transaction that is being rolled
|
|
|
|
back in crash recovery */
|
|
|
|
ibool
|
|
|
|
trx_is_recv(
|
|
|
|
/*========*/
|
|
|
|
const trx_t* trx) /*!< in: transaction */
|
|
|
|
{
|
|
|
|
return(trx == trx_roll_crash_recv_trx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Returns a transaction savepoint taken at this point in time.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return savepoint */
|
2014-02-26 19:11:54 +01:00
|
|
|
trx_savept_t
|
|
|
|
trx_savept_take(
|
|
|
|
/*============*/
|
|
|
|
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;
|
2016-08-12 11:17:45 +03:00
|
|
|
int64_t rows_to_undo;
|
2014-02-26 19:11:54 +01:00
|
|
|
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;
|
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
thr = que_thr_create(fork, heap, NULL);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
roll_node = roll_node_create(heap);
|
|
|
|
|
|
|
|
thr->child = roll_node;
|
|
|
|
roll_node->common.parent = thr;
|
|
|
|
|
|
|
|
trx->graph = fork;
|
|
|
|
|
|
|
|
ut_a(thr == que_fork_start_command(fork));
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_sys_mutex_enter();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
trx_roll_crash_recv_trx = trx;
|
|
|
|
|
|
|
|
trx_roll_max_undo_no = trx->undo_no;
|
|
|
|
|
|
|
|
trx_roll_progress_printed_pct = 0;
|
|
|
|
|
|
|
|
rows_to_undo = trx_roll_max_undo_no;
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_sys_mutex_exit();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (rows_to_undo > 1000000000) {
|
|
|
|
rows_to_undo = rows_to_undo / 1000000;
|
|
|
|
unit = "M";
|
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
const trx_id_t trx_id = trx_get_id_for_print(trx);
|
|
|
|
|
|
|
|
ib::info() << "Rolling back trx with id " << trx_id << ", "
|
|
|
|
<< rows_to_undo << unit << " rows to undo";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (trx_get_dict_operation(trx) != TRX_DICT_OP_NONE) {
|
|
|
|
row_mysql_lock_data_dictionary(trx);
|
|
|
|
dictionary_locked = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
que_run_threads(thr);
|
|
|
|
ut_a(roll_node->undo_thr != NULL);
|
|
|
|
|
|
|
|
que_run_threads(roll_node->undo_thr);
|
|
|
|
|
|
|
|
trx_rollback_finish(thr_get_trx(roll_node->undo_thr));
|
|
|
|
|
|
|
|
/* Free the memory reserved by the undo graph */
|
|
|
|
que_graph_free(static_cast<que_t*>(
|
|
|
|
roll_node->undo_thr->common.parent));
|
|
|
|
|
|
|
|
ut_a(trx->lock.que_state == TRX_QUE_RUNNING);
|
|
|
|
|
|
|
|
if (trx_get_dict_operation(trx) != TRX_DICT_OP_NONE
|
|
|
|
&& trx->table_id != 0) {
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_ad(dictionary_locked);
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/* If the transaction was for a dictionary operation,
|
|
|
|
we drop the relevant table only if it is not flagged
|
|
|
|
as DISCARDED. If it still exists. */
|
|
|
|
|
|
|
|
table = dict_table_open_on_id(
|
2016-08-12 11:17:45 +03:00
|
|
|
trx->table_id, TRUE, DICT_TABLE_OP_NORMAL);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (table && !dict_table_is_discarded(table)) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::warn() << "Dropping table '" << table->name
|
|
|
|
<< "', with id " << trx->table_id
|
|
|
|
<< " in recovery";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
dict_table_close_and_drop(trx, table);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
trx_commit_for_mysql(trx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dictionary_locked) {
|
|
|
|
row_mysql_unlock_data_dictionary(trx);
|
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Rollback of trx with id " << trx_id << " completed";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
mem_heap_free(heap);
|
|
|
|
|
|
|
|
trx_roll_crash_recv_trx = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Rollback or clean up any resurrected incomplete transactions. It assumes
|
|
|
|
that the caller holds the trx_sys_t::mutex and it will release the
|
|
|
|
lock if it does a clean up or rollback.
|
|
|
|
@return TRUE if the transaction was cleaned up or rolled back
|
|
|
|
and trx_sys->mutex was released. */
|
|
|
|
static
|
|
|
|
ibool
|
|
|
|
trx_rollback_resurrected(
|
|
|
|
/*=====================*/
|
|
|
|
trx_t* trx, /*!< in: transaction to rollback or clean */
|
|
|
|
ibool all) /*!< in: FALSE=roll back dictionary transactions;
|
|
|
|
TRUE=roll back all non-PREPARED transactions */
|
|
|
|
{
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_ad(trx_sys_mutex_own());
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/* The trx->is_recovered flag and trx->state are set
|
|
|
|
atomically under the protection of the trx->mutex (and
|
|
|
|
lock_sys->mutex) in lock_trx_release_locks(). We do not want
|
|
|
|
to accidentally clean up a non-recovered transaction here. */
|
|
|
|
|
|
|
|
trx_mutex_enter(trx);
|
|
|
|
bool is_recovered = trx->is_recovered;
|
|
|
|
trx_state_t state = trx->state;
|
|
|
|
trx_mutex_exit(trx);
|
|
|
|
|
|
|
|
if (!is_recovered) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case TRX_STATE_COMMITTED_IN_MEMORY:
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_sys_mutex_exit();
|
|
|
|
ib::info() << "Cleaning up trx with id "
|
|
|
|
<< trx_get_id_for_print(trx);
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
trx_cleanup_at_db_startup(trx);
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_free_resurrected(trx);
|
2014-02-26 19:11:54 +01:00
|
|
|
return(TRUE);
|
|
|
|
case TRX_STATE_ACTIVE:
|
|
|
|
if (all || trx_get_dict_operation(trx) != TRX_DICT_OP_NONE) {
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_sys_mutex_exit();
|
2014-02-26 19:11:54 +01:00
|
|
|
trx_rollback_active(trx);
|
|
|
|
trx_free_for_background(trx);
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
return(FALSE);
|
|
|
|
case TRX_STATE_PREPARED:
|
|
|
|
return(FALSE);
|
|
|
|
case TRX_STATE_NOT_STARTED:
|
2016-08-12 11:17:45 +03:00
|
|
|
case TRX_STATE_FORCED_ROLLBACK:
|
2014-02-26 19:11:54 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_error;
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
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. */
|
|
|
|
void
|
|
|
|
trx_rollback_or_clean_recovered(
|
|
|
|
/*============================*/
|
|
|
|
ibool all) /*!< in: FALSE=roll back dictionary transactions;
|
|
|
|
TRUE=roll back all non-PREPARED transactions */
|
|
|
|
{
|
|
|
|
trx_t* trx;
|
|
|
|
|
|
|
|
ut_a(srv_force_recovery < SRV_FORCE_NO_TRX_UNDO);
|
|
|
|
|
|
|
|
if (trx_sys_get_n_rw_trx() == 0) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (all) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Starting in background the rollback"
|
MDEV-12091 Shutdown fails to wait for rollback of recovered transactions to finish
In the 10.1 InnoDB Plugin, a call os_event_free(buf_flush_event) was
misplaced. The event could be triggered by rollback of resurrected
transactions while shutdown was in progress. This bug was caught
by cmake -DWITH_ASAN testing. This call was only present in the
10.1 InnoDB Plugin, not in other versions, or in XtraDB.
That said, the bug affects all InnoDB versions. Shutdown assumes the
cessation of any page-dirtying activity, including the activity of
the background rollback thread. InnoDB only waited for the background
rollback to finish as part of a slow shutdown (innodb_fast_shutdown=0).
The default is a clean shutdown (innodb_fast_shutdown=1). In a scenario
where InnoDB is killed, restarted, and shut down soon enough, the data
files could become corrupted.
logs_empty_and_mark_files_at_shutdown(): Wait for the
rollback to finish, except if innodb_fast_shutdown=2
(crash-like shutdown) was requested.
trx_rollback_or_clean_recovered(): Before choosing the next
recovered transaction to roll back, terminate early if non-slow
shutdown was initiated. Roll back everything on slow shutdown
(innodb_fast_shutdown=0).
srv_innodb_monitor_mutex: Declare as static, because the mutex
is only used within one module.
In 10.2, os_event_destroy() sets the event to a NULL pointer,
while os_event_free() in earlier versions did not do that.
2017-03-10 16:01:02 +02:00
|
|
|
" of recovered transactions";
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: For XA recovered transactions, we rely on MySQL to
|
|
|
|
do rollback. They will be in TRX_STATE_PREPARED state. If the server
|
|
|
|
is shutdown and they are still lingering in trx_sys_t::trx_list
|
|
|
|
then the shutdown will hang. */
|
|
|
|
|
|
|
|
/* Loop over the transaction list as long as there are
|
|
|
|
recovered transactions to clean up or recover. */
|
|
|
|
|
|
|
|
do {
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_sys_mutex_enter();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
for (trx = UT_LIST_GET_FIRST(trx_sys->rw_trx_list);
|
|
|
|
trx != NULL;
|
|
|
|
trx = UT_LIST_GET_NEXT(trx_list, trx)) {
|
|
|
|
|
|
|
|
assert_trx_in_rw_list(trx);
|
|
|
|
|
MDEV-12091 Shutdown fails to wait for rollback of recovered transactions to finish
In the 10.1 InnoDB Plugin, a call os_event_free(buf_flush_event) was
misplaced. The event could be triggered by rollback of resurrected
transactions while shutdown was in progress. This bug was caught
by cmake -DWITH_ASAN testing. This call was only present in the
10.1 InnoDB Plugin, not in other versions, or in XtraDB.
That said, the bug affects all InnoDB versions. Shutdown assumes the
cessation of any page-dirtying activity, including the activity of
the background rollback thread. InnoDB only waited for the background
rollback to finish as part of a slow shutdown (innodb_fast_shutdown=0).
The default is a clean shutdown (innodb_fast_shutdown=1). In a scenario
where InnoDB is killed, restarted, and shut down soon enough, the data
files could become corrupted.
logs_empty_and_mark_files_at_shutdown(): Wait for the
rollback to finish, except if innodb_fast_shutdown=2
(crash-like shutdown) was requested.
trx_rollback_or_clean_recovered(): Before choosing the next
recovered transaction to roll back, terminate early if non-slow
shutdown was initiated. Roll back everything on slow shutdown
(innodb_fast_shutdown=0).
srv_innodb_monitor_mutex: Declare as static, because the mutex
is only used within one module.
In 10.2, os_event_destroy() sets the event to a NULL pointer,
while os_event_free() in earlier versions did not do that.
2017-03-10 16:01:02 +02:00
|
|
|
if (srv_shutdown_state != SRV_SHUTDOWN_NONE
|
|
|
|
&& srv_fast_shutdown != 0) {
|
|
|
|
all = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/* If this function does a cleanup or rollback
|
|
|
|
then it will release the trx_sys->mutex, therefore
|
|
|
|
we need to reacquire it before retrying the loop. */
|
|
|
|
|
|
|
|
if (trx_rollback_resurrected(trx, all)) {
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_sys_mutex_enter();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_sys_mutex_exit();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
} while (trx != NULL);
|
|
|
|
|
|
|
|
if (all) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Rollback of non-prepared transactions"
|
|
|
|
" completed";
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
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.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return a dummy parameter */
|
|
|
|
extern "C"
|
2014-02-26 19:11:54 +01:00
|
|
|
os_thread_ret_t
|
|
|
|
DECLARE_THREAD(trx_rollback_or_clean_all_recovered)(
|
|
|
|
/*================================================*/
|
2016-06-21 14:21:03 +02:00
|
|
|
void* arg MY_ATTRIBUTE((unused)))
|
2014-02-26 19:11:54 +01:00
|
|
|
/*!< in: a dummy parameter required by
|
|
|
|
os_thread_create */
|
|
|
|
{
|
|
|
|
ut_ad(!srv_read_only_mode);
|
|
|
|
|
|
|
|
#ifdef UNIV_PFS_THREAD
|
2016-09-11 10:57:05 +02:00
|
|
|
pfs_register_thread(trx_rollback_clean_thread_key);
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif /* UNIV_PFS_THREAD */
|
|
|
|
|
|
|
|
trx_rollback_or_clean_recovered(TRUE);
|
|
|
|
|
2015-02-18 16:20:46 +01:00
|
|
|
trx_rollback_or_clean_is_active = false;
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/* 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. */
|
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
os_thread_exit();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
OS_THREAD_DUMMY_RETURN;
|
|
|
|
}
|
|
|
|
|
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled
differently from persistent tables. Because temporary tables are
private to a connection, concurrency control and multi-versioning
(MVCC) are not applicable. For performance reasons, purge is
disabled as well. Rollback is supported for temporary tables;
that is why we have the temporary undo logs in the first place.
Because MVCC and purge are disabled for temporary tables, we should
discard all temporary undo logs already at transaction commit,
just like we discard the persistent insert_undo logs. Before this
change, update_undo logs were being preserved.
trx_temp_undo_t: A wrapper for temporary undo logs, comprising
a rollback segment and a single temporary undo log.
trx_rsegs_t::m_noredo: Use trx_temp_undo_t.
(Instead of insert_undo, update_undo, there will be a single undo.)
trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove.
trx_undo_add_page(): Remove the parameter undo_ptr.
Acquire and release the rollback segment mutex inside the function.
trx_undo_free_last_page(): Remove the parameter trx.
trx_undo_truncate_end(): Remove the parameter trx, and add the
parameter is_temp. Clean up the code a bit.
trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo.
trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup().
Replace the parameter undo_ptr with undo.
This will discard the temporary undo or insert_undo log at
commit/rollback.
trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup():
Remove 3 parameters. Always operate on the persistent update_undo.
trx_serialise(): Renamed from trx_serialisation_number_get().
trx_write_serialisation_history(): Simplify the code flow.
If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO.
trx_commit_in_memory(): Simplify the logic, and add assertions.
trx_undo_page_report_modify(): Keep a direct reference to the
persistent update_undo log.
trx_undo_report_row_operation(): Simplify some code.
Always assign TRX_UNDO_INSERT for temporary undo logs.
trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs.
trx_roll_try_truncate(): Remove the parameter undo_ptr.
Try to truncate all 3 undo logs of the transaction.
trx_roll_pop_top_rec_of_trx_low(): Remove.
trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter
trx->roll_limit. Clear roll_limit when exhausting the undo logs.
Consider all 3 undo logs at once, prioritizing the persistent
undo logs.
row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx()
reset the trx->roll_limit.
2017-03-09 23:20:51 +02:00
|
|
|
/** Try to truncate the undo logs.
|
|
|
|
@param[in,out] trx transaction */
|
2014-02-26 19:11:54 +01:00
|
|
|
static
|
|
|
|
void
|
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled
differently from persistent tables. Because temporary tables are
private to a connection, concurrency control and multi-versioning
(MVCC) are not applicable. For performance reasons, purge is
disabled as well. Rollback is supported for temporary tables;
that is why we have the temporary undo logs in the first place.
Because MVCC and purge are disabled for temporary tables, we should
discard all temporary undo logs already at transaction commit,
just like we discard the persistent insert_undo logs. Before this
change, update_undo logs were being preserved.
trx_temp_undo_t: A wrapper for temporary undo logs, comprising
a rollback segment and a single temporary undo log.
trx_rsegs_t::m_noredo: Use trx_temp_undo_t.
(Instead of insert_undo, update_undo, there will be a single undo.)
trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove.
trx_undo_add_page(): Remove the parameter undo_ptr.
Acquire and release the rollback segment mutex inside the function.
trx_undo_free_last_page(): Remove the parameter trx.
trx_undo_truncate_end(): Remove the parameter trx, and add the
parameter is_temp. Clean up the code a bit.
trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo.
trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup().
Replace the parameter undo_ptr with undo.
This will discard the temporary undo or insert_undo log at
commit/rollback.
trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup():
Remove 3 parameters. Always operate on the persistent update_undo.
trx_serialise(): Renamed from trx_serialisation_number_get().
trx_write_serialisation_history(): Simplify the code flow.
If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO.
trx_commit_in_memory(): Simplify the logic, and add assertions.
trx_undo_page_report_modify(): Keep a direct reference to the
persistent update_undo log.
trx_undo_report_row_operation(): Simplify some code.
Always assign TRX_UNDO_INSERT for temporary undo logs.
trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs.
trx_roll_try_truncate(): Remove the parameter undo_ptr.
Try to truncate all 3 undo logs of the transaction.
trx_roll_pop_top_rec_of_trx_low(): Remove.
trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter
trx->roll_limit. Clear roll_limit when exhausting the undo logs.
Consider all 3 undo logs at once, prioritizing the persistent
undo logs.
row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx()
reset the trx->roll_limit.
2017-03-09 23:20:51 +02:00
|
|
|
trx_roll_try_truncate(trx_t* trx)
|
2014-02-26 19:11:54 +01:00
|
|
|
{
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_ad(mutex_own(&trx->undo_mutex));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
trx->pages_undone = 0;
|
|
|
|
|
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled
differently from persistent tables. Because temporary tables are
private to a connection, concurrency control and multi-versioning
(MVCC) are not applicable. For performance reasons, purge is
disabled as well. Rollback is supported for temporary tables;
that is why we have the temporary undo logs in the first place.
Because MVCC and purge are disabled for temporary tables, we should
discard all temporary undo logs already at transaction commit,
just like we discard the persistent insert_undo logs. Before this
change, update_undo logs were being preserved.
trx_temp_undo_t: A wrapper for temporary undo logs, comprising
a rollback segment and a single temporary undo log.
trx_rsegs_t::m_noredo: Use trx_temp_undo_t.
(Instead of insert_undo, update_undo, there will be a single undo.)
trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove.
trx_undo_add_page(): Remove the parameter undo_ptr.
Acquire and release the rollback segment mutex inside the function.
trx_undo_free_last_page(): Remove the parameter trx.
trx_undo_truncate_end(): Remove the parameter trx, and add the
parameter is_temp. Clean up the code a bit.
trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo.
trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup().
Replace the parameter undo_ptr with undo.
This will discard the temporary undo or insert_undo log at
commit/rollback.
trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup():
Remove 3 parameters. Always operate on the persistent update_undo.
trx_serialise(): Renamed from trx_serialisation_number_get().
trx_write_serialisation_history(): Simplify the code flow.
If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO.
trx_commit_in_memory(): Simplify the logic, and add assertions.
trx_undo_page_report_modify(): Keep a direct reference to the
persistent update_undo log.
trx_undo_report_row_operation(): Simplify some code.
Always assign TRX_UNDO_INSERT for temporary undo logs.
trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs.
trx_roll_try_truncate(): Remove the parameter undo_ptr.
Try to truncate all 3 undo logs of the transaction.
trx_roll_pop_top_rec_of_trx_low(): Remove.
trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter
trx->roll_limit. Clear roll_limit when exhausting the undo logs.
Consider all 3 undo logs at once, prioritizing the persistent
undo logs.
row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx()
reset the trx->roll_limit.
2017-03-09 23:20:51 +02:00
|
|
|
undo_no_t undo_no = trx->undo_no;
|
|
|
|
trx_undo_t* insert_undo = trx->rsegs.m_redo.insert_undo;
|
|
|
|
trx_undo_t* update_undo = trx->rsegs.m_redo.update_undo;
|
|
|
|
|
|
|
|
if (insert_undo || update_undo) {
|
|
|
|
mutex_enter(&trx->rsegs.m_redo.rseg->mutex);
|
|
|
|
if (insert_undo) {
|
|
|
|
ut_ad(insert_undo->rseg == trx->rsegs.m_redo.rseg);
|
|
|
|
trx_undo_truncate_end(insert_undo, undo_no, false);
|
|
|
|
}
|
|
|
|
if (update_undo) {
|
|
|
|
ut_ad(update_undo->rseg == trx->rsegs.m_redo.rseg);
|
|
|
|
trx_undo_truncate_end(update_undo, undo_no, false);
|
|
|
|
}
|
|
|
|
mutex_exit(&trx->rsegs.m_redo.rseg->mutex);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled
differently from persistent tables. Because temporary tables are
private to a connection, concurrency control and multi-versioning
(MVCC) are not applicable. For performance reasons, purge is
disabled as well. Rollback is supported for temporary tables;
that is why we have the temporary undo logs in the first place.
Because MVCC and purge are disabled for temporary tables, we should
discard all temporary undo logs already at transaction commit,
just like we discard the persistent insert_undo logs. Before this
change, update_undo logs were being preserved.
trx_temp_undo_t: A wrapper for temporary undo logs, comprising
a rollback segment and a single temporary undo log.
trx_rsegs_t::m_noredo: Use trx_temp_undo_t.
(Instead of insert_undo, update_undo, there will be a single undo.)
trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove.
trx_undo_add_page(): Remove the parameter undo_ptr.
Acquire and release the rollback segment mutex inside the function.
trx_undo_free_last_page(): Remove the parameter trx.
trx_undo_truncate_end(): Remove the parameter trx, and add the
parameter is_temp. Clean up the code a bit.
trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo.
trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup().
Replace the parameter undo_ptr with undo.
This will discard the temporary undo or insert_undo log at
commit/rollback.
trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup():
Remove 3 parameters. Always operate on the persistent update_undo.
trx_serialise(): Renamed from trx_serialisation_number_get().
trx_write_serialisation_history(): Simplify the code flow.
If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO.
trx_commit_in_memory(): Simplify the logic, and add assertions.
trx_undo_page_report_modify(): Keep a direct reference to the
persistent update_undo log.
trx_undo_report_row_operation(): Simplify some code.
Always assign TRX_UNDO_INSERT for temporary undo logs.
trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs.
trx_roll_try_truncate(): Remove the parameter undo_ptr.
Try to truncate all 3 undo logs of the transaction.
trx_roll_pop_top_rec_of_trx_low(): Remove.
trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter
trx->roll_limit. Clear roll_limit when exhausting the undo logs.
Consider all 3 undo logs at once, prioritizing the persistent
undo logs.
row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx()
reset the trx->roll_limit.
2017-03-09 23:20:51 +02:00
|
|
|
if (trx_undo_t* undo = trx->rsegs.m_noredo.undo) {
|
|
|
|
ut_ad(undo->rseg == trx->rsegs.m_noredo.rseg);
|
|
|
|
mutex_enter(&undo->rseg->mutex);
|
|
|
|
trx_undo_truncate_end(undo, undo_no, true);
|
|
|
|
mutex_exit(&undo->rseg->mutex);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
#ifdef WITH_WSREP_OUT
|
|
|
|
if (wsrep_on(trx->mysql_thd)) {
|
|
|
|
trx->lock.was_chosen_as_deadlock_victim = FALSE;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
2016-08-12 11:17:45 +03:00
|
|
|
#endif /* WITH_WSREP */
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************//**
|
|
|
|
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.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return undo log record, the page s-latched */
|
2014-02-26 19:11:54 +01:00
|
|
|
static
|
|
|
|
trx_undo_rec_t*
|
|
|
|
trx_roll_pop_top_rec(
|
|
|
|
/*=================*/
|
|
|
|
trx_t* trx, /*!< in: transaction */
|
|
|
|
trx_undo_t* undo, /*!< in: undo log */
|
|
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
|
|
{
|
|
|
|
ut_ad(mutex_own(&trx->undo_mutex));
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
page_t* undo_page = trx_undo_page_get_s_latched(
|
2017-03-09 22:06:22 +02:00
|
|
|
page_id_t(undo->space, undo->top_page_no), mtr);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ulint offset = undo->top_offset;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_undo_rec_t* prev_rec = trx_undo_get_prev_rec(
|
2014-02-26 19:11:54 +01:00
|
|
|
undo_page + offset, undo->hdr_page_no, undo->hdr_offset,
|
|
|
|
true, mtr);
|
|
|
|
|
|
|
|
if (prev_rec == NULL) {
|
|
|
|
|
|
|
|
undo->empty = TRUE;
|
|
|
|
} else {
|
2016-08-12 11:17:45 +03:00
|
|
|
page_t* prev_rec_page = page_align(prev_rec);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled
differently from persistent tables. Because temporary tables are
private to a connection, concurrency control and multi-versioning
(MVCC) are not applicable. For performance reasons, purge is
disabled as well. Rollback is supported for temporary tables;
that is why we have the temporary undo logs in the first place.
Because MVCC and purge are disabled for temporary tables, we should
discard all temporary undo logs already at transaction commit,
just like we discard the persistent insert_undo logs. Before this
change, update_undo logs were being preserved.
trx_temp_undo_t: A wrapper for temporary undo logs, comprising
a rollback segment and a single temporary undo log.
trx_rsegs_t::m_noredo: Use trx_temp_undo_t.
(Instead of insert_undo, update_undo, there will be a single undo.)
trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove.
trx_undo_add_page(): Remove the parameter undo_ptr.
Acquire and release the rollback segment mutex inside the function.
trx_undo_free_last_page(): Remove the parameter trx.
trx_undo_truncate_end(): Remove the parameter trx, and add the
parameter is_temp. Clean up the code a bit.
trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo.
trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup().
Replace the parameter undo_ptr with undo.
This will discard the temporary undo or insert_undo log at
commit/rollback.
trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup():
Remove 3 parameters. Always operate on the persistent update_undo.
trx_serialise(): Renamed from trx_serialisation_number_get().
trx_write_serialisation_history(): Simplify the code flow.
If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO.
trx_commit_in_memory(): Simplify the logic, and add assertions.
trx_undo_page_report_modify(): Keep a direct reference to the
persistent update_undo log.
trx_undo_report_row_operation(): Simplify some code.
Always assign TRX_UNDO_INSERT for temporary undo logs.
trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs.
trx_roll_try_truncate(): Remove the parameter undo_ptr.
Try to truncate all 3 undo logs of the transaction.
trx_roll_pop_top_rec_of_trx_low(): Remove.
trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter
trx->roll_limit. Clear roll_limit when exhausting the undo logs.
Consider all 3 undo logs at once, prioritizing the persistent
undo logs.
row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx()
reset the trx->roll_limit.
2017-03-09 23:20:51 +02:00
|
|
|
/** Get the last undo log record of a transaction (for rollback).
|
|
|
|
@param[in,out] trx transaction
|
|
|
|
@param[out] roll_ptr DB_ROLL_PTR to the undo record
|
|
|
|
@param[in,out] heap memory heap for allocation
|
|
|
|
@return undo log record copied to heap
|
|
|
|
@retval NULL if none left or the roll_limit (savepoint) was reached */
|
2014-02-26 19:11:54 +01:00
|
|
|
trx_undo_rec_t*
|
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled
differently from persistent tables. Because temporary tables are
private to a connection, concurrency control and multi-versioning
(MVCC) are not applicable. For performance reasons, purge is
disabled as well. Rollback is supported for temporary tables;
that is why we have the temporary undo logs in the first place.
Because MVCC and purge are disabled for temporary tables, we should
discard all temporary undo logs already at transaction commit,
just like we discard the persistent insert_undo logs. Before this
change, update_undo logs were being preserved.
trx_temp_undo_t: A wrapper for temporary undo logs, comprising
a rollback segment and a single temporary undo log.
trx_rsegs_t::m_noredo: Use trx_temp_undo_t.
(Instead of insert_undo, update_undo, there will be a single undo.)
trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove.
trx_undo_add_page(): Remove the parameter undo_ptr.
Acquire and release the rollback segment mutex inside the function.
trx_undo_free_last_page(): Remove the parameter trx.
trx_undo_truncate_end(): Remove the parameter trx, and add the
parameter is_temp. Clean up the code a bit.
trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo.
trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup().
Replace the parameter undo_ptr with undo.
This will discard the temporary undo or insert_undo log at
commit/rollback.
trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup():
Remove 3 parameters. Always operate on the persistent update_undo.
trx_serialise(): Renamed from trx_serialisation_number_get().
trx_write_serialisation_history(): Simplify the code flow.
If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO.
trx_commit_in_memory(): Simplify the logic, and add assertions.
trx_undo_page_report_modify(): Keep a direct reference to the
persistent update_undo log.
trx_undo_report_row_operation(): Simplify some code.
Always assign TRX_UNDO_INSERT for temporary undo logs.
trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs.
trx_roll_try_truncate(): Remove the parameter undo_ptr.
Try to truncate all 3 undo logs of the transaction.
trx_roll_pop_top_rec_of_trx_low(): Remove.
trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter
trx->roll_limit. Clear roll_limit when exhausting the undo logs.
Consider all 3 undo logs at once, prioritizing the persistent
undo logs.
row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx()
reset the trx->roll_limit.
2017-03-09 23:20:51 +02:00
|
|
|
trx_roll_pop_top_rec_of_trx(trx_t* trx, roll_ptr_t* roll_ptr, mem_heap_t* heap)
|
2014-02-26 19:11:54 +01:00
|
|
|
{
|
2016-08-12 11:17:45 +03:00
|
|
|
mutex_enter(&trx->undo_mutex);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (trx->pages_undone >= TRX_ROLL_TRUNC_THRESHOLD) {
|
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled
differently from persistent tables. Because temporary tables are
private to a connection, concurrency control and multi-versioning
(MVCC) are not applicable. For performance reasons, purge is
disabled as well. Rollback is supported for temporary tables;
that is why we have the temporary undo logs in the first place.
Because MVCC and purge are disabled for temporary tables, we should
discard all temporary undo logs already at transaction commit,
just like we discard the persistent insert_undo logs. Before this
change, update_undo logs were being preserved.
trx_temp_undo_t: A wrapper for temporary undo logs, comprising
a rollback segment and a single temporary undo log.
trx_rsegs_t::m_noredo: Use trx_temp_undo_t.
(Instead of insert_undo, update_undo, there will be a single undo.)
trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove.
trx_undo_add_page(): Remove the parameter undo_ptr.
Acquire and release the rollback segment mutex inside the function.
trx_undo_free_last_page(): Remove the parameter trx.
trx_undo_truncate_end(): Remove the parameter trx, and add the
parameter is_temp. Clean up the code a bit.
trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo.
trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup().
Replace the parameter undo_ptr with undo.
This will discard the temporary undo or insert_undo log at
commit/rollback.
trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup():
Remove 3 parameters. Always operate on the persistent update_undo.
trx_serialise(): Renamed from trx_serialisation_number_get().
trx_write_serialisation_history(): Simplify the code flow.
If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO.
trx_commit_in_memory(): Simplify the logic, and add assertions.
trx_undo_page_report_modify(): Keep a direct reference to the
persistent update_undo log.
trx_undo_report_row_operation(): Simplify some code.
Always assign TRX_UNDO_INSERT for temporary undo logs.
trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs.
trx_roll_try_truncate(): Remove the parameter undo_ptr.
Try to truncate all 3 undo logs of the transaction.
trx_roll_pop_top_rec_of_trx_low(): Remove.
trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter
trx->roll_limit. Clear roll_limit when exhausting the undo logs.
Consider all 3 undo logs at once, prioritizing the persistent
undo logs.
row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx()
reset the trx->roll_limit.
2017-03-09 23:20:51 +02:00
|
|
|
trx_roll_try_truncate(trx);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled
differently from persistent tables. Because temporary tables are
private to a connection, concurrency control and multi-versioning
(MVCC) are not applicable. For performance reasons, purge is
disabled as well. Rollback is supported for temporary tables;
that is why we have the temporary undo logs in the first place.
Because MVCC and purge are disabled for temporary tables, we should
discard all temporary undo logs already at transaction commit,
just like we discard the persistent insert_undo logs. Before this
change, update_undo logs were being preserved.
trx_temp_undo_t: A wrapper for temporary undo logs, comprising
a rollback segment and a single temporary undo log.
trx_rsegs_t::m_noredo: Use trx_temp_undo_t.
(Instead of insert_undo, update_undo, there will be a single undo.)
trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove.
trx_undo_add_page(): Remove the parameter undo_ptr.
Acquire and release the rollback segment mutex inside the function.
trx_undo_free_last_page(): Remove the parameter trx.
trx_undo_truncate_end(): Remove the parameter trx, and add the
parameter is_temp. Clean up the code a bit.
trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo.
trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup().
Replace the parameter undo_ptr with undo.
This will discard the temporary undo or insert_undo log at
commit/rollback.
trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup():
Remove 3 parameters. Always operate on the persistent update_undo.
trx_serialise(): Renamed from trx_serialisation_number_get().
trx_write_serialisation_history(): Simplify the code flow.
If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO.
trx_commit_in_memory(): Simplify the logic, and add assertions.
trx_undo_page_report_modify(): Keep a direct reference to the
persistent update_undo log.
trx_undo_report_row_operation(): Simplify some code.
Always assign TRX_UNDO_INSERT for temporary undo logs.
trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs.
trx_roll_try_truncate(): Remove the parameter undo_ptr.
Try to truncate all 3 undo logs of the transaction.
trx_roll_pop_top_rec_of_trx_low(): Remove.
trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter
trx->roll_limit. Clear roll_limit when exhausting the undo logs.
Consider all 3 undo logs at once, prioritizing the persistent
undo logs.
row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx()
reset the trx->roll_limit.
2017-03-09 23:20:51 +02:00
|
|
|
trx_undo_t* undo;
|
|
|
|
trx_undo_t* insert = trx->rsegs.m_redo.insert_undo;
|
|
|
|
trx_undo_t* update = trx->rsegs.m_redo.update_undo;
|
|
|
|
trx_undo_t* temp = trx->rsegs.m_noredo.undo;
|
|
|
|
const undo_no_t limit = trx->roll_limit;
|
|
|
|
|
|
|
|
ut_ad(!insert || !update || !insert->top_undo_no
|
|
|
|
|| insert->top_undo_no != update->top_undo_no);
|
|
|
|
ut_ad(!insert || !temp || !insert->top_undo_no
|
|
|
|
|| insert->top_undo_no != temp->top_undo_no);
|
|
|
|
ut_ad(!update || !temp || !update->top_undo_no
|
|
|
|
|| update->top_undo_no != temp->top_undo_no);
|
|
|
|
|
|
|
|
if (insert && !insert->empty && limit <= insert->top_undo_no) {
|
|
|
|
if (update && !update->empty
|
|
|
|
&& update->top_undo_no > insert->top_undo_no) {
|
|
|
|
undo = update;
|
|
|
|
} else {
|
|
|
|
undo = insert;
|
|
|
|
}
|
|
|
|
} else if (update && !update->empty && limit <= update->top_undo_no) {
|
|
|
|
undo = update;
|
|
|
|
} else if (temp && !temp->empty && limit <= temp->top_undo_no) {
|
|
|
|
undo = temp;
|
2014-02-26 19:11:54 +01:00
|
|
|
} else {
|
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled
differently from persistent tables. Because temporary tables are
private to a connection, concurrency control and multi-versioning
(MVCC) are not applicable. For performance reasons, purge is
disabled as well. Rollback is supported for temporary tables;
that is why we have the temporary undo logs in the first place.
Because MVCC and purge are disabled for temporary tables, we should
discard all temporary undo logs already at transaction commit,
just like we discard the persistent insert_undo logs. Before this
change, update_undo logs were being preserved.
trx_temp_undo_t: A wrapper for temporary undo logs, comprising
a rollback segment and a single temporary undo log.
trx_rsegs_t::m_noredo: Use trx_temp_undo_t.
(Instead of insert_undo, update_undo, there will be a single undo.)
trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove.
trx_undo_add_page(): Remove the parameter undo_ptr.
Acquire and release the rollback segment mutex inside the function.
trx_undo_free_last_page(): Remove the parameter trx.
trx_undo_truncate_end(): Remove the parameter trx, and add the
parameter is_temp. Clean up the code a bit.
trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo.
trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup().
Replace the parameter undo_ptr with undo.
This will discard the temporary undo or insert_undo log at
commit/rollback.
trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup():
Remove 3 parameters. Always operate on the persistent update_undo.
trx_serialise(): Renamed from trx_serialisation_number_get().
trx_write_serialisation_history(): Simplify the code flow.
If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO.
trx_commit_in_memory(): Simplify the logic, and add assertions.
trx_undo_page_report_modify(): Keep a direct reference to the
persistent update_undo log.
trx_undo_report_row_operation(): Simplify some code.
Always assign TRX_UNDO_INSERT for temporary undo logs.
trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs.
trx_roll_try_truncate(): Remove the parameter undo_ptr.
Try to truncate all 3 undo logs of the transaction.
trx_roll_pop_top_rec_of_trx_low(): Remove.
trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter
trx->roll_limit. Clear roll_limit when exhausting the undo logs.
Consider all 3 undo logs at once, prioritizing the persistent
undo logs.
row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx()
reset the trx->roll_limit.
2017-03-09 23:20:51 +02:00
|
|
|
trx_roll_try_truncate(trx);
|
|
|
|
/* Mark any ROLLBACK TO SAVEPOINT completed, so that
|
|
|
|
if the transaction object is committed and reused
|
|
|
|
later, we will default to a full ROLLBACK. */
|
|
|
|
trx->roll_limit = 0;
|
|
|
|
ut_d(trx->in_rollback = false);
|
2016-08-12 11:17:45 +03:00
|
|
|
mutex_exit(&trx->undo_mutex);
|
2014-02-26 19:11:54 +01:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled
differently from persistent tables. Because temporary tables are
private to a connection, concurrency control and multi-versioning
(MVCC) are not applicable. For performance reasons, purge is
disabled as well. Rollback is supported for temporary tables;
that is why we have the temporary undo logs in the first place.
Because MVCC and purge are disabled for temporary tables, we should
discard all temporary undo logs already at transaction commit,
just like we discard the persistent insert_undo logs. Before this
change, update_undo logs were being preserved.
trx_temp_undo_t: A wrapper for temporary undo logs, comprising
a rollback segment and a single temporary undo log.
trx_rsegs_t::m_noredo: Use trx_temp_undo_t.
(Instead of insert_undo, update_undo, there will be a single undo.)
trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove.
trx_undo_add_page(): Remove the parameter undo_ptr.
Acquire and release the rollback segment mutex inside the function.
trx_undo_free_last_page(): Remove the parameter trx.
trx_undo_truncate_end(): Remove the parameter trx, and add the
parameter is_temp. Clean up the code a bit.
trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo.
trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup().
Replace the parameter undo_ptr with undo.
This will discard the temporary undo or insert_undo log at
commit/rollback.
trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup():
Remove 3 parameters. Always operate on the persistent update_undo.
trx_serialise(): Renamed from trx_serialisation_number_get().
trx_write_serialisation_history(): Simplify the code flow.
If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO.
trx_commit_in_memory(): Simplify the logic, and add assertions.
trx_undo_page_report_modify(): Keep a direct reference to the
persistent update_undo log.
trx_undo_report_row_operation(): Simplify some code.
Always assign TRX_UNDO_INSERT for temporary undo logs.
trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs.
trx_roll_try_truncate(): Remove the parameter undo_ptr.
Try to truncate all 3 undo logs of the transaction.
trx_roll_pop_top_rec_of_trx_low(): Remove.
trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter
trx->roll_limit. Clear roll_limit when exhausting the undo logs.
Consider all 3 undo logs at once, prioritizing the persistent
undo logs.
row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx()
reset the trx->roll_limit.
2017-03-09 23:20:51 +02:00
|
|
|
ut_ad(!undo->empty);
|
|
|
|
ut_ad(limit <= undo->top_undo_no);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
*roll_ptr = trx_undo_build_roll_ptr(
|
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled
differently from persistent tables. Because temporary tables are
private to a connection, concurrency control and multi-versioning
(MVCC) are not applicable. For performance reasons, purge is
disabled as well. Rollback is supported for temporary tables;
that is why we have the temporary undo logs in the first place.
Because MVCC and purge are disabled for temporary tables, we should
discard all temporary undo logs already at transaction commit,
just like we discard the persistent insert_undo logs. Before this
change, update_undo logs were being preserved.
trx_temp_undo_t: A wrapper for temporary undo logs, comprising
a rollback segment and a single temporary undo log.
trx_rsegs_t::m_noredo: Use trx_temp_undo_t.
(Instead of insert_undo, update_undo, there will be a single undo.)
trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove.
trx_undo_add_page(): Remove the parameter undo_ptr.
Acquire and release the rollback segment mutex inside the function.
trx_undo_free_last_page(): Remove the parameter trx.
trx_undo_truncate_end(): Remove the parameter trx, and add the
parameter is_temp. Clean up the code a bit.
trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo.
trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup().
Replace the parameter undo_ptr with undo.
This will discard the temporary undo or insert_undo log at
commit/rollback.
trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup():
Remove 3 parameters. Always operate on the persistent update_undo.
trx_serialise(): Renamed from trx_serialisation_number_get().
trx_write_serialisation_history(): Simplify the code flow.
If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO.
trx_commit_in_memory(): Simplify the logic, and add assertions.
trx_undo_page_report_modify(): Keep a direct reference to the
persistent update_undo log.
trx_undo_report_row_operation(): Simplify some code.
Always assign TRX_UNDO_INSERT for temporary undo logs.
trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs.
trx_roll_try_truncate(): Remove the parameter undo_ptr.
Try to truncate all 3 undo logs of the transaction.
trx_roll_pop_top_rec_of_trx_low(): Remove.
trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter
trx->roll_limit. Clear roll_limit when exhausting the undo logs.
Consider all 3 undo logs at once, prioritizing the persistent
undo logs.
row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx()
reset the trx->roll_limit.
2017-03-09 23:20:51 +02:00
|
|
|
false, undo->rseg->id, undo->top_page_no, undo->top_offset);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled
differently from persistent tables. Because temporary tables are
private to a connection, concurrency control and multi-versioning
(MVCC) are not applicable. For performance reasons, purge is
disabled as well. Rollback is supported for temporary tables;
that is why we have the temporary undo logs in the first place.
Because MVCC and purge are disabled for temporary tables, we should
discard all temporary undo logs already at transaction commit,
just like we discard the persistent insert_undo logs. Before this
change, update_undo logs were being preserved.
trx_temp_undo_t: A wrapper for temporary undo logs, comprising
a rollback segment and a single temporary undo log.
trx_rsegs_t::m_noredo: Use trx_temp_undo_t.
(Instead of insert_undo, update_undo, there will be a single undo.)
trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove.
trx_undo_add_page(): Remove the parameter undo_ptr.
Acquire and release the rollback segment mutex inside the function.
trx_undo_free_last_page(): Remove the parameter trx.
trx_undo_truncate_end(): Remove the parameter trx, and add the
parameter is_temp. Clean up the code a bit.
trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo.
trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup().
Replace the parameter undo_ptr with undo.
This will discard the temporary undo or insert_undo log at
commit/rollback.
trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup():
Remove 3 parameters. Always operate on the persistent update_undo.
trx_serialise(): Renamed from trx_serialisation_number_get().
trx_write_serialisation_history(): Simplify the code flow.
If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO.
trx_commit_in_memory(): Simplify the logic, and add assertions.
trx_undo_page_report_modify(): Keep a direct reference to the
persistent update_undo log.
trx_undo_report_row_operation(): Simplify some code.
Always assign TRX_UNDO_INSERT for temporary undo logs.
trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs.
trx_roll_try_truncate(): Remove the parameter undo_ptr.
Try to truncate all 3 undo logs of the transaction.
trx_roll_pop_top_rec_of_trx_low(): Remove.
trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter
trx->roll_limit. Clear roll_limit when exhausting the undo logs.
Consider all 3 undo logs at once, prioritizing the persistent
undo logs.
row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx()
reset the trx->roll_limit.
2017-03-09 23:20:51 +02:00
|
|
|
mtr_t mtr;
|
|
|
|
mtr.start();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled
differently from persistent tables. Because temporary tables are
private to a connection, concurrency control and multi-versioning
(MVCC) are not applicable. For performance reasons, purge is
disabled as well. Rollback is supported for temporary tables;
that is why we have the temporary undo logs in the first place.
Because MVCC and purge are disabled for temporary tables, we should
discard all temporary undo logs already at transaction commit,
just like we discard the persistent insert_undo logs. Before this
change, update_undo logs were being preserved.
trx_temp_undo_t: A wrapper for temporary undo logs, comprising
a rollback segment and a single temporary undo log.
trx_rsegs_t::m_noredo: Use trx_temp_undo_t.
(Instead of insert_undo, update_undo, there will be a single undo.)
trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove.
trx_undo_add_page(): Remove the parameter undo_ptr.
Acquire and release the rollback segment mutex inside the function.
trx_undo_free_last_page(): Remove the parameter trx.
trx_undo_truncate_end(): Remove the parameter trx, and add the
parameter is_temp. Clean up the code a bit.
trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo.
trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup().
Replace the parameter undo_ptr with undo.
This will discard the temporary undo or insert_undo log at
commit/rollback.
trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup():
Remove 3 parameters. Always operate on the persistent update_undo.
trx_serialise(): Renamed from trx_serialisation_number_get().
trx_write_serialisation_history(): Simplify the code flow.
If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO.
trx_commit_in_memory(): Simplify the logic, and add assertions.
trx_undo_page_report_modify(): Keep a direct reference to the
persistent update_undo log.
trx_undo_report_row_operation(): Simplify some code.
Always assign TRX_UNDO_INSERT for temporary undo logs.
trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs.
trx_roll_try_truncate(): Remove the parameter undo_ptr.
Try to truncate all 3 undo logs of the transaction.
trx_roll_pop_top_rec_of_trx_low(): Remove.
trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter
trx->roll_limit. Clear roll_limit when exhausting the undo logs.
Consider all 3 undo logs at once, prioritizing the persistent
undo logs.
row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx()
reset the trx->roll_limit.
2017-03-09 23:20:51 +02:00
|
|
|
trx_undo_rec_t* undo_rec = trx_roll_pop_top_rec(trx, undo, &mtr);
|
|
|
|
const undo_no_t undo_no = trx_undo_rec_get_undo_no(undo_rec);
|
|
|
|
if (trx_undo_rec_get_type(undo_rec) == TRX_UNDO_INSERT_REC) {
|
|
|
|
ut_ad(undo == insert || undo == temp);
|
|
|
|
*roll_ptr |= 1ULL << ROLL_PTR_INSERT_FLAG_POS;
|
|
|
|
} else {
|
|
|
|
ut_ad(undo == update || undo == temp);
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_ad(trx_roll_check_undo_rec_ordering(
|
|
|
|
undo_no, undo->rseg->space, trx));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/* 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) {
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ulint progress_pct = 100 - (ulint)
|
2014-02-26 19:11:54 +01:00
|
|
|
((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;
|
2016-08-12 11:17:45 +03:00
|
|
|
trx->undo_rseg_space = undo->rseg->space;
|
|
|
|
mutex_exit(&trx->undo_mutex);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled
differently from persistent tables. Because temporary tables are
private to a connection, concurrency control and multi-versioning
(MVCC) are not applicable. For performance reasons, purge is
disabled as well. Rollback is supported for temporary tables;
that is why we have the temporary undo logs in the first place.
Because MVCC and purge are disabled for temporary tables, we should
discard all temporary undo logs already at transaction commit,
just like we discard the persistent insert_undo logs. Before this
change, update_undo logs were being preserved.
trx_temp_undo_t: A wrapper for temporary undo logs, comprising
a rollback segment and a single temporary undo log.
trx_rsegs_t::m_noredo: Use trx_temp_undo_t.
(Instead of insert_undo, update_undo, there will be a single undo.)
trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove.
trx_undo_add_page(): Remove the parameter undo_ptr.
Acquire and release the rollback segment mutex inside the function.
trx_undo_free_last_page(): Remove the parameter trx.
trx_undo_truncate_end(): Remove the parameter trx, and add the
parameter is_temp. Clean up the code a bit.
trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo.
trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup().
Replace the parameter undo_ptr with undo.
This will discard the temporary undo or insert_undo log at
commit/rollback.
trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup():
Remove 3 parameters. Always operate on the persistent update_undo.
trx_serialise(): Renamed from trx_serialisation_number_get().
trx_write_serialisation_history(): Simplify the code flow.
If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO.
trx_commit_in_memory(): Simplify the logic, and add assertions.
trx_undo_page_report_modify(): Keep a direct reference to the
persistent update_undo log.
trx_undo_report_row_operation(): Simplify some code.
Always assign TRX_UNDO_INSERT for temporary undo logs.
trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs.
trx_roll_try_truncate(): Remove the parameter undo_ptr.
Try to truncate all 3 undo logs of the transaction.
trx_roll_pop_top_rec_of_trx_low(): Remove.
trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter
trx->roll_limit. Clear roll_limit when exhausting the undo logs.
Consider all 3 undo logs at once, prioritizing the persistent
undo logs.
row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx()
reset the trx->roll_limit.
2017-03-09 23:20:51 +02:00
|
|
|
trx_undo_rec_t* undo_rec_copy = trx_undo_rec_copy(undo_rec, heap);
|
|
|
|
mtr.commit();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
return(undo_rec_copy);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************//**
|
|
|
|
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.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return own: the query graph */
|
2014-02-26 19:11:54 +01:00
|
|
|
static
|
|
|
|
que_t*
|
|
|
|
trx_roll_graph_build(
|
|
|
|
/*=================*/
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_t* trx) /*!< in/out: transaction */
|
2014-02-26 19:11:54 +01:00
|
|
|
{
|
|
|
|
mem_heap_t* heap;
|
|
|
|
que_fork_t* fork;
|
|
|
|
que_thr_t* thr;
|
|
|
|
|
|
|
|
ut_ad(trx_mutex_own(trx));
|
|
|
|
|
|
|
|
heap = mem_heap_create(512);
|
|
|
|
fork = que_fork_create(NULL, NULL, QUE_FORK_ROLLBACK, heap);
|
|
|
|
fork->trx = trx;
|
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
thr = que_thr_create(fork, heap, NULL);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
thr->child = row_undo_node_create(trx, thr, heap);
|
|
|
|
|
|
|
|
return(fork);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************//**
|
|
|
|
Starts a rollback operation, creates the UNDO graph that will do the
|
|
|
|
actual undo operation.
|
|
|
|
@return query graph thread that will perform the UNDO operations. */
|
|
|
|
static
|
|
|
|
que_thr_t*
|
|
|
|
trx_rollback_start(
|
|
|
|
/*===============*/
|
|
|
|
trx_t* trx, /*!< in: transaction */
|
|
|
|
ib_id_t roll_limit) /*!< in: rollback to undo no (for
|
|
|
|
partial undo), 0 if we are rolling back
|
|
|
|
the entire transaction */
|
|
|
|
{
|
|
|
|
ut_ad(trx_mutex_own(trx));
|
|
|
|
|
|
|
|
/* Initialize the rollback field in the transaction */
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_ad(!trx->roll_limit);
|
|
|
|
ut_ad(!trx->in_rollback);
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
trx->roll_limit = roll_limit;
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_d(trx->in_rollback = true);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
ut_a(trx->roll_limit <= trx->undo_no);
|
|
|
|
|
|
|
|
trx->pages_undone = 0;
|
|
|
|
|
|
|
|
/* Build a 'query' graph which will perform the undo operations */
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
que_t* roll_graph = trx_roll_graph_build(trx);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
trx->graph = roll_graph;
|
|
|
|
|
|
|
|
trx->lock.que_state = TRX_QUE_ROLLING_BACK;
|
|
|
|
|
|
|
|
return(que_fork_start_command(roll_graph));
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************//**
|
|
|
|
Finishes a transaction rollback. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
trx_rollback_finish(
|
|
|
|
/*================*/
|
|
|
|
trx_t* trx) /*!< in: transaction */
|
|
|
|
{
|
|
|
|
trx_commit(trx);
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
trx->mod_tables.clear();
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
trx->lock.que_state = TRX_QUE_RUNNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************//**
|
|
|
|
Creates a rollback command node struct.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return own: rollback node struct */
|
2014-02-26 19:11:54 +01:00
|
|
|
roll_node_t*
|
|
|
|
roll_node_create(
|
|
|
|
/*=============*/
|
|
|
|
mem_heap_t* heap) /*!< in: mem heap where created */
|
|
|
|
{
|
|
|
|
roll_node_t* node;
|
|
|
|
|
|
|
|
node = static_cast<roll_node_t*>(mem_heap_zalloc(heap, sizeof(*node)));
|
|
|
|
|
|
|
|
node->state = ROLL_NODE_SEND;
|
|
|
|
|
|
|
|
node->common.type = QUE_NODE_ROLLBACK;
|
|
|
|
|
|
|
|
return(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************//**
|
|
|
|
Performs an execution step for a rollback command node in a query graph.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return query thread to run next, or NULL */
|
2014-02-26 19:11:54 +01:00
|
|
|
que_thr_t*
|
|
|
|
trx_rollback_step(
|
|
|
|
/*==============*/
|
|
|
|
que_thr_t* thr) /*!< in: query thread */
|
|
|
|
{
|
|
|
|
roll_node_t* node;
|
|
|
|
|
|
|
|
node = static_cast<roll_node_t*>(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) {
|
|
|
|
trx_t* trx;
|
2016-08-12 11:17:45 +03:00
|
|
|
ib_id_t roll_limit;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
trx = thr_get_trx(thr);
|
|
|
|
|
|
|
|
trx_mutex_enter(trx);
|
|
|
|
|
|
|
|
node->state = ROLL_NODE_WAIT;
|
|
|
|
|
|
|
|
ut_a(node->undo_thr == NULL);
|
|
|
|
|
|
|
|
roll_limit = node->partial ? node->savept.least_undo_no : 0;
|
|
|
|
|
|
|
|
trx_commit_or_rollback_prepare(trx);
|
|
|
|
|
|
|
|
node->undo_thr = trx_rollback_start(trx, roll_limit);
|
|
|
|
|
|
|
|
trx_mutex_exit(trx);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ut_ad(node->state == ROLL_NODE_WAIT);
|
|
|
|
|
|
|
|
thr->run_node = que_node_get_parent(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(thr);
|
|
|
|
}
|