summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-02-03 22:34:51 -0500
committerAaron <aaron@10gen.com>2009-02-03 22:34:51 -0500
commitcf4e99b9ee306355e4687cc563ab2248273f7b75 (patch)
tree400486b06523fa57e7b9582592229cc2615e176a /db
parent48cfea2b1afd3fcc2ec5d0f423c9d952bae1f71c (diff)
downloadmongo-cf4e99b9ee306355e4687cc563ab2248273f7b75.tar.gz
Log generated id with inserted object, log id as update query in some cases
Diffstat (limited to 'db')
-rw-r--r--db/cloner.cpp2
-rw-r--r--db/instance.cpp2
-rw-r--r--db/pdfile.cpp9
-rw-r--r--db/pdfile.h2
-rw-r--r--db/query.cpp29
5 files changed, 32 insertions, 12 deletions
diff --git a/db/cloner.cpp b/db/cloner.cpp
index 4c109ca0b14..c7daf5c8037 100644
--- a/db/cloner.cpp
+++ b/db/cloner.cpp
@@ -111,7 +111,7 @@ namespace mongo {
js = fixindex(tmp);
}
- theDataFileMgr.insert(to_collection, (void*) js.objdata(), js.objsize());
+ theDataFileMgr.insert(to_collection, js);
if ( logForRepl )
logOp("i", to_collection, js);
}
diff --git a/db/instance.cpp b/db/instance.cpp
index 77ebb102478..f1f52bb65ff 100644
--- a/db/instance.cpp
+++ b/db/instance.cpp
@@ -438,7 +438,7 @@ namespace mongo {
uassert("insert: bad object from client", false);
}
- theDataFileMgr.insert(ns, (void*) js.objdata(), js.objsize());
+ theDataFileMgr.insert(ns, js);
logOp("i", ns, js);
}
}
diff --git a/db/pdfile.cpp b/db/pdfile.cpp
index 226e37375f3..feb72c1b691 100644
--- a/db/pdfile.cpp
+++ b/db/pdfile.cpp
@@ -708,7 +708,7 @@ namespace mongo {
}
}
- if ( toupdate->netLength() < len ) {
+ if ( toupdate->netLength() < len ) {
// doesn't fit. must reallocate.
if ( d && d->capped ) {
@@ -918,6 +918,13 @@ namespace mongo {
} idToInsert;
#pragma pack()
+ DiskLoc DataFileMgr::insert(const char *ns, BSONObj &o) {
+ DiskLoc loc = insert( ns, o.objdata(), o.objsize() );
+ if ( !loc.isNull() )
+ o = BSONObj( loc.rec() );
+ return loc;
+ }
+
DiskLoc DataFileMgr::insert(const char *ns, const void *obuf, int len, bool god, const BSONElement &writeId) {
bool addIndex = false;
const char *sys = strstr(ns, "system.");
diff --git a/db/pdfile.h b/db/pdfile.h
index 7dc870adcfb..f83523a5b85 100644
--- a/db/pdfile.h
+++ b/db/pdfile.h
@@ -87,6 +87,8 @@ namespace mongo {
const char *ns,
Record *toupdate, const DiskLoc& dl,
const char *buf, int len, stringstream& profiling);
+ // The object o may be updated if modified on insert.
+ DiskLoc insert(const char *ns, BSONObj &o);
DiskLoc insert(const char *ns, const void *buf, int len, bool god = false, const BSONElement &writeId = BSONElement());
void deleteRecord(const char *ns, Record *todelete, const DiskLoc& dl, bool cappedOK = false);
static auto_ptr<Cursor> findAll(const char *ns);
diff --git a/db/query.cpp b/db/query.cpp
index 717a67ecc22..014c29644a2 100644
--- a/db/query.cpp
+++ b/db/query.cpp
@@ -322,14 +322,7 @@ namespace mongo {
}
}
- /* todo:
- _ smart requery find record immediately
- returns:
- 2: we did applyMods() but didn't logOp()
- 5: we did applyMods() and did logOp() (so don't do it again)
- (clean these up later...)
- */
- int _updateObjects(const char *ns, BSONObj updateobj, BSONObj pattern, bool upsert, stringstream& ss, bool logop=false) {
+ int __updateObjects(const char *ns, BSONObj updateobj, BSONObj &pattern, bool upsert, stringstream& ss, bool logop=false) {
int profile = database->profile;
if ( strstr(ns, ".system.") ) {
@@ -358,6 +351,12 @@ namespace mongo {
if ( !matcher.matches(js) ) {
}
else {
+ BSONObjBuilder idPattern;
+ BSONElement id;
+ if ( js.getObjectID( id ) )
+ idPattern.append( id );
+ pattern = idPattern.doneAndDecouple();
+
/* 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.
@@ -425,10 +424,22 @@ namespace mongo {
}
return 0;
}
+
+ /* todo:
+ _ smart requery find record immediately
+ returns:
+ 2: we did applyMods() but didn't logOp()
+ 5: we did applyMods() and did logOp() (so don't do it again)
+ (clean these up later...)
+ */
+ int _updateObjects(const char *ns, BSONObj updateobj, BSONObj pattern, bool upsert, stringstream& ss, bool logop=false) {
+ return __updateObjects( ns, updateobj, pattern, upsert, ss, logop );
+ }
+
/* todo: we can optimize replication by just doing insert when an upsert triggers.
*/
void updateObjects(const char *ns, BSONObj updateobj, BSONObj pattern, bool upsert, stringstream& ss) {
- int rc = _updateObjects(ns, updateobj, pattern, upsert, ss, true);
+ int rc = __updateObjects(ns, updateobj, pattern, upsert, ss, true);
if ( rc != 5 && rc != 0 )
logOp("u", ns, updateobj, &pattern, &upsert);
}