Skip to content

Commit 9024765

Browse files
author
Jacob Mathew
committed
MDEV-14019: Spider + binlog_format = ROW => CRASH
The crash occurs when inserting into, updating or deleting from Spider system tables. These operations do not go through the normal insert, update or delete logic, so binary logging of the row is not properly set up and leads to the crash. The fix for this problem uses the same strategy as is used for the servers system table that contains entries for the servers created with CREATE SERVER. Binary logging is now temporarily disabled on insert, update and delete operations on Spider system tables. Author: Jacob Mathew. Reviewer: Kentoku Shiba.
1 parent aec4734 commit 9024765

File tree

1 file changed

+97
-70
lines changed

1 file changed

+97
-70
lines changed

storage/spider/spd_sys_table.cc

Lines changed: 97 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,86 @@
3535

3636
extern handlerton *spider_hton_ptr;
3737

38+
/**
39+
Insert a Spider system table row.
40+
41+
@param table The spider system table.
42+
@param do_handle_error TRUE if an error message should be printed
43+
before returning.
44+
45+
@return Error code returned by the write.
46+
*/
47+
48+
inline int spider_write_sys_table_row(TABLE *table, bool do_handle_error = TRUE)
49+
{
50+
int error_num;
51+
THD *thd = table->in_use;
52+
53+
tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */
54+
error_num = table->file->ha_write_row(table->record[0]);
55+
reenable_binlog(thd);
56+
57+
if (error_num && do_handle_error)
58+
table->file->print_error(error_num, MYF(0));
59+
60+
return error_num;
61+
}
62+
63+
/**
64+
Update a Spider system table row.
65+
66+
@param table The spider system table.
67+
68+
@return Error code returned by the update.
69+
*/
70+
71+
inline int spider_update_sys_table_row(TABLE *table)
72+
{
73+
int error_num;
74+
THD *thd = table->in_use;
75+
76+
tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */
77+
error_num = table->file->ha_update_row(table->record[1], table->record[0]);
78+
reenable_binlog(thd);
79+
80+
if (error_num)
81+
{
82+
if (error_num == HA_ERR_RECORD_IS_THE_SAME)
83+
error_num = 0;
84+
else
85+
table->file->print_error(error_num, MYF(0));
86+
}
87+
88+
return error_num;
89+
}
90+
91+
/**
92+
Delete a Spider system table row.
93+
94+
@param table The spider system table.
95+
@param record_number Location of the record: 0 or 1.
96+
@param do_handle_error TRUE if an error message should be printed
97+
before returning.
98+
99+
@return Error code returned by the update.
100+
*/
101+
102+
inline int spider_delete_sys_table_row(TABLE *table, int record_number = 0,
103+
bool do_handle_error = TRUE)
104+
{
105+
int error_num;
106+
THD *thd = table->in_use;
107+
108+
tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */
109+
error_num = table->file->ha_delete_row(table->record[record_number]);
110+
reenable_binlog(thd);
111+
112+
if (error_num && do_handle_error)
113+
table->file->print_error(error_num, MYF(0));
114+
115+
return error_num;
116+
}
117+
38118
#if MYSQL_VERSION_ID < 50500
39119
TABLE *spider_open_sys_table(
40120
THD *thd,
@@ -983,11 +1063,8 @@ int spider_insert_xa(
9831063
table->use_all_columns();
9841064
spider_store_xa_bqual_length(table, xid);
9851065
spider_store_xa_status(table, status);
986-
if ((error_num = table->file->ha_write_row(table->record[0])))
987-
{
988-
table->file->print_error(error_num, MYF(0));
1066+
if ((error_num = spider_write_sys_table_row(table)))
9891067
DBUG_RETURN(error_num);
990-
}
9911068
} else {
9921069
my_message(ER_SPIDER_XA_EXISTS_NUM, ER_SPIDER_XA_EXISTS_STR, MYF(0));
9931070
DBUG_RETURN(ER_SPIDER_XA_EXISTS_NUM);
@@ -1017,11 +1094,8 @@ int spider_insert_xa_member(
10171094
}
10181095
table->use_all_columns();
10191096
spider_store_xa_member_info(table, xid, conn);
1020-
if ((error_num = table->file->ha_write_row(table->record[0])))
1021-
{
1022-
table->file->print_error(error_num, MYF(0));
1097+
if ((error_num = spider_write_sys_table_row(table)))
10231098
DBUG_RETURN(error_num);
1024-
}
10251099
} else {
10261100
my_message(ER_SPIDER_XA_MEMBER_EXISTS_NUM, ER_SPIDER_XA_MEMBER_EXISTS_STR,
10271101
MYF(0));
@@ -1051,11 +1125,8 @@ int spider_insert_tables(
10511125
SPIDER_LINK_STATUS_NO_CHANGE ?
10521126
share->alter_table.tmp_link_statuses[roop_count] :
10531127
SPIDER_LINK_STATUS_OK);
1054-
if ((error_num = table->file->ha_write_row(table->record[0])))
1055-
{
1056-
table->file->print_error(error_num, MYF(0));
1128+
if ((error_num = spider_write_sys_table_row(table)))
10571129
DBUG_RETURN(error_num);
1058-
}
10591130
}
10601131

10611132
DBUG_RETURN(0);
@@ -1077,11 +1148,8 @@ int spider_log_tables_link_failed(
10771148
if (table->field[3] == table->timestamp_field)
10781149
table->timestamp_field->set_time();
10791150
#endif
1080-
if ((error_num = table->file->ha_write_row(table->record[0])))
1081-
{
1082-
table->file->print_error(error_num, MYF(0));
1151+
if ((error_num = spider_write_sys_table_row(table)))
10831152
DBUG_RETURN(error_num);
1084-
}
10851153
DBUG_RETURN(0);
10861154
}
10871155

@@ -1115,11 +1183,8 @@ int spider_log_xa_failed(
11151183
if (table->field[20] == table->timestamp_field)
11161184
table->timestamp_field->set_time();
11171185
#endif
1118-
if ((error_num = table->file->ha_write_row(table->record[0])))
1119-
{
1120-
table->file->print_error(error_num, MYF(0));
1186+
if ((error_num = spider_write_sys_table_row(table)))
11211187
DBUG_RETURN(error_num);
1122-
}
11231188
DBUG_RETURN(0);
11241189
}
11251190

@@ -1148,14 +1213,8 @@ int spider_update_xa(
11481213
store_record(table, record[1]);
11491214
table->use_all_columns();
11501215
spider_store_xa_status(table, status);
1151-
if (
1152-
(error_num = table->file->ha_update_row(
1153-
table->record[1], table->record[0])) &&
1154-
error_num != HA_ERR_RECORD_IS_THE_SAME
1155-
) {
1156-
table->file->print_error(error_num, MYF(0));
1216+
if ((error_num = spider_update_sys_table_row(table)))
11571217
DBUG_RETURN(error_num);
1158-
}
11591218
}
11601219

11611220
DBUG_RETURN(0);
@@ -1188,14 +1247,8 @@ int spider_update_tables_name(
11881247
store_record(table, record[1]);
11891248
table->use_all_columns();
11901249
spider_store_tables_name(table, to, strlen(to));
1191-
if (
1192-
(error_num = table->file->ha_update_row(
1193-
table->record[1], table->record[0])) &&
1194-
error_num != HA_ERR_RECORD_IS_THE_SAME
1195-
) {
1196-
table->file->print_error(error_num, MYF(0));
1250+
if ((error_num = spider_update_sys_table_row(table)))
11971251
DBUG_RETURN(error_num);
1198-
}
11991252
}
12001253
roop_count++;
12011254
}
@@ -1239,11 +1292,8 @@ int spider_update_tables_priority(
12391292
SPIDER_LINK_STATUS_NO_CHANGE ?
12401293
alter_table->tmp_link_statuses[roop_count] :
12411294
SPIDER_LINK_STATUS_OK);
1242-
if ((error_num = table->file->ha_write_row(table->record[0])))
1243-
{
1244-
table->file->print_error(error_num, MYF(0));
1295+
if ((error_num = spider_write_sys_table_row(table)))
12451296
DBUG_RETURN(error_num);
1246-
}
12471297
roop_count++;
12481298
} while (roop_count < (int) alter_table->all_link_count);
12491299
DBUG_RETURN(0);
@@ -1259,14 +1309,8 @@ int spider_update_tables_priority(
12591309
spider_store_tables_connect_info(table, alter_table, roop_count);
12601310
spider_store_tables_link_status(table,
12611311
alter_table->tmp_link_statuses[roop_count]);
1262-
if (
1263-
(error_num = table->file->ha_update_row(
1264-
table->record[1], table->record[0])) &&
1265-
error_num != HA_ERR_RECORD_IS_THE_SAME
1266-
) {
1267-
table->file->print_error(error_num, MYF(0));
1312+
if ((error_num = spider_update_sys_table_row(table)))
12681313
DBUG_RETURN(error_num);
1269-
}
12701314
}
12711315
}
12721316
while (TRUE)
@@ -1284,11 +1328,8 @@ int spider_update_tables_priority(
12841328
table->file->print_error(error_num, MYF(0));
12851329
DBUG_RETURN(error_num);
12861330
}
1287-
if ((error_num = table->file->ha_delete_row(table->record[0])))
1288-
{
1289-
table->file->print_error(error_num, MYF(0));
1331+
if ((error_num = spider_delete_sys_table_row(table)))
12901332
DBUG_RETURN(error_num);
1291-
}
12921333
}
12931334
roop_count++;
12941335
}
@@ -1324,14 +1365,8 @@ int spider_update_tables_link_status(
13241365
store_record(table, record[1]);
13251366
table->use_all_columns();
13261367
spider_store_tables_link_status(table, link_status);
1327-
if (
1328-
(error_num = table->file->ha_update_row(
1329-
table->record[1], table->record[0])) &&
1330-
error_num != HA_ERR_RECORD_IS_THE_SAME
1331-
) {
1332-
table->file->print_error(error_num, MYF(0));
1368+
if ((error_num = spider_update_sys_table_row(table)))
13331369
DBUG_RETURN(error_num);
1334-
}
13351370
}
13361371

