drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
replication_slave.h
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#pragma once
22
23#include <plugin/slave/queue_consumer.h>
24#include <plugin/slave/queue_producer.h>
25#include <plugin/slave/replication_schema.h>
26#include <drizzled/plugin/daemon.h>
27#include <boost/thread.hpp>
28#include <unordered_map>
29
30namespace drizzled
31{
32 class Session;
33}
34
35namespace slave
36{
37
38class ReplicationSlave : public drizzled::plugin::Daemon
39{
40public:
41
42 ReplicationSlave(const std::string &config)
43 : drizzled::plugin::Daemon("replication_slave"),
44 _config_file(config)
45 {}
46
47 ~ReplicationSlave()
48 {
49 _consumer_thread.interrupt();
50
51 std::unordered_map<uint32_t, Master *>::const_iterator it;
52
53 for (it= _masters.begin(); it != _masters.end(); ++it)
54 {
55 it->second->thread().interrupt();
56 }
57 }
58
60 void startup(drizzled::Session &session);
61
62private:
63
67 class Master
68 {
69 public:
70 Master(uint32_t id)
71 {
72 _producer.setMasterId(id);
73 }
74
75 QueueProducer &producer()
76 {
77 return _producer;
78 }
79
80 boost::thread &thread()
81 {
82 return _producer_thread;
83 }
84
85 void start()
86 {
87 _producer_thread= boost::thread(&QueueProducer::run, &_producer);
88 }
89
90 private:
93
95 boost::thread _producer_thread;
96 };
97
99 std::string _config_file;
100
101 std::string _error;
102
105
110 boost::thread _consumer_thread;
111
113 std::unordered_map<uint32_t, Master *> _masters;
114
116 Master &master(size_t index)
117 {
118 return *(_masters[index]);
119 }
120
130 bool initWithConfig();
131};
132
133} /* namespace slave */
134
std::unordered_map< uint32_t, Master * > _masters
Master & master(size_t index)
void startup(drizzled::Session &session)
TODO: Rename this file - func.h is stupid.