~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.h

  • Committer: Brian Aker
  • Date: 2010-02-14 01:56:51 UTC
  • mto: (1273.16.5 fix_is)
  • mto: This revision was merged to the branch mainline in revision 1300.
  • Revision ID: brian@gaz-20100214015651-ror9j0xu7dccz0ct
Two fixes for "make dist"

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <drizzled/definitions.h>
25
25
#include <drizzled/plugin.h>
26
26
#include <drizzled/handler_structs.h>
27
 
#include <drizzled/message.h>
28
 
#include <drizzled/message/cache.h>
 
27
#include <drizzled/message/schema.pb.h>
 
28
#include <drizzled/message/table.pb.h>
29
29
#include "drizzled/plugin/plugin.h"
30
30
#include "drizzled/sql_string.h"
31
 
#include "drizzled/identifier.h"
 
31
#include "drizzled/table_identifier.h"
32
32
#include "drizzled/cached_directory.h"
33
 
#include "drizzled/plugin/monitored_in_transaction.h"
34
33
 
35
34
#include <bitset>
36
35
#include <string>
42
41
 
43
42
class TableList;
44
43
class Session;
 
44
class XID;
45
45
class Cursor;
46
46
typedef struct st_hash HASH;
47
47
 
58
58
  HTON_BIT_NOT_USER_SELECTABLE,
59
59
  HTON_BIT_TEMPORARY_NOT_SUPPORTED,   // Having temporary tables not supported
60
60
  HTON_BIT_TEMPORARY_ONLY,
 
61
  HTON_BIT_FILE_BASED, // use for check_lowercase_names
 
62
  HTON_BIT_HAS_DATA_DICTIONARY,
61
63
  HTON_BIT_DOES_TRANSACTIONS,
62
64
  HTON_BIT_STATS_RECORDS_IS_EXACT,
63
65
  HTON_BIT_NULL_IN_KEY,
64
66
  HTON_BIT_CAN_INDEX_BLOBS,
 
67
  HTON_BIT_PRIMARY_KEY_REQUIRED_FOR_POSITION,
65
68
  HTON_BIT_PRIMARY_KEY_IN_READ_INDEX,
66
69
  HTON_BIT_PARTIAL_COLUMN_READ,
67
70
  HTON_BIT_TABLE_SCAN_ON_INDEX,
77
80
  HTON_BIT_NO_PREFIX_CHAR_KEYS,
78
81
  HTON_BIT_HAS_CHECKSUM,
79
82
  HTON_BIT_SKIP_STORE_LOCK,
80
 
  HTON_BIT_SCHEMA_DICTIONARY,
81
 
  HTON_BIT_FOREIGN_KEYS,
82
83
  HTON_BIT_SIZE
83
84
};
84
85
 
88
89
static const std::bitset<HTON_BIT_SIZE> HTON_NOT_USER_SELECTABLE(1 << HTON_BIT_NOT_USER_SELECTABLE);
89
90
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_NOT_SUPPORTED(1 << HTON_BIT_TEMPORARY_NOT_SUPPORTED);
90
91
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_ONLY(1 << HTON_BIT_TEMPORARY_ONLY);
 
92
static const std::bitset<HTON_BIT_SIZE> HTON_FILE_BASED(1 << HTON_BIT_FILE_BASED);
 
93
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_DATA_DICTIONARY(1 << HTON_BIT_HAS_DATA_DICTIONARY);
91
94
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_DOES_TRANSACTIONS(1 << HTON_BIT_DOES_TRANSACTIONS);
92
95
static const std::bitset<HTON_BIT_SIZE> HTON_STATS_RECORDS_IS_EXACT(1 << HTON_BIT_STATS_RECORDS_IS_EXACT);
93
96
static const std::bitset<HTON_BIT_SIZE> HTON_NULL_IN_KEY(1 << HTON_BIT_NULL_IN_KEY);
94
97
static const std::bitset<HTON_BIT_SIZE> HTON_CAN_INDEX_BLOBS(1 << HTON_BIT_CAN_INDEX_BLOBS);
 
