~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/replication_services.h

This patch adds the following functionality:

* Removes the need to manually enable replicators in order
  for an applier to work.
* Removes the enabled/disabled setting of both transaction
  applier plugins and transaction replicator plugins
* Pairs a replicator with an applier into a "ReplicationStream"
  and removes all checks for "enabled" replicators and appliers
* Allows modules that implement a TransactionApplier (such as
  the transaction_log module) to specify which replicator to
  use via a configuration variable.  For instance, the transaction
  log module now has --transaction-log-use-replicator=[default|filtered..]
  instead of the user having to do --default-replicator-enable and such
* Adds a new data dictionary table for REPLICATION_STREAMS, which
  allows querying of activated replication-to-applier streams
  managed by drizzled::ReplicationServices

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#define DRIZZLED_REPLICATION_SERVICES_H
27
27
 
28
28
#include "drizzled/atomics.h"
 
29
#include "drizzled/plugin/replication.h"
29
30
 
 
31
#include <string>
30
32
#include <vector>
 
33
#include <utility>
31
34
 
32
35
namespace drizzled
33
36
{
66
69
    TRANSACTION= 1, /* A GPB Transaction Message */
67
70
    BLOB= 2 /* A BLOB value */
68
71
  };
69
 
  typedef std::vector<plugin::TransactionReplicator *> Replicators;
70
 
  typedef std::vector<plugin::TransactionApplier *> Appliers;
71
 
private:
72
 
  /** 
73
 
   * Atomic boolean set to true if any *active* replicators
74
 
   * or appliers are actually registered.
75
 
   */
76
 
  atomic<bool> is_active;
77
 
  /**
78
 
   * The timestamp of the last time a Transaction message was successfully
79
 
   * applied (sent to an Applier)
80
 
   */
81
 
  atomic<uint64_t> last_applied_timestamp;
82
 
  /** Our collection of replicator plugins */
83
 
  Replicators replicators;
84
 
  /** Our collection of applier plugins */
85
 
  Appliers appliers;
86
 
  /**
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.
90
 
   * 
91
 
   * This method properly sets the is_active member variable.
92
 
   */
93
 
  void evaluateActivePlugins();
94
 
public:
 
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();
95
87
  /** 
96
88
   * Helper method which pushes a constructed message out to the registered
97
89
   * replicator and applier plugins.
98
90
   *
 
91
   * @param Session descriptor
99
92
   * @param Message to push out
100
93
   */
101
 
  void pushTransactionMessage(message::Transaction &to_push);
 
94
  plugin::ReplicationReturnCode pushTransactionMessage(Session &in_session,
 
95
                                                       message::Transaction &to_push);
102
96
  /**
103
97
   * Constructor
104
98
   */
120
114
   * a replicator and an applier that are *active*?
121
115
   */
122
116
  bool isActive() const;
 
117
 
 
118
  /**
 
119
   * Returns the list of replication streams
 
120
   */
 
121
  ReplicationStreams &getReplicationStreams();
 
122
 
123
123
  /**
124
124
   * Attaches a replicator to our internal collection of
125
125
   * replicators.
127
127
   * @param Pointer to a replicator to attach/register
128
128
   */
129
129
  void attachReplicator(plugin::TransactionReplicator *in_replicator);
 
130
  
130
131
  /**
131
132
   * Detaches/unregisters a replicator with our internal
132
133
   * collection of replicators.
134
135
   * @param Pointer to the replicator to detach
135
136
   */
136
137
  void detachReplicator(plugin::TransactionReplicator *in_replicator);
 
138
  
137
139
  /**
138
140
   * Attaches a applier to our internal collection of
139
141
   * appliers.
140
142
   *
141
143
   * @param Pointer to a applier to attach/register
 
144
   * @param The name of the replicator to pair with
142
145
   */
143
 
  void attachApplier(plugin::TransactionApplier *in_applier);
 
146
  void attachApplier(plugin::TransactionApplier *in_applier, const std::string &requested_replicator);
 
147
  
144
148
  /**
145
149
   * Detaches/unregisters a applier with our internal
146
150
   * collection of appliers.
148
152
   * @param Pointer to the applier to detach
149
153
   */
150
154
  void detachApplier(plugin::TransactionApplier *in_applier);
151
 
  /** Returns the timestamp of the last Transaction which was sent to an
 
155
 
 
156
  /** 
 
157
   * Returns the timestamp of the last Transaction which was sent to an
152
158
   * applier.
153
159
   */
154
160
  uint64_t getLastAppliedTimestamp() const;
 
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);
155
185
};
156
186
 
157
187
} /* namespace drizzled */