Skip to content

Commit d8463b6

Browse files
MDEV-27239 Spider: Assertion `thd->transaction->stmt.ha_list == __null || trans == &thd->transaction->stmt' failed in ha_commit_trans on BEGIN WORK after FTWRL
The check on the SQL command type, in ha_spider::external_lock() is deleted by e954d9d. This resulted in the wrong call of spider_internal_start_trx() (and thus Ha_trx_info::register_ha()). I reverted the check and refactored ha_spider::external_lock().
1 parent 6645b1d commit d8463b6

File tree

4 files changed

+105
-94
lines changed

4 files changed

+105
-94
lines changed

storage/spider/ha_spider.cc

Lines changed: 59 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,75 +1182,83 @@ int ha_spider::external_lock(
11821182
int error_num = 0;
11831183
SPIDER_TRX *trx;
11841184
backup_error_status();
1185+
11851186
DBUG_ENTER("ha_spider::external_lock");
11861187
DBUG_PRINT("info",("spider this=%p", this));
11871188
DBUG_PRINT("info",("spider lock_type=%x", lock_type));
1188-
#if MYSQL_VERSION_ID < 50500
1189-
DBUG_PRINT("info",("spider thd->options=%x", (int) thd->options));
1190-
#endif
1191-
#ifdef WITH_PARTITION_STORAGE_ENGINE
1192-
if (
1193-
wide_handler->stage == SPD_HND_STAGE_EXTERNAL_LOCK &&
1194-
wide_handler->stage_executor != this)
1189+
DBUG_PRINT("info", ("spider sql_command=%d", thd_sql_command(thd)));
1190+
1191+
if (wide_handler->stage == SPD_HND_STAGE_EXTERNAL_LOCK)
11951192
{
1196-
DBUG_RETURN(0);
1193+
/* Only the stage executor deals with table locks. */
1194+
if (wide_handler->stage_executor != this)
1195+
{
1196+
DBUG_RETURN(0);
1197+
}
1198+
}
1199+
else
1200+
{
1201+
/* Update the stage executor when the stage changes */
1202+
wide_handler->stage= SPD_HND_STAGE_EXTERNAL_LOCK;
1203+
wide_handler->stage_executor= this;
11971204
}
1198-
wide_handler->stage = SPD_HND_STAGE_EXTERNAL_LOCK;
1199-
wide_handler->stage_executor = this;
1200-
#endif
1201-
#ifdef HANDLER_HAS_NEED_INFO_FOR_AUTO_INC
1202-
info_auto_called = FALSE;
1203-
#endif
12041205

1206+
info_auto_called = FALSE;
1207+
wide_handler->external_lock_type= lock_type;
12051208
wide_handler->sql_command = thd_sql_command(thd);
1209+
1210+
/* We treat BEGIN as if UNLOCK TABLE. */
12061211
if (wide_handler->sql_command == SQLCOM_BEGIN)
1212+
{
12071213
wide_handler->sql_command = SQLCOM_UNLOCK_TABLES;
1214+
}
1215+
if (lock_type == F_UNLCK &&
1216+
wide_handler->sql_command != SQLCOM_UNLOCK_TABLES)
1217+
{
1218+
DBUG_RETURN(0);
1219+
}
12081220

12091221
trx = spider_get_trx(thd, TRUE, &error_num);
12101222
if (error_num)
1223+
{
12111224
DBUG_RETURN(error_num);
1225+
}
12121226
wide_handler->trx = trx;
12131227

1214-
DBUG_PRINT("info",("spider sql_command=%d", wide_handler->sql_command));
1215-
#ifdef HA_CAN_BULK_ACCESS
1216-
wide_handler->external_lock_cnt++;
1217-
#endif
1218-
if (
1219-
lock_type == F_UNLCK &&
1220-
wide_handler->sql_command != SQLCOM_UNLOCK_TABLES
1221-
)
1222-
DBUG_RETURN(0);
1228+
/* Question: Why the following if block is necessary? Why here? */
12231229
if (store_error_num)
1230+
{
12241231
DBUG_RETURN(store_error_num);
1225-
wide_handler->external_lock_type = lock_type;
1226-
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1227-
if ((conn_kinds & SPIDER_CONN_KIND_MYSQL))
1232+
}
1233+
1234+
DBUG_ASSERT(wide_handler->sql_command != SQLCOM_RENAME_TABLE &&
1235+
wide_handler->sql_command != SQLCOM_DROP_DB);
1236+
1237+
if (wide_handler->sql_command == SQLCOM_DROP_TABLE ||
1238+
wide_handler->sql_command == SQLCOM_ALTER_TABLE)
12281239
{
1229-
#endif
1230-
if (
1231-
/* SQLCOM_RENAME_TABLE and SQLCOM_DROP_DB don't come here */
1232-
wide_handler->sql_command == SQLCOM_DROP_TABLE ||
1233-
wide_handler->sql_command == SQLCOM_ALTER_TABLE
1234-
) {
1235-
if (trx->locked_connections)
1236-
{
1237-
my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM,
1238-
ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0));
1239-
DBUG_RETURN(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM);
1240-
}
1241-
DBUG_RETURN(0);
1240+
if (trx->locked_connections)
1241+
{
1242+
my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM,
1243+
ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0));
1244+
DBUG_RETURN(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM);
12421245
}
1243-
if (unlikely((error_num = spider_internal_start_trx(this))))
1246+
DBUG_RETURN(0);
1247+
}
1248+
1249+
if (lock_type != F_UNLCK)
1250+
{
1251+
if (unlikely((error_num= spider_internal_start_trx(this))))
12441252
{
12451253
DBUG_RETURN(error_num);
12461254
}
1247-
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1248-
} else {
1249-
trans_register_ha(trx->thd, FALSE, spider_hton_ptr);
1250-
if (thd_test_options(trx->thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
1251-
trans_register_ha(trx->thd, TRUE, spider_hton_ptr);
1255+
if (wide_handler->sql_command != SQLCOM_SELECT &&
1256+
wide_handler->sql_command != SQLCOM_HA_READ)
1257+
{
1258+
trx->updated_in_this_trx= TRUE;
1259+
DBUG_PRINT("info", ("spider trx->updated_in_this_trx=TRUE"));
1260+
}
12521261
}
1253-
#endif
12541262

12551263
if (wide_handler->lock_table_type > 0 ||
12561264
wide_handler->sql_command == SQLCOM_UNLOCK_TABLES)
@@ -1263,67 +1271,24 @@ int ha_spider::external_lock(
12631271
}
12641272

12651273
/* lock/unlock tables */
1266-
#ifdef WITH_PARTITION_STORAGE_ENGINE
12671274
if (partition_handler && partition_handler->handlers)
12681275
{
1269-
uint roop_count;
1270-
for (roop_count = 0; roop_count < partition_handler->no_parts;
1271-
++roop_count)
1276+
for (uint roop_count= 0; roop_count < partition_handler->no_parts;
1277+
++roop_count)
12721278
{
12731279
if (unlikely((error_num =
12741280
partition_handler->handlers[roop_count]->lock_tables())))
12751281
{
12761282
DBUG_RETURN(error_num);
12771283
}
12781284
}
1279-
} else {
1280-
#endif
1281-
if (unlikely((error_num = lock_tables())))
1282-
{
1283-
DBUG_RETURN(error_num);
1284-
}
1285-
#ifdef WITH_PARTITION_STORAGE_ENGINE
12861285
}
1287-
#endif
1288-
}
1289-
1290-
DBUG_PRINT("info",("spider trx_start=%s",
1291-
trx->trx_start ? "TRUE" : "FALSE"));
1292-
/* need to check after spider_internal_start_trx() */
1293-
if (trx->trx_start)
1294-
{
1295-
switch (wide_handler->sql_command)
1286+
else if (unlikely((error_num= lock_tables())))
12961287
{
1297-
case SQLCOM_SELECT:
1298-
case SQLCOM_HA_READ:
1299-
#ifdef HS_HAS_SQLCOM
1300-
case SQLCOM_HS_READ:
1301-
#endif
1302-
/* nothing to do */
1303-
break;
1304-
case SQLCOM_UPDATE:
1305-
case SQLCOM_UPDATE_MULTI:
1306-
#ifdef HS_HAS_SQLCOM
1307-
case SQLCOM_HS_UPDATE:
1308-
#endif
1309-
case SQLCOM_CREATE_TABLE:
1310-
case SQLCOM_INSERT:
1311-
case SQLCOM_INSERT_SELECT:
1312-
case SQLCOM_DELETE:
1313-
case SQLCOM_LOAD:
1314-
case SQLCOM_REPLACE:
1315-
case SQLCOM_REPLACE_SELECT:
1316-
case SQLCOM_DELETE_MULTI:
1317-
#ifdef HS_HAS_SQLCOM
1318-
case SQLCOM_HS_INSERT:
1319-
case SQLCOM_HS_DELETE:
1320-
#endif
1321-
default:
1322-
trx->updated_in_this_trx = TRUE;
1323-
DBUG_PRINT("info",("spider trx->updated_in_this_trx=TRUE"));
1324-
break;
1288+
DBUG_RETURN(error_num);
13251289
}
13261290
}
1291+
13271292
DBUG_RETURN(0);
13281293
}
13291294

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# MDEV-27239 Spider: Assertion `thd->transaction->stmt.ha_list == __null || trans == &thd->transaction->stmt' failed in ha_commit_trans on BEGIN WORK after FTWRL
3+
#
4+
for master_1
5+
for child2
6+
for child3
7+
CREATE DATABASE auto_test_local;
8+
USE auto_test_local;
9+
CREATE TABLE tbl_a (a INT) ENGINE=SPIDER;
10+
FLUSH TABLE tbl_a WITH READ LOCK;
11+
Warnings:
12+
Error 1429 Unable to connect to foreign data source: localhost
13+
Error 1429 Unable to connect to foreign data source: localhost
14+
Error 1429 Unable to connect to foreign data source: localhost
15+
Error 1429 Unable to connect to foreign data source: localhost
16+
BEGIN;
17+
DROP DATABASE auto_test_local;
18+
for master_1
19+
for child2
20+
for child3
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
!include include/default_mysqld.cnf
2+
!include ../my_1_1.cnf
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--echo #
2+
--echo # MDEV-27239 Spider: Assertion `thd->transaction->stmt.ha_list == __null || trans == &thd->transaction->stmt' failed in ha_commit_trans on BEGIN WORK after FTWRL
3+
--echo #
4+
5+
--disable_query_log
6+
--disable_result_log
7+
--source ../../t/test_init.inc
8+
--enable_result_log
9+
--enable_query_log
10+
11+
CREATE DATABASE auto_test_local;
12+
USE auto_test_local;
13+
14+
CREATE TABLE tbl_a (a INT) ENGINE=SPIDER;
15+
FLUSH TABLE tbl_a WITH READ LOCK;
16+
BEGIN;
17+
18+
DROP DATABASE auto_test_local;
19+
20+
--disable_query_log
21+
--disable_result_log
22+
--source ../../t/test_deinit.inc
23+
--enable_result_log
24+
--enable_query_log

0 commit comments

Comments
 (0)