Commit dd5ce6b0 authored by Marko Mäkelä's avatar Marko Mäkelä

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.
parent 2d3ddaef
...@@ -46,6 +46,7 @@ Created 12/9/1995 Heikki Tuuri ...@@ -46,6 +46,7 @@ Created 12/9/1995 Heikki Tuuri
#include "buf0dump.h" #include "buf0dump.h"
#include "log0sync.h" #include "log0sync.h"
#include "log.h" #include "log.h"
#include "tpool.h"
/* /*
General philosophy of InnoDB redo-logs: General philosophy of InnoDB redo-logs:
...@@ -132,18 +133,57 @@ __attribute__((warn_unused_result)) ...@@ -132,18 +133,57 @@ __attribute__((warn_unused_result))
dberr_t log_file_t::read(os_offset_t offset, span<byte> buf) noexcept dberr_t log_file_t::read(os_offset_t offset, span<byte> buf) noexcept
{ {
ut_ad(is_opened()); ut_ad(is_opened());
return os_file_read(IORequestRead, m_file, buf.data(), offset, buf.size(), byte *data= buf.data();
nullptr); 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 void log_file_t::write(os_offset_t offset, span<const byte> buf) noexcept
{ {
ut_ad(is_opened()); ut_ad(is_opened());
if (dberr_t err= os_file_write_func(IORequestWrite, "ib_logfile0", m_file, const byte *data= buf.data();
buf.data(), offset, buf.size())) size_t size= buf.size();
ib::fatal() << "write(\"ib_logfile0\") returned " << err ut_ad(size);
<< ". Operating system error number " ssize_t s;
<< IF_WIN(GetLastError(), errno) << ".";
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 #ifdef HAVE_INNODB_MMAP
......
...@@ -73,7 +73,7 @@ static WinIoInit win_io_init; ...@@ -73,7 +73,7 @@ static WinIoInit win_io_init;
SSIZE_T pread(const native_file_handle &h, void *buf, size_t count, SSIZE_T pread(const native_file_handle &h, void *buf, size_t count,
unsigned long long offset) unsigned long long offset)
{ {
OVERLAPPED ov{}; OVERLAPPED ov{};
ULARGE_INTEGER uli; ULARGE_INTEGER uli;
...@@ -95,8 +95,8 @@ SSIZE_T pread(const native_file_handle &h, void *buf, size_t count, ...@@ -95,8 +95,8 @@ SSIZE_T pread(const native_file_handle &h, void *buf, size_t count,
return -1; return -1;
} }
SSIZE_T pwrite(const native_file_handle &h, void *buf, size_t count, SSIZE_T pwrite(const native_file_handle &h, const void *buf, size_t count,
unsigned long long offset) unsigned long long offset)
{ {
OVERLAPPED ov{}; OVERLAPPED ov{};
ULARGE_INTEGER uli; ULARGE_INTEGER uli;
......
...@@ -293,10 +293,10 @@ create_thread_pool_win(int min_threads= DEFAULT_MIN_POOL_THREADS, ...@@ -293,10 +293,10 @@ create_thread_pool_win(int min_threads= DEFAULT_MIN_POOL_THREADS,
opened with FILE_FLAG_OVERLAPPED, and bound to completion opened with FILE_FLAG_OVERLAPPED, and bound to completion
port. port.
*/ */
SSIZE_T pwrite(const native_file_handle &h, void *buf, size_t count, SSIZE_T pwrite(const native_file_handle &h, const void *buf, size_t count,
unsigned long long offset); unsigned long long offset);
SSIZE_T pread(const native_file_handle &h, void *buf, size_t count, 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(); HANDLE win_get_syncio_event();
#endif #endif
} // namespace tpool } // namespace tpool
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