Skip to content

Commit

Permalink
MDEV-14132 InnoDB page corruption
Browse files Browse the repository at this point in the history
On some old GNU/Linux systems, invoking posix_fallocate() with
offset=0 would sometimes cause already allocated bytes in the
data file to be overwritten.

Fix a correctness regression that was introduced in
commit 420798a
by invoking posix_fallocate() in a safer way.
A similar change was made in MDEV-5746 earlier.

os_file_get_size(): Avoid changing the state of the file handle,
by invoking fstat() instead of lseek().

os_file_set_size(): Determine the current size of the file
by os_file_get_size(), and then extend the file from that point
onwards.
  • Loading branch information
dr-m committed Nov 6, 2017
1 parent 30a8764 commit 51679e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions storage/innobase/os/os0file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2335,8 +2335,8 @@ os_file_get_size(

return(offset);
#else
return((os_offset_t) lseek(file, 0, SEEK_END));

struct stat statbuf;
return fstat(file, &statbuf) ? os_offset_t(-1) : statbuf.st_size;
#endif /* __WIN__ */
}

Expand Down Expand Up @@ -2390,7 +2390,10 @@ os_file_set_size(
if (srv_use_posix_fallocate) {
int err;
do {
err = posix_fallocate(file, 0, size);
os_offset_t current_size = os_file_get_size(file);
err = current_size >= size
? 0 : posix_fallocate(file, current_size,
size - current_size);
} while (err == EINTR
&& srv_shutdown_state == SRV_SHUTDOWN_NONE);

Expand Down
9 changes: 6 additions & 3 deletions storage/xtradb/os/os0file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2570,8 +2570,8 @@ os_file_get_size(

return(offset);
#else
return((os_offset_t) lseek(file, 0, SEEK_END));

struct stat statbuf;
return fstat(file, &statbuf) ? os_offset_t(-1) : statbuf.st_size;
#endif /* __WIN__ */
}

Expand Down Expand Up @@ -2625,7 +2625,10 @@ os_file_set_size(
if (srv_use_posix_fallocate) {
int err;
do {
err = posix_fallocate(file, 0, size);
os_offset_t current_size = os_file_get_size(file);
err = current_size >= size
? 0 : posix_fallocate(file, current_size,
size - current_size);
} while (err == EINTR
&& srv_shutdown_state == SRV_SHUTDOWN_NONE);

Expand Down

0 comments on commit 51679e5

Please sign in to comment.