File: ndb_binlog_get_binlog_stmts_basic.inc

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (99 lines) | stat: -rw-r--r-- 3,045 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# 
# Get the mysqlbinlog tool --verbose mode to dump the Binlog contents with
# 'SQL' statements in triple-comments over multiple lines, e.g. :
#
### INSERT
###  SET
###  @1=1
###  @2=2
#
# Then munch this output into single-line statements
# e.g. :
#  INSERT SET @1=1 @2=2
#
# Then filter + sort to get deterministic order independent of Ndb table 
# fragmentation, epoch in ndb_apply_status etc.
#

--disable_query_log
let $MYSQLD_DATADIR= `select @@datadir;`;
--exec $MYSQL_BINLOG --verbose $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql

create table raw_binlog_rows (txt varchar(1000));

--eval load data local infile '$MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql' into table raw_binlog_rows columns terminated by '\n';

create table binlog_stmt_parts_unassoc (txt varchar(1000), line_count int AUTO_INCREMENT PRIMARY KEY, stmt_boundary int);

set @line_count=0;
set @stmt_boundary=0;

# Use replace() here to get rid of any unwanted Windows
# CRs
insert into binlog_stmt_parts_unassoc (txt,stmt_boundary)
  select replace(txt, '\r', ''),
         (txt like '%INSERT%' or         # Identify statement boundaries
          txt like '%UPDATE%' or
          txt like '%DELETE%')
    from raw_binlog_rows
    where
      txt like '###%';                   # Discard non verbose output

#select * from binlog_stmt_parts_unassoc;

create table binlog_stmt_parts_assoc (
  txt varchar(1000) collate utf8mb4_bin,
  line_count int,
  stmt_num int
);

set @stmt_count = 0;

insert into binlog_stmt_parts_assoc
  select t.txt,
         t.line_count,
         (SELECT SUM(x.stmt_boundary)
            FROM binlog_stmt_parts_unassoc x
           WHERE x.line_count <= t.line_count)
    from binlog_stmt_parts_unassoc t order by t.line_count;


#select * from binlog_stmt_parts_assoc;

create table binlog_stmts (
  txt varchar(1000) collate utf8mb4_bin,
  stmt_num int
);

insert into binlog_stmts 
  select group_concat(right(txt,             # Combine rows in statment into 1
                            length(txt) - 4) # Trim ### from line start
                      order by line_count
                      separator ' '), stmt_num
    from binlog_stmt_parts_assoc
    group by stmt_num;

#select * from binlog_stmts;

# Drop ndb_apply_status entries and sort by the statment 
# text to get a deterministic order.
#
# Reasonable order would be sort by (PK-cols, stmt_num)
# - Sorting by PK-cols would give determinism between events from different
#   fragments
# - Multiple ops on same pk would be in order of application
#
# However, as that's harder, and unnecessary given that we just want
# deterministic output, not applicable SQL, we will just sort by
# the statement text
#
--enable_query_log
--eval select txt from binlog_stmts where txt $binlog_condition order by txt

--disable_query_log
drop table raw_binlog_rows;
drop table binlog_stmt_parts_unassoc;
drop table binlog_stmt_parts_assoc;
drop table binlog_stmts;
--enable_query_log
--remove_file $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql