Skip to content

Commit dd5ce6b

Browse files
committed
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.
1 parent 2d3ddae commit dd5ce6b

File tree

3 files changed

+53
-13
lines changed

3 files changed

+53
-13
lines changed

storage/innobase/log/log0log.cc

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Created 12/9/1995 Heikki Tuuri
4646
#include "buf0dump.h"
4747
#include "log0sync.h"
4848
#include "log.h"
49+
#include "tpool.h"
4950

5051
/*
5152
General philosophy of InnoDB redo-logs:
@@ -132,18 +133,57 @@ __attribute__((warn_unused_result))
132133
dberr_t log_file_t::read(os_offset_t offset, span<byte> buf) noexcept
133134
{
134135
ut_ad(is_opened());
135-
return os_file_read(IORequestRead, m_file, buf.data(), offset, buf.size(),
136-
nullptr);
136+
byte *data= buf.data();
137+
size_t size= buf.size();
138+
ut_ad(size);
139+
ssize_t s;
140+
141+
for (;;)
142+
{
143+
s= IF_WIN(tpool::pread(m_file, data, size, offset),
144+
pread(m_file, data, size, offset));
145+
if (UNIV_UNLIKELY(s <= 0))
146+
break;
147+
size-= size_t(s);
148+
if (!size)
149+
return DB_SUCCESS;
150+
offset+= s;
151+
data+= s;
152+
ut_a(size < buf.size());
153+
}
154+
155+
sql_print_error("InnoDB: pread(\"ib_logfile0\") returned %zd,"
156+
" operating system error %u",
157+
s, unsigned(IF_WIN(GetLastError(), errno)));
158+
return DB_IO_ERROR;
137159
}
138160

139161
void log_file_t::write(os_offset_t offset, span<const byte> buf) noexcept
140162
{
141163
ut_ad(is_opened());
142-
if (dberr_t err= os_file_write_func(IORequestWrite, "ib_logfile0", m_file,
143-
buf.data(), offset, buf.size()))
144-
ib::fatal() << "write(\"ib_logfile0\") returned " << err
145-
<< ". Operating system error number "
146-
<< IF_WIN(GetLastError(), errno) << ".";
164+
const byte *data= buf.data();
165+
size_t size= buf.size();
166+
ut_ad(size);
167+
ssize_t s;
168+
169+
for (;;)
170+
{
171+
s= IF_WIN(tpool::pwrite(m_file, data, size, offset),
172+
pwrite(m_file, data, size, offset));
173+
if (UNIV_UNLIKELY(s <= 0))
174+
break;
175+
size-= size_t(s);
176+
if (!size)
177+
return;
178+
offset+= s;
179+
data+= s;
180+
ut_a(size < buf.size());
181+
}
182+
183+
sql_print_error("[FATAL] InnoDB: pwrite(\"ib_logfile0\") returned %zd,"
184+
" operating system error %u",
185+
s, unsigned(IF_WIN(GetLastError(), errno)));
186+
abort();
147187
}
148188

149189
#ifdef HAVE_INNODB_MMAP

tpool/aio_simulated.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static WinIoInit win_io_init;
7373

7474

7575
SSIZE_T pread(const native_file_handle &h, void *buf, size_t count,
76-
unsigned long long offset)
76+
unsigned long long offset)
7777
{
7878
OVERLAPPED ov{};
7979
ULARGE_INTEGER uli;
@@ -95,8 +95,8 @@ SSIZE_T pread(const native_file_handle &h, void *buf, size_t count,
9595
return -1;
9696
}
9797

98-
SSIZE_T pwrite(const native_file_handle &h, void *buf, size_t count,
99-
unsigned long long offset)
98+
SSIZE_T pwrite(const native_file_handle &h, const void *buf, size_t count,
99+
unsigned long long offset)
100100
{
101101
OVERLAPPED ov{};
102102
ULARGE_INTEGER uli;

tpool/tpool.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ create_thread_pool_win(int min_threads= DEFAULT_MIN_POOL_THREADS,
293293
opened with FILE_FLAG_OVERLAPPED, and bound to completion
294294
port.
295295
*/
296-
SSIZE_T pwrite(const native_file_handle &h, void *buf, size_t count,
297-
unsigned long long offset);
296+
SSIZE_T pwrite(const native_file_handle &h, const void *buf, size_t count,
297+
unsigned long long offset);
298298
SSIZE_T pread(const native_file_handle &h, void *buf, size_t count,
299-
unsigned long long offset);
299+
unsigned long long offset);
300300
HANDLE win_get_syncio_event();
301301
#endif
302302
} // namespace tpool

0 commit comments

Comments
 (0)