summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRomans Kasperovics <romans.kasperovics@mongodb.com>2022-06-23 07:55:24 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-06-23 08:35:42 +0000
commit3d1c61099274ec772302cf16e486403cfc427e9b (patch)
treefcfe79032e4019510c43beef6ef89baf8feeb7ee
parent9a2feca5954141852d8805d0c575b62dd3bccd69 (diff)
downloadmongo-3d1c61099274ec772302cf16e486403cfc427e9b.tar.gz
SERVER-65948 Add 'changeStreams' cluster-wide parameter
This parameter will be used to activate per-tenant change collections in serverless environment.
-rw-r--r--jstests/libs/cluster_server_parameter_utils.js53
-rw-r--r--jstests/noPassthrough/change_streams_cluster_parameter.js146
-rw-r--r--jstests/replsets/cluster_server_parameter_commands_replset.js3
-rw-r--r--jstests/sharding/cluster_server_parameter_commands_sharded.js3
-rw-r--r--src/mongo/db/SConscript11
-rw-r--r--src/mongo/db/change_streams_cluster_parameter.cpp62
-rw-r--r--src/mongo/db/change_streams_cluster_parameter.h42
-rw-r--r--src/mongo/db/change_streams_cluster_parameter.idl64
-rw-r--r--src/mongo/db/change_streams_cluster_parameter_test.cpp78
-rw-r--r--src/mongo/s/SConscript1
10 files changed, 440 insertions, 23 deletions
diff --git a/jstests/libs/cluster_server_parameter_utils.js b/jstests/libs/cluster_server_parameter_utils.js
index 2191108ab0c..072fac11d9a 100644
--- a/jstests/libs/cluster_server_parameter_utils.js
+++ b/jstests/libs/cluster_server_parameter_utils.js
@@ -6,13 +6,13 @@
* it to the end of nonTestClusterParameterNames.
* 2. Add the clusterParameter document that's expected as default to the end of
* testOnlyClusterParametersDefault if it's test-only. Otherwise, add it to the end of
- * nonTestOnlyClusterParametersDefault.
+ * nonTestClusterParametersDefault.
* 3. Add the clusterParameter document that setClusterParameter is expected to insert after its
* first invocation to the end of testOnlyClusterParametersInsert if it's test-only. Otherwise,
- * add it to the end of nonTestOnlyClusterParametersInsert.
+ * add it to the end of nonTestClusterParametersInsert.
* 4. Add the clusterParameter document that setClusterParameter is expected to update to after its
* second invocation to the end of testOnlyClusterParametersUpdate if it's test-only. Otherwise,
- * add it to the end of nonTestOnlyClusterParametersUpdate.
+ * add it to the end of nonTestClusterParametersUpdate.
*
*/
@@ -21,9 +21,7 @@ const testOnlyClusterParameterNames = [
"testIntClusterParameter",
"testBoolClusterParameter",
];
-const nonTestClusterParameterNames = [
- "changeStreamOptions",
-];
+const nonTestClusterParameterNames = ["changeStreamOptions", "changeStreams"];
const clusterParameterNames = testOnlyClusterParameterNames.concat(nonTestClusterParameterNames);
const testOnlyClusterParametersDefault = [
@@ -40,12 +38,15 @@ const testOnlyClusterParametersDefault = [
boolData: false,
},
];
-const nonTestClusterParametersDefault = [{
- _id: "changeStreamOptions",
- preAndPostImages: {
- expireAfterSeconds: "off",
+const nonTestClusterParametersDefault = [
+ {
+ _id: "changeStreamOptions",
+ preAndPostImages: {
+ expireAfterSeconds: "off",
+ },
},
-}];
+ {_id: "changeStreams", enabled: false, expireAfterSeconds: NumberLong(0)}
+];
const clusterParametersDefault =
testOnlyClusterParametersDefault.concat(nonTestClusterParametersDefault);
@@ -63,12 +64,19 @@ const testOnlyClusterParametersInsert = [
boolData: true,
},
];
-const nonTestClusterParametersInsert = [{
- _id: "changeStreamOptions",
- preAndPostImages: {
- expireAfterSeconds: 30,
+const nonTestClusterParametersInsert = [
+ {
+ _id: "changeStreamOptions",
+ preAndPostImages: {
+ expireAfterSeconds: 30,
+ },
},
-}];
+ {
+ _id: "changeStreams",
+ enabled: true,
+ expireAfterSeconds: 30,
+ }
+];
const clusterParametersInsert =
testOnlyClusterParametersInsert.concat(nonTestClusterParametersInsert);
@@ -86,12 +94,15 @@ const testOnlyClusterParametersUpdate = [
boolData: false,
},
];
-const nonTestClusterParametersUpdate = [{
- _id: "changeStreamOptions",
- preAndPostImages: {
- expireAfterSeconds: "off",
+const nonTestClusterParametersUpdate = [
+ {
+ _id: "changeStreamOptions",
+ preAndPostImages: {
+ expireAfterSeconds: "off",
+ },
},
-}];
+ {_id: "changeStreams", enabled: false, expireAfterSeconds: NumberLong(0)}
+];
const clusterParametersUpdate =
testOnlyClusterParametersUpdate.concat(nonTestClusterParametersUpdate);
diff --git a/jstests/noPassthrough/change_streams_cluster_parameter.js b/jstests/noPassthrough/change_streams_cluster_parameter.js
new file mode 100644
index 00000000000..e76ed12cb04
--- /dev/null
+++ b/jstests/noPassthrough/change_streams_cluster_parameter.js
@@ -0,0 +1,146 @@
+// Tests the 'changeStreams' cluster-wide configuration parameter on the replica sets and the
+// sharded cluster.
+// @tags: [
+// featureFlagClusterWideConfig,
+// requires_replication,
+// requires_sharding,
+// multiversion_incompatible,
+// featureFlagServerlessChangeStreams
+// featureFlagMongoStore
+// ]
+(function() {
+"use strict";
+
+// Verifies that the 'getClusterParameter' on the 'changeStreams' cluster-wide parameter returns the
+// expected response.
+function assertGetResponse(db, expectedChangeStreamParam) {
+ const response = assert.commandWorked(db.runCommand({getClusterParameter: "changeStreams"}));
+ const enabled = response.clusterParameters[0].enabled;
+ assert.eq(enabled, expectedChangeStreamParam.enabled, response);
+ if (enabled) {
+ // TODO SERVER-67145: For some reason the default 'expireAfterSeconds' is not serialized in
+ // mongoS.
+ assert.eq(response.clusterParameters[0].expireAfterSeconds,
+ expectedChangeStreamParam.expireAfterSeconds,
+ response);
+ }
+}
+
+// Tests the 'changeStreams' cluster-wide configuration parameter with the 'admin' database.
+function testWithAdminDB(conn) {
+ const adminDB = conn.getDB("admin");
+
+ // Change streams are initialy disabled.
+ assertGetResponse(adminDB, {enabled: false, expireAfterSeconds: NumberLong(0)});
+
+ // TODO SERVER-67293: Make 'enabled' field requiered; setting 'changeStreams' parameter without
+ // 'enabled' field should fail.
+ // TODO SERVER-67146: The expected error on missing 'enabled' field should be 'BadValue' or
+ // 'InvaludClusterParameter'.
+
+ // Invalid string value for the 'enabled' parameter should fail.
+ assert.commandFailedWithCode(
+ adminDB.runCommand({setClusterParameter: {changeStreams: {enabled: "yes"}}}),
+ ErrorCodes.TypeMismatch);
+
+ // Enabling change streams without 'expireAfterSeconds' should fail.
+ assert.commandFailedWithCode(
+ adminDB.runCommand({setClusterParameter: {changeStreams: {enabled: true}}}),
+ ErrorCodes.BadValue);
+
+ // Invalid string value for the 'expireAfterSeconds' parameter should fail.
+ assert.commandFailedWithCode(
+ adminDB.runCommand(
+ {setClusterParameter: {changeStreams: {enabled: true, expireAfterSeconds: "off"}}}),
+ ErrorCodes.TypeMismatch);
+
+ // A negative value of 'expireAfterSeconds' should fail.
+ assert.commandFailedWithCode(adminDB.runCommand({
+ setClusterParameter: {changeStreams: {enabled: true, expireAfterSeconds: NumberLong(-1)}}
+ }),
+ ErrorCodes.BadValue);
+
+ // A zero value of 'expireAfterSeconds' should fail.
+ assert.commandFailedWithCode(adminDB.runCommand({
+ setClusterParameter: {changeStreams: {enabled: true, expireAfterSeconds: NumberLong(0)}}
+ }),
+ ErrorCodes.BadValue);
+
+ // Enabling change streams with success.
+ assert.commandWorked(adminDB.runCommand({
+ setClusterParameter: {changeStreams: {enabled: true, expireAfterSeconds: NumberLong(3600)}}
+ }));
+ assertGetResponse(adminDB, {enabled: true, expireAfterSeconds: NumberLong(3600)});
+
+ // Modifying expireAfterSeconds while enabled should succeed.
+ assert.commandWorked(adminDB.runCommand({
+ setClusterParameter: {changeStreams: {enabled: true, expireAfterSeconds: NumberLong(100)}}
+ }));
+ assertGetResponse(adminDB, {enabled: true, expireAfterSeconds: NumberLong(100)});
+
+ // Disabling with (non-zero) 'expireAfterSeconds' should fail.
+ assert.commandFailedWithCode(adminDB.runCommand({
+ setClusterParameter: {changeStreams: {enabled: false, expireAfterSeconds: NumberLong(1)}}
+ }),
+ ErrorCodes.BadValue);
+
+ // Disabling without 'expireAfterSeconds' should succeed.
+ assert.commandWorked(
+ adminDB.runCommand({setClusterParameter: {changeStreams: {enabled: false}}}));
+ assertGetResponse(adminDB, {enabled: false, expireAfterSeconds: NumberLong(0)});
+
+ // Disabling again should succeed.
+ assert.commandWorked(
+ adminDB.runCommand({setClusterParameter: {changeStreams: {enabled: false}}}));
+ assertGetResponse(adminDB, {enabled: false, expireAfterSeconds: NumberLong(0)});
+}
+
+function testWithoutAdminDB(conn) {
+ const db = conn.getDB(jsTestName());
+ assert.commandFailedWithCode(db.runCommand({getClusterParameter: "changeStreams"}),
+ ErrorCodes.Unauthorized);
+ assert.commandFailedWithCode(db.runCommand({
+ setClusterParameter: {changeStreams: {enabled: true, expireAfterSeconds: NumberLong(3600)}}
+ }),
+ ErrorCodes.Unauthorized);
+}
+
+// Tests the set and get change streams parameter on the replica-set.
+{
+ const rst = new ReplSetTest({name: "replSet", nodes: 2});
+ rst.startSet();
+ rst.initiate();
+
+ const primary = rst.getPrimary();
+ const secondary = rst.getSecondaries()[0];
+
+ // Verify that the set and get commands cannot be issued on database other than the 'admin'.
+ [primary, secondary].forEach(conn => {
+ testWithoutAdminDB(conn);
+ });
+
+ // Tests the set and get commands on the primary node.
+ testWithAdminDB(primary);
+
+ rst.stopSet();
+}
+
+// Tests the set and get change streams parameter on the sharded cluster.
+{
+ const st = new ShardingTest({shards: 1, mongos: 1});
+ const adminDB = st.rs0.getPrimary().getDB("admin");
+
+ // Test that setClusterParameter cannot be issued directly on shards in the sharded cluster,
+ // while getClusterParameter can.
+ assert.commandFailedWithCode(adminDB.runCommand({
+ setClusterParameter: {changeStreams: {enabled: true, expireAfterSeconds: NumberLong(3600)}}
+ }),
+ ErrorCodes.NotImplemented);
+ assertGetResponse(adminDB, {enabled: false, expireAfterSeconds: NumberLong(0)});
+
+ // Run the set and get commands on the mongoS.
+ testWithAdminDB(st.s);
+
+ st.stop();
+}
+}());
diff --git a/jstests/replsets/cluster_server_parameter_commands_replset.js b/jstests/replsets/cluster_server_parameter_commands_replset.js
index ccf809765fa..79e1356f47c 100644
--- a/jstests/replsets/cluster_server_parameter_commands_replset.js
+++ b/jstests/replsets/cluster_server_parameter_commands_replset.js
@@ -3,7 +3,8 @@
*
* @tags: [
* does_not_support_stepdowns,
- * requires_replication
+ * requires_replication,
+ * multiversion_incompatible
* ]
*/
(function() {
diff --git a/jstests/sharding/cluster_server_parameter_commands_sharded.js b/jstests/sharding/cluster_server_parameter_commands_sharded.js
index 0b1c0a47c3b..c1547d0c3ac 100644
--- a/jstests/sharding/cluster_server_parameter_commands_sharded.js
+++ b/jstests/sharding/cluster_server_parameter_commands_sharded.js
@@ -4,7 +4,8 @@
* @tags: [
* does_not_support_stepdowns,
* requires_replication,
- * requires_sharding
+ * requires_sharding,
+ * multiversion_incompatible
* ]
*/
(function() {
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index ea0817030cc..f06e89c7c3d 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -510,6 +510,14 @@ env.Library(
)
env.Library(
+ target='change_streams_cluster_parameter',
+ source=['change_streams_cluster_parameter.idl', 'change_streams_cluster_parameter.cpp'],
+ LIBDEPS=[
+ '$BUILD_DIR/mongo/idl/cluster_server_parameter',
+ ],
+)
+
+env.Library(
target='change_stream_change_collection_manager',
source=[
'change_stream_change_collection_manager.cpp',
@@ -2508,6 +2516,7 @@ env.Library(
'$BUILD_DIR/mongo/client/clientdriver_minimal',
'$BUILD_DIR/mongo/db/change_stream_change_collection_manager',
'$BUILD_DIR/mongo/db/change_stream_options_manager',
+ '$BUILD_DIR/mongo/db/change_streams_cluster_parameter',
'$BUILD_DIR/mongo/db/pipeline/change_stream_expired_pre_image_remover',
'$BUILD_DIR/mongo/idl/cluster_server_parameter',
'$BUILD_DIR/mongo/idl/cluster_server_parameter_op_observer',
@@ -2680,6 +2689,7 @@ if wiredtiger:
source=[
'cancelable_operation_context_test.cpp',
'catalog_raii_test.cpp',
+ 'change_streams_cluster_parameter_test.cpp',
'client_strand_test.cpp',
'client_context_test.cpp',
'collection_index_usage_tracker_test.cpp',
@@ -2755,6 +2765,7 @@ if wiredtiger:
'$BUILD_DIR/mongo/db/catalog/import_collection_oplog_entry',
'$BUILD_DIR/mongo/db/catalog/index_build_entry_idl',
'$BUILD_DIR/mongo/db/catalog/local_oplog_info',
+ '$BUILD_DIR/mongo/db/change_streams_cluster_parameter',
'$BUILD_DIR/mongo/db/mongohasher',
'$BUILD_DIR/mongo/db/pipeline/change_stream_expired_pre_image_remover',
'$BUILD_DIR/mongo/db/query/common_query_enums_and_helpers',
diff --git a/src/mongo/db/change_streams_cluster_parameter.cpp b/src/mongo/db/change_streams_cluster_parameter.cpp
new file mode 100644
index 00000000000..c0ac9577f2e
--- /dev/null
+++ b/src/mongo/db/change_streams_cluster_parameter.cpp
@@ -0,0 +1,62 @@
+/**
+ * Copyright (C) 2022-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kQuery
+
+#include "mongo/db/change_streams_cluster_parameter.h"
+
+#include "mongo/base/status.h"
+#include "mongo/db/change_streams_cluster_parameter_gen.h"
+#include "mongo/logv2/log.h"
+namespace mongo {
+
+Status validateChangeStreamsClusterParameter(
+ const ChangeStreamsClusterParameterStorage& clusterParameter) {
+ LOGV2_DEBUG(6594801,
+ 1,
+ "Validating change streams cluster parameter",
+ "enabled"_attr = clusterParameter.getEnabled(),
+ "expireAfterSeconds"_attr = clusterParameter.getExpireAfterSeconds());
+ if (clusterParameter.getEnabled()) {
+ if (clusterParameter.getExpireAfterSeconds() <= 0) {
+ return Status(ErrorCodes::BadValue,
+ "Expected a positive integer for 'expireAfterSeconds' field if 'enabled' "
+ "field is true");
+ }
+ } else {
+ if (clusterParameter.getExpireAfterSeconds() != 0) {
+ return Status(
+ ErrorCodes::BadValue,
+ "Expected a zero value for 'expireAfterSeconds' if 'enabled' field is false");
+ }
+ }
+ return Status::OK();
+}
+
+} // namespace mongo
diff --git a/src/mongo/db/change_streams_cluster_parameter.h b/src/mongo/db/change_streams_cluster_parameter.h
new file mode 100644
index 00000000000..ebeedaa0e8b
--- /dev/null
+++ b/src/mongo/db/change_streams_cluster_parameter.h
@@ -0,0 +1,42 @@
+/**
+ * Copyright (C) 2022-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#pragma once
+
+#include "mongo/base/status.h"
+namespace mongo {
+
+class ChangeStreamsClusterParameterStorage;
+
+/**
+ * Validates 'changeStreams' cluster-wide parameter.
+ */
+Status validateChangeStreamsClusterParameter(
+ const ChangeStreamsClusterParameterStorage& clusterParameter);
+} // namespace mongo
diff --git a/src/mongo/db/change_streams_cluster_parameter.idl b/src/mongo/db/change_streams_cluster_parameter.idl
new file mode 100644
index 00000000000..74563d47752
--- /dev/null
+++ b/src/mongo/db/change_streams_cluster_parameter.idl
@@ -0,0 +1,64 @@
+# Copyright (C) 2022-present MongoDB, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the Server Side Public License, version 1,
+# as published by MongoDB, Inc.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# Server Side Public License for more details.
+#
+# You should have received a copy of the Server Side Public License
+# along with this program. If not, see
+# <http://www.mongodb.com/licensing/server-side-public-license>.
+#
+# As a special exception, the copyright holders give permission to link the
+# code of portions of this program with the OpenSSL library under certain
+# conditions as described in each individual source file and distribute
+# linked combinations including the program with the OpenSSL library. You
+# must comply with the Server Side Public License in all respects for
+# all of the code used other than as permitted herein. If you modify file(s)
+# with this exception, you may extend this exception to your version of the
+# file(s), but you are not obligated to do so. If you do not wish to do so,
+# delete this exception statement from your version. If you delete this
+# exception statement from all source files in the program, then also delete
+# it in the license file.
+#
+
+global:
+ cpp_namespace: "mongo"
+ cpp_includes:
+ - "mongo/db/change_streams_cluster_parameter.h"
+
+imports:
+ - "mongo/idl/basic_types.idl"
+ - "mongo/idl/cluster_server_parameter.idl"
+
+structs:
+ ChangeStreamsClusterParameterStorage:
+ description: "A specification for the 'changeStreams' cluster-wide configuration parameter
+ type."
+ inline_chained_structs: true
+ chained_structs:
+ ClusterServerParameter: clusterServerParameter
+ fields:
+ enabled:
+ description: "Enable or disable change streams."
+ type: bool
+ default: false
+ expireAfterSeconds:
+ description: "The number of seconds to retain the change events. This value will be a
+ non-zero positive value if the change stream is enabled and a zero value if the change
+ stream is disabled."
+ type: safeInt64
+ default: 0
+
+server_parameters:
+ changeStreams:
+ description: "The cluster-wide configuration parameter for the change stream in the serverless."
+ set_at: cluster
+ cpp_vartype: ChangeStreamsClusterParameterStorage
+ cpp_varname: gChangeStreamsClusterParameter
+ validator:
+ callback: validateChangeStreamsClusterParameter
diff --git a/src/mongo/db/change_streams_cluster_parameter_test.cpp b/src/mongo/db/change_streams_cluster_parameter_test.cpp
new file mode 100644
index 00000000000..80ef8d71da7
--- /dev/null
+++ b/src/mongo/db/change_streams_cluster_parameter_test.cpp
@@ -0,0 +1,78 @@
+/**
+ * Copyright (C) 2022-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#include "mongo/db/change_streams_cluster_parameter.h"
+#include "mongo/db/change_streams_cluster_parameter_gen.h"
+#include "mongo/unittest/unittest.h"
+
+namespace mongo {
+namespace {
+
+
+TEST(ValidateChangeStreamsClusterParameter, EnabledWithSuccess) {
+ ChangeStreamsClusterParameterStorage changeStreamClusterParam;
+ changeStreamClusterParam.setEnabled(true);
+ changeStreamClusterParam.setExpireAfterSeconds(3600);
+ auto result = validateChangeStreamsClusterParameter(changeStreamClusterParam);
+ ASSERT_TRUE(result.isOK());
+}
+
+TEST(ValidateChangeStreamsClusterParameter, EnabledWithNonPositiveExpireAfterSeconds) {
+ ChangeStreamsClusterParameterStorage changeStreamClusterParam;
+ changeStreamClusterParam.setEnabled(true);
+ changeStreamClusterParam.setExpireAfterSeconds(0);
+ auto resultZero = validateChangeStreamsClusterParameter(changeStreamClusterParam);
+ ASSERT_EQ(resultZero.code(), ErrorCodes::BadValue);
+
+ changeStreamClusterParam.setExpireAfterSeconds(-1);
+ auto resultNegative = validateChangeStreamsClusterParameter(changeStreamClusterParam);
+ ASSERT_EQ(resultNegative.code(), ErrorCodes::BadValue);
+}
+
+TEST(ValidateChangeStreamsClusterParameter, DisabledWithSuccess) {
+ ChangeStreamsClusterParameterStorage changeStreamClusterParam;
+ changeStreamClusterParam.setEnabled(false);
+ auto resultDefault = validateChangeStreamsClusterParameter(changeStreamClusterParam);
+ ASSERT_TRUE(resultDefault.isOK());
+
+ changeStreamClusterParam.setExpireAfterSeconds(0);
+ auto resultZero = validateChangeStreamsClusterParameter(changeStreamClusterParam);
+ ASSERT_TRUE(resultDefault.isOK());
+}
+
+TEST(ValidateChangeStreamsClusterParameter, DisabledWithNonZeroExpireAfterSeconds) {
+ ChangeStreamsClusterParameterStorage changeStreamClusterParam;
+ changeStreamClusterParam.setEnabled(false);
+ changeStreamClusterParam.setExpireAfterSeconds(1);
+ auto result = validateChangeStreamsClusterParameter(changeStreamClusterParam);
+ ASSERT_EQ(result.code(), ErrorCodes::BadValue);
+}
+
+} // namespace
+} // namespace mongo
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index 1998f44dc5e..80cef8dfc81 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -528,6 +528,7 @@ env.Library(
'$BUILD_DIR/mongo/db/audit',
'$BUILD_DIR/mongo/db/auth/authmongos',
'$BUILD_DIR/mongo/db/change_stream_options_manager',
+ '$BUILD_DIR/mongo/db/change_streams_cluster_parameter',
'$BUILD_DIR/mongo/db/commands/rwc_defaults_commands',
'$BUILD_DIR/mongo/db/ftdc/ftdc_mongos',
'$BUILD_DIR/mongo/db/process_health/fault_manager',