98
static const std::bitset<HTON_BIT_SIZE> HTON_PRIMARY_KEY_REQUIRED_FOR_POSITION(1 << HTON_BIT_PRIMARY_KEY_REQUIRED_FOR_POSITION);
95
99
static const std::bitset<HTON_BIT_SIZE> HTON_PRIMARY_KEY_IN_READ_INDEX(1 << HTON_BIT_PRIMARY_KEY_IN_READ_INDEX);
96
100
static const std::bitset<HTON_BIT_SIZE> HTON_PARTIAL_COLUMN_READ(1 << HTON_BIT_PARTIAL_COLUMN_READ);
97
101
static const std::bitset<HTON_BIT_SIZE> HTON_TABLE_SCAN_ON_INDEX(1 << HTON_BIT_TABLE_SCAN_ON_INDEX);
107
111
static const std::bitset<HTON_BIT_SIZE> HTON_NO_PREFIX_CHAR_KEYS(1 << HTON_BIT_NO_PREFIX_CHAR_KEYS);
108
112
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_CHECKSUM(1 << HTON_BIT_HAS_CHECKSUM);
109
113
static const std::bitset<HTON_BIT_SIZE> HTON_SKIP_STORE_LOCK(1 << HTON_BIT_SKIP_STORE_LOCK);
110
 
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_SCHEMA_DICTIONARY(1 << HTON_BIT_SCHEMA_DICTIONARY);
111
 
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_FOREIGN_KEYS(1 << HTON_BIT_FOREIGN_KEYS);
112
114
 
113
115
 
