Skip to content

Commit 6bce0dc

Browse files
committed
Change signature provider options callback
Change provider options callback to take an instance provider_options. Restore method provider_options::intial_options().
1 parent 0b79850 commit 6bce0dc

11 files changed

+55
-40
lines changed

include/wsrep/provider.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,7 @@ namespace wsrep
521521
static std::unique_ptr<provider> make_provider(
522522
wsrep::server_state&,
523523
const std::string& provider_spec,
524-
const std::function<std::string()>& provider_options_cb,
525-
provider_options& options,
524+
const std::function<std::string(provider_options&)>& provider_options_cb,
526525
const wsrep::provider::services& services
527526
= wsrep::provider::services());
528527
protected:

include/wsrep/provider_options.hpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,8 @@ namespace wsrep
224224
* Individual options should be accessed through set()/get().
225225
*
226226
* @return Provider status code.
227-
* @deprecated Provider options are now loaded in provider ctor
228227
*/
229-
enum wsrep::provider::status initial_options();
228+
enum wsrep::provider::status initial_options(wsrep::provider& provider);
230229

231230
/**
232231
* Get the option with the given name
@@ -243,8 +242,8 @@ namespace wsrep
243242
* not be allocated for the new value.
244243
*/
245244
enum wsrep::provider::status set(wsrep::provider& provider,
246-
const std::string& name,
247-
std::unique_ptr<option_value> value);
245+
const std::string& name,
246+
std::unique_ptr<option_value> value);
248247

249248
/**
250249
* Create a new option with default value.

include/wsrep/server_state.hpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,15 @@ namespace wsrep
297297
* @return Zero on success, non-zero on error.
298298
*/
299299
int load_provider(const std::string& provider,
300-
const std::function<std::string()>& provider_options_cb,
300+
const std::function<std::string(provider_options&)>&,
301301
const wsrep::provider::services& services
302302
= wsrep::provider::services());
303303

304-
305304
/**
306305
* Load WSRep provider.
307306
*
308307
* @param provider WSRep provider library to be loaded.
309-
* @param provider_options Provider specific options string
308+
* @param options Provider specific options string
310309
* to be passed for provider during initialization.
311310
* @param services Application defined services passed to
312311
* the provider.
@@ -316,13 +315,13 @@ namespace wsrep
316315
* @note Provided for backward compatibility.
317316
*/
318317
int load_provider(const std::string& provider,
319-
const std::string& provider_options,
318+
const std::string& options,
320319
const wsrep::provider::services& services
321320
= wsrep::provider::services())
322321
{
323-
return load_provider(provider,
324-
[provider_options]() { return provider_options; },
325-
services);
322+
return load_provider(
323+
provider, [options](provider_options&) { return options; },
324+
services);
326325
}
327326

328327
using provider_factory_func =
@@ -357,7 +356,7 @@ namespace wsrep
357356
return *provider_;
358357
}
359358

360-
wsrep::provider_options* provider_options()
359+
wsrep::provider_options* get_provider_options()
361360
{
362361
return &provider_options_;
363362
}

src/config_service_v1.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,10 @@ int wsrep::config_service_v1_fetch(struct wsrep_st* wsrep,
179179

180180
return 0;
181181
}
182+
183+
int wsrep::config_service_v1_fetch(wsrep::provider& provider,
184+
wsrep::provider_options* options)
185+
{
186+
struct wsrep_st* wsrep = (struct wsrep_st*)provider.native();
187+
return config_service_v1_fetch(wsrep, options);
188+
}

src/config_service_v1.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace wsrep
2626
{
2727
class provider;
2828
class provider_options;
29+
int config_service_v1_fetch(provider& provider, provider_options* opts);
2930
int config_service_v1_fetch(struct wsrep_st* wsrep, provider_options* opts);
3031
} // namespace wsrep
3132

src/provider.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "wsrep/provider.hpp"
2121
#include "wsrep/logger.hpp"
22+
#include "wsrep/provider_options.hpp"
2223

2324
#include "wsrep_provider_v26.hpp"
2425

@@ -29,29 +30,30 @@
2930
std::unique_ptr<wsrep::provider> wsrep::provider::make_provider(
3031
wsrep::server_state& server_state,
3132
const std::string& provider_spec,
32-
const std::function<std::string()>& provider_options_cb,
33-
provider_options& provider_options,
33+
const std::function<std::string(provider_options&)>& provider_options_cb,
3434
const wsrep::provider::services& services)
3535
{
3636
try
3737
{
3838
return std::unique_ptr<wsrep::provider>(new wsrep::wsrep_provider_v26(
39-
server_state, provider_spec, provider_options_cb, provider_options,
39+
server_state, provider_spec, provider_options_cb,
4040
services));
4141
}
4242
catch (const wsrep::runtime_error& e)
4343
{
44+
provider_options opts;
4445
wsrep::log_error() << "Failed to create a new provider '"
4546
<< provider_spec << "'"
46-
<< " with options '" << provider_options_cb()
47+
<< " with options '" << provider_options_cb(opts)
4748
<< "': " << e.what();
4849
}
4950
catch (...)
5051
{
52+
provider_options opts;
5153
wsrep::log_error() << "Caught unknown exception when trying to "
5254
<< "create a new provider '"
5355
<< provider_spec << "'"
54-
<< " with options '" << provider_options_cb();
56+
<< " with options '" << provider_options_cb(opts);
5557
}
5658
return 0;
5759
}

