1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2011 David Shrewsbury
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include <plugin/slave/replication_slave.h>
23
#include <drizzled/program_options/config_file.h>
24
#include <drizzled/errmsg_print.h>
25
#include <boost/program_options.hpp>
29
using namespace drizzled;
31
namespace po= boost::program_options;
36
/* Gets called after all plugins are initialized. */
37
void ReplicationSlave::startup(Session &session)
40
if (not initWithConfig())
42
errmsg_printf(error::ERROR,
43
_("Could not start slave services: %s\n"),
48
_consumer_thread= boost::thread(&QueueConsumer::run, &_consumer);
49
_producer_thread= boost::thread(&QueueProducer::run, &_producer);
53
bool ReplicationSlave::initWithConfig()
56
po::options_description slave_options("Options for the slave plugin");
58
slave_options.add_options()
59
("master-host", po::value<string>()->default_value(""))
60
("master-port", po::value<uint16_t>()->default_value(3306))
61
("master-user", po::value<string>()->default_value(""))
62
("master-pass", po::value<string>()->default_value(""))
63
("max-reconnects", po::value<uint32_t>()->default_value(10))
64
("seconds-between-reconnects", po::value<uint32_t>()->default_value(30))
65
("io-thread-sleep", po::value<uint32_t>()->default_value(5))
66
("applier-thread-sleep", po::value<uint32_t>()->default_value(5));
68
ifstream cf_stream(_config_file.c_str());
69
po::store(drizzled::program_options::parse_config_file(cf_stream, slave_options), vm);
73
if (vm.count("master-host"))
74
_producer.setMasterHost(vm["master-host"].as<string>());
76
if (vm.count("master-port"))
77
_producer.setMasterPort(vm["master-port"].as<uint16_t>());
79
if (vm.count("master-user"))
80
_producer.setMasterUser(vm["master-user"].as<string>());
82
if (vm.count("master-pass"))
83
_producer.setMasterPassword(vm["master-pass"].as<string>());
85
if (vm.count("max-reconnects"))
86
_producer.setMaxReconnectAttempts(vm["max-reconnects"].as<uint32_t>());
88
if (vm.count("seconds-between-reconnects"))
89
_producer.setSecondsBetweenReconnects(vm["seconds-between-reconnects"].as<uint32_t>());
91
if (vm.count("io-thread-sleep"))
92
_producer.setSleepInterval(vm["io-thread-sleep"].as<uint32_t>());
94
if (vm.count("applier-thread-sleep"))
95
_consumer.setSleepInterval(vm["applier-thread-sleep"].as<uint32_t>());
97
/* setup schema and tables */
101
_error= rs.getErrorMessage();
108
} /* namespace slave */