~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-02-28 14:09:50 UTC
  • mfrom: (2207 bootstrap)
  • mto: (2209.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2210.
  • Revision ID: olafvdspek@gmail.com-20110228140950-2nu0hyzhuww3wssx
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
 
 
66
  ifstream cf_stream(_config_file.c_str());
 
67
  po::store(drizzled::program_options::parse_config_file(cf_stream, slave_options), vm);
 
68
 
 
69
  po::notify(vm);
 
70
 
 
71
  if (vm.count("master-host"))
 
72
    _producer.setMasterHost(vm["master-host"].as<string>());
 
73
 
 
74
  if (vm.count("master-port"))
 
75
    _producer.setMasterPort(vm["master-port"].as<uint16_t>());
 
76
 
 
77
  if (vm.count("master-user"))
 
78
    _producer.setMasterUser(vm["master-user"].as<string>());
 
79
 
 
80
  if (vm.count("master-pass"))
 
81
    _producer.setMasterPassword(vm["master-pass"].as<string>());
 
82
 
 
83
  if (vm.count("max-reconnects"))
 
84
    _producer.setMaxReconnectAttempts(vm["max-reconnects"].as<uint32_t>());
 
85
 
 
86
  if (vm.count("seconds-between-reconnects"))
 
87
    _producer.setSecondsBetweenReconnects(vm["seconds-between-reconnects"].as<uint32_t>());
 
88
 
 
89
  /* setup schema and tables */
 
90
  ReplicationSchema rs;
 
91
  if (not rs.create())
 
92
  {
 
93
    _error= rs.getErrorMessage();
 
94
    return false;
 
95
  }
 
96
 
 
97
  return true;
 
98
}
 
99
 
 
100
} /* namespace slave */