summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsamantharitter <samantha.ritter@10gen.com>2017-09-19 18:19:35 -0400
committersamantharitter <samantha.ritter@10gen.com>2017-09-22 12:02:25 -0400
commitba1704f7cbc0b9a03a181df145f75f433a59b7df (patch)
treed4374049d51514a554fa1d101661d054d0ac654d /src
parentd90e9a13a515a2c408b58ed0fad60a327ac7d3b7 (diff)
downloadmongo-ba1704f7cbc0b9a03a181df145f75f433a59b7df.tar.gz
SERVER-31174 Move the sessions collection to config.system.sessions
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/namespace_string.cpp3
-rw-r--r--src/mongo/db/ops/insert.cpp6
-rw-r--r--src/mongo/db/pipeline/document_source_list_sessions.h2
-rw-r--r--src/mongo/db/sessions_collection.h4
-rw-r--r--src/mongo/db/system_index.cpp128
-rw-r--r--src/mongo/dbtests/logical_sessions_tests.cpp2
6 files changed, 80 insertions, 65 deletions
diff --git a/src/mongo/db/namespace_string.cpp b/src/mongo/db/namespace_string.cpp
index 35fbde965dd..035228b65ad 100644
--- a/src/mongo/db/namespace_string.cpp
+++ b/src/mongo/db/namespace_string.cpp
@@ -115,7 +115,8 @@ bool NamespaceString::isLegalClientSystemNS() const {
return true;
if (ns() == "admin.system.backup_users")
return true;
- if (ns() == "admin.system.sessions")
+ } else if (db() == "config") {
+ if (ns() == "config.system.sessions")
return true;
}
if (ns() == "local.system.replset")
diff --git a/src/mongo/db/ops/insert.cpp b/src/mongo/db/ops/insert.cpp
index 0b422f8882c..de02fda5642 100644
--- a/src/mongo/db/ops/insert.cpp
+++ b/src/mongo/db/ops/insert.cpp
@@ -235,8 +235,6 @@ Status userAllowedCreateNS(StringData db, StringData coll) {
if (db == "admin") {
if (coll == "system.version")
return Status::OK();
- if (coll == "system.sessions")
- return Status::OK();
if (coll == "system.roles")
return Status::OK();
if (coll == "system.new_users")
@@ -246,6 +244,10 @@ Status userAllowedCreateNS(StringData db, StringData coll) {
if (coll == "system.keys")
return Status::OK();
}
+ if (db == "config") {
+ if (coll == "system.sessions")
+ return Status::OK();
+ }
if (db == "local") {
if (coll == "system.replset")
return Status::OK();
diff --git a/src/mongo/db/pipeline/document_source_list_sessions.h b/src/mongo/db/pipeline/document_source_list_sessions.h
index 38ba2b21b67..47c08af9d73 100644
--- a/src/mongo/db/pipeline/document_source_list_sessions.h
+++ b/src/mongo/db/pipeline/document_source_list_sessions.h
@@ -37,7 +37,7 @@ namespace mongo {
/**
* $listSessions: { allUsers: true/false, users: [ {user:"jsmith", db:"test"}, ... ] }
- * Return all sessions in the admin.system.sessions collection
+ * Return all sessions in the config.system.sessions collection
* or just sessions for the currently logged in user. (Default: false)
*
* This is essentially an alias for {$match:{"_id.uid": myid}} or {$match:{}}
diff --git a/src/mongo/db/sessions_collection.h b/src/mongo/db/sessions_collection.h
index 9d29924069c..63fd34667cf 100644
--- a/src/mongo/db/sessions_collection.h
+++ b/src/mongo/db/sessions_collection.h
@@ -49,9 +49,9 @@ class SessionsCollection {
public:
virtual ~SessionsCollection();
- static constexpr StringData kSessionsDb = "admin"_sd;
+ static constexpr StringData kSessionsDb = "config"_sd;
static constexpr StringData kSessionsCollection = "system.sessions"_sd;
- static constexpr StringData kSessionsFullNS = "admin.system.sessions"_sd;
+ static constexpr StringData kSessionsFullNS = "config.system.sessions"_sd;
static const NamespaceString kSessionsNamespaceString;
diff --git a/src/mongo/db/system_index.cpp b/src/mongo/db/system_index.cpp
index 0c07a4e46ad..be95f1d0758 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("admin.system.sessions");
+const NamespaceString sessionCollectionNamespace("config.system.sessions");
MONGO_INITIALIZER(AuthIndexKeyPatterns)(InitializerContext*) {
v1SystemUsersKeyPattern = BSON("user" << 1 << "userSource" << 1);
@@ -145,72 +145,84 @@ Status verifySystemIndexes(OperationContext* opCtx) {
const NamespaceString& systemUsers = AuthorizationManager::usersCollectionNamespace;
const NamespaceString& systemRoles = AuthorizationManager::rolesCollectionNamespace;
- 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.");
+ // Create indexes for collections on the admin db
+ {
+ 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 user collection
+ indexCatalog->findIndexesByKeyPattern(opCtx, v3SystemUsersKeyPattern, false, &indexes);
+ if (indexes.empty()) {
+ try {
+ generateSystemIndexForExistingCollection(
+ opCtx, collection, systemUsers, v3SystemUsersIndexSpec);
+ } catch (...) {
+ return exceptionToStatus();
+ }
}
}
- }
- // 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 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.
- 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();
+ // 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 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();
+ }
}
}
}
diff --git a/src/mongo/dbtests/logical_sessions_tests.cpp b/src/mongo/dbtests/logical_sessions_tests.cpp
index 13ca0c434c8..0b1b42df660 100644
--- a/src/mongo/dbtests/logical_sessions_tests.cpp
+++ b/src/mongo/dbtests/logical_sessions_tests.cpp
@@ -45,7 +45,7 @@
namespace LogicalSessionTests {
namespace {
-constexpr StringData kTestNS = "admin.system.sessions"_sd;
+constexpr StringData kTestNS = "config.system.sessions"_sd;
LogicalSessionRecord makeRecord(Date_t time = Date_t::now()) {
auto record = makeLogicalSessionRecordForTest();