<?xml version="1.0" encoding="utf-8"?>
<launchpad-bug id="1003679">
  <date_last_updated>2012-05-26 14:43:07.055309+00:00</date_last_updated>
  <api_links>
    <bug_api_link>https://api.launchpad.net/1.0/bugs/1003679</bug_api_link>
    <bug_owner_link>https://api.launchpad.net/1.0/~elenst</bug_owner_link>
    <milestone_link>https://api.launchpad.net/1.0/maria/+milestone/5.5</milestone_link>
    <linked_branches_collection_link>https://api.launchpad.net/1.0/bugs/1003679/linked_branches</linked_branches_collection_link>
    <activity_link>https://api.launchpad.net/1.0/bugs/1003679/activity</activity_link>
  </api_links>
  <bug_web_link>https://bugs.launchpad.net/bugs/1003679</bug_web_link>
  <owner>Elena Stepanova</owner>
  <assignee>Kristian Nielsen</assignee>
  <milestone_title>Maria 5.5</milestone_title>
  <duplicate_link></duplicate_link>
  <duplicate_bug_id></duplicate_bug_id>
  <title>Wrong binlog order on concurrent DROP schema and CREATE function</title>
  <status>New</status>
  <importance>Low</importance>
  <created>2012-05-23 21:42:03.525943+00:00</created>
  <description>
<![CDATA[Also filed as http://bugs.mysql.com/bug.php?id=65428

Concurrent execution of DROP DATABASE and CREATE FUNCTION | PROCEDURE | EVENT causes a wrong order of events in the binary log and, consequently, replication failure.

Provided MTR test case is non-deterministic, so I am also adding an RQG grammar to reproduce.
The problem is that on master CREATE FUNCTION gets executed without an error, but in the binlog DROP DATABASE is written before CREATE FUNCTION.

Reproducible on maria/5.5 revno 3413, mysql-5.5 revno 3737, mysql-trunk revno 3827.
Could not reproduce on maria/5.3, although due to the non-deterministic nature of the test there is no guarantee the problem is not present there.

# MTR test case t1.test
# run as perl ./mtr --mysqld=--binlog-format=mixed t1

--source include/master-slave.inc

DROP DATABASE IF EXISTS db1;

CREATE DATABASE db1;
CREATE FUNCTION db1.f1() RETURNS INT RETURN 1;
--send
DROP DATABASE db1;

--connection master1
--error 0,ER_BAD_DB_ERROR
CREATE FUNCTION db1.f2() RETURNS INT RETURN 1;

--connection master
--reap
SHOW BINLOG EVENTS;

--sync_slave_with_master

# End of MTR test case

# Binlog contents:

Log_name        Pos     Event_type      Server_id       End_log_pos     Info
slave-relay-bin.000002  4       Format_desc     2       245     Server ver: 5.5.23-MariaDB-debug-log, Binlog ver: 4
slave-relay-bin.000002  245     Rotate  1       0       master-bin.000001;pos=4
slave-relay-bin.000002  289     Format_desc     1       245     Server ver: 5.5.23-MariaDB-debug-log, Binlog ver: 4
slave-relay-bin.000002  530     Query   1       334     DROP DATABASE IF EXISTS db1
slave-relay-bin.000002  619     Query   1       415     CREATE DATABASE db1
slave-relay-bin.000002  700     Query   1       574     use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `db1`.`f1`() RETURNS int(11)
RETURN 1
slave-relay-bin.000002  859     Query   1       653     DROP DATABASE db1
slave-relay-bin.000002  938     Query   1       812     use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `db1`.`f2`() RETURNS int(11)
RETURN 1

# RQG grammar t1.yy

query:
     CREATE DATABASE IF NOT EXISTS db1; CREATE FUNCTION db1.f1() RETURNS INT RETURN 1; DROP DATABASE db1;

thread1:
     CREATE FUNCTION db1.f2() RETURNS INT RETURN 1; DROP FUNCTION db1.f2;

# End of RQG grammar

# RQG command line:

perl runall.pl \
--queries=100M \
--threads=2 \
--duration=600 \
--grammar=t1.yy \
--rpl_mode=mixed \
--basedir1=<your basedir> \
--vardir1=<your vardir>]]>  </description>
  <activities>
    <activity datechanged="2012-05-23T21:42:03.525943+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[]]>      </newvalue>
      <whatchanged>bug</whatchanged>
      <person>Elena Stepanova</person>
      <message>added bug</message>
    </activity>
    <activity datechanged="2012-05-26T14:43:06.957288+00:00">
      <oldvalue>
