~drizzle-trunk/drizzle/development

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