diff options
Diffstat (limited to 'src/mongo')
48 files changed, 479 insertions, 426 deletions
diff --git a/src/mongo/base/shim.cpp b/src/mongo/base/shim.cpp index 6494c233478..85257748460 100644 --- a/src/mongo/base/shim.cpp +++ b/src/mongo/base/shim.cpp @@ -29,9 +29,13 @@ #include "mongo/base/shim.h" - namespace mongo { -namespace { -MONGO_INITIALIZER_GROUP(ShimHooks, MONGO_NO_PREREQUISITES, ("default")); -} // namespace + +WeakFunctionRegistry::BasicSlot::~BasicSlot() = default; + +WeakFunctionRegistry& globalWeakFunctionRegistry() { + static auto& p = *new WeakFunctionRegistry(); + return p; +} + } // namespace mongo diff --git a/src/mongo/base/shim.h b/src/mongo/base/shim.h index a8d115d298a..5a97f826475 100644 --- a/src/mongo/base/shim.h +++ b/src/mongo/base/shim.h @@ -30,287 +30,165 @@ #pragma once #include <functional> +#include <map> +#include <memory> +#include <string> #include "mongo/base/init.h" #include "mongo/config.h" +#include "mongo/util/assert_util.h" /** - * The `SHIM` mechanism allows for the creation of "weak-symbol-like" functions which can have their - * actual implementation injected in the final binary without creating a link dependency upon any - * actual implementation. One uses it like this: + * The `WeakFunction` mechanism allows for the creation of "weak-symbol-like" functions + * which can have implementations injected into a link target without creating a link + * dependency. This is used for injecting factory functions and mocks. * - * In a header: - * ``` - * class MyClass { - * public: - * static MONGO_DECLARE_SHIM((int)->std::string) helloWorldFunction; - * }; - * ``` - * - * In the corresponding C++ file (which is a link dependency): - * ``` - * MONGO_DEFINE_SHIM(MyClass::helloWorldFunction); - * ``` - * - * And in any number of implementation files: - * ``` - * MONGO_REGISTER_SHIM(MyClass::helloWorldFunction)(int value)->std::string { - * if (value == 42) { - * return "Hello World"; - * } else { - * return "No way!"; - * } - * } - * ``` - * - * This can be useful for making auto-registering and auto-constructing mock and release class - * factories, among other useful things + * DEPRECATION WARNING: + * This library was created as a one-time expediency to resolve technical debt in the + * link dependency graph. It should not be used in new designs, and existing uses will + * continue to be phased out over time. */ - namespace mongo { -template <typename T> -struct PrivateCall; +class WeakFunctionRegistry { +public: + class BasicSlot { + public: + virtual ~BasicSlot(); + int priority = 0; + }; + + template <typename F> + class Slot : public BasicSlot { + public: + Slot() : Slot(nullptr) {} + explicit Slot(F* f) : f(f) {} + F* f; + }; + + /** + * Get the function slot for `key`. Creating a new empty slot if necessary. + * The slot thus created is permanently associated with function type `F`. + * Throws if `key` is not associated with the requested function type `F`. + */ + template <typename F> + Slot<F>* getSlot(const std::string& key) { + auto [iter, ok] = _slots.try_emplace(key, nullptr); + if (ok) { + iter->second = std::make_unique<Slot<F>>(); + } + Slot<F>* slot = dynamic_cast<Slot<F>*>(iter->second.get()); + if (!slot) { + uasserted(31335, std::string("key ") + key + " mapped to wrong function type"); + } + return slot; + } -/** - * When declaring shim functions that should be private, they really need to be public; however, - * this type can be used as a parameter to permit the function to only be called by the type - * specified in the template parameter. - */ -template <typename T> -struct PrivateTo { -private: - friend PrivateCall<T>; + /** + * Make `f` the implementation of function `key`. Subsequent `getSlot<F>(key)` calls + * will return a slot mapped to a function object that invokes `f` when called. + * + * Throws if a previous call with the same `key` and `priority` was made. If keys + * collide, but at differing priorities, the function that was installed with the + * greater priority gets the slot. + */ + template <typename F> + void inject(const std::string& key, F* impl, int priority) { + Slot<F>* slot = getSlot<F>(key); + if (slot->priority > priority) + return; + if (slot->priority == priority && slot->f) + uasserted(31336, std::string("key collision: ") + key); + slot->priority = priority; + slot->f = impl; + } - PrivateTo() = default; +private: + std::map<std::string, std::unique_ptr<BasicSlot>> _slots; }; -/** - * When calling shim functions that should be private, you pass an immediately created instance of - * the type `PrivateCall< T >`, where `T` is the type that `PrivateTo` requires as a template - * parameter. - */ -template <typename T> -struct PrivateCall { -private: - friend T; - PrivateCall() {} +WeakFunctionRegistry& globalWeakFunctionRegistry(); +template <typename F> +class WeakFunction { public: - operator PrivateTo<T>() { - return {}; + explicit WeakFunction(std::string key) + : _key(std::move(key)), _slot(globalWeakFunctionRegistry().getSlot<F>(_key)) {} + + template <typename... A> + decltype(auto) operator()(A&&... a) const { + return std::invoke(_slot->f, std::forward<A>(a)...); } -}; -} // namespace mongo -namespace shim_detail { -/** - * This type, `storage`, is used as a workaround for needing C++17 `inline` variables. The template - * static member is effectively `inline` already. - */ -template <typename T, typename tag = void> -struct storage { - static T data; +private: + std::string _key; + const WeakFunctionRegistry::Slot<F>* _slot; }; -template <typename T, typename tag> -T storage<T, tag>::data = {}; -} // namespace shim_detail - -#define MONGO_SHIM_DEPENDENTS ("ShimHooks") - -namespace mongo { -#ifdef MONGO_CONFIG_CHECK_SHIM_DEPENDENCIES -const bool checkShimsViaTUHook = true; -#define MONGO_SHIM_TU_HOOK(name) \ - name {} -#else -const bool checkShimsViaTUHook = false; -#define MONGO_SHIM_TU_HOOK(name) -#endif -} // namespace mongo - /** - * Declare a shimmable function with signature `SHIM_SIGNATURE`. Declare such constructs in a C++ - * header as static members of a class. + * Associates an implementation function with a name in the global WeakFunction registry. + * A registration object, useful only for its constructor's side effects. + * + * Example: + * + * // Inject an implementation of the WeakFunction "badSqrt". + * static double badSqrtImpl(double x) { + * return std::sqrt(x) + 1; + * } + * static auto sqrtRegistration = WeakFunctionRegistration("badSqrt", badSqrtImpl); + * + * // Elsewhere... + * double badSqrt(double x) { + * // Use a WeakFunction to allow injected implementations of badSqrt. + * static auto weak = WeakFunction<double(double)>("badSqrt"); + * return weak(x); + * } + * + * The macros below help with the syntax a bit. The example can be updated to use the + * MONGO_WEAK_FUNCTION_ macros. + * + * static double badSqrtImpl(double x) { + * return std::sqrt(x) + 1; + * } + * static auto sqrtRegistration = MONGO_WEAK_FUNCTION_REGISTRATION(badSqrt, badSqrtImpl); + * + * // Elsewhere... + * double badSqrt(double x) { + * // Use a WeakFunction to allow injected implementations of badSqrt. + * // Notice that the function type of `double(double)` is implicitly determined. + * static auto weak = MONGO_WEAK_FUNCTION_DEFINITION(badSqrt); + * return weak(x); + * } */ -#define MONGO_DECLARE_SHIM(/*SHIM_SIGNATURE*/...) MONGO_DECLARE_SHIM_1(__LINE__, __VA_ARGS__) -#define MONGO_DECLARE_SHIM_1(LN, ...) MONGO_DECLARE_SHIM_2(LN, __VA_ARGS__) -#define MONGO_DECLARE_SHIM_2(LN, ...) \ - const struct ShimBasis_##LN { \ - ShimBasis_##LN() = default; \ - struct MongoShimImplGuts { \ - template <bool required = mongo::checkShimsViaTUHook> \ - struct AbiCheckType { \ - AbiCheckType() = default; \ - }; \ - using AbiCheck = AbiCheckType<>; \ - struct LibTUHookTypeBase { \ - LibTUHookTypeBase(); \ - }; \ - template <bool required = true> \ - struct LibTUHookType : LibTUHookTypeBase {}; \ - using LibTUHook = LibTUHookType<>; \ - struct ImplTUHookTypeBase { \ - ImplTUHookTypeBase(); \ - }; \ - template <bool required = mongo::checkShimsViaTUHook> \ - struct ImplTUHookType : ImplTUHookTypeBase {}; \ - using ImplTUHook = ImplTUHookType<>; \ - \ - static auto functionTypeHelper __VA_ARGS__; \ - /* Workaround for Microsoft -- by taking the address of this function pointer, we \ - * avoid the problems that their compiler has with default * arguments in deduced \ - * typedefs. */ \ - using function_type_pointer = decltype(&MongoShimImplGuts::functionTypeHelper); \ - using function_type = std::remove_pointer_t<function_type_pointer>; \ - MongoShimImplGuts* abi(const AbiCheck* const) { \ - return this; \ - } \ - MongoShimImplGuts* lib(const LibTUHook* const) { \ - LibTUHook{}; \ - return this; \ - } \ - MongoShimImplGuts* impl(const ImplTUHook* const) { \ - MONGO_SHIM_TU_HOOK(ImplTUHook); \ - return this; \ - } \ - virtual auto implementation __VA_ARGS__ = 0; \ - \ - using tag = \ - std::tuple<MongoShimImplGuts::function_type, AbiCheck, LibTUHook, ImplTUHook>; \ - }; \ - \ - using storage = shim_detail::storage<MongoShimImplGuts*, MongoShimImplGuts::tag>; \ - \ - /* TODO: When the dependency graph is fixed, add the `impl()->` call to the call chain */ \ - template <typename... Args> \ - auto operator()(Args&&... args) const \ - noexcept(noexcept(storage::data->abi(nullptr)->lib(nullptr)->implementation( \ - std::forward<Args>(args)...))) \ - -> decltype(storage::data->abi(nullptr)->lib(nullptr)->implementation( \ - std::forward<Args>(args)...)) { \ - return storage::data->abi(nullptr)->lib(nullptr)->implementation( \ - std::forward<Args>(args)...); \ - } \ +template <typename F> +struct WeakFunctionRegistration { + /** + * Injects `f` as the implementation for the WeakFunction name `key` in the global + * registry. A priority can optionally be specified as an int parameter. Default + * priority is 0. + */ + WeakFunctionRegistration(std::string key, F* impl, int priority = 0) { + globalWeakFunctionRegistry().inject<F>(key, impl, priority); } - +}; /** - * Evaluates to a string which represents the `MONGO_INITIALIZER` step name in which this specific - * shim is registered. This can be useful to make sure that some initializers depend upon a shim's - * execution and presence in a binary. + * Wrapper for the WeakFunctionRegistration constructor call. + * Declares a registration object that registers the function `impl` as the implementation + * of any WeakFunction objects mapped to the key `func`. + * See WeakFunctionRegistration documentation for an example. */ -#define MONGO_SHIM_DEPENDENCY(...) MONGO_SHIM_EVIL_STRINGIFY_(__VA_ARGS__) -#define MONGO_SHIM_EVIL_STRINGIFY_(args) #args +#define MONGO_WEAK_FUNCTION_REGISTRATION_WITH_PRIORITY(func, impl, priority) \ + ::mongo::WeakFunctionRegistration(#func, impl, priority) -/** - * Define a shimmable function with name `SHIM_NAME`, returning a value of type `RETURN_TYPE`, with - * any arguments. This shim definition macro should go in the associated C++ file to the header - * where a SHIM was defined. This macro does not emit a function definition, only the customization - * point's machinery. - */ -#define MONGO_DEFINE_SHIM(/*SHIM_NAME*/...) MONGO_DEFINE_SHIM_1(__LINE__, __VA_ARGS__) -#define MONGO_DEFINE_SHIM_1(LN, ...) MONGO_DEFINE_SHIM_2(LN, __VA_ARGS__) -#define MONGO_DEFINE_SHIM_2(LN, ...) \ - namespace { \ - namespace shim_namespace##LN { \ - using ShimType = decltype(__VA_ARGS__); \ - ::mongo::Status initializerGroupStartup(::mongo::InitializerContext*) { \ - return Status::OK(); \ - } \ - ::mongo::GlobalInitializerRegisterer _mongoInitializerRegisterer( \ - std::string(MONGO_SHIM_DEPENDENCY(__VA_ARGS__)), \ - mongo::InitializerFunction(initializerGroupStartup), \ - mongo::DeinitializerFunction(nullptr), \ - {}, \ - {MONGO_SHIM_DEPENDENTS}); \ - } /*namespace shim_namespace*/ \ - } /*namespace*/ \ - shim_namespace##LN::ShimType::MongoShimImplGuts::LibTUHookTypeBase::LibTUHookTypeBase() = \ - default; \ - shim_namespace##LN::ShimType __VA_ARGS__{}; +/** Usually we don't specify a priority, so this uses default priority 0. */ +#define MONGO_WEAK_FUNCTION_REGISTRATION(func, impl) \ + MONGO_WEAK_FUNCTION_REGISTRATION_WITH_PRIORITY(func, impl, 0) /** - * Define an implementation of a shimmable function with name `SHIM_NAME`. The compiler will check - * supplied parameters for correctness. This shim registration macro should go in the associated - * C++ implementation file to the header where a SHIM was defined. Such a file would be a mock - * implementation or a real implementation, for example. + * Wrapper for the WeakFunction constructor call to create a WeakFunction that agrees with the + * type signature of the declared function `func`, and uses func's name as a key. + * See WeakFunctionRegistration documentation for an example. */ -#define MONGO_REGISTER_SHIM(/*SHIM_NAME*/...) MONGO_REGISTER_SHIM_1(__LINE__, __VA_ARGS__) -#define MONGO_REGISTER_SHIM_1(LN, ...) MONGO_REGISTER_SHIM_2(LN, __VA_ARGS__) -#define MONGO_REGISTER_SHIM_2(LN, ...) \ - namespace { \ - namespace shim_namespace##LN { \ - using ShimType = decltype(__VA_ARGS__); \ - \ - class Implementation final : public ShimType::MongoShimImplGuts { \ - /* Some compilers don't work well with the trailing `override` in this kind of \ - * function declaration. */ \ - ShimType::MongoShimImplGuts::function_type implementation; /* override */ \ - }; \ - \ - ::mongo::Status createInitializerRegistration(::mongo::InitializerContext* const) { \ - static Implementation impl; \ - ShimType::storage::data = &impl; \ - return Status::OK(); \ - } \ - \ - const ::mongo::GlobalInitializerRegisterer registrationHook{ \ - std::string(MONGO_SHIM_DEPENDENCY(__VA_ARGS__) "_registration"), \ - mongo::InitializerFunction(createInitializerRegistration), \ - mongo::DeinitializerFunction(nullptr), \ - {}, \ - {MONGO_SHIM_DEPENDENCY(__VA_ARGS__), MONGO_SHIM_DEPENDENTS}}; \ - } /*namespace shim_namespace*/ \ - } /*namespace*/ \ - \ - shim_namespace##LN::ShimType::MongoShimImplGuts::ImplTUHookTypeBase::ImplTUHookTypeBase() = \ - default; \ - \ - auto shim_namespace##LN::Implementation::implementation /* After this point someone just \ - writes the signature's arguments \ - and return value (using arrow \ - notation). Then they write the \ - body. */ +#define MONGO_WEAK_FUNCTION_DEFINITION(func) ::mongo::WeakFunction<decltype(func)>(#func) -/** - * Define an overriding implementation of a shimmable function with `SHIM_NAME`. The compiler will - * check the supplied parameters for correctness. This shim override macro should go in the - * associated C++ implementation file to the header where a SHIM was defined. Such a file - * specifying an override would be a C++ implementation used by a mongodb extension module. - * This creates a runtime dependency upon the original registration being linked in. - */ -#define MONGO_OVERRIDE_SHIM(/*SHIM_NAME*/...) MONGO_OVERRIDE_SHIM_1(__LINE__, __VA_ARGS__) -#define MONGO_OVERRIDE_SHIM_1(LN, ...) MONGO_OVERRIDE_SHIM_2(LN, __VA_ARGS__) -#define MONGO_OVERRIDE_SHIM_2(LN, ...) \ - namespace { \ - namespace shim_namespace##LN { \ - using ShimType = decltype(__VA_ARGS__); \ - \ - class OverrideImplementation final : public ShimType::MongoShimImplGuts { \ - /* Some compilers don't work well with the trailing `override` in this kind of \ - * function declaration. */ \ - ShimType::MongoShimImplGuts::function_type implementation; /* override */ \ - }; \ - \ - ::mongo::Status createInitializerOverride(::mongo::InitializerContext* const) { \ - static OverrideImplementation overrideImpl; \ - ShimType::storage::data = &overrideImpl; \ - return Status::OK(); \ - } \ - \ - const ::mongo::GlobalInitializerRegisterer overrideHook{ \ - std::string(MONGO_SHIM_DEPENDENCY(__VA_ARGS__) "_override"), \ - mongo::InitializerFunction(createInitializerOverride), \ - mongo::DeinitializerFunction(nullptr), \ - {MONGO_SHIM_DEPENDENCY( \ - __VA_ARGS__) "_registration"}, /* Override happens after first registration */ \ - {MONGO_SHIM_DEPENDENCY(__VA_ARGS__), /* Provides impl for this shim */ \ - MONGO_SHIM_DEPENDENTS} /* Still a shim registration */ \ - }; \ - } /*namespace shim_namespace*/ \ - } /*namespace*/ \ - \ - auto shim_namespace##LN::OverrideImplementation:: \ - implementation /* After this point someone just writes the signature's arguments and \ - return value (using arrow notation). Then they write the body. */ +} // namespace mongo diff --git a/src/mongo/db/auth/authorization_manager.cpp b/src/mongo/db/auth/authorization_manager.cpp index cfdcf367452..b6c30368b2f 100644 --- a/src/mongo/db/auth/authorization_manager.cpp +++ b/src/mongo/db/auth/authorization_manager.cpp @@ -38,6 +38,7 @@ #include <vector> #include "mongo/base/init.h" +#include "mongo/base/shim.h" #include "mongo/base/status.h" #include "mongo/bson/mutable/document.h" #include "mongo/bson/mutable/element.h" @@ -100,6 +101,10 @@ const int AuthorizationManager::schemaVersion26Upgrade; const int AuthorizationManager::schemaVersion26Final; const int AuthorizationManager::schemaVersion28SCRAM; -MONGO_DEFINE_SHIM(AuthorizationManager::create); + +std::unique_ptr<AuthorizationManager> AuthorizationManager::create() { + static auto w = MONGO_WEAK_FUNCTION_DEFINITION(AuthorizationManager::create); + return w(); +} } // namespace mongo diff --git a/src/mongo/db/auth/authorization_manager.h b/src/mongo/db/auth/authorization_manager.h index 21380460468..7f11e10739c 100644 --- a/src/mongo/db/auth/authorization_manager.h +++ b/src/mongo/db/auth/authorization_manager.h @@ -36,7 +36,6 @@ #include <boost/optional.hpp> #include "mongo/base/secure_allocator.h" -#include "mongo/base/shim.h" #include "mongo/base/status.h" #include "mongo/bson/mutable/element.h" #include "mongo/bson/oid.h" @@ -96,7 +95,7 @@ public: AuthorizationManager() = default; - static MONGO_DECLARE_SHIM(()->std::unique_ptr<AuthorizationManager>) create; + static std::unique_ptr<AuthorizationManager> create(); static constexpr StringData USERID_FIELD_NAME = "userId"_sd; static constexpr StringData USER_NAME_FIELD_NAME = "user"_sd; diff --git a/src/mongo/db/auth/authorization_manager_global.cpp b/src/mongo/db/auth/authorization_manager_global.cpp index ba1015947fb..e549de2f404 100644 --- a/src/mongo/db/auth/authorization_manager_global.cpp +++ b/src/mongo/db/auth/authorization_manager_global.cpp @@ -60,9 +60,7 @@ Status AuthzVersionParameter::setFromString(const std::string& newValueString) { ServiceContext::ConstructorActionRegisterer createAuthorizationManager( "CreateAuthorizationManager", - {"OIDGeneration", - "EndStartupOptionStorage", - MONGO_SHIM_DEPENDENCY(AuthorizationManager::create)}, + {"OIDGeneration", "EndStartupOptionStorage"}, [](ServiceContext* service) { auto authzManager = AuthorizationManager::create(); authzManager->setAuthEnabled(serverGlobalParams.authState == diff --git a/src/mongo/db/auth/authorization_manager_impl.cpp b/src/mongo/db/auth/authorization_manager_impl.cpp index 8c94db89c40..54bae468e32 100644 --- a/src/mongo/db/auth/authorization_manager_impl.cpp +++ b/src/mongo/db/auth/authorization_manager_impl.cpp @@ -38,6 +38,7 @@ #include <vector> #include "mongo/base/init.h" +#include "mongo/base/shim.h" #include "mongo/base/status.h" #include "mongo/bson/mutable/document.h" #include "mongo/bson/mutable/element.h" @@ -222,10 +223,17 @@ Status AuthorizationManagerPinnedUsersServerParameter::setFromString(const std:: return authorizationManagerPinnedUsers.setFromString(str); } -MONGO_REGISTER_SHIM(AuthorizationManager::create)()->std::unique_ptr<AuthorizationManager> { +namespace { + +std::unique_ptr<AuthorizationManager> authorizationManagerCreateImpl() { return std::make_unique<AuthorizationManagerImpl>(); } +auto authorizationManagerCreateRegistration = + MONGO_WEAK_FUNCTION_REGISTRATION(AuthorizationManager::create, authorizationManagerCreateImpl); + +} // namespace + /** * Guard object for synchronizing accesses to data cached in AuthorizationManager instances. * This guard allows one thread to access the cache at a time, and provides an exception-safe diff --git a/src/mongo/db/auth/authorization_session.cpp b/src/mongo/db/auth/authorization_session.cpp index 065049da621..19172661b6a 100644 --- a/src/mongo/db/auth/authorization_session.cpp +++ b/src/mongo/db/auth/authorization_session.cpp @@ -36,6 +36,7 @@ #include <string> #include <vector> +#include "mongo/base/shim.h" #include "mongo/base/status.h" #include "mongo/db/auth/action_set.h" #include "mongo/db/auth/action_type.h" @@ -66,5 +67,10 @@ void AuthorizationSession::ScopedImpersonate::swap() { swap(*std::get<1>(impersonations), _roles); } -MONGO_DEFINE_SHIM(AuthorizationSession::create); +std::unique_ptr<AuthorizationSession> AuthorizationSession::create( + AuthorizationManager* authzManager) { + static auto w = MONGO_WEAK_FUNCTION_DEFINITION(AuthorizationSession::create); + return w(authzManager); +} + } // namespace mongo diff --git a/src/mongo/db/auth/authorization_session.h b/src/mongo/db/auth/authorization_session.h index 61fc801dfac..1546aab99ad 100644 --- a/src/mongo/db/auth/authorization_session.h +++ b/src/mongo/db/auth/authorization_session.h @@ -72,8 +72,7 @@ class AuthorizationSession { AuthorizationSession& operator=(const AuthorizationSession&) = delete; public: - static MONGO_DECLARE_SHIM( - (AuthorizationManager * authzManager)->std::unique_ptr<AuthorizationSession>) create; + static std::unique_ptr<AuthorizationSession> create(AuthorizationManager*); AuthorizationSession() = default; diff --git a/src/mongo/db/auth/authorization_session_impl.cpp b/src/mongo/db/auth/authorization_session_impl.cpp index 07ef4bf6a25..73c2feb31b2 100644 --- a/src/mongo/db/auth/authorization_session_impl.cpp +++ b/src/mongo/db/auth/authorization_session_impl.cpp @@ -36,6 +36,7 @@ #include <string> #include <vector> +#include "mongo/base/shim.h" #include "mongo/base/status.h" #include "mongo/db/auth/action_set.h" #include "mongo/db/auth/action_type.h" @@ -61,14 +62,18 @@ namespace mongo { namespace dps = ::mongo::dotted_path_support; using std::vector; -MONGO_REGISTER_SHIM(AuthorizationSession::create) -(AuthorizationManager* authzManager)->std::unique_ptr<AuthorizationSession> { +namespace { + +std::unique_ptr<AuthorizationSession> authorizationSessionCreateImpl( + AuthorizationManager* authzManager) { return std::make_unique<AuthorizationSessionImpl>( AuthzSessionExternalState::create(authzManager), AuthorizationSessionImpl::InstallMockForTestingOrAuthImpl{}); } -namespace { +auto authorizationSessionCreateRegistration = + MONGO_WEAK_FUNCTION_REGISTRATION(AuthorizationSession::create, authorizationSessionCreateImpl); + constexpr StringData ADMIN_DBNAME = "admin"_sd; // Checks if this connection has the privileges necessary to create or modify the view 'viewNs' diff --git a/src/mongo/db/auth/authz_manager_external_state.cpp b/src/mongo/db/auth/authz_manager_external_state.cpp index 8093e0fb8b3..bc129430819 100644 --- a/src/mongo/db/auth/authz_manager_external_state.cpp +++ b/src/mongo/db/auth/authz_manager_external_state.cpp @@ -29,6 +29,7 @@ #include "mongo/platform/basic.h" +#include "mongo/base/shim.h" #include "mongo/config.h" #include "mongo/db/auth/authorization_manager_global_parameters_gen.h" #include "mongo/db/auth/authz_manager_external_state.h" @@ -38,7 +39,10 @@ namespace mongo { -MONGO_DEFINE_SHIM(AuthzManagerExternalState::create); +std::unique_ptr<AuthzManagerExternalState> AuthzManagerExternalState::create() { + static auto w = MONGO_WEAK_FUNCTION_DEFINITION(AuthzManagerExternalState::create); + return w(); +} AuthzManagerExternalState::AuthzManagerExternalState() = default; AuthzManagerExternalState::~AuthzManagerExternalState() = default; diff --git a/src/mongo/db/auth/authz_manager_external_state.h b/src/mongo/db/auth/authz_manager_external_state.h index e18963fefb3..3a98677cedd 100644 --- a/src/mongo/db/auth/authz_manager_external_state.h +++ b/src/mongo/db/auth/authz_manager_external_state.h @@ -34,7 +34,6 @@ #include <string> #include <vector> -#include "mongo/base/shim.h" #include "mongo/base/status.h" #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authorization_manager_impl.h" @@ -59,7 +58,7 @@ class AuthzManagerExternalState { AuthzManagerExternalState& operator=(const AuthzManagerExternalState&) = delete; public: - static MONGO_DECLARE_SHIM(()->std::unique_ptr<AuthzManagerExternalState>) create; + static std::unique_ptr<AuthzManagerExternalState> create(); virtual ~AuthzManagerExternalState(); diff --git a/src/mongo/db/auth/authz_manager_external_state_d.cpp b/src/mongo/db/auth/authz_manager_external_state_d.cpp index adfbfb083ca..99dab1244ac 100644 --- a/src/mongo/db/auth/authz_manager_external_state_d.cpp +++ b/src/mongo/db/auth/authz_manager_external_state_d.cpp @@ -35,6 +35,7 @@ #include <memory> +#include "mongo/base/shim.h" #include "mongo/base/status.h" #include "mongo/db/auth/authz_session_external_state_d.h" #include "mongo/db/auth/user_name.h" @@ -90,9 +91,15 @@ Status AuthzManagerExternalStateMongod::findOne(OperationContext* opCtx, << query); } -MONGO_REGISTER_SHIM(AuthzManagerExternalState::create) -()->std::unique_ptr<AuthzManagerExternalState> { +namespace { + +std::unique_ptr<AuthzManagerExternalState> authzManagerExternalStateCreateImpl() { return std::make_unique<AuthzManagerExternalStateMongod>(); } +auto authzManagerExternalStateCreateRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + AuthzManagerExternalState::create, authzManagerExternalStateCreateImpl); + +} // namespace + } // namespace mongo diff --git a/src/mongo/db/auth/authz_manager_external_state_mock.cpp b/src/mongo/db/auth/authz_manager_external_state_mock.cpp index 19a7977e605..575985de12c 100644 --- a/src/mongo/db/auth/authz_manager_external_state_mock.cpp +++ b/src/mongo/db/auth/authz_manager_external_state_mock.cpp @@ -34,6 +34,7 @@ #include <memory> #include <string> +#include "mongo/base/shim.h" #include "mongo/base/status.h" #include "mongo/bson/mutable/algorithm.h" #include "mongo/bson/mutable/document.h" @@ -50,12 +51,15 @@ namespace mongo { -MONGO_REGISTER_SHIM(AuthzManagerExternalState::create) -()->std::unique_ptr<AuthzManagerExternalState> { +namespace { + +std::unique_ptr<AuthzManagerExternalState> authzManagerExternalStateCreateImpl() { return std::make_unique<AuthzManagerExternalStateMock>(); } -namespace { +auto authzManagerExternalStateCreateRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + AuthzManagerExternalState::create, authzManagerExternalStateCreateImpl); + void addRoleNameToObjectElement(mutablebson::Element object, const RoleName& role) { fassert(17175, object.appendString(AuthorizationManager::ROLE_NAME_FIELD_NAME, role.getRole())); fassert(17176, object.appendString(AuthorizationManager::ROLE_DB_FIELD_NAME, role.getDB())); diff --git a/src/mongo/db/auth/authz_manager_external_state_s.cpp b/src/mongo/db/auth/authz_manager_external_state_s.cpp index ec1a695ba53..d8835c5a15a 100644 --- a/src/mongo/db/auth/authz_manager_external_state_s.cpp +++ b/src/mongo/db/auth/authz_manager_external_state_s.cpp @@ -36,6 +36,7 @@ #include <string> #include <vector> +#include "mongo/base/shim.h" #include "mongo/db/auth/authz_session_external_state_s.h" #include "mongo/db/auth/user_document_parser.h" #include "mongo/db/auth/user_management_commands_parser.h" @@ -49,11 +50,6 @@ namespace mongo { -MONGO_REGISTER_SHIM(AuthzManagerExternalState::create) -()->std::unique_ptr<AuthzManagerExternalState> { - return std::make_unique<AuthzManagerExternalStateMongos>(); -} - namespace { /** @@ -325,4 +321,15 @@ bool AuthzManagerExternalStateMongos::hasAnyPrivilegeDocuments(OperationContext* return foundRoles.size() > 0; } +namespace { + +std::unique_ptr<AuthzManagerExternalState> authzManagerExternalStateCreateImpl() { + return std::make_unique<AuthzManagerExternalStateMongos>(); +} + +auto authzManagerExternalStateCreateRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + AuthzManagerExternalState::create, authzManagerExternalStateCreateImpl); + +} // namespace + } // namespace mongo diff --git a/src/mongo/db/auth/authz_session_external_state.cpp b/src/mongo/db/auth/authz_session_external_state.cpp index 78cc3d0be28..73a3db66a5e 100644 --- a/src/mongo/db/auth/authz_session_external_state.cpp +++ b/src/mongo/db/auth/authz_session_external_state.cpp @@ -31,6 +31,7 @@ #include "mongo/db/auth/authz_session_external_state.h" +#include "mongo/base/shim.h" #include "mongo/base/status.h" #include "mongo/db/namespace_string.h" @@ -44,6 +45,10 @@ AuthorizationManager& AuthzSessionExternalState::getAuthorizationManager() { return *_authzManager; } -MONGO_DEFINE_SHIM(AuthzSessionExternalState::create); +std::unique_ptr<AuthzSessionExternalState> AuthzSessionExternalState::create( + AuthorizationManager* authzManager) { + static auto w = MONGO_WEAK_FUNCTION_DEFINITION(AuthzSessionExternalState::create); + return w(authzManager); +} } // namespace mongo diff --git a/src/mongo/db/auth/authz_session_external_state.h b/src/mongo/db/auth/authz_session_external_state.h index 7647a9c9df9..d6af2dbfc4e 100644 --- a/src/mongo/db/auth/authz_session_external_state.h +++ b/src/mongo/db/auth/authz_session_external_state.h @@ -50,8 +50,7 @@ class AuthzSessionExternalState { AuthzSessionExternalState& operator=(const AuthzSessionExternalState&) = delete; public: - static MONGO_DECLARE_SHIM( - (AuthorizationManager * authzManager)->std::unique_ptr<AuthzSessionExternalState>) create; + static std::unique_ptr<AuthzSessionExternalState> create(AuthorizationManager* authzManager); virtual ~AuthzSessionExternalState(); diff --git a/src/mongo/db/auth/authz_session_external_state_d.cpp b/src/mongo/db/auth/authz_session_external_state_d.cpp index 3d56df4058f..37246f91054 100644 --- a/src/mongo/db/auth/authz_session_external_state_d.cpp +++ b/src/mongo/db/auth/authz_session_external_state_d.cpp @@ -31,6 +31,7 @@ #include "mongo/db/auth/authz_session_external_state_d.h" +#include "mongo/base/shim.h" #include "mongo/base/status.h" #include "mongo/db/client.h" #include "mongo/db/jsobj.h" @@ -66,9 +67,17 @@ bool AuthzSessionExternalStateMongod::serverIsArbiter() const { repl::ReplicationCoordinator::get(getGlobalServiceContext())->getMemberState().arbiter()); } -MONGO_REGISTER_SHIM(AuthzSessionExternalState::create) -(AuthorizationManager* const authzManager)->std::unique_ptr<AuthzSessionExternalState> { +namespace { + +std::unique_ptr<AuthzSessionExternalState> authzSessionExternalStateImpl( + AuthorizationManager* authzManager) { return std::make_unique<AuthzSessionExternalStateMongod>(authzManager); } +auto authzSessionExternalStateRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + AuthzSessionExternalState::create, authzSessionExternalStateImpl); + +} // namespace + + } // namespace mongo diff --git a/src/mongo/db/auth/authz_session_external_state_mock.cpp b/src/mongo/db/auth/authz_session_external_state_mock.cpp index aec268a8763..fa9c141d230 100644 --- a/src/mongo/db/auth/authz_session_external_state_mock.cpp +++ b/src/mongo/db/auth/authz_session_external_state_mock.cpp @@ -28,10 +28,18 @@ */ #include "mongo/db/auth/authz_session_external_state_mock.h" +#include "mongo/base/shim.h" namespace mongo { -MONGO_REGISTER_SHIM(AuthzSessionExternalState::create) -(AuthorizationManager* const authzManager)->std::unique_ptr<AuthzSessionExternalState> { +namespace { + +std::unique_ptr<AuthzSessionExternalState> authzSessionExternalStateCreateImpl( + AuthorizationManager* authzManager) { return std::make_unique<AuthzSessionExternalStateMock>(authzManager); } + +auto authzSessionExternalStateCreateRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + AuthzSessionExternalState::create, authzSessionExternalStateCreateImpl); + +} // namespace } // namespace mongo diff --git a/src/mongo/db/auth/authz_session_external_state_s.cpp b/src/mongo/db/auth/authz_session_external_state_s.cpp index 4b7a4a791b4..2313564224c 100644 --- a/src/mongo/db/auth/authz_session_external_state_s.cpp +++ b/src/mongo/db/auth/authz_session_external_state_s.cpp @@ -33,6 +33,7 @@ #include <string> +#include "mongo/base/shim.h" #include "mongo/base/status.h" #include "mongo/db/jsobj.h" @@ -46,9 +47,16 @@ void AuthzSessionExternalStateMongos::startRequest(OperationContext* opCtx) { _checkShouldAllowLocalhost(opCtx); } -MONGO_REGISTER_SHIM(AuthzSessionExternalState::create) -(AuthorizationManager* const authzManager)->std::unique_ptr<AuthzSessionExternalState> { +namespace { + +std::unique_ptr<AuthzSessionExternalState> authzSessionExternalStateCreateImpl( + AuthorizationManager* authzManager) { return std::make_unique<AuthzSessionExternalStateMongos>(authzManager); } +auto authzSessionExternalStateCreateRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + AuthzSessionExternalState::create, authzSessionExternalStateCreateImpl); + +} // namespace + } // namespace mongo diff --git a/src/mongo/db/pipeline/mongo_process_interface.cpp b/src/mongo/db/pipeline/mongo_process_interface.cpp index 5e2455b8727..69cb07aeb87 100644 --- a/src/mongo/db/pipeline/mongo_process_interface.cpp +++ b/src/mongo/db/pipeline/mongo_process_interface.cpp @@ -31,8 +31,13 @@ #include "mongo_process_interface.h" +#include "mongo/base/shim.h" + namespace mongo { -MONGO_DEFINE_SHIM(MongoProcessInterface::create); +std::shared_ptr<MongoProcessInterface> MongoProcessInterface::create(OperationContext* opCtx) { + static auto w = MONGO_WEAK_FUNCTION_DEFINITION(MongoProcessInterface::create); + return w(opCtx); +} } // namespace mongo diff --git a/src/mongo/db/pipeline/mongo_process_interface.h b/src/mongo/db/pipeline/mongo_process_interface.h index 754c6e6f37b..ae94f183283 100644 --- a/src/mongo/db/pipeline/mongo_process_interface.h +++ b/src/mongo/db/pipeline/mongo_process_interface.h @@ -36,7 +36,6 @@ #include <string> #include <vector> -#include "mongo/base/shim.h" #include "mongo/client/dbclient_base.h" #include "mongo/db/collection_index_usage_tracker.h" #include "mongo/db/exec/document_value/document.h" @@ -98,8 +97,7 @@ public: * Factory function to create MongoProcessInterface of the right type. The implementation will * be installed by a lib higher up in the link graph depending on the application type. */ - static MONGO_DECLARE_SHIM( - (OperationContext * opCtx)->std::shared_ptr<MongoProcessInterface>) create; + static std::shared_ptr<MongoProcessInterface> create(OperationContext* opCtx); struct MakePipelineOptions { MakePipelineOptions(){}; diff --git a/src/mongo/db/pipeline/process_interface_factory_mongod.cpp b/src/mongo/db/pipeline/process_interface_factory_mongod.cpp index 63a6b9fec22..d8c3de62131 100644 --- a/src/mongo/db/pipeline/process_interface_factory_mongod.cpp +++ b/src/mongo/db/pipeline/process_interface_factory_mongod.cpp @@ -29,16 +29,20 @@ #include "mongo/platform/basic.h" +#include "mongo/base/shim.h" #include "mongo/db/pipeline/process_interface_shardsvr.h" - #include "mongo/db/s/sharding_state.h" namespace mongo { +namespace { -MONGO_REGISTER_SHIM(MongoProcessInterface::create) -(OperationContext* opCtx)->std::shared_ptr<MongoProcessInterface> { +std::shared_ptr<MongoProcessInterface> MongoProcessInterfaceCreateImpl(OperationContext* opCtx) { return ShardingState::get(opCtx)->enabled() ? std::make_shared<MongoInterfaceShardServer>(opCtx) : std::make_shared<MongoInterfaceStandalone>(opCtx); } +auto mongoProcessInterfaceCreateRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + MongoProcessInterface::create, MongoProcessInterfaceCreateImpl); + +} // namespace } // namespace mongo diff --git a/src/mongo/db/read_concern.cpp b/src/mongo/db/read_concern.cpp index 1ddbf1dcefc..07944dd56df 100644 --- a/src/mongo/db/read_concern.cpp +++ b/src/mongo/db/read_concern.cpp @@ -28,12 +28,34 @@ */ #include "mongo/db/read_concern.h" +#include "mongo/base/shim.h" +#include "mongo/db/repl/speculative_majority_read_info.h" namespace mongo { -MONGO_DEFINE_SHIM(setPrepareConflictBehaviorForReadConcern); -MONGO_DEFINE_SHIM(waitForReadConcern); -MONGO_DEFINE_SHIM(waitForLinearizableReadConcern); -MONGO_DEFINE_SHIM(waitForSpeculativeMajorityReadConcern); +void setPrepareConflictBehaviorForReadConcern(OperationContext* opCtx, + const repl::ReadConcernArgs& readConcernArgs, + PrepareConflictBehavior prepareConflictBehavior) { + static auto w = MONGO_WEAK_FUNCTION_DEFINITION(setPrepareConflictBehaviorForReadConcern); + return w(opCtx, readConcernArgs, prepareConflictBehavior); +} + +Status waitForReadConcern(OperationContext* opCtx, + const repl::ReadConcernArgs& readConcernArgs, + bool allowAfterClusterTime) { + static auto w = MONGO_WEAK_FUNCTION_DEFINITION(waitForReadConcern); + return w(opCtx, readConcernArgs, allowAfterClusterTime); +} + +Status waitForLinearizableReadConcern(OperationContext* opCtx, int readConcernTimeout) { + static auto w = MONGO_WEAK_FUNCTION_DEFINITION(waitForLinearizableReadConcern); + return w(opCtx, readConcernTimeout); +} + +Status waitForSpeculativeMajorityReadConcern( + OperationContext* opCtx, repl::SpeculativeMajorityReadInfo speculativeReadInfo) { + static auto w = MONGO_WEAK_FUNCTION_DEFINITION(waitForSpeculativeMajorityReadConcern); + return w(opCtx, speculativeReadInfo); +} } // namespace mongo diff --git a/src/mongo/db/read_concern.h b/src/mongo/db/read_concern.h index cdb4a968682..6168b393954 100644 --- a/src/mongo/db/read_concern.h +++ b/src/mongo/db/read_concern.h @@ -29,8 +29,6 @@ #pragma once -#include "mongo/base/shim.h" - namespace mongo { class BSONObj; @@ -51,10 +49,9 @@ class SpeculativeMajorityReadInfo; * are used to verify if the command is safe to ignore prepare conflicts, and if not, we * enforce prepare conflicts. */ -extern MONGO_DECLARE_SHIM((OperationContext * opCtx, - const repl::ReadConcernArgs& readConcernArgs, - PrepareConflictBehavior prepareConflictBehavior) - ->void) setPrepareConflictBehaviorForReadConcern; +void setPrepareConflictBehaviorForReadConcern(OperationContext* opCtx, + const repl::ReadConcernArgs& readConcernArgs, + PrepareConflictBehavior prepareConflictBehavior); /** * Given the specified read concern arguments, performs checks that the read concern can actually be @@ -65,10 +62,9 @@ extern MONGO_DECLARE_SHIM((OperationContext * opCtx, * Note: Callers should use setPrepareConflictBehaviorForReadConcern method to set the desired * prepare conflict behavior for their command. */ -extern MONGO_DECLARE_SHIM((OperationContext * opCtx, - const repl::ReadConcernArgs& readConcernArgs, - bool allowAfterClusterTime) - ->Status) waitForReadConcern; +Status waitForReadConcern(OperationContext* opCtx, + const repl::ReadConcernArgs& readConcernArgs, + bool allowAfterClusterTime); /* * Given a linearizable read command, confirm that @@ -77,16 +73,14 @@ extern MONGO_DECLARE_SHIM((OperationContext * opCtx, * A readConcernTimeout of 0 indicates that the operation will block indefinitely waiting for read * concern. */ -extern MONGO_DECLARE_SHIM((OperationContext * opCtx, const int readConcernTimeout)->Status) - waitForLinearizableReadConcern; +Status waitForLinearizableReadConcern(OperationContext* opCtx, int readConcernTimeout); /** * Waits to satisfy a "speculative" majority read. * * This method must only be called if the operation is a speculative majority read. */ -extern MONGO_DECLARE_SHIM((OperationContext * opCtx, - repl::SpeculativeMajorityReadInfo speculativeReadInfo) - ->Status) waitForSpeculativeMajorityReadConcern; +Status waitForSpeculativeMajorityReadConcern(OperationContext* opCtx, + repl::SpeculativeMajorityReadInfo speculativeReadInfo); } // namespace mongo diff --git a/src/mongo/db/read_concern_mongod.cpp b/src/mongo/db/read_concern_mongod.cpp index 5cd75844f95..3569bc526c0 100644 --- a/src/mongo/db/read_concern_mongod.cpp +++ b/src/mongo/db/read_concern_mongod.cpp @@ -29,6 +29,7 @@ #define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kCommand +#include "mongo/base/shim.h" #include "mongo/base/status.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -232,13 +233,9 @@ bool canIgnorePrepareConflicts(OperationContext* opCtx, return true; } -} // namespace - -MONGO_REGISTER_SHIM(setPrepareConflictBehaviorForReadConcern) -(OperationContext* opCtx, - const repl::ReadConcernArgs& readConcernArgs, - PrepareConflictBehavior prepareConflictBehavior) - ->void { +void setPrepareConflictBehaviorForReadConcernImpl(OperationContext* opCtx, + const repl::ReadConcernArgs& readConcernArgs, + PrepareConflictBehavior prepareConflictBehavior) { // DBDirectClient should inherit whether or not to ignore prepare conflicts from its parent. if (opCtx->getClient()->isInDirectClient()) { return; @@ -253,9 +250,9 @@ MONGO_REGISTER_SHIM(setPrepareConflictBehaviorForReadConcern) opCtx->recoveryUnit()->setPrepareConflictBehavior(prepareConflictBehavior); } -MONGO_REGISTER_SHIM(waitForReadConcern) -(OperationContext* opCtx, const repl::ReadConcernArgs& readConcernArgs, bool allowAfterClusterTime) - ->Status { +Status waitForReadConcernImpl(OperationContext* opCtx, + const repl::ReadConcernArgs& readConcernArgs, + bool allowAfterClusterTime) { // If we are in a direct client within a transaction, then we may be holding locks, so it is // illegal to wait for read concern. This is fine, since the outer operation should have handled // waiting for read concern. We don't want to ignore prepare conflicts because reads in @@ -387,8 +384,7 @@ MONGO_REGISTER_SHIM(waitForReadConcern) return Status::OK(); } -MONGO_REGISTER_SHIM(waitForLinearizableReadConcern) -(OperationContext* opCtx, const int readConcernTimeout)->Status { +Status waitForLinearizableReadConcernImpl(OperationContext* opCtx, const int readConcernTimeout) { CurOpFailpointHelpers::waitWhileFailPointEnabled( &hangBeforeLinearizableReadConcern, opCtx, "hangBeforeLinearizableReadConcern", [opCtx]() { log() << "batch update - hangBeforeLinearizableReadConcern fail point enabled. " @@ -443,8 +439,8 @@ MONGO_REGISTER_SHIM(waitForLinearizableReadConcern) return awaitReplResult.status; } -MONGO_REGISTER_SHIM(waitForSpeculativeMajorityReadConcern) -(OperationContext* opCtx, repl::SpeculativeMajorityReadInfo speculativeReadInfo)->Status { +Status waitForSpeculativeMajorityReadConcernImpl( + OperationContext* opCtx, repl::SpeculativeMajorityReadInfo speculativeReadInfo) { invariant(speculativeReadInfo.isSpeculativeRead()); // Select the timestamp to wait on. A command may have selected a specific timestamp to wait on. @@ -486,5 +482,14 @@ MONGO_REGISTER_SHIM(waitForSpeculativeMajorityReadConcern) return waitStatus; } +auto setPrepareConflictBehaviorForReadConcernRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + setPrepareConflictBehaviorForReadConcern, setPrepareConflictBehaviorForReadConcernImpl); +auto waitForReadConcernRegistration = + MONGO_WEAK_FUNCTION_REGISTRATION(waitForReadConcern, waitForReadConcernImpl); +auto waitForLinearizableReadConcernRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + waitForLinearizableReadConcern, waitForLinearizableReadConcernImpl); +auto waitForSpeculativeMajorityReadConcernRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + waitForSpeculativeMajorityReadConcern, waitForSpeculativeMajorityReadConcernImpl); +} // namespace } // namespace mongo diff --git a/src/mongo/db/repl/oplog_shim.cpp b/src/mongo/db/repl/oplog_shim.cpp deleted file mode 100644 index f6efbe31683..00000000000 --- a/src/mongo/db/repl/oplog_shim.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (C) 2018-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/repl/oplog.h" - -namespace mongo { -namespace repl { -MONGO_DEFINE_SHIM(GetNextOpTimeClass::getNextOpTimes); -} // namespace repl -} // namespace mongo diff --git a/src/mongo/db/s/transaction_coordinator_curop.cpp b/src/mongo/db/s/transaction_coordinator_curop.cpp index 29df19804c0..8b910183d8f 100644 --- a/src/mongo/db/s/transaction_coordinator_curop.cpp +++ b/src/mongo/db/s/transaction_coordinator_curop.cpp @@ -27,7 +27,15 @@ * it in the license file. */ #include "mongo/db/s/transaction_coordinator_curop.h" +#include "mongo/base/shim.h" namespace mongo { -MONGO_DEFINE_SHIM(reportCurrentOpsForTransactionCoordinators); + +void reportCurrentOpsForTransactionCoordinators(OperationContext* opCtx, + bool includeIdle, + std::vector<BSONObj>* ops) { + static auto w = MONGO_WEAK_FUNCTION_DEFINITION(reportCurrentOpsForTransactionCoordinators); + w(opCtx, includeIdle, ops); +} + } // namespace mongo diff --git a/src/mongo/db/s/transaction_coordinator_curop.h b/src/mongo/db/s/transaction_coordinator_curop.h index 835a969c757..4ab1d2a9798 100644 --- a/src/mongo/db/s/transaction_coordinator_curop.h +++ b/src/mongo/db/s/transaction_coordinator_curop.h @@ -31,6 +31,9 @@ #include "mongo/db/pipeline/mongos_process_interface.h" namespace mongo { -extern MONGO_DECLARE_SHIM((OperationContext * opCtx, bool includeIdle, std::vector<BSONObj>* ops) - ->void) reportCurrentOpsForTransactionCoordinators; + +void reportCurrentOpsForTransactionCoordinators(OperationContext* opCtx, + bool includeIdle, + std::vector<BSONObj>* ops); + } // namespace mongo diff --git a/src/mongo/db/s/transaction_coordinator_curop_mongod.cpp b/src/mongo/db/s/transaction_coordinator_curop_mongod.cpp index 47104250272..ce5644cd826 100644 --- a/src/mongo/db/s/transaction_coordinator_curop_mongod.cpp +++ b/src/mongo/db/s/transaction_coordinator_curop_mongod.cpp @@ -30,9 +30,19 @@ #include "mongo/db/s/transaction_coordinator_service.h" +#include "mongo/base/shim.h" + namespace mongo { -MONGO_REGISTER_SHIM(reportCurrentOpsForTransactionCoordinators) -(OperationContext* opCtx, bool includeIdle, std::vector<BSONObj>* ops)->void { +namespace { + +void reportCurrentOpsForTransactionCoordinatorsImpl(OperationContext* opCtx, + bool includeIdle, + std::vector<BSONObj>* ops) { TransactionCoordinatorService::get(opCtx)->reportCoordinators(opCtx, includeIdle, ops); } + +auto reportCurrentOpsForTransactionCoordinatorsRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + reportCurrentOpsForTransactionCoordinators, reportCurrentOpsForTransactionCoordinatorsImpl); + +} // namespace } // namespace mongo diff --git a/src/mongo/db/s/transaction_coordinator_factory.cpp b/src/mongo/db/s/transaction_coordinator_factory.cpp index bdc892d4e76..524ac5a20d5 100644 --- a/src/mongo/db/s/transaction_coordinator_factory.cpp +++ b/src/mongo/db/s/transaction_coordinator_factory.cpp @@ -29,10 +29,14 @@ #include "mongo/platform/basic.h" +#include "mongo/base/shim.h" #include "mongo/db/s/transaction_coordinator_factory.h" namespace mongo { -MONGO_DEFINE_SHIM(createTransactionCoordinator); +void createTransactionCoordinator(OperationContext* opCtx, TxnNumber clientTxnNumber) { + static auto w = MONGO_WEAK_FUNCTION_DEFINITION(createTransactionCoordinator); + w(opCtx, clientTxnNumber); +} } // namespace mongo diff --git a/src/mongo/db/s/transaction_coordinator_factory.h b/src/mongo/db/s/transaction_coordinator_factory.h index 91a1f797829..9ac8b4e5ae4 100644 --- a/src/mongo/db/s/transaction_coordinator_factory.h +++ b/src/mongo/db/s/transaction_coordinator_factory.h @@ -29,13 +29,11 @@ #pragma once -#include "mongo/base/shim.h" #include "mongo/db/logical_session_id.h" #include "mongo/db/operation_context.h" namespace mongo { -extern MONGO_DECLARE_SHIM((OperationContext * opCtx, TxnNumber clientTxnNumber)->void) - createTransactionCoordinator; +void createTransactionCoordinator(OperationContext* opCtx, TxnNumber clientTxnNumber); } // namespace mongo diff --git a/src/mongo/db/s/transaction_coordinator_factory_mongod.cpp b/src/mongo/db/s/transaction_coordinator_factory_mongod.cpp index 4fea64fd339..16579b5fc96 100644 --- a/src/mongo/db/s/transaction_coordinator_factory_mongod.cpp +++ b/src/mongo/db/s/transaction_coordinator_factory_mongod.cpp @@ -29,15 +29,16 @@ #include "mongo/platform/basic.h" +#include "mongo/base/shim.h" #include "mongo/db/s/transaction_coordinator_factory.h" #include "mongo/db/s/transaction_coordinator_service.h" #include "mongo/db/transaction_participant.h" #include "mongo/db/transaction_participant_gen.h" namespace mongo { +namespace { -MONGO_REGISTER_SHIM(createTransactionCoordinator) -(OperationContext* opCtx, TxnNumber clientTxnNumber)->void { +void createTransactionCoordinatorImpl(OperationContext* opCtx, TxnNumber clientTxnNumber) { auto clientLsid = opCtx->getLogicalSessionId().get(); auto clockSource = opCtx->getServiceContext()->getFastClockSource(); @@ -50,4 +51,8 @@ MONGO_REGISTER_SHIM(createTransactionCoordinator) clockSource->now() + Seconds(gTransactionLifetimeLimitSeconds.load())); } +auto createTransactionCoordinatorRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + createTransactionCoordinator, createTransactionCoordinatorImpl); + +} // namespace } // namespace mongo diff --git a/src/mongo/db/s/transaction_coordinator_worker_curop_info.cpp b/src/mongo/db/s/transaction_coordinator_worker_curop_info.cpp index ead0c5e48ac..970ce795f3c 100644 --- a/src/mongo/db/s/transaction_coordinator_worker_curop_info.cpp +++ b/src/mongo/db/s/transaction_coordinator_worker_curop_info.cpp @@ -33,6 +33,10 @@ namespace mongo { -MONGO_DEFINE_SHIM(getTransactionCoordinatorWorkerCurOpRepository); +std::shared_ptr<TransactionCoordinatorWorkerCurOpRepository> +getTransactionCoordinatorWorkerCurOpRepository() { + static auto w = MONGO_WEAK_FUNCTION_DEFINITION(getTransactionCoordinatorWorkerCurOpRepository); + return w(); +} } // namespace mongo diff --git a/src/mongo/db/s/transaction_coordinator_worker_curop_info.h b/src/mongo/db/s/transaction_coordinator_worker_curop_info.h index 461fed02ec2..2261d5072a2 100644 --- a/src/mongo/db/s/transaction_coordinator_worker_curop_info.h +++ b/src/mongo/db/s/transaction_coordinator_worker_curop_info.h @@ -30,7 +30,6 @@ #include "mongo/db/s/transaction_coordinator_worker_curop_repository.h" -#include "mongo/base/shim.h" #include "mongo/db/curop.h" namespace mongo { diff --git a/src/mongo/db/s/transaction_coordinator_worker_curop_repository.cpp b/src/mongo/db/s/transaction_coordinator_worker_curop_repository.cpp index 4c9e0d103b8..0ee7c95dab8 100644 --- a/src/mongo/db/s/transaction_coordinator_worker_curop_repository.cpp +++ b/src/mongo/db/s/transaction_coordinator_worker_curop_repository.cpp @@ -31,8 +31,14 @@ #include "mongo/db/s/transaction_coordinator_worker_curop_repository.h" +#include "mongo/base/shim.h" + namespace mongo { -MONGO_DEFINE_SHIM(getTransactionCoordinatorWorkerCurOpRepository); +std::shared_ptr<TransactionCoordinatorWorkerCurOpRepository> +getTransactionCoordinatorWorkerCurOpRepository() { + static auto w = MONGO_WEAK_FUNCTION_DEFINITION(getTransactionCoordinatorWorkerCurOpRepository); + return w(); +} } // namespace mongo diff --git a/src/mongo/db/s/transaction_coordinator_worker_curop_repository.h b/src/mongo/db/s/transaction_coordinator_worker_curop_repository.h index a19f72fea12..17987137c91 100644 --- a/src/mongo/db/s/transaction_coordinator_worker_curop_repository.h +++ b/src/mongo/db/s/transaction_coordinator_worker_curop_repository.h @@ -28,11 +28,9 @@ */ #pragma once -#include "mongo/base/shim.h" #include "mongo/db/curop.h" namespace mongo { -class TransactionCoordinatorWorkerCurOpRepository; class TransactionCoordinatorWorkerCurOpRepository { public: @@ -65,6 +63,7 @@ public: virtual void reportState(OperationContext* opCtx, BSONObjBuilder* parent) const = 0; }; -extern MONGO_DECLARE_SHIM(()->std::shared_ptr<TransactionCoordinatorWorkerCurOpRepository>) - getTransactionCoordinatorWorkerCurOpRepository; +std::shared_ptr<TransactionCoordinatorWorkerCurOpRepository> +getTransactionCoordinatorWorkerCurOpRepository(); + } // namespace mongo diff --git a/src/mongo/db/s/transaction_coordinator_worker_curop_repository_mongod.cpp b/src/mongo/db/s/transaction_coordinator_worker_curop_repository_mongod.cpp index a805e6f69f8..84656f496d1 100644 --- a/src/mongo/db/s/transaction_coordinator_worker_curop_repository_mongod.cpp +++ b/src/mongo/db/s/transaction_coordinator_worker_curop_repository_mongod.cpp @@ -34,6 +34,8 @@ namespace mongo { const auto getTransactionCoordinatorWorkerCurOpInfo = OperationContext::declareDecoration<boost::optional<TransactionCoordinatorWorkerCurOpInfo>>(); +namespace { + class MongoDTransactionCoordinatorWorkerCurOpRepository final : public TransactionCoordinatorWorkerCurOpRepository { public: @@ -62,11 +64,17 @@ public: const auto _transactionCoordinatorWorkerCurOpRepository = std::make_shared<MongoDTransactionCoordinatorWorkerCurOpRepository>(); -MONGO_REGISTER_SHIM(getTransactionCoordinatorWorkerCurOpRepository) -()->std::shared_ptr<TransactionCoordinatorWorkerCurOpRepository> { +std::shared_ptr<TransactionCoordinatorWorkerCurOpRepository> +getTransactionCoordinatorWorkerCurOpRepositoryImpl() { return _transactionCoordinatorWorkerCurOpRepository; } +auto getTransactionCoordinatorWorkerCurOpRepositoryRegistration = + MONGO_WEAK_FUNCTION_REGISTRATION(getTransactionCoordinatorWorkerCurOpRepository, + getTransactionCoordinatorWorkerCurOpRepositoryImpl); + +} // namespace + TransactionCoordinatorWorkerCurOpInfo::TransactionCoordinatorWorkerCurOpInfo( LogicalSessionId lsid, TxnNumber txnNumber, Date_t startTime, CoordinatorAction action) : _lsid(lsid), _txnNumber(txnNumber), _startTime(startTime), _action(action) {} diff --git a/src/mongo/embedded/embedded_auth_manager.cpp b/src/mongo/embedded/embedded_auth_manager.cpp index 4701be9c91a..8e80ceea52c 100644 --- a/src/mongo/embedded/embedded_auth_manager.cpp +++ b/src/mongo/embedded/embedded_auth_manager.cpp @@ -29,6 +29,7 @@ #include "mongo/platform/basic.h" +#include "mongo/base/shim.h" #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/embedded/not_implemented.h" @@ -146,10 +147,19 @@ public: private: bool _shouldValidate = false; }; + } // namespace } // namespace embedded -MONGO_REGISTER_SHIM(AuthorizationManager::create)()->std::unique_ptr<AuthorizationManager> { +namespace { + +std::unique_ptr<AuthorizationManager> authorizationManagerCreateImpl() { return std::make_unique<embedded::AuthorizationManager>(); } + +auto authorizationManagerCreateRegistration = + MONGO_WEAK_FUNCTION_REGISTRATION(AuthorizationManager::create, authorizationManagerCreateImpl); + +} // namespace + } // namespace mongo diff --git a/src/mongo/embedded/embedded_auth_session.cpp b/src/mongo/embedded/embedded_auth_session.cpp index d012f913463..9f4fcfdbd58 100644 --- a/src/mongo/embedded/embedded_auth_session.cpp +++ b/src/mongo/embedded/embedded_auth_session.cpp @@ -29,6 +29,7 @@ #include "mongo/platform/basic.h" +#include "mongo/base/shim.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/embedded/not_implemented.h" #include "mongo/util/assert_util.h" @@ -277,9 +278,16 @@ private: } // namespace } // namespace embedded -MONGO_REGISTER_SHIM(AuthorizationSession::create) -(AuthorizationManager* const authzManager)->std::unique_ptr<AuthorizationSession> { +namespace { + +std::unique_ptr<AuthorizationSession> authorizationSessionCreateImpl( + AuthorizationManager* authzManager) { return std::make_unique<embedded::AuthorizationSession>(authzManager); } +auto authorizationSessionCreateRegistration = + MONGO_WEAK_FUNCTION_REGISTRATION(AuthorizationSession::create, authorizationSessionCreateImpl); + +} // namespace + } // namespace mongo diff --git a/src/mongo/embedded/process_interface_factory_embedded.cpp b/src/mongo/embedded/process_interface_factory_embedded.cpp index 54f31980dea..4be510f2d3c 100644 --- a/src/mongo/embedded/process_interface_factory_embedded.cpp +++ b/src/mongo/embedded/process_interface_factory_embedded.cpp @@ -29,13 +29,18 @@ #include "mongo/platform/basic.h" +#include "mongo/base/shim.h" #include "mongo/db/pipeline/process_interface_standalone.h" namespace mongo { +namespace { -MONGO_REGISTER_SHIM(MongoProcessInterface::create) -(OperationContext* opCtx)->std::shared_ptr<MongoProcessInterface> { +std::shared_ptr<MongoProcessInterface> mongoProcessInterfaceCreateImpl(OperationContext* opCtx) { return std::make_shared<MongoInterfaceStandalone>(opCtx); } +auto mongoProcessInterfaceCreateRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + MongoProcessInterface::create, mongoProcessInterfaceCreateImpl); + +} // namespace } // namespace mongo diff --git a/src/mongo/embedded/read_concern_embedded.cpp b/src/mongo/embedded/read_concern_embedded.cpp index dde836dca47..d6fc2a0cbe7 100644 --- a/src/mongo/embedded/read_concern_embedded.cpp +++ b/src/mongo/embedded/read_concern_embedded.cpp @@ -27,21 +27,22 @@ * it in the license file. */ +#include "mongo/base/shim.h" #include "mongo/db/read_concern.h" #include "mongo/db/repl/read_concern_args.h" #include "mongo/db/repl/speculative_majority_read_info.h" namespace mongo { +namespace { -MONGO_REGISTER_SHIM(setPrepareConflictBehaviorForReadConcern) -(OperationContext* opCtx, - const repl::ReadConcernArgs& readConcernArgs, - PrepareConflictBehavior requestedPrepareConflictBehavior) - ->void {} +void setPrepareConflictBehaviorForReadConcernImpl( + OperationContext* opCtx, + const repl::ReadConcernArgs& readConcernArgs, + PrepareConflictBehavior requestedPrepareConflictBehavior) {} -MONGO_REGISTER_SHIM(waitForReadConcern) -(OperationContext* opCtx, const repl::ReadConcernArgs& readConcernArgs, bool allowAfterClusterTime) - ->Status { +Status waitForReadConcernImpl(OperationContext* opCtx, + const repl::ReadConcernArgs& readConcernArgs, + bool allowAfterClusterTime) { if (readConcernArgs.getLevel() == repl::ReadConcernLevel::kLinearizableReadConcern) { return {ErrorCodes::NotImplemented, "linearizable read concern not supported on embedded"}; } else if (readConcernArgs.getLevel() == repl::ReadConcernLevel::kSnapshotReadConcern) { @@ -56,14 +57,24 @@ MONGO_REGISTER_SHIM(waitForReadConcern) return Status::OK(); } -MONGO_REGISTER_SHIM(waitForSpeculativeMajorityReadConcern) -(OperationContext* opCtx, repl::SpeculativeMajorityReadInfo speculativeReadInfo)->Status { + +Status waitForSpeculativeMajorityReadConcernImpl( + OperationContext* opCtx, repl::SpeculativeMajorityReadInfo speculativeReadInfo) { return Status::OK(); } -MONGO_REGISTER_SHIM(waitForLinearizableReadConcern) -(OperationContext* opCtx, const int readConcernTimeout)->Status { +Status waitForLinearizableReadConcernImpl(OperationContext* opCtx, int readConcernTimeout) { return Status::OK(); } +auto setPrepareConflictBehaviorForReadConcernRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + setPrepareConflictBehaviorForReadConcern, setPrepareConflictBehaviorForReadConcernImpl); +auto waitForReadConcernRegistration = + MONGO_WEAK_FUNCTION_REGISTRATION(waitForReadConcern, waitForReadConcernImpl); +auto waitForSpeculativeMajorityReadConcernRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + waitForSpeculativeMajorityReadConcern, waitForSpeculativeMajorityReadConcernImpl); +auto waitForLinearizableReadConcernRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + waitForLinearizableReadConcern, waitForLinearizableReadConcernImpl); + +} // namespace } // namespace mongo diff --git a/src/mongo/embedded/transaction_coordinator_curop_embedded.cpp b/src/mongo/embedded/transaction_coordinator_curop_embedded.cpp index ecec687a3e7..48823dafc7a 100644 --- a/src/mongo/embedded/transaction_coordinator_curop_embedded.cpp +++ b/src/mongo/embedded/transaction_coordinator_curop_embedded.cpp @@ -26,9 +26,19 @@ * exception statement from all source files in the program, then also delete * it in the license file. */ +#include "mongo/base/shim.h" #include "mongo/db/s/transaction_coordinator_curop.h" namespace mongo { -MONGO_REGISTER_SHIM(reportCurrentOpsForTransactionCoordinators) -(OperationContext* opCtx, bool includeIdle, std::vector<BSONObj>* ops)->void {} +namespace { + +void reportCurrentOpsForTransactionCoordinatorsImpl(OperationContext* opCtx, + bool includeIdle, + std::vector<BSONObj>* ops) {} + +auto reportCurrentOpsForTransactionCoordinatorsRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + reportCurrentOpsForTransactionCoordinators, reportCurrentOpsForTransactionCoordinatorsImpl); + + +} // namespace } // namespace mongo diff --git a/src/mongo/embedded/transaction_coordinator_factory_embedded.cpp b/src/mongo/embedded/transaction_coordinator_factory_embedded.cpp index 15e03a5471b..a90e130d13c 100644 --- a/src/mongo/embedded/transaction_coordinator_factory_embedded.cpp +++ b/src/mongo/embedded/transaction_coordinator_factory_embedded.cpp @@ -29,9 +29,16 @@ #include "mongo/platform/basic.h" +#include "mongo/base/shim.h" #include "mongo/db/s/transaction_coordinator_factory.h" namespace mongo { -MONGO_REGISTER_SHIM(createTransactionCoordinator) -(OperationContext* opCtx, TxnNumber clientTxnNumber)->void {} +namespace { + +void createTransactionCoordinatorImpl(OperationContext*, TxnNumber) {} + +auto createTransactionCoordinatorRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + createTransactionCoordinator, createTransactionCoordinatorImpl); + +} // namespace } // namespace mongo diff --git a/src/mongo/embedded/transaction_coordinator_worker_curop_repository_embedded.cpp b/src/mongo/embedded/transaction_coordinator_worker_curop_repository_embedded.cpp index a330a42c2d0..b1975b31a9f 100644 --- a/src/mongo/embedded/transaction_coordinator_worker_curop_repository_embedded.cpp +++ b/src/mongo/embedded/transaction_coordinator_worker_curop_repository_embedded.cpp @@ -31,6 +31,8 @@ #include "mongo/db/s/transaction_coordinator_worker_curop_repository.h" namespace mongo { +namespace { + class NoOpTransactionCoordinatorWorkerCurOpRepository final : public TransactionCoordinatorWorkerCurOpRepository { public: @@ -47,8 +49,14 @@ public: const auto _transactionCoordinatorWorkerCurOpRepository = std::make_shared<NoOpTransactionCoordinatorWorkerCurOpRepository>(); -MONGO_REGISTER_SHIM(getTransactionCoordinatorWorkerCurOpRepository) -()->std::shared_ptr<TransactionCoordinatorWorkerCurOpRepository> { +std::shared_ptr<TransactionCoordinatorWorkerCurOpRepository> +getTransactionCoordinatorWorkerCurOpRepositoryImpl() { return _transactionCoordinatorWorkerCurOpRepository; } + +auto getTransactionCoordinatorWorkerCurOpRepositoryRegistration = + MONGO_WEAK_FUNCTION_REGISTRATION(getTransactionCoordinatorWorkerCurOpRepository, + getTransactionCoordinatorWorkerCurOpRepositoryImpl); + +} // namespace } // namespace mongo diff --git a/src/mongo/shell/bench.cpp b/src/mongo/shell/bench.cpp index 1f318f938dd..9e7dfe3d3a7 100644 --- a/src/mongo/shell/bench.cpp +++ b/src/mongo/shell/bench.cpp @@ -35,6 +35,7 @@ #include <pcrecpp.h> +#include "mongo/base/shim.h" #include "mongo/client/dbclient_cursor.h" #include "mongo/db/namespace_string.h" #include "mongo/db/query/cursor_response.h" @@ -743,7 +744,11 @@ void BenchRunConfig::initializeFromBson(const BSONObj& args) { } } -MONGO_DEFINE_SHIM(BenchRunConfig::createConnectionImpl); +std::unique_ptr<DBClientBase> BenchRunConfig::createConnectionImpl( + const BenchRunConfig& benchRunConfig) { + static auto w = MONGO_WEAK_FUNCTION_DEFINITION(BenchRunConfig::createConnectionImpl); + return w(benchRunConfig); +} std::unique_ptr<DBClientBase> BenchRunConfig::createConnection() const { return BenchRunConfig::createConnectionImpl(*this); diff --git a/src/mongo/shell/bench.h b/src/mongo/shell/bench.h index 170023917ac..e558be8ec40 100644 --- a/src/mongo/shell/bench.h +++ b/src/mongo/shell/bench.h @@ -32,7 +32,6 @@ #include <boost/optional.hpp> #include <string> -#include "mongo/base/shim.h" #include "mongo/client/dbclient_base.h" #include "mongo/db/jsobj.h" #include "mongo/db/logical_session_id.h" @@ -159,8 +158,7 @@ public: */ static BenchRunConfig* createFromBson(const BSONObj& args); - static MONGO_DECLARE_SHIM((const BenchRunConfig&)->std::unique_ptr<DBClientBase>) - createConnectionImpl; + static std::unique_ptr<DBClientBase> createConnectionImpl(const BenchRunConfig&); BenchRunConfig(); diff --git a/src/mongo/shell/shell_utils.cpp b/src/mongo/shell/shell_utils.cpp index d45789ca403..b9e6b9fa7a2 100644 --- a/src/mongo/shell/shell_utils.cpp +++ b/src/mongo/shell/shell_utils.cpp @@ -126,18 +126,19 @@ extern const JSFile bridge; extern const JSFile feature_compatibility_version; } // namespace JSFiles -MONGO_REGISTER_SHIM(BenchRunConfig::createConnectionImpl) -(const BenchRunConfig& config)->std::unique_ptr<DBClientBase> { - const ConnectionString connectionString = uassertStatusOK(ConnectionString::parse(config.host)); +namespace { +std::unique_ptr<DBClientBase> benchRunConfigCreateConnectionImplProvider( + const BenchRunConfig& config) { + const ConnectionString connectionString = uassertStatusOK(ConnectionString::parse(config.host)); std::string errorMessage; std::unique_ptr<DBClientBase> connection(connectionString.connect("BenchRun", errorMessage)); uassert(16158, errorMessage, connection); - return connection; } -namespace { +auto benchRunConfigCreateConnectionImplRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + BenchRunConfig::createConnectionImpl, benchRunConfigCreateConnectionImplProvider); // helper functions for isBalanced bool isUseCmd(std::string code) { diff --git a/src/mongo/tools/mongoebench_main.cpp b/src/mongo/tools/mongoebench_main.cpp index 89feb7cfb55..74f81264289 100644 --- a/src/mongo/tools/mongoebench_main.cpp +++ b/src/mongo/tools/mongoebench_main.cpp @@ -34,6 +34,7 @@ #include <boost/filesystem.hpp> #include "mongo/base/init.h" +#include "mongo/base/shim.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/service_context.h" #include "mongo/embedded/embedded.h" @@ -144,13 +145,14 @@ int mongoeBenchMain(int argc, char* argv[], char** envp) { shutdown(EXIT_CLEAN); } -} // namespace - -MONGO_REGISTER_SHIM(BenchRunConfig::createConnectionImpl) -(const BenchRunConfig& config)->std::unique_ptr<DBClientBase> { +std::unique_ptr<DBClientBase> benchRunConfigCreateConnectionImplProvider(const BenchRunConfig&) { return std::unique_ptr<DBClientBase>(new DBDirectClientWithOwnOpCtx()); } +auto benchRunConfigCreateConnectionImplRegistration = MONGO_WEAK_FUNCTION_REGISTRATION( + BenchRunConfig::createConnectionImpl, benchRunConfigCreateConnectionImplProvider); +} // namespace + } // namespace mongo #if defined(_WIN32) |