Skip to content

Commit 8a18bb9

Browse files
author
Nirbhay Choubey
committed
Merge branch '5.5-galera' into 10.0-galera
2 parents 91acc8b + c18e0da commit 8a18bb9

File tree

9 files changed

+247
-45
lines changed

9 files changed

+247
-45
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# MDEV-8598 : Failed MySQL DDL commands and Galera replication
3+
#
4+
# On node 1
5+
USE test;
6+
DROP TABLE IF EXISTS t1, t2;
7+
CREATE TABLE t1(i INT) ENGINE=INNODB;
8+
INSERT INTO t1 VALUE(1);
9+
SELECT * FROM t1;
10+
i
11+
1
12+
# Create a new user 'foo' with limited privileges
13+
GRANT SELECT on test.* TO foo@localhost;
14+
# Open connection to the 1st node using 'test_user1' user.
15+
SELECT * FROM t1;
16+
i
17+
1
18+
# Following RENAME should not replicate to other node.
19+
RENAME TABLE t1 TO t2;
20+
ERROR 42000: DROP, ALTER command denied to user 'foo'@'localhost' for table 't1'
21+
# On node 2
22+
USE test;
23+
SELECT * FROM t1;
24+
i
25+
1
26+
# On node_1
27+
RENAME TABLE t1 TO t2;
28+
SHOW TABLES;
29+
Tables_in_test
30+
t2
31+
# On node 2
32+
USE test;
33+
SELECT * FROM t2;
34+
i
35+
1
36+
DROP USER foo@localhost;
37+
DROP TABLE t2;
38+
# End of tests

mysql-test/suite/galera/r/view.result

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,49 @@
44
USE test;
55
CREATE DEFINER=CURRENT_USER VIEW v1 AS SELECT 1;
66
DROP VIEW v1;
7+
#
8+
# MDEV-8464 : ALTER VIEW not replicated in some cases
9+
#
10+
# On node_1
11+
USE test;
12+
CREATE TABLE t1(i INT) ENGINE=INNODB;
13+
CREATE DEFINER=CURRENT_USER VIEW v1 AS SELECT * FROM t1;
14+
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t1;
15+
CREATE ALGORITHM=TEMPTABLE VIEW v3 AS SELECT * FROM t1;
16+
CREATE ALGORITHM=UNDEFINED DEFINER=CURRENT_USER VIEW v4 AS SELECT * FROM t1;
17+
# On node_2
18+
USE test;
19+
SHOW CREATE VIEW v1;
20+
View Create View character_set_client collation_connection
21+
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
22+
SHOW CREATE VIEW v2;
23+
View Create View character_set_client collation_connection
24+
v2 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
25+
SHOW CREATE VIEW v3;
26+
View Create View character_set_client collation_connection
27+
v3 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
28+
SHOW CREATE VIEW v4;
29+
View Create View character_set_client collation_connection
30+
v4 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
31+
# On node_1
32+
ALTER ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;
33+
ALTER ALGORITHM=UNDEFINED VIEW v2 AS SELECT * FROM t1;
34+
ALTER DEFINER=CURRENT_USER VIEW v3 AS SELECT * FROM t1;
35+
ALTER ALGORITHM=TEMPTABLE DEFINER=CURRENT_USER VIEW v4 AS SELECT * FROM t1;
36+
# On node_2
37+
SHOW CREATE VIEW v1;
38+
View Create View character_set_client collation_connection
39+
v1 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
40+
SHOW CREATE VIEW v2;
41+
View Create View character_set_client collation_connection
42+
v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
43+
SHOW CREATE VIEW v3;
44+
View Create View character_set_client collation_connection
45+
v3 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
46+
SHOW CREATE VIEW v4;
47+
View Create View character_set_client collation_connection
48+
v4 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
49+
# Cleanup
50+
DROP VIEW v1, v2, v3, v4;
51+
DROP TABLE t1;
752
# End of tests

