2000-07-31 21:29:14 +02:00
|
|
|
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
2001-12-06 13:10:51 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
|
|
|
|
/* Handler-calling-functions */
|
|
|
|
|
2005-05-26 12:09:14 +02:00
|
|
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
2000-07-31 21:29:14 +02:00
|
|
|
#pragma implementation // gcc: Class implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "mysql_priv.h"
|
2005-12-22 06:39:02 +01:00
|
|
|
#include "rpl_filter.h"
|
2000-07-31 21:29:14 +02:00
|
|
|
#include "ha_heap.h"
|
|
|
|
#include "ha_myisam.h"
|
|
|
|
#include "ha_myisammrg.h"
|
2005-10-04 03:42:30 +02:00
|
|
|
|
|
|
|
|
2005-11-07 16:25:06 +01:00
|
|
|
#include <myisampack.h>
|
|
|
|
#include <errno.h>
|
2005-12-22 06:39:02 +01:00
|
|
|
|
2005-11-07 16:25:06 +01:00
|
|
|
#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
|
|
|
|
#define NDB_MAX_ATTRIBUTES_IN_TABLE 128
|
2004-04-15 09:14:14 +02:00
|
|
|
#include "ha_ndbcluster.h"
|
|
|
|
#endif
|
2006-04-13 22:49:29 +02:00
|
|
|
|
2005-11-07 16:25:06 +01:00
|
|
|
#ifdef WITH_PARTITION_STORAGE_ENGINE
|
|
|
|
#include "ha_partition.h"
|
2004-12-11 21:03:51 +01:00
|
|
|
#endif
|
2005-12-22 06:39:02 +01:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
#ifdef WITH_INNOBASE_STORAGE_ENGINE
|
|
|
|
#include "ha_innodb.h"
|
|
|
|
#endif
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2006-04-20 19:03:15 +02:00
|
|
|
/* While we have legacy_db_type, we have this array to
|
|
|
|
check for dups and to find handlerton from legacy_db_type.
|
|
|
|
Remove when legacy_db_type is finally gone */
|
2006-04-13 22:49:29 +02:00
|
|
|
static handlerton *installed_htons[128];
|
2006-05-31 18:07:32 +02:00
|
|
|
st_plugin_int *hton2plugin[MAX_HA];
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
#define BITMAP_STACKBUF_SIZE (128/8)
|
|
|
|
|
2006-05-03 18:40:52 +02:00
|
|
|
KEY_CREATE_INFO default_key_create_info= { HA_KEY_ALG_UNDEF, 0, {NullS,0} };
|
2006-05-03 14:59:17 +02:00
|
|
|
|
2005-10-04 03:42:30 +02:00
|
|
|
/* static functions defined in this file */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
static handler *create_default(TABLE_SHARE *table);
|
|
|
|
|
2003-12-02 21:23:13 +01:00
|
|
|
static SHOW_COMP_OPTION have_yes= SHOW_OPTION_YES;
|
2005-01-27 22:38:56 +01:00
|
|
|
|
|
|
|
/* number of entries in handlertons[] */
|
2006-05-28 14:51:01 +02:00
|
|
|
ulong total_ha= 0;
|
2005-01-27 22:38:56 +01:00
|
|
|
/* number of storage engines (from handlertons[]) that support 2pc */
|
2006-05-28 14:51:01 +02:00
|
|
|
ulong total_ha_2pc= 0;
|
2005-01-27 22:38:56 +01:00
|
|
|
/* size of savepoint storage area (see ha_init) */
|
2006-05-28 14:51:01 +02:00
|
|
|
ulong savepoint_alloc_size= 0;
|
2005-01-16 13:16:23 +01:00
|
|
|
|
2005-09-19 21:06:23 +02:00
|
|
|
struct show_table_alias_st sys_table_aliases[]=
|
|
|
|
{
|
2005-12-21 19:18:40 +01:00
|
|
|
{"INNOBASE", DB_TYPE_INNODB},
|
|
|
|
{"NDB", DB_TYPE_NDBCLUSTER},
|
|
|
|
{"BDB", DB_TYPE_BERKELEY_DB},
|
|
|
|
{"HEAP", DB_TYPE_HEAP},
|
|
|
|
{"MERGE", DB_TYPE_MRG_MYISAM},
|
|
|
|
{NullS, DB_TYPE_UNKNOWN}
|
2002-07-23 17:31:22 +02:00
|
|
|
};
|
2001-03-23 19:38:42 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
const char *ha_row_type[] = {
|
2005-01-07 15:43:27 +01:00
|
|
|
"", "FIXED", "DYNAMIC", "COMPRESSED", "REDUNDANT", "COMPACT", "?","?","?"
|
2000-07-31 21:29:14 +02:00
|
|
|
};
|
|
|
|
|
2001-03-21 00:02:22 +01:00
|
|
|
const char *tx_isolation_names[] =
|
2001-03-23 19:38:42 +01:00
|
|
|
{ "READ-UNCOMMITTED", "READ-COMMITTED", "REPEATABLE-READ", "SERIALIZABLE",
|
|
|
|
NullS};
|
|
|
|
TYPELIB tx_isolation_typelib= {array_elements(tx_isolation_names)-1,"",
|
2004-10-25 14:51:26 +02:00
|
|
|
tx_isolation_names, NULL};
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2004-11-10 16:07:11 +01:00
|
|
|
static TYPELIB known_extensions= {0,"known_exts", NULL, NULL};
|
2004-11-10 23:36:18 +01:00
|
|
|
uint known_extensions_id= 0;
|
2004-11-10 16:07:11 +01:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
handlerton *ha_resolve_by_name(THD *thd, LEX_STRING *name)
|
2003-12-02 21:23:13 +01:00
|
|
|
{
|
2005-09-19 21:06:23 +02:00
|
|
|
show_table_alias_st *table_alias;
|
2005-12-21 19:18:40 +01:00
|
|
|
st_plugin_int *plugin;
|
2005-09-19 21:06:23 +02:00
|
|
|
|
2005-10-10 20:01:45 +02:00
|
|
|
if (thd && !my_strnncoll(&my_charset_latin1,
|
2005-12-21 19:18:40 +01:00
|
|
|
(const uchar *)name->str, name->length,
|
2005-10-13 18:40:46 +02:00
|
|
|
(const uchar *)"DEFAULT", 7))
|
2005-12-21 19:18:40 +01:00
|
|
|
return ha_resolve_by_legacy_type(thd, DB_TYPE_DEFAULT);
|
2005-01-27 22:38:56 +01:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
if ((plugin= plugin_lock(name, MYSQL_STORAGE_ENGINE_PLUGIN)))
|
2003-12-02 21:23:13 +01:00
|
|
|
{
|
2006-05-31 18:07:32 +02:00
|
|
|
handlerton *hton= (handlerton *)plugin->data;
|
2005-12-21 19:18:40 +01:00
|
|
|
if (!(hton->flags & HTON_NOT_USER_SELECTABLE))
|
|
|
|
return hton;
|
|
|
|
plugin_unlock(plugin);
|
2003-12-02 21:23:13 +01:00
|
|
|
}
|
2005-01-27 22:38:56 +01:00
|
|
|
|
2005-09-19 21:06:23 +02:00
|
|
|
/*
|
2005-09-23 01:58:09 +02:00
|
|
|
We check for the historical aliases.
|
2005-09-19 21:06:23 +02:00
|
|
|
*/
|
|
|
|
for (table_alias= sys_table_aliases; table_alias->type; table_alias++)
|
2003-12-02 21:23:13 +01:00
|
|
|
{
|
2005-10-10 20:01:45 +02:00
|
|
|
if (!my_strnncoll(&my_charset_latin1,
|
2005-12-21 19:18:40 +01:00
|
|
|
(const uchar *)name->str, name->length,
|
2005-10-13 18:40:46 +02:00
|
|
|
(const uchar *)table_alias->alias,
|
|
|
|
strlen(table_alias->alias)))
|
2005-12-21 19:18:40 +01:00
|
|
|
return ha_resolve_by_legacy_type(thd, table_alias->type);
|
2003-12-02 21:23:13 +01:00
|
|
|
}
|
2005-09-23 01:58:09 +02:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
return NULL;
|
2003-12-02 21:23:13 +01:00
|
|
|
}
|
2005-10-11 23:58:22 +02:00
|
|
|
|
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
const char *ha_get_storage_engine(enum legacy_db_type db_type)
|
2005-10-01 01:26:48 +02:00
|
|
|
{
|
2005-12-21 19:18:40 +01:00
|
|
|
switch (db_type)
|
2005-10-01 01:26:48 +02:00
|
|
|
{
|
2005-12-21 19:18:40 +01:00
|
|
|
case DB_TYPE_DEFAULT:
|
|
|
|
return "DEFAULT";
|
|
|
|
case DB_TYPE_UNKNOWN:
|
|
|
|
return "UNKNOWN";
|
|
|
|
default:
|
2006-04-13 22:49:29 +02:00
|
|
|
if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT &&
|
|
|
|
installed_htons[db_type])
|
2006-05-31 18:07:32 +02:00
|
|
|
return hton2plugin[installed_htons[db_type]->slot]->name.str;
|
2005-12-21 19:18:40 +01:00
|
|
|
return "*NONE*";
|
2005-10-01 01:26:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
static handler *create_default(TABLE_SHARE *table)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2005-12-21 19:18:40 +01:00
|
|
|
handlerton *hton=ha_resolve_by_legacy_type(current_thd, DB_TYPE_DEFAULT);
|
2006-05-28 14:51:01 +02:00
|
|
|
return (hton && hton->create) ? hton->create(table) : NULL;
|
2005-12-21 19:18:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type)
|
|
|
|
{
|
|
|
|
switch (db_type)
|
2004-03-02 11:08:50 +01:00
|
|
|
{
|
2005-12-21 19:18:40 +01:00
|
|
|
case DB_TYPE_DEFAULT:
|
|
|
|
return (thd->variables.table_type != NULL) ?
|
|
|
|
thd->variables.table_type :
|
|
|
|
(global_system_variables.table_type != NULL ?
|
|
|
|
global_system_variables.table_type : &myisam_hton);
|
|
|
|
case DB_TYPE_UNKNOWN:
|
|
|
|
return NULL;
|
|
|
|
default:
|
2006-04-13 22:49:29 +02:00
|
|
|
if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT)
|
|
|
|
return installed_htons[db_type];
|
2006-05-28 14:51:01 +02:00
|
|
|
return NULL;
|
2004-03-02 11:08:50 +01:00
|
|
|
}
|
2005-04-14 03:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-03 04:44:28 +02:00
|
|
|
/* Use other database handler if databasehandler is not compiled in */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
|
2005-06-17 23:14:44 +02:00
|
|
|
bool no_substitute, bool report_error)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2005-12-21 19:18:40 +01:00
|
|
|
handlerton *hton= ha_resolve_by_legacy_type(thd, database_type);
|
|
|
|
if (ha_storage_engine_is_enabled(hton))
|
|
|
|
return hton;
|
|
|
|
|
2005-06-17 23:14:44 +02:00
|
|
|
if (no_substitute)
|
|
|
|
{
|
|
|
|
if (report_error)
|
|
|
|
{
|
|
|
|
const char *engine_name= ha_get_storage_engine(database_type);
|
|
|
|
my_error(ER_FEATURE_DISABLED,MYF(0),engine_name,engine_name);
|
|
|
|
}
|
2005-12-21 19:18:40 +01:00
|
|
|
return NULL;
|
2005-06-17 23:14:44 +02:00
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
switch (database_type) {
|
|
|
|
#ifndef NO_HASH
|
|
|
|
case DB_TYPE_HASH:
|
2005-12-21 19:18:40 +01:00
|
|
|
return ha_resolve_by_legacy_type(thd, DB_TYPE_HASH);
|
2004-03-02 11:08:50 +01:00
|
|
|
#endif
|
2003-05-13 10:15:11 +02:00
|
|
|
case DB_TYPE_MRG_ISAM:
|
2005-12-21 19:18:40 +01:00
|
|
|
return ha_resolve_by_legacy_type(thd, DB_TYPE_MRG_MYISAM);
|
2000-07-31 21:29:14 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-12-21 19:18:40 +01:00
|
|
|
|
|
|
|
return ha_resolve_by_legacy_type(thd, DB_TYPE_DEFAULT);
|
2000-07-31 21:29:14 +02:00
|
|
|
} /* ha_checktype */
|
|
|
|
|
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
|
2005-12-21 19:18:40 +01:00
|
|
|
handlerton *db_type)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2005-11-07 16:25:06 +01:00
|
|
|
handler *file= NULL;
|
|
|
|
/*
|
|
|
|
handlers are allocated with new in the handlerton create() function
|
|
|
|
we need to set the thd mem_root for these to be allocated correctly
|
|
|
|
*/
|
|
|
|
THD *thd= current_thd;
|
|
|
|
MEM_ROOT *thd_save_mem_root= thd->mem_root;
|
|
|
|
thd->mem_root= alloc;
|
2005-12-21 19:18:40 +01:00
|
|
|
|
|
|
|
if (db_type != NULL && db_type->state == SHOW_OPTION_YES && db_type->create)
|
|
|
|
file= db_type->create(share);
|
|
|
|
|
2005-11-07 16:25:06 +01:00
|
|
|
thd->mem_root= thd_save_mem_root;
|
|
|
|
|
|
|
|
if (!file)
|
2003-03-19 20:43:41 +01:00
|
|
|
{
|
2005-12-21 19:18:40 +01:00
|
|
|
handlerton *def= current_thd->variables.table_type;
|
2003-03-19 20:43:41 +01:00
|
|
|
/* Try first with 'default table type' */
|
|
|
|
if (db_type != def)
|
2005-11-23 21:45:02 +01:00
|
|
|
return get_new_handler(share, alloc, def);
|
2003-03-19 20:43:41 +01:00
|
|
|
}
|
2005-04-28 14:45:27 +02:00
|
|
|
if (file)
|
|
|
|
{
|
2005-05-02 15:45:33 +02:00
|
|
|
if (file->ha_initialise())
|
2005-04-28 14:45:27 +02:00
|
|
|
{
|
|
|
|
delete file;
|
2005-05-02 15:45:33 +02:00
|
|
|
file=0;
|
2005-04-28 14:45:27 +02:00
|
|
|
}
|
2005-11-05 12:20:35 +01:00
|
|
|
}
|
|
|
|
return file;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
|
2005-11-07 16:25:06 +01:00
|
|
|
#ifdef WITH_PARTITION_STORAGE_ENGINE
|
2005-07-18 13:31:02 +02:00
|
|
|
handler *get_ha_partition(partition_info *part_info)
|
|
|
|
{
|
|
|
|
ha_partition *partition;
|
|
|
|
DBUG_ENTER("get_ha_partition");
|
|
|
|
if ((partition= new ha_partition(part_info)))
|
|
|
|
{
|
|
|
|
if (partition->ha_initialise())
|
|
|
|
{
|
|
|
|
delete partition;
|
|
|
|
partition= 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
my_error(ER_OUTOFMEMORY, MYF(0), sizeof(ha_partition));
|
|
|
|
}
|
|
|
|
DBUG_RETURN(((handler*) partition));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-12-23 20:11:38 +01:00
|
|
|
/*
|
|
|
|
Register handler error messages for use with my_error().
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
ha_init_errors()
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 OK
|
|
|
|
!= 0 Error
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int ha_init_errors(void)
|
|
|
|
{
|
|
|
|
#define SETMSG(nr, msg) errmsgs[(nr) - HA_ERR_FIRST]= (msg)
|
|
|
|
const char **errmsgs;
|
|
|
|
|
|
|
|
/* Allocate a pointer array for the error message strings. */
|
|
|
|
/* Zerofill it to avoid uninitialized gaps. */
|
|
|
|
if (! (errmsgs= (const char**) my_malloc(HA_ERR_ERRORS * sizeof(char*),
|
|
|
|
MYF(MY_WME | MY_ZEROFILL))))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Set the dedicated error messages. */
|
|
|
|
SETMSG(HA_ERR_KEY_NOT_FOUND, ER(ER_KEY_NOT_FOUND));
|
|
|
|
SETMSG(HA_ERR_FOUND_DUPP_KEY, ER(ER_DUP_KEY));
|
|
|
|
SETMSG(HA_ERR_RECORD_CHANGED, "Update wich is recoverable");
|
|
|
|
SETMSG(HA_ERR_WRONG_INDEX, "Wrong index given to function");
|
|
|
|
SETMSG(HA_ERR_CRASHED, ER(ER_NOT_KEYFILE));
|
|
|
|
SETMSG(HA_ERR_WRONG_IN_RECORD, ER(ER_CRASHED_ON_USAGE));
|
|
|
|
SETMSG(HA_ERR_OUT_OF_MEM, "Table handler out of memory");
|
|
|
|
SETMSG(HA_ERR_NOT_A_TABLE, "Incorrect file format '%.64s'");
|
|
|
|
SETMSG(HA_ERR_WRONG_COMMAND, "Command not supported");
|
|
|
|
SETMSG(HA_ERR_OLD_FILE, ER(ER_OLD_KEYFILE));
|
|
|
|
SETMSG(HA_ERR_NO_ACTIVE_RECORD, "No record read in update");
|
|
|
|
SETMSG(HA_ERR_RECORD_DELETED, "Intern record deleted");
|
|
|
|
SETMSG(HA_ERR_RECORD_FILE_FULL, ER(ER_RECORD_FILE_FULL));
|
|
|
|
SETMSG(HA_ERR_INDEX_FILE_FULL, "No more room in index file '%.64s'");
|
|
|
|
SETMSG(HA_ERR_END_OF_FILE, "End in next/prev/first/last");
|
|
|
|
SETMSG(HA_ERR_UNSUPPORTED, ER(ER_ILLEGAL_HA));
|
|
|
|
SETMSG(HA_ERR_TO_BIG_ROW, "Too big row");
|
|
|
|
SETMSG(HA_WRONG_CREATE_OPTION, "Wrong create option");
|
|
|
|
SETMSG(HA_ERR_FOUND_DUPP_UNIQUE, ER(ER_DUP_UNIQUE));
|
|
|
|
SETMSG(HA_ERR_UNKNOWN_CHARSET, "Can't open charset");
|
|
|
|
SETMSG(HA_ERR_WRONG_MRG_TABLE_DEF, ER(ER_WRONG_MRG_TABLE));
|
|
|
|
SETMSG(HA_ERR_CRASHED_ON_REPAIR, ER(ER_CRASHED_ON_REPAIR));
|
|
|
|
SETMSG(HA_ERR_CRASHED_ON_USAGE, ER(ER_CRASHED_ON_USAGE));
|
|
|
|
SETMSG(HA_ERR_LOCK_WAIT_TIMEOUT, ER(ER_LOCK_WAIT_TIMEOUT));
|
|
|
|
SETMSG(HA_ERR_LOCK_TABLE_FULL, ER(ER_LOCK_TABLE_FULL));
|
|
|
|
SETMSG(HA_ERR_READ_ONLY_TRANSACTION, ER(ER_READ_ONLY_TRANSACTION));
|
|
|
|
SETMSG(HA_ERR_LOCK_DEADLOCK, ER(ER_LOCK_DEADLOCK));
|
|
|
|
SETMSG(HA_ERR_CANNOT_ADD_FOREIGN, ER(ER_CANNOT_ADD_FOREIGN));
|
2005-09-23 15:22:27 +02:00
|
|
|
SETMSG(HA_ERR_NO_REFERENCED_ROW, ER(ER_NO_REFERENCED_ROW_2));
|
|
|
|
SETMSG(HA_ERR_ROW_IS_REFERENCED, ER(ER_ROW_IS_REFERENCED_2));
|
2004-12-23 20:11:38 +01:00
|
|
|
SETMSG(HA_ERR_NO_SAVEPOINT, "No savepoint with that name");
|
|
|
|
SETMSG(HA_ERR_NON_UNIQUE_BLOCK_SIZE, "Non unique key block size");
|
|
|
|
SETMSG(HA_ERR_NO_SUCH_TABLE, "No such table: '%.64s'");
|
|
|
|
SETMSG(HA_ERR_TABLE_EXIST, ER(ER_TABLE_EXISTS_ERROR));
|
|
|
|
SETMSG(HA_ERR_NO_CONNECTION, "Could not connect to storage engine");
|
2005-04-07 20:17:37 +02:00
|
|
|
SETMSG(HA_ERR_TABLE_DEF_CHANGED, ER(ER_TABLE_DEF_CHANGED));
|
2006-02-09 18:43:10 +01:00
|
|
|
SETMSG(HA_ERR_FOREIGN_DUPLICATE_KEY, "FK constraint would lead to duplicate key");
|
2006-02-17 07:52:32 +01:00
|
|
|
SETMSG(HA_ERR_TABLE_NEEDS_UPGRADE, ER(ER_TABLE_NEEDS_UPGRADE));
|
2004-12-23 20:11:38 +01:00
|
|
|
|
|
|
|
/* Register the error messages for use with my_error(). */
|
|
|
|
return my_error_register(errmsgs, HA_ERR_FIRST, HA_ERR_LAST);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Unregister handler error messages.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
ha_finish_errors()
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 OK
|
|
|
|
!= 0 Error
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int ha_finish_errors(void)
|
|
|
|
{
|
|
|
|
const char **errmsgs;
|
|
|
|
|
|
|
|
/* Allocate a pointer array for the error message strings. */
|
|
|
|
if (! (errmsgs= my_error_unregister(HA_ERR_FIRST, HA_ERR_LAST)))
|
|
|
|
return 1;
|
|
|
|
my_free((gptr) errmsgs, MYF(0));
|
|
|
|
return 0;
|
|
|
|
}
|
2005-03-13 21:58:09 +01:00
|
|
|
|
2004-12-23 20:11:38 +01:00
|
|
|
|
2006-04-13 22:49:29 +02:00
|
|
|
int ha_finalize_handlerton(st_plugin_int *plugin)
|
2005-01-16 13:16:23 +01:00
|
|
|
{
|
2006-05-31 18:07:32 +02:00
|
|
|
handlerton *hton= (handlerton *)plugin->data;
|
2006-04-13 22:49:29 +02:00
|
|
|
DBUG_ENTER("ha_finalize_handlerton");
|
|
|
|
|
|
|
|
switch (hton->state)
|
|
|
|
{
|
|
|
|
case SHOW_OPTION_NO:
|
|
|
|
case SHOW_OPTION_DISABLED:
|
|
|
|
break;
|
|
|
|
case SHOW_OPTION_YES:
|
|
|
|
if (installed_htons[hton->db_type] == hton)
|
|
|
|
installed_htons[hton->db_type]= NULL;
|
2006-05-31 18:07:32 +02:00
|
|
|
if (hton->panic && hton->panic(HA_PANIC_CLOSE))
|
|
|
|
DBUG_RETURN(1);
|
2006-04-13 22:49:29 +02:00
|
|
|
break;
|
|
|
|
};
|
|
|
|
DBUG_RETURN(0);
|
2005-01-16 13:16:23 +01:00
|
|
|
}
|
2004-12-23 20:11:38 +01:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2006-04-13 22:49:29 +02:00
|
|
|
int ha_initialize_handlerton(st_plugin_int *plugin)
|
2005-12-21 19:18:40 +01:00
|
|
|
{
|
2006-05-28 14:51:01 +02:00
|
|
|
handlerton *hton= ((st_mysql_storage_engine *)plugin->plugin->info)->handlerton;
|
|
|
|
DBUG_ENTER("ha_initialize_handlerton");
|
2006-04-13 22:49:29 +02:00
|
|
|
|
2006-05-31 18:07:32 +02:00
|
|
|
plugin->data= hton; // shortcut for the future
|
|
|
|
|
2006-05-28 14:51:01 +02:00
|
|
|
/*
|
|
|
|
the switch below and hton->state should be removed when
|
|
|
|
command-line options for plugins will be implemented
|
|
|
|
*/
|
2006-04-13 22:49:29 +02:00
|
|
|
switch (hton->state) {
|
2005-12-21 19:18:40 +01:00
|
|
|
case SHOW_OPTION_NO:
|
|
|
|
break;
|
|
|
|
case SHOW_OPTION_YES:
|
|
|
|
{
|
2006-05-31 18:07:32 +02:00
|
|
|
uint tmp;
|
2006-04-13 22:49:29 +02:00
|
|
|
/* now check the db_type for conflict */
|
2006-05-28 14:51:01 +02:00
|
|
|
if (hton->db_type <= DB_TYPE_UNKNOWN ||
|
2006-04-13 22:49:29 +02:00
|
|
|
hton->db_type >= DB_TYPE_DEFAULT ||
|
|
|
|
installed_htons[hton->db_type])
|
|
|
|
{
|
|
|
|
int idx= (int) DB_TYPE_FIRST_DYNAMIC;
|
2006-05-28 14:51:01 +02:00
|
|
|
|
2006-04-13 22:49:29 +02:00
|
|
|
while (idx < (int) DB_TYPE_DEFAULT && installed_htons[idx])
|
|
|
|
idx++;
|
|
|
|
|
|
|
|
if (idx == (int) DB_TYPE_DEFAULT)
|
|
|
|
{
|
|
|
|
sql_print_warning("Too many storage engines!");
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
if (hton->db_type != DB_TYPE_UNKNOWN)
|
|
|
|
sql_print_warning("Storage engine '%s' has conflicting typecode. "
|
2006-05-28 14:51:01 +02:00
|
|
|
"Assigning value %d.", plugin->plugin->name, idx);
|
2006-04-13 22:49:29 +02:00
|
|
|
hton->db_type= (enum legacy_db_type) idx;
|
|
|
|
}
|
|
|
|
installed_htons[hton->db_type]= hton;
|
2006-05-31 18:07:32 +02:00
|
|
|
tmp= hton->savepoint_offset;
|
2006-05-28 14:51:01 +02:00
|
|
|
hton->savepoint_offset= savepoint_alloc_size;
|
|
|
|
savepoint_alloc_size+= tmp;
|
|
|
|
hton->slot= total_ha++;
|
2006-05-31 18:07:32 +02:00
|
|
|
hton2plugin[hton->slot]=plugin;
|
2006-05-28 14:51:01 +02:00
|
|
|
if (hton->prepare)
|
|
|
|
total_ha_2pc++;
|
2005-12-21 19:18:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
hton->state= SHOW_OPTION_DISABLED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int ha_init()
|
|
|
|
{
|
2004-03-02 11:08:50 +01:00
|
|
|
int error= 0;
|
2006-04-13 22:49:29 +02:00
|
|
|
DBUG_ENTER("ha_init");
|
|
|
|
|
2004-12-23 20:11:38 +01:00
|
|
|
if (ha_init_errors())
|
2006-04-13 22:49:29 +02:00
|
|
|
DBUG_RETURN(1);
|
2005-02-14 21:50:09 +01:00
|
|
|
|
2005-01-16 13:16:23 +01:00
|
|
|
DBUG_ASSERT(total_ha < MAX_HA);
|
2005-03-19 01:12:25 +01:00
|
|
|
/*
|
|
|
|
Check if there is a transaction-capable storage engine besides the
|
|
|
|
binary log (which is considered a transaction-capable storage engine in
|
|
|
|
counting total_ha)
|
|
|
|
*/
|
|
|
|
opt_using_transactions= total_ha>(ulong)opt_bin_log;
|
2005-01-16 13:16:23 +01:00
|
|
|
savepoint_alloc_size+= sizeof(SAVEPOINT);
|
2006-04-13 22:49:29 +02:00
|
|
|
DBUG_RETURN(error);
|
2005-12-21 19:18:40 +01:00
|
|
|
}
|
|
|
|
|
2006-05-31 18:07:32 +02:00
|
|
|
/*
|
|
|
|
close, flush or restart databases
|
|
|
|
Ignore this for other databases than ours
|
|
|
|
*/
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2006-05-31 18:07:32 +02:00
|
|
|
static my_bool panic_handlerton(THD *unused1, st_plugin_int *plugin, void *arg)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2006-05-31 18:07:32 +02:00
|
|
|
handlerton *hton= (handlerton *)plugin->data;
|
2005-12-21 19:18:40 +01:00
|
|
|
if (hton->state == SHOW_OPTION_YES && hton->panic)
|
|
|
|
((int*)arg)[0]|= hton->panic((enum ha_panic_function)((int*)arg)[1]);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-11-07 16:25:06 +01:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
|
|
|
|
int ha_panic(enum ha_panic_function flag)
|
|
|
|
{
|
|
|
|
int error[2];
|
2006-05-28 14:51:01 +02:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
error[0]= 0; error[1]= (int)flag;
|
|
|
|
plugin_foreach(NULL, panic_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, error);
|
2006-05-28 14:51:01 +02:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
if (flag == HA_PANIC_CLOSE && ha_finish_errors())
|
|
|
|
error[0]= 1;
|
|
|
|
return error[0];
|
2000-07-31 21:29:14 +02:00
|
|
|
} /* ha_panic */
|
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
static my_bool dropdb_handlerton(THD *unused1, st_plugin_int *plugin,
|
|
|
|
void *path)
|
|
|
|
{
|
2006-05-31 18:07:32 +02:00
|
|
|
handlerton *hton= (handlerton *)plugin->data;
|
2005-12-21 19:18:40 +01:00
|
|
|
if (hton->state == SHOW_OPTION_YES && hton->drop_database)
|
|
|
|
hton->drop_database((char *)path);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-10 21:47:08 +02:00
|
|
|
void ha_drop_database(char* path)
|
|
|
|
{
|
2005-12-21 19:18:40 +01:00
|
|
|
plugin_foreach(NULL, dropdb_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, path);
|
|
|
|
}
|
2005-11-07 16:25:06 +01:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
|
|
|
|
static my_bool closecon_handlerton(THD *thd, st_plugin_int *plugin,
|
|
|
|
void *unused)
|
|
|
|
{
|
2006-05-31 18:07:32 +02:00
|
|
|
handlerton *hton= (handlerton *)plugin->data;
|
|
|
|
/*
|
|
|
|
there's no need to rollback here as all transactions must
|
|
|
|
be rolled back already
|
|
|
|
*/
|
2005-12-21 19:18:40 +01:00
|
|
|
if (hton->state == SHOW_OPTION_YES && hton->close_connection &&
|
|
|
|
thd->ha_data[hton->slot])
|
|
|
|
hton->close_connection(thd);
|
|
|
|
return FALSE;
|
2001-10-10 21:47:08 +02:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2005-01-16 13:16:23 +01:00
|
|
|
/* don't bother to rollback here, it's done already */
|
2000-12-06 00:54:17 +01:00
|
|
|
void ha_close_connection(THD* thd)
|
|
|
|
{
|
2005-12-21 19:18:40 +01:00
|
|
|
plugin_foreach(thd, closecon_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, 0);
|
2005-01-16 13:16:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ========================================================================
|
|
|
|
======================= TRANSACTIONS ===================================*/
|
|
|
|
|
2005-03-13 21:58:09 +01:00
|
|
|
/*
|
|
|
|
Register a storage engine for a transaction
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Every storage engine MUST call this function when it starts
|
|
|
|
a transaction or a statement (that is it must be called both for the
|
|
|
|
"beginning of transaction" and "beginning of statement").
|
|
|
|
Only storage engines registered for the transaction/statement
|
|
|
|
will know when to commit/rollback it.
|
2005-04-05 18:42:34 +02:00
|
|
|
|
|
|
|
NOTE
|
|
|
|
trans_register_ha is idempotent - storage engine may register many
|
|
|
|
times per transaction.
|
|
|
|
|
2005-03-13 21:58:09 +01:00
|
|
|
*/
|
2005-01-16 13:16:23 +01:00
|
|
|
void trans_register_ha(THD *thd, bool all, handlerton *ht_arg)
|
|
|
|
{
|
|
|
|
THD_TRANS *trans;
|
2005-04-05 18:42:34 +02:00
|
|
|
handlerton **ht;
|
2005-02-21 11:51:50 +01:00
|
|
|
DBUG_ENTER("trans_register_ha");
|
|
|
|
DBUG_PRINT("enter",("%s", all ? "all" : "stmt"));
|
|
|
|
|
2005-01-16 13:16:23 +01:00
|
|
|
if (all)
|
|
|
|
{
|
|
|
|
trans= &thd->transaction.all;
|
|
|
|
thd->server_status|= SERVER_STATUS_IN_TRANS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
trans= &thd->transaction.stmt;
|
|
|
|
|
2005-04-05 18:42:34 +02:00
|
|
|
for (ht=trans->ht; *ht; ht++)
|
2005-04-05 16:56:40 +02:00
|
|
|
if (*ht == ht_arg)
|
|
|
|
DBUG_VOID_RETURN; /* already registered, return */
|
|
|
|
|
2005-01-16 13:16:23 +01:00
|
|
|
trans->ht[trans->nht++]=ht_arg;
|
2005-04-05 18:42:34 +02:00
|
|
|
DBUG_ASSERT(*ht == ht_arg);
|
2005-01-16 13:16:23 +01:00
|
|
|
trans->no_2pc|=(ht_arg->prepare==0);
|
2005-08-12 21:15:01 +02:00
|
|
|
if (thd->transaction.xid_state.xid.is_null())
|
|
|
|
thd->transaction.xid_state.xid.set(thd->query_id);
|
2005-02-21 11:51:50 +01:00
|
|
|
DBUG_VOID_RETURN;
|
2005-01-16 13:16:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
RETURN
|
|
|
|
0 - ok
|
|
|
|
1 - error, transaction was rolled back
|
|
|
|
*/
|
|
|
|
int ha_prepare(THD *thd)
|
|
|
|
{
|
|
|
|
int error=0, all=1;
|
|
|
|
THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
|
|
|
|
handlerton **ht=trans->ht;
|
|
|
|
DBUG_ENTER("ha_prepare");
|
|
|
|
#ifdef USING_TRANSACTIONS
|
|
|
|
if (trans->nht)
|
|
|
|
{
|
|
|
|
for (; *ht; ht++)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
statistic_increment(thd->status_var.ha_prepare_count,&LOCK_status);
|
2005-09-07 18:03:07 +02:00
|
|
|
if ((*ht)->prepare)
|
2005-01-16 13:16:23 +01:00
|
|
|
{
|
2005-09-07 18:03:07 +02:00
|
|
|
if ((err= (*(*ht)->prepare)(thd, all)))
|
|
|
|
{
|
|
|
|
my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
|
|
|
|
ha_rollback_trans(thd, all);
|
|
|
|
error=1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
2006-05-28 14:51:01 +02:00
|
|
|
ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
|
2006-05-31 18:07:32 +02:00
|
|
|
hton2plugin[(*ht)->slot]->name.str);
|
2005-01-16 13:16:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* USING_TRANSACTIONS */
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
RETURN
|
|
|
|
0 - ok
|
|
|
|
1 - transaction was rolled back
|
|
|
|
2 - error during commit, data may be inconsistent
|
|
|
|
*/
|
|
|
|
int ha_commit_trans(THD *thd, bool all)
|
|
|
|
{
|
|
|
|
int error= 0, cookie= 0;
|
|
|
|
THD_TRANS *trans= all ? &thd->transaction.all : &thd->transaction.stmt;
|
|
|
|
bool is_real_trans= all || thd->transaction.all.nht == 0;
|
|
|
|
handlerton **ht= trans->ht;
|
2005-08-12 21:15:01 +02:00
|
|
|
my_xid xid= thd->transaction.xid_state.xid.get_my_xid();
|
2005-01-16 13:16:23 +01:00
|
|
|
DBUG_ENTER("ha_commit_trans");
|
2005-06-07 12:53:08 +02:00
|
|
|
|
2005-07-30 10:19:57 +02:00
|
|
|
if (thd->in_sub_stmt)
|
2005-06-07 12:53:08 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Since we don't support nested statement transactions in 5.0,
|
|
|
|
we can't commit or rollback stmt transactions while we are inside
|
|
|
|
stored functions or triggers. So we simply do nothing now.
|
|
|
|
TODO: This should be fixed in later ( >= 5.1) releases.
|
|
|
|
*/
|
|
|
|
if (!all)
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
/*
|
|
|
|
We assume that all statements which commit or rollback main transaction
|
|
|
|
are prohibited inside of stored functions or triggers. So they should
|
|
|
|
bail out with error even before ha_commit_trans() call. To be 100% safe
|
|
|
|
let us throw error in non-debug builds.
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
|
|
|
|
DBUG_RETURN(2);
|
|
|
|
}
|
2005-01-16 13:16:23 +01:00
|
|
|
#ifdef USING_TRANSACTIONS
|
|
|
|
if (trans->nht)
|
|
|
|
{
|
2005-04-12 17:15:54 +02:00
|
|
|
if (is_real_trans && wait_if_global_read_lock(thd, 0, 0))
|
|
|
|
{
|
|
|
|
ha_rollback_trans(thd, all);
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2005-02-22 15:22:37 +01:00
|
|
|
DBUG_EXECUTE_IF("crash_commit_before", abort(););
|
2005-07-19 20:21:12 +02:00
|
|
|
|
|
|
|
/* Close all cursors that can not survive COMMIT */
|
|
|
|
if (is_real_trans) /* not a statement commit */
|
|
|
|
thd->stmt_map.close_transient_cursors();
|
|
|
|
|
2005-01-16 13:16:23 +01:00
|
|
|
if (!trans->no_2pc && trans->nht > 1)
|
|
|
|
{
|
|
|
|
for (; *ht && !error; ht++)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
if ((err= (*(*ht)->prepare)(thd, all)))
|
|
|
|
{
|
|
|
|
my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
|
2005-04-12 17:15:54 +02:00
|
|
|
error= 1;
|
2005-01-16 13:16:23 +01:00
|
|
|
}
|
|
|
|
statistic_increment(thd->status_var.ha_prepare_count,&LOCK_status);
|
|
|
|
}
|
2005-02-22 15:22:37 +01:00
|
|
|
DBUG_EXECUTE_IF("crash_commit_after_prepare", abort(););
|
2005-01-27 22:38:56 +01:00
|
|
|
if (error || (is_real_trans && xid &&
|
|
|
|
(error= !(cookie= tc_log->log(thd, xid)))))
|
2005-01-16 13:16:23 +01:00
|
|
|
{
|
|
|
|
ha_rollback_trans(thd, all);
|
2005-04-12 17:15:54 +02:00
|
|
|
error= 1;
|
|
|
|
goto end;
|
2005-01-16 13:16:23 +01:00
|
|
|
}
|
2005-04-12 17:15:54 +02:00
|
|
|
DBUG_EXECUTE_IF("crash_commit_after_log", abort(););
|
2005-01-16 13:16:23 +01:00
|
|
|
}
|
|
|
|
error=ha_commit_one_phase(thd, all) ? cookie ? 2 : 1 : 0;
|
2005-02-22 15:22:37 +01:00
|
|
|
DBUG_EXECUTE_IF("crash_commit_before_unlog", abort(););
|
2005-01-16 13:16:23 +01:00
|
|
|
if (cookie)
|
2005-01-27 22:38:56 +01:00
|
|
|
tc_log->unlog(cookie, xid);
|
2005-02-22 15:22:37 +01:00
|
|
|
DBUG_EXECUTE_IF("crash_commit_after", abort(););
|
2005-04-12 17:15:54 +02:00
|
|
|
end:
|
|
|
|
if (is_real_trans)
|
|
|
|
start_waiting_global_read_lock(thd);
|
2005-01-16 13:16:23 +01:00
|
|
|
}
|
|
|
|
#endif /* USING_TRANSACTIONS */
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2005-04-12 17:15:54 +02:00
|
|
|
/*
|
|
|
|
NOTE - this function does not care about global read lock.
|
|
|
|
A caller should.
|
|
|
|
*/
|
2005-01-16 13:16:23 +01:00
|
|
|
int ha_commit_one_phase(THD *thd, bool all)
|
|
|
|
{
|
|
|
|
int error=0;
|
|
|
|
THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
|
|
|
|
bool is_real_trans=all || thd->transaction.all.nht == 0;
|
|
|
|
handlerton **ht=trans->ht;
|
|
|
|
DBUG_ENTER("ha_commit_one_phase");
|
|
|
|
#ifdef USING_TRANSACTIONS
|
|
|
|
if (trans->nht)
|
|
|
|
{
|
|
|
|
for (ht=trans->ht; *ht; ht++)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
if ((err= (*(*ht)->commit)(thd, all)))
|
|
|
|
{
|
|
|
|
my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
|
|
|
|
error=1;
|
|
|
|
}
|
|
|
|
statistic_increment(thd->status_var.ha_commit_count,&LOCK_status);
|
|
|
|
*ht= 0;
|
|
|
|
}
|
|
|
|
trans->nht=0;
|
|
|
|
trans->no_2pc=0;
|
|
|
|
if (is_real_trans)
|
2005-08-12 21:15:01 +02:00
|
|
|
thd->transaction.xid_state.xid.null();
|
2005-01-16 13:16:23 +01:00
|
|
|
if (all)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_QUERY_CACHE
|
|
|
|
if (thd->transaction.changed_tables)
|
|
|
|
query_cache.invalidate(thd->transaction.changed_tables);
|
2004-04-15 09:14:14 +02:00
|
|
|
#endif
|
2005-01-16 13:16:23 +01:00
|
|
|
thd->variables.tx_isolation=thd->session_tx_isolation;
|
|
|
|
thd->transaction.cleanup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* USING_TRANSACTIONS */
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_rollback_trans(THD *thd, bool all)
|
|
|
|
{
|
|
|
|
int error=0;
|
|
|
|
THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
|
|
|
|
bool is_real_trans=all || thd->transaction.all.nht == 0;
|
|
|
|
DBUG_ENTER("ha_rollback_trans");
|
2005-07-30 10:19:57 +02:00
|
|
|
if (thd->in_sub_stmt)
|
2005-06-07 12:53:08 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
If we are inside stored function or trigger we should not commit or
|
|
|
|
rollback current statement transaction. See comment in ha_commit_trans()
|
|
|
|
call for more information.
|
|
|
|
*/
|
|
|
|
if (!all)
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2005-01-16 13:16:23 +01:00
|
|
|
#ifdef USING_TRANSACTIONS
|
|
|
|
if (trans->nht)
|
|
|
|
{
|
2005-07-19 20:21:12 +02:00
|
|
|
/* Close all cursors that can not survive ROLLBACK */
|
|
|
|
if (is_real_trans) /* not a statement commit */
|
|
|
|
thd->stmt_map.close_transient_cursors();
|
|
|
|
|
2005-01-16 13:16:23 +01:00
|
|
|
for (handlerton **ht=trans->ht; *ht; ht++)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
if ((err= (*(*ht)->rollback)(thd, all)))
|
|
|
|
{ // cannot happen
|
|
|
|
my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
|
|
|
|
error=1;
|
|
|
|
}
|
|
|
|
statistic_increment(thd->status_var.ha_rollback_count,&LOCK_status);
|
|
|
|
*ht= 0;
|
|
|
|
}
|
|
|
|
trans->nht=0;
|
|
|
|
trans->no_2pc=0;
|
|
|
|
if (is_real_trans)
|
2005-08-12 21:15:01 +02:00
|
|
|
thd->transaction.xid_state.xid.null();
|
2005-01-16 13:16:23 +01:00
|
|
|
if (all)
|
|
|
|
{
|
|
|
|
thd->variables.tx_isolation=thd->session_tx_isolation;
|
|
|
|
thd->transaction.cleanup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* USING_TRANSACTIONS */
|
|
|
|
/*
|
|
|
|
If a non-transactional table was updated, warn; don't warn if this is a
|
|
|
|
slave thread (because when a slave thread executes a ROLLBACK, it has
|
|
|
|
been read from the binary log, so it's 100% sure and normal to produce
|
|
|
|
error ER_WARNING_NOT_COMPLETE_ROLLBACK. If we sent the warning to the
|
|
|
|
slave SQL thread, it would not stop the thread but just be printed in
|
|
|
|
the error log; but we don't want users to wonder why they have this
|
|
|
|
message in the error log, so we don't send it.
|
|
|
|
*/
|
|
|
|
if (is_real_trans && (thd->options & OPTION_STATUS_NO_TRANS_UPDATE) &&
|
|
|
|
!thd->slave_thread)
|
|
|
|
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
ER_WARNING_NOT_COMPLETE_ROLLBACK,
|
|
|
|
ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
|
|
|
|
DBUG_RETURN(error);
|
2000-12-06 00:54:17 +01:00
|
|
|
}
|
|
|
|
|
2000-11-24 00:51:18 +01:00
|
|
|
/*
|
2003-06-04 16:58:41 +02:00
|
|
|
This is used to commit or rollback a single statement depending on the value
|
2003-06-05 14:58:23 +02:00
|
|
|
of error. Note that if the autocommit is on, then the following call inside
|
|
|
|
InnoDB will commit or rollback the whole transaction (= the statement). The
|
|
|
|
autocommit mechanism built into InnoDB is based on counting locks, but if
|
|
|
|
the user has used LOCK TABLES then that mechanism does not know to do the
|
|
|
|
commit.
|
2000-11-24 00:51:18 +01:00
|
|
|
*/
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int ha_autocommit_or_rollback(THD *thd, int error)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_autocommit_or_rollback");
|
2000-11-24 00:51:18 +01:00
|
|
|
#ifdef USING_TRANSACTIONS
|
2005-01-16 13:16:23 +01:00
|
|
|
if (thd->transaction.stmt.nht)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2001-03-06 14:24:08 +01:00
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
if (ha_commit_stmt(thd))
|
|
|
|
error=1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
(void) ha_rollback_stmt(thd);
|
2002-07-25 21:46:28 +02:00
|
|
|
|
2002-07-23 17:31:22 +02:00
|
|
|
thd->variables.tx_isolation=thd->session_tx_isolation;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2005-10-11 23:58:22 +02:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
struct xahton_st {
|
|
|
|
XID *xid;
|
|
|
|
int result;
|
|
|
|
};
|
|
|
|
|
|
|
|
static my_bool xacommit_handlerton(THD *unused1, st_plugin_int *plugin,
|
|
|
|
void *arg)
|
2005-01-16 13:16:23 +01:00
|
|
|
{
|
2006-05-31 18:07:32 +02:00
|
|
|
handlerton *hton= (handlerton *)plugin->data;
|
2005-12-21 19:18:40 +01:00
|
|
|
if (hton->state == SHOW_OPTION_YES && hton->recover)
|
|
|
|
{
|
|
|
|
hton->commit_by_xid(((struct xahton_st *)arg)->xid);
|
|
|
|
((struct xahton_st *)arg)->result= 0;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-01-16 13:16:23 +01:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
static my_bool xarollback_handlerton(THD *unused1, st_plugin_int *plugin,
|
|
|
|
void *arg)
|
|
|
|
{
|
2006-05-31 18:07:32 +02:00
|
|
|
handlerton *hton= (handlerton *)plugin->data;
|
2005-12-21 19:18:40 +01:00
|
|
|
if (hton->state == SHOW_OPTION_YES && hton->recover)
|
2005-10-11 23:58:22 +02:00
|
|
|
{
|
2005-12-21 19:18:40 +01:00
|
|
|
hton->rollback_by_xid(((struct xahton_st *)arg)->xid);
|
|
|
|
((struct xahton_st *)arg)->result= 0;
|
2005-10-11 23:58:22 +02:00
|
|
|
}
|
2005-12-21 19:18:40 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_commit_or_rollback_by_xid(XID *xid, bool commit)
|
|
|
|
{
|
|
|
|
struct xahton_st xaop;
|
|
|
|
xaop.xid= xid;
|
|
|
|
xaop.result= 1;
|
2006-05-31 18:07:32 +02:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
plugin_foreach(NULL, commit ? xacommit_handlerton : xarollback_handlerton,
|
|
|
|
MYSQL_STORAGE_ENGINE_PLUGIN, &xaop);
|
|
|
|
|
|
|
|
return xaop.result;
|
2005-01-16 13:16:23 +01:00
|
|
|
}
|
2002-02-09 03:00:24 +01:00
|
|
|
|
2005-10-11 23:58:22 +02:00
|
|
|
|
2005-03-13 21:58:09 +01:00
|
|
|
#ifndef DBUG_OFF
|
|
|
|
/* this does not need to be multi-byte safe or anything */
|
|
|
|
static char* xid_to_str(char *buf, XID *xid)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *s=buf;
|
|
|
|
*s++='\'';
|
|
|
|
for (i=0; i < xid->gtrid_length+xid->bqual_length; i++)
|
|
|
|
{
|
|
|
|
uchar c=(uchar)xid->data[i];
|
2005-03-21 22:41:28 +01:00
|
|
|
/* is_next_dig is set if next character is a number */
|
|
|
|
bool is_next_dig= FALSE;
|
2005-03-16 08:42:06 +01:00
|
|
|
if (i < XIDDATASIZE)
|
|
|
|
{
|
2005-03-21 22:41:28 +01:00
|
|
|
char ch= xid->data[i+1];
|
|
|
|
is_next_dig= (ch >= '0' && ch <='9');
|
2005-03-16 08:42:06 +01:00
|
|
|
}
|
2005-03-13 21:58:09 +01:00
|
|
|
if (i == xid->gtrid_length)
|
|
|
|
{
|
|
|
|
*s++='\'';
|
|
|
|
if (xid->bqual_length)
|
|
|
|
{
|
|
|
|
*s++='.';
|
|
|
|
*s++='\'';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c < 32 || c > 126)
|
|
|
|
{
|
|
|
|
*s++='\\';
|
2005-03-21 22:41:28 +01:00
|
|
|
/*
|
|
|
|
If next character is a number, write current character with
|
|
|
|
3 octal numbers to ensure that the next number is not seen
|
|
|
|
as part of the octal number
|
|
|
|
*/
|
2005-03-16 08:42:06 +01:00
|
|
|
if (c > 077 || is_next_dig)
|
|
|
|
*s++=_dig_vec_lower[c >> 6];
|
|
|
|
if (c > 007 || is_next_dig)
|
|
|
|
*s++=_dig_vec_lower[(c >> 3) & 7];
|
|
|
|
*s++=_dig_vec_lower[c & 7];
|
2005-03-13 21:58:09 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (c == '\'' || c == '\\')
|
|
|
|
*s++='\\';
|
|
|
|
*s++=c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*s++='\'';
|
|
|
|
*s=0;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-01-16 13:16:23 +01:00
|
|
|
/*
|
|
|
|
recover() step of xa
|
2005-03-12 20:09:54 +01:00
|
|
|
|
|
|
|
NOTE
|
|
|
|
there are three modes of operation:
|
|
|
|
|
|
|
|
- automatic recover after a crash
|
|
|
|
in this case commit_list != 0, tc_heuristic_recover==0
|
|
|
|
all xids from commit_list are committed, others are rolled back
|
|
|
|
|
|
|
|
- manual (heuristic) recover
|
|
|
|
in this case commit_list==0, tc_heuristic_recover != 0
|
|
|
|
DBA has explicitly specified that all prepared transactions should
|
|
|
|
be committed (or rolled back).
|
|
|
|
|
|
|
|
- no recovery (MySQL did not detect a crash)
|
|
|
|
in this case commit_list==0, tc_heuristic_recover == 0
|
|
|
|
there should be no prepared transactions in this case.
|
2002-02-09 03:00:24 +01:00
|
|
|
*/
|
2005-01-16 13:16:23 +01:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
struct xarecover_st
|
|
|
|
{
|
|
|
|
int len, found_foreign_xids, found_my_xids;
|
|
|
|
XID *list;
|
|
|
|
HASH *commit_list;
|
|
|
|
bool dry_run;
|
|
|
|
};
|
2005-01-16 13:16:23 +01:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
static my_bool xarecover_handlerton(THD *unused, st_plugin_int *plugin,
|
|
|
|
void *arg)
|
|
|
|
{
|
2006-05-31 18:07:32 +02:00
|
|
|
handlerton *hton= (handlerton *)plugin->data;
|
2005-12-21 19:18:40 +01:00
|
|
|
struct xarecover_st *info= (struct xarecover_st *) arg;
|
|
|
|
int got;
|
2006-05-28 14:51:01 +02:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
if (hton->state == SHOW_OPTION_YES && hton->recover)
|
2005-01-16 13:16:23 +01:00
|
|
|
{
|
2005-12-21 19:18:40 +01:00
|
|
|
while ((got= hton->recover(info->list, info->len)) > 0 )
|
2002-01-22 21:57:56 +01:00
|
|
|
{
|
2005-03-13 21:58:09 +01:00
|
|
|
sql_print_information("Found %d prepared transaction(s) in %s",
|
2006-05-31 18:07:32 +02:00
|
|
|
got, hton2plugin[hton->slot]->name.str);
|
2005-01-16 13:16:23 +01:00
|
|
|
for (int i=0; i < got; i ++)
|
|
|
|
{
|
2005-12-21 19:18:40 +01:00
|
|
|
my_xid x=info->list[i].get_my_xid();
|
2005-01-16 13:16:23 +01:00
|
|
|
if (!x) // not "mine" - that is generated by external TM
|
2005-03-12 20:09:54 +01:00
|
|
|
{
|
2005-03-16 08:42:06 +01:00
|
|
|
#ifndef DBUG_OFF
|
|
|
|
char buf[XIDDATASIZE*4+6]; // see xid_to_str
|
2005-12-21 19:18:40 +01:00
|
|
|
sql_print_information("ignore xid %s", xid_to_str(buf, info->list+i));
|
2005-03-16 08:42:06 +01:00
|
|
|
#endif
|
2005-12-21 19:18:40 +01:00
|
|
|
xid_cache_insert(info->list+i, XA_PREPARED);
|
|
|
|
info->found_foreign_xids++;
|
2005-03-12 20:09:54 +01:00
|
|
|
continue;
|
|
|
|
}
|
2005-12-21 19:18:40 +01:00
|
|
|
if (info->dry_run)
|
2005-03-12 20:09:54 +01:00
|
|
|
{
|
2005-12-21 19:18:40 +01:00
|
|
|
info->found_my_xids++;
|
2005-01-16 13:16:23 +01:00
|
|
|
continue;
|
2005-03-12 20:09:54 +01:00
|
|
|
}
|
|
|
|
// recovery mode
|
2005-12-21 19:18:40 +01:00
|
|
|
if (info->commit_list ?
|
|
|
|
hash_search(info->commit_list, (byte *)&x, sizeof(x)) != 0 :
|
2005-01-16 13:16:23 +01:00
|
|
|
tc_heuristic_recover == TC_HEURISTIC_RECOVER_COMMIT)
|
2005-03-13 21:58:09 +01:00
|
|
|
{
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
char buf[XIDDATASIZE*4+6]; // see xid_to_str
|
2005-12-21 19:18:40 +01:00
|
|
|
sql_print_information("commit xid %s", xid_to_str(buf, info->list+i));
|
2005-03-13 21:58:09 +01:00
|
|
|
#endif
|
2005-12-21 19:18:40 +01:00
|
|
|
hton->commit_by_xid(info->list+i);
|
2005-03-13 21:58:09 +01:00
|
|
|
}
|
2005-01-16 13:16:23 +01:00
|
|
|
else
|
2005-03-13 21:58:09 +01:00
|
|
|
{
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
char buf[XIDDATASIZE*4+6]; // see xid_to_str
|
2005-12-21 19:18:40 +01:00
|
|
|
sql_print_information("rollback xid %s",
|
|
|
|
xid_to_str(buf, info->list+i));
|
2005-03-13 21:58:09 +01:00
|
|
|
#endif
|
2005-12-21 19:18:40 +01:00
|
|
|
hton->rollback_by_xid(info->list+i);
|
2005-03-13 21:58:09 +01:00
|
|
|
}
|
2005-01-16 13:16:23 +01:00
|
|
|
}
|
2005-12-21 19:18:40 +01:00
|
|
|
if (got < info->len)
|
2005-01-16 13:16:23 +01:00
|
|
|
break;
|
2002-01-22 21:57:56 +01:00
|
|
|
}
|
|
|
|
}
|
2005-12-21 19:18:40 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ha_recover(HASH *commit_list)
|
|
|
|
{
|
|
|
|
struct xarecover_st info;
|
|
|
|
DBUG_ENTER("ha_recover");
|
|
|
|
info.found_foreign_xids= info.found_my_xids= 0;
|
|
|
|
info.commit_list= commit_list;
|
|
|
|
info.dry_run= (info.commit_list==0 && tc_heuristic_recover==0);
|
|
|
|
info.list= NULL;
|
|
|
|
|
|
|
|
/* commit_list and tc_heuristic_recover cannot be set both */
|
|
|
|
DBUG_ASSERT(info.commit_list==0 || tc_heuristic_recover==0);
|
|
|
|
/* if either is set, total_ha_2pc must be set too */
|
|
|
|
DBUG_ASSERT(info.dry_run || total_ha_2pc>(ulong)opt_bin_log);
|
|
|
|
|
|
|
|
if (total_ha_2pc <= (ulong)opt_bin_log)
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
|
|
|
if (info.commit_list)
|
|
|
|
sql_print_information("Starting crash recovery...");
|
|
|
|
|
|
|
|
#ifndef WILL_BE_DELETED_LATER
|
|
|
|
/*
|
|
|
|
for now, only InnoDB supports 2pc. It means we can always safely
|
|
|
|
rollback all pending transactions, without risking inconsistent data
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(total_ha_2pc == (ulong) opt_bin_log+1); // only InnoDB and binlog
|
|
|
|
tc_heuristic_recover= TC_HEURISTIC_RECOVER_ROLLBACK; // forcing ROLLBACK
|
|
|
|
info.dry_run=FALSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (info.len= MAX_XID_LIST_SIZE ;
|
|
|
|
info.list==0 && info.len > MIN_XID_LIST_SIZE; info.len/=2)
|
|
|
|
{
|
|
|
|
info.list=(XID *)my_malloc(info.len*sizeof(XID), MYF(0));
|
|
|
|
}
|
|
|
|
if (!info.list)
|
|
|
|
{
|
|
|
|
sql_print_error(ER(ER_OUTOFMEMORY), info.len*sizeof(XID));
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin_foreach(NULL, xarecover_handlerton,
|
|
|
|
MYSQL_STORAGE_ENGINE_PLUGIN, &info);
|
|
|
|
|
|
|
|
my_free((gptr)info.list, MYF(0));
|
|
|
|
if (info.found_foreign_xids)
|
|
|
|
sql_print_warning("Found %d prepared XA transactions",
|
|
|
|
info.found_foreign_xids);
|
|
|
|
if (info.dry_run && info.found_my_xids)
|
2005-03-12 20:09:54 +01:00
|
|
|
{
|
|
|
|
sql_print_error("Found %d prepared transactions! It means that mysqld was "
|
|
|
|
"not shut down properly last time and critical recovery "
|
|
|
|
"information (last binlog or %s file) was manually deleted "
|
|
|
|
"after a crash. You have to start mysqld with "
|
|
|
|
"--tc-heuristic-recover switch to commit or rollback "
|
|
|
|
"pending transactions.",
|
2005-12-21 19:18:40 +01:00
|
|
|
info.found_my_xids, opt_tc_log_file);
|
2005-03-12 20:09:54 +01:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2005-12-21 19:18:40 +01:00
|
|
|
if (info.commit_list)
|
2005-03-13 21:58:09 +01:00
|
|
|
sql_print_information("Crash recovery finished.");
|
2005-01-16 13:16:23 +01:00
|
|
|
DBUG_RETURN(0);
|
2002-01-22 21:57:56 +01:00
|
|
|
}
|
2000-11-24 00:51:18 +01:00
|
|
|
|
2003-05-03 01:29:40 +02:00
|
|
|
/*
|
2005-01-16 13:16:23 +01:00
|
|
|
return the list of XID's to a client, the same way SHOW commands do
|
2003-05-03 01:29:40 +02:00
|
|
|
|
2005-01-16 13:16:23 +01:00
|
|
|
NOTE
|
|
|
|
I didn't find in XA specs that an RM cannot return the same XID twice,
|
|
|
|
so mysql_xa_recover does not filter XID's to ensure uniqueness.
|
|
|
|
It can be easily fixed later, if necessary.
|
2003-05-03 01:29:40 +02:00
|
|
|
*/
|
2005-01-16 13:16:23 +01:00
|
|
|
bool mysql_xa_recover(THD *thd)
|
2003-05-03 01:29:40 +02:00
|
|
|
{
|
2005-01-16 13:16:23 +01:00
|
|
|
List<Item> field_list;
|
|
|
|
Protocol *protocol= thd->protocol;
|
2005-08-12 21:15:01 +02:00
|
|
|
int i=0;
|
|
|
|
XID_STATE *xs;
|
2005-01-16 13:16:23 +01:00
|
|
|
DBUG_ENTER("mysql_xa_recover");
|
|
|
|
|
|
|
|
field_list.push_back(new Item_int("formatID",0,11));
|
|
|
|
field_list.push_back(new Item_int("gtrid_length",0,11));
|
|
|
|
field_list.push_back(new Item_int("bqual_length",0,11));
|
|
|
|
field_list.push_back(new Item_empty_string("data",XIDDATASIZE));
|
|
|
|
|
|
|
|
if (protocol->send_fields(&field_list,
|
|
|
|
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
|
|
|
|
DBUG_RETURN(1);
|
2003-05-03 01:29:40 +02:00
|
|
|
|
2005-08-12 21:15:01 +02:00
|
|
|
pthread_mutex_lock(&LOCK_xid_cache);
|
2005-08-25 08:38:06 +02:00
|
|
|
while ((xs= (XID_STATE*)hash_element(&xid_cache, i++)))
|
2005-01-16 13:16:23 +01:00
|
|
|
{
|
2005-08-12 21:15:01 +02:00
|
|
|
if (xs->xa_state==XA_PREPARED)
|
2005-01-16 13:16:23 +01:00
|
|
|
{
|
2005-08-12 21:15:01 +02:00
|
|
|
protocol->prepare_for_resend();
|
|
|
|
protocol->store_longlong((longlong)xs->xid.formatID, FALSE);
|
|
|
|
protocol->store_longlong((longlong)xs->xid.gtrid_length, FALSE);
|
|
|
|
protocol->store_longlong((longlong)xs->xid.bqual_length, FALSE);
|
|
|
|
protocol->store(xs->xid.data, xs->xid.gtrid_length+xs->xid.bqual_length,
|
|
|
|
&my_charset_bin);
|
|
|
|
if (protocol->write())
|
2005-01-16 13:16:23 +01:00
|
|
|
{
|
2005-08-12 21:15:01 +02:00
|
|
|
pthread_mutex_unlock(&LOCK_xid_cache);
|
|
|
|
DBUG_RETURN(1);
|
2005-01-16 13:16:23 +01:00
|
|
|
}
|
|
|
|
}
|
2003-05-03 01:29:40 +02:00
|
|
|
}
|
2005-01-16 13:16:23 +01:00
|
|
|
|
2005-08-12 21:15:01 +02:00
|
|
|
pthread_mutex_unlock(&LOCK_xid_cache);
|
2005-01-16 13:16:23 +01:00
|
|
|
send_eof(thd);
|
2005-08-12 21:15:01 +02:00
|
|
|
DBUG_RETURN(0);
|
2003-05-03 01:29:40 +02:00
|
|
|
}
|
2000-11-24 00:51:18 +01:00
|
|
|
|
2003-03-03 18:31:01 +01:00
|
|
|
/*
|
|
|
|
This function should be called when MySQL sends rows of a SELECT result set
|
|
|
|
or the EOF mark to the client. It releases a possible adaptive hash index
|
|
|
|
S-latch held by thd in InnoDB and also releases a possible InnoDB query
|
|
|
|
FIFO ticket to enter InnoDB. To save CPU time, InnoDB allows a thd to
|
|
|
|
keep them over several calls of the InnoDB handler interface when a join
|
|
|
|
is executed. But when we let the control to pass to the client they have
|
|
|
|
to be released because if the application program uses mysql_use_result(),
|
|
|
|
it may deadlock on the S-latch if the application on another connection
|
|
|
|
performs another SQL query. In MySQL-4.1 this is even more important because
|
|
|
|
there a connection can have several SELECT queries open at the same time.
|
|
|
|
|
|
|
|
arguments:
|
|
|
|
thd: the thread handle of the current connection
|
|
|
|
return value: always 0
|
|
|
|
*/
|
|
|
|
|
2006-03-26 11:32:52 +02:00
|
|
|
static my_bool release_temporary_latches(THD *thd, st_plugin_int *plugin,
|
|
|
|
void *unused)
|
|
|
|
{
|
2006-05-31 18:07:32 +02:00
|
|
|
handlerton *hton= (handlerton *)plugin->data;
|
2006-03-26 11:32:52 +02:00
|
|
|
|
|
|
|
if (hton->state == SHOW_OPTION_YES && hton->release_temporary_latches)
|
|
|
|
hton->release_temporary_latches(thd);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-03 18:31:01 +01:00
|
|
|
int ha_release_temporary_latches(THD *thd)
|
|
|
|
{
|
2006-03-26 11:32:52 +02:00
|
|
|
plugin_foreach(thd, release_temporary_latches, MYSQL_STORAGE_ENGINE_PLUGIN,
|
|
|
|
NULL);
|
|
|
|
|
2006-01-06 12:21:15 +01:00
|
|
|
return 0;
|
2003-03-03 18:31:01 +01:00
|
|
|
}
|
|
|
|
|
2005-01-16 13:16:23 +01:00
|
|
|
int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
int error=0;
|
2005-11-19 13:09:23 +01:00
|
|
|
THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction.stmt :
|
|
|
|
&thd->transaction.all);
|
2005-01-16 13:16:23 +01:00
|
|
|
handlerton **ht=trans->ht, **end_ht;
|
|
|
|
DBUG_ENTER("ha_rollback_to_savepoint");
|
2002-08-08 02:12:02 +02:00
|
|
|
|
2005-01-16 13:16:23 +01:00
|
|
|
trans->nht=sv->nht;
|
|
|
|
trans->no_2pc=0;
|
|
|
|
end_ht=ht+sv->nht;
|
|
|
|
/*
|
|
|
|
rolling back to savepoint in all storage engines that were part of the
|
|
|
|
transaction when the savepoint was set
|
|
|
|
*/
|
|
|
|
for (; ht < end_ht; ht++)
|
|
|
|
{
|
|
|
|
int err;
|
2005-02-25 15:53:22 +01:00
|
|
|
DBUG_ASSERT((*ht)->savepoint_set != 0);
|
2005-01-16 13:16:23 +01:00
|
|
|
if ((err= (*(*ht)->savepoint_rollback)(thd, (byte *)(sv+1)+(*ht)->savepoint_offset)))
|
|
|
|
{ // cannot happen
|
|
|
|
my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
|
|
|
|
error=1;
|
2002-06-08 23:58:05 +02:00
|
|
|
}
|
2005-11-23 21:45:02 +01:00
|
|
|
statistic_increment(thd->status_var.ha_savepoint_rollback_count,
|
|
|
|
&LOCK_status);
|
2005-01-16 13:16:23 +01:00
|
|
|
trans->no_2pc|=(*ht)->prepare == 0;
|
2001-03-06 14:24:08 +01:00
|
|
|
}
|
2005-01-16 13:16:23 +01:00
|
|
|
/*
|
|
|
|
rolling back the transaction in all storage engines that were not part of
|
|
|
|
the transaction when the savepoint was set
|
|
|
|
*/
|
|
|
|
for (; *ht ; ht++)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2005-01-16 13:16:23 +01:00
|
|
|
int err;
|
2005-11-19 13:09:23 +01:00
|
|
|
if ((err= (*(*ht)->rollback)(thd, !thd->in_sub_stmt)))
|
2005-01-16 13:16:23 +01:00
|
|
|
{ // cannot happen
|
|
|
|
my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
|
|
|
|
error=1;
|
2 minor edits, plus
fix for BUG#1113 "INSERT into non-trans table SELECT ; ROLLBACK" does not send warning"
and
fix for BUG#873 "In transaction, INSERT to non-trans table is written too early to binlog".
Now we don't always write the non-trans update immediately to the binlog;
if there is something in the binlog cache we write it to the binlog cache
(because the non-trans update could depend on a trans table which was modified
earlier in the transaction); then in case of ROLLBACK, we write the binlog
cache to the binlog, wrapped with BEGIN/ROLLBACK.
This guarantees that the slave does the same updates.
For ROLLBACK TO SAVEPOINT: when we execute a SAVEPOINT command we write it
to the binlog cache. At ROLLBACK TO SAVEPOINT, if some non-trans table was updated,
we write ROLLBACK TO SAVEPOINT to the binlog cache; when the transaction
terminates (COMMIT/ROLLBACK), the binlog cache will be flushed to the binlog
(because of the non-trans update) so we'll have SAVEPOINT and ROLLBACK TO
SAVEPOINT in the binlog.
Apart from this rare case of updates of mixed table types in transaction, the
usual way is still clear the binlog cache at ROLLBACK, or chop it at
ROLLBACK TO SAVEPOINT (meaning the SAVEPOINT command is also chopped, which
is fine).
Note that BUG#873 encompasses subbugs 1) and 2) of BUG#333 "3 binlogging bugs when doing INSERT with mixed InnoDB/MyISAM".
2003-08-22 15:39:24 +02:00
|
|
|
}
|
2005-01-16 13:16:23 +01:00
|
|
|
statistic_increment(thd->status_var.ha_rollback_count,&LOCK_status);
|
|
|
|
*ht=0; // keep it conveniently zero-filled
|
2001-03-06 14:24:08 +01:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2003-06-15 00:04:28 +02:00
|
|
|
/*
|
2005-01-16 13:16:23 +01:00
|
|
|
note, that according to the sql standard (ISO/IEC 9075-2:2003)
|
|
|
|
section "4.33.4 SQL-statements and transaction states",
|
|
|
|
SAVEPOINT is *not* transaction-initiating SQL-statement
|
2003-06-15 00:04:28 +02:00
|
|
|
*/
|
|
|
|
|
2005-01-16 13:16:23 +01:00
|
|
|
int ha_savepoint(THD *thd, SAVEPOINT *sv)
|
2003-06-15 00:04:28 +02:00
|
|
|
{
|
|
|
|
int error=0;
|
2005-11-19 13:09:23 +01:00
|
|
|
THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction.stmt :
|
|
|
|
&thd->transaction.all);
|
2005-01-16 13:16:23 +01:00
|
|
|
handlerton **ht=trans->ht;
|
|
|
|
DBUG_ENTER("ha_savepoint");
|
2003-06-15 00:04:28 +02:00
|
|
|
#ifdef USING_TRANSACTIONS
|
2005-01-16 13:16:23 +01:00
|
|
|
for (; *ht; ht++)
|
2003-06-15 00:04:28 +02:00
|
|
|
{
|
2005-01-16 13:16:23 +01:00
|
|
|
int err;
|
|
|
|
if (! (*ht)->savepoint_set)
|
2003-06-15 00:04:28 +02:00
|
|
|
{
|
2005-01-16 13:16:23 +01:00
|
|
|
my_error(ER_CHECK_NOT_IMPLEMENTED, MYF(0), "SAVEPOINT");
|
2003-06-15 00:04:28 +02:00
|
|
|
error=1;
|
2005-01-16 13:16:23 +01:00
|
|
|
break;
|
2003-06-15 00:04:28 +02:00
|
|
|
}
|
2005-01-16 13:16:23 +01:00
|
|
|
if ((err= (*(*ht)->savepoint_set)(thd, (byte *)(sv+1)+(*ht)->savepoint_offset)))
|
|
|
|
{ // cannot happen
|
|
|
|
my_error(ER_GET_ERRNO, MYF(0), err);
|
2005-02-01 20:48:05 +01:00
|
|
|
error=1;
|
|
|
|
}
|
2005-01-16 13:16:23 +01:00
|
|
|
statistic_increment(thd->status_var.ha_savepoint_count,&LOCK_status);
|
2005-02-01 20:48:05 +01:00
|
|
|
}
|
2005-01-16 13:16:23 +01:00
|
|
|
sv->nht=trans->nht;
|
2005-02-01 20:48:05 +01:00
|
|
|
#endif /* USING_TRANSACTIONS */
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2005-01-16 13:16:23 +01:00
|
|
|
int ha_release_savepoint(THD *thd, SAVEPOINT *sv)
|
2003-06-15 00:04:28 +02:00
|
|
|
{
|
|
|
|
int error=0;
|
2005-11-19 13:09:23 +01:00
|
|
|
THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction.stmt :
|
|
|
|
&thd->transaction.all);
|
|
|
|
handlerton **ht=trans->ht, **end_ht;
|
2005-01-16 13:16:23 +01:00
|
|
|
DBUG_ENTER("ha_release_savepoint");
|
|
|
|
|
|
|
|
end_ht=ht+sv->nht;
|
|
|
|
for (; ht < end_ht; ht++)
|
2003-06-15 00:04:28 +02:00
|
|
|
{
|
2005-01-16 13:16:23 +01:00
|
|
|
int err;
|
|
|
|
if (!(*ht)->savepoint_release)
|
|
|
|
continue;
|
|
|
|
if ((err= (*(*ht)->savepoint_release)(thd, (byte *)(sv+1)+(*ht)->savepoint_offset)))
|
|
|
|
{ // cannot happen
|
|
|
|
my_error(ER_GET_ERRNO, MYF(0), err);
|
|
|
|
error=1;
|
2 minor edits, plus
fix for BUG#1113 "INSERT into non-trans table SELECT ; ROLLBACK" does not send warning"
and
fix for BUG#873 "In transaction, INSERT to non-trans table is written too early to binlog".
Now we don't always write the non-trans update immediately to the binlog;
if there is something in the binlog cache we write it to the binlog cache
(because the non-trans update could depend on a trans table which was modified
earlier in the transaction); then in case of ROLLBACK, we write the binlog
cache to the binlog, wrapped with BEGIN/ROLLBACK.
This guarantees that the slave does the same updates.
For ROLLBACK TO SAVEPOINT: when we execute a SAVEPOINT command we write it
to the binlog cache. At ROLLBACK TO SAVEPOINT, if some non-trans table was updated,
we write ROLLBACK TO SAVEPOINT to the binlog cache; when the transaction
terminates (COMMIT/ROLLBACK), the binlog cache will be flushed to the binlog
(because of the non-trans update) so we'll have SAVEPOINT and ROLLBACK TO
SAVEPOINT in the binlog.
Apart from this rare case of updates of mixed table types in transaction, the
usual way is still clear the binlog cache at ROLLBACK, or chop it at
ROLLBACK TO SAVEPOINT (meaning the SAVEPOINT command is also chopped, which
is fine).
Note that BUG#873 encompasses subbugs 1) and 2) of BUG#333 "3 binlogging bugs when doing INSERT with mixed InnoDB/MyISAM".
2003-08-22 15:39:24 +02:00
|
|
|
}
|
2003-06-15 00:04:28 +02:00
|
|
|
}
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2004-11-10 17:56:45 +01:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
static my_bool snapshot_handlerton(THD *thd, st_plugin_int *plugin,
|
|
|
|
void *arg)
|
|
|
|
{
|
2006-05-31 18:07:32 +02:00
|
|
|
handlerton *hton= (handlerton *)plugin->data;
|
2005-12-21 19:18:40 +01:00
|
|
|
if (hton->state == SHOW_OPTION_YES &&
|
|
|
|
hton->start_consistent_snapshot)
|
|
|
|
{
|
|
|
|
hton->start_consistent_snapshot(thd);
|
|
|
|
*((bool *)arg)= false;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-11-10 17:56:45 +01:00
|
|
|
int ha_start_consistent_snapshot(THD *thd)
|
|
|
|
{
|
2005-11-07 16:25:06 +01:00
|
|
|
bool warn= true;
|
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
plugin_foreach(thd, snapshot_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, &warn);
|
|
|
|
|
2004-11-10 17:56:45 +01:00
|
|
|
/*
|
|
|
|
Same idea as when one wants to CREATE TABLE in one engine which does not
|
|
|
|
exist:
|
|
|
|
*/
|
2005-11-07 16:25:06 +01:00
|
|
|
if (warn)
|
|
|
|
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
|
|
|
|
"This MySQL server does not support any "
|
|
|
|
"consistent-read capable storage engine");
|
2004-11-10 17:56:45 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
static my_bool flush_handlerton(THD *thd, st_plugin_int *plugin,
|
|
|
|
void *arg)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2006-05-31 18:07:32 +02:00
|
|
|
handlerton *hton= (handlerton *)plugin->data;
|
2005-12-21 19:18:40 +01:00
|
|
|
if (hton->state == SHOW_OPTION_YES && hton->flush_logs && hton->flush_logs())
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-11-07 16:25:06 +01:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
bool ha_flush_logs(handlerton *db_type)
|
|
|
|
{
|
|
|
|
if (db_type == NULL)
|
2005-11-07 16:25:06 +01:00
|
|
|
{
|
2005-12-21 19:18:40 +01:00
|
|
|
if (plugin_foreach(NULL, flush_handlerton,
|
|
|
|
MYSQL_STORAGE_ENGINE_PLUGIN, 0))
|
|
|
|
return TRUE;
|
2005-11-07 16:25:06 +01:00
|
|
|
}
|
2005-12-21 19:18:40 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (db_type->state != SHOW_OPTION_YES ||
|
|
|
|
(db_type->flush_logs && db_type->flush_logs()))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2000-12-08 16:04:57 +01:00
|
|
|
/*
|
|
|
|
This should return ENOENT if the file doesn't exists.
|
|
|
|
The .frm file will be deleted only if we return 0 or ENOENT
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
int ha_delete_table(THD *thd, handlerton *table_type, const char *path,
|
2005-11-23 21:45:02 +01:00
|
|
|
const char *db, const char *alias, bool generate_warning)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-11-12 04:01:46 +01:00
|
|
|
handler *file;
|
2003-12-30 12:14:21 +01:00
|
|
|
char tmp_path[FN_REFLEN];
|
2005-02-21 19:41:48 +01:00
|
|
|
int error;
|
|
|
|
TABLE dummy_table;
|
|
|
|
TABLE_SHARE dummy_share;
|
|
|
|
DBUG_ENTER("ha_delete_table");
|
|
|
|
|
|
|
|
bzero((char*) &dummy_table, sizeof(dummy_table));
|
|
|
|
bzero((char*) &dummy_share, sizeof(dummy_share));
|
|
|
|
dummy_table.s= &dummy_share;
|
2004-11-12 04:01:46 +01:00
|
|
|
|
|
|
|
/* DB_TYPE_UNKNOWN is used in ALTER TABLE when renaming only .frm files */
|
2005-12-21 19:18:40 +01:00
|
|
|
if (table_type == NULL ||
|
2005-11-23 21:45:02 +01:00
|
|
|
! (file=get_new_handler(&dummy_share, thd->mem_root, table_type)))
|
2005-02-21 19:41:48 +01:00
|
|
|
DBUG_RETURN(ENOENT);
|
2004-11-12 04:01:46 +01:00
|
|
|
|
2003-12-30 12:14:21 +01:00
|
|
|
if (lower_case_table_names == 2 && !(file->table_flags() & HA_FILE_BASED))
|
|
|
|
{
|
|
|
|
/* Ensure that table handler get path in lower case */
|
|
|
|
strmov(tmp_path, path);
|
2004-05-22 21:41:58 +02:00
|
|
|
my_casedn_str(files_charset_info, tmp_path);
|
2003-12-30 12:14:21 +01:00
|
|
|
path= tmp_path;
|
|
|
|
}
|
2005-02-21 19:41:48 +01:00
|
|
|
if ((error= file->delete_table(path)) && generate_warning)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Because file->print_error() use my_error() to generate the error message
|
|
|
|
we must store the error state in thd, reset it and restore it to
|
|
|
|
be able to get hold of the error message.
|
|
|
|
(We should in the future either rewrite handler::print_error() or make
|
|
|
|
a nice method of this.
|
|
|
|
*/
|
|
|
|
bool query_error= thd->query_error;
|
|
|
|
sp_rcontext *spcont= thd->spcont;
|
|
|
|
SELECT_LEX *current_select= thd->lex->current_select;
|
|
|
|
char buff[sizeof(thd->net.last_error)];
|
|
|
|
char new_error[sizeof(thd->net.last_error)];
|
|
|
|
int last_errno= thd->net.last_errno;
|
|
|
|
|
|
|
|
strmake(buff, thd->net.last_error, sizeof(buff)-1);
|
|
|
|
thd->query_error= 0;
|
|
|
|
thd->spcont= 0;
|
|
|
|
thd->lex->current_select= 0;
|
|
|
|
thd->net.last_error[0]= 0;
|
|
|
|
|
|
|
|
/* Fill up strucutures that print_error may need */
|
2005-11-23 21:45:02 +01:00
|
|
|
dummy_share.path.str= (char*) path;
|
|
|
|
dummy_share.path.length= strlen(path);
|
|
|
|
dummy_share.db.str= (char*) db;
|
|
|
|
dummy_share.db.length= strlen(db);
|
|
|
|
dummy_share.table_name.str= (char*) alias;
|
|
|
|
dummy_share.table_name.length= strlen(alias);
|
2005-02-21 19:41:48 +01:00
|
|
|
dummy_table.alias= alias;
|
|
|
|
|
|
|
|
file->print_error(error, 0);
|
|
|
|
strmake(new_error, thd->net.last_error, sizeof(buff)-1);
|
|
|
|
|
|
|
|
/* restore thd */
|
|
|
|
thd->query_error= query_error;
|
|
|
|
thd->spcont= spcont;
|
|
|
|
thd->lex->current_select= current_select;
|
|
|
|
thd->net.last_errno= last_errno;
|
|
|
|
strmake(thd->net.last_error, buff, sizeof(buff)-1);
|
|
|
|
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, error, new_error);
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
delete file;
|
2005-02-21 19:41:48 +01:00
|
|
|
DBUG_RETURN(error);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2001-12-06 13:10:51 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/****************************************************************************
|
|
|
|
** General handler functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2006-01-19 22:40:56 +01:00
|
|
|
|
|
|
|
void handler::ha_statistic_increment(ulong SSV::*offset) const
|
|
|
|
{
|
|
|
|
statistic_increment(table->in_use->status_var.*offset, &LOCK_status);
|
|
|
|
}
|
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
/*
|
|
|
|
Open database-handler.
|
|
|
|
|
|
|
|
IMPLEMENTATION
|
|
|
|
Try O_RDONLY if cannot open as O_RDWR
|
|
|
|
Don't wait for locks if not HA_OPEN_WAIT_IF_LOCKED is set
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
int handler::ha_open(TABLE *table_arg, const char *name, int mode,
|
|
|
|
int test_if_locked)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
int error;
|
2004-08-22 14:23:52 +02:00
|
|
|
DBUG_ENTER("handler::ha_open");
|
2005-11-23 21:45:02 +01:00
|
|
|
DBUG_PRINT("enter",
|
|
|
|
("name: %s db_type: %d db_stat: %d mode: %d lock_test: %d",
|
|
|
|
name, table_share->db_type, table_arg->db_stat, mode,
|
|
|
|
test_if_locked));
|
|
|
|
|
|
|
|
table= table_arg;
|
|
|
|
DBUG_ASSERT(table->s == table_share);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
if ((error=open(name,mode,test_if_locked)))
|
|
|
|
{
|
|
|
|
if ((error == EACCES || error == EROFS) && mode == O_RDWR &&
|
|
|
|
(table->db_stat & HA_TRY_READ_ONLY))
|
|
|
|
{
|
|
|
|
table->db_stat|=HA_READ_ONLY;
|
|
|
|
error=open(name,O_RDONLY,test_if_locked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (error)
|
|
|
|
{
|
2005-11-23 21:45:02 +01:00
|
|
|
my_errno= error; /* Safeguard */
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_PRINT("error",("error: %d errno: %d",error,errno));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-01-06 12:00:13 +01:00
|
|
|
if (table->s->db_options_in_use & HA_OPTION_READ_ONLY_DATA)
|
2000-07-31 21:29:14 +02:00
|
|
|
table->db_stat|=HA_READ_ONLY;
|
2002-01-16 22:02:26 +01:00
|
|
|
(void) extra(HA_EXTRA_NO_READCHECK); // Not needed in SQL
|
|
|
|
|
2005-09-22 00:11:21 +02:00
|
|
|
DBUG_ASSERT(alloc_root_inited(&table->mem_root));
|
|
|
|
|
|
|
|
if (!(ref= (byte*) alloc_root(&table->mem_root, ALIGN_SIZE(ref_length)*2)))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
close();
|
|
|
|
error=HA_ERR_OUT_OF_MEM;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dupp_ref=ref+ALIGN_SIZE(ref_length);
|
2005-11-23 21:45:02 +01:00
|
|
|
|
|
|
|
if (ha_allocate_read_write_set(table->s->fields))
|
|
|
|
error= 1;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
|
2005-05-02 15:45:33 +02:00
|
|
|
int handler::ha_initialise()
|
|
|
|
{
|
2005-05-04 10:44:11 +02:00
|
|
|
DBUG_ENTER("ha_initialise");
|
|
|
|
DBUG_RETURN(FALSE);
|
2005-05-02 15:45:33 +02:00
|
|
|
}
|
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Initalize bit maps for used fields
|
|
|
|
|
|
|
|
Called from open_table_from_share()
|
|
|
|
*/
|
|
|
|
|
2005-04-28 14:45:27 +02:00
|
|
|
int handler::ha_allocate_read_write_set(ulong no_fields)
|
|
|
|
{
|
2005-11-24 05:15:35 +01:00
|
|
|
uint bitmap_size= bitmap_buffer_size(no_fields+1);
|
2005-06-02 18:40:25 +02:00
|
|
|
uint32 *read_buf, *write_buf;
|
2005-04-28 14:45:27 +02:00
|
|
|
DBUG_ENTER("ha_allocate_read_write_set");
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_PRINT("enter", ("no_fields = %d", no_fields));
|
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
if (!multi_alloc_root(&table->mem_root,
|
|
|
|
&read_set, sizeof(MY_BITMAP),
|
|
|
|
&write_set, sizeof(MY_BITMAP),
|
|
|
|
&read_buf, bitmap_size,
|
|
|
|
&write_buf, bitmap_size,
|
|
|
|
NullS))
|
2005-07-18 13:31:02 +02:00
|
|
|
{
|
2005-11-23 21:45:02 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
2005-07-18 13:31:02 +02:00
|
|
|
}
|
2005-11-23 21:45:02 +01:00
|
|
|
bitmap_init(read_set, read_buf, no_fields+1, FALSE);
|
|
|
|
bitmap_init(write_set, write_buf, no_fields+1, FALSE);
|
|
|
|
table->read_set= read_set;
|
|
|
|
table->write_set= write_set;
|
|
|
|
ha_clear_all_set();
|
2005-04-28 14:45:27 +02:00
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
|
|
|
|
2005-05-02 15:45:33 +02:00
|
|
|
void handler::ha_clear_all_set()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_clear_all_set");
|
2005-05-12 11:20:50 +02:00
|
|
|
bitmap_clear_all(read_set);
|
|
|
|
bitmap_clear_all(write_set);
|
|
|
|
bitmap_set_bit(read_set, 0);
|
|
|
|
bitmap_set_bit(write_set, 0);
|
2005-05-05 10:17:09 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2005-05-02 15:45:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int handler::ha_retrieve_all_cols()
|
|
|
|
{
|
2005-05-04 10:44:11 +02:00
|
|
|
DBUG_ENTER("handler::ha_retrieve_all_cols");
|
2005-05-12 11:20:50 +02:00
|
|
|
bitmap_set_all(read_set);
|
2005-05-04 10:44:11 +02:00
|
|
|
DBUG_RETURN(0);
|
2005-05-02 15:45:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int handler::ha_retrieve_all_pk()
|
|
|
|
{
|
2005-05-04 10:44:11 +02:00
|
|
|
DBUG_ENTER("ha_retrieve_all_pk");
|
2005-05-02 15:45:33 +02:00
|
|
|
ha_set_primary_key_in_read_set();
|
2005-05-04 10:44:11 +02:00
|
|
|
DBUG_RETURN(0);
|
2005-04-28 14:45:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void handler::ha_set_primary_key_in_read_set()
|
|
|
|
{
|
|
|
|
ulong prim_key= table->s->primary_key;
|
2005-05-02 15:45:33 +02:00
|
|
|
DBUG_ENTER("handler::ha_set_primary_key_in_read_set");
|
|
|
|
DBUG_PRINT("info", ("Primary key = %d", prim_key));
|
2005-04-28 14:45:27 +02:00
|
|
|
if (prim_key != MAX_KEY)
|
|
|
|
{
|
|
|
|
KEY_PART_INFO *key_part= table->key_info[prim_key].key_part;
|
|
|
|
KEY_PART_INFO *key_part_end= key_part +
|
|
|
|
table->key_info[prim_key].key_parts;
|
|
|
|
for (;key_part != key_part_end; ++key_part)
|
|
|
|
ha_set_bit_in_read_set(key_part->fieldnr);
|
|
|
|
}
|
2005-05-02 15:45:33 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2005-04-28 14:45:27 +02:00
|
|
|
}
|
2005-07-18 13:31:02 +02:00
|
|
|
|
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
|
2002-01-23 01:52:26 +01:00
|
|
|
/*
|
|
|
|
Read first row (only) from a table
|
|
|
|
This is never called for InnoDB or BDB tables, as these table types
|
|
|
|
has the HA_NOT_EXACT_COUNT set.
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2002-01-23 01:52:26 +01:00
|
|
|
int handler::read_first_row(byte * buf, uint primary_key)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
register int error;
|
2002-01-23 01:52:26 +01:00
|
|
|
DBUG_ENTER("handler::read_first_row");
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
statistic_increment(table->in_use->status_var.ha_read_first_count,
|
|
|
|
&LOCK_status);
|
2002-01-23 01:52:26 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
If there is very few deleted rows in the table, find the first row by
|
|
|
|
scanning the table.
|
2004-11-22 14:53:18 +01:00
|
|
|
TODO remove the test for HA_READ_ORDER
|
2002-01-23 01:52:26 +01:00
|
|
|
*/
|
2004-11-22 14:53:18 +01:00
|
|
|
if (deleted < 10 || primary_key >= MAX_KEY ||
|
|
|
|
!(index_flags(primary_key, 0, 0) & HA_READ_ORDER))
|
2002-01-23 01:52:26 +01:00
|
|
|
{
|
2004-06-23 12:29:05 +02:00
|
|
|
(void) ha_rnd_init(1);
|
2002-01-23 01:52:26 +01:00
|
|
|
while ((error= rnd_next(buf)) == HA_ERR_RECORD_DELETED) ;
|
2004-06-23 12:29:05 +02:00
|
|
|
(void) ha_rnd_end();
|
2002-01-23 01:52:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Find the first row through the primary key */
|
2005-07-18 13:31:02 +02:00
|
|
|
(void) ha_index_init(primary_key, 0);
|
2002-01-23 01:52:26 +01:00
|
|
|
error=index_first(buf);
|
2004-06-23 12:29:05 +02:00
|
|
|
(void) ha_index_end();
|
2002-01-23 01:52:26 +01:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2002-01-23 01:52:26 +01:00
|
|
|
/*
|
2004-11-12 04:01:46 +01:00
|
|
|
Generate the next auto-increment number based on increment and offset
|
2005-02-14 21:50:09 +01:00
|
|
|
|
2004-11-12 04:01:46 +01:00
|
|
|
In most cases increment= offset= 1, in which case we get:
|
|
|
|
1,2,3,4,5,...
|
|
|
|
If increment=10 and offset=5 and previous number is 1, we get:
|
|
|
|
1,5,15,25,35,...
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline ulonglong
|
|
|
|
next_insert_id(ulonglong nr,struct system_variables *variables)
|
|
|
|
{
|
|
|
|
nr= (((nr+ variables->auto_increment_increment -
|
|
|
|
variables->auto_increment_offset)) /
|
|
|
|
(ulonglong) variables->auto_increment_increment);
|
|
|
|
return (nr* (ulonglong) variables->auto_increment_increment +
|
|
|
|
variables->auto_increment_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2005-05-18 09:41:35 +02:00
|
|
|
Update the auto_increment field if necessary
|
|
|
|
|
|
|
|
SYNOPSIS
|
2006-06-02 22:21:32 +02:00
|
|
|
update_auto_increment()
|
2005-05-18 09:41:35 +02:00
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 ok
|
|
|
|
1 get_auto_increment() was called and returned ~(ulonglong) 0
|
|
|
|
|
|
|
|
|
|
|
|
IMPLEMENTATION
|
|
|
|
|
|
|
|
Updates columns with type NEXT_NUMBER if:
|
2004-11-12 04:01:46 +01:00
|
|
|
|
|
|
|
- If column value is set to NULL (in which case
|
|
|
|
auto_increment_field_not_null is 0)
|
|
|
|
- If column is set to 0 and (sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO) is not
|
|
|
|
set. In the future we will only set NEXT_NUMBER fields if one sets them
|
|
|
|
to NULL (or they are not included in the insert list).
|
|
|
|
|
|
|
|
|
|
|
|
There are two different cases when the above is true:
|
|
|
|
|
|
|
|
- thd->next_insert_id == 0 (This is the normal case)
|
|
|
|
In this case we set the set the column for the first row to the value
|
|
|
|
next_insert_id(get_auto_increment(column))) which is normally
|
|
|
|
max-used-column-value +1.
|
|
|
|
|
|
|
|
We call get_auto_increment() only for the first row in a multi-row
|
|
|
|
statement. For the following rows we generate new numbers based on the
|
|
|
|
last used number.
|
|
|
|
|
2006-06-02 22:21:32 +02:00
|
|
|
- thd->next_insert_id != 0. This happens when we have read an Intvar event
|
|
|
|
of type INSERT_ID_EVENT from the binary log or when one has used SET
|
|
|
|
INSERT_ID=#.
|
2004-11-12 04:01:46 +01:00
|
|
|
|
|
|
|
In this case we will set the column to the value of next_insert_id.
|
|
|
|
The next row will be given the id
|
|
|
|
next_insert_id(next_insert_id)
|
|
|
|
|
|
|
|
The idea is that generated auto_increment values are predictable and
|
|
|
|
independent of the column values in the table. This is needed to be
|
|
|
|
able to replicate into a table that already has rows with a higher
|
|
|
|
auto-increment value than the one that is inserted.
|
|
|
|
|
|
|
|
After we have already generated an auto-increment number and the user
|
|
|
|
inserts a column with a higher value than the last used one, we will
|
|
|
|
start counting from the inserted value.
|
|
|
|
|
|
|
|
thd->next_insert_id is cleared after it's been used for a statement.
|
2006-06-02 22:21:32 +02:00
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
Replace all references to "next number" or NEXT_NUMBER to
|
|
|
|
"auto_increment", everywhere (see below: there is
|
|
|
|
table->auto_increment_field_not_null, and there also exists
|
|
|
|
table->next_number_field, it's not consistent).
|
|
|
|
|
2002-01-23 01:52:26 +01:00
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2006-06-02 22:21:32 +02:00
|
|
|
#define AUTO_INC_DEFAULT_NB_ROWS 1 // Some prefer 1024 here
|
|
|
|
#define AUTO_INC_DEFAULT_NB_MAX_BITS 16
|
|
|
|
#define AUTO_INC_DEFAULT_NB_MAX ((1 << AUTO_INC_DEFAULT_NB_MAX_BITS) - 1)
|
|
|
|
|
2005-05-18 09:41:35 +02:00
|
|
|
bool handler::update_auto_increment()
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-11-12 04:01:46 +01:00
|
|
|
ulonglong nr;
|
|
|
|
THD *thd= table->in_use;
|
|
|
|
struct system_variables *variables= &thd->variables;
|
2005-05-16 14:21:35 +02:00
|
|
|
bool auto_increment_field_not_null;
|
2005-05-18 09:41:35 +02:00
|
|
|
bool result= 0;
|
2004-08-22 14:23:52 +02:00
|
|
|
DBUG_ENTER("handler::update_auto_increment");
|
2004-11-12 04:01:46 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
We must save the previous value to be able to restore it if the
|
|
|
|
row was not inserted
|
|
|
|
*/
|
|
|
|
thd->prev_insert_id= thd->next_insert_id;
|
2005-05-16 14:21:35 +02:00
|
|
|
auto_increment_field_not_null= table->auto_increment_field_not_null;
|
2006-06-02 22:21:32 +02:00
|
|
|
table->auto_increment_field_not_null= FALSE; // to reset for next row
|
2004-11-12 04:01:46 +01:00
|
|
|
|
|
|
|
if ((nr= table->next_number_field->val_int()) != 0 ||
|
2005-05-16 14:21:35 +02:00
|
|
|
auto_increment_field_not_null &&
|
2004-11-12 04:01:46 +01:00
|
|
|
thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO)
|
2001-03-06 14:24:08 +01:00
|
|
|
{
|
2006-06-02 22:21:32 +02:00
|
|
|
/*
|
|
|
|
The user did specify a value for the auto_inc column, we don't generate
|
|
|
|
a new value, write it down.
|
|
|
|
*/
|
2001-03-06 14:24:08 +01:00
|
|
|
auto_increment_column_changed=0;
|
2004-11-12 04:01:46 +01:00
|
|
|
|
2006-06-02 22:21:32 +02:00
|
|
|
/*
|
|
|
|
Update next_insert_id if we had already generated a value in this
|
|
|
|
statement (case of INSERT VALUES(null),(3763),(null):
|
|
|
|
the last NULL needs to insert 3764, not the value of the first NULL plus
|
|
|
|
1).
|
|
|
|
*/
|
2004-11-12 04:01:46 +01:00
|
|
|
if (thd->clear_next_insert_id && nr >= thd->next_insert_id)
|
|
|
|
{
|
|
|
|
if (variables->auto_increment_increment != 1)
|
|
|
|
nr= next_insert_id(nr, variables);
|
|
|
|
else
|
|
|
|
nr++;
|
|
|
|
thd->next_insert_id= nr;
|
|
|
|
DBUG_PRINT("info",("next_insert_id: %lu", (ulong) nr));
|
|
|
|
}
|
2005-05-18 09:41:35 +02:00
|
|
|
DBUG_RETURN(0);
|
2001-03-06 14:24:08 +01:00
|
|
|
}
|
2004-11-12 04:01:46 +01:00
|
|
|
if (!(nr= thd->next_insert_id))
|
|
|
|
{
|
2006-06-02 22:21:32 +02:00
|
|
|
ulonglong nb_desired_values= 1, nb_reserved_values;
|
|
|
|
#ifdef TO_BE_ENABLED_SOON
|
|
|
|
/*
|
|
|
|
Reserved intervals will be stored in "THD::auto_inc_intervals".
|
|
|
|
handler::estimation_rows_to_insert will be the argument passed by
|
|
|
|
handler::ha_start_bulk_insert().
|
|
|
|
*/
|
|
|
|
uint estimation_known= test(estimation_rows_to_insert > 0);
|
|
|
|
uint nb_already_reserved_intervals= thd->auto_inc_intervals.nb_elements();
|
|
|
|
/*
|
|
|
|
If an estimation was given to the engine:
|
|
|
|
- use it.
|
|
|
|
- if we already reserved numbers, it means the estimation was
|
|
|
|
not accurate, then we'll reserve 2*AUTO_INC_DEFAULT_NB_VALUES the 2nd
|
|
|
|
time, twice that the 3rd time etc.
|
|
|
|
If no estimation was given, use those increasing defaults from the
|
|
|
|
start, starting from AUTO_INC_DEFAULT_NB_VALUES.
|
|
|
|
Don't go beyond a max to not reserve "way too much" (because reservation
|
|
|
|
means potentially losing unused values).
|
|
|
|
*/
|
|
|
|
if (nb_already_reserved_intervals == 0 && estimation_known)
|
|
|
|
nb_desired_values= estimation_rows_to_insert;
|
|
|
|
else /* go with the increasing defaults */
|
|
|
|
{
|
|
|
|
/* avoid overflow in formula, with this if() */
|
|
|
|
if (nb_already_reserved_intervals <= AUTO_INC_DEFAULT_NB_MAX_BITS)
|
|
|
|
{
|
|
|
|
nb_desired_values= AUTO_INC_DEFAULT_NB_VALUES *
|
|
|
|
(1 << nb_already_reserved_intervals);
|
|
|
|
set_if_smaller(nb_desired_values, AUTO_INC_DEFAULT_NB_MAX);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nb_desired_values= AUTO_INC_DEFAULT_NB_MAX;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* This call ignores all its parameters but nr, currently */
|
|
|
|
get_auto_increment(variables->auto_increment_offset,
|
|
|
|
variables->auto_increment_increment,
|
|
|
|
nb_desired_values, &nr,
|
|
|
|
&nb_reserved_values);
|
|
|
|
if (nr == ~(ulonglong) 0)
|
2005-05-18 09:41:35 +02:00
|
|
|
result= 1; // Mark failure
|
|
|
|
|
2006-06-02 22:21:32 +02:00
|
|
|
/*
|
|
|
|
That should not be needed when engines actually use offset and increment
|
|
|
|
above.
|
|
|
|
*/
|
2004-11-12 04:01:46 +01:00
|
|
|
if (variables->auto_increment_increment != 1)
|
|
|
|
nr= next_insert_id(nr-1, variables);
|
|
|
|
/*
|
|
|
|
Update next row based on the found value. This way we don't have to
|
|
|
|
call the handler for every generated auto-increment value on a
|
|
|
|
multi-row statement
|
|
|
|
*/
|
|
|
|
thd->next_insert_id= nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_PRINT("info",("auto_increment: %lu", (ulong) nr));
|
|
|
|
|
|
|
|
/* Mark that we should clear next_insert_id before next stmt */
|
|
|
|
thd->clear_next_insert_id= 1;
|
|
|
|
|
2005-09-14 00:41:44 +02:00
|
|
|
if (!table->next_number_field->store((longlong) nr, TRUE))
|
2003-03-31 21:14:26 +02:00
|
|
|
thd->insert_id((ulonglong) nr);
|
2003-06-30 12:28:36 +02:00
|
|
|
else
|
|
|
|
thd->insert_id(table->next_number_field->val_int());
|
2004-11-12 04:01:46 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
We can't set next_insert_id if the auto-increment key is not the
|
|
|
|
first key part, as there is no guarantee that the first parts will be in
|
|
|
|
sequence
|
|
|
|
*/
|
2005-01-06 12:00:13 +01:00
|
|
|
if (!table->s->next_number_key_offset)
|
2004-11-12 04:01:46 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Set next insert id to point to next auto-increment value to be able to
|
|
|
|
handle multi-row statements
|
|
|
|
This works even if auto_increment_increment > 1
|
|
|
|
*/
|
|
|
|
thd->next_insert_id= next_insert_id(nr, variables);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
thd->next_insert_id= 0;
|
|
|
|
|
|
|
|
/* Mark that we generated a new value */
|
2001-03-06 14:24:08 +01:00
|
|
|
auto_increment_column_changed=1;
|
2005-05-18 09:41:35 +02:00
|
|
|
DBUG_RETURN(result);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2004-11-12 04:01:46 +01:00
|
|
|
/*
|
|
|
|
restore_auto_increment
|
|
|
|
|
|
|
|
In case of error on write, we restore the last used next_insert_id value
|
|
|
|
because the previous value was not used.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void handler::restore_auto_increment()
|
|
|
|
{
|
|
|
|
THD *thd= table->in_use;
|
|
|
|
if (thd->next_insert_id)
|
|
|
|
thd->next_insert_id= thd->prev_insert_id;
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2006-06-02 22:21:32 +02:00
|
|
|
/*
|
|
|
|
Reserves an interval of auto_increment values from the handler.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
get_auto_increment()
|
|
|
|
offset
|
|
|
|
increment
|
|
|
|
nb_desired_values how many values we want
|
|
|
|
first_value (OUT) the first value reserved by the handler
|
|
|
|
nb_reserved_values (OUT) how many values the handler reserved
|
|
|
|
|
|
|
|
offset and increment means that we want values to be of the form
|
|
|
|
offset + N * increment, where N>=0 is integer.
|
|
|
|
If the function sets *first_value to ~(ulonglong)0 it means an error.
|
|
|
|
If the function sets *nb_reserved_values to ULONGLONG_MAX it means it has
|
|
|
|
reserved to "positive infinite".
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void handler::get_auto_increment(ulonglong offset, ulonglong increment,
|
|
|
|
ulonglong nb_desired_values,
|
|
|
|
ulonglong *first_value,
|
|
|
|
ulonglong *nb_reserved_values)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-11-12 04:01:46 +01:00
|
|
|
ulonglong nr;
|
2000-07-31 21:29:14 +02:00
|
|
|
int error;
|
2002-07-21 23:55:32 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
(void) extra(HA_EXTRA_KEYREAD);
|
2005-07-18 13:31:02 +02:00
|
|
|
index_init(table->s->next_number_index, 1);
|
2005-01-06 12:00:13 +01:00
|
|
|
if (!table->s->next_number_key_offset)
|
2002-07-21 23:55:32 +02:00
|
|
|
{ // Autoincrement at key-start
|
|
|
|
error=index_last(table->record[1]);
|
2006-06-02 22:21:32 +02:00
|
|
|
/*
|
|
|
|
MySQL implicitely assumes such method does locking (as MySQL decides to
|
|
|
|
use nr+increment without checking again with the handler, in
|
|
|
|
handler::update_auto_increment()), so reserves to infinite.
|
|
|
|
*/
|
|
|
|
*nb_reserved_values= ULONGLONG_MAX;
|
2002-07-21 23:55:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
byte key[MAX_KEY_LENGTH];
|
2004-11-12 04:01:46 +01:00
|
|
|
key_copy(key, table->record[0],
|
2005-01-06 12:00:13 +01:00
|
|
|
table->key_info + table->s->next_number_index,
|
|
|
|
table->s->next_number_key_offset);
|
|
|
|
error= index_read(table->record[1], key, table->s->next_number_key_offset,
|
|
|
|
HA_READ_PREFIX_LAST);
|
2006-06-02 22:21:32 +02:00
|
|
|
/*
|
|
|
|
MySQL needs to call us for next row: assume we are inserting ("a",null)
|
|
|
|
here, we return 3, and next this statement will want to insert
|
|
|
|
("b",null): there is no reason why ("b",3+1) would be the good row to
|
|
|
|
insert: maybe it already exists, maybe 3+1 is too large...
|
|
|
|
*/
|
|
|
|
*nb_reserved_values= 1;
|
2002-07-21 23:55:32 +02:00
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
if (error)
|
|
|
|
nr=1;
|
|
|
|
else
|
2005-01-06 12:00:13 +01:00
|
|
|
nr= ((ulonglong) table->next_number_field->
|
|
|
|
val_int_offset(table->s->rec_buff_length)+1);
|
2000-07-31 21:29:14 +02:00
|
|
|
index_end();
|
2002-07-21 23:55:32 +02:00
|
|
|
(void) extra(HA_EXTRA_NO_KEYREAD);
|
2006-06-02 22:21:32 +02:00
|
|
|
*first_value= nr;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2005-02-21 19:41:48 +01:00
|
|
|
|
2006-05-12 15:02:42 +02:00
|
|
|
void handler::print_keydupp_error(uint key_nr, const char *msg)
|
|
|
|
{
|
|
|
|
/* Write the duplicated key in the error message */
|
|
|
|
char key[MAX_KEY_LENGTH];
|
|
|
|
String str(key,sizeof(key),system_charset_info);
|
|
|
|
/* Table is opened and defined at this point */
|
|
|
|
key_unpack(&str,table,(uint) key_nr);
|
|
|
|
uint max_length=MYSQL_ERRMSG_SIZE-(uint) strlen(msg);
|
|
|
|
if (str.length() >= max_length)
|
|
|
|
{
|
|
|
|
str.length(max_length-4);
|
|
|
|
str.append(STRING_WITH_LEN("..."));
|
|
|
|
}
|
|
|
|
my_printf_error(ER_DUP_ENTRY, msg,
|
|
|
|
MYF(0), str.c_ptr(), table->key_info[key_nr].name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-21 19:41:48 +01:00
|
|
|
/*
|
|
|
|
Print error that we got from handler function
|
|
|
|
|
2005-03-12 20:09:54 +01:00
|
|
|
NOTE
|
2005-02-21 19:41:48 +01:00
|
|
|
In case of delete table it's only safe to use the following parts of
|
|
|
|
the 'table' structure:
|
|
|
|
table->s->path
|
|
|
|
table->alias
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
void handler::print_error(int error, myf errflag)
|
|
|
|
{
|
2004-08-22 14:23:52 +02:00
|
|
|
DBUG_ENTER("handler::print_error");
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_PRINT("enter",("error: %d",error));
|
|
|
|
|
|
|
|
int textno=ER_GET_ERRNO;
|
|
|
|
switch (error) {
|
2003-07-15 20:43:57 +02:00
|
|
|
case EACCES:
|
|
|
|
textno=ER_OPEN_AS_READONLY;
|
|
|
|
break;
|
2000-07-31 21:29:14 +02:00
|
|
|
case EAGAIN:
|
|
|
|
textno=ER_FILE_USED;
|
|
|
|
break;
|
|
|
|
case ENOENT:
|
|
|
|
textno=ER_FILE_NOT_FOUND;
|
|
|
|
break;
|
|
|
|
case HA_ERR_KEY_NOT_FOUND:
|
|
|
|
case HA_ERR_NO_ACTIVE_RECORD:
|
|
|
|
case HA_ERR_END_OF_FILE:
|
|
|
|
textno=ER_KEY_NOT_FOUND;
|
|
|
|
break;
|
2003-01-28 17:42:08 +01:00
|
|
|
case HA_ERR_WRONG_MRG_TABLE_DEF:
|
2000-07-31 21:29:14 +02:00
|
|
|
textno=ER_WRONG_MRG_TABLE;
|
|
|
|
break;
|
|
|
|
case HA_ERR_FOUND_DUPP_KEY:
|
|
|
|
{
|
|
|
|
uint key_nr=get_dup_key(error);
|
|
|
|
if ((int) key_nr >= 0)
|
|
|
|
{
|
2006-05-12 15:02:42 +02:00
|
|
|
print_keydupp_error(key_nr, ER(ER_DUP_ENTRY));
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
textno=ER_DUP_KEY;
|
|
|
|
break;
|
|
|
|
}
|
2006-02-09 18:43:10 +01:00
|
|
|
case HA_ERR_FOREIGN_DUPLICATE_KEY:
|
|
|
|
{
|
|
|
|
uint key_nr= get_dup_key(error);
|
|
|
|
if ((int) key_nr >= 0)
|
|
|
|
{
|
|
|
|
/* Write the key in the error message */
|
|
|
|
char key[MAX_KEY_LENGTH];
|
|
|
|
String str(key,sizeof(key),system_charset_info);
|
|
|
|
/* Table is opened and defined at this point */
|
|
|
|
key_unpack(&str,table,(uint) key_nr);
|
|
|
|
uint max_length= MYSQL_ERRMSG_SIZE-(uint) strlen(ER(ER_FOREIGN_DUPLICATE_KEY));
|
|
|
|
if (str.length() >= max_length)
|
|
|
|
{
|
|
|
|
str.length(max_length-4);
|
|
|
|
str.append(STRING_WITH_LEN("..."));
|
|
|
|
}
|
|
|
|
my_error(ER_FOREIGN_DUPLICATE_KEY, MYF(0), table_share->table_name.str,
|
|
|
|
str.c_ptr(), key_nr+1);
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
textno= ER_DUP_KEY;
|
|
|
|
break;
|
|
|
|
}
|
2004-12-10 13:06:49 +01:00
|
|
|
case HA_ERR_NULL_IN_SPATIAL:
|
|
|
|
textno= ER_UNKNOWN_ERROR;
|
2005-08-08 20:35:51 +02:00
|
|
|
break;
|
2000-07-31 21:29:14 +02:00
|
|
|
case HA_ERR_FOUND_DUPP_UNIQUE:
|
|
|
|
textno=ER_DUP_UNIQUE;
|
|
|
|
break;
|
|
|
|
case HA_ERR_RECORD_CHANGED:
|
|
|
|
textno=ER_CHECKREAD;
|
|
|
|
break;
|
|
|
|
case HA_ERR_CRASHED:
|
|
|
|
textno=ER_NOT_KEYFILE;
|
|
|
|
break;
|
2004-12-23 20:11:38 +01:00
|
|
|
case HA_ERR_WRONG_IN_RECORD:
|
|
|
|
textno= ER_CRASHED_ON_USAGE;
|
|
|
|
break;
|
2000-11-22 02:45:02 +01:00
|
|
|
case HA_ERR_CRASHED_ON_USAGE:
|
|
|
|
textno=ER_CRASHED_ON_USAGE;
|
|
|
|
break;
|
2004-12-23 20:11:38 +01:00
|
|
|
case HA_ERR_NOT_A_TABLE:
|
|
|
|
textno= error;
|
|
|
|
break;
|
2000-11-22 02:45:02 +01:00
|
|
|
case HA_ERR_CRASHED_ON_REPAIR:
|
|
|
|
textno=ER_CRASHED_ON_REPAIR;
|
|
|
|
break;
|
2000-07-31 21:29:14 +02:00
|
|
|
case HA_ERR_OUT_OF_MEM:
|
2005-08-08 20:35:51 +02:00
|
|
|
textno=ER_OUT_OF_RESOURCES;
|
|
|
|
break;
|
2000-07-31 21:29:14 +02:00
|
|
|
case HA_ERR_WRONG_COMMAND:
|
|
|
|
textno=ER_ILLEGAL_HA;
|
|
|
|
break;
|
|
|
|
case HA_ERR_OLD_FILE:
|
|
|
|
textno=ER_OLD_KEYFILE;
|
|
|
|
break;
|
|
|
|
case HA_ERR_UNSUPPORTED:
|
|
|
|
textno=ER_UNSUPPORTED_EXTENSION;
|
|
|
|
break;
|
|
|
|
case HA_ERR_RECORD_FILE_FULL:
|
2004-12-23 20:11:38 +01:00
|
|
|
case HA_ERR_INDEX_FILE_FULL:
|
2005-08-08 20:35:51 +02:00
|
|
|
textno=ER_RECORD_FILE_FULL;
|
2004-12-23 20:11:38 +01:00
|
|
|
break;
|
2001-05-29 15:29:08 +02:00
|
|
|
case HA_ERR_LOCK_WAIT_TIMEOUT:
|
|
|
|
textno=ER_LOCK_WAIT_TIMEOUT;
|
|
|
|
break;
|
|
|
|
case HA_ERR_LOCK_TABLE_FULL:
|
|
|
|
textno=ER_LOCK_TABLE_FULL;
|
|
|
|
break;
|
2001-09-18 03:58:15 +02:00
|
|
|
case HA_ERR_LOCK_DEADLOCK:
|
|
|
|
textno=ER_LOCK_DEADLOCK;
|
|
|
|
break;
|
2001-05-29 15:29:08 +02:00
|
|
|
case HA_ERR_READ_ONLY_TRANSACTION:
|
|
|
|
textno=ER_READ_ONLY_TRANSACTION;
|
|
|
|
break;
|
2001-10-30 16:38:44 +01:00
|
|
|
case HA_ERR_CANNOT_ADD_FOREIGN:
|
|
|
|
textno=ER_CANNOT_ADD_FOREIGN;
|
|
|
|
break;
|
|
|
|
case HA_ERR_ROW_IS_REFERENCED:
|
2005-09-23 15:22:27 +02:00
|
|
|
{
|
|
|
|
String str;
|
|
|
|
get_error_message(error, &str);
|
|
|
|
my_error(ER_ROW_IS_REFERENCED_2, MYF(0), str.c_ptr_safe());
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
2001-10-30 16:38:44 +01:00
|
|
|
case HA_ERR_NO_REFERENCED_ROW:
|
2005-09-23 15:22:27 +02:00
|
|
|
{
|
|
|
|
String str;
|
|
|
|
get_error_message(error, &str);
|
|
|
|
my_error(ER_NO_REFERENCED_ROW_2, MYF(0), str.c_ptr_safe());
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
2005-04-07 20:17:37 +02:00
|
|
|
case HA_ERR_TABLE_DEF_CHANGED:
|
|
|
|
textno=ER_TABLE_DEF_CHANGED;
|
|
|
|
break;
|
2004-09-13 14:46:38 +02:00
|
|
|
case HA_ERR_NO_SUCH_TABLE:
|
2005-11-23 21:45:02 +01:00
|
|
|
my_error(ER_NO_SUCH_TABLE, MYF(0), table_share->db.str,
|
|
|
|
table_share->table_name.str);
|
2004-09-13 14:46:38 +02:00
|
|
|
break;
|
2005-12-22 06:39:02 +01:00
|
|
|
case HA_ERR_RBR_LOGGING_FAILED:
|
|
|
|
textno= ER_BINLOG_ROW_LOGGING_FAILED;
|
|
|
|
break;
|
2006-01-12 10:05:07 +01:00
|
|
|
case HA_ERR_DROP_INDEX_FK:
|
|
|
|
{
|
|
|
|
const char *ptr= "???";
|
|
|
|
uint key_nr= get_dup_key(error);
|
|
|
|
if ((int) key_nr >= 0)
|
|
|
|
ptr= table->key_info[key_nr].name;
|
|
|
|
my_error(ER_DROP_INDEX_FK, MYF(0), ptr);
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
2006-02-17 07:52:32 +01:00
|
|
|
case HA_ERR_TABLE_NEEDS_UPGRADE:
|
|
|
|
textno=ER_TABLE_NEEDS_UPGRADE;
|
|
|
|
break;
|
2000-07-31 21:29:14 +02:00
|
|
|
default:
|
|
|
|
{
|
2004-05-13 11:56:45 +02:00
|
|
|
/* The error was "unknown" to this function.
|
|
|
|
Ask handler if it has got a message for this error */
|
|
|
|
bool temporary= FALSE;
|
2004-05-24 12:35:39 +02:00
|
|
|
String str;
|
|
|
|
temporary= get_error_message(error, &str);
|
|
|
|
if (!str.is_empty())
|
2004-05-13 11:56:45 +02:00
|
|
|
{
|
2004-05-25 12:10:54 +02:00
|
|
|
const char* engine= table_type();
|
2004-05-13 11:56:45 +02:00
|
|
|
if (temporary)
|
2004-11-13 18:35:51 +01:00
|
|
|
my_error(ER_GET_TEMPORARY_ERRMSG, MYF(0), error, str.ptr(), engine);
|
2004-05-13 11:56:45 +02:00
|
|
|
else
|
2004-11-13 18:35:51 +01:00
|
|
|
my_error(ER_GET_ERRMSG, MYF(0), error, str.ptr(), engine);
|
2004-05-13 11:56:45 +02:00
|
|
|
}
|
2005-01-16 13:16:23 +01:00
|
|
|
else
|
2004-05-13 11:56:45 +02:00
|
|
|
my_error(ER_GET_ERRNO,errflag,error);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
}
|
2005-11-23 21:45:02 +01:00
|
|
|
my_error(textno, errflag, table_share->table_name.str, error);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2003-05-14 00:27:26 +02:00
|
|
|
|
2005-01-16 13:16:23 +01:00
|
|
|
/*
|
2004-05-13 11:56:45 +02:00
|
|
|
Return an error message specific to this handler
|
2005-01-16 13:16:23 +01:00
|
|
|
|
2004-05-13 11:56:45 +02:00
|
|
|
SYNOPSIS
|
2004-05-24 12:35:39 +02:00
|
|
|
error error code previously returned by handler
|
|
|
|
buf Pointer to String where to add error message
|
2005-03-13 21:58:09 +01:00
|
|
|
|
2004-05-24 12:35:39 +02:00
|
|
|
Returns true if this is a temporary error
|
2004-05-13 11:56:45 +02:00
|
|
|
*/
|
|
|
|
|
2004-05-24 12:35:39 +02:00
|
|
|
bool handler::get_error_message(int error, String* buf)
|
2004-05-13 11:56:45 +02:00
|
|
|
{
|
2004-06-23 12:29:05 +02:00
|
|
|
return FALSE;
|
2004-05-13 11:56:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-17 07:52:32 +01:00
|
|
|
int handler::ha_check_for_upgrade(HA_CHECK_OPT *check_opt)
|
|
|
|
{
|
|
|
|
KEY *keyinfo, *keyend;
|
|
|
|
KEY_PART_INFO *keypart, *keypartend;
|
|
|
|
|
|
|
|
if (!table->s->mysql_version)
|
|
|
|
{
|
|
|
|
/* check for blob-in-key error */
|
|
|
|
keyinfo= table->key_info;
|
|
|
|
keyend= table->key_info + table->s->keys;
|
|
|
|
for (; keyinfo < keyend; keyinfo++)
|
|
|
|
{
|
|
|
|
keypart= keyinfo->key_part;
|
|
|
|
keypartend= keypart + keyinfo->key_parts;
|
|
|
|
for (; keypart < keypartend; keypart++)
|
|
|
|
{
|
|
|
|
if (!keypart->fieldnr)
|
|
|
|
continue;
|
|
|
|
Field *field= table->field[keypart->fieldnr-1];
|
|
|
|
if (field->type() == FIELD_TYPE_BLOB)
|
|
|
|
{
|
|
|
|
if (check_opt->sql_flags & TT_FOR_UPGRADE)
|
|
|
|
check_opt->flags= T_MEDIUM;
|
|
|
|
return HA_ADMIN_NEEDS_CHECK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return check_for_upgrade(check_opt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int handler::check_old_types()
|
|
|
|
{
|
|
|
|
Field** field;
|
|
|
|
|
|
|
|
if (!table->s->mysql_version)
|
|
|
|
{
|
|
|
|
/* check for bad DECIMAL field */
|
|
|
|
for (field= table->field; (*field); field++)
|
|
|
|
{
|
|
|
|
if ((*field)->type() == FIELD_TYPE_NEWDECIMAL)
|
|
|
|
{
|
|
|
|
return HA_ADMIN_NEEDS_ALTER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool update_frm_version(TABLE *table, bool needs_lock)
|
|
|
|
{
|
|
|
|
char path[FN_REFLEN];
|
|
|
|
File file;
|
|
|
|
int result= 1;
|
|
|
|
DBUG_ENTER("update_frm_version");
|
|
|
|
|
|
|
|
if (table->s->mysql_version != MYSQL_VERSION_ID)
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
2006-02-17 10:37:37 +01:00
|
|
|
strxmov(path, table->s->normalized_path.str, reg_ext, NullS);
|
2006-02-17 07:52:32 +01:00
|
|
|
|
|
|
|
if (needs_lock)
|
|
|
|
pthread_mutex_lock(&LOCK_open);
|
|
|
|
|
|
|
|
if ((file= my_open(path, O_RDWR|O_BINARY, MYF(MY_WME))) >= 0)
|
|
|
|
{
|
|
|
|
uchar version[4];
|
2006-02-17 10:37:37 +01:00
|
|
|
char *key= table->s->table_cache_key.str;
|
|
|
|
uint key_length= table->s->table_cache_key.length;
|
2006-02-17 07:52:32 +01:00
|
|
|
TABLE *entry;
|
|
|
|
HASH_SEARCH_STATE state;
|
|
|
|
|
|
|
|
int4store(version, MYSQL_VERSION_ID);
|
|
|
|
|
|
|
|
if ((result= my_pwrite(file,(byte*) version,4,51L,MYF_RW)))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
for (entry=(TABLE*) hash_first(&open_cache,(byte*) key,key_length, &state);
|
|
|
|
entry;
|
|
|
|
entry= (TABLE*) hash_next(&open_cache,(byte*) key,key_length, &state))
|
|
|
|
entry->s->mysql_version= MYSQL_VERSION_ID;
|
|
|
|
}
|
|
|
|
err:
|
|
|
|
if (file >= 0)
|
|
|
|
VOID(my_close(file,MYF(MY_WME)));
|
|
|
|
if (needs_lock)
|
|
|
|
pthread_mutex_unlock(&LOCK_open);
|
|
|
|
DBUG_RETURN(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-05-14 00:27:26 +02:00
|
|
|
/* Return key if error because of duplicated keys */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
uint handler::get_dup_key(int error)
|
|
|
|
{
|
2004-08-22 14:23:52 +02:00
|
|
|
DBUG_ENTER("handler::get_dup_key");
|
2000-07-31 21:29:14 +02:00
|
|
|
table->file->errkey = (uint) -1;
|
2006-02-09 18:43:10 +01:00
|
|
|
if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
|
|
|
|
error == HA_ERR_FOUND_DUPP_UNIQUE || error == HA_ERR_NULL_IN_SPATIAL ||
|
|
|
|
error == HA_ERR_DROP_INDEX_FK)
|
2000-07-31 21:29:14 +02:00
|
|
|
info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK);
|
|
|
|
DBUG_RETURN(table->file->errkey);
|
|
|
|
}
|
|
|
|
|
2003-05-14 00:27:26 +02:00
|
|
|
|
2005-02-21 13:47:57 +01:00
|
|
|
/*
|
|
|
|
Delete all files with extension from bas_ext()
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
delete_table()
|
|
|
|
name Base name of table
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
We assume that the handler may return more extensions than
|
|
|
|
was actually used for the file.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 If we successfully deleted at least one file from base_ext and
|
2005-03-13 21:58:09 +01:00
|
|
|
didn't get any other errors than ENOENT
|
2005-03-09 15:33:01 +01:00
|
|
|
# Error
|
2005-02-21 13:47:57 +01:00
|
|
|
*/
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int handler::delete_table(const char *name)
|
|
|
|
{
|
2005-02-21 13:47:57 +01:00
|
|
|
int error= 0;
|
|
|
|
int enoent_or_zero= ENOENT; // Error if no file was deleted
|
2005-03-09 15:33:01 +01:00
|
|
|
char buff[FN_REFLEN];
|
2005-02-21 13:47:57 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
for (const char **ext=bas_ext(); *ext ; ext++)
|
|
|
|
{
|
2005-12-31 06:01:26 +01:00
|
|
|
fn_format(buff, name, "", *ext, MY_UNPACK_FILENAME|MY_APPEND_EXT);
|
2005-03-09 15:33:01 +01:00
|
|
|
if (my_delete_with_symlink(buff, MYF(0)))
|
2000-12-08 16:04:57 +01:00
|
|
|
{
|
2005-02-21 13:47:57 +01:00
|
|
|
if ((error= my_errno) != ENOENT)
|
2000-12-08 16:04:57 +01:00
|
|
|
break;
|
|
|
|
}
|
2005-02-21 13:47:57 +01:00
|
|
|
else
|
2005-02-21 19:41:48 +01:00
|
|
|
enoent_or_zero= 0; // No error for ENOENT
|
2005-02-21 13:47:57 +01:00
|
|
|
error= enoent_or_zero;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2000-12-08 16:04:57 +01:00
|
|
|
return error;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int handler::rename_table(const char * from, const char * to)
|
|
|
|
{
|
2005-04-28 10:49:18 +02:00
|
|
|
int error= 0;
|
|
|
|
for (const char **ext= bas_ext(); *ext ; ext++)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2005-04-28 10:49:18 +02:00
|
|
|
if (rename_file_ext(from, to, *ext))
|
|
|
|
{
|
|
|
|
if ((error=my_errno) != ENOENT)
|
|
|
|
break;
|
|
|
|
error= 0;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2005-04-28 10:49:18 +02:00
|
|
|
return error;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2005-11-06 08:29:03 +01:00
|
|
|
|
|
|
|
void handler::drop_table(const char *name)
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
delete_table(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-17 07:52:32 +01:00
|
|
|
/*
|
|
|
|
Performs checks upon the table.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
check()
|
|
|
|
thd thread doing CHECK TABLE operation
|
|
|
|
check_opt options from the parser
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
HA_ADMIN_OK Successful upgrade
|
|
|
|
HA_ADMIN_NEEDS_UPGRADE Table has structures requiring upgrade
|
|
|
|
HA_ADMIN_NEEDS_ALTER Table has structures requiring ALTER TABLE
|
|
|
|
HA_ADMIN_NOT_IMPLEMENTED
|
|
|
|
*/
|
|
|
|
|
|
|
|
int handler::ha_check(THD *thd, HA_CHECK_OPT *check_opt)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if ((table->s->mysql_version >= MYSQL_VERSION_ID) &&
|
|
|
|
(check_opt->sql_flags & TT_FOR_UPGRADE))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (table->s->mysql_version < MYSQL_VERSION_ID)
|
|
|
|
{
|
|
|
|
if ((error= check_old_types()))
|
|
|
|
return error;
|
|
|
|
error= ha_check_for_upgrade(check_opt);
|
|
|
|
if (error && (error != HA_ADMIN_NEEDS_CHECK))
|
|
|
|
return error;
|
|
|
|
if (!error && (check_opt->sql_flags & TT_FOR_UPGRADE))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ((error= check(thd, check_opt)))
|
|
|
|
return error;
|
|
|
|
return update_frm_version(table, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int handler::ha_repair(THD* thd, HA_CHECK_OPT* check_opt)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
if ((result= repair(thd, check_opt)))
|
|
|
|
return result;
|
|
|
|
return update_frm_version(table, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-14 00:27:26 +02:00
|
|
|
/*
|
2005-03-02 10:38:25 +01:00
|
|
|
Tell the storage engine that it is allowed to "disable transaction" in the
|
|
|
|
handler. It is a hint that ACID is not required - it is used in NDB for
|
|
|
|
ALTER TABLE, for example, when data are copied to temporary table.
|
|
|
|
A storage engine may treat this hint any way it likes. NDB for example
|
|
|
|
starts to commit every now and then automatically.
|
|
|
|
This hint can be safely ignored.
|
2001-05-29 15:29:08 +02:00
|
|
|
*/
|
2003-05-14 00:27:26 +02:00
|
|
|
|
2004-09-03 17:11:09 +02:00
|
|
|
int ha_enable_transaction(THD *thd, bool on)
|
2001-05-29 15:29:08 +02:00
|
|
|
{
|
|
|
|
int error=0;
|
|
|
|
|
2004-09-03 17:11:09 +02:00
|
|
|
DBUG_ENTER("ha_enable_transaction");
|
|
|
|
thd->transaction.on= on;
|
2005-02-16 17:34:02 +01:00
|
|
|
if (on)
|
2005-03-02 10:38:25 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Now all storage engines should have transaction handling enabled.
|
|
|
|
But some may have it enabled all the time - "disabling" transactions
|
|
|
|
is an optimization hint that storage engine is free to ignore.
|
|
|
|
So, let's commit an open transaction (if any) now.
|
|
|
|
*/
|
2005-12-10 00:00:33 +01:00
|
|
|
if (!(error= ha_commit_stmt(thd)))
|
|
|
|
error= end_trans(thd, COMMIT);
|
2005-03-02 10:38:25 +01:00
|
|
|
}
|
2001-05-29 15:29:08 +02:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int handler::index_next_same(byte *buf, const byte *key, uint keylen)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
if (!(error=index_next(buf)))
|
|
|
|
{
|
2004-05-16 13:48:32 +02:00
|
|
|
if (key_cmp_if_same(table, key, active_index, keylen))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
table->status=STATUS_NOT_FOUND;
|
|
|
|
error=HA_ERR_END_OF_FILE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-10 16:44:04 +01:00
|
|
|
void handler::get_dynamic_partition_info(PARTITION_INFO *stat_info, uint part_id)
|
|
|
|
{
|
|
|
|
info(HA_STATUS_CONST | HA_STATUS_TIME | HA_STATUS_VARIABLE |
|
|
|
|
HA_STATUS_NO_LOCK);
|
|
|
|
stat_info->records= records;
|
|
|
|
stat_info->mean_rec_length= mean_rec_length;
|
|
|
|
stat_info->data_file_length= data_file_length;
|
|
|
|
stat_info->max_data_file_length= max_data_file_length;
|
|
|
|
stat_info->index_file_length= index_file_length;
|
|
|
|
stat_info->delete_length= delete_length;
|
|
|
|
stat_info->create_time= create_time;
|
|
|
|
stat_info->update_time= update_time;
|
|
|
|
stat_info->check_time= check_time;
|
|
|
|
stat_info->check_sum= 0;
|
|
|
|
if (table_flags() & (ulong) HA_HAS_CHECKSUM)
|
|
|
|
stat_info->check_sum= checksum();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/****************************************************************************
|
|
|
|
** Some general functions that isn't in the handler class
|
|
|
|
****************************************************************************/
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
2006-06-01 20:47:15 +02:00
|
|
|
Initiates table-file and calls appropriate database-creator
|
2005-11-23 21:45:02 +01:00
|
|
|
|
|
|
|
NOTES
|
|
|
|
We must have a write lock on LOCK_open to be sure no other thread
|
2006-06-01 20:47:15 +02:00
|
|
|
interferes with table
|
2005-11-23 21:45:02 +01:00
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 ok
|
|
|
|
1 error
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
int ha_create_table(THD *thd, const char *path,
|
|
|
|
const char *db, const char *table_name,
|
|
|
|
HA_CREATE_INFO *create_info,
|
2000-07-31 21:29:14 +02:00
|
|
|
bool update_create_info)
|
|
|
|
{
|
2005-11-23 21:45:02 +01:00
|
|
|
int error= 1;
|
2000-07-31 21:29:14 +02:00
|
|
|
TABLE table;
|
2003-12-30 12:14:21 +01:00
|
|
|
char name_buff[FN_REFLEN];
|
2005-11-23 21:45:02 +01:00
|
|
|
const char *name;
|
|
|
|
TABLE_SHARE share;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("ha_create_table");
|
2005-11-23 21:45:02 +01:00
|
|
|
|
|
|
|
init_tmp_table_share(&share, db, 0, table_name, path);
|
|
|
|
if (open_table_def(thd, &share, 0) ||
|
2006-01-17 08:40:00 +01:00
|
|
|
open_table_from_share(thd, &share, "", 0, (uint) READ_ALL, 0, &table,
|
|
|
|
TRUE))
|
2005-11-23 21:45:02 +01:00
|
|
|
goto err;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
if (update_create_info)
|
|
|
|
update_create_info_from_table(create_info, &table);
|
2005-11-23 21:45:02 +01:00
|
|
|
|
|
|
|
name= share.path.str;
|
2003-12-30 12:14:21 +01:00
|
|
|
if (lower_case_table_names == 2 &&
|
|
|
|
!(table.file->table_flags() & HA_FILE_BASED))
|
|
|
|
{
|
|
|
|
/* Ensure that handler gets name in lower case */
|
|
|
|
strmov(name_buff, name);
|
2004-05-22 21:41:58 +02:00
|
|
|
my_casedn_str(files_charset_info, name_buff);
|
2003-12-30 12:14:21 +01:00
|
|
|
name= name_buff;
|
|
|
|
}
|
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
error= table.file->create(name, &table, create_info);
|
|
|
|
VOID(closefrm(&table, 0));
|
2001-09-14 01:54:33 +02:00
|
|
|
if (error)
|
2005-11-23 21:45:02 +01:00
|
|
|
{
|
|
|
|
strxmov(name_buff, db, ".", table_name, NullS);
|
|
|
|
my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), name_buff, error);
|
|
|
|
}
|
|
|
|
err:
|
|
|
|
free_table_share(&share);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(error != 0);
|
|
|
|
}
|
|
|
|
|
2004-09-13 14:46:38 +02:00
|
|
|
/*
|
2005-11-23 21:45:02 +01:00
|
|
|
Try to discover table from engine
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
If found, write the frm file to disk.
|
2005-06-08 13:31:59 +02:00
|
|
|
|
2004-09-13 14:46:38 +02:00
|
|
|
RETURN VALUES:
|
2005-11-23 21:45:02 +01:00
|
|
|
-1 Table did not exists
|
|
|
|
0 Table created ok
|
|
|
|
> 0 Error, table existed but could not be created
|
2004-09-13 14:46:38 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
int ha_create_table_from_engine(THD* thd, const char *db, const char *name)
|
2004-09-13 14:46:38 +02:00
|
|
|
{
|
2004-10-14 17:03:46 +02:00
|
|
|
int error;
|
|
|
|
const void *frmblob;
|
|
|
|
uint frmlen;
|
2004-09-13 14:46:38 +02:00
|
|
|
char path[FN_REFLEN];
|
|
|
|
HA_CREATE_INFO create_info;
|
|
|
|
TABLE table;
|
2005-11-23 21:45:02 +01:00
|
|
|
TABLE_SHARE share;
|
2004-09-13 14:46:38 +02:00
|
|
|
DBUG_ENTER("ha_create_table_from_engine");
|
2005-06-27 19:31:00 +02:00
|
|
|
DBUG_PRINT("enter", ("name '%s'.'%s'", db, name));
|
2004-09-13 14:46:38 +02:00
|
|
|
|
|
|
|
bzero((char*) &create_info,sizeof(create_info));
|
|
|
|
if ((error= ha_discover(thd, db, name, &frmblob, &frmlen)))
|
2005-06-08 13:31:59 +02:00
|
|
|
{
|
2005-06-27 19:31:00 +02:00
|
|
|
/* Table could not be discovered and thus not created */
|
2005-06-16 15:17:47 +02:00
|
|
|
DBUG_RETURN(error);
|
2005-06-08 13:31:59 +02:00
|
|
|
}
|
|
|
|
|
2004-10-14 17:03:46 +02:00
|
|
|
/*
|
2005-06-08 13:31:59 +02:00
|
|
|
Table exists in handler and could be discovered
|
|
|
|
frmblob and frmlen are set, write the frm to disk
|
2004-10-14 17:03:46 +02:00
|
|
|
*/
|
2004-09-13 14:46:38 +02:00
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
(void)strxnmov(path,FN_REFLEN-1,mysql_data_home,"/",db,"/",name,NullS);
|
2005-06-08 13:31:59 +02:00
|
|
|
// Save the frm file
|
2005-06-27 19:31:00 +02:00
|
|
|
error= writefrm(path, frmblob, frmlen);
|
|
|
|
my_free((char*) frmblob, MYF(0));
|
|
|
|
if (error)
|
2005-06-16 15:17:47 +02:00
|
|
|
DBUG_RETURN(2);
|
2004-09-13 14:46:38 +02:00
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
init_tmp_table_share(&share, db, 0, name, path);
|
|
|
|
if (open_table_def(thd, &share, 0))
|
|
|
|
{
|
|
|
|
DBUG_RETURN(3);
|
|
|
|
}
|
2006-01-17 08:40:00 +01:00
|
|
|
if (open_table_from_share(thd, &share, "" ,0, 0, 0, &table, FALSE))
|
2005-11-23 21:45:02 +01:00
|
|
|
{
|
|
|
|
free_table_share(&share);
|
2005-06-16 15:17:47 +02:00
|
|
|
DBUG_RETURN(3);
|
2005-11-23 21:45:02 +01:00
|
|
|
}
|
2004-09-13 14:46:38 +02:00
|
|
|
|
2005-06-08 13:31:59 +02:00
|
|
|
update_create_info_from_table(&create_info, &table);
|
2005-11-02 15:53:04 +01:00
|
|
|
create_info.table_options|= HA_OPTION_CREATE_FROM_ENGINE;
|
2004-09-13 14:46:38 +02:00
|
|
|
|
2005-06-08 13:31:59 +02:00
|
|
|
if (lower_case_table_names == 2 &&
|
|
|
|
!(table.file->table_flags() & HA_FILE_BASED))
|
|
|
|
{
|
|
|
|
/* Ensure that handler gets name in lower case */
|
|
|
|
my_casedn_str(files_charset_info, path);
|
2004-09-13 14:46:38 +02:00
|
|
|
}
|
2005-06-08 13:31:59 +02:00
|
|
|
error=table.file->create(path,&table,&create_info);
|
2005-11-23 21:45:02 +01:00
|
|
|
VOID(closefrm(&table, 1));
|
2004-09-13 14:46:38 +02:00
|
|
|
|
2005-06-08 13:31:59 +02:00
|
|
|
DBUG_RETURN(error != 0);
|
2004-09-13 14:46:38 +02:00
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
void st_ha_check_opt::init()
|
|
|
|
{
|
|
|
|
flags= sql_flags= 0;
|
|
|
|
sort_buffer_size = current_thd->variables.myisam_sort_buff_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
Key cache handling.
|
|
|
|
|
|
|
|
This code is only relevant for ISAM/MyISAM tables
|
|
|
|
|
|
|
|
key_cache->cache may be 0 only in the case where a key cache is not
|
|
|
|
initialized or when we where not able to init the key cache in a previous
|
|
|
|
call to ha_init_key_cache() (probably out of memory)
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/* Init a key cache if it has not been initied before */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2003-11-20 21:06:25 +01:00
|
|
|
int ha_init_key_cache(const char *name, KEY_CACHE *key_cache)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2003-11-18 12:47:27 +01:00
|
|
|
DBUG_ENTER("ha_init_key_cache");
|
|
|
|
|
2003-11-20 21:06:25 +01:00
|
|
|
if (!key_cache->key_cache_inited)
|
2003-10-02 05:20:17 +02:00
|
|
|
{
|
|
|
|
pthread_mutex_lock(&LOCK_global_system_variables);
|
2003-11-20 21:06:25 +01:00
|
|
|
long tmp_buff_size= (long) key_cache->param_buff_size;
|
|
|
|
long tmp_block_size= (long) key_cache->param_block_size;
|
|
|
|
uint division_limit= key_cache->param_division_limit;
|
|
|
|
uint age_threshold= key_cache->param_age_threshold;
|
2003-10-02 05:20:17 +02:00
|
|
|
pthread_mutex_unlock(&LOCK_global_system_variables);
|
2003-11-20 21:06:25 +01:00
|
|
|
DBUG_RETURN(!init_key_cache(key_cache,
|
2003-11-18 12:47:27 +01:00
|
|
|
tmp_block_size,
|
|
|
|
tmp_buff_size,
|
2003-11-20 21:06:25 +01:00
|
|
|
division_limit, age_threshold));
|
2003-10-02 05:20:17 +02:00
|
|
|
}
|
2003-11-18 12:47:27 +01:00
|
|
|
DBUG_RETURN(0);
|
2002-07-23 17:31:22 +02:00
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
|
|
|
/* Resize key cache */
|
|
|
|
|
2003-11-20 21:06:25 +01:00
|
|
|
int ha_resize_key_cache(KEY_CACHE *key_cache)
|
2003-10-02 08:37:05 +02:00
|
|
|
{
|
2003-11-18 12:47:27 +01:00
|
|
|
DBUG_ENTER("ha_resize_key_cache");
|
|
|
|
|
2003-11-20 21:06:25 +01:00
|
|
|
if (key_cache->key_cache_inited)
|
2003-10-02 05:20:17 +02:00
|
|
|
{
|
|
|
|
pthread_mutex_lock(&LOCK_global_system_variables);
|
2003-11-20 21:06:25 +01:00
|
|
|
long tmp_buff_size= (long) key_cache->param_buff_size;
|
|
|
|
long tmp_block_size= (long) key_cache->param_block_size;
|
|
|
|
uint division_limit= key_cache->param_division_limit;
|
|
|
|
uint age_threshold= key_cache->param_age_threshold;
|
2003-10-02 05:20:17 +02:00
|
|
|
pthread_mutex_unlock(&LOCK_global_system_variables);
|
2003-11-20 21:06:25 +01:00
|
|
|
DBUG_RETURN(!resize_key_cache(key_cache, tmp_block_size,
|
|
|
|
tmp_buff_size,
|
|
|
|
division_limit, age_threshold));
|
2003-10-02 05:20:17 +02:00
|
|
|
}
|
2003-11-18 12:47:27 +01:00
|
|
|
DBUG_RETURN(0);
|
2003-10-02 05:20:17 +02:00
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
|
|
|
/* Change parameters for key cache (like size) */
|
|
|
|
|
2003-11-20 21:06:25 +01:00
|
|
|
int ha_change_key_cache_param(KEY_CACHE *key_cache)
|
2003-10-02 05:20:17 +02:00
|
|
|
{
|
2003-11-20 21:06:25 +01:00
|
|
|
if (key_cache->key_cache_inited)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&LOCK_global_system_variables);
|
|
|
|
uint division_limit= key_cache->param_division_limit;
|
|
|
|
uint age_threshold= key_cache->param_age_threshold;
|
|
|
|
pthread_mutex_unlock(&LOCK_global_system_variables);
|
|
|
|
change_key_cache_param(key_cache, division_limit, age_threshold);
|
|
|
|
}
|
2003-10-02 05:20:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2002-07-23 17:31:22 +02:00
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
/* Free memory allocated by a key cache */
|
|
|
|
|
2003-11-20 21:06:25 +01:00
|
|
|
int ha_end_key_cache(KEY_CACHE *key_cache)
|
2002-07-23 17:31:22 +02:00
|
|
|
{
|
2003-11-20 21:06:25 +01:00
|
|
|
end_key_cache(key_cache, 1); // Can never fail
|
2003-10-02 05:20:17 +02:00
|
|
|
return 0;
|
2002-07-23 17:31:22 +02:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
/* Move all tables from one key cache to another one */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-11-20 21:06:25 +01:00
|
|
|
int ha_change_key_cache(KEY_CACHE *old_key_cache,
|
|
|
|
KEY_CACHE *new_key_cache)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2003-11-18 12:47:27 +01:00
|
|
|
mi_change_key_cache(old_key_cache, new_key_cache);
|
|
|
|
return 0;
|
2002-07-23 17:31:22 +02:00
|
|
|
}
|
2004-04-08 12:58:06 +02:00
|
|
|
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
|
|
|
Try to discover one table from handler(s)
|
2004-10-14 17:03:46 +02:00
|
|
|
|
|
|
|
RETURN
|
2005-06-16 15:17:47 +02:00
|
|
|
-1 : Table did not exists
|
|
|
|
0 : OK. In this case *frmblob and *frmlen are set
|
|
|
|
>0 : error. frmblob and frmlen may not be set
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
|
|
|
|
2004-10-14 17:03:46 +02:00
|
|
|
int ha_discover(THD *thd, const char *db, const char *name,
|
|
|
|
const void **frmblob, uint *frmlen)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2005-06-16 15:17:47 +02:00
|
|
|
int error= -1; // Table does not exist in any handler
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ENTER("ha_discover");
|
2004-09-13 14:46:38 +02:00
|
|
|
DBUG_PRINT("enter", ("db: %s, name: %s", db, name));
|
2005-07-20 18:40:55 +02:00
|
|
|
if (is_prefix(name,tmp_file_prefix)) /* skip temporary tables */
|
|
|
|
DBUG_RETURN(error);
|
2005-11-07 16:25:06 +01:00
|
|
|
#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
|
2004-04-15 09:14:14 +02:00
|
|
|
if (have_ndbcluster == SHOW_OPTION_YES)
|
2004-09-13 14:46:38 +02:00
|
|
|
error= ndbcluster_discover(thd, db, name, frmblob, frmlen);
|
2004-04-15 09:14:14 +02:00
|
|
|
#endif
|
|
|
|
if (!error)
|
2005-01-16 13:16:23 +01:00
|
|
|
statistic_increment(thd->status_var.ha_discover_count,&LOCK_status);
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-13 14:46:38 +02:00
|
|
|
/*
|
2006-06-01 20:47:15 +02:00
|
|
|
Call this function in order to give the handler the possibility
|
2004-09-21 12:13:58 +02:00
|
|
|
to ask engine if there are any new tables that should be written to disk
|
|
|
|
or any dropped tables that need to be removed from disk
|
2004-09-13 14:46:38 +02:00
|
|
|
*/
|
|
|
|
|
2004-09-21 12:13:58 +02:00
|
|
|
int
|
|
|
|
ha_find_files(THD *thd,const char *db,const char *path,
|
2004-09-26 16:11:24 +02:00
|
|
|
const char *wild, bool dir, List<char> *files)
|
2004-09-13 14:46:38 +02:00
|
|
|
{
|
|
|
|
int error= 0;
|
2004-09-21 12:13:58 +02:00
|
|
|
DBUG_ENTER("ha_find_files");
|
|
|
|
DBUG_PRINT("enter", ("db: %s, path: %s, wild: %s, dir: %d",
|
|
|
|
db, path, wild, dir));
|
2005-11-07 16:25:06 +01:00
|
|
|
#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
|
2004-09-13 14:46:38 +02:00
|
|
|
if (have_ndbcluster == SHOW_OPTION_YES)
|
2004-09-26 16:11:24 +02:00
|
|
|
error= ndbcluster_find_files(thd, db, path, wild, dir, files);
|
2004-09-13 14:46:38 +02:00
|
|
|
#endif
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2004-10-14 17:03:46 +02:00
|
|
|
|
2004-09-13 14:46:38 +02:00
|
|
|
/*
|
|
|
|
Ask handler if the table exists in engine
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 Table does not exist
|
|
|
|
1 Table exists
|
|
|
|
# Error code
|
|
|
|
|
|
|
|
*/
|
2005-06-08 13:31:59 +02:00
|
|
|
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name)
|
2004-09-13 14:46:38 +02:00
|
|
|
{
|
2005-06-08 13:31:59 +02:00
|
|
|
int error= 0;
|
|
|
|
DBUG_ENTER("ha_table_exists_in_engine");
|
2004-09-13 14:46:38 +02:00
|
|
|
DBUG_PRINT("enter", ("db: %s, name: %s", db, name));
|
2005-11-07 16:25:06 +01:00
|
|
|
#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
|
2004-09-13 14:46:38 +02:00
|
|
|
if (have_ndbcluster == SHOW_OPTION_YES)
|
2005-06-08 13:31:59 +02:00
|
|
|
error= ndbcluster_table_exists_in_engine(thd, db, name);
|
2004-09-13 14:46:38 +02:00
|
|
|
#endif
|
2005-06-08 13:31:59 +02:00
|
|
|
DBUG_PRINT("exit", ("error: %d", error));
|
2004-09-13 14:46:38 +02:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
/*
|
|
|
|
TODO: change this into a dynamic struct
|
|
|
|
List<handlerton> does not work as
|
|
|
|
1. binlog_end is called when MEM_ROOT is gone
|
|
|
|
2. cannot work with thd MEM_ROOT as memory should be freed
|
|
|
|
*/
|
|
|
|
#define MAX_HTON_LIST_ST 63
|
|
|
|
struct hton_list_st
|
|
|
|
{
|
|
|
|
handlerton *hton[MAX_HTON_LIST_ST];
|
|
|
|
uint sz;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct binlog_func_st
|
|
|
|
{
|
|
|
|
enum_binlog_func fn;
|
|
|
|
void *arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Listing handlertons first to avoid recursive calls and deadlock
|
|
|
|
*/
|
|
|
|
static my_bool binlog_func_list(THD *thd, st_plugin_int *plugin, void *arg)
|
|
|
|
{
|
|
|
|
hton_list_st *hton_list= (hton_list_st *)arg;
|
2006-05-31 18:07:32 +02:00
|
|
|
handlerton *hton= (handlerton *)plugin->data;
|
2006-01-12 19:51:02 +01:00
|
|
|
if (hton->state == SHOW_OPTION_YES && hton->binlog_func)
|
|
|
|
{
|
|
|
|
uint sz= hton_list->sz;
|
|
|
|
if (sz == MAX_HTON_LIST_ST-1)
|
|
|
|
{
|
|
|
|
/* list full */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
hton_list->hton[sz]= hton;
|
|
|
|
hton_list->sz= sz+1;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static my_bool binlog_func_foreach(THD *thd, binlog_func_st *bfn)
|
|
|
|
{
|
|
|
|
handlerton *hton;
|
|
|
|
hton_list_st hton_list;
|
|
|
|
hton_list.sz= 0;
|
|
|
|
plugin_foreach(thd, binlog_func_list,
|
|
|
|
MYSQL_STORAGE_ENGINE_PLUGIN, &hton_list);
|
|
|
|
|
|
|
|
uint i= 0, sz= hton_list.sz;
|
|
|
|
while(i < sz)
|
|
|
|
hton_list.hton[i++]->binlog_func(thd, bfn->fn, bfn->arg);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ha_reset_logs(THD *thd)
|
|
|
|
{
|
|
|
|
binlog_func_st bfn= {BFN_RESET_LOGS, 0};
|
|
|
|
binlog_func_foreach(thd, &bfn);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ha_reset_slave(THD* thd)
|
|
|
|
{
|
|
|
|
binlog_func_st bfn= {BFN_RESET_SLAVE, 0};
|
|
|
|
binlog_func_foreach(thd, &bfn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ha_binlog_wait(THD* thd)
|
|
|
|
{
|
|
|
|
binlog_func_st bfn= {BFN_BINLOG_WAIT, 0};
|
|
|
|
binlog_func_foreach(thd, &bfn);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ha_binlog_end(THD* thd)
|
|
|
|
{
|
|
|
|
binlog_func_st bfn= {BFN_BINLOG_END, 0};
|
|
|
|
binlog_func_foreach(thd, &bfn);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ha_binlog_index_purge_file(THD *thd, const char *file)
|
|
|
|
{
|
|
|
|
binlog_func_st bfn= {BFN_BINLOG_PURGE_FILE, (void *)file};
|
|
|
|
binlog_func_foreach(thd, &bfn);
|
2006-01-14 11:06:44 +01:00
|
|
|
return 0;
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct binlog_log_query_st
|
|
|
|
{
|
|
|
|
enum_binlog_command binlog_command;
|
|
|
|
const char *query;
|
|
|
|
uint query_length;
|
|
|
|
const char *db;
|
|
|
|
const char *table_name;
|
|
|
|
};
|
|
|
|
|
2006-02-06 11:47:12 +01:00
|
|
|
static my_bool binlog_log_query_handlerton2(THD *thd,
|
|
|
|
const handlerton *hton,
|
|
|
|
void *args)
|
2006-01-12 19:51:02 +01:00
|
|
|
{
|
|
|
|
struct binlog_log_query_st *b= (struct binlog_log_query_st*)args;
|
|
|
|
if (hton->state == SHOW_OPTION_YES && hton->binlog_log_query)
|
|
|
|
hton->binlog_log_query(thd,
|
|
|
|
b->binlog_command,
|
|
|
|
b->query,
|
|
|
|
b->query_length,
|
|
|
|
b->db,
|
|
|
|
b->table_name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-02-06 11:47:12 +01:00
|
|
|
static my_bool binlog_log_query_handlerton(THD *thd,
|
|
|
|
st_plugin_int *plugin,
|
|
|
|
void *args)
|
|
|
|
{
|
2006-05-31 18:07:32 +02:00
|
|
|
return binlog_log_query_handlerton2(thd, (const handlerton *)plugin->data, args);
|
2006-02-06 11:47:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ha_binlog_log_query(THD *thd, const handlerton *hton,
|
|
|
|
enum_binlog_command binlog_command,
|
2006-01-12 19:51:02 +01:00
|
|
|
const char *query, uint query_length,
|
|
|
|
const char *db, const char *table_name)
|
|
|
|
{
|
|
|
|
struct binlog_log_query_st b;
|
|
|
|
b.binlog_command= binlog_command;
|
|
|
|
b.query= query;
|
|
|
|
b.query_length= query_length;
|
|
|
|
b.db= db;
|
|
|
|
b.table_name= table_name;
|
2006-02-06 11:47:12 +01:00
|
|
|
if (hton == 0)
|
|
|
|
plugin_foreach(thd, binlog_log_query_handlerton,
|
|
|
|
MYSQL_STORAGE_ENGINE_PLUGIN, &b);
|
|
|
|
else
|
|
|
|
binlog_log_query_handlerton2(thd, hton, &b);
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
|
|
|
#endif
|
2004-09-13 14:46:38 +02:00
|
|
|
|
2004-12-23 21:45:10 +01:00
|
|
|
/*
|
|
|
|
Read the first row of a multi-range set.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
read_multi_range_first()
|
|
|
|
found_range_p Returns a pointer to the element in 'ranges' that
|
|
|
|
corresponds to the returned row.
|
|
|
|
ranges An array of KEY_MULTI_RANGE range descriptions.
|
|
|
|
range_count Number of ranges in 'ranges'.
|
|
|
|
sorted If result should be sorted per key.
|
|
|
|
buffer A HANDLER_BUFFER for internal handler usage.
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
Record is read into table->record[0].
|
|
|
|
*found_range_p returns a valid value only if read_multi_range_first()
|
|
|
|
returns 0.
|
|
|
|
Sorting is done within each range. If you want an overall sort, enter
|
|
|
|
'ranges' with sorted ranges.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 OK, found a row
|
|
|
|
HA_ERR_END_OF_FILE No rows in range
|
|
|
|
# Error code
|
|
|
|
*/
|
|
|
|
|
|
|
|
int handler::read_multi_range_first(KEY_MULTI_RANGE **found_range_p,
|
|
|
|
KEY_MULTI_RANGE *ranges, uint range_count,
|
|
|
|
bool sorted, HANDLER_BUFFER *buffer)
|
|
|
|
{
|
|
|
|
int result= HA_ERR_END_OF_FILE;
|
|
|
|
DBUG_ENTER("handler::read_multi_range_first");
|
|
|
|
multi_range_sorted= sorted;
|
|
|
|
multi_range_buffer= buffer;
|
|
|
|
|
|
|
|
for (multi_range_curr= ranges, multi_range_end= ranges + range_count;
|
|
|
|
multi_range_curr < multi_range_end;
|
|
|
|
multi_range_curr++)
|
|
|
|
{
|
|
|
|
result= read_range_first(multi_range_curr->start_key.length ?
|
|
|
|
&multi_range_curr->start_key : 0,
|
|
|
|
multi_range_curr->end_key.length ?
|
|
|
|
&multi_range_curr->end_key : 0,
|
|
|
|
test(multi_range_curr->range_flag & EQ_RANGE),
|
|
|
|
multi_range_sorted);
|
|
|
|
if (result != HA_ERR_END_OF_FILE)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*found_range_p= multi_range_curr;
|
|
|
|
DBUG_PRINT("exit",("result %d", result));
|
|
|
|
DBUG_RETURN(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Read the next row of a multi-range set.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
read_multi_range_next()
|
|
|
|
found_range_p Returns a pointer to the element in 'ranges' that
|
|
|
|
corresponds to the returned row.
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
Record is read into table->record[0].
|
|
|
|
*found_range_p returns a valid value only if read_multi_range_next()
|
|
|
|
returns 0.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 OK, found a row
|
|
|
|
HA_ERR_END_OF_FILE No (more) rows in range
|
|
|
|
# Error code
|
|
|
|
*/
|
|
|
|
|
|
|
|
int handler::read_multi_range_next(KEY_MULTI_RANGE **found_range_p)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
DBUG_ENTER("handler::read_multi_range_next");
|
|
|
|
|
|
|
|
/* We should not be called after the last call returned EOF. */
|
|
|
|
DBUG_ASSERT(multi_range_curr < multi_range_end);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Save a call if there can be only one row in range. */
|
|
|
|
if (multi_range_curr->range_flag != (UNIQUE_RANGE | EQ_RANGE))
|
|
|
|
{
|
|
|
|
result= read_range_next();
|
|
|
|
|
|
|
|
/* On success or non-EOF errors jump to the end. */
|
|
|
|
if (result != HA_ERR_END_OF_FILE)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
We need to set this for the last range only, but checking this
|
|
|
|
condition is more expensive than just setting the result code.
|
|
|
|
*/
|
|
|
|
result= HA_ERR_END_OF_FILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try the next range(s) until one matches a record. */
|
|
|
|
for (multi_range_curr++;
|
|
|
|
multi_range_curr < multi_range_end;
|
|
|
|
multi_range_curr++)
|
|
|
|
{
|
|
|
|
result= read_range_first(multi_range_curr->start_key.length ?
|
|
|
|
&multi_range_curr->start_key : 0,
|
|
|
|
multi_range_curr->end_key.length ?
|
|
|
|
&multi_range_curr->end_key : 0,
|
|
|
|
test(multi_range_curr->range_flag & EQ_RANGE),
|
|
|
|
multi_range_sorted);
|
|
|
|
if (result != HA_ERR_END_OF_FILE)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while ((result == HA_ERR_END_OF_FILE) &&
|
|
|
|
(multi_range_curr < multi_range_end));
|
|
|
|
|
|
|
|
*found_range_p= multi_range_curr;
|
|
|
|
DBUG_PRINT("exit",("handler::read_multi_range_next: result %d", result));
|
|
|
|
DBUG_RETURN(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-08 12:58:06 +02:00
|
|
|
/*
|
|
|
|
Read first row between two ranges.
|
|
|
|
Store ranges for future calls to read_range_next
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
read_range_first()
|
|
|
|
start_key Start key. Is 0 if no min range
|
|
|
|
end_key End key. Is 0 if no max range
|
2004-05-16 13:48:32 +02:00
|
|
|
eq_range_arg Set to 1 if start_key == end_key
|
2004-04-08 12:58:06 +02:00
|
|
|
sorted Set to 1 if result should be sorted per key
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
Record is read into table->record[0]
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 Found row
|
|
|
|
HA_ERR_END_OF_FILE No rows in range
|
|
|
|
# Error code
|
|
|
|
*/
|
|
|
|
|
|
|
|
int handler::read_range_first(const key_range *start_key,
|
|
|
|
const key_range *end_key,
|
2004-05-16 13:48:32 +02:00
|
|
|
bool eq_range_arg, bool sorted)
|
2004-04-08 12:58:06 +02:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
DBUG_ENTER("handler::read_range_first");
|
|
|
|
|
2004-05-16 13:48:32 +02:00
|
|
|
eq_range= eq_range_arg;
|
2004-04-08 12:58:06 +02:00
|
|
|
end_range= 0;
|
|
|
|
if (end_key)
|
|
|
|
{
|
|
|
|
end_range= &save_end_range;
|
|
|
|
save_end_range= *end_key;
|
|
|
|
key_compare_result_on_equal= ((end_key->flag == HA_READ_BEFORE_KEY) ? 1 :
|
|
|
|
(end_key->flag == HA_READ_AFTER_KEY) ? -1 : 0);
|
|
|
|
}
|
|
|
|
range_key_part= table->key_info[active_index].key_part;
|
|
|
|
|
|
|
|
if (!start_key) // Read first record
|
|
|
|
result= index_first(table->record[0]);
|
|
|
|
else
|
|
|
|
result= index_read(table->record[0],
|
|
|
|
start_key->key,
|
|
|
|
start_key->length,
|
|
|
|
start_key->flag);
|
|
|
|
if (result)
|
2004-09-07 16:21:29 +02:00
|
|
|
DBUG_RETURN((result == HA_ERR_KEY_NOT_FOUND)
|
|
|
|
? HA_ERR_END_OF_FILE
|
|
|
|
: result);
|
2004-04-08 12:58:06 +02:00
|
|
|
|
|
|
|
DBUG_RETURN (compare_key(end_range) <= 0 ? 0 : HA_ERR_END_OF_FILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Read next row between two ranges.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
read_range_next()
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
Record is read into table->record[0]
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 Found row
|
|
|
|
HA_ERR_END_OF_FILE No rows in range
|
|
|
|
# Error code
|
|
|
|
*/
|
|
|
|
|
2004-05-16 13:48:32 +02:00
|
|
|
int handler::read_range_next()
|
2004-04-08 12:58:06 +02:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
DBUG_ENTER("handler::read_range_next");
|
|
|
|
|
|
|
|
if (eq_range)
|
2004-05-16 13:48:32 +02:00
|
|
|
{
|
|
|
|
/* We trust that index_next_same always gives a row in range */
|
|
|
|
DBUG_RETURN(index_next_same(table->record[0],
|
|
|
|
end_range->key,
|
|
|
|
end_range->length));
|
|
|
|
}
|
|
|
|
result= index_next(table->record[0]);
|
2004-04-08 12:58:06 +02:00
|
|
|
if (result)
|
|
|
|
DBUG_RETURN(result);
|
|
|
|
DBUG_RETURN(compare_key(end_range) <= 0 ? 0 : HA_ERR_END_OF_FILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-05-16 13:48:32 +02:00
|
|
|
Compare if found key (in row) is over max-value
|
2004-04-08 12:58:06 +02:00
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
compare_key
|
2004-05-16 13:48:32 +02:00
|
|
|
range range to compare to row. May be 0 for no range
|
2004-04-08 12:58:06 +02:00
|
|
|
|
|
|
|
NOTES
|
2004-05-16 13:48:32 +02:00
|
|
|
See key.cc::key_cmp() for details
|
2004-04-08 12:58:06 +02:00
|
|
|
|
|
|
|
RETURN
|
2004-05-16 13:48:32 +02:00
|
|
|
The return value is SIGN(key_in_row - range_key):
|
|
|
|
|
2004-04-08 12:58:06 +02:00
|
|
|
0 Key is equal to range or 'range' == 0 (no range)
|
|
|
|
-1 Key is less than range
|
|
|
|
1 Key is larger than range
|
|
|
|
*/
|
|
|
|
|
|
|
|
int handler::compare_key(key_range *range)
|
|
|
|
{
|
2004-05-16 13:48:32 +02:00
|
|
|
int cmp;
|
2004-04-08 12:58:06 +02:00
|
|
|
if (!range)
|
|
|
|
return 0; // No max range
|
2004-05-16 13:48:32 +02:00
|
|
|
cmp= key_cmp(range_key_part, range->key, range->length);
|
|
|
|
if (!cmp)
|
|
|
|
cmp= key_compare_result_on_equal;
|
|
|
|
return cmp;
|
2004-04-08 12:58:06 +02:00
|
|
|
}
|
2004-06-23 12:29:05 +02:00
|
|
|
|
|
|
|
int handler::index_read_idx(byte * buf, uint index, const byte * key,
|
|
|
|
uint key_len, enum ha_rkey_function find_flag)
|
|
|
|
{
|
2005-07-18 13:31:02 +02:00
|
|
|
int error= ha_index_init(index, 0);
|
2004-06-23 12:29:05 +02:00
|
|
|
if (!error)
|
|
|
|
error= index_read(buf, key, key_len, find_flag);
|
|
|
|
if (!error)
|
|
|
|
error= ha_index_end();
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2004-11-10 23:36:18 +01:00
|
|
|
|
2004-11-10 16:07:11 +01:00
|
|
|
/*
|
|
|
|
Returns a list of all known extensions.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
ha_known_exts()
|
2006-05-28 14:51:01 +02:00
|
|
|
|
2004-11-10 16:07:11 +01:00
|
|
|
NOTES
|
|
|
|
No mutexes, worst case race is a minor surplus memory allocation
|
2004-11-10 23:36:18 +01:00
|
|
|
We have to recreate the extension map if mysqld is restarted (for example
|
|
|
|
within libmysqld)
|
2004-11-10 16:07:11 +01:00
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
pointer pointer to TYPELIB structure
|
|
|
|
*/
|
2004-11-10 23:36:18 +01:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
static my_bool exts_handlerton(THD *unused, st_plugin_int *plugin,
|
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
List<char> *found_exts= (List<char> *) arg;
|
2006-05-31 18:07:32 +02:00
|
|
|
handlerton *hton= (handlerton *)plugin->data;
|
2005-12-21 19:18:40 +01:00
|
|
|
handler *file;
|
|
|
|
if (hton->state == SHOW_OPTION_YES && hton->create &&
|
|
|
|
(file= hton->create((TABLE_SHARE*) 0)))
|
|
|
|
{
|
|
|
|
List_iterator_fast<char> it(*found_exts);
|
|
|
|
const char **ext, *old_ext;
|
2006-05-28 14:51:01 +02:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
for (ext= file->bas_ext(); *ext; ext++)
|
|
|
|
{
|
|
|
|
while ((old_ext= it++))
|
|
|
|
{
|
|
|
|
if (!strcmp(old_ext, *ext))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!old_ext)
|
|
|
|
found_exts->push_back((char *) *ext);
|
|
|
|
|
|
|
|
it.rewind();
|
|
|
|
}
|
|
|
|
delete file;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-11-10 16:07:11 +01:00
|
|
|
TYPELIB *ha_known_exts(void)
|
|
|
|
{
|
2005-11-03 12:20:13 +01:00
|
|
|
MEM_ROOT *mem_root= current_thd->mem_root;
|
2004-11-10 23:36:18 +01:00
|
|
|
if (!known_extensions.type_names || mysys_usage_id != known_extensions_id)
|
2004-11-10 16:07:11 +01:00
|
|
|
{
|
|
|
|
List<char> found_exts;
|
2004-11-10 23:36:18 +01:00
|
|
|
const char **ext, *old_ext;
|
|
|
|
|
|
|
|
known_extensions_id= mysys_usage_id;
|
2005-03-27 14:15:21 +02:00
|
|
|
found_exts.push_back((char*) triggers_file_ext);
|
2005-07-19 18:06:49 +02:00
|
|
|
found_exts.push_back((char*) trigname_file_ext);
|
2006-05-28 14:51:01 +02:00
|
|
|
|
|
|
|
plugin_foreach(NULL, exts_handlerton,
|
2005-12-21 19:18:40 +01:00
|
|
|
MYSQL_STORAGE_ENGINE_PLUGIN, &found_exts);
|
|
|
|
|
2004-11-10 23:36:18 +01:00
|
|
|
ext= (const char **) my_once_alloc(sizeof(char *)*
|
|
|
|
(found_exts.elements+1),
|
|
|
|
MYF(MY_WME | MY_FAE));
|
2006-05-28 14:51:01 +02:00
|
|
|
|
2005-02-25 15:53:22 +01:00
|
|
|
DBUG_ASSERT(ext != 0);
|
2004-11-10 16:07:11 +01:00
|
|
|
known_extensions.count= found_exts.elements;
|
|
|
|
known_extensions.type_names= ext;
|
2004-11-10 23:36:18 +01:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
List_iterator_fast<char> it(found_exts);
|
2004-11-10 23:36:18 +01:00
|
|
|
while ((old_ext= it++))
|
|
|
|
*ext++= old_ext;
|
|
|
|
*ext= 0;
|
2004-11-10 16:07:11 +01:00
|
|
|
}
|
|
|
|
return &known_extensions;
|
|
|
|
}
|
2005-04-20 18:27:46 +02:00
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
static bool stat_print(THD *thd, const char *type, uint type_len,
|
|
|
|
const char *file, uint file_len,
|
|
|
|
const char *status, uint status_len)
|
2005-11-07 16:25:06 +01:00
|
|
|
{
|
|
|
|
Protocol *protocol= thd->protocol;
|
|
|
|
protocol->prepare_for_resend();
|
2005-12-21 19:18:40 +01:00
|
|
|
protocol->store(type, type_len, system_charset_info);
|
|
|
|
protocol->store(file, file_len, system_charset_info);
|
|
|
|
protocol->store(status, status_len, system_charset_info);
|
2005-11-07 16:25:06 +01:00
|
|
|
if (protocol->write())
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
|
|
|
|
static my_bool showstat_handlerton(THD *thd, st_plugin_int *plugin,
|
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
enum ha_stat_type stat= *(enum ha_stat_type *) arg;
|
2006-05-31 18:07:32 +02:00
|
|
|
handlerton *hton= (handlerton *)plugin->data;
|
2005-12-21 19:18:40 +01:00
|
|
|
if (hton->state == SHOW_OPTION_YES && hton->show_status &&
|
|
|
|
hton->show_status(thd, stat_print, stat))
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat)
|
2005-11-07 16:25:06 +01:00
|
|
|
{
|
|
|
|
List<Item> field_list;
|
|
|
|
Protocol *protocol= thd->protocol;
|
2005-12-21 19:18:40 +01:00
|
|
|
bool result;
|
2005-11-07 16:25:06 +01:00
|
|
|
|
|
|
|
field_list.push_back(new Item_empty_string("Type",10));
|
|
|
|
field_list.push_back(new Item_empty_string("Name",FN_REFLEN));
|
|
|
|
field_list.push_back(new Item_empty_string("Status",10));
|
|
|
|
|
|
|
|
if (protocol->send_fields(&field_list,
|
|
|
|
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
|
|
|
|
return TRUE;
|
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
if (db_type == NULL)
|
2005-11-07 16:25:06 +01:00
|
|
|
{
|
2006-05-28 14:51:01 +02:00
|
|
|
result= plugin_foreach(thd, showstat_handlerton,
|
2005-12-21 19:18:40 +01:00
|
|
|
MYSQL_STORAGE_ENGINE_PLUGIN, &stat);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (db_type->state != SHOW_OPTION_YES)
|
2006-05-28 14:51:01 +02:00
|
|
|
{
|
2006-05-31 18:07:32 +02:00
|
|
|
const LEX_STRING *name=&hton2plugin[db_type->slot]->name;
|
|
|
|
result= stat_print(thd, name->str, name->length,
|
2005-12-21 19:18:40 +01:00
|
|
|
"", 0, "DISABLED", 8) ? 1 : 0;
|
2006-05-28 14:51:01 +02:00
|
|
|
}
|
2005-12-21 19:18:40 +01:00
|
|
|
else
|
2006-05-28 14:51:01 +02:00
|
|
|
result= db_type->show_status &&
|
2005-12-21 19:18:40 +01:00
|
|
|
db_type->show_status(thd, stat_print, stat) ? 1 : 0;
|
2005-11-07 16:25:06 +01:00
|
|
|
}
|
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
if (!result)
|
|
|
|
send_eof(thd);
|
|
|
|
return result;
|
2005-11-07 16:25:06 +01:00
|
|
|
}
|
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
/*
|
|
|
|
Function to check if the conditions for row-based binlogging is
|
|
|
|
correct for the table.
|
|
|
|
|
|
|
|
A row in the given table should be replicated if:
|
2006-03-03 09:49:46 +01:00
|
|
|
- Row-based replication is enabled in the current thread
|
2005-12-22 06:39:02 +01:00
|
|
|
- The binlog is enabled
|
2006-03-03 09:49:46 +01:00
|
|
|
- It is not a temporary table
|
|
|
|
- The binary log is open
|
|
|
|
- The database the table resides in shall be binlogged (binlog_*_db rules)
|
2006-03-09 15:59:29 +01:00
|
|
|
- table is not mysql.event
|
2005-12-22 06:39:02 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_ROW_BASED_REPLICATION
|
2006-01-09 11:08:23 +01:00
|
|
|
/* The Sun compiler cannot instantiate the template below if this is
|
|
|
|
declared static, but it works by putting it into an anonymous
|
|
|
|
namespace. */
|
|
|
|
namespace {
|
2006-03-17 18:11:07 +01:00
|
|
|
struct st_table_data {
|
|
|
|
char const *db;
|
|
|
|
char const *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
int table_name_compare(void const *a, void const *b)
|
|
|
|
{
|
|
|
|
st_table_data const *x = (st_table_data const*) a;
|
|
|
|
st_table_data const *y = (st_table_data const*) b;
|
|
|
|
|
|
|
|
/* Doing lexical compare in order (db,name) */
|
|
|
|
int const res= strcmp(x->db, y->db);
|
|
|
|
return res != 0 ? res : strcmp(x->name, y->name);
|
|
|
|
}
|
|
|
|
|
2006-01-09 11:08:23 +01:00
|
|
|
bool check_table_binlog_row_based(THD *thd, TABLE *table)
|
|
|
|
{
|
2006-03-17 18:11:07 +01:00
|
|
|
static st_table_data const ignore[] = {
|
|
|
|
{ "mysql", "event" },
|
|
|
|
{ "mysql", "general_log" },
|
|
|
|
{ "mysql", "slow_log" }
|
|
|
|
};
|
|
|
|
|
|
|
|
my_size_t const ignore_size = sizeof(ignore)/sizeof(*ignore);
|
|
|
|
st_table_data const item = { table->s->db.str, table->s->table_name.str };
|
|
|
|
|
|
|
|
if (table->s->cached_row_logging_check == -1)
|
|
|
|
table->s->cached_row_logging_check=
|
|
|
|
(table->s->tmp_table == NO_TMP_TABLE) &&
|
|
|
|
binlog_filter->db_ok(table->s->db.str) &&
|
|
|
|
bsearch(&item, ignore, ignore_size,
|
|
|
|
sizeof(st_table_data), table_name_compare) == NULL;
|
|
|
|
|
|
|
|
DBUG_ASSERT(table->s->cached_row_logging_check == 0 ||
|
|
|
|
table->s->cached_row_logging_check == 1);
|
|
|
|
|
2006-01-09 11:08:23 +01:00
|
|
|
return
|
WL#2977 and WL#2712 global and session-level variable to set the binlog format (row/statement),
and new binlog format called "mixed" (which is statement-based except if only row-based is correct,
in this cset it means if UDF or UUID is used; more cases could be added in later 5.1 release):
SET GLOBAL|SESSION BINLOG_FORMAT=row|statement|mixed|default;
the global default is statement unless cluster is enabled (then it's row) as in 5.1-alpha.
It's not possible to use SET on this variable if a session is currently in row-based mode and has open temporary tables (because CREATE
TEMPORARY TABLE was not binlogged so temp table is not known on slave), or if NDB is enabled (because
NDB does not support such change on-the-fly, though it will later), of if in a stored function (see below).
The added tests test the possibility or impossibility to SET, their effects, and the mixed mode,
including in prepared statements and in stored procedures and functions.
Caveats:
a) The mixed mode will not work for stored functions: in mixed mode, a stored function will
always be binlogged as one call and in a statement-based way (e.g. INSERT VALUES(myfunc()) or SELECT myfunc()).
b) for the same reason, changing the thread's binlog format inside a stored function is
refused with an error message.
c) the same problems apply to triggers; implementing b) for triggers will be done later (will ask
Dmitri).
Additionally, as the binlog format is now changeable by each user for his session, I remove the implication
which was done at startup, where row-based automatically set log-bin-trust-routine-creators to 1
(not possible anymore as a user can now switch to stmt-based and do nasty things again), and automatically
set --innodb-locks-unsafe-for-binlog to 1 (was anyway theoretically incorrect as it disabled
phantom protection).
Plus fixes for compiler warnings.
2006-02-25 22:21:03 +01:00
|
|
|
thd->current_stmt_binlog_row_based &&
|
2006-01-09 11:08:23 +01:00
|
|
|
thd && (thd->options & OPTION_BIN_LOG) &&
|
2006-03-03 09:49:46 +01:00
|
|
|
mysql_bin_log.is_open() &&
|
2006-03-17 18:11:07 +01:00
|
|
|
table->s->cached_row_logging_check;
|
2006-01-09 11:08:23 +01:00
|
|
|
}
|
2005-12-22 06:39:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class RowsEventT> int binlog_log_row(TABLE* table,
|
|
|
|
const byte *before_record,
|
|
|
|
const byte *after_record)
|
|
|
|
{
|
2006-01-12 19:51:02 +01:00
|
|
|
if (table->file->is_injective())
|
|
|
|
return 0;
|
2005-12-22 06:39:02 +01:00
|
|
|
bool error= 0;
|
|
|
|
THD *const thd= current_thd;
|
|
|
|
|
|
|
|
if (check_table_binlog_row_based(thd, table))
|
|
|
|
{
|
|
|
|
MY_BITMAP cols;
|
|
|
|
/* Potential buffer on the stack for the bitmap */
|
|
|
|
uint32 bitbuf[BITMAP_STACKBUF_SIZE/sizeof(uint32)];
|
|
|
|
uint n_fields= table->s->fields;
|
|
|
|
my_bool use_bitbuf= n_fields <= sizeof(bitbuf)*8;
|
|
|
|
if (likely(!(error= bitmap_init(&cols,
|
|
|
|
use_bitbuf ? bitbuf : NULL,
|
|
|
|
(n_fields + 7) & ~7UL,
|
|
|
|
false))))
|
|
|
|
{
|
|
|
|
bitmap_set_all(&cols);
|
|
|
|
error=
|
|
|
|
RowsEventT::binlog_row_logging_function(thd, table,
|
|
|
|
table->file->has_transactions(),
|
|
|
|
&cols, table->s->fields,
|
|
|
|
before_record, after_record);
|
|
|
|
if (!use_bitbuf)
|
|
|
|
bitmap_free(&cols);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return error ? HA_ERR_RBR_LOGGING_FAILED : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Instantiate the versions we need for the above template function, because we
|
|
|
|
have -fno-implicit-template as compiling option.
|
|
|
|
*/
|
|
|
|
|
|
|
|
template int binlog_log_row<Write_rows_log_event>(TABLE *, const byte *, const byte *);
|
|
|
|
template int binlog_log_row<Delete_rows_log_event>(TABLE *, const byte *, const byte *);
|
|
|
|
template int binlog_log_row<Update_rows_log_event>(TABLE *, const byte *, const byte *);
|
|
|
|
|
|
|
|
#endif /* HAVE_ROW_BASED_REPLICATION */
|
|
|
|
|
2006-01-26 09:25:37 +01:00
|
|
|
int handler::ha_external_lock(THD *thd, int lock_type)
|
2005-12-22 06:39:02 +01:00
|
|
|
{
|
2006-02-16 08:30:53 +01:00
|
|
|
DBUG_ENTER("handler::ha_external_lock");
|
2005-12-22 06:39:02 +01:00
|
|
|
int error;
|
2006-01-26 09:25:37 +01:00
|
|
|
if (unlikely(error= external_lock(thd, lock_type)))
|
2006-02-16 08:30:53 +01:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
#ifdef HAVE_ROW_BASED_REPLICATION
|
|
|
|
if (table->file->is_injective())
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
There is a number of statements that are logged statement-based
|
|
|
|
but call external lock. For these, we do not need to generate a
|
|
|
|
table map.
|
|
|
|
|
|
|
|
TODO: The need for this switch is an indication that the model for
|
|
|
|
locking combined with row-based replication needs to be looked
|
|
|
|
over. Ideally, no such special handling should be needed.
|
|
|
|
*/
|
2006-05-05 19:08:40 +02:00
|
|
|
switch (thd->lex->sql_command) {
|
2006-02-16 08:30:53 +01:00
|
|
|
case SQLCOM_TRUNCATE:
|
|
|
|
case SQLCOM_ALTER_TABLE:
|
2006-05-05 19:08:40 +02:00
|
|
|
case SQLCOM_OPTIMIZE:
|
|
|
|
case SQLCOM_REPAIR:
|
2006-02-16 08:30:53 +01:00
|
|
|
DBUG_RETURN(0);
|
2006-03-26 11:32:52 +02:00
|
|
|
default:
|
|
|
|
break;
|
2006-02-16 08:30:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
If we are locking a table for writing, we generate a table map.
|
|
|
|
For all other kinds of locks, we don't do anything.
|
|
|
|
*/
|
|
|
|
if (lock_type == F_WRLCK && check_table_binlog_row_based(thd, table))
|
2005-12-22 06:39:02 +01:00
|
|
|
{
|
2006-02-16 08:30:53 +01:00
|
|
|
int const has_trans= table->file->has_transactions();
|
|
|
|
error= thd->binlog_write_table_map(table, has_trans);
|
|
|
|
if (unlikely(error))
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
DBUG_RETURN(0);
|
2006-01-26 09:25:37 +01:00
|
|
|
}
|
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
int handler::ha_write_row(byte *buf)
|
|
|
|
{
|
|
|
|
int error;
|
2006-01-26 09:25:37 +01:00
|
|
|
if (unlikely(error= write_row(buf)))
|
|
|
|
return error;
|
2005-12-22 06:39:02 +01:00
|
|
|
#ifdef HAVE_ROW_BASED_REPLICATION
|
2006-01-26 09:25:37 +01:00
|
|
|
if (unlikely(error= binlog_log_row<Write_rows_log_event>(table, 0, buf)))
|
|
|
|
return error;
|
2005-12-22 06:39:02 +01:00
|
|
|
#endif
|
2006-01-26 09:25:37 +01:00
|
|
|
return 0;
|
2005-12-22 06:39:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int handler::ha_update_row(const byte *old_data, byte *new_data)
|
|
|
|
{
|
|
|
|
int error;
|
2006-03-23 20:13:44 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Some storage engines require that the new record is in record[0]
|
|
|
|
(and the old record is in record[1]).
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(new_data == table->record[0]);
|
|
|
|
|
2006-01-26 09:25:37 +01:00
|
|
|
if (unlikely(error= update_row(old_data, new_data)))
|
|
|
|
return error;
|
2005-12-22 06:39:02 +01:00
|
|
|
#ifdef HAVE_ROW_BASED_REPLICATION
|
2006-01-26 09:25:37 +01:00
|
|
|
if (unlikely(error= binlog_log_row<Update_rows_log_event>(table, old_data, new_data)))
|
|
|
|
return error;
|
2005-12-22 06:39:02 +01:00
|
|
|
#endif
|
2006-01-26 09:25:37 +01:00
|
|
|
return 0;
|
2005-12-22 06:39:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int handler::ha_delete_row(const byte *buf)
|
|
|
|
{
|
|
|
|
int error;
|
2006-01-26 09:25:37 +01:00
|
|
|
if (unlikely(error= delete_row(buf)))
|
|
|
|
return error;
|
2005-12-22 06:39:02 +01:00
|
|
|
#ifdef HAVE_ROW_BASED_REPLICATION
|
2006-01-26 09:25:37 +01:00
|
|
|
if (unlikely(error= binlog_log_row<Delete_rows_log_event>(table, buf, 0)))
|
|
|
|
return error;
|
2005-12-22 06:39:02 +01:00
|
|
|
#endif
|
2006-01-26 09:25:37 +01:00
|
|
|
return 0;
|
2005-12-22 06:39:02 +01:00
|
|
|
}
|
2006-06-01 20:47:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Dummy function which accept information about log files which is not need
|
|
|
|
by handlers
|
|
|
|
*/
|
|
|
|
void signal_log_not_needed(struct handlerton, char *log_file)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("signal_log_not_needed");
|
|
|
|
DBUG_PRINT("enter", ("logfile '%s'", log_file));
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TRANS_LOG_MGM_EXAMPLE_CODE
|
|
|
|
/*
|
|
|
|
Example of transaction log management functions based on assumption that logs
|
|
|
|
placed into a directory
|
|
|
|
*/
|
|
|
|
#include <my_dir.h>
|
|
|
|
#include <my_sys.h>
|
|
|
|
int example_of_iterator_using_for_logs_cleanup(handlerton *hton)
|
|
|
|
{
|
|
|
|
void *buffer;
|
|
|
|
int res= 1;
|
|
|
|
struct handler_iterator iterator;
|
|
|
|
struct handler_log_file_data data;
|
|
|
|
|
|
|
|
if (!hton->create_iterator)
|
|
|
|
return 1; /* iterator creator is not supported */
|
|
|
|
|
|
|
|
if ((*hton->create_iterator)(HA_TRANSACTLOG_ITERATOR, &iterator) !=
|
|
|
|
HA_ITERATOR_OK)
|
|
|
|
{
|
|
|
|
/* error during creation of log iterator or iterator is not supported */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
while((*iterator.next)(&iterator, (void*)&data) == 0)
|
|
|
|
{
|
|
|
|
printf("%s\n", data.filename.str);
|
|
|
|
if (data.status == HA_LOG_STATUS_FREE &&
|
|
|
|
my_delete(data.filename.str, MYF(MY_WME)))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
res= 0;
|
|
|
|
err:
|
|
|
|
(*iterator.destroy)(&iterator);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Here we should get info from handler where it save logs but here is
|
|
|
|
just example, so we use constant.
|
|
|
|
IMHO FN_ROOTDIR ("/") is safe enough for example, because nobody has
|
|
|
|
rights on it except root and it consist of directories only at lest for
|
|
|
|
*nix (sorry, can't find windows-safe solution here, but it is only example).
|
|
|
|
*/
|
|
|
|
#define fl_dir FN_ROOTDIR
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Dummy function to return log status should be replaced by function which
|
|
|
|
really detect the log status and check that the file is a log of this
|
|
|
|
handler.
|
|
|
|
*/
|
|
|
|
enum log_status fl_get_log_status(char *log)
|
|
|
|
{
|
|
|
|
MY_STAT stat_buff;
|
|
|
|
if (my_stat(log, &stat_buff, MYF(0)))
|
|
|
|
return HA_LOG_STATUS_INUSE;
|
|
|
|
return HA_LOG_STATUS_NOSUCHLOG;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct fl_buff
|
|
|
|
{
|
|
|
|
LEX_STRING *names;
|
|
|
|
enum log_status *statuses;
|
|
|
|
uint32 entries;
|
|
|
|
uint32 current;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int fl_log_iterator_next(struct handler_iterator *iterator,
|
|
|
|
void *iterator_object)
|
|
|
|
{
|
|
|
|
struct fl_buff *buff= (struct fl_buff *)iterator->buffer;
|
|
|
|
struct handler_log_file_data *data=
|
|
|
|
(struct handler_log_file_data *) iterator_object;
|
|
|
|
if (buff->current >= buff->entries)
|
|
|
|
return 1;
|
|
|
|
data->filename= buff->names[buff->current];
|
|
|
|
data->status= buff->statuses[buff->current];
|
|
|
|
buff->current++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void fl_log_iterator_destroy(struct handler_iterator *iterator)
|
|
|
|
{
|
|
|
|
my_free((gptr)iterator->buffer, MYF(MY_ALLOW_ZERO_PTR));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
returns buffer, to be assigned in handler_iterator struct
|
|
|
|
*/
|
|
|
|
enum handler_create_iterator_result
|
|
|
|
fl_log_iterator_buffer_init(struct handler_iterator *iterator)
|
|
|
|
{
|
|
|
|
MY_DIR *dirp;
|
|
|
|
struct fl_buff *buff;
|
|
|
|
char *name_ptr;
|
|
|
|
byte *ptr;
|
|
|
|
FILEINFO *file;
|
|
|
|
uint32 i;
|
|
|
|
|
|
|
|
/* to be able to make my_free without crash in case of error */
|
|
|
|
iterator->buffer= 0;
|
|
|
|
|
|
|
|
if (!(dirp = my_dir(fl_dir, MYF(0))))
|
|
|
|
{
|
|
|
|
return HA_ITERATOR_ERROR;
|
|
|
|
}
|
|
|
|
if ((ptr= (byte*)my_malloc(ALIGN_SIZE(sizeof(fl_buff)) +
|
|
|
|
((ALIGN_SIZE(sizeof(LEX_STRING)) +
|
|
|
|
sizeof(enum log_status) +
|
|
|
|
+ FN_REFLEN) *
|
|
|
|
(uint) dirp->number_off_files),
|
|
|
|
MYF(0))) == 0)
|
|
|
|
{
|
|
|
|
return HA_ITERATOR_ERROR;
|
|
|
|
}
|
|
|
|
buff= (struct fl_buff *)ptr;
|
|
|
|
buff->entries= buff->current= 0;
|
|
|
|
ptr= ptr + (ALIGN_SIZE(sizeof(fl_buff)));
|
|
|
|
buff->names= (LEX_STRING*) (ptr);
|
|
|
|
ptr= ptr + ((ALIGN_SIZE(sizeof(LEX_STRING)) *
|
|
|
|
(uint) dirp->number_off_files));
|
|
|
|
buff->statuses= (enum log_status *)(ptr);
|
|
|
|
name_ptr= (char *)(ptr + (sizeof(enum log_status) *
|
|
|
|
(uint) dirp->number_off_files));
|
|
|
|
for (i=0 ; i < (uint) dirp->number_off_files ; i++)
|
|
|
|
{
|
|
|
|
enum log_status st;
|
|
|
|
file= dirp->dir_entry + i;
|
|
|
|
if ((file->name[0] == '.' &&
|
|
|
|
((file->name[1] == '.' && file->name[2] == '\0') ||
|
|
|
|
file->name[1] == '\0')))
|
|
|
|
continue;
|
|
|
|
if ((st= fl_get_log_status(file->name)) == HA_LOG_STATUS_NOSUCHLOG)
|
|
|
|
continue;
|
|
|
|
name_ptr= strxnmov(buff->names[buff->entries].str= name_ptr,
|
|
|
|
FN_REFLEN, fl_dir, file->name, NullS);
|
|
|
|
buff->names[buff->entries].length= (name_ptr -
|
|
|
|
buff->names[buff->entries].str) - 1;
|
|
|
|
buff->statuses[buff->entries]= st;
|
|
|
|
buff->entries++;
|
|
|
|
}
|
|
|
|
|
|
|
|
iterator->buffer= buff;
|
|
|
|
iterator->next= &fl_log_iterator_next;
|
|
|
|
iterator->destroy= &fl_log_iterator_destroy;
|
|
|
|
return HA_ITERATOR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* An example of a iterator creator */
|
|
|
|
enum handler_create_iterator_result
|
|
|
|
fl_create_iterator(enum handler_iterator_type type,
|
|
|
|
struct handler_iterator *iterator)
|
|
|
|
{
|
|
|
|
switch(type){
|
|
|
|
case HA_TRANSACTLOG_ITERATOR:
|
|
|
|
return fl_log_iterator_buffer_init(iterator);
|
|
|
|
default:
|
|
|
|
return HA_ITERATOR_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /*TRANS_LOG_MGM_EXAMPLE_CODE*/
|