diff options
41 files changed, 360 insertions, 367 deletions
diff --git a/client/clientOnly.cpp b/client/clientOnly.cpp index ffdcd989bab..8711dd713fa 100644 --- a/client/clientOnly.cpp +++ b/client/clientOnly.cpp @@ -1,7 +1,4 @@ - -#include <iostream> - -using namespace std; +#include "../stdafx.h" namespace mongo { @@ -9,10 +6,10 @@ namespace mongo { // Database* database = 0; void dbexit(int returnCode, const char *whyMsg ) { - cout << "dbexit called" << endl; + out() << "dbexit called" << endl; if ( whyMsg ) - cout << " b/c " << whyMsg << endl; - cout << "exiting" << endl; + out() << " b/c " << whyMsg << endl; + out() << "exiting" << endl; exit( returnCode ); } diff --git a/client/connpool.h b/client/connpool.h index 2fa3469e759..c1ad3c409a8 100644 --- a/client/connpool.h +++ b/client/connpool.h @@ -81,9 +81,9 @@ namespace mongo { /* you are supposed to call done(). if you did that, correctly, we only get here if an exception was thrown. in such a scenario, we can't be sure we fully read all expected data of a reply on the socket. so - we don't try to reuse the connection. The cout is just informational. + we don't try to reuse the connection. The out() is just informational. */ - cout << "~ScopedDBConnection: _conn != null\n"; + out() << "~ScopedDBConnection: _conn != null\n"; kill(); } } diff --git a/client/dbclient.cpp b/client/dbclient.cpp index 7f7d419b456..cfbccd19fb0 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -136,7 +136,7 @@ namespace mongo { DBClientConnection c; string err; if ( !c.connect("localhost", err) ) { - cout << "can't connect to server " << err << endl; + out() << "can't connect to server " << err << endl; return; } BSONObj info; @@ -145,22 +145,22 @@ namespace mongo { b.append("0", 99); BSONObj args = b.done(); bool ok = c.eval("dwight", "function() { return args[0]; }", info, retValue, &args); - cout << "eval ok=" << ok << endl; - cout << "retvalue=" << retValue.toString() << endl; - cout << "info=" << info.toString() << endl; + out() << "eval ok=" << ok << endl; + out() << "retvalue=" << retValue.toString() << endl; + out() << "info=" << info.toString() << endl; - cout << endl; + out() << endl; int x = 3; assert( c.eval("dwight", "function() { return 3; }", x) ); - cout << "***\n"; + out() << "***\n"; BSONObj foo = fromjson("{\"x\":7}"); - cout << foo.toString() << endl; + out() << foo.toString() << endl; int res=0; ok = c.eval("dwight", "function(parm1) { return parm1.x; }", foo, res); - cout << ok << " retval:" << res << endl; + out() << ok << " retval:" << res << endl; } int test2() { @@ -192,7 +192,7 @@ namespace mongo { size_t idx = ip.find( ":" ); if ( idx != string::npos ) { - //cout << "port string:" << ip.substr( idx ) << endl; + //out() << "port string:" << ip.substr( idx ) << endl; port = atoi( ip.substr( idx + 1 ).c_str() ); ip = ip.substr( 0 , idx ); ip = hostbyname(ip.c_str()); @@ -484,25 +484,25 @@ namespace mongo { // "./db testclient" to invoke extern BSONObj emptyObj; void testClient() { - cout << "testClient()" << endl; + out() << "testClient()" << endl; // DBClientConnection c(true); DBClientPaired c; string err; if ( !c.connect("10.211.55.2", "1.2.3.4") ) { // if( !c.connect("10.211.55.2", err) ) { - cout << "testClient: connect() failed" << endl; + out() << "testClient: connect() failed" << endl; } else { // temp: - cout << "test query returns: " << c.findOne("foo.bar", fromjson("{}")).toString() << endl; + out() << "test query returns: " << c.findOne("foo.bar", fromjson("{}")).toString() << endl; } again: - cout << "query foo.bar..." << endl; + out() << "query foo.bar..." << endl; auto_ptr<DBClientCursor> cursor = c.query("foo.bar", emptyObj, 0, 0, 0, Option_CursorTailable); DBClientCursor *cc = cursor.get(); if ( cc == 0 ) { - cout << "query() returned 0, sleeping 10 secs" << endl; + out() << "query() returned 0, sleeping 10 secs" << endl; sleepsecs(10); goto again; } @@ -511,21 +511,21 @@ again: try { m = cc->more(); } catch (AssertionException&) { - cout << "more() asserted, sleeping 10 sec" << endl; + out() << "more() asserted, sleeping 10 sec" << endl; goto again; } - cout << "more: " << m << " dead:" << cc->isDead() << endl; + out() << "more: " << m << " dead:" << cc->isDead() << endl; if ( !m ) { if ( cc->isDead() ) - cout << "cursor dead, stopping" << endl; + out() << "cursor dead, stopping" << endl; else { - cout << "Sleeping 10 seconds" << endl; + out() << "Sleeping 10 seconds" << endl; sleepsecs(10); continue; } break; } - cout << cc->next().toString() << endl; + out() << cc->next().toString() << endl; } } diff --git a/client/dbclient.h b/client/dbclient.h index 0f06b2e78e9..dd3b4ac5716 100644 --- a/client/dbclient.h +++ b/client/dbclient.h @@ -259,7 +259,7 @@ namespace mongo { jscode source code for a javascript function. info the command object which contains any information on the invocation result including the return value and other information. If an error occurs running the jscode, error - information will be in info. (try "cout << info.toString()") + information will be in info. (try "out() << info.toString()") retValue return value from the jscode function. args args to pass to the jscode function. when invoked, the 'args' variable will be defined for use by the jscode. diff --git a/db/btree.cpp b/db/btree.cpp index 5305c21dbd0..14f0addad18 100644 --- a/db/btree.cpp +++ b/db/btree.cpp @@ -74,7 +74,7 @@ namespace mongo { // return; if ( bt_dmp ) { - cout << thisLoc.toString() << ' '; + out() << thisLoc.toString() << ' '; ((BtreeBucket *) this)->dump(); } @@ -116,10 +116,10 @@ namespace mongo { BSONObj k2 = keyNode(i+1).key; int z = k1.woCompare(k2, order); //OK if ( z > 0 ) { - cout << "ERROR: btree key order corrupt. Keys:" << endl; + out() << "ERROR: btree key order corrupt. Keys:" << endl; if ( ++nDumped < 5 ) { for ( int j = 0; j < n; j++ ) { - cout << " " << keyNode(j).key.toString() << endl; + out() << " " << keyNode(j).key.toString() << endl; } ((BtreeBucket *) this)->dump(); } @@ -128,9 +128,9 @@ namespace mongo { } else if ( z == 0 ) { if ( !(k(i).recordLoc < k(i+1).recordLoc) ) { - cout << "ERROR: btree key order corrupt (recordloc's wrong). Keys:" << endl; - cout << " k(" << i << "):" << keyNode(i).key.toString() << " RL:" << k(i).recordLoc.toString() << endl; - cout << " k(" << i+1 << "):" << keyNode(i+1).key.toString() << " RL:" << k(i+1).recordLoc.toString() << endl; + out() << "ERROR: btree key order corrupt (recordloc's wrong). Keys:" << endl; + out() << " k(" << i << "):" << keyNode(i).key.toString() << " RL:" << k(i).recordLoc.toString() << endl; + out() << " k(" << i+1 << "):" << keyNode(i+1).key.toString() << " RL:" << k(i+1).recordLoc.toString() << endl; wassert( k(i).recordLoc < k(i+1).recordLoc ); } } @@ -361,10 +361,10 @@ namespace mongo { goto found; } } - cout << "ERROR: can't find ref to deleted bucket.\n"; - cout << "To delete:\n"; + out() << "ERROR: can't find ref to deleted bucket.\n"; + out() << "To delete:\n"; dump(); - cout << "Parent:\n"; + out() << "Parent:\n"; p->dump(); assert(false); } @@ -434,7 +434,7 @@ found: inline void fix(const DiskLoc& thisLoc, const DiskLoc& child) { if ( !child.isNull() ) { if ( insert_debug ) - cout << " " << child.toString() << ".parent=" << thisLoc.toString() << endl; + out() << " " << child.toString() << ".parent=" << thisLoc.toString() << endl; child.btree()->parent = thisLoc; } } @@ -455,7 +455,7 @@ found: { dassert( thisLoc.btree() == this ); if ( insert_debug ) - cout << " " << thisLoc.toString() << ".insertHere " << key.toString() << '/' << recordLoc.toString() << ' ' + out() << " " << thisLoc.toString() << ".insertHere " << key.toString() << '/' << recordLoc.toString() << ' ' << lchild.toString() << ' ' << rchild.toString() << " keypos:" << keypos << endl; DiskLoc oldLoc = thisLoc; @@ -464,15 +464,15 @@ found: _KeyNode& kn = k(keypos); if ( keypos+1 == n ) { // last key if ( nextChild != lchild ) { - cout << "ERROR nextChild != lchild" << endl; - cout << " thisLoc: " << thisLoc.toString() << ' ' << idx.indexNamespace() << endl; - cout << " keyPos: " << keypos << " n:" << n << endl; - cout << " nextChild: " << nextChild.toString() << " lchild: " << lchild.toString() << endl; - cout << " recordLoc: " << recordLoc.toString() << " rchild: " << rchild.toString() << endl; - cout << " key: " << key.toString() << endl; + out() << "ERROR nextChild != lchild" << endl; + out() << " thisLoc: " << thisLoc.toString() << ' ' << idx.indexNamespace() << endl; + out() << " keyPos: " << keypos << " n:" << n << endl; + out() << " nextChild: " << nextChild.toString() << " lchild: " << lchild.toString() << endl; + out() << " recordLoc: " << recordLoc.toString() << " rchild: " << rchild.toString() << endl; + out() << " key: " << key.toString() << endl; dump(); #if defined(_WIN32) - cout << "\n\nDUMPING FULL INDEX" << endl; + out() << "\n\nDUMPING FULL INDEX" << endl; bt_dmp=1; bt_fv=1; idx.head.btree()->fullValidate(idx.head); @@ -488,15 +488,15 @@ found: else { k(keypos).prevChildBucket = lchild; if ( k(keypos+1).prevChildBucket != lchild ) { - cout << "ERROR k(keypos+1).prevChildBucket != lchild" << endl; - cout << " thisLoc: " << thisLoc.toString() << ' ' << idx.indexNamespace() << endl; - cout << " keyPos: " << keypos << " n:" << n << endl; - cout << " k(keypos+1).pcb: " << k(keypos+1).prevChildBucket.toString() << " lchild: " << lchild.toString() << endl; - cout << " recordLoc: " << recordLoc.toString() << " rchild: " << rchild.toString() << endl; - cout << " key: " << key.toString() << endl; + out() << "ERROR k(keypos+1).prevChildBucket != lchild" << endl; + out() << " thisLoc: " << thisLoc.toString() << ' ' << idx.indexNamespace() << endl; + out() << " keyPos: " << keypos << " n:" << n << endl; + out() << " k(keypos+1).pcb: " << k(keypos+1).prevChildBucket.toString() << " lchild: " << lchild.toString() << endl; + out() << " recordLoc: " << recordLoc.toString() << " rchild: " << rchild.toString() << endl; + out() << " key: " << key.toString() << endl; dump(); #if defined(_WIN32) - cout << "\n\nDUMPING FULL INDEX" << endl; + out() << "\n\nDUMPING FULL INDEX" << endl; bt_dmp=1; bt_fv=1; idx.head.btree()->fullValidate(idx.head); @@ -512,7 +512,7 @@ found: // split if ( split_debug ) - cout << " " << thisLoc.toString() << ".split" << endl; + out() << " " << thisLoc.toString() << ".split" << endl; int mid = n / 2; @@ -527,9 +527,9 @@ found: mid--; if ( mid < 3 ) { problem() << "Assertion failure - mid<3: duplicate key bug not fixed yet" << endl; - cout << "Assertion failure - mid<3: duplicate key bug not fixed yet" << endl; - cout << " ns:" << idx.indexNamespace() << endl; - cout << " key:" << mn.key.toString() << endl; + out() << "Assertion failure - mid<3: duplicate key bug not fixed yet" << endl; + out() << " ns:" << idx.indexNamespace() << endl; + out() << " key:" << mn.key.toString() << endl; break; } } @@ -539,7 +539,7 @@ found: DiskLoc rLoc; if ( split_debug ) - cout << " mid:" << mid << ' ' << keyNode(mid).key.toString() << " n:" << n << endl; + out() << " mid:" << mid << ' ' << keyNode(mid).key.toString() << " n:" << n << endl; for ( int i = mid+1; i < n; i++ ) { KeyNode kn = keyNode(i); r->pushBack(kn.recordLoc, kn.key, order, kn.prevChildBucket); @@ -549,7 +549,7 @@ found: //r->dump(); rLoc = theDataFileMgr.insert(idx.indexNamespace().c_str(), r, r->Size(), true); if ( split_debug ) - cout << " new rLoc:" << rLoc.toString() << endl; + out() << " new rLoc:" << rLoc.toString() << endl; free(r); r = 0; rLoc.btree()->fixParentPtrs(rLoc); @@ -559,7 +559,7 @@ found: nextChild = middle.prevChildBucket; // middle key gets promoted, its children will be thisLoc (l) and rLoc (r) if ( split_debug ) { //rLoc.btree()->dump(); - cout << " middle key:" << middle.key.toString() << endl; + out() << " middle key:" << middle.key.toString() << endl; } // promote middle to a parent node @@ -571,7 +571,7 @@ found: p->assertValid( order ); parent = idx.head = theDataFileMgr.insert(idx.indexNamespace().c_str(), p, p->Size(), true); if ( split_debug ) - cout << " we were root, making new root:" << hex << parent.getOfs() << dec << endl; + out() << " we were root, making new root:" << hex << parent.getOfs() << dec << endl; free(p); rLoc.btree()->parent = parent; } @@ -581,7 +581,7 @@ found: */ rLoc.btree()->parent = parent; if ( split_debug ) - cout << " promoting middle key " << middle.key.toString() << endl; + out() << " promoting middle key " << middle.key.toString() << endl; parent.btree()->_insert(parent, middle.recordLoc, middle.key, order, false, thisLoc, rLoc, idx); } //BtreeBucket *br = rLoc.btree(); @@ -602,7 +602,7 @@ found: if ( keypos <= mid ) { // if( keypos < mid ) { if ( split_debug ) - cout << " keypos<mid, insertHere() the new key" << endl; + out() << " keypos<mid, insertHere() the new key" << endl; insertHere(thisLoc, keypos, recordLoc, key, order, lchild, rchild, idx); //dump(); } else { @@ -610,13 +610,13 @@ found: assert(kp>=0); rLoc.btree()->insertHere(rLoc, kp, recordLoc, key, order, lchild, rchild, idx); // set a bp here. -// if( !lchild.isNull() ) cout << lchild.btree()->parent.toString() << endl; -// if( !rchild.isNull() ) cout << rchild.btree()->parent.toString() << endl; +// if( !lchild.isNull() ) out() << lchild.btree()->parent.toString() << endl; +// if( !rchild.isNull() ) out() << rchild.btree()->parent.toString() << endl; } } if ( split_debug ) - cout << " split end " << hex << thisLoc.getOfs() << dec << endl; + out() << " split end " << hex << thisLoc.getOfs() << dec << endl; } /* start a new index off, empty */ @@ -636,10 +636,10 @@ found: DiskLoc BtreeBucket::advance(const DiskLoc& thisLoc, int& keyOfs, int direction, const char *caller) { if ( keyOfs < 0 || keyOfs >= n ) { - cout << "ASSERT failure BtreeBucket::advance, caller: " << caller << endl; - cout << " thisLoc: " << thisLoc.toString() << endl; - cout << " keyOfs: " << keyOfs << " n:" << n << " direction: " << direction << endl; - cout << bucketSummary() << endl; + out() << "ASSERT failure BtreeBucket::advance, caller: " << caller << endl; + out() << " thisLoc: " << thisLoc.toString() << endl; + out() << " keyOfs: " << keyOfs << " n:" << n << " direction: " << direction << endl; + out() << bucketSummary() << endl; assert(false); } int adj = direction < 0 ? 1 : 0; @@ -719,24 +719,24 @@ found: int pos; bool found = find(key, recordLoc, order, pos); if ( insert_debug ) { - cout << " " << thisLoc.toString() << '.' << "_insert " << + out() << " " << thisLoc.toString() << '.' << "_insert " << key.toString() << '/' << recordLoc.toString() << " l:" << lChild.toString() << " r:" << rChild.toString() << endl; - cout << " found:" << found << " pos:" << pos << " n:" << n << endl; + out() << " found:" << found << " pos:" << pos << " n:" << n << endl; } if ( found ) { if ( k(pos).isUnused() ) { - cout << "an unused already occupying keyslot, write more code.\n"; - cout << " index may be corrupt (missing data) now.\n"; + out() << "an unused already occupying keyslot, write more code.\n"; + out() << " index may be corrupt (missing data) now.\n"; } - cout << "_insert(): key already exists in index\n"; - cout << " " << idx.indexNamespace().c_str() << " thisLoc:" << thisLoc.toString() << '\n'; - cout << " " << key.toString() << '\n'; - cout << " " << "recordLoc:" << recordLoc.toString() << " pos:" << pos << endl; - cout << " old l r: " << childForPos(pos).toString() << ' ' << childForPos(pos+1).toString() << endl; - cout << " new l r: " << lChild.toString() << ' ' << rChild.toString() << endl; + out() << "_insert(): key already exists in index\n"; + out() << " " << idx.indexNamespace().c_str() << " thisLoc:" << thisLoc.toString() << '\n'; + out() << " " << key.toString() << '\n'; + out() << " " << "recordLoc:" << recordLoc.toString() << " pos:" << pos << endl; + out() << " old l r: " << childForPos(pos).toString() << ' ' << childForPos(pos+1).toString() << endl; + out() << " new l r: " << lChild.toString() << ' ' << rChild.toString() << endl; assert(false); // on a dup key always insert on the right or else you will be broken. @@ -746,16 +746,16 @@ found: if( !rChild.isNull() ) { while( pos < n && k(pos).prevChildBucket != lchild ) { pos++; - cout << "looking for the right dup key" << endl; + out() << "looking for the right dup key" << endl; } } */ } - DEBUGGING cout << "TEMP: key: " << key.toString() << endl; + DEBUGGING out() << "TEMP: key: " << key.toString() << endl; DiskLoc& child = getChild(pos); if ( insert_debug ) - cout << " getChild(" << pos << "): " << child.toString() << endl; + out() << " getChild(" << pos << "): " << child.toString() << endl; if ( child.isNull() || !rChild.isNull() /* means an 'internal' insert */ ) { insertHere(thisLoc, pos, recordLoc, key, order, lChild, rChild, idx); return 0; @@ -765,17 +765,17 @@ found: } void BtreeBucket::dump() { - cout << "DUMP btreebucket: "; - cout << " parent:" << hex << parent.getOfs() << dec; + out() << "DUMP btreebucket: "; + out() << " parent:" << hex << parent.getOfs() << dec; for ( int i = 0; i < n; i++ ) { - cout << '\n'; + out() << '\n'; KeyNode k = keyNode(i); - cout << '\t' << i << '\t' << k.key.toString() << "\tleft:" << hex << + out() << '\t' << i << '\t' << k.key.toString() << "\tleft:" << hex << k.prevChildBucket.getOfs() << "\trec:" << k.recordLoc.getOfs() << dec; if ( this->k(i).isUnused() ) - cout << " UNUSED"; + out() << " UNUSED"; } - cout << " right:" << hex << nextChild.getOfs() << dec << endl; + out() << " right:" << hex << nextChild.getOfs() << dec << endl; } /* todo: meaning of return code unclear clean up */ @@ -791,9 +791,9 @@ found: ++ninserts; /* if( ninserts % 1000 == 0 ) { - cout << "ninserts: " << ninserts << endl; + out() << "ninserts: " << ninserts << endl; if( 0 && ninserts >= 127287 ) { - cout << "debug?" << endl; + out() << "debug?" << endl; split_debug = 1; } } diff --git a/db/btreecursor.cpp b/db/btreecursor.cpp index f2d9b93d1b0..735c9dc441a 100644 --- a/db/btreecursor.cpp +++ b/db/btreecursor.cpp @@ -39,11 +39,11 @@ namespace mongo { bool found; if ( otherTraceLevel >= 12 ) { if ( otherTraceLevel >= 200 ) { - cout << "::BtreeCursor() qtl>200. validating entire index." << endl; + out() << "::BtreeCursor() qtl>200. validating entire index." << endl; indexDetails.head.btree()->fullValidate(indexDetails.head, order); } else { - cout << "BTreeCursor(). dumping head bucket" << endl; + out() << "BTreeCursor(). dumping head bucket" << endl; indexDetails.head.btree()->dump(); } } diff --git a/db/clientcursor.cpp b/db/clientcursor.cpp index 43334245d48..400c912038e 100644 --- a/db/clientcursor.cpp +++ b/db/clientcursor.cpp @@ -125,7 +125,7 @@ namespace mongo { } c->checkLocation(); if ( c->tailing() ) { - DEV cout << "killing cursor as we would have to advance it and it is tailable" << endl; + DEV out() << "killing cursor as we would have to advance it and it is tailable" << endl; delete *i; continue; } @@ -177,7 +177,7 @@ namespace mongo { break; } ctmLast = ctm; - DEV cout << " alloccursorid " << x << endl; + DEV out() << " alloccursorid " << x << endl; return x; } diff --git a/db/clientcursor.h b/db/clientcursor.h index a484286db49..b04085ec2b2 100644 --- a/db/clientcursor.h +++ b/db/clientcursor.h @@ -74,7 +74,7 @@ namespace mongo { CCById::iterator it = clientCursorsById.find(id); if ( it == clientCursorsById.end() ) { if ( warn ) - OCCASIONALLY cout << "ClientCursor::find(): cursor not found in map " << id << " (ok after a drop)\n"; + OCCASIONALLY out() << "ClientCursor::find(): cursor not found in map " << id << " (ok after a drop)\n"; return 0; } return it->second; diff --git a/db/cloner.cpp b/db/cloner.cpp index d3cc5c77a17..6f09ccdae72 100644 --- a/db/cloner.cpp +++ b/db/cloner.cpp @@ -69,9 +69,9 @@ namespace mongo { BSONObj res= b.doneAndDecouple(); /* if( mod ) { - cout << "before: " << o.toString() << endl; + out() << "before: " << o.toString() << endl; o.dump(); - cout << "after: " << res.toString() << endl; + out() << "after: " << res.toString() << endl; res.dump(); }*/ @@ -98,7 +98,7 @@ namespace mongo { /* assure object is valid. note this will slow us down a good bit. */ if ( !tmp.valid() ) { - cout << "skipping corrupt object from " << from_collection << '\n'; + out() << "skipping corrupt object from " << from_collection << '\n'; continue; } @@ -162,9 +162,9 @@ namespace mongo { string s = "bad system.namespaces object " + collection.toString(); /* temp - cout << masterHost << endl; - cout << ns << endl; - cout << e.toString() << endl; + out() << masterHost << endl; + out() << ns << endl; + out() << e.toString() << endl; exit(1);*/ massert(s.c_str(), false); diff --git a/db/database.h b/db/database.h index 4bfba490122..fd3080dc6bc 100644 --- a/db/database.h +++ b/db/database.h @@ -53,12 +53,12 @@ namespace mongo { assert(this); if ( n < 0 || n >= DiskLoc::MaxFiles ) { - cout << "getFile(): n=" << n << endl; + out() << "getFile(): n=" << n << endl; assert( n >= 0 && n < DiskLoc::MaxFiles ); } DEV { if ( n > 100 ) - cout << "getFile(): n=" << n << "?" << endl; + out() << "getFile(): n=" << n << "?" << endl; } while ( n >= (int) files.size() ) files.push_back(0); diff --git a/db/db.cpp b/db/db.cpp index 92a107e4345..503e22e9033 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -57,11 +57,11 @@ namespace mongo { } mystartupdbcpp; void quicktest() { - cout << "quicktest()\n"; + out() << "quicktest()\n"; MemoryMappedFile mmf; char *m = (char *) mmf.map("/tmp/quicktest", 16384); - // cout << "mmf reads: " << m << endl; + // out() << "mmf reads: " << m << endl; strcpy_s(m, 1000, "hello worldz"); } @@ -89,7 +89,7 @@ namespace mongo { c->_current(); c->advance(); } - cout << endl; + out() << endl; database = 0; } @@ -175,7 +175,7 @@ namespace mongo { DbResponse dbresponse; if ( !assembleResponse( m, dbresponse ) ) { - cout << curTimeMillis() % 10000 << " end msg " << dbMsgPort.farEnd.toString() << endl; + out() << curTimeMillis() % 10000 << " end msg " << dbMsgPort.farEnd.toString() << endl; if ( dbMsgPort.farEnd.isLocalHost() ) { dbMsgPort.shutdown(); sleepmillis(50); @@ -183,7 +183,7 @@ namespace mongo { exit(EXIT_SUCCESS); } else { - cout << " (not from localhost, ignoring end msg)" << endl; + out() << " (not from localhost, ignoring end msg)" << endl; } } @@ -234,10 +234,10 @@ namespace mongo { Timer t; bool ok = p.call(send, response); double tm = t.micros() + 1; - cout << " ****ok. response.data:" << ok << " time:" << tm / 1000.0 << "ms " << + out() << " ****ok. response.data:" << ok << " time:" << tm / 1000.0 << "ms " << ((double) len) * 8 / 1000000 / (tm/1000000) << "Mbps" << endl; if ( q+1 < Loops ) { - cout << "\t\tSLEEP 8 then sending again as a test" << endl; + out() << "\t\tSLEEP 8 then sending again as a test" << endl; sleepsecs(8); } } @@ -341,12 +341,12 @@ int main(int argc, char* argv[], char *envp[] ) unsigned x = 0x12345678; unsigned char& b = (unsigned char&) x; if ( b != 0x78 ) { - cout << "big endian cpus not yet supported" << endl; + out() << "big endian cpus not yet supported" << endl; return 33; } } - DEV cout << "warning: DEV mode enabled\n"; + DEV out() << "warning: DEV mode enabled\n"; #if !defined(_WIN32) signal(SIGPIPE, pipeSigHandler); @@ -363,7 +363,7 @@ int main(int argc, char* argv[], char *envp[] ) JavaJS = new JavaJSImpl(); javajstest(); #else - cout << "NOJNI build cannot test" << endl; + out() << "NOJNI build cannot test" << endl; #endif return 0; } @@ -467,7 +467,7 @@ int main(int argc, char* argv[], char *envp[] ) else if ( strncmp(s.c_str(), "--oplog", 7) == 0 ) { int x = s[7] - '0'; if ( x < 0 || x > 7 ) { - cout << "can't interpret --oplog setting" << endl; + out() << "can't interpret --oplog setting" << endl; exit(13); } opLogging = x; @@ -480,38 +480,38 @@ int main(int argc, char* argv[], char *envp[] ) } usage: - cout << "Mongo db "; + out() << "Mongo db "; #if defined(NOJNI) - cout << "[nojni build] "; + out() << "[nojni build] "; #endif - cout << "usage:\n"; - cout << " run run db" << endl; - cout << " msg end [port] shut down db server listening on port (or default)" << endl; - cout << " msg [msg] [port] send a request to the db server listening on port (or default)" << endl; - cout << " msglots send a bunch of test messages, and then wait for answer on the last one" << endl; - cout << " longmsg send a long test message to the db server" << endl; - cout << " quicktest just check basic assertions and exit" << endl; - cout << " test2 run test2() - see code" << endl; - cout << "\nOptions:\n"; - cout << " --help show this usage information\n"; - 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 << " --verbose\n"; - cout << " --objcheck inspect client data for validity on receipt\n"; - cout << " --quota enable db quota management\n"; - cout << " --appsrvpath <path> root directory for the babble app server\n"; - cout << " --nocursors diagnostic/debugging option\n"; - cout << " --nojni" << endl; - cout << " --oplog<n> 0=off 1=W 2=R 3=both 7=W+some reads" << endl; - cout << " --oplogSize <size> custom size for operation log" << endl; - cout << "\nReplication:" << endl; - cout << " --master\n"; - cout << " --slave" << endl; - cout << " --source <server:port>" << endl; - cout << " --pairwith <server:port> <arbiter>" << endl; - cout << endl; + out() << "usage:\n"; + out() << " run run db" << endl; + out() << " msg end [port] shut down db server listening on port (or default)" << endl; + out() << " msg [msg] [port] send a request to the db server listening on port (or default)" << endl; + out() << " msglots send a bunch of test messages, and then wait for answer on the last one" << endl; + out() << " longmsg send a long test message to the db server" << endl; + out() << " quicktest just check basic assertions and exit" << endl; + out() << " test2 run test2() - see code" << endl; + out() << "\nOptions:\n"; + out() << " --help show this usage information\n"; + out() << " --port <portno> specify port number, default is 27017\n"; + out() << " --dbpath <root> directory for datafiles, default is /data/db/\n"; + out() << " --quiet quieter output\n"; + out() << " --cpu show cpu+iowait utilization periodically\n"; + out() << " --verbose\n"; + out() << " --objcheck inspect client data for validity on receipt\n"; + out() << " --quota enable db quota management\n"; + out() << " --appsrvpath <path> root directory for the babble app server\n"; + out() << " --nocursors diagnostic/debugging option\n"; + out() << " --nojni" << endl; + out() << " --oplog<n> 0=off 1=W 2=R 3=both 7=W+some reads" << endl; + out() << " --oplogSize <size> custom size for operation log" << endl; + out() << "\nReplication:" << endl; + out() << " --master\n"; + out() << " --slave" << endl; + out() << " --source <server:port>" << endl; + out() << " --pairwith <server:port> <arbiter>" << endl; + out() << endl; return 0; } @@ -523,7 +523,7 @@ namespace mongo { string getDbContext(); -#undef cout +#undef out() #if !defined(_WIN32) @@ -542,12 +542,12 @@ namespace mongo { if ( ++segvs > 1 ) { signal(x, SIG_DFL); if ( segvs == 2 ) { - cout << "\n\n\n got 2nd SIGSEGV" << endl; + out() << "\n\n\n got 2nd SIGSEGV" << endl; sayDbContext(); } return; } - cout << "got SIGSEGV " << x << ", terminating :-(" << endl; + out() << "got SIGSEGV " << x << ", terminating :-(" << endl; sayDbContext(); // closeAllSockets(); // MemoryMappedFile::closeAllFiles(); @@ -557,7 +557,7 @@ namespace mongo { void mysighandler(int x) { signal(x, SIG_IGN); - cout << "got kill or ctrl c signal " << x << ", will terminate after current cmd ends" << endl; + out() << "got kill or ctrl c signal " << x << ", will terminate after current cmd ends" << endl; { dblock lk; log() << "now exiting" << endl; diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp index 99f7e6a9b60..7e6504b4669 100644 --- a/db/dbcommands.cpp +++ b/db/dbcommands.cpp @@ -568,7 +568,7 @@ namespace mongo { // delete just one index int x = d->findIndexByName(idxName); if ( x >= 0 ) { - cout << " d->nIndexes was " << d->nIndexes << endl; + out() << " d->nIndexes was " << d->nIndexes << endl; anObjBuilder.append("nIndexesWas", (double)d->nIndexes); /* note it is important we remove the IndexDetails with this diff --git a/db/dbeval.cpp b/db/dbeval.cpp index 9bc78d1b6a9..79d571ca1a4 100644 --- a/db/dbeval.cpp +++ b/db/dbeval.cpp @@ -73,8 +73,8 @@ namespace mongo { if ( args.type() == Array ) { BSONObj eo = args.embeddedObject(); if ( edebug ) { - cout << "args:" << eo.toString() << endl; - cout << "code:\n" << code << endl; + out() << "args:" << eo.toString() << endl; + out() << "code:\n" << code << endl; } s.setObject("args", eo); } @@ -85,7 +85,7 @@ namespace mongo { res = s.invoke(f); int m = t.millis(); if ( m > 100 ) { - stdcout() << "TEMP: dbeval too slow:" << endl; + out() << "TEMP: dbeval too slow:" << endl; problem() << "dbeval time: " << dec << m << "ms " << ns << endl; OCCASIONALLY log() << code << endl; else if ( m >= 1000 ) log() << code << endl; diff --git a/db/dbwebserver.cpp b/db/dbwebserver.cpp index 62301a346a0..60e8b76f969 100644 --- a/db/dbwebserver.cpp +++ b/db/dbwebserver.cpp @@ -161,7 +161,7 @@ namespace mongo { vector<string>& headers // if completely empty, content-type: text/html will be added ) { - //cout << "url [" << url << "]" << endl; + //out() << "url [" << url << "]" << endl; if ( url.size() > 1 ) { handleRESTRequest( rq , url , responseMsg , responseCode , headers ); @@ -263,7 +263,7 @@ namespace mongo { responseCode = 400; headers.push_back( "X_err: bad request" ); ss << "don't know how to handle a [" << method << "]"; - cout << "don't know how to handle a [" << method << "]" << endl; + out() << "don't know how to handle a [" << method << "]" << endl; } responseMsg = ss.str(); diff --git a/db/flushtest.cpp b/db/flushtest.cpp index 6730666279b..a301e0e9195 100644 --- a/db/flushtest.cpp +++ b/db/flushtest.cpp @@ -5,10 +5,6 @@ namespace mongo { -// logstream defines these, we don't want that: -#undef cout -#undef endl - #if defined(F_FULLFSYNC) void fullsync(int f) { fcntl( f, F_FULLFSYNC ); diff --git a/db/instance.cpp b/db/instance.cpp index 676c3758a53..323e5bb6d29 100644 --- a/db/instance.cpp +++ b/db/instance.cpp @@ -92,7 +92,7 @@ namespace mongo { if ( strncmp(ddd.getns(), "clusterstock", 12) != 0 ) { static int q; if ( ++q < 20 ) - cout << "TEMP skip " << ddd.getns() << endl; + out() << "TEMP skip " << ddd.getns() << endl; goto skip; } #endif @@ -102,7 +102,7 @@ namespace mongo { char *p = m.data->_data; int len = strlen(p); if ( len > 400 ) - cout << curTimeMillis() % 10000 << + out() << curTimeMillis() % 10000 << " long msg received, len:" << len << " ends with: " << p + len - 10 << endl; bool end = strcmp("end", p) == 0; @@ -169,7 +169,7 @@ namespace mongo { } } else { - cout << " operation isn't supported: " << m.data->operation() << endl; + out() << " operation isn't supported: " << m.data->operation() << endl; assert(false); } @@ -178,7 +178,7 @@ namespace mongo { DEV log = true; if ( log || ms > 100 ) { ss << ' ' << t.millis() << "ms"; - cout << ss.str().c_str() << endl; + out() << ss.str().c_str() << endl; } if ( database && database->profile >= 1 ) { if ( database->profile >= 2 || ms >= 100 ) { @@ -453,7 +453,7 @@ namespace mongo { } } else { - cout << " jnicall: operation isn't supported: " << m.data->operation() << endl; + mongo::out() << " jnicall: operation isn't supported: " << m.data->operation() << endl; assert(false); } @@ -461,7 +461,7 @@ namespace mongo { log = log || ctr++ % 128 == 0; if ( log || ms > 100 ) { ss << ' ' << t.millis() << "ms"; - cout << ss.str().c_str() << endl; + mongo::out() << ss.str().c_str() << endl; } if ( database && database->profile >= 1 ) { if ( database->profile >= 2 || ms >= 100 ) { @@ -511,14 +511,14 @@ namespace mongo { /* not using log() herein in case we are called from segvhandler and we were already locked */ #undef exit void dbexit(int rc, const char *why) { - cout << "dbexit: " << why << "; flushing op log and files" << endl; + out() << "dbexit: " << why << "; flushing op log and files" << endl; flushOpLog(); /* must do this before unmapping mem or you may get a seg fault */ closeAllSockets(); MemoryMappedFile::closeAllFiles(); - cout << "dbexit: really exiting now" << endl; + out() << "dbexit: really exiting now" << endl; exit(rc); } diff --git a/db/javajs.cpp b/db/javajs.cpp index f7daddd5a14..960484c10c4 100644 --- a/db/javajs.cpp +++ b/db/javajs.cpp @@ -68,7 +68,7 @@ namespace mongo { longer needed and can be removed. */ extern "C" void tss_cleanup_implemented(void) { - //cout << "tss_cleanup_implemented called" << endl; + //out() << "tss_cleanup_implemented called" << endl; } #endif @@ -425,7 +425,7 @@ namespace mongo { int len = _getEnv()->CallStaticIntMethod( _dbhook , _scopeGetObject , id , _getEnv()->NewStringUTF( field ) , bb ); _getEnv()->DeleteLocalRef( bb ); - //cout << "len : " << len << endl; + //out() << "len : " << len << endl; jassert( len > 0 && len < guess ); BSONObj obj(buf, true); @@ -478,7 +478,7 @@ namespace mongo { int res = _jvm->AttachCurrentThread( (void**)&env , (void*)&_vmArgs ); if ( res ) { - cout << "ERROR javajs attachcurrentthread fails res:" << res << '\n'; + out() << "ERROR javajs attachcurrentthread fails res:" << res << '\n'; assert(false); } @@ -636,7 +636,7 @@ namespace mongo { if ( debug ) log() << "about to create scope" << endl; jlong scope = JavaJS.scopeCreate(); jassert( scope ); - if ( debug ) cout << "got scope" << endl; + if ( debug ) out() << "got scope" << endl; jlong func1 = JavaJS.functionCreate( "foo = 5.6; bar = \"eliot\"; abc = { foo : 517 }; " ); @@ -645,28 +645,28 @@ namespace mongo { jassert( 5.6 == JavaJS.scopeGetNumber( scope , "foo" ) ); jassert( ((string)"eliot") == JavaJS.scopeGetString( scope , "bar" ) ); - if ( debug ) cout << "func2 start" << endl; + if ( debug ) out() << "func2 start" << endl; jassert( JavaJS.scopeSetNumber( scope , "a" , 5.17 ) ); jassert( JavaJS.scopeSetString( scope , "b" , "eliot" ) ); jlong func2 = JavaJS.functionCreate( "assert( 5.17 == a ); assert( \"eliot\" == b );" ); jassert( ! JavaJS.invoke( scope , func2 ) ); - if ( debug ) cout << "func2 end" << endl; + if ( debug ) out() << "func2 end" << endl; - if ( debug ) cout << "func3 start" << endl; + if ( debug ) out() << "func3 start" << endl; jlong func3 = JavaJS.functionCreate( "function(){ z = true; } " ); jassert( func3 ); jassert( ! JavaJS.invoke( scope , func3 ) ); jassert( JavaJS.scopeGetBoolean( scope , "z" ) ); - if ( debug ) cout << "func3 done" << endl; + if ( debug ) out() << "func3 done" << endl; #ifdef J_USE_OBJ - if ( debug ) cout << "going to get object" << endl; + if ( debug ) out() << "going to get object" << endl; BSONObj obj = JavaJS.scopeGetObject( scope , "abc" ); - if ( debug ) cout << "done getting object" << endl; + if ( debug ) out() << "done getting object" << endl; if ( debug ) { - cout << "obj : " << obj.toString() << endl; + out() << "obj : " << obj.toString() << endl; } { @@ -677,27 +677,27 @@ namespace mongo { time_t end = time(0); if ( debug ) - cout << "time : " << (unsigned) ( end - start ) << endl; + out() << "time : " << (unsigned) ( end - start ) << endl; } - if ( debug ) cout << "func4 start" << endl; + if ( debug ) out() << "func4 start" << endl; JavaJS.scopeSetObject( scope , "obj" , &obj ); - if ( debug ) cout << "\t here 1" << endl; + if ( debug ) out() << "\t here 1" << endl; jlong func4 = JavaJS.functionCreate( "tojson( obj );" ); - if ( debug ) cout << "\t here 2" << endl; + if ( debug ) out() << "\t here 2" << endl; jassert( ! JavaJS.invoke( scope , func4 ) ); - if ( debug ) cout << "func4 end" << endl; + if ( debug ) out() << "func4 end" << endl; - if ( debug ) cout << "func5 start" << endl; + if ( debug ) out() << "func5 start" << endl; jassert( JavaJS.scopeSetObject( scope , "c" , &obj ) ); jlong func5 = JavaJS.functionCreate( "assert.eq( 517 , c.foo );" ); jassert( func5 ); jassert( ! JavaJS.invoke( scope , func5 ) ); - if ( debug ) cout << "func5 done" << endl; + if ( debug ) out() << "func5 done" << endl; #endif - if ( debug ) cout << "func6 start" << endl; + if ( debug ) out() << "func6 start" << endl; for ( int i=0; i<100; i++ ) { double val = i + 5; JavaJS.scopeSetNumber( scope , "zzz" , val ); @@ -706,7 +706,7 @@ namespace mongo { double n = JavaJS.scopeGetNumber( scope , "xxx" ); jassert( val == n ); } - if ( debug ) cout << "func6 done" << endl; + if ( debug ) out() << "func6 done" << endl; jlong func7 = JavaJS.functionCreate( "return 11;" ); jassert( ! JavaJS.invoke( scope , func7 ) ); diff --git a/db/jsobj.cpp b/db/jsobj.cpp index 6ba5d040cf6..e280fdb4efb 100644 --- a/db/jsobj.cpp +++ b/db/jsobj.cpp @@ -347,7 +347,7 @@ namespace mongo { } break; default: - cout << "BSONElement: bad type " << (int) type() << endl; + out() << "BSONElement: bad type " << (int) type() << endl; assert(false); } ((BSONElement *) this)->totalSize = x + fieldNameSize; @@ -356,11 +356,11 @@ namespace mongo { const char *next = data + totalSize; if ( *next < MinKey || ( *next > JSTypeMax && *next != MaxKey ) ) { // bad type. - cout << "***\n"; - cout << "Bad data or size in BSONElement::size()\n"; - cout << "bad type:" << (int) *next << '\n'; - cout << "totalsize:" << totalSize << " fieldnamesize:" << fieldNameSize << '\n'; - cout << "lastrec:" << endl; + out() << "***\n"; + out() << "Bad data or size in BSONElement::size()\n"; + out() << "bad type:" << (int) *next << '\n'; + out() << "totalsize:" << totalSize << " fieldnamesize:" << fieldNameSize << '\n'; + out() << "lastrec:" << endl; //dumpmemory(data, totalSize + 15); assert(false); } @@ -460,7 +460,7 @@ namespace mongo { return strcmp(l.regexFlags(), r.regexFlags()); } default: - cout << "compareElementValues: bad type " << (int) l.type() << endl; + out() << "compareElementValues: bad type " << (int) l.type() << endl; assert(false); } return -1; diff --git a/db/jsobj.h b/db/jsobj.h index 6078cc7ecca..ed46d5faff8 100644 --- a/db/jsobj.h +++ b/db/jsobj.h @@ -399,13 +399,13 @@ namespace mongo { void validateEmpty(); void dump() { - cout << hex; + out() << hex; const char *p = objdata(); for ( int i = 0; i < objsize(); i++ ) { - cout << i << '\t' << (unsigned) *p; + out() << i << '\t' << (unsigned) *p; if ( *p >= 'A' && *p <= 'z' ) - cout << '\t' << *p; - cout << endl; + out() << '\t' << *p; + out() << endl; p++; } } diff --git a/db/matcher.cpp b/db/matcher.cpp index bfa07864c08..83bd41cf0f2 100644 --- a/db/matcher.cpp +++ b/db/matcher.cpp @@ -152,7 +152,7 @@ namespace mongo { if ( e.type() == RegEx ) { if ( nRegex >= 4 ) { - cout << "ERROR: too many regexes in query" << endl; + out() << "ERROR: too many regexes in query" << endl; } else { pcrecpp::RE_Options options; @@ -527,8 +527,8 @@ namespace mongo { /* static const boost::regex e("(\\d{4}[- ]){3}\\d{4}"); static const boost::regex b("....."); - cout << "regex result: " << regex_match("hello", e) << endl; - cout << "regex result: " << regex_match("abcoo", b) << endl; + out() << "regex result: " << regex_match("hello", e) << endl; + out() << "regex result: " << regex_match("abcoo", b) << endl; */ pcrecpp::RE re1(")({a}h.*o"); pcrecpp::RE re("h.llo"); diff --git a/db/namespace.cpp b/db/namespace.cpp index 74707a472c7..d2e7e9d3c66 100644 --- a/db/namespace.cpp +++ b/db/namespace.cpp @@ -72,7 +72,7 @@ namespace mongo { (unsigned&) (((Record *) d)->data) = 0xeeeeeeee; } dassert( dloc.drec() == d ); - DEBUGGING cout << "TEMP: add deleted rec " << dloc.toString() << ' ' << hex << d->extentOfs << endl; + DEBUGGING out() << "TEMP: add deleted rec " << dloc.toString() << ' ' << hex << d->extentOfs << endl; if ( capped ) { if ( !deletedList[ 1 ].isValid() ) { // Initial extent allocation. Insert at end. @@ -114,7 +114,7 @@ namespace mongo { extentLoc.set(loc.a(), r->extentOfs); assert( r->extentOfs < loc.getOfs() ); - DEBUGGING cout << "TEMP: alloc() returns " << loc.toString() << ' ' << ns << " lentoalloc:" << lenToAlloc << " ext:" << extentLoc.toString() << endl; + DEBUGGING out() << "TEMP: alloc() returns " << loc.toString() << ' ' << ns << " lentoalloc:" << lenToAlloc << " ext:" << extentLoc.toString() << endl; int left = regionlen - lenToAlloc; if ( capped == 0 ) { @@ -214,24 +214,24 @@ namespace mongo { } void NamespaceDetails::dumpDeleted(set<DiskLoc> *extents) { -// cout << "DUMP deleted chains" << endl; +// out() << "DUMP deleted chains" << endl; for ( int i = 0; i < Buckets; i++ ) { -// cout << " bucket " << i << endl; +// out() << " bucket " << i << endl; DiskLoc dl = deletedList[i]; while ( !dl.isNull() ) { DeletedRecord *r = dl.drec(); DiskLoc extLoc(dl.a(), r->extentOfs); if ( extents == 0 || extents->count(extLoc) <= 0 ) { - cout << " bucket " << i << endl; - cout << " " << dl.toString() << " ext:" << extLoc.toString(); + out() << " bucket " << i << endl; + out() << " " << dl.toString() << " ext:" << extLoc.toString(); if ( extents && extents->count(extLoc) <= 0 ) - cout << '?'; - cout << " len:" << r->lengthWithHeaders << endl; + out() << '?'; + out() << " len:" << r->lengthWithHeaders << endl; } dl = r->nextDeleted; } } -// cout << endl; +// out() << endl; } /* combine adjacent deleted records @@ -259,7 +259,7 @@ namespace mongo { while ( 1 ) { j++; if ( j == drecs.end() ) { - DEBUGGING cout << "TEMP: compact adddelrec\n"; + DEBUGGING out() << "TEMP: compact adddelrec\n"; addDeletedRec(a.drec(), a); break; } @@ -269,13 +269,13 @@ namespace mongo { a.drec()->lengthWithHeaders += b.drec()->lengthWithHeaders; j++; if ( j == drecs.end() ) { - DEBUGGING cout << "temp: compact adddelrec2\n"; + DEBUGGING out() << "temp: compact adddelrec2\n"; addDeletedRec(a.drec(), a); return; } b = *j; } - DEBUGGING cout << "temp: compact adddelrec3\n"; + DEBUGGING out() << "temp: compact adddelrec3\n"; addDeletedRec(a.drec(), a); a = b; } @@ -340,15 +340,15 @@ namespace mongo { int n_complaints_cap = 0; 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'; + out() << "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 ) { - cout << " Extent " << i; + out() << " 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() << + out() << " (capExtent)"; + out() << '\n'; + out() << " magic: " << hex << e.ext()->magic << dec << " extent->ns: " << e.ext()->ns.buf << '\n'; + out() << " fr: " << e.ext()->firstRecord.toString() << " 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 diff --git a/db/pdfile.cpp b/db/pdfile.cpp index 05d8dc25e08..8c226a20952 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -70,12 +70,12 @@ namespace mongo { _objdata = r->data; _objsize = *((int*) _objdata); if( _objsize > r->netLength() ) { - cout << "About to assert fail _objsize <= r->netLength()" << endl; - cout << " _objsize: " << _objsize << endl; - cout << " netLength(): " << r->netLength() << endl; - cout << " extentOfs: " << r->extentOfs << endl; - cout << " nextOfs: " << r->nextOfs << endl; - cout << " prevOfs: " << r->prevOfs << endl; + out() << "About to assert fail _objsize <= r->netLength()" << endl; + out() << " _objsize: " << _objsize << endl; + out() << " netLength(): " << r->netLength() << endl; + out() << " extentOfs: " << r->extentOfs << endl; + out() << " nextOfs: " << r->nextOfs << endl; + out() << " prevOfs: " << r->prevOfs << endl; assert( _objsize <= r->netLength() ); } iFree = false; @@ -243,7 +243,7 @@ namespace mongo { no files are open yet. we might want to do something about that. */ if ( loops > 8 ) { assert( loops < 10000 ); - cout << "warning: loops=" << loops << " fileno:" << fileNo << ' ' << ns << '\n'; + out() << "warning: loops=" << loops << " fileno:" << fileNo << ' ' << ns << '\n'; } log() << "newExtent: " << ns << " file " << fileNo << " full, adding a new file\n"; return database->addAFile()->newExtent(ns, approxSize, newCapped, loops+1); @@ -270,7 +270,7 @@ namespace mongo { } details->lastExtentSize = approxSize; - DEBUGGING cout << "temp: newextent adddelrec " << ns << endl; + DEBUGGING out() << "temp: newextent adddelrec " << ns << endl; details->addDeletedRec(emptyLoc.drec(), emptyLoc); DEV log() << "new extent " << ns << " size: 0x" << hex << ExtentSize << " loc: 0x" << hex << offset @@ -354,20 +354,20 @@ namespace mongo { DiskLoc loc; bool found = nsindex(ns)->find(ns, loc); if ( !found ) { - // cout << "info: findAll() namespace does not exist: " << ns << endl; + // out() << "info: findAll() namespace does not exist: " << ns << endl; return auto_ptr<Cursor>(new BasicCursor(DiskLoc())); } Extent *e = getExtent(loc); DEBUGGING { - cout << "listing extents for " << ns << endl; + out() << "listing extents for " << ns << endl; DiskLoc tmp = loc; set<DiskLoc> extents; while ( 1 ) { Extent *f = getExtent(tmp); - cout << "extent: " << tmp.toString() << endl; + out() << "extent: " << tmp.toString() << endl; extents.insert(tmp); tmp = f->xnext; if ( tmp.isNull() ) @@ -375,7 +375,7 @@ namespace mongo { f = f->getNextExtent(); } - cout << endl; + out() << endl; nsdetails(ns)->dumpDeleted(&extents); } @@ -384,7 +384,7 @@ namespace mongo { /* todo: if extent is empty, free it for reuse elsewhere. that is a bit complicated have to clean up the freelists. */ - RARELY cout << "info DFM::findAll(): extent " << loc.toString() << " was empty, skipping ahead " << ns << endl; + RARELY out() << "info DFM::findAll(): extent " << loc.toString() << " was empty, skipping ahead " << ns << endl; // find a nonempty extent // it might be nice to free the whole extent here! but have to clean up free recs then. e = e->getNextExtent(); @@ -413,7 +413,7 @@ namespace mongo { if ( !d->capped ) { Extent *e = d->lastExtent.ext(); while ( e->lastRecord.isNull() && !e->xprev.isNull() ) { - OCCASIONALLY cout << " findTableScan: extent empty, skipping ahead" << endl; + OCCASIONALLY out() << " findTableScan: extent empty, skipping ahead" << endl; e = e->getPrevExtent(); } return auto_ptr<Cursor>(new ReverseCursor( e->lastRecord )); @@ -471,8 +471,8 @@ namespace mongo { void IndexDetails::getKeysFromObject( const BSONObj& obj, BSONObjSetDefaultOrder& keys) const { BSONObj keyPattern = info.obj().getObjectField("key"); // e.g., keyPattern == { ts : 1 } if ( keyPattern.objsize() == 0 ) { - cout << keyPattern.toString() << endl; - cout << info.obj().toString() << endl; + out() << keyPattern.toString() << endl; + out() << info.obj().toString() << endl; assert(false); } BSONObjBuilder b; @@ -546,10 +546,10 @@ namespace mongo { id.getKeysFromObject(obj, keys); for ( set<BSONObj>::iterator i=keys.begin(); i != keys.end(); i++ ) { BSONObj j = *i; -// cout << "UNINDEX: j:" << j.toString() << " head:" << id.head.toString() << dl.toString() << endl; +// out() << "UNINDEX: j:" << j.toString() << " head:" << id.head.toString() << dl.toString() << endl; if ( otherTraceLevel >= 5 ) { - cout << "_unindexRecord() " << obj.toString(); - cout << "\n unindex:" << j.toString() << endl; + out() << "_unindexRecord() " << obj.toString(); + out() << "\n unindex:" << j.toString() << endl; } nUnindexes++; bool ok = false; @@ -558,15 +558,15 @@ namespace mongo { } catch (AssertionException&) { problem() << "Assertion failure: _unindex failed " << id.indexNamespace() << endl; - cout << "Assertion failure: _unindex failed" << '\n'; - cout << " obj:" << obj.toString() << '\n'; - cout << " key:" << j.toString() << '\n'; - cout << " dl:" << dl.toString() << endl; + out() << "Assertion failure: _unindex failed" << '\n'; + out() << " obj:" << obj.toString() << '\n'; + out() << " key:" << j.toString() << '\n'; + out() << " dl:" << dl.toString() << endl; sayDbContext(); } if ( !ok ) { - cout << "unindex failed (key too big?) " << id.indexNamespace() << '\n'; + out() << "unindex failed (key too big?) " << id.indexNamespace() << '\n'; } } } @@ -586,7 +586,7 @@ namespace mongo { NamespaceDetails* d = nsdetails(ns); if ( d->capped && !cappedOK ) { - cout << "failing remove on a capped ns " << ns << endl; + out() << "failing remove on a capped ns " << ns << endl; return; } @@ -720,7 +720,7 @@ namespace mongo { } catch (AssertionException&) { ss << " exception update index "; - cout << " caught assertion update index " << idxns.c_str() << '\n'; + out() << " caught assertion update index " << idxns.c_str() << '\n'; problem() << " caught assertion update index " << idxns.c_str() << endl; } } @@ -817,14 +817,14 @@ namespace mongo { const char *sys = strstr(ns, "system."); if ( sys ) { if ( sys == ns ) { - cout << "ERROR: attempt to insert for invalid database 'system': " << ns << endl; + out() << "ERROR: attempt to insert for invalid database 'system': " << ns << endl; return DiskLoc(); } if ( strstr(ns, ".system.") ) { if ( strstr(ns, ".system.indexes") ) addIndex = true; else if ( !god ) { - cout << "ERROR: attempt to insert in system namespace " << ns << endl; + out() << "ERROR: attempt to insert in system namespace " << ns << endl; return DiskLoc(); } } @@ -856,9 +856,9 @@ namespace mongo { BSONObj key = io.getObjectField("key"); if ( *name == 0 || tabletoidxns.empty() || key.isEmpty() || key.objsize() > 2048 ) { - cout << "user warning: bad add index attempt name:" << (name?name:"") << "\n ns:" << + out() << "user warning: bad add index attempt name:" << (name?name:"") << "\n ns:" << tabletoidxns << "\n ourns:" << ns; - cout << "\n idxobj:" << io.toString() << endl; + out() << "\n idxobj:" << io.toString() << endl; return DiskLoc(); } tableToIndex = nsdetails(tabletoidxns.c_str()); @@ -878,7 +878,7 @@ namespace mongo { return DiskLoc(); } if ( tableToIndex->findIndexByName(name) >= 0 ) { - //cout << "INFO: index:" << name << " already exists for:" << tabletoidxns << endl; + //out() << "INFO: index:" << name << " already exists for:" << tabletoidxns << endl; return DiskLoc(); } //indexFullNS = tabletoidxns; @@ -943,7 +943,7 @@ namespace mongo { if ( d->nIndexes ) indexRecord(d, buf, len, loc); -// cout << " inserted at loc:" << hex << loc.getOfs() << " lenwhdr:" << hex << lenWHdr << dec << ' ' << ns << endl; +// out() << " inserted at loc:" << hex << loc.getOfs() << " lenwhdr:" << hex << lenWHdr << dec << ' ' << ns << endl; return loc; } diff --git a/db/pdfile.h b/db/pdfile.h index 893f65ac341..d2378313a9a 100644 --- a/db/pdfile.h +++ b/db/pdfile.h @@ -417,9 +417,9 @@ namespace mongo { char buf[256]; nsToClient(ns, buf); if ( database->name != buf ) { - cout << "ERROR: attempt to write to wrong database database\n"; - cout << " ns:" << ns << '\n'; - cout << " database->name:" << database->name << endl; + out() << "ERROR: attempt to write to wrong database database\n"; + out() << " ns:" << ns << '\n'; + out() << " database->name:" << database->name << endl; assert( database->name == buf ); } } diff --git a/db/query.cpp b/db/query.cpp index 3ff09721c0c..9481c71c8fe 100644 --- a/db/query.cpp +++ b/db/query.cpp @@ -109,7 +109,7 @@ namespace mongo { int direction = matchDirection( idxKey, order ); if ( direction != 0 ) { BSONObjBuilder b; - DEV cout << " using index " << d->indexes[i].indexNamespace() << '\n'; + DEV out() << " using index " << d->indexes[i].indexNamespace() << '\n'; if ( isSorted ) *isSorted = true; @@ -175,7 +175,7 @@ namespace mongo { be issues with it. so fix this to use index after that is fixed. */ - OCCASIONALLY cout << "finish query optimizer for lt gt compound\n"; + OCCASIONALLY out() << "finish query optimizer for lt gt compound\n"; goto fail; } } @@ -215,7 +215,7 @@ namespace mongo { } } BSONObj q2 = b2.done(); - DEV cout << "using index " << d->indexes[i].indexNamespace() << endl; + DEV out() << "using index " << d->indexes[i].indexNamespace() << endl; if ( simple && simpleKeyMatch ) *simpleKeyMatch = true; return auto_ptr<Cursor>( new BtreeCursor(d->indexes[i], q2, 1, query)); @@ -223,7 +223,7 @@ namespace mongo { } fail: - DEV cout << "getIndexCursor fail " << ns << '\n'; + DEV out() << "getIndexCursor fail " << ns << '\n'; return auto_ptr<Cursor>(); } @@ -234,13 +234,13 @@ fail: int deleteObjects(const char *ns, BSONObj pattern, bool justOne, bool god) { if ( strstr(ns, ".system.") && !god ) { /*if( strstr(ns, ".system.namespaces") ){ - cout << "info: delete on system namespace " << ns << '\n'; + out() << "info: delete on system namespace " << ns << '\n'; } else if( strstr(ns, ".system.indexes") ) { - cout << "info: delete on system namespace " << ns << '\n'; + out() << "info: delete on system namespace " << ns << '\n'; } else*/ { - cout << "ERROR: attempt to delete in system namespace " << ns << endl; + out() << "ERROR: attempt to delete in system namespace " << ns << endl; return -1; } } @@ -364,16 +364,16 @@ fail: (clean these up later...) */ int _updateObjects(const char *ns, BSONObj updateobj, BSONObj pattern, bool upsert, stringstream& ss, bool logop=false) { - //cout << "TEMP BAD"; + //out() << "TEMP BAD"; //lrutest.find(updateobj); int profile = database->profile; - // cout << "update ns:" << ns << " objsize:" << updateobj.objsize() << " queryobjsize:" << + // out() << "update ns:" << ns << " objsize:" << updateobj.objsize() << " queryobjsize:" << // pattern.objsize(); if ( strstr(ns, ".system.") ) { - cout << "\nERROR: attempt to update in system namespace " << ns << endl; + out() << "\nERROR: attempt to update in system namespace " << ns << endl; ss << " can't update system namespace "; return 0; } @@ -646,9 +646,9 @@ fail: (Which may indicate bad data from appserver?) */ if ( query.objsize() == 0 ) { - cout << "Bad query object?\n jsobj:"; - cout << jsobj.toString() << "\n query:"; - cout << query.toString() << endl; + out() << "Bad query object?\n jsobj:"; + out() << jsobj.toString() << "\n query:"; + out() << query.toString() << endl; uassert("bad query object", false); } @@ -677,7 +677,7 @@ fail: while ( c->ok() ) { BSONObj js = c->current(); //if( queryTraceLevel >= 50 ) - // cout << " checking against:\n " << js.toString() << endl; + // out() << " checking against:\n " << js.toString() << endl; nscanned++; bool deep; if ( !matcher->matches(js, &deep) ) { @@ -719,7 +719,7 @@ fail: ClientCursor *cc = new ClientCursor(); cc->c = c; cursorid = cc->cursorid; - DEV cout << " query has more, cursorid: " << cursorid << endl; + DEV out() << " query has more, cursorid: " << cursorid << endl; //cc->pattern = query; cc->matcher = matcher; cc->ns = ns; @@ -758,7 +758,7 @@ fail: ClientCursor *cc = new ClientCursor(); cc->c = c; cursorid = cc->cursorid; - DEV cout << " query has no more but tailable, cursorid: " << cursorid << endl; + DEV out() << " query has no more but tailable, cursorid: " << cursorid << endl; //cc->pattern = query; cc->matcher = matcher; cc->ns = ns; @@ -849,9 +849,9 @@ fail: if ( !cc->matcher->matches(js, &deep) ) { } else { - //cout << "matches " << c->currLoc().toString() << ' ' << deep << '\n'; + //out() << "matches " << c->currLoc().toString() << ' ' << deep << '\n'; if ( deep && c->getsetdup(c->currLoc()) ) { - //cout << " but it's a dup \n"; + //out() << " but it's a dup \n"; } else { bool ok = fillQueryResultFromObj(b, cc->filter.get(), js); diff --git a/db/repl.cpp b/db/repl.cpp index 725d1152090..9a649d812de 100644 --- a/db/repl.cpp +++ b/db/repl.cpp @@ -948,7 +948,7 @@ namespace mongo { *p = EOO; //BSONObj temp(r); - //cout << "temp:" << temp.toString() << endl; + //out() << "temp:" << temp.toString() << endl; database = oldClient; } @@ -1025,7 +1025,7 @@ namespace mongo { try { s = _replMain(sources); } catch (...) { - cout << "TEMP: caught exception in _replMain" << endl; + out() << "TEMP: caught exception in _replMain" << endl; } { dblock lk; @@ -1127,7 +1127,7 @@ namespace mongo { void tempThread() { while ( 1 ) { - cout << dbMutexInfo.isLocked() << endl; + out() << dbMutexInfo.isLocked() << endl; sleepmillis(100); } } diff --git a/db/security.h b/db/security.h index 74aabce21ee..1bb4d1a5ca7 100644 --- a/db/security.h +++ b/db/security.h @@ -26,7 +26,7 @@ namespace mongo { public: AuthenticationInfo() { } ~AuthenticationInfo() { -// cout << "TEMP: auth info was cleaned up ********************************************" << endl; +// stdout() << "TEMP: auth info was cleaned up ********************************************" << endl; } }; diff --git a/db/tests.cpp b/db/tests.cpp index f5c2bedff3b..9011414e3fb 100644 --- a/db/tests.cpp +++ b/db/tests.cpp @@ -25,7 +25,7 @@ namespace mongo { int test2_old() { - cout << "test2" << endl; + out() << "test2" << endl; printStackTrace(); if ( 1 ) return 1; @@ -47,14 +47,14 @@ namespace mongo { *p = 'a'; f.flush(true); - cout << "done" << endl; + out() << "done" << endl; char *x = start + 32 * 1024 * 1024; char *y = start + 48 * 1024 * 1024; char *z = start + 62 * 1024 * 1024; strcpy(z, "zfoo"); - cout << "y" << endl; + out() << "y" << endl; strcpy(y, "yfoo"); strcpy(x, "xfoo"); strcpy(start, "xfoo"); diff --git a/dbgrid/dbgrid.cpp b/dbgrid/dbgrid.cpp index 1d3c13a7f4b..872416caac2 100644 --- a/dbgrid/dbgrid.cpp +++ b/dbgrid/dbgrid.cpp @@ -51,12 +51,12 @@ namespace mongo { #endif void usage() { - cout << "Mongo dbgrid usage:\n\n"; - cout << " --port <portno>\n"; - cout << " --griddb <griddbname> [<griddbname>...]\n"; - cout << " --infer infer griddbname by replacing \"-n<n>\"\n"; - cout << " in our hostname with \"-grid\".\n"; - cout << endl; + out() << "Mongo dbgrid usage:\n\n"; + out() << " --port <portno>\n"; + out() << " --griddb <griddbname> [<griddbname>...]\n"; + out() << " --infer infer griddbname by replacing \"-n<n>\"\n"; + out() << " in our hostname with \"-grid\".\n"; + out() << endl; } MessagingPort *grab = 0; @@ -106,22 +106,22 @@ namespace mongo { gridDatabase.init(); /* try { - cout << "TEMP" << endl; + out() << "TEMP" << endl; { ScopedDbConnection c("localhost"); - cout << c.conn().findOne("dwight.bar", emptyObj).toString() << endl; + out() << c.conn().findOne("dwight.bar", emptyObj).toString() << endl; c.done(); - cout << "OK1" << endl; + out() << "OK1" << endl; } { ScopedDbConnection c("localhost"); c.conn().findOne("dwight.bar", emptyObj); c.done(); - cout << "OK1" << endl; + out() << "OK1" << endl; } - cout << "OK2" << endl; + out() << "OK2" << endl; } catch(...) { - cout << "exception" << endl; + out() << "exception" << endl; } */ @@ -161,11 +161,11 @@ int main(int argc, char* argv[], char *envp[] ) { n++; } if ( n == 0 ) { - cout << "error: no args for --griddb\n"; + out() << "error: no args for --griddb\n"; return 4; } if ( n > 2 ) { - cout << "error: --griddb does not support more than 2 parameters yet\n"; + out() << "error: --griddb does not support more than 2 parameters yet\n"; return 5; } } diff --git a/dbgrid/griddatabase.cpp b/dbgrid/griddatabase.cpp index 432ff124197..0dacb180ae1 100644 --- a/dbgrid/griddatabase.cpp +++ b/dbgrid/griddatabase.cpp @@ -71,7 +71,7 @@ namespace mongo { if ( dashDashGridDb.empty() ) { if ( !dashDashInfer ) { - cout << "--griddb or --infer required\n"; + out() << "--griddb or --infer required\n"; exit(7); } stringstream sl, sr; diff --git a/dbgrid/request.cpp b/dbgrid/request.cpp index 681099bc242..eb7af085c59 100644 --- a/dbgrid/request.cpp +++ b/dbgrid/request.cpp @@ -49,7 +49,7 @@ namespace mongo { DbMessage d(m); const char *ns = d.getns(); - cout << "TEMP: getmore: " << ns << endl; + out() << "TEMP: getmore: " << ns << endl; ScopedDbConnection dbcon(tempHost); DBClientConnection &c = dbcon.conn(); @@ -70,7 +70,7 @@ namespace mongo { try { if ( q.ntoreturn == -1 && strstr(q.ns, ".$cmd") ) { BSONObjBuilder builder; - cout << q.query.toString() << endl; + out() << q.query.toString() << endl; bool ok = runCommandAgainstRegistered(q.ns, q.query, builder); if ( ok ) { BSONObj x = builder.done(); diff --git a/dbtests/dbtests.cpp b/dbtests/dbtests.cpp index a5a1677cd78..45e1f0d3456 100644 --- a/dbtests/dbtests.cpp +++ b/dbtests/dbtests.cpp @@ -39,7 +39,7 @@ void usage() { " -debug run tests with verbose output\n" " -list list available test suites\n" " <suite> run the specified test suite only"; - cout << instructions << endl; + out() << instructions << endl; } int main( int argc, char** argv ) { diff --git a/dbtests/jsobjtests.cpp b/dbtests/jsobjtests.cpp index 4f62ca990fb..20be4bafd7a 100644 --- a/dbtests/jsobjtests.cpp +++ b/dbtests/jsobjtests.cpp @@ -426,7 +426,7 @@ namespace JsobjTests { private: static void assertEquals( const BSONObj &expected, const BSONObj &actual ) { if ( expected.woCompare( actual ) ) { - cout << "Expected: " << expected.toString() + out() << "Expected: " << expected.toString() << ", got: " << actual.toString(); } ASSERT( !expected.woCompare( actual ) ); diff --git a/dbtests/namespacetests.cpp b/dbtests/namespacetests.cpp index ac46a5b0d88..1dffd7f4bc3 100644 --- a/dbtests/namespacetests.cpp +++ b/dbtests/namespacetests.cpp @@ -90,7 +90,7 @@ namespace NamespaceTests { } static void assertEquals( const BSONObj &a, const BSONObj &b ) { if ( a.woCompare( b ) != 0 ) { - cout << "expected: " << a.toString() + out() << "expected: " << a.toString() << ", got: " << b.toString() << endl; } ASSERT( a.woCompare( b ) == 0 ); diff --git a/grid/message.cpp b/grid/message.cpp index 6d599d1d0b6..fd48c9443b4 100644 --- a/grid/message.cpp +++ b/grid/message.cpp @@ -224,7 +224,7 @@ namespace mongo { bool MessagingPort::recv(Message& m) { again: - mmm( cout << "* recv() sock:" << this->sock << endl; ) + mmm( out() << "* recv() sock:" << this->sock << endl; ) int len = -1; char *lenbuf = (char *) &len; @@ -232,7 +232,7 @@ again: while ( 1 ) { int x = ::recv(sock, lenbuf, lft, 0); if ( x == 0 ) { - DEV cout << "MessagingPort recv() conn closed? " << farEnd.toString() << endl; + DEV out() << "MessagingPort recv() conn closed? " << farEnd.toString() << endl; m.reset(); return false; } @@ -270,7 +270,7 @@ again: md->len = len; if ( len <= 0 ) { - cout << "got a length of " << len << ", something is wrong" << endl; + out() << "got a length of " << len << ", something is wrong" << endl; return false; } @@ -279,7 +279,7 @@ again: while ( 1 ) { int x = ::recv(sock, p, left, 0); if ( x == 0 ) { - DEV cout << "MessagingPort::recv(): conn closed? " << farEnd.toString() << endl; + DEV out() << "MessagingPort::recv(): conn closed? " << farEnd.toString() << endl; m.reset(); return false; } @@ -307,30 +307,30 @@ again: } bool MessagingPort::call(Message& toSend, Message& response) { - mmm( cout << "*call()" << endl; ) + mmm( out() << "*call()" << endl; ) MSGID old = toSend.data->id; say(/*to,*/ toSend); while ( 1 ) { bool ok = recv(response); if ( !ok ) return false; - //cout << "got response: " << response.data->responseTo << endl; + //out() << "got response: " << response.data->responseTo << endl; if ( response.data->responseTo == toSend.data->id ) break; - cout << "********************" << endl; - cout << "ERROR: MessagingPort::call() wrong id got:" << response.data->responseTo << " expect:" << toSend.data->id << endl; - cout << " old:" << old << endl; - cout << " response msgid:" << response.data->id << endl; - cout << " response len: " << response.data->len << endl; + out() << "********************" << endl; + out() << "ERROR: MessagingPort::call() wrong id got:" << response.data->responseTo << " expect:" << toSend.data->id << endl; + out() << " old:" << old << endl; + out() << " response msgid:" << response.data->id << endl; + out() << " response len: " << response.data->len << endl; assert(false); response.reset(); } - mmm( cout << "*call() end" << endl; ) + mmm( out() << "*call() end" << endl; ) return true; } void MessagingPort::say(Message& toSend, int responseTo) { - mmm( cout << "* say() sock:" << this->sock << " thr:" << GetCurrentThreadId() << endl; ) + mmm( out() << "* say() sock:" << this->sock << " thr:" << GetCurrentThreadId() << endl; ) MSGID msgid = NextMsgId; ++NextMsgId; toSend.data->id = msgid; diff --git a/tools/dump.cpp b/tools/dump.cpp index 63784831c01..a8b4e1fb139 100644 --- a/tools/dump.cpp +++ b/tools/dump.cpp @@ -28,7 +28,7 @@ namespace mongo { namespace dump { void doCollection( DBClientConnection & conn , const char * coll , path outputFile ) { - cout << "\t" << coll << " to " << outputFile.string() << endl; + mongo::out() << "\t" << coll << " to " << outputFile.string() << endl; int out = open( outputFile.string().c_str() , O_WRONLY | O_CREAT | O_TRUNC , 0666 ); assert( out ); @@ -43,13 +43,13 @@ namespace mongo { num++; } - cout << "\t\t " << num << " objects" << endl; + mongo::out() << "\t\t " << num << " objects" << endl; close( out ); } void go( DBClientConnection & conn , const char * db , const path outdir ) { - cout << "DATABASE: " << db << endl; + mongo::out() << "DATABASE: " << db << endl; create_directories( outdir ); @@ -76,14 +76,14 @@ namespace mongo { DBClientConnection conn; string errmsg; if ( ! conn.connect( host , errmsg ) ) { - cout << "couldn't connect : " << errmsg << endl; + mongo::out() << "couldn't connect : " << errmsg << endl; throw -11; } path root(outdir); if ( strlen( db ) == 1 && db[0] == '*' ) { - cout << "all dbs" << endl; + mongo::out() << "all dbs" << endl; BSONObjBuilder query; query.appendBool( "listDatabases" , 1 ); @@ -148,10 +148,10 @@ int main( int argc , char ** argv ) { if ( vm.count( "out" ) ) outdir = vm["out"].as<string>().c_str(); - cout << "mongo dump" << endl; - cout << "\t host \t" << host << endl; - cout << "\t db \t" << db << endl; - cout << "\t output dir \t" << outdir << endl; + mongo::out() << "mongo dump" << endl; + mongo::out() << "\t host \t" << host << endl; + mongo::out() << "\t db \t" << db << endl; + mongo::out() << "\t output dir \t" << outdir << endl; dump::go( host , db , outdir ); } diff --git a/tools/import.cpp b/tools/import.cpp index ce0548fe8c5..3e11c101b2f 100644 --- a/tools/import.cpp +++ b/tools/import.cpp @@ -50,7 +50,7 @@ namespace mongo { } - cout << root.string() << endl; + out() << root.string() << endl; string ns; { @@ -67,7 +67,7 @@ namespace mongo { ns += "." + l; } - cout << "\t going into namespace [" << ns << "]" << endl; + out() << "\t going into namespace [" << ns << "]" << endl; MemoryMappedFile mmf; assert( mmf.map( root.string().c_str() ) ); @@ -79,7 +79,7 @@ namespace mongo { while ( read < mmf.length() ) { if ( ! *data ) { - cout << "\t ** got unexpected end of file ** continuing..." << endl; + out() << "\t ** got unexpected end of file ** continuing..." << endl; break; } @@ -91,10 +91,10 @@ namespace mongo { data += o.objsize(); if ( ! ( ++num % 1000 ) ) - cout << "read " << read << "/" << mmf.length() << " bytes so far. " << num << " objects" << endl; + out() << "read " << read << "/" << mmf.length() << " bytes so far. " << num << " objects" << endl; } - cout << "\t " << num << " objects" << endl; + out() << "\t " << num << " objects" << endl; } @@ -103,7 +103,7 @@ namespace mongo { DBClientConnection conn; string errmsg; if ( ! conn.connect( dbHost , errmsg ) ) { - cout << "couldn't connect : " << errmsg << endl; + out() << "couldn't connect : " << errmsg << endl; throw -11; } @@ -150,9 +150,9 @@ int main( int argc , char ** argv ) { if ( vm.count( "dir" ) ) dir = vm["dir"].as<string>().c_str(); - cout << "mongo dump" << endl; - cout << "\t host \t" << host << endl; - cout << "\t dir \t" << dir << endl; + out() << "mongo dump" << endl; + out() << "\t host \t" << host << endl; + out() << "\t dir \t" << dir << endl; import::go( host , dir ); return 0; diff --git a/util/hashtab.h b/util/hashtab.h index 8da28b3018e..1f280e29aaa 100644 --- a/util/hashtab.h +++ b/util/hashtab.h @@ -72,11 +72,11 @@ namespace mongo { chain++; i = (i+1) % n; if ( i == start ) { - cout << "warning: hashtable is full " << name << endl; + out() << "warning: hashtable is full " << name << endl; return -1; } if ( chain == 200 ) - cout << "warning: hashtable long chain " << name << endl; + out() << "warning: hashtable long chain " << name << endl; } } @@ -84,7 +84,7 @@ namespace mongo { /* buf must be all zeroes on initialization. */ HashTable(void *buf, int buflen, const char *_name) : name(_name) { int m = sizeof(Node); - // cout << "hashtab init, buflen:" << buflen << " m:" << m << endl; + // out() << "hashtab init, buflen:" << buflen << " m:" << m << endl; n = buflen / m; if ( (n & 1) == 0 ) n--; @@ -93,7 +93,7 @@ namespace mongo { assert(nodes[0].hash == 0); assert( sizeof(Node) == 628 ); - //cout << "HashTable() " << _name << " sizeof(node):" << sizeof(Node) << " n:" << n << endl; + //out() << "HashTable() " << _name << " sizeof(node):" << sizeof(Node) << " n:" << n << endl; } Type* get(const Key& k) { diff --git a/util/log.h b/util/log.h index b053bea0bf9..fbbc58beeed 100644 --- a/util/log.h +++ b/util/log.h @@ -106,12 +106,12 @@ namespace mongo { inline Logstream& log() { return logstream.prolog(); } - + inline Logstream& out() { + return logstream; + } + inline ostream& stdcout() { return cout; } -#define cout logstream - - } // namespace mongo diff --git a/util/mmap.cpp b/util/mmap.cpp index 402690e4ce9..ff943504588 100644 --- a/util/mmap.cpp +++ b/util/mmap.cpp @@ -32,7 +32,7 @@ namespace mongo { int closingAllFiles = 0; void MemoryMappedFile::closeAllFiles() { if ( closingAllFiles ) { - cout << "warning closingAllFiles=" << closingAllFiles << endl; + out() << "warning closingAllFiles=" << closingAllFiles << endl; return; } ++closingAllFiles; @@ -92,13 +92,13 @@ namespace mongo { filenamew.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if ( fd == INVALID_HANDLE_VALUE ) { - cout << "CreateFile failed " << filename << endl; + out() << "CreateFile failed " << filename << endl; return 0; } #if defined(_WIN32) if ( mapped > 500000000 ) { - cout << "WARNING: too much mem mapped for win32" << endl; + out() << "WARNING: too much mem mapped for win32" << endl; // if( length > 50000000 ) // length = 50000000; } @@ -107,15 +107,15 @@ namespace mongo { maphandle = CreateFileMapping(fd, NULL, PAGE_READWRITE, 0, length, NULL); if ( maphandle == NULL ) { - cout << "CreateFileMapping failed " << filename << endl; + out() << "CreateFileMapping failed " << filename << endl; return 0; } view = MapViewOfFile(maphandle, FILE_MAP_ALL_ACCESS, 0, 0, 0); if ( view == 0 ) { - cout << "MapViewOfFile failed " << filename << " errno:"; - cout << GetLastError(); - cout << endl; + out() << "MapViewOfFile failed " << filename << " errno:"; + out() << GetLastError(); + out() << endl; } return view; @@ -165,7 +165,7 @@ namespace mongo { fd = open(filename, O_CREAT | O_RDWR | O_NOATIME, S_IRUSR | S_IWUSR); if ( !fd ) { - cout << "couldn't open " << filename << ' ' << errno << endl; + out() << "couldn't open " << filename << ' ' << errno << endl; return 0; } @@ -203,7 +203,7 @@ namespace mongo { view = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if ( view == MAP_FAILED ) { - cout << " mmap() failed for " << filename << " len:" << length << " errno:" << errno << endl; + out() << " mmap() failed for " << filename << " len:" << length << " errno:" << errno << endl; return 0; } return view; diff --git a/util/sock.cpp b/util/sock.cpp index aefb314127c..560b016bf24 100644 --- a/util/sock.cpp +++ b/util/sock.cpp @@ -32,29 +32,29 @@ namespace mongo { } void sendtest() { - cout << "sendtest\n"; + out() << "sendtest\n"; SockAddr me(27016); SockAddr dest("127.0.0.1", 27015); UDPConnection c; if ( c.init(me) ) { char buf[256]; - cout << "sendto: "; - cout << c.sendto(buf, sizeof(buf), dest) << " errno:" << h_errno << endl; + out() << "sendto: "; + out() << c.sendto(buf, sizeof(buf), dest) << " errno:" << h_errno << endl; } - cout << "end\n"; + out() << "end\n"; } void listentest() { - cout << "listentest\n"; + out() << "listentest\n"; SockAddr me(27015); SockAddr sender; UDPConnection c; if ( c.init(me) ) { char buf[256]; - cout << "recvfrom: "; - cout << c.recvfrom(buf, sizeof(buf), sender) << " errno:" << h_errno << endl; + out() << "recvfrom: "; + out() << c.recvfrom(buf, sizeof(buf), sender) << " errno:" << h_errno << endl; } - cout << "end listentest\n"; + out() << "end listentest\n"; } void xmain(); @@ -63,12 +63,12 @@ namespace mongo { #if defined(_WIN32) WSADATA d; if ( WSAStartup(MAKEWORD(2,2), &d) != 0 ) { - cout << "ERROR: wsastartup failed " << errno << endl; + out() << "ERROR: wsastartup failed " << errno << endl; problem() << "ERROR: wsastartup failed " << errno << endl; exit(1); } #endif - //cout << "ntohl:" << ntohl(256) << endl; + //out() << "ntohl:" << ntohl(256) << endl; //sendtest(); //listentest(); } diff --git a/util/sock.h b/util/sock.h index c78c17a53b9..9450070593d 100644 --- a/util/sock.h +++ b/util/sock.h @@ -34,7 +34,7 @@ namespace mongo { inline void disableNagle(int sock) { int x = 1; if ( setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *) &x, sizeof(x)) ) - cout << "ERROR: disableNagle failed" << endl; + out() << "ERROR: disableNagle failed" << endl; } inline void prebindOptions( int sock ) { } @@ -79,7 +79,7 @@ namespace mongo { DEV log() << "doing prebind option" << endl; int x = 1; if ( setsockopt( sock , SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)) < 0 ) - cout << "Failed to set socket opt, SO_REUSEADDR" << endl; + out() << "Failed to set socket opt, SO_REUSEADDR" << endl; } @@ -92,7 +92,7 @@ namespace mongo { tv.tv_usec = 1000; int rc = setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *) &tv, sizeof(tv)); if ( rc ) { - cout << "ERROR: setsockopt RCVTIMEO failed rc:" << rc << " errno:" << getLastError() << " secs:" << secs << " sock:" << sock << endl; + out() << "ERROR: setsockopt RCVTIMEO failed rc:" << rc << " errno:" << getLastError() << " secs:" << secs << " sock:" << sock << endl; } } @@ -172,8 +172,8 @@ namespace mongo { inline int UDPConnection::sendto(char *buf, int len, const SockAddr& EndPoint) { if ( 0 && rand() < (RAND_MAX>>4) ) { - cout << " NOTSENT "; - // cout << curTimeMillis() << " .TEST: NOT SENDING PACKET" << endl; + out() << " NOTSENT "; + // out() << curTimeMillis() << " .TEST: NOT SENDING PACKET" << endl; return 0; } return ::sendto(sock, buf, len, 0, (sockaddr *) &EndPoint.sa, EndPoint.addressSize); @@ -182,12 +182,12 @@ namespace mongo { inline bool UDPConnection::init(const SockAddr& myAddr) { sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if ( sock == INVALID_SOCKET ) { - cout << "invalid socket? " << errno << endl; + out() << "invalid socket? " << errno << endl; return false; } - //cout << sizeof(sockaddr_in) << ' ' << myAddr.addressSize << endl; + //out() << sizeof(sockaddr_in) << ' ' << myAddr.addressSize << endl; if ( ::bind(sock, (sockaddr *) &myAddr.sa, myAddr.addressSize) != 0 ) { - cout << "udp init failed" << endl; + out() << "udp init failed" << endl; closesocket(sock); sock = 0; return false; @@ -199,7 +199,7 @@ namespace mongo { SO_RCVBUF, (char*)&rcvbuf, &optLen) != -1) - cout << "SO_RCVBUF:" << rcvbuf << endl; + out() << "SO_RCVBUF:" << rcvbuf << endl; return true; } |