Commit 2a8ae4bd authored by Sujatha's avatar Sujatha

MDEV-19855: Create "Sql_cmd_show_slave_status" class for "SHOW SLAVE STATUS" command.

Create "Sql_cmd_show_slave_status" class for "SHOW SLAVE STATUS" command.
parent b3b965a9
......@@ -1646,6 +1646,40 @@ const char *print_slave_db_safe(const char* db)
#endif /* HAVE_REPLICATION */
bool Sql_cmd_show_slave_status::execute(THD *thd)
{
#ifndef HAVE_REPLICATION
my_ok(thd);
return false;
#else
DBUG_ENTER("Sql_cmd_show_slave_status::execute");
bool res= true;
/* Accept one of two privileges */
if (check_global_access(thd, SUPER_ACL | REPL_CLIENT_ACL))
goto error;
if (is_show_all_slaves_stat())
{
mysql_mutex_lock(&LOCK_active_mi);
res= show_all_master_info(thd);
mysql_mutex_unlock(&LOCK_active_mi);
}
else
{
LEX_MASTER_INFO *lex_mi= &thd->lex->mi;
Master_info *mi;
if ((mi= get_master_info(&lex_mi->connection_name,
Sql_condition::WARN_LEVEL_ERROR)))
{
res= show_master_info(thd, mi, 0);
mi->release();
}
}
error:
DBUG_RETURN(res);
#endif
}
int init_strvar_from_file(char *var, int max_size, IO_CACHE *f,
const char *default_val)
{
......
......@@ -208,6 +208,26 @@ class Sql_cmd : public Sql_alloc
}
};
class Sql_cmd_show_slave_status: public Sql_cmd
{
protected:
bool show_all_slaves_status;
public:
Sql_cmd_show_slave_status()
:show_all_slaves_status(false)
{}
Sql_cmd_show_slave_status(bool status_all)
:show_all_slaves_status(status_all)
{}
enum_sql_command sql_command_code() const { return SQLCOM_SHOW_SLAVE_STAT; }
bool execute(THD *thd);
bool is_show_all_slaves_stat() { return show_all_slaves_status; }
};
class Sql_cmd_create_table_like: public Sql_cmd,
public Storage_engine_name
{
......
......@@ -4079,31 +4079,7 @@ mysql_execute_command(THD *thd)
mysql_mutex_unlock(&LOCK_active_mi);
break;
}
case SQLCOM_SHOW_SLAVE_STAT:
{
/* Accept one of two privileges */
if (check_global_access(thd, SUPER_ACL | REPL_CLIENT_ACL))
goto error;
if (lex->verbose)
{
mysql_mutex_lock(&LOCK_active_mi);
res= show_all_master_info(thd);
mysql_mutex_unlock(&LOCK_active_mi);
}
else
{
LEX_MASTER_INFO *lex_mi= &thd->lex->mi;
Master_info *mi;
if ((mi= get_master_info(&lex_mi->connection_name,
Sql_condition::WARN_LEVEL_ERROR)))
{
res= show_master_info(thd, mi, 0);
mi->release();
}
}
break;
}
case SQLCOM_SHOW_MASTER_STAT:
{
/* Accept one of two privileges */
......@@ -6074,6 +6050,7 @@ mysql_execute_command(THD *thd)
DBUG_ASSERT(first_table == all_tables && first_table != 0);
/* fall through */
case SQLCOM_ALTER_SEQUENCE:
case SQLCOM_SHOW_SLAVE_STAT:
case SQLCOM_SIGNAL:
case SQLCOM_RESIGNAL:
case SQLCOM_GET_DIAGNOSTICS:
......
......@@ -1933,14 +1933,15 @@ static int mysql_test_show_grants(Prepared_statement *stmt)
TRUE error, error message is set in THD
*/
static int mysql_test_show_slave_status(Prepared_statement *stmt)
static int mysql_test_show_slave_status(Prepared_statement *stmt,
bool show_all_slaves_stat)
{
DBUG_ENTER("mysql_test_show_slave_status");
THD *thd= stmt->thd;
List<Item> fields;
show_master_info_get_fields(thd, &fields, thd->lex->verbose, 0);
show_master_info_get_fields(thd, &fields, show_all_slaves_stat, 0);
DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
}
......@@ -2393,12 +2394,20 @@ static bool check_prepared_statement(Prepared_statement *stmt)
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
#ifndef EMBEDDED_LIBRARY
case SQLCOM_SHOW_SLAVE_STAT:
if ((res= mysql_test_show_slave_status(stmt)) == 2)
{
/* Statement and field info has already been sent */
DBUG_RETURN(FALSE);
DBUG_ASSERT(thd->lex->m_sql_cmd);
Sql_cmd_show_slave_status *cmd;
cmd= dynamic_cast<Sql_cmd_show_slave_status*>(thd->lex->m_sql_cmd);
DBUG_ASSERT(cmd);
if ((res= mysql_test_show_slave_status(stmt,
cmd->is_show_all_slaves_stat()))
== 2)
{
/* Statement and field info has already been sent */
DBUG_RETURN(FALSE);
}
break;
}
break;
case SQLCOM_SHOW_MASTER_STAT:
if ((res= mysql_test_show_master_status(stmt)) == 2)
{
......
......@@ -14205,20 +14205,26 @@ show_param:
}
| ALL SLAVES STATUS_SYM
{
if (!(Lex->m_sql_cmd= new (thd->mem_root)
Sql_cmd_show_slave_status(true)))
MYSQL_YYABORT;
Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
Lex->verbose= 1;
}
| SLAVE STATUS_SYM
{
LEX *lex= thd->lex;
lex->mi.connection_name= null_clex_str;
if (!(lex->m_sql_cmd= new (thd->mem_root)
Sql_cmd_show_slave_status()))
MYSQL_YYABORT;
lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
lex->verbose= 0;
}
| SLAVE connection_name STATUS_SYM
{
if (!(Lex->m_sql_cmd= new (thd->mem_root)
Sql_cmd_show_slave_status()))
MYSQL_YYABORT;
Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
Lex->verbose= 0;
}
| CREATE PROCEDURE_SYM sp_name
{
......
......@@ -14329,19 +14329,25 @@ show_param:
| ALL SLAVES STATUS_SYM
{
Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
Lex->verbose= 1;
if (!(Lex->m_sql_cmd= new (thd->mem_root)
Sql_cmd_show_slave_status(true)))
MYSQL_YYABORT;
}
| SLAVE STATUS_SYM
{
LEX *lex= thd->lex;
lex->mi.connection_name= null_clex_str;
lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
lex->verbose= 0;
if (!(lex->m_sql_cmd= new (thd->mem_root)
Sql_cmd_show_slave_status()))
MYSQL_YYABORT;
}
| SLAVE connection_name STATUS_SYM
{
Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
Lex->verbose= 0;
if (!(Lex->m_sql_cmd= new (thd->mem_root)
Sql_cmd_show_slave_status()))
MYSQL_YYABORT;
}
| CREATE PROCEDURE_SYM sp_name
{
......
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