<![CDATA[Concurrent execution of DROP DATABASE and CREATE FUNCTION | PROCEDURE | EVENT causes a wrong order of events in the binary log and, consequently, replication failure.

Provided MTR test case is non-deterministic, so I am also adding an RQG grammar to reproduce.
The problem is that on master CREATE FUNCTION gets executed without an error, but in the binlog DROP DATABASE is written before CREATE FUNCTION.

Reproducible on maria/5.5 revno 3413, mysql-5.5 revno 3737, mysql-trunk revno 3827.
Could not reproduce on maria/5.3, although due to the non-deterministic nature of the test there is no guarantee the problem is not present there.

# MTR test case t1.test
# run as perl ./mtr --mysqld=--binlog-format=mixed t1

--source include/master-slave.inc

DROP DATABASE IF EXISTS db1;

CREATE DATABASE db1; 
CREATE FUNCTION db1.f1() RETURNS INT RETURN 1;
--send
DROP DATABASE db1;

--connection master1
--error 0,ER_BAD_DB_ERROR
CREATE FUNCTION db1.f2() RETURNS INT RETURN 1;

--connection master
--reap
SHOW BINLOG EVENTS;

--sync_slave_with_master

# End of MTR test case

# Binlog contents:

Log_name        Pos     Event_type      Server_id       End_log_pos     Info
slave-relay-bin.000002  4       Format_desc     2       245     Server ver: 5.5.23-MariaDB-debug-log, Binlog ver: 4
slave-relay-bin.000002  245     Rotate  1       0       master-bin.000001;pos=4
slave-relay-bin.000002  289     Format_desc     1       245     Server ver: 5.5.23-MariaDB-debug-log, Binlog ver: 4
slave-relay-bin.000002  530     Query   1       334     DROP DATABASE IF EXISTS db1
slave-relay-bin.000002  619     Query   1       415     CREATE DATABASE db1
slave-relay-bin.000002  700     Query   1       574     use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `db1`.`f1`() RETURNS int(11)
RETURN 1
slave-relay-bin.000002  859     Query   1       653     DROP DATABASE db1
slave-relay-bin.000002  938     Query   1       812     use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `db1`.`f2`() RETURNS int(11)
RETURN 1

# RQG grammar t1.yy

query:
     CREATE DATABASE IF NOT EXISTS db1; CREATE FUNCTION db1.f1() RETURNS INT RETURN 1; DROP DATABASE db1; 

thread1:
     CREATE FUNCTION db1.f2() RETURNS INT RETURN 1; DROP FUNCTION db1.f2;

# End of RQG grammar

# RQG command line:

perl runall.pl \
--queries=100M \
--threads=2 \
--duration=600 \
--grammar=t1.yy \
--rpl_mode=mixed \
--basedir1=<your basedir> \
--vardir1=<your vardir>]]>      </oldvalue>
      <newvalue>
<![CDATA[Also filed as http://bugs.mysql.com/bug.php?id=65428

Concurrent execution of DROP DATABASE and CREATE FUNCTION | PROCEDURE | EVENT causes a wrong order of events in the binary log and, consequently, replication failure.

Provided MTR test case is non-deterministic, so I am also adding an RQG grammar to reproduce.
The problem is that on master CREATE FUNCTION gets executed without an error, but in the binlog DROP DATABASE is written before CREATE FUNCTION.

Reproducible on maria/5.5 revno 3413, mysql-5.5 revno 3737, mysql-trunk revno 3827.
Could not reproduce on maria/5.3, although due to the non-deterministic nature of the test there is no guarantee the problem is not present there.

# MTR test case t1.test
# run as perl ./mtr --mysqld=--binlog-format=mixed t1

--source include/master-slave.inc

DROP DATABASE IF EXISTS db1;

CREATE DATABASE db1;
CREATE FUNCTION db1.f1() RETURNS INT RETURN 1;
--send
DROP DATABASE db1;

--connection master1
--error 0,ER_BAD_DB_ERROR
CREATE FUNCTION db1.f2() RETURNS INT RETURN 1;

--connection master
--reap
SHOW BINLOG EVENTS;

--sync_slave_with_master

# End of MTR test case

# Binlog contents:

Log_name        Pos     Event_type      Server_id       End_log_pos     Info
slave-relay-bin.000002  4       Format_desc     2       245     Server ver: 5.5.23-MariaDB-debug-log, Binlog ver: 4
slave-relay-bin.000002  245     Rotate  1       0       master-bin.000001;pos=4
slave-relay-bin.000002  289     Format_desc     1       245     Server ver: 5.5.23-MariaDB-debug-log, Binlog ver: 4
slave-relay-bin.000002  530     Query   1       334     DROP DATABASE IF EXISTS db1
slave-relay-bin.000002  619     Query   1       415     CREATE DATABASE db1
slave-relay-bin.000002  700     Query   1       574     use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `db1`.`f1`() RETURNS int(11)
RETURN 1
slave-relay-bin.000002  859     Query   1       653     DROP DATABASE db1
slave-relay-bin.000002  938     Query   1       812     use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `db1`.`f2`() RETURNS int(11)
RETURN 1

# RQG grammar t1.yy

query:
     CREATE DATABASE IF NOT EXISTS db1; CREATE FUNCTION db1.f1() RETURNS INT RETURN 1; DROP DATABASE db1;

thread1:
     CREATE FUNCTION db1.f2() RETURNS INT RETURN 1; DROP FUNCTION db1.f2;

# End of RQG grammar

# RQG command line:

perl runall.pl \
--queries=100M \
--threads=2 \
--duration=600 \
--grammar=t1.yy \
--rpl_mode=mixed \
--basedir1=<your basedir> \
--vardir1=<your vardir>]]>      </newvalue>
      <whatchanged>description</whatchanged>
      <person>Elena Stepanova</person>
      <message></message>
    </activity>
  </activities>
  <comments>
    <comment commentlink="https://api.launchpad.net/1.0/maria/+bug/1003679/comments/0" datecreated="2012-05-23T21:42:03.525943+00:00">
      <person>Elena Stepanova</person>
      <subject>
