summaryrefslogtreecommitdiff
path: root/sql/log_event.h
diff options
context:
space:
mode:
authorunknown <rafal@quant.(none)>2007-08-26 14:31:10 +0200
committerunknown <rafal@quant.(none)>2007-08-26 14:31:10 +0200
commit642eda22295b89d095c5d3d86f8c7c87d28e5131 (patch)
tree81aff1f6b7eb590b3dbf821c2bf569fef289fbf5 /sql/log_event.h
parentfc766e515e05624708dbfbf4983b3449097f2693 (diff)
downloadmariadb-git-642eda22295b89d095c5d3d86f8c7c87d28e5131.tar.gz
BUG#21842 (Cluster fails to replicate to innodb or myisam with err 134
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). sql/log_event.cc: - Initialization of new Rows_log_event members. - Fixing some typos in documentation. In Rows_log_event::do_apply_event: - Set COMPLETE_ROWS_F flag (when master and slave have the same number of columns and all colums are present in the row) - Move initialization of tables write/read sets here, outside the rows processing loop (and out of unpack_row() function). - Remove calls to do_prepare_row() - no longer needed. - Add code managing m_curr_row and m_curr_row_end pointers. - Change signatures of row processing methods of Rows_log_event and it descendants - now most arguments are taken from class members. - Remove do_prepare_row() methods which are no longer used. - The auto_afree_ptr template is moved to rpl_utility.h (so that it can be used in log_event_old.cc). - Removed copy_extra_fields() function - no longer used. In Rows_log_event::write_row (former replace_record): - The old code is moved to log_event_old.cc. - Use prepare_record() and non-destructive unpack_current_row() to fill record with data. - In case a record being inserted already exists on slave and row data is incomplete use the record found and non-destructive unpack_current_row() to combine new column values with existing ones. - More debug info added. In Rows_log_event::find_row (former find_and_fetch_row function): - The old code is moved to log_event_old.cc. - Unpacking of the row is moved here. - In case of search using PK, the key data is prepared here. - More debug info added. - Remove initialization of Rows_log_event::m_after_image buffer which is no longer used. - Use new row unpacking methods in Update_rows_log_event::do_exec_row() to create before and after image. Note: all existing code used by Rows_log_event::do_apply_event() has been moved to log_event_old.cc to be used by *_rows_log_event_old classes. sql/log_event.h: - Add new COMPLETE_ROWS_F flag in Rows_log_event. - Add Rows_log_event members describing the row being processed. - Add a pointer to key buffer which is used in derived classes. - Add new methods: find__row(), write_row() and unpack_current_row(). - Change signatures of do_...() methods (replace method arguments by class members). - Remove do_prepare_row() method which is no longer used. - Update method documentation. - Add Old_rows_log_event class, which contains the old row processing code, as a friend of Rows_log_event so that it can access all members of an event instance. sql/log_event_old.cc: Move here old implementation of Rows_log_event::do_apply_event() and helper methods. sql/log_event_old.h: - Define new class Old_rows_log_event encapsulating old version of Rows_log_event::do_apply_event() and the helper methods. - Add the Old_rows_log_event class as a base for *_old versions of RBR event classes, ensure that the old version of do_apply_event() is called. - For *_old classes, declare the helper methods used in the old version of do_apply_event(). sql/rpl_record.cc: - Make unpack_row non-destructive for columns not present in the row. - Don't fill read/write set here as it is done outside these functions. - Move initialization of a record with default values to a separate function prepare_record(). sql/rpl_record.h: - Change signature of unpack_row(). - Declare function prepare_record(). sql/rpl_utility.cc: Make tabe_def::calc_field_size() a const method. sql/rpl_utility.h: Make table_def::calc_field_size() a const method. Move auto_afree_ptr template here so that it can be re-used (currently in log_event.cc and log_event_old.cc). Similar with DBUG_PRINT_BITSET macro. mysql-test/extra/rpl_tests/rpl_ndb_2multi_basic.test: Modification of rpl_ndb_2multi_eng test. Tests with partitioned tables are removed and a setup with slave having different number of columns than master is added. mysql-test/include/rpl_multi_engine2.inc: Modification of rpl_multi_engine3.inc which operates on more rows and replaces "DELETE FROM t1" with "TRUNCATE TABLE t1" as the first form doesn't replicate in NDB -> non-NDB setting (BUG#28538). mysql-test/suite/rpl_ndb/r/rpl_ndb_2other.result: Results of the test. mysql-test/suite/rpl_ndb/t/rpl_ndb_2other-slave.opt: Test options. --log-slave-updates=0 is compulsory as otherwise non-NDB slave applying row events from NDB master will fail when trying to log them. mysql-test/suite/rpl_ndb/t/rpl_ndb_2other.test: Test replication of NDB table to slave using other engine. The main test is in extra/rpl_tests/rpl_ndb_2multi_basic.test. It is included here several times with different settings of default storage engine on slave.
Diffstat (limited to 'sql/log_event.h')
-rw-r--r--sql/log_event.h107
1 files changed, 54 insertions, 53 deletions
diff --git a/sql/log_event.h b/sql/log_event.h
index 05854c2195c..064d13b3e62 100644
--- a/sql/log_event.h
+++ b/sql/log_event.h
@@ -23,6 +23,10 @@
#include <my_bitmap.h>
#include "rpl_constants.h"
+#ifndef MYSQL_CLIENT
+#include "rpl_record.h"
+#include "rpl_reporting.h"
+#endif
#define LOG_READ_EOF -1
#define LOG_READ_BOGUS -2
@@ -2180,7 +2184,13 @@ public:
NO_FOREIGN_KEY_CHECKS_F = (1U << 1),
/* Value of the OPTION_RELAXED_UNIQUE_CHECKS flag in thd->options */
- RELAXED_UNIQUE_CHECKS_F = (1U << 2)
+ RELAXED_UNIQUE_CHECKS_F = (1U << 2),
+
+ /**
+ Indicates that rows in this event are complete, that is contain
+ values for all columns of the table.
+ */
+ COMPLETE_ROWS_F = (1U << 3)
};
typedef uint16 flag_set;
@@ -2284,7 +2294,26 @@ protected:
uchar *m_rows_cur; /* One-after the end of the data */
uchar *m_rows_end; /* One-after the end of the allocated space */
+ const uchar *m_curr_row; /* Start of the row being processed */
+ const uchar *m_curr_row_end; /* One-after the end of the current row */
+
flag_set m_flags; /* Flags for row-level events */
+ uchar *m_key; /* Buffer to keep key value during searches */
+
+ /* helper functions */
+
+#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+ int find_row(const RELAY_LOG_INFO *const);
+ int write_row(const RELAY_LOG_INFO *const, const bool);
+
+ // Unpack the current row into m_table->record[0]
+ int unpack_current_row(const RELAY_LOG_INFO *const rli)
+ {
+ DBUG_ASSERT(m_table);
+ return ::unpack_row(rli, m_table, m_width, m_curr_row, &m_cols,
+ &m_curr_row_end, &m_master_reclength);
+ }
+#endif
private:
@@ -2309,7 +2338,8 @@ private:
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;
+ virtual
+ int do_before_row_operations(const Slave_reporting_capability *const log) = 0;
/*
Primitive to clean up after a sequence of row executions.
@@ -2319,45 +2349,33 @@ private:
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.
+
+ The error argument, if non-zero, indicates an error which happened during
+ row processing before this function was called. In this case, even if
+ function is successful, it should return the error code given in the argument.
*/
- 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;
+ virtual
+ int do_after_row_operations(const Slave_reporting_capability *const log,
+ int error) = 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.
+ The row is located at m_curr_row. When the function returns,
+ m_curr_row_end should point at the next row (one byte after the end
+ of the current row).
RETURN VALUE
0 if execution succeeded, 1 if execution failed.
*/
- virtual int do_exec_row(TABLE *table) = 0;
+ virtual int do_exec_row(const RELAY_LOG_INFO *const rli) = 0;
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
-};
+ friend class Old_rows_log_event;
+};
/*****************************************************************************
@@ -2407,14 +2425,9 @@ private:
#endif
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
- uchar *m_memory;
- uchar *m_after_image;
-
- 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);
+ virtual int do_before_row_operations(const Slave_reporting_capability *const);
+ virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
+ virtual int do_exec_row(const RELAY_LOG_INFO *const);
#endif
};
@@ -2486,15 +2499,9 @@ protected:
#endif
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
- uchar *m_memory;
- uchar *m_key;
- uchar *m_after_image;
-
- 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);
+ virtual int do_before_row_operations(const Slave_reporting_capability *const);
+ virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
+ virtual int do_exec_row(const RELAY_LOG_INFO *const);
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
};
@@ -2557,15 +2564,9 @@ protected:
#endif
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
- uchar *m_memory;
- uchar *m_key;
- uchar *m_after_image;
-
- 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);
+ virtual int do_before_row_operations(const Slave_reporting_capability *const);
+ virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
+ virtual int do_exec_row(const RELAY_LOG_INFO *const);
#endif
};