~drizzle-trunk/drizzle/development

636.1.1 by Mark Atwood
add replicator plugin type
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
4
 *  Copyright (C) 2008-2009 Sun Microsystems
1308.2.2 by Jay Pipes
Fixes transaction log/replication for multi-column primary keys. Changes CREATE SCHEMA to not use statement-base RAW_SQL and instead use a derived message::Statement subclass.
5
 *  Copyright (c) 2009-2010 Jay Pipes <jaypipes@gmail.com>
636.1.1 by Mark Atwood
add replicator plugin type
6
 *
1039.5.11 by Jay Pipes
Adds multi-value INSERT test, modifies TransactionServices to support UPDATE statements (though WHERE clause still not done...)
7
 *  Authors:
8
 *
1308.2.2 by Jay Pipes
Fixes transaction log/replication for multi-column primary keys. Changes CREATE SCHEMA to not use statement-base RAW_SQL and instead use a derived message::Statement subclass.
9
 *    Jay Pipes <jaypipes@gmail.com>
1039.5.11 by Jay Pipes
Adds multi-value INSERT test, modifies TransactionServices to support UPDATE statements (though WHERE clause still not done...)
10
 *
636.1.1 by Mark Atwood
add replicator plugin type
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.
14
 *
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.
19
 *
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
23
 */
