1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
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/definitions.h>
25
#include <drizzled/sql_plugin.h>
26
#include <drizzled/handler_structs.h>
38
typedef struct st_mysql_lex_string LEX_STRING;
39
typedef bool (stat_print_fn)(Session *session, const char *type, uint32_t type_len,
40
const char *file, uint32_t file_len,
41
const char *status, uint32_t status_len);
42
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
44
/* Possible flags of a StorageEngine (there can be 32 of them) */
45
enum engine_flag_bits {
46
HTON_BIT_CLOSE_CURSORS_AT_COMMIT,
47
HTON_BIT_ALTER_NOT_SUPPORTED, // Engine does not support alter
48
HTON_BIT_CAN_RECREATE, // Delete all is used for truncate
49
HTON_BIT_HIDDEN, // Engine does not appear in lists
50
HTON_BIT_FLUSH_AFTER_RENAME,
51
HTON_BIT_NOT_USER_SELECTABLE,
52
HTON_BIT_TEMPORARY_NOT_SUPPORTED, // Having temporary tables not supported
53
HTON_BIT_TEMPORARY_ONLY,
57
static const std::bitset<HTON_BIT_SIZE> HTON_NO_FLAGS(0);
58
static const std::bitset<HTON_BIT_SIZE> HTON_CLOSE_CURSORS_AT_COMMIT(1 << HTON_BIT_CLOSE_CURSORS_AT_COMMIT);
59
static const std::bitset<HTON_BIT_SIZE> HTON_ALTER_NOT_SUPPORTED(1 << HTON_BIT_ALTER_NOT_SUPPORTED);
60
static const std::bitset<HTON_BIT_SIZE> HTON_CAN_RECREATE(1 << HTON_BIT_CAN_RECREATE);
61
static const std::bitset<HTON_BIT_SIZE> HTON_HIDDEN(1 << HTON_BIT_HIDDEN);
62
static const std::bitset<HTON_BIT_SIZE> HTON_FLUSH_AFTER_RENAME(1 << HTON_BIT_FLUSH_AFTER_RENAME);
63
static const std::bitset<HTON_BIT_SIZE> HTON_NOT_USER_SELECTABLE(1 << HTON_BIT_NOT_USER_SELECTABLE);
64
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_NOT_SUPPORTED(1 << HTON_BIT_TEMPORARY_NOT_SUPPORTED);
65
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_ONLY(1 << HTON_BIT_TEMPORARY_ONLY);
70
StorageEngine is a singleton structure - one instance per storage engine -
71
to provide access to storage engine functionality that works on the
72
"global" level (unlike handler class that works on a per-table basis)
74
usually StorageEngine instance is defined statically in ha_xxx.cc as
76
static StorageEngine { ... } xxx_engine;
78
savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
83
Name used for storage engine.
85
const std::string name;
86
const bool two_phase_commit;
89
const std::bitset<HTON_BIT_SIZE> flags; /* global handler flags */
91
to store per-savepoint data storage engine is provided with an area
92
of a requested size (0 is ok here).
93
savepoint_offset must be initialized statically to the size of
94
the needed memory to store per-savepoint information.
95
After xxx_init it is changed to be an offset to savepoint storage
96
area and need not be used by storage engine.
97
see binlog_engine and binlog_savepoint_set/rollback for an example.
99
size_t savepoint_offset;
100
size_t orig_savepoint_offset;
101
std::vector<std::string> aliases;
103
void setTransactionReadWrite(Session* session);
108
* Implementing classes should override these to provide savepoint
111
virtual int savepoint_set_hook(Session *, void *) { return 0; }
113
virtual int savepoint_rollback_hook(Session *, void *) { return 0; }
115
virtual int savepoint_release_hook(Session *, void *) { return 0; }
119
StorageEngine(const std::string name_arg,
120
const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS,
121
size_t savepoint_offset_arg= 0,
122
bool support_2pc= false);
124
virtual ~StorageEngine();
127
each storage engine has it's own memory area (actually a pointer)
128
in the session, for storing per-connection information.
131
session->ha_data[xxx_engine.slot]
133
slot number is initialized by MySQL after xxx_init() is called.
137
inline uint32_t getSlot (void) { return slot; }
138
inline void setSlot (uint32_t value) { slot= value; }
140
const std::vector<std::string>& getAliases()
145
void addAlias(std::string alias)
147
aliases.push_back(alias);
152
return two_phase_commit;
156
bool is_enabled() const
161
bool is_user_selectable() const
163
return not flags.test(HTON_BIT_NOT_USER_SELECTABLE);
166
bool check_flag(const engine_flag_bits flag) const
168
return flags.test(flag);
171
void enable() { enabled= true; }
172
void disable() { enabled= false; }
174
std::string getName() const { return name; }
177
StorageEngine methods:
179
close_connection is only called if
180
session->ha_data[xxx_engine.slot] is non-zero, so even if you don't need
181
this storage area - set it to something, so that MySQL would know
182
this storage engine was accessed in this connection
184
virtual int close_connection(Session *)
189
'all' is true if it's a real commit, that makes persistent changes
190
'all' is false if it's not in fact a commit but an end of the
191
statement that is part of the transaction.
192
NOTE 'all' is also false in auto-commit mode where 'end of statement'
193
and 'real commit' mean the same event.
195
virtual int commit(Session *, bool)
200
virtual int rollback(Session *, bool)
206
The void * points to an uninitialized storage area of requested size
207
(see savepoint_offset description)
209
int savepoint_set(Session *session, void *sp)
211
return savepoint_set_hook(session, (unsigned char *)sp+savepoint_offset);
215
The void * points to a storage area, that was earlier passed
216
to the savepoint_set call
218
int savepoint_rollback(Session *session, void *sp)
220
return savepoint_rollback_hook(session,
221
(unsigned char *)sp+savepoint_offset);
224
int savepoint_release(Session *session, void *sp)
226
return savepoint_release_hook(session,
227
(unsigned char *)sp+savepoint_offset);
230
virtual int prepare(Session *, bool) { return 0; }
231
virtual int recover(XID *, uint32_t) { return 0; }
232
virtual int commit_by_xid(XID *) { return 0; }
233
virtual int rollback_by_xid(XID *) { return 0; }
234
virtual handler *create(TableShare *, MEM_ROOT *)= 0;
236
virtual void drop_database(char*) { }
237
virtual int start_consistent_snapshot(Session *) { return 0; }
238
virtual bool flush_logs() { return false; }
239
virtual bool show_status(Session *, stat_print_fn *, enum ha_stat_type)
244
/* args: current_session, tables, cond */
245
virtual int fill_files_table(Session *, TableList *,
246
Item *) { return 0; }
247
virtual int release_temporary_latches(Session *) { return false; }
249
/* args: current_session, db, name */
250
virtual int table_exists_in_engine(Session*, const char *, const char *);
253
If frm_error() is called then we will use this to find out what file
254
extentions exist for the storage engine. This is also used by the default
255
rename_table and delete_table method in handler.cc.
257
For engines that have two file name extentions (separate meta/index file
258
and data file), the order of elements is relevant. First element of engine
259
file name extentions array should be meta/index file extention. Second
260
element - data file extention. This order is assumed by
261
prepare_for_repair() when REPAIR Table ... USE_FRM is issued.
263
virtual const char **bas_ext() const =0;
266
virtual int createTableImpl(Session *session, const char *table_name,
268
HA_CREATE_INFO *create_info)= 0;
270
virtual int renameTableImpl(Session* session, const char *from, const char *to);
272
virtual int deleteTableImpl(Session* session, const std::string table_path);
275
int createTable(Session *session, const char *table_name, Table *table_arg,
276
HA_CREATE_INFO *create_info) {
277
setTransactionReadWrite(session);
279
return createTableImpl(session, table_name, table_arg, create_info);
282
int renameTable(Session *session, const char *from, const char *to) {
283
setTransactionReadWrite(session);
285
return renameTableImpl(session, from, to);
288
int deleteTable(Session* session, const std::string table_path) {
289
setTransactionReadWrite(session);
291
return deleteTableImpl(session, table_path);
296
StorageEngine *ha_default_storage_engine(Session *session);
297
StorageEngine *ha_resolve_by_name(Session *session, const LEX_STRING *name);
298
handler *get_new_handler(TableShare *share, MEM_ROOT *alloc,
299
StorageEngine *db_type);
300
const std::string ha_resolve_storage_engine_name(const StorageEngine *db_type);
302
#endif /* DRIZZLED_PLUGIN_STORAGE_ENGINE_H */