diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2020-08-11 12:09:45 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-08-11 16:58:25 +0000 |
commit | 28f2b388fc1ab81685d51caa53e240f7b5d3f13c (patch) | |
tree | b35c9f0d24ab481685c61a330ff17112435d3cf1 /src | |
parent | c602f35664ce98582f03cedfa142ce901f223224 (diff) | |
download | mongo-28f2b388fc1ab81685d51caa53e240f7b5d3f13c.tar.gz |
SERVER-50006 Move OCSPManager to ServiceContext
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/mongod_main.cpp | 3 | ||||
-rw-r--r-- | src/mongo/s/mongos_main.cpp | 4 | ||||
-rw-r--r-- | src/mongo/shell/mongo_main.cpp | 2 | ||||
-rw-r--r-- | src/mongo/util/net/ocsp/ocsp_manager.cpp | 21 | ||||
-rw-r--r-- | src/mongo/util/net/ocsp/ocsp_manager.h | 10 | ||||
-rw-r--r-- | src/mongo/util/net/ssl_manager_openssl.cpp | 3 |
6 files changed, 35 insertions, 8 deletions
diff --git a/src/mongo/db/mongod_main.cpp b/src/mongo/db/mongod_main.cpp index 36cee8e12be..2925d4762c5 100644 --- a/src/mongo/db/mongod_main.cpp +++ b/src/mongo/db/mongod_main.cpp @@ -341,7 +341,7 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) { serviceContext->setPeriodicRunner(std::move(runner)); #ifdef MONGO_CONFIG_SSL - OCSPManager::get()->startThreadPool(); + OCSPManager::start(serviceContext); CertificateExpirationMonitor::get()->start(serviceContext); #endif @@ -1320,6 +1320,7 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) { #endif FlowControl::shutdown(serviceContext); + OCSPManager::shutdown(serviceContext); } } // namespace diff --git a/src/mongo/s/mongos_main.cpp b/src/mongo/s/mongos_main.cpp index 9477303e6c9..7dd126bca28 100644 --- a/src/mongo/s/mongos_main.cpp +++ b/src/mongo/s/mongos_main.cpp @@ -394,6 +394,8 @@ void cleanupTask(const ShutdownTaskArgs& shutdownArgs) { #ifndef MONGO_CONFIG_USE_RAW_LATCHES LatchAnalyzer::get(serviceContext).dump(); #endif + + OCSPManager::shutdown(serviceContext); } Status initializeSharding(OperationContext* opCtx) { @@ -671,7 +673,7 @@ ExitCode runMongosServer(ServiceContext* serviceContext) { } #ifdef MONGO_CONFIG_SSL - OCSPManager::get()->startThreadPool(); + OCSPManager::start(serviceContext); CertificateExpirationMonitor::get()->start(serviceContext); #endif diff --git a/src/mongo/shell/mongo_main.cpp b/src/mongo/shell/mongo_main.cpp index e2651c86dc2..d8be01a8e0f 100644 --- a/src/mongo/shell/mongo_main.cpp +++ b/src/mongo/shell/mongo_main.cpp @@ -737,7 +737,7 @@ int mongo_main(int argc, char* argv[]) { auto serviceContext = getGlobalServiceContext(); #ifdef MONGO_CONFIG_SSL - OCSPManager::get()->startThreadPool(); + OCSPManager::start(serviceContext); #endif transport::TransportLayerASIO::Options opts; diff --git a/src/mongo/util/net/ocsp/ocsp_manager.cpp b/src/mongo/util/net/ocsp/ocsp_manager.cpp index 9b0a2e517c7..a620858ac9d 100644 --- a/src/mongo/util/net/ocsp/ocsp_manager.cpp +++ b/src/mongo/util/net/ocsp/ocsp_manager.cpp @@ -29,6 +29,8 @@ #include "mongo/platform/basic.h" +#include <memory> + #include "mongo/db/client.h" #include "mongo/executor/network_interface_factory.h" #include "mongo/util/net/ocsp/ocsp_manager.h" @@ -38,6 +40,8 @@ namespace mongo { namespace { +const auto getOCSPManager = ServiceContext::declareDecoration<std::unique_ptr<OCSPManager>>(); + auto makeTaskExecutor() { ThreadPool::Options tpOptions; tpOptions.poolName = "OCSPManagerHTTP"; @@ -50,6 +54,23 @@ auto makeTaskExecutor() { } // namespace +OCSPManager* OCSPManager::get(ServiceContext* service) { + return getOCSPManager(service).get(); +} + +void OCSPManager::start(ServiceContext* service) { + auto manager = std::make_unique<OCSPManager>(); + + manager->startThreadPool(); + + getOCSPManager(service) = std::move(manager); +} + +void OCSPManager::shutdown(ServiceContext* service) { + get(service)->_pool->shutdown(); + getOCSPManager(service).reset(); +} + OCSPManager::OCSPManager() { _pool = makeTaskExecutor(); diff --git a/src/mongo/util/net/ocsp/ocsp_manager.h b/src/mongo/util/net/ocsp/ocsp_manager.h index 674e3b5476b..2b4485eaea4 100644 --- a/src/mongo/util/net/ocsp/ocsp_manager.h +++ b/src/mongo/util/net/ocsp/ocsp_manager.h @@ -30,6 +30,7 @@ #include "mongo/base/data_range.h" +#include "mongo/db/service_context.h" #include "mongo/util/concurrency/thread_pool.h" #include "mongo/util/duration.h" #include "mongo/util/future.h" @@ -45,16 +46,17 @@ class OCSPManager { public: OCSPManager(); - static OCSPManager* get() { - static OCSPManager manager = OCSPManager(); + static void start(ServiceContext* service); - return &manager; - }; + static void shutdown(ServiceContext* service); + + static OCSPManager* get(ServiceContext* service); Future<std::vector<uint8_t>> requestStatus(std::vector<uint8_t> data, StringData responderURI, OCSPPurpose direction); +private: void startThreadPool(); private: diff --git a/src/mongo/util/net/ssl_manager_openssl.cpp b/src/mongo/util/net/ssl_manager_openssl.cpp index ba7519c0321..dd8667e5fee 100644 --- a/src/mongo/util/net/ssl_manager_openssl.cpp +++ b/src/mongo/util/net/ssl_manager_openssl.cpp @@ -48,6 +48,7 @@ #include "mongo/base/secure_allocator.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/config.h" +#include "mongo/db/service_context.h" #include "mongo/logv2/log.h" #include "mongo/platform/atomic_word.h" #include "mongo/transport/session.h" @@ -762,7 +763,7 @@ Future<UniqueOCSPResponse> retrieveOCSPResponse(const std::string& host, } // Query the OCSP responder - return OCSPManager::get() + return OCSPManager::get(getGlobalServiceContext()) ->requestStatus(buffer, host, purpose) .then([](std::vector<uint8_t> responseData) mutable -> StatusWith<UniqueOCSPResponse> { const uint8_t* respDataPtr = responseData.data(); |