Bug #47126 equal flag values causing unexpected behaviour
Submitted: 4 Sep 2009 9:18 Modified: 7 Mar 2010 1:53
Reporter: Satya B Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.1 OS:Any
Assigned to: Alexey Botchkov CPU Architecture:Any

[4 Sep 2009 9:18] Satya B
Description:
In 5.1 include/my_sys.h, the flags MY_DONT_OVERWRITE_FILE and MY_SYNC_DIR have
same value 1024.

Both the flags are used in my_copy()

 create_flag= (MyFlags & MY_DONT_OVERWRITE_FILE) ? O_EXCL : O_TRUNC;

    if ((to_file=  my_create(to,(int) stat_buff.st_mode,
                             O_WRONLY | create_flag | O_BINARY | O_SHARE,
                             MyFlags)) < 0)

You might expect my_create to create a file without overwriting the file if it exists but since MY_SYNC_DIR flag value is same as MY_DONT_OVERWRITE_FILE, it 
ends up syncing the directory and overwriting the file which is not intended.

The other way round is also possible and the behaviour can be random.It can cause performance issues because it ends up unnecessarily syncing directories to disk, which is an I/0 operation to disk.

How to repeat:
use debugger and see that my_syncdir() is called after my_create() even though the flag passed is MY_DONT_OVERWRITE_FILE

Suggested fix:
use different flag value for either of them
[24 Oct 2009 9:03] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/88075

2899 Alexey Botchkov	2009-10-24
      Bug#47126      equal flag values causing unexpected behaviour
         Actually the MY_SYNC_DIR flag is never used, so we can declare is as 0,
         but decided to assign a new value for it as it's probably safer and
         worths nothing.
      
      per-file comments:
        include/my_sys.h
      Bug#47126      equal flag values causing unexpected behaviour
           assign unique value for the MY_SYNC_DIR
[11 Nov 2009 13:29] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/90089

2916 Alexey Botchkov	2009-11-11
      Bug#47126      equal flag values causing unexpected behaviour
         Although the MY_SYNC_DIR flag supported in my_create(), my_delete(),
         my_rename() and my_symlink(), this feature is not used in the
         mysql code now. So technically we can declare the MY_SYNC_DIR as 0,
         but I decided to assign a new value for it as it's probably safer and
         worths nothing.
      
      per-file comments:
        include/my_sys.h
      Bug#47126      equal flag values causing unexpected behaviour
           assign unique value for the MY_SYNC_DIR
[18 Nov 2009 14:41] Alexey Botchkov
pushed into mysql-next-mr-bugfixing
[20 Nov 2009 12:56] Bugs System
Pushed into 6.0.14-alpha (revid:kostja@sun.com-20091120124947-yi6h2jbgw0kbciwm) (version source revid:holyfoot@mysql.com-20091117114617-75quk99yr1coxv8c) (merge vers: 6.0.14-alpha) (pib:13)
[11 Dec 2009 6:03] Bugs System
Pushed into 5.6.0-beta (revid:alik@sun.com-20091211055628-ltr7fero363uev7r) (version source revid:alik@sun.com-20091211055453-717czhtezc74u8db) (merge vers: 5.6.0-beta) (pib:13)
[7 Jan 2010 16:36] Paul DuBois
Noted in 5.6.0, 6.0.14 changelogs.

Corrected a potential problem of unintended overwriting of files when
the MY_DONT_OVERWRITE_FILE flag was used.
[6 Mar 2010 11:09] Bugs System
Pushed into 5.5.3-m3 (revid:alik@sun.com-20100306103849-hha31z2enhh7jwt3) (version source revid:vvaintroub@mysql.com-20091211201717-03qf8ckwiw0np80p) (merge vers: 5.6.0-beta) (pib:16)
[7 Mar 2010 1:53] Paul DuBois
Moved 5.6.0 changelog entry to 5.5.3.