diff options
author | Vladislav Vaintroub <wlad@mariadb.com> | 2017-10-06 16:36:40 +0000 |
---|---|---|
committer | Vladislav Vaintroub <wlad@mariadb.com> | 2017-10-07 08:30:20 +0000 |
commit | 420798a81ac9a81d20629535fac3032e025e7733 (patch) | |
tree | fd930bc1cad32dd561ab9f9bc25462df6d4c3d5e /storage/innobase/os | |
parent | 0373e05a59afd14444337dfc9f9d3bc98a815e18 (diff) | |
download | mariadb-git-420798a81ac9a81d20629535fac3032e025e7733.tar.gz |
Refactor os_file_set_size to extend already existing files.
Change fil_space_extend_must_retry() to use this function.
Diffstat (limited to 'storage/innobase/os')
-rw-r--r-- | storage/innobase/os/os0file.cc | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index 44093935bc7..2a13746516f 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -2340,7 +2340,16 @@ os_file_get_size( #endif /* __WIN__ */ } -/** Set the size of a newly created file. +/** Extend a file. + +On Windows, extending a file allocates blocks for the file, +unless the file is sparse. + +On Unix, we will extend the file with ftruncate(), if +file needs to be sparse. Otherwise posix_fallocate() is used +when available, and if not, binary zeroes are added to the end +of file. + @param[in] name file name @param[in] file file handle @param[in] size desired file size @@ -2391,15 +2400,21 @@ os_file_set_size( "file %s failed with error %d", size, name, err); } + /* Set errno because posix_fallocate() does not do it.*/ + errno = err; return(!err); } # endif + os_offset_t current_size = os_file_get_size(file); + + if (current_size >= size) { + return true; + } + /* Write up to 1 megabyte at a time. */ ulint buf_size = ut_min(64, (ulint) (size / UNIV_PAGE_SIZE)) * UNIV_PAGE_SIZE; - os_offset_t current_size = 0; - byte* buf2 = static_cast<byte*>(calloc(1, buf_size + UNIV_PAGE_SIZE)); if (!buf2) { |