Skip to content

Commit 72274c1

Browse files
committed
SQL: TRT failure fixes [closes #318]
Unclosed stmt transaction TRT failure in inplace Related to #305
1 parent cc6701a commit 72274c1

File tree

5 files changed

+50
-32
lines changed

5 files changed

+50
-32
lines changed

sql/handler.cc

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,15 +1420,14 @@ int ha_commit_trans(THD *thd, bool all)
14201420
{
14211421
handlerton *ht= hi->ht();
14221422
if ((ht->flags & HTON_NATIVE_SYS_VERSIONING) &&
1423-
thd->lex->sql_command == SQLCOM_ALTER_TABLE ?
1423+
(thd->lex->sql_command == SQLCOM_ALTER_TABLE ?
14241424
hi->is_trx_tmp_read_write() :
1425-
hi->is_trx_read_write())
1425+
hi->is_trx_read_write()))
14261426
{
14271427
TR_table trt(thd, true);
1428-
bool updated;
1429-
if (trt.update(updated))
1428+
if (trt.update())
14301429
goto err;
1431-
if (updated && all)
1430+
if (all)
14321431
trans_commit_stmt(thd);
14331432
break;
14341433
}
@@ -4301,14 +4300,6 @@ bool handler::ha_commit_inplace_alter_table(TABLE *altered_table,
43014300
MDL_EXCLUSIVE) ||
43024301
!commit);
43034302

4304-
if (commit && native_versioned())
4305-
{
4306-
TR_table trt(ha_thd(), true);
4307-
bool updated;
4308-
if (trt.update(updated))
4309-
return true;
4310-
}
4311-
43124303
return commit_inplace_alter_table(altered_table, ha_alter_info, commit);
43134304
}
43144305

