~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/replicator.h

  • Committer: Eric Herman
  • Date: 2008-12-07 15:29:44 UTC
  • mto: (656.1.14 devel)
  • mto: This revision was merged to the branch mainline in revision 670.
  • Revision ID: eric@mysql.com-20081207152944-cq1nx1cyi0huqj0f
Added pointer to online version of the FAQ

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
5
 
 *  Copyright (C) 2009-2010 Jay Pipes <jaypipes@gmail.com>
6
 
 *
7
 
 *  Authors:
8
 
 *
9
 
 *    Jay Pipes <jaypipes@gmail.com>
 
4
 *  Copyright (C) 2008 Mark Atwood
10
5
 *
11
6
 *  This program is free software; you can redistribute it and/or modify
12
7
 *  it under the terms of the GNU General Public License as published by
22
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23
18
 */
24
19
 
25
 
#ifndef DRIZZLED_REPLICATION_SERVICES_H
26
 
#define DRIZZLED_REPLICATION_SERVICES_H
27
 
 
28
 
#include "drizzled/atomics.h"
29
 
#include "drizzled/plugin/replication.h"
30
 
 
31
 
#include <string>
32
 
#include <vector>
33
 
#include <utility>
34
 
 
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
 
}
51
 
 
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
 
 */
57
 
class ReplicationServices
58
 
{
59
 
public:
60
 
  typedef uint64_t GlobalTransactionId;
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
 
  };
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();
87
 
  /** 
88
 
   * Helper method which pushes a constructed message out to the registered
89
 
   * replicator and applier plugins.
90
 
   *
91
 
   * @param Session descriptor
92
 
   * @param Message to push out
93
 
   */
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
 
  }
110
 
 
111
 
  /**
112
 
   * Returns whether the ReplicationServices object
113
 
   * is active.  In other words, does it have both
114
 
   * a replicator and an applier that are *active*?
115
 
   */
116
 
  bool isActive() const;
117
 
 
118
 
  /**
119
 
   * Returns the list of replication streams
120
 
   */
121
 
  ReplicationStreams &getReplicationStreams();
122
 
 
123
 
  /**
124
 
   * Attaches a replicator to our internal collection of
125
 
   * replicators.
126
 
   *
127
 
   * @param Pointer to a replicator to attach/register
128
 
   */
129
 
  void attachReplicator(plugin::TransactionReplicator *in_replicator);
130
 
  
131
 
  /**
132
 
   * Detaches/unregisters a replicator with our internal
133
 
   * collection of replicators.
134
 
   *
135
 
   * @param Pointer to the replicator to detach
136
 
   */
137
 
  void detachReplicator(plugin::TransactionReplicator *in_replicator);
138
 
  
139
 
  /**
140
 
   * Attaches a applier to our internal collection of
141
 
   * appliers.
142
 
   *
143
 
   * @param Pointer to a applier to attach/register
144
 
   * @param The name of the replicator to pair with
145
 
   */
146
 
  void attachApplier(plugin::TransactionApplier *in_applier, const std::string &requested_replicator);
147
 
  
148
 
  /**
149
 
   * Detaches/unregisters a applier with our internal
150
 
   * collection of appliers.
151
 
   *
152
 
   * @param Pointer to the applier to detach
153
 
   */
154
 
  void detachApplier(plugin::TransactionApplier *in_applier);
155
 
 
156
 
  /** 
157
 
   * Returns the timestamp of the last Transaction which was sent to an
158
 
   * applier.
159
 
   */
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);
185
 
};
186
 
 
187
 
} /* namespace drizzled */
188
 
 
189
 
#endif /* DRIZZLED_REPLICATION_SERVICES_H */
 
20
#ifndef DRIZZLED_REPLICATOR_H
 
21
#define DRIZZLED_REPLICATOR_H
 
22
 
 
23
#include <drizzled/plugin_replicator.h>
 
24
 
 
25
int replicator_initializer (st_plugin_int *plugin);
 
26
int replicator_finalizer (st_plugin_int *plugin);
 
27
 
 
28
/* todo, fill in this API */
 
29
/* these are the functions called by the rest of the drizzle server
 
30
   to do whatever this plugin does. */
 
31
bool replicator_session_init (Session *session);
 
32
bool replicator_write_row(Session *session, Table *table);
 
33
bool replicator_update_row(Session *session, Table *table,
 
34
                           const unsigned char *before,
 
35
                           const unsigned char *after);
 
36
bool replicator_delete_row(Session *session, Table *table);
 
37
 
 
38
/* The below control transactions */
 
39
bool replicator_end_transaction(Session *session, bool autocommit, bool commit);
 
40
bool replicator_rollback_to_savepoint(Session *session, void *save_point);
 
41
bool replicator_savepoint_set(Session *session, void *save_point);
 
42
bool replicator_prepare(Session *session);
 
43
 
 
44
#endif /* DRIZZLED_REPLICATOR_H */