diff options
author | unknown <tsmith@maint1.mysql.com> | 2007-07-05 01:05:47 +0200 |
---|---|---|
committer | unknown <tsmith@maint1.mysql.com> | 2007-07-05 01:05:47 +0200 |
commit | bd8b9746bfbb620b0f37d030169e2ae459aec4de (patch) | |
tree | 46812f6c11e790baeeed0712f371e6a5c4800699 /sql | |
parent | aa6565cef755b3383f081c39a126ac62768bd394 (diff) | |
download | mariadb-git-bd8b9746bfbb620b0f37d030169e2ae459aec4de.tar.gz |
WL#3914: Additonal accessors required to compile InnoDB as a plugin storage engine
Add more accessors to MySQL internals in mysql/plugin.h, for storage
engine plugins.
Add some accessors specific to the InnoDB storage engine, to allow
InnoDB to be compiled as a plugin (without MYSQL_SERVER). InnoDB
has additional requirements, due to its foreign key support, etc.
include/m_string.h:
Add structure tag to LEX_STRING definition, so that it can be referred
to by forward declarations. Allow struct st_mysql_lex_string to be
defined here, or in mysql/plugin.h.
include/my_global.h:
Define INNODB_COMPATIBILITY_HOOKS unconditionally; it brackets
some definitions needed for the InnoDB storage engine plugin
which do not belong in our general plugin interface.
include/mysql/plugin.h:
Additional accessors for MySQL internals:
- Full definition of MYSQL_LEX_STRING (identical to LEX_STRING from
m_string.h)
- Full definition of MYSQL_XID (binary compatible with XID from
handler.h)
- mysql_tmpfile(), creates a temporary file in mysqld's tmpdir
- thd_killed(), to check killed state of connection
- thd_alloc() and similar allocation functions
- thd_get_xid(), to get XID of connection's transaction
- mysql_query_cache_invalidate4, to invalidate a table's query cache entries
sql/handler.h:
Use MYSQL_XIDDATASIZE definition from mysql/plugin.h, to avoid redundant
definitions
sql/log.cc:
Add definitions for two InnoDB compatibility hooks:
- mysql_bin_log_file(), to get log filename
- mysql_bin_log_file_pos, to get position in file
These are defined only if INNODB_COMPATIBILITY_HOOKS is defined;
they are needed by the InnoDB plugin, but aren't part of the general
plugin interface. They are declared in ha_innodb.h for InnoDB's
use.
sql/mysql_priv.h:
Expose some server internals when INNODB_COMPATIBILITY_HOOKS is
defined, so that InnoDB can be built as a plugin when MYSQL_SERVER
is not defined.
Move make_lex_string inside THD class.
sql/sql_cache.cc:
Add definiton of mysql_query_cache_invalidate4(), a part of the
plugin API (mysql/plugin.h).
sql/sql_class.cc:
Add definitions for several accessor functions which form part
of the plugin API (mysql/plugin.h):
- mysql_tmpfile()
- thd_alloc() and friends
- thd_make_lex_string()
- thd_get_xid()
Add definitons for accessor functions which InnoDB requires,
but which are not part of the plugin interface:
- thd_charset()
- thd_query()
- thd_slave_thread()
- thd_non_transactional_update()
- thd_binlog_format()
Move definition of make_lex_string() from sql_show.cc into THD class
sql/sql_class.h:
Remove LEX_STRING_make(), and move make_lex_string() from sql_show.cc inside THD
class.
sql/sql_parse.cc:
Use thd->make_lex_string() instead of thd->LEX_STRING_make()
sql/sql_show.cc:
Move make_lex_string() inside THD class
storage/innobase/handler/ha_innodb.cc:
Call thd_make_lex_string() instead of make_lex_string().
Diffstat (limited to 'sql')
-rw-r--r-- | sql/handler.h | 10 | ||||
-rw-r--r-- | sql/log.cc | 23 | ||||
-rw-r--r-- | sql/mysql_priv.h | 54 | ||||
-rw-r--r-- | sql/sql_cache.cc | 12 | ||||
-rw-r--r-- | sql/sql_class.cc | 128 | ||||
-rw-r--r-- | sql/sql_class.h | 11 | ||||
-rw-r--r-- | sql/sql_parse.cc | 6 | ||||
-rw-r--r-- | sql/sql_show.cc | 22 |
8 files changed, 229 insertions, 37 deletions
diff --git a/sql/handler.h b/sql/handler.h index 4095a2f4cb1..09de9a3873a 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -328,13 +328,21 @@ typedef ulonglong my_xid; // this line is the same as in log_event.h #define MYSQL_XID_OFFSET (MYSQL_XID_PREFIX_LEN+sizeof(server_id)) #define MYSQL_XID_GTRID_LEN (MYSQL_XID_OFFSET+sizeof(my_xid)) -#define XIDDATASIZE 128 +#define XIDDATASIZE MYSQL_XIDDATASIZE #define MAXGTRIDSIZE 64 #define MAXBQUALSIZE 64 #define COMPATIBLE_DATA_YES 0 #define COMPATIBLE_DATA_NO 1 +/** + struct xid_t is binary compatible with the XID structure as + in the X/Open CAE Specification, Distributed Transaction Processing: + The XA Specification, X/Open Company Ltd., 1991. + http://www.opengroup.org/bookstore/catalog/c193.htm + + @see MYSQL_XID in mysql/plugin.h +*/ struct xid_t { long formatID; long gtrid_length; diff --git a/sql/log.cc b/sql/log.cc index 2821fb399a4..8ad290fdefc 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -5245,6 +5245,29 @@ err1: return 1; } + +#ifdef INNODB_COMPATIBILITY_HOOKS +/** + Get the file name of the MySQL binlog. + @return the name of the binlog file +*/ +extern "C" +const char* mysql_bin_log_file_name(void) +{ + return mysql_bin_log.get_log_fname(); +} +/** + Get the current position of the MySQL binlog. + @return byte offset from the beginning of the binlog +*/ +extern "C" +ulonglong mysql_bin_log_file_pos(void) +{ + return (ulonglong) mysql_bin_log.get_log_file()->pos_in_file; +} +#endif /* INNODB_COMPATIBILITY_HOOKS */ + + struct st_mysql_storage_engine binlog_storage_engine= { MYSQL_HANDLERTON_INTERFACE_VERSION }; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 98c06148313..d18dc9b90e9 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -1182,7 +1182,11 @@ bool mysqld_show_open_tables(THD *thd,const char *wild); bool mysqld_show_logs(THD *thd); void append_identifier(THD *thd, String *packet, const char *name, uint length); +#endif /* MYSQL_SERVER */ +#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS int get_quote_char_for_identifier(THD *thd, const char *name, uint length); +#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ +#ifdef MYSQL_SERVER void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild); int mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd); bool mysqld_show_create(THD *thd, TABLE_LIST *table_list); @@ -1211,9 +1215,6 @@ void reset_status_vars(); /* information schema */ extern LEX_STRING INFORMATION_SCHEMA_NAME; extern const LEX_STRING partition_keywords[]; -LEX_STRING *make_lex_string(THD *thd, LEX_STRING *lex_str, - const char* str, uint length, - bool allocate_lex_string); ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name); ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx); int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, @@ -1691,9 +1692,14 @@ extern int creating_table; // How many mysql_create_table() are running */ extern time_t server_start_time; +#endif /* MYSQL_SERVER */ +#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS extern uint mysql_data_home_len; extern char *mysql_data_home,server_version[SERVER_VERSION_LENGTH], - mysql_real_data_home[], *opt_mysql_tmpdir, mysql_charsets_dir[], + mysql_real_data_home[]; +#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ +#ifdef MYSQL_SERVER +extern char *opt_mysql_tmpdir, mysql_charsets_dir[], def_ft_boolean_syntax[sizeof(ft_boolean_syntax)]; #define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list)) extern MY_TMPDIR mysql_tmpdir_list; @@ -1710,8 +1716,13 @@ extern Gt_creator gt_creator; extern Lt_creator lt_creator; extern Ge_creator ge_creator; extern Le_creator le_creator; -extern char language[FN_REFLEN], reg_ext[FN_EXTLEN]; +extern char language[FN_REFLEN]; +#endif /* MYSQL_SERVER */ +#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS +extern char reg_ext[FN_EXTLEN]; extern uint reg_ext_length; +#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ +#ifdef MYSQL_SERVER extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN]; extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file; extern char log_error_file[FN_REFLEN], *opt_tc_log_file; @@ -1740,17 +1751,32 @@ extern ulong max_binlog_size, max_relay_log_size; extern ulong opt_binlog_rows_event_max_size; extern ulong rpl_recovery_rank, thread_cache_size, thread_pool_size; extern ulong back_log; -extern ulong specialflag, current_pid; +#endif /* MYSQL_SERVER */ +#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS +extern ulong specialflag; +#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ +#ifdef MYSQL_SERVER +extern ulong current_pid; extern ulong expire_logs_days, sync_binlog_period, sync_binlog_counter; extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size; extern ulong tc_log_page_waits; extern my_bool relay_log_purge, opt_innodb_safe_binlog, opt_innodb; extern uint test_flags,select_errors,ha_open_options; extern uint protocol_version, mysqld_port, dropping_tables; -extern uint delay_key_write_options, lower_case_table_names; +extern uint delay_key_write_options; +#endif /* MYSQL_SERVER */ +#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS +extern uint lower_case_table_names; +#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ +#ifdef MYSQL_SERVER extern bool opt_endinfo, using_udf_functions; extern my_bool locked_in_memory; -extern bool opt_using_transactions, mysqld_embedded; +extern bool opt_using_transactions; +#endif /* MYSQL_SERVER */ +#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS +extern bool mysqld_embedded; +#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ +#ifdef MYSQL_SERVER extern bool using_update_log, opt_large_files, server_id_supplied; extern bool opt_update_log, opt_bin_log, opt_error_log; extern my_bool opt_log, opt_slow_log; @@ -1774,8 +1800,12 @@ extern uint opt_crash_binlog_innodb; extern char *shared_memory_base_name, *mysqld_unix_port; extern my_bool opt_enable_shared_memory; extern char *default_tz_name; +#endif /* MYSQL_SERVER */ +#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS extern my_bool opt_large_pages; extern uint opt_large_page_size; +#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ +#ifdef MYSQL_SERVER extern char *opt_logname, *opt_slow_logname; extern const char *log_output_str; @@ -1811,7 +1841,11 @@ extern MY_BITMAP temp_pool; extern String my_empty_string; extern const String my_null_string; extern SHOW_VAR status_vars[]; +#endif /* MYSQL_SERVER */ +#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS extern struct system_variables global_system_variables; +#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ +#ifdef MYSQL_SERVER extern struct system_variables max_system_variables; extern struct system_status_var global_status_var; extern struct rand_struct sql_rand; @@ -2009,10 +2043,14 @@ int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr); char *fn_rext(char *name); /* Conversion functions */ +#endif /* MYSQL_SERVER */ +#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS uint strconvert(CHARSET_INFO *from_cs, const char *from, CHARSET_INFO *to_cs, char *to, uint to_length, uint *errors); uint filename_to_tablename(const char *from, char *to, uint to_length); uint tablename_to_filename(const char *from, char *to, uint to_length); +#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ +#ifdef MYSQL_SERVER uint build_table_filename(char *buff, size_t bufflen, const char *db, const char *table, const char *ext, uint flags); diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 719c67aff6a..173ef4c02df 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -765,6 +765,18 @@ void query_cache_invalidate_by_MyISAM_filename(const char *filename) } +/* + The following function forms part of the C plugin API +*/ +extern "C" +void mysql_query_cache_invalidate4(THD *thd, + const char *key, unsigned key_length, + int using_trx) +{ + query_cache.invalidate(thd, key, (uint32) key_length, (my_bool) using_trx); +} + + /***************************************************************************** Query_cache methods *****************************************************************************/ diff --git a/sql/sql_class.cc b/sql/sql_class.cc index e279e23ab69..337bd4e6cc1 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -207,6 +207,31 @@ Open_tables_state::Open_tables_state(ulong version_arg) The following functions form part of the C plugin API */ +extern "C" int mysql_tmpfile(const char *prefix) +{ + char filename[FN_REFLEN]; + File fd = create_temp_file(filename, mysql_tmpdir, prefix, +#ifdef __WIN__ + O_BINARY | O_TRUNC | O_SEQUENTIAL | + O_SHORT_LIVED | +#endif /* __WIN__ */ + O_CREAT | O_EXCL | O_RDWR | O_TEMPORARY, + MYF(MY_WME)); + if (fd >= 0) { +#ifndef __WIN__ + /* + This can be removed once the following bug is fixed: + Bug #28903 create_temp_file() doesn't honor O_TEMPORARY option + (file not removed) (Unix) + */ + unlink(filename); +#endif /* !__WIN__ */ + } + + return fd; +} + + extern "C" int thd_in_lock_tables(const THD *thd) { @@ -488,6 +513,49 @@ void THD::pop_internal_handler() m_internal_handler= NULL; } +extern "C" +void *thd_alloc(MYSQL_THD thd, unsigned int size) +{ + return thd->alloc(size); +} + +extern "C" +void *thd_calloc(MYSQL_THD thd, unsigned int size) +{ + return thd->calloc(size); +} + +extern "C" +char *thd_strdup(MYSQL_THD thd, const char *str) +{ + return thd->strdup(str); +} + +extern "C" +char *thd_strmake(MYSQL_THD thd, const char *str, unsigned int size) +{ + return thd->strmake(str, size); +} + +extern "C" +LEX_STRING *thd_make_lex_string(THD *thd, LEX_STRING *lex_str, + const char *str, unsigned int size, + int allocate_lex_string) +{ + return thd->make_lex_string(lex_str, str, size, + (bool) allocate_lex_string); +} + +extern "C" +void *thd_memdup(MYSQL_THD thd, const void* str, unsigned int size) +{ + return thd->memdup(str, size); +} + +void thd_get_xid(const MYSQL_THD thd, MYSQL_XID *xid) +{ + *xid = *(MYSQL_XID *) &thd->transaction.xid_state.xid; +} /* Init common variables that has to be reset on start and on change_user @@ -856,6 +924,30 @@ void THD::cleanup_after_query() } +/** + Create a LEX_STRING in this connection + + @param lex_str pointer to LEX_STRING object to be initialized + @param str initializer to be copied into lex_str + @param length length of str, in bytes + @param allocate_lex_string if TRUE, allocate new LEX_STRING object, + instead of using lex_str value + @return NULL on failure, or pointer to the LEX_STRING object +*/ +LEX_STRING *THD::make_lex_string(LEX_STRING *lex_str, + const char* str, uint length, + bool allocate_lex_string) +{ + if (allocate_lex_string) + if (!(lex_str= (LEX_STRING *)alloc(sizeof(LEX_STRING)))) + return 0; + if (!(lex_str->str= strmake_root(mem_root, str, length))) + return 0; + lex_str->length= length; + return lex_str; +} + + /* Convert a string to another character set @@ -2441,7 +2533,43 @@ void THD::restore_backup_open_tables_state(Open_tables_state *backup) DBUG_VOID_RETURN; } +/** + Check the killed state of a user thread + @param thd user thread + @retval 0 the user thread is active + @retval 1 the user thread has been killed +*/ +extern "C" int thd_killed(const MYSQL_THD thd) +{ + return(thd->killed); +} + +#ifdef INNODB_COMPATIBILITY_HOOKS +extern "C" struct charset_info_st *thd_charset(MYSQL_THD thd) +{ + return(thd->charset()); +} + +extern "C" char **thd_query(MYSQL_THD thd) +{ + return(&thd->query); +} + +extern "C" int thd_slave_thread(const MYSQL_THD thd) +{ + return(thd->slave_thread); +} +extern "C" int thd_non_transactional_update(const MYSQL_THD thd) +{ + return(thd->no_trans_update.all); +} + +extern "C" int thd_binlog_format(const THD *thd) +{ + return (int) thd->variables.binlog_format; +} +#endif // INNODB_COMPATIBILITY_HOOKS */ /**************************************************************************** Handling of statement states in functions and triggers. diff --git a/sql/sql_class.h b/sql/sql_class.h index 6fa71b57997..a35cdbbec2a 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -490,13 +490,6 @@ public: { return strdup_root(mem_root,str); } inline char *strmake(const char *str, size_t size) { return strmake_root(mem_root,str,size); } - inline bool LEX_STRING_make(LEX_STRING *lex_str, const char *str, - size_t size) - { - return ((lex_str->str= - strmake_root(mem_root, str, (lex_str->length= size)))) == 0; - } - inline void *memdup(const void *str, size_t size) { return memdup_root(mem_root,str,size); } inline void *memdup_w_gap(const void *str, size_t size, uint gap) @@ -1594,6 +1587,10 @@ public: return alloc_root(&transaction.mem_root,size); } + LEX_STRING *make_lex_string(LEX_STRING *lex_str, + const char* str, uint length, + bool allocate_lex_string); + bool convert_string(LEX_STRING *to, CHARSET_INFO *to_cs, const char *from, uint from_length, CHARSET_INFO *from_cs); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index bd151dc2028..aa661b64598 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1025,8 +1025,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, HA_CREATE_INFO create_info; status_var_increment(thd->status_var.com_stat[SQLCOM_CREATE_DB]); - if (thd->LEX_STRING_make(&db, packet, packet_length -1) || - thd->LEX_STRING_make(&alias, db.str, db.length) || + if (thd->make_lex_string(&db, packet, packet_length - 1, FALSE) || + thd->make_lex_string(&alias, db.str, db.length, FALSE) || check_db_name(&db)) { my_error(ER_WRONG_DB_NAME, MYF(0), db.str ? db.str : "NULL"); @@ -1046,7 +1046,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, status_var_increment(thd->status_var.com_stat[SQLCOM_DROP_DB]); LEX_STRING db; - if (thd->LEX_STRING_make(&db, packet, packet_length - 1) || + if (thd->make_lex_string(&db, packet, packet_length - 1, FALSE) || check_db_name(&db)) { my_error(ER_WRONG_DB_NAME, MYF(0), db.str ? db.str : "NULL"); diff --git a/sql/sql_show.cc b/sql/sql_show.cc index f66897df671..e74f09362e3 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2175,20 +2175,6 @@ void calc_sum_of_all_status(STATUS_VAR *to) } -LEX_STRING *make_lex_string(THD *thd, LEX_STRING *lex_str, - const char* str, uint length, - bool allocate_lex_string) -{ - MEM_ROOT *mem= thd->mem_root; - if (allocate_lex_string) - if (!(lex_str= (LEX_STRING *)thd->alloc(sizeof(LEX_STRING)))) - return 0; - lex_str->str= strmake_root(mem, str, length); - lex_str->length= length; - return lex_str; -} - - /* INFORMATION_SCHEMA name */ LEX_STRING INFORMATION_SCHEMA_NAME= { C_STRING_WITH_LEN("information_schema")}; @@ -5194,10 +5180,10 @@ int make_schema_select(THD *thd, SELECT_LEX *sel, We have to make non const db_name & table_name because of lower_case_table_names */ - make_lex_string(thd, &db, INFORMATION_SCHEMA_NAME.str, - INFORMATION_SCHEMA_NAME.length, 0); - make_lex_string(thd, &table, schema_table->table_name, - strlen(schema_table->table_name), 0); + thd->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str, + INFORMATION_SCHEMA_NAME.length, 0); + thd->make_lex_string(&table, schema_table->table_name, + strlen(schema_table->table_name), 0); if (schema_table->old_format(thd, schema_table) || /* Handle old syntax */ !sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0), 0, 0, TL_READ)) |