diff options
author | Andy Schwerin <schwerin@10gen.com> | 2012-03-29 16:20:45 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@10gen.com> | 2012-04-17 14:15:15 -0400 |
commit | 23a1c8019a8f25dab89a55a5f7c84dd19720adff (patch) | |
tree | 13dbf1b096bbef1225fa33e1555b422119d2b1f7 | |
parent | 829e3beaa0d55e2231a79725e44fcbd3b1cfa48a (diff) | |
download | mongo-23a1c8019a8f25dab89a55a5f7c84dd19720adff.tar.gz |
SERVER-5449: It's not an error for the write() syscall to return a non-negative value less than len.
Instead of treating it as an error for write() to return a non-negative value less than len,
keep writing in a loop until the entire buffer has been written to the log file.
-rw-r--r-- | util/logfile.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/util/logfile.cpp b/util/logfile.cpp index 609edb8fe2d..65c56e220a4 100644 --- a/util/logfile.cpp +++ b/util/logfile.cpp @@ -170,21 +170,29 @@ namespace mongo { } void LogFile::synchronousAppend(const void *b, size_t len) { + + const char *buf = static_cast<const char *>( b ); + ssize_t charsToWrite = static_cast<ssize_t>( len ); + + if (charsToWrite < 0 || _fd < 0) { + log() << "LogFile::synchronousAppend preconditions not met."; + ::abort(); + } + #ifdef POSIX_FADV_DONTNEED const off_t pos = lseek(_fd, 0, SEEK_CUR); // doesn't actually seek #endif - const char *buf = (char *) b; - assert(_fd); - assert(((size_t)buf)%4096==0); // aligned - if( len % 4096 != 0 ) { - log() << len << ' ' << len % 4096 << endl; - assert(false); - } - ssize_t written = write(_fd, buf, len); - if( written != (ssize_t) len ) { - log() << "write fails written:" << written << " len:" << len << " buf:" << buf << ' ' << errnoWithDescription() << endl; - uasserted(13515, str::stream() << "error appending to file " << _fd << ' ' << errnoWithDescription()); + while ( charsToWrite > 0 ) { + const ssize_t written = write( _fd, buf, static_cast<size_t>( charsToWrite ) ); + if ( -1 == written ) { + log() << "LogFile::synchronousAppend failed with " << charsToWrite + << " bytes unwritten out of " << len << " bytes; b=" << b << ' ' + << errnoWithDescription() << std::endl; + ::abort(); + } + buf += written; + charsToWrite -= written; } if( @@ -194,7 +202,8 @@ namespace mongo { fsync(_fd) #endif ) { - uasserted(13514, str::stream() << "error appending to file on fsync " << ' ' << errnoWithDescription()); + log() << "error appending to file on fsync " << ' ' << errnoWithDescription(); + ::abort(); } #ifdef POSIX_FADV_DONTNEED |