Skip to content

Commit d1d4726

Browse files
committed
Change THD->transaction to a pointer to enable multiple transactions
All changes (except one) is of type thd->transaction. -> thd->transaction-> thd->transaction points by default to 'thd->default_transaction' This allows us to 'easily' have multiple active transactions for a THD object, like when reading data from the mysql.proc table
1 parent 7ae812c commit d1d4726

32 files changed

+317
-311
lines changed

sql/handler.cc

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,14 +1244,14 @@ void trans_register_ha(THD *thd, bool all, handlerton *ht_arg, ulonglong trxid)
12441244

12451245
if (all)
12461246
{
1247-
trans= &thd->transaction.all;
1247+
trans= &thd->transaction->all;
12481248
thd->server_status|= SERVER_STATUS_IN_TRANS;
12491249
if (thd->tx_read_only)
12501250
thd->server_status|= SERVER_STATUS_IN_TRANS_READONLY;
12511251
DBUG_PRINT("info", ("setting SERVER_STATUS_IN_TRANS"));
12521252
}
12531253
else
1254-
trans= &thd->transaction.stmt;
1254+
trans= &thd->transaction->stmt;
12551255

12561256
ha_info= thd->ha_data[ht_arg->slot].ha_info + (all ? 1 : 0);
12571257

@@ -1263,8 +1263,8 @@ void trans_register_ha(THD *thd, bool all, handlerton *ht_arg, ulonglong trxid)
12631263
trans->no_2pc|=(ht_arg->prepare==0);
12641264

12651265
/* Set implicit xid even if there's explicit XA, it will be ignored anyway. */
1266-
if (thd->transaction.implicit_xid.is_null())
1267-
thd->transaction.implicit_xid.set(thd->query_id);
1266+
if (thd->transaction->implicit_xid.is_null())
1267+
thd->transaction->implicit_xid.set(thd->query_id);
12681268

12691269
/*
12701270
Register transaction start in performance schema if not done already.
@@ -1327,7 +1327,7 @@ static int prepare_or_error(handlerton *ht, THD *thd, bool all)
13271327
int ha_prepare(THD *thd)
13281328
{
13291329
int error=0, all=1;
1330-
THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
1330+
THD_TRANS *trans=all ? &thd->transaction->all : &thd->transaction->stmt;
13311331
Ha_trx_info *ha_info= trans->ha_list;
13321332
DBUG_ENTER("ha_prepare");
13331333

@@ -1377,7 +1377,7 @@ uint ha_count_rw_all(THD *thd, Ha_trx_info **ptr_ha_info)
13771377
{
13781378
unsigned rw_ha_count= 0;
13791379

1380-
for (auto ha_info= thd->transaction.all.ha_list; ha_info;
1380+
for (auto ha_info= thd->transaction->all.ha_list; ha_info;
13811381
ha_info= ha_info->next())
13821382
{
13831383
if (ha_info->is_trx_read_write())
@@ -1472,15 +1472,15 @@ int ha_commit_trans(THD *thd, bool all)
14721472
'all' means that this is either an explicit commit issued by
14731473
user, or an implicit commit issued by a DDL.
14741474
*/
1475-
THD_TRANS *trans= all ? &thd->transaction.all : &thd->transaction.stmt;
1475+
THD_TRANS *trans= all ? &thd->transaction->all : &thd->transaction->stmt;
14761476
/*
14771477
"real" is a nick name for a transaction for which a commit will
14781478
make persistent changes. E.g. a 'stmt' transaction inside a 'all'
14791479
transation is not 'real': even though it's possible to commit it,
14801480
the changes are not durable as they might be rolled back if the
14811481
enclosing 'all' transaction is rolled back.
14821482
*/
1483-
bool is_real_trans= ((all || thd->transaction.all.ha_list == 0) &&
1483+
bool is_real_trans= ((all || thd->transaction->all.ha_list == 0) &&
14841484
!(thd->variables.option_bits & OPTION_GTID_BEGIN));
14851485
Ha_trx_info *ha_info= trans->ha_list;
14861486
bool need_prepare_ordered, need_commit_ordered;
@@ -1507,8 +1507,8 @@ int ha_commit_trans(THD *thd, bool all)
15071507
flags will not get propagated to its normal transaction's
15081508
counterpart.
15091509
*/
1510-
DBUG_ASSERT(thd->transaction.stmt.ha_list == NULL ||
1511-
trans == &thd->transaction.stmt);
1510+
DBUG_ASSERT(thd->transaction->stmt.ha_list == NULL ||
1511+
trans == &thd->transaction->stmt);
15121512

15131513
if (thd->in_sub_stmt)
15141514
{
@@ -1538,7 +1538,7 @@ int ha_commit_trans(THD *thd, bool all)
15381538
*/
15391539
if (is_real_trans)
15401540
{
1541-
thd->transaction.cleanup();
1541+
thd->transaction->cleanup();
15421542
MYSQL_COMMIT_TRANSACTION(thd->m_transaction_psi);
15431543
thd->m_transaction_psi= NULL;
15441544
}
@@ -1649,7 +1649,7 @@ int ha_commit_trans(THD *thd, bool all)
16491649
// Here, the call will not commit inside InnoDB. It is only working
16501650
// around closing thd->transaction.stmt open by TR_table::open().
16511651
if (all)
1652-
commit_one_phase_2(thd, false, &thd->transaction.stmt, false);
1652+
commit_one_phase_2(thd, false, &thd->transaction->stmt, false);
16531653
}
16541654
}
16551655
#endif
@@ -1710,11 +1710,11 @@ int ha_commit_trans(THD *thd, bool all)
17101710
goto done;
17111711
}
17121712