114
116
class Table;
117
119
namespace plugin
118
120
{
119
121
 
120
 
typedef std::vector<StorageEngine *> EngineVector;
121
 
 
122
 
typedef std::set<std::string> TableNameList;
123
 
 
124
122
extern const std::string UNKNOWN_STRING;
125
123
extern const std::string DEFAULT_DEFINITION_FILE_EXT;
126
124
 
132
130
  usually StorageEngine instance is defined statically in ha_xxx.cc as
133
131
 
134
132
  static StorageEngine { ... } xxx_engine;
 
133
 
 
134
  savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
135
135
*/
136
 
class StorageEngine : public Plugin,
137
 
                      public MonitoredInTransaction
 
136
class StorageEngine : public Plugin
138
137
{
139
138
public:
140
139
  typedef uint64_t Table_flags;
141
140
 
142
141
private:
 
142
 
 
143
  /*
 
144
    Name used for storage engine.
 
145
  */
 
146
  const bool two_phase_commit;
 
147
  bool enabled;
 
148
 
143
149
  const std::bitset<HTON_BIT_SIZE> flags; /* global Cursor flags */
144
150
 
145
 
  static EngineVector &getSchemaEngines();
146
 
 
147
 
  virtual void setTransactionReadWrite(Session& session);
148
 
 
149
 
  /*
150
 
   * Indicates to a storage engine the start of a
151
 
   * new SQL statement.
152
 
   */
153
 
  virtual void doStartStatement(Session *session)
154
 
  {
155
 
    (void) session;
156
 
  }
157
 
 
158
 
  /*
159
 
   * Indicates to a storage engine the end of
160
 
   * the current SQL statement in the supplied
161
 
   * Session.
162
 
   */
163
 
  virtual void doEndStatement(Session *session)
164
 
  {
165
 
    (void) session;
166
 
  }
 
151
  void setTransactionReadWrite(Session& session);
167
152
 
168
153
protected:
169
154
  std::string table_definition_ext;
198
183
  ProtoCache proto_cache;
199
184
  pthread_mutex_t proto_cache_mutex;
200
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
 
201
196
public:
202
197
 
203
198
  StorageEngine(const std::string name_arg,
204
 
                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);
205
201
 
206
202
  virtual ~StorageEngine();
207
203
 
208
 
  virtual int doGetTableDefinition(Session &session,
209
 
                                   const drizzled::TableIdentifier &identifier,
210
 
                                   message::Table &table_message)
 
204
  virtual int doGetTableDefinition(Session& session,
 
205
                                   const char *path,
 
206
                                   const char *db,
 
207
                                   const char *table_name,
 
208
                                   const bool is_tmp,
 
209
                                   message::Table *table_proto)
211
210
  {
212
211
    (void)session;
213
 
    (void)identifier;
214
 
    (void)table_message;
 
212
    (void)path;
 
213
    (void)db;
 
214
    (void)table_name;
 
215
    (void)is_tmp;
 
216
    (void)table_proto;
215
217
 
216
218
    return ENOENT;
217
219
  }
224
226
public:
225
227
  virtual void print_error(int error, myf errflag, Table& table);
226
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
 
227
255
  bool is_user_selectable() const
228
256
  {
229
257
    return not flags.test(HTON_BIT_NOT_USER_SELECTABLE);
236
264
 
237
265
  // @todo match check_flag interface
238
266
  virtual uint32_t index_flags(enum  ha_key_alg) const { return 0; }
239
 
  virtual void startStatement(Session *session)
240
 
  {
241
 
    doStartStatement(session);
242
 
  }
243
 
  virtual void endStatement(Session *session)
244
 
  {
245
 
    doEndStatement(session);
246
 
  }
 
267
 
 
268
 
 
269
  void enable() { enabled= true; }
 
270
  void disable() { enabled= false; }
247
271
 
248
272
  /*
249
 
   * Called during Session::cleanup() for all engines
250
 
   */
 
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
  */
251
280
  virtual int close_connection(Session  *)
252
281
  {
253
282
    return 0;
254
283
  }
255
 
  virtual Cursor *create(Table &)= 0;
 
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; }
 
328
  virtual Cursor *create(TableShare &, memory::Root *)= 0;
256
329
  /* args: path */
 
330
  virtual void drop_database(char*) { }
 
331
  virtual int start_consistent_snapshot(Session *) { return 0; }
257
332
  virtual bool flush_logs() { return false; }
258
333
  virtual bool show_status(Session *, stat_print_fn *, enum ha_stat_type)
259
334
  {
260
335
    return false;
261
336
  }
262
337
 
 
338
  virtual int release_temporary_latches(Session *) { return false; }
 
339
 
263
340
  /**
264
341
    If frm_error() is called then we will use this to find out what file
265
342
    extentions exist for the storage engine. This is also used by the default
274
351
  virtual const char **bas_ext() const =0;
275
352
 
276
353
protected:
277
 
  virtual int doCreateTable(Session &session,
278
 
                            Table &table_arg,
279
 
                            const drizzled::TableIdentifier &identifier,
280
 
                            message::Table &message)= 0;
281
 
 
282
 
  virtual int doRenameTable(Session &session,
283
 
                            const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to)= 0;
 
354
  virtual int doCreateTable(Session *session,
 
355
                            const char *table_name,
 
356
                            Table& table_arg,
 
357
                            message::Table& proto)= 0;
 
358
 
 
359
  virtual int doRenameTable(Session* session,
 
360
                            const char *from, const char *to);
 
361
 
284
362
 
285
363
public:
286
364
 
287
 
  int renameTable(Session &session, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to);
288
 
 
289
 
  virtual void doGetTableIdentifiers(CachedDirectory &directory,
290
 
                                     const drizzled::SchemaIdentifier &schema_identifier,
291
 
                                     TableIdentifier::vector &set_of_identifiers)= 0;
292
 
 
293
 
  virtual int doDropTable(Session &session,
294
 
                          const drizzled::TableIdentifier &identifier)= 0;
 
365
  int renameTable(Session *session, const char *from, const char *to) 
 
366
  {
 
367
    setTransactionReadWrite(*session);
 
368
 
 
369
    return doRenameTable(session, from, to);
 
370
  }
 
371
 
 
372
  // TODO: move these to protected
 
373
  virtual void doGetTableNames(CachedDirectory &directory,
 
374
                               std::string& db_name,
 
375
                               std::set<std::string>& set_of_names);
 
376
  virtual int doDropTable(Session& session,
 
377
                          const std::string table_path)= 0;
 
378
 
 
379
  const char *checkLowercaseNames(const char *path, char *tmp_path);
295
380
 
296
381
  /* Class Methods for operating on plugin */
297
382
  static bool addPlugin(plugin::StorageEngine *engine);
298
383
  static void removePlugin(plugin::StorageEngine *engine);
299
384
 
300
385
  static int getTableDefinition(Session& session,
301
 
                                const drizzled::TableIdentifier &identifier,
302
 
                                message::table::shared_ptr &table_proto,
303
 
                                bool include_temporary_tables= true);
304
 
  static bool doesTableExist(Session &session,
305
 
                             const drizzled::TableIdentifier &identifier,
306
 
                             bool include_temporary_tables= true);
307
 
 
308
 
  virtual bool doDoesTableExist(Session& session, const drizzled::TableIdentifier &identifier);
309
 
 
310
 
  static plugin::StorageEngine *findByName(const std::string &find_str);
311
 
  static plugin::StorageEngine *findByName(Session& session, const std::string &find_str);
312
 
 
 
386
                                TableIdentifier &identifier,
 
387
                                message::Table *table_proto= NULL);
 
388
  static int getTableDefinition(Session& session,
 
389
                                const char* path,
 
390
                                const char *db,
 
391
                                const char *table_name,
 
392
                                const bool is_tmp,
 
393
                                message::Table *table_proto= NULL);
 
394
 
 
395
  static plugin::StorageEngine *findByName(std::string find_str);
 
396
  static plugin::StorageEngine *findByName(Session& session,
 
397
                                           std::string find_str);
313
398
  static void closeConnection(Session* session);
314
399
  static void dropDatabase(char* path);
 
400
  static int commitOrRollbackByXID(XID *xid, bool commit);
 
401
  static int releaseTemporaryLatches(Session *session);
315
402
  static bool flushLogs(plugin::StorageEngine *db_type);
316
 
  static int dropTable(Session& session,
317
 
                       const drizzled::TableIdentifier &identifier);
318
 
  static int dropTable(Session& session,
319
 
                       StorageEngine &engine,
320
 
                       const drizzled::TableIdentifier &identifier);
321
 
  static void getIdentifiers(Session &session,
322
 
                             const SchemaIdentifier &schema_identifier,
323
 
                             TableIdentifier::vector &set_of_identifiers);
324
 
 
325
 
  // Check to see if any SE objects to creation.
326
 
  static bool canCreateTable(const drizzled::TableIdentifier &identifier);
327
 
  virtual bool doCanCreateTable(const drizzled::TableIdentifier &identifier)
328
 
  { (void)identifier;  return true; }
 
403
  static int recover(HASH *commit_list);
 
404
  static int startConsistentSnapshot(Session *session);
 
405
  static int dropTable(Session& session,
 
406
                       TableIdentifier &identifier,
 
407
                       bool generate_warning);
 
408
  static void getTableNames(const std::string& db_name, std::set<std::string> &set_of_names);
329
409
 
330
410
  // @note All schema methods defined here
331
 
  static void getIdentifiers(Session &session, SchemaIdentifier::vector &schemas);
332
 
  static bool getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::schema::shared_ptr &proto);
