From cb583b2f1bf1c910e82c7caee4a53e0f3ff954ba Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Fri, 23 Sep 2022 01:09:46 +0300 Subject: [PATCH] MDEV-29609 create_not_windows test fails with different result make_tmp_name() creates temporary name with prefix containing PID and TID. This prefix influences max length of the rest of the name (the whole name is limited by NAME_LEN). During the test run PID and TID can change. PID increases when the server restarts. TID is incremented with the new connections (generated by next_thread_id(), is not the posix thread ID). During the test run PID can increase max 2 decimal positions: from tens to thousands this requires ~900 restarts. TID depends on connection count, but for test we assume it will not trespass 100000 connections which is 5 decimal positions. So it should be enough to reserve 7 characters for PID and TID increment. The patch reserves more: it reserves 12 characters for 7-decimal PID and 5-decimal TID plus 4 chars of additional reserve (for future prefix changes) and assumes minimal legth of the prefix is 30 bytes: #sql-backup-PID-TID- #sql-create-PID-TID- 4-6-PID-TID- is 10 + 4 + PID + TID, so PID + TID is 16 chars (7 + 5 + 4). --- mysql-test/main/create_not_windows.result | 12 ++++++------ sql/sql_table.cc | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/mysql-test/main/create_not_windows.result b/mysql-test/main/create_not_windows.result index 3ab2d56bf17..43860c2fdca 100644 --- a/mysql-test/main/create_not_windows.result +++ b/mysql-test/main/create_not_windows.result @@ -57,11 +57,11 @@ tttttttttttttttttttttttt❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎ set @@debug_dbug="+d,ddl_log_create_after_save_backup", @debug_crash_counter=1; create or replace table tttttttttttttttttttttttt❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎ (z int); ERROR HY000: Lost connection to server during query -#sql-backup-PID-TID-tttttttttttttttttttttttt@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e.MYD -#sql-backup-PID-TID-tttttttttttttttttttttttt@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e.MYI -#sql-backup-PID-TID-tttttttttttttttttttttttt@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e.frm -#sql-create-PID-TID-tttttttttttttttttttttttt@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e.MYD -#sql-create-PID-TID-tttttttttttttttttttttttt@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e.MYI -#sql-create-PID-TID-tttttttttttttttttttttttt@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e.frm +#sql-backup-PID-TID-tttttttttttttttttttttttt@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e.MYD +#sql-backup-PID-TID-tttttttttttttttttttttttt@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e.MYI +#sql-backup-PID-TID-tttttttttttttttttttttttt@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e.frm +#sql-create-PID-TID-tttttttttttttttttttttttt@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e.MYD +#sql-create-PID-TID-tttttttttttttttttttttttt@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e.MYI +#sql-create-PID-TID-tttttttttttttttttttttttt@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e.frm drop table tttttttttttttttttttttttt❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎; set @@debug_dbug=""; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index de71432a355..23dab5056c3 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1251,13 +1251,19 @@ bool make_tmp_name(THD *thd, const char *prefix, const Table_name *orig, char res_name[NAME_LEN + 1]; char file_name[NAME_LEN + 1]; LEX_CSTRING table_name; + /* + Filename trimming should not depend on prefix length with variable PID and + thread ID. This makes tests happier. + */ + constexpr int MIN_PREFIX= 30; size_t len= my_snprintf(res_name, sizeof(res_name) - 1, tmp_file_prefix "-%s-%lx-%llx-", prefix, current_pid, thd->thread_id); + const size_t pfx_len= len < MIN_PREFIX ? MIN_PREFIX : len; uint len2= tablename_to_filename(orig->table_name.str, file_name, - sizeof(res_name) - len - 1); + sizeof(res_name) - pfx_len - 1); DBUG_ASSERT(len + len2 < sizeof(res_name) - 1); memcpy(res_name + len, file_name, len2 + 1);