Merge lp:~tsarev/percona-server/5.1-18205_02_wl36.patch into lp:percona-server/5.1
- 5.1-18205_02_wl36.patch
- Merge into 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 |
Related bugs: | |
Related blueprints: |
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.
Commit message
Description of the change
http://
merge wl36.patch from lp:percona-server/rnt-5.1
Feature WL #36 description: http://
To post a comment you must log in.
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote : | # |
review:
Needs Information
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Percona-Server/client/Makefile.am' | |||
2 | --- Percona-Server/client/Makefile.am 2011-07-03 15:47:37 +0000 | |||
3 | +++ Percona-Server/client/Makefile.am 2012-02-09 15:07:20 +0000 | |||
4 | @@ -24,6 +24,7 @@ | |||
5 | 24 | INCLUDES = -I$(top_builddir)/include \ | 24 | INCLUDES = -I$(top_builddir)/include \ |
6 | 25 | -I$(top_srcdir)/include \ | 25 | -I$(top_srcdir)/include \ |
7 | 26 | -I$(top_srcdir)/regex \ | 26 | -I$(top_srcdir)/regex \ |
8 | 27 | -I$(top_srcdir)/sql \ | ||
9 | 27 | $(openssl_includes) | 28 | $(openssl_includes) |
10 | 28 | 29 | ||
11 | 29 | LIBS = @CLIENT_LIBS@ | 30 | LIBS = @CLIENT_LIBS@ |
12 | @@ -107,7 +108,8 @@ | |||
13 | 107 | rpl_utility.h rpl_tblmap.h rpl_tblmap.cc \ | 108 | rpl_utility.h rpl_tblmap.h rpl_tblmap.cc \ |
14 | 108 | log_event.cc my_decimal.h my_decimal.cc \ | 109 | log_event.cc my_decimal.h my_decimal.cc \ |
15 | 109 | log_event_old.h log_event_old.cc \ | 110 | log_event_old.h log_event_old.cc \ |
17 | 110 | rpl_record_old.h rpl_record_old.cc | 111 | rpl_record_old.h rpl_record_old.cc \ |
18 | 112 | sql_list.h rpl_filter.h sql_list.cc rpl_filter.cc | ||
19 | 111 | strings_src=decimal.c | 113 | strings_src=decimal.c |
20 | 112 | 114 | ||
21 | 113 | link_sources: | 115 | link_sources: |
22 | 114 | 116 | ||
23 | === modified file 'Percona-Server/client/client_priv.h' | |||
24 | --- Percona-Server/client/client_priv.h 2011-11-24 02:01:33 +0000 | |||
25 | +++ Percona-Server/client/client_priv.h 2012-02-09 15:07:20 +0000 | |||
26 | @@ -97,6 +97,7 @@ | |||
27 | 97 | OPT_SYSLOG, | 97 | OPT_SYSLOG, |
28 | 98 | #endif | 98 | #endif |
29 | 99 | OPT_FIRST_SLAVE, | 99 | OPT_FIRST_SLAVE, |
30 | 100 | OPT_REWRITE_DB, | ||
31 | 100 | OPT_ALL, | 101 | OPT_ALL, |
32 | 101 | OPT_NO_REMOVE_EOL_CARRET, | 102 | OPT_NO_REMOVE_EOL_CARRET, |
33 | 102 | OPT_INNODB_OPTIMIZE_KEYS, | 103 | OPT_INNODB_OPTIMIZE_KEYS, |
34 | 103 | 104 | ||
35 | === modified file 'Percona-Server/client/mysqlbinlog.cc' | |||
36 | --- Percona-Server/client/mysqlbinlog.cc 2011-07-11 16:13:27 +0000 | |||
37 | +++ Percona-Server/client/mysqlbinlog.cc 2012-02-09 15:07:20 +0000 | |||
38 | @@ -38,6 +38,15 @@ | |||
39 | 38 | #include "sql_common.h" | 38 | #include "sql_common.h" |
40 | 39 | #include <welcome_copyright_notice.h> // ORACLE_WELCOME_COPYRIGHT_NOTICE | 39 | #include <welcome_copyright_notice.h> // ORACLE_WELCOME_COPYRIGHT_NOTICE |
41 | 40 | 40 | ||
42 | 41 | /* Needed for Rpl_filter */ | ||
43 | 42 | CHARSET_INFO* system_charset_info= &my_charset_utf8_general_ci; | ||
44 | 43 | |||
45 | 44 | #include "sql_string.h" // needed for Rpl_filter | ||
46 | 45 | #include "sql_list.h" // needed for Rpl_filter | ||
47 | 46 | #include "rpl_filter.h" | ||
48 | 47 | |||
49 | 48 | Rpl_filter *binlog_filter; | ||
50 | 49 | |||
51 | 41 | #define BIN_LOG_HEADER_SIZE 4 | 50 | #define BIN_LOG_HEADER_SIZE 4 |
52 | 42 | #define PROBE_HEADER_LEN (EVENT_LEN_OFFSET+4) | 51 | #define PROBE_HEADER_LEN (EVENT_LEN_OFFSET+4) |
53 | 43 | 52 | ||
54 | @@ -623,6 +632,49 @@ | |||
55 | 623 | 632 | ||
56 | 624 | 633 | ||
57 | 625 | /** | 634 | /** |
58 | 635 | Print "use <db>" statement when current db is to be changed. | ||
59 | 636 | |||
60 | 637 | We have to control emiting USE statements according to rewrite-db options. | ||
61 | 638 | We have to do it here (see process_event() below) and to suppress | ||
62 | 639 | producing USE statements by corresponding log event print-functions. | ||
63 | 640 | */ | ||
64 | 641 | void print_use_stmt(PRINT_EVENT_INFO* pinfo, const char* db, size_t db_len) | ||
65 | 642 | { | ||
66 | 643 | /* | ||
67 | 644 | pinfo->db is the current db. | ||
68 | 645 | If current db is the same as required db, do nothing. | ||
69 | 646 | */ | ||
70 | 647 | if (!db || !memcmp(pinfo->db, db, db_len + 1)) | ||
71 | 648 | return; | ||
72 | 649 | |||
73 | 650 | /* | ||
74 | 651 | Current db and required db are different. | ||
75 | 652 | Check for rewrite rule for required db. (Note that in a rewrite rule | ||
76 | 653 | neither db_from nor db_to part can be empty) | ||
77 | 654 | */ | ||
78 | 655 | size_t len_to= 0; | ||
79 | 656 | const char* db_to= binlog_filter->get_rewrite_db(db, &len_to); | ||
80 | 657 | |||
81 | 658 | /* | ||
82 | 659 | If there is no rewrite rule for db (in this case len_to is left = 0), | ||
83 | 660 | printing of the corresponding USE statement is left for log event | ||
84 | 661 | print-function. | ||
85 | 662 | */ | ||
86 | 663 | if (!len_to) | ||
87 | 664 | return; | ||
88 | 665 | |||
89 | 666 | // In case of rewrite rule print USE statement for db_to | ||
90 | 667 | fprintf(result_file, "use %s%s\n", db_to, pinfo->delimiter); | ||
91 | 668 | |||
92 | 669 | /* | ||
93 | 670 | Copy the *original* db to pinfo to suppress emiting | ||
94 | 671 | of USE stmts by log_event print-functions. | ||
95 | 672 | */ | ||
96 | 673 | memcpy(pinfo->db, db, db_len + 1); | ||
97 | 674 | } | ||
98 | 675 | |||
99 | 676 | |||
100 | 677 | /** | ||
101 | 626 | Prints the given event in base64 format. | 678 | Prints the given event in base64 format. |
102 | 627 | 679 | ||
103 | 628 | The header is printed to the head cache and the body is printed to | 680 | The header is printed to the head cache and the body is printed to |
104 | @@ -741,9 +793,22 @@ | |||
105 | 741 | 793 | ||
106 | 742 | switch (ev_type) { | 794 | switch (ev_type) { |
107 | 743 | case QUERY_EVENT: | 795 | case QUERY_EVENT: |
111 | 744 | if (!((Query_log_event*)ev)->is_trans_keyword() && | 796 | { |
112 | 745 | shall_skip_database(((Query_log_event*)ev)->db)) | 797 | Query_log_event *qe= (Query_log_event*)ev; |
113 | 746 | goto end; | 798 | if (!qe->is_trans_keyword()) |
114 | 799 | { | ||
115 | 800 | if (shall_skip_database(qe->db)) | ||
116 | 801 | goto end; | ||
117 | 802 | } | ||
118 | 803 | else | ||
119 | 804 | { | ||
120 | 805 | /* | ||
121 | 806 | In case the event for one of these statements is obtained | ||
122 | 807 | from 5.0 binary log, make it compatible with 5.1. | ||
123 | 808 | */ | ||
124 | 809 | ev->flags|= LOG_EVENT_SUPPRESS_USE_F; | ||
125 | 810 | } | ||
126 | 811 | print_use_stmt(print_event_info, qe->db, qe->db_len); | ||
127 | 747 | if (opt_base64_output_mode == BASE64_OUTPUT_ALWAYS) | 812 | if (opt_base64_output_mode == BASE64_OUTPUT_ALWAYS) |
128 | 748 | { | 813 | { |
129 | 749 | if ((retval= write_event_header_and_base64(ev, result_file, | 814 | if ((retval= write_event_header_and_base64(ev, result_file, |
130 | @@ -754,6 +819,7 @@ | |||
131 | 754 | else | 819 | else |
132 | 755 | ev->print(result_file, print_event_info); | 820 | ev->print(result_file, print_event_info); |
133 | 756 | break; | 821 | break; |
134 | 822 | } | ||
135 | 757 | 823 | ||
136 | 758 | case CREATE_FILE_EVENT: | 824 | case CREATE_FILE_EVENT: |
137 | 759 | { | 825 | { |
138 | @@ -875,6 +941,7 @@ | |||
139 | 875 | 941 | ||
140 | 876 | if (!shall_skip_database(exlq->db)) | 942 | if (!shall_skip_database(exlq->db)) |
141 | 877 | { | 943 | { |
142 | 944 | print_use_stmt(print_event_info, exlq->db, exlq->db_len); | ||
143 | 878 | if (fname) | 945 | if (fname) |
144 | 879 | { | 946 | { |
145 | 880 | convert_path_to_forward_slashes(fname); | 947 | convert_path_to_forward_slashes(fname); |
146 | @@ -898,6 +965,14 @@ | |||
147 | 898 | destroy_evt= FALSE; | 965 | destroy_evt= FALSE; |
148 | 899 | goto end; | 966 | goto end; |
149 | 900 | } | 967 | } |
150 | 968 | size_t len_to= 0; | ||
151 | 969 | const char* db_to= binlog_filter->get_rewrite_db(map->get_db_name(), | ||
152 | 970 | &len_to); | ||
153 | 971 | if (len_to && map->rewrite_db(db_to, len_to, glob_description_event)) | ||
154 | 972 | { | ||
155 | 973 | error("Could not rewrite database name"); | ||
156 | 974 | goto err; | ||
157 | 975 | } | ||
158 | 901 | } | 976 | } |
159 | 902 | case WRITE_ROWS_EVENT: | 977 | case WRITE_ROWS_EVENT: |
160 | 903 | case DELETE_ROWS_EVENT: | 978 | case DELETE_ROWS_EVENT: |
161 | @@ -983,15 +1058,19 @@ | |||
162 | 983 | retval= ERROR_STOP; | 1058 | retval= ERROR_STOP; |
163 | 984 | end: | 1059 | end: |
164 | 985 | rec_count++; | 1060 | rec_count++; |
165 | 1061 | |||
166 | 1062 | |||
167 | 986 | /* | 1063 | /* |
170 | 987 | Destroy the log_event object. If reading from a remote host, | 1064 | Destroy the log_event object. |
171 | 988 | set the temp_buf to NULL so that memory isn't freed twice. | 1065 | MariaDB MWL#36: mainline does this: |
172 | 1066 | If reading from a remote host, | ||
173 | 1067 | set the temp_buf to NULL so that memory isn't freed twice. | ||
174 | 1068 | We no longer do that, we use Rpl_filter::event_owns_temp_buf instead. | ||
175 | 989 | */ | 1069 | */ |
176 | 990 | if (ev) | 1070 | if (ev) |
177 | 991 | { | 1071 | { |
181 | 992 | if (remote_opt) | 1072 | /* destroy it later if not set (ignored table map) */ |
182 | 993 | ev->temp_buf= 0; | 1073 | if (destroy_evt) |
180 | 994 | if (destroy_evt) /* destroy it later if not set (ignored table map) */ | ||
183 | 995 | delete ev; | 1074 | delete ev; |
184 | 996 | } | 1075 | } |
185 | 997 | DBUG_RETURN(retval); | 1076 | DBUG_RETURN(retval); |
186 | @@ -1156,6 +1235,10 @@ | |||
187 | 1156 | "Used to reserve file descriptors for use by this program.", | 1235 | "Used to reserve file descriptors for use by this program.", |
188 | 1157 | &open_files_limit, &open_files_limit, 0, GET_ULONG, | 1236 | &open_files_limit, &open_files_limit, 0, GET_ULONG, |
189 | 1158 | REQUIRED_ARG, MY_NFILE, 8, OS_FILE_LIMIT, 0, 1, 0}, | 1237 | REQUIRED_ARG, MY_NFILE, 8, OS_FILE_LIMIT, 0, 1, 0}, |
190 | 1238 | {"rewrite-db", OPT_REWRITE_DB, | ||
191 | 1239 | "Updates to a database with a different name than the original. \ | ||
192 | 1240 | Example: rewrite-db='from->to'.", | ||
193 | 1241 | 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
194 | 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} |
195 | 1160 | }; | 1243 | }; |
196 | 1161 | 1244 | ||
197 | @@ -1347,6 +1430,53 @@ | |||
198 | 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); |
199 | 1348 | } | 1431 | } |
200 | 1349 | break; | 1432 | break; |
201 | 1433 | case OPT_REWRITE_DB: // db_from->db_to | ||
202 | 1434 | { | ||
203 | 1435 | /* See also handling of OPT_REPLICATE_REWRITE_DB in sql/mysqld.cc */ | ||
204 | 1436 | char* ptr; | ||
205 | 1437 | char* key= argument; // db-from | ||
206 | 1438 | char* val; // db-to | ||
207 | 1439 | |||
208 | 1440 | // Where key begins | ||
209 | 1441 | while (*key && my_isspace(&my_charset_latin1, *key)) | ||
210 | 1442 | key++; | ||
211 | 1443 | |||
212 | 1444 | // Where val begins | ||
213 | 1445 | if (!(ptr= strstr(argument, "->"))) | ||
214 | 1446 | { | ||
215 | 1447 | sql_print_error("Bad syntax in rewrite-db: missing '->'!\n"); | ||
216 | 1448 | return 1; | ||
217 | 1449 | } | ||
218 | 1450 | val= ptr + 2; | ||
219 | 1451 | while (*val && my_isspace(&my_charset_latin1, *val)) | ||
220 | 1452 | val++; | ||
221 | 1453 | |||
222 | 1454 | // Write \0 and skip blanks at the end of key | ||
223 | 1455 | *ptr-- = 0; | ||
224 | 1456 | while (my_isspace(&my_charset_latin1, *ptr) && ptr > argument) | ||
225 | 1457 | *ptr-- = 0; | ||
226 | 1458 | |||
227 | 1459 | if (!*key) | ||
228 | 1460 | { | ||
229 | 1461 | sql_print_error("Bad syntax in rewrite-db: empty db-from!\n"); | ||
230 | 1462 | return 1; | ||
231 | 1463 | } | ||
232 | 1464 | |||
233 | 1465 | // Skip blanks at the end of val | ||
234 | 1466 | ptr= val; | ||
235 | 1467 | while (*ptr && !my_isspace(&my_charset_latin1, *ptr)) | ||
236 | 1468 | ptr++; | ||
237 | 1469 | *ptr= 0; | ||
238 | 1470 | |||
239 | 1471 | if (!*val) | ||
240 | 1472 | { | ||
241 | 1473 | sql_print_error("Bad syntax in rewrite-db: empty db-to!\n"); | ||
242 | 1474 | return 1; | ||
243 | 1475 | } | ||
244 | 1476 | |||
245 | 1477 | binlog_filter->add_db_rewrite(key, val); | ||
246 | 1478 | break; | ||
247 | 1479 | } | ||
248 | 1350 | case 'v': | 1480 | case 'v': |
249 | 1351 | if (argument == disabled_my_option) | 1481 | if (argument == disabled_my_option) |
250 | 1352 | verbose= 0; | 1482 | verbose= 0; |
251 | @@ -1616,7 +1746,7 @@ | |||
252 | 1616 | If reading from a remote host, ensure the temp_buf for the | 1746 | If reading from a remote host, ensure the temp_buf for the |
253 | 1617 | Log_event class is pointing to the incoming stream. | 1747 | Log_event class is pointing to the incoming stream. |
254 | 1618 | */ | 1748 | */ |
256 | 1619 | ev->register_temp_buf((char *) net->read_pos + 1); | 1749 | ev->register_temp_buf((char *) net->read_pos + 1, FALSE); |
257 | 1620 | 1750 | ||
258 | 1621 | Log_event_type type= ev->get_type_code(); | 1751 | Log_event_type type= ev->get_type_code(); |
259 | 1622 | if (glob_description_event->binlog_version >= 3 || | 1752 | if (glob_description_event->binlog_version >= 3 || |
260 | @@ -2016,6 +2146,8 @@ | |||
261 | 2016 | return retval; | 2146 | return retval; |
262 | 2017 | } | 2147 | } |
263 | 2018 | 2148 | ||
264 | 2149 | /* Used in sql_alloc(). Inited and freed in main() */ | ||
265 | 2150 | MEM_ROOT s_mem_root; | ||
266 | 2019 | 2151 | ||
267 | 2020 | int main(int argc, char** argv) | 2152 | int main(int argc, char** argv) |
268 | 2021 | { | 2153 | { |
269 | @@ -2028,6 +2160,13 @@ | |||
270 | 2028 | 2160 | ||
271 | 2029 | my_init_time(); // for time functions | 2161 | my_init_time(); // for time functions |
272 | 2030 | 2162 | ||
273 | 2163 | init_alloc_root(&s_mem_root, 16384, 0); | ||
274 | 2164 | if (!(binlog_filter= new Rpl_filter)) | ||
275 | 2165 | { | ||
276 | 2166 | error("Failed to create Rpl_filter"); | ||
277 | 2167 | exit(1); | ||
278 | 2168 | } | ||
279 | 2169 | |||
280 | 2031 | if (load_defaults("my", load_default_groups, &argc, &argv)) | 2170 | if (load_defaults("my", load_default_groups, &argc, &argv)) |
281 | 2032 | exit(1); | 2171 | exit(1); |
282 | 2033 | defaults_argv= argv; | 2172 | defaults_argv= argv; |
283 | @@ -2116,6 +2255,8 @@ | |||
284 | 2116 | if (result_file != stdout) | 2255 | if (result_file != stdout) |
285 | 2117 | my_fclose(result_file, MYF(0)); | 2256 | my_fclose(result_file, MYF(0)); |
286 | 2118 | cleanup(); | 2257 | cleanup(); |
287 | 2258 | delete binlog_filter; | ||
288 | 2259 | free_root(&s_mem_root, MYF(0)); | ||
289 | 2119 | free_defaults(defaults_argv); | 2260 | free_defaults(defaults_argv); |
290 | 2120 | my_free_open_file_info(); | 2261 | my_free_open_file_info(); |
291 | 2121 | load_processor.destroy(); | 2262 | load_processor.destroy(); |
292 | @@ -2127,6 +2268,12 @@ | |||
293 | 2127 | DBUG_RETURN(retval == ERROR_STOP ? 1 : 0); | 2268 | DBUG_RETURN(retval == ERROR_STOP ? 1 : 0); |
294 | 2128 | } | 2269 | } |
295 | 2129 | 2270 | ||
296 | 2271 | |||
297 | 2272 | void *sql_alloc(size_t size) | ||
298 | 2273 | { | ||
299 | 2274 | return alloc_root(&s_mem_root, size); | ||
300 | 2275 | } | ||
301 | 2276 | |||
302 | 2130 | /* | 2277 | /* |
303 | 2131 | We must include this here as it's compiled with different options for | 2278 | We must include this here as it's compiled with different options for |
304 | 2132 | the server | 2279 | the server |
305 | @@ -2137,4 +2284,7 @@ | |||
306 | 2137 | #include "my_decimal.cc" | 2284 | #include "my_decimal.cc" |
307 | 2138 | #include "log_event.cc" | 2285 | #include "log_event.cc" |
308 | 2139 | #include "log_event_old.cc" | 2286 | #include "log_event_old.cc" |
309 | 2287 | #include "sql_string.cc" | ||
310 | 2288 | #include "sql_list.cc" | ||
311 | 2289 | #include "rpl_filter.cc" | ||
312 | 2140 | 2290 | ||
313 | 2141 | 2291 | ||
314 | === modified file 'Percona-Server/client/sql_string.cc' | |||
315 | --- Percona-Server/client/sql_string.cc 2011-11-01 06:50:54 +0000 | |||
316 | +++ Percona-Server/client/sql_string.cc 2012-02-09 15:07:20 +0000 | |||
317 | @@ -28,15 +28,6 @@ | |||
318 | 28 | #ifdef HAVE_FCONVERT | 28 | #ifdef HAVE_FCONVERT |
319 | 29 | #include <floatingpoint.h> | 29 | #include <floatingpoint.h> |
320 | 30 | #endif | 30 | #endif |
321 | 31 | |||
322 | 32 | /* | ||
323 | 33 | The following extern declarations are ok as these are interface functions | ||
324 | 34 | required by the string function | ||
325 | 35 | */ | ||
326 | 36 | |||
327 | 37 | extern void sql_alloc(size_t size); | ||
328 | 38 | extern void sql_element_free(void *ptr); | ||
329 | 39 | |||
330 | 40 | #include "sql_string.h" | 31 | #include "sql_string.h" |
331 | 41 | 32 | ||
332 | 42 | /***************************************************************************** | 33 | /***************************************************************************** |
333 | 43 | 34 | ||
334 | === modified file 'Percona-Server/client/sql_string.h' | |||
335 | --- Percona-Server/client/sql_string.h 2011-06-30 15:37:13 +0000 | |||
336 | +++ Percona-Server/client/sql_string.h 2012-02-09 15:07:20 +0000 | |||
337 | @@ -17,6 +17,9 @@ | |||
338 | 17 | 17 | ||
339 | 18 | /* This file is originally from the mysql distribution. Coded by monty */ | 18 | /* This file is originally from the mysql distribution. Coded by monty */ |
340 | 19 | 19 | ||
341 | 20 | #ifndef CLIENT_SQL_STRING_H | ||
342 | 21 | #define CLIENT_SQL_STRING_H | ||
343 | 22 | |||
344 | 20 | #ifdef USE_PRAGMA_INTERFACE | 23 | #ifdef USE_PRAGMA_INTERFACE |
345 | 21 | #pragma interface /* gcc class implementation */ | 24 | #pragma interface /* gcc class implementation */ |
346 | 22 | #endif | 25 | #endif |
347 | @@ -359,3 +362,5 @@ | |||
348 | 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); |
349 | 360 | } | 363 | } |
350 | 361 | }; | 364 | }; |
351 | 365 | |||
352 | 366 | #endif | ||
353 | 362 | 367 | ||
354 | === added file 'Percona-Server/mysql-test/include/wl36.inc' | |||
355 | --- Percona-Server/mysql-test/include/wl36.inc 1970-01-01 00:00:00 +0000 | |||
356 | +++ Percona-Server/mysql-test/include/wl36.inc 2012-02-09 15:07:20 +0000 | |||
357 | @@ -0,0 +1,51 @@ | |||
358 | 1 | # | ||
359 | 2 | # WL #36: http://askmonty.org/worklog/Server-Sprint/?tid=36 | ||
360 | 3 | # This is basic test for --rewrite-db option. | ||
361 | 4 | # mysqlbinlog --rewrite-db="from->to" should rewrite database | ||
362 | 5 | # | ||
363 | 6 | |||
364 | 7 | CREATE DATABASE a; USE a; CREATE TABLE t1(a INT); | ||
365 | 8 | CREATE DATABASE b; USE b; CREATE TABLE t1(b INT); | ||
366 | 9 | CREATE DATABASE c; USE c; CREATE TABLE t1(c INT); | ||
367 | 10 | |||
368 | 11 | RESET MASTER; | ||
369 | 12 | --let MYSQLD_DATA_DIR=`select @@datadir` | ||
370 | 13 | --let BIN_LOG_FILE_NAME=query_get_value(show master status, File, 1) | ||
371 | 14 | --let BIN_LOG_START_POSITION=query_get_value(show master status, Position, 1) | ||
372 | 15 | USE a; INSERT INTO t1 VALUES(0); | ||
373 | 16 | USE b; INSERT INTO t1 VALUES(1); | ||
374 | 17 | --let BIN_LOG_STOP_POSITION=query_get_value(show master status, Position, 1) | ||
375 | 18 | FLUSH LOGS; | ||
376 | 19 | |||
377 | 20 | --let BIN_LOG_FULL_PATH=`SELECT CONCAT("$MYSQLD_DATA_DIR", "$BIN_LOG_FILE_NAME")` | ||
378 | 21 | |||
379 | 22 | --let i=3 | ||
380 | 23 | # i=3: rewrite nothing | ||
381 | 24 | # i=2: rewrite a->c | ||
382 | 25 | # i=0: rewrite a->b | ||
383 | 26 | --disable_query_log | ||
384 | 27 | while ($i) | ||
385 | 28 | { | ||
386 | 29 | --let REWRITE=`SELECT CASE $i WHEN 3 THEN '' WHEN 2 THEN '--rewrite-db="a->c"' WHEN 1 THEN '--rewrite-db="a->b"' END` | ||
387 | 30 | |||
388 | 31 | USE a; DELETE FROM t1; | ||
389 | 32 | USE b; DELETE FROM t1; | ||
390 | 33 | USE c; DELETE FROM t1; | ||
391 | 34 | |||
392 | 35 | --echo # | ||
393 | 36 | --echo # Apply log with '$REWRITE' | ||
394 | 37 | --echo # | ||
395 | 38 | |||
396 | 39 | --exec $MYSQL_BINLOG $REWRITE --start-position=$BIN_LOG_START_POSITION --stop-position=$BIN_LOG_STOP_POSITION $BIN_LOG_FULL_PATH | $MYSQL | ||
397 | 40 | |||
398 | 41 | USE a; SELECT * FROM t1; | ||
399 | 42 | USE b; SELECT * FROM t1; | ||
400 | 43 | USE c; SELECT * FROM t1; | ||
401 | 44 | |||
402 | 45 | dec $i; | ||
403 | 46 | } | ||
404 | 47 | --enable_query_log | ||
405 | 48 | |||
406 | 49 | USE a; DROP TABLE t1; DROP DATABASE a; | ||
407 | 50 | USE b; DROP TABLE t1; DROP DATABASE b; | ||
408 | 51 | USE c; DROP TABLE t1; DROP DATABASE c; | ||
409 | 0 | 52 | ||
410 | === modified file 'Percona-Server/mysql-test/r/mysqlbinlog.result' | |||
411 | --- Percona-Server/mysql-test/r/mysqlbinlog.result 2011-03-25 14:16:13 +0000 | |||
412 | +++ Percona-Server/mysql-test/r/mysqlbinlog.result 2012-02-09 15:07:20 +0000 | |||
413 | @@ -220,7 +220,6 @@ | |||
414 | 220 | /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; | 220 | /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; |
415 | 221 | DELIMITER /*!*/; | 221 | DELIMITER /*!*/; |
416 | 222 | ROLLBACK/*!*/; | 222 | ROLLBACK/*!*/; |
417 | 223 | use test/*!*/; | ||
418 | 224 | SET TIMESTAMP=1108844556/*!*/; | 223 | SET TIMESTAMP=1108844556/*!*/; |
419 | 225 | SET @@session.pseudo_thread_id=999999999/*!*/; | 224 | SET @@session.pseudo_thread_id=999999999/*!*/; |
420 | 226 | SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; | 225 | SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; |
421 | @@ -228,6 +227,7 @@ | |||
422 | 228 | SET @@session.collation_database=DEFAULT/*!*/; | 227 | SET @@session.collation_database=DEFAULT/*!*/; |
423 | 229 | BEGIN | 228 | BEGIN |
424 | 230 | /*!*/; | 229 | /*!*/; |
425 | 230 | use test/*!*/; | ||
426 | 231 | SET TIMESTAMP=1108844555/*!*/; | 231 | SET TIMESTAMP=1108844555/*!*/; |
427 | 232 | insert t1 values (1) | 232 | insert t1 values (1) |
428 | 233 | /*!*/; | 233 | /*!*/; |
429 | @@ -239,7 +239,6 @@ | |||
430 | 239 | /*!40019 SET @@session.max_insert_delayed_threads=0*/; | 239 | /*!40019 SET @@session.max_insert_delayed_threads=0*/; |
431 | 240 | /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; | 240 | /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; |
432 | 241 | DELIMITER /*!*/; | 241 | DELIMITER /*!*/; |
433 | 242 | use test/*!*/; | ||
434 | 243 | SET TIMESTAMP=1108844556/*!*/; | 242 | SET TIMESTAMP=1108844556/*!*/; |
435 | 244 | SET @@session.pseudo_thread_id=999999999/*!*/; | 243 | SET @@session.pseudo_thread_id=999999999/*!*/; |
436 | 245 | SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; | 244 | SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; |
437 | @@ -247,6 +246,7 @@ | |||
438 | 247 | SET @@session.collation_database=DEFAULT/*!*/; | 246 | SET @@session.collation_database=DEFAULT/*!*/; |
439 | 248 | BEGIN | 247 | BEGIN |
440 | 249 | /*!*/; | 248 | /*!*/; |
441 | 249 | use test/*!*/; | ||
442 | 250 | SET TIMESTAMP=1108844555/*!*/; | 250 | SET TIMESTAMP=1108844555/*!*/; |
443 | 251 | insert t1 values (1) | 251 | insert t1 values (1) |
444 | 252 | /*!*/; | 252 | /*!*/; |
445 | @@ -581,7 +581,6 @@ | |||
446 | 581 | SET @@session.collation_database=DEFAULT/*!*/; | 581 | SET @@session.collation_database=DEFAULT/*!*/; |
447 | 582 | BEGIN | 582 | BEGIN |
448 | 583 | /*!*/; | 583 | /*!*/; |
449 | 584 | use test/*!*/; | ||
450 | 585 | SET TIMESTAMP=1266652094/*!*/; | 584 | SET TIMESTAMP=1266652094/*!*/; |
451 | 586 | SavePoint mixed_cases | 585 | SavePoint mixed_cases |
452 | 587 | /*!*/; | 586 | /*!*/; |
453 | @@ -592,11 +591,9 @@ | |||
454 | 592 | SET TIMESTAMP=1266652094/*!*/; | 591 | SET TIMESTAMP=1266652094/*!*/; |
455 | 593 | INSERT INTO db1.t1 VALUES(40) | 592 | INSERT INTO db1.t1 VALUES(40) |
456 | 594 | /*!*/; | 593 | /*!*/; |
457 | 595 | use test/*!*/; | ||
458 | 596 | SET TIMESTAMP=1266652094/*!*/; | 594 | SET TIMESTAMP=1266652094/*!*/; |
459 | 597 | ROLLBACK TO mixed_cases | 595 | ROLLBACK TO mixed_cases |
460 | 598 | /*!*/; | 596 | /*!*/; |
461 | 599 | use db1/*!*/; | ||
462 | 600 | SET TIMESTAMP=1266652094/*!*/; | 597 | SET TIMESTAMP=1266652094/*!*/; |
463 | 601 | INSERT INTO db1.t2 VALUES("after rollback to") | 598 | INSERT INTO db1.t2 VALUES("after rollback to") |
464 | 602 | /*!*/; | 599 | /*!*/; |
465 | @@ -624,7 +621,6 @@ | |||
466 | 624 | SET @@session.collation_database=DEFAULT/*!*/; | 621 | SET @@session.collation_database=DEFAULT/*!*/; |
467 | 625 | BEGIN | 622 | BEGIN |
468 | 626 | /*!*/; | 623 | /*!*/; |
469 | 627 | use test/*!*/; | ||
470 | 628 | SET TIMESTAMP=1266652094/*!*/; | 624 | SET TIMESTAMP=1266652094/*!*/; |
471 | 629 | SavePoint mixed_cases | 625 | SavePoint mixed_cases |
472 | 630 | /*!*/; | 626 | /*!*/; |
473 | 631 | 627 | ||
474 | === added file 'Percona-Server/mysql-test/r/wl36-mixed.result' | |||
475 | --- Percona-Server/mysql-test/r/wl36-mixed.result 1970-01-01 00:00:00 +0000 | |||
476 | +++ Percona-Server/mysql-test/r/wl36-mixed.result 2012-02-09 15:07:20 +0000 | |||
477 | @@ -0,0 +1,48 @@ | |||
478 | 1 | CREATE DATABASE a; | ||
479 | 2 | USE a; | ||
480 | 3 | CREATE TABLE t1(a INT); | ||
481 | 4 | CREATE DATABASE b; | ||
482 | 5 | USE b; | ||
483 | 6 | CREATE TABLE t1(b INT); | ||
484 | 7 | CREATE DATABASE c; | ||
485 | 8 | USE c; | ||
486 | 9 | CREATE TABLE t1(c INT); | ||
487 | 10 | RESET MASTER; | ||
488 | 11 | USE a; | ||
489 | 12 | INSERT INTO t1 VALUES(0); | ||
490 | 13 | USE b; | ||
491 | 14 | INSERT INTO t1 VALUES(1); | ||
492 | 15 | FLUSH LOGS; | ||
493 | 16 | # | ||
494 | 17 | # Apply log with '' | ||
495 | 18 | # | ||
496 | 19 | a | ||
497 | 20 | 0 | ||
498 | 21 | b | ||
499 | 22 | 1 | ||
500 | 23 | c | ||
501 | 24 | # | ||
502 | 25 | # Apply log with '--rewrite-db="a->c"' | ||
503 | 26 | # | ||
504 | 27 | a | ||
505 | 28 | b | ||
506 | 29 | 1 | ||
507 | 30 | c | ||
508 | 31 | 0 | ||
509 | 32 | # | ||
510 | 33 | # Apply log with '--rewrite-db="a->b"' | ||
511 | 34 | # | ||
512 | 35 | a | ||
513 | 36 | b | ||
514 | 37 | 0 | ||
515 | 38 | 1 | ||
516 | 39 | c | ||
517 | 40 | USE a; | ||
518 | 41 | DROP TABLE t1; | ||
519 | 42 | DROP DATABASE a; | ||
520 | 43 | USE b; | ||
521 | 44 | DROP TABLE t1; | ||
522 | 45 | DROP DATABASE b; | ||
523 | 46 | USE c; | ||
524 | 47 | DROP TABLE t1; | ||
525 | 48 | DROP DATABASE c; | ||
526 | 0 | 49 | ||
527 | === added file 'Percona-Server/mysql-test/r/wl36-row.result' | |||
528 | --- Percona-Server/mysql-test/r/wl36-row.result 1970-01-01 00:00:00 +0000 | |||
529 | +++ Percona-Server/mysql-test/r/wl36-row.result 2012-02-09 15:07:20 +0000 | |||
530 | @@ -0,0 +1,48 @@ | |||
531 | 1 | CREATE DATABASE a; | ||
532 | 2 | USE a; | ||
533 | 3 | CREATE TABLE t1(a INT); | ||
534 | 4 | CREATE DATABASE b; | ||
535 | 5 | USE b; | ||
536 | 6 | CREATE TABLE t1(b INT); | ||
537 | 7 | CREATE DATABASE c; | ||
538 | 8 | USE c; | ||
539 | 9 | CREATE TABLE t1(c INT); | ||
540 | 10 | RESET MASTER; | ||
541 | 11 | USE a; | ||
542 | 12 | INSERT INTO t1 VALUES(0); | ||
543 | 13 | USE b; | ||
544 | 14 | INSERT INTO t1 VALUES(1); | ||
545 | 15 | FLUSH LOGS; | ||
546 | 16 | # | ||
547 | 17 | # Apply log with '' | ||
548 | 18 | # | ||
549 | 19 | a | ||
550 | 20 | 0 | ||
551 | 21 | b | ||
552 | 22 | 1 | ||
553 | 23 | c | ||
554 | 24 | # | ||
555 | 25 | # Apply log with '--rewrite-db="a->c"' | ||
556 | 26 | # | ||
557 | 27 | a | ||
558 | 28 | b | ||
559 | 29 | 1 | ||
560 | 30 | c | ||
561 | 31 | 0 | ||
562 | 32 | # | ||
563 | 33 | # Apply log with '--rewrite-db="a->b"' | ||
564 | 34 | # | ||
565 | 35 | a | ||
566 | 36 | b | ||
567 | 37 | 0 | ||
568 | 38 | 1 | ||
569 | 39 | c | ||
570 | 40 | USE a; | ||
571 | 41 | DROP TABLE t1; | ||
572 | 42 | DROP DATABASE a; | ||
573 | 43 | USE b; | ||
574 | 44 | DROP TABLE t1; | ||
575 | 45 | DROP DATABASE b; | ||
576 | 46 | USE c; | ||
577 | 47 | DROP TABLE t1; | ||
578 | 48 | DROP DATABASE c; | ||
579 | 0 | 49 | ||
580 | === added file 'Percona-Server/mysql-test/r/wl36-statement.result' | |||
581 | --- Percona-Server/mysql-test/r/wl36-statement.result 1970-01-01 00:00:00 +0000 | |||
582 | +++ Percona-Server/mysql-test/r/wl36-statement.result 2012-02-09 15:07:20 +0000 | |||
583 | @@ -0,0 +1,48 @@ | |||
584 | 1 | CREATE DATABASE a; | ||
585 | 2 | USE a; | ||
586 | 3 | CREATE TABLE t1(a INT); | ||
587 | 4 | CREATE DATABASE b; | ||
588 | 5 | USE b; | ||
589 | 6 | CREATE TABLE t1(b INT); | ||
590 | 7 | CREATE DATABASE c; | ||
591 | 8 | USE c; | ||
592 | 9 | CREATE TABLE t1(c INT); | ||
593 | 10 | RESET MASTER; | ||
594 | 11 | USE a; | ||
595 | 12 | INSERT INTO t1 VALUES(0); | ||
596 | 13 | USE b; | ||
597 | 14 | INSERT INTO t1 VALUES(1); | ||
598 | 15 | FLUSH LOGS; | ||
599 | 16 | # | ||
600 | 17 | # Apply log with '' | ||
601 | 18 | # | ||
602 | 19 | a | ||
603 | 20 | 0 | ||
604 | 21 | b | ||
605 | 22 | 1 | ||
606 | 23 | c | ||
607 | 24 | # | ||
608 | 25 | # Apply log with '--rewrite-db="a->c"' | ||
609 | 26 | # | ||
610 | 27 | a | ||
611 | 28 | b | ||
612 | 29 | 1 | ||
613 | 30 | c | ||
614 | 31 | 0 | ||
615 | 32 | # | ||
616 | 33 | # Apply log with '--rewrite-db="a->b"' | ||
617 | 34 | # | ||
618 | 35 | a | ||
619 | 36 | b | ||
620 | 37 | 0 | ||
621 | 38 | 1 | ||
622 | 39 | c | ||
623 | 40 | USE a; | ||
624 | 41 | DROP TABLE t1; | ||
625 | 42 | DROP DATABASE a; | ||
626 | 43 | USE b; | ||
627 | 44 | DROP TABLE t1; | ||
628 | 45 | DROP DATABASE b; | ||
629 | 46 | USE c; | ||
630 | 47 | DROP TABLE t1; | ||
631 | 48 | DROP DATABASE c; | ||
632 | 0 | 49 | ||
633 | === added file 'Percona-Server/mysql-test/t/wl36-mixed.test' | |||
634 | --- Percona-Server/mysql-test/t/wl36-mixed.test 1970-01-01 00:00:00 +0000 | |||
635 | +++ Percona-Server/mysql-test/t/wl36-mixed.test 2012-02-09 15:07:20 +0000 | |||
636 | @@ -0,0 +1,3 @@ | |||
637 | 1 | --source include/have_log_bin.inc | ||
638 | 2 | --source include/have_binlog_format_mixed.inc | ||
639 | 3 | --source include/wl36.inc | ||
640 | 0 | 4 | ||
641 | === added file 'Percona-Server/mysql-test/t/wl36-row.test' | |||
642 | --- Percona-Server/mysql-test/t/wl36-row.test 1970-01-01 00:00:00 +0000 | |||
643 | +++ Percona-Server/mysql-test/t/wl36-row.test 2012-02-09 15:07:20 +0000 | |||
644 | @@ -0,0 +1,3 @@ | |||
645 | 1 | --source include/have_log_bin.inc | ||
646 | 2 | --source include/have_binlog_format_row.inc | ||
647 | 3 | --source include/wl36.inc | ||
648 | 0 | 4 | ||
649 | === added file 'Percona-Server/mysql-test/t/wl36-statement.test' | |||
650 | --- Percona-Server/mysql-test/t/wl36-statement.test 1970-01-01 00:00:00 +0000 | |||
651 | +++ Percona-Server/mysql-test/t/wl36-statement.test 2012-02-09 15:07:20 +0000 | |||
652 | @@ -0,0 +1,3 @@ | |||
653 | 1 | --source include/have_log_bin.inc | ||
654 | 2 | --source include/have_binlog_format_statement.inc | ||
655 | 3 | --source include/wl36.inc | ||
656 | 0 | 4 | ||
657 | === modified file 'Percona-Server/sql/log_event.cc' | |||
658 | --- Percona-Server/sql/log_event.cc 2012-01-30 04:30:33 +0000 | |||
659 | +++ Percona-Server/sql/log_event.cc 2012-02-09 15:07:20 +0000 | |||
660 | @@ -1134,7 +1134,7 @@ | |||
661 | 1134 | goto err; | 1134 | goto err; |
662 | 1135 | } | 1135 | } |
663 | 1136 | if ((res= read_log_event(buf, data_len, &error, description_event))) | 1136 | if ((res= read_log_event(buf, data_len, &error, description_event))) |
665 | 1137 | res->register_temp_buf(buf); | 1137 | res->register_temp_buf(buf, TRUE); |
666 | 1138 | 1138 | ||
667 | 1139 | err: | 1139 | err: |
668 | 1140 | UNLOCK_MUTEX; | 1140 | UNLOCK_MUTEX; |
669 | @@ -8271,6 +8271,111 @@ | |||
670 | 8271 | my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR)); | 8271 | my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR)); |
671 | 8272 | } | 8272 | } |
672 | 8273 | 8273 | ||
673 | 8274 | |||
674 | 8275 | #ifdef MYSQL_CLIENT | ||
675 | 8276 | |||
676 | 8277 | /* | ||
677 | 8278 | Rewrite database name for the event to name specified by new_db | ||
678 | 8279 | SYNOPSIS | ||
679 | 8280 | new_db Database name to change to | ||
680 | 8281 | new_len Length | ||
681 | 8282 | desc Event describing binlog that we're writing to. | ||
682 | 8283 | |||
683 | 8284 | DESCRIPTION | ||
684 | 8285 | Reset db name. This function assumes that temp_buf member contains event | ||
685 | 8286 | representation taken from a binary log. It resets m_dbnam and m_dblen and | ||
686 | 8287 | rewrites temp_buf with new db name. | ||
687 | 8288 | |||
688 | 8289 | RETURN | ||
689 | 8290 | 0 - Success | ||
690 | 8291 | other - Error | ||
691 | 8292 | */ | ||
692 | 8293 | |||
693 | 8294 | int Table_map_log_event::rewrite_db(const char* new_db, size_t new_len, | ||
694 | 8295 | const Format_description_log_event* desc) | ||
695 | 8296 | { | ||
696 | 8297 | DBUG_ENTER("Table_map_log_event::rewrite_db"); | ||
697 | 8298 | DBUG_ASSERT(temp_buf); | ||
698 | 8299 | |||
699 | 8300 | uint header_len= min(desc->common_header_len, | ||
700 | 8301 | LOG_EVENT_MINIMAL_HEADER_LEN) + TABLE_MAP_HEADER_LEN; | ||
701 | 8302 | int len_diff; | ||
702 | 8303 | |||
703 | 8304 | if (!(len_diff= new_len - m_dblen)) | ||
704 | 8305 | { | ||
705 | 8306 | memcpy((void*) (temp_buf + header_len + 1), new_db, m_dblen + 1); | ||
706 | 8307 | memcpy((void*) m_dbnam, new_db, m_dblen + 1); | ||
707 | 8308 | DBUG_RETURN(0); | ||
708 | 8309 | } | ||
709 | 8310 | |||
710 | 8311 | // Create new temp_buf | ||
711 | 8312 | ulong event_cur_len= uint4korr(temp_buf + EVENT_LEN_OFFSET); | ||
712 | 8313 | ulong event_new_len= event_cur_len + len_diff; | ||
713 | 8314 | char* new_temp_buf= (char*) my_malloc(event_new_len, MYF(MY_WME)); | ||
714 | 8315 | |||
715 | 8316 | if (!new_temp_buf) | ||
716 | 8317 | { | ||
717 | 8318 | sql_print_error("Table_map_log_event::rewrite_db: " | ||
718 | 8319 | "failed to allocate new temp_buf (%d bytes required)", | ||
719 | 8320 | event_new_len); | ||
720 | 8321 | DBUG_RETURN(-1); | ||
721 | 8322 | } | ||
722 | 8323 | |||
723 | 8324 | // Rewrite temp_buf | ||
724 | 8325 | char* ptr= new_temp_buf; | ||
725 | 8326 | ulong cnt= 0; | ||
726 | 8327 | |||
727 | 8328 | // Copy header and change event length | ||
728 | 8329 | memcpy(ptr, temp_buf, header_len); | ||
729 | 8330 | int4store(ptr + EVENT_LEN_OFFSET, event_new_len); | ||
730 | 8331 | ptr += header_len; | ||
731 | 8332 | cnt += header_len; | ||
732 | 8333 | |||
733 | 8334 | // Write new db name length and new name | ||
734 | 8335 | *ptr++ = new_len; | ||
735 | 8336 | memcpy(ptr, new_db, new_len + 1); | ||
736 | 8337 | ptr += new_len + 1; | ||
737 | 8338 | cnt += m_dblen + 2; | ||
738 | 8339 | |||
739 | 8340 | // Copy rest part | ||
740 | 8341 | memcpy(ptr, temp_buf + cnt, event_cur_len - cnt); | ||
741 | 8342 | |||
742 | 8343 | // Reregister temp buf | ||
743 | 8344 | free_temp_buf(); | ||
744 | 8345 | register_temp_buf(new_temp_buf, TRUE); | ||
745 | 8346 | |||
746 | 8347 | // Reset m_dbnam and m_dblen members | ||
747 | 8348 | m_dblen= new_len; | ||
748 | 8349 | |||
749 | 8350 | // m_dbnam resides in m_memory together with m_tblnam and m_coltype | ||
750 | 8351 | uchar* memory= m_memory; | ||
751 | 8352 | char const* tblnam= m_tblnam; | ||
752 | 8353 | uchar* coltype= m_coltype; | ||
753 | 8354 | |||
754 | 8355 | m_memory= (uchar*) my_multi_malloc(MYF(MY_WME), | ||
755 | 8356 | &m_dbnam, (uint) m_dblen + 1, | ||
756 | 8357 | &m_tblnam, (uint) m_tbllen + 1, | ||
757 | 8358 | &m_coltype, (uint) m_colcnt, | ||
758 | 8359 | NullS); | ||
759 | 8360 | |||
760 | 8361 | if (!m_memory) | ||
761 | 8362 | { | ||
762 | 8363 | sql_print_error("Table_map_log_event::rewrite_db: " | ||
763 | 8364 | "failed to allocate new m_memory (%d + %d + %d bytes required)", | ||
764 | 8365 | m_dblen + 1, m_tbllen + 1, m_colcnt); | ||
765 | 8366 | DBUG_RETURN(-1); | ||
766 | 8367 | } | ||
767 | 8368 | |||
768 | 8369 | memcpy((void*)m_dbnam, new_db, m_dblen + 1); | ||
769 | 8370 | memcpy((void*)m_tblnam, tblnam, m_tbllen + 1); | ||
770 | 8371 | memcpy(m_coltype, coltype, m_colcnt); | ||
771 | 8372 | |||
772 | 8373 | my_free(memory, MYF(MY_WME)); | ||
773 | 8374 | DBUG_RETURN(0); | ||
774 | 8375 | } | ||
775 | 8376 | #endif /* MYSQL_CLIENT */ | ||
776 | 8377 | |||
777 | 8378 | |||
778 | 8274 | /* | 8379 | /* |
779 | 8275 | Return value is an error code, one of: | 8380 | Return value is an error code, one of: |
780 | 8276 | 8381 | ||
781 | 8277 | 8382 | ||
782 | === modified file 'Percona-Server/sql/log_event.h' | |||
783 | --- Percona-Server/sql/log_event.h 2012-01-30 04:30:33 +0000 | |||
784 | +++ Percona-Server/sql/log_event.h 2012-02-09 15:07:20 +0000 | |||
785 | @@ -889,6 +889,13 @@ | |||
786 | 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. |
787 | 890 | */ | 890 | */ |
788 | 891 | char *temp_buf; | 891 | char *temp_buf; |
789 | 892 | |||
790 | 893 | /* | ||
791 | 894 | TRUE <=> this event 'owns' temp_buf and should call my_free() when done | ||
792 | 895 | with it | ||
793 | 896 | */ | ||
794 | 897 | bool event_owns_temp_buf; | ||
795 | 898 | |||
796 | 892 | /* | 899 | /* |
797 | 893 | Timestamp on the master(for debugging and replication of | 900 | Timestamp on the master(for debugging and replication of |
798 | 894 | NOW()/TIMESTAMP). It is important for queries and LOAD DATA | 901 | NOW()/TIMESTAMP). It is important for queries and LOAD DATA |
799 | @@ -1030,12 +1037,17 @@ | |||
800 | 1030 | Log_event(const char* buf, const Format_description_log_event | 1037 | Log_event(const char* buf, const Format_description_log_event |
801 | 1031 | *description_event); | 1038 | *description_event); |
802 | 1032 | virtual ~Log_event() { free_temp_buf();} | 1039 | virtual ~Log_event() { free_temp_buf();} |
804 | 1033 | void register_temp_buf(char* buf) { temp_buf = buf; } | 1040 | void register_temp_buf(char* buf, bool must_free) |
805 | 1041 | { | ||
806 | 1042 | temp_buf= buf; | ||
807 | 1043 | event_owns_temp_buf= must_free; | ||
808 | 1044 | } | ||
809 | 1034 | void free_temp_buf() | 1045 | void free_temp_buf() |
810 | 1035 | { | 1046 | { |
811 | 1036 | if (temp_buf) | 1047 | if (temp_buf) |
812 | 1037 | { | 1048 | { |
814 | 1038 | my_free(temp_buf, MYF(0)); | 1049 | if (event_owns_temp_buf) |
815 | 1050 | my_free(temp_buf, MYF(0)); | ||
816 | 1039 | temp_buf = 0; | 1051 | temp_buf = 0; |
817 | 1040 | } | 1052 | } |
818 | 1041 | } | 1053 | } |
819 | @@ -3360,6 +3372,8 @@ | |||
820 | 3360 | ulong get_table_id() const { return m_table_id; } | 3372 | ulong get_table_id() const { return m_table_id; } |
821 | 3361 | const char *get_table_name() const { return m_tblnam; } | 3373 | const char *get_table_name() const { return m_tblnam; } |
822 | 3362 | const char *get_db_name() const { return m_dbnam; } | 3374 | const char *get_db_name() const { return m_dbnam; } |
823 | 3375 | int rewrite_db(const char* new_name, size_t new_name_len, | ||
824 | 3376 | const Format_description_log_event*); | ||
825 | 3363 | #endif | 3377 | #endif |
826 | 3364 | 3378 | ||
827 | 3365 | virtual Log_event_type get_type_code() { return TABLE_MAP_EVENT; } | 3379 | virtual Log_event_type get_type_code() { return TABLE_MAP_EVENT; } |
828 | 3366 | 3380 | ||
829 | === modified file 'Percona-Server/sql/mysql_priv.h' | |||
830 | --- Percona-Server/sql/mysql_priv.h 2011-11-24 02:01:21 +0000 | |||
831 | +++ Percona-Server/sql/mysql_priv.h 2012-02-09 15:07:20 +0000 | |||
832 | @@ -93,12 +93,16 @@ | |||
833 | 93 | #include "unireg.h" | 93 | #include "unireg.h" |
834 | 94 | 94 | ||
835 | 95 | void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size); | 95 | void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size); |
836 | 96 | #endif // MYSQL_CLIENT | ||
837 | 97 | |||
838 | 96 | void *sql_alloc(size_t); | 98 | void *sql_alloc(size_t); |
839 | 97 | void *sql_calloc(size_t); | 99 | void *sql_calloc(size_t); |
840 | 98 | char *sql_strdup(const char *str); | 100 | char *sql_strdup(const char *str); |
841 | 99 | char *sql_strmake(const char *str, size_t len); | 101 | char *sql_strmake(const char *str, size_t len); |
842 | 100 | void *sql_memdup(const void * ptr, size_t size); | 102 | void *sql_memdup(const void * ptr, size_t size); |
843 | 101 | void sql_element_free(void *ptr); | 103 | void sql_element_free(void *ptr); |
844 | 104 | |||
845 | 105 | #ifndef MYSQL_CLIENT | ||
846 | 102 | char *sql_strmake_with_convert(const char *str, size_t arg_length, | 106 | char *sql_strmake_with_convert(const char *str, size_t arg_length, |
847 | 103 | CHARSET_INFO *from_cs, | 107 | CHARSET_INFO *from_cs, |
848 | 104 | size_t max_res_length, | 108 | size_t max_res_length, |
849 | 105 | 109 | ||
850 | === modified file 'Percona-Server/sql/mysqld.cc' | |||
851 | --- Percona-Server/sql/mysqld.cc 2012-02-07 03:25:46 +0000 | |||
852 | +++ Percona-Server/sql/mysqld.cc 2012-02-09 15:07:20 +0000 | |||
853 | @@ -8469,6 +8469,7 @@ | |||
854 | 8469 | } | 8469 | } |
855 | 8470 | case (int)OPT_REPLICATE_REWRITE_DB: | 8470 | case (int)OPT_REPLICATE_REWRITE_DB: |
856 | 8471 | { | 8471 | { |
857 | 8472 | /* See also OPT_REWRITE_DB handling in client/mysqlbinlog.cc */ | ||
858 | 8472 | char* key = argument,*p, *val; | 8473 | char* key = argument,*p, *val; |
859 | 8473 | 8474 | ||
860 | 8474 | if (!(p= strstr(argument, "->"))) | 8475 | if (!(p= strstr(argument, "->"))) |
861 | 8475 | 8476 | ||
862 | === modified file 'Percona-Server/sql/rpl_filter.cc' | |||
863 | --- Percona-Server/sql/rpl_filter.cc 2011-06-30 15:37:13 +0000 | |||
864 | +++ Percona-Server/sql/rpl_filter.cc 2012-02-09 15:07:20 +0000 | |||
865 | @@ -48,6 +48,7 @@ | |||
866 | 48 | } | 48 | } |
867 | 49 | 49 | ||
868 | 50 | 50 | ||
869 | 51 | #ifndef MYSQL_CLIENT | ||
870 | 51 | /* | 52 | /* |
871 | 52 | Returns true if table should be logged/replicated | 53 | Returns true if table should be logged/replicated |
872 | 53 | 54 | ||
873 | @@ -132,6 +133,7 @@ | |||
874 | 132 | !do_table_inited && !wild_do_table_inited); | 133 | !do_table_inited && !wild_do_table_inited); |
875 | 133 | } | 134 | } |
876 | 134 | 135 | ||
877 | 136 | #endif | ||
878 | 135 | 137 | ||
879 | 136 | /* | 138 | /* |
880 | 137 | Checks whether a db matches some do_db and ignore_db rules | 139 | Checks whether a db matches some do_db and ignore_db rules |
881 | @@ -517,6 +519,13 @@ | |||
882 | 517 | } | 519 | } |
883 | 518 | 520 | ||
884 | 519 | 521 | ||
885 | 522 | bool | ||
886 | 523 | Rpl_filter::rewrite_db_is_empty() | ||
887 | 524 | { | ||
888 | 525 | return rewrite_db.is_empty(); | ||
889 | 526 | } | ||
890 | 527 | |||
891 | 528 | |||
892 | 520 | const char* | 529 | const char* |
893 | 521 | Rpl_filter::get_rewrite_db(const char* db, size_t *new_len) | 530 | Rpl_filter::get_rewrite_db(const char* db, size_t *new_len) |
894 | 522 | { | 531 | { |
895 | 523 | 532 | ||
896 | === modified file 'Percona-Server/sql/rpl_filter.h' | |||
897 | --- Percona-Server/sql/rpl_filter.h 2007-05-10 09:59:39 +0000 | |||
898 | +++ Percona-Server/sql/rpl_filter.h 2012-02-09 15:07:20 +0000 | |||
899 | @@ -42,7 +42,9 @@ | |||
900 | 42 | 42 | ||
901 | 43 | /* Checks - returns true if ok to replicate/log */ | 43 | /* Checks - returns true if ok to replicate/log */ |
902 | 44 | 44 | ||
904 | 45 | bool tables_ok(const char* db, TABLE_LIST* tables); | 45 | #ifndef MYSQL_CLIENT |
905 | 46 | bool tables_ok(const char* db, TABLE_LIST *tables); | ||
906 | 47 | #endif | ||
907 | 46 | bool db_ok(const char* db); | 48 | bool db_ok(const char* db); |
908 | 47 | bool db_ok_with_wild_table(const char *db); | 49 | bool db_ok_with_wild_table(const char *db); |
909 | 48 | 50 | ||
910 | @@ -69,6 +71,7 @@ | |||
911 | 69 | void get_wild_do_table(String* str); | 71 | void get_wild_do_table(String* str); |
912 | 70 | void get_wild_ignore_table(String* str); | 72 | void get_wild_ignore_table(String* str); |
913 | 71 | 73 | ||
914 | 74 | bool rewrite_db_is_empty(); | ||
915 | 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); |
916 | 73 | 76 | ||
917 | 74 | I_List<i_string>* get_do_db(); | 77 | I_List<i_string>* get_do_db(); |
918 | 75 | 78 | ||
919 | === modified file 'Percona-Server/sql/sql_string.cc' | |||
920 | --- Percona-Server/sql/sql_string.cc 2011-10-31 09:10:04 +0000 | |||
921 | +++ Percona-Server/sql/sql_string.cc 2012-02-09 15:07:20 +0000 | |||
922 | @@ -39,6 +39,9 @@ | |||
923 | 39 | 39 | ||
924 | 40 | #include "sql_string.h" | 40 | #include "sql_string.h" |
925 | 41 | 41 | ||
926 | 42 | #ifdef MYSQL_CLIENT | ||
927 | 43 | #error Attempt to use server-side sql_string on client. Use client/sql_string.cc | ||
928 | 44 | #endif | ||
929 | 42 | /***************************************************************************** | 45 | /***************************************************************************** |
930 | 43 | ** String functions | 46 | ** String functions |
931 | 44 | *****************************************************************************/ | 47 | *****************************************************************************/ |
932 | 45 | 48 | ||
933 | === modified file 'Percona-Server/sql/sql_string.h' | |||
934 | --- Percona-Server/sql/sql_string.h 2011-07-03 15:47:37 +0000 | |||
935 | +++ Percona-Server/sql/sql_string.h 2012-02-09 15:07:20 +0000 | |||
936 | @@ -1,3 +1,6 @@ | |||
937 | 1 | #ifndef MYSQL_SQL_STRING_H_INCLUDED | ||
938 | 2 | #define MYSQL_SQL_STRING_H_INCLUDED | ||
939 | 3 | |||
940 | 1 | /* | 4 | /* |
941 | 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. |
942 | 3 | 6 | ||
943 | @@ -25,6 +28,10 @@ | |||
944 | 25 | #define NOT_FIXED_DEC 31 | 28 | #define NOT_FIXED_DEC 31 |
945 | 26 | #endif | 29 | #endif |
946 | 27 | 30 | ||
947 | 31 | #ifdef MYSQL_CLIENT | ||
948 | 32 | #error Attempt to use server-side sql_string on client. Use client/sql_string.h | ||
949 | 33 | #endif | ||
950 | 34 | |||
951 | 28 | class String; | 35 | class String; |
952 | 29 | int sortcmp(const String *a,const String *b, CHARSET_INFO *cs); | 36 | int sortcmp(const String *a,const String *b, CHARSET_INFO *cs); |
953 | 30 | String *copy_if_not_alloced(String *a,String *b,uint32 arg_length); | 37 | String *copy_if_not_alloced(String *a,String *b,uint32 arg_length); |
954 | @@ -408,3 +415,5 @@ | |||
955 | 408 | { | 415 | { |
956 | 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; |
957 | 410 | } | 417 | } |
958 | 418 | |||
959 | 419 | #endif // MYSQL_SQL_STRING_H_INCLUDED | ||
960 | 411 | 420 | ||
961 | === modified file 'Percona-Server/sql/thr_malloc.cc' | |||
962 | --- Percona-Server/sql/thr_malloc.cc 2011-06-30 15:37:13 +0000 | |||
963 | +++ Percona-Server/sql/thr_malloc.cc 2012-02-09 15:07:20 +0000 | |||
964 | @@ -65,11 +65,13 @@ | |||
965 | 65 | } | 65 | } |
966 | 66 | 66 | ||
967 | 67 | 67 | ||
968 | 68 | #ifndef MYSQL_CLIENT | ||
969 | 68 | void *sql_alloc(size_t Size) | 69 | void *sql_alloc(size_t Size) |
970 | 69 | { | 70 | { |
971 | 70 | MEM_ROOT *root= *my_pthread_getspecific_ptr(MEM_ROOT**,THR_MALLOC); | 71 | MEM_ROOT *root= *my_pthread_getspecific_ptr(MEM_ROOT**,THR_MALLOC); |
972 | 71 | return alloc_root(root,Size); | 72 | return alloc_root(root,Size); |
973 | 72 | } | 73 | } |
974 | 74 | #endif | ||
975 | 73 | 75 | ||
976 | 74 | 76 | ||
977 | 75 | void *sql_calloc(size_t size) | 77 | void *sql_calloc(size_t size) |
978 | 76 | 78 | ||
979 | === added file 'doc/source/flexibility/mysqlbinlog_change_db.rst' | |||
980 | --- doc/source/flexibility/mysqlbinlog_change_db.rst 1970-01-01 00:00:00 +0000 | |||
981 | +++ doc/source/flexibility/mysqlbinlog_change_db.rst 2012-02-09 15:07:20 +0000 | |||
982 | @@ -0,0 +1,43 @@ | |||
983 | 1 | .. _mysqlbinlog_change_db: | ||
984 | 2 | |||
985 | 3 | ========================= | ||
986 | 4 | Ability to change database for mysqlbinlog | ||
987 | 5 | ========================= | ||
988 | 6 | |||
989 | 7 | Sometimes there is a need to take a binary log and apply it to a database with | ||
990 | 8 | a different name than the original name of the database on binlog producer. | ||
991 | 9 | |||
992 | 10 | If one is using statement-based replication, he can achieve this by grepping | ||
993 | 11 | out "USE dbname" statements out of the output of mysqlbinlog(*). With | ||
994 | 12 | row-based replication this is no longer possible, as database name is encoded | ||
995 | 13 | within the the BINLOG '....' statement. | ||
996 | 14 | |||
997 | 15 | This task is about adding an option to mysqlbinlog that would allow to change | ||
998 | 16 | the names of used databases in both RBR and SBR events. | ||
999 | 17 | |||
1000 | 18 | Varible :variable:`rewrite-db` of **mysqlbinlog** utility allows to setup rewriting rule "from->"to". | ||
1001 | 19 | |||
1002 | 20 | Version Specific Information | ||
1003 | 21 | ============================ | ||
1004 | 22 | |||
1005 | 23 | * 5.1.62-12.1 | ||
1006 | 24 | Full functionality. | ||
1007 | 25 | |||
1008 | 26 | Client Command Line Parameter | ||
1009 | 27 | ============================= | ||
1010 | 28 | |||
1011 | 29 | .. variable:: rewrite-db | ||
1012 | 30 | |||
1013 | 31 | :cli: Yes | ||
1014 | 32 | :conf: Yes | ||
1015 | 33 | :scope: Global | ||
1016 | 34 | :dyn: No | ||
1017 | 35 | :vartype: String | ||
1018 | 36 | :default: Off | ||
1019 | 37 | |||
1020 | 38 | |||
1021 | 39 | Related Reading | ||
1022 | 40 | =============== | ||
1023 | 41 | |||
1024 | 42 | * `WL #36 <http://askmonty.org/worklog/Server-Sprint/?tid=36>`_ | ||
1025 | 43 | |||
1026 | 0 | 44 | ||
1027 | === modified file 'doc/source/index.rst' | |||
1028 | --- doc/source/index.rst 2012-01-31 10:35:01 +0000 | |||
1029 | +++ doc/source/index.rst 2012-02-09 15:07:20 +0000 | |||
1030 | @@ -88,6 +88,7 @@ | |||
1031 | 88 | flexibility/innodb_files_extend | 88 | flexibility/innodb_files_extend |
1032 | 89 | flexibility/log_warnings_suppress | 89 | flexibility/log_warnings_suppress |
1033 | 90 | flexibility/mysql_remove_eol_carret | 90 | flexibility/mysql_remove_eol_carret |
1034 | 91 | flexibility/mysqlbinlog_change_db | ||
1035 | 91 | flexibility/replication_skip_single_statement | 92 | flexibility/replication_skip_single_statement |
1036 | 92 | flexibility/buff_read_ahead_area | 93 | flexibility/buff_read_ahead_area |
1037 | 93 | flexibility/innodb_fast_shutdown | 94 | flexibility/innodb_fast_shutdown |
For the feature branch to go in, it needs an associated blueprint on Launchpad.