132
130
usually StorageEngine instance is defined statically in ha_xxx.cc as
134
132
static StorageEngine { ... } xxx_engine;
134
savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
136
class StorageEngine : public Plugin,
137
public MonitoredInTransaction
136
class StorageEngine : public Plugin
140
139
typedef uint64_t Table_flags;
144
Name used for storage engine.
146
const bool two_phase_commit;
143
149
const std::bitset<HTON_BIT_SIZE> flags; /* global Cursor flags */
145
static EngineVector &getSchemaEngines();
147
virtual void setTransactionReadWrite(Session& session);
150
* Indicates to a storage engine the start of a
153
virtual void doStartStatement(Session *session)
159
* Indicates to a storage engine the end of
160
* the current SQL statement in the supplied
163
virtual void doEndStatement(Session *session)
151
void setTransactionReadWrite(Session& session);
169
154
std::string table_definition_ext;
198
183
ProtoCache proto_cache;
199
184
pthread_mutex_t proto_cache_mutex;
187
* Implementing classes should override these to provide savepoint
190
virtual int savepoint_set_hook(Session *, NamedSavepoint &) { return 0; }
192
virtual int savepoint_rollback_hook(Session *, NamedSavepoint &) { return 0; }
194
virtual int savepoint_release_hook(Session *, NamedSavepoint &) { return 0; }
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);
206
202
virtual ~StorageEngine();
208
virtual int doGetTableDefinition(Session &session,
209
const drizzled::TableIdentifier &identifier,
210
message::Table &table_message)
204
virtual int doGetTableDefinition(Session& session,
207
const char *table_name,
209
message::Table *table_proto)
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)
241
doStartStatement(session);
243
virtual void endStatement(Session *session)
245
doEndStatement(session);
269
void enable() { enabled= true; }
270
void disable() { enabled= false; }
249
* Called during Session::cleanup() for all engines
273
StorageEngine methods:
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
251
280
virtual int close_connection(Session *)
255
virtual Cursor *create(Table &)= 0;
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.
291
virtual int commit(Session *, bool)
296
virtual int rollback(Session *, bool)
302
The void * points to an uninitialized storage area of requested size
303
(see savepoint_offset description)
305
int savepoint_set(Session *session, NamedSavepoint &sp)
307
return savepoint_set_hook(session, sp);
311
The void * points to a storage area, that was earlier passed
312
to the savepoint_set call
314
int savepoint_rollback(Session *session, NamedSavepoint &sp)
316
return savepoint_rollback_hook(session, sp);
319
int savepoint_release(Session *session, NamedSavepoint &sp)
321
return savepoint_release_hook(session, sp);
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;
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)
338
virtual int release_temporary_latches(Session *) { return false; }
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;
277
virtual int doCreateTable(Session &session,
279
const drizzled::TableIdentifier &identifier,
280
message::Table &message)= 0;
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,
357
message::Table& proto)= 0;
359
virtual int doRenameTable(Session* session,
360
const char *from, const char *to);
287
int renameTable(Session &session, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to);
289
virtual void doGetTableIdentifiers(CachedDirectory &directory,
290
const drizzled::SchemaIdentifier &schema_identifier,
291
TableIdentifier::vector &set_of_identifiers)= 0;
293
virtual int doDropTable(Session &session,
294
const drizzled::TableIdentifier &identifier)= 0;
365
int renameTable(Session *session, const char *from, const char *to)
367
setTransactionReadWrite(*session);
369
return doRenameTable(session, from, to);
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;
379
const char *checkLowercaseNames(const char *path, char *tmp_path);
296
381
/* Class Methods for operating on plugin */
297
382
static bool addPlugin(plugin::StorageEngine *engine);
298
383
static void removePlugin(plugin::StorageEngine *engine);
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);
308
virtual bool doDoesTableExist(Session& session, const drizzled::TableIdentifier &identifier);
310
static plugin::StorageEngine *findByName(const std::string &find_str);
311
static plugin::StorageEngine *findByName(Session& session, const std::string &find_str);
386
TableIdentifier &identifier,
387
message::Table *table_proto= NULL);
388
static int getTableDefinition(Session& session,
391
const char *table_name,
393
message::Table *table_proto= NULL);
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);
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);
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);
340
// @note make private/protected
341
virtual void doGetSchemaIdentifiers(SchemaIdentifier::vector&)
344
virtual bool doGetSchemaDefinition(const drizzled::SchemaIdentifier&, drizzled::message::schema::shared_ptr&)
349
virtual bool doCreateSchema(const drizzled::message::Schema&)
352
virtual bool doAlterSchema(const drizzled::message::Schema&)
355
virtual bool doDropSchema(const drizzled::SchemaIdentifier&)
411
static void getSchemaNames(std::set<std::string>& set_of_names);
412
static bool getSchemaDefinition(const std::string &schema_name, message::Schema &proto);
358
415
static inline const std::string &resolveName(const StorageEngine *engine)
387
446
virtual uint32_t max_supported_key_part_length(void) const { return 255; }
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);
397
* The below are simple virtual overrides for the plugin::MonitoredInTransaction
400
virtual bool participatesInSqlTransaction() const
402
return false; /* plugin::StorageEngine is non-transactional in terms of SQL */
404
virtual bool participatesInXaTransaction() const
406
return false; /* plugin::StorageEngine is non-transactional in terms of XA */
408
virtual bool alwaysRegisterForXaTransaction() const
413
virtual bool validateCreateTableOption(const std::string &key, const std::string &state)
421
virtual bool validateCreateSchemaOption(const std::string &key, const std::string &state)
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);
430
455
} /* namespace plugin */