Skip to content

Commit 6edfdae

Browse files
committed
MDEV-35983 Avoid install failures by using retry logic for file operations
Added retry logic to certain file operations during installation as a workaround for issues caused by buggy antivirus software on Windows. Retry logic added for WritePrivateProfileString (mysql_install_db.cc) and renaming file in Innodb.
1 parent 1f5d2b2 commit 6edfdae

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

sql/mysql_install_db.cc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,29 @@ static char *init_bootstrap_command_line(char *cmdline, size_t size)
344344

345345
static char my_ini_path[MAX_PATH];
346346

347+
/**
348+
Wrapper for WritePrivateProfileStringA, with retries and sleeps
349+
if file is locked by another process.
350+
*/
351+
static BOOL write_private_profile_string_with_retries(const char *appname,
352+
const char *key, const char *val, const char *filename)
353+
{
354+
static constexpr int RETRIES=50;
355+
static constexpr int SLEEP_MS=10;
356+
for (int n= RETRIES;; n--)
357+
{
358+
if (WritePrivateProfileStringA(appname, key, val, filename))
359+
return TRUE;
360+
if (GetLastError() != ERROR_ACCESS_DENIED || !n)
361+
return FALSE;
362+
Sleep(SLEEP_MS);
363+
}
364+
}
365+
347366
static void write_myini_str(const char *key, const char* val, const char *section="mysqld")
348367
{
349368
DBUG_ASSERT(my_ini_path[0]);
350-
if (!WritePrivateProfileString(section, key, val, my_ini_path))
369+
if (!write_private_profile_string_with_retries(section, key, val, my_ini_path))
351370
{
352371
die("Can't write to ini file key=%s, val=%s, section=%s, Windows error %u",key,val,section,
353372
GetLastError());

storage/innobase/os/os0file.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,8 +2314,20 @@ os_file_rename_func(
23142314
ut_ad(exists);
23152315
#endif /* UNIV_DEBUG */
23162316

2317-
if (MoveFileEx(oldpath, newpath, MOVEFILE_REPLACE_EXISTING)) {
2318-
return(true);
2317+
for (int retry= 50;; retry--){
2318+
if (MoveFileEx(oldpath, newpath, MOVEFILE_REPLACE_EXISTING))
2319+
return true;
2320+
2321+
if (!retry)
2322+
break;
2323+
2324+
if (GetLastError() != ERROR_SHARING_VIOLATION)
2325+
break;
2326+
2327+
// oldpath was opened by someone else (antivirus?)
2328+
//without FILE_SHARE_DELETE flag. Retry operation
2329+
2330+
Sleep(10);
23192331
}
23202332

23212333
os_file_handle_rename_error(oldpath, newpath);

0 commit comments

Comments
 (0)