for master_1
for child2
child2_1
child2_2
child2_3
for child3
child3_1
child3_2
child3_3
for master_1
for child2
child2_1
child2_2
child2_3
for child3
child3_1
child3_2
child3_3

drop and create databases
DROP DATABASE IF EXISTS auto_test_local;
CREATE DATABASE auto_test_local;
USE auto_test_local;
DROP DATABASE IF EXISTS auto_test_remote;
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
DROP DATABASE IF EXISTS auto_test_remote2;
CREATE DATABASE auto_test_remote2;
USE auto_test_remote2;
DROP DATABASE IF EXISTS auto_test_remote3;
CREATE DATABASE auto_test_remote3;
USE auto_test_remote3;
DROP DATABASE IF EXISTS auto_test_local;
CREATE DATABASE auto_test_local;
USE auto_test_local;
DROP DATABASE IF EXISTS auto_test_local;
CREATE DATABASE auto_test_local;
USE auto_test_local;
DROP DATABASE IF EXISTS auto_test_local;
CREATE DATABASE auto_test_local;
USE auto_test_local;

test select 1
SELECT 1;
1
1

create table with partition test
DROP TABLE IF EXISTS ta_l2;
CREATE TABLE ta_l2 (
a INT,
b CHAR(1),
c DATETIME,
PRIMARY KEY(a)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_P_2_1
INSERT INTO ta_l2 (a, b, c) VALUES
(1, 'a', '2008-08-01 10:21:39'),
(2, 'b', '2000-01-01 00:00:00'),
(3, 'e', '2007-06-04 20:03:11'),
(4, 'd', '2003-11-30 05:01:03'),
(5, 'c', '2001-12-31 23:59:59');

select test
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a;
a	b	date_format(c, '%Y-%m-%d %H:%i:%s')
1	a	2008-08-01 10:21:39
2	b	2000-01-01 00:00:00
3	e	2007-06-04 20:03:11
4	d	2003-11-30 05:01:03
5	c	2001-12-31 23:59:59

fail-over test
SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%';
Variable_name	Value
Spider_mon_table_cache_version	0
Spider_mon_table_cache_version_req	1
INSERT INTO ta_l2 (a, b, c) VALUES
(6, 'e', '2011-05-05 20:04:05');
ERROR HY000: Table 'SYSTEM.ta_r4' get a problem
SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables
ORDER BY db_name, table_name, link_id;
db_name	table_name	link_id	link_status
auto_test_local	ta_l2#P#pt1	0	1
auto_test_local	ta_l2#P#pt1	1	1
auto_test_local	ta_l2#P#pt2	0	1
auto_test_local	ta_l2#P#pt2	1	3
SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log;
db_name	table_name	link_id
auto_test_local	ta_l2#P#pt2	1
SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%';
Variable_name	Value
Spider_mon_table_cache_version	1
Spider_mon_table_cache_version_req	1
INSERT INTO ta_l2 (a, b, c) VALUES
(6, 'e', '2011-05-05 20:04:05');
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a;
a	b	date_format(c, '%Y-%m-%d %H:%i:%s')
1	a	2008-08-01 10:21:39
2	b	2000-01-01 00:00:00
3	e	2007-06-04 20:03:11
4	d	2003-11-30 05:01:03
5	c	2001-12-31 23:59:59
6	e	2011-05-05 20:04:05

recovery test
ALTER TABLE ta_l2
PARTITION BY KEY(a) (
PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3",
    priority "1000"',
PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4",
    priority "1000001", lst "0 2"'
  );
SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables
ORDER BY db_name, table_name, link_id;
db_name	table_name	link_id	link_status
auto_test_local	ta_l2#P#pt1	0	1
auto_test_local	ta_l2#P#pt1	1	1
auto_test_local	ta_l2#P#pt2	0	1
auto_test_local	ta_l2#P#pt2	1	2
SELECT spider_copy_tables('ta_l2#P#pt2', '0', '1');
spider_copy_tables('ta_l2#P#pt2', '0', '1')
1
ALTER TABLE ta_l2
PARTITION BY KEY(a) (
PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3",
    priority "1000"',
PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4",
    priority "1000001", lst "0 1"'
  );
SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables
ORDER BY db_name, table_name, link_id;
db_name	table_name	link_id	link_status
auto_test_local	ta_l2#P#pt1	0	1
auto_test_local	ta_l2#P#pt1	1	1
auto_test_local	ta_l2#P#pt2	0	1
auto_test_local	ta_l2#P#pt2	1	1
INSERT INTO ta_l2 (a, b, c) VALUES
(8, 'g', '2011-05-05 21:33:30'),
(9, 'h', '2011-05-05 22:32:10');
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a;
a	b	date_format(c, '%Y-%m-%d %H:%i:%s')
1	a	2008-08-01 10:21:39
2	b	2000-01-01 00:00:00
3	e	2007-06-04 20:03:11
4	d	2003-11-30 05:01:03
5	c	2001-12-31 23:59:59
6	e	2011-05-05 20:04:05
8	g	2011-05-05 21:33:30
9	h	2011-05-05 22:32:10
DROP TABLE ta_l2;

create table with partition test
DROP TABLE IF EXISTS ta_l2;
CREATE TABLE ta_l2 (
a INT,
b CHAR(1),
c DATETIME,
PRIMARY KEY(a)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_P_2_1
INSERT INTO ta_l2 (a, b, c) VALUES
(1, 'a', '2008-08-01 10:21:39'),
(2, 'b', '2000-01-01 00:00:00'),
(3, 'e', '2007-06-04 20:03:11'),
(4, 'd', '2003-11-30 05:01:03'),
(5, 'c', '2001-12-31 23:59:59');

select test
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a;
a	b	date_format(c, '%Y-%m-%d %H:%i:%s')
1	a	2008-08-01 10:21:39
2	b	2000-01-01 00:00:00
3	e	2007-06-04 20:03:11
4	d	2003-11-30 05:01:03
5	c	2001-12-31 23:59:59

fail-over test
SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%';
Variable_name	Value
Spider_mon_table_cache_version	1
Spider_mon_table_cache_version_req	1
INSERT INTO ta_l2 (a, b, c) VALUES
(6, 'e', '2011-05-05 20:04:05');
ERROR HY000: Table 'SYSTEM.ta_r2' get a problem
SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables
ORDER BY db_name, table_name, link_id;
db_name	table_name	link_id	link_status
auto_test_local	ta_l2#P#pt1	0	1
auto_test_local	ta_l2#P#pt1	1	1
auto_test_local	ta_l2#P#pt2	0	3
auto_test_local	ta_l2#P#pt2	1	1
SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log;
db_name	table_name	link_id
auto_test_local	ta_l2#P#pt2	1
auto_test_local	ta_l2#P#pt2	0
SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%';
Variable_name	Value
Spider_mon_table_cache_version	1
Spider_mon_table_cache_version_req	1
INSERT INTO ta_l2 (a, b, c) VALUES
(6, 'e', '2011-05-05 20:04:05');
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a;
a	b	date_format(c, '%Y-%m-%d %H:%i:%s')
1	a	2008-08-01 10:21:39
3	e	2007-06-04 20:03:11
5	c	2001-12-31 23:59:59
6	e	2011-05-05 20:04:05

recovery test
ALTER TABLE ta_l2
PARTITION BY KEY(a) (
PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3",
    priority "1000"',
PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4",
    priority "1000001", lst "1 0"'
  );
SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables
ORDER BY db_name, table_name, link_id;
db_name	table_name	link_id	link_status
auto_test_local	ta_l2#P#pt1	0	1
auto_test_local	ta_l2#P#pt1	1	1
auto_test_local	ta_l2#P#pt2	0	1
auto_test_local	ta_l2#P#pt2	1	1
INSERT INTO ta_l2 (a, b, c) VALUES
(8, 'g', '2011-05-05 21:33:30'),
(9, 'h', '2011-05-05 22:32:10');
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a;
a	b	date_format(c, '%Y-%m-%d %H:%i:%s')
1	a	2008-08-01 10:21:39
3	e	2007-06-04 20:03:11
5	c	2001-12-31 23:59:59
8	g	2011-05-05 21:33:30
9	h	2011-05-05 22:32:10
DROP TABLE ta_l2;

deinit
DROP DATABASE IF EXISTS auto_test_local;
DROP DATABASE IF EXISTS auto_test_remote;
DROP DATABASE IF EXISTS auto_test_remote2;
DROP DATABASE IF EXISTS auto_test_remote3;
DROP DATABASE IF EXISTS auto_test_local;
DROP DATABASE IF EXISTS auto_test_local;
DROP DATABASE IF EXISTS auto_test_local;
for master_1
for child2
child2_1
child2_2
child2_3
for child3
child3_1
child3_2
child3_3
for master_1
for child2
child2_1
child2_2
child2_3
for child3
child3_1
child3_2
child3_3

end of test
