diff options
author | Fernando Lisboa <fernando.lisboa@mongodb.com> | 2022-07-07 06:01:10 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-07 06:50:27 +0000 |
commit | e756e14a6679b3a97b5f7438f984d5b40736d1e8 (patch) | |
tree | be1365658fa24cb58abf6f73fcee7573ec24b0af | |
parent | 10df28a8ef8b90ebdf75b20cfd4731d89feda46b (diff) | |
download | mongo-e756e14a6679b3a97b5f7438f984d5b40736d1e8.tar.gz |
SERVER-66561: Change BasicCommandWithReplyBuilderInterface to use DatabaseName
-rw-r--r-- | src/mongo/db/commands.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/commands.h | 17 | ||||
-rw-r--r-- | src/mongo/db/commands/dbcommands.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/commands/profile_common.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/hello_auth.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/repl/hello_auth.h | 5 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_info.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_build_info.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_hello_cmd.cpp | 4 |
9 files changed, 34 insertions, 21 deletions
diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp index 988e3db8831..6e8b2cee87d 100644 --- a/src/mongo/db/commands.cpp +++ b/src/mongo/db/commands.cpp @@ -876,7 +876,7 @@ public: : CommandInvocation(command), _command(command), _request(request), - _dbName(_request.getDatabase().toString()) {} + _dbName(_request.getValidatedTenantId(), _request.getDatabase().toString()) {} private: void run(OperationContext* opCtx, rpc::ReplyBuilderInterface* result) override { @@ -905,7 +905,7 @@ private: } NamespaceString ns() const override { - return NamespaceString(_command->parseNs(_dbName, cmdObj())); + return NamespaceString(_dbName.tenantId(), _command->parseNs(_dbName.toString(), cmdObj())); } bool supportsWriteConcern() const override { @@ -945,7 +945,7 @@ private: BasicCommandWithReplyBuilderInterface* const _command; const OpMsgRequest _request; - const std::string _dbName; + const DatabaseName _dbName; }; Command::~Command() = default; diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h index 15f80320e0f..bc1d274a4f8 100644 --- a/src/mongo/db/commands.h +++ b/src/mongo/db/commands.h @@ -856,7 +856,7 @@ public: * Runs the given command. Returns true upon success. */ virtual bool runWithReplyBuilder(OperationContext* opCtx, - const std::string& db, + const DatabaseName& dbName, const BSONObj& cmdObj, rpc::ReplyBuilderInterface* replyBuilder) = 0; @@ -864,9 +864,10 @@ public: * Provides a future that may run the command asynchronously. By default, it falls back to * runWithReplyBuilder. */ - virtual Future<void> runAsync(std::shared_ptr<RequestExecutionContext> rec, std::string db) { + virtual Future<void> runAsync(std::shared_ptr<RequestExecutionContext> rec, + const DatabaseName& dbName) { if (!runWithReplyBuilder( - rec->getOpCtx(), db, rec->getRequest().body, rec->getReplyBuilder())) + rec->getOpCtx(), dbName, rec->getRequest().body, rec->getReplyBuilder())) return Status(ErrorCodes::FailedToRunWithReplyBuilder, fmt::format("Failed to run command: {}", rec->getCommand()->getName())); return Status::OK(); @@ -1002,11 +1003,12 @@ public: BSONObjBuilder& result) = 0; bool runWithReplyBuilder(OperationContext* opCtx, - const std::string& db, + const DatabaseName& dbName, const BSONObj& cmdObj, rpc::ReplyBuilderInterface* replyBuilder) override { auto result = replyBuilder->getBodyBuilder(); - return run(opCtx, db, cmdObj, result); + // TODO SERVER-67459 change BasicCommand::run to take in DatabaseName + return run(opCtx, dbName.toStringWithTenantId(), cmdObj, result); } }; @@ -1066,7 +1068,7 @@ protected: BasicCommandWithRequestParser(StringData name) : BasicCommandWithReplyBuilderInterface(name) {} bool runWithReplyBuilder(OperationContext* opCtx, - const std::string& db, + const DatabaseName& dbName, const BSONObj& cmdObj, rpc::ReplyBuilderInterface* replyBuilder) final { auto result = replyBuilder->getBodyBuilder(); @@ -1074,7 +1076,8 @@ protected: // To enforce API versioning auto requestParser = RequestParser(opCtx, cmdObj); - auto cmdDone = runWithRequestParser(opCtx, db, cmdObj, requestParser, result); + auto cmdDone = runWithRequestParser( + opCtx, dbName.toStringWithTenantId(), cmdObj, requestParser, result); // Only validate results in test mode so that we don't expose users to errors if we // construct an invalid reply. diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp index f377df1db04..e87aefdc96a 100644 --- a/src/mongo/db/commands/dbcommands.cpp +++ b/src/mongo/db/commands/dbcommands.cpp @@ -696,7 +696,7 @@ public: } else { { stdx::lock_guard<Client> lk(*opCtx->getClient()); - // TODO SERVER-66561: For getDatabaseProfileLevel, takes the passed in "const + // TODO SERVER-67459: For getDatabaseProfileLevel, takes the passed in "const // DatabaseName& dbname" directly. // TODO: OldClientContext legacy, needs to be removed CurOp::get(opCtx)->enter_inlock( @@ -777,7 +777,7 @@ public: return true; } - Future<void> runAsync(std::shared_ptr<RequestExecutionContext> rec, std::string) final { + Future<void> runAsync(std::shared_ptr<RequestExecutionContext> rec, const DatabaseName&) final { auto opCtx = rec->getOpCtx(); return BuildInfoExecutor::get(opCtx->getServiceContext())->schedule(std::move(rec)); } diff --git a/src/mongo/db/commands/profile_common.cpp b/src/mongo/db/commands/profile_common.cpp index 7057dba6c2e..8a2daba0298 100644 --- a/src/mongo/db/commands/profile_common.cpp +++ b/src/mongo/db/commands/profile_common.cpp @@ -81,7 +81,7 @@ bool ProfileCmdBase::run(OperationContext* opCtx, *sampleRate >= 0.0 && *sampleRate <= 1.0); } - // TODO SERVER-66561: For _applyProfilingLevel, takes the passed in "const DatabaseName& dbName" + // TODO SERVER-67459: For _applyProfilingLevel, takes the passed in "const DatabaseName& dbName" // directly. // Delegate to _applyProfilingLevel to set the profiling level appropriately whether // we are on mongoD or mongoS. @@ -124,7 +124,7 @@ bool ProfileCmdBase::run(OperationContext* opCtx, } attrs.add("from", oldState.obj()); - // TODO SERVER-66561: For getDatabaseProfileSettings, takes the passed in "const + // TODO SERVER-67459: For getDatabaseProfileSettings, takes the passed in "const // DatabaseName& dbName" directly. // newSettings.level may differ from profilingLevel: profilingLevel is part of the request, diff --git a/src/mongo/db/repl/hello_auth.cpp b/src/mongo/db/repl/hello_auth.cpp index d6b1472943c..ef3efef33e5 100644 --- a/src/mongo/db/repl/hello_auth.cpp +++ b/src/mongo/db/repl/hello_auth.cpp @@ -39,7 +39,10 @@ namespace mongo { -void handleHelloAuth(OperationContext* opCtx, const HelloCommand& cmd, BSONObjBuilder* result) { +void handleHelloAuth(OperationContext* opCtx, + const DatabaseName& dbName, + const HelloCommand& cmd, + BSONObjBuilder* result) { // saslSupportedMechs: UserName -> List[String] if (auto userNameVariant = cmd.getSaslSupportedMechs()) { auto userName = UserName::parseFromVariant(userNameVariant.value()); @@ -59,6 +62,10 @@ void handleHelloAuth(OperationContext* opCtx, const HelloCommand& cmd, BSONObjBu return; } + uassert(6656100, + "Cannot specify speculativeAuthenticate with a tenantId", + !dbName.tenantId() || dbName.tenantId() == TenantId::kSystemTenantId); + uassert(ErrorCodes::BadValue, str::stream() << "hello." << auth::kSpeculativeAuthenticate << " must be a non-empty Object", diff --git a/src/mongo/db/repl/hello_auth.h b/src/mongo/db/repl/hello_auth.h index 8f8a73269db..e714a7a6bf4 100644 --- a/src/mongo/db/repl/hello_auth.h +++ b/src/mongo/db/repl/hello_auth.h @@ -42,6 +42,9 @@ namespace mongo { * This will attach supported mechanisms or invoke the behavior of saslStart/authenticate commands * as appropriate. */ -void handleHelloAuth(OperationContext* opCtx, const HelloCommand& cmd, BSONObjBuilder* result); +void handleHelloAuth(OperationContext* opCtx, + const DatabaseName& dbName, + const HelloCommand& cmd, + BSONObjBuilder* result); } // namespace mongo diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp index 36da6a84b5e..4544d37ec4d 100644 --- a/src/mongo/db/repl/replication_info.cpp +++ b/src/mongo/db/repl/replication_info.cpp @@ -343,7 +343,7 @@ public: std::vector<Privilege>* out) const final {} // No auth required bool runWithReplyBuilder(OperationContext* opCtx, - const string&, + const DatabaseName& dbName, const BSONObj& cmdObj, rpc::ReplyBuilderInterface* replyBuilder) final { CommandHelpers::handleMarkKillOnClientDisconnect(opCtx); @@ -537,7 +537,7 @@ public: } } - handleHelloAuth(opCtx, cmd, &result); + handleHelloAuth(opCtx, dbName, cmd, &result); if (getTestCommandsEnabled()) { validateResult(&result); diff --git a/src/mongo/s/commands/cluster_build_info.cpp b/src/mongo/s/commands/cluster_build_info.cpp index 4d1fa56e292..742ab9832eb 100644 --- a/src/mongo/s/commands/cluster_build_info.cpp +++ b/src/mongo/s/commands/cluster_build_info.cpp @@ -107,7 +107,7 @@ public: return true; } - Future<void> runAsync(std::shared_ptr<RequestExecutionContext> rec, std::string) final { + Future<void> runAsync(std::shared_ptr<RequestExecutionContext> rec, const DatabaseName&) final { auto opCtx = rec->getOpCtx(); return ClusterBuildInfoExecutor::get(opCtx->getServiceContext())->schedule(std::move(rec)); } diff --git a/src/mongo/s/commands/cluster_hello_cmd.cpp b/src/mongo/s/commands/cluster_hello_cmd.cpp index a2368e3964f..6b958b00b9b 100644 --- a/src/mongo/s/commands/cluster_hello_cmd.cpp +++ b/src/mongo/s/commands/cluster_hello_cmd.cpp @@ -115,7 +115,7 @@ public: } bool runWithReplyBuilder(OperationContext* opCtx, - const std::string& dbname, + const DatabaseName& dbName, const BSONObj& cmdObj, rpc::ReplyBuilderInterface* replyBuilder) final { CommandHelpers::handleMarkKillOnClientDisconnect(opCtx); @@ -256,7 +256,7 @@ public: } } - handleHelloAuth(opCtx, cmd, &result); + handleHelloAuth(opCtx, dbName, cmd, &result); if (getTestCommandsEnabled()) { validateResult(&result); |