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"
35
/* some forward declarations needed */
41
class TransactionReplicator;
42
class TransactionApplier;
50
* This is a class which manages transforming internal
51
* transactional events into GPB messages and sending those
52
* events out through registered replicators and appliers.
54
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;
73
* Atomic boolean set to true if any *active* replicators
74
* or appliers are actually registered.
76
atomic<bool> is_active;
78
* The timestamp of the last time a Transaction message was successfully
79
* applied (sent to an Applier)
81
atomic<uint64_t> last_applied_timestamp;
82
/** Our collection of replicator plugins */
83
Replicators replicators;
84
/** Our collection of applier plugins */
87
* Helper method which is called after any change in the
88
* registered appliers or replicators to evaluate whether
89
* any remaining plugins are actually active.
91
* This method properly sets the is_active member variable.
93
void evaluateActivePlugins();
96
* Helper method which pushes a constructed message out to the registered
97
* replicator and applier plugins.
99
* @param Message to push out
101
void pushTransactionMessage(message::Transaction &to_push);
105
ReplicationServices();
109
* Returns the singleton instance of ReplicationServices
111
static inline ReplicationServices &singleton()
113
static ReplicationServices replication_services;
114
return replication_services;
118
* Returns whether the ReplicationServices object
119
* is active. In other words, does it have both
120
* a replicator and an applier that are *active*?
122
bool isActive() const;
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);
131
* Detaches/unregisters a replicator with our internal
132
* collection of replicators.
134
* @param Pointer to the replicator to detach
136
void detachReplicator(plugin::TransactionReplicator *in_replicator);
138
* Attaches a applier to our internal collection of
141
* @param Pointer to a applier to attach/register
143
void attachApplier(plugin::TransactionApplier *in_applier);
145
* Detaches/unregisters a applier with our internal
146
* collection of appliers.
148
* @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
154
uint64_t getLastAppliedTimestamp() const;
157
} /* namespace drizzled */
159
#endif /* DRIZZLED_REPLICATION_SERVICES_H */