sql/sql_table.cc

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7428,11 +7428,22 @@ static bool mysql_inplace_alter_table(THD *thd,
74287428
DEBUG_SYNC(thd, "alter_table_inplace_before_commit");
74297429
THD_STAGE_INFO(thd, stage_alter_inplace_commit);
74307430

7431-
if (table->file->ha_commit_inplace_alter_table(altered_table,
7432-
ha_alter_info,
7433-
true))
74347431
{
7435-
goto rollback;
7432+
TR_table trt(thd, true);
7433+
if (table->file->native_versioned())
7434+
{
7435+
if (trt.update())
7436+
return true;
7437+
}
7438+
7439+
if (table->file->ha_commit_inplace_alter_table(altered_table,
7440+
ha_alter_info,
7441+
true))
7442+
{
7443+
goto rollback;
7444+
}
7445+
7446+
thd->drop_temporary_table(altered_table, NULL, false);
74367447
}
74377448

74387449
close_all_tables_for_name(thd, table->s,
@@ -7442,8 +7453,6 @@ static bool mysql_inplace_alter_table(THD *thd,
74427453
NULL);
74437454
table_list->table= table= NULL;
74447455

7445-
thd->drop_temporary_table(altered_table, NULL, false);
7446-
74477456
/*
74487457
Replace the old .FRM with the new .FRM, but keep the old name for now.
74497458
Rename to the new name (if needed) will be handled separately below.

sql/table.cc

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8484,22 +8484,38 @@ LEX_CSTRING *fk_option_name(enum_fk_option opt)
84848484
return names + opt;
84858485
}
84868486

8487-
TR_table::TR_table(THD* _thd, bool rw) : thd(_thd)
8487+
TR_table::TR_table(THD* _thd, bool rw) :
8488+
thd(_thd), open_tables_backup(NULL)
84888489
{
84898490
init_one_table(LEX_STRING_WITH_LEN(MYSQL_SCHEMA_NAME),
84908491
LEX_STRING_WITH_LEN(TRANSACTION_REG_NAME),
84918492
TRANSACTION_REG_NAME.str, rw ? TL_WRITE : TL_READ);
8493+
}
8494+
8495+
bool TR_table::open()
8496+
{
8497+
DBUG_ASSERT(!table);
84928498
open_tables_backup= new Open_tables_backup;
8493-
if (open_tables_backup)
8494-
open_log_table(thd, this, open_tables_backup);
8495-
else
8499+
if (!open_tables_backup)
8500+
{
84968501
my_error(ER_OUT_OF_RESOURCES, MYF(0));
8502+
return true;
8503+
}
8504+
8505+
All_tmp_tables_list *temporary_tables= thd->temporary_tables;
8506+
bool error= !open_log_table(thd, this, open_tables_backup);
8507+
thd->temporary_tables= temporary_tables;
8508+
8509+
return error;
84978510
}
84988511

84998512
TR_table::~TR_table()
85008513
{
85018514
if (table)
8515+
{
8516+
thd->temporary_tables= NULL;
85028517
close_log_table(thd, open_tables_backup);
8518+
}
85038519
delete open_tables_backup;
85048520
}
85058521

@@ -8532,16 +8548,17 @@ enum_tx_isolation TR_table::iso_level() const
85328548
return res;
85338549
}
85348550

8535-
bool TR_table::update(bool &updated)
8551+
bool TR_table::update()
85368552
{
8537-
if (!table)
8553+
if (!table && open())
85388554
return true;
85398555

85408556
DBUG_ASSERT(table->s);
85418557
handlerton *hton= table->s->db_type();
85428558
DBUG_ASSERT(hton);
85438559
DBUG_ASSERT(hton->flags & HTON_NATIVE_SYS_VERSIONING);
85448560

8561+
bool updated;
85458562
if ((updated= hton->vers_get_trt_data(*this)))
85468563
{
85478564
int error= table->file->ha_write_row(table->record[0]);
@@ -8557,7 +8574,7 @@ bool TR_table::update(bool &updated)
85578574
#define newx new (thd->mem_root)
85588575
bool TR_table::query(ulonglong trx_id)
85598576
{
8560-
if (!table)
8577+
if (!table && open())
85618578
return false;
85628579
SQL_SELECT_auto select;
85638580
READ_RECORD info;
@@ -8587,7 +8604,7 @@ bool TR_table::query(ulonglong trx_id)
85878604

85888605
bool TR_table::query(MYSQL_TIME &commit_time, bool backwards)
85898606
{
8590-
if (!table)
8607+
if (!table && open())
85918608
return false;
85928609
SQL_SELECT_auto select;
85938610
READ_RECORD info;
@@ -8684,13 +8701,13 @@ bool TR_table::query_sees(bool &result, ulonglong trx_id1, ulonglong trx_id0,
86848701
return false;
86858702
}
86868703

8687-
bool TR_table::check() const
8704+
bool TR_table::check()
86888705
{
86898706
// InnoDB may not be loaded
86908707
if (!ha_resolve_by_legacy_type(thd, DB_TYPE_INNODB))
86918708
return false;
86928709

8693-
if (!table)
8710+
if (open())
86948711
return true;
86958712

86968713
if (table->file->ht->db_type != DB_TYPE_INNODB)

sql/table.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2946,12 +2946,13 @@ class TR_table: public TABLE_LIST
29462946
FIELD_COUNT
29472947
};
29482948
TR_table(THD *_thd, bool rw= false);
2949+
bool open();
29492950
~TR_table();
29502951
THD *get_thd() const { return thd; }
29512952
void store(uint field_id, ulonglong val);
29522953
void store(uint field_id, timeval ts);
29532954
void store_data(ulonglong trx_id, ulonglong commit_id, timeval commit_ts);
2954-
bool update(bool &updated);
2955+
bool update();
29552956
// return true if found; false if not found or error
29562957
bool query(ulonglong trx_id);
29572958
bool query(MYSQL_TIME &commit_time, bool backwards);
@@ -2979,7 +2980,7 @@ class TR_table: public TABLE_LIST
29792980
DBUG_ASSERT(iso_level <= ISO_SERIALIZABLE);
29802981
store(FLD_ISO_LEVEL, iso_level + 1);
29812982
}
2982-
bool check() const;
2983+
bool check();
29832984
};
29842985

29852986
#endif /* MYSQL_CLIENT */

sql/vtmd.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ VTMD_table::update(THD *thd, const char* archive_name)
258258
if (!result)
259259
{
260260
TR_table trt(thd, true);
261-
result= trt.update(result);
261+
result= trt.update();
262262
}
263263

264264
close_log_table(thd, &open_tables_backup);

0 commit comments

Comments
 (0)