| 1 |
--source include/have_ndb.inc |
| 2 |
--source include/have_log_bin.inc |
| 3 |
--source include/have_debug.inc |
| 4 |
|
| 5 |
# Bug#35217 Strange ndb_binlog_index error inserting rows in MyISAM table |
| 6 |
# Verify that mysql.ndb_binlog_index is getting unique epoch values |
| 7 |
# Do this by dropping the PK, inserting some data and checking |
| 8 |
# uniqueness |
| 9 |
# |
| 10 |
alter table mysql.ndb_binlog_index drop primary key; |
| 11 |
|
| 12 |
use test; |
| 13 |
|
| 14 |
create table t1 (a int) engine=ndb; |
| 15 |
|
| 16 |
delimiter %; |
| 17 |
create procedure ins (`rows` int) |
| 18 |
begin |
| 19 |
set @x = 0; |
| 20 |
repeat |
| 21 |
insert into t1 values (1); |
| 22 |
set @x = @x + 1; |
| 23 |
until @x = `rows` |
| 24 |
end repeat; |
| 25 |
end% |
| 26 |
|
| 27 |
delimiter ;% |
| 28 |
|
| 29 |
call ins(10000); |
| 30 |
|
| 31 |
# Did any of the epochs have > 1 entry? |
| 32 |
# (Answer should be no !) |
| 33 |
--echo Duplicate epochs according to mysql.ndb_binlog_index |
| 34 |
select epoch >> 32 as gci, |
| 35 |
(epoch << 32) >> 32 as ugci, |
| 36 |
sum(1) as count |
| 37 |
from mysql.ndb_binlog_index |
| 38 |
group by epoch |
| 39 |
having count > 1; |
| 40 |
|
| 41 |
# Now look at what's in the Binlog events themselves, in case they also |
| 42 |
# carry duplicate epochs |
| 43 |
# |
| 44 |
# Code here similar to ndb_binlog_get_binlog_stmts.inc |
| 45 |
# |
| 46 |
--disable_query_log |
| 47 |
let $MYSQLD_DATADIR= `select @@datadir;`; |
| 48 |
--exec $MYSQL_BINLOG --verbose $MYSQLD_DATADIR/binlog.000001 > $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql |
| 49 |
|
| 50 |
create table raw_binlog_rows (txt varchar(1000)); |
| 51 |
|
| 52 |
--eval load data local infile '$MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql' into table raw_binlog_rows columns terminated by '\n'; |
| 53 |
|
| 54 |
create table binlog_stmt_parts_unassoc (txt varchar(1000), line_count int NOT NULL AUTO_INCREMENT PRIMARY KEY, stmt_boundary int); |
| 55 |
|
| 56 |
# Auto incrementing line_count values preserve the order of the raw binlog rows. |
| 57 |
# Use replace() here to get rid of any unwanted Windows |
| 58 |
# CRs |
| 59 |
insert into binlog_stmt_parts_unassoc (txt,stmt_boundary) |
| 60 |
select replace(txt, '\r', ''), |
| 61 |
(txt like '%INSERT%' or # Identify statement boundaries |
| 62 |
txt like '%UPDATE%' or |
| 63 |
txt like '%DELETE%') |
| 64 |
from raw_binlog_rows |
| 65 |
where |
| 66 |
txt like '###%'; # Discard non verbose output |
| 67 |
|
| 68 |
create table binlog_stmt_parts_assoc (txt varchar(1000), line_count int, stmt_num int); |
| 69 |
|
| 70 |
set @stmt_count = 0; |
| 71 |
|
| 72 |
insert into binlog_stmt_parts_assoc |
| 73 |
( select txt, |
| 74 |
line_count, |
| 75 |
SUM(stmt_boundary) OVER(ORDER BY line_count) AS stmt_count # All rows from same stmt will |
| 76 |
# have same stmt_num |
| 77 |
from binlog_stmt_parts_unassoc order by line_count); |
| 78 |
|
| 79 |
create table binlog_stmts (txt varchar(1000), stmt_num int); |
| 80 |
|
| 81 |
insert into binlog_stmts |
| 82 |
select group_concat(right(txt, # Combine rows in statment into 1 |
| 83 |
length(txt) - 4) # Trim ### from line start |
| 84 |
order by line_count |
| 85 |
separator ' '), stmt_num |
| 86 |
from binlog_stmt_parts_assoc |
| 87 |
group by stmt_num; |
| 88 |
|
| 89 |
|
| 90 |
create table epochs_in_binlog (epoch bigint); |
| 91 |
|
| 92 |
# Trim INSERT INTO mysql.ndb_apply_status SET @1=1 @2=144115213845659648 @3='' @4=0 @5=0 |
| 93 |
# down to a list of epochs |
| 94 |
# |
| 95 |
insert into epochs_in_binlog |
| 96 |
select substring_index(right(txt, length(txt) - instr(txt, '@2=') - 3),' ', 1) |
| 97 |
from binlog_stmts |
| 98 |
where txt like '%ndb_apply_status%' |
| 99 |
order by txt; |
| 100 |
|
| 101 |
--enable_query_log |
| 102 |
--echo Duplicate epochs according to MySQLD Binlog entries |
| 103 |
select epoch >> 32 as gci, |
| 104 |
(epoch << 32) >> 32 as ugci, |
| 105 |
sum(1) as count |
| 106 |
from epochs_in_binlog |
| 107 |
group by epoch |
| 108 |
having count > 1; |
| 109 |
|
| 110 |
--disable_query_log |
| 111 |
drop table raw_binlog_rows; |
| 112 |
drop table binlog_stmt_parts_unassoc; |
| 113 |
drop table binlog_stmt_parts_assoc; |
| 114 |
drop table binlog_stmts; |
| 115 |
drop table epochs_in_binlog; |
| 116 |
--enable_query_log |
| 117 |
|
| 118 |
# Now cleanup |
| 119 |
|
| 120 |
reset master; |
| 121 |
alter table mysql.ndb_binlog_index add primary key (epoch, orig_server_id, orig_epoch); |
| 122 |
|
| 123 |
drop procedure ins; |
| 124 |
drop table t1; |
| 125 |
--remove_file $MYSQLTEST_VARDIR/tmp/ndb_binlog_mysqlbinlog.sql |