src/provider_options.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include "wsrep/provider_options.hpp"
21+
#include "wsrep/provider.hpp"
2122
#include "config_service_v1.hpp"
2223
#include "wsrep/logger.hpp"
2324

@@ -97,9 +98,18 @@ wsrep::provider_options::provider_options()
9798
{
9899
}
99100

100-
enum wsrep::provider::status wsrep::provider_options::initial_options()
101+
enum wsrep::provider::status
102+
wsrep::provider_options::initial_options(wsrep::provider& provider)
101103
{
102-
return wsrep::provider::error_not_implemented;
104+
options_.clear();
105+
if (config_service_v1_fetch(provider, this))
106+
{
107+
return wsrep::provider::error_not_implemented;
108+
}
109+
else
110+
{
111+
return wsrep::provider::success;
112+
}
103113
}
104114

105115
const wsrep::provider_options::option*

src/server_state.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,13 @@ 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()>& provider_options_cb,
503+
const std::function<std::string(provider_options&)>& provider_options_cb,
504504
const wsrep::provider::services& services)
505505
{
506506
wsrep::log_info() << "Loading provider " << provider_spec
507507
<< " initial position: " << initial_position_;
508508
provider_ = provider_factory_(*this, provider_spec, provider_options_cb,
509-
provider_options_, services);
509+
services);
510510
return (provider_ ? 0 : 1);
511511
}
512512

src/wsrep_provider_v26.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,7 @@ void wsrep::wsrep_provider_v26::deinit_services()
773773
wsrep::wsrep_provider_v26::wsrep_provider_v26(
774774
wsrep::server_state& server_state,
775775
const std::string& provider_spec,
776-
const std::function<std::string()>& provider_options_cb,
777-
provider_options& options,
776+
const std::function<std::string(provider_options&)>& provider_options_cb,
778777
const wsrep::provider::services& services)
779778
: provider(server_state)
780779
, wsrep_()
@@ -794,7 +793,8 @@ wsrep::wsrep_provider_v26::wsrep_provider_v26(
794793
}
795794

796795
init_services(services);
797-
config_service_v1_fetch(wsrep_, &options);
796+
provider_options options;
797+
config_service_v1_fetch(wsrep_, &options); // TODO check failure
798798

799799
struct wsrep_init_args init_args;
800800
memset(&init_args, 0, sizeof(init_args));
@@ -803,7 +803,7 @@ wsrep::wsrep_provider_v26::wsrep_provider_v26(
803803
init_args.node_address = server_state_.address().c_str();
804804
init_args.node_incoming = server_state_.incoming_address().c_str();
805805
init_args.data_dir = server_state_.working_dir().c_str();
806-
const auto& provider_options = provider_options_cb();
806+
const auto& provider_options = provider_options_cb(options);
807807
init_args.options = provider_options.c_str();
808808
init_args.proto_ver = server_state.max_protocol_version();
809809
init_args.state_id = &state_id;

src/wsrep_provider_v26.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ namespace wsrep
3434
void init_services(const wsrep::provider::services& services);
3535
void deinit_services();
3636
wsrep_provider_v26(wsrep::server_state&, const std::string&,
37-
const std::function<std::string()>&,
38-
provider_options& provider_options,
37+
const std::function<std::string(provider_options&)>&,
3938
const wsrep::provider::services& services);
4039
~wsrep_provider_v26() WSREP_OVERRIDE;
4140
enum wsrep::provider::status

test/mock_server_state.hpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,16 @@ namespace wsrep
261261
, cond_()
262262
, provider_()
263263
{
264-
set_provider_factory([&](wsrep::server_state&,
265-
const std::string&,
266-
const std::function<std::string()>&,
267-
wsrep::provider_options&,
268-
const wsrep::provider::services&)
269-
{
270-
// The provider object is destroyed upon server state
271-
// destruction, so using a raw pointer is safe.
272-
provider_ = new wsrep::mock_provider(*this);
273-
return std::unique_ptr<wsrep::provider>(provider_);
274-
});
264+
set_provider_factory(
265+
[&](wsrep::server_state&, const std::string&,
266+
const std::function<std::string(wsrep::provider_options&)>&,
267+
const wsrep::provider::services&)
268+
{
269+
// The provider object is destroyed upon server state
270+
// destruction, so using a raw pointer is safe.
271+
provider_ = new wsrep::mock_provider(*this);
272+
return std::unique_ptr<wsrep::provider>(provider_);
273+
});
275274

276275
const int ret WSREP_UNUSED = load_provider("mock", "");
277276
assert(ret == 0);

0 commit comments

Comments
 (0)