SERVER-107176 Introduce placeholder configureBackgroundTask command (#38181)

GitOrigin-RevId: cbba465fa485a9e44b873ed5236a519b666696eb
This commit is contained in:
Pol Piñol Castuera 2025-07-15 10:17:47 +02:00 committed by MongoDB Bot
parent b80e9b6c22
commit e77deabd36
20 changed files with 381 additions and 0 deletions

2
.github/CODEOWNERS vendored
View File

@ -1373,6 +1373,7 @@ WORKSPACE.bazel @10gen/devprod-build @svc-auto-approve-bot
/jstests/sharding/**/addShard* @10gen/server-catalog-and-routing @svc-auto-approve-bot
/jstests/sharding/**/custom_write_concern.js @10gen/server-catalog-and-routing @svc-auto-approve-bot
/jstests/sharding/**/check_metadata* @10gen/server-catalog-and-routing @svc-auto-approve-bot
/jstests/sharding/**/*configure_background_tasks* @10gen/server-catalog-and-routing @svc-auto-approve-bot
/jstests/sharding/**/start_shard_draining* @10gen/server-catalog-and-routing @svc-auto-approve-bot
/jstests/sharding/**/replica_set_to_csrs_promotion.js @10gen/server-catalog-and-routing @svc-auto-approve-bot
@ -1704,6 +1705,7 @@ WORKSPACE.bazel @10gen/devprod-build @svc-auto-approve-bot
/src/mongo/db/commands/**/async_command_execution_test.* @10gen/server-programmability @svc-auto-approve-bot
/src/mongo/db/commands/**/authentication_commands.* @10gen/server-security @svc-auto-approve-bot
/src/mongo/db/commands/**/buildinfo_common.* @10gen/server-programmability @svc-auto-approve-bot
/src/mongo/db/commands/**/configure_background_task* @10gen/server-catalog-and-routing @svc-auto-approve-bot
/src/mongo/db/commands/**/*cluster*parameter* @10gen/server-catalog-and-routing @svc-auto-approve-bot
/src/mongo/db/commands/**/cluster_server_parameter_cmds.idl @10gen/server-security @svc-auto-approve-bot
/src/mongo/db/commands/**/collmod_cmd.cpp @10gen/server-catalog-and-routing @svc-auto-approve-bot

View File

@ -2805,6 +2805,49 @@ export const authCommandsLib = {
}
]
},
{
testname: "configureBackgroundTask",
command: {configureBackgroundTask: 1, task: "ttlMonitor", mode: "enabled"},
skipUnlessReplicaSet: true,
testcases: [
{
runOnDb: adminDbName,
roles: {clusterManager: 1, clusterAdmin: 1, root: 1, __system: 1}
},
{
runOnDb: adminDbName,
privileges: [{resource: {cluster: true}, actions: ["configureBackgroundTask"]}]
},
{
runOnDb: adminDbName,
privileges: [
{resource: {db: "", collection: ""}, actions: ["configureBackgroundTask"]}
],
expectAuthzFailure: true
},
{
runOnDb: adminDbName,
privileges: [{
resource: {db: adminDbName, collection: ""},
actions: ["configureBackgroundTask"]
}],
expectAuthzFailure: true
},
{
runOnDb: adminDbName,
privileges: [{
resource: {db: adminDbName, collection: "coll"},
actions: ["configureBackgroundTask"]
}],
expectAuthzFailure: true
},
{
runOnDb: adminDbName,
privileges: [{resource: {cluster: true}, actions: ["convertToCapped"]}],
expectAuthzFailure: true
}
]
},
{
testname: "collMod",
command: {collMod: "foo"},

View File

@ -315,6 +315,7 @@ let viewsCommandTests = {
commitTransaction: {skip: isUnrelated},
compact: {command: {compact: "view", force: true}, expectFailure: true, skipSharded: true},
compactStructuredEncryptionData: {skip: isUnrelated},
configureBackgroundTask: {skip: isUnrelated},
configureFailPoint: {skip: isUnrelated},
configureCollectionBalancing: {skip: isUnrelated},
configureQueryAnalyzer: {

View File

@ -695,6 +695,7 @@ const wcCommandsTests = {
},
compact: {skip: "does not accept write concern"},
compactStructuredEncryptionData: {skip: "does not accept write concern"},
configureBackgroundTask: {skip: "does not accept write concern"},
configureCollectionBalancing: {skip: "does not accept write concern"},
configureFailPoint: {skip: "internal command"},
configureQueryAnalyzer: {skip: "does not accept write concern"},
@ -3655,6 +3656,7 @@ const wcTimeseriesViewsCommandsTests = {
commitTransaction: {skip: "not supported on timeseries views"},
compact: {skip: "does not accept write concern"},
compactStructuredEncryptionData: {skip: "does not accept write concern"},
configureBackgroundTask: {skip: "does not accept write concern"},
configureCollectionBalancing: {skip: "does not accept write concern"},
configureFailPoint: {skip: "internal command"},
configureQueryAnalyzer: {skip: "does not accept write concern"},

View File

@ -520,6 +520,11 @@ const allCommands = {
},
},
compactStructuredEncryptionData: {skip: "requires additional encrypted collection setup"},
configureBackgroundTask: {
command: {configureBackgroundTask: 1, task: "ttlMonitor", mode: "enabled"},
isAdminCommand: true,
doesNotRunOnMongos: true,
},
configureFailPoint: {skip: isAnInternalCommand},
configureCollectionBalancing: {
setUp: function(conn) {

View File

@ -210,6 +210,7 @@ const allCommands = {
commitTransaction: {skip: isPrimaryOnly},
compact: {skip: isNotAUserDataRead},
compactStructuredEncryptionData: {skip: isPrimaryOnly},
configureBackgroundTask: {skip: isPrimaryOnly},
configureFailPoint: {skip: isNotAUserDataRead},
configureCollectionBalancing: {skip: isPrimaryOnly},
configureQueryAnalyzer: {skip: isPrimaryOnly},

View File

@ -55,6 +55,9 @@ filters:
- "check_metadata*":
approvers:
- 10gen/server-catalog-and-routing
- "*configure_background_tasks*":
approvers:
- 10gen/server-catalog-and-routing
- "start_shard_draining*":
approvers:
- 10gen/server-catalog-and-routing

View File

@ -405,6 +405,11 @@ const allCommands = {
},
},
compactStructuredEncryptionData: {skip: "requires additional encrypted collection setup"},
configureBackgroundTask: {
command: {configureBackgroundTask: 1, task: "ttlMonitor", mode: "enabled"},
shouldFail: false,
isAdminCommand: true,
},
configureFailPoint: {skip: isAnInternalCommand},
configureCollectionBalancing: {skip: requiresMongoS},
configureQueryAnalyzer: {skip: requiresMongoS},

View File

@ -0,0 +1,108 @@
/*
* Tests configureBackgroundTask command.
*
* @tags: [
* requires_fcv_82,
* ]
*/
import {ShardingTest} from "jstests/libs/shardingtest.js";
const st = new ShardingTest({shards: 2});
const dbName = jsTestName();
(function testInvalidParameters() {
jsTestLog("Testing invalid parameters for configureBackgroundTask command");
assert.commandFailedWithCode(
st.shard0.adminCommand({configureBackgroundTask: 1, task: "invalidTask", mode: "enabled"}),
ErrorCodes.BadValue);
assert.commandFailedWithCode(
st.shard0.adminCommand(
{configureBackgroundTask: 1, task: "ttlMonitor", mode: "invalidMode"}),
ErrorCodes.BadValue);
assert.commandFailedWithCode(
st.shard0.getDB(dbName).runCommand(
{configureBackgroundTask: 1, task: "ttlMonitor", mode: "enabled"}),
ErrorCodes.Unauthorized);
assert.commandFailedWithCode(st.shard0.adminCommand({
configureBackgroundTask: 1,
task: "ttlMonitor",
mode: "enabled",
throttleDelayMs: "invalidDelay"
}),
ErrorCodes.TypeMismatch);
assert.commandFailedWithCode(st.shard0.adminCommand({
configureBackgroundTask: 1,
task: "ttlMonitor",
mode: "throttled",
throttleDelayMs: 10.5
}),
ErrorCodes.TypeMismatch);
assert.commandFailedWithCode(st.shard0.adminCommand({
configureBackgroundTask: 1,
task: "ttlMonitor",
mode: "throttled",
throttleDelayMs: NumberInt(-100)
}),
ErrorCodes.IllegalOperation);
})();
(function testTTLMonitor() {
jsTestLog("Testing TTL monitor task");
assert.commandWorked(
st.shard0.adminCommand({configureBackgroundTask: 1, task: "ttlMonitor", mode: "disabled"}));
assert.commandWorked(
st.shard0.adminCommand({configureBackgroundTask: 1, task: "ttlMonitor", mode: "enabled"}));
assert.commandWorked(st.shard0.adminCommand({
configureBackgroundTask: 1,
task: "ttlMonitor",
mode: "throttled",
throttleDelayMs: NumberInt(500)
}));
})();
(function testRangeDeleter() {
jsTestLog("Testing range deleter task");
assert.commandWorked(st.shard0.adminCommand(
{configureBackgroundTask: 1, task: "rangeDeleter", mode: "enabled"}));
assert.commandWorked(st.shard0.adminCommand(
{configureBackgroundTask: 1, task: "rangeDeleter", mode: "disabled"}));
assert.commandWorked(st.shard0.adminCommand({
configureBackgroundTask: 1,
task: "rangeDeleter",
mode: "throttled",
throttleDelayMs: NumberInt(500)
}));
})();
(function testMigrations() {
jsTestLog("Testing migrations task");
assert.commandWorked(
st.shard0.adminCommand({configureBackgroundTask: 1, task: "migrations", mode: "enabled"}));
assert.commandWorked(
st.shard0.adminCommand({configureBackgroundTask: 1, task: "migrations", mode: "disabled"}));
assert.commandFailedWithCode(st.shard0.adminCommand({
configureBackgroundTask: 1,
task: "migrations",
mode: "throttled",
throttleDelayMs: NumberInt(500)
}),
ErrorCodes.IllegalOperation);
})();
st.stop();

View File

@ -366,6 +366,7 @@ let testCases = {
},
compact: {skip: "does not accept read or write concern"},
compactStructuredEncryptionData: {skip: "does not accept read or write concern"},
configureBackgroundTask: {skip: "does not accept read or write concern"},
configureCollectionBalancing: {skip: "does not accept read or write concern"},
configureFailPoint: {skip: "does not accept read or write concern"},
configureQueryAnalyzer: {skip: "does not accept read or write concern"},

View File

@ -175,6 +175,7 @@ let testCases = {
commitTransaction: {skip: "primary only"},
compact: {skip: "does not return user data"},
compactStructuredEncryptionData: {skip: "does not return user data"},
configureBackgroundTask: {skip: "primary only"},
configureCollectionBalancing: {skip: "does not return user data"},
configureFailPoint: {skip: "does not return user data"},
configureQueryAnalyzer: {skip: "does not return user data"},

View File

@ -180,6 +180,7 @@ let testCases = {
collStats: {skip: "does not return user data"},
compact: {skip: "does not return user data"},
compactStructuredEncryptionData: {skip: "does not return user data"},
configureBackgroundTask: {skip: "primary only"},
configureFailPoint: {skip: "does not return user data"},
configureQueryAnalyzer: {skip: "does not return user data"},
connPoolStats: {skip: "does not return user data"},

View File

@ -185,6 +185,7 @@ let testCases = {
commitTransaction: {skip: "primary only"},
compact: {skip: "does not return user data"},
compactStructuredEncryptionData: {skip: "does not return user data"},
configureBackgroundTask: {skip: "primary only"},
configureCollectionBalancing: {skip: "does not return user data"},
configureFailPoint: {skip: "does not return user data"},
configureQueryAnalyzer: {skip: "does not return user data"},

View File

@ -517,6 +517,7 @@ ddl:
- src/mongo/s/request_types/migration_blocking_operation*
- src/mongo/s/migration_blocking_operation*
- src/mongo/db/metadata_consistency_types.idl
- src/mongo/db/commands/configure_background_task_command*
- src/mongo/db/commands/shuffle_list_command_results*
- src/mongo/db/s/shardsvr_validate_shard_key_candidate.cpp
- src/mongo/db/s/config/configsvr_run_restore*

View File

@ -73,6 +73,7 @@ enums:
closeAllDatabases: "closeAllDatabases" # Deprecated (backwards compatibility)
collMod: "collMod"
collStats: "collStats"
configureBackgroundTask: "configureBackgroundTask"
compact: "compact"
compactStructuredEncryptionData: "compactStructuredEncryptionData"
configureQueryAnalyzer: "configureQueryAnalyzer"

View File

@ -370,6 +370,7 @@ roles:
- checkMetadataConsistency
- transitionFromDedicatedConfigServer
- transitionToDedicatedConfigServer
- configureBackgroundTask
- matchType: any_normal
actions: &clusterManagerRoleDatabaseActions

View File

@ -548,6 +548,15 @@ idl_generator(
],
)
idl_generator(
name = "configure_background_task_command_gen",
src = "configure_background_task_command.idl",
deps = [
"//src/mongo/db:basic_types_gen",
"//src/mongo/idl:generic_argument_gen",
],
)
mongo_cc_library(
name = "list_collections_filter",
srcs = [
@ -1392,6 +1401,8 @@ mongo_cc_library(
name = "standalone",
srcs = [
"collmod_cmd.cpp",
"configure_background_task_command.cpp",
"configure_background_task_command_gen",
"create_command.cpp",
"create_indexes_cmd.cpp",
"dbcommands.cpp",

View File

@ -9,6 +9,9 @@ filters:
- "buildinfo_common.*":
approvers:
- 10gen/server-programmability
- "configure_background_task*":
approvers:
- 10gen/server-catalog-and-routing
- "*cluster*parameter*":
approvers:
- 10gen/server-catalog-and-routing

View File

@ -0,0 +1,120 @@
/**
* Copyright (C) 2025-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/base/error_codes.h"
#include "mongo/db/auth/action_type.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/auth/privilege.h"
#include "mongo/db/auth/resource_pattern.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/configure_background_task_command_gen.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/service_context.h"
#include "mongo/util/assert_util.h"
#include <string>
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
namespace mongo {
namespace {
class ConfigureBackgroundTaskCommand final : public TypedCommand<ConfigureBackgroundTaskCommand> {
public:
using Request = ConfigureBackgroundTask;
AllowedOnSecondary secondaryAllowed(ServiceContext*) const override {
return AllowedOnSecondary::kNever;
}
bool adminOnly() const override {
return true;
}
std::string help() const override {
return "Configures background tasks with enabled, disabled or throttled mode.";
}
class Invocation final : public InvocationBase {
public:
using InvocationBase::InvocationBase;
void typedRun(OperationContext* opCtx) {
if (request().getMode() == ConfigureBackgroundTaskModeEnum::kThrottled) {
uassert(ErrorCodes::IllegalOperation,
"Throttle delay can only be set in throttled mode",
request().getThrottleDelayMs().has_value());
uassert(ErrorCodes::IllegalOperation,
"Throttle delay can only be set in throttled mode",
request().getThrottleDelayMs().get() >= 0);
}
if (request().getTask() == ConfigureBackgroundTaskControlEnum::kMigrations) {
uassert(ErrorCodes::IllegalOperation,
"Migrations task can't be set in throttled mode",
request().getMode() != ConfigureBackgroundTaskModeEnum::kThrottled);
}
if (request().getTask() == ConfigureBackgroundTaskControlEnum::kRangeDeleter ||
request().getTask() == ConfigureBackgroundTaskControlEnum::kMigrations) {
uassert(ErrorCodes::IllegalOperation,
"The range deleter and migrations task can not be configured in a "
"non-sharded toplogy",
ShardingState::get(opCtx)->enabled());
}
}
private:
bool supportsWriteConcern() const override {
return false;
}
NamespaceString ns() const override {
return NamespaceString(request().getDbName());
}
void doCheckAuthorization(OperationContext* opCtx) const override {
uassert(ErrorCodes::Unauthorized,
"Unauthorized",
AuthorizationSession::get(opCtx->getClient())
->isAuthorizedForActionsOnResource(
ResourcePattern::forClusterResource(request().getDbName().tenantId()),
ActionType::configureBackgroundTask));
}
};
};
MONGO_REGISTER_COMMAND(ConfigureBackgroundTaskCommand).forShard();
} // namespace
} // namespace mongo

View File

@ -0,0 +1,70 @@
# Copyright (C) 2025-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"
imports:
- "mongo/db/basic_types.idl"
enums:
ConfigureBackgroundTaskControl:
description: "Available background tasks to control with the command"
type: string
values:
kTTLMonitor: "ttlMonitor"
kRangeDeleter: "rangeDeleter"
kMigrations: "migrations"
ConfigureBackgroundTaskMode:
description: "Available operational states to set to the background task"
type: string
values:
kEnabled: "enabled"
kDisabled: "disabled"
kThrottled: "throttled"
commands:
configureBackgroundTask:
description: "Command to control background tasks"
command_name: configureBackgroundTask
cpp_name: ConfigureBackgroundTask
api_version: ""
namespace: ignored
strict: false
fields:
task:
type: ConfigureBackgroundTaskControl
description: "Background task to control"
mode:
type: ConfigureBackgroundTaskMode
description: "Operating state of the chosen task"
throttleDelayMs:
type: int
description: "Pause length between work cycles when throttling"
optional: true