diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/commands.cpp | 14 | ||||
-rw-r--r-- | src/mongo/db/commands.h | 9 | ||||
-rw-r--r-- | src/mongo/db/commands/dbcommands.cpp | 16 | ||||
-rw-r--r-- | src/mongo/db/commands_test_crutch.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/s_only.cpp | 10 |
5 files changed, 44 insertions, 9 deletions
diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp index 8bb1892afe5..07454381f8c 100644 --- a/src/mongo/db/commands.cpp +++ b/src/mongo/db/commands.cpp @@ -372,4 +372,18 @@ bool Command::isUserManagementCommand(const std::string& name) { return userManagementCommands.count(name); } +namespace { +stdx::function<void(OperationContext*, const DBException&)> registeredRegisterErrorHandler = + [](OperationContext*, const DBException&) { fassertFailed(40357); }; +} // namespace + +void Command::registerRegisterError( + stdx::function<void(OperationContext*, const DBException&)> handler) { + registeredRegisterErrorHandler = std::move(handler); +} + +void Command::registerError(OperationContext* const txn, const DBException& exception) { + registeredRegisterErrorHandler(txn, exception); +} + } // namespace mongo diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h index dd4aa4a5255..ceb72554572 100644 --- a/src/mongo/db/commands.h +++ b/src/mongo/db/commands.h @@ -43,6 +43,7 @@ #include "mongo/db/write_concern.h" #include "mongo/rpc/reply_builder_interface.h" #include "mongo/rpc/request_interface.h" +#include "mongo/stdx/functional.h" #include "mongo/util/string_map.h" namespace mongo { @@ -427,6 +428,14 @@ public: static void registerError(OperationContext* txn, const DBException& exception); /** + * Registers the implementation of the `registerError` function. This hook is needed because + * mongos does not have CurOp linked in to it. This must be called from a MONGO_INITIALIZER + * context and/or a single-threaded context. + */ + static void registerRegisterError( + stdx::function<void(OperationContext*, const DBException&)> registerErrorHandler); + + /** * This function checks if a command is a user management command by name. */ static bool isUserManagementCommand(const std::string& name); diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp index 2c4a19b5174..7695eefe007 100644 --- a/src/mongo/db/commands/dbcommands.cpp +++ b/src/mongo/db/commands/dbcommands.cpp @@ -120,6 +120,18 @@ using std::string; using std::stringstream; using std::unique_ptr; +namespace { +void registerErrorImpl(OperationContext* txn, const DBException& exception) { + CurOp::get(txn)->debug().exceptionInfo = exception.getInfo(); +} + +MONGO_INITIALIZER(InitializeRegisterErrorHandler)(InitializerContext* const) { + Command::registerRegisterError(registerErrorImpl); + return Status::OK(); +} +} // namespace + + class CmdShutdownMongoD : public CmdShutdown { public: virtual void help(stringstream& help) const { @@ -1611,8 +1623,4 @@ bool Command::run(OperationContext* txn, return result; } -void Command::registerError(OperationContext* txn, const DBException& exception) { - CurOp::get(txn)->debug().exceptionInfo = exception.getInfo(); -} - } // namespace mongo diff --git a/src/mongo/db/commands_test_crutch.cpp b/src/mongo/db/commands_test_crutch.cpp index de083acb447..f9b7d965dbe 100644 --- a/src/mongo/db/commands_test_crutch.cpp +++ b/src/mongo/db/commands_test_crutch.cpp @@ -43,8 +43,4 @@ void Command::execCommand(OperationContext*, invariant(false); } -void Command::registerError(OperationContext*, const DBException&) { - invariant(false); -} - } // namespace mongo diff --git a/src/mongo/s/s_only.cpp b/src/mongo/s/s_only.cpp index d9475872961..c7db840cd14 100644 --- a/src/mongo/s/s_only.cpp +++ b/src/mongo/s/s_only.cpp @@ -32,6 +32,7 @@ #include <tuple> +#include "mongo/base/init.h" #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authorization_manager_global.h" #include "mongo/db/auth/authorization_session.h" @@ -160,6 +161,13 @@ void Command::execCommandClient(OperationContext* txn, appendCommandStatus(result, ok, errmsg); } -void Command::registerError(OperationContext* txn, const DBException& exception) {} +namespace { +void registerErrorImpl(OperationContext* txn, const DBException& exception) {} + +MONGO_INITIALIZER(InitializeRegisterErrorHandler)(InitializerContext* const) { + Command::registerRegisterError(registerErrorImpl); + return Status::OK(); +} +} // namespace } // namespace mongo |