24
1039.5.31 by Jay Pipes
This patch does a few things:
25
#ifndef DRIZZLED_REPLICATION_SERVICES_H
26
#define DRIZZLED_REPLICATION_SERVICES_H
636.1.1 by Mark Atwood
add replicator plugin type
27
1039.5.5 by Jay Pipes
This commit does two things:
28
#include "drizzled/atomics.h"
1405.3.1 by Jay Pipes
Adapts the plugin::TransactionReplicator and plugin::TransactionApplier
29
#include "drizzled/plugin/replication.h"
1143.2.10 by Jay Pipes
Phase 2 new replication work:
30
1405.6.1 by Jay Pipes
This patch adds the following functionality:
31
#include <string>
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
32
#include <vector>
1405.6.1 by Jay Pipes
This patch adds the following functionality:
33
#include <utility>
636.1.1 by Mark Atwood
add replicator plugin type
34
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
35
namespace drizzled
36
{
37
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
38
/* some forward declarations needed */
39
class Session;
40
class Table;
41
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
42
namespace plugin
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
43
{
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
44
  class TransactionReplicator;
45
  class TransactionApplier;
46
}
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
47
namespace message
48
{
49
  class Transaction;
50
}
1130.1.2 by Monty Taylor
Re-org'd the replication stuff into slots.
51
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
52
/**
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.
56
 */
1039.5.31 by Jay Pipes
This patch does a few things:
57
class ReplicationServices
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
58
{
1039.5.19 by Jay Pipes
Per Stew's suggestions in code review:
59
public:
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
60
  typedef uint64_t GlobalTransactionId;
1143.2.15 by Jay Pipes
This patch does the following:
61
  /**
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.
66
   */
67
  enum MessageType
68
  {
69
    TRANSACTION= 1, /* A GPB Transaction Message */
70
    BLOB= 2 /* A BLOB value */
71
  };
1405.6.1 by Jay Pipes
This patch adds the following functionality:
72
  typedef std::pair<plugin::TransactionReplicator *, plugin::TransactionApplier *> ReplicationPair;
73
  typedef std::vector<ReplicationPair> ReplicationStreams;
74
  /**
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
79
   * streams.
80
   *
81
   * @todo
82
   *
83
   * This is only necessary because we don't yet have plugin dependency
84
   * tracking...
85
   */
86
  bool evaluateRegisteredPlugins();
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
87
  /** 
88
   * Helper method which pushes a constructed message out to the registered
89
   * replicator and applier plugins.
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
90
   *
1405.3.3 by Jay Pipes
Adds Session reference to replication API
91
   * @param Session descriptor
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
92
   * @param Message to push out
93
   */
1405.3.3 by Jay Pipes
Adds Session reference to replication API
94
  plugin::ReplicationReturnCode pushTransactionMessage(Session &in_session,
95
                                                       message::Transaction &to_push);
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
96
  /**
1039.5.5 by Jay Pipes
This commit does two things:
97
   * Constructor
98
   */
1039.5.31 by Jay Pipes
This patch does a few things:
99
  ReplicationServices();
1130.1.2 by Monty Taylor
Re-org'd the replication stuff into slots.
100
101
  /**
102
   * Singleton method
103
   * Returns the singleton instance of ReplicationServices
104
   */
105
  static inline ReplicationServices &singleton()
106
  {
107
    static ReplicationServices replication_services;
108
    return replication_services;
109
  }
110
1039.5.5 by Jay Pipes
This commit does two things:
111
  /**
1039.5.31 by Jay Pipes
This patch does a few things:
112
   * Returns whether the ReplicationServices object
1039.5.5 by Jay Pipes
This commit does two things:
113
   * is active.  In other words, does it have both
114
   * a replicator and an applier that are *active*?
115
   */
116
  bool isActive() const;
1405.6.1 by Jay Pipes
This patch adds the following functionality:
117
118
  /**
119
   * Returns the list of replication streams
120
   */
121
  ReplicationStreams &getReplicationStreams();
122
1039.5.5 by Jay Pipes
This commit does two things:
123
  /**
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
124
   * Attaches a replicator to our internal collection of
125
   * replicators.
126
   *
127
   * @param Pointer to a replicator to attach/register
128
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
129
  void attachReplicator(plugin::TransactionReplicator *in_replicator);
1405.6.1 by Jay Pipes
This patch adds the following functionality:
130
  
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
131
  /**
132
   * Detaches/unregisters a replicator with our internal
133
   * collection of replicators.
134
   *
135
   * @param Pointer to the replicator to detach
136
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
137
  void detachReplicator(plugin::TransactionReplicator *in_replicator);
1405.6.1 by Jay Pipes
This patch adds the following functionality:
138
  
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
139
  /**
140
   * Attaches a applier to our internal collection of
141
   * appliers.
142
   *
143
   * @param Pointer to a applier to attach/register
1405.6.1 by Jay Pipes
This patch adds the following functionality:
144
   * @param The name of the replicator to pair with
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
145
   */
1405.6.1 by Jay Pipes
This patch adds the following functionality:
146
  void attachApplier(plugin::TransactionApplier *in_applier, const std::string &requested_replicator);
147
  
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
148
  /**
149
   * Detaches/unregisters a applier with our internal
150
   * collection of appliers.
151
   *
152
   * @param Pointer to the applier to detach
153
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
154
  void detachApplier(plugin::TransactionApplier *in_applier);
1405.6.1 by Jay Pipes
This patch adds the following functionality:
155
156
  /** 
157
   * Returns the timestamp of the last Transaction which was sent to an
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
158
   * applier.
1039.5.31 by Jay Pipes
This patch does a few things:
159
   */
160
  uint64_t getLastAppliedTimestamp() const;
1405.6.1 by Jay Pipes
This patch adds the following functionality:
161
private:
162
  typedef std::vector<plugin::TransactionReplicator *> Replicators;
163
  typedef std::vector<std::pair<std::string, plugin::TransactionApplier *> > Appliers;
164
  /** 
165
   * Atomic boolean set to true if any *active* replicators
166
   * or appliers are actually registered.
167
   */
168
  bool is_active;
169
  /**
170
   * The timestamp of the last time a Transaction message was successfully
171
   * applied (sent to an Applier)
172
   */
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 */
177
  Appliers appliers;
178
  /** Our replication streams */
179
  ReplicationStreams replication_streams;
180
  /**
181
   * Strips underscores and lowercases supplied replicator name
182
   * or requested name, and appends the suffix "replicator" if missing...
183
   */
184
  void normalizeReplicatorName(std::string &name);
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
185
};
186
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
187
} /* namespace drizzled */
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
188
1039.5.31 by Jay Pipes
This patch does a few things:
189
#endif /* DRIZZLED_REPLICATION_SERVICES_H */