summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Zhang <jason.zhang@mongodb.com>2022-09-15 00:19:45 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-09-15 00:51:07 +0000
commit4057fb4127a569286d8e342d9bbdd7a7f75806b5 (patch)
treeb4a6dfd60fc89f83ece9688452acbab3504fd78f /src
parent1a13031f7cdfb6cffdcff212edef0790fe084df2 (diff)
downloadmongo-4057fb4127a569286d8e342d9bbdd7a7f75806b5.tar.gz
SERVER-69623 Add _clusterQueryWithoutShardKey command stub
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/internal_transactions_feature_flag.idl2
-rw-r--r--src/mongo/s/SConscript1
-rw-r--r--src/mongo/s/commands/SConscript1
-rw-r--r--src/mongo/s/commands/cluster_query_without_shard_key_cmd.cpp98
-rw-r--r--src/mongo/s/request_types/cluster_commands_without_shard_key.idl54
5 files changed, 155 insertions, 1 deletions
diff --git a/src/mongo/db/internal_transactions_feature_flag.idl b/src/mongo/db/internal_transactions_feature_flag.idl
index 6740092ed83..97b0bcd927a 100644
--- a/src/mongo/db/internal_transactions_feature_flag.idl
+++ b/src/mongo/db/internal_transactions_feature_flag.idl
@@ -47,5 +47,5 @@ feature_flags:
featureFlagUpdateOneWithoutShardKey:
description: Feature flag to enable updateOne, deleteOne, and findAndModify without a shard key or _id equality in their filter against a sharded collection.
- cpp_varname: gfeatureFlagUpdateOneWithoutShardKey
+ cpp_varname: gFeatureFlagUpdateOneWithoutShardKey
default: false
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index d8ed42e46d1..f7746d9b4be 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -168,6 +168,7 @@ env.Library(
'request_types/balancer_collection_status.idl',
'request_types/cleanup_reshard_collection.idl',
'request_types/clone_catalog_data.idl',
+ 'request_types/cluster_commands_without_shard_key.idl',
'request_types/commit_reshard_collection.idl',
'request_types/configure_collection_balancing.idl',
'request_types/drop_collection_if_uuid_not_matching.idl',
diff --git a/src/mongo/s/commands/SConscript b/src/mongo/s/commands/SConscript
index a37bee825c2..7dd1f0bc554 100644
--- a/src/mongo/s/commands/SConscript
+++ b/src/mongo/s/commands/SConscript
@@ -76,6 +76,7 @@ env.Library(
'cluster_pipeline_cmd_s.cpp',
'cluster_plan_cache_clear_cmd.cpp',
'cluster_profile_cmd.cpp',
+ 'cluster_query_without_shard_key_cmd.cpp',
'cluster_refine_collection_shard_key_cmd.cpp',
'cluster_rename_collection_cmd.cpp',
'cluster_repair_sharded_collection_chunks_history_cmd.cpp',
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
new file mode 100644
index 00000000000..8b2cfcf2560
--- /dev/null
+++ b/src/mongo/s/commands/cluster_query_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 ClusterQueryWithoutShardKeyCmd : public TypedCommand<ClusterQueryWithoutShardKeyCmd> {
+public:
+ using Request = ClusterQueryWithoutShardKey;
+ using Response = ClusterQueryWithoutShardKeyResponse;
+
+ 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 read phase for a write without a shard key.",
+ "clientWriteRequest"_attr = request().getWriteCmd(),
+ "stmtIdInBatch"_attr = request().getStmtId());
+ 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(ClusterQueryWithoutShardKeyCmd,
+ 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
new file mode 100644
index 00000000000..0b08e9abc9b
--- /dev/null
+++ b/src/mongo/s/request_types/cluster_commands_without_shard_key.idl
@@ -0,0 +1,54 @@
+# 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"
+
+imports:
+ - "mongo/db/basic_types.idl"
+ - "mongo/s/sharding_types.idl"
+structs:
+ clusterQueryWithoutShardKeyResponse:
+ description: "The response for the '_clusterQueryWithoutShardKeyFind' 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."
+ namespace: ignored
+ api_version: ""
+ reply_type: clusterQueryWithoutShardKeyResponse
+ fields:
+ writeCmd:
+ description: "The original write command."
+ type: object
+ stmtId:
+ description: "The stmtId of the write statement in the original batch write."
+ type: int
+