diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-09-30 17:11:56 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-09-30 17:11:56 -0400 |
commit | 8658e97ed342f3a8c0e1be3b8bdfce847abd99a5 (patch) | |
tree | d87b19dd645ef62d3a432ad405052199f69cf223 /db/mr.cpp | |
parent | 993b94fceee166c717f9e9707d4908f62869e072 (diff) | |
download | mongo-8658e97ed342f3a8c0e1be3b8bdfce847abd99a5.tar.gz |
unlock while doing map/reduce
Diffstat (limited to 'db/mr.cpp')
-rw-r--r-- | db/mr.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/db/mr.cpp b/db/mr.cpp index 4ab3ccf9bb0..b0125a0f169 100644 --- a/db/mr.cpp +++ b/db/mr.cpp @@ -233,11 +233,14 @@ namespace mongo { auto_ptr<Scope> s = globalScriptEngine->getPooledScope( ns ); s->localConnect( database->name.c_str() ); - + string resultColl = tempCollectionName( cmdObj.firstElement().valuestr() ); + string finalOutput = resultColl; if ( cmdObj["out"].type() == String ) - resultColl = database->name + "." + cmdObj["out"].valuestr(); + finalOutput = database->name + "." + cmdObj["out"].valuestr(); + string resultCollShort = resultColl.substr( database->name.size() + 1 ); + string finalOutputShort = finalOutput.substr( database->name.size() + 1 ); log(1) << "\t resultColl: " << resultColl << " short: " << resultCollShort << endl; db.dropCollection( resultColl ); db.ensureIndex( resultColl , BSON( "key" << 1 ) ); @@ -245,6 +248,8 @@ namespace mongo { int num = 0; try { + dbtemprelease temprlease; + s->execSetup( (string)"tempcoll = db[\"" + resultCollShort + "\"];" , "tempcoll1" ); if ( s->type( "emit" ) == 6 ){ s->injectNative( "emit" , fast_emit ); @@ -309,8 +314,16 @@ namespace mongo { db.dropCollection( resultColl ); throw; } - - result.append( "result" , resultCollShort ); + + + if ( finalOutput != resultColl ){ + // need to do this with the full dblock, that's why its after the try/catch + db.dropCollection( finalOutput ); + BSONObj info; + uassert( "rename failed" , db.runCommand( "admin" , BSON( "renameCollection" << resultColl << "to" << finalOutput ) , info ) ); + } + + result.append( "result" , finalOutputShort ); result.append( "numObjects" , num ); result.append( "timeMillis" , t.millis() ); |