26
25
#define DRIZZLED_REPLICATION_SERVICES_H
28
27
#include "drizzled/atomics.h"
29
#include "drizzled/plugin/replication.h"
35
#include "drizzled/visibility.h"
40
30
/* some forward declarations needed */
46
class TransactionReplicator;
47
class TransactionApplier;
38
class CommandReplicator;
55
48
* This is a class which manages transforming internal
56
49
* transactional events into GPB messages and sending those
57
50
* events out through registered replicators and appliers.
59
class DRIZZLED_API ReplicationServices
52
class ReplicationServices
55
static const size_t DEFAULT_RECORD_SIZE= 100;
62
56
typedef uint64_t GlobalTransactionId;
64
* Types of messages that can go in the transaction
65
* log file. Every time something is written into the
66
* transaction log, it is preceded by a header containing
67
* the type of message which follows.
71
TRANSACTION= 1, /* A GPB Transaction Message */
72
BLOB= 2 /* A BLOB value */
74
typedef std::pair<plugin::TransactionReplicator *, plugin::TransactionApplier *> ReplicationPair;
75
typedef std::vector<ReplicationPair> ReplicationStreams;
77
* Method which is called after plugins have been loaded but
78
* before the first client connects. It determines if the registration
79
* of applier and replicator plugins is proper and pairs
80
* the applier and requested replicator plugins into the replication
85
* This is only necessary because we don't yet have plugin dependency
88
bool evaluateRegisteredPlugins();
90
* Helper method which pushes a constructed message out to the registered
91
* replicator and applier plugins.
93
* @param Session descriptor
59
* Atomic boolean set to true if any *active* replicators
60
* or appliers are actually registered.
62
atomic<bool> is_active;
64
* The timestamp of the last time a Command message was successfully
65
* applied (sent to an Applier)
67
atomic<uint64_t> last_applied_timestamp;
68
/** Our collection of replicator plugins */
69
std::vector<drizzled::plugin::CommandReplicator *> replicators;
70
/** Our collection of applier plugins */
71
std::vector<drizzled::plugin::CommandApplier *> appliers;
73
* Helper method which is called after any change in the
74
* registered appliers or replicators to evaluate whether
75
* any remaining plugins are actually active.
77
* This method properly sets the is_active member variable.
79
void evaluateActivePlugins();
81
* Helper method which attaches a transaction context
82
* the supplied command based on the supplied Session's
83
* transaction information.
85
void setCommandTransactionContext(drizzled::message::Command &in_command, Session *in_session) const;
87
* Helper method which pushes a constructed message out
88
* to the registered replicator and applier plugins.
94
90
* @param Message to push out
96
plugin::ReplicationReturnCode pushTransactionMessage(Session &in_session,
97
message::Transaction &to_push);
92
void push(drizzled::message::Command &to_push);
116
112
* a replicator and an applier that are *active*?
118
114
bool isActive() const;
121
* Returns the list of replication streams
123
ReplicationStreams &getReplicationStreams();
126
116
* Attaches a replicator to our internal collection of
129
119
* @param Pointer to a replicator to attach/register
131
void attachReplicator(plugin::TransactionReplicator *in_replicator);
121
void attachReplicator(drizzled::plugin::CommandReplicator *in_replicator);
134
123
* Detaches/unregisters a replicator with our internal
135
124
* collection of replicators.
137
126
* @param Pointer to the replicator to detach
139
void detachReplicator(plugin::TransactionReplicator *in_replicator);
128
void detachReplicator(drizzled::plugin::CommandReplicator *in_replicator);
142
130
* Attaches a applier to our internal collection of
145
133
* @param Pointer to a applier to attach/register
146
* @param The name of the replicator to pair with
148
void attachApplier(plugin::TransactionApplier *in_applier, const std::string &requested_replicator);
135
void attachApplier(drizzled::plugin::CommandApplier *in_applier);
151
137
* Detaches/unregisters a applier with our internal
152
138
* collection of appliers.
154
140
* @param Pointer to the applier to detach
156
void detachApplier(plugin::TransactionApplier *in_applier);
159
* Returns the timestamp of the last Transaction which was sent to an
142
void detachApplier(drizzled::plugin::CommandApplier *in_applier);
144
* Creates a new StartTransaction GPB message and pushes
147
* @param Pointer to the Session starting the transaction
149
void startTransaction(Session *in_session);
151
* Creates a new CommitTransaction GPB message and pushes
154
* @param Pointer to the Session committing the transaction
156
void commitTransaction(Session *in_session);
158
* Creates a new RollbackTransaction GPB message and pushes
161
* @param Pointer to the Session committing the transaction
163
void rollbackTransaction(Session *in_session);
165
* Creates a new InsertRecord GPB message and pushes it to
168
* @param Pointer to the Session which has inserted a record
169
* @param Pointer to the Table containing insert information
171
void insertRecord(Session *in_session, Table *in_table);
173
* Creates a new UpdateRecord GPB message and pushes it to
176
* @param Pointer to the Session which has updated a record
177
* @param Pointer to the Table containing update information
178
* @param Pointer to the raw bytes representing the old record/row
179
* @param Pointer to the raw bytes representing the new record/row
181
void updateRecord(Session *in_session,
183
const unsigned char *old_record,
184
const unsigned char *new_record);
186
* Creates a new DeleteRecord GPB message and pushes it to
189
* @param Pointer to the Session which has deleted a record
190
* @param Pointer to the Table containing delete information
192
void deleteRecord(Session *in_session, Table *in_table);
194
* Creates a new RawSql GPB message and pushes it to
197
* @TODO With a real data dictionary, this really shouldn't
198
* be needed. CREATE TABLE would map to insertRecord call
199
* on the I_S, etc. Not sure what to do with administrative
200
* commands like CHECK TABLE, though..
202
* @param Pointer to the Session which issued the statement
203
* @param Query string
204
* @param Length of the query string
206
void rawStatement(Session *in_session, const char *in_query, size_t in_query_len);
208
* Returns the timestamp of the last Command which was sent to
162
211
uint64_t getLastAppliedTimestamp() const;
164
typedef std::vector<plugin::TransactionReplicator *> Replicators;
165
typedef std::vector<std::pair<std::string, plugin::TransactionApplier *> > Appliers;
167
* Atomic boolean set to true if any *active* replicators
168
* or appliers are actually registered.
172
* The timestamp of the last time a Transaction message was successfully
173
* applied (sent to an Applier)
175
atomic<uint64_t> last_applied_timestamp;
176
/** Our collection of registered replicator plugins */
177
Replicators replicators;
178
/** Our collection of registered applier plugins and their requested replicator plugin names */
180
/** Our replication streams */
181
ReplicationStreams replication_streams;
183
* Strips underscores and lowercases supplied replicator name
184
* or requested name, and appends the suffix "replicator" if missing...
186
void normalizeReplicatorName(std::string &name);
189
} /* namespace drizzled */
214
} /* end namespace drizzled */
191
216
#endif /* DRIZZLED_REPLICATION_SERVICES_H */