summaryrefslogtreecommitdiff
path: root/src/mongo/db/sessions_collection_sharded.cpp
diff options
context:
space:
mode:
authorsamantharitter <samantha.ritter@10gen.com>2017-10-06 15:12:40 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-10-11 00:52:09 -0400
commit45d35fe3fcefefe1282b8e0dfc8cd76cb247951d (patch)
tree6643f175807ae1c20902885846d29e888127f9a6 /src/mongo/db/sessions_collection_sharded.cpp
parent8b3694d704d4c472adba87e8fb0827372324c215 (diff)
downloadmongo-45d35fe3fcefefe1282b8e0dfc8cd76cb247951d.tar.gz
SERVER-31184 Make servers automatically set up config.system.sessions
Diffstat (limited to 'src/mongo/db/sessions_collection_sharded.cpp')
-rw-r--r--src/mongo/db/sessions_collection_sharded.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/mongo/db/sessions_collection_sharded.cpp b/src/mongo/db/sessions_collection_sharded.cpp
index bbcf195d8dd..de7699eb962 100644
--- a/src/mongo/db/sessions_collection_sharded.cpp
+++ b/src/mongo/db/sessions_collection_sharded.cpp
@@ -35,7 +35,10 @@
#include "mongo/db/query/canonical_query.h"
#include "mongo/db/query/query_request.h"
#include "mongo/db/sessions_collection_rs.h"
+#include "mongo/rpc/get_status_from_command_result.h"
+#include "mongo/s/catalog_cache.h"
#include "mongo/s/commands/cluster_write.h"
+#include "mongo/s/grid.h"
#include "mongo/s/query/cluster_find.h"
#include "mongo/s/write_ops/batch_write_exec.h"
#include "mongo/s/write_ops/batched_command_request.h"
@@ -52,6 +55,26 @@ BSONObj lsidQuery(const LogicalSessionId& lsid) {
} // namespace
+Status SessionsCollectionSharded::_checkCacheForSessionsCollection(OperationContext* opCtx) {
+ // If the collection doesn't exist, fail. Only the config servers generate it.
+ auto res = Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(
+ opCtx, NamespaceString(SessionsCollection::kSessionsFullNS.toString()));
+ if (!res.isOK()) {
+ return res.getStatus();
+ }
+
+ auto routingInfo = res.getValue();
+ if (routingInfo.cm()) {
+ return Status::OK();
+ }
+
+ return {ErrorCodes::NamespaceNotFound, "config.system.sessions is not yet sharded"};
+}
+
+Status SessionsCollectionSharded::setupSessionsCollection(OperationContext* opCtx) {
+ return _checkCacheForSessionsCollection(opCtx);
+}
+
Status SessionsCollectionSharded::refreshSessions(OperationContext* opCtx,
const LogicalSessionRecordSet& sessions) {
auto send = [&](BSONObj toSend) {