Commit 4c69dc81 authored by Nirbhay Choubey's avatar Nirbhay Choubey

MDEV#7501 : alter table exchange partition is not replicated in galera cluster

Added logic to replicate ALTER TABLE EXCHANGE PARTITION to other nodes
in the cluster.
parent 82cecb1c
......@@ -20,4 +20,85 @@ pk i
SELECT * FROM t1;
pk i
DROP TABLE t1;
#
# MDEV#7501 : alter table exchange partition is not replicated in
# galera cluster
#
# On node_1
CREATE TABLE test.t1 (
i INT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY (i)
) ENGINE=INNODB
PARTITION BY RANGE (i)
(PARTITION p1 VALUES LESS THAN (10) ENGINE = INNODB,
PARTITION p2 VALUES LESS THAN (20) ENGINE = INNODB,
PARTITION pMax VALUES LESS THAN MAXVALUE ENGINE = INNODB);
INSERT INTO test.t1 (i) VALUE (9),(19);
CREATE TABLE test.p1 LIKE test.t1;
ALTER TABLE test.p1 REMOVE PARTITIONING;
ALTER TABLE test.t1 EXCHANGE PARTITION p1 WITH TABLE test.p1;
SELECT * FROM test.t1;
i
19
SELECT * FROM test.p1;
i
9
# On node_2
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(10) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`i`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (i)
(PARTITION p1 VALUES LESS THAN (10) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (20) ENGINE = InnoDB,
PARTITION pMax VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
SHOW CREATE TABLE p1;
Table Create Table
p1 CREATE TABLE `p1` (
`i` int(10) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`i`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1
SELECT * FROM test.t1;
i
19
SELECT * FROM test.p1;
i
9
# On node_1
ALTER TABLE t1 TRUNCATE PARTITION p2;
SELECT * FROM test.t1;
i
# On node_2
SELECT * FROM test.t1;
i
# On node_1
ALTER TABLE t1 DROP PARTITION p2;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(10) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`i`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (i)
(PARTITION p1 VALUES LESS THAN (10) ENGINE = InnoDB,
PARTITION pMax VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
# On node_2
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(10) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`i`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (i)
(PARTITION p1 VALUES LESS THAN (10) ENGINE = InnoDB,
PARTITION pMax VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
DROP TABLE t1, p1;
# End of test
......@@ -27,5 +27,68 @@ SELECT * FROM t1;
# Cleanup
DROP TABLE t1;
--echo #
--echo # MDEV#7501 : alter table exchange partition is not replicated in
--echo # galera cluster
--echo #
--echo
--echo # On node_1
--connection node_1
CREATE TABLE test.t1 (
i INT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY (i)
) ENGINE=INNODB
PARTITION BY RANGE (i)
(PARTITION p1 VALUES LESS THAN (10) ENGINE = INNODB,
PARTITION p2 VALUES LESS THAN (20) ENGINE = INNODB,
PARTITION pMax VALUES LESS THAN MAXVALUE ENGINE = INNODB);
INSERT INTO test.t1 (i) VALUE (9),(19);
CREATE TABLE test.p1 LIKE test.t1;
ALTER TABLE test.p1 REMOVE PARTITIONING;
ALTER TABLE test.t1 EXCHANGE PARTITION p1 WITH TABLE test.p1;
SELECT * FROM test.t1;
SELECT * FROM test.p1;
--echo
--echo # On node_2
--connection node_2
SHOW CREATE TABLE t1;
SHOW CREATE TABLE p1;
SELECT * FROM test.t1;
SELECT * FROM test.p1;
--echo
--echo # On node_1
--connection node_1
ALTER TABLE t1 TRUNCATE PARTITION p2;
SELECT * FROM test.t1;
--echo
--echo # On node_2
--connection node_2
SELECT * FROM test.t1;
--echo
--echo # On node_1
--connection node_1
ALTER TABLE t1 DROP PARTITION p2;
SHOW CREATE TABLE t1;
--echo
--echo # On node_2
--connection node_2
SHOW CREATE TABLE t1;
# Cleanup
DROP TABLE t1, p1;
--source include/galera_end.inc
--echo # End of test
......@@ -530,6 +530,21 @@ bool Sql_cmd_alter_table_exchange_partition::
&alter_prelocking_strategy))
DBUG_RETURN(true);
#ifdef WITH_WSREP
/* Forward declaration */
TABLE *find_temporary_table(THD *thd, const TABLE_LIST *tl);
if ((!thd->is_current_stmt_binlog_format_row() ||
/* TODO: Do we really need to check for temp tables in this case? */
!find_temporary_table(thd, table_list)) &&
wsrep_to_isolation_begin(thd, table_list->db, table_list->table_name,
NULL))
{
WSREP_WARN("ALTER TABLE EXCHANGE PARTITION isolation failure");
DBUG_RETURN(TRUE);
}
#endif /* WITH_WSREP */
part_table= table_list->table;
swap_table= swap_table_list->table;
......@@ -764,6 +779,7 @@ bool Sql_cmd_alter_table_truncate_partition::execute(THD *thd)
DBUG_RETURN(TRUE);
#ifdef WITH_WSREP
/* Forward declaration */
TABLE *find_temporary_table(THD *thd, const TABLE_LIST *tl);
if ((!thd->is_current_stmt_binlog_format_row() ||
......@@ -772,7 +788,7 @@ bool Sql_cmd_alter_table_truncate_partition::execute(THD *thd)
thd, first_table->db, first_table->table_name, NULL)
)
{
WSREP_WARN("ALTER TABLE isolation failure");
WSREP_WARN("ALTER TABLE TRUNCATE PARTITION isolation failure");
DBUG_RETURN(TRUE);
}
#endif /* WITH_WSREP */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment