drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
queue_producer.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 <client/rust_client.h>
24#include <drizzled/error_t.h>
25#include <plugin/slave/queue_thread.h>
26#include <plugin/slave/sql_executor.h>
27#include <string>
28#include <vector>
29
30namespace slave
31{
32
33class QueueProducer : public QueueThread, public SQLExecutor
34{
35public:
36 QueueProducer() :
37 SQLExecutor("slave", "replication"),
39 _master_port(3306),
40 _master_id(0),
41 _drizzle(nullptr, &drizzle_free),
42 _connection(nullptr),
43 _last_return(DRIZZLE_RETURN_OK),
44 _is_connected(false),
45 _saved_max_commit_id(0),
46 _max_reconnects(10),
47 _seconds_between_reconnects(30)
48 {}
49
50 virtual ~QueueProducer();
51
52 bool init();
53 bool process();
54 void shutdown();
55
56 void setSleepInterval(uint32_t seconds)
57 {
58 _check_interval= seconds;
59 }
60
61 uint32_t getSleepInterval()
62 {
63 return _check_interval;
64 }
65
66 void setMasterHost(const std::string &host)
67 {
68 _master_host= host;
69 }
70
71 void setMasterPort(uint16_t port)
72 {
73 _master_port= port;
74 }
75
76 void setMasterUser(const std::string &user)
77 {
78 _master_user= user;
79 }
80
81 void setMasterPassword(const std::string &password)
82 {
83 _master_pass= password;
84 }
85
86 void setMaxReconnectAttempts(uint32_t max)
87 {
88 _max_reconnects= max;
89 }
90
91 void setSecondsBetweenReconnects(uint32_t seconds)
92 {
93 _seconds_between_reconnects= seconds;
94 }
95
96 void setCachedMaxCommitId(uint64_t value)
97 {
98 _saved_max_commit_id= value;
99 }
100
101 uint64_t cachedMaxCommitId()
102 {
103 return _saved_max_commit_id;
104 }
105
106 void setMasterId(uint32_t value)
107 {
108 _master_id= value;
109 }
110
111 uint32_t masterId()
112 {
113 return _master_id;
114 }
115
116private:
119
120 /* Master server connection parameters */
121 std::string _master_host;
122 uint16_t _master_port;
123 std::string _master_user;
124 std::string _master_pass;
125
126 uint32_t _master_id;
127
128 std::unique_ptr<drizzle_st, decltype(&drizzle_free)> _drizzle;
129 drizzle_con_st *_connection;
130 drizzle_return_t _last_return;
131
132 bool _is_connected;
133 uint64_t _saved_max_commit_id;
134 uint32_t _max_reconnects;
135 uint32_t _seconds_between_reconnects;
136
137 std::string _last_error_message;
138
142 bool openConnection();
143
147 bool closeConnection();
148
158 bool reconnect(bool initial_connection);
159
168 bool queryForMaxCommitId(uint64_t *max_commit_id);
169
183 enum drizzled::error_t queryForReplicationEvents(uint64_t max_commit_id);
184
185 bool queryForTrxIdList(uint64_t max_commit_id, std::vector<uint64_t> &list);
186 bool queueInsert(const char *trx_id,
187 const char *seg_id,
188 const char *commit_id,
189 const char *originating_server_uuid,
190 const char *originating_commit_id,
191 const char *msg,
192 size_t msg_size);
193
200 void setIOState(const std::string &err_msg, bool status);
201
202};
203
204} /* namespace slave */
205
bool reconnect(bool initial_connection)
bool queryForMaxCommitId(uint64_t *max_commit_id)
enum drizzled::error_t queryForReplicationEvents(uint64_t max_commit_id)
void setIOState(const std::string &err_msg, bool status)