mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 21:12:26 +01:00
13e5c9de80
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.
227 lines
8.6 KiB
C
227 lines
8.6 KiB
C
/*****************************************************************************
|
|
|
|
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
|
|
Copyright (c) 2015, 2017, MariaDB Corporation.
|
|
|
|
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 include/trx0roll.h
|
|
Transaction rollback
|
|
|
|
Created 3/26/1996 Heikki Tuuri
|
|
*******************************************************/
|
|
|
|
#ifndef trx0roll_h
|
|
#define trx0roll_h
|
|
|
|
#include "univ.i"
|
|
#include "trx0trx.h"
|
|
#include "trx0types.h"
|
|
#include "mtr0mtr.h"
|
|
#include "trx0sys.h"
|
|
|
|
extern bool trx_rollback_or_clean_is_active;
|
|
|
|
/*******************************************************************//**
|
|
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 */
|
|
/*******************************************************************//**
|
|
Returns a transaction savepoint taken at this point in time.
|
|
@return savepoint */
|
|
trx_savept_t
|
|
trx_savept_take(
|
|
/*============*/
|
|
trx_t* trx); /*!< in: transaction */
|
|
|
|
/** 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 */
|
|
trx_undo_rec_t*
|
|
trx_roll_pop_top_rec_of_trx(trx_t* trx, roll_ptr_t* roll_ptr, mem_heap_t* heap)
|
|
MY_ATTRIBUTE((nonnull, warn_unused_result));
|
|
|
|
/*******************************************************************//**
|
|
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 */
|
|
/*******************************************************************//**
|
|
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.
|
|
@return a dummy parameter */
|
|
extern "C"
|
|
os_thread_ret_t
|
|
DECLARE_THREAD(trx_rollback_or_clean_all_recovered)(
|
|
/*================================================*/
|
|
void* arg MY_ATTRIBUTE((unused)));
|
|
/*!< in: a dummy parameter required by
|
|
os_thread_create */
|
|
/*********************************************************************//**
|
|
Creates a rollback command node struct.
|
|
@return own: rollback node struct */
|
|
roll_node_t*
|
|
roll_node_create(
|
|
/*=============*/
|
|
mem_heap_t* heap); /*!< in: mem heap where created */
|
|
/***********************************************************//**
|
|
Performs an execution step for a rollback command node in a query graph.
|
|
@return query thread to run next, or NULL */
|
|
que_thr_t*
|
|
trx_rollback_step(
|
|
/*==============*/
|
|
que_thr_t* thr); /*!< in: query thread */
|
|
/*******************************************************************//**
|
|
Rollback a transaction used in MySQL.
|
|
@return error code or DB_SUCCESS */
|
|
dberr_t
|
|
trx_rollback_for_mysql(
|
|
/*===================*/
|
|
trx_t* trx) /*!< in/out: transaction */
|
|
MY_ATTRIBUTE((nonnull));
|
|
/*******************************************************************//**
|
|
Rollback the latest SQL statement for MySQL.
|
|
@return error code or DB_SUCCESS */
|
|
dberr_t
|
|
trx_rollback_last_sql_stat_for_mysql(
|
|
/*=================================*/
|
|
trx_t* trx) /*!< in/out: transaction */
|
|
MY_ATTRIBUTE((nonnull));
|
|
/*******************************************************************//**
|
|
Rollback a transaction to a given savepoint or do a complete rollback.
|
|
@return error code or DB_SUCCESS */
|
|
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 */
|
|
MY_ATTRIBUTE((nonnull(1)));
|
|
/*******************************************************************//**
|
|
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 */
|
|
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 */
|
|
MY_ATTRIBUTE((nonnull, warn_unused_result));
|
|
/*******************************************************************//**
|
|
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.
|
|
@return always DB_SUCCESS */
|
|
dberr_t
|
|
trx_savepoint_for_mysql(
|
|
/*====================*/
|
|
trx_t* trx, /*!< in: transaction handle */
|
|
const char* savepoint_name, /*!< in: savepoint name */
|
|
int64_t binlog_cache_pos) /*!< in: MySQL binlog cache
|
|
position corresponding to this
|
|
connection at the time of the
|
|
savepoint */
|
|
MY_ATTRIBUTE((nonnull));
|
|
/*******************************************************************//**
|
|
Releases a named savepoint. 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_release_savepoint_for_mysql(
|
|
/*============================*/
|
|
trx_t* trx, /*!< in: transaction handle */
|
|
const char* savepoint_name) /*!< in: savepoint name */
|
|
MY_ATTRIBUTE((nonnull, warn_unused_result));
|
|
/*******************************************************************//**
|
|
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 > this one;
|
|
if this is NULL, free all savepoints
|
|
of trx */
|
|
/** Rollback node states */
|
|
enum roll_node_state {
|
|
ROLL_NODE_NONE = 0, /*!< Unknown state */
|
|
ROLL_NODE_SEND, /*!< about to send a rollback signal to
|
|
the transaction */
|
|
ROLL_NODE_WAIT /*!< rollback signal sent to the
|
|
transaction, waiting for completion */
|
|
};
|
|
|
|
/** Rollback command node in a query graph */
|
|
struct roll_node_t{
|
|
que_common_t common; /*!< node type: QUE_NODE_ROLLBACK */
|
|
enum roll_node_state state; /*!< node execution state */
|
|
bool partial;/*!< TRUE if we want a partial
|
|
rollback */
|
|
trx_savept_t savept; /*!< savepoint to which to
|
|
roll back, in the case of a
|
|
partial rollback */
|
|
que_thr_t* undo_thr;/*!< undo query graph */
|
|
};
|
|
|
|
/** A savepoint set with SQL's "SAVEPOINT savepoint_id" command */
|
|
struct trx_named_savept_t{
|
|
char* name; /*!< savepoint name */
|
|
trx_savept_t savept; /*!< the undo number corresponding to
|
|
the savepoint */
|
|
int64_t mysql_binlog_cache_pos;
|
|
/*!< the MySQL binlog cache position
|
|
corresponding to this savepoint, not
|
|
defined if the MySQL binlogging is not
|
|
enabled */
|
|
UT_LIST_NODE_T(trx_named_savept_t)
|
|
trx_savepoints; /*!< the list of savepoints of a
|
|
transaction */
|
|
};
|
|
|
|
#ifndef UNIV_NONINL
|
|
#include "trx0roll.ic"
|
|
#endif
|
|
|
|
#endif
|