mariadb/mysql-test/suite/rpl_ndb/t/rpl_ndb_blob.test
Sven Sandberg f3985c649d 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.
2009-07-14 21:31:19 +02:00

144 lines
3.8 KiB
Text

--source include/have_ndb.inc
# Since the master generates row-based events, the slave must be in
# ROW or MIXED mode to accept the events.
--source include/have_binlog_format_mixed_or_row.inc
--source include/ndb_master-slave.inc
#
# basic test of blob replication for NDB
#
# easy test
--connection master
create table t1 (
a int not null primary key,
b text not null
) engine=ndb;
insert into t1 values(1, repeat('abc',10));
insert into t1 values(2, repeat('def',200));
insert into t1 values(3, repeat('ghi',3000));
select 'M', a, sha1(b) from t1
order by a;
--sync_slave_with_master
--sleep 5
--connection slave
select 'S', a, sha1(b) from t1
order by a;
--connection master
drop table t1;
--sync_slave_with_master
# hard test
--connection master
create table t1 (
a int not null primary key,
b text not null,
c int,
d longblob,
e tinyblob
) engine=ndbcluster;
--disable_query_log
# length 61
set @s0 = 'rggurloniukyehuxdbfkkyzlceixzrehqhvxvxbpwizzvjzpucqmzrhzxzfau';
set @s1 = 'ykyymbzqgqlcjhlhmyqelfoaaohvtbekvifukdtnvcrrjveevfakxarxexomz';
set @s2 = 'dbnfqyzgtqxalcrwtfsqabknvtfcbpoonxsjiqvmhnfikxxhcgoexlkoezvah';
--enable_query_log
insert into t1 values (
0, repeat(@s2,454), 100, repeat(@s2,345), NULL);
insert into t1 values (
1, repeat(@s0,504), NULL, repeat(@s1,732), repeat(@s1,1));
insert into t1 values (
2, '', 102, '', repeat(@s2,1));
insert into t1 values (
3, repeat(@s0,545), 103, repeat(@s2,788), repeat(@s0,1));
insert into t1 values (
4, repeat(@s1,38), 104, repeat(@s0,260), repeat(@s0,1));
insert into t1 values (
5, repeat(@s2,12), 105, repeat(@s2,40), repeat(@s1,1));
insert into t1 values (
6, repeat(@s1,242), 106, NULL, repeat(@s1,1));
insert into t1 values (
7, repeat(@s1,30), 107, repeat(@s0,161), '');
insert into t1 values (
8, repeat(@s1,719), 108, repeat(@s2,104), NULL);
insert into t1 values (
9, repeat(@s2,427), NULL, NULL, NULL);
select 'M', a, sha1(b), c, sha1(d), sha1(e)
from t1 order by a;
--sync_slave_with_master
--sleep 5
--connection slave
select 'S', a, sha1(b), c, sha1(d), sha1(e)
from t1 order by a;
--connection master
drop table t1;
--sync_slave_with_master
# table with varsize key (future cluster/schema)
# sql/ha_ndbcluster_binlog.cc
--connection master
CREATE TABLE IF NOT EXISTS t1 (
db VARBINARY(63) NOT NULL,
name VARBINARY(63) NOT NULL,
slock BINARY(32) NOT NULL,
query BLOB NOT NULL,
node_id INT UNSIGNED NOT NULL,
epoch BIGINT UNSIGNED NOT NULL,
id INT UNSIGNED NOT NULL,
version INT UNSIGNED NOT NULL,
type INT UNSIGNED NOT NULL,
PRIMARY KEY USING HASH (db,name))
ENGINE=NDB;
insert into t1 values ('test','t1',
'abc',repeat(@s0,10), 11,12,13,14,15);
insert into t1 values ('test','t2',
'def',repeat(@s1,100), 21,22,23,24,25);
insert into t1 values ('test','t3',
'ghi',repeat(@s2,1000),31,32,33,34,35);
insert into t1 values ('testtttttttttt','t1',
'abc',repeat(@s0,10), 11,12,13,14,15);
insert into t1 values ('testttttttttttt','t1',
'def',repeat(@s1,100), 21,22,23,24,25);
insert into t1 values ('testtttttttttttt','t1',
'ghi',repeat(@s2,1000),31,32,33,34,35);
insert into t1 values ('t','t11111111111',
'abc',repeat(@s0,10), 11,12,13,14,15);
insert into t1 values ('t','t111111111111',
'def',repeat(@s1,100), 21,22,23,24,25);
insert into t1 values ('t','t1111111111111',
'ghi',repeat(@s2,1000),31,32,33,34,35);
select 'M', db, name, sha1(query), node_id, epoch, id, version, type
from t1 order by db, name;
--sync_slave_with_master
--sleep 5
--connection slave
select 'S', db, name, sha1(query), node_id, epoch, id, version, type
from t1 order by db, name;
--connection master
drop table t1;
--sync_slave_with_master
#
# view the binlog - not deterministic (mats)
#
#--connection master
#let $VERSION=`select version()`;
#--replace_result $VERSION VERSION
#show binlog events;