1713-
DBUG_ASSERT(thd->transaction.implicit_xid.get_my_xid() ==
1714-
thd->transaction.implicit_xid.quick_get_my_xid());
1715-
DBUG_ASSERT(!thd->transaction.xid_state.is_explicit_XA() ||
1713+
DBUG_ASSERT(thd->transaction->implicit_xid.get_my_xid() ==
1714+
thd->transaction->implicit_xid.quick_get_my_xid());
1715+
DBUG_ASSERT(!thd->transaction->xid_state.is_explicit_XA() ||
17161716
thd->lex->xa_opt == XA_ONE_PHASE);
1717-
xid= thd->transaction.implicit_xid.quick_get_my_xid();
1717+
xid= thd->transaction->implicit_xid.quick_get_my_xid();
17181718

17191719
#ifdef WITH_WSREP
17201720
if (run_wsrep_hooks && !error)
@@ -1845,7 +1845,7 @@ int ha_commit_trans(THD *thd, bool all)
18451845

18461846
int ha_commit_one_phase(THD *thd, bool all)
18471847
{
1848-
THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
1848+
THD_TRANS *trans=all ? &thd->transaction->all : &thd->transaction->stmt;
18491849
/*
18501850
"real" is a nick name for a transaction for which a commit will
18511851
make persistent changes. E.g. a 'stmt' transaction inside a 'all'
@@ -1859,7 +1859,7 @@ int ha_commit_one_phase(THD *thd, bool all)
18591859
ha_commit_one_phase() can be called with an empty
18601860
transaction.all.ha_list, see why in trans_register_ha()).
18611861
*/
1862-
bool is_real_trans= ((all || thd->transaction.all.ha_list == 0) &&
1862+
bool is_real_trans= ((all || thd->transaction->all.ha_list == 0) &&
18631863
!(thd->variables.option_bits & OPTION_GTID_BEGIN));
18641864
int res;
18651865
DBUG_ENTER("ha_commit_one_phase");
@@ -1906,16 +1906,16 @@ commit_one_phase_2(THD *thd, bool all, THD_TRANS *trans, bool is_real_trans)
19061906
if (all)
19071907
{
19081908
#ifdef HAVE_QUERY_CACHE
1909-
if (thd->transaction.changed_tables)
1910-
query_cache.invalidate(thd, thd->transaction.changed_tables);
1909+
if (thd->transaction->changed_tables)
1910+
query_cache.invalidate(thd, thd->transaction->changed_tables);
19111911
#endif
19121912
}
19131913
}
19141914
/* Free resources and perform other cleanup even for 'empty' transactions. */
19151915
if (is_real_trans)
19161916
{
19171917
thd->has_waiter= false;
1918-
thd->transaction.cleanup();
1918+
thd->transaction->cleanup();
19191919
if (count >= 2)
19201920
statistic_increment(transactions_multi_engine, LOCK_status);
19211921
}
@@ -1927,7 +1927,7 @@ commit_one_phase_2(THD *thd, bool all, THD_TRANS *trans, bool is_real_trans)
19271927
int ha_rollback_trans(THD *thd, bool all)
19281928
{
19291929
int error=0;
1930-
THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
1930+
THD_TRANS *trans=all ? &thd->transaction->all : &thd->transaction->stmt;
19311931
Ha_trx_info *ha_info= trans->ha_list, *ha_info_next;
19321932
/*
19331933
"real" is a nick name for a transaction for which a commit will
@@ -1942,15 +1942,15 @@ int ha_rollback_trans(THD *thd, bool all)
19421942
ha_commit_one_phase() is called with an empty
19431943
transaction.all.ha_list, see why in trans_register_ha()).
19441944
*/
1945-
bool is_real_trans=all || thd->transaction.all.ha_list == 0;
1945+
bool is_real_trans=all || thd->transaction->all.ha_list == 0;
19461946
DBUG_ENTER("ha_rollback_trans");
19471947

19481948
/*
19491949
We must not rollback the normal transaction if a statement
19501950
transaction is pending.
19511951
*/
1952-
DBUG_ASSERT(thd->transaction.stmt.ha_list == NULL ||
1953-
trans == &thd->transaction.stmt);
1952+
DBUG_ASSERT(thd->transaction->stmt.ha_list == NULL ||
1953+
trans == &thd->transaction->stmt);
19541954

19551955
#ifdef HAVE_REPLICATION
19561956
if (is_real_trans)
@@ -1967,7 +1967,7 @@ int ha_rollback_trans(THD *thd, bool all)
19671967
builds, we explicitly do the signalling before rolling back.
19681968
*/
19691969
DBUG_ASSERT(!(thd->rgi_slave && thd->rgi_slave->did_mark_start_commit) ||
1970-
thd->transaction.xid_state.is_explicit_XA());
1970+
thd->transaction->xid_state.is_explicit_XA());
19711971
if (thd->rgi_slave && thd->rgi_slave->did_mark_start_commit)
19721972
thd->rgi_slave->unmark_start_commit();
19731973
}
@@ -2042,10 +2042,10 @@ int ha_rollback_trans(THD *thd, bool all)
20422042
transaction hasn't been started in any transactional storage engine.
20432043
*/
20442044
if (thd->transaction_rollback_request)
2045-
thd->transaction.xid_state.set_error(thd->get_stmt_da()->sql_errno());
2045+
thd->transaction->xid_state.set_error(thd->get_stmt_da()->sql_errno());
20462046

20472047
thd->has_waiter= false;
2048-
thd->transaction.cleanup();
2048+
thd->transaction->cleanup();
20492049
}
20502050
if (all)
20512051
thd->transaction_rollback_request= FALSE;
@@ -2063,7 +2063,7 @@ int ha_rollback_trans(THD *thd, bool all)
20632063
it doesn't matter if a warning is pushed to a system thread or not:
20642064
No one will see it...
20652065
*/
2066-
if (is_real_trans && thd->transaction.all.modified_non_trans_table &&
2066+
if (is_real_trans && thd->transaction->all.modified_non_trans_table &&
20672067
!thd->slave_thread && thd->killed < KILL_CONNECTION)
20682068
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
20692069
ER_WARNING_NOT_COMPLETE_ROLLBACK,
@@ -2405,8 +2405,8 @@ commit_checkpoint_notify_ha(handlerton *hton, void *cookie)
24052405
bool ha_rollback_to_savepoint_can_release_mdl(THD *thd)
24062406
{
24072407
Ha_trx_info *ha_info;
2408-
THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction.stmt :
2409-
&thd->transaction.all);
2408+
THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction->stmt :
2409+
&thd->transaction->all);
24102410

