21
21
#include <drizzled/definitions.h>
22
22
#include <drizzled/base.h>
23
23
#include <drizzled/handler.h>
24
#include <drizzled/handlerton.h>
24
#include <drizzled/plugin/storage_engine.h>
25
25
#include <drizzled/session.h>
26
26
#include <drizzled/error.h>
27
27
#include <drizzled/gettext.h>
32
32
While we have legacy_db_type, we have this array to
33
check for dups and to find handlerton from legacy_db_type.
33
check for dups and to find StorageEngine from legacy_db_type.
34
34
Remove when legacy_db_type is finally gone
36
st_plugin_int *hton2plugin[MAX_HA];
36
st_plugin_int *engine2plugin[MAX_HA];
38
static handlerton *installed_htons[128];
38
static StorageEngine *installed_engines[128];
40
40
static const LEX_STRING sys_table_aliases[]=
47
/* args: current_session, db, name */
48
int StorageEngine::table_exists_in_engine(Session*, const char *, const char *)
50
return HA_ERR_NO_SUCH_TABLE;
48
handlerton *ha_resolve_by_legacy_type(Session *session,
53
StorageEngine *ha_resolve_by_legacy_type(Session *session,
49
54
enum legacy_db_type db_type)
53
58
case DB_TYPE_DEFAULT:
54
return ha_default_handlerton(session);
59
return ha_default_storage_engine(session);
56
61
if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT &&
57
(plugin= ha_lock_engine(session, installed_htons[db_type])))
58
return plugin_data(plugin, handlerton*);
62
(plugin= ha_lock_engine(session, installed_engines[db_type])))
63
return plugin_data(plugin, StorageEngine*);
60
65
case DB_TYPE_UNKNOWN:
75
Return the default storage engine handlerton for thread
80
Return the default storage engine StorageEngine for thread
77
@param ha_default_handlerton(session)
82
@param ha_default_storage_engine(session)
78
83
@param session current thread
86
pointer to StorageEngine
83
handlerton *ha_default_handlerton(Session *session)
88
StorageEngine *ha_default_storage_engine(Session *session)
85
90
plugin_ref plugin= ha_default_plugin(session);
87
handlerton *hton= plugin_data(plugin, handlerton*);
92
StorageEngine *engine= plugin_data(plugin, StorageEngine*);
94
Return the storage engine handlerton for the supplied name
99
Return the storage engine StorageEngine for the supplied name
96
101
@param session current thread
97
102
@param name name of storage engine
114
119
if ((plugin= my_plugin_lock_by_name(session, name, DRIZZLE_STORAGE_ENGINE_PLUGIN)))
116
handlerton *hton= plugin_data(plugin, handlerton *);
117
if (!(hton->flags.test(HTON_BIT_NOT_USER_SELECTABLE)))
121
StorageEngine *engine= plugin_data(plugin, StorageEngine *);
122
if (!(engine->flags.test(HTON_BIT_NOT_USER_SELECTABLE)))
158
163
Use other database handler if databasehandler is not compiled in.
160
handlerton *ha_checktype(Session *session, enum legacy_db_type database_type,
165
StorageEngine *ha_checktype(Session *session, enum legacy_db_type database_type,
161
166
bool no_substitute, bool report_error)
163
handlerton *hton= ha_resolve_by_legacy_type(session, database_type);
164
if (ha_storage_engine_is_enabled(hton))
168
StorageEngine *engine= ha_resolve_by_legacy_type(session, database_type);
169
if (ha_storage_engine_is_enabled(engine))
167
172
if (no_substitute)
169
174
if (report_error)
171
const char *engine_name= ha_resolve_storage_engine_name(hton);
176
const char *engine_name= ha_resolve_storage_engine_name(engine);
172
177
my_error(ER_FEATURE_DISABLED,MYF(0),engine_name,engine_name);
177
return ha_default_handlerton(session);
182
return ha_default_storage_engine(session);
178
183
} /* ha_checktype */
181
186
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
187
StorageEngine *engine)
186
if (db_type && db_type->state == SHOW_OPTION_YES && db_type->create)
191
if (engine && engine->state == SHOW_OPTION_YES)
188
if ((file= db_type->create(db_type, share, alloc)))
193
if ((file= engine->create(share, alloc)))
194
199
Here the call to current_session() is ok as we call this function a lot of
195
200
times but we enter this branch very seldom.
197
return(get_new_handler(share, alloc, ha_default_handlerton(current_session)));
202
return(get_new_handler(share, alloc, ha_default_storage_engine(current_session)));
201
int ha_finalize_handlerton(st_plugin_int *plugin)
206
int storage_engine_finalizer(st_plugin_int *plugin)
203
handlerton *hton= (handlerton *)plugin->data;
208
StorageEngine *engine= static_cast<StorageEngine *>(plugin->data);
210
switch (engine->state)
207
212
case SHOW_OPTION_NO:
208
213
case SHOW_OPTION_DISABLED:
210
215
case SHOW_OPTION_YES:
211
if (installed_htons[hton->db_type] == hton)
212
installed_htons[hton->db_type]= NULL;
216
if (installed_engines[engine->db_type] == engine)
217
installed_engines[engine->db_type]= NULL;
216
if (hton && plugin->plugin->deinit)
217
(void)plugin->plugin->deinit(hton);
219
free((unsigned char*)hton);
221
if (engine && plugin->plugin->deinit)
222
(void)plugin->plugin->deinit(engine);
225
int ha_initialize_handlerton(st_plugin_int *plugin)
228
int storage_engine_initializer(st_plugin_int *plugin)
229
hton= (handlerton *)malloc(sizeof(handlerton));
230
memset(hton, 0, sizeof(handlerton));
232
/* Historical Requirement */
233
plugin->data= hton; // shortcut for the future
230
StorageEngine *engine;
234
233
if (plugin->plugin->init)
236
if (plugin->plugin->init(hton))
235
if (plugin->plugin->init(&engine))
238
errmsg_printf(ERRMSG_LVL_ERROR, _("Plugin '%s' init function returned error."),
237
errmsg_printf(ERRMSG_LVL_ERROR,
238
_("Plugin '%s' init function returned error."),
244
hton->name= plugin->name.str;
244
engine->name= plugin->name.str;
247
the switch below and hton->state should be removed when
247
the switch below and engine->state should be removed when
248
248
command-line options for plugins will be implemented
250
switch (hton->state) {
250
switch (engine->state) {
251
251
case SHOW_OPTION_NO:
253
253
case SHOW_OPTION_YES:
256
256
/* now check the db_type for conflict */
257
if (hton->db_type <= DB_TYPE_UNKNOWN ||
258
hton->db_type >= DB_TYPE_DEFAULT ||
259
installed_htons[hton->db_type])
257
if (engine->db_type <= DB_TYPE_UNKNOWN ||
258
engine->db_type >= DB_TYPE_DEFAULT ||
259
installed_engines[engine->db_type])
261
261
int idx= (int) DB_TYPE_FIRST_DYNAMIC;
263
while (idx < (int) DB_TYPE_DEFAULT && installed_htons[idx])
263
while (idx < (int) DB_TYPE_DEFAULT && installed_engines[idx])
266
266
if (idx == (int) DB_TYPE_DEFAULT)
268
268
errmsg_printf(ERRMSG_LVL_WARN, _("Too many storage engines!"));
271
if (hton->db_type != DB_TYPE_UNKNOWN)
271
if (engine->db_type != DB_TYPE_UNKNOWN)
272
272
errmsg_printf(ERRMSG_LVL_WARN,
273
273
_("Storage engine '%s' has conflicting typecode. Assigning value %d."),
274
274
plugin->plugin->name, idx);
275
hton->db_type= (enum legacy_db_type) idx;
275
engine->db_type= (enum legacy_db_type) idx;
277
installed_htons[hton->db_type]= hton;
278
tmp= hton->savepoint_offset;
279
hton->savepoint_offset= savepoint_alloc_size;
277
installed_engines[engine->db_type]= engine;
278
tmp= engine->savepoint_offset;
279
engine->savepoint_offset= savepoint_alloc_size;
280
280
savepoint_alloc_size+= tmp;
281
hton->slot= total_ha++;
282
hton2plugin[hton->slot]=plugin;
281
engine->slot= total_ha++;
282
engine2plugin[engine->slot]=plugin;
283
if (engine->has_2pc())
287
287
/* fall through */
289
hton->state= SHOW_OPTION_DISABLED;
289
engine->state= SHOW_OPTION_DISABLED;
294
This is entirely for legacy. We will create a new "disk based" hton and a
295
"memory" hton which will be configurable longterm. We should be able to
294
This is entirely for legacy. We will create a new "disk based" engine and a
295
"memory" engine which will be configurable longterm. We should be able to
296
296
remove partition and myisammrg.
298
298
if (strcmp(plugin->plugin->name, "MEMORY") == 0)
301
301
if (strcmp(plugin->plugin->name, "MyISAM") == 0)
302
myisam_engine= engine;
304
plugin->data= engine;
304
305
plugin->state= PLUGIN_IS_READY;
311
enum legacy_db_type ha_legacy_type(const handlerton *db_type)
310
enum legacy_db_type ha_legacy_type(const StorageEngine *db_type)
313
312
return (db_type == NULL) ? DB_TYPE_UNKNOWN : db_type->db_type;
316
const char *ha_resolve_storage_engine_name(const handlerton *db_type)
315
const char *ha_resolve_storage_engine_name(const StorageEngine *db_type)
318
return db_type == NULL ? "UNKNOWN" : hton2plugin[db_type->slot]->name.str;
317
return db_type == NULL ? "UNKNOWN" : engine2plugin[db_type->slot]->name.str;
321
bool ha_check_storage_engine_flag(const handlerton *db_type, const hton_flag_bits flag)
320
bool ha_check_storage_engine_flag(const StorageEngine *db_type, const engine_flag_bits flag)
323
322
return db_type == NULL ? false : db_type->flags.test(static_cast<size_t>(flag));
326
bool ha_storage_engine_is_enabled(const handlerton *db_type)
325
bool ha_storage_engine_is_enabled(const StorageEngine *db_type)
328
return (db_type && db_type->create) ?
329
328
(db_type->state == SHOW_OPTION_YES) : false;
332
LEX_STRING *ha_storage_engine_name(const handlerton *hton)
331
LEX_STRING *ha_storage_engine_name(const StorageEngine *engine)
334
return &hton2plugin[hton->slot]->name;
333
return &engine2plugin[engine->slot]->name;