Skip to content

Commit

Permalink
MDEV-21382 use fdatasync() for redo log where appropriate
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kevgs committed Jan 5, 2020
1 parent d978971 commit 6f2e228
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
2 changes: 1 addition & 1 deletion storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions storage/innobase/include/log0log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
15 changes: 15 additions & 0 deletions storage/innobase/include/os0file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand Down
23 changes: 20 additions & 3 deletions storage/innobase/log/log0log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
Expand Down
21 changes: 21 additions & 0 deletions storage/innobase/os/os0file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 6f2e228

Please sign in to comment.