2116.1.23
by David Shrewsbury
Added empty version of producer thread |
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 |
||
2234
by Brian Aker
Mass removal of ifdef/endif in favor of pragma once. |
21 |
#pragma once
|
2116.1.23
by David Shrewsbury
Added empty version of producer thread |
22 |
|
2221.4.1
by David Shrewsbury
Change producer thread to continously poll the master for replication events until no more are available, then sleep. |
23 |
#include <client/client_priv.h> |
24 |
#include <drizzled/error_t.h> |
|
2116.1.38
by David Shrewsbury
Change include style |
25 |
#include <plugin/slave/queue_thread.h> |
26 |
#include <plugin/slave/sql_executor.h> |
|
2116.1.23
by David Shrewsbury
Added empty version of producer thread |
27 |
#include <string> |
2116.1.31
by David Shrewsbury
Major refactor of common functionality into new classes. |
28 |
#include <vector> |
2116.1.23
by David Shrewsbury
Added empty version of producer thread |
29 |
|
30 |
namespace slave |
|
31 |
{
|
|
32 |
||
2116.1.31
by David Shrewsbury
Major refactor of common functionality into new classes. |
33 |
class QueueProducer : public QueueThread, public SQLExecutor |
2116.1.23
by David Shrewsbury
Added empty version of producer thread |
34 |
{
|
35 |
public: |
|
36 |
QueueProducer() : |
|
2116.1.31
by David Shrewsbury
Major refactor of common functionality into new classes. |
37 |
SQLExecutor("slave", "replication"), |
2116.1.23
by David Shrewsbury
Added empty version of producer thread |
38 |
_check_interval(5), |
2116.1.30
by David Shrewsbury
incremental |
39 |
_master_port(3306), |
2360.1.1
by Mark Atwood
restore multi master replication |
40 |
_master_id(0), |
2116.1.32
by David Shrewsbury
incremental |
41 |
_last_return(DRIZZLE_RETURN_OK), |
2116.1.31
by David Shrewsbury
Major refactor of common functionality into new classes. |
42 |
_is_connected(false), |
2116.1.32
by David Shrewsbury
incremental |
43 |
_saved_max_commit_id(0), |
44 |
_max_reconnects(10), |
|
45 |
_seconds_between_reconnects(30) |
|
2116.1.23
by David Shrewsbury
Added empty version of producer thread |
46 |
{}
|
47 |
||
2116.1.29
by David Shrewsbury
Initial stages of master connection |
48 |
virtual ~QueueProducer(); |
2116.1.23
by David Shrewsbury
Added empty version of producer thread |
49 |
|
50 |
bool init(); |
|
51 |
bool process(); |
|
52 |
void shutdown(); |
|
53 |
||
54 |
void setSleepInterval(uint32_t seconds) |
|
55 |
{
|
|
56 |
_check_interval= seconds; |
|
57 |
}
|
|
58 |
||
59 |
uint32_t getSleepInterval() |
|
60 |
{
|
|
61 |
return _check_interval; |
|
62 |
}
|
|
63 |
||
64 |
void setMasterHost(const std::string &host) |
|
65 |
{
|
|
66 |
_master_host= host; |
|
67 |
}
|
|
68 |
||
69 |
void setMasterPort(uint16_t port) |
|
70 |
{
|
|
71 |
_master_port= port; |
|
72 |
}
|
|
73 |
||
74 |
void setMasterUser(const std::string &user) |
|
75 |
{
|
|
76 |
_master_user= user; |
|
77 |
}
|
|
78 |
||
79 |
void setMasterPassword(const std::string &password) |
|
80 |
{
|
|
81 |
_master_pass= password; |
|
82 |
}
|
|
83 |
||
2116.1.33
by David Shrewsbury
incremental |
84 |
void setMaxReconnectAttempts(uint32_t max) |
85 |
{
|
|
86 |
_max_reconnects= max; |
|
87 |
}
|
|
88 |
||
89 |
void setSecondsBetweenReconnects(uint32_t seconds) |
|
90 |
{
|
|
91 |
_seconds_between_reconnects= seconds; |
|
92 |
}
|
|
93 |
||
2225.3.1
by David Shrewsbury
Persist --slave.max-commit-id value to applier_state table. |
94 |
void setCachedMaxCommitId(uint64_t value) |
2221.8.1
by David Shrewsbury
Add new --slave.max-commit-id option to control where we begin reading the master transaction log. |
95 |
{
|
96 |
_saved_max_commit_id= value; |
|
97 |
}
|
|
98 |
||
2360.1.1
by Mark Atwood
restore multi master replication |
99 |
uint64_t cachedMaxCommitId() |
100 |
{
|
|
101 |
return _saved_max_commit_id; |
|
102 |
}
|
|
103 |
||
104 |
void setMasterId(uint32_t value) |
|
105 |
{
|
|
106 |
_master_id= value; |
|
107 |
}
|
|
108 |
||
109 |
uint32_t masterId() |
|
110 |
{
|
|
111 |
return _master_id; |
|
112 |
}
|
|
113 |
||
2116.1.23
by David Shrewsbury
Added empty version of producer thread |
114 |
private: |
115 |
/** Number of seconds to sleep between checking queue for messages */
|
|
116 |
uint32_t _check_interval; |
|
117 |
||
118 |
/* Master server connection parameters */
|
|
119 |
std::string _master_host; |
|
120 |
uint16_t _master_port; |
|
121 |
std::string _master_user; |
|
122 |
std::string _master_pass; |
|
2116.1.29
by David Shrewsbury
Initial stages of master connection |
123 |
|
2360.1.1
by Mark Atwood
restore multi master replication |
124 |
uint32_t _master_id; |
125 |
||
2116.1.31
by David Shrewsbury
Major refactor of common functionality into new classes. |
126 |
drizzle_st _drizzle; |
127 |
drizzle_con_st _connection; |
|
2116.1.32
by David Shrewsbury
incremental |
128 |
drizzle_return_t _last_return; |
2116.1.29
by David Shrewsbury
Initial stages of master connection |
129 |
|
2116.1.30
by David Shrewsbury
incremental |
130 |
bool _is_connected; |
2116.1.50
by David Shrewsbury
Fix commit_id to correct uint64_t type |
131 |
uint64_t _saved_max_commit_id; |
2116.1.32
by David Shrewsbury
incremental |
132 |
uint32_t _max_reconnects; |
133 |
uint32_t _seconds_between_reconnects; |
|
2116.1.30
by David Shrewsbury
incremental |
134 |
|
2116.1.33
by David Shrewsbury
incremental |
135 |
std::string _last_error_message; |
136 |
||
137 |
/**
|
|
138 |
* Open connection to the master server.
|
|
139 |
*/
|
|
2116.1.29
by David Shrewsbury
Initial stages of master connection |
140 |
bool openConnection(); |
2116.1.33
by David Shrewsbury
incremental |
141 |
|
142 |
/**
|
|
143 |
* Close connection to the master server.
|
|
144 |
*/
|
|
2116.1.29
by David Shrewsbury
Initial stages of master connection |
145 |
bool closeConnection(); |
2116.1.33
by David Shrewsbury
incremental |
146 |
|
147 |
/**
|
|
148 |
* Attempt to reconnect to the master server.
|
|
149 |
*
|
|
150 |
* This method does not return until reconnect succeeds, or we exceed our
|
|
151 |
* maximum number of retries defined by _max_reconnects.
|
|
152 |
*
|
|
153 |
* @retval true Reconnect succeeded
|
|
154 |
* @retval false Reconnect failed
|
|
155 |
*/
|
|
2116.2.2
by Joseph Daly
fix bad variable names |
156 |
bool reconnect(bool initial_connection); |
2116.1.33
by David Shrewsbury
incremental |
157 |
|
2221.4.1
by David Shrewsbury
Change producer thread to continously poll the master for replication events until no more are available, then sleep. |
158 |
/**
|
159 |
* Get maximum commit ID that we have stored locally on the slave.
|
|
160 |
*
|
|
161 |
* This method determines where this slave is in relation to the master,
|
|
162 |
* or, in other words, how "caught up" we are.
|
|
163 |
*
|
|
164 |
* @param[out] max_commit_id Maximum commit ID we have on this slave.
|
|
165 |
*/
|
|
2116.1.50
by David Shrewsbury
Fix commit_id to correct uint64_t type |
166 |
bool queryForMaxCommitId(uint64_t *max_commit_id); |
2221.4.1
by David Shrewsbury
Change producer thread to continously poll the master for replication events until no more are available, then sleep. |
167 |
|
168 |
/**
|
|
169 |
* Get replication events/messages from the master.
|
|
170 |
*
|
|
171 |
* Calling this method will a limited number of events from the master.
|
|
172 |
* It should be repeatedly called until it returns -1, which means there
|
|
173 |
* were no more events to retrieve.
|
|
174 |
*
|
|
175 |
* @param[in] max_commit_id Largest commit ID we have stored locally.
|
|
176 |
*
|
|
177 |
* @retval EE_OK Successfully retrieved events
|
|
178 |
* @retval ER_NO No errors, but no more events to retrieve
|
|
179 |
* @retval ER_YES Error
|
|
180 |
*/
|
|
181 |
enum drizzled::error_t queryForReplicationEvents(uint64_t max_commit_id); |
|
182 |
||
2116.1.50
by David Shrewsbury
Fix commit_id to correct uint64_t type |
183 |
bool queryForTrxIdList(uint64_t max_commit_id, std::vector<uint64_t> &list); |
2116.1.32
by David Shrewsbury
incremental |
184 |
bool queueInsert(const char *trx_id, |
185 |
const char *seg_id, |
|
186 |
const char *commit_id, |
|
2290.1.3
by Joseph Daly
slave plugin work |
187 |
const char *originating_server_uuid, |
188 |
const char *originating_commit_id, |
|
2116.1.32
by David Shrewsbury
incremental |
189 |
const char *msg, |
190 |
const char *msg_length); |
|
191 |
||
2116.1.33
by David Shrewsbury
incremental |
192 |
/**
|
193 |
* Update IO thread status in state table.
|
|
194 |
*
|
|
195 |
* @param err_msg Error message string
|
|
196 |
* @param status false = STOPPED, true = RUNNING
|
|
197 |
*/
|
|
198 |
void setIOState(const std::string &err_msg, bool status); |
|
199 |
||
2116.1.23
by David Shrewsbury
Added empty version of producer thread |
200 |
};
|
201 |
||
202 |
} /* namespace slave */ |
|
203 |