Commit 45667e64 authored by msvensson@pilot.(none)'s avatar msvensson@pilot.(none)

Merge bk-internal:/home/bk/mysql-5.1-maint

into  pilot.(none):/data/msvensson/mysql/mysql-5.1-new-maint
parents 8efb5ab3 653f7341
#######################################
# 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;
#############################################################
# Author: Rafal
# Date: 2007-08-20
# based on rpl_multi_engine3.inc
#############################################################
connection slave;
STOP SLAVE;
RESET SLAVE;
connection master;
RESET MASTER;
connection slave;
START SLAVE;
--echo --- Populate t1 with data ---
connection master;
--disable_query_log
INSERT INTO t1 VALUES(42,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(2,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(4,1,'Testing MySQL databases is a cool ',
'Must make it bug free for the customer',
654321.4321,15.21,0,1965,"1985-11-14");
INSERT INTO t1 VALUES(142,1,'Testing MySQL databases is a cool ',
'Must make it bug free for the customer',
654321.4321,15.21,0,1965,"1995-11-14");
INSERT INTO t1 VALUES(412,1,'Testing MySQL databases is a cool ',
'Must make it bug free for the customer',
654321.4321,15.21,0,1965,"2005-11-14");
--enable_query_log
--echo --- Select from t1 on master ---
select *
from t1
order by id;
sync_slave_with_master;
--echo --- Select from t1 on slave ---
select *
from t1
order by id;
--echo --- Perform basic operation on master ---
--echo --- and ensure replicated correctly ---
connection master;
--echo --- Update t1 on master --
UPDATE t1 SET b1 = 0, bc='updated', t="2006-02-22"
WHERE id < 100
ORDER BY id;
--echo --- Check the update on master ---
SELECT *
FROM t1
WHERE id < 100
ORDER BY id;
# Must give injector thread a little time to get update
# into the binlog other wise we will miss the update.
sync_slave_with_master;
--echo --- Check Update on slave ---
SELECT *
FROM t1
WHERE id < 100
ORDER BY id;
connection master;
--echo --- Remove a record from t1 on master ---
# Note: there is an error in replication of Delete_row
# from NDB to MyISAM (BUG#28538). However, if there is
# only one row in Delete_row event then it works fine,
# as this test demonstrates.
DELETE FROM t1 WHERE id = 412;
--echo --- Show current count on master for t1 ---
SELECT COUNT(*) FROM t1;
sync_slave_with_master;
--echo --- Show current count on slave for t1 ---
SELECT COUNT(*) FROM t1;
connection master;
TRUNCATE TABLE t1;
sync_slave_with_master;
connection master;
This diff is collapsed.
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
rpl_ndb_2innodb : BUG#19227 2006-04-20 pekka pk delete apparently not replicated rpl_ndb_2innodb : BUG#19227 2006-04-20 pekka pk delete apparently not replicated
rpl_ndb_2myisam : BUG#19227 Seems to pass currently rpl_ndb_2myisam : BUG#19227 Seems to pass currently
rpl_ndb_dd_partitions : BUG#19259 2006-04-21 rpl_ndb_dd_partitions fails on s/AMD rpl_ndb_dd_partitions : BUG#19259 2006-04-21 rpl_ndb_dd_partitions fails on s/AMD
#rpl_ndb_innodb2ndb : Bug#29549 rpl_ndb_myisam2ndb,rpl_ndb_innodb2ndb failed on Solaris for pack_length issue rpl_ndb_innodb2ndb : Bug#29549 rpl_ndb_myisam2ndb,rpl_ndb_innodb2ndb failed on Solaris for pack_length issue
#rpl_ndb_myisam2ndb : Bug#29549 rpl_ndb_myisam2ndb,rpl_ndb_innodb2ndb failed on Solaris for pack_length issue rpl_ndb_myisam2ndb : Bug#29549 rpl_ndb_myisam2ndb,rpl_ndb_innodb2ndb failed on Solaris for pack_length issue
rpl_ndb_ddl : BUG#28798 2007-05-31 lars Valgrind failure in NDB rpl_ndb_ddl : BUG#28798 2007-05-31 lars Valgrind failure in NDB
rpl_ndb_mix_innodb : BUG#28123 rpl_ndb_mix_innodb.test casue slave to core on sol10-sparc-a rpl_ndb_mix_innodb : BUG#28123 rpl_ndb_mix_innodb.test casue slave to core on sol10-sparc-a
rpl_ndb_ctype_ucs2_def : BUG#27404 util thd mysql_parse sig11 when mysqld default multibyte charset rpl_ndb_ctype_ucs2_def : BUG#27404 util thd mysql_parse sig11 when mysqld default multibyte charset
......
#############################################################
# Author: Rafal Somla
# Date: 2006-08-20
# Purpose: Trying to test ability to replicate from cluster
# to other engines (innodb, myisam).
##############################################################
--source include/have_ndb.inc
--source include/have_innodb.inc
--source include/have_binlog_format_mixed_or_row.inc
--source include/master-slave.inc
# On master use NDB as storage engine.
connection master;
SET storage_engine=ndb;
--echo
--echo === NDB -> MYISAM ===
--echo
connection slave;
SET storage_engine=myisam;
--source extra/rpl_tests/rpl_ndb_2multi_basic.test
--echo
--echo === NDB -> INNODB ===
--echo
connection slave;
SET storage_engine=innodb;
--source extra/rpl_tests/rpl_ndb_2multi_basic.test
--echo
--echo === NDB -> NDB ===
--echo
connection slave;
SET storage_engine=ndb;
--source extra/rpl_tests/rpl_ndb_2multi_basic.test
-- source include/have_query_cache.inc -- source include/have_query_cache.inc
# Disabled on embedded due to bug #30710, "query_cache.test fails on
# embedded w/ per-column privs test". Please re-enable when that bug
# is resolved.
-- source include/not_embedded.inc
# #
# Tests with query cache # Tests with query cache
# #
......
...@@ -7796,19 +7796,10 @@ uchar *Field_blob::pack(uchar *to, const uchar *from, uint max_length) ...@@ -7796,19 +7796,10 @@ uchar *Field_blob::pack(uchar *to, const uchar *from, uint max_length)
uint32 length=get_length(); // Length of from string uint32 length=get_length(); // Length of from string
if (length > max_length) if (length > max_length)
{ {
ptr=to;
length=max_length; length=max_length;
store_length(length); // Store max length store_length(to,packlength,length,TRUE);
ptr= (uchar*) from;
}
else
#ifdef WORDS_BIGENDIAN
if (table->s->db_low_byte_first)
{
store_length(to,packlength,length,0);
} }
else else
#endif
memcpy(to,from,packlength); // Copy length memcpy(to,from,packlength); // Copy length
if (length) if (length)
{ {
...@@ -7846,16 +7837,7 @@ const uchar *Field_blob::unpack(uchar *to, ...@@ -7846,16 +7837,7 @@ const uchar *Field_blob::unpack(uchar *to,
const uchar *Field_blob::unpack(uchar *to, const uchar *from) const uchar *Field_blob::unpack(uchar *to, const uchar *from)
{ {
uint32 length=get_length(from); uint32 length=get_length(from);
#ifdef WORDS_BIGENDIAN
if (table->s->db_low_byte_first)
{
store_length(to,packlength,length,1);
}
else
#endif
{
memcpy(to,from,packlength); memcpy(to,from,packlength);
}
from+=packlength; from+=packlength;
if (length) if (length)
memcpy_fixed(to+packlength, &from, sizeof(from)); memcpy_fixed(to+packlength, &from, sizeof(from));
......
This diff is collapsed.
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
#include <my_bitmap.h> #include <my_bitmap.h>
#include "rpl_constants.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_EOF -1
#define LOG_READ_BOGUS -2 #define LOG_READ_BOGUS -2
...@@ -2186,7 +2190,13 @@ class Rows_log_event : public Log_event ...@@ -2186,7 +2190,13 @@ class Rows_log_event : public Log_event
NO_FOREIGN_KEY_CHECKS_F = (1U << 1), NO_FOREIGN_KEY_CHECKS_F = (1U << 1),
/* Value of the OPTION_RELAXED_UNIQUE_CHECKS flag in thd->options */ /* 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; typedef uint16 flag_set;
...@@ -2292,6 +2302,25 @@ class Rows_log_event : public Log_event ...@@ -2292,6 +2302,25 @@ class Rows_log_event : public Log_event
flag_set m_flags; /* Flags for row-level events */ flag_set m_flags; /* Flags for row-level events */
/* helper functions */
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
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 */
uchar *m_key; /* Buffer to keep key value during searches */
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: private:
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
...@@ -2315,7 +2344,8 @@ class Rows_log_event : public Log_event ...@@ -2315,7 +2344,8 @@ class Rows_log_event : public Log_event
The member function will return 0 if all went OK, or a non-zero The member function will return 0 if all went OK, or a non-zero
error code otherwise. 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. Primitive to clean up after a sequence of row executions.
...@@ -2325,45 +2355,33 @@ class Rows_log_event : public Log_event ...@@ -2325,45 +2355,33 @@ class Rows_log_event : public Log_event
After doing a sequence of do_prepare_row() and do_exec_row(), After doing a sequence of do_prepare_row() and do_exec_row(),
this member function should be called to clean up and release this member function should be called to clean up and release
any allocated buffers. any allocated buffers.
*/
virtual int do_after_row_operations(TABLE *table, int error) = 0;
/* The error argument, if non-zero, indicates an error which happened during
Primitive to prepare for handling one row in a row-level event. 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.
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*, virtual
uchar const *row_start, int do_after_row_operations(const Slave_reporting_capability *const log,
uchar const **row_end) = 0; int error) = 0;
/* /*
Primitive to do the actual execution necessary for a row. Primitive to do the actual execution necessary for a row.
DESCRIPTION DESCRIPTION
The member function will do the actual execution needed to handle a row. 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 RETURN VALUE
0 if execution succeeded, 1 if execution failed. 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) */ #endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
};
friend class Old_rows_log_event;
};
/***************************************************************************** /*****************************************************************************
...@@ -2413,14 +2431,9 @@ class Write_rows_log_event : public Rows_log_event ...@@ -2413,14 +2431,9 @@ class Write_rows_log_event : public Rows_log_event
#endif #endif
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
uchar *m_memory; virtual int do_before_row_operations(const Slave_reporting_capability *const);
uchar *m_after_image; virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
virtual int do_exec_row(const Relay_log_info *const);
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
}; };
...@@ -2492,15 +2505,9 @@ class Update_rows_log_event : public Rows_log_event ...@@ -2492,15 +2505,9 @@ class Update_rows_log_event : public Rows_log_event
#endif #endif
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
uchar *m_memory; virtual int do_before_row_operations(const Slave_reporting_capability *const);
uchar *m_key; virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
uchar *m_after_image; virtual int do_exec_row(const Relay_log_info *const);
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) */ #endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
}; };
...@@ -2563,15 +2570,9 @@ class Delete_rows_log_event : public Rows_log_event ...@@ -2563,15 +2570,9 @@ class Delete_rows_log_event : public Rows_log_event
#endif #endif
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
uchar *m_memory; virtual int do_before_row_operations(const Slave_reporting_capability *const);
uchar *m_key; virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
uchar *m_after_image; virtual int do_exec_row(const Relay_log_info *const);
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
}; };
......
This diff is collapsed.
...@@ -21,8 +21,89 @@ ...@@ -21,8 +21,89 @@
*/ */
class Write_rows_log_event_old : public Write_rows_log_event 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: public:
enum enum
{ {
...@@ -49,14 +130,26 @@ class Write_rows_log_event_old : public Write_rows_log_event ...@@ -49,14 +130,26 @@ class Write_rows_log_event_old : public Write_rows_log_event
virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; } virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) #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*, virtual int do_prepare_row(THD*, Relay_log_info const*, TABLE*,
uchar const *row_start, uchar const **row_end); uchar const *row_start, uchar const **row_end);
virtual int do_exec_row(TABLE *table);
#endif #endif
}; };
class Update_rows_log_event_old : public Update_rows_log_event class Update_rows_log_event_old
: public Update_rows_log_event, public Old_rows_log_event
{ {
uchar *m_after_image, *m_memory;
public: public:
enum enum
{ {
...@@ -67,14 +160,16 @@ class Update_rows_log_event_old : public Update_rows_log_event ...@@ -67,14 +160,16 @@ class Update_rows_log_event_old : public Update_rows_log_event
#if !defined(MYSQL_CLIENT) #if !defined(MYSQL_CLIENT)
Update_rows_log_event_old(THD *thd, TABLE *table, ulong table_id, Update_rows_log_event_old(THD *thd, TABLE *table, ulong table_id,
MY_BITMAP const *cols, bool is_transactional) MY_BITMAP const *cols, bool is_transactional)
: Update_rows_log_event(thd, table, table_id, cols, is_transactional) : Update_rows_log_event(thd, table, table_id, cols, is_transactional),
m_after_image(NULL), m_memory(NULL)
{ {
} }
#endif #endif
#if defined(HAVE_REPLICATION) #if defined(HAVE_REPLICATION)
Update_rows_log_event_old(const char *buf, uint event_len, Update_rows_log_event_old(const char *buf, uint event_len,
const Format_description_log_event *descr) const Format_description_log_event *descr)
: Update_rows_log_event(buf, event_len, descr) : Update_rows_log_event(buf, event_len, descr),
m_after_image(NULL), m_memory(NULL)
{ {
} }
#endif #endif
...@@ -83,14 +178,25 @@ class Update_rows_log_event_old : public Update_rows_log_event ...@@ -83,14 +178,25 @@ class Update_rows_log_event_old : public Update_rows_log_event
virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; } virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) #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*, virtual int do_prepare_row(THD*, Relay_log_info const*, TABLE*,
uchar const *row_start, uchar const **row_end); uchar const *row_start, uchar const **row_end);
virtual int do_exec_row(TABLE *table);
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */ #endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
}; };
class Delete_rows_log_event_old : public Delete_rows_log_event class Delete_rows_log_event_old
: public Delete_rows_log_event, public Old_rows_log_event
{ {
uchar *m_after_image, *m_memory;
public: public:
enum enum
{ {
...@@ -101,14 +207,16 @@ class Delete_rows_log_event_old : public Delete_rows_log_event ...@@ -101,14 +207,16 @@ class Delete_rows_log_event_old : public Delete_rows_log_event
#if !defined(MYSQL_CLIENT) #if !defined(MYSQL_CLIENT)
Delete_rows_log_event_old(THD *thd, TABLE *table, ulong table_id, Delete_rows_log_event_old(THD *thd, TABLE *table, ulong table_id,
MY_BITMAP const *cols, bool is_transactional) MY_BITMAP const *cols, bool is_transactional)
: Delete_rows_log_event(thd, table, table_id, cols, is_transactional) : Delete_rows_log_event(thd, table, table_id, cols, is_transactional),
m_after_image(NULL), m_memory(NULL)
{ {
} }
#endif #endif
#if defined(HAVE_REPLICATION) #if defined(HAVE_REPLICATION)
Delete_rows_log_event_old(const char *buf, uint event_len, Delete_rows_log_event_old(const char *buf, uint event_len,
const Format_description_log_event *descr) const Format_description_log_event *descr)
: Delete_rows_log_event(buf, event_len, descr) : Delete_rows_log_event(buf, event_len, descr),
m_after_image(NULL), m_memory(NULL)
{ {
} }
#endif #endif
...@@ -117,8 +225,16 @@ class Delete_rows_log_event_old : public Delete_rows_log_event ...@@ -117,8 +225,16 @@ class Delete_rows_log_event_old : public Delete_rows_log_event
virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; } virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) #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*, virtual int do_prepare_row(THD*, Relay_log_info const*, TABLE*,
uchar const *row_start, uchar const **row_end); uchar const *row_start, uchar const **row_end);
virtual int do_exec_row(TABLE *table);
#endif #endif
}; };
......
...@@ -157,9 +157,8 @@ pack_row(TABLE *table, MY_BITMAP const* cols, ...@@ -157,9 +157,8 @@ pack_row(TABLE *table, MY_BITMAP const* cols,
the various member functions of Field and subclasses expect to the various member functions of Field and subclasses expect to
write. write.
The row is assumed to only consist of the fields for which the The row is assumed to only consist of the fields for which the corresponding
bitset represented by @c arr and @c bits; the other parts of the bit in bitset @c cols is set; the other parts of the record are left alone.
record are left alone.
At most @c colcnt columns are read: if the table is larger than At most @c colcnt columns are read: if the table is larger than
that, the remaining fields are not filled in. that, the remaining fields are not filled in.
...@@ -169,16 +168,12 @@ pack_row(TABLE *table, MY_BITMAP const* cols, ...@@ -169,16 +168,12 @@ pack_row(TABLE *table, MY_BITMAP const* cols,
@param colcnt Number of columns to read from record @param colcnt Number of columns to read from record
@param row_data @param row_data
Packed row data Packed row data
@param cols Pointer to columns data to fill in @param cols Pointer to bitset describing columns to fill in
@param row_end Pointer to variable that will hold the value of the @param row_end Pointer to variable that will hold the value of the
one-after-end position for the row one-after-end position for the row
@param master_reclength @param master_reclength
Pointer to variable that will be set to the length of the Pointer to variable that will be set to the length of the
record on the master side record on the master side
@param rw_set Pointer to bitmap that holds either the read_set or the
write_set of the table
@param event_type
@retval 0 No error @retval 0 No error
...@@ -192,8 +187,7 @@ int ...@@ -192,8 +187,7 @@ int
unpack_row(Relay_log_info const *rli, unpack_row(Relay_log_info const *rli,
TABLE *table, uint const colcnt, TABLE *table, uint const colcnt,
uchar const *const row_data, MY_BITMAP const *cols, uchar const *const row_data, MY_BITMAP const *cols,
uchar const **const row_end, ulong *const master_reclength, uchar const **const row_end, ulong *const master_reclength)
MY_BITMAP* const rw_set, Log_event_type const event_type)
{ {
DBUG_ENTER("unpack_row"); DBUG_ENTER("unpack_row");
DBUG_ASSERT(row_data); DBUG_ASSERT(row_data);
...@@ -203,10 +197,6 @@ unpack_row(Relay_log_info const *rli, ...@@ -203,10 +197,6 @@ unpack_row(Relay_log_info const *rli,
uchar const *null_ptr= row_data; uchar const *null_ptr= row_data;
uchar const *pack_ptr= row_data + master_null_byte_count; uchar const *pack_ptr= row_data + master_null_byte_count;
bitmap_clear_all(rw_set);
empty_record(table);
Field **const begin_ptr = table->field; Field **const begin_ptr = table->field;
Field **field_ptr; Field **field_ptr;
Field **const end_ptr= begin_ptr + colcnt; Field **const end_ptr= begin_ptr + colcnt;
...@@ -266,7 +256,6 @@ unpack_row(Relay_log_info const *rli, ...@@ -266,7 +256,6 @@ unpack_row(Relay_log_info const *rli,
#endif #endif
} }
bitmap_set_bit(rw_set, f->field_index);
null_mask <<= 1; null_mask <<= 1;
} }
i++; i++;
...@@ -309,29 +298,57 @@ unpack_row(Relay_log_info const *rli, ...@@ -309,29 +298,57 @@ unpack_row(Relay_log_info const *rli,
*master_reclength = table->s->reclength; *master_reclength = table->s->reclength;
} }
/* DBUG_RETURN(error);
Set properties for remaining columns, if there are any. We let the }
corresponding bit in the write_set be set, to write the value if
it was not there already. We iterate over all remaining columns, /**
even if there were an error, to get as many error messages as Fills @c table->record[0] with default values.
possible. We are still able to return a pointer to the next row,
so redo that. First @c empty_record() is called and then, additionally, fields are
initialized explicitly with a call to @c set_default().
This generation of error messages is only relevant when inserting
new rows. For optimization reasons, the explicit initialization can be skipped for
first @c skip fields. This is useful if later we are going to fill these
fields from other source (e.g. from a Rows replication event).
If @c check is true, fields are explicitly initialized only if they have
default value or can be NULL. Otherwise error is reported.
@param log Used to report errors.
@param table Table whose record[0] buffer is prepared.
@param skip Number of columns for which default value initialization
should be skipped.
@param check Indicates if errors should be checked when setting default
values.
@returns 0 on success.
*/ */
for ( ; *field_ptr ; ++field_ptr) int prepare_record(const Slave_reporting_capability *const log,
TABLE *const table,
const uint skip, const bool check)
{
DBUG_ENTER("prepare_record");
int error= 0;
empty_record(table);
if (skip >= table->s->fields) // nothing to do
DBUG_RETURN(0);
/* Explicit initialization of fields */
for (Field **field_ptr= table->field+skip ; *field_ptr ; ++field_ptr)
{ {
uint32 const mask= NOT_NULL_FLAG | NO_DEFAULT_VALUE_FLAG; uint32 const mask= NOT_NULL_FLAG | NO_DEFAULT_VALUE_FLAG;
Field *const f= *field_ptr; Field *const f= *field_ptr;
if (event_type == WRITE_ROWS_EVENT && if (check && ((f->flags & mask) == mask))
((*field_ptr)->flags & mask) == mask)
{ {
rli->report(ERROR_LEVEL, ER_NO_DEFAULT_FOR_FIELD, DBUG_ASSERT(log);
log->report(ERROR_LEVEL, ER_NO_DEFAULT_FOR_FIELD,
"Field `%s` of table `%s`.`%s` " "Field `%s` of table `%s`.`%s` "
"has no default value and cannot be NULL", "has no default value and cannot be NULL",
(*field_ptr)->field_name, table->s->db.str, f->field_name, table->s->db.str,
table->s->table_name.str); table->s->table_name.str);
error = ER_NO_DEFAULT_FOR_FIELD; error = ER_NO_DEFAULT_FOR_FIELD;
} }
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#ifndef RPL_RECORD_H #ifndef RPL_RECORD_H
#define RPL_RECORD_H #define RPL_RECORD_H
#include <rpl_reporting.h>
#if !defined(MYSQL_CLIENT) #if !defined(MYSQL_CLIENT)
size_t pack_row(TABLE* table, MY_BITMAP const* cols, size_t pack_row(TABLE* table, MY_BITMAP const* cols,
uchar *row_data, const uchar *data); uchar *row_data, const uchar *data);
...@@ -25,9 +27,11 @@ size_t pack_row(TABLE* table, MY_BITMAP const* cols, ...@@ -25,9 +27,11 @@ size_t pack_row(TABLE* table, MY_BITMAP const* cols,
int unpack_row(Relay_log_info const *rli, int unpack_row(Relay_log_info const *rli,
TABLE *table, uint const colcnt, TABLE *table, uint const colcnt,
uchar const *const row_data, MY_BITMAP const *cols, uchar const *const row_data, MY_BITMAP const *cols,
uchar const **const row_end, ulong *const master_reclength, uchar const **const row_end, ulong *const master_reclength);
MY_BITMAP* const rw_set,
Log_event_type const event_type); // Fill table's record[0] with default values.
int prepare_record(const Slave_reporting_capability *const, TABLE *const,
const uint =0, const bool =FALSE);
#endif #endif
#endif #endif
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
This function returns the field size in raw bytes based on the type This function returns the field size in raw bytes based on the type
and the encoded field data from the master's raw data. and the encoded field data from the master's raw data.
*/ */
uint32 table_def::calc_field_size(uint col, uchar *master_data) uint32 table_def::calc_field_size(uint col, uchar *master_data) const
{ {
uint32 length; uint32 length;
......
...@@ -217,7 +217,7 @@ class table_def ...@@ -217,7 +217,7 @@ class table_def
WL#3915) or needs to advance the pointer for the fields in the raw WL#3915) or needs to advance the pointer for the fields in the raw
data from the master to a specific column. data from the master to a specific column.
*/ */
uint32 calc_field_size(uint col, uchar *master_data); uint32 calc_field_size(uint col, uchar *master_data) const;
/** /**
Decide if the table definition is compatible with a table. Decide if the table definition is compatible with a table.
...@@ -258,4 +258,44 @@ struct RPL_TABLE_LIST ...@@ -258,4 +258,44 @@ struct RPL_TABLE_LIST
table_def m_tabledef; table_def m_tabledef;
}; };
/* Anonymous namespace for template functions/classes */
namespace {
/*
Smart pointer that will automatically call my_afree (a macro) when
the pointer goes out of scope. This is used so that I do not have
to remember to call my_afree() before each return. There is no
overhead associated with this, since all functions are inline.
I (Matz) would prefer to use the free function as a template
parameter, but that is not possible when the "function" is a
macro.
*/
template <class Obj>
class auto_afree_ptr
{
Obj* m_ptr;
public:
auto_afree_ptr(Obj* ptr) : m_ptr(ptr) { }
~auto_afree_ptr() { if (m_ptr) my_afree(m_ptr); }
void assign(Obj* ptr) {
/* Only to be called if it hasn't been given a value before. */
DBUG_ASSERT(m_ptr == NULL);
m_ptr= ptr;
}
Obj* get() { return m_ptr; }
};
}
#define DBUG_PRINT_BITSET(N,FRM,BS) \
do { \
char buf[256]; \
for (uint i = 0 ; i < (BS)->n_bits ; ++i) \
buf[i] = bitmap_is_set((BS), i) ? '1' : '0'; \
buf[(BS)->n_bits] = '\0'; \
DBUG_PRINT((N), ((FRM), buf)); \
} while (0)
#endif /* RPL_UTILITY_H */ #endif /* RPL_UTILITY_H */
...@@ -132,6 +132,11 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, ...@@ -132,6 +132,11 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
const char* table_name, bool overwrite); const char* table_name, bool overwrite);
static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi); static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi);
static Log_event* next_event(Relay_log_info* rli); static Log_event* next_event(Relay_log_info* rli);
static int terminate_slave_thread(THD *thd,
pthread_mutex_t* term_lock,
pthread_cond_t* term_cond,
volatile uint *slave_running,
bool skip_lock);
/* /*
Find out which replications threads are running Find out which replications threads are running
...@@ -312,35 +317,26 @@ int terminate_slave_threads(Master_info* mi,int thread_mask,bool skip_lock) ...@@ -312,35 +317,26 @@ int terminate_slave_threads(Master_info* mi,int thread_mask,bool skip_lock)
DBUG_RETURN(0); /* successfully do nothing */ DBUG_RETURN(0); /* successfully do nothing */
int error,force_all = (thread_mask & SLAVE_FORCE_ALL); int error,force_all = (thread_mask & SLAVE_FORCE_ALL);
pthread_mutex_t *sql_lock = &mi->rli.run_lock, *io_lock = &mi->run_lock; pthread_mutex_t *sql_lock = &mi->rli.run_lock, *io_lock = &mi->run_lock;
pthread_mutex_t *sql_cond_lock,*io_cond_lock;
sql_cond_lock=sql_lock; if ((thread_mask & (SLAVE_IO|SLAVE_FORCE_ALL)))
io_cond_lock=io_lock;
if (skip_lock)
{
sql_lock = io_lock = 0;
}
if ((thread_mask & (SLAVE_IO|SLAVE_FORCE_ALL)) && mi->slave_running)
{ {
DBUG_PRINT("info",("Terminating IO thread")); DBUG_PRINT("info",("Terminating IO thread"));
mi->abort_slave=1; mi->abort_slave=1;
if ((error=terminate_slave_thread(mi->io_thd,io_lock, if ((error=terminate_slave_thread(mi->io_thd,io_lock,
io_cond_lock,
&mi->stop_cond, &mi->stop_cond,
&mi->slave_running)) && &mi->slave_running,
skip_lock)) &&
!force_all) !force_all)
DBUG_RETURN(error); DBUG_RETURN(error);
} }
if ((thread_mask & (SLAVE_SQL|SLAVE_FORCE_ALL)) && mi->rli.slave_running) if ((thread_mask & (SLAVE_SQL|SLAVE_FORCE_ALL)))
{ {
DBUG_PRINT("info",("Terminating SQL thread")); DBUG_PRINT("info",("Terminating SQL thread"));
DBUG_ASSERT(mi->rli.sql_thd != 0) ;
mi->rli.abort_slave=1; mi->rli.abort_slave=1;
if ((error=terminate_slave_thread(mi->rli.sql_thd,sql_lock, if ((error=terminate_slave_thread(mi->rli.sql_thd,sql_lock,
sql_cond_lock,
&mi->rli.stop_cond, &mi->rli.stop_cond,
&mi->rli.slave_running)) && &mi->rli.slave_running,
skip_lock)) &&
!force_all) !force_all)
DBUG_RETURN(error); DBUG_RETURN(error);
} }
...@@ -348,23 +344,60 @@ int terminate_slave_threads(Master_info* mi,int thread_mask,bool skip_lock) ...@@ -348,23 +344,60 @@ int terminate_slave_threads(Master_info* mi,int thread_mask,bool skip_lock)
} }
int terminate_slave_thread(THD* thd, pthread_mutex_t* term_lock, /**
pthread_mutex_t *cond_lock, Wait for a slave thread to terminate.
This function is called after requesting the thread to terminate
(by setting @c abort_slave member of @c Relay_log_info or @c
Master_info structure to 1). Termination of the thread is
controlled with the the predicate <code>*slave_running</code>.
Function will acquire @c term_lock before waiting on the condition
unless @c skip_lock is true in which case the mutex should be owned
by the caller of this function and will remain acquired after
return from the function.
@param term_lock
Associated lock to use when waiting for @c term_cond
@param term_cond
Condition that is signalled when the thread has terminated
@param slave_running
Pointer to predicate to check for slave thread termination
@param skip_lock
If @c true the lock will not be acquired before waiting on
the condition. In this case, it is assumed that the calling
function acquires the lock before calling this function.
@retval 0 All OK
*/
static int
terminate_slave_thread(THD *thd,
pthread_mutex_t* term_lock,
pthread_cond_t* term_cond, pthread_cond_t* term_cond,
volatile uint *slave_running) volatile uint *slave_running,
bool skip_lock)
{ {
int error;
DBUG_ENTER("terminate_slave_thread"); DBUG_ENTER("terminate_slave_thread");
if (term_lock)
{ if (!skip_lock)
pthread_mutex_lock(term_lock); pthread_mutex_lock(term_lock);
safe_mutex_assert_owner(term_lock);
if (!*slave_running) if (!*slave_running)
{ {
if (!skip_lock)
pthread_mutex_unlock(term_lock); pthread_mutex_unlock(term_lock);
DBUG_RETURN(ER_SLAVE_NOT_RUNNING); DBUG_RETURN(ER_SLAVE_NOT_RUNNING);
} }
}
DBUG_ASSERT(thd != 0); DBUG_ASSERT(thd != 0);
THD_CHECK_SENTRY(thd); THD_CHECK_SENTRY(thd);
/* /*
Is is critical to test if the slave is running. Otherwise, we might Is is critical to test if the slave is running. Otherwise, we might
be referening freed memory trying to kick it be referening freed memory trying to kick it
...@@ -380,9 +413,13 @@ int terminate_slave_thread(THD* thd, pthread_mutex_t* term_lock, ...@@ -380,9 +413,13 @@ int terminate_slave_thread(THD* thd, pthread_mutex_t* term_lock,
*/ */
struct timespec abstime; struct timespec abstime;
set_timespec(abstime,2); set_timespec(abstime,2);
pthread_cond_timedwait(term_cond, cond_lock, &abstime); error= pthread_cond_timedwait(term_cond, term_lock, &abstime);
DBUG_ASSERT(error == ETIMEDOUT || error == 0);
} }
if (term_lock)
DBUG_ASSERT(*slave_running == 0);
if (!skip_lock)
pthread_mutex_unlock(term_lock); pthread_mutex_unlock(term_lock);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
......
...@@ -138,10 +138,6 @@ bool flush_relay_log_info(Relay_log_info* rli); ...@@ -138,10 +138,6 @@ bool flush_relay_log_info(Relay_log_info* rli);
int register_slave_on_master(MYSQL* mysql); int register_slave_on_master(MYSQL* mysql);
int terminate_slave_threads(Master_info* mi, int thread_mask, int terminate_slave_threads(Master_info* mi, int thread_mask,
bool skip_lock = 0); bool skip_lock = 0);
int terminate_slave_thread(THD* thd, pthread_mutex_t* term_mutex,
pthread_mutex_t* cond_lock,
pthread_cond_t* term_cond,
volatile uint* slave_running);
int start_slave_threads(bool need_slave_mutex, bool wait_for_start, int start_slave_threads(bool need_slave_mutex, bool wait_for_start,
Master_info* mi, const char* master_info_fname, Master_info* mi, const char* master_info_fname,
const char* slave_info_fname, int thread_mask); const char* slave_info_fname, int thread_mask);
......
...@@ -209,7 +209,7 @@ dict_mem_table_add_col( ...@@ -209,7 +209,7 @@ dict_mem_table_add_col(
col = (dict_col_t*) dict_table_get_nth_col(table, i); col = (dict_col_t*) dict_table_get_nth_col(table, i);
col->ind = i; col->ind = (unsigned int) i;
col->ord_part = 0; col->ord_part = 0;
col->mtype = (unsigned int) mtype; col->mtype = (unsigned int) mtype;
......
...@@ -7220,7 +7220,7 @@ ulong ...@@ -7220,7 +7220,7 @@ ulong
ha_innobase::innobase_get_auto_increment( ha_innobase::innobase_get_auto_increment(
ulonglong* value) /* out: autoinc value */ ulonglong* value) /* out: autoinc value */
{ {
ulint error; ulong error;
do { do {
error = innobase_autoinc_lock(); error = innobase_autoinc_lock();
...@@ -7323,7 +7323,7 @@ ha_innobase::get_auto_increment( ...@@ -7323,7 +7323,7 @@ ha_innobase::get_auto_increment(
/* Called for the first time ? */ /* Called for the first time ? */
if (prebuilt->trx->n_autoinc_rows == 0) { if (prebuilt->trx->n_autoinc_rows == 0) {
prebuilt->trx->n_autoinc_rows = nb_desired_values; prebuilt->trx->n_autoinc_rows = (ulint) nb_desired_values;
/* It's possible for nb_desired_values to be 0: /* It's possible for nb_desired_values to be 0:
e.g., INSERT INTO T1(C) SELECT C FROM T2; */ e.g., INSERT INTO T1(C) SELECT C FROM T2; */
......
...@@ -4555,6 +4555,15 @@ row_search_autoinc_read_column( ...@@ -4555,6 +4555,15 @@ row_search_autoinc_read_column(
ut_a(len != UNIV_SQL_NULL); ut_a(len != UNIV_SQL_NULL);
ut_a(len <= sizeof value); ut_a(len <= sizeof value);
#ifdef WORDS_BIGENDIAN
/* Copy integer data and restore sign bit */
memcpy((ptr = dest), data, len);
if (!unsigned_type) {
dest[0] ^= 128;
}
#else
/* Convert integer data from Innobase to a little-endian format, /* Convert integer data from Innobase to a little-endian format,
sign bit restored to normal */ sign bit restored to normal */
...@@ -4566,6 +4575,7 @@ row_search_autoinc_read_column( ...@@ -4566,6 +4575,7 @@ row_search_autoinc_read_column(
if (!unsigned_type) { if (!unsigned_type) {
dest[len - 1] ^= 128; dest[len - 1] ^= 128;
} }
#endif
/* The assumption here is that the AUTOINC value can't be negative.*/ /* The assumption here is that the AUTOINC value can't be negative.*/
switch (len) { switch (len) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment