revision-id: c7be3f5df70af13069f677957953db509506c728 (mariadb-10.4.4-187-gc7be3f5df70) parent(s): e6297bbe376a687d3ab4771a5692a029f9507425 author: Sujatha committer: Sujatha timestamp: 2019-06-25 14:01:08 +0530 message: 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. --- sql/slave.cc | 37 +++++++++++++++++++++++++++++++++++++ sql/sql_cmd.h | 21 +++++++++++++++++++++ sql/sql_parse.cc | 26 +++++--------------------- sql/sql_prepare.cc | 23 ++++++++++++++++------- sql/sql_yacc.yy | 9 ++++++--- sql/sql_yacc_ora.yy | 9 ++++++--- 6 files changed, 91 insertions(+), 34 deletions(-) diff --git a/sql/slave.cc b/sql/slave.cc index a3776c0a580..e42b131ce4a 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1646,6 +1646,43 @@ 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; + Sql_cmd_show_slave_status *cmd; + cmd= dynamic_cast<Sql_cmd_show_slave_status*> (thd->lex->m_sql_cmd); + DBUG_ASSERT(cmd); + + /* Accept one of two privileges */ + if (check_global_access(thd, SUPER_ACL | REPL_CLIENT_ACL)) + goto error; + if (cmd->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) { diff --git a/sql/sql_cmd.h b/sql/sql_cmd.h index 7f1fd06aa46..2902da1c2e2 100644 --- a/sql/sql_cmd.h +++ b/sql/sql_cmd.h @@ -208,6 +208,27 @@ 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= 0; + } + + 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 { diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 54a41adbf68..d0d222b0d80 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4081,29 +4081,13 @@ mysql_execute_command(THD *thd) } 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(); - } - } + DBUG_ASSERT(lex->m_sql_cmd != NULL); + res= lex->m_sql_cmd->execute(thd); + DBUG_PRINT("result", ("res: %d killed: %d is_error: %d", + res, thd->killed, thd->is_error())); break; } + case SQLCOM_SHOW_MASTER_STAT: { /* Accept one of two privileges */ diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 68c9edc9283..ab90e16d903 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -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) { diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index d50f9722d7e..a749713d65b 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -14205,20 +14205,23 @@ show_param: } | ALL SLAVES STATUS_SYM { + if (!(Lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_show_slave_status(1))) + 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 { diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index 75c57111dc5..3143ca47e61 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -14329,19 +14329,22 @@ 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(1))) + 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 {