Skip to content

Commit b99e495

Browse files
pierlauroMongoDB Bot
authored andcommitted
SERVER-102076 Make ServerParameter conditions operation FCV aware (#44101)
GitOrigin-RevId: 8a44d322e3dffdb5803a8f0fab260b9cbe3e118b
1 parent 71654c4 commit b99e495

File tree

11 files changed

+21
-11
lines changed

11 files changed

+21
-11
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,7 @@ WORKSPACE.bazel @10gen/devprod-build @svc-auto-approve-bot
19121912
/src/mongo/db/commands/**/validate.cpp @10gen/server-validate @svc-auto-approve-bot
19131913
/src/mongo/db/commands/**/vote*index_build* @10gen/server-index-builds @svc-auto-approve-bot
19141914
/src/mongo/db/commands/**/rotate_certificates* @10gen/server-security @svc-auto-approve-bot
1915+
/src/mongo/db/commands/**/parameters.cpp @10gen/server-security @svc-auto-approve-bot
19151916
/src/mongo/db/commands/**/profile* @10gen/query-integration-observability @svc-auto-approve-bot
19161917
/src/mongo/db/commands/**/set_profiling_filter_globally_cmd* @10gen/query-integration-observability @svc-auto-approve-bot
19171918
/src/mongo/db/commands/**/top_command.cpp @10gen/query-integration-observability @svc-auto-approve-bot

src/mongo/db/cluster_parameters/cluster_server_parameter_server_status.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ std::set<std::string> getDefaultReportedParameters() {
3838
return {"pauseMigrationsDuringMultiUpdates"};
3939
}
4040

41-
bool isParameterSet(ServerParameter* param) {
41+
bool isParameterSet(OperationContext* opCtx, ServerParameter* param) {
4242
if (!param) {
4343
return false;
4444
}
45-
if (!param->isEnabled()) {
45+
if (!param->isEnabled(VersionContext::getDecoration(opCtx))) {
4646
return false;
4747
}
4848
if (param->getClusterParameterTime(boost::none) == LogicalTime::kUninitialized) {
@@ -73,7 +73,7 @@ BSONObj ClusterServerParameterServerStatus::_getParametersToReport(OperationCont
7373
BSONObjBuilder mapBuilder;
7474
for (const auto& name : _reportedParameters) {
7575
auto param = _clusterParameters->getIfExists(name);
76-
if (!isParameterSet(param)) {
76+
if (!isParameterSet(opCtx, param)) {
7777
continue;
7878
}
7979
BSONObjBuilder elementBuilder(mapBuilder.subobjStart(name));

src/mongo/db/cluster_parameters/get_cluster_parameter_invocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ GetClusterParameterInvocation::retrieveRequestedParameters(
6868

6969
// For each parameter, generate a BSON representation of it and retrieve its name.
7070
auto makeBSON = [&](ServerParameter* requestedParameter, bool skipOnError) {
71-
if (!requestedParameter->isEnabled()) {
71+
if (!requestedParameter->isEnabled(VersionContext::getDecoration(opCtx))) {
7272
uassert(ErrorCodes::BadValue,
7373
str::stream() << "Server parameter: '" << requestedParameter->name()
7474
<< "' is disabled",

src/mongo/db/cluster_parameters/set_cluster_parameter_invocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ std::pair<BSONObj, BSONObj> SetClusterParameterInvocation::normalizeParameter(
129129

130130
uassert(ErrorCodes::BadValue,
131131
str::stream() << "Server parameter: '" << sp->name() << "' is disabled",
132-
skipValidation || sp->isEnabled());
132+
skipValidation || sp->isEnabled(VersionContext::getDecoration(opCtx)));
133133

134134
Timestamp clusterTime =
135135
clusterParameterTime ? *clusterParameterTime : _dbService.getUpdateClusterTime(opCtx);

src/mongo/db/commands/OWNERS.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ filters:
6060
- "rotate_certificates*":
6161
approvers:
6262
- 10gen/server-security
63+
- "parameters.cpp":
64+
approvers:
65+
- 10gen/server-security
6366
- "profile*":
6467
approvers:
6568
- 10gen/query-integration-observability

src/mongo/db/commands/parameters.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class CmdGet : public BasicCommand {
292292
for (ServerParameter::Map::const_iterator i = m.begin(); i != m.end(); ++i) {
293293
// Skip any parameters that should be filtered out according to the command options, as
294294
// well as any disabled parameters.
295-
if (!i->second->isEnabled() ||
295+
if (!i->second->isEnabled(VersionContext::getDecoration(opCtx)) ||
296296
(requireNameMatch && !cmdObj.hasElement(i->first.c_str())) ||
297297
(requireRuntimeSettable && !i->second->allowedToChangeAtRuntime()) ||
298298
(requireStartupSettable && !i->second->allowedToChangeAtStartup()) ||
@@ -398,7 +398,7 @@ class CmdSet : public BasicCommand {
398398
uassert(ErrorCodes::InvalidOptions,
399399
str::stream() << "Server parameter: '" << foundParameter->second->name()
400400
<< "' is disabled",
401-
foundParameter->second->isEnabled());
401+
foundParameter->second->isEnabled(VersionContext::getDecoration(opCtx)));
402402

403403
// Make sure we are allowed to change this parameter
404404
uassert(ErrorCodes::IllegalOperation,

src/mongo/db/feature_flag.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void FCVGatedFeatureFlagBase::appendFlagValueAndMetadata(BSONObjBuilder& flagBui
181181

182182
auto fcvSnapshot = serverGlobalParams.featureCompatibility.acquireFCVSnapshot();
183183
if (fcvSnapshot.isVersionInitialized()) {
184-
// TODO (SERVER-102076): Use VersionContext from opCtx instead of
184+
// TODO (SERVER-114119): Use VersionContext from opCtx instead of
185185
// kVersionContextIgnored_UNSAFE.
186186
flagBuilder.append("currentlyEnabled",
187187
isEnabled(kVersionContextIgnored_UNSAFE, fcvSnapshot));

src/mongo/db/server_options_helpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Status validateBaseOptions(const moe::Environment& params) {
165165
str::stream() << "Unknown --setParameter '" << setParam.first << "'"};
166166
}
167167

168-
if (!param->isEnabled()) {
168+
if (!param->isEnabled(kNoVersionContext)) {
169169
return {ErrorCodes::BadValue,
170170
str::stream() << "--setParameter '" << setParam.first
171171
<< "' only available when used with 'enableTestCommands'"};

src/mongo/db/server_parameter.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,12 @@ class MONGO_MOD_OPEN ServerParameter {
299299
*/
300300
bool enable();
301301

302-
bool isEnabled() const {
303-
const auto fcvSnapshot = serverGlobalParams.featureCompatibility.acquireFCVSnapshot();
302+
bool isEnabled(const VersionContext& vCtx) const {
303+
const auto optFcvSnapshot = vCtx.getOperationFCV(VersionContext::Passkey());
304+
305+
const auto fcvSnapshot = optFcvSnapshot.has_value()
306+
? *optFcvSnapshot
307+
: serverGlobalParams.featureCompatibility.acquireFCVSnapshot();
304308
return isEnabledOnVersion(
305309
fcvSnapshot.isVersionInitialized()
306310
? fcvSnapshot.getVersion()

src/mongo/db/version_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class VersionContext {
135135
friend class VersionContextTest;
136136
friend class FCVGatedFeatureFlagBase;
137137
friend class ShardingDDLCoordinator;
138+
friend class ServerParameter;
138139
Passkey() = default;
139140
~Passkey() = default;
140141
};

0 commit comments

Comments
 (0)