~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/replication_services.h

Merge Monty - Updates to pandora-build to support features of gcc 4.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23
23
 */
24
24
 
25
 
#pragma once
 
25
#ifndef DRIZZLED_REPLICATION_SERVICES_H
 
26
#define DRIZZLED_REPLICATION_SERVICES_H
26
27
 
27
 
#include <drizzled/atomics.h>
28
 
#include <drizzled/plugin/replication.h>
 
28
#include "drizzled/atomics.h"
 
29
#include "drizzled/plugin/replication.h"
29
30
 
30
31
#include <string>
31
32
#include <vector>
32
33
#include <utility>
33
34
 
34
 
#include <drizzled/visibility.h>
35
 
 
36
 
namespace drizzled {
 
35
namespace drizzled
 
36
{
 
37
 
 
38
/* some forward declarations needed */
 
39
class Session;
 
40
class Table;
 
41
 
 
42
namespace plugin
 
43
{
 
44
  class TransactionReplicator;
 
45
  class TransactionApplier;
 
46
}
 
47
namespace message
 
48
{
 
49
  class Transaction;
 
50
}
37
51
 
38
52
/**
39
53
 * This is a class which manages transforming internal 
40
54
 * transactional events into GPB messages and sending those
41
55
 * events out through registered replicators and appliers.
42
56
 */
43
 
class DRIZZLED_API ReplicationServices
 
57
class ReplicationServices
44
58
{
45
59
public:
46
60
  typedef uint64_t GlobalTransactionId;
69
83
   * This is only necessary because we don't yet have plugin dependency
70
84
   * tracking...
71
85
   */
72
 
  static bool evaluateRegisteredPlugins();
 
86
  bool evaluateRegisteredPlugins();
73
87
  /** 
74
88
   * Helper method which pushes a constructed message out to the registered
75
89
   * replicator and applier plugins.
77
91
   * @param Session descriptor
78
92
   * @param Message to push out
79
93
   */
80
 
  static plugin::ReplicationReturnCode pushTransactionMessage(Session &in_session, message::Transaction &to_push);
 
94
  plugin::ReplicationReturnCode pushTransactionMessage(Session &in_session,
 
95
                                                       message::Transaction &to_push);
 
96
  /**
 
97
   * Constructor
 
98
   */
 
99
  ReplicationServices();
 
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
  }
81
110
 
82
111
  /**
83
112
   * Returns whether the ReplicationServices object
84
113
   * is active.  In other words, does it have both
85
114
   * a replicator and an applier that are *active*?
86
115
   */
87
 
  static bool isActive();
 
116
  bool isActive() const;
88
117
 
89
118
  /**
90
119
   * Returns the list of replication streams
91
120
   */
92
 
  static ReplicationStreams &getReplicationStreams();
 
121
  ReplicationStreams &getReplicationStreams();
93
122
 
94
123
  /**
95
124
   * Attaches a replicator to our internal collection of
97
126
   *
98
127
   * @param Pointer to a replicator to attach/register
99
128
   */
100
 
  static void attachReplicator(plugin::TransactionReplicator *in_replicator);
 
129
  void attachReplicator(plugin::TransactionReplicator *in_replicator);
101
130
  
102
131
  /**
103
132
   * Detaches/unregisters a replicator with our internal
105
134
   *
106
135
   * @param Pointer to the replicator to detach
107
136
   */
108
 
  static void detachReplicator(plugin::TransactionReplicator *in_replicator);
 
137
  void detachReplicator(plugin::TransactionReplicator *in_replicator);
109
138
  
110
139
  /**
111
140
   * Attaches a applier to our internal collection of
114
143
   * @param Pointer to a applier to attach/register
115
144
   * @param The name of the replicator to pair with
116
145
   */
117
 
  static void attachApplier(plugin::TransactionApplier *in_applier, const std::string &requested_replicator);
 
146
  void attachApplier(plugin::TransactionApplier *in_applier, const std::string &requested_replicator);
118
147
  
119
148
  /**
120
149
   * Detaches/unregisters a applier with our internal
122
151
   *
123
152
   * @param Pointer to the applier to detach
124
153
   */
125
 
  static void detachApplier(plugin::TransactionApplier *in_applier);
 
154
  void detachApplier(plugin::TransactionApplier *in_applier);
126
155
 
127
156
  /** 
128
157
   * Returns the timestamp of the last Transaction which was sent to an
129
158
   * applier.
130
159
   */
131
 
  static uint64_t getLastAppliedTimestamp();
 
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);
132
185
};
133
186
 
134
187
} /* namespace drizzled */
135
188
 
 
189
#endif /* DRIZZLED_REPLICATION_SERVICES_H */