Skip to content

Commit 85378f0

Browse files
author
Souvik Pal
committed
WL#15280: HEATWAVE SUPPORT FOR MDS HA
# This is the 1st commit message: WL#15280: HEATWAVE SUPPORT FOR MDS HA Problem Statement ----------------- Currently customers cannot enable heatwave analytics service to their HA DBSystem or enable HA if they are using Heatwave enabled DBSystem. In this change, we attempt to remove this limitation and provide failover support of heatwave in an HA enabled DBSystem. High Level Overview ------------------- To support heatwave with HA, we extended the existing feature of auto- reloading of tables to heatwave on MySQL server restart (WL-14396). To provide seamless failover functionality to tables loaded to heatwave, each node in the HA cluster (group replication) must have the latest view of tables which are currently loaded to heatwave cluster attached to the primary, i.e., the secondary_load flag should be in-sync always. To achieve this, we made following changes - 1. replicate secondary load/unload DDL statements to all the active secondary nodes by writing the DDL into the binlog, and 2. Control how secondary load/unload is executed when heatwave cluster is not attached to node executing the command Implementation Details ---------------------- Current implementation depends on two key assumptions - 1. All MDS DBSystems will have RAPID plugin installed. 2. No non-MDS system will have the RAPID plugin installed. Based on these assumptions, we made certain changes w.r.t. how server handles execution of secondary load/unload statements. 1. If secondary load/unload command is executed from a mysql client session on a system without RAPID plugin installed (i.e., non-MDS), instead of an error, a warning message will be shown to the user, and the DDL is allowed to commit. 2. If secondary load/unload command is executed from a replication connection on an MDS system without heatwave cluster attached, instead of throwing an error, the DDL is allowed to commit. 3. If no error is thrown from secondary engine, then the DDL will update the secondary_load metadata and write a binlog entry. Writing to binlog implies that all the consumer of binlog now need to handle this DDL gracefully. This has an adverse effect on Point-in-time Recovery. If the PITR backup is taken from a DBSystem with heatwave, it may contain traces of secondary load/unload statements in its binlog. If such a backup is used to restore a new DBSystem, it will cause failure while trying to execute statements from its binlog because a) DBSystem will not heatwave cluster attached at this time, and b) Statements from binlog are executed from standard mysql client connection, thus making them indistinguishable from user executed command. Customers will be prevented (by control plane) from using PITR functionality on a heatwave enabled DBSystem until there is a solution for this. Testing ------- This commit changes the behavior of secondary load/unload statements, so it - adjusts existing tests' expectations, and - adds a new test validating new DDL behavior under different scenarios Change-Id: Ief7e9b3d4878748b832c366da02892917dc47d83 # This is the commit message #2: WL#15280: HEATWAVE SUPPORT FOR MDS HA (PITR SUPPORT) Problem ------- A PITR backup taken from a heatwave enabled system could have traces of secondary load or unload statements in binlog. When such a backup is used to restore another system, it can cause failure because of following two reasons: 1. Currently, even if the target system is heatwave enabled, heatwave cluster is attached only after PITR restore phase completes. 2. When entries from binlogs are applied, a standard mysql client connection is used. This makes it indistinguishable from other user session. Since secondary load (or unload) statements are meant to throw error when they are executed by user in the absence of a healthy heatwave cluster, PITR restore workflow will fail if binlogs from the backup have any secondary load (or unload) statements in them. Solution -------- To avoid PITR failure, we are introducing a new system variable rapid_enable_delayed_secondary_ops. It controls how load or unload commands are to be processed by rapid plugin. - When turned ON, the plugin silently skips the secondary engine operation (load/unload) and returns success to the caller. This allows secondary load (or unload) statements to be executed by the server in the absence of any heatwave cluster. - When turned OFF, it follows the existing behavior. - The default value is OFF. - The value can only be changed when rapid_bootstrap is IDLE or OFF. - This variable cannot be persisted. In PITR workflow, Control Plane would set the variable at the start of PITR restore and then reset it at the end of workflow. This allows the workflow to complete without failure even when heatwave cluster is not attached. Since metadata is always updated when secondary load/unload DDLs are executed, when heatwave cluster is attached at a later point in time, the respective tables get reloaded to heatwave automatically. Change-Id: I42e984910da23a0e416edb09d3949989159ef707 # This is the commit message mysql#3: WL#15280: HEATWAVE SUPPORT FOR MDS HA (TEST CHANGES) This commit adds new functional tests for the MDS HA + HW integration. Change-Id: Ic818331a4ca04b16998155efd77ac95da08deaa1 # This is the commit message mysql#4: WL#15280: HEATWAVE SUPPORT FOR MDS HA BUG#34776485: RESTRICT DEFAULT VALUE FOR rapid_enable_delayed_secondary_ops This commit does two things: 1. Add a basic test for newly introduced system variable rapid_enable_delayed_secondary_ops, which controls the behavior of alter table secondary load/unload ddl statements when rapid cluster is not available. 2. It also restricts the DEFAULT value setting for the system variable So, following is not allowed: SET GLOBAL rapid_enable_delayed_secondary_ops = default This variable is to be used in restricted scenarios and control plane only sets it to ON/OFF before and after PITR apply. Allowing set to default has no practical use. Change-Id: I85c84dfaa0f868dbfc7b1a88792a89ffd2e81da2 # This is the commit message mysql#5: Bug#34726490: ADD DIAGNOSTICS FOR SECONDARY LOAD / UNLOAD DDL Problem: -------- If secondary load or unload DDL gets rolled back due to some error after it had loaded / unloaded the table in heatwave cluster, there is no undo of the secondary engine action. Only secondary_load flag update is reverted and binlog is not written. From User's perspective, the table is loaded and can be seen on performance_schema. There are also no error messages printed to notify that the ddl didn't commit. This creates a problem to debug any issue in this area. Solution: --------- The partial undo of secondary load/unload ddl will be handled in bug#34592922. In this commit, we add diagnostics to reveal if the ddl failed to commit, and from what stage. Change-Id: I46c04dd5dbc07fc17beb8aa2a8d0b15ddfa171af # This is the commit message mysql#6: WL#15280: HEATWAVE SUPPORT FOR MDS HA (TEST FIX) Since ALTER TABLE SECONDARY LOAD / UNLOAD DDL statements now write to binlog, from Heatwave's perspective, SCN is bumped up. In this commit, we are adjusting expected SCN values in certain tests which does secondary load/unload and expects SCN to match. Change-Id: I9635b3cd588d01148d763d703c72cf50a0c0bb98 # This is the commit message mysql#7: Adding MTR tests for ML in rapid group_replication suite Added MTR tests with Heatwave ML queries with in an HA setup. Change-Id: I386a3530b5bbe6aea551610b6e739ab1cf366439 # This is the commit message mysql#8: WL#15280: HEATWAVE SUPPORT FOR MDS HA (MTR TEST ADJUSTMENT) In this commit we have adjusted the existing test to work with the new MTR test infrastructure which extends the functionalities to HA landscape. With this change, a lot of mannual settings have now become redundant and thus removed in this commit. Change-Id: Ie1f4fcfdf047bfe8638feaa9f54313d509cbad7e # This is the commit message mysql#9: WL#15280: HEATWAVE SUPPORT FOR MDS HA (CLANG-TIDY FIX) Fix clang-tidy warnings found in previous change#16530, patch#20 Change-Id: I15d25df135694c2f6a3a9146feebe2b981637662 Change-Id: I3f3223a85bb52343a4619b0c2387856b09438265
1 parent a270236 commit 85378f0

