2116.1.20
by David Shrewsbury
Refactor design pattern |
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.20
by David Shrewsbury
Refactor design pattern |
22 |
|
2116.1.38
by David Shrewsbury
Change include style |
23 |
#include <plugin/slave/queue_thread.h> |
24 |
#include <plugin/slave/sql_executor.h> |
|
2116.1.31
by David Shrewsbury
Major refactor of common functionality into new classes. |
25 |
#include <drizzled/session.h> |
2116.1.20
by David Shrewsbury
Refactor design pattern |
26 |
|
27 |
namespace drizzled |
|
28 |
{
|
|
29 |
namespace message |
|
30 |
{
|
|
31 |
class Transaction; |
|
32 |
}
|
|
33 |
}
|
|
34 |
||
35 |
namespace slave |
|
36 |
{
|
|
37 |
||
2116.1.31
by David Shrewsbury
Major refactor of common functionality into new classes. |
38 |
class QueueConsumer : public QueueThread, public SQLExecutor |
2116.1.20
by David Shrewsbury
Refactor design pattern |
39 |
{
|
40 |
public: |
|
41 |
QueueConsumer() : |
|
2116.1.31
by David Shrewsbury
Major refactor of common functionality into new classes. |
42 |
QueueThread(), |
43 |
SQLExecutor("slave", "replication"), |
|
2260.1.1
by David Shrewsbury
Revert multi-master code |
44 |
_check_interval(5) |
2116.1.20
by David Shrewsbury
Refactor design pattern |
45 |
{ } |
46 |
||
2116.1.23
by David Shrewsbury
Added empty version of producer thread |
47 |
bool init(); |
48 |
bool process(); |
|
49 |
void shutdown(); |
|
2116.1.20
by David Shrewsbury
Refactor design pattern |
50 |
|
51 |
void setSleepInterval(uint32_t seconds) |
|
52 |
{
|
|
53 |
_check_interval= seconds; |
|
54 |
}
|
|
55 |
||
56 |
uint32_t getSleepInterval() |
|
57 |
{
|
|
58 |
return _check_interval; |
|
59 |
}
|
|
60 |
||
2116.1.28
by David Shrewsbury
More config file work |
61 |
/**
|
62 |
* Update applier status in state table.
|
|
63 |
*
|
|
64 |
* @param err_msg Error message string
|
|
65 |
* @param status false = STOPPED, true = RUNNING
|
|
66 |
*/
|
|
67 |
void setApplierState(const std::string &err_msg, bool status); |
|
68 |
||
2116.1.20
by David Shrewsbury
Refactor design pattern |
69 |
private: |
70 |
typedef std::vector<uint64_t> TrxIdList; |
|
71 |
||
72 |
/** Number of seconds to sleep between checking queue for messages */
|
|
73 |
uint32_t _check_interval; |
|
74 |
||
2260.1.1
by David Shrewsbury
Revert multi-master code |
75 |
bool getListOfCompletedTransactions(TrxIdList &list); |
2116.1.20
by David Shrewsbury
Refactor design pattern |
76 |
|
77 |
bool getMessage(drizzled::message::Transaction &transaction, |
|
78 |
std::string &commit_id, |
|
79 |
uint64_t trx_id, |
|
2290.1.3
by Joseph Daly
slave plugin work |
80 |
std::string &originating_server_uuid, |
81 |
uint64_t &originating_commit_id, |
|
2116.1.20
by David Shrewsbury
Refactor design pattern |
82 |
uint32_t segment_id); |
83 |
||
84 |
/**
|
|
85 |
* Convert the given Transaction message into equivalent SQL.
|
|
86 |
*
|
|
87 |
* @param[in] transaction Transaction protobuf message to convert.
|
|
88 |
* @param[in,out] aggregate_sql Buffer for total SQL for this transaction.
|
|
89 |
* @param[in,out] segmented_sql Buffer for carried over segmented statements.
|
|
90 |
*
|
|
91 |
* @retval true Success
|
|
92 |
* @retval false Failure
|
|
93 |
*/
|
|
94 |
bool convertToSQL(const drizzled::message::Transaction &transaction, |
|
95 |
std::vector<std::string> &aggregate_sql, |
|
96 |
std::vector<std::string> &segmented_sql); |
|
97 |
||
98 |
/**
|
|
99 |
* Execute a batch of SQL statements.
|
|
100 |
*
|
|
101 |
* @param sql Batch of SQL statements to execute.
|
|
102 |
* @param commit_id Commit ID value to store in state table.
|
|
2290.1.3
by Joseph Daly
slave plugin work |
103 |
* @param originating_server_uuid Server ID of the master where
|
104 |
* this SQL was originally applied.
|
|
105 |
* @param originating_commit_id Commit ID of the master where
|
|
106 |
* this SQL was originally applied.
|
|
2116.1.20
by David Shrewsbury
Refactor design pattern |
107 |
*
|
108 |
* @retval true Success
|
|
109 |
* @retval false Failure
|
|
110 |
*/
|
|
2116.1.31
by David Shrewsbury
Major refactor of common functionality into new classes. |
111 |
bool executeSQLWithCommitId(std::vector<std::string> &sql, |
2290.1.3
by Joseph Daly
slave plugin work |
112 |
const std::string &commit_id, |
2290.1.5
by Joseph Daly
slave fixes |
113 |
const std::string &originating_server_uuid, |
2290.1.3
by Joseph Daly
slave plugin work |
114 |
uint64_t originating_commit_id); |
2116.1.20
by David Shrewsbury
Refactor design pattern |
115 |
|
116 |
/**
|
|
117 |
* Remove messages for a given transaction from the queue.
|
|
118 |
*
|
|
2260.1.1
by David Shrewsbury
Revert multi-master code |
119 |
* @param trx_id Transaction ID for the messages to remove.
|
2116.1.20
by David Shrewsbury
Refactor design pattern |
120 |
*
|
121 |
* @retval true Success
|
|
122 |
* @retval false Failure
|
|
123 |
*/
|
|
2260.1.1
by David Shrewsbury
Revert multi-master code |
124 |
bool deleteFromQueue(uint64_t trx_id); |
2116.1.20
by David Shrewsbury
Refactor design pattern |
125 |
|
126 |
/**
|
|
127 |
* Determine if a Statement message is an end message.
|
|
128 |
*
|
|
129 |
* @retval true Is an end Statement message
|
|
130 |
* @retval false Is NOT an end Statement message
|
|
131 |
*/
|
|
132 |
bool isEndStatement(const drizzled::message::Statement &statement); |
|
133 |
};
|
|
134 |
||
135 |
} /* namespace slave */ |
|
136 |