-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PS-9238: Make MySQL 5.7 compatible with CREATE TABLE AS SELECT [...] START TRANSACTION to improve 8.0 -> 5.7 replication reliability #5362
base: 8.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
include/assert.inc [ctas_compatibility_mode default should be OFF] | ||
SET GLOBAL ctas_compatibility_mode = ON; | ||
ERROR HY000: Variable 'ctas_compatibility_mode' is a read only variable | ||
CREATE TABLE t1 (a int); | ||
INSERT INTO t1 VALUES (0); | ||
# restart: --ctas-compatibility-mode=ON --log-bin=ctas_binlog | ||
CREATE TABLE t2 AS SELECT * FROM t1; | ||
# restart: | ||
include/assert_grep.inc ["Checking if ctas_compatibility_mode works"] | ||
include/assert_grep.inc ["Checking if rows are inserted as the separate transaction"] | ||
DROP TABLE t1, t2; | ||
include/rpl_init.inc [topology=1->2] | ||
Warnings: | ||
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure. | ||
Note #### Storing MySQL user name or password information in the connection metadata repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START REPLICA; see the 'START REPLICA Syntax' in the MySQL Manual for more information. | ||
CREATE TABLE t1 (a int); | ||
INSERT INTO t1 VALUES (0); | ||
include/rpl_sync.inc | ||
[connection server_2] | ||
include/rpl_restart_server.inc [server_number=2 parameters: --ctas-compatibility-mode=ON --log-bin=ctas_binlog] | ||
include/rpl_start_slaves.inc | ||
[connection server_1] | ||
CREATE TABLE t2 AS SELECT * FROM t1; | ||
include/rpl_sync.inc | ||
[connection server_2] | ||
include/rpl_restart_server.inc [server_number=2] | ||
include/rpl_start_slaves.inc | ||
[connection server_2] | ||
include/assert_grep.inc ["Checking if ctas_compatibility_mode works on replica"] | ||
include/assert_grep.inc ["Checking if rows are inserted as the separate transaction on replica"] | ||
[connection server_1] | ||
DROP TABLE t1, t2; | ||
include/rpl_end.inc |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# | ||
# The default is OFF | ||
# | ||
--let $assert_text= ctas_compatibility_mode default should be OFF | ||
--let $assert_cond= "[SHOW GLOBAL VARIABLES LIKE "ctas_compatibility_mode", Value, 1]" = "OFF" | ||
--source include/assert.inc | ||
|
||
# | ||
# Check that it is read-only | ||
# | ||
--error ER_INCORRECT_GLOBAL_LOCAL_VAR | ||
SET GLOBAL ctas_compatibility_mode = ON; | ||
|
||
# | ||
# Check that compatibility mode works | ||
# | ||
CREATE TABLE t1 (a int); | ||
INSERT INTO t1 VALUES (0); | ||
|
||
--let $binlog_file = ctas_binlog | ||
--let $restart_parameters = "restart: --ctas-compatibility-mode=ON --log-bin=$binlog_file" | ||
--source include/restart_mysqld.inc | ||
|
||
CREATE TABLE t2 AS SELECT * FROM t1; | ||
|
||
--let $restart_parameters = "restart:" | ||
--source include/restart_mysqld.inc | ||
|
||
let $MYSQLD_DATADIR= `select @@datadir;`; | ||
--exec $MYSQL_BINLOG --verbose $MYSQLD_DATADIR/$binlog_file.000001 > $MYSQLTEST_VARDIR/tmp/$binlog_file.sql | ||
--let $assert_file = $MYSQLTEST_VARDIR/tmp/$binlog_file.sql | ||
--let $assert_text = "Checking if ctas_compatibility_mode works" | ||
--let $assert_select = START TRANSACTION | ||
--let $assert_count = 0 | ||
--source include/assert_grep.inc | ||
|
||
--let $assert_text = "Checking if rows are inserted as the separate transaction" | ||
--let $assert_select = BEGIN | ||
--let $assert_count = 1 | ||
--source include/assert_grep.inc | ||
|
||
# cleanup | ||
DROP TABLE t1, t2; | ||
--remove_file $MYSQLD_DATADIR/$binlog_file.000001 | ||
--remove_file $MYSQLTEST_VARDIR/tmp/$binlog_file.sql | ||
|
||
|
||
# | ||
# Check the behavior of replica started with ctas_compatibility_mode enabled | ||
# | ||
--let $rpl_topology = 1->2 | ||
--source include/rpl_init.inc | ||
CREATE TABLE t1 (a int); | ||
INSERT INTO t1 VALUES (0); | ||
--source include/rpl_sync.inc | ||
|
||
# Now restart replica with ctas-compatibility-mode=ON and a custom binlog file | ||
--let $rpl_connection_name = server_2 | ||
--source include/rpl_connection.inc | ||
--let $binlog_file = ctas_binlog | ||
--let $rpl_server_parameters = --ctas-compatibility-mode=ON --log-bin=$binlog_file | ||
--let $rpl_server_number = 2 | ||
--source include/rpl_restart_server.inc | ||
--source include/rpl_start_slaves.inc | ||
|
||
# Execute CTAS on source server | ||
--let $rpl_connection_name = server_1 | ||
--source include/rpl_connection.inc | ||
CREATE TABLE t2 AS SELECT * FROM t1; | ||
--source include/rpl_sync.inc | ||
|
||
# Restart replica with the default parameters | ||
--let $rpl_connection_name = server_2 | ||
--source include/rpl_connection.inc | ||
--let $rpl_server_parameters = | ||
--let $rpl_server_number = 2 | ||
--source include/rpl_restart_server.inc | ||
--source include/rpl_start_slaves.inc | ||
|
||
# We expect that replica started with --ctas-compatibility-mode=ON behaved accordingly | ||
--let $rpl_connection_name = server_2 | ||
--source include/rpl_connection.inc | ||
let $MYSQLD_DATADIR= `select @@datadir;`; | ||
--exec $MYSQL_BINLOG --verbose $MYSQLD_DATADIR/$binlog_file.000001 > $MYSQLTEST_VARDIR/tmp/$binlog_file.sql | ||
--let $assert_file = $MYSQLTEST_VARDIR/tmp/$binlog_file.sql | ||
--let $assert_text = "Checking if ctas_compatibility_mode works on replica" | ||
--let $assert_select = START TRANSACTION | ||
--let $assert_count = 0 | ||
--source include/assert_grep.inc | ||
|
||
--let $assert_text = "Checking if rows are inserted as the separate transaction on replica" | ||
--let $assert_select = BEGIN | ||
--let $assert_count = 1 | ||
--source include/assert_grep.inc | ||
|
||
# cleanup | ||
--remove_file $MYSQLD_DATADIR/$binlog_file.000001 | ||
--remove_file $MYSQLTEST_VARDIR/tmp/$binlog_file.sql | ||
|
||
--let $rpl_connection_name = server_1 | ||
--source include/rpl_connection.inc | ||
DROP TABLE t1, t2; | ||
|
||
--source include/rpl_end.inc |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3039,8 +3039,9 @@ int Query_result_create::binlog_show_create_table(THD *thd) { | |||||||||
|
||||||||||
bool is_trans = false; | ||||||||||
bool direct = true; | ||||||||||
if (get_default_handlerton(thd, thd->lex->create_info->db_type)->flags & | ||||||||||
HTON_SUPPORTS_ATOMIC_DDL) { | ||||||||||
if ((get_default_handlerton(thd, thd->lex->create_info->db_type)->flags & | ||||||||||
HTON_SUPPORTS_ATOMIC_DDL) && | ||||||||||
Comment on lines
+3042
to
+3043
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
!opt_ctas_compatibility_mode) { | ||||||||||
is_trans = true; | ||||||||||
direct = false; | ||||||||||
} | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2363,7 +2363,8 @@ bool store_create_info(THD *thd, Table_ref *table_list, String *packet, | |||||
This is done only while binlogging CREATE TABLE AS SELECT. | ||||||
*/ | ||||||
if (!thd->lex->query_block->field_list_is_empty() && | ||||||
(create_info_arg->db_type->flags & HTON_SUPPORTS_ATOMIC_DDL)) { | ||||||
(create_info_arg->db_type->flags & HTON_SUPPORTS_ATOMIC_DDL) && | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
!opt_ctas_compatibility_mode) { | ||||||
packet->append(STRING_WITH_LEN(" START TRANSACTION")); | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10396,8 +10396,23 @@ bool mysql_create_table(THD *thd, Table_ref *create_table, | |||||
} | ||||||
} | ||||||
} else { | ||||||
result = write_bin_log(thd, true, thd->query().str, thd->query().length, | ||||||
is_trans); | ||||||
/* | ||||||
We can get here from replica thread executing | ||||||
CREATE TABLE ... START TRANSACTION. If ctas_compatibility_mode==true | ||||||
we follow the right path because of create_info->m_transactional_ddl | ||||||
being set properly to false in | ||||||
PT_create_start_transaction_option::contextualize(), but we need to | ||||||
remove START TRANSACTION clause from the query before binlogging it. | ||||||
*/ | ||||||
size_t query_length = thd->query().length; | ||||||
if (opt_ctas_compatibility_mode) { | ||||||
const char *pos = strstr(thd->query().str, "START TRANSACTION"); | ||||||
if (pos != nullptr) { | ||||||
query_length = pos - thd->query().str; | ||||||
} | ||||||
} | ||||||
result = | ||||||
write_bin_log(thd, true, thd->query().str, query_length, is_trans); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4292,6 +4292,13 @@ static Sys_var_int32 Sys_regexp_stack_limit( | |
GLOBAL_VAR(opt_regexp_stack_limit), CMD_LINE(REQUIRED_ARG), | ||
VALID_RANGE(0, INT32_MAX), DEFAULT(8000000), BLOCK_SIZE(1)); | ||
|
||
static Sys_var_bool Sys_ctas_compatibility_mode( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"ctas_compatibility_mode", | ||
"Execute and binlog CTAS in pre 8.0.21 way, i.e. with intermediate commit " | ||
"after the table creation.", | ||
READ_ONLY GLOBAL_VAR(opt_ctas_compatibility_mode), CMD_LINE(OPT_ARG), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
DEFAULT(false)); | ||
|
||
static Sys_var_bool Sys_replica_compressed_protocol( | ||
"replica_compressed_protocol", | ||
"Use compression in the source/replica protocol.", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
method
contextualize
can be made const