MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ndb_binlog_get_binlog_stmts_basic.inc
1 #
2 # Get the mysqlbinlog tool --verbose mode to dump the Binlog contents with
3 # 'SQL' statements in triple-comments over multiple lines, e.g. :
4 #
5 ### INSERT
6 ### SET
7 ### @1=1
8 ### @2=2
9 #
10 # Then munch this output into single-line statements
11 # e.g. :
12 # INSERT SET @1=1 @2=2
13 #
14 # Then filter + sort to get deterministic order independent of Ndb table
15 # fragmentation, epoch in ndb_apply_status etc.
16 #
17 
18 --disable_query_log
19 let $MYSQLD_DATADIR= `select @@datadir;`;
20 --exec $MYSQL_BINLOG --verbose $MYSQLD_DATADIR/mysqld-bin.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql
21 
22 create table raw_binlog_rows (txt varchar(1000));
23 
24 --eval load data local infile '$MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql' into table raw_binlog_rows columns terminated by '\n';
25 
26 create table binlog_stmt_parts_unassoc (txt varchar(1000), line_count int, stmt_boundary int);
27 
28 set @line_count=0;
29 set @stmt_boundary=0;
30 
31 # Use replace() here to get rid of any unwanted Windows
32 # CRs
33 insert into binlog_stmt_parts_unassoc
34  select replace(txt, '\r', ''),
35  @line_count:= @line_count + 1, # So we can preserve order later
36  (txt like '%INSERT%' or # Identify statement boundaries
37  txt like '%UPDATE%' or
38  txt like '%DELETE%')
39  from raw_binlog_rows
40  where
41  txt like '###%'; # Discard non verbose output
42 
43 #select * from binlog_stmt_parts_unassoc;
44 
45 create table binlog_stmt_parts_assoc (txt varchar(1000), line_count int, stmt_num int);
46 
47 set @stmt_count = 0;
48 
49 insert into binlog_stmt_parts_assoc
50  select txt,
51  line_count,
52  @stmt_count:= @stmt_count + stmt_boundary # All rows from same stmt will
53  # have same stmt_num
54  from binlog_stmt_parts_unassoc order by line_count;
55 
56 
57 #select * from binlog_stmt_parts_assoc;
58 
59 create table binlog_stmts (txt varchar(1000), stmt_num int);
60 
61 insert into binlog_stmts
62  select group_concat(right(txt, # Combine rows in statment into 1
63  length(txt) - 4) # Trim ### from line start
64  order by line_count
65  separator ' '), stmt_num
66  from binlog_stmt_parts_assoc
67  group by stmt_num;
68 
69 #select * from binlog_stmts;
70 
71 # Drop ndb_apply_status entries and sort by the statment
72 # text to get a deterministic order.
73 #
74 # Reasonable order would be sort by (PK-cols, stmt_num)
75 # - Sorting by PK-cols would give determinism between events from different
76 # fragments
77 # - Multiple ops on same pk would be in order of application
78 #
79 # However, as that's harder, and unnecessary given that we just want
80 # deterministic output, not applicable SQL, we will just sort by
81 # the statement text
82 #
83 --enable_query_log
84 --eval select txt from binlog_stmts where txt $binlog_condition order by txt
85 
86 --disable_query_log
87 drop table raw_binlog_rows;
88 drop table binlog_stmt_parts_unassoc;
89 drop table binlog_stmt_parts_assoc;
90 drop table binlog_stmts;
91 --enable_query_log