mysql-test/suite/galera/t/rename.test

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--source include/galera_cluster.inc
2+
--source include/have_innodb.inc
3+
4+
--echo #
5+
--echo # MDEV-8598 : Failed MySQL DDL commands and Galera replication
6+
--echo #
7+
--echo # On node 1
8+
--connection node_1
9+
USE test;
10+
--disable_warnings
11+
DROP TABLE IF EXISTS t1, t2;
12+
--enable_warnings
13+
14+
CREATE TABLE t1(i INT) ENGINE=INNODB;
15+
INSERT INTO t1 VALUE(1);
16+
SELECT * FROM t1;
17+
18+
--echo # Create a new user 'foo' with limited privileges
19+
GRANT SELECT on test.* TO foo@localhost;
20+
21+
--echo # Open connection to the 1st node using 'test_user1' user.
22+
--let $port_1= \$NODE_MYPORT_1
23+
--connect(foo_node_1,localhost,foo,,test,$port_1,)
24+
25+
--connection foo_node_1
26+
SELECT * FROM t1;
27+
--echo # Following RENAME should not replicate to other node.
28+
--error ER_TABLEACCESS_DENIED_ERROR
29+
RENAME TABLE t1 TO t2;
30+
31+
--echo # On node 2
32+
--connection node_2
33+
USE test;
34+
SELECT * FROM t1;
35+
36+
--echo # On node_1
37+
--connection node_1
38+
RENAME TABLE t1 TO t2;
39+
SHOW TABLES;
40+
41+
--echo # On node 2
42+
--connection node_2
43+
USE test;
44+
SELECT * FROM t2;
45+
46+
# Cleanup
47+
--connection node_1
48+
DROP USER foo@localhost;
49+
DROP TABLE t2;
50+
51+
--echo # End of tests
52+

mysql-test/suite/galera/t/view.test

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,43 @@ USE test;
88
CREATE DEFINER=CURRENT_USER VIEW v1 AS SELECT 1;
99
DROP VIEW v1;
1010

11+
--echo #
12+
--echo # MDEV-8464 : ALTER VIEW not replicated in some cases
13+
--echo #
14+
--echo # On node_1
15+
--connection node_1
16+
USE test;
17+
CREATE TABLE t1(i INT) ENGINE=INNODB;
18+
CREATE DEFINER=CURRENT_USER VIEW v1 AS SELECT * FROM t1;
19+
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t1;
20+
CREATE ALGORITHM=TEMPTABLE VIEW v3 AS SELECT * FROM t1;
21+
CREATE ALGORITHM=UNDEFINED DEFINER=CURRENT_USER VIEW v4 AS SELECT * FROM t1;
22+
23+
--echo # On node_2
24+
--connection node_2
25+
USE test;
26+
SHOW CREATE VIEW v1;
27+
SHOW CREATE VIEW v2;
28+
SHOW CREATE VIEW v3;
29+
SHOW CREATE VIEW v4;
30+
31+
--echo # On node_1
32+
--connection node_1
33+
ALTER ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;
34+
ALTER ALGORITHM=UNDEFINED VIEW v2 AS SELECT * FROM t1;
35+
ALTER DEFINER=CURRENT_USER VIEW v3 AS SELECT * FROM t1;
36+
ALTER ALGORITHM=TEMPTABLE DEFINER=CURRENT_USER VIEW v4 AS SELECT * FROM t1;
37+
38+
--echo # On node_2
39+
--connection node_2
40+
SHOW CREATE VIEW v1;
41+
SHOW CREATE VIEW v2;
42+
SHOW CREATE VIEW v3;
43+
SHOW CREATE VIEW v4;
44+
45+
--echo # Cleanup
46+
DROP VIEW v1, v2, v3, v4;
47+
DROP TABLE t1;
48+
1149
--echo # End of tests
50+

