1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-08-08 02:02:57 +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 way it is possible get options which are given
at DBMS startup, in command line or config file.
This commit is contained in:
Daniele Sciascia
2025-02-19 13:31:52 +02:00
parent 2dc8339ff1
commit 3965d83968
12 changed files with 195 additions and 56 deletions

View File

@@ -29,6 +29,7 @@
#include <cstring>
#include <functional>
#include <memory>
#include <string>
#include <vector>
@@ -50,6 +51,7 @@ namespace wsrep
class event_service;
class client_service;
class connection_monitor_service;
class provider_options;
class stid
{
public:
@@ -521,13 +523,13 @@ namespace wsrep
* Create a new provider.
*
* @param provider_spec Provider specification
* @param provider_options Initial options to provider
* @param provider_options_cb Callback to get initial provider options
* @param thread_service Optional thread service implementation.
*/
static std::unique_ptr<provider> make_provider(
wsrep::server_state&,
const std::string& provider_spec,
const std::string& provider_options,
wsrep::server_state&, const std::string& provider_spec,
const std::function<int(const provider_options&, std::string&)>&
provider_options_cb,
const wsrep::provider::services& services
= wsrep::provider::services());

View File

@@ -214,7 +214,7 @@ namespace wsrep
int flags_;
};
provider_options(wsrep::provider&);
provider_options();
provider_options(const provider_options&) = delete;
provider_options& operator=(const provider_options&) = delete;
@@ -225,7 +225,7 @@ namespace wsrep
*
* @return Provider status code.
*/
enum wsrep::provider::status initial_options();
enum wsrep::provider::status initial_options(wsrep::provider& provider);
/**
* Get the option with the given name
@@ -241,7 +241,8 @@ namespace wsrep
* @return wsrep::provider::error_size_exceeded if memory could
* not be allocated for the new value.
*/
enum wsrep::provider::status set(const std::string& name,
enum wsrep::provider::status set(wsrep::provider& provider,
const std::string& name,
std::unique_ptr<option_value> value);
/**
@@ -252,10 +253,15 @@ namespace wsrep
std::unique_ptr<option_value> value,
std::unique_ptr<option_value> default_value, int flags);
void for_each(const std::function<void(option*)>& fn);
/**
* Invoke the given function with each provider option
* as argument.
*
* @param fn Function to call for each option
*/
void for_each(const std::function<void(option*)>& fn) const;
private:
provider& provider_;
using options_map = std::map<std::string, std::unique_ptr<option>>;
options_map options_;
};

View File

@@ -117,6 +117,7 @@ namespace wsrep
class server_service;
class client_service;
class encryption_service;
class provider_options;
/** @class Server Context
*
@@ -287,17 +288,47 @@ namespace wsrep
* 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 provider_options_cb Callback to get provider options.
* The function to be called must be
* idempotent.
* @param services Application defined services passed to
* the provider.
*
* @return Zero on success, non-zero on error.
*/
int load_provider(
const std::string& provider,
const std::function<int(const provider_options&, std::string&)>&
provider_options_cb,
const wsrep::provider::services& services
= wsrep::provider::services());
/**
* Load WSRep provider.
*
* @param provider WSRep provider library to be loaded.
* @param 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 std::string& options,
const wsrep::provider::services& services
= wsrep::provider::services());
= wsrep::provider::services())
{
return load_provider(
provider,
[options](const provider_options&, std::string& option_string) {
option_string.append(options);
return 0;
},
services);
}
using provider_factory_func =
std::function<decltype(wsrep::provider::make_provider)>;