~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
 *
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
4
 *  Copyright (C) 2008-2009 Sun Microsystems
636.1.1 by Mark Atwood
add replicator plugin type
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
20
#ifndef DRIZZLED_REPLICATOR_H
21
#define DRIZZLED_REPLICATOR_H
22
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
23
#include <vector>
636.1.1 by Mark Atwood
add replicator plugin type
24
25
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
26
/* some forward declarations needed */
27
class Session;
28
class Table;
29
30
namespace drizzled
31
{
32
  namespace plugin
33
  {
34
    class Replicator;
35
    class Applier;
36
  }
37
  namespace message
38
  {
39
    class Command;
40
  }
41
}
42
971.1.49 by Monty Taylor
Hooked transaction_services into Plugin_registry.
43
void add_replicator(drizzled::plugin::Replicator *repl);
971.1.52 by Monty Taylor
Did the finalizers. Renamed plugin_registry.
44
void remove_replicator(drizzled::plugin::Replicator *repl);
971.1.49 by Monty Taylor
Hooked transaction_services into Plugin_registry.
45
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
46
/**
47
 * This is a class which manages transforming internal 
48
 * transactional events into GPB messages and sending those
49
 * events out through registered replicators and appliers.
50
 */
51
namespace drizzled
52
{
53
class TransactionServices
54
{
55
private:
56
  /** Our collection of replicator plugins */
57
  std::vector<drizzled::plugin::Replicator *> replicators;
58
  /** Our collection of applier plugins */
59
  std::vector<drizzled::plugin::Applier *> appliers;
60
  /** 
61
   * Helper method which attaches a transaction context
62
   * the supplied command based on the supplied Session's
63
   * transaction information.
64
   */
65
  void setCommandTransactionContext(drizzled::message::Command *in_command, Session *in_session) const;
66
  /**
67
   * Helper method which pushes a constructed message out
68
   * to the registered replicator and applier plugins.
69
   *
70
   * @param Message to push out
71
   */
72
  void push(drizzled::message::Command *to_push);
73
public:
74
  /**
75
   * Attaches a replicator to our internal collection of
76
   * replicators.
77
   *
78
   * @param Pointer to a replicator to attach/register
79
   */
80
  void attachReplicator(drizzled::plugin::Replicator *in_replicator);
81
  /**
82
   * Detaches/unregisters a replicator with our internal
83
   * collection of replicators.
84
   *
85
   * @param Pointer to the replicator to detach
86
   */
87
  void detachReplicator(drizzled::plugin::Replicator *in_replicator);
88
  /**
89
   * Attaches a applier to our internal collection of
90
   * appliers.
91
   *
92
   * @param Pointer to a applier to attach/register
93
   */
94
  void attachApplier(drizzled::plugin::Applier *in_applier);
95
  /**
96
   * Detaches/unregisters a applier with our internal
97
   * collection of appliers.
98
   *
99
   * @param Pointer to the applier to detach
100
   */
101
  void detachApplier(drizzled::plugin::Applier *in_applier);
102
  /**
103
   * Creates a new StartTransaction GPB message and pushes
104
   * it to replicators.
105
   *
106
   * @param Pointer to the Session starting the transaction
107
   */
108
  void startTransaction(Session *in_session);
109
  /**
110
   * Creates a new CommitTransaction GPB message and pushes
111
   * it to replicators.
112
   *
113
   * @param Pointer to the Session committing the transaction
114
   */
115
  void commitTransaction(Session *in_session);
116
  /**
117
   * Creates a new RollbackTransaction GPB message and pushes
118
   * it to replicators.
119
   *
120
   * @param Pointer to the Session committing the transaction
121
   */
122
  void rollbackTransaction(Session *in_session);
123
  /**
124
   * Creates a new InsertRecord GPB message and pushes it to
125
   * replicators.
126
   *
127
   * @param Pointer to the Session which has inserted a record
128
   * @param Pointer to the Table containing insert information
129
   */
130
  void insertRecord(Session *in_session, Table *in_table);
131
  /**
132
   * Creates a new UpdateRecord GPB message and pushes it to
133
   * replicators.
134
   *
135
   * @param Pointer to the Session which has updated a record
136
   * @param Pointer to the Table containing update information
137
   */
138
  void updateRecord(Session *in_session, Table *in_table, const unsigned char *, const unsigned char *);
139
  /**
140
   * Creates a new DeleteRecord GPB message and pushes it to
141
   * replicators.
142
   *
143
   * @param Pointer to the Session which has deleted a record
144
   * @param Pointer to the Table containing delete information
145
   */
146
  void deleteRecord(Session *in_session, Table *in_table);
147
  /**
148
   * Creates a new RawSql GPB message and pushes it to 
149
   * replicators.
150
   *
151
   * @TODO With a real data dictionary, this really shouldn't
152
   * be needed.  CREATE TABLE would map to insertRecord call
153
   * on the I_S, etc.  Not sure what to do with administrative
154
   * commands like CHECK TABLE, though..
155
   *
156
   * @param Pointer to the Session which issued the statement
157
   * @param Query string
158
   * @param Length of the query string
159
   */
160
  void rawStatement(Session *in_session, const char *in_query, size_t in_query_len);
161
};
162
163
} /* end namespace drizzled */
164
165
#ifdef oldcode
636.1.1 by Mark Atwood
add replicator plugin type
166
/* todo, fill in this API */
167
/* these are the functions called by the rest of the drizzle server
168
   to do whatever this plugin does. */
661 by Brian Aker
First major pass through new replication.
169
bool replicator_session_init (Session *session);
170
bool replicator_write_row(Session *session, Table *table);
665.1.1 by Eric Herman
more EOL whitespace fixups
171
bool replicator_update_row(Session *session, Table *table,
172
                           const unsigned char *before,
661 by Brian Aker
First major pass through new replication.
173
                           const unsigned char *after);
174
bool replicator_delete_row(Session *session, Table *table);
664 by Brian Aker
Completing up replication API.
175
176
/* The below control transactions */
663 by Brian Aker
End points on new replication (aka end transaction)
177
bool replicator_end_transaction(Session *session, bool autocommit, bool commit);
664 by Brian Aker
Completing up replication API.
178
bool replicator_prepare(Session *session);
666 by Brian Aker
Updating new replication positions in code.
179
bool replicator_statement(Session *session, const char *query, size_t query_length);
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
180
#endif /* oldcode */
636.1.1 by Mark Atwood
add replicator plugin type
181
#endif /* DRIZZLED_REPLICATOR_H */