Skip to content

Commit d9b44fa

Browse files
committed
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.
1 parent 2d7b357 commit d9b44fa

File tree

6 files changed

+38
-11
lines changed

6 files changed

+38
-11
lines changed

Diff for: include/wsrep/provider.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <cstring>
3131

32+
#include <functional>
3233
#include <memory>
3334
#include <string>
3435
#include <vector>
@@ -514,10 +515,9 @@ namespace wsrep
514515
static std::unique_ptr<provider> make_provider(
515516
wsrep::server_state&,
516517
const std::string& provider_spec,
517-
const std::string& provider_options,
518+
const std::function<std::string()>& provider_options_cb,
518519
const wsrep::provider::services& services
519520
= wsrep::provider::services());
520-
521521
protected:
522522
wsrep::server_state& server_state_;
523523
};

Diff for: include/wsrep/server_state.hpp

+26-1
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,24 @@ namespace wsrep
283283
*/
284284
enum wsrep::provider::status send_pending_rollback_events();
285285

286+
/**
287+
* Load WSRep provider.
288+
*
289+
* @param provider WSRep provider library to be loaded.
290+
* @param provider_options_cb Callback to get provider options.
291+
* The function to be called must be
292+
* idempotent.
293+
* @param services Application defined services passed to
294+
* the provider.
295+
*
296+
* @return Zero on success, non-zero on error.
297+
*/
298+
int load_provider(const std::string& provider,
299+
const std::function<std::string()>& provider_options_cb,
300+
const wsrep::provider::services& services
301+
= wsrep::provider::services());
302+
303+
286304
/**
287305
* Load WSRep provider.
288306
*
@@ -293,11 +311,18 @@ namespace wsrep
293311
* the provider.
294312
*
295313
* @return Zero on success, non-zero on error.
314+
*
315+
* @note Provided for backward compatibility.
296316
*/
297317
int load_provider(const std::string& provider,
298318
const std::string& provider_options,
299319
const wsrep::provider::services& services
300-
= wsrep::provider::services());
320+
= wsrep::provider::services())
321+
{
322+
return load_provider(provider,
323+
[provider_options]() { return provider_options; },
324+
services);
325+
}
301326

302327
using provider_factory_func =
303328
std::function<decltype(wsrep::provider::make_provider)>;

Diff for: src/provider.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,27 @@
2929
std::unique_ptr<wsrep::provider> wsrep::provider::make_provider(
3030
wsrep::server_state& server_state,
3131
const std::string& provider_spec,
32-
const std::string& provider_options,
32+
const std::function<std::string()>& provider_options_cb,
3333
const wsrep::provider::services& services)
3434
{
3535
try
3636
{
3737
return std::unique_ptr<wsrep::provider>(new wsrep::wsrep_provider_v26(
38-
server_state, provider_options, provider_spec, services));
38+
server_state, provider_spec, provider_options_cb, services));
3939
}
4040
catch (const wsrep::runtime_error& e)
4141
{
4242
wsrep::log_error() << "Failed to create a new provider '"
4343
<< provider_spec << "'"
44-
<< " with options '" << provider_options
44+
<< " with options '" << provider_options_cb()
4545
<< "': " << e.what();
4646
}
4747
catch (...)
4848
{
4949
wsrep::log_error() << "Caught unknown exception when trying to "
5050
<< "create a new provider '"
5151
<< provider_spec << "'"
52-
<< " with options '" << provider_options;
52+
<< " with options '" << provider_options_cb();
5353
}
5454
return 0;
5555
}

Diff for: src/server_state.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,14 @@ static int apply_toi(wsrep::provider& provider,
499499
//////////////////////////////////////////////////////////////////////////////
500500

501501
int wsrep::server_state::load_provider(
502-
const std::string& provider_spec, const std::string& provider_options,
502+
const std::string& provider_spec,
503+
const std::function<std::string()>& provider_options_cb,
503504
const wsrep::provider::services& services)
504505
{
505506
wsrep::log_info() << "Loading provider " << provider_spec
506507
<< " initial position: " << initial_position_;
507508
provider_
508-
= provider_factory_(*this, provider_spec, provider_options, services);
509+
= provider_factory_(*this, provider_spec, provider_options_cb, services);
509510
return (provider_ ? 0 : 1);
510511
}
511512

Diff for: src/wsrep_provider_v26.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,8 @@ void wsrep::wsrep_provider_v26::deinit_services()
742742

743743
wsrep::wsrep_provider_v26::wsrep_provider_v26(
744744
wsrep::server_state& server_state,
745-
const std::string& provider_options,
746745
const std::string& provider_spec,
746+
const std::function<std::string()>& provider_options_cb,
747747
const wsrep::provider::services& services)
748748
: provider(server_state)
749749
, wsrep_()
@@ -763,6 +763,7 @@ wsrep::wsrep_provider_v26::wsrep_provider_v26(
763763
init_args.node_address = server_state_.address().c_str();
764764
init_args.node_incoming = server_state_.incoming_address().c_str();
765765
init_args.data_dir = server_state_.working_dir().c_str();
766+
const auto& provider_options = provider_options_cb();
766767
init_args.options = provider_options.c_str();
767768
init_args.proto_ver = server_state.max_protocol_version();
768769
init_args.state_id = &state_id;

Diff for: src/wsrep_provider_v26.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace wsrep
3333
void init_services(const wsrep::provider::services& services);
3434
void deinit_services();
3535
wsrep_provider_v26(wsrep::server_state&, const std::string&,
36-
const std::string&,
36+
const std::function<std::string()>&,
3737
const wsrep::provider::services& services);
3838
~wsrep_provider_v26() WSREP_OVERRIDE;
3939
enum wsrep::provider::status

0 commit comments

Comments
 (0)