1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008-2009 Sun Microsystems
5
* Copyright (c) 2009-2010 Jay Pipes <jaypipes@gmail.com>
9
* Jay Pipes <jaypipes@gmail.com>
11
* This program is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation; version 2 of the License.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* 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"
38
/* some forward declarations needed */
44
class TransactionReplicator;
45
class TransactionApplier;
53
* This is a class which manages transforming internal
54
* transactional events into GPB messages and sending those
55
* events out through registered replicators and appliers.
57
class ReplicationServices
60
typedef uint64_t GlobalTransactionId;
62
* Types of messages that can go in the transaction
63
* log file. Every time something is written into the
64
* transaction log, it is preceded by a header containing
65
* the type of message which follows.
69
TRANSACTION= 1, /* A GPB Transaction Message */
70
BLOB= 2 /* A BLOB value */
72
typedef std::pair<plugin::TransactionReplicator *, plugin::TransactionApplier *> ReplicationPair;
73
typedef std::vector<ReplicationPair> ReplicationStreams;
75
* Method which is called after plugins have been loaded but
76
* before the first client connects. It determines if the registration
77
* of applier and replicator plugins is proper and pairs
78
* the applier and requested replicator plugins into the replication
83
* This is only necessary because we don't yet have plugin dependency
86
bool evaluateRegisteredPlugins();
88
* Helper method which pushes a constructed message out to the registered
89
* replicator and applier plugins.
91
* @param Session descriptor
92
* @param Message to push out
94
plugin::ReplicationReturnCode pushTransactionMessage(Session &in_session,
95
message::Transaction &to_push);
99
ReplicationServices();
103
* Returns the singleton instance of ReplicationServices
105
static inline ReplicationServices &singleton()
107
static ReplicationServices replication_services;
108
return replication_services;
112
* Returns whether the ReplicationServices object
113
* is active. In other words, does it have both
114
* a replicator and an applier that are *active*?
116
bool isActive() const;
119
* Returns the list of replication streams
121
ReplicationStreams &getReplicationStreams();
124
* Attaches a replicator to our internal collection of
127
* @param Pointer to a replicator to attach/register
129
void attachReplicator(plugin::TransactionReplicator *in_replicator);
132
* Detaches/unregisters a replicator with our internal
133
* collection of replicators.
135
* @param Pointer to the replicator to detach
137
void detachReplicator(plugin::TransactionReplicator *in_replicator);
140
* Attaches a applier to our internal collection of
143
* @param Pointer to a applier to attach/register
144
* @param The name of the replicator to pair with
146
void attachApplier(plugin::TransactionApplier *in_applier, const std::string &requested_replicator);
149
* Detaches/unregisters a applier with our internal
150
* collection of appliers.
152
* @param Pointer to the applier to detach
154
void detachApplier(plugin::TransactionApplier *in_applier);
157
* Returns the timestamp of the last Transaction which was sent to an
160
uint64_t getLastAppliedTimestamp() const;
162
typedef std::vector<plugin::TransactionReplicator *> Replicators;
163
typedef std::vector<std::pair<std::string, plugin::TransactionApplier *> > Appliers;
165
* Atomic boolean set to true if any *active* replicators
166
* or appliers are actually registered.
170
* The timestamp of the last time a Transaction message was successfully
171
* applied (sent to an Applier)
173
atomic<uint64_t> last_applied_timestamp;
174
/** Our collection of registered replicator plugins */
175
Replicators replicators;
176
/** Our collection of registered applier plugins and their requested replicator plugin names */
178
/** Our replication streams */
179
ReplicationStreams replication_streams;
181
* Strips underscores and lowercases supplied replicator name
182
* or requested name, and appends the suffix "replicator" if missing...
184
void normalizeReplicatorName(std::string &name);
187
} /* namespace drizzled */
189
#endif /* DRIZZLED_REPLICATION_SERVICES_H */