Merge lp:~tsarev/percona-server/5.1-18205_02_wl36.patch into lp:percona-server/5.1

Proposed by Oleg Tsarev
Status: Superseded
Proposed branch: lp:~tsarev/percona-server/5.1-18205_02_wl36.patch
Merge into: lp:percona-server/5.1
Diff against target: 1037 lines (+572/-29)
24 files modified
Percona-Server/client/Makefile.am (+3/-1)
Percona-Server/client/client_priv.h (+1/-0)
Percona-Server/client/mysqlbinlog.cc (+159/-9)
Percona-Server/client/sql_string.cc (+0/-9)
Percona-Server/client/sql_string.h (+5/-0)
Percona-Server/mysql-test/include/wl36.inc (+51/-0)
Percona-Server/mysql-test/r/mysqlbinlog.result (+2/-6)
Percona-Server/mysql-test/r/wl36-mixed.result (+48/-0)
Percona-Server/mysql-test/r/wl36-row.result (+48/-0)
Percona-Server/mysql-test/r/wl36-statement.result (+48/-0)
Percona-Server/mysql-test/t/wl36-mixed.test (+3/-0)
Percona-Server/mysql-test/t/wl36-row.test (+3/-0)
Percona-Server/mysql-test/t/wl36-statement.test (+3/-0)
Percona-Server/sql/log_event.cc (+106/-1)
Percona-Server/sql/log_event.h (+16/-2)
Percona-Server/sql/mysql_priv.h (+4/-0)
Percona-Server/sql/mysqld.cc (+1/-0)
Percona-Server/sql/rpl_filter.cc (+9/-0)
Percona-Server/sql/rpl_filter.h (+4/-1)
Percona-Server/sql/sql_string.cc (+3/-0)
Percona-Server/sql/sql_string.h (+9/-0)
Percona-Server/sql/thr_malloc.cc (+2/-0)
doc/source/flexibility/mysqlbinlog_change_db.rst (+43/-0)
doc/source/index.rst (+1/-0)
To merge this branch: bzr merge lp:~tsarev/percona-server/5.1-18205_02_wl36.patch
Reviewer Review Type Date Requested Status
Laurynas Biveinis (community) Needs Information
Review via email: mp+91985@code.launchpad.net

This proposal has been superseded by a proposal from 2012-02-09.

To post a comment you must log in.
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote :

For the feature branch to go in, it needs an associated blueprint on Launchpad.

