Bug #73365 InnoDB: 1048576 bytes should have been written, only -1 were written
Submitted: 23 Jul 2014 12:32 Modified: 10 Dec 2014 18:58
Reporter: Shahriyar Rzayev (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S1 (Critical)
Version:5.6.19 OS:Linux (CentOS 6.5)
Assigned to: CPU Architecture:Any
Triage: Needs Triage: D4 (Minor)

[23 Jul 2014 12:32] Shahriyar Rzayev
Description:
Dear experts while i am trying to reproduce my previous another bug report:

http://bugs.mysql.com/bug.php?id=72437

Exactly the issue is about full disk error.
I create a condition where in MySQL 5.6.19 with enabled GTID got a full disk error:

2014-07-23 08:10:10 2753 [Warning] Disk is full writing '/usr/local/mysql/data/mysql-bin.000010' (Errcode: 28 - No space left on device). Waiting for someone to free space...

But another thing here was:

2014-07-23 08:09:59 7f44500f0700 InnoDB: Error: Write to file ./apa_az/news.ibd failed at offset 218103808.
InnoDB: 1048576 bytes should have been written, only -1 were written.
InnoDB: Operating system error number 28.
InnoDB: Check that your OS and file system support files of this size.
InnoDB: Check also that the disk is not full or a disk quota exceeded.
InnoDB: Error number 28 means 'No space left on device'.

"1048576 bytes should have been written, only -1 were written." -> what is -1 in here?

How to repeat:
1. Installed MySQL 5.6.19 from source with debug option.
2. Enabled GTID.
3. imported a dump file which is much more in size from actual server size.
4. Got a full disk error.

Suggested fix:
As i paste in description there was two "-1" issues:
1. [Warning] Error reading GTIDs from binary log: -1
2. 048576 bytes should have been written, only -1 were written.

So "-1" is cryptic error message in both conditions maybe somewhat it is possible to change message.
Thank you.
[24 Jul 2014 16:02] David Bennett
The -1 value is an error return from the os_file_pwrite() function in storage/innobase/os/os0file.c.   This only occurs on non-Windows platforms.  On Windows the WriteFile functions _Out_opt_ lpNumberOfBytesWritten is used which will return 0 on error.  A patch is attached which will correct the error message.
[24 Jul 2014 16:06] David Bennett
Patch to fix the reported bytes written to zero on os_file_pwrite() error.

Attachment: mysql_bug_73365.patch (text/x-patch), 362 bytes.

[25 Jul 2014 7:40] Shahriyar Rzayev
Yes after applying patch message in error log changed:

InnoDB: 1048576 bytes should have been written, only 0 were written.
InnoDB: Operating system error number 28.
InnoDB: Check that your OS and file system support files of this size.
InnoDB: Check also that the disk is not full or a disk quota exceeded.
InnoDB: Error number 28 means 'No space left on device'.
InnoDB: Some operating system error numbers are described at

It was really very interesting.
Thank You.
[29 Jul 2014 18:09] Sveta Smirnova
Thank you for the report.

Verified as described: os_file_pwrite returns -1 in case if lseek fails with error or in case if pwrite fails with error (os_file_pwrite returns value of pwrite which is -1 in case of error).
[29 Jul 2014 18:11] Sveta Smirnova
David,

in order for us to accept your patch please sign Oracle Contributors Agreement as described in the "Contributions" tab.
[31 Jul 2014 5:42] David Bennett
Sveta,  You should already have one on file for me.  I contributed to the Jersey project recently.   I believe that David Delabassee approved it on April 2nd, 2014.
[10 Dec 2014 18:58] Daniel Price
Posted by developer:
 
Fixed as of the upcoming 5.6.23, 5.7.6 releases, and here's the changelog entry:

On non-Windows platforms, "os-file_pread" and "os_file_pwrite" functions
return -1 when an error occurs. This value was printed in an error message
as the number of bytes read or written. Instead of printing the -1 value
in the error message, a separate error message indicating a system call
failure is now printed. Thanks to David Bennett for the patch.
[12 Feb 2015 13:27] Laurynas Biveinis
$ git show -s ae0f4c1
commit ae0f4c17c82d1d3ee89ca5afb64655b4ab1d2552
Author: aditya.a <aditya.a@oracle.com>
Date:   Mon Dec 8 18:17:02 2014 +0530

    Bug#19315210 INNODB: 1048576 BYTES SHOULD HAVE BEEN WRITTEN, ONLY -1 WERE WRITTEN
    
    PROBLEM
    -------
    os-file_pread /os_file_pwrite functions return -1 when an error occurs and is printed
    in error message as the number of bytes read/written which is confusing to the user.
    
    FIX
    ---
    If -1 is returned print a seperate error message indicating system call failure
    
    [Approved by Jimmy #rb7475 and #rb7455 ]