MXS-2486: Make SSL configurations immutable

Changes to SSL configurations is expected to be rare which allows them to
be made into immutable objects once created. This is an acceptable
compromise between performance and usability.
This commit is contained in:
Markus Mäkelä
2019-05-24 13:11:24 +03:00
parent 52ef9afcc6
commit 859e930466
2 changed files with 13 additions and 10 deletions

View File

@ -151,12 +151,17 @@ public:
SSLProvider(std::unique_ptr<mxs::SSLContext> context); SSLProvider(std::unique_ptr<mxs::SSLContext> context);
// Current configuration
const mxs::SSLConfig& config() const; const mxs::SSLConfig& config() const;
mxs::SSLContext* context() const;
void set_context(std::unique_ptr<mxs::SSLContext> ssl); // The context or nullptr if no context is set
mxs::SSLContext* context() const;
// Set the context, argument must not be null
void set_context(std::unique_ptr<mxs::SSLContext> ssl);
private: private:
mxs::rworker_local<std::shared_ptr<mxs::SSLContext>> m_context; /**< SSL context */ std::unique_ptr<mxs::SSLContext> m_context; /**< SSL context */
mxs::SSLConfig m_config; /**< SSL configuration */ mxs::SSLConfig m_config; /**< SSL configuration */
}; };
} }

View File

@ -422,7 +422,7 @@ SSLProvider::SSLProvider(std::unique_ptr<mxs::SSLContext> context)
mxs::SSLContext* SSLProvider::context() const mxs::SSLContext* SSLProvider::context() const
{ {
mxb_assert_message(mxs::RoutingWorker::get_current(), "Must be used on a RoutingWorker"); mxb_assert_message(mxs::RoutingWorker::get_current(), "Must be used on a RoutingWorker");
return m_context->get(); return m_context.get();
} }
const mxs::SSLConfig& SSLProvider::config() const const mxs::SSLConfig& SSLProvider::config() const
@ -432,10 +432,8 @@ const mxs::SSLConfig& SSLProvider::config() const
void SSLProvider::set_context(std::unique_ptr<mxs::SSLContext> ssl) void SSLProvider::set_context(std::unique_ptr<mxs::SSLContext> ssl)
{ {
mxb_assert_message(mxs::RoutingWorker::get_current() mxb_assert(ssl);
== mxs::RoutingWorker::get(mxs::RoutingWorker::MAIN), m_context = std::move(ssl);
"Must be only set on the main RoutingWorker"); m_config = m_context->config();
m_config = ssl ? ssl->config() : mxs::SSLConfig {};
m_context.assign(std::move(ssl));
} }
} }