summaryrefslogtreecommitdiff
path: root/sql/log.cc
diff options
context:
space:
mode:
authorunknown <serg@serg.mylan>2005-04-05 13:17:49 +0200
committerunknown <serg@serg.mylan>2005-04-05 13:17:49 +0200
commitcd0a50bf34477bf547cc4a66f0d5d9651574a65b (patch)
treea9dd96a05ad4e0e84d0b4f7711b882492d5ea59d /sql/log.cc
parent5dbcb1555fb63618be171b478a1af8a49b3b46ef (diff)
downloadmariadb-git-cd0a50bf34477bf547cc4a66f0d5d9651574a65b.tar.gz
remove the rest of isam/merge references
fix a race condition in TC_LOG_BINLOG::unlog include/Makefile.am: remove the rest of isam/merge references include/config-win.h: unused and abused macro removed include/my_pthread.h: unused and abused macro removed include/my_sys.h: MY_IGNORE_BADFD flag include/mysql_embed.h: remove the rest of isam/merge references mysql-test/r/replace.result: remove the rest of isam/merge references mysql-test/t/replace.test: remove the rest of isam/merge references mysql-test/t/xa.test: comment mysys/my_sync.c: MY_IGNORE_BADFD flag sql/handler.cc: remove the rest of isam/merge references sql/log.cc: fix a race condition in TC_LOG_BINLOG::unlog preparation for binlog group commit sql/mysql_priv.h: remove duplicates sql/mysqld.cc: remove the rest of isam/merge references sql/opt_range.cc: remove the rest of isam/merge references sql/set_var.cc: hide unused variables. simplify sync_binlog code sql/sql_base.cc: remove the rest of isam/merge references sql/sql_class.h: cleanup
Diffstat (limited to 'sql/log.cc')
-rw-r--r--sql/log.cc53
1 files changed, 29 insertions, 24 deletions
diff --git a/sql/log.cc b/sql/log.cc
index 9af70a4d527..1d6bb4cdf41 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -1531,18 +1531,20 @@ bool MYSQL_LOG::write(THD *thd,enum enum_server_command command,
return 0;
}
-
-inline bool sync_binlog(IO_CACHE *cache)
+bool MYSQL_LOG::flush_and_sync()
{
- if (sync_binlog_period == ++sync_binlog_counter && sync_binlog_period)
+ int err=0, fd=log_file.file;
+ safe_mutex_assert_owner(&LOCK_log);
+ if (flush_io_cache(&log_file))
+ return 1;
+ if (++sync_binlog_counter >= sync_binlog_period && sync_binlog_period)
{
sync_binlog_counter= 0;
- return my_sync(cache->file, MYF(MY_WME));
+ err=my_sync(fd, MYF(MY_WME));
}
- return 0;
+ return err;
}
-
/*
Write an event to the binary log
*/
@@ -1675,8 +1677,8 @@ bool MYSQL_LOG::write(Log_event *event_info)
}
}
- /*
- Write the SQL command
+ /*
+ Write the SQL command
*/
if (event_info->write(file))
@@ -1684,8 +1686,10 @@ bool MYSQL_LOG::write(Log_event *event_info)
if (file == &log_file) // we are writing to the real log (disk)
{
- if (flush_io_cache(file) || sync_binlog(file))
+ if (flush_and_sync())
goto err;
+ signal_update();
+ rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED);
}
error=0;
@@ -1698,15 +1702,9 @@ err:
my_error(ER_ERROR_ON_WRITE, MYF(0), name, errno);
write_error=1;
}
- if (file == &log_file)
- {
- signal_update();
- rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED);
- }
}
pthread_mutex_unlock(&LOCK_log);
-
DBUG_RETURN(error);
}
@@ -1813,7 +1811,7 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event)
if (commit_event->write(&log_file))
goto err;
DBUG_skip_commit:
- if (flush_io_cache(&log_file) || sync_binlog(&log_file))
+ if (flush_and_sync())
goto err;
DBUG_EXECUTE_IF("half_binlogged_transaction", abort(););
if (cache->error) // Error on read
@@ -1983,26 +1981,26 @@ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length,
SYNOPSIS
wait_for_update()
thd Thread variable
- master_or_slave If 0, the caller is the Binlog_dump thread from master;
+ is_slave If 0, the caller is the Binlog_dump thread from master;
if 1, the caller is the SQL thread from the slave. This
influences only thd->proc_info.
NOTES
One must have a lock on LOCK_log before calling this function.
- This lock will be freed before return! That's required by
+ This lock will be released before return! That's required by
THD::enter_cond() (see NOTES in sql_class.h).
*/
-void MYSQL_LOG::wait_for_update(THD* thd, bool master_or_slave)
+void MYSQL_LOG::wait_for_update(THD* thd, bool is_slave)
{
const char *old_msg;
DBUG_ENTER("wait_for_update");
old_msg= thd->enter_cond(&update_cond, &LOCK_log,
- master_or_slave ?
+ is_slave ?
"Has read all relay log; waiting for the slave I/O "
- "thread to update it" :
+ "thread to update it" :
"Has sent all binlog to slave; waiting for binlog "
- "to be updated");
+ "to be updated");
pthread_cond_wait(&update_cond, &LOCK_log);
thd->exit_cond(old_msg);
DBUG_VOID_RETURN;
@@ -2051,7 +2049,12 @@ void MYSQL_LOG::close(uint exiting)
my_pwrite(log_file.file, &flags, 1, offset, MYF(0));
}
- if (my_close(log_file.file,MYF(0)) < 0 && ! write_error)
+ if (my_sync(log_file.file,MYF(MY_WME)) && ! write_error)
+ {
+ write_error=1;
+ sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno);
+ }
+ if (my_close(log_file.file,MYF(MY_WME)) && ! write_error)
{
write_error=1;
sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno);
@@ -2945,8 +2948,10 @@ int TC_LOG_BINLOG::log(THD *thd, my_xid xid)
void TC_LOG_BINLOG::unlog(ulong cookie, my_xid xid)
{
- if (thread_safe_dec_and_test(prepared_xids, &LOCK_prep_xids))
+ pthread_mutex_lock(&LOCK_prep_xids);
+ if (--prepared_xids == 0)
pthread_cond_signal(&COND_prep_xids);
+ pthread_mutex_unlock(&LOCK_prep_xids);
rotate_and_purge(0); // as ::write() did not rotate
}