17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_PLUGIN_STORAGE_ENGINE_H
21
#define DRIZZLED_PLUGIN_STORAGE_ENGINE_H
24
#include <drizzled/cached_directory.h>
20
#ifndef DRIZZLED_HANDLERTON_H
21
#define DRIZZLED_HANDLERTON_H
25
26
#include <drizzled/definitions.h>
26
#include <drizzled/error_t.h>
27
#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>
41
#include <drizzled/visibility.h>
27
#include <drizzled/sql_plugin.h>
49
typedef struct st_hash HASH;
34
typedef struct st_mysql_lex_string LEX_STRING;
35
typedef struct st_table_share TABLE_SHARE;
52
36
typedef bool (stat_print_fn)(Session *session, const char *type, uint32_t type_len,
53
37
const char *file, uint32_t file_len,
54
38
const char *status, uint32_t status_len);
39
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
56
/* Possible flags of a StorageEngine (there can be 32 of them) */
57
enum engine_flag_bits {
41
/* Possible flags of a handlerton (there can be 32 of them) */
43
HTON_BIT_CLOSE_CURSORS_AT_COMMIT,
58
44
HTON_BIT_ALTER_NOT_SUPPORTED, // Engine does not support alter
45
HTON_BIT_CAN_RECREATE, // Delete all is used for truncate
59
46
HTON_BIT_HIDDEN, // Engine does not appear in lists
47
HTON_BIT_FLUSH_AFTER_RENAME,
60
48
HTON_BIT_NOT_USER_SELECTABLE,
61
49
HTON_BIT_TEMPORARY_NOT_SUPPORTED, // Having temporary tables not supported
62
HTON_BIT_TEMPORARY_ONLY,
63
HTON_BIT_DOES_TRANSACTIONS,
64
HTON_BIT_STATS_RECORDS_IS_EXACT,
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,
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,
50
HTON_BIT_SUPPORT_LOG_TABLES, // Engine supports log tables
51
HTON_BIT_NO_PARTITION, // You can not partition these tables
87
55
static const std::bitset<HTON_BIT_SIZE> HTON_NO_FLAGS(0);
56
static const std::bitset<HTON_BIT_SIZE> HTON_CLOSE_CURSORS_AT_COMMIT(1 << HTON_BIT_CLOSE_CURSORS_AT_COMMIT);
88
57
static const std::bitset<HTON_BIT_SIZE> HTON_ALTER_NOT_SUPPORTED(1 << HTON_BIT_ALTER_NOT_SUPPORTED);
58
static const std::bitset<HTON_BIT_SIZE> HTON_CAN_RECREATE(1 << HTON_BIT_CAN_RECREATE);
89
59
static const std::bitset<HTON_BIT_SIZE> HTON_HIDDEN(1 << HTON_BIT_HIDDEN);
60
static const std::bitset<HTON_BIT_SIZE> HTON_FLUSH_AFTER_RENAME(1 << HTON_BIT_FLUSH_AFTER_RENAME);
90
61
static const std::bitset<HTON_BIT_SIZE> HTON_NOT_USER_SELECTABLE(1 << HTON_BIT_NOT_USER_SELECTABLE);
91
62
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_NOT_SUPPORTED(1 << HTON_BIT_TEMPORARY_NOT_SUPPORTED);
92
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);
117
class NamedSavepoint;
122
typedef std::vector<StorageEngine *> EngineVector;
124
typedef std::set<std::string> TableNameList;
126
extern const std::string UNKNOWN_STRING;
127
extern DRIZZLED_API const std::string DEFAULT_DEFINITION_FILE_EXT;
63
static const std::bitset<HTON_BIT_SIZE> HTON_SUPPORT_LOG_TABLES(1 << HTON_BIT_SUPPORT_LOG_TABLES);
64
static const std::bitset<HTON_BIT_SIZE> HTON_NO_PARTITION(1 << HTON_BIT_NO_PARTITION);
131
StorageEngine is a singleton structure - one instance per storage engine -
67
handlerton is a singleton structure - one instance per storage engine -
132
68
to provide access to storage engine functionality that works on the
133
"global" level (unlike Cursor class that works on a per-table basis)
135
usually StorageEngine instance is defined statically in ha_xxx.cc as
137
static StorageEngine { ... } xxx_engine;
69
"global" level (unlike handler class that works on a per-table basis)
71
usually handlerton instance is defined statically in ha_xxx.cc as
73
static handlerton { ... } xxx_hton;
75
savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
139
class DRIZZLED_API StorageEngine :
141
public MonitoredInTransaction
143
friend class SEAPITester;
145
typedef uint64_t Table_flags;
148
static EngineVector &getSchemaEngines();
149
const std::bitset<HTON_BIT_SIZE> flags; /* global Cursor flags */
152
virtual void setTransactionReadWrite(Session& session);
155
* Indicates to a storage engine the start of a
158
virtual void doStartStatement(Session *session)
164
* Indicates to a storage engine the end of
165
* the current SQL statement in the supplied
168
virtual void doEndStatement(Session *session)
174
std::string table_definition_ext;
177
const std::string& getTableDefinitionFileExtension()
179
return table_definition_ext;
183
std::vector<std::string> aliases;
186
const std::vector<std::string>& getAliases() const
191
void addAlias(std::string alias)
193
aliases.push_back(alias);
200
Used as a protobuf storage currently by TEMP only engines.
202
typedef std::map <std::string, message::Table> ProtoCache;
203
ProtoCache proto_cache;
204
pthread_mutex_t proto_cache_mutex;
207
StorageEngine(const std::string name_arg,
208
const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
210
virtual ~StorageEngine();
213
virtual int doGetTableDefinition(Session &session,
214
const drizzled::identifier::Table &identifier,
215
message::Table &table_message)
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;
229
virtual void print_error(int error, myf errflag, const Table& table) const;
231
bool is_user_selectable() const
233
return not flags.test(HTON_BIT_NOT_USER_SELECTABLE);
236
bool check_flag(const engine_flag_bits flag) const
238
return flags.test(flag);
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)
245
doStartStatement(session);
247
virtual void endStatement(Session *session)
249
doEndStatement(session);
253
* Called during Session::cleanup() for all engines
255
virtual int close_connection(Session *)
260
virtual Cursor *create(Table &)= 0;
262
virtual bool flush_logs() { return false; }
263
virtual bool show_status(Session *, stat_print_fn *, enum ha_stat_type)
269
If frm_error() is called then we will use this to find out what file
270
extentions exist for the storage engine. This is also used by the default
271
rename_table and delete_table method in Cursor.cc.
273
For engines that have two file name extentions (separate meta/index file
274
and data file), the order of elements is relevant. First element of engine
275
file name extentions array should be meta/index file extention. Second
276
element - data file extention. This order is assumed by
277
prepare_for_repair() when REPAIR Table ... USE_FRM is issued.
279
virtual const char **bas_ext() const =0;
282
virtual int doCreateTable(Session &session,
284
const drizzled::identifier::Table &identifier,
285
message::Table &message)= 0;
287
virtual int doRenameTable(Session &session,
288
const drizzled::identifier::Table &from, const drizzled::identifier::Table &to)= 0;
290
virtual int doDropTable(Session &session,
291
const drizzled::identifier::Table &identifier)= 0;
293
virtual void doGetTableIdentifiers(CachedDirectory &directory,
294
const drizzled::identifier::Schema &schema_identifier,
295
identifier::Table::vector &set_of_identifiers)= 0;
297
virtual bool doDoesTableExist(Session& session, const drizzled::identifier::Table &identifier);
299
virtual bool doCanCreateTable(const drizzled::identifier::Table &identifier)
300
{ (void)identifier; return true; }
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;
320
int renameTable(Session &session, const drizzled::identifier::Table &from, const drizzled::identifier::Table &to);
322
/* Class Methods for operating on plugin */
323
static bool addPlugin(plugin::StorageEngine *engine);
324
static void removePlugin(plugin::StorageEngine *engine);
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);
338
static plugin::StorageEngine *findByName(const std::string &find_str);
339
static plugin::StorageEngine *findByName(Session& session, const std::string &find_str);
341
static void closeConnection(Session* session);
342
static void dropDatabase(char* path);
343
static bool flushLogs(plugin::StorageEngine *db_type);
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);
351
static bool dropTable(Session& session,
352
StorageEngine &engine,
353
identifier::Table::const_reference identifier,
354
drizzled::error_t &error);
356
static void getIdentifiers(Session &session,
357
const identifier::Schema &schema_identifier,
358
identifier::Table::vector &set_of_identifiers);
360
// Check to see if any SE objects to creation.
361
static bool canCreateTable(const drizzled::identifier::Table &identifier);
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);
373
// @note make private/protected
375
virtual void doGetSchemaIdentifiers(identifier::Schema::vector&)
378
virtual bool doGetSchemaDefinition(const drizzled::identifier::Schema&, drizzled::message::schema::shared_ptr&)
383
virtual bool doCreateSchema(const drizzled::message::Schema&)
386
virtual bool doAlterSchema(const drizzled::message::Schema&)
389
virtual bool doDropSchema(const drizzled::identifier::Schema&)
393
static inline const std::string &resolveName(const StorageEngine *engine)
395
return engine == NULL ? UNKNOWN_STRING : engine->getName();
398
static bool createTable(Session &session,
399
const identifier::Table &identifier,
400
message::Table& table_message);
402
static void removeLostTemporaryTables(Session &session, const char *directory);
404
Cursor *getCursor(Table &share);
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()); }
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; }
424
/* TODO-> Make private */
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);
433
* The below are simple virtual overrides for the plugin::MonitoredInTransaction
436
virtual bool participatesInSqlTransaction() const
438
return false; /* plugin::StorageEngine is non-transactional in terms of SQL */
440
virtual bool participatesInXaTransaction() const
442
return false; /* plugin::StorageEngine is non-transactional in terms of XA */
444
virtual bool alwaysRegisterForXaTransaction() const
449
virtual bool validateCreateTableOption(const std::string &key, const std::string &state)
457
virtual bool validateCreateSchemaOption(const std::string &key, const std::string &state)
80
Name used for storage engine.
85
Historical marker for if the engine is available of not
87
SHOW_COMP_OPTION state;
90
Historical number used for frm file to determine the correct storage engine.
91
This is going away and new engines will just use "name" for this.
93
enum legacy_db_type db_type;
95
each storage engine has it's own memory area (actually a pointer)
96
in the session, for storing per-connection information.
99
session->ha_data[xxx_hton.slot]
101
slot number is initialized by MySQL after xxx_init() is called.
105
to store per-savepoint data storage engine is provided with an area
106
of a requested size (0 is ok here).
107
savepoint_offset must be initialized statically to the size of
108
the needed memory to store per-savepoint information.
109
After xxx_init it is changed to be an offset to savepoint storage
110
area and need not be used by storage engine.
111
see binlog_hton and binlog_savepoint_set/rollback for an example.
113
uint32_t savepoint_offset;
117
close_connection is only called if
118
session->ha_data[xxx_hton.slot] is non-zero, so even if you don't need
119
this storage area - set it to something, so that MySQL would know
120
this storage engine was accessed in this connection
122
int (*close_connection)(handlerton *hton, Session *session);
124
sv points to an uninitialized storage area of requested size
125
(see savepoint_offset description)
127
int (*savepoint_set)(handlerton *hton, Session *session, void *sv);
129
sv points to a storage area, that was earlier passed
130
to the savepoint_set call
132
int (*savepoint_rollback)(handlerton *hton, Session *session, void *sv);
133
int (*savepoint_release)(handlerton *hton, Session *session, void *sv);
135
'all' is true if it's a real commit, that makes persistent changes
136
'all' is false if it's not in fact a commit but an end of the
137
statement that is part of the transaction.
138
NOTE 'all' is also false in auto-commit mode where 'end of statement'
139
and 'real commit' mean the same event.
141
int (*commit)(handlerton *hton, Session *session, bool all);
142
int (*rollback)(handlerton *hton, Session *session, bool all);
143
int (*prepare)(handlerton *hton, Session *session, bool all);
144
int (*recover)(handlerton *hton, XID *xid_list, uint32_t len);
145
int (*commit_by_xid)(handlerton *hton, XID *xid);
146
int (*rollback_by_xid)(handlerton *hton, XID *xid);
147
void *(*create_cursor_read_view)(handlerton *hton, Session *session);
148
void (*set_cursor_read_view)(handlerton *hton, Session *session, void *read_view);
149
void (*close_cursor_read_view)(handlerton *hton, Session *session, void *read_view);
150
handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root);
151
void (*drop_database)(handlerton *hton, char* path);
152
int (*start_consistent_snapshot)(handlerton *hton, Session *session);
153
bool (*flush_logs)(handlerton *hton);
154
bool (*show_status)(handlerton *hton, Session *session, stat_print_fn *print, enum ha_stat_type stat);
155
int (*fill_files_table)(handlerton *hton, Session *session,
158
std::bitset<HTON_BIT_SIZE> flags; /* global handler flags */
159
int (*release_temporary_latches)(handlerton *hton, Session *session);
161
int (*table_exists_in_engine)(handlerton *hton, Session* session, const char *db,
163
uint32_t license; /* Flag for Engine License */
164
void *data; /* Location for engines to keep personal structures */
466
std::ostream& operator<<(std::ostream& output, const StorageEngine &engine);
468
} /* namespace plugin */
469
} /* namespace drizzled */
471
#endif /* DRIZZLED_PLUGIN_STORAGE_ENGINE_H */
169
handlerton *ha_default_handlerton(Session *session);
170
plugin_ref ha_resolve_by_name(Session *session, const LEX_STRING *name);
171
plugin_ref ha_lock_engine(Session *session, handlerton *hton);
172
handlerton *ha_resolve_by_legacy_type(Session *session,
173
enum legacy_db_type db_type);
174
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
175
handlerton *db_type);
176
handlerton *ha_checktype(Session *session, enum legacy_db_type database_type,
177
bool no_substitute, bool report_error);
179
enum legacy_db_type ha_legacy_type(const handlerton *db_type);
180
const char *ha_resolve_storage_engine_name(const handlerton *db_type);
181
bool ha_check_storage_engine_flag(const handlerton *db_type, const hton_flag_bits flag);
182
bool ha_storage_engine_is_enabled(const handlerton *db_type);
183
LEX_STRING *ha_storage_engine_name(const handlerton *hton);
185
#endif /* DRIZZLED_HANDLERTON_H */