summaryrefslogtreecommitdiff
path: root/storage/innobase
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-04-29 16:00:17 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2020-04-29 16:00:17 +0300
commit3e6722d88d686a5e14266abdc8b85577124bb309 (patch)
tree1f235f32765433b32a95dc40d9c33821a220c9e9 /storage/innobase
parent496d0372ef2ff2a570c20923af4df32a03781acd (diff)
downloadmariadb-git-3e6722d88d686a5e14266abdc8b85577124bb309.tar.gz
Cleanup: More trx_t member functions
trx_t::rollback(): Renamed from trx_rollback_to_savepoint(). trx_t::rollback_low(): Renamed from trx_rollback_to_savepoint_low(). fts_sql_commit(): Defined as an alias of trx_commit_for_mysql(). fts_sql_rollback(): Defined as an alias of trx_t::rollback(). fts_rename_aux_tables_to_hex_format(): Fix the error handling that likely never worked because we failed to roll back the first transaction.
Diffstat (limited to 'storage/innobase')
-rw-r--r--storage/innobase/dict/dict0stats.cc2
-rw-r--r--storage/innobase/fts/fts0fts.cc16
-rw-r--r--storage/innobase/fts/fts0sql.cc31
-rw-r--r--storage/innobase/handler/handler0alter.cc2
-rw-r--r--storage/innobase/include/fts0priv.h20
-rw-r--r--storage/innobase/include/trx0roll.h13
-rw-r--r--storage/innobase/include/trx0trx.h7
-rw-r--r--storage/innobase/row/row0mysql.cc18
-rw-r--r--storage/innobase/trx/trx0roll.cc153
9 files changed, 94 insertions, 168 deletions
diff --git a/storage/innobase/dict/dict0stats.cc b/storage/innobase/dict/dict0stats.cc
index 61810a88889..f1fbd54296d 100644
--- a/storage/innobase/dict/dict0stats.cc
+++ b/storage/innobase/dict/dict0stats.cc
@@ -319,7 +319,7 @@ dict_stats_exec_sql(
} else {
trx->op_info = "rollback of internal trx on stats tables";
trx->dict_operation_lock_mode = RW_X_LATCH;
- trx_rollback_to_savepoint(trx, NULL);
+ trx->rollback();
trx->dict_operation_lock_mode = 0;
trx->op_info = "";
ut_a(trx->error_state == DB_SUCCESS);
diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc
index 1a9a75eaa76..f43fb7511bc 100644
--- a/storage/innobase/fts/fts0fts.cc
+++ b/storage/innobase/fts/fts0fts.cc
@@ -6384,6 +6384,7 @@ fts_rename_aux_tables_to_hex_format(
trx_rename->dict_operation_lock_mode = 0;
if (err != DB_SUCCESS) {
+ fts_sql_rollback(trx_rename);
ib::warn() << "Rollback operations on all aux tables of "
"table "<< parent_table->name << ". All the fts index "
@@ -6391,18 +6392,13 @@ fts_rename_aux_tables_to_hex_format(
"Please rebuild the index again.";
/* Corrupting the fts index related to parent table. */
- trx_t* trx_corrupt;
- trx_corrupt = trx_create();
- trx_corrupt->dict_operation_lock_mode = RW_X_LATCH;
- trx_start_for_ddl(trx_corrupt, TRX_DICT_OP_TABLE);
- fts_parent_all_index_set_corrupt(trx_corrupt, parent_table);
- trx_corrupt->dict_operation_lock_mode = 0;
- fts_sql_commit(trx_corrupt);
- trx_free(trx_corrupt);
- } else {
- fts_sql_commit(trx_rename);
+ trx_rename->dict_operation_lock_mode = RW_X_LATCH;
+ trx_start_for_ddl(trx_rename, TRX_DICT_OP_TABLE);
+ fts_parent_all_index_set_corrupt(trx_rename, parent_table);
+ trx_rename->dict_operation_lock_mode = 0;
}
+ fts_sql_commit(trx_rename);
trx_free(trx_rename);
ib_vector_reset(aux_tables);
}
diff --git a/storage/innobase/fts/fts0sql.cc b/storage/innobase/fts/fts0sql.cc
index 6873df102bf..94269ef001c 100644
--- a/storage/innobase/fts/fts0sql.cc
+++ b/storage/innobase/fts/fts0sql.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 2007, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2019, MariaDB Corporation.
+Copyright (c) 2019, 2020, 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
@@ -261,32 +261,3 @@ fts_get_select_columns_str(
return(str);
}
-
-/******************************************************************//**
-Commit a transaction.
-@return DB_SUCCESS or error code */
-dberr_t
-fts_sql_commit(
-/*===========*/
- trx_t* trx) /*!< in: transaction */
-{
- dberr_t error;
-
- error = trx_commit_for_mysql(trx);
-
- /* Commit should always succeed */
- ut_a(error == DB_SUCCESS);
-
- return(DB_SUCCESS);
-}
-
-/******************************************************************//**
-Rollback a transaction.
-@return DB_SUCCESS or error code */
-dberr_t
-fts_sql_rollback(
-/*=============*/
- trx_t* trx) /*!< in: transaction */
-{
- return(trx_rollback_to_savepoint(trx, NULL));
-}
diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc
index 932ec414231..ef2f1279880 100644
--- a/storage/innobase/handler/handler0alter.cc
+++ b/storage/innobase/handler/handler0alter.cc
@@ -6250,7 +6250,7 @@ prepare_inplace_alter_table_dict(
user_table, ctx->drop_fk, ctx->num_to_drop_fk)) {
new_clustered_failed:
DBUG_ASSERT(ctx->trx != ctx->prebuilt->trx);
- trx_rollback_to_savepoint(ctx->trx, NULL);
+ ctx->trx->rollback();
ut_ad(user_table->get_ref_count() == 1);
diff --git a/storage/innobase/include/fts0priv.h b/storage/innobase/include/fts0priv.h
index 018e801409b..6d8617da0c9 100644
--- a/storage/innobase/include/fts0priv.h
+++ b/storage/innobase/include/fts0priv.h
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 2011, 2018, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2017, 2019, MariaDB Corporation.
+Copyright (c) 2017, 2020, 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
@@ -292,22 +292,8 @@ fts_trx_table_id_cmp(
const void* p1, /*!< in: id1 */
const void* p2) /*!< in: id2 */
MY_ATTRIBUTE((nonnull, warn_unused_result));
-/******************************************************************//**
-Commit a transaction.
-@return DB_SUCCESS if all OK */
-dberr_t
-fts_sql_commit(
-/*===========*/
- trx_t* trx) /*!< in: transaction */
- MY_ATTRIBUTE((nonnull));
-/******************************************************************//**
-Rollback a transaction.
-@return DB_SUCCESS if all OK */
-dberr_t
-fts_sql_rollback(
-/*=============*/
- trx_t* trx) /*!< in: transaction */
- MY_ATTRIBUTE((nonnull));
+#define fts_sql_commit(trx) trx_commit_for_mysql(trx)
+#define fts_sql_rollback(trx) (trx)->rollback()
/******************************************************************//**
Parse an SQL string. %s is replaced with the table's id. Don't acquire
the dict mutex
diff --git a/storage/innobase/include/trx0roll.h b/storage/innobase/include/trx0roll.h
index 7f27a054866..89b8bdead53 100644
--- a/storage/innobase/include/trx0roll.h
+++ b/storage/innobase/include/trx0roll.h
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2015, 2019, MariaDB Corporation.
+Copyright (c) 2015, 2020, 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
@@ -103,17 +103,6 @@ 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
diff --git a/storage/innobase/include/trx0trx.h b/storage/innobase/include/trx0trx.h
index af96bb16434..7a2b2213af0 100644
--- a/storage/innobase/include/trx0trx.h
+++ b/storage/innobase/include/trx0trx.h
@@ -1101,6 +1101,13 @@ public:
@param[in] table_id table identifier */
void evict_table(table_id_t table_id);
+ /** Initiate rollback.
+ @param savept savepoint to which to roll back
+ @return error code or DB_SUCCESS */
+ dberr_t rollback(trx_savept_t *savept= nullptr);
+ /** Roll back an active transaction.
+ @param savept savepoint to which to roll back */
+ inline void rollback_low(trx_savept_t *savept= nullptr);
/** Finish rollback.
@return whether the rollback was completed normally
@retval false if the rollback was aborted by shutdown */
diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc
index 22e63f44827..07080b63a08 100644
--- a/storage/innobase/row/row0mysql.cc
+++ b/storage/innobase/row/row0mysql.cc
@@ -731,7 +731,7 @@ handle_new_error:
/* Roll back the latest, possibly incomplete insertion
or update */
- trx_rollback_to_savepoint(trx, savept);
+ trx->rollback(savept);
}
/* MySQL will roll back the latest SQL statement */
break;
@@ -754,7 +754,7 @@ handle_new_error:
/* Roll back the whole transaction; this resolution was added
to version 3.23.43 */
- trx_rollback_to_savepoint(trx, NULL);
+ trx->rollback();
break;
case DB_MUST_GET_MORE_FILE_SPACE:
@@ -2425,7 +2425,7 @@ err_exit:
break;
case DB_OUT_OF_FILE_SPACE:
trx->error_state = DB_SUCCESS;
- trx_rollback_to_savepoint(trx, NULL);
+ trx->rollback();
ib::warn() << "Cannot create table "
<< table->name
@@ -2456,7 +2456,7 @@ err_exit:
case DB_TABLESPACE_EXISTS:
default:
trx->error_state = DB_SUCCESS;
- trx_rollback_to_savepoint(trx, NULL);
+ trx->rollback();
dict_mem_table_free(table);
break;
}
@@ -3793,7 +3793,7 @@ do_drop:
<< ut_get_name(trx, tablename) << ".";
trx->error_state = DB_SUCCESS;
- trx_rollback_to_savepoint(trx, NULL);
+ trx->rollback();
trx->error_state = DB_SUCCESS;
/* Mark all indexes available in the data dictionary
@@ -4525,7 +4525,7 @@ end:
" succeed.";
}
trx->error_state = DB_SUCCESS;
- trx_rollback_to_savepoint(trx, NULL);
+ trx->rollback();
trx->error_state = DB_SUCCESS;
} else {
/* The following call will also rename the .ibd data file if
@@ -4535,7 +4535,7 @@ end:
table, new_name, !new_is_tmp);
if (err != DB_SUCCESS) {
trx->error_state = DB_SUCCESS;
- trx_rollback_to_savepoint(trx, NULL);
+ trx->rollback();
trx->error_state = DB_SUCCESS;
goto funct_exit;
}
@@ -4577,7 +4577,7 @@ end:
}
trx->error_state = DB_SUCCESS;
- trx_rollback_to_savepoint(trx, NULL);
+ trx->rollback();
trx->error_state = DB_SUCCESS;
}
@@ -4589,7 +4589,7 @@ end:
ut_a(DB_SUCCESS == dict_table_rename_in_cache(
table, old_name, FALSE));
trx->error_state = DB_SUCCESS;
- trx_rollback_to_savepoint(trx, NULL);
+ trx->rollback();
trx->error_state = DB_SUCCESS;
goto funct_exit;
}
diff --git a/storage/innobase/trx/trx0roll.cc b/storage/innobase/trx/trx0roll.cc
index 346b208700f..adf41906cb7 100644
--- a/storage/innobase/trx/trx0roll.cc
+++ b/storage/innobase/trx/trx0roll.cc
@@ -90,107 +90,85 @@ inline bool trx_t::rollback_finish()
undo= nullptr;
}
commit_low();
- lock.que_state = TRX_QUE_RUNNING;
+ lock.que_state= TRX_QUE_RUNNING;
return false;
}
-/*******************************************************************//**
-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 */
+/** Roll back an active transaction. */
+inline void trx_t::rollback_low(trx_savept_t *savept)
{
- 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->savept = savept;
- check_trx_state(trx);
- } else {
- assert_trx_nonlocking_or_in_list(trx);
- }
-
- trx->error_state = DB_SUCCESS;
-
- if (trx->has_logged_or_recovered()) {
+ mem_heap_t *heap= mem_heap_create(512);
+ roll_node_t *roll_node= roll_node_create(heap);
+ roll_node->savept= savept;
- ut_ad(trx->rsegs.m_redo.rseg != 0
- || trx->rsegs.m_noredo.rseg != 0);
+ if (savept)
+ check_trx_state(this);
+ else
+ assert_trx_nonlocking_or_in_list(this);
- thr = pars_complete_graph_for_exec(roll_node, trx, heap, NULL);
+ error_state = DB_SUCCESS;
- 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 (has_logged_or_recovered())
+ {
+ ut_ad(rsegs.m_redo.rseg || rsegs.m_noredo.rseg);
+ que_thr_t *thr= pars_complete_graph_for_exec(roll_node, this, heap,
+ nullptr);
+ ut_a(thr == que_fork_start_command(static_cast<que_fork_t*>
+ (que_node_get_parent(thr))));
+ que_run_threads(thr);
+ 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) {
- trx->rollback_finish();
- MONITOR_INC(MONITOR_TRX_ROLLBACK);
- } else {
- ut_a(trx->error_state == DB_SUCCESS);
- const undo_no_t limit = savept->least_undo_no;
- for (trx_mod_tables_t::iterator i = trx->mod_tables.begin();
- i != trx->mod_tables.end(); ) {
- trx_mod_tables_t::iterator j = i++;
- ut_ad(j->second.valid());
- if (j->second.rollback(limit)) {
- trx->mod_tables.erase(j);
- }
- }
- trx->lock.que_state = TRX_QUE_RUNNING;
- MONITOR_INC(MONITOR_TRX_ROLLBACK_SAVEPOINT);
- }
+ if (!savept)
+ {
+ rollback_finish();
+ MONITOR_INC(MONITOR_TRX_ROLLBACK);
+ }
+ else
+ {
+ ut_a(error_state == DB_SUCCESS);
+ const undo_no_t limit= savept->least_undo_no;
+ for (trx_mod_tables_t::iterator i= mod_tables.begin();
+ i != mod_tables.end(); )
+ {
+ trx_mod_tables_t::iterator j= i++;
+ ut_ad(j->second.valid());
+ if (j->second.rollback(limit))
+ mod_tables.erase(j);
+ }
+ lock.que_state= TRX_QUE_RUNNING;
+ MONITOR_INC(MONITOR_TRX_ROLLBACK_SAVEPOINT);
+ }
- mem_heap_free(heap);
+ mem_heap_free(heap);
- /* There might be work for utility threads.*/
- srv_active_wake_master_thread();
+ /* There might be work for utility threads.*/
+ srv_active_wake_master_thread();
- MONITOR_DEC(MONITOR_TRX_ACTIVE);
+ MONITOR_DEC(MONITOR_TRX_ACTIVE);
}
-/*******************************************************************//**
-Rollback a transaction to a given savepoint or do a complete rollback.
+/** Initiate rollback.
+@param savept savepoint
@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 */
+dberr_t trx_t::rollback(trx_savept_t *savept)
{
+ ut_ad(!trx_mutex_own(this));
+ if (state == TRX_STATE_NOT_STARTED)
+ {
+ error_state= DB_SUCCESS;
+ return DB_SUCCESS;
+ }
+ ut_ad(state == TRX_STATE_ACTIVE);
#ifdef WITH_WSREP
- if (!savept && trx->is_wsrep() && wsrep_thd_is_SR(trx->mysql_thd)) {
- wsrep_handle_SR_rollback(NULL, trx->mysql_thd);
- }
+ if (!savept && is_wsrep() && wsrep_thd_is_SR(mysql_thd))
+ wsrep_handle_SR_rollback(nullptr, mysql_thd);
#endif /* WITH_WSREP */
- ut_ad(!trx_mutex_own(trx));
-
- trx_start_if_not_started_xa(trx, true);
-
- trx_rollback_to_savepoint_low(trx, savept);
-
- return(trx->error_state);
+ rollback_low(savept);
+ return error_state;
}
/*******************************************************************//**
@@ -209,7 +187,7 @@ trx_rollback_for_mysql_low(
object, and we set a dummy session that we use for all MySQL
transactions. */
- trx_rollback_to_savepoint_low(trx, NULL);
+ trx->rollback_low();
trx->op_info = "";
@@ -319,8 +297,7 @@ trx_rollback_last_sql_stat_for_mysql(
trx->op_info = "rollback of SQL statement";
- err = trx_rollback_to_savepoint(
- trx, &trx->last_sql_stat_start);
+ err = trx->rollback(&trx->last_sql_stat_start);
if (trx->fts_trx != NULL) {
fts_savepoint_rollback_last_stmt(trx);
@@ -441,7 +418,7 @@ trx_rollback_to_savepoint_for_mysql_low(
trx->op_info = "rollback to a savepoint";
- err = trx_rollback_to_savepoint(trx, &savep->savept);
+ err = trx->rollback(&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