<![CDATA[Wrong binlog order on concurrent DROP schema and CREATE function]]>      </subject>
      <content>
<![CDATA[Concurrent execution of DROP DATABASE and CREATE FUNCTION | PROCEDURE | EVENT causes a wrong order of events in the binary log and, consequently, replication failure.

Provided MTR test case is non-deterministic, so I am also adding an RQG grammar to reproduce.
The problem is that on master CREATE FUNCTION gets executed without an error, but in the binlog DROP DATABASE is written before CREATE FUNCTION.

Reproducible on maria/5.5 revno 3413, mysql-5.5 revno 3737, mysql-trunk revno 3827.
Could not reproduce on maria/5.3, although due to the non-deterministic nature of the test there is no guarantee the problem is not present there.

# MTR test case t1.test
# run as perl ./mtr --mysqld=--binlog-format=mixed t1

--source include/master-slave.inc

DROP DATABASE IF EXISTS db1;

CREATE DATABASE db1; 
CREATE FUNCTION db1.f1() RETURNS INT RETURN 1;
--send
DROP DATABASE db1;

--connection master1
--error 0,ER_BAD_DB_ERROR
CREATE FUNCTION db1.f2() RETURNS INT RETURN 1;

--connection master
--reap
SHOW BINLOG EVENTS;

--sync_slave_with_master

# End of MTR test case

# Binlog contents:

Log_name        Pos     Event_type      Server_id       End_log_pos     Info
slave-relay-bin.000002  4       Format_desc     2       245     Server ver: 5.5.23-MariaDB-debug-log, Binlog ver: 4
slave-relay-bin.000002  245     Rotate  1       0       master-bin.000001;pos=4
slave-relay-bin.000002  289     Format_desc     1       245     Server ver: 5.5.23-MariaDB-debug-log, Binlog ver: 4
slave-relay-bin.000002  530     Query   1       334     DROP DATABASE IF EXISTS db1
slave-relay-bin.000002  619     Query   1       415     CREATE DATABASE db1
slave-relay-bin.000002  700     Query   1       574     use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `db1`.`f1`() RETURNS int(11)
RETURN 1
slave-relay-bin.000002  859     Query   1       653     DROP DATABASE db1
slave-relay-bin.000002  938     Query   1       812     use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `db1`.`f2`() RETURNS int(11)
RETURN 1

# RQG grammar t1.yy

query:
     CREATE DATABASE IF NOT EXISTS db1; CREATE FUNCTION db1.f1() RETURNS INT RETURN 1; DROP DATABASE db1; 

thread1:
     CREATE FUNCTION db1.f2() RETURNS INT RETURN 1; DROP FUNCTION db1.f2;

# End of RQG grammar

# RQG command line:

perl runall.pl \
--queries=100M \
--threads=2 \
--duration=600 \
--grammar=t1.yy \
--rpl_mode=mixed \
--basedir1=<your basedir> \
--vardir1=<your vardir>]]>      </content>
    </comment>
  </comments>
</launchpad-bug>
