diff options
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r-- | src/mongo/db/commands/apply_ops.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/commands/cleanup_orphaned_cmd.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/commands/collection_to_capped.cpp | 18 | ||||
-rw-r--r-- | src/mongo/db/commands/compact.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/commands/create_indexes.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/commands/drop_indexes.cpp | 14 | ||||
-rw-r--r-- | src/mongo/db/commands/find_and_modify.cpp | 21 | ||||
-rw-r--r-- | src/mongo/db/commands/mr.cpp | 14 | ||||
-rw-r--r-- | src/mongo/db/commands/rename_collection.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/commands/test_commands.cpp | 19 | ||||
-rw-r--r-- | src/mongo/db/commands/touch.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/commands/validate.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/commands/write_commands/batch_executor.cpp | 83 | ||||
-rw-r--r-- | src/mongo/db/commands/write_commands/batch_executor.h | 6 | ||||
-rw-r--r-- | src/mongo/db/commands/write_commands/write_commands.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/commands/write_commands/write_commands.h | 4 |
16 files changed, 125 insertions, 115 deletions
diff --git a/src/mongo/db/commands/apply_ops.cpp b/src/mongo/db/commands/apply_ops.cpp index a189af5db6f..b86d8716d08 100644 --- a/src/mongo/db/commands/apply_ops.cpp +++ b/src/mongo/db/commands/apply_ops.cpp @@ -59,7 +59,7 @@ namespace mongo { // applyOps can do pretty much anything, so require all privileges. RoleGraph::generateUniversalPrivileges(out); } - virtual bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool newRun(TransactionExperiment* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { if ( cmdObj.firstElement().type() != Array ) { errmsg = "ops has to be an array"; @@ -84,7 +84,6 @@ namespace mongo { // SERVER-4328 todo : is global ok or does this take a long time? i believe multiple // ns used so locking individually requires more analysis Lock::GlobalWrite globalWriteLock; - DurTransaction txn; // Preconditions check reads the database state, so needs to be done locked if ( cmdObj["preCondition"].type() == Array ) { @@ -132,7 +131,7 @@ namespace mongo { invariant(Lock::nested()); Client::Context ctx(ns); - bool failed = applyOperation_inlock(&txn, ctx.db(), temp, false, alwaysUpsert); + bool failed = applyOperation_inlock(txn, ctx.db(), temp, false, alwaysUpsert); ab.append(!failed); if ( failed ) errors++; @@ -163,7 +162,7 @@ namespace mongo { } } - logOp(&txn, "c", tempNS.c_str(), cmdBuilder.done()); + logOp(txn, "c", tempNS.c_str(), cmdBuilder.done()); } return errors == 0; diff --git a/src/mongo/db/commands/cleanup_orphaned_cmd.cpp b/src/mongo/db/commands/cleanup_orphaned_cmd.cpp index 5a851307535..fcc81a00c59 100644 --- a/src/mongo/db/commands/cleanup_orphaned_cmd.cpp +++ b/src/mongo/db/commands/cleanup_orphaned_cmd.cpp @@ -61,7 +61,8 @@ namespace mongo { * * If the collection is not sharded, returns CleanupResult_Done. */ - CleanupResult cleanupOrphanedData( const NamespaceString& ns, + CleanupResult cleanupOrphanedData( TransactionExperiment* txn, + const NamespaceString& ns, const BSONObj& startingFromKeyConst, bool secondaryThrottle, BSONObj* stoppedAtKey, @@ -116,7 +117,8 @@ namespace mongo { // Metadata snapshot may be stale now, but deleter checks metadata again in write lock // before delete. - if ( !getDeleter()->deleteNow( ns.toString(), + if ( !getDeleter()->deleteNow( txn, + ns.toString(), orphanRange.minKey, orphanRange.maxKey, keyPattern, @@ -177,7 +179,8 @@ namespace mongo { // Output static BSONField<BSONObj> stoppedAtKeyField; - bool run( string const &db, + bool newRun( TransactionExperiment* txn, + string const &db, BSONObj &cmdObj, int, string &errmsg, @@ -231,7 +234,8 @@ namespace mongo { } BSONObj stoppedAtKey; - CleanupResult cleanupResult = cleanupOrphanedData( NamespaceString( ns ), + CleanupResult cleanupResult = cleanupOrphanedData( txn, + NamespaceString( ns ), startingFromKey, secondaryThrottle, &stoppedAtKey, diff --git a/src/mongo/db/commands/collection_to_capped.cpp b/src/mongo/db/commands/collection_to_capped.cpp index 0ed6f1bc15d..f1a375e6694 100644 --- a/src/mongo/db/commands/collection_to_capped.cpp +++ b/src/mongo/db/commands/collection_to_capped.cpp @@ -142,7 +142,7 @@ namespace mongo { NamespaceString(dbname, collection)), targetActions)); } - bool run(const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { + bool newRun(TransactionExperiment* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { string from = jsobj.getStringField( "cloneCollectionAsCapped" ); string to = jsobj.getStringField( "toCollection" ); double size = jsobj.getField( "size" ).number(); @@ -155,9 +155,8 @@ namespace mongo { Lock::DBWrite dbXLock(dbname); Client::Context ctx(dbname); - DurTransaction txn; - Status status = cloneCollectionAsCapped( &txn, ctx.db(), from, to, size, temp, true ); + Status status = cloneCollectionAsCapped( txn, ctx.db(), from, to, size, temp, true ); return appendCommandStatus( result, status ); } } cmdCloneCollectionAsCapped; @@ -197,12 +196,11 @@ namespace mongo { return std::vector<BSONObj>(); } - bool run(const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { + bool newRun(TransactionExperiment* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { // calls renamecollection which does a global lock, so we must too: // Lock::GlobalWrite globalWriteLock; Client::Context ctx(dbname); - DurTransaction txn; Database* db = ctx.db(); @@ -222,28 +220,28 @@ namespace mongo { string longTmpName = str::stream() << dbname << "." << shortTmpName; if ( db->getCollection( longTmpName ) ) { - Status status = db->dropCollection( &txn, longTmpName ); + Status status = db->dropCollection( txn, longTmpName ); if ( !status.isOK() ) return appendCommandStatus( result, status ); } - Status status = cloneCollectionAsCapped( &txn, db, shortSource, shortTmpName, size, true, false ); + Status status = cloneCollectionAsCapped( txn, db, shortSource, shortTmpName, size, true, false ); if ( !status.isOK() ) return appendCommandStatus( result, status ); verify( db->getCollection( longTmpName ) ); - status = db->dropCollection( &txn, longSource ); + status = db->dropCollection( txn, longSource ); if ( !status.isOK() ) return appendCommandStatus( result, status ); - status = db->renameCollection( &txn, longTmpName, longSource, false ); + status = db->renameCollection( txn, longTmpName, longSource, false ); if ( !status.isOK() ) return appendCommandStatus( result, status ); if (!fromRepl) - logOp(&txn, "c",(dbname + ".$cmd").c_str(), jsobj); + logOp(txn, "c",(dbname + ".$cmd").c_str(), jsobj); return true; } } cmdConvertToCapped; diff --git a/src/mongo/db/commands/compact.cpp b/src/mongo/db/commands/compact.cpp index 97508e62b5f..a469347d677 100644 --- a/src/mongo/db/commands/compact.cpp +++ b/src/mongo/db/commands/compact.cpp @@ -83,7 +83,7 @@ namespace mongo { return IndexBuilder::killMatchingIndexBuilds(db->getCollection(ns), criteria); } - virtual bool run(const string& db, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool newRun(TransactionExperiment* txn, const string& db, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { string coll = cmdObj.firstElement().valuestr(); if( coll.empty() || db.empty() ) { errmsg = "no collection name specified"; @@ -145,7 +145,6 @@ namespace mongo { Lock::DBWrite lk(ns.ns()); BackgroundOperation::assertNoBgOpInProgForNs(ns.ns()); Client::Context ctx(ns); - DurTransaction txn; Collection* collection = ctx.db()->getCollection(ns.ns()); if( ! collection ) { @@ -162,7 +161,7 @@ namespace mongo { std::vector<BSONObj> indexesInProg = stopIndexBuilds(ctx.db(), cmdObj); - StatusWith<CompactStats> status = collection->compact( &txn, &compactOptions ); + StatusWith<CompactStats> status = collection->compact( txn, &compactOptions ); if ( !status.isOK() ) return appendCommandStatus( result, status.getStatus() ); diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index ddc9fa9b535..06b0b6e20b7 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -70,7 +70,7 @@ namespace mongo { return b.obj(); } - virtual bool run( const string& dbname, BSONObj& cmdObj, int options, + virtual bool newRun(TransactionExperiment* txn, const string& dbname, BSONObj& cmdObj, int options, string& errmsg, BSONObjBuilder& result, bool fromRepl = false ) { @@ -167,13 +167,12 @@ namespace mongo { Client::WriteContext writeContext( ns.ns(), storageGlobalParams.dbpath, false /* doVersion */ ); - DurTransaction txn; Database* db = writeContext.ctx().db(); - Collection* collection = db->getCollection( &txn, ns.ns() ); + Collection* collection = db->getCollection( txn, ns.ns() ); result.appendBool( "createdCollectionAutomatically", collection == NULL ); if ( !collection ) { - collection = db->createCollection( &txn, ns.ns() ); + collection = db->createCollection( txn, ns.ns() ); invariant( collection ); } @@ -191,7 +190,7 @@ namespace mongo { } } - status = collection->getIndexCatalog()->createIndex(&txn, spec, true); + status = collection->getIndexCatalog()->createIndex(txn, spec, true); if ( status.code() == ErrorCodes::IndexAlreadyExists ) { if ( !result.hasField( "note" ) ) result.append( "note", "index already exists" ); @@ -205,7 +204,7 @@ namespace mongo { if ( !fromRepl ) { std::string systemIndexes = ns.getSystemIndexesCollection(); - logOp( &txn, "i", systemIndexes.c_str(), spec ); + logOp( txn, "i", systemIndexes.c_str(), spec ); } } diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp index f7655fdbcb3..ea60d797f69 100644 --- a/src/mongo/db/commands/drop_indexes.cpp +++ b/src/mongo/db/commands/drop_indexes.cpp @@ -92,12 +92,11 @@ namespace mongo { } CmdDropIndexes() : Command("dropIndexes", false, "deleteIndexes") { } - bool run(const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& anObjBuilder, bool fromRepl) { + bool newRun(TransactionExperiment* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& anObjBuilder, bool fromRepl) { Lock::DBWrite dbXLock(dbname); - DurTransaction txn; - bool ok = wrappedRun(&txn, dbname, jsobj, errmsg, anObjBuilder); + bool ok = wrappedRun(txn, dbname, jsobj, errmsg, anObjBuilder); if (ok && !fromRepl) - logOp(&txn, "c",(dbname + ".$cmd").c_str(), jsobj); + logOp(txn, "c",(dbname + ".$cmd").c_str(), jsobj); return ok; } bool wrappedRun(TransactionExperiment* txn, @@ -213,7 +212,7 @@ namespace mongo { return IndexBuilder::killMatchingIndexBuilds(db->getCollection(ns), criteria); } - bool run(const string& dbname , BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool /*fromRepl*/) { + bool newRun(TransactionExperiment* txn, const string& dbname , BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool /*fromRepl*/) { static DBDirectClient db; BSONElement e = jsobj.firstElement(); @@ -223,7 +222,6 @@ namespace mongo { Lock::DBWrite dbXLock(dbname); Client::Context ctx(toDeleteNs); - DurTransaction txn; Collection* collection = ctx.db()->getCollection( toDeleteNs ); @@ -255,7 +253,7 @@ namespace mongo { } result.appendNumber( "nIndexesWas", collection->getIndexCatalog()->numIndexesTotal() ); - Status s = collection->getIndexCatalog()->dropAllIndexes(&txn, true); + Status s = collection->getIndexCatalog()->dropAllIndexes(txn, true); if ( !s.isOK() ) { errmsg = "dropIndexes failed"; return appendCommandStatus( result, s ); @@ -264,7 +262,7 @@ namespace mongo { for ( list<BSONObj>::iterator i=all.begin(); i!=all.end(); i++ ) { BSONObj o = *i; LOG(1) << "reIndex ns: " << toDeleteNs << " index: " << o << endl; - Status s = collection->getIndexCatalog()->createIndex(&txn, o, false); + Status s = collection->getIndexCatalog()->createIndex(txn, o, false); if ( !s.isOK() ) return appendCommandStatus( result, s ); } diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp index 34370d6907a..98aab888860 100644 --- a/src/mongo/db/commands/find_and_modify.cpp +++ b/src/mongo/db/commands/find_and_modify.cpp @@ -65,7 +65,7 @@ namespace mongo { find_and_modify::addPrivilegesRequiredForFindAndModify(this, dbname, cmdObj, out); } /* this will eventually replace run, once sort is handled */ - bool runNoDirectClient( const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool runNoDirectClient( TransactionExperiment* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { verify( cmdObj["sort"].eoo() ); const string ns = dbname + '.' + cmdObj.firstElement().valuestr(); @@ -96,7 +96,7 @@ namespace mongo { Lock::DBWrite dbXLock(dbname); Client::Context ctx(ns); - return runNoDirectClient( ns , + return runNoDirectClient( txn, ns , query , fields , update , upsert , returnNew , remove , result , errmsg ); @@ -122,7 +122,8 @@ namespace mongo { result.append( "value" , p.transform( doc ) ); } - static bool runNoDirectClient(const string& ns, + static bool runNoDirectClient(TransactionExperiment* txn, + const string& ns, const BSONObj& queryOriginal, const BSONObj& fields, const BSONObj& update, @@ -134,8 +135,7 @@ namespace mongo { Lock::DBWrite lk( ns ); Client::Context cx( ns ); - DurTransaction txn; - Collection* collection = cx.db()->getCollection( &txn, ns ); + Collection* collection = cx.db()->getCollection( txn, ns ); const WhereCallbackReal whereCallback = WhereCallbackReal(StringData(ns)); @@ -222,7 +222,7 @@ namespace mongo { if ( remove ) { _appendHelper(result, doc, found, fields, whereCallback); if ( found ) { - deleteObjects(&txn, cx.db(), ns, queryModified, true, true); + deleteObjects(txn, cx.db(), ns, queryModified, true, true); BSONObjBuilder le( result.subobjStart( "lastErrorObject" ) ); le.appendNumber( "n" , 1 ); le.done(); @@ -252,8 +252,7 @@ namespace mongo { // the shard version below, but for now no UpdateLifecycleImpl updateLifecycle(false, requestNs); request.setLifecycle(&updateLifecycle); - UpdateResult res = - mongo::update(&txn, cx.db(), request, &cc().curop()->debug()); + UpdateResult res = mongo::update(txn, cx.db(), request, &cc().curop()->debug()); if ( !collection ) { // collection created by an upsert collection = cx.db()->getCollection( ns ); @@ -298,11 +297,11 @@ namespace mongo { return true; } - virtual bool run(const string& dbname, BSONObj& cmdObj, int x, string& errmsg, BSONObjBuilder& result, bool y) { - static DBDirectClient db; + virtual bool newRun(TransactionExperiment* txn, const string& dbname, BSONObj& cmdObj, int x, string& errmsg, BSONObjBuilder& result, bool y) { + DBDirectClient db(txn); if (cmdObj["sort"].eoo()) { - return runNoDirectClient(dbname, cmdObj, x, errmsg, result, y); + return runNoDirectClient(txn, dbname, cmdObj, x, errmsg, result, y); } const string ns = dbname + '.' + cmdObj.firstElement().valuestr(); diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index 7c39fee77e4..7a540a8a3ef 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -1208,7 +1208,7 @@ namespace mongo { addPrivilegesRequiredForMapReduce(this, dbname, cmdObj, out); } - bool run(const string& dbname , BSONObj& cmd, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { + bool newRun(TransactionExperiment* txn, const string& dbname , BSONObj& cmd, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { Timer t; Client& client = cc(); CurOp * op = client.curop(); @@ -1240,8 +1240,7 @@ namespace mongo { BSONObjBuilder countsBuilder; BSONObjBuilder timingBuilder; - DurTransaction txn; - State state( &txn, config ); + State state( txn, config ); if ( ! state.sourceExists() ) { errmsg = "ns doesn't exist"; return false; @@ -1354,7 +1353,7 @@ namespace mongo { reduceTime += t.micros(); - txn.checkForInterrupt(); + txn->checkForInterrupt(); } pm.hit(); @@ -1365,7 +1364,7 @@ namespace mongo { } pm.finished(); - txn.checkForInterrupt(); + txn->checkForInterrupt(); // update counters countsBuilder.appendNumber("input", numInputs); @@ -1447,7 +1446,7 @@ namespace mongo { actions.addAction(ActionType::internal); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool newRun(TransactionExperiment* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { ShardedConnectionInfo::addHook(); // legacy name string shardedOutputCollection = cmdObj["shardedOutputCollection"].valuestrsafe(); @@ -1464,8 +1463,7 @@ namespace mongo { CurOp * op = client.curop(); Config config( dbname , cmdObj.firstElement().embeddedObjectUserCheck() ); - DurTransaction txn; - State state(&txn, config); + State state(txn, config); state.init(); // no need for incremental collection because records are already sorted diff --git a/src/mongo/db/commands/rename_collection.cpp b/src/mongo/db/commands/rename_collection.cpp index cd72f781707..07bf511141b 100644 --- a/src/mongo/db/commands/rename_collection.cpp +++ b/src/mongo/db/commands/rename_collection.cpp @@ -91,15 +91,14 @@ namespace mongo { IndexBuilder::restoreIndexes( indexesInProg ); } - virtual bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool newRun(TransactionExperiment* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { Lock::GlobalWrite globalWriteLock; - DurTransaction txn; - bool ok = wrappedRun(&txn, dbname, cmdObj, errmsg, result, fromRepl); + bool ok = wrappedRun(txn, dbname, cmdObj, errmsg, result, fromRepl); if (ok && !fromRepl) - logOp(&txn, "c",(dbname + ".$cmd").c_str(), cmdObj); + logOp(txn, "c",(dbname + ".$cmd").c_str(), cmdObj); return ok; } - virtual bool wrappedRun(DurTransaction* txn, + virtual bool wrappedRun(TransactionExperiment* txn, const string& dbname, BSONObj& cmdObj, string& errmsg, diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp index 263b7af7f88..428298868b9 100644 --- a/src/mongo/db/commands/test_commands.cpp +++ b/src/mongo/db/commands/test_commands.cpp @@ -55,7 +55,7 @@ namespace mongo { virtual void help( stringstream &help ) const { help << "internal. for testing only."; } - virtual bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + virtual bool newRun(TransactionExperiment* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { string coll = cmdObj[ "godinsert" ].valuestrsafe(); log() << "test only command godinsert invoked coll:" << coll << endl; uassert( 13049, "godinsert must specify a collection", !coll.empty() ); @@ -64,17 +64,16 @@ namespace mongo { Lock::DBWrite lk(ns); Client::Context ctx( ns ); - DurTransaction txn; Database* db = ctx.db(); Collection* collection = db->getCollection( ns ); if ( !collection ) { - collection = db->createCollection( &txn, ns ); + collection = db->createCollection( txn, ns ); if ( !collection ) { errmsg = "could not create collection"; return false; } } - StatusWith<DiskLoc> res = collection->insertDocument( &txn, obj, false ); + StatusWith<DiskLoc> res = collection->insertDocument( txn, obj, false ); return appendCommandStatus( result, res.getStatus() ); } }; @@ -134,7 +133,7 @@ namespace mongo { virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, std::vector<Privilege>* out) {} - virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + virtual bool newRun(TransactionExperiment* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { string coll = cmdObj[ "captrunc" ].valuestrsafe(); uassert( 13416, "captrunc must specify a collection", !coll.empty() ); NamespaceString nss( dbname, coll ); @@ -142,7 +141,6 @@ namespace mongo { bool inc = cmdObj.getBoolField( "inc" ); // inclusive range? Client::WriteContext ctx( nss.ns() ); - DurTransaction txn; Collection* collection = ctx.ctx().db()->getCollection( nss.ns() ); massert( 13417, "captrunc collection not found or empty", collection); @@ -155,7 +153,7 @@ namespace mongo { Runner::RunnerState state = runner->getNext(NULL, &end); massert( 13418, "captrunc invalid n", Runner::RUNNER_ADVANCED == state); } - collection->temp_cappedTruncateAfter( &txn, end, inc ); + collection->temp_cappedTruncateAfter( txn, end, inc ); return true; } }; @@ -182,27 +180,26 @@ namespace mongo { return IndexBuilder::killMatchingIndexBuilds(db->getCollection(ns), criteria); } - virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool newRun(TransactionExperiment* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { string coll = cmdObj[ "emptycapped" ].valuestrsafe(); uassert( 13428, "emptycapped must specify a collection", !coll.empty() ); NamespaceString nss( dbname, coll ); Client::WriteContext ctx( nss.ns() ); - DurTransaction txn; Database* db = ctx.ctx().db(); Collection* collection = db->getCollection( nss.ns() ); massert( 13429, "emptycapped no such collection", collection ); std::vector<BSONObj> indexes = stopIndexBuilds(db, cmdObj); - Status status = collection->truncate(&txn); + Status status = collection->truncate(txn); if ( !status.isOK() ) return appendCommandStatus( result, status ); IndexBuilder::restoreIndexes(indexes); if (!fromRepl) - logOp(&txn, "c",(dbname + ".$cmd").c_str(), cmdObj); + logOp(txn, "c",(dbname + ".$cmd").c_str(), cmdObj); return true; } }; diff --git a/src/mongo/db/commands/touch.cpp b/src/mongo/db/commands/touch.cpp index 6427fba7b64..2011758f042 100644 --- a/src/mongo/db/commands/touch.cpp +++ b/src/mongo/db/commands/touch.cpp @@ -77,7 +77,8 @@ namespace mongo { } TouchCmd() : Command("touch") { } - virtual bool run(const string& dbname, + virtual bool newRun(TransactionExperiment* txn, + const string& dbname, BSONObj& cmdObj, int, string& errmsg, @@ -104,7 +105,6 @@ namespace mongo { } Client::ReadContext context( nss.ns() ); - DurTransaction txn; Database* db = context.ctx().db(); Collection* collection = db->getCollection( nss.ns() ); @@ -114,7 +114,7 @@ namespace mongo { } return appendCommandStatus( result, - collection->touch( &txn, + collection->touch( txn, touch_data, touch_indexes, &result ) ); } diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp index d9d20610b45..3fba9dd4b00 100644 --- a/src/mongo/db/commands/validate.cpp +++ b/src/mongo/db/commands/validate.cpp @@ -59,7 +59,7 @@ namespace mongo { } //{ validate: "collectionnamewithoutthedbpart" [, scandata: <bool>] [, full: <bool> } */ - bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { + bool newRun(TransactionExperiment* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { string ns = dbname + "." + cmdObj.firstElement().valuestrsafe(); NamespaceString ns_string(ns); @@ -76,7 +76,6 @@ namespace mongo { } Client::ReadContext ctx(ns_string.ns()); - DurTransaction txn; Database* db = ctx.ctx().db(); if ( !db ) { @@ -93,7 +92,7 @@ namespace mongo { result.append( "ns", ns ); ValidateResults results; - Status status = collection->validate( &txn, full, scanData, &results, &result ); + Status status = collection->validate( txn, full, scanData, &results, &result ); if ( !status.isOK() ) return appendCommandStatus( result, status ); diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp index 160ed358bab..d7295a5458f 100644 --- a/src/mongo/db/commands/write_commands/batch_executor.cpp +++ b/src/mongo/db/commands/write_commands/batch_executor.cpp @@ -89,10 +89,12 @@ namespace mongo { using mongoutils::str::stream; - WriteBatchExecutor::WriteBatchExecutor( const BSONObj& wc, + WriteBatchExecutor::WriteBatchExecutor( TransactionExperiment* txn, + const BSONObj& wc, Client* client, OpCounters* opCounters, LastError* le ) : + _txn(txn), _defaultWriteConcern( wc ), _client( client ), _opCounters( opCounters ), @@ -577,7 +579,10 @@ namespace mongo { } } - static void finishCurrentOp( Client* client, CurOp* currentOp, WriteErrorDetail* opError ) { + static void finishCurrentOp( TransactionExperiment* txn, + Client* client, + CurOp* currentOp, + WriteErrorDetail* opError ) { currentOp->done(); int executionTime = currentOp->debug().executionTime = currentOp->totalTimeMillis(); @@ -600,8 +605,7 @@ namespace mongo { } if ( currentOp->shouldDBProfile( executionTime ) ) { - DurTransaction txn; - profile( &txn, *client, currentOp->getOp(), *currentOp ); + profile( txn, *client, currentOp->getOp(), *currentOp ); } } @@ -614,18 +618,23 @@ namespace mongo { // - error // - static void singleInsert( const BSONObj& docToInsert, + static void singleInsert( TransactionExperiment* txn, + const BSONObj& docToInsert, Collection* collection, WriteOpResult* result ); - static void singleCreateIndex( const BSONObj& indexDesc, + static void singleCreateIndex( TransactionExperiment* txn, + const BSONObj& indexDesc, Collection* collection, WriteOpResult* result ); - static void multiUpdate( const BatchItemRef& updateItem, + static void multiUpdate( TransactionExperiment* txn, + const BatchItemRef& updateItem, WriteOpResult* result ); - static void multiRemove( const BatchItemRef& removeItem, WriteOpResult* result ); + static void multiRemove( TransactionExperiment* txn, + const BatchItemRef& removeItem, + WriteOpResult* result ); // // WRITE EXECUTION @@ -644,7 +653,8 @@ namespace mongo { /** * Constructs a new instance, for performing inserts described in "aRequest". */ - explicit ExecInsertsState(const BatchedCommandRequest* aRequest); + explicit ExecInsertsState(TransactionExperiment* txn, + const BatchedCommandRequest* aRequest); /** * Acquires the write lock and client context needed to perform the current write operation. @@ -677,6 +687,8 @@ namespace mongo { */ Collection* getCollection() { return _collection; } + TransactionExperiment* txn; + // Request object describing the inserts. const BatchedCommandRequest* request; @@ -796,7 +808,7 @@ namespace mongo { // particularly on operation interruption. These kinds of errors necessarily prevent // further insertOne calls, and stop the batch. As a result, the only expected source of // such exceptions are interruptions. - ExecInsertsState state(&request); + ExecInsertsState state(_txn, &request); normalizeInserts(request, &state.normalizedInserts); ElapsedTracker elapsedTracker(128, 10); // 128 hits or 10 ms, matching RunnerYieldPolicy's @@ -832,7 +844,7 @@ namespace mongo { incOpStats( updateItem ); WriteOpResult result; - multiUpdate( updateItem, &result ); + multiUpdate( _txn, updateItem, &result ); if ( !result.getStats().upsertedID.isEmpty() ) { *upsertedId = result.getStats().upsertedID; @@ -840,7 +852,7 @@ namespace mongo { // END CURRENT OP incWriteStats( updateItem, result.getStats(), result.getError(), currentOp.get() ); - finishCurrentOp( _client, currentOp.get(), result.getError() ); + finishCurrentOp( _txn, _client, currentOp.get(), result.getError() ); if ( result.getError() ) { result.getError()->setIndex( updateItem.getItemIndex() ); @@ -859,11 +871,11 @@ namespace mongo { WriteOpResult result; - multiRemove( removeItem, &result ); + multiRemove( _txn, removeItem, &result ); // END CURRENT OP incWriteStats( removeItem, result.getStats(), result.getError(), currentOp.get() ); - finishCurrentOp( _client, currentOp.get(), result.getError() ); + finishCurrentOp( _txn, _client, currentOp.get(), result.getError() ); if ( result.getError() ) { result.getError()->setIndex( removeItem.getItemIndex() ); @@ -875,7 +887,9 @@ namespace mongo { // IN-DB-LOCK CORE OPERATIONS // - WriteBatchExecutor::ExecInsertsState::ExecInsertsState(const BatchedCommandRequest* aRequest) : + WriteBatchExecutor::ExecInsertsState::ExecInsertsState(TransactionExperiment* txn, + const BatchedCommandRequest* aRequest) : + txn(txn), request(aRequest), currIndex(0), _collection(NULL) { @@ -906,8 +920,7 @@ namespace mongo { _collection = database->getCollection(request->getTargetingNS()); if (!_collection) { // Implicitly create if it doesn't exist - DurTransaction txn; - _collection = database->createCollection(&txn, request->getTargetingNS()); + _collection = database->createCollection(txn, request->getTargetingNS()); if (!_collection) { result->setError( toWriteError(Status(ErrorCodes::InternalError, @@ -948,10 +961,10 @@ namespace mongo { try { if (state->lockAndCheck(result)) { if (!state->request->isInsertIndexRequest()) { - singleInsert(insertDoc, state->getCollection(), result); + singleInsert(state->txn, insertDoc, state->getCollection(), result); } else { - singleCreateIndex(insertDoc, state->getCollection(), result); + singleCreateIndex(state->txn, insertDoc, state->getCollection(), result); } } } @@ -989,7 +1002,7 @@ namespace mongo { result.getStats(), result.getError(), currentOp.get()); - finishCurrentOp(_client, currentOp.get(), result.getError()); + finishCurrentOp(_txn, _client, currentOp.get(), result.getError()); if (result.getError()) { *error = result.releaseError(); @@ -1002,7 +1015,8 @@ namespace mongo { * * Might fault or error, otherwise populates the result. */ - static void singleInsert( const BSONObj& docToInsert, + static void singleInsert( TransactionExperiment* txn, + const BSONObj& docToInsert, Collection* collection, WriteOpResult* result ) { @@ -1010,15 +1024,14 @@ namespace mongo { Lock::assertWriteLocked( insertNS ); - DurTransaction txn; - StatusWith<DiskLoc> status = collection->insertDocument( &txn, docToInsert, true ); + StatusWith<DiskLoc> status = collection->insertDocument( txn, docToInsert, true ); if ( !status.isOK() ) { result->setError(toWriteError(status.getStatus())); } else { - logOp( &txn, "i", insertNS.c_str(), docToInsert ); - txn.commitIfNeeded(); + logOp( txn, "i", insertNS.c_str(), docToInsert ); + txn->commitIfNeeded(); result->getStats().n = 1; } } @@ -1029,16 +1042,16 @@ namespace mongo { * * Might fault or error, otherwise populates the result. */ - static void singleCreateIndex( const BSONObj& indexDesc, + static void singleCreateIndex( TransactionExperiment* txn, + const BSONObj& indexDesc, Collection* collection, WriteOpResult* result ) { - DurTransaction txn; const string indexNS = collection->ns().getSystemIndexesCollection(); Lock::assertWriteLocked( indexNS ); - Status status = collection->getIndexCatalog()->createIndex(&txn, indexDesc, true); + Status status = collection->getIndexCatalog()->createIndex(txn, indexDesc, true); if ( status.code() == ErrorCodes::IndexAlreadyExists ) { result->getStats().n = 0; @@ -1047,12 +1060,13 @@ namespace mongo { result->setError(toWriteError(status)); } else { - logOp( &txn, "i", indexNS.c_str(), indexDesc ); + logOp( txn, "i", indexNS.c_str(), indexDesc ); result->getStats().n = 1; } } - static void multiUpdate( const BatchItemRef& updateItem, + static void multiUpdate( TransactionExperiment* txn, + const BatchItemRef& updateItem, WriteOpResult* result ) { const NamespaceString nsString(updateItem.getRequest()->getNS()); @@ -1082,10 +1096,9 @@ namespace mongo { Client::Context ctx( nsString.ns(), storageGlobalParams.dbpath, false /* don't check version */ ); - DurTransaction txn; try { - UpdateResult res = executor.execute(&txn, ctx.db()); + UpdateResult res = executor.execute(txn, ctx.db()); const long long numDocsModified = res.numDocsModified; const long long numMatched = res.numMatched; @@ -1113,7 +1126,8 @@ namespace mongo { * * Might fault or error, otherwise populates the result. */ - static void multiRemove( const BatchItemRef& removeItem, + static void multiRemove( TransactionExperiment* txn, + const BatchItemRef& removeItem, WriteOpResult* result ) { const NamespaceString nss( removeItem.getRequest()->getNS() ); @@ -1145,10 +1159,9 @@ namespace mongo { Client::Context writeContext( nss.ns(), storageGlobalParams.dbpath, false /* don't check version */); - DurTransaction txn; try { - result->getStats().n = executor.execute(&txn, writeContext.db()); + result->getStats().n = executor.execute(txn, writeContext.db()); } catch ( const DBException& ex ) { status = ex.toStatus(); diff --git a/src/mongo/db/commands/write_commands/batch_executor.h b/src/mongo/db/commands/write_commands/batch_executor.h index c45443231ef..6406474e396 100644 --- a/src/mongo/db/commands/write_commands/batch_executor.h +++ b/src/mongo/db/commands/write_commands/batch_executor.h @@ -43,6 +43,7 @@ namespace mongo { class BSONObjBuilder; class CurOp; class OpCounters; + class TransactionExperiment; struct LastError; struct WriteOpStats; @@ -58,7 +59,8 @@ namespace mongo { // State object used by private execInserts. TODO: Do not expose this type. class ExecInsertsState; - WriteBatchExecutor( const BSONObj& defaultWriteConcern, + WriteBatchExecutor( TransactionExperiment* txn, + const BSONObj& defaultWriteConcern, Client* client, OpCounters* opCounters, LastError* le ); @@ -132,6 +134,8 @@ namespace mongo { const WriteErrorDetail* error, CurOp* currentOp ); + TransactionExperiment* _txn; + // Default write concern, if one isn't provide in the batches. const BSONObj _defaultWriteConcern; diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp index f64c1fa7545..bcc297cf4b6 100644 --- a/src/mongo/db/commands/write_commands/write_commands.cpp +++ b/src/mongo/db/commands/write_commands/write_commands.cpp @@ -102,7 +102,8 @@ namespace mongo { // Write commands are counted towards their corresponding opcounters, not command opcounters. bool WriteCmd::shouldAffectCommandCounter() const { return false; } - bool WriteCmd::run(const string& dbName, + bool WriteCmd::newRun(TransactionExperiment* txn, + const string& dbName, BSONObj& cmdObj, int options, string& errMsg, @@ -132,7 +133,8 @@ namespace mongo { // TODO: fix this for sane behavior where we query repl set object if ( getLastErrorDefault ) defaultWriteConcern = *getLastErrorDefault; - WriteBatchExecutor writeBatchExecutor(defaultWriteConcern, + WriteBatchExecutor writeBatchExecutor(txn, + defaultWriteConcern, &cc(), &globalOpCounters, lastError.get()); diff --git a/src/mongo/db/commands/write_commands/write_commands.h b/src/mongo/db/commands/write_commands/write_commands.h index f8fccacc439..c94c505d5b5 100644 --- a/src/mongo/db/commands/write_commands/write_commands.h +++ b/src/mongo/db/commands/write_commands/write_commands.h @@ -72,7 +72,9 @@ namespace mongo { virtual bool shouldAffectCommandCounter() const; // Write command entry point. - virtual bool run(const string& dbname, + virtual bool newRun( + TransactionExperiment* txn, + const string& dbname, BSONObj& cmdObj, int options, string& errmsg, |