1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

BUG#39934: Slave stops for engine that only support row-based logging

General overview:
The logic for switching to row format when binlog_format=MIXED had
numerous flaws. The underlying problem was the lack of a consistent
architecture.
General purpose of this changeset:
This changeset introduces an architecture for switching to row format
when binlog_format=MIXED. It enforces the architecture where it has
to. It leaves some bugs to be fixed later. It adds extensive tests to
verify that unsafe statements work as expected and that appropriate
errors are produced by problems with the selection of binlog format.
It was not practical to split this into smaller pieces of work.

Problem 1:
To determine the logging mode, the code has to take several parameters
into account (namely: (1) the value of binlog_format; (2) the
capabilities of the engines; (3) the type of the current statement:
normal, unsafe, or row injection). These parameters may conflict in
several ways, namely:
 - binlog_format=STATEMENT for a row injection
 - binlog_format=STATEMENT for an unsafe statement
 - binlog_format=STATEMENT for an engine only supporting row logging
 - binlog_format=ROW for an engine only supporting statement logging
 - statement is unsafe and engine does not support row logging
 - row injection in a table that does not support statement logging
 - statement modifies one table that does not support row logging and
   one that does not support statement logging
Several of these conflicts were not detected, or were detected with
an inappropriate error message. The problem of BUG#39934 was that no
appropriate error message was written for the case when an engine
only supporting row logging executed a row injection with
binlog_format=ROW. However, all above cases must be handled.
Fix 1:
Introduce new error codes (sql/share/errmsg.txt). Ensure that all
conditions are detected and handled in decide_logging_format()

Problem 2:
The binlog format shall be determined once per statement, in
decide_logging_format(). It shall not be changed before or after that.
Before decide_logging_format() is called, all information necessary to
determine the logging format must be available. This principle ensures
that all unsafe statements are handled in a consistent way.
However, this principle is not followed:
thd->set_current_stmt_binlog_row_based_if_mixed() is called in several
places, including from code executing UPDATE..LIMIT,
INSERT..SELECT..LIMIT, DELETE..LIMIT, INSERT DELAYED, and
SET @@binlog_format. After Problem 1 was fixed, that caused
inconsistencies where these unsafe statements would not print the
appropriate warnings or errors for some of the conflicts.
Fix 2:
Remove calls to THD::set_current_stmt_binlog_row_based_if_mixed() from
code executed after decide_logging_format(). Compensate by calling the
set_current_stmt_unsafe() at parse time. This way, all unsafe statements
are detected by decide_logging_format().

Problem 3:
INSERT DELAYED is not unsafe: it is logged in statement format even if
binlog_format=MIXED, and no warning is printed even if
binlog_format=STATEMENT. This is BUG#45825.
Fix 3:
Made INSERT DELAYED set itself to unsafe at parse time. This allows
decide_logging_format() to detect that a warning should be printed or
the binlog_format changed.

Problem 4:
LIMIT clause were not marked as unsafe when executed inside stored
functions/triggers/views/prepared statements. This is
BUG#45785.
Fix 4:
Make statements containing the LIMIT clause marked as unsafe at
parse time, instead of at execution time. This allows propagating
unsafe-ness to the view.
This commit is contained in:
Sven Sandberg
2009-07-14 21:31:19 +02:00
parent 81b5a391b0
commit f3985c649d
110 changed files with 4967 additions and 6362 deletions

View File

