Commit 8a18bb96 authored by Nirbhay Choubey's avatar Nirbhay Choubey

Merge branch '5.5-galera' into 10.0-galera

parents 91acc8b1 c18e0dab
#
# MDEV-8598 : Failed MySQL DDL commands and Galera replication
#
# On node 1
USE test;
DROP TABLE IF EXISTS t1, t2;
CREATE TABLE t1(i INT) ENGINE=INNODB;
INSERT INTO t1 VALUE(1);
SELECT * FROM t1;
i
1
# Create a new user 'foo' with limited privileges
GRANT SELECT on test.* TO foo@localhost;
# Open connection to the 1st node using 'test_user1' user.
SELECT * FROM t1;
i
1
# Following RENAME should not replicate to other node.
RENAME TABLE t1 TO t2;
ERROR 42000: DROP, ALTER command denied to user 'foo'@'localhost' for table 't1'
# On node 2
USE test;
SELECT * FROM t1;
i
1
# On node_1
RENAME TABLE t1 TO t2;
SHOW TABLES;
Tables_in_test
t2
# On node 2
USE test;
SELECT * FROM t2;
i
1
DROP USER foo@localhost;
DROP TABLE t2;
# End of tests
...@@ -4,4 +4,49 @@ ...@@ -4,4 +4,49 @@
USE test; USE test;
CREATE DEFINER=CURRENT_USER VIEW v1 AS SELECT 1; CREATE DEFINER=CURRENT_USER VIEW v1 AS SELECT 1;
DROP VIEW v1; DROP VIEW v1;
#
# MDEV-8464 : ALTER VIEW not replicated in some cases
#
# On node_1
USE test;
CREATE TABLE t1(i INT) ENGINE=INNODB;
CREATE DEFINER=CURRENT_USER VIEW v1 AS SELECT * FROM t1;
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t1;
CREATE ALGORITHM=TEMPTABLE VIEW v3 AS SELECT * FROM t1;
CREATE ALGORITHM=UNDEFINED DEFINER=CURRENT_USER VIEW v4 AS SELECT * FROM t1;
# On node_2
USE test;
SHOW CREATE VIEW v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
SHOW CREATE VIEW v2;
View Create View character_set_client collation_connection
v2 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
SHOW CREATE VIEW v3;
View Create View character_set_client collation_connection
v3 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
SHOW CREATE VIEW v4;
View Create View character_set_client collation_connection
v4 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
# On node_1
ALTER ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;
ALTER ALGORITHM=UNDEFINED VIEW v2 AS SELECT * FROM t1;
ALTER DEFINER=CURRENT_USER VIEW v3 AS SELECT * FROM t1;
ALTER ALGORITHM=TEMPTABLE DEFINER=CURRENT_USER VIEW v4 AS SELECT * FROM t1;
# On node_2
SHOW CREATE VIEW v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
SHOW CREATE VIEW v2;
View Create View character_set_client collation_connection
v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
SHOW CREATE VIEW v3;
View Create View character_set_client collation_connection
v3 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
SHOW CREATE VIEW v4;
View Create View character_set_client collation_connection
v4 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `t1`.`i` AS `i` from `t1` latin1 latin1_swedish_ci
# Cleanup
DROP VIEW v1, v2, v3, v4;
DROP TABLE t1;
# End of tests # End of tests
--source include/galera_cluster.inc
--source include/have_innodb.inc
--echo #
--echo # MDEV-8598 : Failed MySQL DDL commands and Galera replication
--echo #
--echo # On node 1
--connection node_1
USE test;
--disable_warnings
DROP TABLE IF EXISTS t1, t2;
--enable_warnings
CREATE TABLE t1(i INT) ENGINE=INNODB;
INSERT INTO t1 VALUE(1);
SELECT * FROM t1;
--echo # Create a new user 'foo' with limited privileges
GRANT SELECT on test.* TO foo@localhost;
--echo # Open connection to the 1st node using 'test_user1' user.
--let $port_1= \$NODE_MYPORT_1
--connect(foo_node_1,localhost,foo,,test,$port_1,)
--connection foo_node_1
SELECT * FROM t1;
--echo # Following RENAME should not replicate to other node.
--error ER_TABLEACCESS_DENIED_ERROR
RENAME TABLE t1 TO t2;
--echo # On node 2
--connection node_2
USE test;
SELECT * FROM t1;
--echo # On node_1
--connection node_1
RENAME TABLE t1 TO t2;
SHOW TABLES;
--echo # On node 2
--connection node_2
USE test;
SELECT * FROM t2;
# Cleanup
--connection node_1
DROP USER foo@localhost;
DROP TABLE t2;
--echo # End of tests
...@@ -8,4 +8,43 @@ USE test; ...@@ -8,4 +8,43 @@ USE test;
CREATE DEFINER=CURRENT_USER VIEW v1 AS SELECT 1; CREATE DEFINER=CURRENT_USER VIEW v1 AS SELECT 1;
DROP VIEW v1; DROP VIEW v1;
--echo #
--echo # MDEV-8464 : ALTER VIEW not replicated in some cases
--echo #
--echo # On node_1
--connection node_1
USE test;
CREATE TABLE t1(i INT) ENGINE=INNODB;
CREATE DEFINER=CURRENT_USER VIEW v1 AS SELECT * FROM t1;
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t1;
CREATE ALGORITHM=TEMPTABLE VIEW v3 AS SELECT * FROM t1;
CREATE ALGORITHM=UNDEFINED DEFINER=CURRENT_USER VIEW v4 AS SELECT * FROM t1;
--echo # On node_2
--connection node_2
USE test;
SHOW CREATE VIEW v1;
SHOW CREATE VIEW v2;
SHOW CREATE VIEW v3;
SHOW CREATE VIEW v4;
--echo # On node_1
--connection node_1
ALTER ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;
ALTER ALGORITHM=UNDEFINED VIEW v2 AS SELECT * FROM t1;
ALTER DEFINER=CURRENT_USER VIEW v3 AS SELECT * FROM t1;
ALTER ALGORITHM=TEMPTABLE DEFINER=CURRENT_USER VIEW v4 AS SELECT * FROM t1;
--echo # On node_2
--connection node_2
SHOW CREATE VIEW v1;
SHOW CREATE VIEW v2;
SHOW CREATE VIEW v3;
SHOW CREATE VIEW v4;
--echo # Cleanup
DROP VIEW v1, v2, v3, v4;
DROP TABLE t1;
--echo # End of tests --echo # End of tests
...@@ -4718,20 +4718,22 @@ restart: ...@@ -4718,20 +4718,22 @@ restart:
} }
} }
#ifdef WITH_WSREP #ifdef WITH_WSREP
if ((thd->lex->sql_command== SQLCOM_INSERT || if (wsrep_replicate_myisam &&
thd->lex->sql_command== SQLCOM_INSERT_SELECT || (*start) &&
thd->lex->sql_command== SQLCOM_REPLACE || (*start)->table &&
thd->lex->sql_command== SQLCOM_REPLACE_SELECT || (*start)->table->file->ht->db_type == DB_TYPE_MYISAM &&
thd->lex->sql_command== SQLCOM_UPDATE || thd->get_command() != COM_STMT_PREPARE &&
thd->lex->sql_command== SQLCOM_UPDATE_MULTI || ((thd->lex->sql_command == SQLCOM_INSERT ||
thd->lex->sql_command== SQLCOM_LOAD || thd->lex->sql_command == SQLCOM_INSERT_SELECT ||
thd->lex->sql_command== SQLCOM_DELETE) && thd->lex->sql_command == SQLCOM_REPLACE ||
wsrep_replicate_myisam && thd->lex->sql_command == SQLCOM_REPLACE_SELECT ||
(*start) && thd->lex->sql_command == SQLCOM_UPDATE ||
(*start)->table && (*start)->table->file->ht->db_type == DB_TYPE_MYISAM) thd->lex->sql_command == SQLCOM_UPDATE_MULTI ||
{ thd->lex->sql_command == SQLCOM_LOAD ||
WSREP_TO_ISOLATION_BEGIN(NULL, NULL, (*start)); thd->lex->sql_command == SQLCOM_DELETE)))
} {
WSREP_TO_ISOLATION_BEGIN(NULL, NULL, (*start));
}
error: error:
#endif #endif
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
#include "sql_connect.h" // decrease_user_connections, #include "sql_connect.h" // decrease_user_connections,
// check_mqh, // check_mqh,
// reset_mqh // reset_mqh
#include "sql_rename.h" // mysql_rename_table #include "sql_rename.h" // mysql_rename_tables
#include "sql_tablespace.h" // mysql_alter_tablespace #include "sql_tablespace.h" // mysql_alter_tablespace
#include "hostname.h" // hostname_cache_refresh #include "hostname.h" // hostname_cache_refresh
#include "sql_acl.h" // *_ACL, check_grant, is_acl_user, #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 ...@@ -132,7 +132,7 @@ static void sql_kill(THD *thd, longlong id, killed_state state, killed_type type
static void sql_kill_user(THD *thd, LEX_USER *user, killed_state state); static void sql_kill_user(THD *thd, LEX_USER *user, killed_state state);
static bool lock_tables_precheck(THD *thd, TABLE_LIST *tables); static bool lock_tables_precheck(THD *thd, TABLE_LIST *tables);
static bool execute_show_status(THD *, TABLE_LIST *); static bool execute_show_status(THD *, TABLE_LIST *);
static bool execute_rename_table(THD *, TABLE_LIST *, TABLE_LIST *); static bool check_rename_table(THD *, TABLE_LIST *, TABLE_LIST *);
const char *any_db="*any*"; // Special symbol for check_access const char *any_db="*any*"; // Special symbol for check_access
...@@ -1064,6 +1064,11 @@ bool do_command(THD *thd) ...@@ -1064,6 +1064,11 @@ bool do_command(THD *thd)
command != COM_SLEEP && command != COM_SLEEP &&
command != COM_STATISTICS && command != COM_STATISTICS &&
command != COM_TIME && command != COM_TIME &&
command != COM_STMT_PREPARE &&
command != COM_STMT_SEND_LONG_DATA &&
command != COM_STMT_EXECUTE &&
command != COM_STMT_RESET &&
command != COM_STMT_CLOSE &&
command != COM_END command != COM_END
) { ) {
my_message(ER_UNKNOWN_COM_ERROR, my_message(ER_UNKNOWN_COM_ERROR,
...@@ -3503,8 +3508,12 @@ end_with_restore_list: ...@@ -3503,8 +3508,12 @@ end_with_restore_list:
#endif /* HAVE_REPLICATION */ #endif /* HAVE_REPLICATION */
case SQLCOM_RENAME_TABLE: case SQLCOM_RENAME_TABLE:
{ {
if (check_rename_table(thd, first_table, all_tables))
goto error;
WSREP_TO_ISOLATION_BEGIN(0, 0, first_table) WSREP_TO_ISOLATION_BEGIN(0, 0, first_table)
if (execute_rename_table(thd, first_table, all_tables))
if (mysql_rename_tables(thd, first_table, 0))
goto error; goto error;
break; break;
} }
...@@ -5805,8 +5814,8 @@ static bool execute_show_status(THD *thd, TABLE_LIST *all_tables) ...@@ -5805,8 +5814,8 @@ static bool execute_show_status(THD *thd, TABLE_LIST *all_tables)
} }
static bool execute_rename_table(THD *thd, TABLE_LIST *first_table, static bool check_rename_table(THD *thd, TABLE_LIST *first_table,
TABLE_LIST *all_tables) TABLE_LIST *all_tables)
{ {
DBUG_ASSERT(first_table == all_tables && first_table != 0); DBUG_ASSERT(first_table == all_tables && first_table != 0);
TABLE_LIST *table; TABLE_LIST *table;
...@@ -5820,7 +5829,7 @@ static bool execute_rename_table(THD *thd, TABLE_LIST *first_table, ...@@ -5820,7 +5829,7 @@ static bool execute_rename_table(THD *thd, TABLE_LIST *first_table,
&table->next_local->grant.privilege, &table->next_local->grant.privilege,
&table->next_local->grant.m_internal, &table->next_local->grant.m_internal,
0, 0)) 0, 0))
return 1; return true;
TABLE_LIST old_list, new_list; TABLE_LIST old_list, new_list;
/* /*
we do not need initialize old_list and new_list because we will 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, ...@@ -5833,10 +5842,10 @@ static bool execute_rename_table(THD *thd, TABLE_LIST *first_table,
INSERT_ACL | CREATE_ACL) && INSERT_ACL | CREATE_ACL) &&
check_grant(thd, INSERT_ACL | CREATE_ACL, &new_list, FALSE, 1, check_grant(thd, INSERT_ACL | CREATE_ACL, &new_list, FALSE, 1,
FALSE))) FALSE)))
return 1; return true;
} }
return mysql_rename_tables(thd, first_table, 0); return false;
} }
......
...@@ -122,8 +122,6 @@ static void get_cs_converted_string_value(THD *thd, ...@@ -122,8 +122,6 @@ static void get_cs_converted_string_value(THD *thd,
static int show_create_view(THD *thd, TABLE_LIST *table, String *buff); static int show_create_view(THD *thd, TABLE_LIST *table, String *buff);
static void append_algorithm(TABLE_LIST *table, String *buff);
static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table); static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table);
/** /**
...@@ -2082,32 +2080,30 @@ static void store_key_options(THD *thd, String *packet, TABLE *table, ...@@ -2082,32 +2080,30 @@ static void store_key_options(THD *thd, String *packet, TABLE *table,
} }
} }
void
view_store_options(THD *thd, TABLE_LIST *table, String *buff)
{
append_algorithm(table, buff);
append_definer(thd, buff, &table->definer.user, &table->definer.host);
if (table->view_suid)
buff->append(STRING_WITH_LEN("SQL SECURITY DEFINER "));
else
buff->append(STRING_WITH_LEN("SQL SECURITY INVOKER "));
}
/* /*
Append DEFINER clause to the given buffer. Append ALGORITHM clause to the given buffer.
SYNOPSIS SYNOPSIS
append_definer() append_algorithm()
thd [in] thread handle table [in] table list
buffer [inout] buffer to hold DEFINER clause buff [inout] buffer to hold the ALGORITHM clause
definer_user [in] user name part of definer check_inherit [in] if true, do nothing if algorithm is INHERIT
definer_host [in] host name part of definer
*/ */
static void append_algorithm(TABLE_LIST *table, String *buff) static void append_algorithm(TABLE_LIST *table, String *buff,
bool check_inherit)
{ {
int16 algorithm= (int16) table->algorithm;
DBUG_ENTER("append_algorithm");
/*
Handle a special case when ALGORITHM is not specified, in which case we
simply return.
*/
if (check_inherit && (algorithm == VIEW_ALGORITHM_INHERIT))
DBUG_VOID_RETURN;
buff->append(STRING_WITH_LEN("ALGORITHM=")); buff->append(STRING_WITH_LEN("ALGORITHM="));
switch ((int16)table->algorithm) { switch ((int16)table->algorithm) {
case VIEW_ALGORITHM_UNDEFINED: case VIEW_ALGORITHM_UNDEFINED:
...@@ -2122,6 +2118,8 @@ static void append_algorithm(TABLE_LIST *table, String *buff) ...@@ -2122,6 +2118,8 @@ static void append_algorithm(TABLE_LIST *table, String *buff)
default: default:
DBUG_ASSERT(0); // never should happen DBUG_ASSERT(0); // never should happen
} }
DBUG_VOID_RETURN;
} }
/* /*
...@@ -2148,6 +2146,23 @@ void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user, ...@@ -2148,6 +2146,23 @@ void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user,
buffer->append(' '); buffer->append(' ');
} }
void
view_store_options4(THD *thd, TABLE_LIST *table, String *buff,
bool check_inherit)
{
append_algorithm(table, buff, check_inherit);
append_definer(thd, buff, &table->definer.user, &table->definer.host);
if (table->view_suid)
buff->append(STRING_WITH_LEN("SQL SECURITY DEFINER "));
else
buff->append(STRING_WITH_LEN("SQL SECURITY INVOKER "));
}
void
view_store_options(THD *thd, TABLE_LIST *table, String *buff)
{
view_store_options4(thd, table, buff, false);
}
static int show_create_view(THD *thd, TABLE_LIST *table, String *buff) static int show_create_view(THD *thd, TABLE_LIST *table, String *buff)
{ {
......
...@@ -108,6 +108,8 @@ void free_status_vars(); ...@@ -108,6 +108,8 @@ void free_status_vars();
void reset_status_vars(); void reset_status_vars();
bool show_create_trigger(THD *thd, const sp_name *trg_name); bool show_create_trigger(THD *thd, const sp_name *trg_name);
void view_store_options(THD *thd, TABLE_LIST *table, String *buff); void view_store_options(THD *thd, TABLE_LIST *table, String *buff);
void view_store_options4(THD *thd, TABLE_LIST *table, String *buff,
bool check_inherit);
void init_fill_schema_files_row(TABLE* table); void init_fill_schema_files_row(TABLE* table);
bool schema_table_store_record(THD *thd, TABLE *table); bool schema_table_store_record(THD *thd, TABLE *table);
......
...@@ -1151,7 +1151,7 @@ create_view_query(THD *thd, uchar** buf, size_t* buf_len) ...@@ -1151,7 +1151,7 @@ create_view_query(THD *thd, uchar** buf, size_t* buf_len)
views->view_suid = lex->create_view_suid; views->view_suid = lex->create_view_suid;
views->with_check = lex->create_view_check; views->with_check = lex->create_view_check;
view_store_options(thd, views, &buff); view_store_options4(thd, views, &buff, true);
buff.append(STRING_WITH_LEN("VIEW ")); buff.append(STRING_WITH_LEN("VIEW "));
/* Test if user supplied a db (ie: we did not use thd->db) */ /* Test if user supplied a db (ie: we did not use thd->db) */
if (views->db && views->db[0] && if (views->db && views->db[0] &&
......
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