~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
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
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
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
25
#pragma once
636.1.1 by Mark Atwood
add replicator plugin type
26
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
27
#include <drizzled/atomics.h>
28
#include <drizzled/plugin/replication.h>
1143.2.10 by Jay Pipes
Phase 2 new replication work:
29
1405.6.1 by Jay Pipes
This patch adds the following functionality:
30
#include <string>
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
31
#include <vector>
1405.6.1 by Jay Pipes
This patch adds the following functionality:
32
#include <utility>
636.1.1 by Mark Atwood
add replicator plugin type
33
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
34
#include <drizzled/visibility.h>
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
35
2252.1.16 by Olaf van der Spek
Common fwd
36
namespace drizzled {
1130.1.2 by Monty Taylor
Re-org'd the replication stuff into slots.
37
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
38
/**
39
 * This is a class which manages transforming internal 
40
 * transactional events into GPB messages and sending those
41
 * events out through registered replicators and appliers.
42
 */
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
43
class DRIZZLED_API ReplicationServices
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
44
{
1039.5.19 by Jay Pipes
Per Stew's suggestions in code review:
45
public:
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
46
  typedef uint64_t GlobalTransactionId;
1143.2.15 by Jay Pipes
This patch does the following:
47
  /**
48
   * Types of messages that can go in the transaction
49
   * log file.  Every time something is written into the
50
   * transaction log, it is preceded by a header containing
51
   * the type of message which follows.
52
   */
53
  enum MessageType
54
  {
55
    TRANSACTION= 1, /* A GPB Transaction Message */
56
    BLOB= 2 /* A BLOB value */
57
  };
1405.6.1 by Jay Pipes
This patch adds the following functionality:
58
  typedef std::pair<plugin::TransactionReplicator *, plugin::TransactionApplier *> ReplicationPair;
59
  typedef std::vector<ReplicationPair> ReplicationStreams;
60
  /**
61
   * Method which is called after plugins have been loaded but
62
   * before the first client connects.  It determines if the registration
63
   * of applier and replicator plugins is proper and pairs
64
   * the applier and requested replicator plugins into the replication
65
   * streams.
66
   *
67
   * @todo
68
   *
69
   * This is only necessary because we don't yet have plugin dependency
70
   * tracking...
71
   */
72
  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.
73
  /** 
74
   * Helper method which pushes a constructed message out to the registered
75
   * replicator and applier plugins.
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
76
   *
1405.3.3 by Jay Pipes
Adds Session reference to replication API
77
   * @param Session descriptor
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
78
   * @param Message to push out
79
   */
1405.3.3 by Jay Pipes
Adds Session reference to replication API
80
  plugin::ReplicationReturnCode pushTransactionMessage(Session &in_session,
81
                                                       message::Transaction &to_push);
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
82
  /**
1039.5.5 by Jay Pipes
This commit does two things:
83
   * Constructor
84
   */
1039.5.31 by Jay Pipes
This patch does a few things:
85
  ReplicationServices();
1130.1.2 by Monty Taylor
Re-org'd the replication stuff into slots.
86
87
  /**
88
   * Singleton method
89
   * Returns the singleton instance of ReplicationServices
90
   */
91
  static inline ReplicationServices &singleton()
92
  {
93
    static ReplicationServices replication_services;
94
    return replication_services;
95
  }
96
1039.5.5 by Jay Pipes
This commit does two things:
97
  /**
1039.5.31 by Jay Pipes
This patch does a few things:
98
   * Returns whether the ReplicationServices object
1039.5.5 by Jay Pipes
This commit does two things:
99
   * is active.  In other words, does it have both
100
   * a replicator and an applier that are *active*?
101
   */
102
  bool isActive() const;
1405.6.1 by Jay Pipes
This patch adds the following functionality:
103
104
  /**
105
   * Returns the list of replication streams
106
   */
107
  ReplicationStreams &getReplicationStreams();
108
1039.5.5 by Jay Pipes
This commit does two things:
109
  /**
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
110
   * Attaches a replicator to our internal collection of
111
   * replicators.
112
   *
113
   * @param Pointer to a replicator to attach/register
114
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
115
  void attachReplicator(plugin::TransactionReplicator *in_replicator);
1405.6.1 by Jay Pipes
This patch adds the following functionality:
116
  
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
117
  /**
118
   * Detaches/unregisters a replicator with our internal
119
   * collection of replicators.
120
   *
121
   * @param Pointer to the replicator to detach
122
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
123
  void detachReplicator(plugin::TransactionReplicator *in_replicator);
1405.6.1 by Jay Pipes
This patch adds the following functionality:
124
  
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
125
  /**
126
   * Attaches a applier to our internal collection of
127
   * appliers.
128
   *
129
   * @param Pointer to a applier to attach/register
1405.6.1 by Jay Pipes
This patch adds the following functionality:
130
   * @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
131
   */
1405.6.1 by Jay Pipes
This patch adds the following functionality:
132
  void attachApplier(plugin::TransactionApplier *in_applier, const std::string &requested_replicator);
133
  
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
134
  /**
135
   * Detaches/unregisters a applier with our internal
136
   * collection of appliers.
137
   *
138
   * @param Pointer to the applier to detach
139
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
140
  void detachApplier(plugin::TransactionApplier *in_applier);
1405.6.1 by Jay Pipes
This patch adds the following functionality:
141
142
  /** 
143
   * 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.
144
   * applier.
1039.5.31 by Jay Pipes
This patch does a few things:
145
   */
146
  uint64_t getLastAppliedTimestamp() const;
1405.6.1 by Jay Pipes
This patch adds the following functionality:
147
private:
148
  typedef std::vector<plugin::TransactionReplicator *> Replicators;
149
  typedef std::vector<std::pair<std::string, plugin::TransactionApplier *> > Appliers;
150
  /** 
151
   * Atomic boolean set to true if any *active* replicators
152
   * or appliers are actually registered.
153
   */
154
  bool is_active;
155
  /**
156
   * The timestamp of the last time a Transaction message was successfully
157
   * applied (sent to an Applier)
158
   */
159
  atomic<uint64_t> last_applied_timestamp;
160
  /** Our collection of registered replicator plugins */
161
  Replicators replicators;
162
  /** Our collection of registered applier plugins and their requested replicator plugin names */
163
  Appliers appliers;
164
  /** Our replication streams */
165
  ReplicationStreams replication_streams;
166
  /**
167
   * Strips underscores and lowercases supplied replicator name
168
   * or requested name, and appends the suffix "replicator" if missing...
169
   */
170
  void normalizeReplicatorName(std::string &name);
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
171
};
172
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
173
} /* namespace drizzled */
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
174