summaryrefslogtreecommitdiff
path: root/src/mongo/util/logfile.cpp
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@10gen.com>2012-03-29 16:20:45 -0400
committerAndy Schwerin <schwerin@10gen.com>2012-03-29 23:11:14 -0400
commit7d069f92855e6a401cfac0efbacad6dd083c2356 (patch)
tree3b73f7d04f6688de777dc92729185bb5bfbd8773 /src/mongo/util/logfile.cpp
parentfceb1efdabfba8ee49246f96bd85f677b954b757 (diff)
downloadmongo-7d069f92855e6a401cfac0efbacad6dd083c2356.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.
Diffstat (limited to 'src/mongo/util/logfile.cpp')
-rw-r--r--src/mongo/util/logfile.cpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/mongo/util/logfile.cpp b/src/mongo/util/logfile.cpp
index d6992465936..b3f25be2253 100644
--- a/src/mongo/util/logfile.cpp
+++ b/src/mongo/util/logfile.cpp
@@ -215,21 +215,28 @@ 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 );
+
+ fassert( 16141, charsToWrite >= 0 );
+ fassert( 16142, _fd >= 0 );
+ fassert( 16143, reinterpret_cast<ssize_t>( buf ) % 4096 == 0 ); // aligned
+
#ifdef POSIX_FADV_DONTNEED
const off_t pos = lseek(_fd, 0, SEEK_CUR); // doesn't actually seek, just get current position
#endif
- const char *buf = (char *) b;
- verify(_fd);
- verify(((size_t)buf)%4096==0); // aligned
- if( len % 4096 != 0 ) {
- log() << len << ' ' << len % 4096 << endl;
- verify(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;
+ fassertFailed( 13515 );
+ }
+ buf += written;
+ charsToWrite -= written;
}
if(
@@ -239,7 +246,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();
+ fassertFailed( 13514 );
}
#ifdef POSIX_FADV_DONTNEED