~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to drizzled/transaction_services.h

  • Committer: Padraig O'Sullivan
  • Date: 2010-04-17 01:38:47 UTC
  • mfrom: (1237.9.238 bad-staging)
  • Revision ID: osullivan.padraig@gmail.com-20100417013847-ibjioqsfbmf5yg4g
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#ifndef DRIZZLED_TRANSACTION_SERVICES_H
26
26
#define DRIZZLED_TRANSACTION_SERVICES_H
27
27
 
 
28
#include "drizzled/atomics.h"
 
29
#include "drizzled/message/transaction.pb.h"
 
30
 
28
31
namespace drizzled
29
32
{
30
33
 
46
49
class TransactionServices
47
50
{
48
51
public:
 
52
  static const size_t DEFAULT_RECORD_SIZE= 100;
 
53
  typedef uint64_t TransactionId;
49
54
  /**
50
55
   * Constructor
51
56
   */
52
 
  TransactionServices() {}
 
57
  TransactionServices()
 
58
  {
 
59
    /**
 
60
     * @todo set transaction ID to the last one from an applier...
 
61
     */
 
62
    current_transaction_id= 0;
 
63
  }
53
64
 
54
65
  /**
55
66
   * Singleton method
60
71
    static TransactionServices transaction_services;
61
72
    return transaction_services;
62
73
  }
 
74
 
 
75
  /**
 
76
   * Returns true if the transaction manager should construct
 
77
   * Transaction and Statement messages, false otherwise.
 
78
   */
 
79
  bool shouldConstructMessages();
 
80
  /**
 
81
   * Method which returns the active Transaction message
 
82
   * for the supplied Session.  If one is not found, a new Transaction
 
83
   * message is allocated, initialized, and returned.
 
84
   *
 
85
   * @param The session processing the transaction
 
86
   */
 
87
  message::Transaction *getActiveTransactionMessage(Session *in_session);
 
88
  /** 
 
89
   * Method which attaches a transaction context
 
90
   * the supplied transaction based on the supplied Session's
 
91
   * transaction information.  This method also ensure the
 
92
   * transaction message is attached properly to the Session object
 
93
   *
 
94
   * @param The transaction message to initialize
 
95
   * @param The Session processing this transaction
 
96
   */
 
97
  void initTransactionMessage(message::Transaction &in_transaction, Session *in_session);
 
98
  /** 
 
99
   * Helper method which finalizes data members for the 
 
100
   * supplied transaction's context.
 
101
   *
 
102
   * @param The transaction message to finalize 
 
103
   * @param The Session processing this transaction
 
104
   */
 
105
  void finalizeTransactionMessage(message::Transaction &in_transaction, Session *in_session);
 
106
  /**
 
107
   * Helper method which deletes transaction memory and
 
108
   * unsets Session's transaction and statement messages.
 
109
   */
 
110
  void cleanupTransactionMessage(message::Transaction *in_transaction,
 
111
                                 Session *in_session);
 
112
  /**
 
113
   * Helper method which initializes a Statement message
 
114
   *
 
115
   * @param The statement to initialize
 
116
   * @param The type of the statement
 
117
   * @param The session processing this statement
 
118
   */
 
119
  void initStatementMessage(message::Statement &statement,
 
120
                            message::Statement::Type in_type,
 
121
                            Session *in_session);
 
122
  /**
 
123
   * Finalizes a Statement message and sets the Session's statement
 
124
   * message to NULL.
 
125
   *
 
126
   * @param The statement to initialize
 
127
   * @param The session processing this statement
 
128
   */
 
129
  void finalizeStatementMessage(message::Statement &statement,
 
130
                                Session *in_session);
 
131
  /** Helper method which returns an initialized Statement message for methods
 
132
   * doing insertion of data.
 
133
   *
 
134
   * @param[in] Pointer to the Session doing the processing
 
135
   * @param[in] Pointer to the Table object being inserted into
 
136
   */
 
137
  message::Statement &getInsertStatement(Session *in_session,
 
138
                                         Table *in_table);
 
139
 
 
140
  /**
 
141
   * Helper method which initializes the header message for
 
142
   * insert operations.
 
143
   *
 
144
   * @param[inout] Statement message container to modify
 
145
   * @param[in] Pointer to the Session doing the processing
 
146
   * @param[in] Pointer to the Table being inserted into
 
147
   */
 
148
  void setInsertHeader(message::Statement &statement,
 
149
                       Session *in_session,
 
150
                       Table *in_table);
 
151
  /**
 
152
   * Helper method which returns an initialized Statement
 
153
   * message for methods doing updates of data.
 
154
   *
 
155
   * @param[in] Pointer to the Session doing the processing
 
156
   * @param[in] Pointer to the Table object being updated
 
157
   * @param[in] Pointer to the old data in the record
 
158
   * @param[in] Pointer to the new data in the record
 
159
   */
 
160
  message::Statement &getUpdateStatement(Session *in_session,
 
161
                                         Table *in_table,
 
162
                                         const unsigned char *old_record, 
 
163
                                         const unsigned char *new_record);
 
164
  /**
 
165
   * Helper method which initializes the header message for
 
166
   * update operations.
 
167
   *
 
168
   * @param[inout] Statement message container to modify
 
169
   * @param[in] Pointer to the Session doing the processing
 
170
   * @param[in] Pointer to the Table being updated
 
171
   * @param[in] Pointer to the old data in the record
 
172
   * @param[in] Pointer to the new data in the record
 
173
   */
 
174
  void setUpdateHeader(message::Statement &statement,
 
175
                       Session *in_session,
 
176
                       Table *in_table,
 
177
                       const unsigned char *old_record, 
 
178
                       const unsigned char *new_record);
 
179
  /**
 
180
   * Helper method which returns an initialized Statement
 
181
   * message for methods doing deletion of data.
 
182
   *
 
183
   * @param[in] Pointer to the Session doing the processing
 
184
   * @param[in] Pointer to the Table object being deleted from
 
185
   */
 
186
  message::Statement &getDeleteStatement(Session *in_session,
 
187
                                         Table *in_table);
 
188
 
 
189
  /**
 
190
   * Helper method which initializes the header message for
 
191
   * insert operations.
 
192
   *
 
193
   * @param[inout] Statement message container to modify
 
194
   * @param[in] Pointer to the Session doing the processing
 
195
   * @param[in] Pointer to the Table being deleted from
 
196
   */
 
197
  void setDeleteHeader(message::Statement &statement,
 
198
                       Session *in_session,
 
199
                       Table *in_table);
 
200
  /** 
 
201
   * Commits a normal transaction (see above) and pushes the transaction
 
202
   * message out to the replicators.
 
203
   *
 
204
   * @param Pointer to the Session committing the transaction
 
205
   */
 
206
  int commitTransactionMessage(Session *in_session);
 
207
  /** 
 
208
   * Marks the current active transaction message as being rolled back and
 
209
   * pushes the transaction message out to replicators.
 
210
   *
 
211
   * @param Pointer to the Session committing the transaction
 
212
   */
 
213
  void rollbackTransactionMessage(Session *in_session);
 
214
  /**
 
215
   * Creates a new InsertRecord GPB message and pushes it to
 
216
   * replicators.
 
217
   *
 
218
   * @param Pointer to the Session which has inserted a record
 
219
   * @param Pointer to the Table containing insert information
 
220
   *
 
221
   * Grr, returning "true" here on error because of the cursor
 
222
   * reversed bool return crap...fix that.
 
223
   */
 
224
  bool insertRecord(Session *in_session, Table *in_table);
 
225
  /**
 
226
   * Creates a new UpdateRecord GPB message and pushes it to
 
227
   * replicators.
 
228
   *
 
229
   * @param Pointer to the Session which has updated a record
 
230
   * @param Pointer to the Table containing update information
 
231
   * @param Pointer to the raw bytes representing the old record/row
 
232
   * @param Pointer to the raw bytes representing the new record/row 
 
233
   */
 
234
  void updateRecord(Session *in_session, 
 
235
                    Table *in_table, 
 
236
                    const unsigned char *old_record, 
 
237
                    const unsigned char *new_record);
 
238
  /**
 
239
   * Creates a new DeleteRecord GPB message and pushes it to
 
240
   * replicators.
 
241
   *
 
242
   * @param Pointer to the Session which has deleted a record
 
243
   * @param Pointer to the Table containing delete information
 
244
   */
 
245
  void deleteRecord(Session *in_session, Table *in_table);
 
246
  /**
 
247
   * Creates a CreateSchema Statement GPB message and adds it
 
248
   * to the Session's active Transaction GPB message for pushing
 
249
   * out to the replicator streams.
 
250
   *
 
251
   * @param[in] Pointer to the Session which issued the statement
 
252
   * @param[in] message::Schema message describing new schema
 
253
   */
 
254
  void createSchema(Session *in_session, const message::Schema &schema);
 
255
  /**
 
256
   * Creates a DropSchema Statement GPB message and adds it
 
257
   * to the Session's active Transaction GPB message for pushing
 
258
   * out to the replicator streams.
 
259
   *
 
260
   * @param[in] Pointer to the Session which issued the statement
 
261
   * @param[in] message::Schema message describing new schema
 
262
   */
 
263
  void dropSchema(Session *in_session, const std::string &schema_name);
 
264
  /**
 
265
   * Creates a CreateTable Statement GPB message and adds it
 
266
   * to the Session's active Transaction GPB message for pushing
 
267
   * out to the replicator streams.
 
268
   *
 
269
   * @param[in] Pointer to the Session which issued the statement
 
270
   * @param[in] message::Table message describing new schema
 
271
   */
 
272
  void createTable(Session *in_session, const message::Table &table);
 
273
  /**
 
274
   * Creates a DropTable Statement GPB message and adds it
 
275
   * to the Session's active Transaction GPB message for pushing
 
276
   * out to the replicator streams.
 
277
   *
 
278
   * @param[in] Pointer to the Session which issued the statement
 
279
   * @param[in] The schema of the table being dropped
 
280
   * @param[in] The table name of the table being dropped
 
281
   * @param[in] Did the user specify an IF EXISTS clause?
 
282
   */
 
283
  void dropTable(Session *in_session,
 
284
                     const std::string &schema_name,
 
285
                     const std::string &table_name,
 
286
                     bool if_exists);
 
287
  /**
 
288
   * Creates a TruncateTable Statement GPB message and adds it
 
289
   * to the Session's active Transaction GPB message for pushing
 
290
   * out to the replicator streams.
 
291
   *
 
292
   * @param[in] Pointer to the Session which issued the statement
 
293
   * @param[in] The Table being truncated
 
294
   */
 
295
  void truncateTable(Session *in_session, Table *in_table);
 
296
  /**
 
297
   * Creates a new RawSql GPB message and pushes it to 
 
298
   * replicators.
 
299
   *
 
300
   * @TODO With a real data dictionary, this really shouldn't
 
301
   * be needed.  CREATE TABLE would map to insertRecord call
 
302
   * on the I_S, etc.  Not sure what to do with administrative
 
303
   * commands like CHECK TABLE, though..
 
304
   *
 
305
   * @param Pointer to the Session which issued the statement
 
306
   * @param Query string
 
307
   */
 
308
  void rawStatement(Session *in_session, const std::string &query);
63
309
  /* transactions: interface to plugin::StorageEngine functions */
64
 
  int ha_commit_one_phase(Session *session, bool all);
65
 
  int ha_rollback_trans(Session *session, bool all);
 
310
  int commitPhaseOne(Session *session, bool all);
 
311
  int rollbackTransaction(Session *session, bool all);
66
312
 
67
313
  /* transactions: these functions never call plugin::StorageEngine functions directly */
68
 
  int ha_commit_trans(Session *session, bool all);
69
 
  int ha_autocommit_or_rollback(Session *session, int error);
 
314
  int commitTransaction(Session *session, bool all);
 
315
  int autocommitOrRollback(Session *session, int error);
70
316
 
71
317
  /* savepoints */
72
 
  int ha_rollback_to_savepoint(Session *session, NamedSavepoint &sv);
73
 
  int ha_savepoint(Session *session, NamedSavepoint &sv);
74
 
  int ha_release_savepoint(Session *session, NamedSavepoint &sv);
75
 
  bool mysql_xa_recover(Session *session);
 
318
  int rollbackToSavepoint(Session *session, NamedSavepoint &sv);
 
319
  int setSavepoint(Session *session, NamedSavepoint &sv);
 
320
  int releaseSavepoint(Session *session, NamedSavepoint &sv);
76
321
 
77
322
  /**
78
323
   * Marks a storage engine as participating in a statement
151
396
                                      plugin::MonitoredInTransaction *monitored,
152
397
                                      plugin::TransactionalStorageEngine *engine,
153
398
                                      plugin::XaResourceManager *resource_manager);
 
399
  TransactionId getNextTransactionId()
 
400
  {
 
401
    return current_transaction_id.increment();
 
402
  }
 
403
  TransactionId getCurrentTransactionId()
 
404
  {
 
405
    return current_transaction_id;
 
406
  }
 
407
  /**
 
408
   * DEBUG ONLY.  See plugin::TransactionLog::truncate()
 
409
   */
 
410
  void resetTransactionId()
 
411
  {
 
412
    current_transaction_id= 0;
 
413
  }
 
414
private:
 
415
  atomic<TransactionId> current_transaction_id;
154
416
};
155
417
 
156
418
} /* namespace drizzled */