2014-02-26 19:11:54 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
|
2016-06-21 14:21:03 +02:00
|
|
|
Copyright (c) 1997, 2016, Oracle and/or its affiliates. All Rights Reserved.
|
2019-04-25 09:04:09 +03:00
|
|
|
Copyright (c) 2017, 2019, 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.,
|
2019-05-11 19:25:02 +03:00
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************//**
|
|
|
|
@file row/row0undo.cc
|
|
|
|
Row undo
|
|
|
|
|
|
|
|
Created 1/8/1997 Heikki Tuuri
|
|
|
|
*******************************************************/
|
|
|
|
|
|
|
|
#include "row0undo.h"
|
|
|
|
#include "fsp0fsp.h"
|
|
|
|
#include "mach0data.h"
|
|
|
|
#include "trx0rseg.h"
|
|
|
|
#include "trx0trx.h"
|
|
|
|
#include "trx0roll.h"
|
|
|
|
#include "trx0undo.h"
|
|
|
|
#include "trx0purge.h"
|
|
|
|
#include "trx0rec.h"
|
|
|
|
#include "que0que.h"
|
|
|
|
#include "row0row.h"
|
|
|
|
#include "row0uins.h"
|
|
|
|
#include "row0umod.h"
|
|
|
|
#include "row0upd.h"
|
|
|
|
#include "row0mysql.h"
|
|
|
|
#include "srv0srv.h"
|
|
|
|
|
|
|
|
/* How to undo row operations?
|
|
|
|
(1) For an insert, we have stored a prefix of the clustered index record
|
|
|
|
in the undo log. Using it, we look for the clustered record, and using
|
|
|
|
that we look for the records in the secondary indexes. The insert operation
|
|
|
|
may have been left incomplete, if the database crashed, for example.
|
|
|
|
We may have look at the trx id and roll ptr to make sure the record in the
|
|
|
|
clustered index is really the one for which the undo log record was
|
|
|
|
written. We can use the framework we get from the original insert op.
|
|
|
|
(2) Delete marking: We can use the framework we get from the original
|
|
|
|
delete mark op. We only have to check the trx id.
|
|
|
|
(3) Update: This may be the most complicated. We have to use the framework
|
|
|
|
we get from the original update op.
|
|
|
|
|
|
|
|
What if the same trx repeatedly deletes and inserts an identical row.
|
|
|
|
Then the row id changes and also roll ptr. What if the row id was not
|
|
|
|
part of the ordering fields in the clustered index? Maybe we have to write
|
|
|
|
it to undo log. Well, maybe not, because if we order the row id and trx id
|
|
|
|
in descending order, then the only undeleted copy is the first in the
|
|
|
|
index. Our searches in row operations always position the cursor before
|
|
|
|
the first record in the result set. But, if there is no key defined for
|
|
|
|
a table, then it would be desirable that row id is in ascending order.
|
|
|
|
So, lets store row id in descending order only if it is not an ordering
|
|
|
|
field in the clustered index.
|
|
|
|
|
|
|
|
NOTE: Deletes and inserts may lead to situation where there are identical
|
|
|
|
records in a secondary index. Is that a problem in the B-tree? Yes.
|
|
|
|
Also updates can lead to this, unless trx id and roll ptr are included in
|
|
|
|
ord fields.
|
|
|
|
(1) Fix in clustered indexes: include row id, trx id, and roll ptr
|
|
|
|
in node pointers of B-tree.
|
|
|
|
(2) Fix in secondary indexes: include all fields in node pointers, and
|
|
|
|
if an entry is inserted, check if it is equal to the right neighbor,
|
|
|
|
in which case update the right neighbor: the neighbor must be delete
|
|
|
|
marked, set it unmarked and write the trx id of the current transaction.
|
|
|
|
|
|
|
|
What if the same trx repeatedly updates the same row, updating a secondary
|
|
|
|
index field or not? Updating a clustered index ordering field?
|
|
|
|
|
|
|
|
(1) If it does not update the secondary index and not the clustered index
|
|
|
|
ord field. Then the secondary index record stays unchanged, but the
|
|
|
|
trx id in the secondary index record may be smaller than in the clustered
|
|
|
|
index record. This is no problem?
|
|
|
|
(2) If it updates secondary index ord field but not clustered: then in
|
|
|
|
secondary index there are delete marked records, which differ in an
|
|
|
|
ord field. No problem.
|
|
|
|
(3) Updates clustered ord field but not secondary, and secondary index
|
|
|
|
is unique. Then the record in secondary index is just updated at the
|
|
|
|
clustered ord field.
|
|
|
|
(4)
|
|
|
|
|
|
|
|
Problem with duplicate records:
|
|
|
|
Fix 1: Add a trx op no field to all indexes. A problem: if a trx with a
|
|
|
|
bigger trx id has inserted and delete marked a similar row, our trx inserts
|
|
|
|
again a similar row, and a trx with an even bigger id delete marks it. Then
|
|
|
|
the position of the row should change in the index if the trx id affects
|
|
|
|
the alphabetical ordering.
|
|
|
|
|
|
|
|
Fix 2: If an insert encounters a similar row marked deleted, we turn the
|
|
|
|
insert into an 'update' of the row marked deleted. Then we must write undo
|
|
|
|
info on the update. A problem: what if a purge operation tries to remove
|
|
|
|
the delete marked row?
|
|
|
|
|
|
|
|
We can think of the database row versions as a linked list which starts
|
|
|
|
from the record in the clustered index, and is linked by roll ptrs
|
|
|
|
through undo logs. The secondary index records are references which tell
|
|
|
|
what kinds of records can be found in this linked list for a record
|
|
|
|
in the clustered index.
|
|
|
|
|
|
|
|
How to do the purge? A record can be removed from the clustered index
|
|
|
|
if its linked list becomes empty, i.e., the row has been marked deleted
|
|
|
|
and its roll ptr points to the record in the undo log we are going through,
|
|
|
|
doing the purge. Similarly, during a rollback, a record can be removed
|
|
|
|
if the stored roll ptr in the undo log points to a trx already (being) purged,
|
|
|
|
or if the roll ptr is NULL, i.e., it was a fresh insert. */
|
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Creates a row undo node to a query graph.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return own: undo node */
|
2014-02-26 19:11:54 +01:00
|
|
|
undo_node_t*
|
|
|
|
row_undo_node_create(
|
|
|
|
/*=================*/
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_t* trx, /*!< in/out: transaction */
|
2014-02-26 19:11:54 +01:00
|
|
|
que_thr_t* parent, /*!< in: parent node, i.e., a thr node */
|
|
|
|
mem_heap_t* heap) /*!< in: memory heap where created */
|
|
|
|
{
|
|
|
|
undo_node_t* undo;
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE)
|
2019-04-25 09:04:09 +03:00
|
|
|
|| trx_state_eq(trx, TRX_STATE_PREPARED_RECOVERED)
|
2016-08-12 11:17:45 +03:00
|
|
|
|| trx_state_eq(trx, TRX_STATE_PREPARED));
|
|
|
|
ut_ad(parent);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
undo = static_cast<undo_node_t*>(
|
|
|
|
mem_heap_alloc(heap, sizeof(undo_node_t)));
|
|
|
|
|
|
|
|
undo->common.type = QUE_NODE_UNDO;
|
|
|
|
undo->common.parent = parent;
|
|
|
|
|
|
|
|
undo->state = UNDO_NODE_FETCH_NEXT;
|
|
|
|
undo->trx = trx;
|
|
|
|
|
|
|
|
btr_pcur_init(&(undo->pcur));
|
|
|
|
|
|
|
|
undo->heap = mem_heap_create(256);
|
|
|
|
|
|
|
|
return(undo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************//**
|
|
|
|
Looks for the clustered index record when node has the row reference.
|
|
|
|
The pcur in node is used in the search. If found, stores the row to node,
|
|
|
|
and stores the position of pcur, and detaches it. The pcur must be closed
|
|
|
|
by the caller in any case.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return true if found; NOTE the node->pcur must be closed by the
|
2014-02-26 19:11:54 +01:00
|
|
|
caller, regardless of the return value */
|
2016-08-12 11:17:45 +03:00
|
|
|
bool
|
2014-02-26 19:11:54 +01:00
|
|
|
row_undo_search_clust_to_pcur(
|
|
|
|
/*==========================*/
|
2016-08-12 11:17:45 +03:00
|
|
|
undo_node_t* node) /*!< in/out: row undo node */
|
2014-02-26 19:11:54 +01:00
|
|
|
{
|
|
|
|
dict_index_t* clust_index;
|
2016-08-12 11:17:45 +03:00
|
|
|
bool found;
|
2014-02-26 19:11:54 +01:00
|
|
|
mtr_t mtr;
|
2016-08-12 11:17:45 +03:00
|
|
|
row_ext_t** ext;
|
|
|
|
const rec_t* rec;
|
2014-02-26 19:11:54 +01:00
|
|
|
mem_heap_t* heap = NULL;
|
|
|
|
ulint offsets_[REC_OFFS_NORMAL_SIZE];
|
|
|
|
ulint* offsets = offsets_;
|
|
|
|
rec_offs_init(offsets_);
|
|
|
|
|
MDEV-11415 Remove excessive undo logging during ALTER TABLE…ALGORITHM=COPY
If a crash occurs during ALTER TABLE…ALGORITHM=COPY, InnoDB would spend
a lot of time rolling back writes to the intermediate copy of the table.
To reduce the amount of busy work done, a work-around was introduced in
commit fd069e2bb36a3c1c1f26d65dd298b07e6d83ac8b in MySQL 4.1.8 and 5.0.2,
to commit the transaction after every 10,000 inserted rows.
A proper fix would have been to disable the undo logging altogether and
to simply drop the intermediate copy of the table on subsequent server
startup. This is what happens in MariaDB 10.3 with MDEV-14717,MDEV-14585.
In MariaDB 10.2, the intermediate copy of the table would be left behind
with a name starting with the string #sql.
This is a backport of a bug fix from MySQL 8.0.0 to MariaDB,
contributed by jixianliang <271365745@qq.com>.
Unlike recent MySQL, MariaDB supports ALTER IGNORE. For that operation
InnoDB must for now keep the undo logging enabled, so that the latest
row can be rolled back in case of an error.
In Galera cluster, the LOAD DATA statement will retain the existing
behaviour and commit the transaction after every 10,000 rows if
the parameter wsrep_load_data_splitting=ON is set. The logic to do
so (the wsrep_load_data_split() function and the call
handler::extra(HA_EXTRA_FAKE_START_STMT)) are joint work
by Ji Xianliang and Marko Mäkelä.
The original fix:
Author: Thirunarayanan Balathandayuthapani <thirunarayanan.balathandayuth@oracle.com>
Date: Wed Dec 2 16:09:15 2015 +0530
Bug#17479594 AVOID INTERMEDIATE COMMIT WHILE DOING ALTER TABLE ALGORITHM=COPY
Problem:
During ALTER TABLE, we commit and restart the transaction for every
10,000 rows, so that the rollback after recovery would not take so long.
Fix:
Suppress the undo logging during copy alter operation. If fts_index is
present then insert directly into fts auxiliary table rather
than doing at commit time.
ha_innobase::num_write_row: Remove the variable.
ha_innobase::write_row(): Remove the hack for committing every 10000 rows.
row_lock_table_for_mysql(): Remove the extra 2 parameters.
lock_get_src_table(), lock_is_table_exclusive(): Remove.
Reviewed-by: Marko Mäkelä <marko.makela@oracle.com>
Reviewed-by: Shaohua Wang <shaohua.wang@oracle.com>
Reviewed-by: Jon Olav Hauglid <jon.hauglid@oracle.com>
2018-01-26 21:45:25 +02:00
|
|
|
ut_ad(!node->table->skip_alter_undo);
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
mtr_start(&mtr);
|
|
|
|
|
|
|
|
clust_index = dict_table_get_first_index(node->table);
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
found = row_search_on_row_ref(&node->pcur, BTR_MODIFY_LEAF,
|
2014-02-26 19:11:54 +01:00
|
|
|
node->table, node->ref, &mtr);
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (!found) {
|
|
|
|
goto func_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
rec = btr_pcur_get_rec(&node->pcur);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-09-19 19:20:11 +03:00
|
|
|
offsets = rec_get_offsets(rec, clust_index, offsets, true,
|
2014-02-26 19:11:54 +01:00
|
|
|
ULINT_UNDEFINED, &heap);
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
found = row_get_rec_roll_ptr(rec, clust_index, offsets)
|
|
|
|
== node->roll_ptr;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (found) {
|
|
|
|
ut_ad(row_get_rec_trx_id(rec, clust_index, offsets)
|
|
|
|
== node->trx->id);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (dict_table_get_format(node->table) >= UNIV_FORMAT_B) {
|
|
|
|
/* In DYNAMIC or COMPRESSED format, there is
|
|
|
|
no prefix of externally stored columns in the
|
|
|
|
clustered index record. Build a cache of
|
|
|
|
column prefixes. */
|
|
|
|
ext = &node->ext;
|
|
|
|
} else {
|
|
|
|
/* REDUNDANT and COMPACT formats store a local
|
|
|
|
768-byte prefix of each externally stored
|
|
|
|
column. No cache is needed. */
|
|
|
|
ext = NULL;
|
|
|
|
node->ext = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
node->row = row_build(ROW_COPY_DATA, clust_index, rec,
|
|
|
|
offsets, NULL,
|
|
|
|
NULL, NULL, ext, node->heap);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/* We will need to parse out virtual column info from undo
|
|
|
|
log, first mark them DATA_MISSING. So we will know if the
|
|
|
|
value gets updated */
|
|
|
|
if (node->table->n_v_cols
|
|
|
|
&& node->state != UNDO_NODE_INSERT
|
|
|
|
&& !(node->cmpl_info & UPD_NODE_NO_ORD_CHANGE)) {
|
|
|
|
for (ulint i = 0;
|
|
|
|
i < dict_table_get_n_v_cols(node->table); i++) {
|
|
|
|
dfield_get_type(dtuple_get_nth_v_field(
|
|
|
|
node->row, i))->mtype = DATA_MISSING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
if (node->rec_type == TRX_UNDO_UPD_EXIST_REC) {
|
|
|
|
node->undo_row = dtuple_copy(node->row, node->heap);
|
|
|
|
row_upd_replace(node->undo_row, &node->undo_ext,
|
|
|
|
clust_index, node->update, node->heap);
|
|
|
|
} else {
|
|
|
|
node->undo_row = NULL;
|
|
|
|
node->undo_ext = NULL;
|
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
btr_pcur_store_position(&node->pcur, &mtr);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (heap) {
|
2014-02-26 19:11:54 +01:00
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
func_exit:
|
|
|
|
btr_pcur_commit_specify_mtr(&node->pcur, &mtr);
|
|
|
|
return(found);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************//**
|
|
|
|
Fetches an undo log record and does the undo for the recorded operation.
|
|
|
|
If none left, or a partial rollback completed, returns control to the
|
|
|
|
parent node, which is always a query thread node.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return DB_SUCCESS if operation successfully completed, else error code */
|
2016-09-06 09:43:16 +03:00
|
|
|
static MY_ATTRIBUTE((warn_unused_result))
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
|
|
|
row_undo(
|
|
|
|
/*=====*/
|
|
|
|
undo_node_t* node, /*!< in: row undo node */
|
|
|
|
que_thr_t* thr) /*!< in: query thread */
|
|
|
|
{
|
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_t* trx = node->trx;
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_ad(trx->in_rollback);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (node->state == UNDO_NODE_FETCH_NEXT) {
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
node->undo_rec = trx_roll_pop_top_rec_of_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
|
|
|
trx, &node->roll_ptr, node->heap);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
if (!node->undo_rec) {
|
|
|
|
/* Rollback completed for this query thread */
|
|
|
|
thr->run_node = que_node_get_parent(node);
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
node->undo_no = trx_undo_rec_get_undo_no(node->undo_rec);
|
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
|
|
|
node->state = trx_undo_roll_ptr_is_insert(node->roll_ptr)
|
|
|
|
? UNDO_NODE_INSERT : UNDO_NODE_MODIFY;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Prevent DROP TABLE etc. while we are rolling back this row.
|
|
|
|
If we are doing a TABLE CREATE or some other dictionary operation,
|
|
|
|
then we already have dict_operation_lock locked in x-mode. Do not
|
|
|
|
try to lock again, because that would cause a hang. */
|
|
|
|
|
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
|
|
|
const bool locked_data_dict = (trx->dict_operation_lock_mode == 0);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (locked_data_dict) {
|
|
|
|
|
|
|
|
row_mysql_freeze_data_dictionary(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
|
|
|
dberr_t err;
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
if (node->state == UNDO_NODE_INSERT) {
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
err = row_undo_ins(node, thr);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
node->state = UNDO_NODE_FETCH_NEXT;
|
|
|
|
} else {
|
|
|
|
ut_ad(node->state == UNDO_NODE_MODIFY);
|
|
|
|
err = row_undo_mod(node, thr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (locked_data_dict) {
|
|
|
|
|
|
|
|
row_mysql_unfreeze_data_dictionary(trx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do some cleanup */
|
|
|
|
btr_pcur_close(&(node->pcur));
|
|
|
|
|
|
|
|
mem_heap_empty(node->heap);
|
|
|
|
|
|
|
|
thr->run_node = node;
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************//**
|
|
|
|
Undoes a row operation in a table. This is a high-level function used
|
|
|
|
in SQL execution graphs.
|
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*
|
|
|
|
row_undo_step(
|
|
|
|
/*==========*/
|
|
|
|
que_thr_t* thr) /*!< in: query thread */
|
|
|
|
{
|
|
|
|
dberr_t err;
|
|
|
|
undo_node_t* node;
|
|
|
|
trx_t* trx;
|
|
|
|
|
|
|
|
ut_ad(thr);
|
|
|
|
|
|
|
|
srv_inc_activity_count();
|
|
|
|
|
|
|
|
trx = thr_get_trx(thr);
|
|
|
|
|
|
|
|
node = static_cast<undo_node_t*>(thr->run_node);
|
|
|
|
|
|
|
|
ut_ad(que_node_get_type(node) == QUE_NODE_UNDO);
|
|
|
|
|
2017-12-13 18:02:09 +02:00
|
|
|
if (UNIV_UNLIKELY(trx == trx_roll_crash_recv_trx)
|
2017-12-13 18:56:22 +02:00
|
|
|
&& trx_roll_must_shutdown()) {
|
2017-12-13 18:02:09 +02:00
|
|
|
/* Shutdown has been initiated. */
|
|
|
|
trx->error_state = DB_INTERRUPTED;
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
err = row_undo(node, thr);
|
|
|
|
|
|
|
|
trx->error_state = err;
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
/* SQL error detected */
|
|
|
|
|
|
|
|
if (err == DB_OUT_OF_FILE_SPACE) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::fatal() << "Out of tablespace during rollback."
|
|
|
|
" Consider increasing your tablespace.";
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::fatal() << "Error (" << ut_strerr(err) << ") in rollback.";
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return(thr);
|
|
|
|
}
|