Skip to content

Commit

Permalink
Merge branch '5.5-galera' into 10.0-galera
Browse files Browse the repository at this point in the history
  • Loading branch information
Nirbhay Choubey committed Aug 14, 2015
2 parents 91acc8b + c18e0da commit 8a18bb9
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 45 deletions.
38 changes: 38 additions & 0 deletions mysql-test/suite/galera/r/rename.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# 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
45 changes: 45 additions & 0 deletions mysql-test/suite/galera/r/view.result
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,49 @@
USE test;
CREATE DEFINER=CURRENT_USER VIEW v1 AS SELECT 1;
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
52 changes: 52 additions & 0 deletions mysql-test/suite/galera/t/rename.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--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

39 changes: 39 additions & 0 deletions mysql-test/suite/galera/t/view.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,43 @@ USE test;
CREATE DEFINER=CURRENT_USER VIEW v1 AS SELECT 1;
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

30 changes: 16 additions & 14 deletions sql/sql_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4718,20 +4718,22 @@ bool open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags,
}
}
#ifdef WITH_WSREP
if ((thd->lex->sql_command== SQLCOM_INSERT ||
thd->lex->sql_command== SQLCOM_INSERT_SELECT ||
thd->lex->sql_command== SQLCOM_REPLACE ||
thd->lex->sql_command== SQLCOM_REPLACE_SELECT ||
thd->lex->sql_command== SQLCOM_UPDATE ||
thd->lex->sql_command== SQLCOM_UPDATE_MULTI ||
thd->lex->sql_command== SQLCOM_LOAD ||
thd->lex->sql_command== SQLCOM_DELETE) &&
wsrep_replicate_myisam &&
(*start) &&
(*start)->table && (*start)->table->file->ht->db_type == DB_TYPE_MYISAM)
{
WSREP_TO_ISOLATION_BEGIN(NULL, NULL, (*start));
}
if (wsrep_replicate_myisam &&
(*start) &&
(*start)->table &&
(*start)->table->file->ht->db_type == DB_TYPE_MYISAM &&
thd->get_command() != COM_STMT_PREPARE &&
((thd->lex->sql_command == SQLCOM_INSERT ||
thd->lex->sql_command == SQLCOM_INSERT_SELECT ||
thd->lex->sql_command == SQLCOM_REPLACE ||
thd->lex->sql_command == SQLCOM_REPLACE_SELECT ||
thd->lex->sql_command == SQLCOM_UPDATE ||
thd->lex->sql_command == SQLCOM_UPDATE_MULTI ||
thd->lex->sql_command == SQLCOM_LOAD ||
thd->lex->sql_command == SQLCOM_DELETE)))
{
WSREP_TO_ISOLATION_BEGIN(NULL, NULL, (*start));
}
error:
#endif

Expand Down
25 changes: 17 additions & 8 deletions sql/sql_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#include "sql_connect.h" // decrease_user_connections,
// check_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 "hostname.h" // hostname_cache_refresh
#include "sql_acl.h" // *_ACL, check_grant, is_acl_user,
Expand Down Expand Up @@ -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 bool lock_tables_precheck(THD *thd, TABLE_LIST *tables);
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

Expand Down Expand Up @@ -1064,6 +1064,11 @@ bool do_command(THD *thd)
command != COM_SLEEP &&
command != COM_STATISTICS &&
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
) {
my_message(ER_UNKNOWN_COM_ERROR,
Expand Down Expand Up @@ -3503,8 +3508,12 @@ case SQLCOM_PREPARE:
#endif /* HAVE_REPLICATION */
case SQLCOM_RENAME_TABLE:
{
if (check_rename_table(thd, first_table, all_tables))
goto error;

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;
break;
}
Expand Down Expand Up @@ -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,
TABLE_LIST *all_tables)
static bool check_rename_table(THD *thd, TABLE_LIST *first_table,
TABLE_LIST *all_tables)
{
DBUG_ASSERT(first_table == all_tables && first_table != 0);
TABLE_LIST *table;
Expand All @@ -5820,7 +5829,7 @@ static bool execute_rename_table(THD *thd, TABLE_LIST *first_table,
&table->next_local->grant.privilege,
&table->next_local->grant.m_internal,
0, 0))
return 1;
return true;
TABLE_LIST old_list, new_list;
/*
we do not need initialize old_list and new_list because we will
Expand All @@ -5833,10 +5842,10 @@ static bool execute_rename_table(THD *thd, TABLE_LIST *first_table,
INSERT_ACL | CREATE_ACL) &&
check_grant(thd, INSERT_ACL | CREATE_ACL, &new_list, FALSE, 1,
FALSE)))
return 1;
return true;
}

return mysql_rename_tables(thd, first_table, 0);
return false;
}


Expand Down
59 changes: 37 additions & 22 deletions sql/sql_show.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 void append_algorithm(TABLE_LIST *table, String *buff);

static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table);

/**
Expand Down Expand Up @@ -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
append_definer()
thd [in] thread handle
buffer [inout] buffer to hold DEFINER clause
definer_user [in] user name part of definer
definer_host [in] host name part of definer
append_algorithm()
table [in] table list
buff [inout] buffer to hold the ALGORITHM clause
check_inherit [in] if true, do nothing if algorithm is INHERIT
*/

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="));
switch ((int16)table->algorithm) {
case VIEW_ALGORITHM_UNDEFINED:
Expand All @@ -2122,6 +2118,8 @@ static void append_algorithm(TABLE_LIST *table, String *buff)
default:
DBUG_ASSERT(0); // never should happen
}

DBUG_VOID_RETURN;
}

/*
Expand All @@ -2148,6 +2146,23 @@ void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user,
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)
{
Expand Down
Loading

0 comments on commit 8a18bb9

Please sign in to comment.