MDEV-34450 os_file_write_func() is an overkill for ib_logfile0

log_file_t::read(), log_file_t::write(): Invoke pread() or pwrite()
directly, so that we can give more accurate diagnostics in case of
a failure, and so that we will avoid the overhead of setting up 5(!)
stack frames and related objects.

tpool::pwrite(): Add a missing const qualifier.
This commit is contained in:
Marko Mäkelä 2024-09-30 13:36:38 +03:00
parent 2d3ddaef35
commit dd5ce6b0c4
3 changed files with 53 additions and 13 deletions

View file

@ -46,6 +46,7 @@ Created 12/9/1995 Heikki Tuuri
#include "buf0dump.h"
#include "log0sync.h"
#include "log.h"
#include "tpool.h"
/*
General philosophy of InnoDB redo-logs:
@ -132,18 +133,57 @@ __attribute__((warn_unused_result))
dberr_t log_file_t::read(os_offset_t offset, span<byte> buf) noexcept
{
ut_ad(is_opened());
return os_file_read(IORequestRead, m_file, buf.data(), offset, buf.size(),
nullptr);
byte *data= buf.data();
size_t size= buf.size();
ut_ad(size);
ssize_t s;
for (;;)
{
s= IF_WIN(tpool::pread(m_file, data, size, offset),
pread(m_file, data, size, offset));
if (UNIV_UNLIKELY(s <= 0))
break;
size-= size_t(s);
if (!size)
return DB_SUCCESS;
offset+= s;
data+= s;
ut_a(size < buf.size());
}
sql_print_error("InnoDB: pread(\"ib_logfile0\") returned %zd,"
" operating system error %u",
s, unsigned(IF_WIN(GetLastError(), errno)));
return DB_IO_ERROR;
}
void log_file_t::write(os_offset_t offset, span<const byte> buf) noexcept
{
ut_ad(is_opened());
if (dberr_t err= os_file_write_func(IORequestWrite, "ib_logfile0", m_file,
buf.data(), offset, buf.size()))
ib::fatal() << "write(\"ib_logfile0\") returned " << err
<< ". Operating system error number "
<< IF_WIN(GetLastError(), errno) << ".";
const byte *data= buf.data();
size_t size= buf.size();
ut_ad(size);
ssize_t s;
for (;;)
{
s= IF_WIN(tpool::pwrite(m_file, data, size, offset),
pwrite(m_file, data, size, offset));
if (UNIV_UNLIKELY(s <= 0))
break;
size-= size_t(s);
if (!size)
return;
offset+= s;
data+= s;
ut_a(size < buf.size());
}
sql_print_error("[FATAL] InnoDB: pwrite(\"ib_logfile0\") returned %zd,"
" operating system error %u",
s, unsigned(IF_WIN(GetLastError(), errno)));
abort();
}
#ifdef HAVE_INNODB_MMAP

View file

@ -73,7 +73,7 @@ static WinIoInit win_io_init;
SSIZE_T pread(const native_file_handle &h, void *buf, size_t count,
unsigned long long offset)
unsigned long long offset)
{
OVERLAPPED ov{};
ULARGE_INTEGER uli;
@ -95,8 +95,8 @@ SSIZE_T pread(const native_file_handle &h, void *buf, size_t count,
return -1;
}
SSIZE_T pwrite(const native_file_handle &h, void *buf, size_t count,
unsigned long long offset)
SSIZE_T pwrite(const native_file_handle &h, const void *buf, size_t count,
unsigned long long offset)
{
OVERLAPPED ov{};
ULARGE_INTEGER uli;

View file

@ -293,10 +293,10 @@ create_thread_pool_win(int min_threads= DEFAULT_MIN_POOL_THREADS,
opened with FILE_FLAG_OVERLAPPED, and bound to completion
port.
*/
SSIZE_T pwrite(const native_file_handle &h, void *buf, size_t count,
unsigned long long offset);
SSIZE_T pwrite(const native_file_handle &h, const void *buf, size_t count,
unsigned long long offset);
SSIZE_T pread(const native_file_handle &h, void *buf, size_t count,
unsigned long long offset);
unsigned long long offset);
HANDLE win_get_syncio_event();
#endif
} // namespace tpool