mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Aria will now register it's transactions
MDEV-22531 Remove maria::implicit_commit() MDEV-22607 Assertion `ha_info->ht() != binlog_hton' failed in MYSQL_BIN_LOG::unlog_xa_prepare From the handler point of view, Aria now looks like a transactional engine. One effect of this is that we don't need to call maria::implicit_commit() anymore. This change also forces the server to call trans_commit_stmt() after doing any read or writes to system tables. This work will also make it easier to later allow users to have system tables in other engines than Aria. To handle the case that Aria doesn't support rollback, a new handlerton flag, HTON_NO_ROLLBACK, was added to engines that has transactions without rollback (for the moment only binlog and Aria). Other things - Moved freeing of MARIA_SHARE to a separate function as the MARIA_SHARE can be still part of a transaction even if the table has closed. - Changed Aria checkpoint to use the new MARIA_SHARE free function. This fixes a possible memory leak when using S3 tables - Changed testing of binlog_hton to instead test for HTON_NO_ROLLBACK - Removed checking of has_transaction_manager() in handler.cc as we can assume that as the transaction was started by the engine, it does support transactions. - Added new class 'start_new_trans' that can be used to start indepdendent sub transactions, for example while reading mysql.proc, using help or status tables etc. - open_system_tables...() and open_proc_table_for_Read() doesn't anymore take a Open_tables_backup list. This is now handled by 'start_new_trans'. - Split thd::has_transactions() to thd::has_transactions() and thd::has_transactions_and_rollback() - Added handlerton code to free cached transactions objects. Needed by InnoDB. squash! 2ed35999f2a2d84f1c786a21ade5db716b6f1bbc
This commit is contained in:
@ -72,6 +72,7 @@
|
||||
#include "wsrep_trans_observer.h"
|
||||
#endif /* WITH_WSREP */
|
||||
#include "opt_trace.h"
|
||||
#include <mysql/psi/mysql_transaction.h>
|
||||
|
||||
#ifdef HAVE_SYS_SYSCALL_H
|
||||
#include <sys/syscall.h>
|
||||
@ -2589,7 +2590,8 @@ void THD::add_changed_table(TABLE *table)
|
||||
{
|
||||
DBUG_ENTER("THD::add_changed_table(table)");
|
||||
|
||||
DBUG_ASSERT(in_multi_stmt_transaction_mode() && table->file->has_transactions());
|
||||
DBUG_ASSERT(in_multi_stmt_transaction_mode() &&
|
||||
table->file->has_transactions());
|
||||
add_changed_table(table->s->table_cache_key.str,
|
||||
(long) table->s->table_cache_key.length);
|
||||
DBUG_VOID_RETURN;
|
||||
@ -5742,6 +5744,92 @@ void THD::mark_transaction_to_rollback(bool all)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Commit the whole transaction (both statment and all)
|
||||
|
||||
This is used mainly to commit an independent transaction,
|
||||
like reading system tables.
|
||||
|
||||
@return 0 0k
|
||||
@return <>0 error code. my_error() has been called()
|
||||
*/
|
||||
|
||||
int THD::commit_whole_transaction_and_close_tables()
|
||||
{
|
||||
int error, error2;
|
||||
DBUG_ENTER("THD::commit_whole_transaction_and_close_tables");
|
||||
|
||||
/*
|
||||
This can only happened if we failed to open any table in the
|
||||
new transaction
|
||||
*/
|
||||
DBUG_ASSERT(open_tables);
|
||||
|
||||
if (!open_tables) // Safety for production usage
|
||||
DBUG_RETURN(0);
|
||||
|
||||
/*
|
||||
Ensure table was locked (opened with open_and_lock_tables()). If not
|
||||
the THD can't be part of any transactions and doesn't have to call
|
||||
this function.
|
||||
*/
|
||||
DBUG_ASSERT(lock);
|
||||
|
||||
error= ha_commit_trans(this, FALSE);
|
||||
/* This will call external_lock to unlock all tables */
|
||||
if ((error2= mysql_unlock_tables(this, lock)))
|
||||
{
|
||||
my_error(ER_ERROR_DURING_COMMIT, MYF(0), error2);
|
||||
error= error2;
|
||||
}
|
||||
lock= 0;
|
||||
if ((error2= ha_commit_trans(this, TRUE)))
|
||||
error= error2;
|
||||
close_thread_tables(this);
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
|
||||
/**
|
||||
Start a new independent transaction
|
||||
*/
|
||||
|
||||
start_new_trans::start_new_trans(THD *thd)
|
||||
{
|
||||
org_thd= thd;
|
||||
mdl_savepoint= thd->mdl_context.mdl_savepoint();
|
||||
memcpy(old_ha_data, thd->ha_data, sizeof(old_ha_data));
|
||||
thd->reset_n_backup_open_tables_state(&open_tables_state_backup);
|
||||
bzero(thd->ha_data, sizeof(thd->ha_data));
|
||||
old_transaction= thd->transaction;
|
||||
thd->transaction= &new_transaction;
|
||||
new_transaction.on= 1;
|
||||
in_sub_stmt= thd->in_sub_stmt;
|
||||
thd->in_sub_stmt= 0;
|
||||
server_status= thd->server_status;
|
||||
m_transaction_psi= thd->m_transaction_psi;
|
||||
thd->m_transaction_psi= 0;
|
||||
thd->server_status&= ~(SERVER_STATUS_IN_TRANS |
|
||||
SERVER_STATUS_IN_TRANS_READONLY);
|
||||
thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
|
||||
}
|
||||
|
||||
|
||||
void start_new_trans::restore_old_transaction()
|
||||
{
|
||||
org_thd->transaction= old_transaction;
|
||||
org_thd->restore_backup_open_tables_state(&open_tables_state_backup);
|
||||
ha_close_connection(org_thd);
|
||||
memcpy(org_thd->ha_data, old_ha_data, sizeof(old_ha_data));
|
||||
org_thd->mdl_context.rollback_to_savepoint(mdl_savepoint);
|
||||
org_thd->in_sub_stmt= in_sub_stmt;
|
||||
org_thd->server_status= server_status;
|
||||
if (org_thd->m_transaction_psi)
|
||||
MYSQL_COMMIT_TRANSACTION(org_thd->m_transaction_psi);
|
||||
org_thd->m_transaction_psi= m_transaction_psi;
|
||||
org_thd= 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Decide on logging format to use for the statement and issue errors
|
||||
or warnings as needed. The decision depends on the following
|
||||
|
Reference in New Issue
Block a user