1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-07-30 07:23:07 +03:00

Pass callback to get provider options to provider_v26 constructor

Passing a callback allows constructing the options string using
config service after loading the provider but before initializing
the provider.
This commit is contained in:
Teemu Ollakka
2025-02-19 13:31:52 +02:00
committed by Daniele Sciascia
parent 2dc8339ff1
commit cb8f870d58
7 changed files with 41 additions and 14 deletions

View File

@ -29,6 +29,7 @@
#include <cstring> #include <cstring>
#include <functional>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@ -527,10 +528,9 @@ namespace wsrep
static std::unique_ptr<provider> make_provider( static std::unique_ptr<provider> make_provider(
wsrep::server_state&, wsrep::server_state&,
const std::string& provider_spec, const std::string& provider_spec,
const std::string& provider_options, const std::function<std::string()>& provider_options_cb,
const wsrep::provider::services& services const wsrep::provider::services& services
= wsrep::provider::services()); = wsrep::provider::services());
protected: protected:
wsrep::server_state& server_state_; wsrep::server_state& server_state_;
}; };

View File

@ -287,18 +287,43 @@ namespace wsrep
* Load WSRep provider. * Load WSRep provider.
* *
* @param provider WSRep provider library to be loaded. * @param provider WSRep provider library to be loaded.
* @param provider_options Provider specific options string * @param provider_options_cb Callback to get provider options.
* to be passed for provider during initialization. * The function to be called must be
* idempotent.
* @param services Application defined services passed to * @param services Application defined services passed to
* the provider. * the provider.
* *
* @return Zero on success, non-zero on error. * @return Zero on success, non-zero on error.
*/ */
int load_provider(const std::string& provider, int load_provider(const std::string& provider,
const std::string& provider_options, const std::function<std::string()>& provider_options_cb,
const wsrep::provider::services& services const wsrep::provider::services& services
= wsrep::provider::services()); = wsrep::provider::services());
/**
* Load WSRep provider.
*
* @param provider WSRep provider library to be loaded.
* @param provider_options Provider specific options string
* to be passed for provider during initialization.
* @param services Application defined services passed to
* the provider.
*
* @return Zero on success, non-zero on error.
*
* @note Provided for backward compatibility.
*/
int load_provider(const std::string& provider,
const std::string& provider_options,
const wsrep::provider::services& services
= wsrep::provider::services())
{
return load_provider(provider,
[provider_options]() { return provider_options; },
services);
}
using provider_factory_func = using provider_factory_func =
std::function<decltype(wsrep::provider::make_provider)>; std::function<decltype(wsrep::provider::make_provider)>;

View File

@ -29,19 +29,19 @@
std::unique_ptr<wsrep::provider> wsrep::provider::make_provider( std::unique_ptr<wsrep::provider> wsrep::provider::make_provider(
wsrep::server_state& server_state, wsrep::server_state& server_state,
const std::string& provider_spec, const std::string& provider_spec,
const std::string& provider_options, const std::function<std::string()>& provider_options_cb,
const wsrep::provider::services& services) const wsrep::provider::services& services)
{ {
try try
{ {
return std::unique_ptr<wsrep::provider>(new wsrep::wsrep_provider_v26( return std::unique_ptr<wsrep::provider>(new wsrep::wsrep_provider_v26(
server_state, provider_options, provider_spec, services)); server_state, provider_spec, provider_options_cb, services));
} }
catch (const wsrep::runtime_error& e) catch (const wsrep::runtime_error& e)
{ {
wsrep::log_error() << "Failed to create a new provider '" wsrep::log_error() << "Failed to create a new provider '"
<< provider_spec << "'" << provider_spec << "'"
<< " with options '" << provider_options << " with options '" << provider_options_cb()
<< "': " << e.what(); << "': " << e.what();
} }
catch (...) catch (...)
@ -49,7 +49,7 @@ std::unique_ptr<wsrep::provider> wsrep::provider::make_provider(
wsrep::log_error() << "Caught unknown exception when trying to " wsrep::log_error() << "Caught unknown exception when trying to "
<< "create a new provider '" << "create a new provider '"
<< provider_spec << "'" << provider_spec << "'"
<< " with options '" << provider_options; << " with options '" << provider_options_cb();
} }
return 0; return 0;
} }

View File

@ -499,13 +499,14 @@ static int apply_toi(wsrep::provider& provider,
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
int wsrep::server_state::load_provider( int wsrep::server_state::load_provider(
const std::string& provider_spec, const std::string& provider_options, const std::string& provider_spec,
const std::function<std::string()>& provider_options_cb,
const wsrep::provider::services& services) const wsrep::provider::services& services)
{ {
wsrep::log_info() << "Loading provider " << provider_spec wsrep::log_info() << "Loading provider " << provider_spec
<< " initial position: " << initial_position_; << " initial position: " << initial_position_;
provider_ provider_
= provider_factory_(*this, provider_spec, provider_options, services); = provider_factory_(*this, provider_spec, provider_options_cb, services);
return (provider_ ? 0 : 1); return (provider_ ? 0 : 1);
} }

View File

@ -775,8 +775,8 @@ void wsrep::wsrep_provider_v26::deinit_services()
wsrep::wsrep_provider_v26::wsrep_provider_v26( wsrep::wsrep_provider_v26::wsrep_provider_v26(
wsrep::server_state& server_state, wsrep::server_state& server_state,
const std::string& provider_options,
const std::string& provider_spec, const std::string& provider_spec,
const std::function<std::string()>& provider_options_cb,
const wsrep::provider::services& services) const wsrep::provider::services& services)
: provider(server_state) : provider(server_state)
, wsrep_() , wsrep_()
@ -796,6 +796,7 @@ wsrep::wsrep_provider_v26::wsrep_provider_v26(
init_args.node_address = server_state_.address().c_str(); init_args.node_address = server_state_.address().c_str();
init_args.node_incoming = server_state_.incoming_address().c_str(); init_args.node_incoming = server_state_.incoming_address().c_str();
init_args.data_dir = server_state_.working_dir().c_str(); init_args.data_dir = server_state_.working_dir().c_str();
const auto& provider_options = provider_options_cb();
init_args.options = provider_options.c_str(); init_args.options = provider_options.c_str();
init_args.proto_ver = server_state.max_protocol_version(); init_args.proto_ver = server_state.max_protocol_version();
init_args.state_id = &state_id; init_args.state_id = &state_id;

View File

@ -33,7 +33,7 @@ namespace wsrep
void init_services(const wsrep::provider::services& services); void init_services(const wsrep::provider::services& services);
void deinit_services(); void deinit_services();
wsrep_provider_v26(wsrep::server_state&, const std::string&, wsrep_provider_v26(wsrep::server_state&, const std::string&,
const std::string&, const std::function<std::string()>&,
const wsrep::provider::services& services); const wsrep::provider::services& services);
~wsrep_provider_v26() WSREP_OVERRIDE; ~wsrep_provider_v26() WSREP_OVERRIDE;
enum wsrep::provider::status enum wsrep::provider::status

View File

@ -262,7 +262,7 @@ namespace wsrep
{ {
set_provider_factory([&](wsrep::server_state&, set_provider_factory([&](wsrep::server_state&,
const std::string&, const std::string&,
const std::string&, const std::function<std::string()>&,
const wsrep::provider::services&) const wsrep::provider::services&)
{ {
// The provider object is destroyed upon server state // The provider object is destroyed upon server state