Skip to content

Commit

Permalink
MDEV-26192: Sparse files are being created on thinly provisioned storage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dr-m committed Jul 20, 2021
1 parent ed0a7b1 commit 61fcbed
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
35 changes: 20 additions & 15 deletions storage/innobase/fil/fil0fil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ fil_space_extend_must_retry(
os_offset_t(FIL_IBD_FILE_INITIAL_SIZE << srv_page_size_shift));

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

os_has_said_disk_full = *success;
if (*success) {
Expand Down Expand Up @@ -2024,24 +2024,17 @@ fil_ibd_create(
}

const bool is_compressed = fil_space_t::is_compressed(flags);
fil_space_crypt_t* crypt_data = nullptr;
#ifdef _WIN32
const bool is_sparse = is_compressed;
if (is_compressed) {
os_file_set_sparse_win32(file);
}
#else
const bool is_sparse = is_compressed
&& DB_SUCCESS == os_file_punch_hole(file, 0, 4096)
&& !my_test_if_thinly_provisioned(file);
#endif

if (!os_file_set_size(
path, file,
os_offset_t(size) << srv_page_size_shift, is_compressed)) {
*err = DB_OUT_OF_FILE_SPACE;
err_exit:
os_file_close(file);
os_file_delete(innodb_data_file_key, path);
free(crypt_data);
return NULL;
}

if (fil_space_t::full_crc32(flags)) {
flags |= FSP_FLAGS_FCRC32_PAGE_SSIZE();
} else {
Expand All @@ -2050,9 +2043,21 @@ fil_ibd_create(

/* Create crypt data if the tablespace is either encrypted or user has
requested it to remain unencrypted. */
crypt_data = (mode != FIL_ENCRYPTION_DEFAULT || srv_encrypt_tables)
fil_space_crypt_t* crypt_data = (mode != FIL_ENCRYPTION_DEFAULT
|| srv_encrypt_tables)
? fil_space_create_crypt_data(mode, key_id)
: NULL;
: nullptr;

if (!os_file_set_size(path, file,
os_offset_t(size) << srv_page_size_shift,
is_sparse)) {
*err = DB_OUT_OF_FILE_SPACE;
err_exit:
os_file_close(file);
os_file_delete(innodb_data_file_key, path);
free(crypt_data);
return nullptr;
}

fil_space_t::name_type space_name;

Expand Down
12 changes: 11 additions & 1 deletion storage/innobase/log/log0recv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,19 @@ bool recv_sys_t::recover_deferred(recv_sys_t::map::iterator &p,
node->deferred= true;
if (!space->acquire())
goto fail;
const bool is_compressed= fil_space_t::is_compressed(flags);
#ifdef _WIN32
const bool is_sparse= is_compressed;
if (is_compressed)
os_file_set_sparse_win32(node->handle);
#else
const bool is_sparse= is_compressed &&
DB_SUCCESS == os_file_punch_hole(node->handle, 0, 4096) &&
!my_test_if_thinly_provisioned(node->handle);
#endif
if (!os_file_set_size(node->name, node->handle,
size * fil_space_t::physical_size(flags),
space->is_compressed()))
is_sparse))
{
space->release();
goto fail;
Expand Down

0 comments on commit 61fcbed

Please sign in to comment.