333
 
  static bool getSchemaDefinition(const drizzled::SchemaIdentifier &identifier, message::schema::shared_ptr &proto);
334
 
  static bool doesSchemaExist(const drizzled::SchemaIdentifier &identifier);
335
 
  static const CHARSET_INFO *getSchemaCollation(const drizzled::SchemaIdentifier &identifier);
336
 
  static bool createSchema(const drizzled::message::Schema &schema_message);
337
 
  static bool dropSchema(const drizzled::SchemaIdentifier &identifier);
338
 
  static bool alterSchema(const drizzled::message::Schema &schema_message);
339
 
 
340
 
  // @note make private/protected
341
 
  virtual void doGetSchemaIdentifiers(SchemaIdentifier::vector&)
342
 
  { }
343
 
 
344
 
  virtual bool doGetSchemaDefinition(const drizzled::SchemaIdentifier&, drizzled::message::schema::shared_ptr&)
345
 
  { 
346
 
    return false; 
347
 
  }
348
 
 
349
 
  virtual bool doCreateSchema(const drizzled::message::Schema&)
350
 
  { return false; }
351
 
 
352
 
  virtual bool doAlterSchema(const drizzled::message::Schema&)
353
 
  { return false; }
354
 
 
355
 
  virtual bool doDropSchema(const drizzled::SchemaIdentifier&)
