diff options
author | Ian Whalen <ian.whalen@gmail.com> | 2017-09-22 16:10:50 -0400 |
---|---|---|
committer | Ian Whalen <ian.whalen@gmail.com> | 2017-09-22 16:10:50 -0400 |
commit | ab7ceed2108a7d19518490929b03fa6f4a13257c (patch) | |
tree | a46f487d592c62089f3e58d236e29f843c802b21 /src/mongo/db/system_index.cpp | |
parent | c4b90fe5509eb70e4009e0d7ddbd71b4b92d0274 (diff) | |
download | mongo-ab7ceed2108a7d19518490929b03fa6f4a13257c.tar.gz |
Revert "SERVER-31174 Move the sessions collection to config.system.sessions"
This reverts commit ba1704f7cbc0b9a03a181df145f75f433a59b7df.
Diffstat (limited to 'src/mongo/db/system_index.cpp')
-rw-r--r-- | src/mongo/db/system_index.cpp | 128 |
1 files changed, 58 insertions, 70 deletions
diff --git a/src/mongo/db/system_index.cpp b/src/mongo/db/system_index.cpp index be95f1d0758..0c07a4e46ad 100644 --- a/src/mongo/db/system_index.cpp +++ b/src/mongo/db/system_index.cpp @@ -67,7 +67,7 @@ IndexSpec v3SystemUsersIndexSpec; IndexSpec v3SystemRolesIndexSpec; IndexSpec v1SystemSessionsIndexSpec; -const NamespaceString sessionCollectionNamespace("config.system.sessions"); +const NamespaceString sessionCollectionNamespace("admin.system.sessions"); MONGO_INITIALIZER(AuthIndexKeyPatterns)(InitializerContext*) { v1SystemUsersKeyPattern = BSON("user" << 1 << "userSource" << 1); @@ -145,84 +145,72 @@ Status verifySystemIndexes(OperationContext* opCtx) { const NamespaceString& systemUsers = AuthorizationManager::usersCollectionNamespace; const NamespaceString& systemRoles = AuthorizationManager::rolesCollectionNamespace; - // Create indexes for collections on the admin db - { - AutoGetDb autoDb(opCtx, systemUsers.db(), MODE_X); - if (!autoDb.getDb()) { - return Status::OK(); - } - - Collection* collection = autoDb.getDb()->getCollection(opCtx, systemUsers); - if (collection) { - IndexCatalog* indexCatalog = collection->getIndexCatalog(); - invariant(indexCatalog); - - // Make sure the old unique index from v2.4 on system.users doesn't exist. - std::vector<IndexDescriptor*> indexes; - indexCatalog->findIndexesByKeyPattern(opCtx, v1SystemUsersKeyPattern, false, &indexes); - - if (!indexes.empty()) { - fassert(ErrorCodes::AmbiguousIndexKeyPattern, indexes.size() == 1); - return Status(ErrorCodes::AuthSchemaIncompatible, - "Old 2.4 style user index identified. " - "The authentication schema needs to be updated by " - "running authSchemaUpgrade on a 2.6 server."); - } + AutoGetDb autoDb(opCtx, systemUsers.db(), MODE_X); + if (!autoDb.getDb()) { + return Status::OK(); + } - // Ensure that system indexes exist for the user collection - indexCatalog->findIndexesByKeyPattern(opCtx, v3SystemUsersKeyPattern, false, &indexes); - if (indexes.empty()) { - try { - generateSystemIndexForExistingCollection( - opCtx, collection, systemUsers, v3SystemUsersIndexSpec); - } catch (...) { - return exceptionToStatus(); - } - } + Collection* collection = autoDb.getDb()->getCollection(opCtx, systemUsers); + if (collection) { + IndexCatalog* indexCatalog = collection->getIndexCatalog(); + invariant(indexCatalog); + + // Make sure the old unique index from v2.4 on system.users doesn't exist. + std::vector<IndexDescriptor*> indexes; + indexCatalog->findIndexesByKeyPattern(opCtx, v1SystemUsersKeyPattern, false, &indexes); + + if (!indexes.empty()) { + fassert(ErrorCodes::AmbiguousIndexKeyPattern, indexes.size() == 1); + return Status(ErrorCodes::AuthSchemaIncompatible, + "Old 2.4 style user index identified. " + "The authentication schema needs to be updated by " + "running authSchemaUpgrade on a 2.6 server."); } - // Ensure that system indexes exist for the roles collection, if it exists. - collection = autoDb.getDb()->getCollection(opCtx, systemRoles); - if (collection) { - IndexCatalog* indexCatalog = collection->getIndexCatalog(); - invariant(indexCatalog); - - std::vector<IndexDescriptor*> indexes; - indexCatalog->findIndexesByKeyPattern(opCtx, v3SystemRolesKeyPattern, false, &indexes); - if (indexes.empty()) { - try { - generateSystemIndexForExistingCollection( - opCtx, collection, systemRoles, v3SystemRolesIndexSpec); - } catch (...) { - return exceptionToStatus(); - } + // Ensure that system indexes exist for the user collection + indexCatalog->findIndexesByKeyPattern(opCtx, v3SystemUsersKeyPattern, false, &indexes); + if (indexes.empty()) { + try { + generateSystemIndexForExistingCollection( + opCtx, collection, systemUsers, v3SystemUsersIndexSpec); + } catch (...) { + return exceptionToStatus(); } } } - // Create indexes for system collections in the config db. - { - AutoGetDb autoDb(opCtx, sessionCollectionNamespace.db(), MODE_X); - if (!autoDb.getDb()) { - return Status::OK(); + // Ensure that system indexes exist for the roles collection, if it exists. + collection = autoDb.getDb()->getCollection(opCtx, systemRoles); + if (collection) { + IndexCatalog* indexCatalog = collection->getIndexCatalog(); + invariant(indexCatalog); + + std::vector<IndexDescriptor*> indexes; + indexCatalog->findIndexesByKeyPattern(opCtx, v3SystemRolesKeyPattern, false, &indexes); + if (indexes.empty()) { + try { + generateSystemIndexForExistingCollection( + opCtx, collection, systemRoles, v3SystemRolesIndexSpec); + } catch (...) { + return exceptionToStatus(); + } } + } - // Ensure that system indexes exist for the sessions collection, if it exists. - auto collection = autoDb.getDb()->getCollection(opCtx, sessionCollectionNamespace); - if (collection) { - IndexCatalog* indexCatalog = collection->getIndexCatalog(); - invariant(indexCatalog); - - std::vector<IndexDescriptor*> indexes; - indexCatalog->findIndexesByKeyPattern( - opCtx, v1SystemSessionsKeyPattern, false, &indexes); - if (indexes.empty()) { - try { - generateSystemIndexForExistingCollection( - opCtx, collection, sessionCollectionNamespace, v1SystemSessionsIndexSpec); - } catch (...) { - return exceptionToStatus(); - } + // Ensure that system indexes exist for the sessions collection, if it exists. + collection = autoDb.getDb()->getCollection(opCtx, sessionCollectionNamespace); + if (collection) { + IndexCatalog* indexCatalog = collection->getIndexCatalog(); + invariant(indexCatalog); + + std::vector<IndexDescriptor*> indexes; + indexCatalog->findIndexesByKeyPattern(opCtx, v1SystemSessionsKeyPattern, false, &indexes); + if (indexes.empty()) { + try { + generateSystemIndexForExistingCollection( + opCtx, collection, sessionCollectionNamespace, v1SystemSessionsIndexSpec); + } catch (...) { + return exceptionToStatus(); } } } |