~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/replication_services.h

  • Committer: Jay Pipes
  • Date: 2010-03-16 21:30:44 UTC
  • mto: This revision was merged to the branch mainline in revision 1351.
  • Revision ID: jpipes@serialcoder-20100316213044-e4f0xc0aga34l1es
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
#include "drizzled/atomics.h"
29
29
 
30
 
#include "drizzled/message/transaction.pb.h"
31
 
 
32
30
#include <vector>
33
31
 
34
32
namespace drizzled
43
41
  class TransactionReplicator;
44
42
  class TransactionApplier;
45
43
}
 
44
namespace message
 
45
{
 
46
  class Transaction;
 
47
}
46
48
 
47
49
/**
48
50
 * This is a class which manages transforming internal 
52
54
class ReplicationServices
53
55
{
54
56
public:
55
 
  static const size_t DEFAULT_RECORD_SIZE= 100;
56
57
  typedef uint64_t GlobalTransactionId;
57
58
  /**
58
59
   * Types of messages that can go in the transaction
90
91
   * This method properly sets the is_active member variable.
91
92
   */
92
93
  void evaluateActivePlugins();
93
 
  /**
94
 
   * Helper method which returns the active Transaction message
95
 
   * for the supplied Session.  If one is not found, a new Transaction
96
 
   * message is allocated, initialized, and returned.
97
 
   *
98
 
   * @param The session processing the transaction
99
 
   */
100
 
  message::Transaction *getActiveTransaction(Session *in_session) const;
101
 
  /** 
102
 
   * Helper method which attaches a transaction context
103
 
   * the supplied transaction based on the supplied Session's
104
 
   * transaction information.  This method also ensure the
105
 
   * transaction message is attached properly to the Session object
106
 
   *
107
 
   * @param The transaction message to initialize
108
 
   * @param The Session processing this transaction
109
 
   */
110
 
  void initTransaction(message::Transaction &in_command, Session *in_session) const;
111
 
  /** 
112
 
   * Helper method which finalizes data members for the 
113
 
   * supplied transaction's context.
114
 
   *
115
 
   * @param The transaction message to finalize 
116
 
   * @param The Session processing this transaction
117
 
   */
118
 
  void finalizeTransaction(message::Transaction &in_command, Session *in_session) const;
119
 
  /**
120
 
   * Helper method which deletes transaction memory and
121
 
   * unsets Session's transaction and statement messages.
122
 
   */
123
 
  void cleanupTransaction(message::Transaction *in_transaction,
124
 
                          Session *in_session) const;
125
 
  /**
126
 
   * Helper method which initializes a Statement message
127
 
   *
128
 
   * @param The statement to initialize
129
 
   * @param The type of the statement
130
 
   * @param The session processing this statement
131
 
   */
132
 
  void initStatement(message::Statement &statement,
133
 
                     message::Statement::Type in_type,
134
 
                     Session *in_session) const;
135
 
  /**
136
 
   * Helper method which returns an initialized Statement
137
 
   * message for methods doing insertion of data.
138
 
   *
139
 
   * @param[in] Pointer to the Session doing the processing
140
 
   * @param[in] Pointer to the Table object being inserted into
141
 
   */
142
 
  message::Statement &getInsertStatement(Session *in_session,
143
 
                                         Table *in_table) const;
144
 
 
145
 
  /**
146
 
   * Helper method which initializes the header message for
147
 
   * insert operations.
148
 
   *
149
 
   * @param[inout] Statement message container to modify
150
 
   * @param[in] Pointer to the Session doing the processing
151
 
   * @param[in] Pointer to the Table being inserted into
152
 
   */
153
 
  void setInsertHeader(message::Statement &statement,
154
 
                       Session *in_session,
155
 
                       Table *in_table) const;
156
 
  /**
157
 
   * Helper method which returns an initialized Statement
158
 
   * message for methods doing updates of data.
159
 
   *
160
 
   * @param[in] Pointer to the Session doing the processing
161
 
   * @param[in] Pointer to the Table object being updated
162
 
   * @param[in] Pointer to the old data in the record
163
 
   * @param[in] Pointer to the new data in the record
164
 
   */
