Skip to content

Commit 1f1b47e

Browse files
author
Joao Gramacho
committed
Bug#23490641 ASSERTION FAILURE IN 'MYSQL_BIN_LOG::PREPARE()' IF DML IS
PASSED IN --INIT-FILE Problem: In order to avoid polluting the binary log (and generating GTIDs) for MySQL initialization statements, the initialize process was refactored to disable binary logging before processing the compiled statements, and enabling the binary logging again once finishing processing the compiled statements and before processing any file passed as parameter to the initialize process. The change above failed when the script/fill_help_tables.sql is updated with current help script that included a "SET sql_log_bin=0;" on it. Analysis: The MYSQL_BIN_LOG::prepare function has an assertion to ensure that the session sql_log_bin variable is true when a statement are prepared to go to the binary log. The bootstrap function that handle the initialize process started with sql_log_bin = true, but disabled the internal representation of it by resetting the OPTION_BIN_LOG bit from thd->variables.option_bits. The fill_help_tables.sql script is disabling the sql_log_bin session variable and it is compiled into the server code. When the initialize process starts to apply a file passed as parameter, it has the internal representation of the binary logging restored (OPTION_BIN_LOG bit of thd->variables.option_bits) but the sql_log_bin session variable was disabled, making the MYSQL_BIN_LOG::prepare assertion to fail. Fix: The initialize process now will check if binary log is enabled while processing compiled statement. It will disable binary logging on such cases.
1 parent 30d98bb commit 1f1b47e

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

mysql-test/t/initialize_gtid.test

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ CREATE TABLE test.t1(a INT) ENGINE=innodb;
3232
BEGIN;
3333
INSERT INTO test.t1 VALUES (1);
3434
COMMIT;
35+
SET sql_log_bin= 0;
36+
BEGIN;
37+
INSERT INTO test.t1 VALUES (2);
38+
COMMIT;
39+
SET sql_log_bin= 1;
3540
DROP TABLE test.t1;
3641
DROP DATABASE test;
3742
EOF

sql/bootstrap.cc

+22-3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ static void handle_bootstrap_impl(THD *thd)
8888
File_command_iterator file_iter(bootstrap_file, mysql_file_fgets_fn);
8989
Compiled_in_command_iterator comp_iter;
9090
bool has_binlog_option= thd->variables.option_bits & OPTION_BIN_LOG;
91+
int query_source, last_query_source= -1;
9192

9293
thd->thread_stack= (char*) &thd;
9394
thd->security_context()->assign_user(STRING_WITH_LEN("boot"));
@@ -113,7 +114,6 @@ static void handle_bootstrap_impl(THD *thd)
113114
{
114115
int error= 0;
115116
int rc;
116-
int query_source, last_query_source= -1;
117117

118118
rc= Command_iterator::current_iterator->next(query, &error, &query_source);
119119

@@ -133,6 +133,12 @@ static void handle_bootstrap_impl(THD *thd)
133133
thd->variables.option_bits&= ~OPTION_BIN_LOG;
134134
break;
135135
case QUERY_SOURCE_FILE:
136+
/*
137+
Some compiled script might have disable binary logging session
138+
variable during compiled scripts. Enabling it again as it was
139+
enabled before applying the compiled statements.
140+
*/
141+
thd->variables.sql_log_bin= true;
136142
thd->variables.option_bits|= OPTION_BIN_LOG;
137143
break;
138144
default:
@@ -222,16 +228,29 @@ static void handle_bootstrap_impl(THD *thd)
222228

223229
free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
224230
thd->get_transaction()->free_memory(MYF(MY_KEEP_PREALLOC));
231+
232+
/*
233+
If the last statement has enabled the session binary logging while
234+
processing queries that are compiled and must not be binary logged,
235+
we must disable binary logging again.
236+
*/
237+
if (last_query_source == QUERY_SOURCE_COMPILED &&
238+
thd->variables.option_bits & OPTION_BIN_LOG)
239+
thd->variables.option_bits&= ~OPTION_BIN_LOG;
240+
225241
}
226242

227243
Command_iterator::current_iterator->end();
228244

229245
/*
230-
We should re-enable SQL_LOG_BIN session if it was enabled during
231-
bootstrap/initialization.
246+
We should re-enable SQL_LOG_BIN session if it was enabled by default
247+
but disabled during bootstrap/initialization.
232248
*/
233249
if (has_binlog_option)
250+
{
251+
thd->variables.sql_log_bin= true;
234252
thd->variables.option_bits|= OPTION_BIN_LOG;
253+
}
235254

236255
DBUG_VOID_RETURN;
237256
}

0 commit comments

Comments
 (0)