File tree

7 files changed

+94
-119
lines changed

7 files changed

+94
-119
lines changed

mysql-test/suite/rpl/include/rpl_secondary_engine_load.inc

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ ALTER TABLE t1 SECONDARY_LOAD;
6868
--source include/sync_slave_sql_with_master.inc
6969
--echo [ Connection Slave ]
7070

71-
# Check that SECONDARY_LOAD was not propagated and that the table has not been
72-
# loaded into its secondary engine.
73-
FLUSH STATUS;
74-
SELECT * FROM t1;
75-
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
76-
77-
# Load table also on slave.
78-
ALTER TABLE t1 SECONDARY_LOAD;
7971

8072
# Check that the query is offloaded.
8173
FLUSH STATUS;
@@ -150,12 +142,6 @@ ALTER TABLE t2 SECONDARY_LOAD;
150142
SHOW CREATE TABLE t2;
151143
SHOW CREATE TABLE t3;
152144

153-
FLUSH STATUS;
154-
SELECT * FROM t2;
155-
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
156-
157-
# Load the table on slave.
158-
ALTER TABLE t2 SECONDARY_LOAD;
159145

160146
FLUSH STATUS;
161147
SELECT * FROM t2;
@@ -176,14 +162,6 @@ DROP TABLE t3;
176162
--source include/sync_slave_sql_with_master.inc
177163
--echo [ Connection Slave ]
178164

