2011-06-30 17:37:13 +02:00
|
|
|
/*
|
2011-11-21 18:13:14 +01:00
|
|
|
Copyright (c) 2006, 2010, Oracle and/or its affiliates.
|
2006-05-03 15:00:38 +02:00
|
|
|
|
|
|
|
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
|
2006-12-27 02:23:51 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2006-05-03 15:00:38 +02:00
|
|
|
|
|
|
|
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
|
2011-06-30 17:37:13 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2006-05-03 15:00:38 +02:00
|
|
|
|
|
|
|
#include "rpl_utility.h"
|
2011-05-03 14:01:11 +02:00
|
|
|
|
|
|
|
#ifndef MYSQL_CLIENT
|
2007-06-11 22:15:39 +02:00
|
|
|
#include "rpl_rli.h"
|
2006-05-03 15:00:38 +02:00
|
|
|
|
2007-07-30 00:10:42 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* table_def member definitions *
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
This function returns the field size in raw bytes based on the type
|
|
|
|
and the encoded field data from the master's raw data.
|
|
|
|
*/
|
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.
2007-08-26 14:31:10 +02:00
|
|
|
uint32 table_def::calc_field_size(uint col, uchar *master_data) const
|
2006-05-03 15:00:38 +02:00
|
|
|
{
|
|
|
|
uint32 length;
|
|
|
|
|
2007-07-30 00:10:42 +02:00
|
|
|
switch (type(col)) {
|
2006-05-03 15:00:38 +02:00
|
|
|
case MYSQL_TYPE_NEWDECIMAL:
|
2007-07-30 00:10:42 +02:00
|
|
|
length= my_decimal_get_binary_size(m_field_metadata[col] >> 8,
|
2007-09-14 17:22:41 +02:00
|
|
|
m_field_metadata[col] & 0xff);
|
2007-07-30 00:10:42 +02:00
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_DECIMAL:
|
|
|
|
case MYSQL_TYPE_FLOAT:
|
|
|
|
case MYSQL_TYPE_DOUBLE:
|
|
|
|
length= m_field_metadata[col];
|
|
|
|
break;
|
2007-09-14 17:22:41 +02:00
|
|
|
/*
|
|
|
|
The cases for SET and ENUM are include for completeness, however
|
|
|
|
both are mapped to type MYSQL_TYPE_STRING and their real types
|
|
|
|
are encoded in the field metadata.
|
|
|
|
*/
|
2007-07-30 00:10:42 +02:00
|
|
|
case MYSQL_TYPE_SET:
|
|
|
|
case MYSQL_TYPE_ENUM:
|
|
|
|
case MYSQL_TYPE_STRING:
|
|
|
|
{
|
2007-09-14 17:22:41 +02:00
|
|
|
uchar type= m_field_metadata[col] >> 8U;
|
|
|
|
if ((type == MYSQL_TYPE_SET) || (type == MYSQL_TYPE_ENUM))
|
2007-07-30 00:10:42 +02:00
|
|
|
length= m_field_metadata[col] & 0x00ff;
|
|
|
|
else
|
|
|
|
{
|
2007-09-14 17:22:41 +02:00
|
|
|
/*
|
|
|
|
We are reading the actual size from the master_data record
|
|
|
|
because this field has the actual lengh stored in the first
|
|
|
|
byte.
|
|
|
|
*/
|
|
|
|
length= (uint) *master_data + 1;
|
|
|
|
DBUG_ASSERT(length != 0);
|
2007-07-30 00:10:42 +02:00
|
|
|
}
|
2006-05-03 15:00:38 +02:00
|
|
|
break;
|
2007-07-30 00:10:42 +02:00
|
|
|
}
|
2006-05-03 15:00:38 +02:00
|
|
|
case MYSQL_TYPE_YEAR:
|
|
|
|
case MYSQL_TYPE_TINY:
|
|
|
|
length= 1;
|
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_SHORT:
|
|
|
|
length= 2;
|
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_INT24:
|
|
|
|
length= 3;
|
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_LONG:
|
|
|
|
length= 4;
|
|
|
|
break;
|
|
|
|
#ifdef HAVE_LONG_LONG
|
|
|
|
case MYSQL_TYPE_LONGLONG:
|
|
|
|
length= 8;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case MYSQL_TYPE_NULL:
|
|
|
|
length= 0;
|
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_NEWDATE:
|
|
|
|
length= 3;
|
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_DATE:
|
|
|
|
case MYSQL_TYPE_TIME:
|
|
|
|
length= 3;
|
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_TIMESTAMP:
|
|
|
|
length= 4;
|
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_DATETIME:
|
|
|
|
length= 8;
|
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_BIT:
|
2007-07-30 00:10:42 +02:00
|
|
|
{
|
2007-09-14 17:22:41 +02:00
|
|
|
/*
|
|
|
|
Decode the size of the bit field from the master.
|
|
|
|
from_len is the length in bytes from the master
|
|
|
|
from_bit_len is the number of extra bits stored in the master record
|
|
|
|
If from_bit_len is not 0, add 1 to the length to account for accurate
|
|
|
|
number of bytes needed.
|
|
|
|
*/
|
2007-07-30 00:10:42 +02:00
|
|
|
uint from_len= (m_field_metadata[col] >> 8U) & 0x00ff;
|
|
|
|
uint from_bit_len= m_field_metadata[col] & 0x00ff;
|
2007-08-03 17:12:00 +02:00
|
|
|
DBUG_ASSERT(from_bit_len <= 7);
|
2007-07-30 00:10:42 +02:00
|
|
|
length= from_len + ((from_bit_len > 0) ? 1 : 0);
|
2006-05-03 15:00:38 +02:00
|
|
|
break;
|
2007-07-30 00:10:42 +02:00
|
|
|
}
|
2006-05-03 15:00:38 +02:00
|
|
|
case MYSQL_TYPE_VARCHAR:
|
2007-07-30 18:55:26 +02:00
|
|
|
{
|
2007-07-30 00:10:42 +02:00
|
|
|
length= m_field_metadata[col] > 255 ? 2 : 1; // c&p of Field_varstring::data_length()
|
2007-07-30 18:55:26 +02:00
|
|
|
DBUG_ASSERT(uint2korr(master_data) > 0);
|
2007-07-30 00:10:42 +02:00
|
|
|
length+= length == 1 ? (uint32) *master_data : uint2korr(master_data);
|
2006-05-03 15:00:38 +02:00
|
|
|
break;
|
2007-07-30 18:55:26 +02:00
|
|
|
}
|
2006-05-03 15:00:38 +02:00
|
|
|
case MYSQL_TYPE_TINY_BLOB:
|
|
|
|
case MYSQL_TYPE_MEDIUM_BLOB:
|
|
|
|
case MYSQL_TYPE_LONG_BLOB:
|
|
|
|
case MYSQL_TYPE_BLOB:
|
|
|
|
case MYSQL_TYPE_GEOMETRY:
|
2007-07-30 00:10:42 +02:00
|
|
|
{
|
2007-08-02 22:15:52 +02:00
|
|
|
#if 1
|
|
|
|
/*
|
|
|
|
BUG#29549:
|
|
|
|
This is currently broken for NDB, which is using big-endian
|
|
|
|
order when packing length of BLOB. Once they have decided how to
|
|
|
|
fix the issue, we can enable the code below to make sure to
|
|
|
|
always read the length in little-endian order.
|
|
|
|
*/
|
2007-07-30 00:10:42 +02:00
|
|
|
Field_blob fb(m_field_metadata[col]);
|
2011-05-20 23:56:13 +02:00
|
|
|
length= fb.get_packed_size(master_data);
|
2007-08-02 22:15:52 +02:00
|
|
|
#else
|
|
|
|
/*
|
|
|
|
Compute the length of the data. We cannot use get_length() here
|
|
|
|
since it is dependent on the specific table (and also checks the
|
|
|
|
packlength using the internal 'table' pointer) and replication
|
|
|
|
is using a fixed format for storing data in the binlog.
|
|
|
|
*/
|
|
|
|
switch (m_field_metadata[col]) {
|
|
|
|
case 1:
|
|
|
|
length= *master_data;
|
|
|
|
break;
|
|
|
|
case 2:
|
2007-09-14 17:22:41 +02:00
|
|
|
length= uint2korr(master_data);
|
2007-08-02 22:15:52 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
length= uint3korr(master_data);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
length= uint4korr(master_data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0); // Should not come here
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
length+= m_field_metadata[col];
|
|
|
|
#endif
|
2006-05-03 15:00:38 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-07-30 00:10:42 +02:00
|
|
|
default:
|
2008-01-30 17:35:25 +01:00
|
|
|
length= ~(uint32) 0;
|
2007-07-30 00:10:42 +02:00
|
|
|
}
|
2006-09-08 10:20:14 +02:00
|
|
|
return length;
|
2006-05-03 15:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Is the definition compatible with a table?
|
|
|
|
|
|
|
|
*/
|
|
|
|
int
|
2007-08-16 07:37:50 +02:00
|
|
|
table_def::compatible_with(Relay_log_info const *rli_arg, TABLE *table)
|
2006-05-03 15:00:38 +02:00
|
|
|
const
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
We only check the initial columns for the tables.
|
|
|
|
*/
|
|
|
|
uint const cols_to_check= min(table->s->fields, size());
|
|
|
|
int error= 0;
|
2007-08-16 07:37:50 +02:00
|
|
|
Relay_log_info const *rli= const_cast<Relay_log_info*>(rli_arg);
|
2006-05-03 15:00:38 +02:00
|
|
|
|
|
|
|
TABLE_SHARE const *const tsh= table->s;
|
|
|
|
|
|
|
|
for (uint col= 0 ; col < cols_to_check ; ++col)
|
|
|
|
{
|
BUG#37426: RBR breaks for CHAR() UTF-8 fields > 85 chars
In order to handle CHAR() fields, 8 bits were reserved for
the size of the CHAR field. However, instead of denoting the
number of characters in the field, field_length was used which
denotes the number of bytes in the field.
Since UTF-8 fields can have three bytes per character (and
has been extended to have four bytes per character in 6.0),
an extra two bits have been encoded in the field metadata
work for fields of type Field_string (i.e., CHAR fields).
Since the metadata word is filled, the extra bits have been
encoded in the upper 4 bits of the real type (the most
significant byte of the metadata word) by computing the
bitwise xor of the extra two bits. Since the upper 4 bits
of the real type always is 1111 for Field_string, this
means that for fields of length <256, the encoding is
identical to the encoding used in pre-5.1.26 servers, but
for lengths of 256 or more, an unrecognized type is formed,
causing an old slave (that does not handle lengths of 256
or more) to stop.
mysql-test/extra/rpl_tests/rpl_row_basic.test:
Adding test cases for replicating UTF-8 fields of lengths
of 256 or more (bytes).
mysql-test/suite/binlog/r/binlog_base64_flag.result:
Result file change.
mysql-test/suite/binlog/t/binlog_base64_flag.test:
Adding tests to trigger check that an error is generated when replicating from a
5.1.25 server for tables with a CHAR(128) but not when replicating a table with a
CHAR(63). Although the bug indicates that the limit is 83, we elected to use CHAR(63)
since 6.0 uses 4-byte UTF-8, and anything exceeding 63 would then cause the test to fail
when the patch is merged to 6.0.
mysql-test/suite/bugs/combinations:
Adding combinations file to run all bug reports in all binlog modes (where
applicable).
mysql-test/suite/bugs/r/rpl_bug37426.result:
Result file change.
mysql-test/suite/bugs/t/rpl_bug37426.test:
Added test for reported bug.
mysql-test/suite/rpl/r/rpl_row_basic_2myisam.result:
Result file change.
mysql-test/suite/rpl/r/rpl_row_basic_3innodb.result:
Result file change.
sql/field.cc:
Encoding an extra two bits in the most significant nibble (4 bits)
of the metadata word. Adding assertions to ensure that no attempt
is made to use lengths longer than supported.
Extending compatible_field_size() function with an extra parameter
holding a Relay_log_instace for error reporting.
Field_string::compatible_field_size() now reports an error if field
size for a CHAR is >255.
sql/field.h:
Field length is now computed from most significant 4 bits
of metadata word, or is equal to the row pack length if
there is no metadata.
Extending compatible_field_size() function with an extra parameter
holding a Relay_log_instace for error reporting.
sql/rpl_utility.cc:
Adding relay log parameter to compatible_field_size().
Minor refactoring to eliminate duplicate code.
sql/slave.cc:
Extending rpl_master_has_bug() with a single-argument predicate function and
a parameter to the predicate function. The predicate function can be used to
test for extra conditions for the bug before writing an error message.
sql/slave.h:
Extending rpl_master_has_bug() with a single-argument predicate function and
a parameter to the predicate function. The predicate function can be used to
test for extra conditions for the bug before writing an error message.
Also removing gratuitous default argument.
sql/sql_insert.cc:
Changing calls to rpl_master_has_bug() to adapt to changed signature.
2008-06-30 22:11:18 +02:00
|
|
|
Field *const field= table->field[col];
|
|
|
|
if (field->type() != type(col))
|
2006-05-03 15:00:38 +02:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(col < size() && col < tsh->fields);
|
|
|
|
DBUG_ASSERT(tsh->db.str && tsh->table_name.str);
|
|
|
|
error= 1;
|
2007-06-09 07:19:37 +02:00
|
|
|
char buf[256];
|
|
|
|
my_snprintf(buf, sizeof(buf), "Column %d type mismatch - "
|
|
|
|
"received type %d, %s.%s has type %d",
|
|
|
|
col, type(col), tsh->db.str, tsh->table_name.str,
|
BUG#37426: RBR breaks for CHAR() UTF-8 fields > 85 chars
In order to handle CHAR() fields, 8 bits were reserved for
the size of the CHAR field. However, instead of denoting the
number of characters in the field, field_length was used which
denotes the number of bytes in the field.
Since UTF-8 fields can have three bytes per character (and
has been extended to have four bytes per character in 6.0),
an extra two bits have been encoded in the field metadata
work for fields of type Field_string (i.e., CHAR fields).
Since the metadata word is filled, the extra bits have been
encoded in the upper 4 bits of the real type (the most
significant byte of the metadata word) by computing the
bitwise xor of the extra two bits. Since the upper 4 bits
of the real type always is 1111 for Field_string, this
means that for fields of length <256, the encoding is
identical to the encoding used in pre-5.1.26 servers, but
for lengths of 256 or more, an unrecognized type is formed,
causing an old slave (that does not handle lengths of 256
or more) to stop.
mysql-test/extra/rpl_tests/rpl_row_basic.test:
Adding test cases for replicating UTF-8 fields of lengths
of 256 or more (bytes).
mysql-test/suite/binlog/r/binlog_base64_flag.result:
Result file change.
mysql-test/suite/binlog/t/binlog_base64_flag.test:
Adding tests to trigger check that an error is generated when replicating from a
5.1.25 server for tables with a CHAR(128) but not when replicating a table with a
CHAR(63). Although the bug indicates that the limit is 83, we elected to use CHAR(63)
since 6.0 uses 4-byte UTF-8, and anything exceeding 63 would then cause the test to fail
when the patch is merged to 6.0.
mysql-test/suite/bugs/combinations:
Adding combinations file to run all bug reports in all binlog modes (where
applicable).
mysql-test/suite/bugs/r/rpl_bug37426.result:
Result file change.
mysql-test/suite/bugs/t/rpl_bug37426.test:
Added test for reported bug.
mysql-test/suite/rpl/r/rpl_row_basic_2myisam.result:
Result file change.
mysql-test/suite/rpl/r/rpl_row_basic_3innodb.result:
Result file change.
sql/field.cc:
Encoding an extra two bits in the most significant nibble (4 bits)
of the metadata word. Adding assertions to ensure that no attempt
is made to use lengths longer than supported.
Extending compatible_field_size() function with an extra parameter
holding a Relay_log_instace for error reporting.
Field_string::compatible_field_size() now reports an error if field
size for a CHAR is >255.
sql/field.h:
Field length is now computed from most significant 4 bits
of metadata word, or is equal to the row pack length if
there is no metadata.
Extending compatible_field_size() function with an extra parameter
holding a Relay_log_instace for error reporting.
sql/rpl_utility.cc:
Adding relay log parameter to compatible_field_size().
Minor refactoring to eliminate duplicate code.
sql/slave.cc:
Extending rpl_master_has_bug() with a single-argument predicate function and
a parameter to the predicate function. The predicate function can be used to
test for extra conditions for the bug before writing an error message.
sql/slave.h:
Extending rpl_master_has_bug() with a single-argument predicate function and
a parameter to the predicate function. The predicate function can be used to
test for extra conditions for the bug before writing an error message.
Also removing gratuitous default argument.
sql/sql_insert.cc:
Changing calls to rpl_master_has_bug() to adapt to changed signature.
2008-06-30 22:11:18 +02:00
|
|
|
field->type());
|
2007-06-09 07:19:37 +02:00
|
|
|
rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
|
|
|
|
ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);
|
2006-05-03 15:00:38 +02:00
|
|
|
}
|
2007-08-10 18:48:01 +02:00
|
|
|
/*
|
|
|
|
Check the slave's field size against that of the master.
|
|
|
|
*/
|
BUG#37426: RBR breaks for CHAR() UTF-8 fields > 85 chars
In order to handle CHAR() fields, 8 bits were reserved for
the size of the CHAR field. However, instead of denoting the
number of characters in the field, field_length was used which
denotes the number of bytes in the field.
Since UTF-8 fields can have three bytes per character (and
has been extended to have four bytes per character in 6.0),
an extra two bits have been encoded in the field metadata
work for fields of type Field_string (i.e., CHAR fields).
Since the metadata word is filled, the extra bits have been
encoded in the upper 4 bits of the real type (the most
significant byte of the metadata word) by computing the
bitwise xor of the extra two bits. Since the upper 4 bits
of the real type always is 1111 for Field_string, this
means that for fields of length <256, the encoding is
identical to the encoding used in pre-5.1.26 servers, but
for lengths of 256 or more, an unrecognized type is formed,
causing an old slave (that does not handle lengths of 256
or more) to stop.
mysql-test/extra/rpl_tests/rpl_row_basic.test:
Adding test cases for replicating UTF-8 fields of lengths
of 256 or more (bytes).
mysql-test/suite/binlog/r/binlog_base64_flag.result:
Result file change.
mysql-test/suite/binlog/t/binlog_base64_flag.test:
Adding tests to trigger check that an error is generated when replicating from a
5.1.25 server for tables with a CHAR(128) but not when replicating a table with a
CHAR(63). Although the bug indicates that the limit is 83, we elected to use CHAR(63)
since 6.0 uses 4-byte UTF-8, and anything exceeding 63 would then cause the test to fail
when the patch is merged to 6.0.
mysql-test/suite/bugs/combinations:
Adding combinations file to run all bug reports in all binlog modes (where
applicable).
mysql-test/suite/bugs/r/rpl_bug37426.result:
Result file change.
mysql-test/suite/bugs/t/rpl_bug37426.test:
Added test for reported bug.
mysql-test/suite/rpl/r/rpl_row_basic_2myisam.result:
Result file change.
mysql-test/suite/rpl/r/rpl_row_basic_3innodb.result:
Result file change.
sql/field.cc:
Encoding an extra two bits in the most significant nibble (4 bits)
of the metadata word. Adding assertions to ensure that no attempt
is made to use lengths longer than supported.
Extending compatible_field_size() function with an extra parameter
holding a Relay_log_instace for error reporting.
Field_string::compatible_field_size() now reports an error if field
size for a CHAR is >255.
sql/field.h:
Field length is now computed from most significant 4 bits
of metadata word, or is equal to the row pack length if
there is no metadata.
Extending compatible_field_size() function with an extra parameter
holding a Relay_log_instace for error reporting.
sql/rpl_utility.cc:
Adding relay log parameter to compatible_field_size().
Minor refactoring to eliminate duplicate code.
sql/slave.cc:
Extending rpl_master_has_bug() with a single-argument predicate function and
a parameter to the predicate function. The predicate function can be used to
test for extra conditions for the bug before writing an error message.
sql/slave.h:
Extending rpl_master_has_bug() with a single-argument predicate function and
a parameter to the predicate function. The predicate function can be used to
test for extra conditions for the bug before writing an error message.
Also removing gratuitous default argument.
sql/sql_insert.cc:
Changing calls to rpl_master_has_bug() to adapt to changed signature.
2008-06-30 22:11:18 +02:00
|
|
|
if (!error &&
|
2010-03-17 15:28:49 +01:00
|
|
|
!field->compatible_field_size(field_metadata(col), rli_arg, m_flags))
|
2007-08-10 18:48:01 +02:00
|
|
|
{
|
|
|
|
error= 1;
|
|
|
|
char buf[256];
|
|
|
|
my_snprintf(buf, sizeof(buf), "Column %d size mismatch - "
|
|
|
|
"master has size %d, %s.%s on slave has size %d."
|
|
|
|
" Master's column size should be <= the slave's "
|
|
|
|
"column size.", col,
|
BUG#37426: RBR breaks for CHAR() UTF-8 fields > 85 chars
In order to handle CHAR() fields, 8 bits were reserved for
the size of the CHAR field. However, instead of denoting the
number of characters in the field, field_length was used which
denotes the number of bytes in the field.
Since UTF-8 fields can have three bytes per character (and
has been extended to have four bytes per character in 6.0),
an extra two bits have been encoded in the field metadata
work for fields of type Field_string (i.e., CHAR fields).
Since the metadata word is filled, the extra bits have been
encoded in the upper 4 bits of the real type (the most
significant byte of the metadata word) by computing the
bitwise xor of the extra two bits. Since the upper 4 bits
of the real type always is 1111 for Field_string, this
means that for fields of length <256, the encoding is
identical to the encoding used in pre-5.1.26 servers, but
for lengths of 256 or more, an unrecognized type is formed,
causing an old slave (that does not handle lengths of 256
or more) to stop.
mysql-test/extra/rpl_tests/rpl_row_basic.test:
Adding test cases for replicating UTF-8 fields of lengths
of 256 or more (bytes).
mysql-test/suite/binlog/r/binlog_base64_flag.result:
Result file change.
mysql-test/suite/binlog/t/binlog_base64_flag.test:
Adding tests to trigger check that an error is generated when replicating from a
5.1.25 server for tables with a CHAR(128) but not when replicating a table with a
CHAR(63). Although the bug indicates that the limit is 83, we elected to use CHAR(63)
since 6.0 uses 4-byte UTF-8, and anything exceeding 63 would then cause the test to fail
when the patch is merged to 6.0.
mysql-test/suite/bugs/combinations:
Adding combinations file to run all bug reports in all binlog modes (where
applicable).
mysql-test/suite/bugs/r/rpl_bug37426.result:
Result file change.
mysql-test/suite/bugs/t/rpl_bug37426.test:
Added test for reported bug.
mysql-test/suite/rpl/r/rpl_row_basic_2myisam.result:
Result file change.
mysql-test/suite/rpl/r/rpl_row_basic_3innodb.result:
Result file change.
sql/field.cc:
Encoding an extra two bits in the most significant nibble (4 bits)
of the metadata word. Adding assertions to ensure that no attempt
is made to use lengths longer than supported.
Extending compatible_field_size() function with an extra parameter
holding a Relay_log_instace for error reporting.
Field_string::compatible_field_size() now reports an error if field
size for a CHAR is >255.
sql/field.h:
Field length is now computed from most significant 4 bits
of metadata word, or is equal to the row pack length if
there is no metadata.
Extending compatible_field_size() function with an extra parameter
holding a Relay_log_instace for error reporting.
sql/rpl_utility.cc:
Adding relay log parameter to compatible_field_size().
Minor refactoring to eliminate duplicate code.
sql/slave.cc:
Extending rpl_master_has_bug() with a single-argument predicate function and
a parameter to the predicate function. The predicate function can be used to
test for extra conditions for the bug before writing an error message.
sql/slave.h:
Extending rpl_master_has_bug() with a single-argument predicate function and
a parameter to the predicate function. The predicate function can be used to
test for extra conditions for the bug before writing an error message.
Also removing gratuitous default argument.
sql/sql_insert.cc:
Changing calls to rpl_master_has_bug() to adapt to changed signature.
2008-06-30 22:11:18 +02:00
|
|
|
field->pack_length_from_metadata(m_field_metadata[col]),
|
|
|
|
tsh->db.str, tsh->table_name.str,
|
|
|
|
field->row_pack_length());
|
2007-08-10 18:48:01 +02:00
|
|
|
rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
|
|
|
|
ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);
|
|
|
|
}
|
2006-05-03 15:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
2011-05-03 14:01:11 +02:00
|
|
|
|
|
|
|
#endif /* MYSQL_CLIENT */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param even_buf point to the buffer containing serialized event
|
|
|
|
@param event_len length of the event accounting possible checksum alg
|
|
|
|
|
|
|
|
@return TRUE if test fails
|
|
|
|
FALSE as success
|
|
|
|
*/
|
|
|
|
bool event_checksum_test(uchar *event_buf, ulong event_len, uint8 alg)
|
|
|
|
{
|
|
|
|
bool res= FALSE;
|
|
|
|
uint16 flags= 0; // to store in FD's buffer flags orig value
|
|
|
|
|
|
|
|
if (alg != BINLOG_CHECKSUM_ALG_OFF && alg != BINLOG_CHECKSUM_ALG_UNDEF)
|
|
|
|
{
|
|
|
|
ha_checksum incoming;
|
|
|
|
ha_checksum computed;
|
|
|
|
|
|
|
|
if (event_buf[EVENT_TYPE_OFFSET] == FORMAT_DESCRIPTION_EVENT)
|
|
|
|
{
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
int8 fd_alg= event_buf[event_len - BINLOG_CHECKSUM_LEN -
|
|
|
|
BINLOG_CHECKSUM_ALG_DESC_LEN];
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
FD event is checksummed and therefore verified w/o the binlog-in-use flag
|
|
|
|
*/
|
|
|
|
flags= uint2korr(event_buf + FLAGS_OFFSET);
|
|
|
|
if (flags & LOG_EVENT_BINLOG_IN_USE_F)
|
|
|
|
event_buf[FLAGS_OFFSET] &= ~LOG_EVENT_BINLOG_IN_USE_F;
|
|
|
|
/*
|
|
|
|
The only algorithm currently is CRC32. Zero indicates
|
|
|
|
the binlog file is checksum-free *except* the FD-event.
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(fd_alg == BINLOG_CHECKSUM_ALG_CRC32 || fd_alg == 0);
|
|
|
|
DBUG_ASSERT(alg == BINLOG_CHECKSUM_ALG_CRC32);
|
|
|
|
/*
|
|
|
|
Complile time guard to watch over the max number of alg
|
|
|
|
*/
|
|
|
|
compile_time_assert(BINLOG_CHECKSUM_ALG_ENUM_END <= 0x80);
|
|
|
|
}
|
|
|
|
incoming= uint4korr(event_buf + event_len - BINLOG_CHECKSUM_LEN);
|
|
|
|
computed= my_checksum(0L, NULL, 0);
|
|
|
|
/* checksum the event content but the checksum part itself */
|
|
|
|
computed= my_checksum(computed, (const uchar*) event_buf,
|
|
|
|
event_len - BINLOG_CHECKSUM_LEN);
|
|
|
|
if (flags != 0)
|
|
|
|
{
|
|
|
|
/* restoring the orig value of flags of FD */
|
|
|
|
DBUG_ASSERT(event_buf[EVENT_TYPE_OFFSET] == FORMAT_DESCRIPTION_EVENT);
|
2011-05-08 12:26:07 +02:00
|
|
|
event_buf[FLAGS_OFFSET]= (uchar) flags;
|
2011-05-03 14:01:11 +02:00
|
|
|
}
|
|
|
|
res= !(computed == incoming);
|
|
|
|
}
|
|
|
|
return DBUG_EVALUATE_IF("simulate_checksum_test_failure", TRUE, res);
|
|
|
|
}
|