165
 
  message::Statement &getUpdateStatement(Session *in_session,
166
 
                                         Table *in_table,
167
 
                                         const unsigned char *old_record, 
168
 
                                         const unsigned char *new_record) const;
169
 
  /**
170
 
   * Helper method which initializes the header message for
171
 
   * update operations.
172
 
   *
173
 
   * @param[inout] Statement message container to modify
174
 
   * @param[in] Pointer to the Session doing the processing
175
 
   * @param[in] Pointer to the Table being updated
176
 
   * @param[in] Pointer to the old data in the record
177
 
   * @param[in] Pointer to the new data in the record
178
 
   */
179
 
  void setUpdateHeader(message::Statement &statement,
180
 
                       Session *in_session,
181
 
                       Table *in_table,
182
 
                       const unsigned char *old_record, 
183
 
                       const unsigned char *new_record) const;
184
 
  /**
185
 
   * Helper method which returns an initialized Statement
186
 
   * message for methods doing deletion of data.
187
 
   *
188
 
   * @param[in] Pointer to the Session doing the processing
189
 
   * @param[in] Pointer to the Table object being deleted from
190
 
   */
191
 
  message::Statement &getDeleteStatement(Session *in_session,
192
 
                                         Table *in_table) const;
193
 
 
194
 
  /**
195
 
   * Helper method which initializes the header message for
196
 
   * insert operations.
197
 
   *
198
 
   * @param[inout] Statement message container to modify
199
 
   * @param[in] Pointer to the Session doing the processing
200
 
   * @param[in] Pointer to the Table being deleted from
201
 
   */
202
 
  void setDeleteHeader(message::Statement &statement,
203
 
                       Session *in_session,
204
 
                       Table *in_table) const;
205
 
  /**
206
 
   * Helper method which pushes a constructed message out
207
 
   * to the registered replicator and applier plugins.
 
94
public:
 
95
  /** 
 
96
   * Helper method which pushes a constructed message out to the registered
 
97
   * replicator and applier plugins.
208
98
   *
209
99
   * @param Message to push out
210
100
   */
211
 
  void push(message::Transaction &to_push);
212
 
public:
 
101
  void pushTransactionMessage(message::Transaction &to_push);
213
102
  /**
214
103
   * Constructor
215
104
   */
259
148
   * @param Pointer to the applier to detach
260
149
   */
261
150
  void detachApplier(plugin::TransactionApplier *in_applier);
262
 
  /**
263
 
   * Commits a normal transaction (see above) and pushes the
264
 
   * transaction message out to the replicators.
265
 
   *
266
 
   * @param Pointer to the Session committing the transaction
267
 
   */
268
 
  void commitTransaction(Session *in_session);
269
 
  /**
270
 
   * Marks the current active transaction message as being rolled
271
 
   * back and pushes the transaction message out to replicators.
272
 
   *
273
 
   * @param Pointer to the Session committing the transaction
274
 
   */
275
 
  void rollbackTransaction(Session *in_session);
276
 
  /**
277
 
   * Finalizes a Statement message and sets the Session's statement
278
 
   * message to NULL.
279
 
   *
280
 
   * @param The statement to initialize
281
 
   * @param The session processing this statement
282
 
   */
283
 
  void finalizeStatement(message::Statement &statement,
284
 
                         Session *in_session) const;
285
 
  /**
286
 
   * Creates a new InsertRecord GPB message and pushes it to
287
 
   * replicators.
288
 
   *
289
 
   * @param Pointer to the Session which has inserted a record
290
 
   * @param Pointer to the Table containing insert information
291
 
   *
292
 
   * Grr, returning "true" here on error because of the cursor
293
 
   * reversed bool return crap...fix that.
294
 
   */
295
 
  bool insertRecord(Session *in_session, Table *in_table);
