Skip to content

Commit 61fcbed

Browse files
committed
MDEV-26192: Sparse files are being created on thinly provisioned storage
In MDEV-26029 the intention was that page_compressed tables would be written as regular (non-sparse) files if the file is stored on a thinly provisioned block device. We were incorrectly requesting os_file_set_size() to create sparse files even on thinly provisioned storage. fil_space_extend_must_retry(): Extend the file in the correct fashion. fil_ibd_create(), recv_sys_t::recover_deferred(): Only create a sparse file for page_compressed tables if thin provisioning is not detected.
1 parent ed0a7b1 commit 61fcbed

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

storage/innobase/fil/fil0fil.cc

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ fil_space_extend_must_retry(
577577
os_offset_t(FIL_IBD_FILE_INITIAL_SIZE << srv_page_size_shift));
578578

579579
*success = os_file_set_size(node->name, node->handle, new_size,
580-
space->is_compressed());
580+
node->punch_hole == 1);
581581

582582
os_has_said_disk_full = *success;
583583
if (*success) {
@@ -2024,24 +2024,17 @@ fil_ibd_create(
20242024
}
20252025

20262026
const bool is_compressed = fil_space_t::is_compressed(flags);
2027-
fil_space_crypt_t* crypt_data = nullptr;
20282027
#ifdef _WIN32
2028+
const bool is_sparse = is_compressed;
20292029
if (is_compressed) {
20302030
os_file_set_sparse_win32(file);
20312031
}
2032+
#else
2033+
const bool is_sparse = is_compressed
2034+
&& DB_SUCCESS == os_file_punch_hole(file, 0, 4096)
2035+
&& !my_test_if_thinly_provisioned(file);
20322036
#endif
20332037

2034-
if (!os_file_set_size(
2035-
path, file,
2036-
os_offset_t(size) << srv_page_size_shift, is_compressed)) {
2037-
*err = DB_OUT_OF_FILE_SPACE;
2038-
err_exit:
2039-
os_file_close(file);
2040-
os_file_delete(innodb_data_file_key, path);
2041-
free(crypt_data);
2042-
return NULL;
2043-
}
2044-
20452038
if (fil_space_t::full_crc32(flags)) {
20462039
flags |= FSP_FLAGS_FCRC32_PAGE_SSIZE();
20472040
} else {
@@ -2050,9 +2043,21 @@ fil_ibd_create(
20502043

20512044
/* Create crypt data if the tablespace is either encrypted or user has
20522045
requested it to remain unencrypted. */
2053-
crypt_data = (mode != FIL_ENCRYPTION_DEFAULT || srv_encrypt_tables)
2046+
fil_space_crypt_t* crypt_data = (mode != FIL_ENCRYPTION_DEFAULT
2047+
|| srv_encrypt_tables)
20542048
? fil_space_create_crypt_data(mode, key_id)
2055-
: NULL;
2049+
: nullptr;
2050+
2051+
if (!os_file_set_size(path, file,
2052+
os_offset_t(size) << srv_page_size_shift,
2053+
is_sparse)) {
2054+
*err = DB_OUT_OF_FILE_SPACE;
2055+
err_exit:
2056+
os_file_close(file);
2057+
os_file_delete(innodb_data_file_key, path);
2058+
free(crypt_data);
2059+
return nullptr;
2060+
}
20562061

20572062
fil_space_t::name_type space_name;
20582063

storage/innobase/log/log0recv.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,9 +839,19 @@ bool recv_sys_t::recover_deferred(recv_sys_t::map::iterator &p,
839839
node->deferred= true;
840840
if (!space->acquire())
841841
goto fail;
842+
const bool is_compressed= fil_space_t::is_compressed(flags);
843+
#ifdef _WIN32
844+
const bool is_sparse= is_compressed;
845+
if (is_compressed)
846+
os_file_set_sparse_win32(node->handle);
847+
#else
848+
const bool is_sparse= is_compressed &&
849+
DB_SUCCESS == os_file_punch_hole(node->handle, 0, 4096) &&
850+
!my_test_if_thinly_provisioned(node->handle);
851+
#endif
842852
if (!os_file_set_size(node->name, node->handle,
843853
size * fil_space_t::physical_size(flags),
844-
space->is_compressed()))
854+
is_sparse))
845855
{
846856
space->release();
847857
goto fail;

0 commit comments

Comments
 (0)