~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.h

  • Committer: Jay Pipes
  • Date: 2009-09-15 21:01:42 UTC
  • mto: (1126.2.5 merge)
  • mto: This revision was merged to the branch mainline in revision 1128.
  • Revision ID: jpipes@serialcoder-20090915210142-x8mwiqn1q0vzjspp
Moves Alter_info out into its own header and source file, cleans up some related include mess in sql_lex.h, and renames Alter_info to AlterInfo.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
21
21
#define DRIZZLED_PLUGIN_STORAGE_ENGINE_H
22
22
 
23
23
 
24
 
#include <drizzled/cached_directory.h>
25
24
#include <drizzled/definitions.h>
26
 
#include <drizzled/error_t.h>
 
25
#include <drizzled/sql_plugin.h>
27
26
#include <drizzled/handler_structs.h>
28
 
#include <drizzled/identifier.h>
29
 
#include <drizzled/message.h>
30
 
#include <drizzled/message/cache.h>
31
 
#include <drizzled/plugin.h>
32
 
#include <drizzled/plugin/monitored_in_transaction.h>
33
 
#include <drizzled/plugin/plugin.h>
34
 
#include <drizzled/sql_string.h>
 
27
#include <drizzled/message/table.pb.h>
 
28
#include <drizzled/registry.h>
35
29
 
36
30
#include <bitset>
37
31
#include <string>
38
32
#include <vector>
39
 
#include <set>
40
 
 
41
 
#include <drizzled/visibility.h>
42
 
 
43
 
namespace drizzled
44
 
