summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Shteinfeld <ben.shteinfeld@mongodb.com>2023-04-06 17:58:25 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-04-25 13:26:45 +0000
commita6e03c4a2f76ec9a40004a80dd670a065916a011 (patch)
treea9628927db239c7c89abf5c282d6df034919a414
parent8a853b2b68beccf5f15e46f0f819aa2d59b9af7f (diff)
downloadmongo-a6e03c4a2f76ec9a40004a80dd670a065916a011.tar.gz
SERVER-75010 Introduce inShardedEnvironment() function to
MongoProcessInterface This is a partial backport of https://github.com/mongodb/mongo/commit/28c7db0e580afb4fe889f16370cf44c6f95f8cf3. (cherry picked from commit 190f4f7f5def5af8ae8d992ddabaea06e216f743)
-rw-r--r--src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp4
-rw-r--r--src/mongo/db/pipeline/process_interface/common_mongod_process_interface.h2
-rw-r--r--src/mongo/db/pipeline/process_interface/mongo_process_interface.h6
-rw-r--r--src/mongo/db/pipeline/process_interface/mongos_process_interface.h4
-rw-r--r--src/mongo/db/pipeline/process_interface/stub_mongo_process_interface.h4
5 files changed, 20 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp b/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp
index e73764a6a7e..4a4aa559818 100644
--- a/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp
+++ b/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp
@@ -310,6 +310,10 @@ std::string CommonMongodProcessInterface::getShardName(OperationContext* opCtx)
return std::string();
}
+bool CommonMongodProcessInterface::inShardedEnvironment(OperationContext* opCtx) const {
+ return ShardingState::get(opCtx)->enabled();
+}
+
std::vector<GenericCursor> CommonMongodProcessInterface::getIdleCursors(
const boost::intrusive_ptr<ExpressionContext>& expCtx, CurrentOpUserMode userMode) const {
return CursorManager::get(expCtx->opCtx)->getIdleCursors(expCtx->opCtx, userMode);
diff --git a/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.h b/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.h
index 75fafc04c07..51e947c9780 100644
--- a/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.h
+++ b/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.h
@@ -80,6 +80,8 @@ public:
Pipeline* pipeline) final;
std::string getShardName(OperationContext* opCtx) const final;
+ bool inShardedEnvironment(OperationContext* opCtx) const final;
+
boost::optional<Document> lookupSingleDocument(
const boost::intrusive_ptr<ExpressionContext>& expCtx,
const NamespaceString& nss,
diff --git a/src/mongo/db/pipeline/process_interface/mongo_process_interface.h b/src/mongo/db/pipeline/process_interface/mongo_process_interface.h
index 9a29d0b5df9..205a92e0c1d 100644
--- a/src/mongo/db/pipeline/process_interface/mongo_process_interface.h
+++ b/src/mongo/db/pipeline/process_interface/mongo_process_interface.h
@@ -162,6 +162,12 @@ public:
*/
virtual bool supportsReadPreferenceForWriteOp(
const boost::intrusive_ptr<ExpressionContext>& expCtx) = 0;
+
+ /**
+ * Returns whether this process is running as part of a sharded cluster.
+ */
+ virtual bool inShardedEnvironment(OperationContext* opCtx) const = 0;
+
/**
* Advances the proxied write time associated with the client in ReplClientInfo to
* be at least as high as the one tracked by the OperationTimeTracker associated with the
diff --git a/src/mongo/db/pipeline/process_interface/mongos_process_interface.h b/src/mongo/db/pipeline/process_interface/mongos_process_interface.h
index 7141915b7d3..bad8912bd4c 100644
--- a/src/mongo/db/pipeline/process_interface/mongos_process_interface.h
+++ b/src/mongo/db/pipeline/process_interface/mongos_process_interface.h
@@ -66,6 +66,10 @@ public:
bool isSharded(OperationContext* opCtx, const NamespaceString& nss) final;
+ bool inShardedEnvironment(OperationContext*) const final {
+ return true;
+ }
+
Status insert(const boost::intrusive_ptr<ExpressionContext>& expCtx,
const NamespaceString& ns,
std::vector<BSONObj>&& objs,
diff --git a/src/mongo/db/pipeline/process_interface/stub_mongo_process_interface.h b/src/mongo/db/pipeline/process_interface/stub_mongo_process_interface.h
index fcf0458ea3c..51a9e8c0786 100644
--- a/src/mongo/db/pipeline/process_interface/stub_mongo_process_interface.h
+++ b/src/mongo/db/pipeline/process_interface/stub_mongo_process_interface.h
@@ -199,6 +199,10 @@ public:
MONGO_UNREACHABLE;
}
+ bool inShardedEnvironment(OperationContext*) const override {
+ MONGO_UNREACHABLE;
+ }
+
std::string getHostAndPort(OperationContext* opCtx) const override {
MONGO_UNREACHABLE;
}