From 917b4fb0bf2b403ada21f7416ff147e8b3876537 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 11 Jul 2003 14:26:44 +0200 Subject: Fix for BUG#791: a safer way of initing the mutexes in MYSQL_LOG. is_open() is now always thread-safe. See each file for details. sql/handler.cc: is_open() with locks sql/item_func.cc: is_open() with locks sql/log.cc: No more 'inited'. We now always use is_open() in a thread-safe manner. This simplifies some functions (no more need to test is_open() twice). sql/log_event.cc: is_open() with locks sql/mysqld.cc: Init mutexes for the global MYSQL_LOG objects. We care about no_rotate, because we can't do it in open() anymore (because we don't have 'inited' anymore). sql/repl_failsafe.cc: is_open() with locks sql/slave.cc: init pthread objects (mutexes, conds) in the constructor of st_relay_log_info. Some better locking in rotate_relay_log(). sql/sql_base.cc: is_open() with locks sql/sql_class.h: Before, we inited LOCK_log in MYSQL_LOG::open(), so in other places of the code when we were never 100% sure that it had been inited. For example, if the server was running without --log-bin, ::open() was not called so the mutex was not inited. We could detect it with !inited, but not safely as 'inited' was not protected by any mutex. So now: we *always* init the LOCK_log mutex, even if the log is not used. We can't init the mutex in MYSQL_LOG's constructor, because for global objects like mysql_bin_log, mysql_log etc, the constructor is called before MY_INIT(), but safe_mutex depends on MY_INIT(). So we have a new function MYSQL_LOG::init_pthread_objects which we call in main(), after MY_INIT(). For the relay log, we call this function in the constructor of st_relay_log_info, which is called before any function tries to use the relay log (the relay log is always invoked as rli.relay_log). So now we should be safe in all cases and we don't need 'inited'. sql/sql_db.cc: is_open() with locks sql/sql_delete.cc: is_open() with locks sql/sql_insert.cc: is_open() with locks sql/sql_load.cc: is_open() with locks sql/sql_parse.cc: is_open() with locks sql/sql_rename.cc: is_open() with locks sql/sql_repl.cc: is_open() with locks sql/sql_table.cc: is_open() with locks sql/sql_update.cc: is_open() with locks --- sql/sql_insert.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 167ccf974c7..f94963f2570 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -308,7 +308,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List &fields, if ((info.copied || info.deleted) && (error <= 0 || !transactional_table)) { mysql_update_log.write(thd, thd->query, thd->query_length); - if (mysql_bin_log.is_open()) + if (mysql_bin_log.is_open(1)) { Query_log_event qinfo(thd, thd->query, thd->query_length, log_delayed); @@ -1143,7 +1143,7 @@ bool delayed_insert::handle_inserts(void) { int error; uint max_rows; - bool using_ignore=0, using_bin_log=mysql_bin_log.is_open(); + bool using_ignore=0, using_bin_log=mysql_bin_log.is_open(1); delayed_row *row; DBUG_ENTER("handle_inserts"); @@ -1361,7 +1361,7 @@ void select_insert::send_error(uint errcode,const char *err) if (last_insert_id) thd->insert_id(last_insert_id); // For binary log mysql_update_log.write(thd,thd->query,thd->query_length); - if (mysql_bin_log.is_open()) + if (mysql_bin_log.is_open(1)) { Query_log_event qinfo(thd, thd->query, thd->query_length, table->file->has_transactions()); @@ -1387,7 +1387,7 @@ bool select_insert::send_eof() thd->insert_id(last_insert_id); // For binary log /* Write to binlog before commiting transaction */ mysql_update_log.write(thd,thd->query,thd->query_length); - if (mysql_bin_log.is_open()) + if (mysql_bin_log.is_open(1)) { Query_log_event qinfo(thd, thd->query, thd->query_length, table->file->has_transactions()); -- cgit v1.2.1