Bug #72597 mysqlbinlog --raw does not check for errors
Submitted: 9 May 2014 20:50 Modified: 8 Jul 2014 12:54
Reporter: Domas Mituzas Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.6, 5.6.19 OS:Any
Assigned to: CPU Architecture:Any

[9 May 2014 20:50] Domas Mituzas
Description:
mysqlbinlog --raw does not check for errors (such as EIO or ENOSPC), so it can actually end up corrupting written out binary logs without reporting any errors nor warnings nor anything.

there're two raw_mode fwrites and both don't check errors, e.g.:

      if (raw_mode)
      {
        my_fwrite(result_file, net->read_pos + 1 , len - 1, MYF(0));

How to repeat:
mysqlbinlog -R --raw

Suggested fix:
retry or fail on EIO, fail on exhausted retries, fail on ENOSPC, unless configured option to wait/retry is added.
[9 May 2014 20:52] Domas Mituzas
easy way to come up with space limited file system for a test:

mount -t tmpfs -o size=1M tmpfs ./test-mount/

strace example:

write(4, "..."..., 83) = -1 ENOSPC (No space left on device)
write(4, "..."..., 4096) = -1 ENOSPC (No space left on device)
recvfrom(3, "..."..., 16384, 0, NULL, NULL) = 11072
write(4, "...", 27) = -1 ENOSPC (No space left on device)
write(4, "..."..., 83) = -1 ENOSPC (No space left on device)
write(4, "..."..., 4096) = -1 ENOSPC (No space left on device)
write(4, "...", 27) = -1 ENOSPC (No space left on device)
write(4, "..."..., 83) = -1 ENOSPC (No space left on device)
write(4, "..."..., 763) = -1 ENOSPC (No space left on device)
write(4, "...", 27) = -1 ENOSPC (No space left on device)
write(4, "..."..., 79) = -1 ENOSPC (No space left on device)
write(4, "..."..., 2833) = -1 ENOSPC (No space left on device)
write(4, "...", 27) = -1 ENOSPC (No space left on device)
write(4, "..."..., 83) = -1 ENOSPC (No space left on device)
write(4, "..."..., 567) = -1 ENOSPC (No space left on device)
write(4, "...", 27) = -1 ENOSPC (No space left on device)
[12 May 2014 9:29] Umesh Shastry
Hello Domas,

Thank you for the report.
Verified as described.

Thanks,
Umesh
[12 May 2014 9:32] Umesh Shastry
// with 5.6.19

write(4, ",\234rS\36\352\f\0\0\367\37\0\0O\334k\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
recvfrom(3, "\370\37\0\210\0,\234rS\36\352\f\0\0\367\37\0\0F\374k\r\0\0F\0\0\0\0\0\0\0"..., 16384, 0, NULL, NULL) = 16384
write(4, ",\234rS\36\352\f\0\0\367\37\0\0F\374k\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
write(4, ",\234rS\36\352\f\0\0\367\37\0\0=\34l\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
recvfrom(3, "S\36\352\f\0\0\367\37\0\0004<l\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374CvQ"..., 8180, 0, NULL, NULL) = 8180
write(4, ",\234rS\36\352\f\0\0\367\37\0\0004<l\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
recvfrom(3, "\370\37\0\213\0,\234rS\36\352\f\0\0\367\37\0\0+\\l\r\0\0F\0\0\0\0\0\0\0"..., 16384, 0, NULL, NULL) = 16384
write(4, ",\234rS\36\352\f\0\0\367\37\0\0+\\l\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
write(4, ",\234rS\36\352\f\0\0\367\37\0\0\"|l\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
recvfrom(3, "S\36\352\f\0\0\367\37\0\0\31\234l\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374\211xQ"..., 8180, 0, NULL, NULL) = 8180
write(4, ",\234rS\36\352\f\0\0\367\37\0\0\31\234l\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
recvfrom(3, "\370\37\0\216\0,\234rS\36\352\f\0\0\367\37\0\0\20\274l\r\0\0F\0\0\0\0\0\0\0"..., 16384, 0, NULL, NULL) = 16384
write(4, ",\234rS\36\352\f\0\0\367\37\0\0\20\274l\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
write(4, ",\234rS\36\352\f\0\0\367\37\0\0\7\334l\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
recvfrom(3, "S\36\352\f\0\0\367\37\0\0\376\373l\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374\317zQ"..., 8180, 0, NULL, NULL) = 8180
write(4, ",\234rS\36\352\f\0\0\367\37\0\0\376\373l\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
recvfrom(3, "\370\37\0\221\0,\234rS\36\352\f\0\0\367\37\0\0\365\33m\r\0\0F\0\0\0\0\0\0\0"..., 16384, 0, NULL, NULL) = 16384
write(4, ",\234rS\36\352\f\0\0\367\37\0\0\365\33m\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
write(4, ",\234rS\36\352\f\0\0\367\37\0\0\354;m\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
recvfrom(3, "S\36\352\f\0\0\367\37\0\0\343[m\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374\25}Q"..., 8180, 0, NULL, NULL) = 8180
write(4, ",\234rS\36\352\f\0\0\367\37\0\0\343[m\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
recvfrom(3, "\370\37\0\224\0,\234rS\36\352\f\0\0\367\37\0\0\332{m\r\0\0F\0\0\0\0\0\0\0"..., 16384, 0, NULL, NULL) = 16384
write(4, ",\234rS\36\352\f\0\0\367\37\0\0\332{m\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
write(4, ",\234rS\36\352\f\0\0\367\37\0\0\321\233m\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
recvfrom(3, "S\36\352\f\0\0\367\37\0\0\310\273m\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374[\177Q"..., 8180, 0, NULL, NULL) = 8180
write(4, ",\234rS\36\352\f\0\0\367\37\0\0\310\273m\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
recvfrom(3, "\370\37\0\227\0,\234rS\36\352\f\0\0\367\37\0\0\277\333m\r\0\0F\0\0\0\0\0\0\0"..., 16384, 0, NULL, NULL) = 16384
write(4, ",\234rS\36\352\f\0\0\367\37\0\0\277\333m\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
write(4, ",\234rS\36\352\f\0\0\367\37\0\0\266\373m\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374"..., 4096) = -1 ENOSPC (No space left on device)
recvfrom(3, "S\36\352\f\0\0\367\37\0\0\255\33n\r\0\0F\0\0\0\0\0\0\0\2\0\2\377\374\241\201Q"..., 8180, 0, NULL, NULL) = 8180
[8 Jul 2014 12:54] Jon Stephens
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

Documented fix in the MySQL 5.6.20 and 5.7.5 changelogs as follows:

    mysqlbinlog --raw did not check for errors caused by failed writes,
    which could result in silent corruption of binary logs. Now in such
    cases it stops with an error.

Closed.      

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html