mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
BUG#35542 Add option to sync master and relay log to disk after every event
BUG#31665 sync_binlog should cause relay logs to be synchronized NOTE: Backporting the patch to next-mr. Add sync_relay_log option to server, this option works for relay log the same as option sync_binlog for binlog. This option also synchronize master info to disk when set to non-zero value. Original patches from Sinisa and Mark, with some modifications
This commit is contained in:
35
sql/log.cc
35
sql/log.cc
@ -49,8 +49,7 @@
|
||||
|
||||
LOGGER logger;
|
||||
|
||||
MYSQL_BIN_LOG mysql_bin_log;
|
||||
ulong sync_binlog_counter= 0;
|
||||
MYSQL_BIN_LOG mysql_bin_log(&sync_binlog_period);
|
||||
|
||||
static bool test_if_number(const char *str,
|
||||
long *res, bool allow_wildcards);
|
||||
@ -2410,9 +2409,10 @@ const char *MYSQL_LOG::generate_name(const char *log_name,
|
||||
|
||||
|
||||
|
||||
MYSQL_BIN_LOG::MYSQL_BIN_LOG()
|
||||
MYSQL_BIN_LOG::MYSQL_BIN_LOG(uint *sync_period)
|
||||
:bytes_written(0), prepared_xids(0), file_id(1), open_count(1),
|
||||
need_start_event(TRUE), m_table_map_version(0),
|
||||
sync_period_ptr(sync_period),
|
||||
is_relay_log(0),
|
||||
description_event_for_exec(0), description_event_for_queue(0)
|
||||
{
|
||||
@ -3643,6 +3643,8 @@ bool MYSQL_BIN_LOG::append(Log_event* ev)
|
||||
}
|
||||
bytes_written+= ev->data_written;
|
||||
DBUG_PRINT("info",("max_size: %lu",max_size));
|
||||
if (flush_and_sync(0))
|
||||
goto err;
|
||||
if ((uint) my_b_append_tell(&log_file) > max_size)
|
||||
new_file_without_locking();
|
||||
|
||||
@ -3673,6 +3675,8 @@ bool MYSQL_BIN_LOG::appendv(const char* buf, uint len,...)
|
||||
bytes_written += len;
|
||||
} while ((buf=va_arg(args,const char*)) && (len=va_arg(args,uint)));
|
||||
DBUG_PRINT("info",("max_size: %lu",max_size));
|
||||
if (flush_and_sync(0))
|
||||
goto err;
|
||||
if ((uint) my_b_append_tell(&log_file) > max_size)
|
||||
new_file_without_locking();
|
||||
|
||||
@ -3682,17 +3686,21 @@ err:
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
|
||||
|
||||
bool MYSQL_BIN_LOG::flush_and_sync()
|
||||
bool MYSQL_BIN_LOG::flush_and_sync(bool *synced)
|
||||
{
|
||||
int err=0, fd=log_file.file;
|
||||
if (synced)
|
||||
*synced= 0;
|
||||
safe_mutex_assert_owner(&LOCK_log);
|
||||
if (flush_io_cache(&log_file))
|
||||
return 1;
|
||||
if (++sync_binlog_counter >= sync_binlog_period && sync_binlog_period)
|
||||
uint sync_period= get_sync_period();
|
||||
if (sync_period && ++sync_counter >= sync_period)
|
||||
{
|
||||
sync_binlog_counter= 0;
|
||||
sync_counter= 0;
|
||||
err=my_sync(fd, MYF(MY_WME));
|
||||
if (synced)
|
||||
*synced= 1;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
@ -3983,7 +3991,7 @@ MYSQL_BIN_LOG::flush_and_set_pending_rows_event(THD *thd,
|
||||
|
||||
if (file == &log_file)
|
||||
{
|
||||
error= flush_and_sync();
|
||||
error= flush_and_sync(0);
|
||||
if (!error)
|
||||
{
|
||||
signal_update();
|
||||
@ -4169,7 +4177,8 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info)
|
||||
|
||||
if (file == &log_file) // we are writing to the real log (disk)
|
||||
{
|
||||
if (flush_and_sync())
|
||||
bool synced;
|
||||
if (flush_and_sync(&synced))
|
||||
goto err;
|
||||
signal_update();
|
||||
rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED);
|
||||
@ -4425,7 +4434,7 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log)
|
||||
DBUG_ASSERT(carry == 0);
|
||||
|
||||
if (sync_log)
|
||||
flush_and_sync();
|
||||
return flush_and_sync(0);
|
||||
|
||||
return 0; // All OK
|
||||
}
|
||||
@ -4472,7 +4481,8 @@ bool MYSQL_BIN_LOG::write_incident(THD *thd, bool lock)
|
||||
ev.write(&log_file);
|
||||
if (lock)
|
||||
{
|
||||
if (!error && !(error= flush_and_sync()))
|
||||
bool synced;
|
||||
if (!error && !(error= flush_and_sync(&synced)))
|
||||
{
|
||||
signal_update();
|
||||
rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED);
|
||||
@ -4560,7 +4570,8 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event,
|
||||
if (incident && write_incident(thd, FALSE))
|
||||
goto err;
|
||||
|
||||
if (flush_and_sync())
|
||||
bool synced;
|
||||
if (flush_and_sync(&synced))
|
||||
goto err;
|
||||
DBUG_EXECUTE_IF("half_binlogged_transaction", abort(););
|
||||
if (cache->error) // Error on read
|
||||
|
Reference in New Issue
Block a user