diff options
author | Hari Khalsa <hkhalsa@10gen.com> | 2014-08-29 12:49:19 -0400 |
---|---|---|
committer | Hari Khalsa <hkhalsa@10gen.com> | 2014-09-09 12:54:42 -0400 |
commit | da86d5ed4f14dbd05fa713b530759a11ab9b149c (patch) | |
tree | 205f9046cb887e28a4e853275dcf3d63cabbfe76 /src/mongo | |
parent | fe1c74d2656b3609f529842a7c810034671ddea1 (diff) | |
download | mongo-da86d5ed4f14dbd05fa713b530759a11ab9b149c.tar.gz |
SERVER-14668 remove no-OpCtx DBDirectClient and update all former users
Diffstat (limited to 'src/mongo')
25 files changed, 246 insertions, 126 deletions
diff --git a/src/mongo/db/auth/authorization_manager.cpp b/src/mongo/db/auth/authorization_manager.cpp index a8043af6d6e..6946a27bfc3 100644 --- a/src/mongo/db/auth/authorization_manager.cpp +++ b/src/mongo/db/auth/authorization_manager.cpp @@ -299,8 +299,9 @@ namespace mongo { return _externalState->hasAnyPrivilegeDocuments(txn); } - Status AuthorizationManager::writeAuthSchemaVersionIfNeeded() { + Status AuthorizationManager::writeAuthSchemaVersionIfNeeded(OperationContext* txn) { Status status = _externalState->updateOne( + txn, AuthorizationManager::versionCollectionNamespace, AuthorizationManager::versionDocumentQuery, BSON("$set" << BSON(AuthorizationManager::schemaVersionFieldName << @@ -313,28 +314,33 @@ namespace mongo { return status; } - Status AuthorizationManager::insertPrivilegeDocument(const std::string& dbname, + Status AuthorizationManager::insertPrivilegeDocument(OperationContext* txn, + const std::string& dbname, const BSONObj& userObj, const BSONObj& writeConcern) const { - return _externalState->insertPrivilegeDocument(dbname, userObj, writeConcern); + return _externalState->insertPrivilegeDocument(txn, dbname, userObj, writeConcern); } - Status AuthorizationManager::updatePrivilegeDocument(const UserName& user, + Status AuthorizationManager::updatePrivilegeDocument(OperationContext* txn, + const UserName& user, const BSONObj& updateObj, const BSONObj& writeConcern) const { - return _externalState->updatePrivilegeDocument(user, updateObj, writeConcern); + return _externalState->updatePrivilegeDocument(txn, user, updateObj, writeConcern); } - Status AuthorizationManager::removePrivilegeDocuments(const BSONObj& query, + Status AuthorizationManager::removePrivilegeDocuments(OperationContext* txn, + const BSONObj& query, const BSONObj& writeConcern, int* numRemoved) const { - return _externalState->removePrivilegeDocuments(query, writeConcern, numRemoved); + return _externalState->removePrivilegeDocuments(txn, query, writeConcern, numRemoved); } - Status AuthorizationManager::removeRoleDocuments(const BSONObj& query, + Status AuthorizationManager::removeRoleDocuments(OperationContext* txn, + const BSONObj& query, const BSONObj& writeConcern, int* numRemoved) const { - Status status = _externalState->remove(rolesCollectionNamespace, + Status status = _externalState->remove(txn, + rolesCollectionNamespace, query, writeConcern, numRemoved); @@ -344,9 +350,11 @@ namespace mongo { return status; } - Status AuthorizationManager::insertRoleDocument(const BSONObj& roleObj, + Status AuthorizationManager::insertRoleDocument(OperationContext* txn, + const BSONObj& roleObj, const BSONObj& writeConcern) const { - Status status = _externalState->insert(rolesCollectionNamespace, + Status status = _externalState->insert(txn, + rolesCollectionNamespace, roleObj, writeConcern); if (status.isOK()) { @@ -365,10 +373,12 @@ namespace mongo { return status; } - Status AuthorizationManager::updateRoleDocument(const RoleName& role, + Status AuthorizationManager::updateRoleDocument(OperationContext* txn, + const RoleName& role, const BSONObj& updateObj, const BSONObj& writeConcern) const { Status status = _externalState->updateOne( + txn, rolesCollectionNamespace, BSON(AuthorizationManager::ROLE_NAME_FIELD_NAME << role.getRole() << AuthorizationManager::ROLE_DB_FIELD_NAME << role.getDB()), @@ -398,14 +408,16 @@ namespace mongo { return _externalState->query(txn, collectionName, query, projection, resultProcessor); } - Status AuthorizationManager::updateAuthzDocuments(const NamespaceString& collectionName, + Status AuthorizationManager::updateAuthzDocuments(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& query, const BSONObj& updatePattern, bool upsert, bool multi, const BSONObj& writeConcern, int* nMatched) const { - return _externalState->update(collectionName, + return _externalState->update(txn, + collectionName, query, updatePattern, upsert, diff --git a/src/mongo/db/auth/authorization_manager.h b/src/mongo/db/auth/authorization_manager.h index 6962e9d137a..b45712847d0 100644 --- a/src/mongo/db/auth/authorization_manager.h +++ b/src/mongo/db/auth/authorization_manager.h @@ -181,14 +181,15 @@ namespace mongo { * * Do not call if getAuthorizationVersion() reports a value other than schemaVersion26Final. */ - Status writeAuthSchemaVersionIfNeeded(); + Status writeAuthSchemaVersionIfNeeded(OperationContext* txn); /** * Creates the given user object in the given database. * 'writeConcern' contains the arguments to be passed to getLastError to block for * successful completion of the write. */ - Status insertPrivilegeDocument(const std::string& dbname, + Status insertPrivilegeDocument(OperationContext* txn, + const std::string& dbname, const BSONObj& userObj, const BSONObj& writeConcern) const; @@ -197,7 +198,8 @@ namespace mongo { * 'writeConcern' contains the arguments to be passed to getLastError to block for * successful completion of the write. */ - Status updatePrivilegeDocument(const UserName& user, + Status updatePrivilegeDocument(OperationContext* txn, + const UserName& user, const BSONObj& updateObj, const BSONObj& writeConcern) const; @@ -207,7 +209,8 @@ namespace mongo { * 'writeConcern' contains the arguments to be passed to getLastError to block for * successful completion of the write. */ - Status removePrivilegeDocuments(const BSONObj& query, + Status removePrivilegeDocuments(OperationContext* txn, + const BSONObj& query, const BSONObj& writeConcern, int* numRemoved) const; @@ -216,14 +219,17 @@ namespace mongo { * 'writeConcern' contains the arguments to be passed to getLastError to block for * successful completion of the write. */ - Status insertRoleDocument(const BSONObj& roleObj, const BSONObj& writeConcern) const; + Status insertRoleDocument(OperationContext* txn, + const BSONObj& roleObj, + const BSONObj& writeConcern) const; /** * Updates the given role object with the given update modifier. * 'writeConcern' contains the arguments to be passed to getLastError to block for * successful completion of the write. */ - Status updateRoleDocument(const RoleName& role, + Status updateRoleDocument(OperationContext* txn, + const RoleName& role, const BSONObj& updateObj, const BSONObj& writeConcern) const; @@ -232,7 +238,8 @@ namespace mongo { * Should only be called on collections with authorization documents in them * (ie admin.system.users and admin.system.roles). */ - Status updateAuthzDocuments(const NamespaceString& collectionName, + Status updateAuthzDocuments(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& query, const BSONObj& updatePattern, bool upsert, @@ -246,7 +253,8 @@ namespace mongo { * 'writeConcern' contains the arguments to be passed to getLastError to block for * successful completion of the write. */ - Status removeRoleDocuments(const BSONObj& query, + Status removeRoleDocuments(OperationContext* txn, + const BSONObj& query, const BSONObj& writeConcern, int* numRemoved) const; diff --git a/src/mongo/db/auth/authorization_manager_test.cpp b/src/mongo/db/auth/authorization_manager_test.cpp index e230dc1e405..64ca474ec48 100644 --- a/src/mongo/db/auth/authorization_manager_test.cpp +++ b/src/mongo/db/auth/authorization_manager_test.cpp @@ -170,7 +170,10 @@ namespace { TEST_F(AuthorizationManagerTest, testAcquireV2User) { externalState->setAuthzVersion(AuthorizationManager::schemaVersion26Final); + OperationContextNoop txn; + ASSERT_OK(externalState->insertPrivilegeDocument( + &txn, "admin", BSON("_id" << "admin.v2read" << "user" << "v2read" << @@ -179,6 +182,7 @@ namespace { "roles" << BSON_ARRAY(BSON("role" << "read" << "db" << "test"))), BSONObj())); ASSERT_OK(externalState->insertPrivilegeDocument( + &txn, "admin", BSON("_id" << "admin.v2cluster" << "user" << "v2cluster" << @@ -187,8 +191,6 @@ namespace { "roles" << BSON_ARRAY(BSON("role" << "clusterAdmin" << "db" << "admin"))), BSONObj())); - OperationContextNoop txn; - User* v2read; ASSERT_OK(authzManager->acquireUser(&txn, UserName("v2read", "test"), &v2read)); ASSERT_EQUALS(UserName("v2read", "test"), v2read->getName()); diff --git a/src/mongo/db/auth/authorization_session_test.cpp b/src/mongo/db/auth/authorization_session_test.cpp index 8c25e9b6e3d..e0263650651 100644 --- a/src/mongo/db/auth/authorization_session_test.cpp +++ b/src/mongo/db/auth/authorization_session_test.cpp @@ -135,7 +135,8 @@ namespace { authzSession->addAndAuthorizeUser(&_txn, UserName("spencer", "test"))); // Add a user with readWrite and dbAdmin on the test DB - ASSERT_OK(managerState->insertPrivilegeDocument("admin", + ASSERT_OK(managerState->insertPrivilegeDocument(&_txn, + "admin", BSON("user" << "spencer" << "db" << "test" << "credentials" << BSON("MONGODB-CR" << "a") << @@ -154,7 +155,8 @@ namespace { otherFooCollResource, ActionType::insert)); // Add an admin user with readWriteAnyDatabase - ASSERT_OK(managerState->insertPrivilegeDocument("admin", + ASSERT_OK(managerState->insertPrivilegeDocument(&_txn, + "admin", BSON("user" << "admin" << "db" << "admin" << "credentials" << BSON("MONGODB-CR" << "a") << @@ -195,7 +197,8 @@ namespace { TEST_F(AuthorizationSessionTest, DuplicateRolesOK) { // Add a user with doubled-up readWrite and single dbAdmin on the test DB - ASSERT_OK(managerState->insertPrivilegeDocument("admin", + ASSERT_OK(managerState->insertPrivilegeDocument(&_txn, + "admin", BSON("user" << "spencer" << "db" << "test" << "credentials" << BSON("MONGODB-CR" << "a") << @@ -217,7 +220,8 @@ namespace { } TEST_F(AuthorizationSessionTest, SystemCollectionsAccessControl) { - ASSERT_OK(managerState->insertPrivilegeDocument("admin", + ASSERT_OK(managerState->insertPrivilegeDocument(&_txn, + "admin", BSON("user" << "rw" << "db" << "test" << "credentials" << BSON("MONGODB-CR" << "a") << @@ -226,14 +230,16 @@ namespace { BSON("role" << "dbAdmin" << "db" << "test"))), BSONObj())); - ASSERT_OK(managerState->insertPrivilegeDocument("admin", + ASSERT_OK(managerState->insertPrivilegeDocument(&_txn, + "admin", BSON("user" << "useradmin" << "db" << "test" << "credentials" << BSON("MONGODB-CR" << "a") << "roles" << BSON_ARRAY(BSON("role" << "userAdmin" << "db" << "test"))), BSONObj())); - ASSERT_OK(managerState->insertPrivilegeDocument("admin", + ASSERT_OK(managerState->insertPrivilegeDocument(&_txn, + "admin", BSON("user" << "rwany" << "db" << "test" << "credentials" << BSON("MONGODB-CR" << "a") << @@ -242,7 +248,8 @@ namespace { BSON("role" << "dbAdminAnyDatabase" << "db" << "admin"))), BSONObj())); - ASSERT_OK(managerState->insertPrivilegeDocument("admin", + ASSERT_OK(managerState->insertPrivilegeDocument(&_txn, + "admin", BSON("user" << "useradminany" << "db" << "test" << "credentials" << BSON("MONGODB-CR" << "a") << @@ -331,7 +338,8 @@ namespace { TEST_F(AuthorizationSessionTest, InvalidateUser) { // Add a readWrite user - ASSERT_OK(managerState->insertPrivilegeDocument("admin", + ASSERT_OK(managerState->insertPrivilegeDocument(&_txn, + "admin", BSON("user" << "spencer" << "db" << "test" << "credentials" << BSON("MONGODB-CR" << "a") << @@ -351,11 +359,13 @@ namespace { // Change the user to be read-only int ignored; managerState->remove( + &_txn, AuthorizationManager::usersCollectionNamespace, BSONObj(), BSONObj(), &ignored); - ASSERT_OK(managerState->insertPrivilegeDocument("admin", + ASSERT_OK(managerState->insertPrivilegeDocument(&_txn, + "admin", BSON("user" << "spencer" << "db" << "test" << "credentials" << BSON("MONGODB-CR" << "a") << @@ -376,6 +386,7 @@ namespace { // Delete the user. managerState->remove( + &_txn, AuthorizationManager::usersCollectionNamespace, BSONObj(), BSONObj(), @@ -392,7 +403,8 @@ namespace { TEST_F(AuthorizationSessionTest, UseOldUserInfoInFaceOfConnectivityProblems) { // Add a readWrite user - ASSERT_OK(managerState->insertPrivilegeDocument("admin", + ASSERT_OK(managerState->insertPrivilegeDocument(&_txn, + "admin", BSON("user" << "spencer" << "db" << "test" << "credentials" << BSON("MONGODB-CR" << "a") << @@ -413,11 +425,13 @@ namespace { int ignored; managerState->setFindsShouldFail(true); managerState->remove( + &_txn, AuthorizationManager::usersCollectionNamespace, BSONObj(), BSONObj(), &ignored); - ASSERT_OK(managerState->insertPrivilegeDocument("admin", + ASSERT_OK(managerState->insertPrivilegeDocument(&_txn, + "admin", BSON("user" << "spencer" << "db" << "test" << "credentials" << BSON("MONGODB-CR" << "a") << diff --git a/src/mongo/db/auth/authz_manager_external_state.cpp b/src/mongo/db/auth/authz_manager_external_state.cpp index 4b9b3501a11..0520b0df526 100644 --- a/src/mongo/db/auth/authz_manager_external_state.cpp +++ b/src/mongo/db/auth/authz_manager_external_state.cpp @@ -56,10 +56,11 @@ namespace mongo { } - Status AuthzManagerExternalState::insertPrivilegeDocument(const string& dbname, + Status AuthzManagerExternalState::insertPrivilegeDocument(OperationContext* txn, + const string& dbname, const BSONObj& userObj, const BSONObj& writeConcern) { - Status status = insert(NamespaceString("admin.system.users"), userObj, writeConcern); + Status status = insert(txn, NamespaceString("admin.system.users"), userObj, writeConcern); if (status.isOK()) { return status; } @@ -76,9 +77,12 @@ namespace mongo { return status; } - Status AuthzManagerExternalState::updatePrivilegeDocument( - const UserName& user, const BSONObj& updateObj, const BSONObj& writeConcern) { + Status AuthzManagerExternalState::updatePrivilegeDocument(OperationContext* txn, + const UserName& user, + const BSONObj& updateObj, + const BSONObj& writeConcern) { Status status = updateOne( + txn, NamespaceString("admin.system.users"), BSON(AuthorizationManager::USER_NAME_FIELD_NAME << user.getUser() << AuthorizationManager::USER_DB_FIELD_NAME << user.getDB()), @@ -99,10 +103,12 @@ namespace mongo { return status; } - Status AuthzManagerExternalState::removePrivilegeDocuments(const BSONObj& query, + Status AuthzManagerExternalState::removePrivilegeDocuments(OperationContext* txn, + const BSONObj& query, const BSONObj& writeConcern, int* numRemoved) { - Status status = remove(NamespaceString("admin.system.users"), + Status status = remove(txn, + NamespaceString("admin.system.users"), query, writeConcern, numRemoved); @@ -113,13 +119,15 @@ namespace mongo { } Status AuthzManagerExternalState::updateOne( + OperationContext* txn, const NamespaceString& collectionName, const BSONObj& query, const BSONObj& updatePattern, bool upsert, const BSONObj& writeConcern) { int nMatched; - Status status = update(collectionName, + Status status = update(txn, + collectionName, query, updatePattern, upsert, diff --git a/src/mongo/db/auth/authz_manager_external_state.h b/src/mongo/db/auth/authz_manager_external_state.h index 566299fcef0..2483c682e9c 100644 --- a/src/mongo/db/auth/authz_manager_external_state.h +++ b/src/mongo/db/auth/authz_manager_external_state.h @@ -124,14 +124,16 @@ namespace mongo { * * TODO(spencer): remove dbname argument once users are only written into the admin db */ - Status insertPrivilegeDocument(const std::string& dbname, + Status insertPrivilegeDocument(OperationContext* txn, + const std::string& dbname, const BSONObj& userObj, const BSONObj& writeConcern); /** * Updates the given user object with the given update modifier. */ - Status updatePrivilegeDocument(const UserName& user, + Status updatePrivilegeDocument(OperationContext* txn, + const UserName& user, const BSONObj& updateObj, const BSONObj& writeConcern); @@ -139,7 +141,8 @@ namespace mongo { * Removes users for the given database matching the given query. * Writes into *numRemoved the number of user documents that were modified. */ - Status removePrivilegeDocuments(const BSONObj& query, + Status removePrivilegeDocuments(OperationContext* txn, + const BSONObj& query, const BSONObj& writeConcern, int* numRemoved); @@ -176,7 +179,8 @@ namespace mongo { * Inserts "document" into "collectionName". * If there is a duplicate key error, returns a Status with code DuplicateKey. */ - virtual Status insert(const NamespaceString& collectionName, + virtual Status insert(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& document, const BSONObj& writeConcern) = 0; @@ -189,7 +193,8 @@ namespace mongo { * NoMatchingDocument. The Status message in that case is not very descriptive and should * not be displayed to the end user. */ - virtual Status updateOne(const NamespaceString& collectionName, + virtual Status updateOne(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& query, const BSONObj& updatePattern, bool upsert, @@ -198,7 +203,8 @@ namespace mongo { /** * Updates documents matching "query" according to "updatePattern" in "collectionName". */ - virtual Status update(const NamespaceString& collectionName, + virtual Status update(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& query, const BSONObj& updatePattern, bool upsert, @@ -209,7 +215,8 @@ namespace mongo { /** * Removes all documents matching "query" from "collectionName". */ - virtual Status remove(const NamespaceString& collectionName, + virtual Status remove(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& query, const BSONObj& writeConcern, int* numRemoved) = 0; @@ -217,7 +224,8 @@ namespace mongo { /** * Creates an index with the given pattern on "collectionName". */ - virtual Status createIndex(const NamespaceString& collectionName, + virtual Status createIndex(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& pattern, bool unique, const BSONObj& writeConcern) = 0; @@ -225,7 +233,8 @@ namespace mongo { /** * Drops indexes other than the _id index on "collectionName". */ - virtual Status dropIndexes(const NamespaceString& collectionName, + virtual Status dropIndexes(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& writeConcern) = 0; /** diff --git a/src/mongo/db/auth/authz_manager_external_state_d.cpp b/src/mongo/db/auth/authz_manager_external_state_d.cpp index 63c5d9b9409..84798ef6d40 100644 --- a/src/mongo/db/auth/authz_manager_external_state_d.cpp +++ b/src/mongo/db/auth/authz_manager_external_state_d.cpp @@ -133,11 +133,12 @@ namespace mongo { } Status AuthzManagerExternalStateMongod::insert( + OperationContext* txn, const NamespaceString& collectionName, const BSONObj& document, const BSONObj& writeConcern) { try { - DBDirectClient client; + DBDirectClient client(txn); client.insert(collectionName, document); // Handle write concern @@ -159,7 +160,8 @@ namespace mongo { } } - Status AuthzManagerExternalStateMongod::update(const NamespaceString& collectionName, + Status AuthzManagerExternalStateMongod::update(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& query, const BSONObj& updatePattern, bool upsert, @@ -167,7 +169,7 @@ namespace mongo { const BSONObj& writeConcern, int* nMatched) { try { - DBDirectClient client; + DBDirectClient client(txn); client.update(collectionName, query, updatePattern, upsert, multi); // Handle write concern @@ -189,12 +191,13 @@ namespace mongo { } Status AuthzManagerExternalStateMongod::remove( + OperationContext* txn, const NamespaceString& collectionName, const BSONObj& query, const BSONObj& writeConcern, int* numRemoved) { try { - DBDirectClient client; + DBDirectClient client(txn); client.remove(collectionName, query); // Handle write concern @@ -216,11 +219,12 @@ namespace mongo { } Status AuthzManagerExternalStateMongod::createIndex( + OperationContext* txn, const NamespaceString& collectionName, const BSONObj& pattern, bool unique, const BSONObj& writeConcern) { - DBDirectClient client; + DBDirectClient client(txn); try { if (client.ensureIndex(collectionName.ns(), pattern, @@ -243,9 +247,10 @@ namespace mongo { } Status AuthzManagerExternalStateMongod::dropIndexes( + OperationContext* txn, const NamespaceString& collectionName, const BSONObj& writeConcern) { - DBDirectClient client; + DBDirectClient client(txn); try { client.dropIndexes(collectionName.ns()); BSONObjBuilder gleBuilder; diff --git a/src/mongo/db/auth/authz_manager_external_state_d.h b/src/mongo/db/auth/authz_manager_external_state_d.h index 551bbba0850..613d4632ebb 100644 --- a/src/mongo/db/auth/authz_manager_external_state_d.h +++ b/src/mongo/db/auth/authz_manager_external_state_d.h @@ -62,25 +62,30 @@ namespace mongo { const BSONObj& query, const BSONObj& projection, const stdx::function<void(const BSONObj&)>& resultProcessor); - virtual Status insert(const NamespaceString& collectionName, + virtual Status insert(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& document, const BSONObj& writeConcern); - virtual Status update(const NamespaceString& collectionName, + virtual Status update(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& query, const BSONObj& updatePattern, bool upsert, bool multi, const BSONObj& writeConcern, int* nMatched); - virtual Status remove(const NamespaceString& collectionName, + virtual Status remove(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& query, const BSONObj& writeConcern, int* numRemoved); - virtual Status createIndex(const NamespaceString& collectionName, + virtual Status createIndex(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& pattern, bool unique, const BSONObj& writeConcern); - virtual Status dropIndexes(const NamespaceString& collectionName, + virtual Status dropIndexes(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& writeConcern); virtual bool tryAcquireAuthzUpdateLock(const StringData& why); virtual void releaseAuthzUpdateLock(); diff --git a/src/mongo/db/auth/authz_manager_external_state_mock.cpp b/src/mongo/db/auth/authz_manager_external_state_mock.cpp index 91a92519cf5..1c41763072c 100644 --- a/src/mongo/db/auth/authz_manager_external_state_mock.cpp +++ b/src/mongo/db/auth/authz_manager_external_state_mock.cpp @@ -38,6 +38,7 @@ #include "mongo/db/jsobj.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/namespace_string.h" +#include "mongo/db/operation_context_noop.h" #include "mongo/db/ops/update_driver.h" #include "mongo/platform/unordered_set.h" #include "mongo/util/map_util.h" @@ -88,8 +89,10 @@ namespace { } void AuthzManagerExternalStateMock::setAuthzVersion(int version) { + OperationContextNoop opCtx; uassertStatusOK( - updateOne(AuthorizationManager::versionCollectionNamespace, + updateOne(&opCtx, + AuthorizationManager::versionCollectionNamespace, AuthorizationManager::versionDocumentQuery, BSON("$set" << BSON(AuthorizationManager::schemaVersionFieldName << version)), @@ -179,6 +182,7 @@ namespace { } Status AuthzManagerExternalStateMock::insert( + OperationContext* txn, const NamespaceString& collectionName, const BSONObj& document, const BSONObj&) { @@ -205,6 +209,7 @@ namespace { } Status AuthzManagerExternalStateMock::updateOne( + OperationContext* txn, const NamespaceString& collectionName, const BSONObj& query, const BSONObj& updatePattern, @@ -252,14 +257,15 @@ namespace { if (!status.isOK()) { return status; } - return insert(collectionName, document.getObject(), writeConcern); + return insert(txn, collectionName, document.getObject(), writeConcern); } else { return status; } } - Status AuthzManagerExternalStateMock::update(const NamespaceString& collectionName, + Status AuthzManagerExternalStateMock::update(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& query, const BSONObj& updatePattern, bool upsert, @@ -271,6 +277,7 @@ namespace { } Status AuthzManagerExternalStateMock::remove( + OperationContext* txn, const NamespaceString& collectionName, const BSONObj& query, const BSONObj&, @@ -295,6 +302,7 @@ namespace { } Status AuthzManagerExternalStateMock::createIndex( + OperationContext* txn, const NamespaceString& collectionName, const BSONObj& pattern, bool unique, @@ -303,6 +311,7 @@ namespace { } Status AuthzManagerExternalStateMock::dropIndexes( + OperationContext* txn, const NamespaceString& collectionName, const BSONObj& writeConcern) { return Status::OK(); diff --git a/src/mongo/db/auth/authz_manager_external_state_mock.h b/src/mongo/db/auth/authz_manager_external_state_mock.h index 9078ed253db..6621698ab93 100644 --- a/src/mongo/db/auth/authz_manager_external_state_mock.h +++ b/src/mongo/db/auth/authz_manager_external_state_mock.h @@ -73,33 +73,39 @@ namespace mongo { const stdx::function<void(const BSONObj&)>& resultProcessor); // This implementation does not understand uniqueness constraints. - virtual Status insert(const NamespaceString& collectionName, + virtual Status insert(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& document, const BSONObj& writeConcern); // This implementation does not understand uniqueness constraints, ignores writeConcern, // and only correctly handles some upsert behaviors. - virtual Status updateOne(const NamespaceString& collectionName, + virtual Status updateOne(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& query, const BSONObj& updatePattern, bool upsert, const BSONObj& writeConcern); - virtual Status update(const NamespaceString& collectionName, + virtual Status update(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& query, const BSONObj& updatePattern, bool upsert, bool multi, const BSONObj& writeConcern, int* nMatched); - virtual Status remove(const NamespaceString& collectionName, + virtual Status remove(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& query, const BSONObj& writeConcern, int* numRemoved); - virtual Status createIndex(const NamespaceString& collectionName, + virtual Status createIndex(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& pattern, bool unique, const BSONObj& writeConcern); - virtual Status dropIndexes(const NamespaceString& collectionName, + virtual Status dropIndexes(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& writeConcern); virtual bool tryAcquireAuthzUpdateLock(const StringData& why); virtual void releaseAuthzUpdateLock(); diff --git a/src/mongo/db/auth/authz_manager_external_state_s.cpp b/src/mongo/db/auth/authz_manager_external_state_s.cpp index b6cdf8ed6d3..cc2fdb5a83d 100644 --- a/src/mongo/db/auth/authz_manager_external_state_s.cpp +++ b/src/mongo/db/auth/authz_manager_external_state_s.cpp @@ -254,13 +254,15 @@ namespace mongo { } Status AuthzManagerExternalStateMongos::insert( + OperationContext* txn, const NamespaceString& collectionName, const BSONObj& document, const BSONObj& writeConcern) { return clusterInsert(collectionName, document, writeConcern, NULL); } - Status AuthzManagerExternalStateMongos::update(const NamespaceString& collectionName, + Status AuthzManagerExternalStateMongos::update(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& query, const BSONObj& updatePattern, bool upsert, @@ -284,6 +286,7 @@ namespace mongo { } Status AuthzManagerExternalStateMongos::remove( + OperationContext* txn, const NamespaceString& collectionName, const BSONObj& query, const BSONObj& writeConcern, @@ -299,6 +302,7 @@ namespace mongo { } Status AuthzManagerExternalStateMongos::createIndex( + OperationContext* txn, const NamespaceString& collectionName, const BSONObj& pattern, bool unique, @@ -307,6 +311,7 @@ namespace mongo { } Status AuthzManagerExternalStateMongos::dropIndexes( + OperationContext* txn, const NamespaceString& collectionName, const BSONObj& writeConcern) { diff --git a/src/mongo/db/auth/authz_manager_external_state_s.h b/src/mongo/db/auth/authz_manager_external_state_s.h index 785c940131c..333b8cac917 100644 --- a/src/mongo/db/auth/authz_manager_external_state_s.h +++ b/src/mongo/db/auth/authz_manager_external_state_s.h @@ -90,25 +90,30 @@ namespace mongo { const BSONObj& projection, const stdx::function<void(const BSONObj&)>& resultProcessor); - virtual Status insert(const NamespaceString& collectionName, + virtual Status insert(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& document, const BSONObj& writeConcern); - virtual Status update(const NamespaceString& collectionName, + virtual Status update(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& query, const BSONObj& updatePattern, bool upsert, bool multi, const BSONObj& writeConcern, int* nMatched); - virtual Status remove(const NamespaceString& collectionName, + virtual Status remove(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& query, const BSONObj& writeConcern, int* numRemoved); - virtual Status createIndex(const NamespaceString& collectionName, + virtual Status createIndex(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& pattern, bool unique, const BSONObj& writeConcern); - virtual Status dropIndexes(const NamespaceString& collectionName, + virtual Status dropIndexes(OperationContext* txn, + const NamespaceString& collectionName, const BSONObj& writeConcern); virtual bool tryAcquireAuthzUpdateLock(const StringData& why); virtual void releaseAuthzUpdateLock(); diff --git a/src/mongo/db/clientcursor.h b/src/mongo/db/clientcursor.h index 6e8fb2e1219..6eaafd7d8d1 100644 --- a/src/mongo/db/clientcursor.h +++ b/src/mongo/db/clientcursor.h @@ -57,9 +57,17 @@ namespace mongo { */ class ClientCursor : private boost::noncopyable { public: - ClientCursor(const Collection* collection, PlanExecutor* exec, - int qopts = 0, const BSONObj query = BSONObj()); + /** + * This ClientCursor constructor creates a cursorid that can be getMore'd + */ + ClientCursor(const Collection* collection, + PlanExecutor* exec, + int qopts = 0, + const BSONObj query = BSONObj()); + /** + * This ClientCursor is used to track sharding state. + */ ClientCursor(const Collection* collection); ~ClientCursor(); diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp index 9cae565ccd5..62adcc9c4fe 100644 --- a/src/mongo/db/commands/user_management_commands.cpp +++ b/src/mongo/db/commands/user_management_commands.cpp @@ -285,7 +285,7 @@ namespace mongo { "schema version " << AuthorizationManager::schemaVersion26Final << " but found " << foundSchemaVersion); } - return authzManager->writeAuthSchemaVersionIfNeeded(); + return authzManager->writeAuthSchemaVersionIfNeeded(txn); } static Status requireAuthSchemaVersion26UpgradeOrFinal(OperationContext* txn, @@ -481,7 +481,8 @@ namespace mongo { args.hasHashedPassword, args.hasCustomData? &args.customData : NULL, args.roles); - status = authzManager->insertPrivilegeDocument(dbname, + status = authzManager->insertPrivilegeDocument(txn, + dbname, userObj, args.writeConcern); return appendCommandStatus(result, status); @@ -637,7 +638,8 @@ namespace mongo { args.hasCustomData? &args.customData : NULL, args.hasRoles? &args.roles : NULL); - status = authzManager->updatePrivilegeDocument(args.userName, + status = authzManager->updatePrivilegeDocument(txn, + args.userName, BSON("$set" << updateSetBuilder.done()), args.writeConcern); // Must invalidate even on bad status - what if the write succeeded but the GLE failed? @@ -724,6 +726,7 @@ namespace mongo { audit::logDropUser(ClientBasic::getCurrent(), userName); status = authzManager->removePrivilegeDocuments( + txn, BSON(AuthorizationManager::USER_NAME_FIELD_NAME << userName.getUser() << AuthorizationManager::USER_DB_FIELD_NAME << userName.getDB()), writeConcern, @@ -807,6 +810,7 @@ namespace mongo { audit::logDropAllUsersFromDatabase(ClientBasic::getCurrent(), dbname); status = authzManager->removePrivilegeDocuments( + txn, BSON(AuthorizationManager::USER_DB_FIELD_NAME << dbname), writeConcern, &numRemoved); @@ -912,7 +916,7 @@ namespace mongo { roles); BSONArray newRolesBSONArray = roleSetToBSONArray(userRoles); status = authzManager->updatePrivilegeDocument( - userName, BSON("$set" << BSON("roles" << newRolesBSONArray)), writeConcern); + txn, userName, BSON("$set" << BSON("roles" << newRolesBSONArray)), writeConcern); // Must invalidate even on bad status - what if the write succeeded but the GLE failed? authzManager->invalidateUserByName(userName); return appendCommandStatus(result, status); @@ -1010,7 +1014,7 @@ namespace mongo { roles); BSONArray newRolesBSONArray = roleSetToBSONArray(userRoles); status = authzManager->updatePrivilegeDocument( - userName, BSON("$set" << BSON("roles" << newRolesBSONArray)), writeConcern); + txn, userName, BSON("$set" << BSON("roles" << newRolesBSONArray)), writeConcern); // Must invalidate even on bad status - what if the write succeeded but the GLE failed? authzManager->invalidateUserByName(userName); return appendCommandStatus(result, status); @@ -1310,7 +1314,7 @@ namespace mongo { args.roles, args.privileges); - status = authzManager->insertRoleDocument(roleObjBuilder.done(), args.writeConcern); + status = authzManager->insertRoleDocument(txn, roleObjBuilder.done(), args.writeConcern); return appendCommandStatus(result, status); } @@ -1437,7 +1441,8 @@ namespace mongo { args.hasRoles? &args.roles : NULL, args.hasPrivileges? &args.privileges : NULL); - status = authzManager->updateRoleDocument(args.roleName, + status = authzManager->updateRoleDocument(txn, + args.roleName, BSON("$set" << updateSetBuilder.done()), args.writeConcern); // Must invalidate even on bad status - what if the write succeeded but the GLE failed? @@ -1572,6 +1577,7 @@ namespace mongo { privilegesToAdd); status = authzManager->updateRoleDocument( + txn, roleName, updateBSONBuilder.done(), writeConcern); @@ -1710,6 +1716,7 @@ namespace mongo { BSONObjBuilder updateBSONBuilder; updateObj.writeTo(&updateBSONBuilder); status = authzManager->updateRoleDocument( + txn, roleName, updateBSONBuilder.done(), writeConcern); @@ -1829,6 +1836,7 @@ namespace mongo { rolesToAdd); status = authzManager->updateRoleDocument( + txn, roleName, BSON("$set" << BSON("roles" << rolesVectorToBSONArray(directRoles))), writeConcern); @@ -1942,6 +1950,7 @@ namespace mongo { rolesToRemove); status = authzManager->updateRoleDocument( + txn, roleName, BSON("$set" << BSON("roles" << rolesVectorToBSONArray(roles))), writeConcern); @@ -2039,6 +2048,7 @@ namespace mongo { // Remove this role from all users int nMatched; status = authzManager->updateAuthzDocuments( + txn, NamespaceString("admin.system.users"), BSON("roles" << BSON("$elemMatch" << BSON(AuthorizationManager::ROLE_NAME_FIELD_NAME << @@ -2068,6 +2078,7 @@ namespace mongo { // Remove this role from all other roles status = authzManager->updateAuthzDocuments( + txn, NamespaceString("admin.system.roles"), BSON("roles" << BSON("$elemMatch" << BSON(AuthorizationManager::ROLE_NAME_FIELD_NAME << @@ -2100,6 +2111,7 @@ namespace mongo { roleName); // Finally, remove the actual role document status = authzManager->removeRoleDocuments( + txn, BSON(AuthorizationManager::ROLE_NAME_FIELD_NAME << roleName.getRole() << AuthorizationManager::ROLE_DB_FIELD_NAME << roleName.getDB()), writeConcern, @@ -2191,6 +2203,7 @@ namespace mongo { // Remove these roles from all users int nMatched; status = authzManager->updateAuthzDocuments( + txn, AuthorizationManager::usersCollectionNamespace, BSON("roles" << BSON(AuthorizationManager::ROLE_DB_FIELD_NAME << dbname)), BSON("$pull" << BSON("roles" << @@ -2216,6 +2229,7 @@ namespace mongo { std::string sourceFieldName = str::stream() << "roles." << AuthorizationManager::ROLE_DB_FIELD_NAME; status = authzManager->updateAuthzDocuments( + txn, AuthorizationManager::rolesCollectionNamespace, BSON(sourceFieldName << dbname), BSON("$pull" << BSON("roles" << @@ -2240,6 +2254,7 @@ namespace mongo { audit::logDropAllRolesFromDatabase(ClientBasic::getCurrent(), dbname); // Finally, remove the actual role documents status = authzManager->removeRoleDocuments( + txn, BSON(AuthorizationManager::ROLE_DB_FIELD_NAME << dbname), writeConcern, &nMatched); @@ -2638,7 +2653,8 @@ namespace mongo { * admin.system.users collection. * Also removes any users it encounters from the usersToDrop set. */ - static void addUser(AuthorizationManager* authzManager, + static void addUser(OperationContext* txn, + AuthorizationManager* authzManager, const StringData& db, bool update, const BSONObj& writeConcern, @@ -2651,7 +2667,8 @@ namespace mongo { if (update && usersToDrop->count(userName)) { auditCreateOrUpdateUser(userObj, false); - Status status = authzManager->updatePrivilegeDocument(userName, + Status status = authzManager->updatePrivilegeDocument(txn, + userName, userObj, writeConcern); if (!status.isOK()) { @@ -2661,7 +2678,8 @@ namespace mongo { } } else { auditCreateOrUpdateUser(userObj, true); - Status status = authzManager->insertPrivilegeDocument(userName.getDB().toString(), + Status status = authzManager->insertPrivilegeDocument(txn, + userName.getDB().toString(), userObj, writeConcern); if (!status.isOK()) { @@ -2680,7 +2698,8 @@ namespace mongo { * admin.system.roles collection. * Also removes any roles it encounters from the rolesToDrop set. */ - static void addRole(AuthorizationManager* authzManager, + static void addRole(OperationContext* txn, + AuthorizationManager* authzManager, const StringData& db, bool update, const BSONObj& writeConcern, @@ -2693,7 +2712,8 @@ namespace mongo { if (update && rolesToDrop->count(roleName)) { auditCreateOrUpdateRole(roleObj, false); - Status status = authzManager->updateRoleDocument(roleName, + Status status = authzManager->updateRoleDocument(txn, + roleName, roleObj, writeConcern); if (!status.isOK()) { @@ -2703,7 +2723,7 @@ namespace mongo { } } else { auditCreateOrUpdateRole(roleObj, true); - Status status = authzManager->insertRoleDocument(roleObj, writeConcern); + Status status = authzManager->insertRoleDocument(txn, roleObj, writeConcern); if (!status.isOK()) { // Match the behavior of mongorestore to continue on failure warning() << "Could not insert role " << roleName << @@ -2760,6 +2780,7 @@ namespace mongo { db.empty() ? BSONObj() : BSON(AuthorizationManager::USER_DB_FIELD_NAME << db), BSONObj(), stdx::bind(&CmdMergeAuthzCollections::addUser, + txn, authzManager, db, drop, @@ -2777,6 +2798,7 @@ namespace mongo { const UserName& userName = *it; audit::logDropUser(ClientBasic::getCurrent(), userName); status = authzManager->removePrivilegeDocuments( + txn, BSON(AuthorizationManager::USER_NAME_FIELD_NAME << userName.getUser().toString() << AuthorizationManager::USER_DB_FIELD_NAME << @@ -2841,6 +2863,7 @@ namespace mongo { BSONObj() : BSON(AuthorizationManager::ROLE_DB_FIELD_NAME << db), BSONObj(), stdx::bind(&CmdMergeAuthzCollections::addRole, + txn, authzManager, db, drop, @@ -2858,6 +2881,7 @@ namespace mongo { const RoleName& roleName = *it; audit::logDropRole(ClientBasic::getCurrent(), roleName); status = authzManager->removeRoleDocuments( + txn, BSON(AuthorizationManager::ROLE_NAME_FIELD_NAME << roleName.getRole().toString() << AuthorizationManager::ROLE_DB_FIELD_NAME << diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp index 3f47051c03d..3495644750f 100644 --- a/src/mongo/db/instance.cpp +++ b/src/mongo/db/instance.cpp @@ -921,11 +921,6 @@ namespace mongo { } } - DBDirectClient::DBDirectClient() - : _txnOwned(new OperationContextImpl), - _txn(_txnOwned.get()) - {} - DBDirectClient::DBDirectClient(OperationContext* txn) : _txn(txn) {} diff --git a/src/mongo/db/instance.h b/src/mongo/db/instance.h index 238f580c37b..d95f3b710f7 100644 --- a/src/mongo/db/instance.h +++ b/src/mongo/db/instance.h @@ -88,7 +88,6 @@ namespace mongo { public: static const HostAndPort dummyHost; - DBDirectClient(); // DEPRECATED DBDirectClient(OperationContext* txn); void setOpCtx(OperationContext* txn) { _txn = txn; }; @@ -136,8 +135,7 @@ namespace mongo { virtual QueryOptions _lookupAvailableOptions(); private: - boost::scoped_ptr<OperationContext> _txnOwned; - OperationContext* _txn; // Points either to _txnOwned or a passed-in transaction. + OperationContext* _txn; }; void maybeCreatePidFile(); diff --git a/src/mongo/db/repl/repl_coordinator_legacy.cpp b/src/mongo/db/repl/repl_coordinator_legacy.cpp index c9b43d80d91..beb7621366c 100644 --- a/src/mongo/db/repl/repl_coordinator_legacy.cpp +++ b/src/mongo/db/repl/repl_coordinator_legacy.cpp @@ -647,7 +647,7 @@ namespace { } - scoped_ptr<ReplSetConfig> newConfig(ReplSetConfig::make(args.newConfigObj, args.force)); + scoped_ptr<ReplSetConfig> newConfig(ReplSetConfig::make(txn, args.newConfigObj, args.force)); log() << "replSet replSetReconfig config object parses ok, " << newConfig->members.size() << " members specified" << rsLog; @@ -727,7 +727,7 @@ namespace { scoped_ptr<ReplSetConfig> newConfig; try { - newConfig.reset(ReplSetConfig::make(configObj)); + newConfig.reset(ReplSetConfig::make(txn, configObj)); } catch (const DBException& e) { log() << "replSet replSetInitiate exception: " << e.what() << rsLog; return Status(ErrorCodes::InvalidReplicaSetConfig, diff --git a/src/mongo/db/repl/repl_set_impl.cpp b/src/mongo/db/repl/repl_set_impl.cpp index 3271a5a7100..ce5b0310832 100644 --- a/src/mongo/db/repl/repl_set_impl.cpp +++ b/src/mongo/db/repl/repl_set_impl.cpp @@ -766,7 +766,7 @@ namespace { try { OwnedPointerVector<ReplSetConfig> configs; try { - configs.mutableVector().push_back(ReplSetConfig::makeDirect()); + configs.mutableVector().push_back(ReplSetConfig::makeDirect(txn)); } catch (DBException& e) { log() << "replSet exception loading our local replset configuration object : " @@ -776,7 +776,7 @@ namespace { i != _seeds->end(); i++) { try { - configs.mutableVector().push_back(ReplSetConfig::make(*i)); + configs.mutableVector().push_back(ReplSetConfig::make(txn, *i)); } catch (DBException& e) { log() << "replSet exception trying to load config from " << *i @@ -792,7 +792,7 @@ namespace { i++) { try { configs.mutableVector().push_back( - ReplSetConfig::make(HostAndPort(*i))); + ReplSetConfig::make(txn, HostAndPort(*i))); } catch (DBException&) { LOG(1) << "replSet exception trying to load config from discovered " @@ -805,7 +805,7 @@ namespace { if (!replSettings.reconfig.isEmpty()) { try { - configs.mutableVector().push_back(ReplSetConfig::make(replSettings.reconfig, + configs.mutableVector().push_back(ReplSetConfig::make(txn, replSettings.reconfig, true)); } catch (DBException& re) { diff --git a/src/mongo/db/repl/rs.cpp b/src/mongo/db/repl/rs.cpp index d9e0a519b16..81bddf34548 100644 --- a/src/mongo/db/repl/rs.cpp +++ b/src/mongo/db/repl/rs.cpp @@ -102,7 +102,7 @@ namespace repl { OperationContextImpl txn; log() << "replset msgReceivedNewConfig version: " << o["version"].toString() << rsLog; - scoped_ptr<ReplSetConfig> config(ReplSetConfig::make(o)); + scoped_ptr<ReplSetConfig> config(ReplSetConfig::make(&txn, o)); if( config->version > rs->config().version ) theReplSet->haveNewConfig(&txn, *config, false); else { diff --git a/src/mongo/db/repl/rs_config.cpp b/src/mongo/db/repl/rs_config.cpp index 0f6cd20e48e..ed7aaef0290 100644 --- a/src/mongo/db/repl/rs_config.cpp +++ b/src/mongo/db/repl/rs_config.cpp @@ -616,13 +616,13 @@ namespace { _heartbeatTimeout(DEFAULT_HB_TIMEOUT) { } - ReplSetConfig* ReplSetConfig::make(BSONObj cfg, bool force) { + ReplSetConfig* ReplSetConfig::make(OperationContext* txn, BSONObj cfg, bool force) { auto_ptr<ReplSetConfig> ret(new ReplSetConfig()); - ret->init(cfg, force); + ret->init(txn, cfg, force); return ret.release(); } - void ReplSetConfig::init(BSONObj cfg, bool force) { + void ReplSetConfig::init(OperationContext* txn, BSONObj cfg, bool force) { clear(); from(cfg); if( force ) { @@ -634,14 +634,14 @@ namespace { _ok = true; } - ReplSetConfig* ReplSetConfig::make(const HostAndPort& h) { + ReplSetConfig* ReplSetConfig::make(OperationContext* txn, const HostAndPort& h) { auto_ptr<ReplSetConfig> ret(new ReplSetConfig()); - ret->init(h); + ret->init(txn, h); return ret.release(); } - ReplSetConfig* ReplSetConfig::makeDirect() { - DBDirectClient cli; + ReplSetConfig* ReplSetConfig::makeDirect(OperationContext* txn) { + DBDirectClient cli(txn); BSONObj config = cli.findOne(rsConfigNs, Query()).getOwned(); // Check for no local config @@ -649,10 +649,10 @@ namespace { return new ReplSetConfig(); } - return make(config, false); + return make(txn, config, false); } - void ReplSetConfig::init(const HostAndPort& h) { + void ReplSetConfig::init(OperationContext* txn, const HostAndPort& h) { LOG(2) << "ReplSetConfig load " << h.toString() << rsLog; clear(); @@ -706,7 +706,7 @@ namespace { } // on startup, socket is not listening yet - DBDirectClient cli; + DBDirectClient cli(txn); cfg = cli.findOne( rsConfigNs, Query() ).getOwned(); count = cli.count(rsConfigNs); } diff --git a/src/mongo/db/repl/rs_config.h b/src/mongo/db/repl/rs_config.h index b46668ba939..3e33277dd8a 100644 --- a/src/mongo/db/repl/rs_config.h +++ b/src/mongo/db/repl/rs_config.h @@ -62,15 +62,15 @@ namespace repl { * reasons.) If something is misconfigured, throws an exception. If the * host couldn't be queried or is just blank, ok() will be false. */ - static ReplSetConfig* make(const HostAndPort& h); + static ReplSetConfig* make(OperationContext* txn, const HostAndPort& h); - static ReplSetConfig* make(BSONObj cfg, bool force=false); + static ReplSetConfig* make(OperationContext* txn, BSONObj cfg, bool force=false); /** * This uses DBDirectClient to check itself for a config. This way we don't need to connect * to ourselves over the network to fetch our own config. */ - static ReplSetConfig* makeDirect(); + static ReplSetConfig* makeDirect(OperationContext* txn); bool ok() const { return _ok; } @@ -195,8 +195,8 @@ namespace repl { private: ReplSetConfig(); - void init(const HostAndPort& h); - void init(BSONObj cfg, bool force); + void init(OperationContext* txn, const HostAndPort& h); + void init(OperationContext* txn, BSONObj cfg, bool force); /** * If replication can be chained. If chaining is disallowed, it can still be explicitly diff --git a/src/mongo/dbtests/config_server_fixture.h b/src/mongo/dbtests/config_server_fixture.h index 9f61d8ba30c..abb03cc7165 100644 --- a/src/mongo/dbtests/config_server_fixture.h +++ b/src/mongo/dbtests/config_server_fixture.h @@ -29,6 +29,7 @@ #pragma once #include "mongo/db/instance.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/wire_version.h" #include "mongo/client/dbclientinterface.h" #include "mongo/unittest/unittest.h" @@ -40,7 +41,7 @@ namespace mongo { class CustomDirectClient: public DBDirectClient { public: - CustomDirectClient() { + CustomDirectClient() : DBDirectClient(&_txn) { setWireVersions(minWireVersion, maxWireVersion); } @@ -70,6 +71,8 @@ namespace mongo { return true; } + + OperationContextImpl _txn; }; class CustomConnectHook: public ConnectionString::ConnectionHook { diff --git a/src/mongo/dbtests/merge_chunk_tests.cpp b/src/mongo/dbtests/merge_chunk_tests.cpp index aeab04a30d7..a9bceb016e5 100644 --- a/src/mongo/dbtests/merge_chunk_tests.cpp +++ b/src/mongo/dbtests/merge_chunk_tests.cpp @@ -124,6 +124,8 @@ namespace mongo { protected: + OperationContextImpl _txn; + virtual void setUp() { ConfigServerFixture::setUp(); shardingState.initialize( configSvr().toString() ); @@ -134,8 +136,6 @@ namespace mongo { shardingState.resetShardingState(); ConfigServerFixture::tearDown(); } - - OperationContextImpl _txn; }; // diff --git a/src/mongo/tools/tool.cpp b/src/mongo/tools/tool.cpp index 045d830d77c..07abc3069b9 100644 --- a/src/mongo/tools/tool.cpp +++ b/src/mongo/tools/tool.cpp @@ -46,6 +46,7 @@ #include "mongo/db/global_environment_experiment.h" #include "mongo/db/global_environment_d.h" #include "mongo/db/json.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/repl/repl_coordinator_global.h" #include "mongo/db/repl/repl_coordinator_mock.h" #include "mongo/db/storage_options.h" @@ -147,7 +148,8 @@ namespace mongo { ::_exit(EXIT_FAILURE); } - _conn = new DBDirectClient(); + _txn.reset(new OperationContextImpl()); + _conn = new DBDirectClient(_txn.get()); } int ret = -1; diff --git a/src/mongo/tools/tool.h b/src/mongo/tools/tool.h index c63188e40d5..235d2b46aab 100644 --- a/src/mongo/tools/tool.h +++ b/src/mongo/tools/tool.h @@ -83,6 +83,8 @@ namespace mongo { mongo::DBClientBase * _conn; mongo::DBClientBase * _slaveConn; + scoped_ptr<OperationContext> _txn; + private: void auth(); }; |