sql/sql_base.cc

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4718,20 +4718,22 @@ bool open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags,
47184718
}
47194719
}
47204720
#ifdef WITH_WSREP
4721-
if ((thd->lex->sql_command== SQLCOM_INSERT ||
4722-
thd->lex->sql_command== SQLCOM_INSERT_SELECT ||
4723-
thd->lex->sql_command== SQLCOM_REPLACE ||
4724-
thd->lex->sql_command== SQLCOM_REPLACE_SELECT ||
4725-
thd->lex->sql_command== SQLCOM_UPDATE ||
4726-
thd->lex->sql_command== SQLCOM_UPDATE_MULTI ||
4727-
thd->lex->sql_command== SQLCOM_LOAD ||
4728-
thd->lex->sql_command== SQLCOM_DELETE) &&
4729-
wsrep_replicate_myisam &&
4730-
(*start) &&
4731-
(*start)->table && (*start)->table->file->ht->db_type == DB_TYPE_MYISAM)
4732-
{
4733-
WSREP_TO_ISOLATION_BEGIN(NULL, NULL, (*start));
4734-
}
4721+
if (wsrep_replicate_myisam &&
4722+
(*start) &&
4723+
(*start)->table &&
4724+
(*start)->table->file->ht->db_type == DB_TYPE_MYISAM &&
4725+
thd->get_command() != COM_STMT_PREPARE &&
4726+
((thd->lex->sql_command == SQLCOM_INSERT ||
4727+
thd->lex->sql_command == SQLCOM_INSERT_SELECT ||
4728+
thd->lex->sql_command == SQLCOM_REPLACE ||
4729+
thd->lex->sql_command == SQLCOM_REPLACE_SELECT ||
4730+
thd->lex->sql_command == SQLCOM_UPDATE ||
4731+
thd->lex->sql_command == SQLCOM_UPDATE_MULTI ||
4732+
thd->lex->sql_command == SQLCOM_LOAD ||
4733+
thd->lex->sql_command == SQLCOM_DELETE)))
4734+
{
4735+
WSREP_TO_ISOLATION_BEGIN(NULL, NULL, (*start));
4736+
}
47354737
error:
47364738
#endif
47374739