179-
# Check that SECONDARY_UNLOAD was not propagated and that the table is
180-
# still loaded into its secondary engine.
181-
FLUSH STATUS;
182-
SELECT * FROM t1;
183-
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
184-
185-
# Unload table also on slave.
186-
ALTER TABLE t1 SECONDARY_UNLOAD;
187165

188166
# Check that the table is unloaded.
189167
FLUSH STATUS;

mysql-test/suite/rpl/r/rpl_mix_or_row_secondary_engine_load.result

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,6 @@ include/sync_slave_sql_with_master.inc
4747
FLUSH STATUS;
4848
SELECT * FROM t1;
4949
pk vc j b vb
50-
1 Poodle {"key": "value"} Pug 4
51-
2 Labrador [{"key": "value"}, {"key": "value2"}] Boxer ��
52-
3 Beagle [1, 2, 3] Pitbull ��4
53-
4 Collie ["ab", "bc", "cd"] Huskey ���
54-
5 Shiba {"1": "one"} Mastiff ��
55-
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
56-
Variable_name Value
57-
Secondary_engine_execution_count 0
58-
ALTER TABLE t1 SECONDARY_LOAD;
59-
FLUSH STATUS;
60-
SELECT * FROM t1;
61-
pk vc j b vb
6250
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
6351
Variable_name Value
6452
Secondary_engine_execution_count 1
@@ -172,18 +160,6 @@ t3 CREATE TABLE `t3` (
172160
FLUSH STATUS;
173161
SELECT * FROM t2;
174162
pk vc j b vb
175-
1 Poodle {"key": "value"} Pug 4
176-
2 Labrador [{"key": "value"}, {"key": "value2"}] Boxer ��
177-
3 Beagle [1, 2, 3] Pitbull ��4
178-
4 Collie ["ab", "bc", "cd"] Huskey ���
179-
5 Shiba {"1": "one"} Mastiff ��
180-
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
181-
Variable_name Value
182-
Secondary_engine_execution_count 0
183-
ALTER TABLE t2 SECONDARY_LOAD;
184-
FLUSH STATUS;
185-
SELECT * FROM t2;
186-
pk vc j b vb
187163
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
188164
Variable_name Value
189165
Secondary_engine_execution_count 1
@@ -201,13 +177,6 @@ include/sync_slave_sql_with_master.inc
201177
FLUSH STATUS;
202178
SELECT * FROM t1;
203179
pk vc j b vb
204-
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
205-
Variable_name Value
206-
Secondary_engine_execution_count 1
207-
ALTER TABLE t1 SECONDARY_UNLOAD;
208-
FLUSH STATUS;
209-
SELECT * FROM t1;
210-
pk vc j b vb
211180
1 Poodle {"key": "value"} Pug 4
212181
2 Labrador [{"key": "value"}, {"key": "value2"}] Boxer ��
213182
3 Beagle [1, 2, 3] Pitbull ��4
@@ -243,14 +212,9 @@ include/wait_for_slave_param.inc [Slave_SQL_Running_State]
243212
FLUSH STATUS;
244213
SELECT * FROM t2;
245214
pk vc j b vb
246-
1 Poodle {"key": "value"} Pug 4
247-
2 Labrador [{"key": "value"}, {"key": "value2"}] Boxer ��
248-
3 Beagle [1, 2, 3] Pitbull ��4
249-
4 Collie ["ab", "bc", "cd"] Huskey ���
250-
5 Shiba {"1": "one"} Mastiff ��
251215
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
252216
Variable_name Value
253-
Secondary_engine_execution_count 0
217+
Secondary_engine_execution_count 1
254218
[ Connection Master ]
255219
ALTER TABLE t1 SECONDARY_ENGINE=NULL;
256220
include/sync_slave_sql_with_master.inc
@@ -351,14 +315,9 @@ include/wait_for_slave_param.inc [Slave_SQL_Running_State]
351315
FLUSH STATUS;
352316
SELECT * FROM t1;
353317
pk vc j b vb
354-
1 Poodle {"key": "value"} Pug 4
355-
2 Labrador [{"key": "value"}, {"key": "value2"}] Boxer ��
356-
3 Beagle [1, 2, 3] Pitbull ��4
357-
4 Collie ["ab", "bc", "cd"] Huskey ���
358-
5 Shiba {"1": "one"} Mastiff ��
359318
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
360319
Variable_name Value
361-
Secondary_engine_execution_count 0
320+
Secondary_engine_execution_count 1
362321
[ Connection Master ]
363322
DROP TABLE t1;
364323
DROP TABLE t2;

mysql-test/suite/rpl/r/rpl_stmt_secondary_engine_load.result

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,6 @@ include/sync_slave_sql_with_master.inc
4747
FLUSH STATUS;
4848
SELECT * FROM t1;
4949
pk vc j b vb
50-
1 Poodle {"key": "value"} Pug 4
51-
2 Labrador [{"key": "value"}, {"key": "value2"}] Boxer ��
52-
3 Beagle [1, 2, 3] Pitbull ��4
53-
4 Collie ["ab", "bc", "cd"] Huskey ���
54-
5 Shiba {"1": "one"} Mastiff ��
55-
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
56-
Variable_name Value
57-
Secondary_engine_execution_count 0
58-
ALTER TABLE t1 SECONDARY_LOAD;
59-
FLUSH STATUS;
60-
SELECT * FROM t1;
61-
pk vc j b vb
6250
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
6351
Variable_name Value
6452
Secondary_engine_execution_count 1
@@ -172,18 +160,6 @@ t3 CREATE TABLE `t3` (
172160
FLUSH STATUS;
173161
SELECT * FROM t2;
174162
pk vc j b vb
175-
1 Poodle {"key": "value"} Pug 4
176-
2 Labrador [{"key": "value"}, {"key": "value2"}] Boxer ��
177-
3 Beagle [1, 2, 3] Pitbull ��4
178-
4 Collie ["ab", "bc", "cd"] Huskey ���
179-
5 Shiba {"1": "one"} Mastiff ��
180-
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
181-
Variable_name Value
182-
Secondary_engine_execution_count 0
183-
ALTER TABLE t2 SECONDARY_LOAD;
184-
FLUSH STATUS;
185-
SELECT * FROM t2;
186-
pk vc j b vb
187163
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
188164
Variable_name Value
189165
Secondary_engine_execution_count 1
@@ -201,13 +177,6 @@ include/sync_slave_sql_with_master.inc
201177
FLUSH STATUS;
202178
SELECT * FROM t1;
203179
pk vc j b vb
204-
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
205-
Variable_name Value
206-
Secondary_engine_execution_count 1
207-
ALTER TABLE t1 SECONDARY_UNLOAD;
208-
FLUSH STATUS;
209-
SELECT * FROM t1;
210-
pk vc j b vb
211180
1 Poodle {"key": "value"} Pug 4
212181
2 Labrador [{"key": "value"}, {"key": "value2"}] Boxer ��
213182
3 Beagle [1, 2, 3] Pitbull ��4
@@ -243,14 +212,9 @@ include/wait_for_slave_param.inc [Slave_SQL_Running_State]
243212
FLUSH STATUS;
244213
SELECT * FROM t2;
245214
pk vc j b vb
246-
1 Poodle {"key": "value"} Pug 4
247-
2 Labrador [{"key": "value"}, {"key": "value2"}] Boxer ��
248-
3 Beagle [1, 2, 3] Pitbull ��4
249-
4 Collie ["ab", "bc", "cd"] Huskey ���
250-
5 Shiba {"1": "one"} Mastiff ��
251215
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
252216
Variable_name Value
253-
Secondary_engine_execution_count 0
217+
Secondary_engine_execution_count 1
254218
[ Connection Master ]
255219
ALTER TABLE t1 SECONDARY_ENGINE=NULL;
256220
include/sync_slave_sql_with_master.inc
@@ -351,14 +315,9 @@ include/wait_for_slave_param.inc [Slave_SQL_Running_State]
351315
FLUSH STATUS;
352316
SELECT * FROM t1;
353317
pk vc j b vb
354-
1 Poodle {"key": "value"} Pug 4
355-
2 Labrador [{"key": "value"}, {"key": "value2"}] Boxer ��
356-
3 Beagle [1, 2, 3] Pitbull ��4
357-
4 Collie ["ab", "bc", "cd"] Huskey ���
358-
5 Shiba {"1": "one"} Mastiff ��
359318
SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
360319
Variable_name Value
361-
Secondary_engine_execution_count 0
320+
Secondary_engine_execution_count 1
362321
[ Connection Master ]
363322
DROP TABLE t1;
364323
DROP TABLE t2;

mysql-test/suite/secondary_engine/r/define.result

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ DROP TABLE t1;
1010
#
1111
CREATE TABLE t1 (a INT) SECONDARY_ENGINE NONEXISTENT;
1212
ALTER TABLE t1 SECONDARY_LOAD;
13-
ERROR 42000: Unknown storage engine 'NONEXISTENT'
13+
Warnings:
14+
Warning 1286 Unknown storage engine 'NONEXISTENT'
1415
DROP TABLE t1;
1516
#
1617
# Attempt to load table into an unsupported secondary storage engine.

mysql-test/suite/secondary_engine/t/define.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ DROP TABLE t1;
1212
--echo # Attempt to load table into an unknown storage engine.
1313
--echo #
1414
CREATE TABLE t1 (a INT) SECONDARY_ENGINE NONEXISTENT;
15-
--error ER_UNKNOWN_STORAGE_ENGINE
15+
# expect warning
1616
ALTER TABLE t1 SECONDARY_LOAD;
1717
DROP TABLE t1;
1818

sql/sql_class.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,11 @@ class THD : public MDL_context_owner,
18971897
/* MTS: method inserts a new unique name into binlog_updated_dbs */
18981898
void add_to_binlog_accessed_dbs(const char *db);
18991899

1900+
bool is_applier_thread() const {
1901+
return system_thread == SYSTEM_THREAD_SLAVE_SQL ||
1902+
system_thread == SYSTEM_THREAD_SLAVE_WORKER;
1903+
}
1904+
19001905
private:
19011906
std::unique_ptr<Transaction_ctx> m_transaction;
19021907

sql/sql_table.cc

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949
#include "mysql/psi/psi_table.h" // IWYU pragma: keep
5050

5151
/* PSI_TABLE_CALL() with WITH_LOCK_ORDER */
52-
#include "mysql/psi/mysql_table.h" // IWYU pragma: keep
53-
5452
#include "decimal.h"
5553
#include "field_types.h" // enum_field_types
5654
#include "lex_string.h"
@@ -81,6 +79,7 @@
8179
#include "mysql/plugin.h"
8280
#include "mysql/psi/mysql_mutex.h"
8381
#include "mysql/psi/mysql_stage.h"
82+
#include "mysql/psi/mysql_table.h" // IWYU pragma: keep
8483
#include "mysql_com.h"
8584
#include "mysql_time.h"
8685
#include "mysqld_error.h" // ER_*
@@ -2667,8 +2666,10 @@ static bool secondary_engine_load_table(THD *thd, const TABLE &table) {
26672666
ha_resolve_by_name(thd, &table.s->secondary_engine, false);
26682667
if ((plugin == nullptr) || !plugin_is_ready(table.s->secondary_engine,
26692668
MYSQL_STORAGE_ENGINE_PLUGIN)) {
2670-
my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), table.s->secondary_engine.str);
2671-
return true;
2669+
push_warning_printf(
2670+
thd, Sql_condition::SL_WARNING, ER_UNKNOWN_STORAGE_ENGINE,
2671+
ER_THD(thd, ER_UNKNOWN_STORAGE_ENGINE), table.s->secondary_engine.str);
2672+
return false;
26722673
}
26732674

26742675
// The engine must support being used as a secondary engine.
@@ -2730,9 +2731,12 @@ static bool secondary_engine_unload_table(THD *thd, const char *db_name,
27302731
plugin_ref plugin = ha_resolve_by_name(thd, &secondary_engine, false);
27312732
if ((plugin == nullptr) ||
27322733
!plugin_is_ready(secondary_engine, MYSQL_STORAGE_ENGINE_PLUGIN)) {
2733-
if (error_if_not_loaded)
2734-
my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), secondary_engine);
2735-
return error_if_not_loaded;
2734+
if (error_if_not_loaded) {
2735+
push_warning_printf(
2736+
thd, Sql_condition::SL_WARNING, ER_UNKNOWN_STORAGE_ENGINE,
2737+
ER_THD(thd, ER_UNKNOWN_STORAGE_ENGINE), secondary_engine);
2738+
}
2739+
return false;
27362740
}
27372741
handlerton *hton = plugin_data<handlerton *>(plugin);
27382742
if (hton == nullptr) {
@@ -11484,6 +11488,15 @@ bool Sql_cmd_secondary_load_unload::mysql_secondary_load_or_unload(
1148411488
hton->flags & HTON_SUPPORTS_SECONDARY_ENGINE &&
1148511489
hton->post_ddl != nullptr);
1148611490

11491+
// cache table name locally for future use
11492+
const size_t name_len = table_list->db_length +
11493+
table_list->table_name_length +
11494+
5; // for backticks, dot `db`.`tab`
11495+
// allocated on thread, freed-up on thread exit
11496+
char *full_tab_name = (char *)sql_calloc(name_len + 1); // for \0 at the end
11497+
sprintf(full_tab_name, "`%s`.%s`", table_list->db, table_list->table_name);
11498+
full_tab_name[name_len] = '\0'; // may not needed, since inited with 0
11499+
1148711500
dd::cache::Dictionary_client::Auto_releaser releaser(thd->dd_client());
1148811501
dd::Table *table_def = nullptr;
1148911502
if (thd->dd_client()->acquire_for_modification(
@@ -11518,6 +11531,14 @@ bool Sql_cmd_secondary_load_unload::mysql_secondary_load_or_unload(
1151811531
cleanup();
1151911532
});
1152011533

11534+
/* Currently, if the DDL rolls back after completing the secondary engine
11535+
* operation, then during undo only the secondary_flag update is undone, but
11536+
* the secondary engine operation (load/unload) is not undone. This creates
11537+
* a temporary inconsistency in the system where the secondary_load flag is
11538+
* not in sync with the actual status of the table in the secondary engine. */
11539+
11540+
// TODO: undo handling of secondary engine operation
11541+
1152111542
// Load if SECONDARY_LOAD, unload if SECONDARY_UNLOAD
1152211543
const bool is_load = m_alter_info->flags & Alter_info::ALTER_SECONDARY_LOAD;
1152311544

@@ -11540,19 +11561,71 @@ bool Sql_cmd_secondary_load_unload::mysql_secondary_load_or_unload(
1154011561
table_list->table_name, *table_def, true))
1154111562
return true;
1154211563
}
11564+
DBUG_PRINT("sec_load_unload", ("secondary engine %s succeeded for table %s",
11565+
(is_load ? "load" : "unload"), full_tab_name));
11566+
11567+
DBUG_EXECUTE_IF("sim_fail_before_metadata_update", {
11568+
DBUG_PRINT("sec_load_unload", ("Force exit before metadata update"));
11569+
my_error(
11570+
ER_SECONDARY_ENGINE, MYF(0),
11571+
"Simulated failure of sec_{un}load before secondary_load flag update");
11572+
return true;
11573+
});
1154311574

