~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/replication_services.h

  • Committer: Mark Atwood
  • Date: 2011-10-27 05:08:12 UTC
  • mfrom: (2445.1.11 rf)
  • Revision ID: me@mark.atwood.name-20111027050812-1icvs72lb0u4xdc4
mergeĀ lp:~olafvdspek/drizzle/refactor8

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