Bug #35036 Maria's usage of my_stat() is unreliable on Windows
Submitted: 4 Mar 2008 15:18 Modified: 19 Mar 2008 22:08
Reporter: Guilhem Bichot Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Maria storage engine Severity:S3 (Non-critical)
Version:5.1-maria OS:Any
Assigned to: Oleksandr Byelkin CPU Architecture:Any

[4 Mar 2008 15:18] Guilhem Bichot
Description:
I have verified on Windows that if one process does my_write() to a file and then does a my_stat() on this same file, the st_size member of the MY_STAT result may not reflect the my_write(). That is, write 10 bytes, then write 10 bytes, then stat: stat will say the file is 10 byte long. Even a my_close() between write and stat does not improve this.
The problem was experienced in the control file and fixed by:
ChangeSet 1.2583.1.1 2008/02/11 14:48:03 guilhem@mysqlwin32.
  Fix for failures of ma_control_file-t, ma_test_loghandler_purge-t,
  ma_test_loghandler_pagecache-t on Windows.

The log handler writes to files and later does my_stat() on them so is vulnerable to this. It is a serious problem as pages of log may be missed.

How to repeat:
code review

Suggested fix:
Replace all my_stat() calls of ma_loghandler.c which make use of st_size, with:
file_size= my_seek(fd, 0, SEEK_END, MYF(...))
(careful: this moves the file's pointer).
[6 Mar 2008 14: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/43521

ChangeSet@1.2613, 2008-03-06 16:01:35+02:00, bell@desktop.sanja.is.com.ua +1 -0
  my_stat is not reliable under windows for determinating file
  length so it is replaced with my_seek. (BUG#35036)
[6 Mar 2008 18:34] 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/43545

ChangeSet@1.2613, 2008-03-06 20:33:16+02:00, bell@desktop.sanja.is.com.ua +1 -0
  Maria's usage of my_stat() is unreliable on Windows. (BUG#35036)
  %llu replaces with %s/llstr() as in other MySQL code.
[7 Mar 2008 21:33] 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/43631

ChangeSet@1.2613, 2008-03-07 23:32:04+02:00, bell@desktop.sanja.is.com.ua +1 -0
  Maria's usage of my_stat() is unreliable on Windows. (BUG#35036)
  %llu replaces with %s/llstr() as in other MySQL code.
[8 Mar 2008 9:45] 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/43641

ChangeSet@1.2613, 2008-03-08 11:44:46+02:00, bell@desktop.sanja.is.com.ua +1 -0
  Maria's usage of my_stat() is unreliable on Windows. (BUG#35036)
  %llu replaces with %s/llstr() as in other MySQL code.