22
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
#ifndef DRIZZLED_REPLICATION_SERVICES_H
26
#define DRIZZLED_REPLICATION_SERVICES_H
28
#include <drizzled/atomics.h>
29
#include <drizzled/plugin/replication.h>
35
#include <drizzled/visibility.h>
40
/* some forward declarations needed */
46
class TransactionReplicator;
47
class TransactionApplier;
55
* This is a class which manages transforming internal
56
* transactional events into GPB messages and sending those
57
* events out through registered replicators and appliers.
59
class DRIZZLED_API ReplicationServices
62
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
94
* @param Message to push out
96
plugin::ReplicationReturnCode pushTransactionMessage(Session &in_session,
97
message::Transaction &to_push);
101
ReplicationServices();
105
* Returns the singleton instance of ReplicationServices
107
static inline ReplicationServices &singleton()
109
static ReplicationServices replication_services;
110
return replication_services;
114
* Returns whether the ReplicationServices object
115
* is active. In other words, does it have both
116
* a replicator and an applier that are *active*?
118
bool isActive() const;
121
* Returns the list of replication streams
123
ReplicationStreams &getReplicationStreams();
126
* Attaches a replicator to our internal collection of
129
* @param Pointer to a replicator to attach/register
131
void attachReplicator(plugin::TransactionReplicator *in_replicator);
134
* Detaches/unregisters a replicator with our internal
135
* collection of replicators.
137
* @param Pointer to the replicator to detach
139
void detachReplicator(plugin::TransactionReplicator *in_replicator);
142
* Attaches a applier to our internal collection of
145
* @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);
151
* Detaches/unregisters a applier with our internal
152
* collection of appliers.
154
* @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
162
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 */
191
#endif /* DRIZZLED_REPLICATION_SERVICES_H */
20
#ifndef DRIZZLED_REPLICATOR_H
21
#define DRIZZLED_REPLICATOR_H
23
#include <drizzled/plugin_replicator.h>
25
int replicator_initializer (st_plugin_int *plugin);
26
int replicator_finalizer (st_plugin_int *plugin);
28
/* todo, fill in this API */
29
/* these are the functions called by the rest of the drizzle server
30
to do whatever this plugin does. */
31
bool replicator_session_init (Session *session);
32
bool replicator_write_row(Session *session, Table *table);
33
bool replicator_update_row(Session *session, Table *table,
34
const unsigned char *before,
35
const unsigned char *after);
36
bool replicator_delete_row(Session *session, Table *table);
38
/* The below control transactions */
39
bool replicator_end_transaction(Session *session, bool autocommit, bool commit);
40
bool replicator_prepare(Session *session);
41
bool replicator_statement(Session *session, const char *query, size_t query_length);
43
#endif /* DRIZZLED_REPLICATOR_H */