diff options
author | samantharitter <samantha.ritter@10gen.com> | 2017-10-06 15:12:40 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-10-11 00:52:09 -0400 |
commit | 45d35fe3fcefefe1282b8e0dfc8cd76cb247951d (patch) | |
tree | 6643f175807ae1c20902885846d29e888127f9a6 /src/mongo/db/sessions_collection_rs.cpp | |
parent | 8b3694d704d4c472adba87e8fb0827372324c215 (diff) | |
download | mongo-45d35fe3fcefefe1282b8e0dfc8cd76cb247951d.tar.gz |
SERVER-31184 Make servers automatically set up config.system.sessions
Diffstat (limited to 'src/mongo/db/sessions_collection_rs.cpp')
-rw-r--r-- | src/mongo/db/sessions_collection_rs.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/mongo/db/sessions_collection_rs.cpp b/src/mongo/db/sessions_collection_rs.cpp index 4cfbffff3c3..cc65d9df574 100644 --- a/src/mongo/db/sessions_collection_rs.cpp +++ b/src/mongo/db/sessions_collection_rs.cpp @@ -44,6 +44,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/repl/repl_set_config.h" #include "mongo/db/repl/replication_coordinator.h" +#include "mongo/rpc/get_status_from_command_result.h" #include "mongo/stdx/memory.h" namespace mongo { @@ -131,6 +132,28 @@ auto dispatch(const NamespaceString& ns, } // namespace +Status SessionsCollectionRS::setupSessionsCollection(OperationContext* opCtx) { + return dispatch(kSessionsNamespaceString, + MODE_IX, + opCtx, + [&] { + // Creating the TTL index will auto-generate the collection. + DBDirectClient client(opCtx); + BSONObj info; + auto cmd = generateCreateIndexesCmd(); + if (!client.runCommand(kSessionsDb.toString(), cmd, info)) { + return getStatusFromCommandResult(info); + } + + return Status::OK(); + }, + [&](DBClientBase*) { + // If we are not the primary, we aren't going to do writes + // anyway, so just return ok. + return Status::OK(); + }); +} + Status SessionsCollectionRS::refreshSessions(OperationContext* opCtx, const LogicalSessionRecordSet& sessions) { return dispatch( |