Commit 3e6722d8 authored by Marko Mäkelä's avatar Marko Mäkelä

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.
parent 496d0372
......@@ -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);
......
......@@ -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);
}
......
/*****************************************************************************
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));
}
......@@ -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);
......
/*****************************************************************************
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
......
/*****************************************************************************
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
......
......@@ -1101,6 +1101,13 @@ struct trx_t {
@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 */
......
......@@ -731,7 +731,7 @@ row_mysql_handle_errors(
/* 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 @@ row_mysql_handle_errors(
/* 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 @@ row_create_table_for_mysql(
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 @@ row_create_table_for_mysql(
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 @@ row_drop_table_for_mysql(
<< 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 @@ row_rename_table_for_mysql(
" 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 @@ row_rename_table_for_mysql(
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 @@ row_rename_table_for_mysql(
}
trx->error_state = DB_SUCCESS;
trx_rollback_to_savepoint(trx, NULL);
trx->rollback();
trx->error_state = DB_SUCCESS;
}
......@@ -4589,7 +4589,7 @@ row_rename_table_for_mysql(
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;
}
......
......@@ -90,73 +90,56 @@ 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);
thr = pars_complete_graph_for_exec(roll_node, trx, heap, NULL);
if (savept)
check_trx_state(this);
else
assert_trx_nonlocking_or_in_list(this);
ut_a(thr == que_fork_start_command(
static_cast<que_fork_t*>(que_node_get_parent(thr))));
error_state = DB_SUCCESS;
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);
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));
que_graph_free(static_cast<que_t*>(roll_node->undo_thr->common.parent));
}
if (!savept) {
trx->rollback_finish();
if (!savept)
{
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);
}
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);
}
trx->lock.que_state = TRX_QUE_RUNNING;
lock.que_state= TRX_QUE_RUNNING;
MONITOR_INC(MONITOR_TRX_ROLLBACK_SAVEPOINT);
}
......@@ -168,29 +151,24 @@ trx_rollback_to_savepoint_low(
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)
{
#ifdef WITH_WSREP
if (!savept && trx->is_wsrep() && wsrep_thd_is_SR(trx->mysql_thd)) {
wsrep_handle_SR_rollback(NULL, trx->mysql_thd);
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 && 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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment