summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-12-29 20:43:25 -0800
committerAaron <aaron@10gen.com>2009-12-29 20:43:25 -0800
commit9240b5026630f3cb28a30d47b91bcee20802ed14 (patch)
treec4a71d62242fc9a6bb34778ff14e463b6312d3cb
parent54fd59f6e1f6837df0a4244c78d577aa686950db (diff)
parent5f36804299a717ef4a96e7c1ac38e62a796d0e3c (diff)
downloadmongo-9240b5026630f3cb28a30d47b91bcee20802ed14.tar.gz
Merge branch 'master' of github.com:mongodb/mongo
-rw-r--r--db/commands.h2
-rw-r--r--db/curop.h17
-rw-r--r--db/db.cpp7
-rw-r--r--db/dbcommands.cpp2
-rw-r--r--db/dbhelpers.cpp4
-rw-r--r--db/instance.cpp64
-rw-r--r--db/pdfile.cpp6
-rw-r--r--db/pdfile.h3
-rw-r--r--db/query.cpp14
-rw-r--r--db/query.h6
-rw-r--r--db/repl.cpp16
-rw-r--r--db/update.cpp7
-rw-r--r--util/builder.h6
13 files changed, 87 insertions, 67 deletions
diff --git a/db/commands.h b/db/commands.h
index 1c5a4e82617..523a740056f 100644
--- a/db/commands.h
+++ b/db/commands.h
@@ -97,6 +97,6 @@ namespace mongo {
bool runCommandAgainstRegistered(const char *ns, BSONObj& jsobj, BSONObjBuilder& anObjBuilder);
- bool _runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &b, BSONObjBuilder& anObjBuilder, bool fromRepl, int queryOptions);
+ bool _runCommands(const char *ns, BSONObj& jsobj, BufBuilder &b, BSONObjBuilder& anObjBuilder, bool fromRepl, int queryOptions);
} // namespace mongo
diff --git a/db/curop.h b/db/curop.h
index c58719d1c3a..0bf5b4664f7 100644
--- a/db/curop.h
+++ b/db/curop.h
@@ -8,9 +8,18 @@
namespace mongo {
+ struct OpDebug {
+
+ StringBuilder str;
+
+ void reset(){
+ str.reset();
+ }
+ };
+
/* Current operation (for the current Client).
an embedded member of Client class, and typically used from within the mutex there. */
- class CurOp {
+ class CurOp : boost::noncopyable {
static WrappingInt _nextOpNum;
static BSONObj _tooBig; // { $msg : "query not recording (too large)" }
@@ -32,19 +41,19 @@ namespace mongo {
return o;
}
- stringstream _debug;
+ OpDebug _debug;
public:
void reset( const sockaddr_in &_client) {
_active = true;
_opNum = _nextOpNum.atomicIncrement();
_timer.reset();
_ns[0] = '?'; // just in case not set later
- _debug.rdbuf()->pubseekpos(0);
+ _debug.reset();
resetQuery();
client = _client;
}
- stringstream& debugstream(){
+ OpDebug& debug(){
return _debug;
}
diff --git a/db/db.cpp b/db/db.cpp
index db198cec3ff..421b86c1b88 100644
--- a/db/db.cpp
+++ b/db/db.cpp
@@ -79,8 +79,7 @@ namespace mongo {
QueryResult* emptyMoreResult(long long);
void testTheDb() {
- stringstream ss;
-
+ OpDebug debug;
setClient("sys.unittest.pdfile");
/* this is not validly formatted, if you query this namespace bad things will happen */
@@ -91,8 +90,8 @@ namespace mongo {
deleteObjects("sys.unittest.delete", j1, false);
theDataFileMgr.insert("sys.unittest.delete", &js1, sizeof(js1));
deleteObjects("sys.unittest.delete", j1, false);
- updateObjects("sys.unittest.delete", j1, j1, true,false,ss,true);
- updateObjects("sys.unittest.delete", j1, j1, false,false,ss,true);
+ updateObjects("sys.unittest.delete", j1, j1, true,false,true,debug);
+ updateObjects("sys.unittest.delete", j1, j1, false,false,true,debug);
auto_ptr<Cursor> c = theDataFileMgr.findAll("sys.unittest.pdfile");
while ( c->ok() ) {
diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp
index 35eef287596..0f9739ec560 100644
--- a/db/dbcommands.cpp
+++ b/db/dbcommands.cpp
@@ -1341,7 +1341,7 @@ namespace mongo {
returns true if ran a cmd
*/
- bool _runCommands(const char *ns, BSONObj& _cmdobj, stringstream& ss, BufBuilder &b, BSONObjBuilder& anObjBuilder, bool fromRepl, int queryOptions) {
+ bool _runCommands(const char *ns, BSONObj& _cmdobj, BufBuilder &b, BSONObjBuilder& anObjBuilder, bool fromRepl, int queryOptions) {
if( logLevel >= 1 )
log() << "run command " << ns << ' ' << _cmdobj << endl;
diff --git a/db/dbhelpers.cpp b/db/dbhelpers.cpp
index 1be6783ebeb..3091152094a 100644
--- a/db/dbhelpers.cpp
+++ b/db/dbhelpers.cpp
@@ -181,9 +181,9 @@ namespace mongo {
}
void Helpers::putSingleton(const char *ns, BSONObj obj) {
+ OpDebug debug;
DBContext context(ns);
- stringstream ss;
- updateObjects(ns, obj, /*pattern=*/BSONObj(), /*upsert=*/true, /*multi=*/false, ss, /*logop=*/true );
+ updateObjects(ns, obj, /*pattern=*/BSONObj(), /*upsert=*/true, /*multi=*/false , true , debug );
}
void Helpers::emptyCollection(const char *ns) {
diff --git a/db/instance.cpp b/db/instance.cpp
index 69690d47fb4..5a81f558b88 100644
--- a/db/instance.cpp
+++ b/db/instance.cpp
@@ -38,13 +38,11 @@
namespace mongo {
- auto_ptr< QueryResult > runQuery(Message& m, QueryMessage& q, stringstream& ss );
-
void receivedKillCursors(Message& m);
- void receivedUpdate(Message& m, stringstream& ss);
- void receivedDelete(Message& m, stringstream& ss);
- void receivedInsert(Message& m, stringstream& ss);
- bool receivedGetMore(DbResponse& dbresponse, Message& m, stringstream& ss);
+ void receivedUpdate(Message& m, CurOp& op);
+ void receivedDelete(Message& m, CurOp& op);
+ void receivedInsert(Message& m, CurOp& op);
+ bool receivedGetMore(DbResponse& dbresponse, Message& m, CurOp& curop );
CmdLine cmdLine;
@@ -136,8 +134,8 @@ namespace mongo {
}
static bool receivedQuery(DbResponse& dbresponse, Message& m,
- stringstream& ss, bool logit,
- mongolock& lock
+ CurOp& op, bool logit,
+ mongolock& lock
) {
bool ok = true;
MSGID responseTo = m.data->id;
@@ -165,11 +163,11 @@ namespace mongo {
Client& client = cc();
client.top.setRead();
client.curop()->setNS(q.ns);
- msgdata = runQuery(m, q, ss ).release();
+ msgdata = runQuery(m, q, op ).release();
}
catch ( AssertionException& e ) {
ok = false;
- ss << " exception ";
+ op.debug().str << " exception ";
LOGSOME problem() << " Caught Assertion in runQuery ns:" << q.ns << ' ' << e.toString() << '\n';
log() << " ntoskip:" << q.ntoskip << " ntoreturn:" << q.ntoreturn << '\n';
if ( q.query.valid() )
@@ -204,7 +202,7 @@ namespace mongo {
Database *database = cc().database();
if ( database ) {
if ( database->profile )
- ss << " bytes:" << resp->data->dataLen();
+ op.debug().str << " bytes:" << resp->data->dataLen();
}
else {
if ( strstr(q.ns, "$cmd") == 0 ) // (this condition is normal for $cmd dropDatabase)
@@ -258,10 +256,11 @@ namespace mongo {
c.clearns();
CurOp& currentOp = *c.curop();
- currentOp.reset( client);
+ currentOp.reset(client);
currentOp.setOp(op);
-
- stringstream ss;
+
+ OpDebug& debug = currentOp.debug();
+ StringBuilder& ss = debug.str;
int logThreshold = cmdLine.slowMS;
bool log = logLevel >= 1;
@@ -285,7 +284,7 @@ namespace mongo {
if ( op == dbQuery ) {
// receivedQuery() does its own authorization processing.
- if ( ! receivedQuery(dbresponse, m, ss, true, lk) )
+ if ( ! receivedQuery(dbresponse, m, currentOp, true, lk) )
log = true;
}
else if ( op == dbGetMore ) {
@@ -293,7 +292,7 @@ namespace mongo {
OPREAD;
DEV log = true;
ss << "getmore ";
- if ( ! receivedGetMore(dbresponse, m, ss) )
+ if ( ! receivedGetMore(dbresponse, m, currentOp) )
log = true;
}
else if ( op == dbMsg ) {
@@ -327,11 +326,11 @@ namespace mongo {
OPWRITE;
try {
ss << "insert ";
- receivedInsert(m, ss);
+ receivedInsert(m, currentOp);
}
catch ( AssertionException& e ) {
LOGSOME problem() << " Caught Assertion insert, continuing\n";
- ss << " exception " + e.toString();
+ ss << " exception " << e.toString();
log = true;
}
}
@@ -339,11 +338,11 @@ namespace mongo {
OPWRITE;
try {
ss << "update ";
- receivedUpdate(m, ss);
+ receivedUpdate(m, currentOp);
}
catch ( AssertionException& e ) {
LOGSOME problem() << " Caught Assertion update, continuing" << endl;
- ss << " exception " + e.toString();
+ ss << " exception " << e.toString();
log = true;
}
}
@@ -351,11 +350,11 @@ namespace mongo {
OPWRITE;
try {
ss << "remove ";
- receivedDelete(m, ss);
+ receivedDelete(m, currentOp);
}
catch ( AssertionException& e ) {
LOGSOME problem() << " Caught Assertion receivedDelete, continuing" << endl;
- ss << " exception " + e.toString();
+ ss << " exception " << e.toString();
log = true;
}
}
@@ -443,7 +442,7 @@ namespace mongo {
cc().clearns();
}
- void receivedUpdate(Message& m, stringstream& ss) {
+ void receivedUpdate(Message& m, CurOp& op) {
DbMessage d(m);
const char *ns = d.getns();
assert(*ns);
@@ -451,7 +450,7 @@ namespace mongo {
setClient(ns);
Client& client = cc();
client.top.setWrite();
- ss << ns << ' ';
+ op.debug().str << ns << ' ';
int flags = d.pullInt();
BSONObj query = d.nextJsObj();
@@ -466,16 +465,16 @@ namespace mongo {
{
string s = query.toString();
/* todo: we shouldn't do all this ss stuff when we don't need it, it will slow us down. */
- ss << " query: " << s;
+ op.debug().str << " query: " << s;
CurOp& currentOp = *client.curop();
currentOp.setQuery(query);
}
- UpdateResult res = updateObjects(ns, toupdate, query, upsert, multi, ss, true);
+ UpdateResult res = updateObjects(ns, toupdate, query, upsert, multi, true, op.debug() );
/* TODO FIX: recordUpdate should take a long int for parm #2 */
recordUpdate( res.existing , (int) res.num ); // for getlasterror
}
- void receivedDelete(Message& m, stringstream &ss) {
+ void receivedDelete(Message& m, CurOp& op) {
DbMessage d(m);
const char *ns = d.getns();
assert(*ns);
@@ -489,7 +488,7 @@ namespace mongo {
BSONObj pattern = d.nextJsObj();
{
string s = pattern.toString();
- ss << " query: " << s;
+ op.debug().str << " query: " << s;
CurOp& currentOp = *client.curop();
currentOp.setQuery(pattern);
}
@@ -499,10 +498,11 @@ namespace mongo {
QueryResult* emptyMoreResult(long long);
- bool receivedGetMore(DbResponse& dbresponse, /*AbstractMessagingPort& dbMsgPort, */Message& m, stringstream& ss) {
+ bool receivedGetMore(DbResponse& dbresponse, Message& m, CurOp& curop ) {
bool ok = true;
DbMessage d(m);
const char *ns = d.getns();
+ StringBuilder& ss = curop.debug().str;
ss << ns;
setClient(ns);
cc().top.setRead();
@@ -514,7 +514,7 @@ namespace mongo {
try {
AuthenticationInfo *ai = currentClient.get()->ai;
uassert( 10057 , "unauthorized", ai->isAuthorized(cc().database()->name.c_str()));
- msgdata = getMore(ns, ntoreturn, cursorid, ss);
+ msgdata = getMore(ns, ntoreturn, cursorid, curop);
}
catch ( AssertionException& e ) {
ss << " exception " + e.toString();
@@ -531,14 +531,14 @@ namespace mongo {
return ok;
}
- void receivedInsert(Message& m, stringstream& ss) {
+ void receivedInsert(Message& m, CurOp& op) {
DbMessage d(m);
const char *ns = d.getns();
assert(*ns);
uassert( 10058 , "not master", isMasterNs( ns ) );
setClient(ns);
cc().top.setWrite();
- ss << ns;
+ op.debug().str << ns;
while ( d.moreJSObjs() ) {
BSONObj js = d.nextJsObj();
diff --git a/db/pdfile.cpp b/db/pdfile.cpp
index bba8bb82e68..cd46741c348 100644
--- a/db/pdfile.cpp
+++ b/db/pdfile.cpp
@@ -39,6 +39,7 @@ _ disallow system* manipulations from the database.
#include "namespace.h"
#include "queryutil.h"
#include "extsort.h"
+#include "curop.h"
namespace mongo {
@@ -949,8 +950,9 @@ namespace mongo {
*/
const DiskLoc DataFileMgr::update(const char *ns,
Record *toupdate, const DiskLoc& dl,
- const char *_buf, int _len, stringstream& ss)
+ const char *_buf, int _len, OpDebug& debug)
{
+ StringBuilder& ss = debug.str;
dassert( toupdate == dl.rec() );
NamespaceDetails *d = nsdetails(ns);
@@ -1021,7 +1023,7 @@ namespace mongo {
problem() << " caught assertion update index " << idx.indexNamespace() << endl;
}
if ( cc().database()->profile )
- ss << '\n' << changes[x].added.size() << " key updates ";
+ ss << "\n" << changes[x].added.size() << " key updates ";
}
}
diff --git a/db/pdfile.h b/db/pdfile.h
index 5f108f11204..d13e0433a3c 100644
--- a/db/pdfile.h
+++ b/db/pdfile.h
@@ -38,6 +38,7 @@ namespace mongo {
class Extent;
class Record;
class Cursor;
+ class OpDebug;
void dropDatabase(const char *ns);
bool repairDatabase(const char *ns, string &errmsg, bool preserveClonedFilesOnFailure = false, bool backupOriginalFiles = false);
@@ -101,7 +102,7 @@ namespace mongo {
const DiskLoc update(
const char *ns,
Record *toupdate, const DiskLoc& dl,
- const char *buf, int len, stringstream& profiling);
+ const char *buf, int len, OpDebug& debug);
// The object o may be updated if modified on insert.
void insertAndLog( const char *ns, const BSONObj &o, bool god = false );
DiskLoc insert(const char *ns, BSONObj &o, bool god = false);
diff --git a/db/query.cpp b/db/query.cpp
index e8a93d33a2c..c6ad75c6574 100644
--- a/db/query.cpp
+++ b/db/query.cpp
@@ -206,15 +206,15 @@ namespace mongo {
int initialExtentSize(int len);
- bool runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &b, BSONObjBuilder& anObjBuilder, bool fromRepl, int queryOptions) {
+ bool runCommands(const char *ns, BSONObj& jsobj, CurOp& curop, BufBuilder &b, BSONObjBuilder& anObjBuilder, bool fromRepl, int queryOptions) {
try {
- return _runCommands(ns, jsobj, ss, b, anObjBuilder, fromRepl, queryOptions);
+ return _runCommands(ns, jsobj, b, anObjBuilder, fromRepl, queryOptions);
}
catch ( AssertionException& e ) {
if ( !e.msg.empty() )
anObjBuilder.append("assertion", e.msg);
}
- ss << " assertion ";
+ curop.debug().str << " assertion ";
anObjBuilder.append("errmsg", "db assertion failure");
anObjBuilder.append("ok", 0.0);
BSONObj x = anObjBuilder.done();
@@ -276,7 +276,8 @@ namespace mongo {
return qr;
}
- QueryResult* getMore(const char *ns, int ntoreturn, long long cursorid , stringstream& ss) {
+ QueryResult* getMore(const char *ns, int ntoreturn, long long cursorid , CurOp& curop ) {
+ StringBuilder& ss = curop.debug().str;
ClientCursor *cc = ClientCursor::find(cursorid);
int bufSize = 512;
@@ -667,7 +668,8 @@ namespace mongo {
ClientCursor * findingStartCursor_;
};
- auto_ptr< QueryResult > runQuery(Message& m, QueryMessage& q, stringstream& ss ) {
+ auto_ptr< QueryResult > runQuery(Message& m, QueryMessage& q, CurOp& curop ) {
+ StringBuilder& ss = curop.debug().str;
const char *ns = q.ns;
int ntoskip = q.ntoskip;
int _ntoreturn = q.ntoreturn;
@@ -704,7 +706,7 @@ namespace mongo {
int n = 0;
/* we assume you are using findOne() for running a cmd... */
- if ( ntoreturn == 1 && runCommands(ns, jsobj, ss, bb, cmdResBuf, false, queryOptions) ) {
+ if ( ntoreturn == 1 && runCommands(ns, jsobj, curop, bb, cmdResBuf, false, queryOptions) ) {
n = 1;
qr.reset( (QueryResult *) bb.buf() );
bb.decouple();
diff --git a/db/query.h b/db/query.h
index 5e36d91d736..d69b6d974a8 100644
--- a/db/query.h
+++ b/db/query.h
@@ -72,7 +72,7 @@
namespace mongo {
// for an existing query (ie a ClientCursor), send back additional information.
- QueryResult* getMore(const char *ns, int ntoreturn, long long cursorid , stringstream& ss);
+ QueryResult* getMore(const char *ns, int ntoreturn, long long cursorid , CurOp& op);
struct UpdateResult {
bool existing;
@@ -101,14 +101,14 @@ namespace mongo {
/* returns true if an existing object was updated, false if no existing object was found.
multi - update multiple objects - mostly useful with things like $set
*/
- UpdateResult updateObjects(const char *ns, BSONObj updateobj, BSONObj pattern, bool upsert, bool multi , stringstream& ss, bool logop );
+ UpdateResult updateObjects(const char *ns, BSONObj updateobj, BSONObj pattern, bool upsert, bool multi , bool logop , OpDebug& debug );
// If justOne is true, deletedId is set to the id of the deleted object.
int deleteObjects(const char *ns, BSONObj pattern, bool justOne, bool logop = false, bool god=false);
long long runCount(const char *ns, const BSONObj& cmd, string& err);
- //auto_ptr< QueryResult > runQuery(Message& m, stringstream& ss );
+ auto_ptr< QueryResult > runQuery(Message& m, QueryMessage& q, CurOp& curop );
} // namespace mongo
diff --git a/db/repl.cpp b/db/repl.cpp
index 73a4e763d8b..220af8e14f8 100644
--- a/db/repl.cpp
+++ b/db/repl.cpp
@@ -541,9 +541,9 @@ namespace mongo {
BSONObj o = jsobj();
log( 1 ) << "Saving repl source: " << o << endl;
- stringstream ss;
+ OpDebug debug;
setClient("local.sources");
- UpdateResult res = updateObjects("local.sources", o, pattern, true/*upsert for pair feature*/, false,ss,false);
+ UpdateResult res = updateObjects("local.sources", o, pattern, true/*upsert for pair feature*/, false,false,debug);
assert( ! res.mod );
assert( res.num == 1 );
cc().clearns();
@@ -759,8 +759,8 @@ namespace mongo {
}
void ReplSource::applyOperation(const BSONObj& op) {
- log( 6 ) << "applying op: " << op << endl;
- stringstream ss;
+ log( 6 ) << "applying op: " << op << endl;
+ OpDebug debug;
BSONObj o = op.getObjectField("o");
const char *ns = op.getStringField("ns");
// operation type -- see logOp() comments for types
@@ -779,7 +779,7 @@ namespace mongo {
if( !o.getObjectID(_id) ) {
/* No _id. This will be very slow. */
Timer t;
- updateObjects(ns, o, o, true, false, ss, false );
+ updateObjects(ns, o, o, true, false, false , debug );
if( t.millis() >= 2 ) {
RARELY OCCASIONALLY log() << "warning, repl doing slow updates (no _id field) for " << ns << endl;
}
@@ -791,13 +791,13 @@ namespace mongo {
/* erh 10/16/2009 - this is probably not relevant any more since its auto-created, but not worth removing */
RARELY ensureHaveIdIndex(ns); // otherwise updates will be slow
- updateObjects(ns, o, b.done(), true, false, ss, false );
+ updateObjects(ns, o, b.done(), true, false, false , debug );
}
}
}
else if ( *opType == 'u' ) {
RARELY ensureHaveIdIndex(ns); // otherwise updates will be super slow
- updateObjects(ns, o, op.getObjectField("o2"), op.getBoolField("b"), false, ss, false );
+ updateObjects(ns, o, op.getObjectField("o2"), op.getBoolField("b"), false, false , debug );
}
else if ( *opType == 'd' ) {
if ( opType[1] == 0 )
@@ -812,7 +812,7 @@ namespace mongo {
BufBuilder bb;
BSONObjBuilder ob;
assert( *opType == 'c' );
- _runCommands(ns, o, ss, bb, ob, true, 0);
+ _runCommands(ns, o, bb, ob, true, 0);
}
}
catch ( UserException& e ) {
diff --git a/db/update.cpp b/db/update.cpp
index a4d39bbd7c9..6cdbc45cbf0 100644
--- a/db/update.cpp
+++ b/db/update.cpp
@@ -563,8 +563,9 @@ namespace mongo {
};
- UpdateResult updateObjects(const char *ns, BSONObj updateobjOrig, BSONObj patternOrig, bool upsert, bool multi, stringstream& ss, bool logop ) {
+ UpdateResult updateObjects(const char *ns, BSONObj updateobjOrig, BSONObj patternOrig, bool upsert, bool multi, bool logop , OpDebug& debug ) {
int profile = cc().database()->profile;
+ StringBuilder& ss = debug.str;
uassert( 10155 , "cannot update reserved $ collection", strchr(ns, '$') == 0 );
if ( strstr(ns, ".system.") ) {
@@ -653,7 +654,7 @@ namespace mongo {
}
else {
BSONObj newObj = mods.createNewFromMods( loc.obj() );
- DiskLoc newLoc = theDataFileMgr.update(ns, r, loc , newObj.objdata(), newObj.objsize(), ss);
+ DiskLoc newLoc = theDataFileMgr.update(ns, r, loc , newObj.objdata(), newObj.objsize(), debug);
if ( newLoc != loc || isIndexed ){
// object moved, need to make sure we don' get again
seenObjects.insert( newLoc );
@@ -689,7 +690,7 @@ namespace mongo {
BSONElementManipulator::lookForTimestamps( updateobj );
checkNoMods( updateobj );
- theDataFileMgr.update(ns, r, loc , updateobj.objdata(), updateobj.objsize(), ss);
+ theDataFileMgr.update(ns, r, loc , updateobj.objdata(), updateobj.objsize(), debug);
if ( logop )
logOp("u", ns, updateobj, &pattern );
return UpdateResult( 1 , 0 , 1 );
diff --git a/util/builder.h b/util/builder.h
index a658aaee4da..72803c46931 100644
--- a/util/builder.h
+++ b/util/builder.h
@@ -160,9 +160,15 @@ namespace mongo {
StringBuilder& operator<<( long x ){
SBNUM( x , 22 , "%ld" );
}
+ StringBuilder& operator<<( unsigned long x ){
+ SBNUM( x , 22 , "%lu" );
+ }
StringBuilder& operator<<( long long x ){
SBNUM( x , 22 , "%lld" );
}
+ StringBuilder& operator<<( unsigned long long x ){
+ SBNUM( x , 22 , "%llu" );
+ }
StringBuilder& operator<<( short x ){
SBNUM( x , 8 , "%hd" );
}