-- source include/have_ndb.inc
-- source include/have_multi_ndb.inc
-- source include/have_binlog_format_row.inc

--disable_warnings
connection server2;
drop database if exists mysqltest;
drop table if exists t1,t2,t3;
connection server1;
drop database if exists mysqltest;
drop table if exists t1,t2,t3;
--connection server1
reset master;
--connection server2
reset master;
--enable_warnings

#
# basic test to see if ddl distribution works across
# multiple binlogs
#

# create database
--connection server1
create database mysqltest;

# create table
--connection server1
use mysqltest;
create table t1 (a int primary key) engine=ndb;

--connection server2
create table t2 (a int primary key) engine=ndb;
--source include/show_binlog_events.inc

--connection server1
--source include/show_binlog_events.inc

# alter table
--connection server1
reset master;
--connection server2
reset master;

--connection server2
alter table t2 add column (b int);

--connection server1
--source include/show_binlog_events.inc

# alter database
--connection server1
reset master;
--connection server2
reset master;

--connection server2
ALTER DATABASE mysqltest CHARACTER SET latin1;


# having drop here instead of below sometimes triggers bug#18976
## drop table and drop should come after data events
--connection server2
drop table mysqltest.t1;

--connection server1
--source include/show_binlog_events.inc
# to track down bug#18976
--real_sleep 10
--source include/show_binlog_events.inc

#--connection server2
#drop table mysqltest.t1;

# drop database and drop should come after data events
--connection server1
reset master;
--connection server2
reset master;

--connection server1
use test;
insert into t2 values (1,2);
drop database mysqltest;
create table t1 (a int primary key) engine=ndb;

--connection server2
--source include/show_binlog_events.inc

--connection server2
drop table t2;

# logfile groups and table spaces
--connection server1
reset master;
--connection server2
reset master;

--connection server1
CREATE LOGFILE GROUP lg1
ADD UNDOFILE 'undofile.dat'
INITIAL_SIZE 16M
UNDO_BUFFER_SIZE = 1M
ENGINE=NDB;

ALTER LOGFILE GROUP lg1
ADD UNDOFILE 'undofile02.dat'
INITIAL_SIZE = 4M 
ENGINE=NDB;

CREATE TABLESPACE ts1
ADD DATAFILE 'datafile.dat'
USE LOGFILE GROUP lg1
INITIAL_SIZE 12M
ENGINE NDB;

ALTER TABLESPACE ts1
ADD DATAFILE 'datafile02.dat'
INITIAL_SIZE = 4M 
ENGINE=NDB;

ALTER TABLESPACE ts1 
DROP DATAFILE 'datafile.dat' 
ENGINE = NDB;

ALTER TABLESPACE ts1 
DROP DATAFILE 'datafile02.dat' 
ENGINE = NDB;

DROP TABLESPACE ts1 
ENGINE = NDB;

DROP LOGFILE GROUP lg1 
ENGINE =NDB;

# having drop here instead of below sometimes triggers bug#18976
#drop table t1;

--connection server2
--source include/show_binlog_events.inc
# to track down bug#18976
--real_sleep 10
--source include/show_binlog_events.inc

drop table t1;

#
# Bug #17827 cluster: rename of several tables in one statement,
# gets multiply logged
#
--connection server1
reset master;
show tables;
--connection server2
reset master;
show tables;

--connection server1
create table t1 (a int key) engine=ndb;
create table t2 (a int key) engine=ndb;
create table t3 (a int key) engine=ndb;
rename table t3 to t4, t2 to t3, t1 to t2, t4 to t1;
--connection server2
--source include/show_binlog_events.inc

drop table t1;
drop table t2;
drop table t3;

#
# Bug #17838 binlog not setup on seconday master after rename
#
#
--connection server1
reset master;
show tables;
--connection server2
reset master;
show tables;

--connection server1
create table t1 (a int key) engine=ndb;
insert into t1 values(1);
rename table t1 to t2;
insert into t2 values(2);

# now we should see data in table t1 _and_ t2
# prior to bug fix, data was missing for t2
--connection server2
drop table t2;
--source include/show_binlog_events.inc
