Skip to content

Commit

Permalink
Fixed issue on file space extension. File space should be extended from
Browse files Browse the repository at this point in the history
current offset to desired size if posix_fallocate is used.
  • Loading branch information
Jan Lindström committed Feb 6, 2014
1 parent 7f3950a commit 18353c6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 37 deletions.
34 changes: 15 additions & 19 deletions storage/innobase/fil/fil0fil.cc
Expand Up @@ -48,6 +48,7 @@ Created 10/25/1995 Heikki Tuuri
#include "page0zip.h"
#include "trx0sys.h"
#include "row0mysql.h"
#include "os0file.h"
#ifndef UNIV_HOTBACKUP
# include "buf0lru.h"
# include "ibuf0ibuf.h"
Expand Down Expand Up @@ -4860,28 +4861,25 @@ fil_extend_space_to_desired_size(

#ifdef HAVE_POSIX_FALLOCATE
if (srv_use_posix_fallocate) {
ulint n_pages = size_after_extend;

success = os_file_set_size(node->name, node->handle,
n_pages * page_size);

/* Temporal solution: In directFS using atomic writes
we must use posix_fallocate to extend the file because
pwrite past end of file fails but when compression is
used the file pages must be physically initialized with
zeroes, thus after file extend with posix_fallocate
we still write empty pages to file. */
if (success &&
srv_use_atomic_writes &&
srv_compress_pages) {
goto extend_file;
os_offset_t start_offset = start_page_no * page_size;
os_offset_t end_offset = (size_after_extend - start_page_no) * page_size;

if (posix_fallocate(node->handle, start_offset, end_offset) == -1) {
ib_logf(IB_LOG_LEVEL_ERROR, "preallocating file "
"space for file \'%s\' failed. Current size "
INT64PF ", desired size " INT64PF "\n",
node->name, start_offset, end_offset);
success = FALSE;
} else {
success = TRUE;
}

mutex_enter(&fil_system->mutex);

if (success) {
node->size += n_pages;
space->size += n_pages;
node->size += (size_after_extend - start_page_no);
space->size += (size_after_extend - start_page_no);

os_has_said_disk_full = FALSE;
}

Expand All @@ -4895,8 +4893,6 @@ fil_extend_space_to_desired_size(
}
#endif

extend_file:

/* Extend at most 64 pages at a time */
buf_size = ut_min(64, size_after_extend - start_page_no) * page_size;
buf2 = static_cast<byte*>(mem_alloc(buf_size + page_size));
Expand Down
31 changes: 13 additions & 18 deletions storage/xtradb/fil/fil0fil.cc
Expand Up @@ -4988,27 +4988,24 @@ fil_extend_space_to_desired_size(

#ifdef HAVE_POSIX_FALLOCATE
if (srv_use_posix_fallocate) {
ulint n_pages = size_after_extend;

success = os_file_set_size(node->name, node->handle, n_pages * page_size);

/* Temporal solution: In directFS using atomic writes
we must use posix_fallocate to extend the file because
pwrite past end of file fails but when compression is
used the file pages must be physically initialized with
zeroes, thus after file extend with posix_fallocate
we still write empty pages to file. */
if (success &&
srv_use_atomic_writes &&
srv_compress_pages) {
goto extend_file;
os_offset_t start_offset = start_page_no * page_size;
os_offset_t end_offset = (size_after_extend - start_page_no) * page_size;

if (posix_fallocate(node->handle, start_offset, end_offset) == -1) {
ib_logf(IB_LOG_LEVEL_ERROR, "preallocating file "
"space for file \'%s\' failed. Current size "
INT64PF ", desired size " INT64PF "\n",
node->name, start_offset, end_offset);
success = FALSE;
} else {
success = TRUE;
}

mutex_enter(&fil_system->mutex);

if (success) {
node->size += n_pages;
space->size += n_pages;
node->size += (size_after_extend - start_page_no);
space->size += (size_after_extend - start_page_no);
os_has_said_disk_full = FALSE;
}

Expand All @@ -5022,8 +5019,6 @@ fil_extend_space_to_desired_size(
}
#endif

extend_file:

/* Extend at most 64 pages at a time */
buf_size = ut_min(64, size_after_extend - start_page_no) * page_size;
buf2 = static_cast<byte*>(mem_alloc(buf_size + page_size));
Expand Down

0 comments on commit 18353c6

Please sign in to comment.