diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2014-07-24 14:44:23 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2014-07-28 17:14:17 -0400 |
commit | 78d2f38aa445ef1658300e66e1db14b9f1eceba8 (patch) | |
tree | d8503e6badb65230017c5c6a4042983283b11933 /src/mongo/db/dbeval.cpp | |
parent | 5e515de16fe1eac1f7079a2a95aa9e4f716ee3ec (diff) | |
download | mongo-78d2f38aa445ef1658300e66e1db14b9f1eceba8.tar.gz |
SERVER-13961 Pass through OperationContext in the JS framework
The JS framework uses DBDirectClient, which requires OperationContext in
order to not conflict with locks, which have already been acquired.
This change also makes dbEval not use pooled scopes and create a new scope
instead.
Diffstat (limited to 'src/mongo/db/dbeval.cpp')
-rw-r--r-- | src/mongo/db/dbeval.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/mongo/db/dbeval.cpp b/src/mongo/db/dbeval.cpp index 41069802f1d..355f725026e 100644 --- a/src/mongo/db/dbeval.cpp +++ b/src/mongo/db/dbeval.cpp @@ -28,7 +28,7 @@ * it in the license file. */ -#include "mongo/pch.h" +#include "mongo/platform/basic.h" #include <time.h> @@ -46,7 +46,12 @@ namespace mongo { const int edebug=0; - bool dbEval(const string& dbName, BSONObj& cmd, BSONObjBuilder& result, string& errmsg) { + static bool dbEval(OperationContext* txn, + const string& dbName, + const BSONObj& cmd, + BSONObjBuilder& result, + string& errmsg) { + BSONElement e = cmd.firstElement(); uassert( 10046 , "eval needs Code" , e.type() == Code || e.type() == CodeWScope || e.type() == String ); @@ -69,18 +74,18 @@ namespace mongo { return false; } - const string userToken = ClientBasic::getCurrent()->getAuthorizationSession() - ->getAuthenticatedUserNamesToken(); - auto_ptr<Scope> s = globalScriptEngine->getPooledScope( dbName, "dbeval" + userToken ); + scoped_ptr<Scope> s(globalScriptEngine->newScope()); + ScriptingFunction f = s->createFunction(code); if ( f == 0 ) { errmsg = (string)"compile failed: " + s->getError(); return false; } + s->localConnectForDbEval(txn, dbName.c_str()); + if ( e.type() == CodeWScope ) s->init( e.codeWScopeScopeDataUnsafe() ); - s->localConnect( dbName.c_str() ); BSONObj args; { @@ -139,14 +144,14 @@ namespace mongo { CmdEval() : Command("eval", false, "$eval") { } bool run(OperationContext* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { if ( cmdObj["nolock"].trueValue() ) { - return dbEval(dbname, cmdObj, result, errmsg); + return dbEval(txn, dbname, cmdObj, result, errmsg); } Lock::GlobalWrite lk(txn->lockState()); // No WriteUnitOfWork necessary, as dbEval will create its own, see "nolock" case above Client::Context ctx(txn, dbname ); - return dbEval(dbname, cmdObj, result, errmsg); + return dbEval(txn, dbname, cmdObj, result, errmsg); } } cmdeval; |