sql/sql_parse.cc

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#include "sql_connect.h" // decrease_user_connections,
5252
// check_mqh,
5353
// reset_mqh
54-
#include "sql_rename.h" // mysql_rename_table
54+
#include "sql_rename.h" // mysql_rename_tables
5555
#include "sql_tablespace.h" // mysql_alter_tablespace
5656
#include "hostname.h" // hostname_cache_refresh
5757
#include "sql_acl.h" // *_ACL, check_grant, is_acl_user,
@@ -132,7 +132,7 @@ static void sql_kill(THD *thd, longlong id, killed_state state, killed_type type
132132
static void sql_kill_user(THD *thd, LEX_USER *user, killed_state state);
133133
static bool lock_tables_precheck(THD *thd, TABLE_LIST *tables);
134134
static bool execute_show_status(THD *, TABLE_LIST *);
135-
static bool execute_rename_table(THD *, TABLE_LIST *, TABLE_LIST *);
135+
static bool check_rename_table(THD *, TABLE_LIST *, TABLE_LIST *);
136136

137137
const char *any_db="*any*"; // Special symbol for check_access
138138

@@ -1064,6 +1064,11 @@ bool do_command(THD *thd)
10641064
command != COM_SLEEP &&
10651065
command != COM_STATISTICS &&
10661066
command != COM_TIME &&
1067+
command != COM_STMT_PREPARE &&
1068+
command != COM_STMT_SEND_LONG_DATA &&
1069+
command != COM_STMT_EXECUTE &&
1070+
command != COM_STMT_RESET &&
1071+
command != COM_STMT_CLOSE &&
10671072
command != COM_END
10681073
) {
10691074
my_message(ER_UNKNOWN_COM_ERROR,
@@ -3503,8 +3508,12 @@ case SQLCOM_PREPARE:
35033508
#endif /* HAVE_REPLICATION */
35043509
case SQLCOM_RENAME_TABLE:
35053510
{
3511+
if (check_rename_table(thd, first_table, all_tables))
3512+
goto error;
3513+
35063514
WSREP_TO_ISOLATION_BEGIN(0, 0, first_table)
3507-
if (execute_rename_table(thd, first_table, all_tables))
3515+
3516+
if (mysql_rename_tables(thd, first_table, 0))
35083517
goto error;
35093518
break;
35103519
}
@@ -5805,8 +5814,8 @@ static bool execute_show_status(THD *thd, TABLE_LIST *all_tables)
58055814
}
58065815

58075816

5808-
static bool execute_rename_table(THD *thd, TABLE_LIST *first_table,
5809-
TABLE_LIST *all_tables)
5817+
static bool check_rename_table(THD *thd, TABLE_LIST *first_table,
5818+
TABLE_LIST *all_tables)
58105819
{
58115820
DBUG_ASSERT(first_table == all_tables && first_table != 0);
58125821
TABLE_LIST *table;
@@ -5820,7 +5829,7 @@ static bool execute_rename_table(THD *thd, TABLE_LIST *first_table,
58205829
&table->next_local->grant.privilege,
58215830
&table->next_local->grant.m_internal,
58225831
0, 0))
5823-
return 1;
5832+
return true;
58245833
TABLE_LIST old_list, new_list;
58255834
/*
58265835
we do not need initialize old_list and new_list because we will
@@ -5833,10 +5842,10 @@ static bool execute_rename_table(THD *thd, TABLE_LIST *first_table,
58335842
INSERT_ACL | CREATE_ACL) &&
58345843
check_grant(thd, INSERT_ACL | CREATE_ACL, &new_list, FALSE, 1,
58355844
FALSE)))
5836-
return 1;
5845+
return true;
58375846
}
58385847

5839-
return mysql_rename_tables(thd, first_table, 0);
5848+
return false;
58405849
}
58415850

58425851

sql/sql_show.cc

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ static void get_cs_converted_string_value(THD *thd,
122122

123123
static int show_create_view(THD *thd, TABLE_LIST *table, String *buff);
124124

125-
static void append_algorithm(TABLE_LIST *table, String *buff);
126-
127125
static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table);
128126

129127
/**
@@ -2082,32 +2080,30 @@ static void store_key_options(THD *thd, String *packet, TABLE *table,
20822080
}
20832081
}
20842082

2085-
2086-
void
2087-
view_store_options(THD *thd, TABLE_LIST *table, String *buff)
2088-
{
2089-
append_algorithm(table, buff);
2090-
append_definer(thd, buff, &table->definer.user, &table->definer.host);
2091-
if (table->view_suid)
2092-
buff->append(STRING_WITH_LEN("SQL SECURITY DEFINER "));
2093-
else
2094-
buff->append(STRING_WITH_LEN("SQL SECURITY INVOKER "));
2095-
}
2096-
2097-
20982083
/*
2099-
Append DEFINER clause to the given buffer.
2084+
Append ALGORITHM clause to the given buffer.
21002085
21012086
SYNOPSIS
2102-
append_definer()
2103-
thd [in] thread handle
2104-
buffer [inout] buffer to hold DEFINER clause
2105-
definer_user [in] user name part of definer
2106-
definer_host [in] host name part of definer
2087+
append_algorithm()
2088+
table [in] table list
2089+
buff [inout] buffer to hold the ALGORITHM clause
2090+
check_inherit [in] if true, do nothing if algorithm is INHERIT
21072091
*/
21082092

2109-
static void append_algorithm(TABLE_LIST *table, String *buff)
2093+
static void append_algorithm(TABLE_LIST *table, String *buff,
2094+
bool check_inherit)
21102095
{
2096+
int16 algorithm= (int16) table->algorithm;
2097+
2098+
DBUG_ENTER("append_algorithm");
2099+
2100+
/*
2101+
Handle a special case when ALGORITHM is not specified, in which case we
2102+
simply return.
2103+
*/
2104+
if (check_inherit && (algorithm == VIEW_ALGORITHM_INHERIT))
2105+
DBUG_VOID_RETURN;
2106+
21112107
buff->append(STRING_WITH_LEN("ALGORITHM="));
21122108
switch ((int16)table->algorithm) {
21132109
case VIEW_ALGORITHM_UNDEFINED:
@@ -2122,6 +2118,8 @@ static void append_algorithm(TABLE_LIST *table, String *buff)
21222118
default:
21232119
DBUG_ASSERT(0); // never should happen
21242120
}
2121+
2122+
DBUG_VOID_RETURN;
21252123
}
21262124

21272125
/*
@@ -2148,6 +2146,23 @@ void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user,
21482146
buffer->append(' ');
21492147
}
21502148

2149+
void
2150+
view_store_options4(THD *thd, TABLE_LIST *table, String *buff,
2151+
bool check_inherit)
2152+
{
2153+
append_algorithm(table, buff, check_inherit);
2154+
append_definer(thd, buff, &table->definer.user, &table->definer.host);
2155+
if (table->view_suid)
2156+
buff->append(STRING_WITH_LEN("SQL SECURITY DEFINER "));
2157+
else
2158+
buff->append(STRING_WITH_LEN("SQL SECURITY INVOKER "));
2159+
}
2160+
2161+
void
2162+
view_store_options(THD *thd, TABLE_LIST *table, String *buff)
2163+
{
2164+
view_store_options4(thd, table, buff, false);
2165+
}
21512166

21522167
static int show_create_view(THD *thd, TABLE_LIST *table, String *buff)
21532168
{

0 commit comments

Comments
 (0)