Skip to content

Commit

Permalink
MDEV-27796 Windows - starting server with huge innodb-log-buffer-size…
Browse files Browse the repository at this point in the history
… may fail

Fixed tpool::pread() and tpool::pwrite() to return SSIZE_T on Windows,
so that huge numbers are not converted to negatives.

Also, make sure to never attempt reading/writing more bytes than
DWORD can accomodate (4G)
  • Loading branch information
vaintroub committed Feb 10, 2022
1 parent 9e39d0a commit 012e724
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions tpool/aio_simulated.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct WinIoInit
static WinIoInit win_io_init;


int 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)
{
OVERLAPPED ov{};
Expand All @@ -81,6 +81,8 @@ int pread(const native_file_handle &h, void *buf, size_t count,
ov.Offset= uli.LowPart;
ov.OffsetHigh= uli.HighPart;
ov.hEvent= win_get_syncio_event();
if (count > 0xFFFFFFFF)
count= 0xFFFFFFFF;

if (ReadFile(h, buf, (DWORD) count, 0, &ov) ||
(GetLastError() == ERROR_IO_PENDING))
Expand All @@ -93,7 +95,7 @@ int pread(const native_file_handle &h, void *buf, size_t count,
return -1;
}

int pwrite(const native_file_handle &h, void *buf, size_t count,
SSIZE_T pwrite(const native_file_handle &h, void *buf, size_t count,
unsigned long long offset)
{
OVERLAPPED ov{};
Expand All @@ -102,7 +104,8 @@ int pwrite(const native_file_handle &h, void *buf, size_t count,
ov.Offset= uli.LowPart;
ov.OffsetHigh= uli.HighPart;
ov.hEvent= win_get_syncio_event();

if (count > 0xFFFFFFFF)
count= 0xFFFFFFFF;
if (WriteFile(h, buf, (DWORD) count, 0, &ov) ||
(GetLastError() == ERROR_IO_PENDING))
{
Expand Down
4 changes: 2 additions & 2 deletions tpool/tpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ create_thread_pool_win(int min_threads= DEFAULT_MIN_POOL_THREADS,
opened with FILE_FLAG_OVERLAPPED, and bound to completion
port.
*/
int pwrite(const native_file_handle &h, void *buf, size_t count,
SSIZE_T pwrite(const native_file_handle &h, void *buf, size_t count,
unsigned long long offset);
int 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);
HANDLE win_get_syncio_event();
#endif
Expand Down

0 comments on commit 012e724

Please sign in to comment.