diff options
author | David Storch <david.storch@mongodb.com> | 2022-06-01 21:58:13 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-06-01 22:39:26 +0000 |
commit | 6147e2b653fe414ce8f6d64454d9b98802863ae7 (patch) | |
tree | c07721416a4370dd6ffff0408e311562fce62971 /src | |
parent | 4d6a40567f2d18fd10dbe6d2272fbe648be1a459 (diff) | |
download | mongo-6147e2b653fe414ce8f6d64454d9b98802863ae7.tar.gz |
SERVER-66833 Improve error and log messages on attempt to use unsupported legacy op code
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/commands/get_last_error.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/dbmessage.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/dbmessage.h | 10 | ||||
-rw-r--r-- | src/mongo/db/ops/write_ops_parsers_test.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/service_entry_point_common.cpp | 12 | ||||
-rw-r--r-- | src/mongo/rpc/SConscript | 4 | ||||
-rw-r--r-- | src/mongo/rpc/op_legacy_integration_test.cpp | 197 | ||||
-rw-r--r-- | src/mongo/rpc/unsupported_wire_ops.idl (renamed from src/mongo/rpc/deprecated_wire_ops.idl) | 13 | ||||
-rw-r--r-- | src/mongo/rpc/warn_unsupported_wire_ops.cpp (renamed from src/mongo/rpc/warn_deprecated_wire_ops.cpp) | 20 | ||||
-rw-r--r-- | src/mongo/rpc/warn_unsupported_wire_ops.h (renamed from src/mongo/rpc/warn_deprecated_wire_ops.h) | 4 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_get_last_error_cmd.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/commands/strategy.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/service_entry_point_mongos.cpp | 18 |
13 files changed, 159 insertions, 147 deletions
diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp index dc6d4c7acca..770218f1faf 100644 --- a/src/mongo/db/commands/get_last_error.cpp +++ b/src/mongo/db/commands/get_last_error.cpp @@ -32,7 +32,7 @@ #include "mongo/db/client.h" #include "mongo/db/commands.h" -#include "mongo/rpc/warn_deprecated_wire_ops.h" +#include "mongo/rpc/warn_unsupported_wire_ops.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand @@ -66,7 +66,7 @@ public: const BSONObj&, std::string&, BSONObjBuilder&) { - warnDeprecation(*opCtx->getClient(), "getLastError"); + warnUnsupportedOp(*opCtx->getClient(), "getLastError"); uasserted(5739000, "getLastError command is not supported"); return false; } diff --git a/src/mongo/db/dbmessage.cpp b/src/mongo/db/dbmessage.cpp index a3ff583ba24..bba632c1ff1 100644 --- a/src/mongo/db/dbmessage.cpp +++ b/src/mongo/db/dbmessage.cpp @@ -138,7 +138,10 @@ T DbMessage::readAndAdvance() { return t; } -Message makeDeprecatedInsertMessage(StringData ns, const BSONObj* objs, size_t count, int flags) { +Message makeUnsupportedOpInsertMessage(StringData ns, + const BSONObj* objs, + size_t count, + int flags) { return makeMessage(dbInsert, [&](BufBuilder& b) { int reservedFlags = 0; if (flags & InsertOption_ContinueOnError) @@ -153,9 +156,12 @@ Message makeDeprecatedInsertMessage(StringData ns, const BSONObj* objs, size_t c }); } -DbResponse makeErrorResponseToDeprecatedOpQuery(StringData errorMsg) { +DbResponse makeErrorResponseToUnsupportedOpQuery(StringData errorMsg) { BSONObjBuilder err; - err.append("$err", errorMsg); + err.append("$err", + str::stream() << errorMsg + << ". The client driver may require an upgrade. For more details see " + "https://dochub.mongodb.org/core/legacy-opcode-removal"); err.append("code", 5739101); err.append("ok", 0.0); BSONObj errObj = err.done(); diff --git a/src/mongo/db/dbmessage.h b/src/mongo/db/dbmessage.h index 99e174f246a..95e0cfc6f7f 100644 --- a/src/mongo/db/dbmessage.h +++ b/src/mongo/db/dbmessage.h @@ -426,10 +426,10 @@ enum InsertOptions { * The OP_INSERT command is no longer supported, so new callers of this function should not be * added! This is currently retained for the limited purpose of unit testing. */ -Message makeDeprecatedInsertMessage(StringData ns, - const BSONObj* objs, - size_t count, - int flags = 0); +Message makeUnsupportedOpInsertMessage(StringData ns, + const BSONObj* objs, + size_t count, + int flags = 0); /** * A response to a DbMessage. @@ -451,5 +451,5 @@ struct DbResponse { /** * Helper to build an error DbResponse for OP_QUERY and OP_GET_MORE. */ -DbResponse makeErrorResponseToDeprecatedOpQuery(StringData errorMsg); +DbResponse makeErrorResponseToUnsupportedOpQuery(StringData errorMsg); } // namespace mongo diff --git a/src/mongo/db/ops/write_ops_parsers_test.cpp b/src/mongo/db/ops/write_ops_parsers_test.cpp index dff6ab2cb0b..a75bb2bd5b2 100644 --- a/src/mongo/db/ops/write_ops_parsers_test.cpp +++ b/src/mongo/db/ops/write_ops_parsers_test.cpp @@ -404,7 +404,7 @@ TEST(LegacyWriteOpsParsers, SingleInsert) { const std::string ns = "test.foo"; const BSONObj obj = BSON("x" << 1); for (bool continueOnError : {false, true}) { - auto message = makeDeprecatedInsertMessage( + auto message = makeUnsupportedOpInsertMessage( ns, &obj, 1, continueOnError ? InsertOption_ContinueOnError : 0); const auto op = InsertOp::parseLegacy(message); ASSERT_EQ(op.getNamespace().ns(), ns); @@ -419,7 +419,7 @@ TEST(LegacyWriteOpsParsers, EmptyMultiInsertFails) { const std::string ns = "test.foo"; for (bool continueOnError : {false, true}) { auto objs = std::vector<BSONObj>{}; - auto message = makeDeprecatedInsertMessage( + auto message = makeUnsupportedOpInsertMessage( ns, objs.data(), objs.size(), (continueOnError ? InsertOption_ContinueOnError : 0)); ASSERT_THROWS_CODE( InsertOp::parseLegacy(message), AssertionException, ErrorCodes::InvalidLength); @@ -432,7 +432,7 @@ TEST(LegacyWriteOpsParsers, RealMultiInsert) { const BSONObj obj1 = BSON("x" << 1); for (bool continueOnError : {false, true}) { auto objs = std::vector<BSONObj>{obj0, obj1}; - auto message = makeDeprecatedInsertMessage( + auto message = makeUnsupportedOpInsertMessage( ns, objs.data(), objs.size(), continueOnError ? InsertOption_ContinueOnError : 0); const auto op = InsertOp::parseLegacy(message); ASSERT_EQ(op.getNamespace().ns(), ns); diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp index 43f15c819af..f8fd464e134 100644 --- a/src/mongo/db/service_entry_point_common.cpp +++ b/src/mongo/db/service_entry_point_common.cpp @@ -101,7 +101,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/rpc/warn_unsupported_wire_ops.h" #include "mongo/s/shard_cannot_refresh_due_to_locks_held_exception.h" #include "mongo/s/would_change_owning_shard_exception.h" #include "mongo/transport/hello_metrics.h" @@ -2066,8 +2066,8 @@ struct QueryOpRunner : SynchronousOpRunner { invariant(!executionContext->nsString().isCommand()); globalOpCounters.gotQueryDeprecated(); - warnDeprecation(executionContext->client(), networkOpToString(dbQuery)); - return makeErrorResponseToDeprecatedOpQuery("OP_QUERY is no longer supported"); + warnUnsupportedOp(executionContext->client(), networkOpToString(dbQuery)); + return makeErrorResponseToUnsupportedOpQuery("OP_QUERY is no longer supported"); } }; @@ -2075,8 +2075,8 @@ struct GetMoreOpRunner : SynchronousOpRunner { using SynchronousOpRunner::SynchronousOpRunner; DbResponse runSync() override { globalOpCounters.gotGetMoreDeprecated(); - warnDeprecation(executionContext->client(), networkOpToString(dbGetMore)); - return makeErrorResponseToDeprecatedOpQuery("OP_GET_MORE is no longer supported"); + warnUnsupportedOp(executionContext->client(), networkOpToString(dbGetMore)); + return makeErrorResponseToUnsupportedOpQuery("OP_GET_MORE is no longer supported"); } }; @@ -2168,7 +2168,7 @@ std::unique_ptr<HandleRequest::OpRunner> HandleRequest::makeOpRunner() { } DbResponse FireAndForgetOpRunner::runSync() { - warnDeprecation(executionContext->client(), networkOpToString(executionContext->op())); + warnUnsupportedOp(executionContext->client(), networkOpToString(executionContext->op())); runAndForget(); return {}; } diff --git a/src/mongo/rpc/SConscript b/src/mongo/rpc/SConscript index a3de4fa709e..a5734bc4f75 100644 --- a/src/mongo/rpc/SConscript +++ b/src/mongo/rpc/SConscript @@ -52,7 +52,6 @@ protoEnv.Library( env.Library( target='rpc', source=[ - 'deprecated_wire_ops.idl', 'factory.cpp', 'legacy_reply.cpp', 'legacy_reply_builder.cpp', @@ -60,7 +59,8 @@ env.Library( 'object_check.cpp', 'object_check.idl', 'reply_builder_interface.cpp', - 'warn_deprecated_wire_ops.cpp', + 'unsupported_wire_ops.idl', + 'warn_unsupported_wire_ops.cpp', ], LIBDEPS=[ '$BUILD_DIR/mongo/base', diff --git a/src/mongo/rpc/op_legacy_integration_test.cpp b/src/mongo/rpc/op_legacy_integration_test.cpp index a999f4647dc..298bf910d94 100644 --- a/src/mongo/rpc/op_legacy_integration_test.cpp +++ b/src/mongo/rpc/op_legacy_integration_test.cpp @@ -51,12 +51,12 @@ long getOpCount(BSONObj serverStatus, const char* opName) { return serverStatus["opcounters"][opName].Long(); } -long getDeprecatedOpCount(BSONObj serverStatus, const char* opName) { - auto deprecatedOpcounters = serverStatus["opcounters"]["deprecated"]; - return deprecatedOpcounters ? deprecatedOpcounters[opName].Long() : 0; +long getUnsupportedOpCount(BSONObj serverStatus, const char* opName) { + auto unsupportedOpcounters = serverStatus["opcounters"]["deprecated"]; + return unsupportedOpcounters ? unsupportedOpcounters[opName].Long() : 0; } -Message makeDeprecatedUpdateMessage(StringData ns, BSONObj query, BSONObj update, int flags) { +Message makeUnsupportedOpUpdateMessage(StringData ns, BSONObj query, BSONObj update, int flags) { return makeMessage(dbUpdate, [&](BufBuilder& b) { const int reservedFlags = 0; b.appendNum(reservedFlags); @@ -68,7 +68,7 @@ Message makeDeprecatedUpdateMessage(StringData ns, BSONObj query, BSONObj update }); } -Message makeDeprecatedRemoveMessage(StringData ns, BSONObj query, int flags) { +Message makeUnsupportedOpRemoveMessage(StringData ns, BSONObj query, int flags) { return makeMessage(dbDelete, [&](BufBuilder& b) { const int reservedFlags = 0; b.appendNum(reservedFlags); @@ -79,7 +79,7 @@ Message makeDeprecatedRemoveMessage(StringData ns, BSONObj query, int flags) { }); } -Message makeDeprecatedKillCursorsMessage(long long cursorId) { +Message makeUnsupportedOpKillCursorsMessage(long long cursorId) { return makeMessage(dbKillCursors, [&](BufBuilder& b) { b.appendNum((int)0); // reserved b.appendNum((int)1); // number @@ -87,12 +87,12 @@ Message makeDeprecatedKillCursorsMessage(long long cursorId) { }); } -Message makeDeprecatedQueryMessage(StringData ns, - BSONObj query, - int nToReturn, - int nToSkip, - const BSONObj* fieldsToReturn, - int queryOptions) { +Message makeUnsupportedOpQueryMessage(StringData ns, + BSONObj query, + int nToReturn, + int nToSkip, + const BSONObj* fieldsToReturn, + int queryOptions) { return makeMessage(dbQuery, [&](BufBuilder& b) { b.appendNum(queryOptions); b.appendStr(ns); @@ -104,7 +104,10 @@ Message makeDeprecatedQueryMessage(StringData ns, }); } -Message makeDeprecatedGetMoreMessage(StringData ns, long long cursorId, int nToReturn, int flags) { +Message makeUnsupportedOpGetMoreMessage(StringData ns, + long long cursorId, + int nToReturn, + int flags) { return makeMessage(dbGetMore, [&](BufBuilder& b) { b.appendNum(flags); b.appendStr(ns); @@ -113,8 +116,8 @@ Message makeDeprecatedGetMoreMessage(StringData ns, long long cursorId, int nToR }); } -// Issue a find command request so we can use cursor id from it to test the deprecated getMore -// and killCursors ops. +// Issue a find command request so we can use cursor id from it to test the unsupported getMore +// and killCursors wire protocol ops. int64_t getValidCursorIdFromFindCmd(DBClientBase* conn, const char* collName) { Message findCmdRequest = OpMsgRequest::fromDBAndBody("testOpLegacy", BSON("find" << collName << "batchSize" << 2)) @@ -130,16 +133,16 @@ int64_t getValidCursorIdFromFindCmd(DBClientBase* conn, const char* collName) { return cursorId; } -TEST(OpLegacy, DeprecatedWriteOpsCounters) { +TEST(OpLegacy, UnsupportedWriteOpsCounters) { auto conn = getIntegrationTestConnection(); - const std::string ns = "testOpLegacy.DeprecatedWriteOpsCounters"; + const std::string ns = "testOpLegacy.UnsupportedWriteOpsCounters"; - // Cache the counters prior to running the deprecated requests. + // Cache the counters prior to running the unsupported requests. auto serverStatusCmd = fromjson("{serverStatus: 1}"); BSONObj serverStatusReplyPrior; ASSERT(conn->runCommand("admin", serverStatusCmd, serverStatusReplyPrior)); - // Building parts for the deprecated requests. + // Building parts for the unsupported requests. const BSONObj doc1 = fromjson("{a: 1}"); const BSONObj doc2 = fromjson("{a: 2}"); const BSONObj insert[2] = {doc1, doc2}; @@ -148,30 +151,30 @@ TEST(OpLegacy, DeprecatedWriteOpsCounters) { // Issue the requests. They are expected to fail but should still be counted. Message ignore; - auto opInsert = makeDeprecatedInsertMessage(ns, insert, 2, 0 /*continue on error*/); + auto opInsert = makeUnsupportedOpInsertMessage(ns, insert, 2, 0 /*continue on error*/); ASSERT_THROWS(conn->call(opInsert, ignore), ExceptionForCat<ErrorCategory::NetworkError>); - auto opUpdate = makeDeprecatedUpdateMessage(ns, query, update, 0 /*no upsert, no multi*/); + auto opUpdate = makeUnsupportedOpUpdateMessage(ns, query, update, 0 /*no upsert, no multi*/); ASSERT_THROWS(conn->call(opUpdate, ignore), ExceptionForCat<ErrorCategory::NetworkError>); - auto opDelete = makeDeprecatedRemoveMessage(ns, query, 0 /*limit*/); + auto opDelete = makeUnsupportedOpRemoveMessage(ns, query, 0 /*limit*/); ASSERT_THROWS(conn->call(opDelete, ignore), ExceptionForCat<ErrorCategory::NetworkError>); - // Check the opcounters after running the deprecated operations. + // Check the opcounters after running the unsupported operations. BSONObj serverStatusReply; ASSERT(conn->runCommand("admin", serverStatusCmd, serverStatusReply)); - ASSERT_EQ(getDeprecatedOpCount(serverStatusReplyPrior, "insert") + 2, - getDeprecatedOpCount(serverStatusReply, "insert")); + ASSERT_EQ(getUnsupportedOpCount(serverStatusReplyPrior, "insert") + 2, + getUnsupportedOpCount(serverStatusReply, "insert")); - ASSERT_EQ(getDeprecatedOpCount(serverStatusReplyPrior, "update") + 1, - getDeprecatedOpCount(serverStatusReply, "update")); + ASSERT_EQ(getUnsupportedOpCount(serverStatusReplyPrior, "update") + 1, + getUnsupportedOpCount(serverStatusReply, "update")); - ASSERT_EQ(getDeprecatedOpCount(serverStatusReplyPrior, "delete") + 1, - getDeprecatedOpCount(serverStatusReply, "delete")); + ASSERT_EQ(getUnsupportedOpCount(serverStatusReplyPrior, "delete") + 1, + getUnsupportedOpCount(serverStatusReply, "delete")); - ASSERT_EQ(getDeprecatedOpCount(serverStatusReplyPrior, "total") + 2 + 1 + 1, - getDeprecatedOpCount(serverStatusReply, "total")); + ASSERT_EQ(getUnsupportedOpCount(serverStatusReplyPrior, "total") + 2 + 1 + 1, + getUnsupportedOpCount(serverStatusReply, "total")); } void assertFailure(const Message response, StringData expectedErr) { @@ -186,65 +189,65 @@ void assertFailure(const Message response, StringData expectedErr) { << responseBody; } -TEST(OpLegacy, DeprecatedReadOpsCounters) { +TEST(OpLegacy, UnsupportedReadOpsCounters) { auto conn = getIntegrationTestConnection(); - const std::string ns = "testOpLegacy.DeprecatedReadOpsCounters"; + const std::string ns = "testOpLegacy.UnsupportedReadOpsCounters"; BSONObj insert = fromjson(R"({ - insert: "DeprecatedReadOpsCounters", + insert: "UnsupportedReadOpsCounters", documents: [ {a: 1},{a: 2},{a: 3},{a: 4},{a: 5},{a: 6},{a: 7} ] })"); BSONObj ignoreResponse; ASSERT(conn->runCommand("testOpLegacy", insert, ignoreResponse)); - // Cache the counters prior to running the deprecated requests. + // Cache the counters prior to running the unsupported requests. auto serverStatusCmd = fromjson("{serverStatus: 1}"); BSONObj serverStatusReplyPrior; ASSERT(conn->runCommand("admin", serverStatusCmd, serverStatusReplyPrior)); - // Issue the deprecated requests. They all should fail one way or another. - Message opQueryRequest = makeDeprecatedQueryMessage(ns, - fromjson("{}"), - 2 /*nToReturn*/, - 0 /*nToSkip*/, - nullptr /*fieldsToReturn*/, - 0 /*queryOptions*/); + // Issue the unsupported requests. They all should fail one way or another. + Message opQueryRequest = makeUnsupportedOpQueryMessage(ns, + fromjson("{}"), + 2 /*nToReturn*/, + 0 /*nToSkip*/, + nullptr /*fieldsToReturn*/, + 0 /*queryOptions*/); Message opQueryReply; ASSERT(conn->call(opQueryRequest, opQueryReply)); assertFailure(opQueryReply, "OP_QUERY is no longer supported"); - const int64_t cursorId = getValidCursorIdFromFindCmd(conn.get(), "DeprecatedReadOpsCounters"); + const int64_t cursorId = getValidCursorIdFromFindCmd(conn.get(), "UnsupportedReadOpsCounters"); Message opGetMoreRequest = - makeDeprecatedGetMoreMessage(ns, cursorId, 2 /*nToReturn*/, 0 /*flags*/); + makeUnsupportedOpGetMoreMessage(ns, cursorId, 2 /*nToReturn*/, 0 /*flags*/); Message opGetMoreReply; ASSERT(conn->call(opGetMoreRequest, opGetMoreReply)); assertFailure(opGetMoreReply, "OP_GET_MORE is no longer supported"); - Message opKillCursorsRequest = makeDeprecatedKillCursorsMessage(cursorId); + Message opKillCursorsRequest = makeUnsupportedOpKillCursorsMessage(cursorId); Message opKillCursorsReply; ASSERT_THROWS(conn->call(opKillCursorsRequest, opKillCursorsReply), ExceptionForCat<ErrorCategory::NetworkError>); - // Check the opcounters after running the deprecated operations. + // Check the opcounters after running the unsupported operations. BSONObj serverStatusReply; ASSERT(conn->runCommand("admin", serverStatusCmd, serverStatusReply)); - ASSERT_EQ(getDeprecatedOpCount(serverStatusReplyPrior, "query") + 1, - getDeprecatedOpCount(serverStatusReply, "query")); + ASSERT_EQ(getUnsupportedOpCount(serverStatusReplyPrior, "query") + 1, + getUnsupportedOpCount(serverStatusReply, "query")); - ASSERT_EQ(getDeprecatedOpCount(serverStatusReplyPrior, "getmore") + 1, - getDeprecatedOpCount(serverStatusReply, "getmore")); + ASSERT_EQ(getUnsupportedOpCount(serverStatusReplyPrior, "getmore") + 1, + getUnsupportedOpCount(serverStatusReply, "getmore")); - ASSERT_EQ(getDeprecatedOpCount(serverStatusReplyPrior, "killcursors") + 1, - getDeprecatedOpCount(serverStatusReply, "killcursors")); + ASSERT_EQ(getUnsupportedOpCount(serverStatusReplyPrior, "killcursors") + 1, + getUnsupportedOpCount(serverStatusReply, "killcursors")); - ASSERT_EQ(getDeprecatedOpCount(serverStatusReplyPrior, "total") + 1 + 1 + 1, - getDeprecatedOpCount(serverStatusReply, "total")); + ASSERT_EQ(getUnsupportedOpCount(serverStatusReplyPrior, "total") + 1 + 1 + 1, + getUnsupportedOpCount(serverStatusReply, "total")); } -// The dochub link for deprecation warning messages. -static constexpr auto docLink = "https://dochub.mongodb.org/core/legacy-opcode-compatibility"; +// The dochub link for warning messages about the removed op codes. +static constexpr auto docLink = "https://dochub.mongodb.org/core/legacy-opcode-removal"; // Check whether the most recent "deprecation" entry in the log matches the given opName and // severity (if the 'severity' string isn't empty). Return 'false' if no deprecation entries found. @@ -279,14 +282,14 @@ void getLastError(DBClientBase* conn) { ASSERT_EQ(status.code(), expectedCode) << replyObj; } -void exerciseDeprecatedOps(DBClientBase* conn, const std::string& expectedSeverity) { - // Build the deprecated requests and the getLog command. - const std::string ns = "testOpLegacy.exerciseDeprecatedOps"; +void exerciseUnsupportedOps(DBClientBase* conn, const std::string& expectedSeverity) { + // Build the unsupported requests and the getLog command. + const std::string ns = "testOpLegacy.exerciseUnsupportedOps"; // Insert some docs into the collection so even though the legacy write ops are failing we can // still test getMore, killCursors and query. BSONObj data = fromjson(R"({ - insert: "exerciseDeprecatedOps", + insert: "exerciseUnsupportedOps", documents: [ {a: 1},{a: 2},{a: 3},{a: 4},{a: 5},{a: 6},{a: 7} ] })"); BSONObj ignoreResponse; @@ -297,16 +300,16 @@ void exerciseDeprecatedOps(DBClientBase* conn, const std::string& expectedSeveri const BSONObj insert[2] = {doc1, doc2}; const BSONObj query = fromjson("{a: {$lt: 42}}"); const BSONObj update = fromjson("{$set: {b: 2}}"); - auto opInsert = makeDeprecatedInsertMessage(ns, insert, 2, 0 /*continue on error*/); - auto opUpdate = makeDeprecatedUpdateMessage(ns, query, update, 0 /*no upsert, no multi*/); - auto opDelete = makeDeprecatedRemoveMessage(ns, query, 0 /*limit*/); - auto opQuery = makeDeprecatedQueryMessage( + auto opInsert = makeUnsupportedOpInsertMessage(ns, insert, 2, 0 /*continue on error*/); + auto opUpdate = makeUnsupportedOpUpdateMessage(ns, query, update, 0 /*no upsert, no multi*/); + auto opDelete = makeUnsupportedOpRemoveMessage(ns, query, 0 /*limit*/); + auto opQuery = makeUnsupportedOpQueryMessage( ns, query, 2 /*nToReturn*/, 0 /*nToSkip*/, nullptr /*fieldsToReturn*/, 0 /*queryOptions*/); Message ignore; - // The first deprecated call after adding a suppression is still logged with elevated severity - // and after it the suppression kicks in. Any deprecated op can be used to start the suppression - // period, here we chose getLastError. + // The first unsupported call after adding a suppression is still logged with elevated severity + // and after it the suppression kicks in. Any unsupported op can be used to start the + // suppression period, here we chose getLastError. getLastError(conn); ASSERT_THROWS(conn->call(opInsert, ignore), ExceptionForCat<ErrorCategory::NetworkError>); @@ -322,14 +325,14 @@ void exerciseDeprecatedOps(DBClientBase* conn, const std::string& expectedSeveri ASSERT(conn->call(opQuery, replyQuery)); ASSERT(wasLogged(conn, "query", expectedSeverity)); - int64_t cursorId = getValidCursorIdFromFindCmd(conn, "exerciseDeprecatedOps"); + int64_t cursorId = getValidCursorIdFromFindCmd(conn, "exerciseUnsupportedOps"); - auto opGetMore = makeDeprecatedGetMoreMessage(ns, cursorId, 2 /*nToReturn*/, 0 /*flags*/); + auto opGetMore = makeUnsupportedOpGetMoreMessage(ns, cursorId, 2 /*nToReturn*/, 0 /*flags*/); Message replyGetMore; ASSERT(conn->call(opGetMore, replyGetMore)); ASSERT(wasLogged(conn, "getmore", expectedSeverity)); - auto opKillCursors = makeDeprecatedKillCursorsMessage(cursorId); + auto opKillCursors = makeUnsupportedOpKillCursorsMessage(cursorId); ASSERT_THROWS(conn->call(opKillCursors, ignore), ExceptionForCat<ErrorCategory::NetworkError>); ASSERT(wasLogged(conn, "killcursors", expectedSeverity)); @@ -337,16 +340,16 @@ void exerciseDeprecatedOps(DBClientBase* conn, const std::string& expectedSeveri ASSERT(wasLogged(conn, "remove", expectedSeverity)); } -void setDeprecatedWireOpsWarningPeriod(DBClientBase* conn, Seconds timeout) { +void setUnsupportedWireOpsWarningPeriod(DBClientBase* conn, Seconds timeout) { const BSONObj warningTimeout = BSON("setParameter" << 1 << "deprecatedWireOpsWarningPeriodInSeconds" << timeout.count()); BSONObj response; ASSERT(conn->runCommand("admin", warningTimeout, response)); } -class DeprecatedWireOpsWarningPeriodScope { +class UnsupportedWireOpsWarningPeriodScope { public: - DeprecatedWireOpsWarningPeriodScope() { + UnsupportedWireOpsWarningPeriodScope() { auto conn = getIntegrationTestConnection(); BSONObj currentSetting; ASSERT(conn->runCommand( @@ -355,17 +358,17 @@ public: currentSetting)); timeout = currentSetting["deprecatedWireOpsWarningPeriodInSeconds"].Int(); } - ~DeprecatedWireOpsWarningPeriodScope() { + ~UnsupportedWireOpsWarningPeriodScope() { auto conn = getIntegrationTestConnection(); - setDeprecatedWireOpsWarningPeriod(conn.get(), Seconds{timeout}); + setUnsupportedWireOpsWarningPeriod(conn.get(), Seconds{timeout}); } private: int timeout = 3600; }; -TEST(OpLegacy, DeprecatedOpsLogging) { - DeprecatedWireOpsWarningPeriodScope timeoutSettingScope; +TEST(OpLegacy, UnsupportedOpsLogging) { + UnsupportedWireOpsWarningPeriodScope timeoutSettingScope; auto conn = getIntegrationTestConnection(); @@ -375,11 +378,11 @@ TEST(OpLegacy, DeprecatedOpsLogging) { "admin", fromjson("{getParameter: 1, logComponentVerbosity: {command: 1}}"), logSettings)); ASSERT_LTE(2, logSettings["logComponentVerbosity"]["command"]["verbosity"].Int()); - setDeprecatedWireOpsWarningPeriod(conn.get(), Seconds{0} /*timeout*/); - exerciseDeprecatedOps(conn.get(), "W" /*expectedSeverity*/); + setUnsupportedWireOpsWarningPeriod(conn.get(), Seconds{0} /*timeout*/); + exerciseUnsupportedOps(conn.get(), "W" /*expectedSeverity*/); - setDeprecatedWireOpsWarningPeriod(conn.get(), Seconds{3600} /*timeout*/); - exerciseDeprecatedOps(conn.get(), "D2" /*expectedSeverity*/); + setUnsupportedWireOpsWarningPeriod(conn.get(), Seconds{3600} /*timeout*/); + exerciseUnsupportedOps(conn.get(), "D2" /*expectedSeverity*/); } TEST(OpLegacy, GenericCommandViaOpQuery) { @@ -395,12 +398,12 @@ TEST(OpLegacy, GenericCommandViaOpQuery) { ASSERT(wasLogged(conn.get(), "getLastError", "")); // The actual command doesn't matter, as long as it's not 'hello' or 'isMaster'. - auto opQuery = makeDeprecatedQueryMessage("testOpLegacy.$cmd", - serverStatusCmd, - 1 /*nToReturn*/, - 0 /*nToSkip*/, - nullptr /*fieldsToReturn*/, - 0 /*queryOptions*/); + auto opQuery = makeUnsupportedOpQueryMessage("testOpLegacy.$cmd", + serverStatusCmd, + 1 /*nToReturn*/, + 0 /*nToSkip*/, + nullptr /*fieldsToReturn*/, + 0 /*queryOptions*/); Message replyQuery; ASSERT(conn->call(opQuery, replyQuery)); QueryResult::ConstView qr = replyQuery.singleData().view2ptr(); @@ -415,8 +418,8 @@ TEST(OpLegacy, GenericCommandViaOpQuery) { BSONObj serverStatusReply; ASSERT(conn->runCommand("admin", serverStatusCmd, serverStatusReply)); - ASSERT_EQ(getDeprecatedOpCount(serverStatusReplyPrior, "query") + 1, - getDeprecatedOpCount(serverStatusReply, "query")); + ASSERT_EQ(getUnsupportedOpCount(serverStatusReplyPrior, "query") + 1, + getUnsupportedOpCount(serverStatusReply, "query")); } // 'hello' and 'isMaster' commands, issued via OP_QUERY protocol, are still fully supported. @@ -432,12 +435,12 @@ void testAllowedCommand(const char* command, ErrorCodes::Error code = ErrorCodes getLastError(conn.get()); ASSERT(wasLogged(conn.get(), "getLastError", "")); - auto opQuery = makeDeprecatedQueryMessage("testOpLegacy.$cmd", - fromjson(command), - 1 /*nToReturn*/, - 0 /*nToSkip*/, - nullptr /*fieldsToReturn*/, - 0 /*queryOptions*/); + auto opQuery = makeUnsupportedOpQueryMessage("testOpLegacy.$cmd", + fromjson(command), + 1 /*nToReturn*/, + 0 /*nToSkip*/, + nullptr /*fieldsToReturn*/, + 0 /*queryOptions*/); Message replyQuery; ASSERT(conn->call(opQuery, replyQuery)); QueryResult::ConstView qr = replyQuery.singleData().view2ptr(); @@ -450,8 +453,8 @@ void testAllowedCommand(const char* command, ErrorCodes::Error code = ErrorCodes BSONObj serverStatusReply; ASSERT(conn->runCommand("admin", serverStatusCmd, serverStatusReply)); - ASSERT_EQ(getDeprecatedOpCount(serverStatusReplyPrior, "query"), - getDeprecatedOpCount(serverStatusReply, "query")); + ASSERT_EQ(getUnsupportedOpCount(serverStatusReplyPrior, "query"), + getUnsupportedOpCount(serverStatusReply, "query")); } TEST(OpLegacy, IsSelfCommandViaOpQuery) { diff --git a/src/mongo/rpc/deprecated_wire_ops.idl b/src/mongo/rpc/unsupported_wire_ops.idl index b5972d91a8d..800b902c2cf 100644 --- a/src/mongo/rpc/deprecated_wire_ops.idl +++ b/src/mongo/rpc/unsupported_wire_ops.idl @@ -28,16 +28,15 @@ global: cpp_namespace: mongo cpp_includes: - - "mongo/rpc/warn_deprecated_wire_ops.h" + - "mongo/rpc/warn_unsupported_wire_ops.h" 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." + description: "The period in which the server logs a warning message for use of removed 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, runtime ] cpp_vartype: AtomicWord<int> on_update: "onUpdateOfWireOpsWarningPeriod" diff --git a/src/mongo/rpc/warn_deprecated_wire_ops.cpp b/src/mongo/rpc/warn_unsupported_wire_ops.cpp index cbad96cdda5..11a2f9f6699 100644 --- a/src/mongo/rpc/warn_deprecated_wire_ops.cpp +++ b/src/mongo/rpc/warn_unsupported_wire_ops.cpp @@ -30,7 +30,7 @@ #include "mongo/platform/basic.h" -#include "mongo/rpc/warn_deprecated_wire_ops.h" +#include "mongo/rpc/warn_unsupported_wire_ops.h" #include <fmt/format.h> #include <string> @@ -39,8 +39,8 @@ #include "mongo/db/stats/counters.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/rpc/unsupported_wire_ops_gen.h" #include "mongo/util/duration.h" #include "mongo/util/static_immortal.h" #include "mongo/util/synchronized_value.h" @@ -91,7 +91,7 @@ Status onUpdateOfWireOpsWarningPeriod(const int& /*timeout*/) { return Status::OK(); } -void warnDeprecation(Client& client, StringData op) { +void warnUnsupportedOp(Client& client, StringData op) { std::string clientKey; BSONObj clientInfo; if (auto clientMetadata = ClientMetadata::get(&client); clientMetadata) { @@ -107,8 +107,9 @@ void warnDeprecation(Client& client, StringData op) { LOGV2_DEBUG(5578800, getSeveritySource().get(clientKey).toInt(), - "Deprecated operation requested. For more details see " - "https://dochub.mongodb.org/core/legacy-opcode-compatibility", + "Received wire protocol op code or command that is no longer supported. " + "The client driver may require an upgrade. " + "For more details see https://dochub.mongodb.org/core/legacy-opcode-removal", "op"_attr = op, "clientInfo"_attr = clientInfo); } @@ -128,10 +129,13 @@ void checkAllowedOpQueryCommand(Client& client, StringData cmd) { if (std::find(allowedOpQueryCommands.begin(), allowedOpQueryCommands.end(), cmd) == allowedOpQueryCommands.end()) { - warnDeprecation(client, networkOpToString(dbQuery)); + warnUnsupportedOp(client, networkOpToString(dbQuery)); globalOpCounters.gotQueryDeprecated(); - uasserted(ErrorCodes::UnsupportedOpQueryCommand, - "Unsupported OP_QUERY command: {}"_format(cmd)); + uasserted( + ErrorCodes::UnsupportedOpQueryCommand, + "Unsupported OP_QUERY command: {}. The client driver may require an upgrade. " + "For more details see https://dochub.mongodb.org/core/legacy-opcode-removal"_format( + cmd)); } } diff --git a/src/mongo/rpc/warn_deprecated_wire_ops.h b/src/mongo/rpc/warn_unsupported_wire_ops.h index fbfb49cbdb6..942cfb99587 100644 --- a/src/mongo/rpc/warn_deprecated_wire_ops.h +++ b/src/mongo/rpc/warn_unsupported_wire_ops.h @@ -37,7 +37,7 @@ 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. + * - The specific unsupported 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. @@ -49,7 +49,7 @@ namespace mongo { * - If this value is 0, every legacy op code or getLastError request is logged with a warning * message. */ -void warnDeprecation(Client& client, StringData op); +void warnUnsupportedOp(Client& client, StringData op); /** * Callback that gets invoked when 'deprecatedWireOpsWarningPeriodInSeconds' setting is changed. 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 9a1d73c015b..83900625783 100644 --- a/src/mongo/s/commands/cluster_get_last_error_cmd.cpp +++ b/src/mongo/s/commands/cluster_get_last_error_cmd.cpp @@ -30,7 +30,7 @@ #include "mongo/platform/basic.h" #include "mongo/db/commands.h" -#include "mongo/rpc/warn_deprecated_wire_ops.h" +#include "mongo/rpc/warn_unsupported_wire_ops.h" namespace mongo { namespace { @@ -62,7 +62,7 @@ public: } virtual bool run(OperationContext*, const std::string&, const BSONObj&, BSONObjBuilder&) { - warnDeprecation(cc(), "getLastError"); + warnUnsupportedOp(cc(), "getLastError"); uasserted(5739001, "getLastError command is not supported"); return false; } diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp index d765a90c5b9..c0292ef3e5a 100644 --- a/src/mongo/s/commands/strategy.cpp +++ b/src/mongo/s/commands/strategy.cpp @@ -74,7 +74,7 @@ #include "mongo/rpc/op_msg.h" #include "mongo/rpc/op_msg_rpc_impls.h" #include "mongo/rpc/rewrite_state_change_errors.h" -#include "mongo/rpc/warn_deprecated_wire_ops.h" +#include "mongo/rpc/warn_unsupported_wire_ops.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/cluster_commands_helpers.h" diff --git a/src/mongo/s/service_entry_point_mongos.cpp b/src/mongo/s/service_entry_point_mongos.cpp index ba084a9a4a7..401a1363202 100644 --- a/src/mongo/s/service_entry_point_mongos.cpp +++ b/src/mongo/s/service_entry_point_mongos.cpp @@ -47,7 +47,7 @@ #include "mongo/db/stats/counters.h" #include "mongo/logv2/log.h" #include "mongo/rpc/message.h" -#include "mongo/rpc/warn_deprecated_wire_ops.h" +#include "mongo/rpc/warn_unsupported_wire_ops.h" #include "mongo/s/commands/strategy.h" #include "mongo/s/grid.h" #include "mongo/s/load_balancer_support.h" @@ -146,36 +146,36 @@ Future<DbResponse> HandleRequest::handleRequest() { case dbQuery: if (!nsString.isCommand()) { globalOpCounters.gotQueryDeprecated(); - warnDeprecation(*(rec->getOpCtx()->getClient()), networkOpToString(dbQuery)); + warnUnsupportedOp(*(rec->getOpCtx()->getClient()), networkOpToString(dbQuery)); return Future<DbResponse>::makeReady( - makeErrorResponseToDeprecatedOpQuery("OP_QUERY is no longer supported")); + makeErrorResponseToUnsupportedOpQuery("OP_QUERY is no longer supported")); } [[fallthrough]]; // It's a query containing a command case dbMsg: return std::make_unique<CommandOpRunner>(shared_from_this())->run(); case dbGetMore: { globalOpCounters.gotGetMoreDeprecated(); - warnDeprecation(*(rec->getOpCtx()->getClient()), networkOpToString(dbGetMore)); + warnUnsupportedOp(*(rec->getOpCtx()->getClient()), networkOpToString(dbGetMore)); return Future<DbResponse>::makeReady( - makeErrorResponseToDeprecatedOpQuery("OP_GET_MORE is no longer supported")); + makeErrorResponseToUnsupportedOpQuery("OP_GET_MORE is no longer supported")); } case dbKillCursors: globalOpCounters.gotKillCursorsDeprecated(); - warnDeprecation(*(rec->getOpCtx()->getClient()), networkOpToString(op)); + warnUnsupportedOp(*(rec->getOpCtx()->getClient()), networkOpToString(op)); uasserted(5745707, "OP_KILL_CURSORS is no longer supported"); case dbInsert: { auto opInsert = InsertOp::parseLegacy(rec->getMessage()); globalOpCounters.gotInsertsDeprecated(opInsert.getDocuments().size()); - warnDeprecation(*(rec->getOpCtx()->getClient()), networkOpToString(op)); + warnUnsupportedOp(*(rec->getOpCtx()->getClient()), networkOpToString(op)); uasserted(5745706, "OP_INSERT is no longer supported"); } case dbUpdate: globalOpCounters.gotUpdateDeprecated(); - warnDeprecation(*(rec->getOpCtx()->getClient()), networkOpToString(op)); + warnUnsupportedOp(*(rec->getOpCtx()->getClient()), networkOpToString(op)); uasserted(5745705, "OP_UPDATE is no longer supported"); case dbDelete: globalOpCounters.gotDeleteDeprecated(); - warnDeprecation(*(rec->getOpCtx()->getClient()), networkOpToString(op)); + warnUnsupportedOp(*(rec->getOpCtx()->getClient()), networkOpToString(op)); uasserted(5745704, "OP_DELETE is no longer supported"); default: MONGO_UNREACHABLE; |