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_HANDLERTON_H
21
#define DRIZZLED_HANDLERTON_H
26
#include <drizzled/definitions.h>
27
#include <drizzled/sql_plugin.h>
35
typedef struct st_mysql_lex_string LEX_STRING;
36
typedef bool (stat_print_fn)(Session *session, const char *type, uint32_t type_len,
37
const char *file, uint32_t file_len,
38
const char *status, uint32_t status_len);
39
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
41
/* Possible flags of a handlerton (there can be 32 of them) */
43
HTON_BIT_CLOSE_CURSORS_AT_COMMIT,
44
HTON_BIT_ALTER_NOT_SUPPORTED, // Engine does not support alter
45
HTON_BIT_CAN_RECREATE, // Delete all is used for truncate
46
HTON_BIT_HIDDEN, // Engine does not appear in lists
47
HTON_BIT_FLUSH_AFTER_RENAME,
48
HTON_BIT_NOT_USER_SELECTABLE,
49
HTON_BIT_TEMPORARY_NOT_SUPPORTED, // Having temporary tables not supported
50
HTON_BIT_SUPPORT_LOG_TABLES, // Engine supports log tables
51
HTON_BIT_NO_PARTITION, // You can not partition these tables
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);
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);
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);
61
static const std::bitset<HTON_BIT_SIZE> HTON_NOT_USER_SELECTABLE(1 << HTON_BIT_NOT_USER_SELECTABLE);
62
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_NOT_SUPPORTED(1 << HTON_BIT_TEMPORARY_NOT_SUPPORTED);
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);
67
handlerton is a singleton structure - one instance per storage engine -
68
to provide access to storage engine functionality that works on the
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.
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
handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root);
148
void (*drop_database)(handlerton *hton, char* path);
149
int (*start_consistent_snapshot)(handlerton *hton, Session *session);
150
bool (*flush_logs)(handlerton *hton);
151
bool (*show_status)(handlerton *hton, Session *session, stat_print_fn *print, enum ha_stat_type stat);
152
int (*fill_files_table)(handlerton *hton, Session *session,
155
std::bitset<HTON_BIT_SIZE> flags; /* global handler flags */
156
int (*release_temporary_latches)(handlerton *hton, Session *session);
158
int (*table_exists_in_engine)(handlerton *hton, Session* session, const char *db,
160
uint32_t license; /* Flag for Engine License */
161
void *data; /* Location for engines to keep personal structures */
166
handlerton *ha_default_handlerton(Session *session);
167
plugin_ref ha_resolve_by_name(Session *session, const LEX_STRING *name);
168
plugin_ref ha_lock_engine(Session *session, handlerton *hton);
169
handlerton *ha_resolve_by_legacy_type(Session *session,
170
enum legacy_db_type db_type);
171
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
172
handlerton *db_type);
173
handlerton *ha_checktype(Session *session, enum legacy_db_type database_type,
174
bool no_substitute, bool report_error);
176
enum legacy_db_type ha_legacy_type(const handlerton *db_type);
177
const char *ha_resolve_storage_engine_name(const handlerton *db_type);
178
bool ha_check_storage_engine_flag(const handlerton *db_type, const hton_flag_bits flag);
179
bool ha_storage_engine_is_enabled(const handlerton *db_type);
180
LEX_STRING *ha_storage_engine_name(const handlerton *hton);
182
#endif /* DRIZZLED_HANDLERTON_H */