diff options
author | Antonin Kral <a.kral@bobek.cz> | 2012-05-10 06:57:54 +0200 |
---|---|---|
committer | Antonin Kral <a.kral@bobek.cz> | 2012-05-10 06:57:54 +0200 |
commit | 61619b3142c1de8f60f91964ff2656054d4f11a6 (patch) | |
tree | d3aaf9d1e70cac8efa0856e5b5ba39e2fb9dc526 /util | |
parent | eaaa7b30c99b89b5483e0a372bb73fe8c8695185 (diff) | |
download | mongodb-61619b3142c1de8f60f91964ff2656054d4f11a6.tar.gz |
Imported Upstream version 2.0.5
Diffstat (limited to 'util')
-rw-r--r-- | util/allocator.h | 2 | ||||
-rw-r--r-- | util/assert_util.h | 9 | ||||
-rw-r--r-- | util/logfile.cpp | 33 | ||||
-rw-r--r-- | util/mmap_win.cpp | 37 | ||||
-rw-r--r-- | util/version.cpp | 2 |
5 files changed, 54 insertions, 29 deletions
diff --git a/util/allocator.h b/util/allocator.h index a642e7c..23ee4ee 100644 --- a/util/allocator.h +++ b/util/allocator.h @@ -32,8 +32,6 @@ namespace mongo { } #define MONGO_malloc mongo::ourmalloc -#define malloc MONGO_malloc #define MONGO_realloc mongo::ourrealloc -#define realloc MONGO_realloc } // namespace mongo diff --git a/util/assert_util.h b/util/assert_util.h index b4c68b7..c35f651 100644 --- a/util/assert_util.h +++ b/util/assert_util.h @@ -171,20 +171,13 @@ namespace mongo { /** in the mongodb source, use verify() instead of assert(). verify is always evaluated even in release builds. */ inline void verify( int msgid , bool testOK ) { if ( ! testOK ) verifyFailed( msgid ); } -#ifdef assert -#undef assert -#endif - #define MONGO_assert(_Expression) (void)( MONGO_likely(!!(_Expression)) || (mongo::asserted(#_Expression, __FILE__, __LINE__), 0) ) -#define assert MONGO_assert /* "user assert". if asserts, user did something wrong, not our code */ #define MONGO_uassert(msgid, msg, expr) (void)( MONGO_likely(!!(expr)) || (mongo::uasserted(msgid, msg), 0) ) -#define uassert MONGO_uassert /* warning only - keeps going */ #define MONGO_wassert(_Expression) (void)( MONGO_likely(!!(_Expression)) || (mongo::wasserted(#_Expression, __FILE__, __LINE__), 0) ) -#define wassert MONGO_wassert /* display a message, no context, and throw assertionexception @@ -192,7 +185,6 @@ namespace mongo { display happening. */ #define MONGO_massert(msgid, msg, expr) (void)( MONGO_likely(!!(expr)) || (mongo::msgasserted(msgid, msg), 0) ) -#define massert MONGO_massert /* dassert is 'debug assert' -- might want to turn off for production as these could be slow. @@ -202,7 +194,6 @@ namespace mongo { #else # define MONGO_dassert(x) #endif -#define dassert MONGO_dassert // some special ids that we want to duplicate diff --git a/util/logfile.cpp b/util/logfile.cpp index 609edb8..65c56e2 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 diff --git a/util/mmap_win.cpp b/util/mmap_win.cpp index 9173d7b..71bcceb 100644 --- a/util/mmap_win.cpp +++ b/util/mmap_win.cpp @@ -20,6 +20,7 @@ #include "text.h" #include "../db/mongommf.h" #include "../db/concurrency.h" +#include "timer.h" namespace mongo { @@ -166,13 +167,39 @@ namespace mongo { scoped_lock lk(*_flushMutex); - bool success = FlushViewOfFile(_view, 0); // 0 means whole mapping - if (!success) { - int err = GetLastError(); - out() << "FlushViewOfFile failed " << err << " file: " << _filename << endl; + int loopCount = 0; + bool success = false; + bool timeout = false; + int dosError = ERROR_SUCCESS; + const int maximumLoopCount = 1000 * 1000; + const int maximumTimeInSeconds = 60; + Timer t; + while ( !success && !timeout && loopCount < maximumLoopCount ) { + ++loopCount; + success = FALSE != FlushViewOfFile( _view, 0 ); + if ( !success ) { + dosError = GetLastError(); + if ( dosError != ERROR_LOCK_VIOLATION ) { + break; + } + timeout = t.seconds() > maximumTimeInSeconds; + } + } + if ( success && loopCount > 1 ) { + log() << "FlushViewOfFile for " << _filename + << " succeeded after " << loopCount + << " attempts taking " << t.millis() + << " ms" << endl; + } + else if ( !success ) { + log() << "FlushViewOfFile for " << _filename + << " failed with error " << dosError + << " after " << loopCount + << " attempts taking " << t.millis() + << " ms" << endl; } - success = FlushFileBuffers(_fd); + success = FALSE != FlushFileBuffers(_fd); if (!success) { int err = GetLastError(); out() << "FlushFileBuffers failed " << err << " file: " << _filename << endl; diff --git a/util/version.cpp b/util/version.cpp index c644e75..8b08ff4 100644 --- a/util/version.cpp +++ b/util/version.cpp @@ -38,7 +38,7 @@ namespace mongo { * 1.2.3-rc4-pre- * If you really need to do something else you'll need to fix _versionArray() */ - const char versionString[] = "2.0.4"; + const char versionString[] = "2.0.5"; // See unit test for example outputs static BSONArray _versionArray(const char* version){ |