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
26
* @file Server-side utility which is responsible for managing the
27
* communication between the kernel and the replication plugins:
29
* - TransactionReplicator
30
* - TransactionApplier
34
* ReplicationServices is a bridge between replication modules and the kernel,
35
* and its primary function is to */
38
#include "drizzled/replication_services.h"
39
#include "drizzled/plugin/transaction_replicator.h"
40
#include "drizzled/plugin/transaction_applier.h"
41
#include "drizzled/message/transaction.pb.h"
42
#include "drizzled/message/table.pb.h"
43
#include "drizzled/message/statement_transform.h"
44
#include "drizzled/gettext.h"
45
#include "drizzled/session.h"
46
#include "drizzled/error.h"
55
ReplicationServices::ReplicationServices()
60
void ReplicationServices::evaluateActivePlugins()
63
* We loop through replicators and appliers, evaluating
64
* whether or not there is at least one active replicator
65
* and one active applier. If not, we set is_active
68
bool tmp_is_active= false;
70
if (replicators.empty() || appliers.empty())
77
* Determine if any remaining replicators and if those
78
* replicators are active...if not, set is_active
81
for (Replicators::iterator repl_iter= replicators.begin();
82
repl_iter != replicators.end();
85
if ((*repl_iter)->isEnabled())
93
/* No active replicators. Set is_active to false and exit. */
99
* OK, we know there's at least one active replicator.
101
* Now determine if any remaining replicators and if those
102
* replicators are active...if not, set is_active
105
for (Appliers::iterator appl_iter= appliers.begin();
106
appl_iter != appliers.end();
109
if ((*appl_iter)->isEnabled())
115
/* If we get here, there are no active appliers */
119
void ReplicationServices::attachReplicator(plugin::TransactionReplicator *in_replicator)
121
replicators.push_back(in_replicator);
122
evaluateActivePlugins();
125
void ReplicationServices::detachReplicator(plugin::TransactionReplicator *in_replicator)
127
replicators.erase(std::find(replicators.begin(), replicators.end(), in_replicator));
128
evaluateActivePlugins();
131
void ReplicationServices::attachApplier(plugin::TransactionApplier *in_applier)
133
appliers.push_back(in_applier);
134
evaluateActivePlugins();
137
void ReplicationServices::detachApplier(plugin::TransactionApplier *in_applier)
139
appliers.erase(std::find(appliers.begin(), appliers.end(), in_applier));
140
evaluateActivePlugins();
143
bool ReplicationServices::isActive() const
148
void ReplicationServices::pushTransactionMessage(message::Transaction &to_push)
150
vector<plugin::TransactionReplicator *>::iterator repl_iter= replicators.begin();
151
vector<plugin::TransactionApplier *>::iterator appl_start_iter, appl_iter;
152
appl_start_iter= appliers.begin();
154
plugin::TransactionReplicator *cur_repl;
155
plugin::TransactionApplier *cur_appl;
157
while (repl_iter != replicators.end())
159
cur_repl= *repl_iter;
160
if (! cur_repl->isEnabled())
166
appl_iter= appl_start_iter;
167
while (appl_iter != appliers.end())
169
cur_appl= *appl_iter;
171
if (! cur_appl->isEnabled())
177
cur_repl->replicate(cur_appl, to_push);
180
* We update the timestamp for the last applied Transaction so that
181
* publisher plugins can ask the replication services when the
182
* last known applied Transaction was using the getLastAppliedTimestamp()
185
last_applied_timestamp.fetch_and_store(to_push.transaction_context().end_timestamp());
192
} /* namespace drizzled */