24112411
DBUG_ENTER("ha_rollback_to_savepoint_can_release_mdl");
24122412

@@ -2430,8 +2430,8 @@ bool ha_rollback_to_savepoint_can_release_mdl(THD *thd)
24302430
int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv)
24312431
{
24322432
int error=0;
2433-
THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction.stmt :
2434-
&thd->transaction.all);
2433+
THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction->stmt :
2434+
&thd->transaction->all);
24352435
Ha_trx_info *ha_info, *ha_info_next;
24362436

24372437
DBUG_ENTER("ha_rollback_to_savepoint");
@@ -2516,8 +2516,8 @@ int ha_savepoint(THD *thd, SAVEPOINT *sv)
25162516
}
25172517
#endif /* WITH_WSREP */
25182518
int error=0;
2519-
THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction.stmt :
2520-
&thd->transaction.all);
2519+
THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction->stmt :
2520+
&thd->transaction->all);
25212521
Ha_trx_info *ha_info= trans->ha_list;
25222522
DBUG_ENTER("ha_savepoint");
25232523

@@ -5021,7 +5021,7 @@ int ha_enable_transaction(THD *thd, bool on)
50215021
DBUG_ENTER("ha_enable_transaction");
50225022
DBUG_PRINT("enter", ("on: %d", (int) on));
50235023

5024-
if ((thd->transaction.on= on))
5024+
if ((thd->transaction->on= on))
50255025
{
50265026
/*
50275027
Now all storage engines should have transaction handling enabled.

0 commit comments

Comments
 (0)