{
45
33
 
46
34
class TableList;
47
35
class Session;
48
 
class Cursor;
49
 
typedef struct st_hash HASH;
 
36
class XID;
 
37
class handler;
50
38
 
51
39
class TableShare;
 
40
typedef struct st_mysql_lex_string LEX_STRING;
52
41
typedef bool (stat_print_fn)(Session *session, const char *type, uint32_t type_len,
53
42
                             const char *file, uint32_t file_len,
54
43
                             const char *status, uint32_t status_len);
 
44
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
55
45
 
56
46
/* Possible flags of a StorageEngine (there can be 32 of them) */
57
47
enum engine_flag_bits {
58
48
  HTON_BIT_ALTER_NOT_SUPPORTED,       // Engine does not support alter
 
49
  HTON_BIT_CAN_RECREATE,              // Delete all is used for truncate
59
50
  HTON_BIT_HIDDEN,                    // Engine does not appear in lists
 
51
  HTON_BIT_FLUSH_AFTER_RENAME,
60
52
  HTON_BIT_NOT_USER_SELECTABLE,
61
53
  HTON_BIT_TEMPORARY_NOT_SUPPORTED,   // Having temporary tables not supported
62
54
  HTON_BIT_TEMPORARY_ONLY,
63
 
  HTON_BIT_DOES_TRANSACTIONS,
64
 
  HTON_BIT_STATS_RECORDS_IS_EXACT,
65
 
  HTON_BIT_NULL_IN_KEY,
66
 
  HTON_BIT_CAN_INDEX_BLOBS,
67
 
  HTON_BIT_PRIMARY_KEY_IN_READ_INDEX,
68
 
  HTON_BIT_PARTIAL_COLUMN_READ,
69
 
  HTON_BIT_TABLE_SCAN_ON_INDEX,
70
 
  HTON_BIT_FAST_KEY_READ,
71
 
  HTON_BIT_NO_BLOBS,
72
 
  HTON_BIT_HAS_RECORDS,
73
 
  HTON_BIT_NO_AUTO_INCREMENT,
74
 
  HTON_BIT_DUPLICATE_POS,
75
 
  HTON_BIT_AUTO_PART_KEY,
76
 
  HTON_BIT_REQUIRE_PRIMARY_KEY,
77
 
  HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE,
78
 
  HTON_BIT_PRIMARY_KEY_REQUIRED_FOR_DELETE,
79
 
  HTON_BIT_NO_PREFIX_CHAR_KEYS,
80
 
  HTON_BIT_HAS_CHECKSUM,
81
 
  HTON_BIT_SKIP_STORE_LOCK,
82
 
  HTON_BIT_SCHEMA_DICTIONARY,
83
 
  HTON_BIT_FOREIGN_KEYS,
 
55
  HTON_BIT_FILE_BASED, // use for check_lowercase_names
 
56
  HTON_BIT_HAS_DATA_DICTIONARY,
84
57
  HTON_BIT_SIZE
85
58
};
86
59
 
87
60
static const std::bitset<HTON_BIT_SIZE> HTON_NO_FLAGS(0);
88
61
static const std::bitset<HTON_BIT_SIZE> HTON_ALTER_NOT_SUPPORTED(1 << HTON_BIT_ALTER_NOT_SUPPORTED);
 
62
static const std::bitset<HTON_BIT_SIZE> HTON_CAN_RECREATE(1 << HTON_BIT_CAN_RECREATE);
89
63
static const std::bitset<HTON_BIT_SIZE> HTON_HIDDEN(1 << HTON_BIT_HIDDEN);
 
64
static const std::bitset<HTON_BIT_SIZE> HTON_FLUSH_AFTER_RENAME(1 << HTON_BIT_FLUSH_AFTER_RENAME);
90
65
static const std::bitset<HTON_BIT_SIZE> HTON_NOT_USER_SELECTABLE(1 << HTON_BIT_NOT_USER_SELECTABLE);
91
66
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_NOT_SUPPORTED(1 << HTON_BIT_TEMPORARY_NOT_SUPPORTED);
92
67
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_ONLY(1 << HTON_BIT_TEMPORARY_ONLY);
93
 
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_DOES_TRANSACTIONS(1 << HTON_BIT_DOES_TRANSACTIONS);
94
 
static const std::bitset<HTON_BIT_SIZE> HTON_STATS_RECORDS_IS_EXACT(1 << HTON_BIT_STATS_RECORDS_IS_EXACT);
95
 
static const std::bitset<HTON_BIT_SIZE> HTON_NULL_IN_KEY(1 << HTON_BIT_NULL_IN_KEY);
96
 
static const std::bitset<HTON_BIT_SIZE> HTON_CAN_INDEX_BLOBS(1 << HTON_BIT_CAN_INDEX_BLOBS);
97
 
static const std::bitset<HTON_BIT_SIZE> HTON_PRIMARY_KEY_IN_READ_INDEX(1 << HTON_BIT_PRIMARY_KEY_IN_READ_INDEX);
98
 
static const std::bitset<HTON_BIT_SIZE> HTON_PARTIAL_COLUMN_READ(1 << HTON_BIT_PARTIAL_COLUMN_READ);
99
 
static const std::bitset<HTON_BIT_SIZE> HTON_TABLE_SCAN_ON_INDEX(1 << HTON_BIT_TABLE_SCAN_ON_INDEX);
100
 
static const std::bitset<HTON_BIT_SIZE> HTON_FAST_KEY_READ(1 << HTON_BIT_FAST_KEY_READ);
101
 
static const std::bitset<HTON_BIT_SIZE> HTON_NO_BLOBS(1 << HTON_BIT_NO_BLOBS);
102
 
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_RECORDS(1 << HTON_BIT_HAS_RECORDS);
103
 
static const std::bitset<HTON_BIT_SIZE> HTON_NO_AUTO_INCREMENT(1 << HTON_BIT_NO_AUTO_INCREMENT);
104
 
static const std::bitset<HTON_BIT_SIZE> HTON_DUPLICATE_POS(1 << HTON_BIT_DUPLICATE_POS);
105
 
static const std::bitset<HTON_BIT_SIZE> HTON_AUTO_PART_KEY(1 << HTON_BIT_AUTO_PART_KEY);
106
 
static const std::bitset<HTON_BIT_SIZE> HTON_REQUIRE_PRIMARY_KEY(1 << HTON_BIT_REQUIRE_PRIMARY_KEY);
107
 
static const std::bitset<HTON_BIT_SIZE> HTON_REQUIRES_KEY_COLUMNS_FOR_DELETE(1 << HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE);
108
 
static const std::bitset<HTON_BIT_SIZE> HTON_PRIMARY_KEY_REQUIRED_FOR_DELETE(1 << HTON_BIT_PRIMARY_KEY_REQUIRED_FOR_DELETE);
109
 
static const std::bitset<HTON_BIT_SIZE> HTON_NO_PREFIX_CHAR_KEYS(1 << HTON_BIT_NO_PREFIX_CHAR_KEYS);
110
 
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_CHECKSUM(1 << HTON_BIT_HAS_CHECKSUM);
111
 
static const std::bitset<HTON_BIT_SIZE> HTON_SKIP_STORE_LOCK(1 << HTON_BIT_SKIP_STORE_LOCK);
112
 
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_SCHEMA_DICTIONARY(1 << HTON_BIT_SCHEMA_DICTIONARY);
113
 
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_FOREIGN_KEYS(1 << HTON_BIT_FOREIGN_KEYS);
114
 
 
 
68
static const std::bitset<HTON_BIT_SIZE> HTON_FILE_BASED(1 << HTON_BIT_FILE_BASED);
 
69
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_DATA_DICTIONARY(1 << HTON_BIT_HAS_DATA_DICTIONARY);
115
70
 
116
71
class Table;
117
 
class NamedSavepoint;
118
 
 
119
 
namespace plugin
120
 
{
121
 
 
122
 
typedef std::vector<StorageEngine *> EngineVector;
123
 
 
124
 
typedef std::set<std::string> TableNameList;
125
 
 
126
 
extern const std::string UNKNOWN_STRING;
127
 
extern DRIZZLED_API const std::string DEFAULT_DEFINITION_FILE_EXT;
128
 
 
 
72
class TableNameIteratorImplementation;
129
73
 
130
74
/*
131
75
  StorageEngine is a singleton structure - one instance per storage engine -
132
76
  to provide access to storage engine functionality that works on the
133
 
  "global" level (unlike Cursor class that works on a per-table basis)
 
77
  "global" level (unlike handler class that works on a per-table basis)
134
78
 
135
79
  usually StorageEngine instance is defined statically in ha_xxx.cc as
136
80
 
137
81
  static StorageEngine { ... } xxx_engine;
 
82
 
 
83
  savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
138
84
*/
139
 
class DRIZZLED_API StorageEngine :
140
 
  public Plugin,
141
 
  public MonitoredInTransaction
 
85
class StorageEngine
142
86
{
143
 
  friend class SEAPITester;
144
 
public:
145
 
  typedef uint64_t Table_flags;
146
 
 
147
 
private:
148
 
  static EngineVector &getSchemaEngines();
149
 
  const std::bitset<HTON_BIT_SIZE> flags; /* global Cursor flags */
150
 
 
151
 
 
152
 
  virtual void setTransactionReadWrite(Session& session);
153
 
 
154
 
  /*
155
 
   * Indicates to a storage engine the start of a
156
 
   * new SQL statement.
157
 
   */
158
 
  virtual void doStartStatement(Session *session)
159
 
  {
160
 
    (void) session;
161
 
  }
162
 
 
163
 
  /*
164
 
   * Indicates to a storage engine the end of
165
 
   * the current SQL statement in the supplied
166
 
   * Session.
167
 
   */
168
 
  virtual void doEndStatement(Session *session)
169
 
  {
170
 
    (void) session;
171
 
  }
172
 
 
173
 
protected:
174
 
  std::string table_definition_ext;
175
 
 
176
 
public:
177
 
  const std::string& getTableDefinitionFileExtension()
178
 
  {
179
 
    return table_definition_ext;
180
 
  }
181
 
 
182
 
private:
 
87
  /*
 
88
    Name used for storage engine.
 
89
  */
 
90
  const std::string name;
 
91
  const bool two_phase_commit;
 
92
  bool enabled;
 
93
 
 
94
  const std::bitset<HTON_BIT_SIZE> flags; /* global handler flags */
 
95
  /*
 
96
    to store per-savepoint data storage engine is provided with an area
 
97
    of a requested size (0 is ok here).
 
98
    savepoint_offset must be initialized statically to the size of
 
99
    the needed memory to store per-savepoint information.
 
100
    After xxx_init it is changed to be an offset to savepoint storage
 
101
    area and need not be used by storage engine.
 
102
    see binlog_engine and binlog_savepoint_set/rollback for an example.
 
103
  */
 
104
  size_t savepoint_offset;
 
105
  size_t orig_savepoint_offset;
183
106
  std::vector<std::string> aliases;
184
107
 
 
108
  void setTransactionReadWrite(Session* session);
 
109
 
 
110
protected:
 
111
 
 
112
  /**
 
113
   * Implementing classes should override these to provide savepoint
 
114
   * functionality.
 
115
   */
 
116
  virtual int savepoint_set_hook(Session *, void *) { return 0; }
 
117
 
 
118
  virtual int savepoint_rollback_hook(Session *, void *) { return 0; }
 
119
 
 
120
  virtual int savepoint_release_hook(Session *, void *) { return 0; }
 
121
 
185
122
public:
186
 
  const std::vector<std::string>& getAliases() const
 
123
 
 
124
  StorageEngine(const std::string name_arg,
 
125
                const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS,
 
126
                size_t savepoint_offset_arg= 0,
 
127
                bool support_2pc= false);
 
128
 
 
129
  virtual ~StorageEngine();
 
130
 
 
131
  static int getTableProto(const char* path,
 
132
                           drizzled::message::Table *table_proto);
 
133
 
 
134
  virtual int getTableProtoImplementation(const char* path,
 
135
                                          drizzled::message::Table *table_proto)
 
136
    {
 
137
      (void)path;
 
138
      (void)table_proto;
 
139
      return ENOENT;
 
140
    }
 
141
 
 
142
  /*
 
143
    each storage engine has it's own memory area (actually a pointer)
 
144
    in the session, for storing per-connection information.
 
145
    It is accessed as
 
146
 
 
147
      session->ha_data[xxx_engine.slot]
 
148
 
 
149
   slot number is initialized by MySQL after xxx_init() is called.
 
150
  */
 
151
  uint32_t slot;
 
152
 
 
153
  inline uint32_t getSlot (void) { return slot; }
 
154
  inline void setSlot (uint32_t value) { slot= value; }
 
155
 
 
156
  const std::vector<std::string>& getAliases()
187
157
  {
188
158
    return aliases;
189
159
  }
193
163
    aliases.push_back(alias);
194
164
  }
195
165
 
196
 
protected:
197
 
 
198
 
  /**
199
 
    @brief
200
 
    Used as a protobuf storage currently by TEMP only engines.
201
 
  */
202
 
  typedef std::map <std::string, message::Table> ProtoCache;
203
 
  ProtoCache proto_cache;
204
 
  pthread_mutex_t proto_cache_mutex;
205
 
 
206
 
public:
207
 
  StorageEngine(const std::string name_arg,
208
 
                const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
209
 
 
210
 
  virtual ~StorageEngine();
211
 
 
212
 
protected:
213
 
  virtual int doGetTableDefinition(Session &session,
214
 
                                   const drizzled::identifier::Table &identifier,
215
 
                                   message::Table &table_message)
216
 
  {
217
 
    (void)session;
218
 
    (void)identifier;
219
 
    (void)table_message;
220
 
 
221
 
    return ENOENT;
222
 
  }
223
 
 
224
 
  /* Old style cursor errors */
225
 
  void print_keydup_error(uint32_t key_nr, const char *msg, const Table &table) const;
226
 
  virtual bool get_error_message(int error, String *buf) const;
227
 
 
228
 
public:
229
 
  virtual void print_error(int error, myf errflag, const Table& table) const;
 
166
  bool has_2pc()
 
167
  {
 
168
    return two_phase_commit;
 
169
  }
 
170
 
 
171
 
 
172
  bool is_enabled() const
 
173
  {
 
174
    return enabled;
 
175
  }
230
176
 
231
177
  bool is_user_selectable() const
232
178
  {
238
184
    return flags.test(flag);
239
185
  }
240
186
 
241
 
  // @todo match check_flag interface
242
 
  virtual uint32_t index_flags(enum  ha_key_alg) const { return 0; }
243
 
  virtual void startStatement(Session *session)
244
 
  {
245
 
    doStartStatement(session);
246
 
  }
247
 
  virtual void endStatement(Session *session)
248
 
  {
249
 
    doEndStatement(session);
250
 
  }
 
187
  void enable() { enabled= true; }
 
188
  void disable() { enabled= false; }
 
189
 
 
190
  std::string getName() const { return name; }
251
191
 
252
192
  /*
253
 
   * Called during Session::cleanup() for all engines
254
 
   */
 
193
    StorageEngine methods:
 
194
 
 
195
    close_connection is only called if
 
196
    session->ha_data[xxx_engine.slot] is non-zero, so even if you don't need
 
197
    this storage area - set it to something, so that MySQL would know
 
198
    this storage engine was accessed in this connection
 
199
  */
255
200
  virtual int close_connection(Session  *)
256
201
  {
257
202
    return 0;
258
203
  }
259
 
 
260
 
  virtual Cursor *create(Table &)= 0;
 
204
  /*
 
205
    'all' is true if it's a real commit, that makes persistent changes
 
206
    'all' is false if it's not in fact a commit but an end of the
 
207
    statement that is part of the transaction.
 
208
    NOTE 'all' is also false in auto-commit mode where 'end of statement'
 
209
    and 'real commit' mean the same event.
 
210
  */
 
211
  virtual int  commit(Session *, bool)
 
212
  {
 
213
    return 0;
 
214
  }
 
215
 
 
216
  virtual int  rollback(Session *, bool)
 
217
  {
 
218
    return 0;
 
219
  }
 
220
 
 
221
  /*
 
222
    The void * points to an uninitialized storage area of requested size
 
223
    (see savepoint_offset description)
 
224
  */
 
225
  int savepoint_set(Session *session, void *sp)
 
226
  {
 
227
    return savepoint_set_hook(session, (unsigned char *)sp+savepoint_offset);
 
228
  }
 
229
 
 
230
  /*
 
231
    The void * points to a storage area, that was earlier passed
 
232
    to the savepoint_set call
 
233
  */
 
234
  int savepoint_rollback(Session *session, void *sp)
 
235
  {
 
236
     return savepoint_rollback_hook(session,
 
237
                                    (unsigned char *)sp+savepoint_offset);
 
238
  }
 
239
 
 
240
  int savepoint_release(Session *session, void *sp)
 
241
  {
 
242
    return savepoint_release_hook(session,
 
243
                                  (unsigned char *)sp+savepoint_offset);
 
244
  }
 
245
 
 
246
  virtual int  prepare(Session *, bool) { return 0; }
 
247
  virtual int  recover(XID *, uint32_t) { return 0; }
 
248
  virtual int  commit_by_xid(XID *) { return 0; }
 
249
  virtual int  rollback_by_xid(XID *) { return 0; }
 
250
  virtual handler *create(TableShare *, MEM_ROOT *)= 0;
261
251
  /* args: path */
 
252
  virtual void drop_database(char*) { }
 
253
  virtual int start_consistent_snapshot(Session *) { return 0; }
262
254
  virtual bool flush_logs() { return false; }
263
255
  virtual bool show_status(Session *, stat_print_fn *, enum ha_stat_type)
264
256
  {
265
257
    return false;
266
258
  }
267
259
 
 
260
  /* args: current_session, tables, cond */
 
261
  virtual int fill_files_table(Session *, TableList *,
 
262
                               Item *) { return 0; }
 
263
  virtual int release_temporary_latches(Session *) { return false; }
 
264
 
268
265
  /**
269
266
    If frm_error() is called then we will use this to find out what file
270
267
    extentions exist for the storage engine. This is also used by the default
271
 
    rename_table and delete_table method in Cursor.cc.
 
268
    rename_table and delete_table method in handler.cc.
272
269
 
273
270
    For engines that have two file name extentions (separate meta/index file
274
271
    and data file), the order of elements is relevant. First element of engine
279
276
  virtual const char **bas_ext() const =0;
280
277
 
281
278
protected:
282
 
  virtual int doCreateTable(Session &session,
283
 
                            Table &table_arg,
284
 
                            const drizzled::identifier::Table &identifier,
285
 
                            message::Table &message)= 0;
286
 
 
287
 
  virtual int doRenameTable(Session &session,
288
 
                            const drizzled::identifier::Table &from, const drizzled::identifier::Table &to)= 0;
289
 
 
290
 
  virtual int doDropTable(Session &session,
291
 
                          const drizzled::identifier::Table &identifier)= 0;
292
 
 
293
 
  virtual void doGetTableIdentifiers(CachedDirectory &directory,
294
 
                                     const drizzled::identifier::Schema &schema_identifier,
295
 
                                     identifier::Table::vector &set_of_identifiers)= 0;
296
 
 
297
 
  virtual bool doDoesTableExist(Session& session, const drizzled::identifier::Table &identifier);
298
 
 
299
 
  virtual bool doCanCreateTable(const drizzled::identifier::Table &identifier)
300
 
  { (void)identifier;  return true; }
301
 
 
302
 
public:
303
 
 
304
 
  friend class AddSchemaNames;
305
 
  friend class AddTableIdentifier;
306
 
  friend class AlterSchema;
307
 
  friend class CanCreateTable;
308
 
  friend class CreateSchema;
309
 
  friend class DropSchema;
310
 
  friend class DropTable;
311
 
  friend class DropTables;
312
 
  friend class FindEngineByName;
313
 
  friend class Ha_delete_table_error_handler;
314
 
  friend class StorageEngineCloseConnection;
315
 
  friend class StorageEngineDoesTableExist;
316
 
  friend class StorageEngineGetSchemaDefinition;
317
 
  friend class StorageEngineGetTableDefinition;
318
 
  friend class DropTableByIdentifier;
319
 
 
320
 
  int renameTable(Session &session, const drizzled::identifier::Table &from, const drizzled::identifier::Table &to);
321
 
 
322
 
  /* Class Methods for operating on plugin */
323
 
  static bool addPlugin(plugin::StorageEngine *engine);
324
 
  static void removePlugin(plugin::StorageEngine *engine);
325
 
 
326
 
  static int getTableDefinition(Session& session,
327
 
                                const drizzled::identifier::Table &identifier,
328
 
                                message::table::shared_ptr &table_proto,
329
 
                                bool include_temporary_tables= true);
330
 
  static message::table::shared_ptr getTableMessage(Session& session,
331
 
                                                    const drizzled::identifier::Table &identifier,
332
 
                                                    drizzled::error_t &error,
333
 
                                                    bool include_temporary_tables= true);
334
 
  static bool doesTableExist(Session &session,
335
 
                             const drizzled::identifier::Table &identifier,
336
 
                             bool include_temporary_tables= true);
337
 
 
338
 
  static plugin::StorageEngine *findByName(const std::string &find_str);
339
 
  static plugin::StorageEngine *findByName(Session& session, const std::string &find_str);
340
 
 
341
 
  static void closeConnection(Session* session);
342
 
  static void dropDatabase(char* path);
343
 
  static bool flushLogs(plugin::StorageEngine *db_type);
344
 
 
345
 
  static bool dropTable(Session& session,
346
 
                        const drizzled::identifier::Table &identifier);
347
 
  static bool dropTable(Session& session,
348
 
                        const drizzled::identifier::Table &identifier,
349
 
                        drizzled::error_t &error);
350
 
 
351
 
  static bool dropTable(Session& session,
352
 
                        StorageEngine &engine,
353
 
                        identifier::Table::const_reference identifier,
354
 
                        drizzled::error_t &error);
355
 
 
356
 
  static void getIdentifiers(Session &session,
357
 
                             const identifier::Schema &schema_identifier,
358
 
                             identifier::Table::vector &set_of_identifiers);
359
 
 
360
 
  // Check to see if any SE objects to creation.
361
 
  static bool canCreateTable(const drizzled::identifier::Table &identifier);
362
 
 
363
 
  // @note All schema methods defined here
364
 
  static void getIdentifiers(Session &session, identifier::Schema::vector &schemas);
365
 
  static bool getSchemaDefinition(const drizzled::identifier::Table &identifier, message::schema::shared_ptr &proto);
366
 
  static bool getSchemaDefinition(const drizzled::identifier::Schema &identifier, message::schema::shared_ptr &proto);
367
 
  static bool doesSchemaExist(const drizzled::identifier::Schema &identifier);
368
 
  static const CHARSET_INFO *getSchemaCollation(const drizzled::identifier::Schema &identifier);
369
 
  static bool createSchema(const drizzled::message::Schema &schema_message);
370
 
  static bool dropSchema(drizzled::Session& session, identifier::Schema::const_reference identifier);
371
 
  static bool alterSchema(const drizzled::message::Schema &schema_message);
372
 
 
373
 
  // @note make private/protected
374
 
protected:
375
 
  virtual void doGetSchemaIdentifiers(identifier::Schema::vector&)
376
 
  { }
377
 
 
378
 
  virtual bool doGetSchemaDefinition(const drizzled::identifier::Schema&, drizzled::message::schema::shared_ptr&)
379
 
  { 
380
 
    return false; 
381
 
  }
382
 
 
383
 
  virtual bool doCreateSchema(const drizzled::message::Schema&)
384
 
  { return false; }
385
 
 
386
 
  virtual bool doAlterSchema(const drizzled::message::Schema&)
387
 
  { return false; }
388
 
 
389
 
  virtual bool doDropSchema(const drizzled::identifier::Schema&)
390
 
  { return false; }
391
 
 
392
 
public:
393
 
  static inline const std::string &resolveName(const StorageEngine *engine)
394
 
  {
395
 
    return engine == NULL ? UNKNOWN_STRING : engine->getName();
396
 
  }
397
 
 
398
 
  static bool createTable(Session &session,
399
 
                          const identifier::Table &identifier,
400
 
                          message::Table& table_message);
401
 
 
402
 
  static void removeLostTemporaryTables(Session &session, const char *directory);
403
 
 
404
 
  Cursor *getCursor(Table &share);
405
 
 
406
 
  uint32_t max_record_length() const
407
 
  { return std::min((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
408
 
  uint32_t max_keys() const
409
 
  { return std::min((unsigned int)MAX_KEY, max_supported_keys()); }
410
 
  uint32_t max_key_parts() const
411
 
  { return std::min((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
412
 
  uint32_t max_key_length() const
413
 
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
414
 
  uint32_t max_key_part_length(void) const
415
 
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
416
 
 
417
 
  virtual uint32_t max_supported_record_length(void) const
418
 
  { return HA_MAX_REC_LENGTH; }
419
 
  virtual uint32_t max_supported_keys(void) const { return 0; }
420
 
  virtual uint32_t max_supported_key_parts(void) const { return MAX_REF_PARTS; }
421
 
  virtual uint32_t max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
422
 
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
423
 
 
424
 
  /* TODO-> Make private */
425
 
protected:
426
 
  static int deleteDefinitionFromPath(const drizzled::identifier::Table &identifier);
427
 
  static int renameDefinitionFromPath(const drizzled::identifier::Table &dest, const drizzled::identifier::Table &src);
428
 
  static int writeDefinitionFromPath(const drizzled::identifier::Table &identifier, message::Table &proto);
429
 
  static bool readTableFile(const std::string &path, message::Table &table_message);
430
 
 
431
 
public:
432
 
  /* 
433
 
   * The below are simple virtual overrides for the plugin::MonitoredInTransaction
434
 
   * interface.
435
 
   */
436
 
  virtual bool participatesInSqlTransaction() const
437
 
  {
438
 
    return false; /* plugin::StorageEngine is non-transactional in terms of SQL */
439
 
  }
440
 
  virtual bool participatesInXaTransaction() const
441
 
  {
442
 
    return false; /* plugin::StorageEngine is non-transactional in terms of XA */
443
 
  }
444
 
  virtual bool alwaysRegisterForXaTransaction() const
445
 
  {
446
 
    return false;
447
 
  }
448
 
 
449
 
  virtual bool validateCreateTableOption(const std::string &key, const std::string &state)
450
 
  {
451
 
    (void)key;
452
 
    (void)state;
453
 
 
454
 
    return false;
455
 
  }
456
 
 
457
 
  virtual bool validateCreateSchemaOption(const std::string &key, const std::string &state)
458
 
  {
459
 
    (void)key;
460
 
    (void)state;
461
 
 
462
 
    return false;
463
 
  }
464
 
};
465
 
 
466
 
std::ostream& operator<<(std::ostream& output, const StorageEngine &engine);
467
 
 
468
 
} /* namespace plugin */
469
 
} /* namespace drizzled */
 
279
  virtual int createTableImplementation(Session *session,
 
280
                                        const char *table_name,
 
281
                                        Table *table_arg,
 
282
                                        HA_CREATE_INFO *create_info,
 
283
                                        drizzled::message::Table* proto)= 0;
 
284
 
 
285
  virtual int renameTableImplementation(Session* session,
 
286
                                        const char *from, const char *to);
 
287
 
 
288
  virtual int deleteTableImplementation(Session* session,
 
289
                                        const std::string table_path);
 
290
 
 
291
public:
 
292
  int createTable(Session *session, const char *path, Table *table_arg,
 
293
                  HA_CREATE_INFO *create_info,
 
294
                  drizzled::message::Table *proto) 
 
295
  {
 
296
    char name_buff[FN_REFLEN];
 
297
    const char *table_name;
 
298
 
 
299
    table_name= checkLowercaseNames(path, name_buff);
 
300
 
 
301
    setTransactionReadWrite(session);
 
302
 
 
303
    return createTableImplementation(session, table_name, table_arg,
 
304
                                     create_info, proto);
 
305
  }
 
306
 
 
307
  int renameTable(Session *session, const char *from, const char *to) 
 
308
  {
 
309
    setTransactionReadWrite(session);
 
310
 
 
311
    return renameTableImplementation(session, from, to);
 
312
  }
 
313
 
 
314
  int deleteTable(Session* session, const std::string table_path) 
 
315
  {
 
316
    setTransactionReadWrite(session);
 
317
 
 
318
    return deleteTableImplementation(session, table_path);
 
319
  }
 
320
 
 
321
  const char *checkLowercaseNames(const char *path, char *tmp_path);
 
322
 
 
323
  virtual TableNameIteratorImplementation* tableNameIterator(const std::string &database)
 
324
  {
 
325
    (void)database;
 
326
    return NULL;
 
327
  }
 
328
};
 
329
 
 
330
class TableNameIteratorImplementation
 
331
{
 
332
protected:
 
333
  std::string db;
 
334
public:
 
335
  TableNameIteratorImplementation(const std::string &database) : db(database)
 
336
    {};
 
337
  virtual ~TableNameIteratorImplementation() {};
 
338
 
 
339
  virtual int next(std::string *name)= 0;
 
340
 
 
341
};
 
342
 
 
343
class TableNameIterator
 
344
{
 
345
private:
 
346
  drizzled::Registry<StorageEngine *>::iterator engine_iter;
 
347
  TableNameIteratorImplementation *current_implementation;
 
348
  TableNameIteratorImplementation *default_implementation;
 
349
  std::string database;
 
350
public:
 
351
  TableNameIterator(const std::string &db);
 
352
  ~TableNameIterator();
 
353
 
 
354
  int next(std::string *name);
 
355
};
 
356
 
 
357
/* lookups */
 
358
StorageEngine *ha_default_storage_engine(Session *session);
 
359
StorageEngine *ha_resolve_by_name(Session *session, std::string find_str);
 
360
 
 
361
handler *get_new_handler(TableShare *share, MEM_ROOT *alloc,
 
362
                         StorageEngine *db_type);
 
363
const std::string ha_resolve_storage_engine_name(const StorageEngine *db_type);
470
364
 
471
365
#endif /* DRIZZLED_PLUGIN_STORAGE_ENGINE_H */