Skip to content

Commit 1862273

Browse files
committed
MDEV-30209 Race condition between fil_node_open_file() and renaming files
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.
1 parent cf437f6 commit 1862273

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

storage/innobase/mtr/mtr0mtr.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,15 +385,15 @@ bool mtr_t::commit_file(fil_space_t &space, const char *name)
385385

386386
if (name)
387387
{
388+
char *new_name= mem_strdup(name);
389+
mysql_mutex_lock(&fil_system.mutex);
388390
success= os_file_rename(innodb_data_file_key, old_name, name);
389-
390391
if (success)
391-
{
392-
mysql_mutex_lock(&fil_system.mutex);
393-
space.chain.start->name= mem_strdup(name);
394-
mysql_mutex_unlock(&fil_system.mutex);
395-
ut_free(old_name);
396-
}
392+
space.chain.start->name= new_name;
393+
else
394+
old_name= new_name;
395+
mysql_mutex_unlock(&fil_system.mutex);
396+
ut_free(old_name);
397397
}
398398
else
399399
{

0 commit comments

Comments
 (0)