diff options
author | Andrei <andrei.elkin@mariadb.com> | 2021-12-08 14:36:11 +0200 |
---|---|---|
committer | Andrei <andrei.elkin@mariadb.com> | 2021-12-15 22:44:23 +0200 |
commit | 4bcd709d79a74cce3f2dc638f67eb6da1f0e20d8 (patch) | |
tree | 5c4b8b0b0775fb537d850c307ed9060290013487 | |
parent | eb8bd2b16de07bc43d65b6b2db8aaca3783c836b (diff) | |
download | mariadb-git-4bcd709d79a74cce3f2dc638f67eb6da1f0e20d8.tar.gz |
MDEV-11675. Cleanup around mysql_client_binlog_statement to simplify
logics as well as optimize memory usage.
-rw-r--r-- | sql/log.cc | 11 | ||||
-rw-r--r-- | sql/log_event_server.cc | 2 | ||||
-rw-r--r-- | sql/sql_binlog.cc | 103 |
3 files changed, 75 insertions, 41 deletions
diff --git a/sql/log.cc b/sql/log.cc index 9c8c62301ae..628d1c8a1d9 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -586,7 +586,16 @@ private: binlog_cache_mngr(const binlog_cache_mngr& info); }; -// TODO: rename and add header +/** + The function handles the first phase of two-phase binlogged ALTER. + On master binlogs START ALTER when that is configured to do so. + On slave START ALTER gets binlogged and its gtid committed into gtid slave pos + table. + + @return false on success, true on failure + @return @c partial_alter set to @c true when START ALTER phase + has been completed +*/ bool write_bin_log_start_alter(THD *thd, bool& partial_alter, uint64 start_alter_id, bool if_exists, MEM_ROOT *mem) diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index c73656571e3..04f43265647 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -1962,7 +1962,7 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi, if (charset_inited) { rpl_sql_thread_info *sql_info= thd->system_thread_info.rpl_sql_info; - if (sql_info->cached_charset_compare(charset)) + if (thd->slave_thread && sql_info->cached_charset_compare(charset)) { /* Verify that we support the charsets found in the event. */ if (!(thd->variables.character_set_client= diff --git a/sql/sql_binlog.cc b/sql/sql_binlog.cc index 74d2bba39f8..b784fccd318 100644 --- a/sql/sql_binlog.cc +++ b/sql/sql_binlog.cc @@ -169,6 +169,66 @@ int binlog_defragment(THD *thd) return 0; } +/** + Wraps Log_event::apply_event to save and restore + session context in case of Query_log_event. + + @return + 0 on success, + non-zero otherwise. +*/ +#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +int save_restore_context_apply_event(Log_event *ev, rpl_group_info *rgi) +{ + int err= 0; + THD *thd= rgi->thd; + Relay_log_info *rli= thd->rli_fake; + sql_digest_state *m_digest; + PSI_statement_locker *m_statement_psi; + LEX_CSTRING save_db; + my_thread_id m_thread_id= 0; + LEX_CSTRING connection_name= { STRING_WITH_LEN("BINLOG_BASE64_EVENT") }; + + DBUG_ASSERT(!rli->mi); + + if (ev->get_type_code() == QUERY_EVENT) + { + m_digest= thd->m_digest; + m_statement_psi= thd->m_statement_psi; + m_thread_id= thd->variables.pseudo_thread_id; + thd->system_thread_info.rpl_sql_info= NULL; + + if ((rli->mi= new Master_info(&connection_name, false))) + { + save_db= thd->db; + thd->reset_db(&null_clex_str); + } + else + { + my_error(ER_OUT_OF_RESOURCES, MYF(0)); + err= -1; + goto end; + } + thd->m_digest= NULL; + thd->m_statement_psi= NULL; + } + + err= ev->apply_event(rgi); + +end: + if (ev->get_type_code() == QUERY_EVENT) + { + thd->m_digest= m_digest; + thd->m_statement_psi= m_statement_psi; + thd->variables.pseudo_thread_id= m_thread_id; + thd->reset_db(&save_db); + delete rli->mi; + rli->mi= NULL; + } + + return err; +} +#endif /** Execute a BINLOG statement. @@ -215,23 +275,12 @@ void mysql_client_binlog_statement(THD* thd) rli= thd->rli_fake; if (!rli && (rli= thd->rli_fake= new Relay_log_info(FALSE, "BINLOG_BASE64_EVENT"))) rli->sql_driver_thd= thd; - //static LEX_CSTRING connection_name= { STRING_WITH_LEN("BINLOG_BASE64_EVENT") }; - //rli->mi= new Master_info(&connection_name, false); if (!(rgi= thd->rgi_fake)) rgi= thd->rgi_fake= new rpl_group_info(rli); rgi->thd= thd; - thd->system_thread_info.rpl_sql_info= - //new rpl_sql_thread_info(rli->mi->rpl_filter); - new rpl_sql_thread_info(NULL); const char *error= 0; Log_event *ev = 0; my_bool is_fragmented= FALSE; -#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) - sql_digest_state *m_digest; - PSI_statement_locker *m_statement_psi; - LEX_CSTRING save_db; - my_thread_id thread_id= 0; -#endif /* Out of memory check */ @@ -384,30 +433,7 @@ void mysql_client_binlog_statement(THD* thd) LEX *backup_lex; thd->backup_and_reset_current_lex(&backup_lex); - if (ev->get_type_code() == QUERY_EVENT) - { - m_digest= thd->m_digest; - m_statement_psi= thd->m_statement_psi; - save_db.str= my_strndup(key_memory_THD_db, thd->db.str, - thd->db.length, MYF(MY_WME)); - save_db.length= thd->db.length; - if (save_db.str == NULL) - { - my_error(ER_OUT_OF_RESOURCES, MYF(0)); - goto end; - } - thd->m_digest= NULL; - thd->m_statement_psi= NULL; - thread_id= thd->variables.pseudo_thread_id; - } - err= ev->apply_event(rgi); - if (ev->get_type_code() == QUERY_EVENT) - { - thd->m_digest= m_digest; - thd->m_statement_psi= m_statement_psi; - thd->reset_db(&save_db); - thd->variables.pseudo_thread_id= thread_id; - } + err= save_restore_context_apply_event(ev, rgi); thd->restore_current_lex(backup_lex); } thd->variables.option_bits= @@ -423,7 +449,7 @@ void mysql_client_binlog_statement(THD* thd) i.e. when this thread terminates. */ if (ev->get_type_code() != FORMAT_DESCRIPTION_EVENT) - delete ev; + delete ev; ev= 0; if (err) { @@ -431,7 +457,8 @@ void mysql_client_binlog_statement(THD* thd) TODO: Maybe a better error message since the BINLOG statement now contains several events. */ - my_error(ER_UNKNOWN_ERROR, MYF(0)); + if (!thd->is_error()) + my_error(ER_UNKNOWN_ERROR, MYF(0)); goto end; } } @@ -447,8 +474,6 @@ end: thd->variables.option_bits= thd_options; rgi->slave_close_thread_tables(thd); my_free(buf); - //delete rli->mi; - delete thd->system_thread_info.rpl_sql_info; delete rgi; rgi= thd->rgi_fake= NULL; DBUG_VOID_RETURN; |