32 const boost::property_tree::ptree &cfg,
44 auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(
58 delay_ =
config_.get_child(
"module_config").get<
int>(
"delay", 120);
60 pubkey_ =
config_.get_child(
"module_config").get<std::string>(
"pubkey");
73 INFO(
"Current cfg version = " << local <<
". Remote = " << remote);
76 ERROR(
"Failed to retrieve config version");
86 INFO(
"Local configuration version is either equal or greated than the " 88 <<
" Doing nothing.");
94 auto task = std::make_shared<Tasks::GetLocalConfigVersion>(
utils_->kernel());
97 assert(task->succeed());
99 local = task->config_version_;
105 auto task = std::make_shared<Tasks::GetRemoteConfigVersion>(
endpoint_,
pubkey_);
109 if (!task->succeed())
111 if (task->get_exception())
115 std::rethrow_exception(task->get_exception());
117 catch (
const std::exception &e)
119 ERROR(
"Fetching remote version failed: " << e.what());
125 remote = task->config_version_;
131 INFO(
"Starting the synchronization process...");
134 auto fetch_task = std::make_shared<Tasks::FetchRemoteConfig>(
endpoint_,
pubkey_);
136 auto sync_task = std::make_shared<Tasks::SyncConfig>(
utils_->kernel(),
137 fetch_task,
true,
true);
138 sync_task->set_on_success([]() {
INFO(
"Synchronization complete."); });
140 auto *sched = &
utils_->scheduler();
141 fetch_task->set_on_success(
bool fetch_local_version(uint64_t &local)
Fetch the local configuration version by running a task in the main thread.
int delay_
Delay between 2 replications attempt.
std::chrono::system_clock::time_point TimePoint
std::string endpoint_
Target master server.
This module handles the master/slave replication process, from the slave point of view...
CoreUtilsPtr utils_
Pointer to the core utils, which gives access to scheduler and others.
virtual void run() override
This is the main loop of the module.
bool fetch_remote_version(uint64_t &remote)
Fetch the remote configuration version by running a task in a pool, and sending the CONFIG_VERSION me...
bool is_running_
Boolean indicating whether the main loop should run or not.
std::string pubkey_
Master server's public key.
void start_sync()
Launch the tasks so that the synchronisation may take place.
Base class for module implementation.
void replicate()
Start the replication process.
zmqpp::reactor reactor_
The reactor object we poll() on in the main loop.
std::shared_ptr< CoreUtils > CoreUtilsPtr
ReplicationModule(zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
boost::property_tree::ptree config_
The configuration tree passed to the start_module function.