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( ...@@ -319,7 +319,7 @@ dict_stats_exec_sql(
} else { } else {
trx->op_info = "rollback of internal trx on stats tables"; trx->op_info = "rollback of internal trx on stats tables";
trx->dict_operation_lock_mode = RW_X_LATCH; trx->dict_operation_lock_mode = RW_X_LATCH;
trx_rollback_to_savepoint(trx, NULL); trx->rollback();
trx->dict_operation_lock_mode = 0; trx->dict_operation_lock_mode = 0;
trx->op_info = ""; trx->op_info = "";
ut_a(trx->error_state == DB_SUCCESS); ut_a(trx->error_state == DB_SUCCESS);
......
...@@ -6384,6 +6384,7 @@ fts_rename_aux_tables_to_hex_format( ...@@ -6384,6 +6384,7 @@ fts_rename_aux_tables_to_hex_format(
trx_rename->dict_operation_lock_mode = 0; trx_rename->dict_operation_lock_mode = 0;
if (err != DB_SUCCESS) { if (err != DB_SUCCESS) {
fts_sql_rollback(trx_rename);
ib::warn() << "Rollback operations on all aux tables of " ib::warn() << "Rollback operations on all aux tables of "
"table "<< parent_table->name << ". All the fts index " "table "<< parent_table->name << ". All the fts index "
...@@ -6391,18 +6392,13 @@ fts_rename_aux_tables_to_hex_format( ...@@ -6391,18 +6392,13 @@ fts_rename_aux_tables_to_hex_format(
"Please rebuild the index again."; "Please rebuild the index again.";
/* Corrupting the fts index related to parent table. */ /* Corrupting the fts index related to parent table. */
trx_t* trx_corrupt; trx_rename->dict_operation_lock_mode = RW_X_LATCH;
trx_corrupt = trx_create(); trx_start_for_ddl(trx_rename, TRX_DICT_OP_TABLE);
trx_corrupt->dict_operation_lock_mode = RW_X_LATCH; fts_parent_all_index_set_corrupt(trx_rename, parent_table);
trx_start_for_ddl(trx_corrupt, TRX_DICT_OP_TABLE); trx_rename->dict_operation_lock_mode = 0;
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);
} }
fts_sql_commit(trx_rename);
trx_free(trx_rename); trx_free(trx_rename);
ib_vector_reset(aux_tables); ib_vector_reset(aux_tables);
} }
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 2007, 2016, Oracle and/or its affiliates. All Rights Reserved. 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 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 the terms of the GNU General Public License as published by the Free Software
...@@ -261,32 +261,3 @@ fts_get_select_columns_str( ...@@ -261,32 +261,3 @@ fts_get_select_columns_str(
return(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( ...@@ -6250,7 +6250,7 @@ prepare_inplace_alter_table_dict(
user_table, ctx->drop_fk, ctx->num_to_drop_fk)) { user_table, ctx->drop_fk, ctx->num_to_drop_fk)) {
new_clustered_failed: new_clustered_failed:
DBUG_ASSERT(ctx->trx != ctx->prebuilt->trx); 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); ut_ad(user_table->get_ref_count() == 1);
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 2011, 2018, Oracle and/or its affiliates. All Rights Reserved. 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 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 the terms of the GNU General Public License as published by the Free Software
...@@ -292,22 +292,8 @@ fts_trx_table_id_cmp( ...@@ -292,22 +292,8 @@ fts_trx_table_id_cmp(
const void* p1, /*!< in: id1 */ const void* p1, /*!< in: id1 */
const void* p2) /*!< in: id2 */ const void* p2) /*!< in: id2 */
MY_ATTRIBUTE((nonnull, warn_unused_result)); MY_ATTRIBUTE((nonnull, warn_unused_result));
/******************************************************************//** #define fts_sql_commit(trx) trx_commit_for_mysql(trx)
Commit a transaction. #define fts_sql_rollback(trx) (trx)->rollback()
@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));
/******************************************************************//** /******************************************************************//**
Parse an SQL string. %s is replaced with the table's id. Don't acquire Parse an SQL string. %s is replaced with the table's id. Don't acquire
the dict mutex the dict mutex
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. 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 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 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( ...@@ -103,17 +103,6 @@ trx_rollback_last_sql_stat_for_mysql(
trx_t* trx) /*!< in/out: transaction */ trx_t* trx) /*!< in/out: transaction */
MY_ATTRIBUTE((nonnull)); 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 Rolls back a transaction back to a named savepoint. Modifications after the
savepoint are undone but InnoDB does NOT release the corresponding locks 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 which are stored in memory. If a lock is 'implicit', that is, a new inserted
......
...@@ -1101,6 +1101,13 @@ struct trx_t { ...@@ -1101,6 +1101,13 @@ struct trx_t {
@param[in] table_id table identifier */ @param[in] table_id table identifier */
void evict_table(table_id_t table_id); 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. /** Finish rollback.
@return whether the rollback was completed normally @return whether the rollback was completed normally
@retval false if the rollback was aborted by shutdown */ @retval false if the rollback was aborted by shutdown */
......
...@@ -731,7 +731,7 @@ row_mysql_handle_errors( ...@@ -731,7 +731,7 @@ row_mysql_handle_errors(
/* Roll back the latest, possibly incomplete insertion /* Roll back the latest, possibly incomplete insertion
or update */ or update */
trx_rollback_to_savepoint(trx, savept); trx->rollback(savept);
} }
/* MySQL will roll back the latest SQL statement */ /* MySQL will roll back the latest SQL statement */
break; break;
...@@ -754,7 +754,7 @@ row_mysql_handle_errors( ...@@ -754,7 +754,7 @@ row_mysql_handle_errors(
/* Roll back the whole transaction; this resolution was added /* Roll back the whole transaction; this resolution was added
to version 3.23.43 */ to version 3.23.43 */
trx_rollback_to_savepoint(trx, NULL); trx->rollback();
break; break;
case DB_MUST_GET_MORE_FILE_SPACE: case DB_MUST_GET_MORE_FILE_SPACE:
...@@ -2425,7 +2425,7 @@ row_create_table_for_mysql( ...@@ -2425,7 +2425,7 @@ row_create_table_for_mysql(
break; break;
case DB_OUT_OF_FILE_SPACE: case DB_OUT_OF_FILE_SPACE:
trx->error_state = DB_SUCCESS; trx->error_state = DB_SUCCESS;
trx_rollback_to_savepoint(trx, NULL); trx->rollback();
ib::warn() << "Cannot create table " ib::warn() << "Cannot create table "
<< table->name << table->name
...@@ -2456,7 +2456,7 @@ row_create_table_for_mysql( ...@@ -2456,7 +2456,7 @@ row_create_table_for_mysql(
case DB_TABLESPACE_EXISTS: case DB_TABLESPACE_EXISTS:
default: default:
trx->error_state = DB_SUCCESS; trx->error_state = DB_SUCCESS;
trx_rollback_to_savepoint(trx, NULL); trx->rollback();
dict_mem_table_free(table); dict_mem_table_free(table);
break; break;
} }
...@@ -3793,7 +3793,7 @@ row_drop_table_for_mysql( ...@@ -3793,7 +3793,7 @@ row_drop_table_for_mysql(
<< ut_get_name(trx, tablename) << "."; << ut_get_name(trx, tablename) << ".";
trx->error_state = DB_SUCCESS; trx->error_state = DB_SUCCESS;
trx_rollback_to_savepoint(trx, NULL); trx->rollback();
trx->error_state = DB_SUCCESS; trx->error_state = DB_SUCCESS;
/* Mark all indexes available in the data dictionary /* Mark all indexes available in the data dictionary
...@@ -4525,7 +4525,7 @@ row_rename_table_for_mysql( ...@@ -4525,7 +4525,7 @@ row_rename_table_for_mysql(
" succeed."; " succeed.";
} }
trx->error_state = DB_SUCCESS; trx->error_state = DB_SUCCESS;
trx_rollback_to_savepoint(trx, NULL); trx->rollback();
trx->error_state = DB_SUCCESS; trx->error_state = DB_SUCCESS;
} else { } else {
/* The following call will also rename the .ibd data file if /* The following call will also rename the .ibd data file if
...@@ -4535,7 +4535,7 @@ row_rename_table_for_mysql( ...@@ -4535,7 +4535,7 @@ row_rename_table_for_mysql(
table, new_name, !new_is_tmp); table, new_name, !new_is_tmp);
if (err != DB_SUCCESS) { if (err != DB_SUCCESS) {
trx->error_state = DB_SUCCESS; trx->error_state = DB_SUCCESS;
trx_rollback_to_savepoint(trx, NULL); trx->rollback();
trx->error_state = DB_SUCCESS; trx->error_state = DB_SUCCESS;
goto funct_exit; goto funct_exit;
} }
...@@ -4577,7 +4577,7 @@ row_rename_table_for_mysql( ...@@ -4577,7 +4577,7 @@ row_rename_table_for_mysql(
} }
trx->error_state = DB_SUCCESS; trx->error_state = DB_SUCCESS;
trx_rollback_to_savepoint(trx, NULL); trx->rollback();
trx->error_state = DB_SUCCESS; trx->error_state = DB_SUCCESS;
} }
...@@ -4589,7 +4589,7 @@ row_rename_table_for_mysql( ...@@ -4589,7 +4589,7 @@ row_rename_table_for_mysql(
ut_a(DB_SUCCESS == dict_table_rename_in_cache( ut_a(DB_SUCCESS == dict_table_rename_in_cache(
table, old_name, FALSE)); table, old_name, FALSE));
trx->error_state = DB_SUCCESS; trx->error_state = DB_SUCCESS;
trx_rollback_to_savepoint(trx, NULL); trx->rollback();
trx->error_state = DB_SUCCESS; trx->error_state = DB_SUCCESS;
goto funct_exit; goto funct_exit;
} }
......
...@@ -90,107 +90,85 @@ inline bool trx_t::rollback_finish() ...@@ -90,107 +90,85 @@ inline bool trx_t::rollback_finish()
undo= nullptr; undo= nullptr;
} }
commit_low(); commit_low();
lock.que_state = TRX_QUE_RUNNING; lock.que_state= TRX_QUE_RUNNING;
return false; return false;
} }
/*******************************************************************//** /** Roll back an active transaction. */
Rollback a transaction used in MySQL. */ inline void trx_t::rollback_low(trx_savept_t *savept)
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= mem_heap_create(512);
mem_heap_t* heap; roll_node_t *roll_node= roll_node_create(heap);
roll_node_t* roll_node; roll_node->savept= savept;
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()) {
ut_ad(trx->rsegs.m_redo.rseg != 0 if (savept)
|| trx->rsegs.m_noredo.rseg != 0); 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( if (has_logged_or_recovered())
static_cast<que_fork_t*>(que_node_get_parent(thr)))); {
ut_ad(rsegs.m_redo.rseg || rsegs.m_noredo.rseg);
que_run_threads(thr); que_thr_t *thr= pars_complete_graph_for_exec(roll_node, this, heap,
nullptr);
ut_a(roll_node->undo_thr != NULL); ut_a(thr == que_fork_start_command(static_cast<que_fork_t*>
que_run_threads(roll_node->undo_thr); (que_node_get_parent(thr))));
que_run_threads(thr);
/* Free the memory reserved by the undo graph. */ que_run_threads(roll_node->undo_thr);
que_graph_free(static_cast<que_t*>(
roll_node->undo_thr->common.parent)); /* Free the memory reserved by the undo graph. */
} que_graph_free(static_cast<que_t*>(roll_node->undo_thr->common.parent));
}
if (!savept) { if (!savept)
trx->rollback_finish(); {
MONITOR_INC(MONITOR_TRX_ROLLBACK); rollback_finish();
} else { MONITOR_INC(MONITOR_TRX_ROLLBACK);
ut_a(trx->error_state == DB_SUCCESS); }
const undo_no_t limit = savept->least_undo_no; else
for (trx_mod_tables_t::iterator i = trx->mod_tables.begin(); {
i != trx->mod_tables.end(); ) { ut_a(error_state == DB_SUCCESS);
trx_mod_tables_t::iterator j = i++; const undo_no_t limit= savept->least_undo_no;
ut_ad(j->second.valid()); for (trx_mod_tables_t::iterator i= mod_tables.begin();
if (j->second.rollback(limit)) { i != mod_tables.end(); )
trx->mod_tables.erase(j); {
} trx_mod_tables_t::iterator j= i++;
} ut_ad(j->second.valid());
trx->lock.que_state = TRX_QUE_RUNNING; if (j->second.rollback(limit))
MONITOR_INC(MONITOR_TRX_ROLLBACK_SAVEPOINT); 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.*/ /* There might be work for utility threads.*/
srv_active_wake_master_thread(); srv_active_wake_master_thread();
MONITOR_DEC(MONITOR_TRX_ACTIVE); MONITOR_DEC(MONITOR_TRX_ACTIVE);
} }
/*******************************************************************//** /** Initiate rollback.
Rollback a transaction to a given savepoint or do a complete rollback. @param savept savepoint
@return error code or DB_SUCCESS */ @return error code or DB_SUCCESS */
dberr_t dberr_t trx_t::rollback(trx_savept_t *savept)
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(this));
if (state == TRX_STATE_NOT_STARTED)
{
error_state= DB_SUCCESS;
return DB_SUCCESS;
}
ut_ad(state == TRX_STATE_ACTIVE);
#ifdef WITH_WSREP #ifdef WITH_WSREP
if (!savept && trx->is_wsrep() && wsrep_thd_is_SR(trx->mysql_thd)) { if (!savept && is_wsrep() && wsrep_thd_is_SR(mysql_thd))
wsrep_handle_SR_rollback(NULL, trx->mysql_thd); wsrep_handle_SR_rollback(nullptr, mysql_thd);
}
#endif /* WITH_WSREP */ #endif /* WITH_WSREP */
ut_ad(!trx_mutex_own(trx)); rollback_low(savept);
return error_state;
trx_start_if_not_started_xa(trx, true);
trx_rollback_to_savepoint_low(trx, savept);
return(trx->error_state);
} }
/*******************************************************************//** /*******************************************************************//**
...@@ -209,7 +187,7 @@ trx_rollback_for_mysql_low( ...@@ -209,7 +187,7 @@ trx_rollback_for_mysql_low(
object, and we set a dummy session that we use for all MySQL object, and we set a dummy session that we use for all MySQL
transactions. */ transactions. */
trx_rollback_to_savepoint_low(trx, NULL); trx->rollback_low();
trx->op_info = ""; trx->op_info = "";
...@@ -319,8 +297,7 @@ trx_rollback_last_sql_stat_for_mysql( ...@@ -319,8 +297,7 @@ trx_rollback_last_sql_stat_for_mysql(
trx->op_info = "rollback of SQL statement"; trx->op_info = "rollback of SQL statement";
err = trx_rollback_to_savepoint( err = trx->rollback(&trx->last_sql_stat_start);
trx, &trx->last_sql_stat_start);
if (trx->fts_trx != NULL) { if (trx->fts_trx != NULL) {
fts_savepoint_rollback_last_stmt(trx); fts_savepoint_rollback_last_stmt(trx);
...@@ -441,7 +418,7 @@ trx_rollback_to_savepoint_for_mysql_low( ...@@ -441,7 +418,7 @@ trx_rollback_to_savepoint_for_mysql_low(
trx->op_info = "rollback to a savepoint"; 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 /* Store the current undo_no of the transaction so that
we know where to roll back if we have to roll back the 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