summaryrefslogtreecommitdiff
path: root/src/mongo/db/sessions_collection_standalone.cpp
diff options
context:
space:
mode:
authorMarcos José Grillo Ramírez <marcos.grillo@10gen.com>2019-10-29 12:07:54 +0000
committerevergreen <evergreen@mongodb.com>2019-10-29 12:07:54 +0000
commit81f52a69c92d27034ef3a9bf411fb463cab7643e (patch)
tree37a57eaa120a6a3c71a515a7f39dfceb21ee8cee /src/mongo/db/sessions_collection_standalone.cpp
parentaf1a00179bd00083fd6d4c3af34140e4ba2aac6d (diff)
downloadmongo-81f52a69c92d27034ef3a9bf411fb463cab7643e.tar.gz
SERVER-42508 Convert SessionsCollection to throw instead of return status
Change the return value of checkSessionsCollectionExists from Status to void and throws exception on error
Diffstat (limited to 'src/mongo/db/sessions_collection_standalone.cpp')
-rw-r--r--src/mongo/db/sessions_collection_standalone.cpp71
1 files changed, 35 insertions, 36 deletions
diff --git a/src/mongo/db/sessions_collection_standalone.cpp b/src/mongo/db/sessions_collection_standalone.cpp
index c994d7694ad..9d1bb415641 100644
--- a/src/mongo/db/sessions_collection_standalone.cpp
+++ b/src/mongo/db/sessions_collection_standalone.cpp
@@ -46,54 +46,53 @@ BSONObj lsidQuery(const LogicalSessionId& lsid) {
} // namespace
void SessionsCollectionStandalone::setupSessionsCollection(OperationContext* opCtx) {
- auto existsStatus = checkSessionsCollectionExists(opCtx);
- if (existsStatus.isOK()) {
- return;
- }
-
- DBDirectClient client(opCtx);
- BSONObj cmd;
-
- if (existsStatus.code() == ErrorCodes::IndexOptionsConflict) {
- cmd = generateCollModCmd();
- } else {
- cmd = generateCreateIndexesCmd();
- }
-
- BSONObj info;
- if (!client.runCommand(NamespaceString::kLogicalSessionsNamespace.db().toString(), cmd, info)) {
- uassertStatusOKWithContext(getStatusFromCommandResult(info),
- str::stream() << "Failed to create "
- << NamespaceString::kLogicalSessionsNamespace);
+ try {
+ checkSessionsCollectionExists(opCtx);
+ } catch (DBException& ex) {
+
+ DBDirectClient client(opCtx);
+ BSONObj cmd;
+
+ if (ex.code() == ErrorCodes::IndexOptionsConflict) {
+ cmd = generateCollModCmd();
+ } else {
+ cmd = generateCreateIndexesCmd();
+ }
+
+ BSONObj info;
+ if (!client.runCommand(
+ NamespaceString::kLogicalSessionsNamespace.db().toString(), cmd, info)) {
+ uassertStatusOKWithContext(getStatusFromCommandResult(info),
+ str::stream() << "Failed to create "
+ << NamespaceString::kLogicalSessionsNamespace);
+ }
}
}
-Status SessionsCollectionStandalone::checkSessionsCollectionExists(OperationContext* opCtx) {
+void SessionsCollectionStandalone::checkSessionsCollectionExists(OperationContext* opCtx) {
DBDirectClient client(opCtx);
auto indexes = client.getIndexSpecs(NamespaceString::kLogicalSessionsNamespace);
- if (indexes.size() == 0u) {
- return Status{ErrorCodes::NamespaceNotFound, "config.system.sessions does not exist"};
- }
+ uassert(ErrorCodes::NamespaceNotFound,
+ str::stream() << NamespaceString::kLogicalSessionsNamespace << " does not exist",
+ indexes.size() != 0u);
auto index = std::find_if(indexes.begin(), indexes.end(), [](const BSONObj& index) {
return index.getField("name").String() == kSessionsTTLIndex;
});
- 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();
+ uassert(ErrorCodes::IndexNotFound,
+ str::stream() << NamespaceString::kLogicalSessionsNamespace
+ << " does not have the required TTL index",
+ index != indexes.end());
+
+ uassert(ErrorCodes::IndexOptionsConflict,
+ str::stream() << NamespaceString::kLogicalSessionsNamespace
+ << " currently has the incorrect timeout for the TTL index",
+ index->hasField("expireAfterSeconds") &&
+ index->getField("expireAfterSeconds").Int() ==
+ (localLogicalSessionTimeoutMinutes * 60));
}
Status SessionsCollectionStandalone::refreshSessions(OperationContext* opCtx,