summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorPavi Vetriselvan <pavithra.vetriselvan@mongodb.com>2021-04-21 10:42:44 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-07 05:07:15 +0000
commitd8a0fa7c0dd64e01a83fd45b63a2616164f2c019 (patch)
tree027c53326ea5e357854ed96603b2766f898a6ed0 /src/mongo
parent58817e04308cbea4aa7627005cb5aaadd32c89fe (diff)
downloadmongo-d8a0fa7c0dd64e01a83fd45b63a2616164f2c019.tar.gz
SERVER-55788 Deprecate legacy wire protocol opcodes
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/commands/get_last_error.cpp3
-rw-r--r--src/mongo/db/service_entry_point_common.cpp4
-rw-r--r--src/mongo/rpc/SConscript10
-rw-r--r--src/mongo/rpc/deprecated_wire_ops.idl44
-rw-r--r--src/mongo/rpc/warn_deprecated_wire_ops.cpp77
-rw-r--r--src/mongo/rpc/warn_deprecated_wire_ops.h54
-rw-r--r--src/mongo/s/commands/cluster_get_last_error_cmd.cpp2
-rw-r--r--src/mongo/s/service_entry_point_mongos.cpp5
8 files changed, 195 insertions, 4 deletions
diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp
index f2b97a08efd..7cc13764c65 100644
--- a/src/mongo/db/commands/get_last_error.cpp
+++ b/src/mongo/db/commands/get_last_error.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/write_concern.h"
#include "mongo/idl/command_generic_argument.h"
#include "mongo/logv2/log.h"
+#include "mongo/rpc/warn_deprecated_wire_ops.h"
namespace mongo {
namespace {
@@ -119,6 +120,8 @@ public:
}
}
+ warnDeprecation(c, "getLastError");
+
// for sharding; also useful in general for debugging
result.appendNumber("connectionId", c.getConnectionId());
diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp
index abf81db6275..e60c89a3b65 100644
--- a/src/mongo/db/service_entry_point_common.cpp
+++ b/src/mongo/db/service_entry_point_common.cpp
@@ -99,6 +99,7 @@
#include "mongo/rpc/metadata/tracking_metadata.h"
#include "mongo/rpc/op_msg.h"
#include "mongo/rpc/reply_builder_interface.h"
+#include "mongo/rpc/warn_deprecated_wire_ops.h"
#include "mongo/s/shard_cannot_refresh_due_to_locks_held_exception.h"
#include "mongo/transport/hello_metrics.h"
#include "mongo/transport/service_executor.h"
@@ -1958,6 +1959,7 @@ DbResponse receivedQuery(OperationContext* opCtx,
DbResponse dbResponse;
try {
+ warnDeprecation(c, networkOpToString(m.operation()));
Client* client = opCtx->getClient();
Status status = auth::checkAuthForFind(AuthorizationSession::get(client), nss, false);
audit::logQueryAuthzCheck(client, nss, q.query, status.code());
@@ -2094,6 +2096,7 @@ DbResponse receivedGetMore(OperationContext* opCtx,
DbResponse dbresponse;
try {
+ warnDeprecation(*opCtx->getClient(), networkOpToString(m.operation()));
const NamespaceString nsString(ns);
uassert(ErrorCodes::InvalidNamespace,
str::stream() << "Invalid ns [" << ns << "]",
@@ -2280,6 +2283,7 @@ std::unique_ptr<HandleRequest::OpRunner> HandleRequest::makeOpRunner() {
DbResponse FireAndForgetOpRunner::runSync() {
try {
+ warnDeprecation(executionContext->client(), networkOpToString(executionContext->op()));
runAndForget();
} catch (const AssertionException& ue) {
LastError::get(executionContext->client()).setLastError(ue.code(), ue.reason());
diff --git a/src/mongo/rpc/SConscript b/src/mongo/rpc/SConscript
index 22125593a9b..c16d1e116c4 100644
--- a/src/mongo/rpc/SConscript
+++ b/src/mongo/rpc/SConscript
@@ -51,14 +51,16 @@ protoEnv.Library(
env.Library(
target='rpc',
source=[
+ 'deprecated_wire_ops.idl',
'factory.cpp',
- 'object_check.cpp',
- 'legacy_request.cpp',
- 'legacy_request_builder.cpp',
'legacy_reply.cpp',
'legacy_reply_builder.cpp',
- 'reply_builder_interface.cpp',
+ 'legacy_request.cpp',
+ 'legacy_request_builder.cpp',
+ 'object_check.cpp',
'object_check.idl',
+ 'reply_builder_interface.cpp',
+ 'warn_deprecated_wire_ops.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
diff --git a/src/mongo/rpc/deprecated_wire_ops.idl b/src/mongo/rpc/deprecated_wire_ops.idl
new file mode 100644
index 00000000000..c36ba1e9577
--- /dev/null
+++ b/src/mongo/rpc/deprecated_wire_ops.idl
@@ -0,0 +1,44 @@
+# Copyright (C) 2021-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
+
+server_parameters:
+ deprecatedWireOpsWarningPeriodInSeconds:
+ description: "The period in which the server logs a warning message for deprecated op codes
+ and getLastError command. The server logs a warning message only once per each
+ client in this period irrespective of how many such requests have been
+ received.
+ Such requests include OP_QUERY, OP_GET_MORE, OP_KILL_CURSORS, OP_INSERT,
+ OP_UPDATE, OP_DELETE op codes and getLastError command."
+ set_at: [ startup ]
+ cpp_vartype: AtomicWord<int>
+ cpp_varname: deprecatedWireOpsWarningPeriodInSeconds
+ default: 3600
+ validator:
+ gte: 0
diff --git a/src/mongo/rpc/warn_deprecated_wire_ops.cpp b/src/mongo/rpc/warn_deprecated_wire_ops.cpp
new file mode 100644
index 00000000000..c1d199d4b0b
--- /dev/null
+++ b/src/mongo/rpc/warn_deprecated_wire_ops.cpp
@@ -0,0 +1,77 @@
+/**
+ * Copyright (C) 2021-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.
+ */
+
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/rpc/warn_deprecated_wire_ops.h"
+
+#include <fmt/format.h>
+#include <string>
+
+#include "mongo/db/client.h"
+#include "mongo/logv2/log.h"
+#include "mongo/logv2/log_severity_suppressor.h"
+#include "mongo/rpc/deprecated_wire_ops_gen.h"
+#include "mongo/rpc/metadata/client_metadata.h"
+#include "mongo/util/duration.h"
+#include "mongo/util/static_immortal.h"
+
+namespace mongo {
+
+using namespace fmt::literals;
+
+void warnDeprecation(Client& client, StringData op) {
+ static StaticImmortal<logv2::KeyedSeveritySuppressor<std::string>> bumpedSeverity{
+ Seconds{deprecatedWireOpsWarningPeriodInSeconds.load()},
+ logv2::LogSeverity::Warning(),
+ logv2::LogSeverity::Debug(2)};
+
+ std::string clientKey;
+ BSONObj clientInfo;
+ if (auto clientMetadata = ClientMetadata::get(&client); clientMetadata) {
+ auto clientMetadataDoc = clientMetadata->getDocument();
+ clientKey = "{}{}{}"_format(clientMetadata->getApplicationName(),
+ clientMetadataDoc["driver"]["name"].toString(),
+ clientMetadataDoc["driver"]["version"].toString());
+ clientInfo = clientMetadataDoc;
+ } else {
+ clientKey = "{}"_format(client.clientAddress());
+ clientInfo = BSON("address" << client.clientAddress(/*includePort*/ true));
+ }
+
+ LOGV2_DEBUG(5578800,
+ (*bumpedSeverity)(clientKey).toInt(),
+ "Deprecated operation requested",
+ "op"_attr = op,
+ "clientInfo"_attr = clientInfo);
+}
+
+} // namespace mongo
diff --git a/src/mongo/rpc/warn_deprecated_wire_ops.h b/src/mongo/rpc/warn_deprecated_wire_ops.h
new file mode 100644
index 00000000000..ac70c41a930
--- /dev/null
+++ b/src/mongo/rpc/warn_deprecated_wire_ops.h
@@ -0,0 +1,54 @@
+/**
+ * Copyright (C) 2021-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.
+ */
+
+#pragma once
+
+#include "mongo/db/client.h"
+#include "mongo/rpc/message.h"
+
+namespace mongo {
+
+/**
+ * Logs a warning message for use of a legacy opcode or getLastError command once per each unique
+ * client in 60 minutes-period by default.
+ * - The specific deprecated op code or command is given by 'op' parameter.
+ * - Each client is identified by remote IP if client metadata is not available. If client metadata
+ * is available, a client is identified by client metadata’s application name + driver name +
+ * driver version.
+ * - The log message includes the following information.
+ * - Either client IP and port if client metadata is not available,
+ * - Or client metadata if client metadata is available.
+ * - The warning period is defined by 'deprecatedWireOpsWarningPeriodInSeconds' setParameter.
+ * - The default value is 3600 seconds.
+ * - If this value is 0, every legacy op code or getLastError request is logged with a warning
+ * message.
+ */
+void warnDeprecation(Client& client, StringData op);
+
+} // namespace mongo
diff --git a/src/mongo/s/commands/cluster_get_last_error_cmd.cpp b/src/mongo/s/commands/cluster_get_last_error_cmd.cpp
index 1cef4b6cf54..34482d50ccb 100644
--- a/src/mongo/s/commands/cluster_get_last_error_cmd.cpp
+++ b/src/mongo/s/commands/cluster_get_last_error_cmd.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/lasterror.h"
#include "mongo/executor/task_executor_pool.h"
#include "mongo/logv2/log.h"
+#include "mongo/rpc/warn_deprecated_wire_ops.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/s/cluster_last_error_info.h"
@@ -246,6 +247,7 @@ public:
LastError* le = &LastError::get(cc());
le->disable();
+ warnDeprecation(cc(), "getLastError");
// Write commands always have the error stored in the mongos last error
bool errorOccurred = false;
diff --git a/src/mongo/s/service_entry_point_mongos.cpp b/src/mongo/s/service_entry_point_mongos.cpp
index 23d7bcf2b21..c9ec249b0f7 100644
--- a/src/mongo/s/service_entry_point_mongos.cpp
+++ b/src/mongo/s/service_entry_point_mongos.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/service_context.h"
#include "mongo/logv2/log.h"
#include "mongo/rpc/message.h"
+#include "mongo/rpc/warn_deprecated_wire_ops.h"
#include "mongo/s/cluster_last_error_info.h"
#include "mongo/s/commands/strategy.h"
@@ -206,6 +207,7 @@ struct QueryOpRunner final : public OpRunner {
DbResponse runOperation() override {
// Commands are handled through CommandOpRunner and Strategy::clientCommand().
invariant(!hr->nsString.isCommand());
+ warnDeprecation(*hr->rec->getOpCtx()->getClient(), networkOpToString(hr->op));
hr->rec->getOpCtx()->markKillOnClientDisconnect();
return Strategy::queryOp(hr->rec->getOpCtx(), hr->nsString, &hr->rec->getDbMessage());
}
@@ -214,6 +216,7 @@ struct QueryOpRunner final : public OpRunner {
struct GetMoreOpRunner final : public OpRunner {
using OpRunner::OpRunner;
DbResponse runOperation() override {
+ warnDeprecation(*hr->rec->getOpCtx()->getClient(), networkOpToString(hr->op));
return Strategy::getMore(hr->rec->getOpCtx(), hr->nsString, &hr->rec->getDbMessage());
}
};
@@ -221,6 +224,7 @@ struct GetMoreOpRunner final : public OpRunner {
struct KillCursorsOpRunner final : public OpRunner {
using OpRunner::OpRunner;
DbResponse runOperation() override {
+ warnDeprecation(*hr->rec->getOpCtx()->getClient(), networkOpToString(hr->op));
Strategy::killCursors(hr->rec->getOpCtx(), &hr->rec->getDbMessage()); // No Response.
return {};
}
@@ -229,6 +233,7 @@ struct KillCursorsOpRunner final : public OpRunner {
struct WriteOpRunner final : public OpRunner {
using OpRunner::OpRunner;
DbResponse runOperation() override {
+ warnDeprecation(*hr->rec->getOpCtx()->getClient(), networkOpToString(hr->op));
Strategy::writeOp(hr->rec); // No Response.
return {};
}