13371372
DBUG_RETURN(0);
@@ -1358,11 +1393,8 @@ int spider_delete_xa(
13581393
MYF(0));
13591394
DBUG_RETURN(ER_SPIDER_XA_NOT_EXISTS_NUM);
13601395
} else {
1361-
if ((error_num = table->file->ha_delete_row(table->record[0])))
1362-
{
1363-
table->file->print_error(error_num, MYF(0));
1396+
if ((error_num = spider_delete_sys_table_row(table)))
13641397
DBUG_RETURN(error_num);
1365-
}
13661398
}
13671399

13681400
DBUG_RETURN(0);
@@ -1389,7 +1421,7 @@ int spider_delete_xa_member(
13891421
DBUG_RETURN(0);
13901422
} else {
13911423
do {
1392-
if ((error_num = table->file->ha_delete_row(table->record[0])))
1424+
if ((error_num = spider_delete_sys_table_row(table, 0, FALSE)))
13931425
{
13941426
spider_sys_index_end(table);
13951427
table->file->print_error(error_num, MYF(0));
@@ -1424,11 +1456,8 @@ int spider_delete_tables(
14241456
if ((error_num = spider_check_sys_table(table, table_key)))
14251457
break;
14261458
else {
1427-
if ((error_num = table->file->ha_delete_row(table->record[0])))
1428-
{
1429-
table->file->print_error(error_num, MYF(0));
1459+
if ((error_num = spider_delete_sys_table_row(table)))
14301460
DBUG_RETURN(error_num);
1431-
}
14321461
}
14331462
roop_count++;
14341463
}
@@ -2305,7 +2334,7 @@ int spider_sys_replace(
23052334
char table_key[MAX_KEY_LENGTH];
23062335
DBUG_ENTER("spider_sys_replace");
23072336

2308-
while ((error_num = table->file->ha_write_row(table->record[0])))
2337+
while ((error_num = spider_write_sys_table_row(table, FALSE)))
23092338
{
23102339
if (
23112340
table->file->is_fatal_error(error_num, HA_CHECK_DUP) ||
@@ -2357,13 +2386,11 @@ int spider_sys_replace(
23572386
last_uniq_key &&
23582387
!table->file->referenced_by_foreign_key()
23592388
) {
2360-
error_num = table->file->ha_update_row(table->record[1],
2361-
table->record[0]);
2362-
if (error_num && error_num != HA_ERR_RECORD_IS_THE_SAME)
2389+
if ((error_num = spider_update_sys_table_row(table)))
23632390
goto error;
23642391
DBUG_RETURN(0);
23652392
} else {
2366-
if ((error_num = table->file->ha_delete_row(table->record[1])))
2393+
if ((error_num = spider_delete_sys_table_row(table, 1, FALSE)))
23672394
goto error;
23682395
*modified_non_trans_table = TRUE;
23692396
}

0 commit comments

Comments
 (0)