@ -1254,6 +1254,7 @@ public:
/* Used to execute base64 coded binlog events in MySQL server */
Relay_log_info* rli_fake;
void reset_for_next_command();
/*
Constant for THD::where initialization in the beginning of every query.
@ -1421,23 +1422,44 @@ public:
int binlog_flush_pending_rows_event(bool stmt_end);
int binlog_remove_pending_rows_event(bool clear_maps);
int is_current_stmt_binlog_format_row() {
DBUG_ASSERT(current_stmt_binlog_format == BINLOG_FORMAT_STMT ||
current_stmt_binlog_format == BINLOG_FORMAT_ROW);
return current_stmt_binlog_format == BINLOG_FORMAT_ROW;
}
private:
/*
Tells if current statement should binlog row-based(1) or stmt-based(0)
*/
enum_binlog_format current_stmt_binlog_format;
enum enum_binlog_warning_flag {
/* ER_BINLOG_UNSAFE_AND_STMT_ENGINE affects current stmt */
BINLOG_WARNING_FLAG_UNSAFE_AND_STMT_ENGINE = 0,
/* ER_BINLOG_UNSAFE_AND_STMT_MODE affects current stmt */
BINLOG_WARNING_FLAG_UNSAFE_AND_STMT_MODE,
/* One of the warnings has already been printed */
BINLOG_WARNING_FLAG_PRINTED,
/* number of elements of this enum; insert new members above */
BINLOG_WARNING_FLAG_COUNT
};
/**
Flags holding the status of binlog-related warnings for the
current statement. This is a binary combination of (1<<flag),
where flag is a member of @c enum_binlog_warning_flag.
The warnings are determined in @c THD::decide_logging_format, but
issued only later, after the statement has been written to the
binlog. Hence it must be stored in the @c THD object.
*/
uint32 binlog_warning_flags;
/*
Number of outstanding table maps, i.e., table maps in the
transaction cache.
*/
uint binlog_table_maps;
enum enum_binlog_flag {
BINLOG_FLAG_UNSAFE_STMT_PRINTED,
BINLOG_FLAG_COUNT
};
/**
Flags with per-thread information regarding the status of the
binary log.
*/
uint32 binlog_flags;
public:
uint get_binlog_table_maps() const {
return binlog_table_maps;
@ -1749,8 +1771,6 @@ public:
char scramble[SCRAMBLE_LENGTH+1];
bool slave_thread, one_shot_set;
/* tells if current statement should binlog row-based(1) or stmt-based(0) */
bool current_stmt_binlog_row_based;
bool locked, some_tables_deleted;
bool last_cuted_field;
bool no_errors, password;
@ -1902,21 +1922,12 @@ public:
#ifndef MYSQL_CLIENT
enum enum_binlog_query_type {
/*
The query can be logged row-based or statement-based
*/
/* The query can be logged in row format or in statement format. */
ROW_QUERY_TYPE,
/*
The query has to be logged statement-based
*/
/* The query has to be logged in statement format. */
STMT_QUERY_TYPE,
/*
The query represents a change to a table in the "mysql"
database and is currently mapped to ROW_QUERY_TYPE.
*/
MYSQL_QUERY_TYPE,
QUERY_TYPE_COUNT
};
@ -2120,8 +2131,13 @@ public:
void set_n_backup_active_arena(Query_arena *set, Query_arena *backup);
void restore_active_arena(Query_arena *set, Query_arena *backup);
/*
@todo Make these methods private or remove them completely. Only
decide_logging_format should call them. /Sven
*/
inline void set_current_stmt_binlog_row_based_if_mixed()
{
DBUG_ENTER("set_current_stmt_binlog_row_based_if_mixed");
/*
If in a stored/function trigger, the caller should already have done the
change. We test in_sub_stmt to prevent introducing bugs where people
@ -2133,18 +2149,25 @@ public:
*/
if ((variables.binlog_format == BINLOG_FORMAT_MIXED) &&
(in_sub_stmt == 0))
current_stmt_binlog_row_based= TRUE;
current_stmt_binlog_format= BINLOG_FORMAT_ROW;
DBUG_VOID_RETURN;
}
inline void set_current_stmt_binlog_row_based()
{
current_stmt_binlog_row_based= TRUE;
DBUG_ENTER("set_current_stmt_binlog_row_based");
current_stmt_binlog_format= BINLOG_FORMAT_ROW;
DBUG_VOID_RETURN;
}
inline void clear_current_stmt_binlog_row_based()
{
current_stmt_binlog_row_based= FALSE;
DBUG_ENTER("clear_current_stmt_binlog_row_based");
current_stmt_binlog_format= BINLOG_FORMAT_STMT;
DBUG_VOID_RETURN;
}
inline void reset_current_stmt_binlog_row_based()
{
DBUG_ENTER("reset_current_stmt_binlog_row_based");
/*
If there are temporary tables, don't reset back to
statement-based. Indeed it could be that:
@ -2159,19 +2182,18 @@ public:
or trigger is decided when it starts executing, depending for example on
the caller (for a stored function: if caller is SELECT or
INSERT/UPDATE/DELETE...).
Don't reset binlog format for NDB binlog injector thread.
*/
DBUG_PRINT("debug",
("temporary_tables: %s, in_sub_stmt: %s, system_thread: %s",
YESNO(temporary_tables), YESNO(in_sub_stmt),
show_system_thread(system_thread)));
if ((temporary_tables == NULL) && (in_sub_stmt == 0) &&
(system_thread != SYSTEM_THREAD_NDBCLUSTER_BINLOG))
if ((temporary_tables == NULL) && (in_sub_stmt == 0))
{
current_stmt_binlog_row_based=
test(variables.binlog_format == BINLOG_FORMAT_ROW);
current_stmt_binlog_format=
(variables.binlog_format == BINLOG_FORMAT_ROW) ?
BINLOG_FORMAT_ROW : BINLOG_FORMAT_STMT;
}
DBUG_VOID_RETURN;
}
/**
@ -2267,7 +2289,11 @@ public:
*/
void pop_internal_handler();
int decide_logging_format(TABLE_LIST *tables);
private:
/** The current internal error handler for this thread, or NULL. */
Internal_error_handler *m_internal_handler;
/**