summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorRishab Joshi <rishab.joshi@mongodb.com>2022-08-12 15:38:54 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-23 21:07:02 +0000
commit9ca61a6d178ec3bb2fe46c93e31c6ac3a503c75d (patch)
tree9445294b6ad483ffbe4723f10d0ad7f64989ea0d /src/mongo/db
parent9d47a813c02607ff8fb4fbc50b544ebeb494ce85 (diff)
downloadmongo-9ca61a6d178ec3bb2fe46c93e31c6ac3a503c75d.tar.gz
SERVER-67634 Ensure that change collections are never used on config
servers.
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/change_stream_change_collection_manager.cpp6
-rw-r--r--src/mongo/db/change_stream_change_collection_manager.h4
-rw-r--r--src/mongo/db/commands/run_aggregate.cpp6
-rw-r--r--src/mongo/db/repl/primary_only_service_util.h2
-rw-r--r--src/mongo/db/repl/primary_only_service_util_test.cpp4
-rw-r--r--src/mongo/db/set_change_stream_state_coordinator.cpp2
-rw-r--r--src/mongo/db/set_change_stream_state_coordinator.h2
7 files changed, 19 insertions, 7 deletions
diff --git a/src/mongo/db/change_stream_change_collection_manager.cpp b/src/mongo/db/change_stream_change_collection_manager.cpp
index d085b514d18..5559e49390a 100644
--- a/src/mongo/db/change_stream_change_collection_manager.cpp
+++ b/src/mongo/db/change_stream_change_collection_manager.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/repl/apply_ops_command_info.h"
#include "mongo/db/repl/oplog.h"
#include "mongo/db/repl/oplog_entry_gen.h"
+#include "mongo/db/server_options.h"
#include "mongo/logv2/log.h"
namespace mongo {
@@ -200,6 +201,11 @@ void ChangeStreamChangeCollectionManager::create(ServiceContext* service) {
}
bool ChangeStreamChangeCollectionManager::isChangeCollectionsModeActive() {
+ // A change collection must not be enabled on the config server.
+ if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
+ return false;
+ }
+
// If the force fail point is enabled then declare the change collection mode as active.
if (MONGO_unlikely(forceEnableChangeCollectionsMode.shouldFail())) {
return true;
diff --git a/src/mongo/db/change_stream_change_collection_manager.h b/src/mongo/db/change_stream_change_collection_manager.h
index cd2e166b1df..21a60c1bf0e 100644
--- a/src/mongo/db/change_stream_change_collection_manager.h
+++ b/src/mongo/db/change_stream_change_collection_manager.h
@@ -61,8 +61,8 @@ public:
static ChangeStreamChangeCollectionManager& get(OperationContext* opCtx);
/**
- * Returns true if change collections are enabled for recording oplog entries, false
- * otherwise.
+ * Returns true if the server is configured such that change collections can be used to record
+ * oplog entries; ie, we are running in a Serverless context. Returns false otherwise.
*/
static bool isChangeCollectionsModeActive();
diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp
index 981a692634e..acc2597af08 100644
--- a/src/mongo/db/commands/run_aggregate.cpp
+++ b/src/mongo/db/commands/run_aggregate.cpp
@@ -763,6 +763,12 @@ Status runAggregate(OperationContext* opCtx,
nss = NamespaceString::makeChangeCollectionNSS(origNss.tenantId());
}
+ // Assert that a change stream on the config server is always opened on the oplog.
+ tassert(6763400,
+ str::stream() << "Change stream was unexpectedly opened on the namespace: "
+ << nss << " in the config server",
+ serverGlobalParams.clusterRole != ClusterRole::ConfigServer || nss.isOplog());
+
// If the 'assertChangeStreamNssCollection' failpoint is active then ensure that we are
// opening the change stream on the correct namespace.
if (auto scopedFp = assertChangeStreamNssCollection.scoped();
diff --git a/src/mongo/db/repl/primary_only_service_util.h b/src/mongo/db/repl/primary_only_service_util.h
index 64aea0ac8d2..d94af7afc28 100644
--- a/src/mongo/db/repl/primary_only_service_util.h
+++ b/src/mongo/db/repl/primary_only_service_util.h
@@ -103,7 +103,7 @@ public:
/**
* The name of the 'PrimaryOnlyService::Instance'.
*/
- virtual const StringData getInstanceName() = 0;
+ virtual StringData getInstanceName() = 0;
/**
* Interrupts the current running 'DefaultPrimaryOnlyServiceInstance' instance.
diff --git a/src/mongo/db/repl/primary_only_service_util_test.cpp b/src/mongo/db/repl/primary_only_service_util_test.cpp
index 0fc059d3d5a..6392ae9c67e 100644
--- a/src/mongo/db/repl/primary_only_service_util_test.cpp
+++ b/src/mongo/db/repl/primary_only_service_util_test.cpp
@@ -57,7 +57,7 @@ public:
_state = state;
}
- const BSONObj toBSON() const {
+ BSONObj toBSON() const {
return BSON("_id" << _state);
}
@@ -74,7 +74,7 @@ PrimaryOnlyServiceStateStore<TestStateDocument> gStateDocStore{
*/
class TestDefaultPrimaryOnlyServiceInstance : public DefaultPrimaryOnlyServiceInstance {
public:
- const StringData getInstanceName() final {
+ StringData getInstanceName() final {
return kTestPrimaryOnlyServiceInstanceName;
}
diff --git a/src/mongo/db/set_change_stream_state_coordinator.cpp b/src/mongo/db/set_change_stream_state_coordinator.cpp
index a172b2e06fc..a0ee72fac51 100644
--- a/src/mongo/db/set_change_stream_state_coordinator.cpp
+++ b/src/mongo/db/set_change_stream_state_coordinator.cpp
@@ -123,7 +123,7 @@ private:
} // namespace
-const StringData SetChangeStreamStateCoordinator::getInstanceName() {
+StringData SetChangeStreamStateCoordinator::getInstanceName() {
return kSetChangeStreamStateCoordinatorName;
}
diff --git a/src/mongo/db/set_change_stream_state_coordinator.h b/src/mongo/db/set_change_stream_state_coordinator.h
index aaa4d4305d6..7ca1592dc80 100644
--- a/src/mongo/db/set_change_stream_state_coordinator.h
+++ b/src/mongo/db/set_change_stream_state_coordinator.h
@@ -47,7 +47,7 @@ class SetChangeStreamStateCoordinator : public DefaultPrimaryOnlyServiceInstance
public:
explicit SetChangeStreamStateCoordinator(const BSONObj& stateDoc);
- const StringData getInstanceName() final;
+ StringData getInstanceName() final;
boost::optional<BSONObj> reportForCurrentOp(
MongoProcessInterface::CurrentOpConnectionsMode connMode,