From c0fbc1a93e51c573f2a7c23dff45ea930e772e9e Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 26 Mar 2009 16:11:23 -0400 Subject: [PATCH] Register update/delete only on client request --- db/instance.cpp | 6 ++++-- db/query.cpp | 8 ++------ db/query.h | 3 ++- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/db/instance.cpp b/db/instance.cpp index e047bd579a4..11755cddff9 100644 --- a/db/instance.cpp +++ b/db/instance.cpp @@ -314,7 +314,8 @@ namespace mongo { assert( toupdate.objsize() < m.data->dataLen() ); assert( query.objsize() + toupdate.objsize() < m.data->dataLen() ); - updateObjects(ns, toupdate, query, flags & 1, ss); + bool updatedExisting = updateObjects(ns, toupdate, query, flags & 1, ss); + recordUpdate( updatedExisting ); } void receivedDelete(Message& m) { @@ -327,7 +328,8 @@ namespace mongo { assert( d.moreJSObjs() ); BSONObj pattern = d.nextJsObj(); BSONObj deletedId = BSONObj(); - deleteObjects(ns, pattern, justOne, &deletedId); + int n = deleteObjects(ns, pattern, justOne, &deletedId); + recordDelete( n ); if ( justOne ) { if ( deletedId.isEmpty() ) { problem() << "deleted object without id, not logging" << endl; diff --git a/db/query.cpp b/db/query.cpp index 4cbb7b16094..21c33ca9838 100644 --- a/db/query.cpp +++ b/db/query.cpp @@ -161,7 +161,6 @@ namespace mongo { } } while ( c->ok() ); - recordDelete( nDeleted ); return nDeleted; } @@ -586,8 +585,6 @@ namespace mongo { } } - recordUpdate( true ); - /* note: we only update one row and quit. if you do multiple later, be careful or multikeys in arrays could break things badly. best to only allow updating a single row with a multikey lookup. @@ -637,8 +634,6 @@ namespace mongo { if ( profile ) ss << " nscanned:" << u->nscanned(); - recordUpdate( false ); - if ( upsert ) { if ( updateobj.firstElement().fieldName()[0] == '$' ) { /* upsert of an $inc. build a default */ @@ -677,10 +672,11 @@ namespace mongo { return __updateObjects( ns, updateobj, pattern, upsert, ss, logop ); } - void updateObjects(const char *ns, BSONObj updateobj, BSONObj pattern, bool upsert, stringstream& ss) { + bool updateObjects(const char *ns, BSONObj updateobj, BSONObj pattern, bool upsert, stringstream& ss) { int rc = __updateObjects(ns, updateobj, pattern, upsert, ss, true); if ( rc != 5 && rc != 0 && rc != 4 && rc != 3 ) logOp("u", ns, updateobj, &pattern, &upsert); + return ( rc == 1 || rc == 2 || rc == 5 ); } int queryTraceLevel = 0; diff --git a/db/query.h b/db/query.h index 730763ca76f..af38fca4d5e 100644 --- a/db/query.h +++ b/db/query.h @@ -72,7 +72,8 @@ namespace mongo { // for an existing query (ie a ClientCursor), send back additional information. QueryResult* getMore(const char *ns, int ntoreturn, long long cursorid); - void updateObjects(const char *ns, BSONObj updateobj, BSONObj pattern, bool upsert, stringstream& ss); + // returns true if an existing object was updated, false if no existing object was found. + bool updateObjects(const char *ns, BSONObj updateobj, BSONObj pattern, bool upsert, stringstream& ss); // If justOne is true, deletedId is set to the id of the deleted object. int deleteObjects(const char *ns, BSONObj pattern, bool justOne, BSONObj *deletedId = 0, bool god=false);