diff options
author | Jason Rassi <rassi@10gen.com> | 2014-10-20 17:08:55 -0400 |
---|---|---|
committer | Jason Rassi <rassi@10gen.com> | 2014-11-20 12:52:25 -0500 |
commit | 429dc5819eb37e21d9e5c4573aae8421efd50ed7 (patch) | |
tree | e64019b8d4fd795cac5a778df79a0983bb34bcf7 /src/mongo/db | |
parent | 1b204eba0dc80f4007cb88b995b761a8bc0987fc (diff) | |
download | mongo-429dc5819eb37e21d9e5c4573aae8421efd50ed7.tar.gz |
SERVER-15675 Remove OperationContext from UpdateRequest/DeleteRequest
The write execution machinery should have a handle to the operation
context, not the write request structs.
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/commands/find_and_modify.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/commands/write_commands/batch_executor.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/commands/write_commands/write_commands.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/dbhelpers.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/exec/update.cpp | 29 | ||||
-rw-r--r-- | src/mongo/db/exec/update.h | 6 | ||||
-rw-r--r-- | src/mongo/db/instance.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/ops/delete.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/ops/delete_executor.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/ops/delete_executor.h | 13 | ||||
-rw-r--r-- | src/mongo/db/ops/delete_request.h | 5 | ||||
-rw-r--r-- | src/mongo/db/ops/update.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/ops/update.h | 3 | ||||
-rw-r--r-- | src/mongo/db/ops/update_executor.cpp | 29 | ||||
-rw-r--r-- | src/mongo/db/ops/update_executor.h | 19 | ||||
-rw-r--r-- | src/mongo/db/ops/update_request.h | 12 | ||||
-rw-r--r-- | src/mongo/db/query/get_executor.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/repl/master_slave.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/repl/rs_rollback.cpp | 4 |
20 files changed, 104 insertions, 102 deletions
diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp index de0ff7dbb60..c6f7f7fca97 100644 --- a/src/mongo/db/commands/find_and_modify.cpp +++ b/src/mongo/db/commands/find_and_modify.cpp @@ -307,7 +307,7 @@ namespace mongo { } const NamespaceString requestNs(ns); - UpdateRequest request(txn, requestNs); + UpdateRequest request(requestNs); request.setQuery(queryModified); request.setUpdates(update); @@ -320,7 +320,8 @@ namespace mongo { // the shard version below, but for now no UpdateLifecycleImpl updateLifecycle(false, requestNs); request.setLifecycle(&updateLifecycle); - UpdateResult res = mongo::update(cx.db(), + UpdateResult res = mongo::update(txn, + cx.db(), request, &txn->getCurOp()->debug()); diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp index b24b6e72b5a..17552185f0e 100644 --- a/src/mongo/db/commands/write_commands/batch_executor.cpp +++ b/src/mongo/db/commands/write_commands/batch_executor.cpp @@ -1176,7 +1176,7 @@ namespace mongo { const NamespaceString nsString(updateItem.getRequest()->getNS()); const bool isMulti = updateItem.getUpdate()->getMulti(); - UpdateRequest request(txn, nsString); + UpdateRequest request(nsString); request.setQuery(updateItem.getUpdate()->getQuery()); request.setUpdates(updateItem.getUpdate()->getUpdateExpr()); request.setMulti(isMulti); @@ -1192,7 +1192,7 @@ namespace mongo { bool createCollection = false; for ( int fakeLoop = 0; fakeLoop < 1; fakeLoop++ ) { - UpdateExecutor executor(&request, &txn->getCurOp()->debug()); + UpdateExecutor executor(txn, &request, &txn->getCurOp()->debug()); Status status = executor.prepare(); if (!status.isOK()) { result->setError(toWriteError(status)); @@ -1320,7 +1320,7 @@ namespace mongo { WriteOpResult* result ) { const NamespaceString nss( removeItem.getRequest()->getNS() ); - DeleteRequest request(txn, nss); + DeleteRequest request(nss); request.setQuery( removeItem.getDelete()->getQuery() ); request.setMulti( removeItem.getDelete()->getLimit() != 1 ); request.setUpdateOpLog(true); @@ -1333,7 +1333,7 @@ namespace mongo { while ( 1 ) { try { - DeleteExecutor executor( &request ); + DeleteExecutor executor( txn, &request ); Status status = executor.prepare(); if ( !status.isOK() ) { result->setError(toWriteError(status)); diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp index e20ff8c883a..216cba64264 100644 --- a/src/mongo/db/commands/write_commands/write_commands.cpp +++ b/src/mongo/db/commands/write_commands/write_commands.cpp @@ -192,7 +192,7 @@ namespace mongo { if ( BatchedCommandRequest::BatchType_Update == _writeType ) { // Create the update request. - UpdateRequest updateRequest( txn, nsString ); + UpdateRequest updateRequest( nsString ); updateRequest.setQuery( batchItem.getUpdate()->getQuery() ); updateRequest.setUpdates( batchItem.getUpdate()->getUpdateExpr() ); updateRequest.setMulti( batchItem.getUpdate()->getMulti() ); @@ -207,7 +207,7 @@ namespace mongo { // Use the request to create an UpdateExecutor, and from it extract the // plan tree which will be used to execute this update. - UpdateExecutor updateExecutor( &updateRequest, &txn->getCurOp()->debug() ); + UpdateExecutor updateExecutor( txn, &updateRequest, &txn->getCurOp()->debug() ); Status prepStatus = updateExecutor.prepare(); if ( !prepStatus.isOK() ) { return prepStatus; @@ -240,7 +240,7 @@ namespace mongo { invariant( BatchedCommandRequest::BatchType_Delete == _writeType ); // Create the delete request. - DeleteRequest deleteRequest( txn, nsString ); + DeleteRequest deleteRequest( nsString ); deleteRequest.setQuery( batchItem.getDelete()->getQuery() ); deleteRequest.setMulti( batchItem.getDelete()->getLimit() != 1 ); deleteRequest.setUpdateOpLog(true); @@ -252,7 +252,7 @@ namespace mongo { // Use the request to create a DeleteExecutor, and from it extract the // plan tree which will be used to execute this update. - DeleteExecutor deleteExecutor( &deleteRequest ); + DeleteExecutor deleteExecutor( txn, &deleteRequest ); Status prepStatus = deleteExecutor.prepare(); if ( !prepStatus.isOK() ) { return prepStatus; diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp index 116fa9e9379..3aeb2d6b875 100644 --- a/src/mongo/db/dbhelpers.cpp +++ b/src/mongo/db/dbhelpers.cpp @@ -235,7 +235,7 @@ namespace mongo { Client::Context context(txn, ns); const NamespaceString requestNs(ns); - UpdateRequest request(txn, requestNs); + UpdateRequest request(requestNs); request.setQuery(id); request.setUpdates(o); @@ -245,7 +245,7 @@ namespace mongo { UpdateLifecycleImpl updateLifecycle(true, requestNs); request.setLifecycle(&updateLifecycle); - update(context.db(), request, &debug); + update(txn, context.db(), request, &debug); } void Helpers::putSingleton(OperationContext* txn, const char *ns, BSONObj obj) { @@ -253,7 +253,7 @@ namespace mongo { Client::Context context(txn, ns); const NamespaceString requestNs(ns); - UpdateRequest request(txn, requestNs); + UpdateRequest request(requestNs); request.setUpdates(obj); request.setUpsert(); @@ -261,7 +261,7 @@ namespace mongo { UpdateLifecycleImpl updateLifecycle(true, requestNs); request.setLifecycle(&updateLifecycle); - update(context.db(), request, &debug); + update(txn, context.db(), request, &debug); context.getClient()->curop()->done(); } @@ -271,14 +271,14 @@ namespace mongo { Client::Context context(txn, ns); const NamespaceString requestNs(ns); - UpdateRequest request(txn, requestNs); + UpdateRequest request(requestNs); request.setGod(); request.setUpdates(obj); request.setUpsert(); request.setUpdateOpLog(logTheOp); - update(context.db(), request, &debug); + update(txn, context.db(), request, &debug); context.getClient()->curop()->done(); } diff --git a/src/mongo/db/exec/update.cpp b/src/mongo/db/exec/update.cpp index 106c9406711..fab80fe18d8 100644 --- a/src/mongo/db/exec/update.cpp +++ b/src/mongo/db/exec/update.cpp @@ -393,11 +393,13 @@ namespace mongo { // static const char* UpdateStage::kStageType = "UPDATE"; - UpdateStage::UpdateStage(const UpdateStageParams& params, + UpdateStage::UpdateStage(OperationContext* txn, + const UpdateStageParams& params, WorkingSet* ws, Collection* collection, PlanStage* child) - : _params(params), + : _txn(txn), + _params(params), _ws(ws), _collection(collection), _child(child), @@ -487,7 +489,7 @@ namespace mongo { } { - WriteUnitOfWork wunit(request->getOpCtx()); + WriteUnitOfWork wunit(_txn); if (inPlace && !driver->modsAffectIndices()) { // If a set of modifiers were all no-ops, we are still 'in place', but there @@ -497,8 +499,7 @@ namespace mongo { if (!request->isExplain()) { invariant(_collection); const RecordData oldRec(oldObj.objdata(), oldObj.objsize()); - _collection->updateDocumentWithDamages(request->getOpCtx(), loc, - oldRec, source, _damages); + _collection->updateDocumentWithDamages(_txn, loc, oldRec, source, _damages); } docWasModified = true; _specificStats.fastmod = true; @@ -519,7 +520,7 @@ namespace mongo { // Don't actually do the write if this is an explain. if (!request->isExplain()) { invariant(_collection); - StatusWith<DiskLoc> res = _collection->updateDocument(request->getOpCtx(), + StatusWith<DiskLoc> res = _collection->updateDocument(_txn, loc, newObj, true, @@ -542,7 +543,7 @@ namespace mongo { // Call logOp if requested, and we're not an explain. if (request->shouldCallLogOp() && !logObj.isEmpty() && !request->isExplain()) { BSONObj idQuery = driver->makeOplogEntryQuery(newObj, request->isMulti()); - repl::logOp(request->getOpCtx(), + repl::logOp(_txn, "u", request->getNamespaceString().ns().c_str(), logObj, @@ -638,14 +639,14 @@ namespace mongo { return; } - WriteUnitOfWork wunit(request->getOpCtx()); + WriteUnitOfWork wunit(_txn); invariant(_collection); - StatusWith<DiskLoc> newLoc = _collection->insertDocument(request->getOpCtx(), + StatusWith<DiskLoc> newLoc = _collection->insertDocument(_txn, newObj, !request->isGod()/*enforceQuota*/); uassertStatusOK(newLoc.getStatus()); if (request->shouldCallLogOp()) { - repl::logOp(request->getOpCtx(), + repl::logOp(_txn, "i", request->getNamespaceString().ns().c_str(), newObj, @@ -758,9 +759,8 @@ namespace mongo { log() << "Had WriteConflict in the middle of a multi-update, " << "retrying the current update"; - OperationContext* txn = _params.request->getOpCtx(); - txn->recoveryUnit()->commitAndRestart(); - if ( !_collection->findDoc( txn, loc, &reFetched ) ) { + _txn->recoveryUnit()->commitAndRestart(); + if ( !_collection->findDoc( _txn, loc, &reFetched ) ) { // document was deleted, we're done here break; } @@ -780,7 +780,7 @@ namespace mongo { // As restoreState may restore (recreate) cursors, make sure to restore the // state outside of the WritUnitOfWork. - restoreState(_params.request->getOpCtx()); + restoreState(_txn); ++_commonStats.needTime; return PlanStage::NEED_TIME; @@ -848,6 +848,7 @@ namespace mongo { } void UpdateStage::restoreState(OperationContext* opCtx) { + _txn = opCtx; ++_commonStats.unyields; // Restore our child. _child->restoreState(opCtx); diff --git a/src/mongo/db/exec/update.h b/src/mongo/db/exec/update.h index 8e097bac999..99345279c01 100644 --- a/src/mongo/db/exec/update.h +++ b/src/mongo/db/exec/update.h @@ -76,7 +76,8 @@ namespace mongo { class UpdateStage : public PlanStage { MONGO_DISALLOW_COPYING(UpdateStage); public: - UpdateStage(const UpdateStageParams& params, + UpdateStage(OperationContext* txn, + const UpdateStageParams& params, WorkingSet* ws, Collection* collection, PlanStage* child); @@ -130,6 +131,9 @@ namespace mongo { */ Status restoreUpdateState(OperationContext* opCtx); + // Transactional context. Not owned by us. + OperationContext* _txn; + UpdateStageParams _params; // Not owned by us. diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp index 64d55a656e0..9c97fccecdb 100644 --- a/src/mongo/db/instance.cpp +++ b/src/mongo/db/instance.cpp @@ -554,7 +554,7 @@ namespace { op.debug().query = query; op.setQuery(query); - UpdateRequest request(txn, ns); + UpdateRequest request(ns); request.setUpsert(upsert); request.setMulti(multi); @@ -569,7 +569,7 @@ namespace { int attempt = 1; while ( 1 ) { try { - UpdateExecutor executor(&request, &op.debug()); + UpdateExecutor executor(txn, &request, &op.debug()); uassertStatusOK(executor.prepare()); // Tentatively take an intent lock, fix up if we need to create the collection @@ -603,7 +603,7 @@ namespace { // This is an upsert into a non-existing database, so need an exclusive lock // to avoid deadlock { - UpdateExecutor executor(&request, &op.debug()); + UpdateExecutor executor(txn, &request, &op.debug()); uassertStatusOK(executor.prepare()); Lock::DBLock dbLock(txn->lockState(), ns.db(), MODE_X); @@ -645,7 +645,7 @@ namespace { op.debug().query = pattern; op.setQuery(pattern); - DeleteRequest request(txn, ns); + DeleteRequest request(ns); request.setQuery(pattern); request.setMulti(!justOne); request.setUpdateOpLog(true); @@ -655,7 +655,7 @@ namespace { int attempt = 1; while ( 1 ) { try { - DeleteExecutor executor(&request); + DeleteExecutor executor(txn, &request); uassertStatusOK(executor.prepare()); AutoGetDb autoDb(txn, ns.db(), MODE_IX); diff --git a/src/mongo/db/ops/delete.cpp b/src/mongo/db/ops/delete.cpp index 34016c91a92..8fc12448a21 100644 --- a/src/mongo/db/ops/delete.cpp +++ b/src/mongo/db/ops/delete.cpp @@ -48,14 +48,14 @@ namespace mongo { bool god, bool fromMigrate) { NamespaceString nsString(ns); - DeleteRequest request(txn, nsString); + DeleteRequest request(nsString); request.setQuery(pattern); request.setMulti(!justOne); request.setUpdateOpLog(logop); request.setGod(god); request.setFromMigrate(fromMigrate); request.setYieldPolicy(policy); - DeleteExecutor executor(&request); + DeleteExecutor executor(txn, &request); return executor.execute(db); } diff --git a/src/mongo/db/ops/delete_executor.cpp b/src/mongo/db/ops/delete_executor.cpp index 0fb966ef64e..01b08e6c56d 100644 --- a/src/mongo/db/ops/delete_executor.cpp +++ b/src/mongo/db/ops/delete_executor.cpp @@ -46,7 +46,8 @@ namespace mongo { - DeleteExecutor::DeleteExecutor(const DeleteRequest* request) : + DeleteExecutor::DeleteExecutor(OperationContext* txn, const DeleteRequest* request) : + _txn(txn), _request(request), _canonicalQuery(), _isQueryParsed(false) { @@ -66,8 +67,7 @@ namespace mongo { } CanonicalQuery* cqRaw; - const WhereCallbackReal whereCallback( - _request->getOpCtx(), _request->getNamespaceString().db()); + const WhereCallbackReal whereCallback(_txn, _request->getNamespaceString().db()); Status status = CanonicalQuery::canonicalize(_request->getNamespaceString().ns(), _request->getQuery(), @@ -116,7 +116,7 @@ namespace mongo { // on top of an EOFStage. Collection* collection = NULL; if (db) { - collection = db->getCollection(_request->getOpCtx(), ns.ns()); + collection = db->getCollection(_txn, ns.ns()); } if (collection && collection->isCapped()) { @@ -145,7 +145,7 @@ namespace mongo { Status getExecStatus = Status::OK(); if (_canonicalQuery.get()) { // This is the non-idhack branch. - getExecStatus = getExecutorDelete(_request->getOpCtx(), + getExecStatus = getExecutorDelete(_txn, collection, _canonicalQuery.release(), _request->isMulti(), @@ -157,7 +157,7 @@ namespace mongo { } else { // This is the idhack branch. - getExecStatus = getExecutorDelete(_request->getOpCtx(), + getExecStatus = getExecutorDelete(_txn, collection, ns.ns(), _request->getQuery(), diff --git a/src/mongo/db/ops/delete_executor.h b/src/mongo/db/ops/delete_executor.h index e4f5c2f2fe4..cc984af1c95 100644 --- a/src/mongo/db/ops/delete_executor.h +++ b/src/mongo/db/ops/delete_executor.h @@ -53,7 +53,7 @@ namespace mongo { * Expected usage is approximately: * DeleteRequest request(...); * // configure request - * DeleteExecutor executor(&request); + * DeleteExecutor executor(txn, &request); * uassertStatusOK(executor.prepare()); * // Get locks, get ready to execute. * try { @@ -72,7 +72,7 @@ namespace mongo { * The object pointed to by "request" must stay in scope for the life of the constructed * executor. */ - explicit DeleteExecutor(const DeleteRequest* request); + DeleteExecutor(OperationContext* txn, const DeleteRequest* request); ~DeleteExecutor(); @@ -112,16 +112,19 @@ namespace mongo { long long execute(Database* db); private: - /// Unowned pointer to the request object that this executor will process. + // Transactional context. Not owned by us. + OperationContext* _txn; + + // Unowned pointer to the request object that this executor will process. const DeleteRequest* const _request; - /// Parsed query object, or NULL if the query proves to be an id hack query. + // Parsed query object, or NULL if the query proves to be an id hack query. std::auto_ptr<CanonicalQuery> _canonicalQuery; // The tree of execution stages which will be used to execute the update. boost::scoped_ptr<PlanExecutor> _exec; - /// Flag indicating if the query has been successfully parsed. + // Flag indicating if the query has been successfully parsed. bool _isQueryParsed; }; diff --git a/src/mongo/db/ops/delete_request.h b/src/mongo/db/ops/delete_request.h index f1378da5533..3b3d97328ef 100644 --- a/src/mongo/db/ops/delete_request.h +++ b/src/mongo/db/ops/delete_request.h @@ -39,8 +39,7 @@ namespace mongo { class DeleteRequest { MONGO_DISALLOW_COPYING(DeleteRequest); public: - explicit DeleteRequest(OperationContext* txn, const NamespaceString& nsString) : - _txn(txn), + explicit DeleteRequest(const NamespaceString& nsString) : _nsString(nsString), _multi(false), _logop(false), @@ -64,13 +63,11 @@ namespace mongo { bool isGod() const { return _god; } bool isFromMigrate() const { return _fromMigrate; } bool isExplain() const { return _isExplain; } - OperationContext* getOpCtx() const { return _txn; } PlanExecutor::YieldPolicy getYieldPolicy() const { return _yieldPolicy; } std::string toString() const; private: - OperationContext* _txn; const NamespaceString& _nsString; BSONObj _query; bool _multi; diff --git a/src/mongo/db/ops/update.cpp b/src/mongo/db/ops/update.cpp index ceb8af65297..66f797458eb 100644 --- a/src/mongo/db/ops/update.cpp +++ b/src/mongo/db/ops/update.cpp @@ -50,11 +50,12 @@ namespace mongo { - UpdateResult update(Database* db, + UpdateResult update(OperationContext* txn, + Database* db, const UpdateRequest& request, OpDebug* opDebug) { - UpdateExecutor executor(&request, opDebug); + UpdateExecutor executor(txn, &request, opDebug); return executor.execute(db); } diff --git a/src/mongo/db/ops/update.h b/src/mongo/db/ops/update.h index 801c058a763..c4c5e71edff 100644 --- a/src/mongo/db/ops/update.h +++ b/src/mongo/db/ops/update.h @@ -47,7 +47,8 @@ namespace mongo { * * Caller must hold the appropriate database locks. */ - UpdateResult update(Database* db, + UpdateResult update(OperationContext* txn, + Database* db, const UpdateRequest& request, OpDebug* opDebug); diff --git a/src/mongo/db/ops/update_executor.cpp b/src/mongo/db/ops/update_executor.cpp index 1cb67364364..bd95b062024 100644 --- a/src/mongo/db/ops/update_executor.cpp +++ b/src/mongo/db/ops/update_executor.cpp @@ -69,7 +69,9 @@ namespace mongo { } // namespace - UpdateExecutor::UpdateExecutor(const UpdateRequest* request, OpDebug* opDebug) : + UpdateExecutor::UpdateExecutor(OperationContext* txn, const UpdateRequest* request, + OpDebug* opDebug) : + _txn(txn), _request(request), _opDebug(opDebug), _driver(UpdateDriver::Options()), @@ -117,7 +119,7 @@ namespace mongo { // a no-op which returns a trivial EOF plan. Collection* collection = NULL; if (db) { - collection = db->getCollection(_request->getOpCtx(), nsString.ns()); + collection = db->getCollection(_txn, nsString.ns()); } else { invariant(_request->isExplain()); @@ -128,28 +130,26 @@ namespace mongo { // We can only create the collection if this is not an explain, as explains should not // alter the state of the database. if (!collection && _request->isUpsert() && !_request->isExplain()) { - OperationContext* const txn = _request->getOpCtx(); - // We have to have an exclsive lock on the db to be allowed to create the collection. // Callers should either get an X or create the collection. - const Locker* locker = txn->lockState(); + const Locker* locker = _txn->lockState(); invariant( locker->isW() || locker->isLockHeldForMode( ResourceId( RESOURCE_DATABASE, nsString.db() ), MODE_X ) ); - Lock::DBLock lk(txn->lockState(), nsString.db(), MODE_X); + Lock::DBLock lk(_txn->lockState(), nsString.db(), MODE_X); - WriteUnitOfWork wuow(txn); - invariant(db->createCollection(txn, nsString.ns())); + WriteUnitOfWork wuow(_txn); + invariant(db->createCollection(_txn, nsString.ns())); if (!_request->isFromReplication()) { - repl::logOp(txn, + repl::logOp(_txn, "c", (db->name() + ".$cmd").c_str(), BSON("create" << (nsString.coll()))); } wuow.commit(); - collection = db->getCollection(_request->getOpCtx(), nsString.ns()); + collection = db->getCollection(_txn, nsString.ns()); invariant(collection); } @@ -169,7 +169,7 @@ namespace mongo { if (lifecycle) { lifecycle->setCollection(collection); - _driver.refreshIndexKeys(lifecycle->getIndexKeys(_request->getOpCtx())); + _driver.refreshIndexKeys(lifecycle->getIndexKeys(_txn)); } // If yielding is allowed for this plan, then set an auto yield policy. Otherwise set @@ -187,7 +187,7 @@ namespace mongo { Status getExecStatus = Status::OK(); if (_canonicalQuery.get()) { // This is the regular path for when we have a CanonicalQuery. - getExecStatus = getExecutorUpdate(_request->getOpCtx(), + getExecStatus = getExecutorUpdate(_txn, collection, _canonicalQuery.release(), _request, @@ -199,7 +199,7 @@ namespace mongo { else { // This is the idhack fast-path for getting a PlanExecutor without doing the work // to create a CanonicalQuery. - getExecStatus = getExecutorUpdate(_request->getOpCtx(), + getExecStatus = getExecutorUpdate(_txn, collection, nsString.ns(), _request, @@ -283,8 +283,7 @@ namespace mongo { } CanonicalQuery* cqRaw; - const WhereCallbackReal whereCallback( - _request->getOpCtx(), _request->getNamespaceString().db()); + const WhereCallbackReal whereCallback(_txn, _request->getNamespaceString().db()); Status status = CanonicalQuery::canonicalize(_request->getNamespaceString().ns(), _request->getQuery(), diff --git a/src/mongo/db/ops/update_executor.h b/src/mongo/db/ops/update_executor.h index 9294de770d8..d0ef41083a2 100644 --- a/src/mongo/db/ops/update_executor.h +++ b/src/mongo/db/ops/update_executor.h @@ -54,7 +54,7 @@ namespace mongo { * Expected usage is approximately: * UpdateRequest request(...); * // configure request - * UpdateExecutor executor(&request, opDebug); + * UpdateExecutor executor(txn, &request, opDebug); * uassertStatusOK(executor.prepare()); * // Get locks, get ready to execute. * try { @@ -73,7 +73,7 @@ namespace mongo { * The objects pointed to by "request" and "opDebug" must stay in scope for the life of the * constructed executor. */ - UpdateExecutor(const UpdateRequest* request, OpDebug* opDebug); + UpdateExecutor(OperationContext* txn, const UpdateRequest* request, OpDebug* opDebug); ~UpdateExecutor(); @@ -121,25 +121,28 @@ namespace mongo { */ Status parseUpdate(); - /// Unowned pointer to the request object that this executor will process. + // Transactional context. Not owned by us. + OperationContext* _txn; + + // Unowned pointer to the request object that this executor will process. const UpdateRequest* const _request; - /// Unowned pointer to the opdebug object that this executor will populate with debug data. + // Unowned pointer to the opdebug object that this executor will populate with debug data. OpDebug* const _opDebug; - /// Driver for processing updates on matched documents. + // Driver for processing updates on matched documents. UpdateDriver _driver; - /// Parsed query object, or NULL if the query proves to be an id hack query. + // Parsed query object, or NULL if the query proves to be an id hack query. std::auto_ptr<CanonicalQuery> _canonicalQuery; // The tree of execution stages which will be used to execute the update. boost::scoped_ptr<PlanExecutor> _exec; - /// Flag indicating if the query has been successfully parsed. + // Flag indicating if the query has been successfully parsed. bool _isQueryParsed; - /// Flag indicatin gif the update description has been successfully parsed. + // Flag indicatin gif the update description has been successfully parsed. bool _isUpdateParsed; }; diff --git a/src/mongo/db/ops/update_request.h b/src/mongo/db/ops/update_request.h index 381a012912b..5c2692ca3ed 100644 --- a/src/mongo/db/ops/update_request.h +++ b/src/mongo/db/ops/update_request.h @@ -43,9 +43,8 @@ namespace mongo { class UpdateRequest { public: - inline UpdateRequest(OperationContext* txn, const NamespaceString& nsString) - : _txn(txn) - , _nsString(nsString) + inline UpdateRequest(const NamespaceString& nsString) + : _nsString(nsString) , _god(false) , _upsert(false) , _multi(false) @@ -135,10 +134,6 @@ namespace mongo { return _lifecycle; } - inline OperationContext* getOpCtx() const { - return _txn; - } - inline void setExplain(bool value = true) { _isExplain = value; } @@ -169,9 +164,6 @@ namespace mongo { } private: - // Not owned. Must live as long as the request lives. - OperationContext* _txn; - const NamespaceString& _nsString; // Contains the query that selects documents to update. diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp index 0abc5f5de35..9381dc427ed 100644 --- a/src/mongo/db/query/get_executor.cpp +++ b/src/mongo/db/query/get_executor.cpp @@ -567,7 +567,7 @@ namespace mongo { invariant(root); UpdateStageParams updateStageParams(request, driver, opDebug); updateStageParams.canonicalQuery = rawCanonicalQuery; - root = new UpdateStage(updateStageParams, ws.get(), collection, root); + root = new UpdateStage(txn, updateStageParams, ws.get(), collection, root); // We must have a tree of stages in order to have a valid plan executor, but the query // solution may be null. Takes ownership of all args other than 'collection' and 'txn' return PlanExecutor::make(txn, @@ -598,7 +598,7 @@ namespace mongo { // UpdateStage, so in this case we put an UpdateStage on top of an EOFStage. LOG(2) << "Collection " << ns << " does not exist." << " Using EOF stage: " << unparsedQuery.toString(); - UpdateStage* updateStage = new UpdateStage(updateStageParams, ws.get(), collection, + UpdateStage* updateStage = new UpdateStage(txn, updateStageParams, ws.get(), collection, new EOFStage()); return PlanExecutor::make(txn, ws.release(), updateStage, ns, yieldPolicy, execOut); } @@ -609,7 +609,7 @@ namespace mongo { PlanStage* idHackStage = new IDHackStage(txn, collection, unparsedQuery["_id"].wrap(), ws.get()); - UpdateStage* root = new UpdateStage(updateStageParams, ws.get(), collection, + UpdateStage* root = new UpdateStage(txn, updateStageParams, ws.get(), collection, idHackStage); return PlanExecutor::make(txn, ws.release(), root, collection, yieldPolicy, execOut); } diff --git a/src/mongo/db/repl/master_slave.cpp b/src/mongo/db/repl/master_slave.cpp index 3734b064c72..4aea655198b 100644 --- a/src/mongo/db/repl/master_slave.cpp +++ b/src/mongo/db/repl/master_slave.cpp @@ -204,13 +204,13 @@ namespace repl { Client::Context ctx(txn, "local.sources"); const NamespaceString requestNs("local.sources"); - UpdateRequest request(txn, requestNs); + UpdateRequest request(requestNs); request.setQuery(pattern); request.setUpdates(o); request.setUpsert(); - UpdateResult res = update(ctx.db(), request, &debug); + UpdateResult res = update(txn, ctx.db(), request, &debug); verify( ! res.modifiers ); verify( res.numMatched == 1 ); diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index f6c0ba0da21..d8e44410074 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -622,7 +622,7 @@ namespace repl { Timer t; const NamespaceString requestNs(ns); - UpdateRequest request(txn, requestNs); + UpdateRequest request(requestNs); request.setQuery(o); request.setUpdates(o); @@ -631,7 +631,7 @@ namespace repl { UpdateLifecycleImpl updateLifecycle(true, requestNs); request.setLifecycle(&updateLifecycle); - update(db, request, &debug); + update(txn, db, request, &debug); if( t.millis() >= 2 ) { RARELY OCCASIONALLY log() << "warning, repl doing slow updates (no _id field) for " << ns << endl; @@ -645,7 +645,7 @@ namespace repl { b.append(_id); const NamespaceString requestNs(ns); - UpdateRequest request(txn, requestNs); + UpdateRequest request(requestNs); request.setQuery(b.done()); request.setUpdates(o); @@ -654,7 +654,7 @@ namespace repl { UpdateLifecycleImpl updateLifecycle(true, requestNs); request.setLifecycle(&updateLifecycle); - update(db, request, &debug); + update(txn, db, request, &debug); } } } @@ -666,7 +666,7 @@ namespace repl { const bool upsert = valueB || convertUpdateToUpsert; const NamespaceString requestNs(ns); - UpdateRequest request(txn, requestNs); + UpdateRequest request(requestNs); request.setQuery(updateCriteria); request.setUpdates(o); @@ -675,7 +675,7 @@ namespace repl { UpdateLifecycleImpl updateLifecycle(true, requestNs); request.setLifecycle(&updateLifecycle); - UpdateResult ur = update(db, request, &debug); + UpdateResult ur = update(txn, db, request, &debug); if( ur.numMatched == 0 ) { if( ur.modifiers ) { diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp index 753d8e4116a..424f3108ffe 100644 --- a/src/mongo/db/repl/rs_rollback.cpp +++ b/src/mongo/db/repl/rs_rollback.cpp @@ -663,7 +663,7 @@ namespace { updates++; const NamespaceString requestNs(doc.ns); - UpdateRequest request(txn, requestNs); + UpdateRequest request(requestNs); request.setQuery(pattern); request.setUpdates(it->second); @@ -672,7 +672,7 @@ namespace { UpdateLifecycleImpl updateLifecycle(true, requestNs); request.setLifecycle(&updateLifecycle); - update(ctx.db(), request, &debug); + update(txn, ctx.db(), request, &debug); } } |