mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 14:54:20 +01:00
f8b64e17f9
using TPC-B): Problem: A RBR event can contain incomplete row data (only key value and fields which have been changed). In that case, when the row is unpacked into record and written to a table, the missing fields get incorrect NULL values leading to master-slave inconsistency. Solution: Use values found in slave's table for columns which are not given in the rows event. The code for writing a single row uses the following algorithm: 1. unpack row_data into table->record[0], 2. try to insert record, 3. if duplicate record found, fetch it into table->record[0], 4. unpack row_data into table->record[0], 5. write table->record[0] into the table. Where row_data is the row as stored in the data area of a rows event. Thus: a) unpacking of row_data happens at the time when row is written into a table, b) when unpacking (in step 4), only columns present in row_data are overwritten - all other columns remain as they were found in the table. Since all data needed for the above algorithm is stored inside Rows_log_event class, functions which locate and write rows are turned into methods of that class. replace_record() -> Rows_log_event::write_row() find_and_fetch_row() -> Rows_log_event::find_row() Both methods take row data from event's data buffer - the row being processed is pointed by m_curr_row. They unpack the data as needed into table's record buffers record[0] or record[1]. When row is unpacked, m_curr_row_end is set to point at next row in the data buffer. Other changes introduced in this changeset: - Change signature of unpack_row(): don't report errors and don't setup table's rw_set here. Errors can happen only when setting default values in prepare_record() function and are detected there. - In Rows_log_event and derived classes, don't pass arguments to the execution primitives (do_...() member functions) but use class members instead. - Move old row handling code into log_event_old.cc to be used by *_rows_log_event_old classes. Also, a new test rpl_ndb_2other is added which tests basic replication from master using ndb tables to slave storing the same tables using (possibly) different engine (myisam,innodb). Test is based on existing tests rpl_ndb_2myisam and rpl_ndb_2innodb. However, these tests doesn't work for various reasons and currently are disabled (see BUG#19227). The new test differs from the ones it is based on as follows: 1. Single test tests replication with different storage engines on slave (myisam, innodb, ndb). 2. Include file extra/rpl_tests/rpl_ndb_2multi_eng.test containing original tests is replaced by extra/rpl_tests/rpl_ndb_2multi_basic.test which doesn't contain tests using partitioned tables as these don't work currently. Instead, it tests replication to a slave which has more or less columns than master. 3. Include file include/rpl_multi_engine3.inc is replaced with include/rpl_multi_engine2.inc. The later differs by performing slightly different operations (updating more than one row in the table) and clearing table with "TRUNCATE TABLE" statement instead of "DELETE FROM" as replication of "DELETE" doesn't work well in this setting. 4. Slave must use option --log-slave-updates=0 as otherwise execution of replication events generated by ndb fails if table uses a different storage engine on slave (see BUG#29569).
119 lines
3.4 KiB
Text
119 lines
3.4 KiB
Text
#######################################
|
|
# Author: Rafal Somla #
|
|
# Date: 2006-08-20 #
|
|
# Purpose: Test replication of basic #
|
|
# table operations in various setups #
|
|
# #
|
|
# Based on rpl_ndb_2multi_eng.test by #
|
|
# JBM #
|
|
#######################################
|
|
|
|
--echo --- Doing pre test cleanup ---
|
|
|
|
connection master;
|
|
--disable_warnings
|
|
DROP TABLE IF EXISTS t1;
|
|
--enable_query_log
|
|
|
|
#################################################
|
|
--echo --- Create Table Section ---
|
|
|
|
CREATE TABLE t1 (id MEDIUMINT NOT NULL,
|
|
b1 INT,
|
|
vc VARCHAR(255),
|
|
bc CHAR(255),
|
|
d DECIMAL(10,4) DEFAULT 0,
|
|
f FLOAT DEFAULT 0,
|
|
total BIGINT UNSIGNED,
|
|
y YEAR,
|
|
t DATE,
|
|
PRIMARY KEY(id));
|
|
|
|
--echo --- Show table on master ---
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
--echo --- Show table on slave ---
|
|
|
|
sync_slave_with_master;
|
|
SHOW CREATE TABLE t1;
|
|
|
|
--source include/rpl_multi_engine2.inc
|
|
|
|
#################################################
|
|
# Okay lets see how it holds up to table changes
|
|
--echo --- Check that simple Alter statements are replicated correctly --
|
|
|
|
ALTER TABLE t1 DROP PRIMARY KEY;
|
|
# note: table with no PK can't contain blobs if it is to be replicated.
|
|
ALTER TABLE t1 MODIFY vc char(32);
|
|
|
|
--echo --- Show the new improved table on the master ---
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
--echo --- Make sure that our tables on slave are still same engine ---
|
|
--echo --- and that the alter statements replicated correctly ---
|
|
|
|
sync_slave_with_master;
|
|
SHOW CREATE TABLE t1;
|
|
|
|
--source include/rpl_multi_engine2.inc
|
|
|
|
#################################################
|
|
--echo --- Check that replication works when slave has more columns than master
|
|
connection master;
|
|
ALTER TABLE t1 ADD PRIMARY KEY(id,total);
|
|
ALTER TABLE t1 MODIFY vc TEXT;
|
|
|
|
INSERT INTO t1 VALUES(3,1,'Testing MySQL databases is a cool ',
|
|
'Must make it bug free for the customer',
|
|
654321.4321,15.21,0,1965,"1905-11-14");
|
|
INSERT INTO t1 VALUES(20,1,'Testing MySQL databases is a cool ',
|
|
'Must make it bug free for the customer',
|
|
654321.4321,15.21,0,1965,"1965-11-14");
|
|
INSERT INTO t1 VALUES(50,1,'Testing MySQL databases is a cool ',
|
|
'Must make it bug free for the customer',
|
|
654321.4321,15.21,0,1965,"1985-11-14");
|
|
|
|
--echo --- Add columns on slave ---
|
|
--sync_slave_with_master
|
|
ALTER TABLE t1 ADD (u int, v char(16) default 'default');
|
|
UPDATE t1 SET u=7 WHERE id < 50;
|
|
UPDATE t1 SET v='explicit' WHERE id >10;
|
|
|
|
--echo --- Show changed table on slave ---
|
|
|
|
SHOW CREATE TABLE t1;
|
|
SELECT *
|
|
FROM t1
|
|
ORDER BY id;
|
|
|
|
--source include/rpl_multi_engine2.inc
|
|
TRUNCATE TABLE t1;
|
|
|
|
#################################################
|
|
--echo --- Check that replication works when master has more columns than slave
|
|
connection master;
|
|
|
|
--echo --- Remove columns on slave ---
|
|
--sync_slave_with_master
|
|
ALTER TABLE t1 DROP COLUMN v;
|
|
ALTER TABLE t1 DROP COLUMN u;
|
|
ALTER TABLE t1 DROP COLUMN t;
|
|
ALTER TABLE t1 DROP COLUMN y;
|
|
|
|
--echo --- Show changed table on slave ---
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
--source include/rpl_multi_engine2.inc
|
|
TRUNCATE TABLE t1;
|
|
|
|
#################################################
|
|
--echo --- Do Cleanup --
|
|
connection master;
|
|
DROP TABLE IF EXISTS t1;
|
|
|
|
sync_slave_with_master;
|
|
connection master;
|