90
87
static const std::bitset<HTON_BIT_SIZE> HTON_NOT_USER_SELECTABLE(1 << HTON_BIT_NOT_USER_SELECTABLE);
91
88
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_NOT_SUPPORTED(1 << HTON_BIT_TEMPORARY_NOT_SUPPORTED);
92
89
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_ONLY(1 << HTON_BIT_TEMPORARY_ONLY);
90
static const std::bitset<HTON_BIT_SIZE> HTON_FILE_BASED(1 << HTON_BIT_FILE_BASED);
91
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_DATA_DICTIONARY(1 << HTON_BIT_HAS_DATA_DICTIONARY);
93
92
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_DOES_TRANSACTIONS(1 << HTON_BIT_DOES_TRANSACTIONS);
94
93
static const std::bitset<HTON_BIT_SIZE> HTON_STATS_RECORDS_IS_EXACT(1 << HTON_BIT_STATS_RECORDS_IS_EXACT);
95
94
static const std::bitset<HTON_BIT_SIZE> HTON_NULL_IN_KEY(1 << HTON_BIT_NULL_IN_KEY);
96
95
static const std::bitset<HTON_BIT_SIZE> HTON_CAN_INDEX_BLOBS(1 << HTON_BIT_CAN_INDEX_BLOBS);
96
static const std::bitset<HTON_BIT_SIZE> HTON_PRIMARY_KEY_REQUIRED_FOR_POSITION(1 << HTON_BIT_PRIMARY_KEY_REQUIRED_FOR_POSITION);
97
97
static const std::bitset<HTON_BIT_SIZE> HTON_PRIMARY_KEY_IN_READ_INDEX(1 << HTON_BIT_PRIMARY_KEY_IN_READ_INDEX);
98
98
static const std::bitset<HTON_BIT_SIZE> HTON_PARTIAL_COLUMN_READ(1 << HTON_BIT_PARTIAL_COLUMN_READ);
99
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_MRR_CANT_SORT(1 << HTON_BIT_MRR_CANT_SORT);
100
101
static const std::bitset<HTON_BIT_SIZE> HTON_FAST_KEY_READ(1 << HTON_BIT_FAST_KEY_READ);
101
102
static const std::bitset<HTON_BIT_SIZE> HTON_NO_BLOBS(1 << HTON_BIT_NO_BLOBS);
102
103
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_RECORDS(1 << HTON_BIT_HAS_RECORDS);
103
104
static const std::bitset<HTON_BIT_SIZE> HTON_NO_AUTO_INCREMENT(1 << HTON_BIT_NO_AUTO_INCREMENT);
104
105
static const std::bitset<HTON_BIT_SIZE> HTON_DUPLICATE_POS(1 << HTON_BIT_DUPLICATE_POS);
105
106
static const std::bitset<HTON_BIT_SIZE> HTON_AUTO_PART_KEY(1 << HTON_BIT_AUTO_PART_KEY);
107
static const std::bitset<HTON_BIT_SIZE> HTON_NEED_READ_RANGE_BUFFER(1 << HTON_BIT_NEED_READ_RANGE_BUFFER);
106
108
static const std::bitset<HTON_BIT_SIZE> HTON_REQUIRE_PRIMARY_KEY(1 << HTON_BIT_REQUIRE_PRIMARY_KEY);
107
109
static const std::bitset<HTON_BIT_SIZE> HTON_REQUIRES_KEY_COLUMNS_FOR_DELETE(1 << HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE);
108
110
static const std::bitset<HTON_BIT_SIZE> HTON_PRIMARY_KEY_REQUIRED_FOR_DELETE(1 << HTON_BIT_PRIMARY_KEY_REQUIRED_FOR_DELETE);
109
111
static const std::bitset<HTON_BIT_SIZE> HTON_NO_PREFIX_CHAR_KEYS(1 << HTON_BIT_NO_PREFIX_CHAR_KEYS);
110
112
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_CHECKSUM(1 << HTON_BIT_HAS_CHECKSUM);
111
113
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
123
extern const std::string UNKNOWN_STRING;
127
extern DRIZZLED_API const std::string DEFAULT_DEFINITION_FILE_EXT;
124
extern const std::string DEFAULT_DEFINITION_FILE_EXT;
131
127
StorageEngine is a singleton structure - one instance per storage engine -
135
131
usually StorageEngine instance is defined statically in ha_xxx.cc as
137
133
static StorageEngine { ... } xxx_engine;
135
savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
139
class DRIZZLED_API StorageEngine :
141
public MonitoredInTransaction
137
class StorageEngine : public Plugin
143
friend class SEAPITester;
145
140
typedef uint64_t Table_flags;
148
static EngineVector &getSchemaEngines();
145
Name used for storage engine.
147
const bool two_phase_commit;
149
150
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)
152
to store per-savepoint data storage engine is provided with an area
153
of a requested size (0 is ok here).
154
savepoint_offset must be initialized statically to the size of
155
the needed memory to store per-savepoint information.
156
After xxx_init it is changed to be an offset to savepoint storage
157
area and need not be used by storage engine.
158
see binlog_engine and binlog_savepoint_set/rollback for an example.
160
size_t savepoint_offset;
161
size_t orig_savepoint_offset;
163
void setTransactionReadWrite(Session& session);
174
166
std::string table_definition_ext;
200
192
Used as a protobuf storage currently by TEMP only engines.
202
typedef std::map <std::string, message::Table> ProtoCache;
194
typedef std::map <std::string, drizzled::message::Table> ProtoCache;
203
195
ProtoCache proto_cache;
204
196
pthread_mutex_t proto_cache_mutex;
199
* Implementing classes should override these to provide savepoint
202
virtual int savepoint_set_hook(Session *, void *) { return 0; }
204
virtual int savepoint_rollback_hook(Session *, void *) { return 0; }
206
virtual int savepoint_release_hook(Session *, void *) { return 0; }
207
210
StorageEngine(const std::string name_arg,
208
const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
211
const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS,
212
size_t savepoint_offset_arg= 0,
213
bool support_2pc= false);
210
215
virtual ~StorageEngine();
213
virtual int doGetTableDefinition(Session &session,
214
const drizzled::identifier::Table &identifier,
215
message::Table &table_message)
217
virtual int doGetTableDefinition(Session& session,
220
const char *table_name,
222
drizzled::message::Table *table_proto)
224
234
/* 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;
236
void print_keydup_error(uint32_t key_nr, const char *msg, Table &table);
237
void print_error(int error, myf errflag, Table *table= NULL);
238
virtual bool get_error_message(int error, String *buf);
229
virtual void print_error(int error, myf errflag, const Table& table) const;
240
virtual void print_error(int error, myf errflag, Table& table);
243
each storage engine has it's own memory area (actually a pointer)
244
in the session, for storing per-connection information.
247
session->ha_data[xxx_engine.slot]
249
slot number is initialized by MySQL after xxx_init() is called.
253
inline uint32_t getSlot (void) { return slot; }
254
inline uint32_t getSlot (void) const { return slot; }
255
inline void setSlot (uint32_t value) { slot= value; }
259
return two_phase_commit;
263
bool is_enabled() const
231
268
bool is_user_selectable() const
241
278
// @todo match check_flag interface
242
279
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);
282
void enable() { enabled= true; }
283
void disable() { enabled= false; }
253
* Called during Session::cleanup() for all engines
286
StorageEngine methods:
288
close_connection is only called if
289
session->ha_data[xxx_engine.slot] is non-zero, so even if you don't need
290
this storage area - set it to something, so that MySQL would know
291
this storage engine was accessed in this connection
255
293
virtual int close_connection(Session *)
260
virtual Cursor *create(Table &)= 0;
298
'all' is true if it's a real commit, that makes persistent changes
299
'all' is false if it's not in fact a commit but an end of the
300
statement that is part of the transaction.
301
NOTE 'all' is also false in auto-commit mode where 'end of statement'
302
and 'real commit' mean the same event.
304
virtual int commit(Session *, bool)
309
virtual int rollback(Session *, bool)
315
The void * points to an uninitialized storage area of requested size
316
(see savepoint_offset description)
318
int savepoint_set(Session *session, void *sp)
320
return savepoint_set_hook(session, (unsigned char *)sp+savepoint_offset);
324
The void * points to a storage area, that was earlier passed
325
to the savepoint_set call
327
int savepoint_rollback(Session *session, void *sp)
329
return savepoint_rollback_hook(session,
330
(unsigned char *)sp+savepoint_offset);
333
int savepoint_release(Session *session, void *sp)
335
return savepoint_release_hook(session,
336
(unsigned char *)sp+savepoint_offset);
339
virtual int prepare(Session *, bool) { return 0; }
340
virtual int recover(XID *, uint32_t) { return 0; }
341
virtual int commit_by_xid(XID *) { return 0; }
342
virtual int rollback_by_xid(XID *) { return 0; }
343
virtual Cursor *create(TableShare &, drizzled::memory::Root *)= 0;
345
virtual void drop_database(char*) { }
346
virtual int start_consistent_snapshot(Session *) { return 0; }
262
347
virtual bool flush_logs() { return false; }
263
348
virtual bool show_status(Session *, stat_print_fn *, enum ha_stat_type)
353
virtual int release_temporary_latches(Session *) { return false; }
269
356
If frm_error() is called then we will use this to find out what file
270
357
extentions exist for the storage engine. This is also used by the default
279
366
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; }
369
virtual int doCreateTable(Session *session,
370
const char *table_name,
372
drizzled::message::Table& proto)= 0;
374
virtual int doRenameTable(Session* session,
375
const char *from, const char *to);
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);
380
int renameTable(Session *session, const char *from, const char *to)
382
setTransactionReadWrite(*session);
384
return doRenameTable(session, from, to);
387
// TODO: move these to protected
388
virtual void doGetTableNames(drizzled::CachedDirectory &directory,
389
std::string& db_name,
390
std::set<std::string>& set_of_names);
391
virtual int doDropTable(Session& session,
392
const std::string table_path)= 0;
394
const char *checkLowercaseNames(const char *path, char *tmp_path);
322
396
/* Class Methods for operating on plugin */
323
397
static bool addPlugin(plugin::StorageEngine *engine);
324
398
static void removePlugin(plugin::StorageEngine *engine);
326
static message::table::shared_ptr getTableMessage(Session& session,
327
const drizzled::identifier::Table &identifier,
328
bool include_temporary_tables= true);
329
static bool doesTableExist(Session &session,
330
const drizzled::identifier::Table &identifier,
331
bool include_temporary_tables= true);
333
static plugin::StorageEngine *findByName(const std::string &find_str);
334
static plugin::StorageEngine *findByName(Session& session, const std::string &find_str);
400
static int getTableDefinition(Session& session,
401
TableIdentifier &identifier,
402
message::Table *table_proto= NULL);
403
static int getTableDefinition(Session& session,
406
const char *table_name,
408
message::Table *table_proto= NULL);
410
static plugin::StorageEngine *findByName(std::string find_str);
411
static plugin::StorageEngine *findByName(Session& session,
412
std::string find_str);
336
413
static void closeConnection(Session* session);
337
414
static void dropDatabase(char* path);
415
static int commitOrRollbackByXID(XID *xid, bool commit);
416
static int releaseTemporaryLatches(Session *session);
338
417
static bool flushLogs(plugin::StorageEngine *db_type);
340
static bool dropTable(Session& session,
341
const drizzled::identifier::Table &identifier);
342
static bool dropTable(Session& session,
343
const drizzled::identifier::Table &identifier,
344
drizzled::error_t &error);
346
static bool dropTable(Session& session,
347
StorageEngine &engine,
348
identifier::Table::const_reference identifier,
349
drizzled::error_t &error);
351
static void getIdentifiers(Session &session,
352
const identifier::Schema &schema_identifier,
353
identifier::Table::vector &set_of_identifiers);
355
// Check to see if any SE objects to creation.
356
static bool canCreateTable(const drizzled::identifier::Table &identifier);
358
// @note All schema methods defined here
359
static void getIdentifiers(Session &session, identifier::Schema::vector &schemas);
360
static message::schema::shared_ptr getSchemaDefinition(const drizzled::identifier::Table &identifier);
361
static message::schema::shared_ptr getSchemaDefinition(const drizzled::identifier::Schema &identifier);
362
static bool doesSchemaExist(const drizzled::identifier::Schema &identifier);
363
static const CHARSET_INFO *getSchemaCollation(const drizzled::identifier::Schema &identifier);
364
static bool createSchema(const drizzled::message::Schema &schema_message);
365
static bool dropSchema(Session &session,
366
identifier::Schema::const_reference identifier,
367
message::schema::const_reference schema_message);
368
static bool alterSchema(const drizzled::message::Schema &schema_message);
370
// @note make private/protected
372
virtual void doGetSchemaIdentifiers(identifier::Schema::vector&)
375
virtual drizzled::message::schema::shared_ptr doGetSchemaDefinition(const drizzled::identifier::Schema&)
377
return drizzled::message::schema::shared_ptr();
380
virtual bool doCreateSchema(const drizzled::message::Schema&)
383
virtual bool doAlterSchema(const drizzled::message::Schema&)
386
virtual bool doDropSchema(const drizzled::identifier::Schema&)
418
static int recover(HASH *commit_list);
419
static int startConsistentSnapshot(Session *session);
420
static int dropTable(Session& session,
421
drizzled::TableIdentifier &identifier,
422
bool generate_warning);
423
static void getTableNames(std::string& db_name, std::set<std::string> &set_of_names);
390
425
static inline const std::string &resolveName(const StorageEngine *engine)
392
427
return engine == NULL ? UNKNOWN_STRING : engine->getName();
395
static bool createTable(Session &session,
396
const identifier::Table &identifier,
397
message::Table& table_message);
430
static int createTable(Session& session,
431
drizzled::TableIdentifier &identifier,
432
bool update_create_info,
433
drizzled::message::Table& table_proto,
399
436
static void removeLostTemporaryTables(Session &session, const char *directory);
401
Cursor *getCursor(Table &share);
438
Cursor *getCursor(TableShare &share, drizzled::memory::Root *alloc);
403
440
uint32_t max_record_length() const
404
{ return std::min(HA_MAX_REC_LENGTH, max_supported_record_length()); }
441
{ return std::min((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
405
442
uint32_t max_keys() const
406
{ return std::min(MAX_KEY, max_supported_keys()); }
443
{ return std::min((unsigned int)MAX_KEY, max_supported_keys()); }
407
444
uint32_t max_key_parts() const
408
{ return std::min(MAX_REF_PARTS, max_supported_key_parts()); }
445
{ return std::min((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
409
446
uint32_t max_key_length() const
410
{ return std::min(MAX_KEY_LENGTH, max_supported_key_length()); }
447
{ return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
411
448
uint32_t max_key_part_length(void) const
412
{ return std::min(MAX_KEY_LENGTH, max_supported_key_part_length()); }
449
{ return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
414
451
virtual uint32_t max_supported_record_length(void) const
415
452
{ return HA_MAX_REC_LENGTH; }