summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorJason Zhang <jason.zhang@mongodb.com>2022-09-19 15:59:03 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-09-19 17:20:54 +0000
commitd99780adf52c65a2c30727d92b534e6d2190d289 (patch)
tree48efd05dbb1f8d936542e6d0cfdc9253edf6a27c /src/mongo
parentdc9011293fca02542b98ffe1468b62a1f37f4a7f (diff)
downloadmongo-d99780adf52c65a2c30727d92b534e6d2190d289.tar.gz
SERVER-69624 Add _clusterWriteWithoutShardKey command stub
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/s/commands/SConscript1
-rw-r--r--src/mongo/s/commands/cluster_query_without_shard_key_cmd.cpp2
-rw-r--r--src/mongo/s/commands/cluster_write_without_shard_key_cmd.cpp98
-rw-r--r--src/mongo/s/request_types/cluster_commands_without_shard_key.idl23
4 files changed, 121 insertions, 3 deletions
diff --git a/src/mongo/s/commands/SConscript b/src/mongo/s/commands/SConscript
index 05d44aea84f..d0faf09bea5 100644
--- a/src/mongo/s/commands/SConscript
+++ b/src/mongo/s/commands/SConscript
@@ -95,6 +95,7 @@ env.Library(
'cluster_validate_db_metadata_cmd.cpp',
'cluster_whats_my_uri_cmd.cpp',
'cluster_write_cmd_s.cpp',
+ 'cluster_write_without_shard_key_cmd.cpp',
'internal_transactions_test_command_s.cpp',
'kill_sessions_remote.cpp',
'refine_collection_shard_key.idl',
diff --git a/src/mongo/s/commands/cluster_query_without_shard_key_cmd.cpp b/src/mongo/s/commands/cluster_query_without_shard_key_cmd.cpp
index 8b2cfcf2560..f0dd71e84cc 100644
--- a/src/mongo/s/commands/cluster_query_without_shard_key_cmd.cpp
+++ b/src/mongo/s/commands/cluster_query_without_shard_key_cmd.cpp
@@ -53,7 +53,7 @@ public:
"_clusterQueryWithoutShardKey can only be run on Mongos",
isMongos());
- LOGV2(6962400,
+ LOGV2(6962300,
"Running read phase for a write without a shard key.",
"clientWriteRequest"_attr = request().getWriteCmd(),
"stmtIdInBatch"_attr = request().getStmtId());
diff --git a/src/mongo/s/commands/cluster_write_without_shard_key_cmd.cpp b/src/mongo/s/commands/cluster_write_without_shard_key_cmd.cpp
new file mode 100644
index 00000000000..bff43069142
--- /dev/null
+++ b/src/mongo/s/commands/cluster_write_without_shard_key_cmd.cpp
@@ -0,0 +1,98 @@
+/**
+ * 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/auth/authorization_session.h"
+#include "mongo/db/commands.h"
+#include "mongo/db/internal_transactions_feature_flag_gen.h"
+#include "mongo/logv2/log.h"
+#include "mongo/s/is_mongos.h"
+#include "mongo/s/request_types/cluster_commands_without_shard_key_gen.h"
+
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
+
+namespace mongo {
+namespace {
+
+class ClusterWriteWithoutShardKeyCmd : public TypedCommand<ClusterWriteWithoutShardKeyCmd> {
+public:
+ using Request = ClusterWriteWithoutShardKey;
+ using Response = ClusterWriteWithoutShardKeyResponse;
+
+ class Invocation final : public InvocationBase {
+ public:
+ using InvocationBase::InvocationBase;
+
+ Response typedRun(OperationContext* opCtx) {
+ uassert(ErrorCodes::IllegalOperation,
+ "_clusterQueryWithoutShardKey can only be run on Mongos",
+ isMongos());
+
+ LOGV2(6962400,
+ "Running write phase for a write without a shard key.",
+ "clientWriteRequest"_attr = request().getWriteCmd(),
+ "shardId"_attr = request().getShardId());
+ return {};
+ }
+
+ private:
+ NamespaceString ns() const override {
+ return NamespaceString(request().getDbName());
+ }
+
+ bool supportsWriteConcern() const override {
+ return false;
+ }
+
+ void doCheckAuthorization(OperationContext* opCtx) const override {
+ uassert(ErrorCodes::Unauthorized,
+ "Unauthorized",
+ AuthorizationSession::get(opCtx->getClient())
+ ->isAuthorizedForActionsOnResource(ResourcePattern::forClusterResource(),
+ ActionType::internal));
+ }
+ };
+
+ AllowedOnSecondary secondaryAllowed(ServiceContext*) const final {
+ return AllowedOnSecondary::kNever;
+ }
+
+ bool supportsRetryableWrite() const final {
+ return true;
+ }
+
+ bool allowedInTransactions() const final {
+ return true;
+ }
+};
+
+MONGO_REGISTER_FEATURE_FLAGGED_COMMAND(ClusterWriteWithoutShardKeyCmd,
+ feature_flags::gFeatureFlagUpdateOneWithoutShardKey);
+
+} // namespace
+} // namespace mongo
diff --git a/src/mongo/s/request_types/cluster_commands_without_shard_key.idl b/src/mongo/s/request_types/cluster_commands_without_shard_key.idl
index 0b08e9abc9b..acdf5487d25 100644
--- a/src/mongo/s/request_types/cluster_commands_without_shard_key.idl
+++ b/src/mongo/s/request_types/cluster_commands_without_shard_key.idl
@@ -35,12 +35,16 @@ imports:
structs:
clusterQueryWithoutShardKeyResponse:
description: "The response for the '_clusterQueryWithoutShardKeyFind' command."
+ clusterWriteWithoutShardKeyResponse:
+ description: "The response for the '_clusterWriteWithoutShardKeyFind' command."
commands:
_clusterQueryWithoutShardKey:
command_name: _clusterQueryWithoutShardKey
cpp_name: ClusterQueryWithoutShardKey
- description: "An internal command used to broadcast a query to all shards for updates/deletes/findAndModifies that do not provide a shard key."
+ description: >-
+ "An internal command used to broadcast a query to all shards for updates/deletes
+ /findAndModifies that do not provide a shard key."
namespace: ignored
api_version: ""
reply_type: clusterQueryWithoutShardKeyResponse
@@ -51,4 +55,19 @@ commands:
stmtId:
description: "The stmtId of the write statement in the original batch write."
type: int
-
+ _clusterWriteWithoutShardKey:
+ command_name: _clusterWriteWithoutShardKey
+ cpp_name: ClusterWriteWithoutShardKey
+ description: >-
+ "An internal command used to target target an update/delete/findAndModify command to a
+ specific shard using a shardId."
+ namespace: ignored
+ api_version: ""
+ reply_type: clusterWriteWithoutShardKeyResponse
+ fields:
+ writeCmd:
+ description: "The original write command."
+ type: object
+ shardId:
+ description: "The shard id of the target shard for the write."
+ type: shard_id