Skip to content
Permalink
Browse files
MDEV-30209 Race condition between fil_node_open_file() and renaming f…
…iles

mtr_t::commit_file(): Protect the rename operation with fil_system.mutex
like we used to do before commit 2e43af6
in order to prevent fil_node_open_file() from running concurrently.
In other words, fil_system.mutex will protect the consistency of
fil_node_t::name and the file name in the file system.

This race condition should be very hard to trigger. We would need
a low value of innodb_open_files or table_cache limit so that
fil_space_t::try_to_close() will be invoked frequently. Simultaneously
with a RENAME operation, something (such as a write of a data page)
would have to try to open the file.
  • Loading branch information
dr-m committed Dec 12, 2022
1 parent cf437f6 commit 1862273
Showing 1 changed file with 7 additions and 7 deletions.
@@ -385,15 +385,15 @@ bool mtr_t::commit_file(fil_space_t &space, const char *name)

if (name)
{
char *new_name= mem_strdup(name);
mysql_mutex_lock(&fil_system.mutex);
success= os_file_rename(innodb_data_file_key, old_name, name);

if (success)
{
mysql_mutex_lock(&fil_system.mutex);
space.chain.start->name= mem_strdup(name);
mysql_mutex_unlock(&fil_system.mutex);
ut_free(old_name);
}
space.chain.start->name= new_name;
else
old_name= new_name;
mysql_mutex_unlock(&fil_system.mutex);
ut_free(old_name);
}
else
{

0 comments on commit 1862273

Please sign in to comment.