Browse Source
MDEV-10963 Fragmented BINLOG query
MDEV-10963 Fragmented BINLOG query
The problem was originally stated in http://bugs.mysql.com/bug.php?id=82212 The size of an base64-encoded Rows_log_event exceeds its vanilla byte representation in 4/3 times. When a binlogged event size is about 1GB mysqlbinlog generates a BINLOG query that can't be send out due to its size. It is fixed with fragmenting the BINLOG argument C-string into (approximate) halves when the base64 encoded event is over 1GB size. The mysqlbinlog in such case puts out SET @binlog_fragment_0='base64-encoded-fragment_0'; SET @binlog_fragment_1='base64-encoded-fragment_1'; BINLOG @binlog_fragment_0, @binlog_fragment_1; to represent a big BINLOG. For prompt memory release BINLOG handler is made to reset the BINLOG argument user variables in the middle of processing, as if @binlog_fragment_{0,1} = NULL is assigned. Notice the 2 fragments are enough, though the client and server still may need to tweak their @@max_allowed_packet to satisfy to the fragment size (which they would have to do anyway with greater number of fragments, should that be desired). On the lower level the following changes are made: Log_event::print_base64() remains to call encoder and store the encoded data into a cache but now *without* doing any formatting. The latter is left for time when the cache is copied to an output file (e.g mysqlbinlog output). No formatting behavior is also reflected by the change in the meaning of the last argument which specifies whether to cache the encoded data. Rows_log_event::print_helper() is made to invoke a specialized fragmented cache-to-file copying function which is copy_cache_to_file_wrapped() that takes care of fragmenting also optionally wraps encoded strings (fragments) into SQL stanzas. my_b_copy_to_file() is refactored to into my_b_copy_all_to_file(). The former function is generalized to accepts more a limit argument to constraint the copying and does not reinitialize anymore the cache into reading mode. The limit does not do any effect on the fully read cache.pull/1138/head
16 changed files with 511 additions and 68 deletions
-
21client/mysqlbinlog.cc
-
4include/my_sys.h
-
19mysql-test/suite/binlog/r/binlog_base64_flag.result
-
24mysql-test/suite/binlog/r/binlog_mysqlbinlog_row_frag.result
-
22mysql-test/suite/binlog/t/binlog_base64_flag.test
-
45mysql-test/suite/binlog/t/binlog_mysqlbinlog_row_frag.test
-
61mysys/mf_iocache2.c
-
2sql/item_func.cc
-
4sql/item_func.h
-
169sql/log_event.cc
-
13sql/log_event.h
-
16sql/log_event_old.cc
-
94sql/sql_binlog.cc
-
4sql/sql_lex.h
-
11sql/sql_yacc.yy
-
70unittest/sql/mf_iocache-t.cc
@ -0,0 +1,24 @@ |
|||
CREATE TABLE t (a TEXT); |
|||
RESET MASTER; |
|||
INSERT INTO t SET a=repeat('a', 1024); |
|||
SELECT a from t into @a; |
|||
FLUSH LOGS; |
|||
DELETE FROM t; |
|||
FOUND /BINLOG @binlog_fragment_0, @binlog_fragment_1/ in mysqlbinlog.sql |
|||
SELECT a LIKE @a as 'true' FROM t; |
|||
true |
|||
1 |
|||
BINLOG number-of-fragments must be exactly two |
|||
BINLOG @binlog_fragment; |
|||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1 |
|||
BINLOG @binlog_fragment, @binlog_fragment, @binlog_fragment; |
|||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' @binlog_fragment' at line 1 |
|||
SET @binlog_fragment_0='012345'; |
|||
SET @binlog_fragment_1='012345'; |
|||
BINLOG @binlog_fragment_0, @binlog_fragment_1; |
|||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use |
|||
SET @binlog_fragment_0='012345'; |
|||
BINLOG @binlog_fragment_0, @binlog_fragment_not_exist; |
|||
ERROR 42000: Incorrect argument type to variable 'binlog_fragment_not_exist' |
|||
# Cleanup |
|||
DROP TABLE t; |
@ -0,0 +1,45 @@ |
|||
--source include/have_debug.inc |
|||
--source include/have_binlog_format_row.inc |
|||
|
|||
--let $MYSQLD_DATADIR= `select @@datadir` |
|||
|
|||
CREATE TABLE t (a TEXT); |
|||
# events of interest are guaranteed to stay in 000001 log |
|||
RESET MASTER; |
|||
--eval INSERT INTO t SET a=repeat('a', 1024) |
|||
SELECT a from t into @a; |
|||
FLUSH LOGS; |
|||
DELETE FROM t; |
|||
|
|||
--exec $MYSQL_BINLOG --debug-binlog-row-event-max-encoded-size=256 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql |
|||
|
|||
--let SEARCH_PATTERN= BINLOG @binlog_fragment_0, @binlog_fragment_1 |
|||
--let SEARCH_FILE= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql |
|||
--source include/search_pattern_in_file.inc |
|||
|
|||
--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql |
|||
|
|||
SELECT a LIKE @a as 'true' FROM t; |
|||
|
|||
# improper syntax error |
|||
--echo BINLOG number-of-fragments must be exactly two |
|||
--error ER_PARSE_ERROR |
|||
BINLOG @binlog_fragment; |
|||
--error ER_PARSE_ERROR |
|||
BINLOG @binlog_fragment, @binlog_fragment, @binlog_fragment; |
|||
|
|||
# corrupted fragments error check (to the expected error code notice, |
|||
# the same error code occurs in a similar unfragmented case) |
|||
SET @binlog_fragment_0='012345'; |
|||
SET @binlog_fragment_1='012345'; |
|||
--error ER_SYNTAX_ERROR |
|||
BINLOG @binlog_fragment_0, @binlog_fragment_1; |
|||
|
|||
# Not existing fragment is not allowed |
|||
SET @binlog_fragment_0='012345'; |
|||
--error ER_WRONG_TYPE_FOR_VAR |
|||
BINLOG @binlog_fragment_0, @binlog_fragment_not_exist; |
|||
|
|||
--echo # Cleanup |
|||
--remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql |
|||
DROP TABLE t; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue