summaryrefslogtreecommitdiff
path: root/sql/log.cc
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2005-02-21 14:47:57 +0200
committerunknown <monty@mysql.com>2005-02-21 14:47:57 +0200
commitd50af8aece334add754acc08b0231dd7ef9503f5 (patch)
treea17a3f036e3a27e1c193e1d849ad788042a32f8c /sql/log.cc
parentda4604f9e8fa42c8e7c5627b692e0ac6d5409802 (diff)
downloadmariadb-git-d50af8aece334add754acc08b0231dd7ef9503f5.tar.gz
Review of new pushed code (XA & other)
Portability fixes and cleanups Fixed setting of 'res' in mysql_execute_command() sql/handler.cc: delete_table() will not return error for not found files if one handler file was found and deleted sql/handler.h: Incremented MAX_HA so that ndb works again Don't convert char pointer to (my_xid*) as we don't know if the address is aligned on 8 sql/log.cc: Indentation fixes Simplified loop to find next log Fixed race condition in reset_logs that caused mix_innodb_myisam_binlog to fail sql/log_event.cc: Don't convert char pointer to (my_xid*) as we don't know if the address is aligned on 8 sql/sql_acl.cc: Convert db name directly to avoid extra strmov sql/sql_base.cc: Added comment Removed not needed code sql/sql_db.cc: Added comment Remove not needed code sql/sql_parse.cc: Always call mysql_rm_db() with lower case db name Ensure that 'res' is set correctly in mysql_execute_command() (One don't have to set res if one calls my_error() and res should be = 0 for correct commands) sql/sql_repl.cc: Indentation fixes use packet->ptr() instead of packet->c_ptr() sql/sql_table.cc: Join similar code when table didn't exist in engine
Diffstat (limited to 'sql/log.cc')
-rw-r--r--sql/log.cc72
1 files changed, 41 insertions, 31 deletions
diff --git a/sql/log.cc b/sql/log.cc
index cb776cff0e9..ee5ded42309 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -135,10 +135,10 @@ static int binlog_rollback(THD *thd, bool all)
*/
DBUG_ASSERT(all && mysql_bin_log.is_open() && my_b_tell(trans_log));
/*
- Update the binary log with a BEGIN/ROLLBACK block if we have
- cached some queries and we updated some non-transactional
- table. Such cases should be rare (updating a
- non-transactional table inside a transaction...)
+ Update the binary log with a BEGIN/ROLLBACK block if we have
+ cached some queries and we updated some non-transactional
+ table. Such cases should be rare (updating a
+ non-transactional table inside a transaction...)
*/
if (unlikely(thd->options & OPTION_STATUS_NO_TRANS_UPDATE))
{
@@ -919,6 +919,13 @@ bool MYSQL_LOG::reset_logs(THD* thd)
*/
pthread_mutex_lock(&LOCK_log);
pthread_mutex_lock(&LOCK_index);
+ /*
+ The following mutex is needed to ensure that no threads call
+ 'delete thd' as we would then risk missing a 'rollback' from this
+ thread. If the transaction involved MyISAM tables, it should go
+ into binlog even on rollback.
+ */
+ (void) pthread_mutex_lock(&LOCK_thread_count);
/* Save variables so that we can reopen the log */
save_name=name;
@@ -952,6 +959,7 @@ bool MYSQL_LOG::reset_logs(THD* thd)
my_free((gptr) save_name, MYF(0));
err:
+ (void) pthread_mutex_unlock(&LOCK_thread_count);
pthread_mutex_unlock(&LOCK_index);
pthread_mutex_unlock(&LOCK_log);
DBUG_RETURN(error);
@@ -1600,7 +1608,8 @@ bool MYSQL_LOG::write(Log_event* event_info)
{
thd->ha_data[binlog_hton.slot]= trans_log= (IO_CACHE *)
my_malloc(sizeof(IO_CACHE), MYF(MY_ZEROFILL));
- if (!trans_log || open_cached_file(trans_log, mysql_tmpdir, LOG_PREFIX,
+ if (!trans_log || open_cached_file(trans_log, mysql_tmpdir,
+ LOG_PREFIX,
binlog_cache_size, MYF(MY_WME)))
{
my_free((gptr)trans_log, MYF(MY_ALLOW_ZERO_PTR));
@@ -1609,13 +1618,15 @@ bool MYSQL_LOG::write(Log_event* event_info)
}
trans_log->end_of_file= max_binlog_cache_size;
trans_register_ha(thd,
- thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN),
- &binlog_hton);
+ thd->options & (OPTION_NOT_AUTOCOMMIT |
+ OPTION_BEGIN),
+ &binlog_hton);
}
else if (!my_b_tell(trans_log))
trans_register_ha(thd,
- thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN),
- &binlog_hton);
+ thd->options & (OPTION_NOT_AUTOCOMMIT |
+ OPTION_BEGIN),
+ &binlog_hton);
file= trans_log;
}
else if (trans_log && my_b_tell(trans_log))
@@ -1630,8 +1641,8 @@ bool MYSQL_LOG::write(Log_event* event_info)
*/
/*
- 1. Write first log events which describe the 'run environment'
- of the SQL command
+ 1. Write first log events which describe the 'run environment'
+ of the SQL command
*/
if (thd)
@@ -1655,12 +1666,12 @@ bool MYSQL_LOG::write(Log_event* event_info)
{
char buf[200];
int written= my_snprintf(buf, sizeof(buf)-1,
- "SET ONE_SHOT CHARACTER_SET_CLIENT=%u,\
+ "SET ONE_SHOT CHARACTER_SET_CLIENT=%u,\
COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u",
- (uint) thd->variables.character_set_client->number,
- (uint) thd->variables.collation_connection->number,
- (uint) thd->variables.collation_database->number,
- (uint) thd->variables.collation_server->number);
+ (uint) thd->variables.character_set_client->number,
+ (uint) thd->variables.collation_connection->number,
+ (uint) thd->variables.collation_database->number,
+ (uint) thd->variables.collation_server->number);
Query_log_event e(thd, buf, written, 0, FALSE);
if (e.write(file))
goto err;
@@ -1803,9 +1814,9 @@ uint MYSQL_LOG::next_file_id()
IMPLEMENTATION
- To support transaction over replication, we wrap the transaction
with BEGIN/COMMIT or BEGIN/ROLLBACK in the binary log.
- We want to write a BEGIN/ROLLBACK block when a non-transactional table was
- updated in a transaction which was rolled back. This is to ensure that the
- same updates are run on the slave.
+ We want to write a BEGIN/ROLLBACK block when a non-transactional table
+ was updated in a transaction which was rolled back. This is to ensure
+ that the same updates are run on the slave.
*/
bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache)
@@ -2481,15 +2492,13 @@ int TC_LOG_MMAP::open(const char *opt_name)
#endif
fn_format(logname,opt_name,mysql_data_home,"",MY_UNPACK_FILENAME);
- fd= my_open(logname, O_RDWR, MYF(0));
- if (fd == -1)
+ if ((fd= my_open(logname, O_RDWR, MYF(0))) < 0)
{
if (my_errno != ENOENT)
goto err;
if (using_heuristic_recover())
return 1;
- fd= my_create(logname, O_RDWR, 0, MYF(MY_WME));
- if (fd == -1)
+ if ((fd= my_create(logname, O_RDWR, 0, MYF(MY_WME))) < 0)
goto err;
inited=1;
file_length= opt_tc_log_size;
@@ -2827,7 +2836,7 @@ int TC_LOG_MMAP::recover()
*/
if (data[sizeof(tc_log_magic)] != total_ha_2pc)
{
- sql_print_error("Recovery failed! You must have enabled "
+ sql_print_error("Recovery failed! You must enable "
"exactly %d storage engines that support "
"two-phase commit protocol",
data[sizeof(tc_log_magic)]);
@@ -2931,14 +2940,15 @@ int TC_LOG_BINLOG::open(const char *opt_name)
if (! fdle.is_valid())
goto err;
- for (error= 0; !error ;)
+ do
{
- strnmov(log_name, log_info.log_file_name, sizeof(log_name));
- if ((error= find_next_log(&log_info, 1)) != LOG_INFO_EOF)
- {
- sql_print_error("find_log_pos() failed (error: %d)", error);
- goto err;
- }
+ strmake(log_name, log_info.log_file_name, sizeof(log_name)-1);
+ } while (!(error= find_next_log(&log_info, 1)));
+
+ if (error != LOG_INFO_EOF)
+ {
+ sql_print_error("find_log_pos() failed (error: %d)", error);
+ goto err;
}
if ((file= open_binlog(&log, log_name, &errmsg)) < 0)