SERVER-114004 Add command stub for _shardsvrReshardRecipientCriticalSectionStarted (#44064)

GitOrigin-RevId: be397396d296fc391ba279cc6ec769f576d6ebb1
This commit is contained in:
Cheahuychou Mao 2025-11-19 16:53:47 -05:00 committed by MongoDB Bot
parent cfcc2e4bd9
commit 11f2f90d6a
13 changed files with 216 additions and 6 deletions

View File

@ -736,6 +736,12 @@ const internalCommandsMap = {
donorShards: [], donorShards: [],
}, },
}, },
_shardsvrReshardRecipientCriticalSectionStarted: {
testname: "_shardsvrReshardRecipientCriticalSectionStarted",
command: {
_shardsvrReshardRecipientCriticalSectionStarted: UUID(),
},
},
_shardsvrRefineCollectionShardKey: { _shardsvrRefineCollectionShardKey: {
testname: "_shardsvrRefineCollectionShardKey", testname: "_shardsvrRefineCollectionShardKey",
command: {_shardsvrRefineCollectionShardKey: "test.x", newShardKey: {}}, command: {_shardsvrRefineCollectionShardKey: "test.x", newShardKey: {}},

View File

@ -3513,6 +3513,23 @@ export const authCommandsLib = {
{runOnDb: secondDbName, roles: {}}, {runOnDb: secondDbName, roles: {}},
], ],
}, },
{
testname: "_shardsvrReshardRecipientCriticalSectionStarted",
command: {
_shardsvrReshardRecipientCriticalSectionStarted: UUID(),
},
skipSharded: true,
testcases: [
{
runOnDb: adminDbName,
roles: {__system: 1},
privileges: [{resource: {cluster: true}, actions: ["internal"]}],
expectFail: true,
},
{runOnDb: firstDbName, roles: {}},
{runOnDb: secondDbName, roles: {}},
],
},
{ {
testname: "clusterCommitTransaction", testname: "clusterCommitTransaction",
command: {clusterCommitTransaction: 1}, command: {clusterCommitTransaction: 1},

View File

@ -206,6 +206,7 @@ let viewsCommandTests = {
_shardsvrReshardingDonorStartChangeStreamsMonitor: {skip: isAnInternalCommand}, _shardsvrReshardingDonorStartChangeStreamsMonitor: {skip: isAnInternalCommand},
_shardsvrReshardingOperationTime: {skip: isAnInternalCommand}, _shardsvrReshardingOperationTime: {skip: isAnInternalCommand},
_shardsvrReshardRecipientClone: {skip: isAnInternalCommand}, _shardsvrReshardRecipientClone: {skip: isAnInternalCommand},
_shardsvrReshardRecipientCriticalSectionStarted: {skip: isAnInternalCommand},
_shardsvrSetAllowMigrations: {skip: isAnInternalCommand}, _shardsvrSetAllowMigrations: {skip: isAnInternalCommand},
_shardsvrResolveView: {skip: isAnInternalCommand}, _shardsvrResolveView: {skip: isAnInternalCommand},
_shardsvrRunSearchIndexCommand: {skip: isAnInternalCommand}, _shardsvrRunSearchIndexCommand: {skip: isAnInternalCommand},

View File

@ -193,6 +193,7 @@ const wcCommandsTests = {
_shardsvrReshardingDonorStartChangeStreamsMonitor: {skip: "internal command"}, _shardsvrReshardingDonorStartChangeStreamsMonitor: {skip: "internal command"},
_shardsvrReshardingOperationTime: {skip: "internal command"}, _shardsvrReshardingOperationTime: {skip: "internal command"},
_shardsvrReshardRecipientClone: {skip: "internal command"}, _shardsvrReshardRecipientClone: {skip: "internal command"},
_shardsvrReshardRecipientCriticalSectionStarted: {skip: "internal command"},
_shardsvrResolveView: {skip: "internal command"}, _shardsvrResolveView: {skip: "internal command"},
_shardsvrRunSearchIndexCommand: {skip: "internal command"}, _shardsvrRunSearchIndexCommand: {skip: "internal command"},
_shardsvrSetAllowMigrations: {skip: "internal command"}, _shardsvrSetAllowMigrations: {skip: "internal command"},
@ -3405,6 +3406,7 @@ const wcTimeseriesViewsCommandsTests = {
_shardsvrReshardingDonorStartChangeStreamsMonitor: {skip: "internal command"}, _shardsvrReshardingDonorStartChangeStreamsMonitor: {skip: "internal command"},
_shardsvrReshardingOperationTime: {skip: "internal command"}, _shardsvrReshardingOperationTime: {skip: "internal command"},
_shardsvrReshardRecipientClone: {skip: "internal command"}, _shardsvrReshardRecipientClone: {skip: "internal command"},
_shardsvrReshardRecipientCriticalSectionStarted: {skip: "internal command"},
_shardsvrResolveView: {skip: "internal command"}, _shardsvrResolveView: {skip: "internal command"},
_shardsvrRunSearchIndexCommand: {skip: "internal command"}, _shardsvrRunSearchIndexCommand: {skip: "internal command"},
_shardsvrSetAllowMigrations: {skip: "internal command"}, _shardsvrSetAllowMigrations: {skip: "internal command"},

View File

@ -144,6 +144,7 @@ const allCommands = {
_shardsvrReshardingDonorStartChangeStreamsMonitor: {skip: isAnInternalCommand}, _shardsvrReshardingDonorStartChangeStreamsMonitor: {skip: isAnInternalCommand},
_shardsvrReshardingOperationTime: {skip: isAnInternalCommand}, _shardsvrReshardingOperationTime: {skip: isAnInternalCommand},
_shardsvrReshardRecipientClone: {skip: isAnInternalCommand}, _shardsvrReshardRecipientClone: {skip: isAnInternalCommand},
_shardsvrReshardRecipientCriticalSectionStarted: {skip: isAnInternalCommand},
_shardsvrRefineCollectionShardKey: {skip: isAnInternalCommand}, _shardsvrRefineCollectionShardKey: {skip: isAnInternalCommand},
_shardsvrSetAllowMigrations: {skip: isAnInternalCommand}, _shardsvrSetAllowMigrations: {skip: isAnInternalCommand},
_shardsvrSetClusterParameter: {skip: isAnInternalCommand}, _shardsvrSetClusterParameter: {skip: isAnInternalCommand},

View File

@ -131,6 +131,7 @@ const allCommands = {
_shardsvrReshardCollection: {skip: isPrimaryOnly}, _shardsvrReshardCollection: {skip: isPrimaryOnly},
_shardsvrReshardingOperationTime: {skip: isPrimaryOnly}, _shardsvrReshardingOperationTime: {skip: isPrimaryOnly},
_shardsvrReshardRecipientClone: {skip: isPrimaryOnly}, _shardsvrReshardRecipientClone: {skip: isPrimaryOnly},
_shardsvrReshardRecipientCriticalSectionStarted: {skip: isPrimaryOnly},
_shardsvrRefineCollectionShardKey: {skip: isPrimaryOnly}, _shardsvrRefineCollectionShardKey: {skip: isPrimaryOnly},
_shardsvrSetAllowMigrations: {skip: isPrimaryOnly}, _shardsvrSetAllowMigrations: {skip: isPrimaryOnly},
_shardsvrSetClusterParameter: {skip: isAnInternalCommand}, _shardsvrSetClusterParameter: {skip: isAnInternalCommand},

View File

@ -140,6 +140,7 @@ const allCommands = {
_shardsvrReshardCollection: {skip: isAnInternalCommand}, _shardsvrReshardCollection: {skip: isAnInternalCommand},
_shardsvrReshardingOperationTime: {skip: isAnInternalCommand}, _shardsvrReshardingOperationTime: {skip: isAnInternalCommand},
_shardsvrReshardRecipientClone: {skip: isAnInternalCommand}, _shardsvrReshardRecipientClone: {skip: isAnInternalCommand},
_shardsvrReshardRecipientCriticalSectionStarted: {skip: isAnInternalCommand},
_shardsvrRefineCollectionShardKey: {skip: isAnInternalCommand}, _shardsvrRefineCollectionShardKey: {skip: isAnInternalCommand},
_shardsvrSetAllowMigrations: {skip: isAnInternalCommand}, _shardsvrSetAllowMigrations: {skip: isAnInternalCommand},
_shardsvrSetClusterParameter: {skip: isAnInternalCommand}, _shardsvrSetClusterParameter: {skip: isAnInternalCommand},

View File

@ -1019,6 +1019,21 @@ const allTestCases = {
_shardsvrRenameIndexMetadata: {skip: "TODO"}, _shardsvrRenameIndexMetadata: {skip: "TODO"},
_shardsvrReshardCollection: {skip: "TODO"}, _shardsvrReshardCollection: {skip: "TODO"},
_shardsvrReshardRecipientClone: {skip: "TODO"}, _shardsvrReshardRecipientClone: {skip: "TODO"},
_shardsvrReshardRecipientCriticalSectionStarted: {
run: {
sendsDbVersion: false,
runsAgainstAdminDb: true,
command: function (dbName, collName) {
return {
_shardsvrReshardRecipientCriticalSectionStarted: UUID(),
};
},
// When the resharding recipient state machine does not exist, we throw
// NotWritablePrimary under the assumption that the request was delayed and the
// node is no longer the primary.
expectedFailureCode: ErrorCodes.NotWritablePrimary,
},
},
_shardsvrReshardingDonorFetchFinalCollectionStats: {skip: "TODO"}, _shardsvrReshardingDonorFetchFinalCollectionStats: {skip: "TODO"},
_shardsvrReshardingDonorStartChangeStreamsMonitor: {skip: "TODO"}, _shardsvrReshardingDonorStartChangeStreamsMonitor: {skip: "TODO"},
_shardsvrReshardingOperationTime: {skip: "TODO"}, _shardsvrReshardingOperationTime: {skip: "TODO"},

View File

@ -55,6 +55,7 @@ export const commandsAddedToMongodSinceLastLTS = [
"_shardsvrRenameIndexMetadata", "_shardsvrRenameIndexMetadata",
"getTrafficRecordingStatus", "getTrafficRecordingStatus",
"_shardsvrReshardRecipientClone", "_shardsvrReshardRecipientClone",
"_shardsvrReshardRecipientCriticalSectionStarted",
"_shardsvrResolveView", "_shardsvrResolveView",
"_configsvrStartShardDraining", "_configsvrStartShardDraining",
"_shardsvrDropIndexesParticipant", "_shardsvrDropIndexesParticipant",

View File

@ -197,6 +197,7 @@ let testCases = {
_shardsvrReshardingDonorStartChangeStreamsMonitor: {skip: "internal command"}, _shardsvrReshardingDonorStartChangeStreamsMonitor: {skip: "internal command"},
_shardsvrReshardingOperationTime: {skip: "internal command"}, _shardsvrReshardingOperationTime: {skip: "internal command"},
_shardsvrReshardRecipientClone: {skip: "internal command"}, _shardsvrReshardRecipientClone: {skip: "internal command"},
_shardsvrReshardRecipientCriticalSectionStarted: {skip: "internal command"},
_shardsvrResolveView: {skip: "internal command"}, _shardsvrResolveView: {skip: "internal command"},
_shardsvrRunSearchIndexCommand: {skip: "internal command"}, _shardsvrRunSearchIndexCommand: {skip: "internal command"},
_shardsvrSetAllowMigrations: {skip: "internal command"}, _shardsvrSetAllowMigrations: {skip: "internal command"},

View File

@ -716,6 +716,7 @@ mongo_cc_library(
"shardsvr_get_stats_for_balancing_command.cpp", "shardsvr_get_stats_for_balancing_command.cpp",
"shardsvr_move_range_command.cpp", "shardsvr_move_range_command.cpp",
"shardsvr_reshard_recipient_clone_cmd.cpp", "shardsvr_reshard_recipient_clone_cmd.cpp",
"shardsvr_reshard_recipient_critical_section_started_cmd.cpp",
"shardsvr_resharding_donor_fetch_final_collection_stats_command.cpp", "shardsvr_resharding_donor_fetch_final_collection_stats_command.cpp",
"shardsvr_resharding_donor_start_change_streams_monitor_command.cpp", "shardsvr_resharding_donor_start_change_streams_monitor_command.cpp",
"shardsvr_resharding_operation_time_command.cpp", "shardsvr_resharding_operation_time_command.cpp",

View File

@ -0,0 +1,151 @@
/**
* 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/bson/bsonmisc.h"
#include "mongo/db/auth/action_type.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/auth/resource_pattern.h"
#include "mongo/db/commands.h"
#include "mongo/db/database_name.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/s/resharding/resharding_donor_recipient_common.h"
#include "mongo/db/s/resharding/resharding_recipient_service.h"
#include "mongo/db/s/resharding/resharding_util.h"
#include "mongo/db/server_options.h"
#include "mongo/db/service_context.h"
#include "mongo/db/topology/cluster_role.h"
#include "mongo/logv2/log.h"
#include "mongo/logv2/log_attr.h"
#include "mongo/logv2/log_component.h"
#include "mongo/rpc/op_msg.h"
#include "mongo/s/request_types/reshard_collection_gen.h"
#include "mongo/s/resharding/common_types_gen.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/future.h"
#include "mongo/util/uuid.h"
#include <memory>
#include <string>
#include <vector>
#include <boost/move/utility_core.hpp>
#include <boost/optional/optional.hpp>
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
namespace mongo {
namespace {
class ShardsvrReshardRecipientCriticalSectionStartedCommand final
: public TypedCommand<ShardsvrReshardRecipientCriticalSectionStartedCommand> {
public:
using Request = ShardsvrReshardRecipientCriticalSectionStarted;
class Invocation final : public InvocationBase {
public:
using InvocationBase::InvocationBase;
void typedRun(OperationContext* opCtx) {
opCtx->setAlwaysInterruptAtStepDownOrUp_UNSAFE();
uassert(
ErrorCodes::IllegalOperation,
"_shardsvrReshardRecipientCriticalSectionStarted can only be run on shard servers",
serverGlobalParams.clusterRole.has(ClusterRole::ShardServer));
if (auto machine = resharding::tryGetReshardingStateMachineAndThrowIfShuttingDown<
ReshardingRecipientService,
ReshardingRecipientService::RecipientStateMachine,
ReshardingRecipientDocument>(opCtx, uuid())) {
LOGV2(11400401,
"Resharding recipient start executing "
"_shardsvrRecipientCriticalSectionStarted command.",
"reshardingUUID"_attr = uuid());
LOGV2(11400402,
"Resharding recipient finished executing "
"_shardsvrRecipientCriticalSectionStarted command.",
"reshardingUUID"_attr = uuid());
} else {
// If state machine does not exist, either this message was delayed and the
// resharding operation is done, or this node is no longer a primary.
uasserted(ErrorCodes::NotWritablePrimary,
"Internal Error: No matching resharding operation.");
}
}
private:
UUID uuid() const {
return request().getCommandParameter();
}
NamespaceString ns() const override {
return {};
}
bool supportsWriteConcern() const override {
return true;
}
void doCheckAuthorization(OperationContext* opCtx) const override {
uassert(ErrorCodes::Unauthorized,
"Unauthorized",
AuthorizationSession::get(opCtx->getClient())
->isAuthorizedForActionsOnResource(
ResourcePattern::forClusterResource(request().getDbName().tenantId()),
ActionType::internal));
}
};
bool skipApiVersionCheck() const override {
// Internal command (server to server).
return true;
}
std::string help() const override {
return "Internal command run by coordinator against recipients to notify them that the "
"critical section has started. Do not call directly.";
}
bool adminOnly() const override {
return true;
}
AllowedOnSecondary secondaryAllowed(ServiceContext*) const override {
return AllowedOnSecondary::kNever;
}
};
MONGO_REGISTER_COMMAND(ShardsvrReshardRecipientCriticalSectionStartedCommand).forShard();
} // namespace
} // namespace mongo

View File

@ -114,8 +114,8 @@ commands:
demoMode: demoMode:
type: optionalBool type: optionalBool
description: >- description: >-
"When set to true, overrides reshardingMinimumOperationDurationMillis "When set to true, overrides reshardingMinimumOperationDurationMillis
and reshardingDelayBeforeRemainingOperationTimeQueryMillis values to 0 and reshardingDelayBeforeRemainingOperationTimeQueryMillis values to 0
for quick demo of reshardCollection operation" for quick demo of reshardCollection operation"
_configsvrReshardCollection: _configsvrReshardCollection:
@ -194,8 +194,8 @@ commands:
demoMode: demoMode:
type: optionalBool type: optionalBool
description: >- description: >-
"When set to true, overrides reshardingMinimumOperationDurationMillis "When set to true, overrides reshardingMinimumOperationDurationMillis
and reshardingDelayBeforeRemainingOperationTimeQueryMillis values to 0 and reshardingDelayBeforeRemainingOperationTimeQueryMillis values to 0
for quick demo of reshardCollection operation" for quick demo of reshardCollection operation"
rewriteCollection: rewriteCollection:
@ -225,8 +225,8 @@ commands:
demoMode: demoMode:
type: optionalBool type: optionalBool
description: >- description: >-
"When set to true, overrides reshardingMinimumOperationDurationMillis "When set to true, overrides reshardingMinimumOperationDurationMillis
and reshardingDelayBeforeRemainingOperationTimeQueryMillis values to 0 and reshardingDelayBeforeRemainingOperationTimeQueryMillis values to 0
for quick demo of reshardCollection operation" for quick demo of reshardCollection operation"
moveCollection: moveCollection:
@ -337,3 +337,15 @@ commands:
approxCopySize: approxCopySize:
type: ReshardingApproxCopySize type: ReshardingApproxCopySize
description: "Not meant to be used directly. Only use internal fields." description: "Not meant to be used directly. Only use internal fields."
_shardsvrReshardRecipientCriticalSectionStarted:
description:
"The internal command run by coordinator against recipients to notify them that the
critical section has started."
command_name: _shardsvrReshardRecipientCriticalSectionStarted
cpp_name: ShardsvrReshardRecipientCriticalSectionStarted
type: uuid
strict: false
namespace: type
reply_type: OkReply
api_version: ""