~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/slave/replication_slave.cc

  • Committer: Olaf van der Spek
  • Date: 2011-03-01 11:40:52 UTC
  • mfrom: (2210 staging)
  • mto: (2212.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2213.
  • Revision ID: olafvdspek@gmail.com-20110301114052-1sqxpkhrnq5o49ns
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2011 David Shrewsbury
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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
 
19
 */
 
20
 
 
21
#include <config.h>
 
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>
 
26
#include <fstream>
 
27
 
 
28
using namespace std;
 
29
using namespace drizzled;
 
30
 
 
31
namespace po= boost::program_options;
 
32
 
 
33
namespace slave
 
34
{
 
35
 
 
36
/* Gets called after all plugins are initialized. */
 
37
void ReplicationSlave::startup(Session &session)
 
38
{
 
39
  (void)session;
 
40
  if (not initWithConfig())
 
41
  {
 
42
    errmsg_printf(error::ERROR,
 
43
                  _("Could not start slave services: %s\n"),
 
44
                  getError().c_str());
 
45
  }
 
46
  else
 
47
  {
 
48
    _consumer_thread= boost::thread(&QueueConsumer::run, &_consumer);
 
49
    _producer_thread= boost::thread(&QueueProducer::run, &_producer);
 
50
  }
 
51
}
 
52
 
 
53
bool ReplicationSlave::initWithConfig()
 
54
{
 
55
  po::variables_map vm;
 
56
  po::options_description slave_options("Options for the slave plugin");
 
57
 
 
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));
 
67
 
 
68
  ifstream cf_stream(_config_file.c_str());
 
69
  po::store(drizzled::program_options::parse_config_file(cf_stream, slave_options), vm);
 
70
 
 
71
  po::notify(vm);
 
72
 
 
73
  if (vm.count("master-host"))
 
74
    _producer.setMasterHost(vm["master-host"].as<string>());
 
75
 
 
76
  if (vm.count("master-port"))
 
77
    _producer.setMasterPort(vm["master-port"].as<uint16_t>());
 
78
 
 
79
  if (vm.count("master-user"))
 
80
    _producer.setMasterUser(vm["master-user"].as<string>());
 
81
 
 
82
  if (vm.count("master-pass"))
 
83
    _producer.setMasterPassword(vm["master-pass"].as<string>());
 
84
 
 
85
  if (vm.count("max-reconnects"))
 
86
    _producer.setMaxReconnectAttempts(vm["max-reconnects"].as<uint32_t>());
 
87
 
 
88
  if (vm.count("seconds-between-reconnects"))
 
89
    _producer.setSecondsBetweenReconnects(vm["seconds-between-reconnects"].as<uint32_t>());
 
90
 
 
91
  if (vm.count("io-thread-sleep"))
 
92
    _producer.setSleepInterval(vm["io-thread-sleep"].as<uint32_t>());
 
93
 
 
94
  if (vm.count("applier-thread-sleep"))
 
95
    _consumer.setSleepInterval(vm["applier-thread-sleep"].as<uint32_t>());
 
96
 
 
97
  /* setup schema and tables */
 
98
  ReplicationSchema rs;
 
99
  if (not rs.create())
 
100
  {
 
101
    _error= rs.getErrorMessage();
 
102
    return false;
 
103
  }
 
104
 
 
105
  return true;
 
106
}
 
107
 
 
108
} /* namespace slave */