Commit 6f2e2285 authored by Eugene Kosov's avatar Eugene Kosov

MDEV-21382 use fdatasync() for redo log where appropriate

log_t::files::fdatasync(): syncs only data for every log file

os_file_flush_data()
pfs_os_file_flush_data_func(): syncs only data for a given file
parent d9789718
......@@ -18632,7 +18632,7 @@ checkpoint_now_set(THD*, st_mysql_sys_var*, void*, const void* save)
? log_sys.append_on_checkpoint->size() : 0)
< log_sys.lsn) {
log_make_checkpoint();
log_sys.log.fsync();
log_sys.log.fdatasync();
}
dberr_t err = fil_write_flushed_lsn(log_sys.lsn);
......
......@@ -565,6 +565,8 @@ struct log_t{
void write(size_t total_offset, span<byte> buf);
/** flushes OS page cache for all log files */
void fsync();
/** flushes OS page cache (excluding metadata!) for all log files */
void fdatasync();
/** closes all log files */
void close_files();
......
......@@ -787,6 +787,9 @@ The wrapper functions have the prefix of "innodb_". */
# define os_file_flush(file) \
pfs_os_file_flush_func(file, __FILE__, __LINE__)
#define os_file_flush_data(file) \
pfs_os_file_flush_data_func(file, __FILE__, __LINE__)
# define os_file_rename(key, oldpath, newpath) \
pfs_os_file_rename_func(key, oldpath, newpath, __FILE__, __LINE__)
......@@ -1032,6 +1035,18 @@ pfs_os_file_flush_func(
const char* src_file,
uint src_line);
/** NOTE! Please use the corresponding macro os_file_flush_data(), not directly
this function!
This is the performance schema instrumented wrapper function for
os_file_flush_data() which flushes only(!) data (excluding metadata) from OS
page cache of a given file to the disk.
@param[in] file Open file handle
@param[in] src_file file name where func invoked
@param[in] src_line line where the func invoked
@return true if success */
bool pfs_os_file_flush_data_func(pfs_os_file_t file, const char *src_file,
uint src_line);
/** NOTE! Please use the corresponding macro os_file_rename(), not directly
this function!
This is the performance schema instrumented wrapper function for
......
......@@ -659,6 +659,23 @@ void log_t::files::fsync()
log_sys.flushes.fetch_add(1, std::memory_order_release);
}
void log_t::files::fdatasync()
{
ut_ad(files.size() == file_names.size());
log_sys.pending_flushes.fetch_add(1, std::memory_order_acquire);
for (auto it= files.begin(), end= files.end(); it != end; ++it)
{
if (!os_file_flush_data(*it))
{
const auto idx= std::distance(files.begin(), it);
ib::fatal() << "os_file_flush_data(" << file_names[idx] << ") failed";
}
}
log_sys.pending_flushes.fetch_add(1, std::memory_order_release);
log_sys.flushes.fetch_add(1, std::memory_order_release);
}
void log_t::files::close_files()
{
for (auto it= files.begin(), end= files.end(); it != end; ++it)
......@@ -864,7 +881,7 @@ log_write_flush_to_disk_low()
calling os_event_set()! */
ut_a(log_sys.n_pending_flushes == 1); /* No other threads here */
log_sys.log.fsync();
log_sys.log.fdatasync();
log_mutex_enter();
log_sys.flushed_to_disk_lsn = log_sys.current_flush_lsn;
......@@ -1298,7 +1315,7 @@ void log_write_checkpoint_info(lsn_t end_lsn)
: LOG_CHECKPOINT_1,
{buf, OS_FILE_LOG_BLOCK_SIZE});
log_sys.log.fsync();
log_sys.log.fdatasync();
log_mutex_enter();
......@@ -1776,7 +1793,7 @@ logs_empty_and_mark_files_at_shutdown(void)
/* Ensure that all buffered changes are written to the
redo log before fil_close_all_files(). */
log_sys.log.fsync();
log_sys.log.fdatasync();
} else {
lsn = srv_start_lsn;
}
......
......@@ -4614,3 +4614,24 @@ os_normalize_path(
}
}
}
bool pfs_os_file_flush_data_func(pfs_os_file_t file, const char *src_file,
uint src_line)
{
PSI_file_locker_state state;
struct PSI_file_locker *locker= NULL;
register_pfs_file_io_begin(&state, locker, file, 0, PSI_FILE_SYNC, src_file,
src_line);
#ifdef _WIN32
bool result= os_file_flush_func(file);
#else
bool result= true;
if (fdatasync(file) == -1)
ib::error() << "fdatasync() errno: " << errno;
#endif
register_pfs_file_io_end(locker, 0);
return result;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment