~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.h

Updates to tests (now moved into plugins).

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "drizzled/sql_string.h"
31
31
#include "drizzled/table_identifier.h"
32
32
#include "drizzled/cached_directory.h"
33
 
#include "drizzled/plugin/monitored_in_transaction.h"
34
 
 
35
 
#include "drizzled/hash.h"
36
33
 
37
34
#include <bitset>
38
35
#include <string>
44
41
 
45
42
class TableList;
46
43
class Session;
 
44
class XID;
47
45
class Cursor;
48
46
typedef struct st_hash HASH;
49
47
 
82
80
  HTON_BIT_NO_PREFIX_CHAR_KEYS,
83
81
  HTON_BIT_HAS_CHECKSUM,
84
82
  HTON_BIT_SKIP_STORE_LOCK,
85
 
  HTON_BIT_SCHEMA_DICTIONARY,
86
83
  HTON_BIT_SIZE
87
84
};
88
85
 
114
111
static const std::bitset<HTON_BIT_SIZE> HTON_NO_PREFIX_CHAR_KEYS(1 << HTON_BIT_NO_PREFIX_CHAR_KEYS);
115
112
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_CHECKSUM(1 << HTON_BIT_HAS_CHECKSUM);
116
113
static const std::bitset<HTON_BIT_SIZE> HTON_SKIP_STORE_LOCK(1 << HTON_BIT_SKIP_STORE_LOCK);
117
 
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_SCHEMA_DICTIONARY(1 << HTON_BIT_SCHEMA_DICTIONARY);
118
114
 
119
115
 
120
116
class Table;
123
119
namespace plugin
124
120
{
125
121
 
126
 
typedef hash_map<std::string, StorageEngine *> EngineMap;
127
 
typedef std::vector<StorageEngine *> EngineVector;
128
 
 
129
 
typedef std::set<std::string> TableNameList;
130
 
typedef std::set<std::string> SchemaNameList;
131
 
 
132
122
extern const std::string UNKNOWN_STRING;
133
123
extern const std::string DEFAULT_DEFINITION_FILE_EXT;
134
124
 
140
130
  usually StorageEngine instance is defined statically in ha_xxx.cc as
141
131
 
142
132
  static StorageEngine { ... } xxx_engine;
 
133
 
 
134
  savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
143
135
*/
144
 
class StorageEngine : public Plugin,
145
 
                      public MonitoredInTransaction
 
136
class StorageEngine : public Plugin
146
137
{
147
138
public:
148
139
  typedef uint64_t Table_flags;
149
140
 
150
141
private:
 
142
 
 
143
  /*
 
144
    Name used for storage engine.
 
145
  */
 
146
  const bool two_phase_commit;
 
147
  bool enabled;
 
148
 
151
149
  const std::bitset<HTON_BIT_SIZE> flags; /* global Cursor flags */
152
150
 
153
 
  virtual void setTransactionReadWrite(Session& session);
154
 
 
155
 
  /*
156
 
   * Indicates to a storage engine the start of a
157
 
   * new SQL statement.
158
 
   */
159
 
  virtual void doStartStatement(Session *session)
160
 
  {
161
 
    (void) session;
162
 
  }
163
 
 
164
 
  /*
165
 
   * Indicates to a storage engine the end of
166
 
   * the current SQL statement in the supplied
167
 
   * Session.
168
 
   */
169
 
  virtual void doEndStatement(Session *session)
170
 
  {
171
 
    (void) session;
172
 
  }
 
151
  void setTransactionReadWrite(Session& session);
173
152
 
174
153
protected:
175
154
  std::string table_definition_ext;
204
183
  ProtoCache proto_cache;
205
184
  pthread_mutex_t proto_cache_mutex;
206
185
 
 
186
  /**
 
187
   * Implementing classes should override these to provide savepoint
 
188
   * functionality.
 
189
   */
 
190
  virtual int savepoint_set_hook(Session *, NamedSavepoint &) { return 0; }
 
191
 
 
192
  virtual int savepoint_rollback_hook(Session *, NamedSavepoint &) { return 0; }
 
193
 
 
194
  virtual int savepoint_release_hook(Session *, NamedSavepoint &) { return 0; }
 
195
 
207
196
public:
208
197
 
209
198
  StorageEngine(const std::string name_arg,
210
 
                const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
 
199
                const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS,
 
200
                bool support_2pc= false);
211
201
 
212
202
  virtual ~StorageEngine();
213
203
 
236
226
public:
237
227
  virtual void print_error(int error, myf errflag, Table& table);
238
228
 
 
229
  /*
 
230
    each storage engine has it's own memory area (actually a pointer)
 
231
    in the session, for storing per-connection information.
 
232
    It is accessed as
 
233
 
 
234
      session->ha_data[xxx_engine.slot]
 
235
 
 
236
   slot number is initialized by MySQL after xxx_init() is called.
 
237
  */
 
238
  uint32_t slot;
 
239
 
 
240
  inline uint32_t getSlot (void) { return slot; }
 
241
  inline uint32_t getSlot (void) const { return slot; }
 
242
  inline void setSlot (uint32_t value) { slot= value; }
 
243
 
 
244
  bool has_2pc()
 
245
  {
 
246
    return two_phase_commit;
 
247
  }
 
248
 
 
249
 
 
250
  bool is_enabled() const
 
251
  {
 
252
    return enabled;
 
253
  }
 
254
 
239
255
  bool is_user_selectable() const
240
256
  {
241
257
    return not flags.test(HTON_BIT_NOT_USER_SELECTABLE);
248
264
 
249
265
  // @todo match check_flag interface
250
266
  virtual uint32_t index_flags(enum  ha_key_alg) const { return 0; }
251
 
  virtual void startStatement(Session *session)
252
 
  {
253
 
    doStartStatement(session);
254
 
  }
255
 
  virtual void endStatement(Session *session)
256
 
  {
257
 
    doEndStatement(session);
258
 
  }
 
267
 
 
268
 
 
269
  void enable() { enabled= true; }
 
270
  void disable() { enabled= false; }
259
271
 
260
272
  /*
261
 
   * Called during Session::cleanup() for all engines
262
 
   */
 
273
    StorageEngine methods:
 
274
 
 
275
    close_connection is only called if
 
276
    session->ha_data[xxx_engine.slot] is non-zero, so even if you don't need
 
277
    this storage area - set it to something, so that MySQL would know
 
278
    this storage engine was accessed in this connection
 
279
  */
263
280
  virtual int close_connection(Session  *)
264
281
  {
265
282
    return 0;
266
283
  }
 
284
  /*
 
285
    'all' is true if it's a real commit, that makes persistent changes
 
286
    'all' is false if it's not in fact a commit but an end of the
 
287
    statement that is part of the transaction.
 
288
    NOTE 'all' is also false in auto-commit mode where 'end of statement'
 
289
    and 'real commit' mean the same event.
 
290
  */
 
291
  virtual int  commit(Session *, bool)
 
292
  {
 
293
    return 0;
 
294
  }
 
295
 
 
296
  virtual int  rollback(Session *, bool)
 
297
  {
 
298
    return 0;
 
299
  }
 
300
 
 
301
  /*
 
302
    The void * points to an uninitialized storage area of requested size
 
303
    (see savepoint_offset description)
 
304
  */
 
305
  int savepoint_set(Session *session, NamedSavepoint &sp)
 
306
  {
 
307
    return savepoint_set_hook(session, sp);
 
308
  }
 
309
 
 
310
  /*
 
311
    The void * points to a storage area, that was earlier passed
 
312
    to the savepoint_set call
 
313
  */
 
314
  int savepoint_rollback(Session *session, NamedSavepoint &sp)
 
315
  {
 
316
     return savepoint_rollback_hook(session, sp);
 
317
  }
 
318
 
 
319
  int savepoint_release(Session *session, NamedSavepoint &sp)
 
320
  {
 
321
    return savepoint_release_hook(session, sp);
 
322
  }
 
323
 
 
324
  virtual int  prepare(Session *, bool) { return 0; }
 
325
  virtual int  recover(XID *, uint32_t) { return 0; }
 
326
  virtual int  commit_by_xid(XID *) { return 0; }
 
327
  virtual int  rollback_by_xid(XID *) { return 0; }
267
328
  virtual Cursor *create(TableShare &, memory::Root *)= 0;
268
329
  /* args: path */
 
330
  virtual void drop_database(char*) { }
 
331
  virtual int start_consistent_snapshot(Session *) { return 0; }
269
332
  virtual bool flush_logs() { return false; }
270
333
  virtual bool show_status(Session *, stat_print_fn *, enum ha_stat_type)
271
334
  {
272
335
    return false;
273
336
  }
274
337
 
 
338
  virtual int release_temporary_latches(Session *) { return false; }
 
339
 
275
340
  /**
276
341
    If frm_error() is called then we will use this to find out what file
277
342
    extentions exist for the storage engine. This is also used by the default
294
359
  virtual int doRenameTable(Session* session,
295
360
                            const char *from, const char *to);
296
361
 
 
362
 
297
363
public:
298
364
 
299
365
  int renameTable(Session *session, const char *from, const char *to) 
303
369
    return doRenameTable(session, from, to);
304
370
  }
305
371
 
306
 
  // @todo move these to protected
 
372
  // TODO: move these to protected
307
373
  virtual void doGetTableNames(CachedDirectory &directory,
308
374
                               std::string& db_name,
309
 
                               TableNameList &set_of_names);
 
375
                               std::set<std::string>& set_of_names);
310
376
  virtual int doDropTable(Session& session,
311
 
                          const std::string &table_path)= 0;
 
377
                          const std::string table_path)= 0;
312
378
 
313
379
  const char *checkLowercaseNames(const char *path, char *tmp_path);
314
380
 
318
384
 
319
385
  static int getTableDefinition(Session& session,
320
386
                                TableIdentifier &identifier,
321
 
                                message::Table *table_proto= NULL,
322
 
                                bool include_temporary_tables= true);
 
387
                                message::Table *table_proto= NULL);
323
388
  static int getTableDefinition(Session& session,
324
389
                                const char* path,
325
390
                                const char *db,
326
391
                                const char *table_name,
327
392
                                const bool is_tmp,
328
 
                                message::Table *table_proto= NULL,
329
 
                                bool include_temporary_tables= true);
330
 
  static bool doesTableExist(Session& session,
331
 
                             TableIdentifier &identifier,
332
 
                             bool include_temporary_tables= true);
 
393
                                message::Table *table_proto= NULL);
333
394
 
334
395
  static plugin::StorageEngine *findByName(std::string find_str);
335
396
  static plugin::StorageEngine *findByName(Session& session,
336
397
                                           std::string find_str);
337
398
  static void closeConnection(Session* session);
338
399
  static void dropDatabase(char* path);
 
400
  static int commitOrRollbackByXID(XID *xid, bool commit);
 
401
  static int releaseTemporaryLatches(Session *session);
339
402
  static bool flushLogs(plugin::StorageEngine *db_type);
 
403
  static int recover(HASH *commit_list);
 
404
  static int startConsistentSnapshot(Session *session);
340
405
  static int dropTable(Session& session,
341
 
                       TableIdentifier &identifier);
342
 
  static void getTableNames(const std::string& db_name, TableNameList &set_of_names);
343
 
 
344
 
  // Check to see if any SE objects to creation.
345
 
  static bool canCreateTable(drizzled::TableIdentifier &identifier);
346
 
  virtual bool doCanCreateTable(const drizzled::TableIdentifier &identifier)
347
 
  { (void)identifier;  return true; }
 
406
                       TableIdentifier &identifier,
 
407
                       bool generate_warning);
 
408
  static void getTableNames(const std::string& db_name, std::set<std::string> &set_of_names);
348
409
 
349
410
  // @note All schema methods defined here
350
 
  static void getSchemaNames(SchemaNameList &set_of_names);
 
411
  static void getSchemaNames(std::set<std::string>& set_of_names);
351
412
  static bool getSchemaDefinition(const std::string &schema_name, message::Schema &proto);
352
 
  static bool doesSchemaExist(const std::string &schema_name);
353
 
  static const CHARSET_INFO *getSchemaCollation(const std::string &schema_name);
354
 
  static bool createSchema(const drizzled::message::Schema &schema_message);
355
 
  static bool dropSchema(const std::string &schema_name);
356
 
  static bool alterSchema(const drizzled::message::Schema &schema_message);
357
 
 
358
 
  // @note make private/protected
359
 
  virtual void doGetSchemaNames(SchemaNameList &set_of_names)
360
 
  { (void)set_of_names; }
361
 
 
362
 
  virtual bool doGetSchemaDefinition(const std::string &schema_name, drizzled::message::Schema &proto)
363
 
  { 
364
 
    (void)schema_name;
365
 
    (void)proto; 
366
 
 
367
 
    return false; 
368
 
  }
369
 
 
370
 
  virtual bool doCreateSchema(const drizzled::message::Schema &schema_message)
371
 
  { (void)schema_message; return false; }
372
 
 
373
 
  virtual bool doAlterSchema(const drizzled::message::Schema &schema_message)
374
 
  { (void)schema_message; return false; }
375
 
 
376
 
  virtual bool doDropSchema(const std::string &schema_name)
377
 
  { (void)schema_name; return false; }
 
413
 
378
414
 
379
415
  static inline const std::string &resolveName(const StorageEngine *engine)
380
416
  {
384
420
  static int createTable(Session& session,
385
421
                         TableIdentifier &identifier,
386
422
                         bool update_create_info,
387
 
                         message::Table& table_proto);
 
423
                         message::Table& table_proto,
 
424
                         bool used= true);
388
425
 
389
426
  static void removeLostTemporaryTables(Session &session, const char *directory);
390
427
 
413
450
  static int deleteDefinitionFromPath(TableIdentifier &identifier);
414
451
  static int renameDefinitionFromPath(TableIdentifier &dest, TableIdentifier &src);
415
452
  static int writeDefinitionFromPath(TableIdentifier &identifier, message::Table &proto);
416
 
 
417
 
public:
418
 
  /* 
419
 
   * The below are simple virtual overrides for the plugin::MonitoredInTransaction
420
 
   * interface.
421
 
   */
422
 
  virtual bool participatesInSqlTransaction() const
423
 
  {
424
 
    return false; /* plugin::StorageEngine is non-transactional in terms of SQL */
425
 
  }
426
 
  virtual bool participatesInXaTransaction() const
427
 
  {
428
 
    return false; /* plugin::StorageEngine is non-transactional in terms of XA */
429
 
  }
430
 
  virtual bool alwaysRegisterForXaTransaction() const
431
 
  {
432
 
    return false;
433
 
  }
434
453
};
435
454
 
436
455
} /* namespace plugin */