Skip to content

Commit

Permalink
MDEV-29015 innodb os_file_set_size WSL workaround
Browse files Browse the repository at this point in the history
WSL wasn't keeping stack of renamed files
(microsoft/WSL#8443)
resulting in the fstat calls in os_file_set_size returning
ENOENT and no fallocate fallback being possible.

Users reported MySQL was ok, and it used my_seek to
determine the size. We copy this concept here to avoid
the WSL bug.
  • Loading branch information
grooverdan committed Jul 11, 2022
1 parent 0e9a255 commit 8e99781
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions storage/innobase/os/os0file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5304,8 +5304,6 @@ os_file_set_size(

fallback:
#else
struct stat statbuf;

if (is_sparse) {
bool success = !ftruncate(file, size);
if (!success) {
Expand All @@ -5319,17 +5317,18 @@ os_file_set_size(
# ifdef HAVE_POSIX_FALLOCATE
int err;
do {
if (fstat(file, &statbuf)) {
os_offset_t current_size = my_seek(file, 0L, MY_SEEK_END,
MYF(MY_WME));
if (current_size == MY_FILEPOS_ERROR) {
err = errno;
} else {
os_offset_t current_size = statbuf.st_size;
if (current_size >= size) {
return true;
}
current_size &= ~4095ULL;
err = posix_fallocate(file, current_size,
size - current_size);
break;
}
if (current_size >= size) {
return true;
}
current_size &= ~4095ULL;
err = posix_fallocate(file, current_size, size - current_size);

} while (err == EINTR
&& srv_shutdown_state <= SRV_SHUTDOWN_INITIATED);

Expand Down Expand Up @@ -5363,10 +5362,11 @@ os_file_set_size(
}
}
#else
if (fstat(file, &statbuf)) {
os_offset_t current_size = my_seek(file, 0L, MY_SEEK_END, MYF(MY_WME));
if (current_size == MY_FILEPOS_ERROR)
return false;
}
os_offset_t current_size = statbuf.st_size & ~4095ULL;

current_size &= ~4095ULL;
#endif
if (current_size >= size) {
return true;
Expand Down

0 comments on commit 8e99781

Please sign in to comment.