relay log 在执行after_append_to_relay_log 的时候调用了flush_and_sync 进行flush 和sync
bool MYSQL_BIN_LOG::flush_and_sync(const bool force)
{
mysql_mutex_assert_owner(&LOCK_log);
if (flush_io_cache(&log_file))
return 1;
std::pair<bool, bool> result= sync_binlog_file(force);
return result.first;
}
看sync_binlog_file 这个函数,有个技术器,没有达到设置的值,是不会sync文件的。
MYSQL_BIN_LOG::sync_binlog_file(bool force)
{
bool synced= false;
unsigned int sync_period= get_sync_period();
if (force || (sync_period && ++sync_counter >= sync_period))
{
sync_counter= 0;
/**
On *pure non-transactional* workloads there is a small window
in time where a concurrent rotate might be able to close
the file before the sync is actually done. In that case,
ignore the bad file descriptor errors.
Transactional workloads (InnoDB) are not affected since the
the rotation will not happen until all transactions have
committed to the storage engine, thence decreased the XID
counters.
TODO: fix this properly even for non-transactional storage
engines.
*/
if (DBUG_EVALUATE_IF("simulate_error_during_sync_binlog_file", 1,
mysql_file_sync(log_file.file,
MYF(MY_WME | MY_IGNORE_BADFD))))
{
THD *thd= current_thd;
thd->commit_error= THD::CE_SYNC_ERROR;
return std::make_pair(true, synced);
}
synced= true;
}
return std::make_pair(false, synced);
}
也就是说在after sync 的设置下,sync_relay_log > 1的情况下,不会等到全部的relay log全部都sync就会返回ack,这种情况下如果从库挂了,就会丢数据。