356
 
  { return false; }
 
411
  static void getSchemaNames(std::set<std::string>& set_of_names);
 
412
  static bool getSchemaDefinition(const std::string &schema_name, message::Schema &proto);
 
413
 
357
414
 
358
415
  static inline const std::string &resolveName(const StorageEngine *engine)
359
416
  {
361
418
  }
362
419
 
363
420
  static int createTable(Session& session,
364
 
                         const drizzled::TableIdentifier &identifier,
365
 
                         message::Table& table_proto);
 
421
                         TableIdentifier &identifier,
 
422
                         bool update_create_info,
 
423
                         message::Table& table_proto,
 
424
                         bool used= true);
366
425
 
367
426
  static void removeLostTemporaryTables(Session &session, const char *directory);
368
427
 
369
 
  Cursor *getCursor(Table &share);
 
428
  Cursor *getCursor(TableShare &share, memory::Root *alloc);
370
429
 
371
430
  uint32_t max_record_length() const
372
431
  { return std::min((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
387
446
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
388
447
 
389
448
  /* TODO-> Make private */
390
 
  static int deleteDefinitionFromPath(const drizzled::TableIdentifier &identifier);
391
 
  static int renameDefinitionFromPath(const drizzled::TableIdentifier &dest, const drizzled::TableIdentifier &src);
392
 
  static int writeDefinitionFromPath(const drizzled::TableIdentifier &identifier, message::Table &proto);
393
 
  static bool readTableFile(const std::string &path, message::Table &table_message);
394
 
 
395
 
public:
396
 
  /* 
397
 
   * The below are simple virtual overrides for the plugin::MonitoredInTransaction
398
 
   * interface.
399
 
   */
400
 
  virtual bool participatesInSqlTransaction() const
401
 
  {
402
 
    return false; /* plugin::StorageEngine is non-transactional in terms of SQL */
403
 
  }
404
 
  virtual bool participatesInXaTransaction() const
405
 
  {
406
 
    return false; /* plugin::StorageEngine is non-transactional in terms of XA */
407
 
  }
408
 
  virtual bool alwaysRegisterForXaTransaction() const
409
 
  {
410
 
    return false;
411
 
  }
412
 
 
413
 
  virtual bool validateCreateTableOption(const std::string &key, const std::string &state)
414
 
  {
415
 
    (void)key;
416
 
    (void)state;
417
 
 
418
 
    return false;
419
 
  }
420
 
 
421
 
  virtual bool validateCreateSchemaOption(const std::string &key, const std::string &state)
422
 
  {
423
 
    (void)key;
424
 
    (void)state;
425
 
 
426
 
    return false;
427
 
  }
 
449
  static int readDefinitionFromPath(TableIdentifier &identifier, message::Table &proto);
 
450
  static int deleteDefinitionFromPath(TableIdentifier &identifier);
 
451
  static int renameDefinitionFromPath(TableIdentifier &dest, TableIdentifier &src);
 
452
  static int writeDefinitionFromPath(TableIdentifier &identifier, message::Table &proto);
428
453
};
429
454
 
430
455
} /* namespace plugin */