diff options
Diffstat (limited to 'db')
-rw-r--r-- | db/btreecursor.cpp | 4 | ||||
-rw-r--r-- | db/cloner.cpp | 2 | ||||
-rw-r--r-- | db/cursor.cpp | 22 | ||||
-rw-r--r-- | db/database.h | 2 | ||||
-rw-r--r-- | db/db.cpp | 24 | ||||
-rw-r--r-- | db/dbcommands.cpp | 86 | ||||
-rw-r--r-- | db/dbeval.cpp | 21 | ||||
-rw-r--r-- | db/dbmessage.h | 4 | ||||
-rw-r--r-- | db/dbwebserver.cpp | 84 | ||||
-rw-r--r-- | db/flushtest.cpp | 218 | ||||
-rw-r--r-- | db/instance.cpp | 6 | ||||
-rw-r--r-- | db/instance.h | 6 | ||||
-rw-r--r-- | db/javajs.cpp | 34 | ||||
-rw-r--r-- | db/jsobj.cpp | 334 | ||||
-rw-r--r-- | db/jsobj.h | 32 | ||||
-rw-r--r-- | db/json.cpp | 202 | ||||
-rw-r--r-- | db/lasterror.h | 42 | ||||
-rw-r--r-- | db/namespace.cpp | 50 | ||||
-rw-r--r-- | db/namespace.h | 14 | ||||
-rw-r--r-- | db/pdfile.cpp | 46 | ||||
-rw-r--r-- | db/pdfile.h | 4 | ||||
-rw-r--r-- | db/query.cpp | 6 | ||||
-rw-r--r-- | db/repl.cpp | 16 | ||||
-rw-r--r-- | db/replset.h | 8 | ||||
-rw-r--r-- | db/security.cpp | 84 | ||||
-rw-r--r-- | db/security.h | 32 |
26 files changed, 723 insertions, 660 deletions
diff --git a/db/btreecursor.cpp b/db/btreecursor.cpp index 18ce967af97..b141cc24c36 100644 --- a/db/btreecursor.cpp +++ b/db/btreecursor.cpp @@ -69,8 +69,8 @@ void BtreeCursor::findExtremeKeys( const BSONObj &query ) { for ( set<string>::iterator i = fields.begin(); i != fields.end(); ++i ) { const char * field = i->c_str(); BSONElement k = indexDetails.keyPattern().getFieldDotted( field ); - int number = (int) k.number(); // returns 0.0 if not numeric - bool forward = ( ( number >= 0 ? 1 : -1 ) * direction > 0 ); + int number = (int) k.number(); // returns 0.0 if not numeric + bool forward = ( ( number >= 0 ? 1 : -1 ) * direction > 0 ); BSONElement lowest = minKey.firstElement(); BSONElement highest = maxKey.firstElement(); BSONElement e = query.getFieldDotted( field ); diff --git a/db/cloner.cpp b/db/cloner.cpp index 3f406f614a9..ddde078313e 100644 --- a/db/cloner.cpp +++ b/db/cloner.cpp @@ -137,7 +137,7 @@ bool Cloner::go(const char *masterHost, string& errmsg, const string& fromdb, bo dbtemprelease r; if ( !masterSameProcess ) { auto_ptr< DBClientConnection > c( new DBClientConnection() ); - if( !c->connect( masterHost, errmsg ) ) + if ( !c->connect( masterHost, errmsg ) ) return false; conn = c; } else { diff --git a/db/cursor.cpp b/db/cursor.cpp index ff0d132800a..3223195f412 100644 --- a/db/cursor.cpp +++ b/db/cursor.cpp @@ -30,8 +30,12 @@ class Reverse : public AdvanceStrategy { } } _reverse; -AdvanceStrategy *forward() { return &_forward; } -AdvanceStrategy *reverse() { return &_reverse; } +AdvanceStrategy *forward() { + return &_forward; +} +AdvanceStrategy *reverse() { + return &_reverse; +} DiskLoc nextLoop( NamespaceDetails *nsd, const DiskLoc &prev ) { assert( nsd->capLooped() ); @@ -50,8 +54,8 @@ DiskLoc prevLoop( NamespaceDetails *nsd, const DiskLoc &curr ) { } ForwardCappedCursor::ForwardCappedCursor( NamespaceDetails *_nsd ) : - BasicCursor( DiskLoc(), this ), - nsd( _nsd ) { + BasicCursor( DiskLoc(), this ), + nsd( _nsd ) { if ( !nsd ) return; DiskLoc start; @@ -79,18 +83,18 @@ DiskLoc ForwardCappedCursor::next( const DiskLoc &prev ) const { i = nextLoop( nsd, i ); // If we become capFirstNewRecord from same extent, advance to next extent. if ( i == nsd->capFirstNewRecord && - i != nsd->capExtent.ext()->firstRecord ) + i != nsd->capExtent.ext()->firstRecord ) i = nextLoop( nsd, nsd->capExtent.ext()->lastRecord ); // If we have just gotten to beginning of capExtent, skip to capFirstNewRecord if ( i == nsd->capExtent.ext()->firstRecord ) i = nsd->capFirstNewRecord; - + return i; } ReverseCappedCursor::ReverseCappedCursor( NamespaceDetails *_nsd ) : - BasicCursor( DiskLoc(), this ), - nsd( _nsd ) { + BasicCursor( DiskLoc(), this ), + nsd( _nsd ) { if ( !nsd ) return; DiskLoc start; @@ -105,7 +109,7 @@ DiskLoc ReverseCappedCursor::next( const DiskLoc &prev ) const { assert( nsd ); if ( !nsd->capLooped() ) return reverse()->next( prev ); - + DiskLoc i = prev; // Last record if ( nsd->capFirstNewRecord == nsd->capExtent.ext()->firstRecord ) { diff --git a/db/database.h b/db/database.h index 32e92bb76a9..47bffbd62a6 100644 --- a/db/database.h +++ b/db/database.h @@ -28,7 +28,7 @@ class Database { public: Database(const char *nm, bool& justCreated, const char *_path = dbpath) : name(nm), - path(_path) + path(_path) { { int L = strlen(nm); diff --git a/db/db.cpp b/db/db.cpp index cce208374fa..47d66601806 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -143,7 +143,7 @@ public: } // namespace mongo #include "lasterror.h" -#include "security.h" +#include "security.h" namespace mongo { @@ -196,7 +196,7 @@ void connThread() problem() << "Uncaught AssertionException, terminating" << endl; exit(15); } - catch( std::exception &e ) { + catch ( std::exception &e ) { problem() << "Uncaught std::exception: " << e.what() << ", terminating" << endl; exit( 15 ); } @@ -254,7 +254,7 @@ void repairDatabases() { dblock lk; vector< string > dbNames; getDatabaseNames( dbNames ); - for( vector< string >::iterator i = dbNames.begin(); i != dbNames.end(); ++i ) { + for ( vector< string >::iterator i = dbNames.begin(); i != dbNames.end(); ++i ) { string dbName = *i; assert( !setClientTempNs( dbName.c_str() ) ); PhysicalDataFile *p = database->getFile( 0 ); @@ -262,7 +262,7 @@ void repairDatabases() { if ( !h->currentVersion() ) { // QUESTION: Repair even if file format is higher version than code? log() << "repairing database " << dbName << " with pdfile version " << h->version << "." << h->versionMinor << ", " - << "new version: " << VERSION << "." << VERSION_MINOR << endl; + << "new version: " << VERSION << "." << VERSION_MINOR << endl; string errmsg; assert( repairDatabase( dbName.c_str(), errmsg ) ); } else { @@ -274,12 +274,12 @@ void repairDatabases() { void clearTmpFiles() { boost::filesystem::path path( dbpath ); for ( boost::filesystem::directory_iterator i( path ); - i != boost::filesystem::directory_iterator(); ++i ) { + i != boost::filesystem::directory_iterator(); ++i ) { string fileName = i->leaf(); if ( boost::filesystem::is_directory( *i ) && - fileName.length() > 2 && fileName.substr( 0, 3 ) == "tmp" ) + fileName.length() > 2 && fileName.substr( 0, 3 ) == "tmp" ) boost::filesystem::remove_all( *i ); - } + } } Timer startupSrandTimer; @@ -287,7 +287,7 @@ Timer startupSrandTimer; void segvhandler(int x); void initAndListen(int listenPort, const char *appserverLoc = null) { clearTmpFiles(); - + if ( opLogging ) log() << "opLogging = " << opLogging << endl; _oplog.init(); @@ -336,7 +336,7 @@ int main(int argc, char* argv[], char *envp[] ) { srand(curTimeMillis()); boost::filesystem::path::default_name_check( boost::filesystem::no_check ); - + { unsigned x = 0x12345678; unsigned char& b = (unsigned char&) x; @@ -439,8 +439,8 @@ int main(int argc, char* argv[], char *envp[] ) goto usage; else if ( s == "--quiet" ) quiet = true; - else if( s == "--cpu" ) - cpu = true; + else if ( s == "--cpu" ) + cpu = true; else if ( s == "--verbose" ) verbose = true; else if ( s == "--quota" ) @@ -497,7 +497,7 @@ usage: cout << " --port <portno> specify port number, default is 27017\n"; cout << " --dbpath <root> directory for datafiles, default is /data/db/\n"; cout << " --quiet quieter output\n"; - cout << " --cpu show cpu+iowait utilization periodically\n"; + cout << " --cpu show cpu+iowait utilization periodically\n"; cout << " --verbose\n"; cout << " --objcheck inspect client data for validity on receipt\n"; cout << " --quota enable db quota management\n"; diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp index dc6f7dcb206..a466db6256e 100644 --- a/db/dbcommands.cpp +++ b/db/dbcommands.cpp @@ -182,14 +182,18 @@ string validateNS(const char *ns, NamespaceDetails *d) { /* reset any errors so that getlasterror comes back clean. - useful before performing a long series of operations where we want to - see if any of the operations triggered an error, but don't want to check + useful before performing a long series of operations where we want to + see if any of the operations triggered an error, but don't want to check after each op as that woudl be a client/server turnaround. */ -class CmdResetError : public Command { +class CmdResetError : public Command { public: - virtual bool logTheOp() { return false; } - virtual bool slaveOk() { return true; } + virtual bool logTheOp() { + return false; + } + virtual bool slaveOk() { + return true; + } CmdResetError() : Command("reseterror") {} bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) { LastError *le = lastError.get(); @@ -199,16 +203,20 @@ public: } } cmdResetError; -class CmdGetLastError : public Command { +class CmdGetLastError : public Command { public: - virtual bool logTheOp() { return false; } - virtual bool slaveOk() { return true; } + virtual bool logTheOp() { + return false; + } + virtual bool slaveOk() { + return true; + } CmdGetLastError() : Command("getlasterror") {} bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) { LastError *le = lastError.get(); assert( le ); le->nPrev--; // we don't count as an operation - if( le->nPrev != 1 || !le->haveError() ) { + if ( le->nPrev != 1 || !le->haveError() ) { result.appendNull("err"); return true; } @@ -218,10 +226,14 @@ public: } cmdGetLastError; /* for testing purposes only */ -class CmdForceError : public Command { +class CmdForceError : public Command { public: - virtual bool logTheOp() { return false; } - virtual bool slaveOk() { return true; } + virtual bool logTheOp() { + return false; + } + virtual bool slaveOk() { + return true; + } CmdForceError() : Command("forceerror") {} bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) { uassert("forced error", false); @@ -229,16 +241,20 @@ public: } } cmdForceError; -class CmdGetPrevError : public Command { +class CmdGetPrevError : public Command { public: - virtual bool logTheOp() { return false; } - virtual bool slaveOk() { return true; } + virtual bool logTheOp() { + return false; + } + virtual bool slaveOk() { + return true; + } CmdGetPrevError() : Command("getpreverror") {} bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) { LastError *le = lastError.get(); assert( le ); le->nPrev--; // we don't count as an operation - if( !le->haveError() ) { + if ( !le->haveError() ) { result.appendNull("err"); result.append("nPrev", 1); return true; @@ -389,8 +405,8 @@ public: bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) { opLogging = (int) cmdObj.findElement(name).number(); flushOpLog(); - if( !quiet ) - log() << "CMD: opLogging set to " << opLogging << endl; + if ( !quiet ) + log() << "CMD: opLogging set to " << opLogging << endl; return true; } } cmdoplogging; @@ -411,8 +427,8 @@ public: virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) { string nsToDrop = database->name + '.' + cmdObj.findElement(name).valuestr(); NamespaceDetails *d = nsdetails(nsToDrop.c_str()); - if( !quiet ) - log() << "CMD: drop " << nsToDrop << endl; + if ( !quiet ) + log() << "CMD: drop " << nsToDrop << endl; if ( d == 0 ) { errmsg = "ns not found"; return false; @@ -526,8 +542,8 @@ public: BSONElement e = jsobj.findElement(name.c_str()); string toDeleteNs = database->name + '.' + e.valuestr(); NamespaceDetails *d = nsdetails(toDeleteNs.c_str()); - if( !quiet ) - log() << "CMD: deleteIndexes " << toDeleteNs << endl; + if ( !quiet ) + log() << "CMD: deleteIndexes " << toDeleteNs << endl; if ( d ) { BSONElement f = jsobj.findElement("index"); if ( !f.eoo() ) { @@ -584,15 +600,21 @@ public: class CmdListDatabases : public Command { public: - virtual bool logTheOp() { return false; } - virtual bool slaveOk() { return true; } - virtual bool adminOnly() { return true; } + virtual bool logTheOp() { + return false; + } + virtual bool slaveOk() { + return true; + } + virtual bool adminOnly() { + return true; + } CmdListDatabases() : Command("listDatabases") {} bool run(const char *ns, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool /*fromRepl*/) { vector< string > dbNames; getDatabaseNames( dbNames ); vector< BSONObj > dbInfos; - for( vector< string >::iterator i = dbNames.begin(); i != dbNames.end(); ++i ) { + for ( vector< string >::iterator i = dbNames.begin(); i != dbNames.end(); ++i ) { BSONObjBuilder b; b.append( "name", i->c_str() ); b.append( "sizeOnDisk", (double) dbSize( i->c_str() ) ); @@ -613,8 +635,8 @@ extern map<string,Command*> *commands; returns true if ran a cmd */ bool _runCommands(const char *ns, BSONObj& _cmdobj, stringstream& ss, BufBuilder &b, BSONObjBuilder& anObjBuilder, bool fromRepl) { - if( verbose ) - log() << "run command " << ns << ' ' << _cmdobj.toString() << endl; + if ( verbose ) + log() << "run command " << ns << ' ' << _cmdobj.toString() << endl; const char *p = strchr(ns, '.'); if ( !p ) return false; @@ -674,8 +696,8 @@ bool _runCommands(const char *ns, BSONObj& _cmdobj, stringstream& ss, BufBuilder valid = true; string dropNs = us + '.' + e.valuestr(); NamespaceDetails *d = nsdetails(dropNs.c_str()); - if( !quiet ) - log() << "CMD: clean " << dropNs << endl; + if ( !quiet ) + log() << "CMD: clean " << dropNs << endl; if ( d ) { ok = true; anObjBuilder.append("ns", dropNs.c_str()); @@ -689,8 +711,8 @@ bool _runCommands(const char *ns, BSONObj& _cmdobj, stringstream& ss, BufBuilder valid = true; string toValidateNs = us + '.' + e.valuestr(); NamespaceDetails *d = nsdetails(toValidateNs.c_str()); - if( !quiet ) - log() << "CMD: validate " << toValidateNs << endl; + if ( !quiet ) + log() << "CMD: validate " << toValidateNs << endl; if ( d ) { ok = true; anObjBuilder.append("ns", toValidateNs.c_str()); diff --git a/db/dbeval.cpp b/db/dbeval.cpp index 3620211e6f7..de05394d10a 100644 --- a/db/dbeval.cpp +++ b/db/dbeval.cpp @@ -38,13 +38,18 @@ const int edebug=0; bool dbEval(const char *ns, BSONObj& cmd, BSONObjBuilder& result, string& errmsg) { BSONElement e = cmd.firstElement(); assert( e.type() == Code || e.type() == CodeWScope || e.type() == String ); - + const char *code = 0; - switch ( e.type() ){ - case String: - case Code: code = e.valuestr(); break; - case CodeWScope: code = e.codeWScopeCode(); break; - default: assert(0); + switch ( e.type() ) { + case String: + case Code: + code = e.valuestr(); + break; + case CodeWScope: + code = e.codeWScopeCode(); + break; + default: + assert(0); } assert( code ); @@ -80,7 +85,7 @@ bool dbEval(const char *ns, BSONObj& cmd, BSONObjBuilder& result, string& errmsg res = s.invoke(f); int m = t.millis(); if ( m > 100 ) { - stdcout() << "TEMP: dbeval too slow:" << endl; + stdcout() << "TEMP: dbeval too slow:" << endl; problem() << "dbeval time: " << dec << m << "ms " << ns << endl; OCCASIONALLY log() << code << endl; else if ( m >= 1000 ) log() << code << endl; @@ -92,7 +97,7 @@ bool dbEval(const char *ns, BSONObj& cmd, BSONObjBuilder& result, string& errmsg errmsg += s.getString( "error" ); return false; } - + int type = s.type("return"); if ( type == Object || type == Array ) result.append("retval", s.getObject("return")); diff --git a/db/dbmessage.h b/db/dbmessage.h index 9bbd989d2b1..2a5f78842d9 100644 --- a/db/dbmessage.h +++ b/db/dbmessage.h @@ -162,8 +162,8 @@ inline void replyToQuery(int queryResultFlags, BSONObj& responseObj) { replyToQuery(queryResultFlags, - p, requestMsg, - (void *) responseObj.objdata(), responseObj.objsize(), 1); + p, requestMsg, + (void *) responseObj.objdata(), responseObj.objsize(), 1); } } // namespace mongo diff --git a/db/dbwebserver.cpp b/db/dbwebserver.cpp index eaa7128cefd..26405150282 100644 --- a/db/dbwebserver.cpp +++ b/db/dbwebserver.cpp @@ -162,13 +162,13 @@ public: ) { //cout << "url [" << url << "]" << endl; - - if ( url.size() > 1 ){ + + if ( url.size() > 1 ) { handleRESTRequest( rq , url , responseMsg , responseCode , headers ); return; } - - + + responseCode = 200; stringstream ss; ss << "<html><head><title>"; @@ -204,33 +204,33 @@ public: ss << "</pre></body></html>"; responseMsg = ss.str(); } - + void handleRESTRequest( const char *rq, // the full request string url, string& responseMsg, int& responseCode, vector<string>& headers // if completely empty, content-type: text/html will be added - ){ - + ) { + string::size_type first = url.find( "/" , 1 ); - if ( first == string::npos ){ + if ( first == string::npos ) { responseCode = 400; return; } - + string method = parseMethod( rq ); string dbname = url.substr( 1 , first - 1 ); string coll = url.substr( first + 1 ); string action = ""; - + map<string,string> params; - if ( coll.find( "?" ) != string::npos ){ + if ( coll.find( "?" ) != string::npos ) { parseParams( params , coll.substr( coll.find( "?" ) + 1 ) ); coll = coll.substr( 0 , coll.find( "?" ) ); } - - string::size_type last = coll.find_last_of( "/" ); - if ( last == string::npos ){ + + string::size_type last = coll.find_last_of( "/" ); + if ( last == string::npos ) { action = coll; coll = "_defaultCollection"; } @@ -238,24 +238,24 @@ public: action = coll.substr( last + 1 ); coll = coll.substr( 0 , last ); } - + for ( string::size_type i=0; i<coll.size(); i++ ) if ( coll[i] == '/' ) coll[i] = '.'; - + string fullns = dbname + "." + coll; - + headers.push_back( (string)"x-action: " + action ); headers.push_back( (string)"x-ns: " + fullns ); headers.push_back( "Content-Type: text/plain;charset=utf-8" ); - + stringstream ss; - - if ( method == "GET" ){ + + if ( method == "GET" ) { responseCode = 200; handleRESTQuery( fullns , action , params , responseCode , ss ); } - else if ( method == "POST" ){ + else if ( method == "POST" ) { responseCode = 201; handlePost( fullns , body( rq ) , params , responseCode , ss ); } @@ -265,47 +265,47 @@ public: ss << "don't know how to handle a [" << method << "]"; cout << "don't know how to handle a [" << method << "]" << endl; } - + responseMsg = ss.str(); } - void handleRESTQuery( string ns , string action , map<string,string> & params , int & responseCode , stringstream & out ){ + void handleRESTQuery( string ns , string action , map<string,string> & params , int & responseCode , stringstream & out ) { Timer t; - + int skip = _getOption( params["skip"] , 0 ); int num = _getOption( params["limit"] , _getOption( params["count" ] , 1000 ) ); // count is old, limit is new int one = 0; - if ( params["one"].size() > 0 && tolower( params["one"][0] ) == 't' ){ + if ( params["one"].size() > 0 && tolower( params["one"][0] ) == 't' ) { num = 1; one = 1; } - + BSONObjBuilder queryBuilder; - - for ( map<string,string>::iterator i = params.begin(); i != params.end(); i++ ){ + + for ( map<string,string>::iterator i = params.begin(); i != params.end(); i++ ) { if ( ! i->first.find( "filter_" ) == 0 ) continue; - + const char * field = i->first.substr( 7 ).c_str(); const char * val = i->second.c_str(); char * temp; - + // TODO: this is how i guess if something is a number. pretty lame right now double number = strtod( val , &temp ); if ( temp != val ) queryBuilder.append( field , number ); - else + else queryBuilder.append( field , val ); } BSONObj query = queryBuilder.doneAndDecouple(); auto_ptr<DBClientCursor> cursor = db.query( ns.c_str() , query, num , skip ); - - if ( one ){ - if ( cursor->more() ){ + + if ( one ) { + if ( cursor->more() ) { BSONObj obj = cursor->next(); out << obj.jsonString() << "\n"; } @@ -318,17 +318,17 @@ public: out << "{\n"; out << " \"offset\" : " << skip << ",\n"; out << " \"rows\": [\n"; - + int howMany = 0; - while ( cursor->more() ){ + while ( cursor->more() ) { if ( howMany++ ) out << " ,\n"; BSONObj obj = cursor->next(); out << " " << obj.jsonString(); - + } out << "\n ]\n\n"; - + out << " \"total_rows\" : " << howMany << " ,\n"; out << " \"query\" : " << query.jsonString() << " ,\n"; out << " \"millis\" : " << t.millis() << " ,\n"; @@ -336,7 +336,7 @@ public: } // TODO Generate id and revision per couch POST spec - void handlePost( string ns, const char *body, map<string,string> & params, int & responseCode, stringstream & out ){ + void handlePost( string ns, const char *body, map<string,string> & params, int & responseCode, stringstream & out ) { try { BSONObj obj = fromjson( body ); db.insert( ns.c_str(), obj ); @@ -345,17 +345,17 @@ public: out << "{ \"ok\" : false }"; return; } - + responseCode = 201; out << "{ \"ok\" : true }"; } - int _getOption( string val , int def ){ + int _getOption( string val , int def ) { if ( val.size() == 0 ) return def; return atoi( val.c_str() ); } - + private: static DBDirectClient db; }; diff --git a/db/flushtest.cpp b/db/flushtest.cpp index 64911a7e9a3..1c153df5c8e 100644 --- a/db/flushtest.cpp +++ b/db/flushtest.cpp @@ -10,125 +10,129 @@ namespace mongo { #undef endl #if defined(F_FULLFSYNC) -void fullsync(int f) { fcntl( f, F_FULLFSYNC ); } +void fullsync(int f) { + fcntl( f, F_FULLFSYNC ); +} #else -void fullsync(int f) { fdatasync(f); } +void fullsync(int f) { + fdatasync(f); +} #endif int main(int argc, char* argv[], char *envp[] ) { - cout << "hello" << endl; + cout << "hello" << endl; + + FILE *f = fopen("/data/db/temptest", "a"); + + if ( f == 0 ) { + cout << "can't open file\n"; + return 1; + } - FILE *f = fopen("/data/db/temptest", "a"); + { + Timer t; + for ( int i = 0; i < 50000; i++ ) + fwrite("abc", 3, 1, f); + cout << "small writes: " << t.millis() << "ms" << endl; + } - if( f == 0 ) { - cout << "can't open file\n"; - return 1; - } + { + Timer t; + for ( int i = 0; i < 10000; i++ ) { + fwrite("abc", 3, 1, f); + fflush(f); + fsync( fileno( f ) ); + } + int ms = t.millis(); + cout << "flush: " << ms << "ms, " << ms / 10000.0 << "ms/request" << endl; + } - { - Timer t; - for( int i = 0; i < 50000; i++ ) - fwrite("abc", 3, 1, f); - cout << "small writes: " << t.millis() << "ms" << endl; - } - - { - Timer t; - for( int i = 0; i < 10000; i++ ) { - fwrite("abc", 3, 1, f); - fflush(f); - fsync( fileno( f ) ); - } - int ms = t.millis(); - cout << "flush: " << ms << "ms, " << ms / 10000.0 << "ms/request" << endl; - } + { + Timer t; + for ( int i = 0; i < 500; i++ ) { + fwrite("abc", 3, 1, f); + fflush(f); + fsync( fileno( f ) ); + sleepmillis(2); + } + int ms = t.millis() - 500 * 2; + cout << "flush with sleeps: " << ms << "ms, " << ms / 500.0 << "ms/request" << endl; + } - { - Timer t; - for( int i = 0; i < 500; i++ ) { - fwrite("abc", 3, 1, f); - fflush(f); - fsync( fileno( f ) ); - sleepmillis(2); - } - int ms = t.millis() - 500 * 2; - cout << "flush with sleeps: " << ms << "ms, " << ms / 500.0 << "ms/request" << endl; - } + char buf[8192]; + for ( int pass = 0; pass < 2; pass++ ) { + cout << "pass " << pass << endl; + { + Timer t; + int n = 500; + for ( int i = 0; i < n; i++ ) { + if ( pass == 0 ) + fwrite("abc", 3, 1, f); + else + fwrite(buf, 8192, 1, f); + buf[0]++; + fflush(f); + fullsync(fileno(f)); + } + int ms = t.millis(); + cout << "fullsync: " << ms << "ms, " << ms / ((double) n) << "ms/request" << endl; + } - char buf[8192]; - for( int pass = 0; pass < 2; pass++ ) { - cout << "pass " << pass << endl; - { - Timer t; - int n = 500; - for( int i = 0; i < n; i++ ) { - if( pass == 0 ) - fwrite("abc", 3, 1, f); - else - fwrite(buf, 8192, 1, f); - buf[0]++; - fflush(f); - fullsync(fileno(f)); - } - int ms = t.millis(); - cout << "fullsync: " << ms << "ms, " << ms / ((double) n) << "ms/request" << endl; - } + { + Timer t; + for ( int i = 0; i < 500; i++ ) { + if ( pass == 0 ) + fwrite("abc", 3, 1, f); + else + fwrite(buf, 8192, 1, f); + buf[0]++; + fflush(f); + fullsync(fileno(f)); + sleepmillis(2); + } + int ms = t.millis() - 2 * 500; + cout << "fullsync with sleeps: " << ms << "ms, " << ms / 500.0 << "ms/request" << endl; + } + } - { - Timer t; - for( int i = 0; i < 500; i++ ) { - if( pass == 0 ) - fwrite("abc", 3, 1, f); - else - fwrite(buf, 8192, 1, f); - buf[0]++; - fflush(f); - fullsync(fileno(f)); - sleepmillis(2); - } - int ms = t.millis() - 2 * 500; - cout << "fullsync with sleeps: " << ms << "ms, " << ms / 500.0 << "ms/request" << endl; - } - } + // without growing + { + fclose(f); + /* try from beginning of the file, where we aren't appending and changing the file length, + to see if this is faster as the directory entry then doesn't have to be flushed (if noatime in effect). + */ + f = fopen("/data/db/temptest", "r+"); + Timer t; + int n = 500; + for ( int i = 0; i < n; i++ ) { + fwrite("xyz", 3, 1, f); + fflush(f); + fullsync(fileno(f)); + } + int ms = t.millis(); + cout << "fullsync without growing: " << ms << "ms, " << ms / ((double) n) << "ms/request" << endl; + } - // without growing - { - fclose(f); - /* try from beginning of the file, where we aren't appending and changing the file length, - to see if this is faster as the directory entry then doesn't have to be flushed (if noatime in effect). - */ - f = fopen("/data/db/temptest", "r+"); - Timer t; - int n = 500; - for( int i = 0; i < n; i++ ) { - fwrite("xyz", 3, 1, f); - fflush(f); - fullsync(fileno(f)); - } - int ms = t.millis(); - cout << "fullsync without growing: " << ms << "ms, " << ms / ((double) n) << "ms/request" << endl; - } + // without growing, with delay + { + fclose(f); + /* try from beginning of the file, where we aren't appending and changing the file length, + to see if this is faster as the directory entry then doesn't have to be flushed (if noatime in effect). + */ + f = fopen("/data/db/temptest", "r+"); + Timer t; + int n = 500; + for ( int i = 0; i < n; i++ ) { + fwrite("xyz", 3, 1, f); + fflush(f); + fullsync(fileno(f)); + sleepmillis(2); + } + int ms = t.millis() - 2 * 500; + cout << "fullsync without growing with sleeps: " << ms << "ms, " << ms / ((double) n) << "ms/request" << endl; + } - // without growing, with delay - { - fclose(f); - /* try from beginning of the file, where we aren't appending and changing the file length, - to see if this is faster as the directory entry then doesn't have to be flushed (if noatime in effect). - */ - f = fopen("/data/db/temptest", "r+"); - Timer t; - int n = 500; - for( int i = 0; i < n; i++ ) { - fwrite("xyz", 3, 1, f); - fflush(f); - fullsync(fileno(f)); - sleepmillis(2); - } - int ms = t.millis() - 2 * 500; - cout << "fullsync without growing with sleeps: " << ms << "ms, " << ms / ((double) n) << "ms/request" << endl; - } - - return 0; + return 0; } } // namespace mongo diff --git a/db/instance.cpp b/db/instance.cpp index d3a18daae2c..40cb435a288 100644 --- a/db/instance.cpp +++ b/db/instance.cpp @@ -488,14 +488,14 @@ void jniCallback(Message& m, Message& out) void getDatabaseNames( vector< string > &names ) { boost::filesystem::path path( dbpath ); for ( boost::filesystem::directory_iterator i( path ); - i != boost::filesystem::directory_iterator(); ++i ) { + i != boost::filesystem::directory_iterator(); ++i ) { string fileName = i->leaf(); if ( fileName.length() > 3 && fileName.substr( fileName.length() - 3, 3 ) == ".ns" ) names.push_back( fileName.substr( 0, fileName.length() - 3 ) ); } } -bool DBDirectClient::call( Message &toSend, Message &response, bool assertOk ){ +bool DBDirectClient::call( Message &toSend, Message &response, bool assertOk ) { DbResponse dbResponse; assembleResponse( toSend, dbResponse ); assert( dbResponse.response ); @@ -505,7 +505,7 @@ bool DBDirectClient::call( Message &toSend, Message &response, bool assertOk ){ void DBDirectClient::say( Message &toSend ) { DbResponse dbResponse; - assembleResponse( toSend, dbResponse ); + assembleResponse( toSend, dbResponse ); } /* not using log() herein in case we are called from segvhandler and we were already locked */ diff --git a/db/instance.h b/db/instance.h index 28f90171392..52bba249637 100644 --- a/db/instance.h +++ b/db/instance.h @@ -93,10 +93,12 @@ void getDatabaseNames( vector< string > &names ); // --- local client --- class DBDirectClient : public DBClientBase { - virtual string toString() { return "DBDirectClient"; } + virtual string toString() { + return "DBDirectClient"; + } virtual bool call( Message &toSend, Message &response, bool assertOk=true ); virtual void say( Message &toSend ); - virtual void sayPiggyBack( Message &toSend ){ + virtual void sayPiggyBack( Message &toSend ) { // don't need to piggy back when connected locally return say( toSend ); } diff --git a/db/javajs.cpp b/db/javajs.cpp index b508d8da7cc..97194359db2 100644 --- a/db/javajs.cpp +++ b/db/javajs.cpp @@ -115,50 +115,50 @@ JavaJSImpl::JavaJSImpl(const char *appserverPath) { _jvm = 0; _mainEnv = 0; _dbhook = 0; - + stringstream ss; string edTemp; - + const char * ed = 0; ss << "-Djava.class.path=."; - - if ( appserverPath ){ + + if ( appserverPath ) { ed = findEd(appserverPath); assert( ed ); ss << SYSTEM_COLON << ed << "/build/"; - + _addClassPath( ed , ss , "include" ); _addClassPath( ed , ss , "include/jython/" ); _addClassPath( ed , ss , "include/jython/javalib" ); } else { - + const char * jars = findJars(); _addClassPath( jars , ss , "jars" ); - + edTemp += (string)jars + "/jars/babble.jar"; ed = edTemp.c_str(); #if !defined(_WIN32) const char * otherEd = findEd(); - if ( otherEd ){ + if ( otherEd ) { log() << "found ed as well" << endl; ed = otherEd; ss << SYSTEM_COLON << ed << "/build/"; - + _addClassPath( ed , ss , "include" ); _addClassPath( ed , ss , "include/jython/" ); - _addClassPath( ed , ss , "include/jython/javalib" ); + _addClassPath( ed , ss , "include/jython/javalib" ); } - + #endif } - + #if defined(_WIN32) ss << SYSTEM_COLON << "C:\\Program Files\\Java\\jdk\\lib\\tools.jar"; #else @@ -217,13 +217,13 @@ JavaJSImpl::JavaJSImpl(const char *appserverPath) { _envs->reset( _mainEnv ); _dbhook = findClass( "ed/db/JSHook" ); - if ( _dbhook == 0 ){ + if ( _dbhook == 0 ) { log() << "using classpath: " << q << endl; printException(); } jassert( _dbhook ); - if ( ed ){ + if ( ed ) { jmethodID init = _mainEnv->GetStaticMethodID( _dbhook , "init" , "(Ljava/lang/String;)V" ); jassert( init ); _mainEnv->CallStaticVoidMethod( _dbhook , init , _getEnv()->NewStringUTF( ed ) ); @@ -562,14 +562,14 @@ const char * findEd() { #endif }; -const char * findJars(){ +const char * findJars() { static list<const char*> possible; if ( ! possible.size() ) { possible.push_back( "./" ); possible.push_back( "../" ); } - + for ( list<const char*>::iterator i = possible.begin() ; i != possible.end(); i++ ) { const char * temp = *i; const string jarDir = ((string)temp) + "jars/"; @@ -610,7 +610,7 @@ JNIEXPORT jint JNICALL java_native_call(JNIEnv * env , jclass, jobject outBuffer jniCallback( out , in ); curNs = 0; - + JNI_DEBUG( "in.data : " << in.data ); if ( in.data && in.data->len > 0 ) { JNI_DEBUG( "copying data of len :" << in.data->len ); diff --git a/db/jsobj.cpp b/db/jsobj.cpp index 9a4e7dcbc71..c97f316b13b 100644 --- a/db/jsobj.cpp +++ b/db/jsobj.cpp @@ -114,182 +114,182 @@ string BSONElement::toString() const { string escape( string s ) { stringstream ret; - for( string::iterator i = s.begin(); i != s.end(); ++i ) { - switch( *i ) { - case '"': - ret << "\\\""; - break; - case '\\': - ret << "\\\\"; - break; - case '/': - ret << "\\/"; - break; - case '\b': - ret << "\\b"; - break; - case '\f': - ret << "\\f"; - break; - case '\n': - ret << "\\n"; - break; - case '\r': - ret << "\\r"; - break; - case '\t': - ret << "\\t"; - break; - default: - if ( *i >= 0 && *i <= 0x1f ) { - ret << "\\u"; - ret << hex; - ret.width( 4 ); - ret.fill( '0' ); - ret << int( *i ); - } else { - ret << *i; - } + for ( string::iterator i = s.begin(); i != s.end(); ++i ) { + switch ( *i ) { + case '"': + ret << "\\\""; + break; + case '\\': + ret << "\\\\"; + break; + case '/': + ret << "\\/"; + break; + case '\b': + ret << "\\b"; + break; + case '\f': + ret << "\\f"; + break; + case '\n': + ret << "\\n"; + break; + case '\r': + ret << "\\r"; + break; + case '\t': + ret << "\\t"; + break; + default: + if ( *i >= 0 && *i <= 0x1f ) { + ret << "\\u"; + ret << hex; + ret.width( 4 ); + ret.fill( '0' ); + ret << int( *i ); + } else { + ret << *i; + } } } return ret.str(); } typedef boost::archive::iterators::base64_from_binary - < boost::archive::iterators::transform_width - < string::const_iterator, 6, 8 > - > base64_t; +< boost::archive::iterators::transform_width +< string::const_iterator, 6, 8 > +> base64_t; string BSONElement::jsonString( JsonStringFormat format, bool includeFieldNames ) const { stringstream s; if ( includeFieldNames ) - s << '"' << escape( fieldName() ) << "\" : "; + s << '"' << escape( fieldName() ) << "\" : "; switch ( type() ) { - case String: - case Symbol: - s << '"' << escape( valuestr() ) << '"'; - break; - case NumberInt: - case NumberDouble: - if ( number() >= -numeric_limits< double >::max() && + case String: + case Symbol: + s << '"' << escape( valuestr() ) << '"'; + break; + case NumberInt: + case NumberDouble: + if ( number() >= -numeric_limits< double >::max() && number() <= numeric_limits< double >::max() ) { - s.precision( 16 ); - s << number(); - } else { - stringstream ss; - ss << "Number " << number() << " cannot be represented in JSON"; - string message = ss.str(); - massert( message.c_str(), false ); - } - break; - case Bool: - s << ( boolean() ? "true" : "false" ); - break; - case jstNULL: - s << "null"; - break; - case Object: - s << embeddedObject().jsonString( format ); - break; - case Array: { - if ( embeddedObject().isEmpty() ) { - s << "[]"; - break; - } - s << "[ "; - BSONObjIterator i( embeddedObject() ); - BSONElement e = i.next(); - if ( !e.eoo() ) - while ( 1 ) { - s << e.jsonString( format, false ); - e = i.next(); - if ( e.eoo() ) - break; - s << ", "; - } - s << " ]"; - break; - } - case DBRef: { - OID *x = (OID *) (valuestr() + valuestrsize()); - if ( format == TenGen ) - s << "Dbref( "; - else - s << "{ \"$ns\" : "; - s << '"' << valuestr() << "\", "; - if ( format != TenGen ) - s << "\"$id\" : "; - s << '"' << *x << "\" "; - if ( format == TenGen ) - s << ')'; - else - s << '}'; - break; + s.precision( 16 ); + s << number(); + } else { + stringstream ss; + ss << "Number " << number() << " cannot be represented in JSON"; + string message = ss.str(); + massert( message.c_str(), false ); } - case jstOID: - if ( format == TenGen ) - s << "ObjectId( "; - s << '"' << oid() << '"'; - if ( format == TenGen ) - s << " )"; - break; - case BinData: { - int len = *(int *)( value() ); - BinDataType type = BinDataType( *(char *)( (int *)( value() ) + 1 ) ); - s << "{ \"$binary\" : \""; - char *start = ( char * )( value() ) + sizeof( int ) + 1; - string temp(start, len); - string base64 = string( base64_t( temp.begin() ), base64_t( temp.end() ) ); - s << base64; - int padding = ( 4 - ( base64.length() % 4 ) ) % 4; - for( int i = 0; i < padding; ++i ) - s << '='; - s << "\", \"$type\" : \"" << hex; - s.width( 2 ); - s.fill( '0' ); - s << type << dec; - s << "\" }"; + break; + case Bool: + s << ( boolean() ? "true" : "false" ); + break; + case jstNULL: + s << "null"; + break; + case Object: + s << embeddedObject().jsonString( format ); + break; + case Array: { + if ( embeddedObject().isEmpty() ) { + s << "[]"; break; } - case Date: - if ( format == Strict ) - s << "{ \"$date\" : "; - else - s << "Date( "; - s << date(); - if ( format == Strict ) - s << " }"; - else - s << " )"; - break; - case RegEx: - if ( format == Strict ) - s << "{ \"$regex\" : \""; - else - s << "/"; - s << escape( regex() ); - if ( format == Strict ) - s << "\", \"$options\" : \"" << regexFlags() << "\" }"; - else { - s << "/"; - // FIXME Worry about alpha order? - for( const char *f = regexFlags(); *f; ++f ) - switch( *f ) { - case 'g': - case 'i': - case 'm': - s << *f; - default: - break; - } + s << "[ "; + BSONObjIterator i( embeddedObject() ); + BSONElement e = i.next(); + if ( !e.eoo() ) + while ( 1 ) { + s << e.jsonString( format, false ); + e = i.next(); + if ( e.eoo() ) + break; + s << ", "; } - break; - default: - stringstream ss; - ss << "Cannot create a properly formatted JSON string with " - << "element: " << toString() << " of type: " << type(); - string message = ss.str(); - massert( message.c_str(), false ); + s << " ]"; + break; + } + case DBRef: { + OID *x = (OID *) (valuestr() + valuestrsize()); + if ( format == TenGen ) + s << "Dbref( "; + else + s << "{ \"$ns\" : "; + s << '"' << valuestr() << "\", "; + if ( format != TenGen ) + s << "\"$id\" : "; + s << '"' << *x << "\" "; + if ( format == TenGen ) + s << ')'; + else + s << '}'; + break; + } + case jstOID: + if ( format == TenGen ) + s << "ObjectId( "; + s << '"' << oid() << '"'; + if ( format == TenGen ) + s << " )"; + break; + case BinData: { + int len = *(int *)( value() ); + BinDataType type = BinDataType( *(char *)( (int *)( value() ) + 1 ) ); + s << "{ \"$binary\" : \""; + char *start = ( char * )( value() ) + sizeof( int ) + 1; + string temp(start, len); + string base64 = string( base64_t( temp.begin() ), base64_t( temp.end() ) ); + s << base64; + int padding = ( 4 - ( base64.length() % 4 ) ) % 4; + for ( int i = 0; i < padding; ++i ) + s << '='; + s << "\", \"$type\" : \"" << hex; + s.width( 2 ); + s.fill( '0' ); + s << type << dec; + s << "\" }"; + break; + } + case Date: + if ( format == Strict ) + s << "{ \"$date\" : "; + else + s << "Date( "; + s << date(); + if ( format == Strict ) + s << " }"; + else + s << " )"; + break; + case RegEx: + if ( format == Strict ) + s << "{ \"$regex\" : \""; + else + s << "/"; + s << escape( regex() ); + if ( format == Strict ) + s << "\", \"$options\" : \"" << regexFlags() << "\" }"; + else { + s << "/"; + // FIXME Worry about alpha order? + for ( const char *f = regexFlags(); *f; ++f ) + switch ( *f ) { + case 'g': + case 'i': + case 'm': + s << *f; + default: + break; + } + } + break; + default: + stringstream ss; + ss << "Cannot create a properly formatted JSON string with " + << "element: " << toString() << " of type: " << type(); + string message = ss.str(); + massert( message.c_str(), false ); } return s.str(); } @@ -518,7 +518,7 @@ string BSONObj::toString() const { string BSONObj::jsonString( JsonStringFormat format ) const { if ( isEmpty() ) return "{}"; - + stringstream s; s << "{ "; BSONObjIterator i(*this); @@ -555,7 +555,7 @@ int BSONObj::woCompare(const BSONObj &r, const BSONObj &idxKey, return 1; bool ordered = !idxKey.isEmpty(); - + BSONObjIterator i(*this); BSONObjIterator j(r); BSONObjIterator k(idxKey); @@ -878,22 +878,22 @@ struct BsonUnitTest : public UnitTest { -BSONObjBuilderValueStream::BSONObjBuilderValueStream( const char * fieldName , BSONObjBuilder * builder ){ +BSONObjBuilderValueStream::BSONObjBuilderValueStream( const char * fieldName , BSONObjBuilder * builder ) { _fieldName = fieldName; _builder = builder; } - -BSONObjBuilder& BSONObjBuilderValueStream::operator<<( const char * value ){ + +BSONObjBuilder& BSONObjBuilderValueStream::operator<<( const char * value ) { _builder->append( _fieldName , value ); return *_builder; } -BSONObjBuilder& BSONObjBuilderValueStream::operator<<( const int value ){ +BSONObjBuilder& BSONObjBuilderValueStream::operator<<( const int value ) { _builder->appendInt( _fieldName , value ); return *_builder; } -BSONObjBuilder& BSONObjBuilderValueStream::operator<<( const double value ){ +BSONObjBuilder& BSONObjBuilderValueStream::operator<<( const double value ) { _builder->append( _fieldName , value ); return *_builder; } diff --git a/db/jsobj.h b/db/jsobj.h index 8f9c8b0e261..f8af23835d2 100644 --- a/db/jsobj.h +++ b/db/jsobj.h @@ -77,7 +77,7 @@ public: s.width( 8 ); s << b; s << dec; - return s.str(); + return s.str(); } }; ostream& operator<<( ostream &s, const OID &o ); @@ -108,8 +108,8 @@ ostream& operator<<( ostream &s, const OID &o ); */ /* Formatting mode for generating a JSON from the 10gen representation. - Strict - strict RFC format - TenGen - 10gen format, which is close to JS format. This form is understandable by + Strict - strict RFC format + TenGen - 10gen format, which is close to JS format. This form is understandable by javascript running inside the Mongo server via eval() JS - Javascript JSON compatible */ @@ -120,7 +120,7 @@ enum JsonStringFormat { Strict, TenGen, JS }; /* BSONElement represents an "element" in a BSONObj. So for the object { a : 3, b : "abc" }, 'a : 3' is the first element (key+value). - The BSONElement object points into the BSONObj's data. Thus the BSONObj must stay in scope + The BSONElement object points into the BSONObj's data. Thus the BSONObj must stay in scope for the life of the BSONElement. <type><fieldName ><value> @@ -328,10 +328,10 @@ public: // Readable representation of a 10gen object. string toString() const; - + // Properly formatted JSON string. string jsonString( JsonStringFormat format = Strict ) const; - + /* note: addFields always adds _id even if not specified */ int addFields(BSONObj& from, set<string>& fields); /* returns n added */ @@ -353,7 +353,7 @@ public: BSONElement getFieldDottedOrArray(const char *&name) const; BSONElement getField(const string name) const { - return getField( name.c_str() ); + return getField( name.c_str() ); }; BSONElement getField(const char *name) const; /* return has eoo() true if no match */ @@ -514,7 +514,7 @@ typedef set< BSONObj, BSONObjCmpDefaultOrder > BSONObjSetDefaultOrder; class BSONObjBuilderValueStream { public: BSONObjBuilderValueStream( const char * fieldName , BSONObjBuilder * builder ); - + BSONObjBuilder& operator<<( const char * value ); BSONObjBuilder& operator<<( const int value ); BSONObjBuilder& operator<<( const double value ); @@ -551,10 +551,10 @@ public: b.append(fieldName); b.append((void *) subObj.objdata(), subObj.objsize()); } - - /* add a subobject as a member with type Array. Thus arr object should have "0", "1", ... - style fields in it. - */ + + /* add a subobject as a member with type Array. Thus arr object should have "0", "1", ... + style fields in it. + */ void appendArray(const char *fieldName, BSONObj subObj) { b.append((char) Array); b.append(fieldName); @@ -649,7 +649,7 @@ public: b.append( (char) type ); b.append( (void *) data, len ); } - + template < class T > void append( const char *fieldName, const vector< T >& vals ) { BSONObjBuilder arrBuilder; @@ -697,15 +697,15 @@ public: return o.str(); } - BSONObjBuilderValueStream operator<<(const char * name ){ + BSONObjBuilderValueStream operator<<(const char * name ) { return BSONObjBuilderValueStream( name , this ); } - BSONObjBuilderValueStream operator<<( string name ){ + BSONObjBuilderValueStream operator<<( string name ) { return BSONObjBuilderValueStream( name.c_str() , this ); } - + private: // Append the provided arr object as an array. void marshalArray( const char *fieldName, const BSONObj &arr ) { diff --git a/db/json.cpp b/db/json.cpp index 24ea7e8d16f..05cc669486e 100644 --- a/db/json.cpp +++ b/db/json.cpp @@ -25,9 +25,13 @@ using namespace boost::spirit; namespace mongo { struct ObjectBuilder { - BSONObjBuilder *back() { return builders.back().get(); } + BSONObjBuilder *back() { + return builders.back().get(); + } // Storage for field names of elements within builders.back(). - const char *fieldName() { return fieldNames.back().c_str(); } + const char *fieldName() { + return fieldNames.back().c_str(); + } void push() { boost::shared_ptr< BSONObjBuilder > b( new BSONObjBuilder() ); builders.push_back( b ); @@ -42,7 +46,7 @@ struct ObjectBuilder { return ret; } void nameFromIndex() { - fieldNames.back() = BSONObjBuilder::numStr( indexes.back() ); + fieldNames.back() = BSONObjBuilder::numStr( indexes.back() ); } string popString() { string ret = ss.str(); @@ -101,33 +105,33 @@ struct chE { chE( ObjectBuilder &_b ) : b( _b ) {} void operator() ( const char c ) const { char o = '\0'; - switch( c ) { - case '\"': - o = '\"'; - break; - case '\\': - o = '\\'; - break; - case '/': - o = '/'; - break; - case 'b': - o = '\b'; - break; - case 'f': - o = '\f'; - break; - case 'n': - o = '\n'; - break; - case 'r': - o = '\r'; - break; - case 't': - o = '\t'; - break; - default: - assert( false ); + switch ( c ) { + case '\"': + o = '\"'; + break; + case '\\': + o = '\\'; + break; + case '/': + o = '/'; + break; + case 'b': + o = '\b'; + break; + case 'f': + o = '\f'; + break; + case 'n': + o = '\n'; + break; + case 'r': + o = '\r'; + break; + case 't': + o = '\t'; + break; + default: + assert( false ); } b.ss << o; } @@ -135,19 +139,19 @@ struct chE { }; namespace hex { - int val( char c ) { - if ( '0' <= c && c <= '9' ) - return c - '0'; - if ( 'a' <= c && c <= 'f' ) - return c - 'a' + 10; - if ( 'A' <= c && c <= 'F' ) - return c - 'A' + 10; - assert( false ); - return 0xff; - } - char val( const char *c ) { - return ( val( c[ 0 ] ) << 4 ) | val( c[ 1 ] ); - } +int val( char c ) { + if ( '0' <= c && c <= '9' ) + return c - '0'; + if ( 'a' <= c && c <= 'f' ) + return c - 'a' + 10; + if ( 'A' <= c && c <= 'F' ) + return c - 'A' + 10; + assert( false ); + return 0xff; +} +char val( const char *c ) { + return ( val( c[ 0 ] ) << 4 ) | val( c[ 1 ] ); +} } // namespace hex struct chU { @@ -182,16 +186,16 @@ struct fieldNameEnd { void operator() ( const char *start, const char *end ) const { string name = b.popString(); massert( "Invalid use of reserved field name", - name != "$ns" && - name != "$id" && - name != "$binary" && - name != "$type" && - name != "$date" && - name != "$regex" && - name != "$options" ); + name != "$ns" && + name != "$id" && + name != "$binary" && + name != "$type" && + name != "$date" && + name != "$regex" && + name != "$options" ); b.fieldNames.back() = name; } - ObjectBuilder &b; + ObjectBuilder &b; }; struct stringEnd { @@ -264,7 +268,7 @@ struct dbrefNS { OID stringToOid( const char *s ) { OID oid; char *oidP = (char *)( &oid ); - for( int i = 0; i < 12; ++i ) + for ( int i = 0; i < 12; ++i ) oidP[ i ] = hex::val( s[ i * 2 ] ); return oid; } @@ -301,23 +305,23 @@ struct oidEnd { // boost's conversion. struct binDataBinary { typedef - boost::archive::iterators::transform_width - < boost::archive::iterators::binary_from_base64 - < string::const_iterator >, 8, 6 - > binary_t; + boost::archive::iterators::transform_width + < boost::archive::iterators::binary_from_base64 + < string::const_iterator >, 8, 6 + > binary_t; binDataBinary( ObjectBuilder &_b ) : b( _b ) {} void operator() ( const char *start, const char *end ) const { massert( "Badly formatted bindata", ( end - start ) % 4 == 0 ); string base64( start, end ); int len = base64.length(); int pad = 0; - for(; len - pad > 0 && base64[ len - 1 - pad ] == '='; ++pad ) + for (; len - pad > 0 && base64[ len - 1 - pad ] == '='; ++pad ) base64[ len - 1 - pad ] = 'A'; massert( "Badly formatted bindata", pad < 3 ); b.binData = string( binary_t( base64.begin() ), binary_t( base64.end() ) ); b.binData.resize( b.binData.length() - pad ); } - ObjectBuilder &b; + ObjectBuilder &b; }; struct binDataType { @@ -332,7 +336,7 @@ struct binDataEnd { binDataEnd( ObjectBuilder &_b ) : b( _b ) {} void operator() ( const char *start, const char *end ) const { b.back()->appendBinData( b.fieldName(), b.binData.length(), - b.binDataType, b.binData.data() ); + b.binDataType, b.binData.data() ); } ObjectBuilder &b; }; @@ -358,7 +362,7 @@ struct regexValue { void operator() ( const char *start, const char *end ) const { b.regex = b.popString(); } - ObjectBuilder &b; + ObjectBuilder &b; }; struct regexOptions { @@ -366,16 +370,16 @@ struct regexOptions { void operator() ( const char *start, const char *end ) const { b.regexOptions = string( start, end ); } - ObjectBuilder &b; + ObjectBuilder &b; }; struct regexEnd { regexEnd( ObjectBuilder &_b ) : b( _b ) {} void operator() ( const char *start, const char *end ) const { b.back()->appendRegex( b.fieldName(), b.regex.c_str(), - b.regexOptions.c_str() ); + b.regexOptions.c_str() ); } - ObjectBuilder &b; + ObjectBuilder &b; }; // One gotcha with this parsing library is probably best ilustrated with an @@ -395,7 +399,7 @@ struct regexEnd { struct JsonGrammar : public grammar< JsonGrammar > { public: JsonGrammar( ObjectBuilder &_b ) : b( _b ) {} - + template < typename ScannerT > struct definition { definition( JsonGrammar const &self ) { @@ -420,38 +424,38 @@ public: lexeme_d[ str_p( "null" ) ][ nullValue( self.b ) ]; // lexeme_d and rules don't mix well, so we have this mess str = lexeme_d[ ch_p( '"' )[ chClear( self.b ) ] >> - *( ( ch_p( '\\' ) >> - ( ch_p( '"' )[ chE( self.b ) ] | - ch_p( '\\' )[ chE( self.b ) ] | - ch_p( '/' )[ chE( self.b ) ] | - ch_p( 'b' )[ chE( self.b ) ] | - ch_p( 'f' )[ chE( self.b ) ] | - ch_p( 'n' )[ chE( self.b ) ] | - ch_p( 'r' )[ chE( self.b ) ] | - ch_p( 't' )[ chE( self.b ) ] | - ( ch_p( 'u' ) >> ( repeat_p( 4 )[ xdigit_p ][ chU( self.b ) ] ) ) ) ) | - ch_p( '\x7f' )[ ch( self.b ) ] | - ( ~cntrl_p & ~ch_p( '"' ) & ( ~ch_p( '\\' ) )[ ch( self.b ) ] ) ) >> '"' ]; + *( ( ch_p( '\\' ) >> + ( ch_p( '"' )[ chE( self.b ) ] | + ch_p( '\\' )[ chE( self.b ) ] | + ch_p( '/' )[ chE( self.b ) ] | + ch_p( 'b' )[ chE( self.b ) ] | + ch_p( 'f' )[ chE( self.b ) ] | + ch_p( 'n' )[ chE( self.b ) ] | + ch_p( 'r' )[ chE( self.b ) ] | + ch_p( 't' )[ chE( self.b ) ] | + ( ch_p( 'u' ) >> ( repeat_p( 4 )[ xdigit_p ][ chU( self.b ) ] ) ) ) ) | + ch_p( '\x7f' )[ ch( self.b ) ] | + ( ~cntrl_p & ~ch_p( '"' ) & ( ~ch_p( '\\' ) )[ ch( self.b ) ] ) ) >> '"' ]; // real_p accepts numbers with nonsignificant zero prefixes, which // aren't allowed in JSON. Oh well. number = real_p[ numberValue( self.b ) ]; dbref = dbrefS | dbrefT; dbrefS = ch_p( '{' ) >> "\"$ns\"" >> ':' >> - str[ dbrefNS( self.b ) ] >> ',' >> "\"$id\"" >> ':' >> quotedOid >> '}'; + str[ dbrefNS( self.b ) ] >> ',' >> "\"$id\"" >> ':' >> quotedOid >> '}'; dbrefT = str_p( "Dbref" ) >> '(' >> str[ dbrefNS( self.b ) ] >> ',' >> - quotedOid >> ')'; + quotedOid >> ')'; // FIXME Only object id if top level field? oid = oidS | oidT; oidS = str_p( "\"_id\"" ) >> ':' >> quotedOid; oidT = str_p( "\"_id\"" ) >> ':' >> "ObjectId" >> '(' >> quotedOid >> ')'; - + quotedOid = lexeme_d[ '"' >> ( repeat_p( 24 )[ xdigit_p ] )[ oidValue( self.b ) ] >> '"' ]; - + bindata = ch_p( '{' ) >> "\"$binary\"" >> ':' >> - lexeme_d[ '"' >> ( *( range_p( 'A', 'Z' ) | range_p( 'a', 'z' ) | range_p( '0', '9' ) | ch_p( '+' ) | ch_p( '/' ) ) >> *ch_p( '=' ) )[ binDataBinary( self.b ) ] >> '"' ] >> ',' >> "\"$type\"" >> ':' >> - lexeme_d[ '"' >> ( repeat_p( 2 )[ xdigit_p ] )[ binDataType( self.b ) ] >> '"' ] >> '}'; + lexeme_d[ '"' >> ( *( range_p( 'A', 'Z' ) | range_p( 'a', 'z' ) | range_p( '0', '9' ) | ch_p( '+' ) | ch_p( '/' ) ) >> *ch_p( '=' ) )[ binDataBinary( self.b ) ] >> '"' ] >> ',' >> "\"$type\"" >> ':' >> + lexeme_d[ '"' >> ( repeat_p( 2 )[ xdigit_p ] )[ binDataType( self.b ) ] >> '"' ] >> '}'; date = dateS | dateT; dateS = ch_p( '{' ) >> "\"$date\"" >> ':' >> uint_parser< unsigned long long >()[ dateValue( self.b ) ] >> '}'; @@ -461,24 +465,26 @@ public: regexS = ch_p( '{' ) >> "\"$regex\"" >> ':' >> str[ regexValue( self.b ) ] >> ',' >> "\"$options\"" >> ':' >> lexeme_d[ '"' >> ( *( alpha_p ) )[ regexOptions( self.b ) ] >> '"' ] >> '}'; // FIXME Obviously it would be nice to unify this with str. regexT = lexeme_d[ ch_p( '/' )[ chClear( self.b ) ] >> - *( ( ch_p( '\\' ) >> - ( ch_p( '"' )[ chE( self.b ) ] | - ch_p( '\\' )[ chE( self.b ) ] | - ch_p( '/' )[ chE( self.b ) ] | - ch_p( 'b' )[ chE( self.b ) ] | - ch_p( 'f' )[ chE( self.b ) ] | - ch_p( 'n' )[ chE( self.b ) ] | - ch_p( 'r' )[ chE( self.b ) ] | - ch_p( 't' )[ chE( self.b ) ] | - ( ch_p( 'u' ) >> ( repeat_p( 4 )[ xdigit_p ][ chU( self.b ) ] ) ) ) ) | - ch_p( '\x7f' )[ ch( self.b ) ] | - ( ~cntrl_p & ~ch_p( '/' ) & ( ~ch_p( '\\' ) )[ ch( self.b ) ] ) ) >> str_p( "/" )[ regexValue( self.b ) ] - >> ( *( ch_p( 'i' ) | ch_p( 'g' ) | ch_p( 'm' ) ) )[ regexOptions( self.b ) ] ]; + *( ( ch_p( '\\' ) >> + ( ch_p( '"' )[ chE( self.b ) ] | + ch_p( '\\' )[ chE( self.b ) ] | + ch_p( '/' )[ chE( self.b ) ] | + ch_p( 'b' )[ chE( self.b ) ] | + ch_p( 'f' )[ chE( self.b ) ] | + ch_p( 'n' )[ chE( self.b ) ] | + ch_p( 'r' )[ chE( self.b ) ] | + ch_p( 't' )[ chE( self.b ) ] | + ( ch_p( 'u' ) >> ( repeat_p( 4 )[ xdigit_p ][ chU( self.b ) ] ) ) ) ) | + ch_p( '\x7f' )[ ch( self.b ) ] | + ( ~cntrl_p & ~ch_p( '/' ) & ( ~ch_p( '\\' ) )[ ch( self.b ) ] ) ) >> str_p( "/" )[ regexValue( self.b ) ] + >> ( *( ch_p( 'i' ) | ch_p( 'g' ) | ch_p( 'm' ) ) )[ regexOptions( self.b ) ] ]; } rule< ScannerT > object, members, pair, array, elements, value, str, number, - dbref, dbrefS, dbrefT, oid, oidS, oidT, bindata, date, dateS, dateT, - regex, regexS, regexT, quotedOid; - const rule< ScannerT > &start() const { return object; } + dbref, dbrefS, dbrefT, oid, oidS, oidT, bindata, date, dateS, dateT, + regex, regexS, regexT, quotedOid; + const rule< ScannerT > &start() const { + return object; + } }; ObjectBuilder &b; }; diff --git a/db/lasterror.h b/db/lasterror.h index 8f5b59c55b0..d251a5971c2 100644 --- a/db/lasterror.h +++ b/db/lasterror.h @@ -1,6 +1,6 @@ // lasterror.h
-/** +/**
* Copyright (C) 2009 10gen Inc. * * This program is free software: you can redistribute it and/or modify @@ -15,34 +15,40 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -
-#pragma once
-
-#include <boost/thread/tss.hpp>
+ +#pragma once + +#include <boost/thread/tss.hpp> namespace mongo { -
-struct LastError {
- string msg;
- int nPrev;
- void raiseError(const char *_msg) {
- msg = _msg;
- nPrev = 1;
+ +struct LastError { + string msg; + int nPrev; + void raiseError(const char *_msg) { + msg = _msg; + nPrev = 1; + } + bool haveError() const { + return !msg.empty(); + } + void resetError() { + msg.clear(); + }
+ LastError() {
+ nPrev = 0;
}
- bool haveError() const { return !msg.empty(); }
- void resetError() { msg.clear(); }
- LastError() { nPrev = 0; }
};
extern boost::thread_specific_ptr<LastError> lastError;
inline void raiseError(const char *msg) {
LastError *le = lastError.get();
- if( le == 0 ) {
+ if ( le == 0 ) {
DEV log() << "warning: lastError==0 can't report:" << msg << '\n';
return;
}
le->raiseError(msg);
}
- -} // namespace mongo +
+} // namespace mongo
diff --git a/db/namespace.cpp b/db/namespace.cpp index 33ee30b9af3..54731757c7e 100644 --- a/db/namespace.cpp +++ b/db/namespace.cpp @@ -74,14 +74,14 @@ void NamespaceDetails::addDeletedRec(DeletedRecord *d, DiskLoc dloc) { dassert( dloc.drec() == d ); DEBUGGING cout << "TEMP: add deleted rec " << dloc.toString() << ' ' << hex << d->extentOfs << endl; if ( capped ) { - if( !deletedList[ 1 ].isValid() ) { + if ( !deletedList[ 1 ].isValid() ) { // Initial extent allocation. Insert at end. d->nextDeleted = DiskLoc(); if ( deletedList[ 0 ].isNull() ) deletedList[ 0 ] = dloc; else { DiskLoc i = deletedList[ 0 ]; - for(; !i.drec()->nextDeleted.isNull(); i = i.drec()->nextDeleted ); + for (; !i.drec()->nextDeleted.isNull(); i = i.drec()->nextDeleted ); i.drec()->nextDeleted = dloc; } } else { @@ -132,9 +132,9 @@ DiskLoc NamespaceDetails::alloc(const char *ns, int lenToAlloc, DiskLoc& extentL newDel->extentOfs = r->extentOfs; newDel->lengthWithHeaders = left; newDel->nextDeleted.Null(); - + addDeletedRec(newDel, newDelLoc); - + return loc; } @@ -241,15 +241,15 @@ void NamespaceDetails::dumpDeleted(set<DiskLoc> *extents) { */ void NamespaceDetails::compact() { assert(capped); - + list<DiskLoc> drecs; // Pull out capExtent's DRs from deletedList DiskLoc i = firstDeletedInCapExtent(); - for(; !i.isNull() && inCapExtent( i ); i = i.drec()->nextDeleted ) + for (; !i.isNull() && inCapExtent( i ); i = i.drec()->nextDeleted ) drecs.push_back( i ); firstDeletedInCapExtent() = i; - + // This is the O(n^2) part. drecs.sort(); @@ -282,8 +282,8 @@ void NamespaceDetails::compact() { } DiskLoc NamespaceDetails::firstRecord( const DiskLoc &startExtent ) const { - for(DiskLoc i = startExtent.isNull() ? firstExtent : startExtent; - !i.isNull(); i = i.ext()->xnext ) { + for (DiskLoc i = startExtent.isNull() ? firstExtent : startExtent; + !i.isNull(); i = i.ext()->xnext ) { if ( !i.ext()->firstRecord.isNull() ) return i.ext()->firstRecord; } @@ -291,8 +291,8 @@ DiskLoc NamespaceDetails::firstRecord( const DiskLoc &startExtent ) const { } DiskLoc NamespaceDetails::lastRecord( const DiskLoc &startExtent ) const { - for(DiskLoc i = startExtent.isNull() ? lastExtent : startExtent; - !i.isNull(); i = i.ext()->xprev ) { + for (DiskLoc i = startExtent.isNull() ? lastExtent : startExtent; + !i.isNull(); i = i.ext()->xprev ) { if ( !i.ext()->lastRecord.isNull() ) return i.ext()->lastRecord; } @@ -327,7 +327,7 @@ void NamespaceDetails::advanceCapExtent( const char *ns ) { deletedList[ 1 ] = DiskLoc(); else { DiskLoc i = firstDeletedInCapExtent(); - for(; !i.isNull() && nextIsInCapExtent( i ); i = i.drec()->nextDeleted ); + for (; !i.isNull() && nextIsInCapExtent( i ); i = i.drec()->nextDeleted ); deletedList[ 1 ] = i; } @@ -342,14 +342,14 @@ void NamespaceDetails::maybeComplain( const char *ns, int len ) const { if ( ++n_complaints_cap < 8 ) { cout << "couldn't make room for new record (len: " << len << ") in capped ns " << ns << '\n'; int i = 0; - for( DiskLoc e = firstExtent; !e.isNull(); e = e.ext()->xnext, ++i ) { + for ( DiskLoc e = firstExtent; !e.isNull(); e = e.ext()->xnext, ++i ) { cout << " Extent " << i; if ( e == capExtent ) cout << " (capExtent)"; cout << '\n'; cout << " magic: " << hex << e.ext()->magic << dec << " extent->ns: " << e.ext()->ns.buf << '\n'; cout << " fr: " << e.ext()->firstRecord.toString() << - " lr: " << e.ext()->lastRecord.toString() << " extent->len: " << e.ext()->length << '\n'; + " lr: " << e.ext()->lastRecord.toString() << " extent->len: " << e.ext()->length << '\n'; } assert( len * 5 > lastExtentSize ); // assume it is unusually large record; if not, something is broken } @@ -359,7 +359,7 @@ DiskLoc NamespaceDetails::__capAlloc( int len ) { DiskLoc prev = deletedList[ 1 ]; DiskLoc i = firstDeletedInCapExtent(); DiskLoc ret; - for(; !i.isNull() && inCapExtent( i ); prev = i, i = i.drec()->nextDeleted ) { + for (; !i.isNull() && inCapExtent( i ); prev = i, i = i.drec()->nextDeleted ) { // We need to keep at least one DR per extent in deletedList[ 0 ], // so make sure there's space to create a DR at the end. if ( i.drec()->lengthWithHeaders >= len + 24 ) { @@ -367,7 +367,7 @@ DiskLoc NamespaceDetails::__capAlloc( int len ) { break; } } - + /* unlink ourself from the deleted list */ if ( !ret.isNull() ) { if ( prev.isNull() ) @@ -387,21 +387,21 @@ void NamespaceDetails::checkMigrate() { capFirstNewRecord = DiskLoc(); capFirstNewRecord.setInvalid(); // put all the DeletedRecords in deletedList[ 0 ] - for( int i = 1; i < Buckets; ++i ) { + for ( int i = 1; i < Buckets; ++i ) { DiskLoc first = deletedList[ i ]; if ( first.isNull() ) continue; DiskLoc last = first; - for(; !last.drec()->nextDeleted.isNull(); last = last.drec()->nextDeleted ); + for (; !last.drec()->nextDeleted.isNull(); last = last.drec()->nextDeleted ); last.drec()->nextDeleted = deletedList[ 0 ]; deletedList[ 0 ] = first; deletedList[ i ] = DiskLoc(); } // NOTE deletedList[ 1 ] set to DiskLoc() in above - + // Last, in case we're killed before getting here capExtent = firstExtent; - } + } } /* alloc with capped table handling. */ @@ -410,7 +410,7 @@ DiskLoc NamespaceDetails::_alloc(const char *ns, int len) { return __stdAlloc(len); // capped. - + // signal done allocating new extents. if ( !deletedList[ 1 ].isValid() ) deletedList[ 1 ] = DiskLoc(); @@ -438,15 +438,15 @@ DiskLoc NamespaceDetails::_alloc(const char *ns, int len) { // else signal done with first iteration through extents. continue; } - + if ( !capFirstNewRecord.isNull() && - theCapExtent()->firstRecord == capFirstNewRecord ) { + theCapExtent()->firstRecord == capFirstNewRecord ) { // We've deleted all records that were allocated on the previous // iteration through this extent. advanceCapExtent( ns ); continue; } - + if ( theCapExtent()->firstRecord.isNull() ) { if ( firstEmptyExtent.isNull() ) firstEmptyExtent = capExtent; @@ -519,7 +519,7 @@ void NamespaceDetailsTransient::computeIndexKeys() { options: { capped : ..., size : ... } */ void addNewNamespaceToCatalog(const char *ns, BSONObj *options = 0) { - if( verbose ) + if ( verbose ) log() << "New namespace: " << ns << '\n'; if ( strstr(ns, "system.namespaces") ) { // system.namespaces holds all the others, so it is not explicitly listed in the catalog. diff --git a/db/namespace.h b/db/namespace.h index 3509133a8b9..76e73a57a13 100644 --- a/db/namespace.h +++ b/db/namespace.h @@ -68,7 +68,7 @@ public: /** ( foo.bar ).getSisterNS( "blah" ) == foo.blah */ - string getSisterNS( const char * local ){ + string getSisterNS( const char * local ) { assert( local && local[0] != '.' ); string old(buf); if ( old.find( "." ) != string::npos ) @@ -246,9 +246,9 @@ public: void dumpDeleted(set<DiskLoc> *extents = 0); bool capLooped() const { - return capped && capFirstNewRecord.isValid(); + return capped && capFirstNewRecord.isValid(); } - + // Start from firstExtent by default. DiskLoc firstRecord( const DiskLoc &startExtent = DiskLoc() ) const; @@ -258,16 +258,18 @@ public: bool inCapExtent( const DiskLoc &dl ) const; void checkMigrate(); - + private: - Extent *theCapExtent() const { return capExtent.ext(); } + Extent *theCapExtent() const { + return capExtent.ext(); + } void advanceCapExtent( const char *ns ); void maybeComplain( const char *ns, int len ) const; DiskLoc __stdAlloc(int len); DiskLoc __capAlloc(int len); DiskLoc _alloc(const char *ns, int len); void compact(); - + DiskLoc &firstDeletedInCapExtent(); bool nextIsInCapExtent( const DiskLoc &dl ) const; }; diff --git a/db/pdfile.cpp b/db/pdfile.cpp index ccf5806784c..fb8e09389c1 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -101,7 +101,7 @@ bool _userCreateNS(const char *ns, BSONObj& j, string& err) { return false; } - if( verbose ) + if ( verbose ) log() << "create collection " << ns << ' ' << j.toString() << '\n'; /* todo: do this only when we have allocated space successfully? or we could insert with a { ok: 0 } field @@ -127,17 +127,17 @@ bool _userCreateNS(const char *ns, BSONObj& j, string& err) { mx = (int) e.number(); } } - + // $nExtents just for debug/testing. We create '$nExtents' extents, // each of size 'size'. e = j.findElement( "$nExtents" ); int nExtents = int( e.number() ); if ( nExtents > 0 ) - for( int i = 0; i < nExtents; ++i ) { + for ( int i = 0; i < nExtents; ++i ) { database->suitableFile(size)->newExtent( ns, size, newCapped ); } else - while( size > 0 ) { + while ( size > 0 ) { int max = PhysicalDataFile::maxSize() - PDFHeader::headerSize(); int desiredExtentSize = size > max ? max : size; Extent *e = database->suitableFile( desiredExtentSize )->newExtent( ns, desiredExtentSize, newCapped ); @@ -149,7 +149,7 @@ bool _userCreateNS(const char *ns, BSONObj& j, string& err) { if ( mx > 0 ) d->max = mx; - + return true; } @@ -174,12 +174,12 @@ int PhysicalDataFile::maxSize() { int PhysicalDataFile::defaultSize( const char *filename ) const { int size; - + if ( fileNo <= 4 ) size = (64*1024*1024) << fileNo; else size = 0x7ff00000; - + if ( strstr(filename, "_hudsonSmall") ) { int mult = 1; if ( fileNo > 1 && fileNo < 1000 ) @@ -211,13 +211,13 @@ void PhysicalDataFile::open( const char *filename, int minSize ) { } int size = defaultSize( filename ); - while( size < minSize ) { + while ( size < minSize ) { if ( size < maxSize() / 2 ) - size *= 2; - else { - size = maxSize(); - break; - } + size *= 2; + else { + size = maxSize(); + break; + } } if ( size > maxSize() ) size = maxSize(); @@ -812,7 +812,7 @@ void ensureHaveIdIndex(const char *ns) { theDataFileMgr.insert(system_indexes.c_str(), o.objdata(), o.objsize()); } -DiskLoc DataFileMgr::insert(const char *ns, const void *buf, int len, bool god) { +DiskLoc DataFileMgr::insert(const char *ns, const void *buf, int len, bool god) { bool addIndex = false; const char *sys = strstr(ns, "system."); if ( sys ) { @@ -1069,15 +1069,19 @@ boost::intmax_t dbSize( const char *database ) { class SizeAccumulator : public FileOp { public: SizeAccumulator() : totalSize_( 0 ) {} - boost::intmax_t size() const { return totalSize_; } + boost::intmax_t size() const { + return totalSize_; + } private: virtual bool apply( const boost::filesystem::path &p ) { - if( !boost::filesystem::exists( p ) ) + if ( !boost::filesystem::exists( p ) ) return false; totalSize_ += boost::filesystem::file_size( p ); return true; } - virtual const char *op() const { return "checking size"; } + virtual const char *op() const { + return "checking size"; + } boost::intmax_t totalSize_; }; SizeAccumulator sa; @@ -1101,7 +1105,7 @@ boost::intmax_t freeSpace() { } bool repairDatabase( const char *ns, string &errmsg, - bool preserveClonedFilesOnFailure, bool backupOriginalFiles ) { + bool preserveClonedFilesOnFailure, bool backupOriginalFiles ) { stringstream ss; ss << "localhost:" << port; string localhost = ss.str(); @@ -1117,15 +1121,15 @@ bool repairDatabase( const char *ns, string &errmsg, if ( freeSize > -1 && freeSize < totalSize ) { stringstream ss; ss << "Cannot repair database " << dbName << " having size: " << totalSize - << " (bytes) because free disk space is: " << freeSize << " (bytes)"; + << " (bytes) because free disk space is: " << freeSize << " (bytes)"; errmsg = ss.str(); problem() << errmsg << endl; return false; } - + Path reservedPath = uniqueReservedPath( ( preserveClonedFilesOnFailure || backupOriginalFiles ) ? - "backup" : "tmp" ); + "backup" : "tmp" ); BOOST_CHECK_EXCEPTION( boost::filesystem::create_directory( reservedPath ) ); string reservedPathString = reservedPath.native_directory_string(); assert( setClient( dbName, reservedPathString.c_str() ) ); diff --git a/db/pdfile.h b/db/pdfile.h index 92186920f79..dbd7e893ddd 100644 --- a/db/pdfile.h +++ b/db/pdfile.h @@ -323,7 +323,7 @@ inline DiskLoc Record::getPrev(const DiskLoc& myLoc) { return DiskLoc(); return e->xprev.ext()->lastRecord; } - + inline Record* DiskLoc::rec() const { return DataFileMgr::getRecord(*this); } @@ -387,7 +387,7 @@ inline void _applyOpToDataFiles( const char *database, FileOp &fo, const char *p q = p / ss.str(); BOOST_CHECK_EXCEPTION( ok = fo.apply(q) ); if ( ok ) { - if( verbose || extra != 10 ) + if ( verbose || extra != 10 ) log() << fo.op() << " file " << q.string() << '\n'; if ( extra != 10 ) log() << " _applyOpToDataFiles() warning: extra == " << extra << endl; diff --git a/db/query.cpp b/db/query.cpp index f38fae6824c..dcfe4705ebd 100644 --- a/db/query.cpp +++ b/db/query.cpp @@ -50,7 +50,7 @@ int matchDirection( const BSONObj &index, const BSONObj &sort ) { int direction = 0; BSONObjIterator i( index ); BSONObjIterator s( sort ); - while( 1 ) { + while ( 1 ) { BSONElement ie = i.next(); BSONElement se = s.next(); if ( ie.eoo() ) { @@ -60,7 +60,7 @@ int matchDirection( const BSONObj &index, const BSONObj &sort ) { } if ( strcmp( ie.fieldName(), se.fieldName() ) != 0 ) return 0; - + int d = ie.number() == se.number() ? 1 : -1; if ( direction == 0 ) direction = d; @@ -274,7 +274,7 @@ int deleteObjects(const char *ns, BSONObj pattern, bool justOne, bool god) { c->checkLocation(); } } - + return nDeleted; } diff --git a/db/repl.cpp b/db/repl.cpp index 2a2b7e5f6b3..c516335547b 100644 --- a/db/repl.cpp +++ b/db/repl.cpp @@ -122,7 +122,7 @@ void ReplPair::arbitrate() { return; } - /* todo: make an arbitrate command we send to the arbiter instead of this */ + /* todo: make an arbitrate command we send to the arbiter instead of this */ bool is_master; bool ok = conn->isMaster(is_master); if ( !ok ) { @@ -584,12 +584,12 @@ void ReplSource::sync_pullOpLog_applyOperation(BSONObj& op) { dblock lk; bool justCreated; - try { - justCreated = setClientTempNs(ns); - } catch( AssertionException& ) { - problem() << "skipping bad(?) op in oplog, setClient() failed, ns: '" << ns << "'\n"; - addDbNextPass.erase(clientName); - return; + try { + justCreated = setClientTempNs(ns); + } catch ( AssertionException& ) { + problem() << "skipping bad(?) op in oplog, setClient() failed, ns: '" << ns << "'\n"; + addDbNextPass.erase(clientName); + return; } if ( allDead ) { @@ -1138,7 +1138,7 @@ void startReplication() { */ //boost::thread tempt(tempThread); - if( !slave && !master && !replPair ) + if ( !slave && !master && !replPair ) return; { diff --git a/db/replset.h b/db/replset.h index 7ba3978d43b..c08372aeb47 100644 --- a/db/replset.h +++ b/db/replset.h @@ -146,7 +146,7 @@ public: PairSync() { initialsynccomplete = -1; } - + /* call before using the class. from dbmutex */ void init() { BSONObj o; @@ -154,17 +154,17 @@ public: if ( getSingleton("local.pair.sync", o) ) initialsynccomplete = 1; } - + bool initialSyncCompleted() { return initialsynccomplete != 0; } - + void setInitialSyncCompleted() { BSONObj o = fromjson("{\"initialsynccomplete\":1}"); putSingleton("local.pair.sync", o); initialsynccomplete = 1; } - + void setInitialSyncCompletedLocking() { if ( initialsynccomplete == 1 ) return; diff --git a/db/security.cpp b/db/security.cpp index 3d78bfe6921..b8da6553d8b 100644 --- a/db/security.cpp +++ b/db/security.cpp @@ -2,20 +2,20 @@ #include "stdafx.h"
#include "security.h"
-#include "../util/md5.hpp" - -namespace mongo { - -extern "C" int do_md5_test(void); +#include "../util/md5.hpp"
+
+namespace mongo {
+
+extern "C" int do_md5_test(void);
boost::thread_specific_ptr<AuthenticationInfo> authInfo;
typedef unsigned long long nonce;
-struct Security {
+struct Security {
ifstream *devrandom;
- nonce getNonce() {
+ nonce getNonce() {
nonce n;
#if defined(__linux__)
devrandom->read((char*)&n, sizeof(n));
@@ -27,45 +27,53 @@ struct Security { }
Security()
- {
+ {
#if defined(__linux__)
devrandom = new ifstream("/dev/urandom", ios::binary|ios::in);
massert( "can't open dev/urandom", devrandom->is_open() );
#endif
assert( sizeof(nonce) == 8 );
- if( do_md5_test() ) - massert("md5 unit test fails", false); + if ( do_md5_test() )
+ massert("md5 unit test fails", false);
}
} security;
-} // namespace mongo - +} // namespace mongo
+
#include "commands.h"
#include "jsobj.h"
- -namespace mongo { -
-class CmdGetNonce : public Command { -public: - virtual bool logTheOp() { return false; } - virtual bool slaveOk() { return true; } - CmdGetNonce() : Command("getnonce") {} - bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) { - result.append("nonce", (double) security.getNonce()); - return true; - } -} cmdGetNonce; - -class CmdAuthenticate : public Command { -public: - virtual bool logTheOp() { return false; } - virtual bool slaveOk() { return true; } - CmdAuthenticate() : Command("authenticate") {} - bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) { - return false; - } -} cmdAuthenticate; - - -} // namespace mongo +
+namespace mongo {
+
+class CmdGetNonce : public Command {
+public:
+ virtual bool logTheOp() {
+ return false;
+ }
+ virtual bool slaveOk() {
+ return true;
+ }
+ CmdGetNonce() : Command("getnonce") {}
+ bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
+ result.append("nonce", (double) security.getNonce());
+ return true;
+ }
+} cmdGetNonce;
+
+class CmdAuthenticate : public Command {
+public:
+ virtual bool logTheOp() {
+ return false;
+ }
+ virtual bool slaveOk() {
+ return true;
+ }
+ CmdAuthenticate() : Command("authenticate") {}
+ bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
+ return false;
+ }
+} cmdAuthenticate;
+
+
+} // namespace mongo
diff --git a/db/security.h b/db/security.h index 9526a9af1ad..d827fc87624 100644 --- a/db/security.h +++ b/db/security.h @@ -1,6 +1,6 @@ // security.h
-/** +/**
* Copyright (C) 2009 10gen Inc. * * This program is free software: you can redistribute it and/or modify @@ -15,21 +15,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -
-#pragma once
-
-#include <boost/thread/tss.hpp>
+ +#pragma once + +#include <boost/thread/tss.hpp> namespace mongo { -
-class AuthenticationInfo : boost::noncopyable {
-public:
- AuthenticationInfo() { }
- ~AuthenticationInfo() {
-// cout << "TEMP: auth info was cleaned up ********************************************" << endl;
- }
-};
-
-extern boost::thread_specific_ptr<AuthenticationInfo> authInfo;
- } // namespace mongo +class AuthenticationInfo : boost::noncopyable { +public: + AuthenticationInfo() { } + ~AuthenticationInfo() { +// cout << "TEMP: auth info was cleaned up ********************************************" << endl; + } +}; + +extern boost::thread_specific_ptr<AuthenticationInfo> authInfo; + +} // namespace mongo |