summaryrefslogtreecommitdiff
path: root/src/mongo/db/sessions_collection_standalone.cpp
diff options
context:
space:
mode:
authorBlake Oler <blake.oler@mongodb.com>2018-11-01 12:14:56 -0400
committerBlake Oler <blake.oler@mongodb.com>2018-11-02 09:39:31 -0400
commitf13d685ade22d662070bde942eb094790d4e7b8d (patch)
treeea89d8c6c586c421451477a52c3616e438884193 /src/mongo/db/sessions_collection_standalone.cpp
parenta19da30a1bf7462c9a8a0533c43f98bd13fbb190 (diff)
downloadmongo-f13d685ade22d662070bde942eb094790d4e7b8d.tar.gz
SERVER-37624 Allow sessions collection TTL index expiration value to change upon node restart
Diffstat (limited to 'src/mongo/db/sessions_collection_standalone.cpp')
-rw-r--r--src/mongo/db/sessions_collection_standalone.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/mongo/db/sessions_collection_standalone.cpp b/src/mongo/db/sessions_collection_standalone.cpp
index 3a45269070e..a29323817bd 100644
--- a/src/mongo/db/sessions_collection_standalone.cpp
+++ b/src/mongo/db/sessions_collection_standalone.cpp
@@ -47,8 +47,20 @@ BSONObj lsidQuery(const LogicalSessionId& lsid) {
} // namespace
Status SessionsCollectionStandalone::setupSessionsCollection(OperationContext* opCtx) {
+ auto existsStatus = checkSessionsCollectionExists(opCtx);
+ if (existsStatus.isOK()) {
+ return Status::OK();
+ }
+
DBDirectClient client(opCtx);
- auto cmd = generateCreateIndexesCmd();
+ BSONObj cmd;
+
+ if (existsStatus.code() == ErrorCodes::IndexOptionsConflict) {
+ cmd = generateCollModCmd();
+ } else {
+ cmd = generateCreateIndexesCmd();
+ }
+
BSONObj info;
if (!client.runCommand(NamespaceString::kLogicalSessionsNamespace.db().toString(), cmd, info)) {
return getStatusFromCommandResult(info);
@@ -66,15 +78,22 @@ Status SessionsCollectionStandalone::checkSessionsCollectionExists(OperationCont
return Status{ErrorCodes::NamespaceNotFound, "config.system.sessions does not exist"};
}
- auto indexExists = std::find_if(indexes.begin(), indexes.end(), [](const BSONObj& index) {
+ auto index = std::find_if(indexes.begin(), indexes.end(), [](const BSONObj& index) {
return index.getField("name").String() == kSessionsTTLIndex;
});
- if (indexExists == indexes.end()) {
+ if (index == indexes.end()) {
return Status{ErrorCodes::IndexNotFound,
"config.system.sessions does not have the required TTL index"};
};
+ if (!index->hasField("expireAfterSeconds") ||
+ index->getField("expireAfterSeconds").Int() != (localLogicalSessionTimeoutMinutes * 60)) {
+ return Status{
+ ErrorCodes::IndexOptionsConflict,
+ "config.system.sessions currently has the incorrect timeout for the TTL index"};
+ }
+
return Status::OK();
}