Skip to content

Commit b491197

Browse files
author
Daniele Sciascia
committed
Change provider options callback signature to return error code
The callback now returns an error code and takes a reference to provider options string.
1 parent d36bfb2 commit b491197

File tree

7 files changed

+44
-27
lines changed

7 files changed

+44
-27
lines changed

include/wsrep/provider.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,12 @@ namespace wsrep
526526
* @param provider_options_cb Callback to get initial provider options
527527
* @param thread_service Optional thread service implementation.
528528
*/
529-
static std::unique_ptr<provider>
530-
make_provider(wsrep::server_state&, const std::string& provider_spec,
531-
const std::function<std::string(const provider_options&)>&
532-
provider_options_cb,
533-
const wsrep::provider::services& services
534-
= wsrep::provider::services());
529+
static std::unique_ptr<provider> make_provider(
530+
wsrep::server_state&, const std::string& provider_spec,
531+
const std::function<int(const provider_options&, std::string&)>&
532+
provider_options_cb,
533+
const wsrep::provider::services& services
534+
= wsrep::provider::services());
535535

536536
protected:
537537
wsrep::server_state& server_state_;

include/wsrep/server_state.hpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,12 @@ namespace wsrep
296296
*
297297
* @return Zero on success, non-zero on error.
298298
*/
299-
int load_provider(const std::string& provider,
300-
const std::function<std::string(
301-
const provider_options&)>& provider_options_cb,
302-
const wsrep::provider::services& services
303-
= wsrep::provider::services());
299+
int load_provider(
300+
const std::string& provider,
301+
const std::function<int(const provider_options&, std::string&)>&
302+
provider_options_cb,
303+
const wsrep::provider::services& services
304+
= wsrep::provider::services());
304305

305306
/**
306307
* Load WSRep provider.
@@ -321,7 +322,11 @@ namespace wsrep
321322
= wsrep::provider::services())
322323
{
323324
return load_provider(
324-
provider, [options](const provider_options&) { return options; },
325+
provider,
326+
[options](const provider_options&, std::string& option_string) {
327+
option_string.append(options);
328+
return 0;
329+
},
325330
services);
326331
}
327332

src/provider.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
std::unique_ptr<wsrep::provider> wsrep::provider::make_provider(
3131
wsrep::server_state& server_state, const std::string& provider_spec,
32-
const std::function<std::string(const provider_options&)>&
32+
const std::function<int(const provider_options&, std::string&)>&
3333
provider_options_cb,
3434
const wsrep::provider::services& services)
3535
{
@@ -41,19 +41,23 @@ std::unique_ptr<wsrep::provider> wsrep::provider::make_provider(
4141
}
4242
catch (const wsrep::runtime_error& e)
4343
{
44-
provider_options opts;
44+
provider_options options;
45+
std::string options_string;
4546
wsrep::log_error() << "Failed to create a new provider '"
4647
<< provider_spec << "'"
47-
<< " with options '" << provider_options_cb(opts)
48+
<< " with options '"
49+
<< provider_options_cb(options, options_string)
4850
<< "': " << e.what();
4951
}
5052
catch (...)
5153
{
52-
provider_options opts;
54+
provider_options options;
55+
std::string options_string;
5356
wsrep::log_error() << "Caught unknown exception when trying to "
5457
<< "create a new provider '"
5558
<< provider_spec << "'"
56-
<< " with options '" << provider_options_cb(opts);
59+
<< " with options '"
60+
<< provider_options_cb(options, options_string);
5761
}
5862
return 0;
5963
}

src/server_state.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ static int apply_toi(wsrep::provider& provider,
500500

501501
int wsrep::server_state::load_provider(
502502
const std::string& provider_spec,
503-
const std::function<std::string(const provider_options&)>&
503+
const std::function<int(const provider_options&, std::string&)>&
504504
provider_options_cb,
505505
const wsrep::provider::services& services)
506506
{

src/wsrep_provider_v26.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ void wsrep::wsrep_provider_v26::deinit_services()
778778
wsrep::wsrep_provider_v26::wsrep_provider_v26(
779779
wsrep::server_state& server_state,
780780
const std::string& provider_spec,
781-
const std::function<std::string(provider_options&)>& provider_options_cb,
781+
const std::function<int(provider_options&, std::string&)>& provider_options_cb,
782782
const wsrep::provider::services& services)
783783
: provider(server_state)
784784
, wsrep_()
@@ -798,8 +798,6 @@ wsrep::wsrep_provider_v26::wsrep_provider_v26(
798798
}
799799

800800
init_services(services);
801-
provider_options options;
802-
config_service_v2_fetch(wsrep_, &options);
803801

804802
struct wsrep_init_args init_args;
805803
memset(&init_args, 0, sizeof(init_args));
@@ -808,8 +806,6 @@ wsrep::wsrep_provider_v26::wsrep_provider_v26(
808806
init_args.node_address = server_state_.address().c_str();
809807
init_args.node_incoming = server_state_.incoming_address().c_str();
810808
init_args.data_dir = server_state_.working_dir().c_str();
811-
const auto& provider_options = provider_options_cb(options);
812-
init_args.options = provider_options.c_str();
813809
init_args.proto_ver = server_state.max_protocol_version();
814810
init_args.state_id = &state_id;
815811
init_args.state = 0;
@@ -823,6 +819,16 @@ wsrep::wsrep_provider_v26::wsrep_provider_v26(
823819
init_args.sst_donate_cb = &sst_donate_cb;
824820
init_args.synced_cb = &synced_cb;
825821

822+
provider_options options;
823+
config_service_v2_fetch(wsrep_, &options);
824+
825+
std::string provider_options;
826+
if (provider_options_cb(options, provider_options))
827+
{
828+
throw wsrep::runtime_error("Failed to initialize wsrep provider options");
829+
}
830+
init_args.options = provider_options.c_str();
831+
826832
if (wsrep_->init(wsrep_, &init_args) != WSREP_OK)
827833
{
828834
throw wsrep::runtime_error("Failed to initialize wsrep provider");

src/wsrep_provider_v26.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ namespace wsrep
3333
public:
3434
void init_services(const wsrep::provider::services& services);
3535
void deinit_services();
36-
wsrep_provider_v26(wsrep::server_state&, const std::string&,
37-
const std::function<std::string(provider_options&)>&,
38-
const wsrep::provider::services& services);
36+
wsrep_provider_v26(
37+
wsrep::server_state&, const std::string&,
38+
const std::function<int(provider_options&, std::string&)>&,
39+
const wsrep::provider::services& services);
3940
~wsrep_provider_v26() WSREP_OVERRIDE;
4041
enum wsrep::provider::status
4142
connect(const std::string&, const std::string&, const std::string&,

test/mock_server_state.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ namespace wsrep
263263
{
264264
set_provider_factory(
265265
[&](wsrep::server_state&, const std::string&,
266-
const std::function<std::string(const wsrep::provider_options&)>&,
266+
const std::function<int(const wsrep::provider_options&,
267+
std::string&)>&,
267268
const wsrep::provider::services&)
268269
{
269270
// The provider object is destroyed upon server state

0 commit comments

Comments
 (0)