mirror of
https://github.com/MariaDB/server.git
synced 2025-02-01 03:21:53 +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).
243 lines
7.5 KiB
C++
243 lines
7.5 KiB
C++
/* Copyright 2007 MySQL AB. All rights reserved.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
#ifndef LOG_EVENT_OLD_H
|
|
#define LOG_EVENT_OLD_H
|
|
|
|
/*
|
|
Need to include this file at the proper position of log_event.h
|
|
*/
|
|
|
|
|
|
class Old_rows_log_event
|
|
{
|
|
public:
|
|
|
|
virtual ~Old_rows_log_event() {}
|
|
|
|
protected:
|
|
|
|
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
|
|
|
|
int do_apply_event(Rows_log_event*,const RELAY_LOG_INFO*);
|
|
|
|
/*
|
|
Primitive to prepare for a sequence of row executions.
|
|
|
|
DESCRIPTION
|
|
|
|
Before doing a sequence of do_prepare_row() and do_exec_row()
|
|
calls, this member function should be called to prepare for the
|
|
entire sequence. Typically, this member function will allocate
|
|
space for any buffers that are needed for the two member
|
|
functions mentioned above.
|
|
|
|
RETURN VALUE
|
|
|
|
The member function will return 0 if all went OK, or a non-zero
|
|
error code otherwise.
|
|
*/
|
|
virtual int do_before_row_operations(TABLE *table) = 0;
|
|
|
|
/*
|
|
Primitive to clean up after a sequence of row executions.
|
|
|
|
DESCRIPTION
|
|
|
|
After doing a sequence of do_prepare_row() and do_exec_row(),
|
|
this member function should be called to clean up and release
|
|
any allocated buffers.
|
|
*/
|
|
virtual int do_after_row_operations(TABLE *table, int error) = 0;
|
|
|
|
/*
|
|
Primitive to prepare for handling one row in a row-level event.
|
|
|
|
DESCRIPTION
|
|
|
|
The member function prepares for execution of operations needed for one
|
|
row in a row-level event by reading up data from the buffer containing
|
|
the row. No specific interpretation of the data is normally done here,
|
|
since SQL thread specific data is not available: that data is made
|
|
available for the do_exec function.
|
|
|
|
A pointer to the start of the next row, or NULL if the preparation
|
|
failed. Currently, preparation cannot fail, but don't rely on this
|
|
behavior.
|
|
|
|
RETURN VALUE
|
|
Error code, if something went wrong, 0 otherwise.
|
|
*/
|
|
virtual int do_prepare_row(THD*, RELAY_LOG_INFO const*, TABLE*,
|
|
uchar const *row_start,
|
|
uchar const **row_end) = 0;
|
|
|
|
/*
|
|
Primitive to do the actual execution necessary for a row.
|
|
|
|
DESCRIPTION
|
|
The member function will do the actual execution needed to handle a row.
|
|
|
|
RETURN VALUE
|
|
0 if execution succeeded, 1 if execution failed.
|
|
|
|
*/
|
|
virtual int do_exec_row(TABLE *table) = 0;
|
|
|
|
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
|
|
};
|
|
|
|
|
|
class Write_rows_log_event_old
|
|
: public Write_rows_log_event, public Old_rows_log_event
|
|
{
|
|
|
|
public:
|
|
enum
|
|
{
|
|
/* Support interface to THD::binlog_prepare_pending_rows_event */
|
|
TYPE_CODE = PRE_GA_WRITE_ROWS_EVENT
|
|
};
|
|
|
|
#if !defined(MYSQL_CLIENT)
|
|
Write_rows_log_event_old(THD *thd, TABLE *table, ulong table_id,
|
|
MY_BITMAP const *cols, bool is_transactional)
|
|
: Write_rows_log_event(thd, table, table_id, cols, is_transactional)
|
|
{
|
|
}
|
|
#endif
|
|
#if defined(HAVE_REPLICATION)
|
|
Write_rows_log_event_old(const char *buf, uint event_len,
|
|
const Format_description_log_event *descr)
|
|
: Write_rows_log_event(buf, event_len, descr)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
private:
|
|
virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
|
|
|
|
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
|
|
// use old definition of do_apply_event()
|
|
virtual int do_apply_event(const RELAY_LOG_INFO *rli)
|
|
{ return Old_rows_log_event::do_apply_event(this,rli); }
|
|
|
|
// primitives for old version of do_apply_event()
|
|
virtual int do_before_row_operations(TABLE *table);
|
|
virtual int do_after_row_operations(TABLE *table, int error);
|
|
virtual int do_prepare_row(THD*, RELAY_LOG_INFO const*, TABLE*,
|
|
uchar const *row_start, uchar const **row_end);
|
|
virtual int do_exec_row(TABLE *table);
|
|
|
|
#endif
|
|
};
|
|
|
|
|
|
class Update_rows_log_event_old
|
|
: public Update_rows_log_event, public Old_rows_log_event
|
|
{
|
|
uchar *m_after_image, *m_memory;
|
|
|
|
public:
|
|
enum
|
|
{
|
|
/* Support interface to THD::binlog_prepare_pending_rows_event */
|
|
TYPE_CODE = PRE_GA_UPDATE_ROWS_EVENT
|
|
};
|
|
|
|
#if !defined(MYSQL_CLIENT)
|
|
Update_rows_log_event_old(THD *thd, TABLE *table, ulong table_id,
|
|
MY_BITMAP const *cols, bool is_transactional)
|
|
: Update_rows_log_event(thd, table, table_id, cols, is_transactional),
|
|
m_after_image(NULL), m_memory(NULL)
|
|
{
|
|
}
|
|
#endif
|
|
#if defined(HAVE_REPLICATION)
|
|
Update_rows_log_event_old(const char *buf, uint event_len,
|
|
const Format_description_log_event *descr)
|
|
: Update_rows_log_event(buf, event_len, descr),
|
|
m_after_image(NULL), m_memory(NULL)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
private:
|
|
virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
|
|
|
|
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
|
|
// use old definition of do_apply_event()
|
|
virtual int do_apply_event(const RELAY_LOG_INFO *rli)
|
|
{ return Old_rows_log_event::do_apply_event(this,rli); }
|
|
|
|
// primitives for old version of do_apply_event()
|
|
virtual int do_before_row_operations(TABLE *table);
|
|
virtual int do_after_row_operations(TABLE *table, int error);
|
|
virtual int do_prepare_row(THD*, RELAY_LOG_INFO const*, TABLE*,
|
|
uchar const *row_start, uchar const **row_end);
|
|
virtual int do_exec_row(TABLE *table);
|
|
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
|
|
};
|
|
|
|
|
|
class Delete_rows_log_event_old
|
|
: public Delete_rows_log_event, public Old_rows_log_event
|
|
{
|
|
uchar *m_after_image, *m_memory;
|
|
|
|
public:
|
|
enum
|
|
{
|
|
/* Support interface to THD::binlog_prepare_pending_rows_event */
|
|
TYPE_CODE = PRE_GA_DELETE_ROWS_EVENT
|
|
};
|
|
|
|
#if !defined(MYSQL_CLIENT)
|
|
Delete_rows_log_event_old(THD *thd, TABLE *table, ulong table_id,
|
|
MY_BITMAP const *cols, bool is_transactional)
|
|
: Delete_rows_log_event(thd, table, table_id, cols, is_transactional),
|
|
m_after_image(NULL), m_memory(NULL)
|
|
{
|
|
}
|
|
#endif
|
|
#if defined(HAVE_REPLICATION)
|
|
Delete_rows_log_event_old(const char *buf, uint event_len,
|
|
const Format_description_log_event *descr)
|
|
: Delete_rows_log_event(buf, event_len, descr),
|
|
m_after_image(NULL), m_memory(NULL)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
private:
|
|
virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
|
|
|
|
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
|
|
// use old definition of do_apply_event()
|
|
virtual int do_apply_event(const RELAY_LOG_INFO *rli)
|
|
{ return Old_rows_log_event::do_apply_event(this,rli); }
|
|
|
|
// primitives for old version of do_apply_event()
|
|
virtual int do_before_row_operations(TABLE *table);
|
|
virtual int do_after_row_operations(TABLE *table, int error);
|
|
virtual int do_prepare_row(THD*, RELAY_LOG_INFO const*, TABLE*,
|
|
uchar const *row_start, uchar const **row_end);
|
|
virtual int do_exec_row(TABLE *table);
|
|
#endif
|
|
};
|
|
|
|
|
|
#endif
|
|
|