diff options
Diffstat (limited to 'db/common.cpp')
-rw-r--r-- | db/common.cpp | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/db/common.cpp b/db/common.cpp index 44bc54d..0f82bef 100644 --- a/db/common.cpp +++ b/db/common.cpp @@ -1,4 +1,5 @@ -// common.cpp +// @file common.cpp + /* * Copyright (C) 2010 10gen Inc. * @@ -17,17 +18,51 @@ #include "pch.h" #include "concurrency.h" +#include "jsobjmanipulator.h" /** * this just has globals */ namespace mongo { + /** called by mongos, mongod, test. do not call from clients and such. + invoked before about everything except global var construction. + */ + void doPreServerStatupInits() { + } + /* we use new here so we don't have to worry about destructor orders at program shutdown */ - MongoMutex &dbMutex( *(new MongoMutex("rw:dbMutex")) ); + MongoMutex &dbMutex( *(new MongoMutex("dbMutex")) ); MongoMutex::MongoMutex(const char *name) : _m(name) { + static int n = 0; + assert( ++n == 1 ); // below releasingWriteLock we assume MongoMutex is a singleton, and uses dbMutex ref above _remapPrivateViewRequested = false; } + // OpTime::now() uses dbMutex, thus it is in this file not in the cpp files used by drivers and such + void BSONElementManipulator::initTimestamp() { + massert( 10332 , "Expected CurrentTime type", _element.type() == Timestamp ); + unsigned long long ×tamp = *( reinterpret_cast< unsigned long long* >( value() ) ); + if ( timestamp == 0 ) + timestamp = OpTime::now().asDate(); + } + + NOINLINE_DECL OpTime OpTime::skewed() { + bool toLog = false; + ONCE toLog = true; + RARELY toLog = true; + last.i++; + if ( last.i & 0x80000000 ) + toLog = true; + if ( toLog ) { + log() << "clock skew detected prev: " << last.secs << " now: " << (unsigned) time(0) << endl; + } + if ( last.i & 0x80000000 ) { + log() << "error large clock skew detected, shutting down" << endl; + throw ClockSkewException(); + } + return last; + } + } |