26
25
#define DRIZZLED_REPLICATION_SERVICES_H
28
27
#include "drizzled/atomics.h"
35
30
/* some forward declarations needed */
41
class TransactionReplicator;
42
class TransactionApplier;
47
void add_replicator(drizzled::plugin::Replicator *replicator);
48
void remove_replicator(drizzled::plugin::Replicator *replicator);
50
void add_applier(drizzled::plugin::Applier *applier);
51
void remove_applier(drizzled::plugin::Applier *applier);
50
54
* This is a class which manages transforming internal
51
55
* transactional events into GPB messages and sending those
52
56
* events out through registered replicators and appliers.
54
60
class ReplicationServices
57
typedef uint64_t GlobalTransactionId;
59
* Types of messages that can go in the transaction
60
* log file. Every time something is written into the
61
* transaction log, it is preceded by a header containing
62
* the type of message which follows.
66
TRANSACTION= 1, /* A GPB Transaction Message */
67
BLOB= 2 /* A BLOB value */
69
typedef std::vector<plugin::TransactionReplicator *> Replicators;
70
typedef std::vector<plugin::TransactionApplier *> Appliers;
63
static const size_t DEFAULT_RECORD_SIZE= 100;
73
66
* Atomic boolean set to true if any *active* replicators
76
69
atomic<bool> is_active;
78
* The timestamp of the last time a Transaction message was successfully
71
* The timestamp of the last time a Command message was successfully
79
72
* applied (sent to an Applier)
81
74
atomic<uint64_t> last_applied_timestamp;
82
75
/** Our collection of replicator plugins */
83
Replicators replicators;
76
std::vector<drizzled::plugin::Replicator *> replicators;
84
77
/** Our collection of applier plugins */
78
std::vector<drizzled::plugin::Applier *> appliers;
87
80
* Helper method which is called after any change in the
88
81
* registered appliers or replicators to evaluate whether
91
84
* This method properly sets the is_active member variable.
93
86
void evaluateActivePlugins();
96
* Helper method which pushes a constructed message out to the registered
97
* replicator and applier plugins.
88
* Helper method which attaches a transaction context
89
* the supplied command based on the supplied Session's
90
* transaction information.
92
void setCommandTransactionContext(drizzled::message::Command *in_command, Session *in_session) const;
94
* Helper method which pushes a constructed message out
95
* to the registered replicator and applier plugins.
99
97
* @param Message to push out
101
void pushTransactionMessage(message::Transaction &to_push);
99
void push(drizzled::message::Command *to_push);
105
104
ReplicationServices();
109
* Returns the singleton instance of ReplicationServices
111
static inline ReplicationServices &singleton()
113
static ReplicationServices replication_services;
114
return replication_services;
118
106
* Returns whether the ReplicationServices object
119
107
* is active. In other words, does it have both
127
115
* @param Pointer to a replicator to attach/register
129
void attachReplicator(plugin::TransactionReplicator *in_replicator);
117
void attachReplicator(drizzled::plugin::Replicator *in_replicator);
131
119
* Detaches/unregisters a replicator with our internal
132
120
* collection of replicators.
134
122
* @param Pointer to the replicator to detach
136
void detachReplicator(plugin::TransactionReplicator *in_replicator);
124
void detachReplicator(drizzled::plugin::Replicator *in_replicator);
138
126
* Attaches a applier to our internal collection of
141
129
* @param Pointer to a applier to attach/register
143
void attachApplier(plugin::TransactionApplier *in_applier);
131
void attachApplier(drizzled::plugin::Applier *in_applier);
145
133
* Detaches/unregisters a applier with our internal
146
134
* collection of appliers.
148
136
* @param Pointer to the applier to detach
150
void detachApplier(plugin::TransactionApplier *in_applier);
151
/** Returns the timestamp of the last Transaction which was sent to an
138
void detachApplier(drizzled::plugin::Applier *in_applier);
140
* Creates a new StartTransaction GPB message and pushes
143
* @param Pointer to the Session starting the transaction
145
void startTransaction(Session *in_session);
147
* Creates a new CommitTransaction GPB message and pushes
150
* @param Pointer to the Session committing the transaction
152
void commitTransaction(Session *in_session);
154
* Creates a new RollbackTransaction GPB message and pushes
157
* @param Pointer to the Session committing the transaction
159
void rollbackTransaction(Session *in_session);
161
* Creates a new InsertRecord GPB message and pushes it to
164
* @param Pointer to the Session which has inserted a record
165
* @param Pointer to the Table containing insert information
167
void insertRecord(Session *in_session, Table *in_table);
169
* Creates a new UpdateRecord GPB message and pushes it to
172
* @param Pointer to the Session which has updated a record
173
* @param Pointer to the Table containing update information
174
* @param Pointer to the raw bytes representing the old record/row
175
* @param Pointer to the raw bytes representing the new record/row
177
void updateRecord(Session *in_session,
179
const unsigned char *old_record,
180
const unsigned char *new_record);
182
* Creates a new DeleteRecord GPB message and pushes it to
185
* @param Pointer to the Session which has deleted a record
186
* @param Pointer to the Table containing delete information
188
void deleteRecord(Session *in_session, Table *in_table);
190
* Creates a new RawSql GPB message and pushes it to
193
* @TODO With a real data dictionary, this really shouldn't
194
* be needed. CREATE TABLE would map to insertRecord call
195
* on the I_S, etc. Not sure what to do with administrative
196
* commands like CHECK TABLE, though..
198
* @param Pointer to the Session which issued the statement
199
* @param Query string
200
* @param Length of the query string
202
void rawStatement(Session *in_session, const char *in_query, size_t in_query_len);
204
* Returns the timestamp of the last Command which was sent to
154
207
uint64_t getLastAppliedTimestamp() const;
157
} /* namespace drizzled */
210
} /* end namespace drizzled */
159
212
#endif /* DRIZZLED_REPLICATION_SERVICES_H */