296
 
  /**
297
 
   * Creates a new UpdateRecord GPB message and pushes it to
298
 
   * replicators.
299
 
   *
300
 
   * @param Pointer to the Session which has updated a record
301
 
   * @param Pointer to the Table containing update information
302
 
   * @param Pointer to the raw bytes representing the old record/row
303
 
   * @param Pointer to the raw bytes representing the new record/row 
304
 
   */
305
 
  void updateRecord(Session *in_session, 
306
 
                    Table *in_table, 
307
 
                    const unsigned char *old_record, 
308
 
                    const unsigned char *new_record);
309
 
  /**
310
 
   * Creates a new DeleteRecord GPB message and pushes it to
311
 
   * replicators.
312
 
   *
313
 
   * @param Pointer to the Session which has deleted a record
314
 
   * @param Pointer to the Table containing delete information
315
 
   */
316
 
  void deleteRecord(Session *in_session, Table *in_table);
317
 
  /**
318
 
   * Creates a CreateSchema Statement GPB message and adds it
319
 
   * to the Session's active Transaction GPB message for pushing
320
 
   * out to the replicator streams.
321
 
   *
322
 
   * @param[in] Pointer to the Session which issued the statement
323
 
   * @param[in] message::Schema message describing new schema
324
 
   */
325
 
  void createSchema(Session *in_session, const message::Schema &schema);
326
 
  /**
327
 
   * Creates a DropSchema Statement GPB message and adds it
328
 
   * to the Session's active Transaction GPB message for pushing
329
 
   * out to the replicator streams.
330
 
   *
331
 
   * @param[in] Pointer to the Session which issued the statement
332
 
   * @param[in] message::Schema message describing new schema
333
 
   */
334
 
  void dropSchema(Session *in_session, const std::string &schema_name);
335
 
  /**
336
 
   * Creates a CreateTable Statement GPB message and adds it
337
 
   * to the Session's active Transaction GPB message for pushing
338
 
   * out to the replicator streams.
339
 
   *
340
 
   * @param[in] Pointer to the Session which issued the statement
341
 
   * @param[in] message::Table message describing new schema
342
 
   */
343
 
  void createTable(Session *in_session, const message::Table &table);
344
 
  /**
345
 
   * Creates a DropTable Statement GPB message and adds it
346
 
   * to the Session's active Transaction GPB message for pushing
347
 
   * out to the replicator streams.
348
 
   *
349
 
   * @param[in] Pointer to the Session which issued the statement
350
 
   * @param[in] The schema of the table being dropped
351
 
   * @param[in] The table name of the table being dropped
352
 
   * @param[in] Did the user specify an IF EXISTS clause?
353
 
   */
354
 
  void dropTable(Session *in_session,
355
 
                     const std::string &schema_name,
356
 
                     const std::string &table_name,
357
 
                     bool if_exists);
358
 
  /**
359
 
   * Creates a TruncateTable Statement GPB message and adds it
360
 
   * to the Session's active Transaction GPB message for pushing
361
 
   * out to the replicator streams.
362
 
   *
363
 
   * @param[in] Pointer to the Session which issued the statement
364
 
   * @param[in] The Table being truncated
365
 
   */
366
 
  void truncateTable(Session *in_session, Table *in_table);
367
 
  /**
368
 
   * Creates a new RawSql GPB message and pushes it to 
369
 
   * replicators.
370
 
   *
371
 
   * @TODO With a real data dictionary, this really shouldn't
372
 
   * be needed.  CREATE TABLE would map to insertRecord call
373
 
   * on the I_S, etc.  Not sure what to do with administrative
374
 
   * commands like CHECK TABLE, though..
375
 
   *
376
 
   * @param Pointer to the Session which issued the statement
377
 
   * @param Query string
378
 
   */
379
 
  void rawStatement(Session *in_session, const std::string &query);
380
 
  /**
381
 
   * Returns the timestamp of the last Transaction which was sent to 
382
 
   * an applier.
 
151
  /** Returns the timestamp of the last Transaction which was sent to an
 
152
   * applier.
383
153
   */
384
154
  uint64_t getLastAppliedTimestamp() const;
385
155
};