Skip to content

Commit 18353c6

Browse files
author
Jan Lindström
committed
Fixed issue on file space extension. File space should be extended from
current offset to desired size if posix_fallocate is used.
1 parent 7f3950a commit 18353c6

File tree

2 files changed

+28
-37
lines changed

2 files changed

+28
-37
lines changed

storage/innobase/fil/fil0fil.cc

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Created 10/25/1995 Heikki Tuuri
4848
#include "page0zip.h"
4949
#include "trx0sys.h"
5050
#include "row0mysql.h"
51+
#include "os0file.h"
5152
#ifndef UNIV_HOTBACKUP
5253
# include "buf0lru.h"
5354
# include "ibuf0ibuf.h"
@@ -4860,28 +4861,25 @@ fil_extend_space_to_desired_size(
48604861

48614862
#ifdef HAVE_POSIX_FALLOCATE
48624863
if (srv_use_posix_fallocate) {
4863-
ulint n_pages = size_after_extend;
4864-
4865-
success = os_file_set_size(node->name, node->handle,
4866-
n_pages * page_size);
4867-
4868-
/* Temporal solution: In directFS using atomic writes
4869-
we must use posix_fallocate to extend the file because
4870-
pwrite past end of file fails but when compression is
4871-
used the file pages must be physically initialized with
4872-
zeroes, thus after file extend with posix_fallocate
4873-
we still write empty pages to file. */
4874-
if (success &&
4875-
srv_use_atomic_writes &&
4876-
srv_compress_pages) {
4877-
goto extend_file;
4864+
os_offset_t start_offset = start_page_no * page_size;
4865+
os_offset_t end_offset = (size_after_extend - start_page_no) * page_size;
4866+
4867+
if (posix_fallocate(node->handle, start_offset, end_offset) == -1) {
4868+
ib_logf(IB_LOG_LEVEL_ERROR, "preallocating file "
4869+
"space for file \'%s\' failed. Current size "
4870+
INT64PF ", desired size " INT64PF "\n",
4871+
node->name, start_offset, end_offset);
4872+
success = FALSE;
4873+
} else {
4874+
success = TRUE;
48784875
}
48794876

48804877
mutex_enter(&fil_system->mutex);
48814878

48824879
if (success) {
4883-
node->size += n_pages;
4884-
space->size += n_pages;
4880+
node->size += (size_after_extend - start_page_no);
4881+
space->size += (size_after_extend - start_page_no);
4882+
48854883
os_has_said_disk_full = FALSE;
48864884
}
48874885

@@ -4895,8 +4893,6 @@ fil_extend_space_to_desired_size(
48954893
}
48964894
#endif
48974895

4898-
extend_file:
4899-
49004896
/* Extend at most 64 pages at a time */
49014897
buf_size = ut_min(64, size_after_extend - start_page_no) * page_size;
49024898
buf2 = static_cast<byte*>(mem_alloc(buf_size + page_size));

storage/xtradb/fil/fil0fil.cc

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4988,27 +4988,24 @@ fil_extend_space_to_desired_size(
49884988

49894989
#ifdef HAVE_POSIX_FALLOCATE
49904990
if (srv_use_posix_fallocate) {
4991-
ulint n_pages = size_after_extend;
4992-
4993-
success = os_file_set_size(node->name, node->handle, n_pages * page_size);
4994-
4995-
/* Temporal solution: In directFS using atomic writes
4996-
we must use posix_fallocate to extend the file because
4997-
pwrite past end of file fails but when compression is
4998-
used the file pages must be physically initialized with
4999-
zeroes, thus after file extend with posix_fallocate
5000-
we still write empty pages to file. */
5001-
if (success &&
5002-
srv_use_atomic_writes &&
5003-
srv_compress_pages) {
5004-
goto extend_file;
4991+
os_offset_t start_offset = start_page_no * page_size;
4992+
os_offset_t end_offset = (size_after_extend - start_page_no) * page_size;
4993+
4994+
if (posix_fallocate(node->handle, start_offset, end_offset) == -1) {
4995+
ib_logf(IB_LOG_LEVEL_ERROR, "preallocating file "
4996+
"space for file \'%s\' failed. Current size "
4997+
INT64PF ", desired size " INT64PF "\n",
4998+
node->name, start_offset, end_offset);
4999+
success = FALSE;
5000+
} else {
5001+
success = TRUE;
50055002
}
50065003

50075004
mutex_enter(&fil_system->mutex);
50085005

50095006
if (success) {
5010-
node->size += n_pages;
5011-
space->size += n_pages;
5007+
node->size += (size_after_extend - start_page_no);
5008+
space->size += (size_after_extend - start_page_no);
50125009
os_has_said_disk_full = FALSE;
50135010
}
50145011

@@ -5022,8 +5019,6 @@ fil_extend_space_to_desired_size(
50225019
}
50235020
#endif
50245021

5025-
extend_file:
5026-
50275022
/* Extend at most 64 pages at a time */
50285023
buf_size = ut_min(64, size_after_extend - start_page_no) * page_size;
50295024
buf2 = static_cast<byte*>(mem_alloc(buf_size + page_size));

0 commit comments

Comments
 (0)