Commit ce699df9 authored by Monty's avatar Monty

thd->m_transaction_psi was not properly cleared for new connections

This happend when using XA transactions. I also added some extra asserts
to ensure that m_transactions are properly cleared.

Other things:
- Removed set_time() from THD::init_for_queries() as dispatch_command()
  is already doing that.
- Removed duplicate init_for_queries() from prepare_new_connection_state().
  The init_for_queries() functions should only be called once per
  connection.
parent dbcd3384
...@@ -1818,6 +1818,10 @@ int ha_commit_trans(THD *thd, bool all) ...@@ -1818,6 +1818,10 @@ int ha_commit_trans(THD *thd, bool all)
ha_rollback_trans(thd, all); ha_rollback_trans(thd, all);
else else
{ {
/*
We are not really doing a rollback here, but the code in trans_commit()
requres that m_transaction_psi is 0 when we return from this function.
*/
MYSQL_ROLLBACK_TRANSACTION(thd->m_transaction_psi); MYSQL_ROLLBACK_TRANSACTION(thd->m_transaction_psi);
thd->m_transaction_psi= NULL; thd->m_transaction_psi= NULL;
WSREP_DEBUG("rollback skipped %p %d",thd->rgi_slave, WSREP_DEBUG("rollback skipped %p %d",thd->rgi_slave,
......
...@@ -1396,9 +1396,11 @@ void THD::update_all_stats() ...@@ -1396,9 +1396,11 @@ void THD::update_all_stats()
void THD::init_for_queries() void THD::init_for_queries()
{ {
set_time(); DBUG_ASSERT(transaction->on);
ha_enable_transaction(this,TRUE); DBUG_ASSERT(m_transaction_psi == NULL);
/* Set time for --init-file queries */
set_time();
reset_root_defaults(mem_root, variables.query_alloc_block_size, reset_root_defaults(mem_root, variables.query_alloc_block_size,
variables.query_prealloc_size); variables.query_prealloc_size);
reset_root_defaults(&transaction->mem_root, reset_root_defaults(&transaction->mem_root,
...@@ -1550,6 +1552,8 @@ void THD::cleanup(void) ...@@ -1550,6 +1552,8 @@ void THD::cleanup(void)
trans_rollback(this); trans_rollback(this);
DBUG_ASSERT(open_tables == NULL); DBUG_ASSERT(open_tables == NULL);
DBUG_ASSERT(m_transaction_psi == NULL);
/* /*
If the thread was in the middle of an ongoing transaction (rolled If the thread was in the middle of an ongoing transaction (rolled
back a few lines above) or under LOCK TABLES (unlocked the tables back a few lines above) or under LOCK TABLES (unlocked the tables
...@@ -1650,6 +1654,7 @@ void THD::reset_for_reuse() ...@@ -1650,6 +1654,7 @@ void THD::reset_for_reuse()
abort_on_warning= 0; abort_on_warning= 0;
free_connection_done= 0; free_connection_done= 0;
m_command= COM_CONNECT; m_command= COM_CONNECT;
transaction->on= 1;
#if defined(ENABLED_PROFILING) #if defined(ENABLED_PROFILING)
profiling.reset(); profiling.reset();
#endif #endif
......
...@@ -1279,7 +1279,6 @@ void prepare_new_connection_state(THD* thd) ...@@ -1279,7 +1279,6 @@ void prepare_new_connection_state(THD* thd)
} }
thd->proc_info=0; thd->proc_info=0;
thd->init_for_queries();
} }
} }
......
...@@ -843,6 +843,7 @@ bool trans_xa_detach(THD *thd) ...@@ -843,6 +843,7 @@ bool trans_xa_detach(THD *thd)
thd->transaction->all.ha_list= 0; thd->transaction->all.ha_list= 0;
thd->transaction->all.no_2pc= 0; thd->transaction->all.no_2pc= 0;
thd->m_transaction_psi= 0;
return false; return false;
} }
......
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