1154411575
// Update the secondary_load flag based on the current operation.
1154511576
if (table_def->options().set("secondary_load", is_load) ||
11546-
thd->dd_client()->update(table_def))
11577+
thd->dd_client()->update(table_def)) {
11578+
LogErr(ERROR_LEVEL, ER_SECONDARY_ENGINE,
11579+
"SECONDARY_LOAD metadata update failed for table %s", full_tab_name);
1154711580
return true;
11581+
}
11582+
11583+
DBUG_PRINT("sec_load_unload", ("secondary_load flag %s for table %s",
11584+
(is_load ? "set" : "reset"), full_tab_name));
11585+
11586+
DBUG_EXECUTE_IF("sim_fail_before_write_bin_log", {
11587+
DBUG_PRINT("sec_load_unload", ("Force exit before binlog write"));
11588+
my_error(ER_SECONDARY_ENGINE, MYF(0),
11589+
"Simulated failure of sec_{un}load before write_bin_log()");
11590+
return true;
11591+
});
11592+
11593+
/* Write binlog to maintain replication consistency. Read-Replica's may not
11594+
* have binlog enabled. write_bin_log API takes care of such cases. */
11595+
if (write_bin_log(thd, true, thd->query().str, thd->query().length, true) !=
11596+
0) {
11597+
LogErr(ERROR_LEVEL, ER_SECONDARY_ENGINE,
11598+
"Unable to write to binlog for alter table %s secondary_%s",
11599+
full_tab_name, (is_load ? "load" : "unload"));
11600+
return true;
11601+
}
11602+
11603+
DBUG_PRINT("sec_load_unload",
11604+
("binlog entry added for alter table %s secondary_%s",
11605+
full_tab_name, (is_load ? "load" : "unload")));
11606+
11607+
DBUG_EXECUTE_IF("sim_fail_after_write_bin_log", {
11608+
DBUG_PRINT("sec_load_unload", ("Force exit after binlog write"));
11609+
my_error(ER_SECONDARY_ENGINE, MYF(0),
11610+
"Simulated failure of sec_{un}load after write_bin_log()");
11611+
return true;
11612+
});
1154811613

1154911614
// Close primary table.
1155011615
close_all_tables_for_name(thd, table_list->table->s, false, nullptr);
1155111616
table_list->table = nullptr;
1155211617

1155311618
// Commit transaction if no errors.
11554-
if (trans_commit_stmt(thd) || trans_commit_implicit(thd)) return true;
11619+
if (trans_commit_stmt(thd) || trans_commit_implicit(thd)) {
11620+
LogErr(ERROR_LEVEL, ER_SECONDARY_ENGINE,
11621+
"Commit failed for alter table %s secondary_%s", full_tab_name,
11622+
(is_load ? "load" : "unload"));
11623+
return true;
11624+
}
1155511625

11626+
DBUG_PRINT("sec_load_unload",
11627+
("commit succeeded for alter table %s secondary_%s", full_tab_name,
11628+
(is_load ? "load" : "unload")));
1155611629
// Transaction committed successfully, no rollback will be necessary.
1155711630
rollback_guard.commit();
1155811631

0 commit comments

Comments
 (0)