Drizzled Public API Documentation

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