review: Needs Information

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Percona-Server/client/Makefile.am'
--- Percona-Server/client/Makefile.am 2011-07-03 15:47:37 +0000
+++ Percona-Server/client/Makefile.am 2012-02-09 15:07:20 +0000
@@ -24,6 +24,7 @@
24INCLUDES = -I$(top_builddir)/include \24INCLUDES = -I$(top_builddir)/include \
25 -I$(top_srcdir)/include \25 -I$(top_srcdir)/include \
26 -I$(top_srcdir)/regex \26 -I$(top_srcdir)/regex \
27 -I$(top_srcdir)/sql \
27 $(openssl_includes)28 $(openssl_includes)
2829
29LIBS = @CLIENT_LIBS@30LIBS = @CLIENT_LIBS@
@@ -107,7 +108,8 @@
107 rpl_utility.h rpl_tblmap.h rpl_tblmap.cc \108 rpl_utility.h rpl_tblmap.h rpl_tblmap.cc \
108 log_event.cc my_decimal.h my_decimal.cc \109 log_event.cc my_decimal.h my_decimal.cc \
109 log_event_old.h log_event_old.cc \110 log_event_old.h log_event_old.cc \
110 rpl_record_old.h rpl_record_old.cc111 rpl_record_old.h rpl_record_old.cc \
112 sql_list.h rpl_filter.h sql_list.cc rpl_filter.cc
111strings_src=decimal.c113strings_src=decimal.c
112114
113link_sources:115link_sources:
114116
=== modified file 'Percona-Server/client/client_priv.h'
--- Percona-Server/client/client_priv.h 2011-11-24 02:01:33 +0000
+++ Percona-Server/client/client_priv.h 2012-02-09 15:07:20 +0000
@@ -97,6 +97,7 @@
97 OPT_SYSLOG,97 OPT_SYSLOG,
98#endif98#endif
99 OPT_FIRST_SLAVE,99 OPT_FIRST_SLAVE,
100 OPT_REWRITE_DB,
100 OPT_ALL,101 OPT_ALL,
101 OPT_NO_REMOVE_EOL_CARRET,102 OPT_NO_REMOVE_EOL_CARRET,
102 OPT_INNODB_OPTIMIZE_KEYS,103 OPT_INNODB_OPTIMIZE_KEYS,
103104
=== modified file 'Percona-Server/client/mysqlbinlog.cc'
--- Percona-Server/client/mysqlbinlog.cc 2011-07-11 16:13:27 +0000
+++ Percona-Server/client/mysqlbinlog.cc 2012-02-09 15:07:20 +0000
@@ -38,6 +38,15 @@
38#include "sql_common.h"38#include "sql_common.h"
39#include <welcome_copyright_notice.h> // ORACLE_WELCOME_COPYRIGHT_NOTICE39#include <welcome_copyright_notice.h> // ORACLE_WELCOME_COPYRIGHT_NOTICE
4040
41/* Needed for Rpl_filter */
42CHARSET_INFO* system_charset_info= &my_charset_utf8_general_ci;
43
44#include "sql_string.h" // needed for Rpl_filter
45#include "sql_list.h" // needed for Rpl_filter
46#include "rpl_filter.h"
47
48Rpl_filter *binlog_filter;
49
41#define BIN_LOG_HEADER_SIZE 450#define BIN_LOG_HEADER_SIZE 4
42#define PROBE_HEADER_LEN (EVENT_LEN_OFFSET+4)51#define PROBE_HEADER_LEN (EVENT_LEN_OFFSET+4)
4352
@@ -623,6 +632,49 @@
623632
624633
625/**634/**
635 Print "use <db>" statement when current db is to be changed.
636
637 We have to control emiting USE statements according to rewrite-db options.
638 We have to do it here (see process_event() below) and to suppress
639 producing USE statements by corresponding log event print-functions.
640*/
641void print_use_stmt(PRINT_EVENT_INFO* pinfo, const char* db, size_t db_len)
642{
643 /*
644 pinfo->db is the current db.
645 If current db is the same as required db, do nothing.
646 */
647 if (!db || !memcmp(pinfo->db, db, db_len + 1))
648 return;
649
650 /*
651 Current db and required db are different.
652 Check for rewrite rule for required db. (Note that in a rewrite rule
653 neither db_from nor db_to part can be empty)
654 */
655 size_t len_to= 0;
656 const char* db_to= binlog_filter->get_rewrite_db(db, &len_to);
657
658 /*
659 If there is no rewrite rule for db (in this case len_to is left = 0),
660 printing of the corresponding USE statement is left for log event
661 print-function.
662 */
663 if (!len_to)
664 return;
665
666 // In case of rewrite rule print USE statement for db_to
667 fprintf(result_file, "use %s%s\n", db_to, pinfo->delimiter);
668
669 /*
670 Copy the *original* db to pinfo to suppress emiting
671 of USE stmts by log_event print-functions.
672 */
673 memcpy(pinfo->db, db, db_len + 1);
674}
675
676
677/**
626 Prints the given event in base64 format.678 Prints the given event in base64 format.
627679
628 The header is printed to the head cache and the body is printed to680 The header is printed to the head cache and the body is printed to
@@ -741,9 +793,22 @@
741793
742 switch (ev_type) {794 switch (ev_type) {
743 case QUERY_EVENT:795 case QUERY_EVENT:
744 if (!((Query_log_event*)ev)->is_trans_keyword() &&796 {
745 shall_skip_database(((Query_log_event*)ev)->db))797 Query_log_event *qe= (Query_log_event*)ev;
746 goto end;798 if (!qe->is_trans_keyword())
799 {
800 if (shall_skip_database(qe->db))
801 goto end;
802 }
803 else
804 {
805 /*
806 In case the event for one of these statements is obtained
807 from 5.0 binary log, make it compatible with 5.1.
808 */
809 ev->flags|= LOG_EVENT_SUPPRESS_USE_F;
810 }
811 print_use_stmt(print_event_info, qe->db, qe->db_len);
747 if (opt_base64_output_mode == BASE64_OUTPUT_ALWAYS)812 if (opt_base64_output_mode == BASE64_OUTPUT_ALWAYS)
748 {813 {
749 if ((retval= write_event_header_and_base64(ev, result_file,814 if ((retval= write_event_header_and_base64(ev, result_file,
@@ -754,6 +819,7 @@
754 else819 else
755 ev->print(result_file, print_event_info);820 ev->print(result_file, print_event_info);
756 break;821 break;
822 }
757823
758 case CREATE_FILE_EVENT:824 case CREATE_FILE_EVENT:
759 {825 {
@@ -875,6 +941,7 @@
875941
876 if (!shall_skip_database(exlq->db))942 if (!shall_skip_database(exlq->db))
877 {943 {
944 print_use_stmt(print_event_info, exlq->db, exlq->db_len);
878 if (fname)945 if (fname)
879 {946 {
880 convert_path_to_forward_slashes(fname);947 convert_path_to_forward_slashes(fname);
@@ -898,6 +965,14 @@
898 destroy_evt= FALSE;965 destroy_evt= FALSE;
899 goto end;966 goto end;
900 }967 }
968 size_t len_to= 0;
969 const char* db_to= binlog_filter->get_rewrite_db(map->get_db_name(),
970 &len_to);
971 if (len_to && map->rewrite_db(db_to, len_to, glob_description_event))
972 {
973 error("Could not rewrite database name");
974 goto err;
975 }
901 }976 }
902 case WRITE_ROWS_EVENT:977 case WRITE_ROWS_EVENT:
903 case DELETE_ROWS_EVENT:978 case DELETE_ROWS_EVENT:
@@ -983,15 +1058,19 @@
983 retval= ERROR_STOP;1058 retval= ERROR_STOP;
984end:1059end:
985 rec_count++;1060 rec_count++;
1061
1062
986 /*1063 /*
987 Destroy the log_event object. If reading from a remote host,1064 Destroy the log_event object.
988 set the temp_buf to NULL so that memory isn't freed twice.1065 MariaDB MWL#36: mainline does this:
1066 If reading from a remote host,
1067 set the temp_buf to NULL so that memory isn't freed twice.
1068 We no longer do that, we use Rpl_filter::event_owns_temp_buf instead.
989 */1069 */
990 if (ev)1070 if (ev)
991 {1071 {
992 if (remote_opt)1072 /* destroy it later if not set (ignored table map) */
993 ev->temp_buf= 0;1073 if (destroy_evt)
994 if (destroy_evt) /* destroy it later if not set (ignored table map) */
995 delete ev;1074 delete ev;
996 }1075 }
997 DBUG_RETURN(retval);1076 DBUG_RETURN(retval);
@@ -1156,6 +1235,10 @@
1156 "Used to reserve file descriptors for use by this program.",1235 "Used to reserve file descriptors for use by this program.",
1157 &open_files_limit, &open_files_limit, 0, GET_ULONG,1236 &open_files_limit, &open_files_limit, 0, GET_ULONG,
1158 REQUIRED_ARG, MY_NFILE, 8, OS_FILE_LIMIT, 0, 1, 0},1237 REQUIRED_ARG, MY_NFILE, 8, OS_FILE_LIMIT, 0, 1, 0},
1238 {"rewrite-db", OPT_REWRITE_DB,
1239 "Updates to a database with a different name than the original. \
1240Example: rewrite-db='from->to'.",
1241 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1159 {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}1242 {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
1160};1243};
11611244
@@ -1347,6 +1430,53 @@
1347 (find_type_or_exit(argument, &base64_output_mode_typelib, opt->name)-1);1430 (find_type_or_exit(argument, &base64_output_mode_typelib, opt->name)-1);
1348 }1431 }
1349 break;1432 break;
1433 case OPT_REWRITE_DB: // db_from->db_to
1434 {
1435 /* See also handling of OPT_REPLICATE_REWRITE_DB in sql/mysqld.cc */
1436 char* ptr;
1437 char* key= argument; // db-from
1438 char* val; // db-to
1439
1440 // Where key begins
1441 while (*key && my_isspace(&my_charset_latin1, *key))
1442 key++;
1443
1444 // Where val begins
1445 if (!(ptr= strstr(argument, "->")))
1446 {
1447 sql_print_error("Bad syntax in rewrite-db: missing '->'!\n");
1448 return 1;
1449 }
1450 val= ptr + 2;
1451 while (*val && my_isspace(&my_charset_latin1, *val))
1452 val++;
1453
1454 // Write \0 and skip blanks at the end of key
1455 *ptr-- = 0;
1456 while (my_isspace(&my_charset_latin1, *ptr) && ptr > argument)
1457 *ptr-- = 0;
1458
1459 if (!*key)
1460 {
1461 sql_print_error("Bad syntax in rewrite-db: empty db-from!\n");
1462 return 1;
1463 }
1464
1465 // Skip blanks at the end of val
1466 ptr= val;
1467 while (*ptr && !my_isspace(&my_charset_latin1, *ptr))
1468 ptr++;
1469 *ptr= 0;
1470
1471 if (!*val)
1472 {
1473 sql_print_error("Bad syntax in rewrite-db: empty db-to!\n");
1474 return 1;
1475 }
1476
1477 binlog_filter->add_db_rewrite(key, val);
1478 break;
1479 }
1350 case 'v':1480 case 'v':
1351 if (argument == disabled_my_option)1481 if (argument == disabled_my_option)
1352 verbose= 0;1482 verbose= 0;
@@ -1616,7 +1746,7 @@
1616 If reading from a remote host, ensure the temp_buf for the1746 If reading from a remote host, ensure the temp_buf for the
1617 Log_event class is pointing to the incoming stream.1747 Log_event class is pointing to the incoming stream.
1618 */1748 */
1619 ev->register_temp_buf((char *) net->read_pos + 1);1749 ev->register_temp_buf((char *) net->read_pos + 1, FALSE);
16201750
1621 Log_event_type type= ev->get_type_code();1751 Log_event_type type= ev->get_type_code();
1622 if (glob_description_event->binlog_version >= 3 ||1752 if (glob_description_event->binlog_version >= 3 ||
@@ -2016,6 +2146,8 @@
2016 return retval;2146 return retval;
2017}2147}
20182148
2149/* Used in sql_alloc(). Inited and freed in main() */
2150MEM_ROOT s_mem_root;
20192151
2020int main(int argc, char** argv)2152int main(int argc, char** argv)
2021{2153{
@@ -2028,6 +2160,13 @@
20282160
2029 my_init_time(); // for time functions2161 my_init_time(); // for time functions
20302162
2163 init_alloc_root(&s_mem_root, 16384, 0);
2164 if (!(binlog_filter= new Rpl_filter))
2165 {
2166 error("Failed to create Rpl_filter");
2167 exit(1);
2168 }
2169
2031 if (load_defaults("my", load_default_groups, &argc, &argv))2170 if (load_defaults("my", load_default_groups, &argc, &argv))
2032 exit(1);2171 exit(1);
2033 defaults_argv= argv;2172 defaults_argv= argv;
@@ -2116,6 +2255,8 @@
2116 if (result_file != stdout)2255 if (result_file != stdout)
2117 my_fclose(result_file, MYF(0));2256 my_fclose(result_file, MYF(0));
2118 cleanup();2257 cleanup();
2258 delete binlog_filter;
2259 free_root(&s_mem_root, MYF(0));
2119 free_defaults(defaults_argv);2260 free_defaults(defaults_argv);
2120 my_free_open_file_info();2261 my_free_open_file_info();
2121 load_processor.destroy();2262 load_processor.destroy();
@@ -2127,6 +2268,12 @@
2127 DBUG_RETURN(retval == ERROR_STOP ? 1 : 0);2268 DBUG_RETURN(retval == ERROR_STOP ? 1 : 0);
2128}2269}
21292270
2271
2272void *sql_alloc(size_t size)
2273{
2274 return alloc_root(&s_mem_root, size);
2275}
2276
2130/*2277/*
2131 We must include this here as it's compiled with different options for2278 We must include this here as it's compiled with different options for
2132 the server2279 the server
@@ -2137,4 +2284,7 @@
2137#include "my_decimal.cc"2284#include "my_decimal.cc"
2138#include "log_event.cc"2285#include "log_event.cc"
2139#include "log_event_old.cc"2286#include "log_event_old.cc"
2287#include "sql_string.cc"
2288#include "sql_list.cc"
2289#include "rpl_filter.cc"
21402290
21412291
=== modified file 'Percona-Server/client/sql_string.cc'
--- Percona-Server/client/sql_string.cc 2011-11-01 06:50:54 +0000
+++ Percona-Server/client/sql_string.cc 2012-02-09 15:07:20 +0000
@@ -28,15 +28,6 @@
28#ifdef HAVE_FCONVERT28#ifdef HAVE_FCONVERT
29#include <floatingpoint.h>29#include <floatingpoint.h>
30#endif30#endif
31
32/*
33 The following extern declarations are ok as these are interface functions
34 required by the string function
35*/
36
37extern void sql_alloc(size_t size);
38extern void sql_element_free(void *ptr);
39
40#include "sql_string.h"31#include "sql_string.h"
4132
42/*****************************************************************************33/*****************************************************************************
4334
=== modified file 'Percona-Server/client/sql_string.h'
--- Percona-Server/client/sql_string.h 2011-06-30 15:37:13 +0000
+++ Percona-Server/client/sql_string.h 2012-02-09 15:07:20 +0000
@@ -17,6 +17,9 @@
1717
18/* This file is originally from the mysql distribution. Coded by monty */18/* This file is originally from the mysql distribution. Coded by monty */
1919
20#ifndef CLIENT_SQL_STRING_H
21#define CLIENT_SQL_STRING_H
22
20#ifdef USE_PRAGMA_INTERFACE23#ifdef USE_PRAGMA_INTERFACE
21#pragma interface /* gcc class implementation */24#pragma interface /* gcc class implementation */
22#endif25#endif
@@ -359,3 +362,5 @@
359 return (s->alloced && Ptr >= s->Ptr && Ptr < s->Ptr + s->str_length);362 return (s->alloced && Ptr >= s->Ptr && Ptr < s->Ptr + s->str_length);
360 }363 }
361};364};
365
366#endif
362367
=== added file 'Percona-Server/mysql-test/include/wl36.inc'
--- Percona-Server/mysql-test/include/wl36.inc 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/include/wl36.inc 2012-02-09 15:07:20 +0000
@@ -0,0 +1,51 @@
1#
2# WL #36: http://askmonty.org/worklog/Server-Sprint/?tid=36
3# This is basic test for --rewrite-db option.
4# mysqlbinlog --rewrite-db="from->to" should rewrite database
5#
6
7CREATE DATABASE a; USE a; CREATE TABLE t1(a INT);
8CREATE DATABASE b; USE b; CREATE TABLE t1(b INT);
9CREATE DATABASE c; USE c; CREATE TABLE t1(c INT);
10
11RESET MASTER;
12--let MYSQLD_DATA_DIR=`select @@datadir`
13--let BIN_LOG_FILE_NAME=query_get_value(show master status, File, 1)
14--let BIN_LOG_START_POSITION=query_get_value(show master status, Position, 1)
15USE a; INSERT INTO t1 VALUES(0);
16USE b; INSERT INTO t1 VALUES(1);
17--let BIN_LOG_STOP_POSITION=query_get_value(show master status, Position, 1)
18FLUSH LOGS;
19
20--let BIN_LOG_FULL_PATH=`SELECT CONCAT("$MYSQLD_DATA_DIR", "$BIN_LOG_FILE_NAME")`
21
22--let i=3
23# i=3: rewrite nothing
24# i=2: rewrite a->c
25# i=0: rewrite a->b
26--disable_query_log
27while ($i)
28{
29--let REWRITE=`SELECT CASE $i WHEN 3 THEN '' WHEN 2 THEN '--rewrite-db="a->c"' WHEN 1 THEN '--rewrite-db="a->b"' END`
30
31USE a; DELETE FROM t1;
32USE b; DELETE FROM t1;
33USE c; DELETE FROM t1;
34
35--echo #
36--echo # Apply log with '$REWRITE'
37--echo #
38
39--exec $MYSQL_BINLOG $REWRITE --start-position=$BIN_LOG_START_POSITION --stop-position=$BIN_LOG_STOP_POSITION $BIN_LOG_FULL_PATH | $MYSQL
40
41USE a; SELECT * FROM t1;
42USE b; SELECT * FROM t1;
43USE c; SELECT * FROM t1;
44
45dec $i;
46}
47--enable_query_log
48
49USE a; DROP TABLE t1; DROP DATABASE a;
50USE b; DROP TABLE t1; DROP DATABASE b;
51USE c; DROP TABLE t1; DROP DATABASE c;
052
=== modified file 'Percona-Server/mysql-test/r/mysqlbinlog.result'
--- Percona-Server/mysql-test/r/mysqlbinlog.result 2011-03-25 14:16:13 +0000
+++ Percona-Server/mysql-test/r/mysqlbinlog.result 2012-02-09 15:07:20 +0000
@@ -220,7 +220,6 @@
220/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;220/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
221DELIMITER /*!*/;221DELIMITER /*!*/;
222ROLLBACK/*!*/;222ROLLBACK/*!*/;
223use test/*!*/;
224SET TIMESTAMP=1108844556/*!*/;223SET TIMESTAMP=1108844556/*!*/;
225SET @@session.pseudo_thread_id=999999999/*!*/;224SET @@session.pseudo_thread_id=999999999/*!*/;
226SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;225SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
@@ -228,6 +227,7 @@
228SET @@session.collation_database=DEFAULT/*!*/;227SET @@session.collation_database=DEFAULT/*!*/;
229BEGIN228BEGIN
230/*!*/;229/*!*/;
230use test/*!*/;
231SET TIMESTAMP=1108844555/*!*/;231SET TIMESTAMP=1108844555/*!*/;
232insert t1 values (1)232insert t1 values (1)
233/*!*/;233/*!*/;
@@ -239,7 +239,6 @@
239/*!40019 SET @@session.max_insert_delayed_threads=0*/;239/*!40019 SET @@session.max_insert_delayed_threads=0*/;
240/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;240/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
241DELIMITER /*!*/;241DELIMITER /*!*/;
242use test/*!*/;
243SET TIMESTAMP=1108844556/*!*/;242SET TIMESTAMP=1108844556/*!*/;
244SET @@session.pseudo_thread_id=999999999/*!*/;243SET @@session.pseudo_thread_id=999999999/*!*/;
245SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;244SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
@@ -247,6 +246,7 @@
247SET @@session.collation_database=DEFAULT/*!*/;246SET @@session.collation_database=DEFAULT/*!*/;
248BEGIN247BEGIN
249/*!*/;248/*!*/;
249use test/*!*/;
250SET TIMESTAMP=1108844555/*!*/;250SET TIMESTAMP=1108844555/*!*/;
251insert t1 values (1)251insert t1 values (1)
252/*!*/;252/*!*/;
@@ -581,7 +581,6 @@
581SET @@session.collation_database=DEFAULT/*!*/;581SET @@session.collation_database=DEFAULT/*!*/;
582BEGIN582BEGIN
583/*!*/;583/*!*/;
584use test/*!*/;
585SET TIMESTAMP=1266652094/*!*/;584SET TIMESTAMP=1266652094/*!*/;
586SavePoint mixed_cases585SavePoint mixed_cases
587/*!*/;586/*!*/;
@@ -592,11 +591,9 @@
592SET TIMESTAMP=1266652094/*!*/;591SET TIMESTAMP=1266652094/*!*/;
593INSERT INTO db1.t1 VALUES(40)592INSERT INTO db1.t1 VALUES(40)
594/*!*/;593/*!*/;
595use test/*!*/;
596SET TIMESTAMP=1266652094/*!*/;594SET TIMESTAMP=1266652094/*!*/;
597ROLLBACK TO mixed_cases595ROLLBACK TO mixed_cases
598/*!*/;596/*!*/;
599use db1/*!*/;
600SET TIMESTAMP=1266652094/*!*/;597SET TIMESTAMP=1266652094/*!*/;
601INSERT INTO db1.t2 VALUES("after rollback to")598INSERT INTO db1.t2 VALUES("after rollback to")
602/*!*/;599/*!*/;
@@ -624,7 +621,6 @@
624SET @@session.collation_database=DEFAULT/*!*/;621SET @@session.collation_database=DEFAULT/*!*/;
625BEGIN622BEGIN
626/*!*/;623/*!*/;
627use test/*!*/;
628SET TIMESTAMP=1266652094/*!*/;624SET TIMESTAMP=1266652094/*!*/;
629SavePoint mixed_cases625SavePoint mixed_cases
630/*!*/;626/*!*/;
631627
=== added file 'Percona-Server/mysql-test/r/wl36-mixed.result'
--- Percona-Server/mysql-test/r/wl36-mixed.result 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/r/wl36-mixed.result 2012-02-09 15:07:20 +0000
@@ -0,0 +1,48 @@
1CREATE DATABASE a;
2USE a;
3CREATE TABLE t1(a INT);
4CREATE DATABASE b;
5USE b;
6CREATE TABLE t1(b INT);
7CREATE DATABASE c;
8USE c;
9CREATE TABLE t1(c INT);
10RESET MASTER;
11USE a;
12INSERT INTO t1 VALUES(0);
13USE b;
14INSERT INTO t1 VALUES(1);
15FLUSH LOGS;
16#
17# Apply log with ''
18#
19a
200
21b
221
23c
24#
25# Apply log with '--rewrite-db="a->c"'
26#
27a
28b
291
30c
310
32#
33# Apply log with '--rewrite-db="a->b"'
34#
35a
36b
370
381
39c
40USE a;
41DROP TABLE t1;
42DROP DATABASE a;
43USE b;
44DROP TABLE t1;
45DROP DATABASE b;
46USE c;
47DROP TABLE t1;
48DROP DATABASE c;
049
=== added file 'Percona-Server/mysql-test/r/wl36-row.result'
--- Percona-Server/mysql-test/r/wl36-row.result 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/r/wl36-row.result 2012-02-09 15:07:20 +0000
@@ -0,0 +1,48 @@
1CREATE DATABASE a;
2USE a;
3CREATE TABLE t1(a INT);
4CREATE DATABASE b;
5USE b;
6CREATE TABLE t1(b INT);
7CREATE DATABASE c;
8USE c;
9CREATE TABLE t1(c INT);
10RESET MASTER;
11USE a;
12INSERT INTO t1 VALUES(0);
13USE b;
14INSERT INTO t1 VALUES(1);
15FLUSH LOGS;
16#
17# Apply log with ''
18#
19a
200
21b
221
23c
24#
25# Apply log with '--rewrite-db="a->c"'
26#
27a
28b
291
30c
310
32#
33# Apply log with '--rewrite-db="a->b"'
34#
35a
36b
370
381
39c
40USE a;
41DROP TABLE t1;
42DROP DATABASE a;
43USE b;
44DROP TABLE t1;
45DROP DATABASE b;
46USE c;
47DROP TABLE t1;
48DROP DATABASE c;
049
=== added file 'Percona-Server/mysql-test/r/wl36-statement.result'
--- Percona-Server/mysql-test/r/wl36-statement.result 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/r/wl36-statement.result 2012-02-09 15:07:20 +0000
@@ -0,0 +1,48 @@
1CREATE DATABASE a;
2USE a;
3CREATE TABLE t1(a INT);
4CREATE DATABASE b;
5USE b;
6CREATE TABLE t1(b INT);
7CREATE DATABASE c;
8USE c;
9CREATE TABLE t1(c INT);
10RESET MASTER;
11USE a;
12INSERT INTO t1 VALUES(0);
13USE b;
14INSERT INTO t1 VALUES(1);
15FLUSH LOGS;
16#
17# Apply log with ''
18#
19a
200
21b
221
23c
24#
25# Apply log with '--rewrite-db="a->c"'
26#
27a
28b
291
30c
310
32#
33# Apply log with '--rewrite-db="a->b"'
34#
35a
36b
370
381
39c
40USE a;
41DROP TABLE t1;
42DROP DATABASE a;
43USE b;
44DROP TABLE t1;
45DROP DATABASE b;
46USE c;
47DROP TABLE t1;
48DROP DATABASE c;
049
=== added file 'Percona-Server/mysql-test/t/wl36-mixed.test'
--- Percona-Server/mysql-test/t/wl36-mixed.test 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/t/wl36-mixed.test 2012-02-09 15:07:20 +0000
@@ -0,0 +1,3 @@
1--source include/have_log_bin.inc
2--source include/have_binlog_format_mixed.inc
3--source include/wl36.inc
04
=== added file 'Percona-Server/mysql-test/t/wl36-row.test'
--- Percona-Server/mysql-test/t/wl36-row.test 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/t/wl36-row.test 2012-02-09 15:07:20 +0000
@@ -0,0 +1,3 @@
1--source include/have_log_bin.inc
2--source include/have_binlog_format_row.inc
3--source include/wl36.inc
04
=== added file 'Percona-Server/mysql-test/t/wl36-statement.test'
--- Percona-Server/mysql-test/t/wl36-statement.test 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/t/wl36-statement.test 2012-02-09 15:07:20 +0000
@@ -0,0 +1,3 @@
1--source include/have_log_bin.inc
2--source include/have_binlog_format_statement.inc
3--source include/wl36.inc
04
=== modified file 'Percona-Server/sql/log_event.cc'
--- Percona-Server/sql/log_event.cc 2012-01-30 04:30:33 +0000
+++ Percona-Server/sql/log_event.cc 2012-02-09 15:07:20 +0000
@@ -1134,7 +1134,7 @@
1134 goto err;1134 goto err;
1135 }1135 }
1136 if ((res= read_log_event(buf, data_len, &error, description_event)))1136 if ((res= read_log_event(buf, data_len, &error, description_event)))
1137 res->register_temp_buf(buf);1137 res->register_temp_buf(buf, TRUE);
11381138
1139err:1139err:
1140 UNLOCK_MUTEX;1140 UNLOCK_MUTEX;
@@ -8271,6 +8271,111 @@
8271 my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR));8271 my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR));
8272}8272}
82738273
8274
8275#ifdef MYSQL_CLIENT
8276
8277/*
8278 Rewrite database name for the event to name specified by new_db
8279 SYNOPSIS
8280 new_db Database name to change to
8281 new_len Length
8282 desc Event describing binlog that we're writing to.
8283
8284 DESCRIPTION
8285 Reset db name. This function assumes that temp_buf member contains event
8286 representation taken from a binary log. It resets m_dbnam and m_dblen and
8287 rewrites temp_buf with new db name.
8288
8289 RETURN
8290 0 - Success
8291 other - Error
8292*/
8293
8294int Table_map_log_event::rewrite_db(const char* new_db, size_t new_len,
8295 const Format_description_log_event* desc)
8296{
8297 DBUG_ENTER("Table_map_log_event::rewrite_db");
8298 DBUG_ASSERT(temp_buf);
8299
8300 uint header_len= min(desc->common_header_len,
8301 LOG_EVENT_MINIMAL_HEADER_LEN) + TABLE_MAP_HEADER_LEN;
8302 int len_diff;
8303
8304 if (!(len_diff= new_len - m_dblen))
8305 {
8306 memcpy((void*) (temp_buf + header_len + 1), new_db, m_dblen + 1);
8307 memcpy((void*) m_dbnam, new_db, m_dblen + 1);
8308 DBUG_RETURN(0);
8309 }
8310
8311 // Create new temp_buf
8312 ulong event_cur_len= uint4korr(temp_buf + EVENT_LEN_OFFSET);
8313 ulong event_new_len= event_cur_len + len_diff;
8314 char* new_temp_buf= (char*) my_malloc(event_new_len, MYF(MY_WME));
8315
8316 if (!new_temp_buf)
8317 {
8318 sql_print_error("Table_map_log_event::rewrite_db: "
8319 "failed to allocate new temp_buf (%d bytes required)",
8320 event_new_len);
8321 DBUG_RETURN(-1);
8322 }
8323
8324 // Rewrite temp_buf
8325 char* ptr= new_temp_buf;
8326 ulong cnt= 0;
8327
8328 // Copy header and change event length
8329 memcpy(ptr, temp_buf, header_len);
8330 int4store(ptr + EVENT_LEN_OFFSET, event_new_len);
8331 ptr += header_len;
8332 cnt += header_len;
8333
8334 // Write new db name length and new name
8335 *ptr++ = new_len;
8336 memcpy(ptr, new_db, new_len + 1);
8337 ptr += new_len + 1;
8338 cnt += m_dblen + 2;
8339
8340 // Copy rest part
8341 memcpy(ptr, temp_buf + cnt, event_cur_len - cnt);
8342
8343 // Reregister temp buf
8344 free_temp_buf();
8345 register_temp_buf(new_temp_buf, TRUE);
8346
8347 // Reset m_dbnam and m_dblen members
8348 m_dblen= new_len;
8349
8350 // m_dbnam resides in m_memory together with m_tblnam and m_coltype
8351 uchar* memory= m_memory;
8352 char const* tblnam= m_tblnam;
8353 uchar* coltype= m_coltype;
8354
8355 m_memory= (uchar*) my_multi_malloc(MYF(MY_WME),
8356 &m_dbnam, (uint) m_dblen + 1,
8357 &m_tblnam, (uint) m_tbllen + 1,
8358 &m_coltype, (uint) m_colcnt,
8359 NullS);
8360
8361 if (!m_memory)
8362 {
8363 sql_print_error("Table_map_log_event::rewrite_db: "
8364 "failed to allocate new m_memory (%d + %d + %d bytes required)",
8365 m_dblen + 1, m_tbllen + 1, m_colcnt);
8366 DBUG_RETURN(-1);
8367 }
8368
8369 memcpy((void*)m_dbnam, new_db, m_dblen + 1);
8370 memcpy((void*)m_tblnam, tblnam, m_tbllen + 1);
8371 memcpy(m_coltype, coltype, m_colcnt);
8372
8373 my_free(memory, MYF(MY_WME));
8374 DBUG_RETURN(0);
8375}
8376#endif /* MYSQL_CLIENT */
8377
8378
8274/*8379/*
8275 Return value is an error code, one of:8380 Return value is an error code, one of:
82768381
82778382
=== modified file 'Percona-Server/sql/log_event.h'
--- Percona-Server/sql/log_event.h 2012-01-30 04:30:33 +0000
+++ Percona-Server/sql/log_event.h 2012-02-09 15:07:20 +0000
@@ -889,6 +889,13 @@
889 event's type, and its content is distributed in the event-specific fields.889 event's type, and its content is distributed in the event-specific fields.
890 */890 */
891 char *temp_buf;891 char *temp_buf;
892
893 /*
894 TRUE <=> this event 'owns' temp_buf and should call my_free() when done
895 with it
896 */
897 bool event_owns_temp_buf;
898
892 /*899 /*
893 Timestamp on the master(for debugging and replication of900 Timestamp on the master(for debugging and replication of
894 NOW()/TIMESTAMP). It is important for queries and LOAD DATA901 NOW()/TIMESTAMP). It is important for queries and LOAD DATA
@@ -1030,12 +1037,17 @@
1030 Log_event(const char* buf, const Format_description_log_event1037 Log_event(const char* buf, const Format_description_log_event
1031 *description_event);1038 *description_event);
1032 virtual ~Log_event() { free_temp_buf();}1039 virtual ~Log_event() { free_temp_buf();}
1033 void register_temp_buf(char* buf) { temp_buf = buf; }1040 void register_temp_buf(char* buf, bool must_free)
1041 {
1042 temp_buf= buf;
1043 event_owns_temp_buf= must_free;
1044 }
1034 void free_temp_buf()1045 void free_temp_buf()
1035 {1046 {
1036 if (temp_buf)1047 if (temp_buf)
1037 {1048 {
1038 my_free(temp_buf, MYF(0));1049 if (event_owns_temp_buf)
1050 my_free(temp_buf, MYF(0));
1039 temp_buf = 0;1051 temp_buf = 0;
1040 }1052 }
1041 }1053 }
@@ -3360,6 +3372,8 @@
3360 ulong get_table_id() const { return m_table_id; }3372 ulong get_table_id() const { return m_table_id; }
3361 const char *get_table_name() const { return m_tblnam; }3373 const char *get_table_name() const { return m_tblnam; }
3362 const char *get_db_name() const { return m_dbnam; }3374 const char *get_db_name() const { return m_dbnam; }
3375 int rewrite_db(const char* new_name, size_t new_name_len,
3376 const Format_description_log_event*);
3363#endif3377#endif
33643378
3365 virtual Log_event_type get_type_code() { return TABLE_MAP_EVENT; }3379 virtual Log_event_type get_type_code() { return TABLE_MAP_EVENT; }
33663380
=== modified file 'Percona-Server/sql/mysql_priv.h'
--- Percona-Server/sql/mysql_priv.h 2011-11-24 02:01:21 +0000
+++ Percona-Server/sql/mysql_priv.h 2012-02-09 15:07:20 +0000
@@ -93,12 +93,16 @@
93#include "unireg.h"93#include "unireg.h"
9494
95void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size);95void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size);
96#endif // MYSQL_CLIENT
97
96void *sql_alloc(size_t);98void *sql_alloc(size_t);
97void *sql_calloc(size_t);99void *sql_calloc(size_t);
98char *sql_strdup(const char *str);100char *sql_strdup(const char *str);
99char *sql_strmake(const char *str, size_t len);101char *sql_strmake(const char *str, size_t len);
100void *sql_memdup(const void * ptr, size_t size);102void *sql_memdup(const void * ptr, size_t size);
101void sql_element_free(void *ptr);103void sql_element_free(void *ptr);
104
105#ifndef MYSQL_CLIENT
102char *sql_strmake_with_convert(const char *str, size_t arg_length,106char *sql_strmake_with_convert(const char *str, size_t arg_length,
103 CHARSET_INFO *from_cs,107 CHARSET_INFO *from_cs,
104 size_t max_res_length,108 size_t max_res_length,
105109
=== modified file 'Percona-Server/sql/mysqld.cc'
--- Percona-Server/sql/mysqld.cc 2012-02-07 03:25:46 +0000
+++ Percona-Server/sql/mysqld.cc 2012-02-09 15:07:20 +0000
@@ -8469,6 +8469,7 @@
8469 }8469 }
8470 case (int)OPT_REPLICATE_REWRITE_DB:8470 case (int)OPT_REPLICATE_REWRITE_DB:
8471 {8471 {
8472 /* See also OPT_REWRITE_DB handling in client/mysqlbinlog.cc */
8472 char* key = argument,*p, *val;8473 char* key = argument,*p, *val;
84738474
8474 if (!(p= strstr(argument, "->")))8475 if (!(p= strstr(argument, "->")))
84758476
=== modified file 'Percona-Server/sql/rpl_filter.cc'
--- Percona-Server/sql/rpl_filter.cc 2011-06-30 15:37:13 +0000
+++ Percona-Server/sql/rpl_filter.cc 2012-02-09 15:07:20 +0000
@@ -48,6 +48,7 @@
48}48}
4949
5050
51#ifndef MYSQL_CLIENT
51/*52/*
52 Returns true if table should be logged/replicated 53 Returns true if table should be logged/replicated
5354
@@ -132,6 +133,7 @@
132 !do_table_inited && !wild_do_table_inited);133 !do_table_inited && !wild_do_table_inited);
133}134}
134135
136#endif
135137
136/*138/*
137 Checks whether a db matches some do_db and ignore_db rules139 Checks whether a db matches some do_db and ignore_db rules
@@ -517,6 +519,13 @@
517}519}
518520
519521
522bool
523Rpl_filter::rewrite_db_is_empty()
524{
525 return rewrite_db.is_empty();
526}
527
528
520const char*529const char*
521Rpl_filter::get_rewrite_db(const char* db, size_t *new_len)530Rpl_filter::get_rewrite_db(const char* db, size_t *new_len)
522{531{
523532
=== modified file 'Percona-Server/sql/rpl_filter.h'
--- Percona-Server/sql/rpl_filter.h 2007-05-10 09:59:39 +0000
+++ Percona-Server/sql/rpl_filter.h 2012-02-09 15:07:20 +0000
@@ -42,7 +42,9 @@
42 42
43 /* Checks - returns true if ok to replicate/log */43 /* Checks - returns true if ok to replicate/log */
4444
45 bool tables_ok(const char* db, TABLE_LIST* tables);45#ifndef MYSQL_CLIENT
46 bool tables_ok(const char* db, TABLE_LIST *tables);
47#endif
46 bool db_ok(const char* db);48 bool db_ok(const char* db);
47 bool db_ok_with_wild_table(const char *db);49 bool db_ok_with_wild_table(const char *db);
4850
@@ -69,6 +71,7 @@
69 void get_wild_do_table(String* str);71 void get_wild_do_table(String* str);
70 void get_wild_ignore_table(String* str);72 void get_wild_ignore_table(String* str);
7173
74 bool rewrite_db_is_empty();
72 const char* get_rewrite_db(const char* db, size_t *new_len);75 const char* get_rewrite_db(const char* db, size_t *new_len);
7376
74 I_List<i_string>* get_do_db();77 I_List<i_string>* get_do_db();
7578
=== modified file 'Percona-Server/sql/sql_string.cc'
--- Percona-Server/sql/sql_string.cc 2011-10-31 09:10:04 +0000
+++ Percona-Server/sql/sql_string.cc 2012-02-09 15:07:20 +0000
@@ -39,6 +39,9 @@
3939
40#include "sql_string.h"40#include "sql_string.h"
4141
42#ifdef MYSQL_CLIENT
43#error Attempt to use server-side sql_string on client. Use client/sql_string.cc
44#endif
42/*****************************************************************************45/*****************************************************************************
43** String functions46** String functions
44*****************************************************************************/47*****************************************************************************/
4548
=== modified file 'Percona-Server/sql/sql_string.h'
--- Percona-Server/sql/sql_string.h 2011-07-03 15:47:37 +0000
+++ Percona-Server/sql/sql_string.h 2012-02-09 15:07:20 +0000
@@ -1,3 +1,6 @@
1#ifndef MYSQL_SQL_STRING_H_INCLUDED
2#define MYSQL_SQL_STRING_H_INCLUDED
3
1/*4/*
2 Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.5 Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
36
@@ -25,6 +28,10 @@
25#define NOT_FIXED_DEC 3128#define NOT_FIXED_DEC 31
26#endif29#endif
2730
31#ifdef MYSQL_CLIENT
32#error Attempt to use server-side sql_string on client. Use client/sql_string.h
33#endif
34
28class String;35class String;
29int sortcmp(const String *a,const String *b, CHARSET_INFO *cs);36int sortcmp(const String *a,const String *b, CHARSET_INFO *cs);
30String *copy_if_not_alloced(String *a,String *b,uint32 arg_length);37String *copy_if_not_alloced(String *a,String *b,uint32 arg_length);
@@ -408,3 +415,5 @@
408{415{
409 return str+ cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end;416 return str+ cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end;
410}417}
418
419#endif // MYSQL_SQL_STRING_H_INCLUDED
411420
=== modified file 'Percona-Server/sql/thr_malloc.cc'
--- Percona-Server/sql/thr_malloc.cc 2011-06-30 15:37:13 +0000
+++ Percona-Server/sql/thr_malloc.cc 2012-02-09 15:07:20 +0000
@@ -65,11 +65,13 @@
65}65}
6666
6767
68#ifndef MYSQL_CLIENT
68void *sql_alloc(size_t Size)69void *sql_alloc(size_t Size)
69{70{
70 MEM_ROOT *root= *my_pthread_getspecific_ptr(MEM_ROOT**,THR_MALLOC);71 MEM_ROOT *root= *my_pthread_getspecific_ptr(MEM_ROOT**,THR_MALLOC);
71 return alloc_root(root,Size);72 return alloc_root(root,Size);
72}73}
74#endif
7375
7476
75void *sql_calloc(size_t size)77void *sql_calloc(size_t size)
7678
=== added file 'doc/source/flexibility/mysqlbinlog_change_db.rst'
--- doc/source/flexibility/mysqlbinlog_change_db.rst 1970-01-01 00:00:00 +0000
+++ doc/source/flexibility/mysqlbinlog_change_db.rst 2012-02-09 15:07:20 +0000
@@ -0,0 +1,43 @@
1.. _mysqlbinlog_change_db:
2
3=========================
4Ability to change database for mysqlbinlog
5=========================
6
7Sometimes there is a need to take a binary log and apply it to a database with
8a different name than the original name of the database on binlog producer.
9
10If one is using statement-based replication, he can achieve this by grepping
11out "USE dbname" statements out of the output of mysqlbinlog(*). With
12row-based replication this is no longer possible, as database name is encoded
13within the the BINLOG '....' statement.
14
15This task is about adding an option to mysqlbinlog that would allow to change
16the names of used databases in both RBR and SBR events.
17
18Varible :variable:`rewrite-db` of **mysqlbinlog** utility allows to setup rewriting rule "from->"to".
19
20Version Specific Information
21============================
22
23 * 5.1.62-12.1
24 Full functionality.
25
26Client Command Line Parameter
27=============================
28
29.. variable:: rewrite-db
30
31 :cli: Yes
32 :conf: Yes
33 :scope: Global
34 :dyn: No
35 :vartype: String
36 :default: Off
37
38
39Related Reading
40===============
41
42 * `WL #36 <http://askmonty.org/worklog/Server-Sprint/?tid=36>`_
43
044
=== modified file 'doc/source/index.rst'
--- doc/source/index.rst 2012-01-31 10:35:01 +0000
+++ doc/source/index.rst 2012-02-09 15:07:20 +0000
@@ -88,6 +88,7 @@
88 flexibility/innodb_files_extend88 flexibility/innodb_files_extend
89 flexibility/log_warnings_suppress89 flexibility/log_warnings_suppress
90 flexibility/mysql_remove_eol_carret90 flexibility/mysql_remove_eol_carret
91 flexibility/mysqlbinlog_change_db
91 flexibility/replication_skip_single_statement92 flexibility/replication_skip_single_statement
92 flexibility/buff_read_ahead_area93 flexibility/buff_read_ahead_area
93 flexibility/innodb_fast_shutdown94 flexibility/innodb_fast_shutdown

Subscribers

People subscribed via source and target branches