diff options
author | unknown <monty@mashka.mysql.fi> | 2002-06-11 11:20:31 +0300 |
---|---|---|
committer | unknown <monty@mashka.mysql.fi> | 2002-06-11 11:20:31 +0300 |
commit | 70aa7424c41c45a8fb171bbdd9e24d74b70a7765 (patch) | |
tree | 8fcaabe013fff43cf466235067f2c47f0cd66531 /sql | |
parent | 30d5eb22877d0546fb4bd93ead7e8602285d449b (diff) | |
download | mariadb-git-70aa7424c41c45a8fb171bbdd9e24d74b70a7765.tar.gz |
Big code cleanup/review before 4.0.2 release.
(All commit emails since 4.0.1 checked)
This had to be done now, before the 4.1 tree changes to much, to make it easy to propagate bug fixes to the 4.1 tree.
BUILD/SETUP.sh:
Added -DPEDANTIC_SAFEMALLOC as standard debug option
Docs/manual.texi:
Changes for new version.
client/mysql.cc:
Fixed default value for rehash
cleanup
client/mysqladmin.c:
Cleanup
client/mysqlbinlog.cc:
cleanup
client/mysqldump.c:
Cleanup
client/mysqlmanager-pwgen.c:
Cleanup
client/mysqlmanagerc.c:
Cleanup
client/mysqltest.c:
Cleanup
dbug/dbug.c:
Cleanup
extra/resolve_stack_dump.c:
Cleanup & Simple optimizations
include/ft_global.h:
Cleanup
include/my_alloc.h:
Cleanup
include/my_global.h:
Cleanup
include/my_sys.h:
Cleanup
include/myisam.h:
Cleanup
libmysql/libmysql.c:
Cleanup
libmysql/manager.c:
Cleanup
myisam/ft_boolean_search.c:
Cleanup
myisam/ft_dump.c:
Change strcpy -> strmov
myisam/ft_eval.c:
Cleanup
myisam/ft_nlq_search.c:
Cleanup
myisam/ft_test1.c:
strncpy -> strnmov
myisam/ft_update.c:
Cleanup
myisam/mi_static.c:
Cleanup
myisam/mi_test2.c:
Cleanup
myisam/mi_write.c:
Cleanup
mysys/mf_fn_ext.c:
Cleanup
mysys/mf_iocache.c:
Cleanup
mysys/mf_iocache2.c:
Cleanup
mysys/my_getopt.c:
Cleanup
mysys/my_read.c:
Cleanup
mysys/my_thr_init.c:
Cleanup
mysys/queues.c:
Cleanup
mysys/safemalloc.c:
Cleanup
sql/field.cc:
Indentation cleanups
sql/ha_berkeley.cc:
Indentation cleanups
sql/ha_myisam.cc:
Cleanup
sql/item.h:
Indentation cleanups
sql/item_cmpfunc.cc:
Indentation cleanups
sql/item_create.cc:
cleanup
sql/item_func.cc:
Cleanup
sql/item_func.h:
Indentation cleanups
sql/item_strfunc.cc:
Indentation cleanups
sql/item_sum.cc:
Indentation cleanups
sql/item_timefunc.cc:
Indentation cleanups
sql/lock.cc:
Indentation cleanups
sql/log.cc:
Cleanup
strnmov -> strmake
sql/log_event.cc:
Cleanup + optimizations
Fixed memory leak
Added missing pthread_mutex_unlock() (On error condition)
sql/log_event.h:
Indentation and comment cleanup
Merged #ifdef's into common blocks for better readability
sql/mini_client.cc:
Indentation cleanup
sql/mysql_priv.h:
Cleanup
Changed int function to bool
sql/mysqld.cc:
Indentation and comment cleanup
sql/net_pkg.cc:
Indentation cleanup
sql/net_serv.cc:
Changed int function -> bool
sql/nt_servc.cc:
Cleanup
sql/opt_range.cc:
Indentation cleanup
sql/repl_failsafe.cc:
Cleanup + simple optimization
strnmov -> strmake
sql/slave.cc:
strnmov -> strmake
Cleanups
sql/slave.h:
Cleanup
sql/sql_acl.cc:
Indentation and DBUG_PRINT cleanup
Changed WITH MAX... to not use =
sql/sql_base.cc:
Indentation cleanup
sql/sql_cache.cc:
Indentation cleanup
sql/sql_class.cc:
Indentation cleanup
sql/sql_class.h:
Renamed some struct slots
sql/sql_delete.cc:
Indentation cleanup
sql/sql_handler.cc:
Indentation cleanup
sql/sql_insert.cc:
Use new slot names.
sql/sql_lex.cc:
Indentation cleanup
sql/sql_lex.h:
Indentation cleanup
sql/sql_load.cc:
Indentation cleanup
sql/sql_parse.cc:
Indentation cleanup
Removed not used check from LOCK TABLES
sql/sql_repl.cc:
strnmov -> strmake
sql/sql_repl.h:
Removed test if file is included (We want to know if it's included twice to avoid this)
sql/sql_select.cc:
Indentation cleanup
sql/sql_show.cc:
Indentation cleanup
sql/sql_string.cc:
Indentation cleanup
sql/sql_table.cc:
Indentation cleanup
sql/sql_union.cc:
Use renamed struct slot
sql/sql_update.cc:
Indentation cleanup
sql/sql_yacc.yy:
Removed = after GRANT ... MAX_ to make the syntax uniform
sql/table.cc:
Indentation cleanup
sql/table.h:
Indentation cleanup
sql/time.cc:
Indentation cleanup
sql/udf_example.cc:
Indentation cleanup
sql/unireg.cc:
strnmov -> strmake
tests/grant.pl:
Added test for LOCK TABLES
tools/mysqlmanager.c:
Cleanup
fopen() -> my_fopen()
vio/viosocket.c:
DBUG_PRINT cleanups
vio/viosslfactories.c:
Indentation cleanup
Checking of results from malloc()
Fixed possible memory leak
BitKeeper/etc/ignore:
Added scripts/mysql_secure_installation to the ignore list
BitKeeper/etc/logging_ok:
Logging to logging@openlogging.org accepted
Diffstat (limited to 'sql')
50 files changed, 1339 insertions, 1237 deletions
diff --git a/sql/field.cc b/sql/field.cc index 5466facb437..3c45d22135a 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -141,7 +141,7 @@ bool test_if_int(const char *str,int length) str++; if (str == end) return 0; // Error: Empty string - for ( ; str != end ; str++) + for (; str != end ; str++) { if (!isdigit(*str)) { @@ -204,7 +204,7 @@ static bool test_if_real(const char *str,int length) length--; str++; } } - for ( ; length ; length--, str++) + for (; length ; length--, str++) { // Allow end space if (!isspace(*str)) return 0; @@ -3336,9 +3336,9 @@ void Field_datetime::sql_type(String &res) const void Field_string::store(const char *from,uint length) { #ifdef USE_TIS620 - if(!binary_flag) { + if (!binary_flag) { ThNormalize((uchar *)ptr, field_length, (uchar *)from, length); - if(length < field_length) { + if (length < field_length) { bfill(ptr + length, field_length - length, ' '); } } @@ -3540,7 +3540,7 @@ uint Field_string::max_packed_col_length(uint max_length) void Field_varstring::store(const char *from,uint length) { #ifdef USE_TIS620 - if(!binary_flag) + if (!binary_flag) { ThNormalize((uchar *) ptr+2, field_length, (uchar *) from, length); } @@ -3869,7 +3869,7 @@ void Field_blob::store(const char *from,uint len) if (table->copy_blobs || len <= MAX_FIELD_WIDTH) { // Must make a copy #ifdef USE_TIS620 - if(!binary_flag) + if (!binary_flag) { /* If there isn't enough memory, use original string */ if ((th_ptr=(char * ) my_malloc(sizeof(char) * len,MYF(0)))) @@ -4489,7 +4489,7 @@ ulonglong find_set(TYPELIB *lib,const char *x,uint length) for (;;) { const char *pos=start; - for ( ; pos != end && *pos != field_separator ; pos++) ; + for (; pos != end && *pos != field_separator ; pos++) ; uint find=find_enum(lib,start,(uint) (pos-start)); if (!find) error=1; diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc index 614d1b5abf5..0aace45da94 100644 --- a/sql/ha_berkeley.cc +++ b/sql/ha_berkeley.cc @@ -358,7 +358,7 @@ berkeley_cmp_packed_key(DB *file, const DBT *new_key, const DBT *saved_key) KEY_PART_INFO *key_part= key->key_part, *end=key_part+key->key_parts; uint key_length=new_key->size; - for ( ; key_part != end && (int) key_length > 0; key_part++) + for (; key_part != end && (int) key_length > 0; key_part++) { int cmp; if (key_part->null_bit) @@ -396,7 +396,7 @@ berkeley_cmp_fix_length_key(DB *file, const DBT *new_key, const DBT *saved_key) KEY_PART_INFO *key_part= key->key_part, *end=key_part+key->key_parts; uint key_length=new_key->size; - for ( ; key_part != end && (int) key_length > 0 ; key_part++) + for (; key_part != end && (int) key_length > 0 ; key_part++) { int cmp; if ((cmp=key_part->field->pack_cmp(new_key_ptr,saved_key_ptr,0))) @@ -417,7 +417,7 @@ berkeley_key_cmp(TABLE *table, KEY *key_info, const char *key, uint key_length) KEY_PART_INFO *key_part= key_info->key_part, *end=key_part+key_info->key_parts; - for ( ; key_part != end && (int) key_length > 0; key_part++) + for (; key_part != end && (int) key_length > 0; key_part++) { int cmp; if (key_part->null_bit) @@ -561,7 +561,7 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked) ref_length=0; KEY_PART_INFO *key_part= table->key_info[primary_key].key_part; KEY_PART_INFO *end=key_part+table->key_info[primary_key].key_parts; - for ( ; key_part != end ; key_part++) + for (; key_part != end ; key_part++) ref_length+= key_part->field->max_packed_col_length(key_part->length); share->fixed_length_primary_key= (ref_length == table->key_info[primary_key].key_length); @@ -701,7 +701,7 @@ void ha_berkeley::unpack_key(char *record, DBT *key, uint index) *end=key_part+key_info->key_parts; char *pos=(char*) key->data; - for ( ; key_part != end; key_part++) + for (; key_part != end; key_part++) { if (key_part->null_bit) { @@ -747,7 +747,7 @@ DBT *ha_berkeley::create_key(DBT *key, uint keynr, char *buff, key->data=buff; key->app_private= key_info; - for ( ; key_part != end && key_length > 0; key_part++) + for (; key_part != end && key_length > 0; key_part++) { if (key_part->null_bit) { @@ -925,7 +925,7 @@ int ha_berkeley::key_cmp(uint keynr, const byte * old_row, KEY_PART_INFO *key_part=table->key_info[keynr].key_part; KEY_PART_INFO *end=key_part+table->key_info[keynr].key_parts; - for ( ; key_part != end ; key_part++) + for (; key_part != end ; key_part++) { if (key_part->null_bit) { @@ -1584,7 +1584,7 @@ DBT *ha_berkeley::get_pos(DBT *to, byte *pos) KEY_PART_INFO *key_part=table->key_info[primary_key].key_part; KEY_PART_INFO *end=key_part+table->key_info[primary_key].key_parts; - for ( ; key_part != end ; key_part++) + for (; key_part != end ; key_part++) pos+=key_part->field->packed_col_length((char*) pos,key_part->length); to->size= (uint) (pos- (byte*) to->data); } diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 50088c238e0..dc0136b7138 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -45,6 +45,7 @@ TYPELIB myisam_recover_typelib= {array_elements(myisam_recover_names)-1,"", *****************************************************************************/ // collect errors printed by mi_check routines + static void mi_check_print_msg(MI_CHECK *param, const char* msg_type, const char *fmt, va_list args) { @@ -134,7 +135,7 @@ int ha_myisam::net_read_dump(NET* net) int error = 0; my_seek(data_fd, 0L, MY_SEEK_SET, MYF(MY_WME)); - for(;;) + for (;;) { ulong packet_len = my_net_read(net); if (!packet_len) @@ -171,7 +172,7 @@ int ha_myisam::dump(THD* thd, int fd) int error = 0; my_seek(data_fd, 0L, MY_SEEK_SET, MYF(MY_WME)); - for(; bytes_to_read > 0;) + for (; bytes_to_read > 0;) { uint bytes = my_read(data_fd, buf, blocksize, MYF(MY_WME)); if (bytes == MY_FILE_ERROR) @@ -494,8 +495,8 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) while ((error=repair(thd,param,0)) && param.retry_repair) { param.retry_repair=0; - if ((param.testflag & T_RETRY_WITHOUT_QUICK) && - (param.testflag & T_QUICK)) + if (test_all_bits(param.testflag, + (uint) (T_RETRY_WITHOUT_QUICK | T_QUICK))) { param.testflag&= ~T_RETRY_WITHOUT_QUICK; sql_print_error("Warning: Retrying repair of: '%s' without quick", diff --git a/sql/item.h b/sql/item.h index 1ce29748d2e..7612246b4b0 100644 --- a/sql/item.h +++ b/sql/item.h @@ -118,7 +118,10 @@ public: double val_result(); longlong val_int_result(); String *str_result(String* tmp); - bool send(THD *thd, String *str_arg) { return result_field->send(thd,str_arg); } + bool send(THD *thd, String *str_arg) + { + return result_field->send(thd,str_arg); + } void make_field(Send_field *field); bool fix_fields(THD *,struct st_table_list *); bool save_in_field(Field *field); diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index d2eb16ce5de..fd6e767d620 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -549,7 +549,7 @@ Item_func_nullif::fix_length_and_dec() } /* - nullif() returns NULL if arguments are different, else it returns the + nullif () returns NULL if arguments are different, else it returns the first argument. Note that we have to evaluate the first argument twice as the compare may have been done with a different type than return value @@ -1296,7 +1296,7 @@ bool Item_func_like::fix_fields(THD *thd,struct st_table_list *tlist) *last == wild_many) { const char* tmp = first + 1; - for ( ; *tmp != wild_many && *tmp != wild_one && *tmp != escape; tmp++) ; + for (; *tmp != wild_many && *tmp != wild_one && *tmp != escape; tmp++) ; canDoTurboBM = tmp == last; } diff --git a/sql/item_func.cc b/sql/item_func.cc index 4a8c301e894..accc5219a71 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1502,10 +1502,11 @@ void debug_sync_point(const char* lock_name, uint lock_timeout) thd->ull=0; } - /* if the lock has not been aquired by some client, we do not want to - create an entry for it, since we immediately release the lock. In - this case, we will not be waiting, but rather, just waste CPU and - memory on the whole deal + /* + If the lock has not been aquired by some client, we do not want to + create an entry for it, since we immediately release the lock. In + this case, we will not be waiting, but rather, just waste CPU and + memory on the whole deal */ if (!(ull= ((ULL*) hash_search(&hash_user_locks,lock_name, lock_name_len)))) @@ -1515,8 +1516,10 @@ void debug_sync_point(const char* lock_name, uint lock_timeout) } ull->count++; - /* structure is now initialized. Try to get the lock */ - /* Set up control struct to allow others to abort locks */ + /* + Structure is now initialized. Try to get the lock. + Set up control struct to allow others to abort locks + */ thd->proc_info="User lock"; thd->mysys_var->current_mutex= &LOCK_user_locks; thd->mysys_var->current_cond= &ull->cond; @@ -1603,8 +1606,10 @@ longlong Item_func_get_lock::val_int() } ull->count++; - /* structure is now initialized. Try to get the lock */ - /* Set up control struct to allow others to abort locks */ + /* + Structure is now initialized. Try to get the lock. + Set up control struct to allow others to abort locks. + */ thd->proc_info="User lock"; thd->mysys_var->current_mutex= &LOCK_user_locks; thd->mysys_var->current_cond= &ull->cond; @@ -1645,10 +1650,11 @@ longlong Item_func_get_lock::val_int() /* -** Release a user level lock. -** Returns 1 if lock released -** 0 if lock wasn't held -** NULL if no such lock + Release a user level lock. + Return: + 1 if lock released + 0 if lock wasn't held + (SQL) NULL if no such lock */ longlong Item_func_release_lock::val_int() @@ -1717,6 +1723,7 @@ longlong Item_func_benchmark::val_int() return 0; } + #define extra_size sizeof(double) static user_var_entry *get_variable(HASH *hash, LEX_STRING &name, @@ -1980,6 +1987,7 @@ void Item_func_get_user_var::print(String *str) str->append(')'); } + bool Item_func_get_user_var::eq(const Item *item, bool binary_cmp) const { /* Assume we don't have rtti */ @@ -2087,10 +2095,11 @@ bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist) maybe_null=1; join_key=0; - /* const_item is assumed in quite a bit of places, so it would be difficult - to remove; If it would ever to be removed, this should include - modifications to find_best and auto_close as complement to auto_init code - above. + /* + const_item is assumed in quite a bit of places, so it would be difficult + to remove; If it would ever to be removed, this should include + modifications to find_best and auto_close as complement to auto_init code + above. */ if (Item_func::fix_fields(thd,tlist) || !const_item()) { @@ -2110,7 +2119,7 @@ bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist) } /* check that all columns come from the same table */ if (count_bits(used_tables_cache) != 1) - key=NO_SUCH_KEY; + key=NO_SUCH_KEY; const_item_cache=0; table=((Item_field *)fields.head())->field->table; table->fulltext_searched=1; @@ -2124,6 +2133,7 @@ bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist) return 0; } + bool Item_func_match::fix_index() { List_iterator_fast<Item> li(fields); @@ -2200,16 +2210,15 @@ err: return 0; } my_printf_error(ER_FT_MATCHING_KEY_NOT_FOUND, - ER(ER_FT_MATCHING_KEY_NOT_FOUND),MYF(0)); + ER(ER_FT_MATCHING_KEY_NOT_FOUND),MYF(0)); return 1; } + bool Item_func_match::eq(const Item *item, bool binary_cmp) const { - if (item->type() != FUNC_ITEM) - return 0; - - if (func_name() != ((Item_func*)item)->func_name()) + if (item->type() != FUNC_ITEM || + func_name() != ((Item_func*)item)->func_name()) return 0; Item_func_match *ifm=(Item_func_match*) item; @@ -2221,6 +2230,7 @@ bool Item_func_match::eq(const Item *item, bool binary_cmp) const return 0; } + double Item_func_match::val() { if (ft_handler == NULL) @@ -2230,14 +2240,13 @@ double Item_func_match::val() { if (table->file->ft_handler) return ft_handler->please->get_relevance(ft_handler); - join_key=0; } if (key == NO_SUCH_KEY) { - String *a=concat->val_str(&value); - if ((null_value= (a==0))) + String *a= concat->val_str(&value); + if ((null_value= (a == 0))) return 0; return ft_handler->please->find_relevance(ft_handler, (byte *)a->ptr(), a->length()); @@ -2246,6 +2255,7 @@ double Item_func_match::val() return ft_handler->please->find_relevance(ft_handler, record, 0); } + /*************************************************************************** System variables This has to be recoded after we get more than 3 system variables diff --git a/sql/item_func.h b/sql/item_func.h index c3e437712ee..35f17d1686b 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -921,7 +921,8 @@ public: Item_func_match(List<Item> &a, Item *b): Item_real_func(b), fields(a), table(0), master(0), ft_handler(0), - concat(0), key(0), join_key(0) {} + concat(0), key(0), join_key(0) + {} ~Item_func_match() { if (!master && ft_handler) @@ -932,7 +933,8 @@ public: table->file->ft_handler=0; table->fulltext_searched=0; } - if (concat) delete concat; + if (concat) + delete concat; } enum Functype functype() const { return FT_FUNC; } void update_used_tables() {} @@ -945,19 +947,23 @@ public: void init_search(bool no_order); }; + class Item_func_match_nl :public Item_func_match { public: - Item_func_match_nl(List<Item> &a, Item *b): - Item_func_match(a,b) { mode=FT_NL; } + Item_func_match_nl(List<Item> &a, Item *b) + :Item_func_match(a,b) + { mode=FT_NL; } const char *func_name() const { return "match_nl"; } }; + class Item_func_match_bool :public Item_func_match { public: - Item_func_match_bool(List<Item> &a, Item *b): - Item_func_match(a,b) { mode=FT_BOOL; } + Item_func_match_bool(List<Item> &a, Item *b) + :Item_func_match(a,b) + { mode=FT_BOOL; } const char *func_name() const { return "match_bool"; } }; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 9c6681cdcbf..22f962b4947 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -42,7 +42,7 @@ uint nr_of_decimals(const char *str) if ((str=strchr(str,'.'))) { const char *start= ++str; - for ( ; isdigit(*str) ; str++) ; + for (; isdigit(*str) ; str++) ; return (uint) (str-start); } return 0; @@ -208,8 +208,7 @@ void Item_func_concat::fix_length_and_dec() /* Function des_encrypt() by tonu@spam.ee & monty Works only if compiled with OpenSSL library support. - This returns a binary string where first character is - CHAR(128 | key-number). + This returns a binary string where first character is CHAR(128 | key-number). If one uses a string key key_number is 127. Encryption result is longer than original by formula: new_length= org_length + (8-(org_length % 8))+1 @@ -1903,7 +1902,7 @@ String* Item_func_export_set::val_str(String* str) str->append(*yes); else str->append(*no); - if(i != num_set_values - 1) + if (i != num_set_values - 1) str->append(*sep); } return str; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index e8f16e3ed56..7671b14f0a6 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -1102,7 +1102,7 @@ bool Item_sum_count_distinct::add() */ if (tree.elements_in_tree > max_elements_in_tree) { - if(tree_to_myisam()) + if (tree_to_myisam()) return 1; } else if (!tree_insert(&tree, table->record[0] + rec_offset, 0)) diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 9a003b79609..1e222fddcfc 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -683,7 +683,7 @@ String *Item_func_date_format::val_str(String *str) /* Create the result string */ const char *ptr=format->ptr(); const char *end=ptr+format->length(); - for ( ; ptr != end ; ptr++) + for (; ptr != end ; ptr++) { if (*ptr != '%' || ptr+1 == end) str->append(*ptr); @@ -691,7 +691,7 @@ String *Item_func_date_format::val_str(String *str) { switch (*++ptr) { case 'M': - if(!l_time.month) + if (!l_time.month) { null_value=1; return 0; @@ -699,7 +699,7 @@ String *Item_func_date_format::val_str(String *str) str->append(month_names[l_time.month-1]); break; case 'b': - if(!l_time.month) + if (!l_time.month) { null_value=1; return 0; @@ -707,7 +707,7 @@ String *Item_func_date_format::val_str(String *str) str->append(month_names[l_time.month-1].ptr(),3); break; case 'W': - if(date_or_time) + if (date_or_time) { null_value=1; return 0; @@ -716,7 +716,7 @@ String *Item_func_date_format::val_str(String *str) str->append(day_names[weekday]); break; case 'a': - if(date_or_time) + if (date_or_time) { null_value=1; return 0; @@ -725,7 +725,7 @@ String *Item_func_date_format::val_str(String *str) str->append(day_names[weekday].ptr(),3); break; case 'D': - if(date_or_time) + if (date_or_time) { null_value=1; return 0; @@ -791,7 +791,7 @@ String *Item_func_date_format::val_str(String *str) str->append(intbuff); break; case 'j': - if(date_or_time) + if (date_or_time) { null_value=1; return 0; diff --git a/sql/lock.cc b/sql/lock.cc index db849757741..93c826f2528 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -135,7 +135,7 @@ static int lock_external(TABLE **tables,uint count) if ((error=(*tables)->file->external_lock(thd,lock_type))) { - for ( ; i-- ; tables--) + for (; i-- ; tables--) { (*tables)->file->external_lock(thd, F_UNLCK); (*tables)->current_lock=F_UNLCK; @@ -473,7 +473,7 @@ void unlock_table_name(THD *thd, TABLE_LIST *table_list) static bool locked_named_table(THD *thd, TABLE_LIST *table_list) { - for ( ; table_list ; table_list=table_list->next) + for (; table_list ; table_list=table_list->next) { if (table_list->table && table_is_used(table_list->table,0)) return 1; diff --git a/sql/log.cc b/sql/log.cc index 0f8c4a8c4a8..793dfaf6d82 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -384,6 +384,7 @@ int MYSQL_LOG::reset_logs(THD* thd) int error=0; const char* save_name; enum_log_type save_log_type; + pthread_mutex_lock(&LOCK_log); if (find_first_log(&linfo,"")) { @@ -406,6 +407,7 @@ int MYSQL_LOG::reset_logs(THD* thd) need_start_event=1; open(save_name,save_log_type,0,io_cache_type,no_auto_events); my_free((gptr)save_name,MYF(0)); + err: pthread_mutex_unlock(&LOCK_log); return error; @@ -414,17 +416,19 @@ err: int MYSQL_LOG::purge_first_log(struct st_relay_log_info* rli) { - // pre-conditions - DBUG_ASSERT(is_open()); - DBUG_ASSERT(index_file >= 0); - DBUG_ASSERT(rli->slave_running == 1); - DBUG_ASSERT(!strcmp(rli->linfo.log_file_name,rli->relay_log_name)); /* + Test pre-conditions. + Assume that we have previously read the first log and stored it in rli->relay_log_name */ + DBUG_ASSERT(is_open()); + DBUG_ASSERT(index_file >= 0); + DBUG_ASSERT(rli->slave_running == 1); + DBUG_ASSERT(!strcmp(rli->linfo.log_file_name,rli->relay_log_name)); DBUG_ASSERT(rli->linfo.index_file_offset == strlen(rli->relay_log_name) + 1); + int tmp_fd; char* fname, *io_buf; int error = 0; @@ -486,9 +490,11 @@ err: pthread_mutex_lock(&rli->log_space_lock); rli->log_space_total -= s.st_size; pthread_mutex_unlock(&rli->log_space_lock); - // ok to broadcast after the critical region as there is no risk of - // the mutex being destroyed by this thread later - this helps save - // context switches + /* + Ok to broadcast after the critical region as there is no risk of + the mutex being destroyed by this thread later - this helps save + context switches + */ pthread_cond_broadcast(&rli->log_space_cond); if ((error=find_first_log(&rli->linfo,"",0/*no mutex*/))) @@ -500,8 +506,8 @@ err: goto err2; } rli->relay_log_pos = BIN_LOG_HEADER_SIZE; - strnmov(rli->relay_log_name,rli->linfo.log_file_name, - sizeof(rli->relay_log_name)); + strmake(rli->relay_log_name,rli->linfo.log_file_name, + sizeof(rli->relay_log_name)-1); flush_relay_log_info(rli); } /* @@ -689,7 +695,7 @@ void MYSQL_LOG::new_file(bool inside_mutex) if (!no_rotate) { /* - only rotate open logs that are marked non-rotatable + Only rotate open logs that are marked non-rotatable (binlog with constant name are non-rotatable) */ if (generate_new_name(new_name, name)) @@ -720,9 +726,11 @@ void MYSQL_LOG::new_file(bool inside_mutex) r.write(&log_file); bytes_written += r.get_event_len(); } - // update needs to be signaled even if there is no rotate event - // log rotation should give the waiting thread a signal to - // discover EOF and move on to the next log + /* + Update needs to be signaled even if there is no rotate event + log rotation should give the waiting thread a signal to + discover EOF and move on to the next log. + */ signal_update(); } else @@ -745,8 +753,10 @@ bool MYSQL_LOG::append(Log_event* ev) pthread_mutex_lock(&LOCK_log); DBUG_ASSERT(log_file.type == SEQ_READ_APPEND); - // Log_event::write() is smart enough to use my_b_write() or - // my_b_append() depending on the kind of cache we have + /* + Log_event::write() is smart enough to use my_b_write() or + my_b_append() depending on the kind of cache we have. + */ if (ev->write(&log_file)) { error=1; @@ -758,11 +768,13 @@ bool MYSQL_LOG::append(Log_event* ev) new_file(1); } signal_update(); + err: pthread_mutex_unlock(&LOCK_log); return error; } + bool MYSQL_LOG::appendv(const char* buf, uint len,...) { bool error = 0; @@ -1232,8 +1244,12 @@ void MYSQL_LOG::close(bool exiting) } - /* Check if a string is a valid number */ - /* Output: TRUE -> number */ +/* + Check if a string is a valid number + Return: + TRUE String is a number + FALSE Error +*/ static bool test_if_number(register const char *str, long *res, bool allow_wildcards) diff --git a/sql/log_event.cc b/sql/log_event.cc index 0d66185c8dd..5ff2362e9db 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -31,9 +31,9 @@ inline int my_b_safe_write(IO_CACHE* file, const byte *buf, { /* Sasha: We are not writing this with the ? operator to avoid hitting - a possible compiler bug. At least gcc 2.95 cannot deal with - several layers of ternary operators that evaluated comma(,) operator - expressions inside - I do have a test case if somebody wants it + a possible compiler bug. At least gcc 2.95 cannot deal with + several layers of ternary operators that evaluated comma(,) operator + expressions inside - I do have a test case if somebody wants it */ if (file->type == SEQ_READ_APPEND) return my_b_append(file, buf,len); @@ -80,7 +80,7 @@ static void pretty_print_str(String* packet, char* str, int len) while (str < end) { char c; - switch((c=*str++)) { + switch ((c=*str++)) { case '\n': packet->append( "\\n"); break; case '\r': packet->append( "\\r"); break; case '\\': packet->append( "\\\\"); break; @@ -113,8 +113,7 @@ static inline char* slave_load_file_stem(char*buf, uint file_id, const char* Log_event::get_type_str() { - switch(get_type_code()) - { + switch(get_type_code()) { case START_EVENT: return "Start"; case STOP_EVENT: return "Stop"; case QUERY_EVENT: return "Query"; @@ -132,10 +131,9 @@ const char* Log_event::get_type_str() } #ifndef MYSQL_CLIENT -Log_event::Log_event(THD* thd_arg, uint16 flags_arg): - exec_time(0), - flags(flags_arg),cached_event_len(0), - temp_buf(0),thd(thd_arg) +Log_event::Log_event(THD* thd_arg, uint16 flags_arg) + :exec_time(0), flags(flags_arg), cached_event_len(0), + temp_buf(0), thd(thd_arg) { if (thd) { @@ -151,6 +149,7 @@ Log_event::Log_event(THD* thd_arg, uint16 flags_arg): } } + static void cleanup_load_tmpdir() { MY_DIR *dirp; @@ -163,7 +162,7 @@ static void cleanup_load_tmpdir() { file=dirp->dir_entry+i; if (is_prefix(file->name,"SQL_LOAD-")) - my_delete(file->name,MYF(0)); + my_delete(file->name, MYF(0)); } my_dirend(dirp); @@ -171,8 +170,8 @@ static void cleanup_load_tmpdir() #endif -Log_event::Log_event(const char* buf, bool old_format): - cached_event_len(0),temp_buf(0) +Log_event::Log_event(const char* buf, bool old_format) + :cached_event_len(0), temp_buf(0) { when = uint4korr(buf); server_id = uint4korr(buf + SERVER_ID_OFFSET); @@ -303,7 +302,7 @@ void Load_log_event::pack_info(String* packet) uint i; const char* field = fields; tmp.append(" ("); - for(i = 0; i < num_fields; i++) + for (i = 0; i < num_fields; i++) { if (i) tmp.append(" ,"); @@ -319,10 +318,9 @@ void Load_log_event::pack_info(String* packet) void Rotate_log_event::pack_info(String* packet) { - char buf1[256]; + char buf1[256], buf[22]; String tmp(buf1, sizeof(buf1)); tmp.length(0); - char buf[22]; tmp.append(new_log_ident, ident_len); tmp.append(";pos="); tmp.append(llstr(pos,buf)); @@ -333,10 +331,9 @@ void Rotate_log_event::pack_info(String* packet) void Intvar_log_event::pack_info(String* packet) { - char buf1[256]; + char buf1[256], buf[22]; String tmp(buf1, sizeof(buf1)); tmp.length(0); - char buf[22]; tmp.append(get_var_type_name()); tmp.append('='); tmp.append(llstr(val, buf)); @@ -345,14 +342,14 @@ void Intvar_log_event::pack_info(String* packet) void Slave_log_event::pack_info(String* packet) { - char buf1[256]; + char buf1[256], buf[22], *end; String tmp(buf1, sizeof(buf1)); tmp.length(0); - char buf[22]; tmp.append("host="); tmp.append(master_host); tmp.append(",port="); - tmp.append(llstr(master_port,buf)); + end= int10_to_str((long) master_port, buf, 10); + tmp.append(buf, (uint32) (end-buf)); tmp.append(",log="); tmp.append(master_log); tmp.append(",pos="); @@ -390,18 +387,21 @@ int Log_event::net_send(THD* thd, const char* log_name, my_off_t pos) return my_net_write(&thd->net, (char*) packet->ptr(), packet->length()); } -#endif +#endif /* MYSQL_CLIENT */ + int Query_log_event::write(IO_CACHE* file) { return query ? Log_event::write(file) : -1; } + int Log_event::write(IO_CACHE* file) { return (write_header(file) || write_data(file)) ? -1 : 0; } + int Log_event::write_header(IO_CACHE* file) { char buf[LOG_EVENT_HEADER_LEN]; @@ -427,54 +427,61 @@ int Log_event::read_log_event(IO_CACHE* file, String* packet, pthread_mutex_t* log_lock) { ulong data_len; + int result=0; char buf[LOG_EVENT_HEADER_LEN]; + if (log_lock) pthread_mutex_lock(log_lock); if (my_b_read(file, (byte*) buf, sizeof(buf))) { - if (log_lock) pthread_mutex_unlock(log_lock); - // if the read hits eof, we must report it as eof - // so the caller will know it can go into cond_wait to be woken up - // on the next update to the log - if (!file->error) return LOG_READ_EOF; - return file->error > 0 ? LOG_READ_TRUNC: LOG_READ_IO; + /* + If the read hits eof, we must report it as eof so the caller + will know it can go into cond_wait to be woken up on the next + update to the log. + */ + if (!file->error) + result= LOG_READ_EOF; + else + result= (file->error > 0 ? LOG_READ_TRUNC: LOG_READ_IO); + goto end; } - data_len = uint4korr(buf + EVENT_LEN_OFFSET); + data_len= uint4korr(buf + EVENT_LEN_OFFSET); if (data_len < LOG_EVENT_HEADER_LEN || data_len > max_allowed_packet) { - if (log_lock) pthread_mutex_unlock(log_lock); - return (data_len < LOG_EVENT_HEADER_LEN) ? LOG_READ_BOGUS : - LOG_READ_TOO_LARGE; + + result= ((data_len < LOG_EVENT_HEADER_LEN) ? LOG_READ_BOGUS : + LOG_READ_TOO_LARGE); + goto end; } packet->append(buf, sizeof(buf)); - data_len -= LOG_EVENT_HEADER_LEN; + data_len-= LOG_EVENT_HEADER_LEN; if (data_len) { if (packet->append(file, data_len)) { - if (log_lock) - pthread_mutex_unlock(log_lock); - // here we should never hit eof in a non-error condtion - // eof means we are reading the event partially, which should - // never happen - return file->error >= 0 ? LOG_READ_TRUNC: LOG_READ_IO; + /* + Here we should never hit eof in a non-error condtion + eof means we are reading the event partially, which should + never happen. + */ + result= file->error >= 0 ? LOG_READ_TRUNC: LOG_READ_IO; + /* Implicit goto end; */ } } - if (log_lock) pthread_mutex_unlock(log_lock); - return 0; + +end: + if (log_lock) + pthread_mutex_unlock(log_lock); + return result; } #endif // MYSQL_CLIENT #ifndef MYSQL_CLIENT #define UNLOCK_MUTEX if (log_lock) pthread_mutex_unlock(log_lock); -#else -#define UNLOCK_MUTEX -#endif - -#ifndef MYSQL_CLIENT #define LOCK_MUTEX if (log_lock) pthread_mutex_lock(log_lock); #else +#define UNLOCK_MUTEX #define LOCK_MUTEX #endif @@ -488,19 +495,19 @@ Log_event* Log_event::read_log_event(IO_CACHE* file, bool old_format) #endif { char head[LOG_EVENT_HEADER_LEN]; - uint header_size = old_format ? OLD_HEADER_LEN : - LOG_EVENT_HEADER_LEN; + uint header_size= old_format ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN; + LOCK_MUTEX; - if (my_b_read(file, (byte *) head, header_size )) + if (my_b_read(file, (byte *) head, header_size)) { UNLOCK_MUTEX; return 0; } uint data_len = uint4korr(head + EVENT_LEN_OFFSET); - char* buf = 0; - const char* error = 0; - Log_event* res = 0; + char *buf= 0; + const char *error= 0; + Log_event *res= 0; if (data_len > max_allowed_packet) { @@ -522,14 +529,14 @@ Log_event* Log_event::read_log_event(IO_CACHE* file, bool old_format) } buf[data_len] = 0; memcpy(buf, head, header_size); - if (my_b_read(file, (byte*) buf + header_size, - data_len - header_size)) + if (my_b_read(file, (byte*) buf + header_size, data_len - header_size)) { error = "read error"; goto err; } if ((res = read_log_event(buf, data_len, &error, old_format))) res->register_temp_buf(buf); + err: UNLOCK_MUTEX; if (error) @@ -541,17 +548,20 @@ data_len=%d,event_type=%d",error,data_len,head[EVENT_TYPE_OFFSET]); return res; } + Log_event* Log_event::read_log_event(const char* buf, int event_len, const char **error, bool old_format) { if (event_len < EVENT_LEN_OFFSET || - (uint)event_len != uint4korr(buf+EVENT_LEN_OFFSET)) + (uint) event_len != uint4korr(buf+EVENT_LEN_OFFSET)) + { + *error="Sanity check failed"; // Needed to free buffer return NULL; // general sanity check - will fail on a partial read + } Log_event* ev = NULL; - switch(buf[EVENT_TYPE_OFFSET]) - { + switch(buf[EVENT_TYPE_OFFSET]) { case QUERY_EVENT: ev = new Query_log_event(buf, event_len, old_format); break; @@ -591,8 +601,7 @@ Log_event* Log_event::read_log_event(const char* buf, int event_len, default: break; } - if (!ev) return 0; - if (!ev->is_valid()) + if (!ev || !ev->is_valid()) { *error= "Found invalid event in binary log"; delete ev; @@ -602,27 +611,24 @@ Log_event* Log_event::read_log_event(const char* buf, int event_len, return ev; } + #ifdef MYSQL_CLIENT void Log_event::print_header(FILE* file) { char llbuff[22]; fputc('#', file); print_timestamp(file); - fprintf(file, " server id %d log_pos %s ", server_id, + fprintf(file, " server id %d log_pos %s ", server_id, llstr(log_pos,llbuff)); } void Log_event::print_timestamp(FILE* file, time_t* ts) { -#ifdef MYSQL_SERVER - struct tm tm_tmp; -#endif struct tm *res; if (!ts) - { ts = &when; - } -#ifdef MYSQL_SERVER +#ifdef MYSQL_SERVER // This is always false + struct tm tm_tmp; localtime_r(ts,(res= &tm_tmp)); #else res=localtime(ts); @@ -678,8 +684,10 @@ void Rotate_log_event::print(FILE* file, bool short_form, char* last_db) #endif /* #ifdef MYSQL_CLIENT */ + Start_log_event::Start_log_event(const char* buf, - bool old_format) :Log_event(buf, old_format) + bool old_format) + :Log_event(buf, old_format) { buf += (old_format) ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN; binlog_version = uint2korr(buf+ST_BINLOG_VER_OFFSET); @@ -697,9 +705,10 @@ int Start_log_event::write_data(IO_CACHE* file) return (my_b_safe_write(file, (byte*) buff, sizeof(buff)) ? -1 : 0); } + Rotate_log_event::Rotate_log_event(const char* buf, int event_len, - bool old_format): - Log_event(buf, old_format),new_log_ident(NULL),alloced(0) + bool old_format) + :Log_event(buf, old_format),new_log_ident(NULL),alloced(0) { // The caller will ensure that event_len is what we have at EVENT_LEN_OFFSET int header_size = (old_format) ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN; @@ -726,29 +735,31 @@ Rotate_log_event::Rotate_log_event(const char* buf, int event_len, alloced = 1; } + int Rotate_log_event::write_data(IO_CACHE* file) { char buf[ROTATE_HEADER_LEN]; int8store(buf, pos + R_POS_OFFSET); - return my_b_safe_write(file, (byte*)buf, ROTATE_HEADER_LEN) || - my_b_safe_write(file, (byte*)new_log_ident, (uint) ident_len); + return (my_b_safe_write(file, (byte*)buf, ROTATE_HEADER_LEN) || + my_b_safe_write(file, (byte*)new_log_ident, (uint) ident_len)); } + #ifndef MYSQL_CLIENT Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, - bool using_trans): - Log_event(thd_arg), data_buf(0), query(query_arg), db(thd_arg->db), - q_len(thd_arg->query_length), - error_code(thd_arg->killed ? ER_SERVER_SHUTDOWN: thd_arg->net.last_errno), - thread_id(thd_arg->thread_id), - cache_stmt(using_trans && - (thd_arg->options & (OPTION_NOT_AUTO_COMMIT | OPTION_BEGIN))) - { - time_t end_time; - time(&end_time); - exec_time = (ulong) (end_time - thd->start_time); - db_len = (db) ? (uint32) strlen(db) : 0; - } + bool using_trans) + :Log_event(thd_arg), data_buf(0), query(query_arg), db(thd_arg->db), + q_len(thd_arg->query_length), + error_code(thd_arg->killed ? ER_SERVER_SHUTDOWN: thd_arg->net.last_errno), + thread_id(thd_arg->thread_id), + cache_stmt(using_trans && + (thd_arg->options & (OPTION_NOT_AUTO_COMMIT | OPTION_BEGIN))) +{ + time_t end_time; + time(&end_time); + exec_time = (ulong) (end_time - thd->start_time); + db_len = (db) ? (uint32) strlen(db) : 0; +} #endif Query_log_event::Query_log_event(const char* buf, int event_len, @@ -786,6 +797,7 @@ Query_log_event::Query_log_event(const char* buf, int event_len, *((char*)query+q_len) = 0; } + #ifdef MYSQL_CLIENT void Query_log_event::print(FILE* file, bool short_form, char* last_db) @@ -801,10 +813,10 @@ void Query_log_event::print(FILE* file, bool short_form, char* last_db) bool same_db = 0; if (db && last_db) - { - if (!(same_db = !memcmp(last_db, db, db_len + 1))) - memcpy(last_db, db, db_len + 1); - } + { + if (!(same_db = !memcmp(last_db, db, db_len + 1))) + memcpy(last_db, db, db_len + 1); + } if (db && db[0] && !same_db) fprintf(file, "use %s;\n", db); @@ -815,17 +827,18 @@ void Query_log_event::print(FILE* file, bool short_form, char* last_db) my_fwrite(file, (byte*) query, q_len, MYF(MY_NABP | MY_WME)); fprintf(file, ";\n"); } - #endif + int Query_log_event::write_data(IO_CACHE* file) { - if (!query) return -1; + if (!query) + return -1; char buf[QUERY_HEADER_LEN]; int4store(buf + Q_THREAD_ID_OFFSET, thread_id); int4store(buf + Q_EXEC_TIME_OFFSET, exec_time); - buf[Q_DB_LEN_OFFSET] = (char)db_len; + buf[Q_DB_LEN_OFFSET] = (char) db_len; int2store(buf + Q_ERR_CODE_OFFSET, error_code); return (my_b_safe_write(file, (byte*) buf, QUERY_HEADER_LEN) || @@ -833,8 +846,8 @@ int Query_log_event::write_data(IO_CACHE* file) my_b_safe_write(file, (byte*) query, q_len)) ? -1 : 0; } -Intvar_log_event::Intvar_log_event(const char* buf, bool old_format): - Log_event(buf, old_format) +Intvar_log_event::Intvar_log_event(const char* buf, bool old_format) + :Log_event(buf, old_format) { buf += (old_format) ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN; type = buf[I_TYPE_OFFSET]; @@ -843,8 +856,7 @@ Intvar_log_event::Intvar_log_event(const char* buf, bool old_format): const char* Intvar_log_event::get_var_type_name() { - switch(type) - { + switch(type) { case LAST_INSERT_ID_EVENT: return "LAST_INSERT_ID"; case INSERT_ID_EVENT: return "INSERT_ID"; default: /* impossible */ return "UNKNOWN"; @@ -863,6 +875,9 @@ int Intvar_log_event::write_data(IO_CACHE* file) void Intvar_log_event::print(FILE* file, bool short_form, char* last_db) { char llbuff[22]; + const char *msg; + LINT_INIT(msg); + if (!short_form) { print_header(file); @@ -870,21 +885,20 @@ void Intvar_log_event::print(FILE* file, bool short_form, char* last_db) } fprintf(file, "SET "); - switch(type) - { + switch (type) { case LAST_INSERT_ID_EVENT: - fprintf(file, "LAST_INSERT_ID = "); + msg="LAST_INSERT_ID"; break; case INSERT_ID_EVENT: - fprintf(file, "INSERT_ID = "); + msg="INSERT_ID"; break; } - fprintf(file, "%s;\n", llstr(val,llbuff)); + fprintf(file, "%s=%s;\n", msg, llstr(val,llbuff)); fflush(file); - } #endif + int Load_log_event::write_data_header(IO_CACHE* file) { char buf[LOAD_HEADER_LEN]; @@ -899,7 +913,8 @@ int Load_log_event::write_data_header(IO_CACHE* file) int Load_log_event::write_data_body(IO_CACHE* file) { - if (sql_ex.write_data(file)) return 1; + if (sql_ex.write_data(file)) + return 1; if (num_fields && fields && field_lens) { if (my_b_safe_write(file, (byte*)field_lens, num_fields) || @@ -912,12 +927,14 @@ int Load_log_event::write_data_body(IO_CACHE* file) } + static bool write_str(IO_CACHE *file, char *str, byte length) { return (my_b_safe_write(file, &length, 1) || my_b_safe_write(file, (byte*) str, (int) length)); } + int sql_ex_info::write_data(IO_CACHE* file) { if (new_format()) @@ -943,6 +960,7 @@ int sql_ex_info::write_data(IO_CACHE* file) } } + static inline int read_str(char * &buf, char *buf_end, char * &str, uint8 &len) { @@ -954,6 +972,7 @@ static inline int read_str(char * &buf, char *buf_end, char * &str, return 0; } + char* sql_ex_info::init(char* buf,char* buf_end,bool use_new_format) { cached_new_format = use_new_format; @@ -978,13 +997,13 @@ char* sql_ex_info::init(char* buf,char* buf_end,bool use_new_format) else { field_term_len= enclosed_len= line_term_len= line_start_len= escaped_len=1; - field_term = buf++; - enclosed= buf++; - line_term= buf++; - line_start= buf++; - escaped= buf++; - opt_flags = *buf++; - empty_flags=*buf++; + field_term = buf++; // Use first byte in string + enclosed= buf++; + line_term= buf++; + line_start= buf++; + escaped= buf++; + opt_flags = *buf++; + empty_flags= *buf++; if (empty_flags & FIELD_TERM_EMPTY) field_term_len=0; if (empty_flags & ENCLOSED_EMPTY) @@ -1006,7 +1025,7 @@ Load_log_event::Load_log_event(THD* thd, sql_exchange* ex, List<Item>& fields_arg, enum enum_duplicates handle_dup) :Log_event(thd),thread_id(thd->thread_id), num_fields(0),fields(0), field_lens(0),field_block_len(0), table_name(table_name_arg), - db(db_arg), fname(ex->file_name) + db(db_arg), fname(ex->file_name) { time_t end_time; time(&end_time); @@ -1034,14 +1053,12 @@ Load_log_event::Load_log_event(THD* thd, sql_exchange* ex, sql_ex.empty_flags = 0; - switch(handle_dup) - { + switch (handle_dup) { case DUP_IGNORE: sql_ex.opt_flags |= IGNORE_FLAG; break; case DUP_REPLACE: sql_ex.opt_flags |= REPLACE_FLAG; break; case DUP_ERROR: break; } - if (!ex->field_term->length()) sql_ex.empty_flags |= FIELD_TERM_EMPTY; if (!ex->enclosed->length()) @@ -1074,8 +1091,11 @@ Load_log_event::Load_log_event(THD* thd, sql_exchange* ex, #endif -// the caller must do buf[event_len] = 0 before he starts using the -// constructed event +/* + The caller must do buf[event_len] = 0 before he starts using the + constructed event. +*/ + Load_log_event::Load_log_event(const char* buf, int event_len, bool old_format): Log_event(buf, old_format),num_fields(0),fields(0), @@ -1093,7 +1113,7 @@ int Load_log_event::copy_log_event(const char *buf, ulong event_len, uint data_len; char* buf_end = (char*)buf + event_len; const char* data_head = buf + ((old_format) ? - OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN); + OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN); thread_id = uint4korr(data_head + L_THREAD_ID_OFFSET); exec_time = uint4korr(data_head + L_EXEC_TIME_OFFSET); skip_lines = uint4korr(data_head + L_SKIP_LINES_OFFSET); @@ -1101,13 +1121,16 @@ int Load_log_event::copy_log_event(const char *buf, ulong event_len, db_len = (uint)data_head[L_DB_LEN_OFFSET]; num_fields = uint4korr(data_head + L_NUM_FIELDS_OFFSET); - int body_offset = (buf[EVENT_TYPE_OFFSET] == LOAD_EVENT) ? - LOAD_HEADER_LEN + OLD_HEADER_LEN : get_data_body_offset(); + int body_offset = ((buf[EVENT_TYPE_OFFSET] == LOAD_EVENT) ? + LOAD_HEADER_LEN + OLD_HEADER_LEN : + get_data_body_offset()); if ((int) event_len < body_offset) return 1; - //sql_ex.init() on success returns the pointer to the first byte after - //the sql_ex structure, which is the start of field lengths array + /* + Sql_ex.init() on success returns the pointer to the first byte after + the sql_ex structure, which is the start of field lengths array. + */ if (!(field_lens=(uchar*)sql_ex.init((char*)buf + body_offset, buf_end, buf[EVENT_TYPE_OFFSET] != LOAD_EVENT))) @@ -1116,11 +1139,9 @@ int Load_log_event::copy_log_event(const char *buf, ulong event_len, data_len = event_len - body_offset; if (num_fields > data_len) // simple sanity check against corruption return 1; - uint i; - for (i = 0; i < num_fields; i++) - { + for (uint i = 0; i < num_fields; i++) field_block_len += (uint)field_lens[i] + 1; - } + fields = (char*)field_lens + num_fields; table_name = fields + field_block_len; db = table_name + table_name_len + 1; @@ -1142,7 +1163,6 @@ void Load_log_event::print(FILE* file, bool short_form, char* last_db) } bool same_db = 0; - if (db && last_db) { if (!(same_db = !memcmp(last_db, db, db_len + 1))) @@ -1199,8 +1219,8 @@ void Load_log_event::print(FILE* file, bool short_form, char* last_db) { uint i; const char* field = fields; - fprintf( file, " ("); - for(i = 0; i < num_fields; i++) + fprintf(file, " ("); + for (i = 0; i < num_fields; i++) { if (i) fputc(',', file); @@ -1219,10 +1239,11 @@ void Load_log_event::print(FILE* file, bool short_form, char* last_db) #ifndef MYSQL_CLIENT void Log_event::set_log_pos(MYSQL_LOG* log) - { - if (!log_pos) - log_pos = my_b_tell(&log->log_file); - } +{ + if (!log_pos) + log_pos = my_b_tell(&log->log_file); +} + void Load_log_event::set_fields(List<Item> &fields) { @@ -1270,8 +1291,7 @@ Slave_log_event::Slave_log_event(THD* thd_arg, DBUG_VOID_RETURN; } - -#endif +#endif /* ! MYSQL_CLIENT */ Slave_log_event::~Slave_log_event() @@ -1293,7 +1313,7 @@ master_log: '%s' master_pos: %s\n", master_host, master_port, master_log, llstr(master_pos, llbuff)); } -#endif +#endif /* MYSQL_CLIENT */ int Slave_log_event::get_data_size() { @@ -1308,6 +1328,7 @@ int Slave_log_event::write_data(IO_CACHE* file) return my_b_safe_write(file, (byte*)mem_pool, get_data_size()); } + void Slave_log_event::init_from_mem_pool(int data_size) { master_pos = uint8korr(mem_pool + SL_MASTER_POS_OFFSET); @@ -1324,13 +1345,13 @@ void Slave_log_event::init_from_mem_pool(int data_size) master_log_len = strlen(master_log); } -Slave_log_event::Slave_log_event(const char* buf, int event_len): - Log_event(buf,0),mem_pool(0),master_host(0) +Slave_log_event::Slave_log_event(const char* buf, int event_len) + :Log_event(buf,0),mem_pool(0),master_host(0) { event_len -= LOG_EVENT_HEADER_LEN; if (event_len < 0) return; - if (!(mem_pool = (char*)my_malloc(event_len + 1, MYF(MY_WME)))) + if (!(mem_pool = (char*) my_malloc(event_len + 1, MYF(MY_WME)))) return; memcpy(mem_pool, buf + LOG_EVENT_HEADER_LEN, event_len); mem_pool[event_len] = 0; @@ -1341,10 +1362,10 @@ Slave_log_event::Slave_log_event(const char* buf, int event_len): Create_file_log_event::Create_file_log_event(THD* thd_arg, sql_exchange* ex, const char* db_arg, const char* table_name_arg, List<Item>& fields_arg, enum enum_duplicates handle_dup, - char* block_arg, uint block_len_arg): - Load_log_event(thd_arg,ex,db_arg,table_name_arg,fields_arg,handle_dup), - fake_base(0),block(block_arg),block_len(block_len_arg), - file_id(thd_arg->file_id = mysql_bin_log.next_file_id()) + char* block_arg, uint block_len_arg) + :Load_log_event(thd_arg,ex,db_arg,table_name_arg,fields_arg,handle_dup), + fake_base(0),block(block_arg),block_len(block_len_arg), + file_id(thd_arg->file_id = mysql_bin_log.next_file_id()) { sql_ex.force_new_format(); } @@ -1379,8 +1400,8 @@ int Create_file_log_event::write_base(IO_CACHE* file) } Create_file_log_event::Create_file_log_event(const char* buf, int len, - bool old_format): - Load_log_event(buf,0,old_format),fake_base(0),block(0),inited_from_old(0) + bool old_format) + :Load_log_event(buf,0,old_format),fake_base(0),block(0),inited_from_old(0) { int block_offset; if (copy_log_event(buf,len,old_format)) @@ -1389,8 +1410,9 @@ Create_file_log_event::Create_file_log_event(const char* buf, int len, { file_id = uint4korr(buf + LOG_EVENT_HEADER_LEN + + LOAD_HEADER_LEN + CF_FILE_ID_OFFSET); - block_offset = LOG_EVENT_HEADER_LEN + Load_log_event::get_data_size() + - CREATE_FILE_HEADER_LEN + 1; // 1 for \0 terminating fname + // + 1 for \0 terminating fname + block_offset = (LOG_EVENT_HEADER_LEN + Load_log_event::get_data_size() + + CREATE_FILE_HEADER_LEN + 1); if (len < block_offset) return; block = (char*)buf + block_offset; @@ -1418,33 +1440,34 @@ void Create_file_log_event::print(FILE* file, bool short_form, #ifndef MYSQL_CLIENT void Create_file_log_event::pack_info(String* packet) { - char buf1[256]; + char buf1[256],buf[22], *end; String tmp(buf1, sizeof(buf1)); tmp.length(0); - char buf[22]; tmp.append("db="); tmp.append(db, db_len); tmp.append(";table="); tmp.append(table_name, table_name_len); tmp.append(";file_id="); - tmp.append(llstr(file_id,buf)); + end= int10_to_str((long) file_id, buf, 10); + tmp.append(buf, (uint32) (end-buf)); tmp.append(";block_len="); - tmp.append(llstr(block_len,buf)); - net_store_data(packet, (char*)tmp.ptr(), tmp.length()); + end= int10_to_str((long) block_len, buf, 10); + tmp.append(buf, (uint32) (end-buf)); + net_store_data(packet, (char*) tmp.ptr(), tmp.length()); } #endif #ifndef MYSQL_CLIENT Append_block_log_event::Append_block_log_event(THD* thd_arg, char* block_arg, - uint block_len_arg): - Log_event(thd_arg), block(block_arg),block_len(block_len_arg), - file_id(thd_arg->file_id) + uint block_len_arg) + :Log_event(thd_arg), block(block_arg),block_len(block_len_arg), + file_id(thd_arg->file_id) { } #endif -Append_block_log_event::Append_block_log_event(const char* buf, int len): - Log_event(buf, 0),block(0) +Append_block_log_event::Append_block_log_event(const char* buf, int len) + :Log_event(buf, 0),block(0) { if ((uint)len < APPEND_BLOCK_EVENT_OVERHEAD) return; @@ -1473,36 +1496,31 @@ void Append_block_log_event::print(FILE* file, bool short_form, file_id, block_len); } #endif + #ifndef MYSQL_CLIENT void Append_block_log_event::pack_info(String* packet) { char buf1[256]; - String tmp(buf1, sizeof(buf1)); - tmp.length(0); - char buf[22]; - tmp.append(";file_id="); - tmp.append(llstr(file_id,buf)); - tmp.append(";block_len="); - tmp.append(llstr(block_len,buf)); - net_store_data(packet, (char*)tmp.ptr(), tmp.length()); + sprintf(buf1, ";file_id=%u;block_len=%u", file_id, block_len); + net_store_data(packet, buf1); } -#endif -#ifndef MYSQL_CLIENT -Delete_file_log_event::Delete_file_log_event(THD* thd_arg): - Log_event(thd_arg),file_id(thd_arg->file_id) +Delete_file_log_event::Delete_file_log_event(THD* thd_arg) + :Log_event(thd_arg),file_id(thd_arg->file_id) { } #endif -Delete_file_log_event::Delete_file_log_event(const char* buf, int len): - Log_event(buf, 0),file_id(0) + +Delete_file_log_event::Delete_file_log_event(const char* buf, int len) + :Log_event(buf, 0),file_id(0) { if ((uint)len < DELETE_FILE_EVENT_OVERHEAD) return; file_id = uint4korr(buf + LOG_EVENT_HEADER_LEN + AB_FILE_ID_OFFSET); } + int Delete_file_log_event::write_data(IO_CACHE* file) { byte buf[DELETE_FILE_HEADER_LEN]; @@ -1518,32 +1536,29 @@ void Delete_file_log_event::print(FILE* file, bool short_form, return; print_header(file); fputc('\n', file); - fprintf(file, "#Delete_file: file_id=%d\n", - file_id); + fprintf(file, "#Delete_file: file_id=%u\n", file_id); } #endif + #ifndef MYSQL_CLIENT void Delete_file_log_event::pack_info(String* packet) { - char buf1[256]; - String tmp(buf1, sizeof(buf1)); - tmp.length(0); - char buf[22]; - tmp.append(";file_id="); - tmp.append(llstr(file_id,buf)); - net_store_data(packet, (char*)tmp.ptr(), tmp.length()); + char buf1[64]; + sprintf(buf1, ";file_id=%u", (uint) file_id); + net_store_data(packet, buf1); } #endif + #ifndef MYSQL_CLIENT -Execute_load_log_event::Execute_load_log_event(THD* thd_arg): - Log_event(thd_arg),file_id(thd_arg->file_id) +Execute_load_log_event::Execute_load_log_event(THD* thd_arg) + :Log_event(thd_arg),file_id(thd_arg->file_id) { } #endif -Execute_load_log_event::Execute_load_log_event(const char* buf,int len): - Log_event(buf, 0),file_id(0) +Execute_load_log_event::Execute_load_log_event(const char* buf,int len) + :Log_event(buf, 0),file_id(0) { if ((uint)len < EXEC_LOAD_EVENT_OVERHEAD) return; @@ -1572,13 +1587,9 @@ void Execute_load_log_event::print(FILE* file, bool short_form, #ifndef MYSQL_CLIENT void Execute_load_log_event::pack_info(String* packet) { - char buf1[256]; - String tmp(buf1, sizeof(buf1)); - tmp.length(0); - char buf[22]; - tmp.append(";file_id="); - tmp.append(llstr(file_id,buf)); - net_store_data(packet, (char*)tmp.ptr(), tmp.length()); + char buf[64]; + sprintf(buf, ";file_id=%u", (uint) file_id); + net_store_data(packet, buf); } #endif @@ -1600,16 +1611,18 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli) thd->query_error = 0; // clear error thd->net.last_errno = 0; thd->net.last_error[0] = 0; - thd->slave_proxy_id = thread_id; // for temp tables + thd->slave_proxy_id = thread_id; // for temp tables - // sanity check to make sure the master did not get a really bad - // error on the query + /* + Sanity check to make sure the master did not get a really bad + error on the query. + */ if (ignored_error_code((expected_error = error_code)) || !check_expected_error(thd,rli,expected_error)) { mysql_parse(thd, thd->query, q_len); - if (expected_error != - (actual_error = thd->net.last_errno) && expected_error && + if ((expected_error != (actual_error = thd->net.last_errno)) && + expected_error && !ignored_error_code(actual_error) && !ignored_error_code(expected_error)) { @@ -1621,8 +1634,8 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli) actual_error); thd->query_error = 1; } - else if (expected_error == actual_error - || ignored_error_code(actual_error)) + else if (expected_error == actual_error || + ignored_error_code(actual_error)) { thd->query_error = 0; *rli->last_slave_error = 0; @@ -1639,8 +1652,8 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli) return 1; } } - thd->db = 0; // prevent db from being freed - thd->query = 0; // just to be sure + thd->db= 0; // prevent db from being freed + thd->query= 0; // just to be sure // assume no convert for next query unless set explictly thd->convert_set = 0; close_thread_tables(thd); @@ -1648,8 +1661,8 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli) if (thd->query_error || thd->fatal_error) { slave_print_error(rli,actual_error, "error '%s' on query '%s'", - actual_error ? thd->net.last_error : - "unexpected success or fatal error", query); + actual_error ? thd->net.last_error : + "unexpected success or fatal error", query); free_root(&thd->mem_root,0); return 1; } @@ -1657,6 +1670,7 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli) return Log_event::exec_event(rli); } + int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli) { init_sql_alloc(&thd->mem_root, 8192,0); @@ -1710,32 +1724,35 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli) { // mysql_load will use thd->net to read the file thd->net.vio = net->vio; - // make sure the client does not get confused - // about the packet sequence + /* + Make sure the client does not get confused about the packet sequence + */ thd->net.pkt_nr = net->pkt_nr; } if (mysql_load(thd, &ex, &tables, fields, handle_dup, net != 0, - TL_WRITE)) + TL_WRITE)) thd->query_error = 1; if (thd->cuted_fields) sql_print_error("Slave: load data infile at position %s in log \ '%s' produced %d warning(s)", llstr(rli->master_log_pos,llbuff), RPL_LOG_NAME, thd->cuted_fields ); if (net) - net->pkt_nr = thd->net.pkt_nr; + net->pkt_nr= thd->net.pkt_nr; } } else { - // we will just ask the master to send us /dev/null if we do not - // want to load the data - // TODO: this a bug - needs to be done in I/O thread + /* + We will just ask the master to send us /dev/null if we do not + want to load the data. + TODO: this a bug - needs to be done in I/O thread + */ if (net) skip_load_data_infile(net); } thd->net.vio = 0; - thd->db = 0;// prevent db from being freed + thd->db= 0; // prevent db from being freed close_thread_tables(thd); if (thd->query_error) { @@ -1745,7 +1762,7 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli) slave_print_error(rli,sql_error, "Slave: Error '%s' running load data infile ", - ER_SAFE(sql_error)); + ER_SAFE(sql_error)); free_root(&thd->mem_root,0); return 1; } @@ -1760,21 +1777,26 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli) return Log_event::exec_event(rli); } + int Start_log_event::exec_event(struct st_relay_log_info* rli) { close_temporary_tables(thd); - // if we have old format, load_tmpdir is cleaned up by the I/O thread - // TODO: cleanup_load_tmpdir() needs to remove only the files associated - // with the server id that has just started + /* + If we have old format, load_tmpdir is cleaned up by the I/O thread + + TODO: cleanup_load_tmpdir() needs to remove only the files associated + with the server id that has just started + */ if (!rli->mi->old_format) cleanup_load_tmpdir(); return Log_event::exec_event(rli); } + int Stop_log_event::exec_event(struct st_relay_log_info* rli) { // do not clean up immediately after rotate event - if (rli->master_log_pos > 4) + if (rli->master_log_pos > BIN_LOG_HEADER_SIZE) { close_temporary_tables(thd); cleanup_load_tmpdir(); @@ -1809,7 +1831,10 @@ int Rotate_log_event::exec_event(struct st_relay_log_info* rli) && mysql_bin_log.is_open()); rotate_binlog = (*log_name && write_slave_event); if (ident_len >= sizeof(rli->master_log_name)) + { + pthread_mutex_unlock(&rli->data_lock); DBUG_RETURN(1); + } memcpy(log_name, new_log_ident,ident_len); log_name[ident_len] = 0; } @@ -1907,7 +1932,8 @@ int Create_file_log_event::exec_event(struct st_relay_log_info* rli) } if (mysql_bin_log.is_open()) mysql_bin_log.write(this); - error=0; + error=0; // Everything is ok + err: if (error) end_io_cache(&file); @@ -1919,12 +1945,11 @@ err: int Delete_file_log_event::exec_event(struct st_relay_log_info* rli) { char fname[FN_REFLEN+10]; - char* p; - p = slave_load_file_stem(fname, file_id, server_id); + char *p= slave_load_file_stem(fname, file_id, server_id); memcpy(p, ".data", 6); - (void)my_delete(fname, MYF(MY_WME)); + (void) my_delete(fname, MYF(MY_WME)); memcpy(p, ".info", 6); - (void)my_delete(fname, MYF(MY_WME)); + (void) my_delete(fname, MYF(MY_WME)); if (mysql_bin_log.is_open()) mysql_bin_log.write(this); return Log_event::exec_event(rli); @@ -1933,10 +1958,10 @@ int Delete_file_log_event::exec_event(struct st_relay_log_info* rli) int Append_block_log_event::exec_event(struct st_relay_log_info* rli) { char fname[FN_REFLEN+10]; - char* p; - int fd = -1; + char *p= slave_load_file_stem(fname, file_id, server_id); + int fd; int error = 1; - p = slave_load_file_stem(fname, file_id, server_id); + memcpy(p, ".data", 6); if ((fd = my_open(fname, O_WRONLY|O_APPEND|O_BINARY, MYF(MY_WME))) < 0) { @@ -1951,6 +1976,7 @@ int Append_block_log_event::exec_event(struct st_relay_log_info* rli) if (mysql_bin_log.is_open()) mysql_bin_log.write(this); error=0; + err: if (fd >= 0) my_close(fd, MYF(0)); @@ -1960,15 +1986,14 @@ err: int Execute_load_log_event::exec_event(struct st_relay_log_info* rli) { char fname[FN_REFLEN+10]; - char* p; - int fd = -1; + char *p= slave_load_file_stem(fname, file_id, server_id); + int fd; int error = 1; ulong save_options; IO_CACHE file; Load_log_event* lev = 0; - p = slave_load_file_stem(fname, file_id, server_id); + memcpy(p, ".info", 6); - bzero((char*)&file, sizeof(file)); if ((fd = my_open(fname, O_RDONLY|O_BINARY, MYF(MY_WME))) < 0 || init_io_cache(&file, fd, IO_SIZE, READ_CACHE, (my_off_t)0, 0, MYF(MY_WME|MY_NABP))) @@ -1978,8 +2003,8 @@ int Execute_load_log_event::exec_event(struct st_relay_log_info* rli) } if (!(lev = (Load_log_event*)Log_event::read_log_event(&file, (pthread_mutex_t*)0, - (bool)0)) - || lev->get_type_code() != NEW_LOAD_EVENT) + (bool)0)) || + lev->get_type_code() != NEW_LOAD_EVENT) { slave_print_error(rli,0, "File '%s' appears corrupted", fname); goto err; @@ -2000,19 +2025,21 @@ int Execute_load_log_event::exec_event(struct st_relay_log_info* rli) goto err; } thd->options = save_options; - (void)my_delete(fname, MYF(MY_WME)); + (void) my_delete(fname, MYF(MY_WME)); memcpy(p, ".data", 6); - (void)my_delete(fname, MYF(MY_WME)); + (void) my_delete(fname, MYF(MY_WME)); if (mysql_bin_log.is_open()) mysql_bin_log.write(this); error = 0; + err: delete lev; - end_io_cache(&file); if (fd >= 0) + { my_close(fd, MYF(0)); + end_io_cache(&file); + } return error ? error : Log_event::exec_event(rli); } - -#endif +#endif /* !MYSQL_CLIENT */ diff --git a/sql/log_event.h b/sql/log_event.h index a29c3952d46..29cf6287a4f 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -15,8 +15,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _LOG_EVENT_H -#define _LOG_EVENT_H +#ifndef _log_event_h +#define _log_event_h #ifdef __EMX__ #undef write // remove pthread.h macro definition, conflict with write() class member @@ -36,74 +36,76 @@ #define LOG_EVENT_OFFSET 4 #define BINLOG_VERSION 3 -/* we could have used SERVER_VERSION_LENGTH, but this introduces an - obscure dependency - if somebody decided to change SERVER_VERSION_LENGTH - this would have broke the replication protocol +/* + We could have used SERVER_VERSION_LENGTH, but this introduces an + obscure dependency - if somebody decided to change SERVER_VERSION_LENGTH + this would have broke the replication protocol */ #define ST_SERVER_VER_LEN 50 -#define DUMPFILE_FLAG 0x1 -#define OPT_ENCLOSED_FLAG 0x2 -#define REPLACE_FLAG 0x4 -#define IGNORE_FLAG 0x8 +#define DUMPFILE_FLAG 0x1 +#define OPT_ENCLOSED_FLAG 0x2 +#define REPLACE_FLAG 0x4 +#define IGNORE_FLAG 0x8 -#define FIELD_TERM_EMPTY 0x1 -#define ENCLOSED_EMPTY 0x2 -#define LINE_TERM_EMPTY 0x4 -#define LINE_START_EMPTY 0x8 -#define ESCAPED_EMPTY 0x10 +#define FIELD_TERM_EMPTY 0x1 +#define ENCLOSED_EMPTY 0x2 +#define LINE_TERM_EMPTY 0x4 +#define LINE_START_EMPTY 0x8 +#define ESCAPED_EMPTY 0x10 struct old_sql_ex - { - char field_term; - char enclosed; - char line_term; - char line_start; - char escaped; - char opt_flags; - char empty_flags; - }; +{ + char field_term; + char enclosed; + char line_term; + char line_start; + char escaped; + char opt_flags; + char empty_flags; +}; #define NUM_LOAD_DELIM_STRS 5 - struct sql_ex_info - { - char* field_term; - char* enclosed; - char* line_term; - char* line_start; - char* escaped; - uint8 field_term_len,enclosed_len,line_term_len,line_start_len, - escaped_len; - char opt_flags; - char empty_flags; - int cached_new_format; +{ + char* field_term; + char* enclosed; + char* line_term; + char* line_start; + char* escaped; + int cached_new_format; + uint8 field_term_len,enclosed_len,line_term_len,line_start_len, escaped_len; + char opt_flags; + char empty_flags; - // store in new format even if old is possible - void force_new_format() { cached_new_format = 1;} - int data_size() { return new_format() ? - field_term_len + enclosed_len + line_term_len + - line_start_len + escaped_len + 6 : 7;} - int write_data(IO_CACHE* file); - char* init(char* buf,char* buf_end,bool use_new_format); - bool new_format() - { - return (cached_new_format != -1) ? cached_new_format : - (cached_new_format=(field_term_len > 1 || - enclosed_len > 1 || - line_term_len > 1 || line_start_len > 1 || - escaped_len > 1)); - } - } ; - -/* Binary log consists of events. Each event has a fixed length header, - followed by possibly variable ( depending on the type of event) length - data body. The data body consists of an optional fixed length segment - (post-header), and an optional variable length segment. See #defines and - comments below for the format specifics -*/ + // store in new format even if old is possible + void force_new_format() { cached_new_format = 1;} + int data_size() + { + return (new_format() ? + field_term_len + enclosed_len + line_term_len + + line_start_len + escaped_len + 6 : 7); + } + int write_data(IO_CACHE* file); + char* init(char* buf,char* buf_end,bool use_new_format); + bool new_format() + { + return ((cached_new_format != -1) ? cached_new_format : + (cached_new_format=(field_term_len > 1 || + enclosed_len > 1 || + line_term_len > 1 || line_start_len > 1 || + escaped_len > 1))); + } +}; +/* + Binary log consists of events. Each event has a fixed length header, + followed by possibly variable ( depending on the type of event) length + data body. The data body consists of an optional fixed length segment + (post-header), and an optional variable length segment. See #defines and + comments below for the format specifics +*/ /* event-specific post-header sizes */ #define LOG_EVENT_HEADER_LEN 19 @@ -139,11 +141,11 @@ struct sql_ex_info /* query event post-header */ -#define Q_THREAD_ID_OFFSET 0 -#define Q_EXEC_TIME_OFFSET 4 -#define Q_DB_LEN_OFFSET 8 -#define Q_ERR_CODE_OFFSET 9 -#define Q_DATA_OFFSET QUERY_HEADER_LEN +#define Q_THREAD_ID_OFFSET 0 +#define Q_EXEC_TIME_OFFSET 4 +#define Q_DB_LEN_OFFSET 8 +#define Q_ERR_CODE_OFFSET 9 +#define Q_DATA_OFFSET QUERY_HEADER_LEN /* Intvar event post-header */ @@ -159,7 +161,7 @@ struct sql_ex_info #define L_DB_LEN_OFFSET 13 #define L_NUM_FIELDS_OFFSET 14 #define L_SQL_EX_OFFSET 18 -#define L_DATA_OFFSET LOAD_HEADER_LEN +#define L_DATA_OFFSET LOAD_HEADER_LEN /* Rotate event post-header */ @@ -176,10 +178,10 @@ struct sql_ex_info #define DF_FILE_ID_OFFSET 0 -#define QUERY_EVENT_OVERHEAD (LOG_EVENT_HEADER_LEN+QUERY_HEADER_LEN) -#define QUERY_DATA_OFFSET (LOG_EVENT_HEADER_LEN+QUERY_HEADER_LEN) -#define ROTATE_EVENT_OVERHEAD (LOG_EVENT_HEADER_LEN+ROTATE_HEADER_LEN) -#define LOAD_EVENT_OVERHEAD (LOG_EVENT_HEADER_LEN+LOAD_HEADER_LEN) +#define QUERY_EVENT_OVERHEAD (LOG_EVENT_HEADER_LEN+QUERY_HEADER_LEN) +#define QUERY_DATA_OFFSET (LOG_EVENT_HEADER_LEN+QUERY_HEADER_LEN) +#define ROTATE_EVENT_OVERHEAD (LOG_EVENT_HEADER_LEN+ROTATE_HEADER_LEN) +#define LOAD_EVENT_OVERHEAD (LOG_EVENT_HEADER_LEN+LOAD_HEADER_LEN) #define CREATE_FILE_EVENT_OVERHEAD (LOG_EVENT_HEADER_LEN+\ +LOAD_HEADER_LEN+CREATE_FILE_HEADER_LEN) #define DELETE_FILE_EVENT_OVERHEAD (LOG_EVENT_HEADER_LEN+DELETE_FILE_HEADER_LEN) @@ -192,13 +194,19 @@ struct sql_ex_info #define LOG_EVENT_TIME_F 0x1 #define LOG_EVENT_FORCED_ROTATE_F 0x2 -enum Log_event_type { START_EVENT = 1, QUERY_EVENT =2, - STOP_EVENT=3, ROTATE_EVENT = 4, INTVAR_EVENT=5, - LOAD_EVENT=6, SLAVE_EVENT=7, CREATE_FILE_EVENT=8, - APPEND_BLOCK_EVENT=9, EXEC_LOAD_EVENT=10, DELETE_FILE_EVENT=11, - NEW_LOAD_EVENT=12}; -enum Int_event_type { INVALID_INT_EVENT = 0, LAST_INSERT_ID_EVENT = 1, INSERT_ID_EVENT = 2 - }; +enum Log_event_type +{ + START_EVENT = 1, QUERY_EVENT =2, STOP_EVENT=3, ROTATE_EVENT = 4, + INTVAR_EVENT=5, LOAD_EVENT=6, SLAVE_EVENT=7, CREATE_FILE_EVENT=8, + APPEND_BLOCK_EVENT=9, EXEC_LOAD_EVENT=10, DELETE_FILE_EVENT=11, + NEW_LOAD_EVENT=12 +}; + +enum Int_event_type +{ + INVALID_INT_EVENT = 0, LAST_INSERT_ID_EVENT = 1, INSERT_ID_EVENT = 2 +}; + #ifndef MYSQL_CLIENT class String; @@ -220,15 +228,38 @@ public: uint16 flags; int cached_event_len; char* temp_buf; -#ifndef MYSQL_CLIENT + +#ifndef MYSQL_CLIENT THD* thd; + + Log_event(THD* thd_arg, uint16 flags_arg = 0); + // if mutex is 0, the read will proceed without mutex + static Log_event* read_log_event(IO_CACHE* file, + pthread_mutex_t* log_lock, + bool old_format); + static int read_log_event(IO_CACHE* file, String* packet, + pthread_mutex_t* log_lock); + void set_log_pos(MYSQL_LOG* log); + virtual void pack_info(String* packet); + int net_send(THD* thd, const char* log_name, my_off_t pos); + static void init_show_field_list(List<Item>* field_list); + virtual int exec_event(struct st_relay_log_info* rli); + virtual const char* get_db() + { + return thd ? thd->db : 0; + } +#else + // avoid having to link mysqlbinlog against libpthread + static Log_event* read_log_event(IO_CACHE* file, bool old_format); + virtual void print(FILE* file, bool short_form = 0, char* last_db = 0) = 0; + void print_timestamp(FILE* file, time_t *ts = 0); + void print_header(FILE* file); #endif static void *operator new(size_t size) { return (void*) my_malloc((uint)size, MYF(MY_WME|MY_FAE)); } - static void operator delete(void *ptr, size_t size) { my_free((gptr) ptr, MYF(MY_WME|MY_ALLOW_ZERO_PTR)); @@ -237,64 +268,35 @@ public: int write(IO_CACHE* file); int write_header(IO_CACHE* file); virtual int write_data(IO_CACHE* file) - { return write_data_header(file) || write_data_body(file); } + { return write_data_header(file) || write_data_body(file); } virtual int write_data_header(IO_CACHE* file __attribute__((unused))) - { return 0; } + { return 0; } virtual int write_data_body(IO_CACHE* file __attribute__((unused))) - { return 0; } + { return 0; } virtual Log_event_type get_type_code() = 0; virtual bool is_valid() = 0; virtual bool get_cache_stmt() { return 0; } Log_event(const char* buf, bool old_format); -#ifndef MYSQL_CLIENT - Log_event(THD* thd_arg, uint16 flags_arg = 0); -#endif virtual ~Log_event() { free_temp_buf();} void register_temp_buf(char* buf) { temp_buf = buf; } void free_temp_buf() + { + if (temp_buf) { - if (temp_buf) - { - my_free(temp_buf, MYF(0)); - temp_buf = 0; - } + my_free(temp_buf, MYF(0)); + temp_buf = 0; } + } virtual int get_data_size() { return 0;} virtual int get_data_body_offset() { return 0; } - int get_event_len() { return cached_event_len ? cached_event_len : - (cached_event_len = LOG_EVENT_HEADER_LEN + get_data_size()); } -#ifdef MYSQL_CLIENT - virtual void print(FILE* file, bool short_form = 0, char* last_db = 0) = 0; - void print_timestamp(FILE* file, time_t *ts = 0); - void print_header(FILE* file); -#endif - -#ifndef MYSQL_CLIENT - // if mutex is 0, the read will proceed without mutex - static Log_event* read_log_event(IO_CACHE* file, - pthread_mutex_t* log_lock, - bool old_format); -#else // avoid having to link mysqlbinlog against libpthread - static Log_event* read_log_event(IO_CACHE* file, bool old_format); -#endif + int get_event_len() + { + return (cached_event_len ? cached_event_len : + (cached_event_len = LOG_EVENT_HEADER_LEN + get_data_size())); + } static Log_event* read_log_event(const char* buf, int event_len, const char **error, bool old_format); const char* get_type_str(); - -#ifndef MYSQL_CLIENT - static int read_log_event(IO_CACHE* file, String* packet, - pthread_mutex_t* log_lock); - void set_log_pos(MYSQL_LOG* log); - virtual void pack_info(String* packet); - int net_send(THD* thd, const char* log_name, my_off_t pos); - static void init_show_field_list(List<Item>* field_list); - virtual int exec_event(struct st_relay_log_info* rli); - virtual const char* get_db() - { - return thd ? thd->db : 0; - } -#endif - }; @@ -305,13 +307,16 @@ protected: public: const char* query; const char* db; - uint32 q_len; // if we already know the length of the query string - // we pass it here, so we would not have to call strlen() - // otherwise, set it to 0, in which case, we compute it with strlen() + /* + If we already know the length of the query string + we pass it with q_len, so we would not have to call strlen() + otherwise, set it to 0, in which case, we compute it with strlen() + */ + uint32 q_len; uint32 db_len; uint16 error_code; ulong thread_id; -#if !defined(MYSQL_CLIENT) +#ifndef MYSQL_CLIENT bool cache_stmt; Query_log_event(THD* thd_arg, const char* query_arg, @@ -320,6 +325,8 @@ public: void pack_info(String* packet); int exec_event(struct st_relay_log_info* rli); bool get_cache_stmt() { return cache_stmt; } +#else + void print(FILE* file, bool short_form = 0, char* last_db = 0); #endif Query_log_event(const char* buf, int event_len, bool old_format); @@ -336,17 +343,15 @@ public: bool is_valid() { return query != 0; } int get_data_size() { - return q_len + db_len + 2 + - 4 // thread_id - + 4 // exec_time - + 2 // error_code - ; + return (q_len + db_len + 2 + + 4 // thread_id + + 4 // exec_time + + 2 // error_code + ); } -#ifdef MYSQL_CLIENT - void print(FILE* file, bool short_form = 0, char* last_db = 0); -#endif }; + class Slave_log_event: public Log_event { protected: @@ -364,18 +369,16 @@ public: Slave_log_event(THD* thd_arg, struct st_relay_log_info* rli); void pack_info(String* packet); int exec_event(struct st_relay_log_info* rli); -#endif - +#else + void print(FILE* file, bool short_form = 0, char* last_db = 0); +#endif + Slave_log_event(const char* buf, int event_len); ~Slave_log_event(); int get_data_size(); bool is_valid() { return master_host != 0; } Log_event_type get_type_code() { return SLAVE_EVENT; } -#ifdef MYSQL_CLIENT - void print(FILE* file, bool short_form = 0, char* last_db = 0); -#endif int write_data(IO_CACHE* file ); - }; class Load_log_event: public Log_event @@ -399,7 +402,7 @@ public: uint32 skip_lines; sql_ex_info sql_ex; -#if !defined(MYSQL_CLIENT) +#ifndef MYSQL_CLIENT String field_lens_buf; String fields_buf; @@ -414,6 +417,8 @@ public: return exec_event(thd->slave_net,rli); } int exec_event(NET* net, struct st_relay_log_info* rli); +#else + void print(FILE* file, bool short_form = 0, char* last_db = 0); #endif Load_log_event(const char* buf, int event_len, bool old_format); @@ -427,18 +432,14 @@ public: bool is_valid() { return table_name != 0; } int get_data_size() { - return table_name_len + 2 + db_len + 2 + fname_len - + 4 // thread_id - + 4 // exec_time - + 4 // skip_lines - + 4 // field block len - + sql_ex.data_size() + field_block_len + num_fields; - ; + return (table_name_len + 2 + db_len + 2 + fname_len + + 4 // thread_id + + 4 // exec_time + + 4 // skip_lines + + 4 // field block len + + sql_ex.data_size() + field_block_len + num_fields); } int get_data_body_offset() { return LOAD_EVENT_OVERHEAD; } -#ifdef MYSQL_CLIENT - void print(FILE* file, bool short_form = 0, char* last_db = 0); -#endif }; extern char server_version[SERVER_VERSION_LENGTH]; @@ -449,13 +450,19 @@ public: uint32 created; uint16 binlog_version; char server_version[ST_SERVER_VER_LEN]; -#ifndef MYSQL_CLIENT + +#ifndef MYSQL_CLIENT Start_log_event() :Log_event((THD*)0),binlog_version(BINLOG_VERSION) { created = (uint32) when; memcpy(server_version, ::server_version, ST_SERVER_VER_LEN); } + void pack_info(String* packet); + int exec_event(struct st_relay_log_info* rli); +#else + void print(FILE* file, bool short_form = 0, char* last_db = 0); #endif + Start_log_event(const char* buf, bool old_format); ~Start_log_event() {} Log_event_type get_type_code() { return START_EVENT;} @@ -465,25 +472,25 @@ public: { return START_HEADER_LEN; } -#ifndef MYSQL_CLIENT - void pack_info(String* packet); - int exec_event(struct st_relay_log_info* rli); -#endif -#ifdef MYSQL_CLIENT - void print(FILE* file, bool short_form = 0, char* last_db = 0); -#endif }; + class Intvar_log_event: public Log_event { public: ulonglong val; uchar type; + #ifndef MYSQL_CLIENT Intvar_log_event(THD* thd_arg,uchar type_arg, ulonglong val_arg) :Log_event(thd_arg),val(val_arg),type(type_arg) {} -#endif + void pack_info(String* packet); + int exec_event(struct st_relay_log_info* rli); +#else + void print(FILE* file, bool short_form = 0, char* last_db = 0); +#endif + Intvar_log_event(const char* buf, bool old_format); ~Intvar_log_event() {} Log_event_type get_type_code() { return INTVAR_EVENT;} @@ -491,38 +498,29 @@ public: int get_data_size() { return sizeof(type) + sizeof(val);} int write_data(IO_CACHE* file); bool is_valid() { return 1; } -#ifndef MYSQL_CLIENT - void pack_info(String* packet); - int exec_event(struct st_relay_log_info* rli); -#endif - -#ifdef MYSQL_CLIENT - void print(FILE* file, bool short_form = 0, char* last_db = 0); -#endif }; + class Stop_log_event: public Log_event { public: #ifndef MYSQL_CLIENT Stop_log_event() :Log_event((THD*)0) {} + int exec_event(struct st_relay_log_info* rli); +#else + void print(FILE* file, bool short_form = 0, char* last_db = 0); #endif - Stop_log_event(const char* buf, bool old_format):Log_event(buf, - old_format) - { - } + + Stop_log_event(const char* buf, bool old_format): + Log_event(buf, old_format) + {} ~Stop_log_event() {} Log_event_type get_type_code() { return STOP_EVENT;} bool is_valid() { return 1; } -#ifdef MYSQL_CLIENT - void print(FILE* file, bool short_form = 0, char* last_db = 0); -#endif -#ifndef MYSQL_CLIENT - int exec_event(struct st_relay_log_info* rli); -#endif }; + class Rotate_log_event: public Log_event { public: @@ -532,14 +530,18 @@ public: bool alloced; #ifndef MYSQL_CLIENT Rotate_log_event(THD* thd_arg, const char* new_log_ident_arg, - uint ident_len_arg = 0,ulonglong pos_arg = 4) : - Log_event(thd_arg), - new_log_ident(new_log_ident_arg), + uint ident_len_arg = 0,ulonglong pos_arg = 4) + : Log_event(thd_arg), new_log_ident(new_log_ident_arg), ident_len(ident_len_arg ? ident_len_arg : (uint) strlen(new_log_ident_arg)), pos(pos_arg), alloced(0) {} -#endif + void pack_info(String* packet); + int exec_event(struct st_relay_log_info* rli); +#else + void print(FILE* file, bool short_form = 0, char* last_db = 0); +#endif + Rotate_log_event(const char* buf, int event_len, bool old_format); ~Rotate_log_event() { @@ -550,13 +552,6 @@ public: int get_data_size() { return ident_len + ROTATE_HEADER_LEN;} bool is_valid() { return new_log_ident != 0; } int write_data(IO_CACHE* file); -#ifdef MYSQL_CLIENT - void print(FILE* file, bool short_form = 0, char* last_db = 0); -#endif -#ifndef MYSQL_CLIENT - void pack_info(String* packet); - int exec_event(struct st_relay_log_info* rli); -#endif }; /* the classes below are for the new LOAD DATA INFILE logging */ @@ -564,51 +559,59 @@ public: class Create_file_log_event: public Load_log_event { protected: - // pretend we are Load event, so we can write out just - // our Load part - used on the slave when writing event out to - // SQL_LOAD-*.info file + /* + Pretend we are Load event, so we can write out just + our Load part - used on the slave when writing event out to + SQL_LOAD-*.info file + */ bool fake_base; public: char* block; uint block_len; uint file_id; bool inited_from_old; + #ifndef MYSQL_CLIENT Create_file_log_event(THD* thd, sql_exchange* ex, const char* db_arg, const char* table_name_arg, List<Item>& fields_arg, enum enum_duplicates handle_dup, char* block_arg, uint block_len_arg); + void pack_info(String* packet); + int exec_event(struct st_relay_log_info* rli); +#else + void print(FILE* file, bool short_form = 0, char* last_db = 0); #endif Create_file_log_event(const char* buf, int event_len, bool old_format); - ~Create_file_log_event() + ~Create_file_log_event() {} + + Log_event_type get_type_code() { + return fake_base ? Load_log_event::get_type_code() : CREATE_FILE_EVENT; + } + int get_data_size() + { + return (fake_base ? Load_log_event::get_data_size() : + Load_log_event::get_data_size() + + 4 + 1 + block_len); + } + int get_data_body_offset() + { + return (fake_base ? LOAD_EVENT_OVERHEAD: + LOAD_EVENT_OVERHEAD + CREATE_FILE_HEADER_LEN); } - Log_event_type get_type_code() - { - return fake_base ? Load_log_event::get_type_code() : CREATE_FILE_EVENT; - } - int get_data_size() { return fake_base ? Load_log_event::get_data_size() : - Load_log_event::get_data_size() + - 4 + 1 + block_len;} - int get_data_body_offset() { return fake_base ? LOAD_EVENT_OVERHEAD: - LOAD_EVENT_OVERHEAD + CREATE_FILE_HEADER_LEN; } bool is_valid() { return inited_from_old || block != 0; } int write_data_header(IO_CACHE* file); int write_data_body(IO_CACHE* file); - int write_base(IO_CACHE* file); // cut out Create_file extentions and - // write it as Load event - used on the slave - -#ifdef MYSQL_CLIENT - void print(FILE* file, bool short_form = 0, char* last_db = 0); -#endif -#ifndef MYSQL_CLIENT - void pack_info(String* packet); - int exec_event(struct st_relay_log_info* rli); -#endif + /* + Cut out Create_file extentions and + write it as Load event - used on the slave + */ + int write_base(IO_CACHE* file); }; + class Append_block_log_event: public Log_event { public: @@ -618,27 +621,22 @@ public: #ifndef MYSQL_CLIENT Append_block_log_event(THD* thd, char* block_arg, - uint block_len_arg); + uint block_len_arg); int exec_event(struct st_relay_log_info* rli); -#endif + void pack_info(String* packet); +#else + void print(FILE* file, bool short_form = 0, char* last_db = 0); +#endif Append_block_log_event(const char* buf, int event_len); - ~Append_block_log_event() - { - } + ~Append_block_log_event() {} Log_event_type get_type_code() { return APPEND_BLOCK_EVENT;} int get_data_size() { return block_len + APPEND_BLOCK_HEADER_LEN ;} bool is_valid() { return block != 0; } int write_data(IO_CACHE* file); - -#ifdef MYSQL_CLIENT - void print(FILE* file, bool short_form = 0, char* last_db = 0); -#endif -#ifndef MYSQL_CLIENT - void pack_info(String* packet); -#endif }; + class Delete_file_log_event: public Log_event { public: @@ -646,24 +644,18 @@ public: #ifndef MYSQL_CLIENT Delete_file_log_event(THD* thd); + void pack_info(String* packet); + int exec_event(struct st_relay_log_info* rli); +#else + void print(FILE* file, bool short_form = 0, char* last_db = 0); #endif Delete_file_log_event(const char* buf, int event_len); - ~Delete_file_log_event() - { - } + ~Delete_file_log_event() {} Log_event_type get_type_code() { return DELETE_FILE_EVENT;} int get_data_size() { return DELETE_FILE_HEADER_LEN ;} bool is_valid() { return file_id != 0; } int write_data(IO_CACHE* file); - -#ifdef MYSQL_CLIENT - void print(FILE* file, bool short_form = 0, char* last_db = 0); -#endif -#ifndef MYSQL_CLIENT - void pack_info(String* packet); - int exec_event(struct st_relay_log_info* rli); -#endif }; class Execute_load_log_event: public Log_event @@ -673,27 +665,18 @@ public: #ifndef MYSQL_CLIENT Execute_load_log_event(THD* thd); + void pack_info(String* packet); + int exec_event(struct st_relay_log_info* rli); +#else + void print(FILE* file, bool short_form = 0, char* last_db = 0); #endif Execute_load_log_event(const char* buf, int event_len); - ~Execute_load_log_event() - { - } + ~Execute_load_log_event() {} Log_event_type get_type_code() { return EXEC_LOAD_EVENT;} int get_data_size() { return EXEC_LOAD_HEADER_LEN ;} bool is_valid() { return file_id != 0; } int write_data(IO_CACHE* file); - -#ifdef MYSQL_CLIENT - void print(FILE* file, bool short_form = 0, char* last_db = 0); -#endif -#ifndef MYSQL_CLIENT - void pack_info(String* packet); - int exec_event(struct st_relay_log_info* rli); -#endif }; -#endif - - - +#endif /* _log_event_h */ diff --git a/sql/mini_client.cc b/sql/mini_client.cc index ffb5d659238..19e94054272 100644 --- a/sql/mini_client.cc +++ b/sql/mini_client.cc @@ -354,7 +354,7 @@ mc_net_safe_read(MYSQL *mysql) if (socket_errno != SOCKET_EINTR) { mc_end_server(mysql); - if(net->last_errno != ER_NET_PACKET_TOO_LARGE) + if (net->last_errno != ER_NET_PACKET_TOO_LARGE) { net->last_errno=CR_SERVER_LOST; strmov(net->last_error,ER(net->last_errno)); @@ -375,7 +375,7 @@ max_allowed_packet on this server"); net->last_errno=uint2korr(pos); pos+=2; len-=2; - if(!net->last_errno) + if (!net->last_errno) net->last_errno = CR_UNKNOWN_ERROR; } else @@ -791,7 +791,7 @@ mc_mysql_connect(MYSQL *mysql,const char *host, const char *user, else { user = getenv("USER"); - if(!user) user = "mysql"; + if (!user) user = "mysql"; strmov((char*) buff+5, user ); } diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index fd3111f380a..dae392615ff 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -48,7 +48,7 @@ char *sql_strmake(const char *str,uint len); gptr sql_memdup(const void * ptr,unsigned size); void sql_element_free(void *ptr); void kill_one_thread(THD *thd, ulong id); -int net_request_file(NET* net, const char* fname); +bool net_request_file(NET* net, const char* fname); char* query_table_status(THD *thd,const char *db,const char *table_name); #define x_free(A) { my_free((gptr) (A),MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR)); } @@ -200,18 +200,20 @@ char* query_table_status(THD *thd,const char *db,const char *table_name); #define RAID_BLOCK_SIZE 1024 -// Sync points allow us to force the server to reach a certain line of code -// and block there until the client tells the server it is ok to go on. -// The client tells the server to block with SELECT GET_LOCK() -// and unblocks it with SELECT RELEASE_LOCK(). Used for debugging difficult -// concurrency problems #ifdef EXTRA_DEBUG +/* + Sync points allow us to force the server to reach a certain line of code + and block there until the client tells the server it is ok to go on. + The client tells the server to block with SELECT GET_LOCK() + and unblocks it with SELECT RELEASE_LOCK(). Used for debugging difficult + concurrency problems +*/ #define DBUG_SYNC_POINT(lock_name,lock_timeout) \ debug_sync_point(lock_name,lock_timeout) void debug_sync_point(const char* lock_name, uint lock_timeout); #else #define DBUG_SYNC_POINT(lock_name,lock_timeout) -#endif +#endif /* EXTRA_DEBUG */ /* BINLOG_DUMP options */ @@ -376,9 +378,6 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, HA_CREATE_INFO *create_info, List<create_field> &fields, List<Key> &keys, bool tmp_table, bool no_log); -// no_log is needed for the case of CREATE TABLE ... SELECT , as the logging -// will be done later in sql_insert.cc - TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, const char *db, const char *name, List<create_field> *extra_fields, diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 9111b090a99..0dc516e6ab2 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -238,9 +238,10 @@ SHOW_COMP_OPTION have_query_cache=SHOW_OPTION_NO; bool opt_skip_slave_start = 0; // If set, slave is not autostarted -/* if set, some standard measures to enforce - slave data intergity will not be performed - */ +/* + If set, some standard measures to enforce slave data integrity will not + be performed +*/ bool opt_reckless_slave = 0; static bool opt_do_pstack = 0; static ulong opt_specialflag=SPECIAL_ENGLISH; @@ -279,7 +280,7 @@ char glob_hostname[FN_REFLEN]; #include "sslopt-vars.h" #ifdef HAVE_OPENSSL char *des_key_file = 0; -struct st_VioSSLAcceptorFd * ssl_acceptor_fd = 0; +struct st_VioSSLAcceptorFd *ssl_acceptor_fd= 0; #endif /* HAVE_OPENSSL */ I_List <i_string_pair> replicate_rewrite_db; @@ -582,9 +583,7 @@ static void close_connections(void) (void) pthread_mutex_unlock(&LOCK_thread_count); // For unlink from list if (thread_count) - { sleep(1); // Give threads time to die - } /* Force remaining threads to die by closing the connection to the client */ @@ -1185,9 +1184,8 @@ void end_thread(THD *thd, bool put_in_cache) DBUG_PRINT("info", ("sending a broadcast")) /* Tell main we are ready */ - // TODO: explain why we broadcast outside of the lock or - // fix the bug - Sasha (void) pthread_mutex_unlock(&LOCK_thread_count); + /* It's safe to broadcast outside a lock (COND... is not deleted here) */ (void) pthread_cond_broadcast(&COND_thread_count); DBUG_PRINT("info", ("unlocked thread_count mutex")) #ifdef ONE_THREAD @@ -1226,11 +1224,11 @@ void flush_thread_cache() } - /* - ** Aborts a thread nicely. Commes here on SIGPIPE - ** TODO: One should have to fix that thr_alarm know about this - ** thread too - */ +/* + Aborts a thread nicely. Commes here on SIGPIPE + TODO: One should have to fix that thr_alarm know about this + thread too. +*/ #ifdef THREAD_SPECIFIC_SIGPIPE static sig_handler abort_thread(int sig __attribute__((unused))) @@ -1244,9 +1242,9 @@ static sig_handler abort_thread(int sig __attribute__((unused))) #endif /****************************************************************************** -** Setup a signal thread with handles all signals -** Because linux doesn't support scemas use a mutex to check that -** the signal thread is ready before continuing + Setup a signal thread with handles all signals. + Because Linux doesn't support schemas use a mutex to check that + the signal thread is ready before continuing ******************************************************************************/ #if defined(__WIN__) || defined(OS2) @@ -1269,7 +1267,8 @@ static void start_signal_handler(void) #elif defined(__EMX__) static void sig_reload(int signo) { - reload_acl_and_cache((THD*) 0,REFRESH_LOG, (TABLE_LIST*) 0); // Flush everything + // Flush everything + reload_acl_and_cache((THD*) 0,REFRESH_LOG, (TABLE_LIST*) 0); signal(signo, SIG_ACK); } @@ -1357,7 +1356,7 @@ the thread stack. Please read http://www.mysql.com/doc/L/i/Linux.html\n\n", #endif /* HAVE_LINUXTHREADS */ #ifdef HAVE_STACKTRACE - if(!(test_flags & TEST_NO_STACKTRACE)) + if (!(test_flags & TEST_NO_STACKTRACE)) { fprintf(stderr,"thd=%p\n",thd); print_stacktrace(thd ? (gptr) thd->thread_stack : (gptr) 0, @@ -1476,9 +1475,7 @@ static void start_signal_handler(void) } -/* -** This threads handles all signals and alarms -*/ +/* This threads handles all signals and alarms */ /* ARGSUSED */ static void *signal_hand(void *arg __attribute__((unused))) @@ -1596,8 +1593,8 @@ static void *signal_hand(void *arg __attribute__((unused))) /* -** All global error messages are sent here where the first one is stored for -** the client + All global error messages are sent here where the first one is stored for + the client */ @@ -1689,6 +1686,7 @@ pthread_handler_decl(handle_shutdown,arg) } #endif + const char *load_default_groups[]= { "mysqld","server",0 }; #ifdef HAVE_LIBWRAP @@ -1739,9 +1737,10 @@ int main(int argc, char **argv) my_umask=0660; // Default umask for new files my_umask_dir=0700; // Default umask for new directories MAIN_THD; - /* initialize signal_th and shutdown_th to main_th for default value - as we need to initialize them to something safe. They are used - when compiled with safemalloc + /* + Initialize signal_th and shutdown_th to main_th for default value + as we need to initialize them to something safe. They are used + when compiled with safemalloc. */ SIGNAL_THD; SHUTDOWN_THD; @@ -1845,13 +1844,13 @@ int main(int argc, char **argv) #ifdef HAVE_OPENSSL if (opt_use_ssl) { - ssl_acceptor_fd = new_VioSSLAcceptorFd(opt_ssl_key, opt_ssl_cert, - opt_ssl_ca, opt_ssl_capath, - opt_ssl_cipher); - DBUG_PRINT("info",("ssl_acceptor_fd: %p",ssl_acceptor_fd)); + /* having ssl_acceptor_fd != 0 signals the use of SSL */ + ssl_acceptor_fd= new_VioSSLAcceptorFd(opt_ssl_key, opt_ssl_cert, + opt_ssl_ca, opt_ssl_capath, + opt_ssl_cipher); + DBUG_PRINT("info",("ssl_acceptor_fd: %p", ssl_acceptor_fd)); if (!ssl_acceptor_fd) opt_use_ssl = 0; - /* having ssl_acceptor_fd != 0 signals the use of SSL */ } if (des_key_file) load_des_key_file(des_key_file); @@ -2186,11 +2185,12 @@ The server will not act as a slave."); } +/**************************************************************************** + Main and thread entry function for Win32 + (all this is needed only to run mysqld as a service on WinNT) +****************************************************************************/ + #if defined(__WIN__) && !defined(EMBEDDED_LIBRARY) -/* ------------------------------------------------------------------------ - main and thread entry function for Win32 - (all this is needed only to run mysqld as a service on WinNT) - -------------------------------------------------------------------------- */ int mysql_service(void *p) { win_main(Service.my_argc, Service.my_argv); @@ -2202,8 +2202,8 @@ int main(int argc, char **argv) if (Service.GetOS()) /* true NT family */ { char file_path[FN_REFLEN]; - my_path(file_path, argv[0], ""); /* Find name in path */ - fn_format(file_path,argv[0],file_path,"",1+4+16); /* Force use of full path */ + my_path(file_path, argv[0], ""); /* Find name in path */ + fn_format(file_path,argv[0],file_path,"",1+4+16); /* Force full path */ if (argc == 2) { @@ -2268,10 +2268,14 @@ int main(int argc, char **argv) mysql_service(NULL); return 0; } -/* ------------------------------------------------------------------------ */ #endif +/* + Execute all commands from a file. Used by the mysql_install_db script to + create MySQL privilege tables without having to start a full MySQL server. +*/ + static int bootstrap(FILE *file) { THD *thd= new THD; @@ -2476,10 +2480,8 @@ pthread_handler_decl(handle_connections_sockets,arg __attribute__((unused))) MAYBE_BROKEN_SYSCALL; break; } - /* - ** Is this a new connection request - */ + /* Is this a new connection request ? */ #ifdef HAVE_SYS_UN_H if (FD_ISSET(unix_sock,&readFDs)) { @@ -2717,109 +2719,109 @@ pthread_handler_decl(handle_connections_namedpipes,arg) ******************************************************************************/ enum options { - OPT_ISAM_LOG=256, OPT_SKIP_NEW, - OPT_SKIP_GRANT, OPT_SKIP_LOCK, - OPT_ENABLE_LOCK, OPT_USE_LOCKING, - OPT_SOCKET, OPT_UPDATE_LOG, - OPT_BIN_LOG, OPT_SKIP_RESOLVE, - OPT_SKIP_NETWORKING, OPT_BIN_LOG_INDEX, - OPT_BIND_ADDRESS, OPT_PID_FILE, - OPT_SKIP_PRIOR, OPT_BIG_TABLES, - OPT_STANDALONE, OPT_ONE_THREAD, - OPT_CONSOLE, OPT_LOW_PRIORITY_UPDATES, - OPT_SKIP_HOST_CACHE, OPT_LONG_FORMAT, - OPT_FLUSH, OPT_SAFE, - OPT_BOOTSTRAP, OPT_SKIP_SHOW_DB, - OPT_TABLE_TYPE, OPT_INIT_FILE, - OPT_DELAY_KEY_WRITE, OPT_SLOW_QUERY_LOG, - OPT_USE_DELAY_KEY_WRITE, OPT_CHARSETS_DIR, - OPT_BDB_HOME, OPT_BDB_LOG, - OPT_BDB_TMP, OPT_BDB_NOSYNC, - OPT_BDB_LOCK, OPT_BDB_SKIP, - OPT_BDB_NO_RECOVER, OPT_BDB_SHARED, - OPT_MASTER_HOST, OPT_MASTER_USER, - OPT_MASTER_PASSWORD, OPT_MASTER_PORT, - OPT_MASTER_INFO_FILE, OPT_MASTER_CONNECT_RETRY, - OPT_MASTER_RETRY_COUNT, - OPT_MASTER_SSL, OPT_MASTER_SSL_KEY, - OPT_MASTER_SSL_CERT, - OPT_SQL_BIN_UPDATE_SAME, OPT_REPLICATE_DO_DB, - OPT_REPLICATE_IGNORE_DB, OPT_LOG_SLAVE_UPDATES, - OPT_BINLOG_DO_DB, OPT_BINLOG_IGNORE_DB, - OPT_WANT_CORE, OPT_CONCURRENT_INSERT, - OPT_MEMLOCK, OPT_MYISAM_RECOVER, - OPT_REPLICATE_REWRITE_DB, OPT_SERVER_ID, - OPT_SKIP_SLAVE_START, OPT_SKIP_INNOBASE, - OPT_SAFEMALLOC_MEM_LIMIT, OPT_REPLICATE_DO_TABLE, - OPT_REPLICATE_IGNORE_TABLE, OPT_REPLICATE_WILD_DO_TABLE, - OPT_REPLICATE_WILD_IGNORE_TABLE, - OPT_DISCONNECT_SLAVE_EVENT_COUNT, - OPT_ABORT_SLAVE_EVENT_COUNT, - OPT_INNODB_DATA_HOME_DIR, - OPT_INNODB_DATA_FILE_PATH, - OPT_INNODB_LOG_GROUP_HOME_DIR, - OPT_INNODB_LOG_ARCH_DIR, - OPT_INNODB_LOG_ARCHIVE, - OPT_INNODB_FLUSH_LOG_AT_TRX_COMMIT, - OPT_INNODB_FLUSH_METHOD, - OPT_INNODB_FAST_SHUTDOWN, - OPT_SAFE_SHOW_DB, - OPT_INNODB_SKIP, OPT_SKIP_SAFEMALLOC, - OPT_TEMP_POOL, OPT_TX_ISOLATION, - OPT_SKIP_STACK_TRACE, OPT_SKIP_SYMLINKS, - OPT_MAX_BINLOG_DUMP_EVENTS, OPT_SPORADIC_BINLOG_DUMP_FAIL, - OPT_SAFE_USER_CREATE, OPT_SQL_MODE, - OPT_HAVE_NAMED_PIPE, - OPT_DO_PSTACK, OPT_REPORT_HOST, - OPT_REPORT_USER, OPT_REPORT_PASSWORD, OPT_REPORT_PORT, - OPT_SHOW_SLAVE_AUTH_INFO, OPT_OLD_RPL_COMPAT, - OPT_SLAVE_LOAD_TMPDIR, OPT_NO_MIX_TYPE, - OPT_RPL_RECOVERY_RANK,OPT_INIT_RPL_ROLE, - OPT_RELAY_LOG, OPT_RELAY_LOG_INDEX, OPT_RELAY_LOG_INFO_FILE, - OPT_SLAVE_SKIP_ERRORS, OPT_DES_KEY_FILE, OPT_LOCAL_INFILE, - OPT_RECKLESS_SLAVE, - OPT_SSL_SSL, OPT_SSL_KEY, OPT_SSL_CERT, OPT_SSL_CA, - OPT_SSL_CAPATH, OPT_SSL_CIPHER, - OPT_BACK_LOG, OPT_BINLOG_CACHE_SIZE, - OPT_CONNECT_TIMEOUT, OPT_DELAYED_INSERT_TIMEOUT, - OPT_DELAYED_INSERT_LIMIT, OPT_DELAYED_QUEUE_SIZE, - OPT_FLUSH_TIME, OPT_FT_MIN_WORD_LEN, - OPT_FT_MAX_WORD_LEN, OPT_FT_MAX_WORD_LEN_FOR_SORT, - OPT_INTERACTIVE_TIMEOUT, OPT_JOIN_BUFF_SIZE, - OPT_KEY_BUFFER_SIZE, OPT_LONG_QUERY_TIME, - OPT_LOWER_CASE_TABLE_NAMES, OPT_MAX_ALLOWED_PACKET, - OPT_MAX_BINLOG_CACHE_SIZE, OPT_MAX_BINLOG_SIZE, - OPT_MAX_CONNECTIONS, OPT_MAX_CONNECT_ERRORS, - OPT_MAX_DELAYED_THREADS, OPT_MAX_HEP_TABLE_SIZE, - OPT_MAX_JOIN_SIZE, OPT_MAX_SORT_LENGTH, - OPT_MAX_TMP_TABLES, OPT_MAX_USER_CONNECTIONS, - OPT_MAX_WRITE_LOCK_COUNT, OPT_MYISAM_BULK_INSERT_TREE_SIZE, - OPT_MYISAM_BLOCK_SIZE, OPT_MYISAM_MAX_EXTRA_SORT_FILE_SIZE, - OPT_MYISAM_MAX_SORT_FILE_SIZE, OPT_MYISAM_SORT_BUFFER_SIZE, - OPT_NET_BUFFER_LENGTH, OPT_NET_RETRY_COUNT, - OPT_NET_READ_TIMEOUT, OPT_NET_WRITE_TIMEOUT, - OPT_OPEN_FILES_LIMIT, OPT_QUERY_BUFFER_SIZE, - OPT_QUERY_CACHE_LIMIT, OPT_QUERY_CACHE_SIZE, - OPT_QUERY_CACHE_STARTUP_TYPE, OPT_RECORD_BUFFER, - OPT_RECORD_RND_BUFFER, OPT_RELAY_LOG_SPACE_LIMIT, - OPT_SLAVE_NET_TIMEOUT, OPT_SLOW_LAUNCH_TIME, - OPT_SORT_BUFFER, OPT_TABLE_CACHE, - OPT_THREAD_CONCURRENCY, OPT_THREAD_CACHE_SIZE, - OPT_TMP_TABLE_SIZE, OPT_THREAD_STACK, - OPT_WAIT_TIMEOUT, - OPT_INNODB_MIRRORED_LOG_GROUPS, - OPT_INNODB_LOG_FILES_IN_GROUP, - OPT_INNODB_LOG_FILE_SIZE, - OPT_INNODB_LOG_BUFFER_SIZE, - OPT_INNODB_BUFFER_POOL_SIZE, - OPT_INNODB_ADDITIONAL_MEM_POOL_SIZE, - OPT_INNODB_FILE_IO_THREADS, - OPT_INNODB_LOCK_WAIT_TIMEOUT, - OPT_INNODB_THREAD_CONCURRENCY, - OPT_INNODB_FORCE_RECOVERY, - OPT_BDB_CACHE_SIZE, - OPT_BDB_LOG_BUFFER_SIZE, - OPT_BDB_MAX_LOCK + OPT_ISAM_LOG=256, OPT_SKIP_NEW, + OPT_SKIP_GRANT, OPT_SKIP_LOCK, + OPT_ENABLE_LOCK, OPT_USE_LOCKING, + OPT_SOCKET, OPT_UPDATE_LOG, + OPT_BIN_LOG, OPT_SKIP_RESOLVE, + OPT_SKIP_NETWORKING, OPT_BIN_LOG_INDEX, + OPT_BIND_ADDRESS, OPT_PID_FILE, + OPT_SKIP_PRIOR, OPT_BIG_TABLES, + OPT_STANDALONE, OPT_ONE_THREAD, + OPT_CONSOLE, OPT_LOW_PRIORITY_UPDATES, + OPT_SKIP_HOST_CACHE, OPT_LONG_FORMAT, + OPT_FLUSH, OPT_SAFE, + OPT_BOOTSTRAP, OPT_SKIP_SHOW_DB, + OPT_TABLE_TYPE, OPT_INIT_FILE, + OPT_DELAY_KEY_WRITE, OPT_SLOW_QUERY_LOG, + OPT_USE_DELAY_KEY_WRITE, OPT_CHARSETS_DIR, + OPT_BDB_HOME, OPT_BDB_LOG, + OPT_BDB_TMP, OPT_BDB_NOSYNC, + OPT_BDB_LOCK, OPT_BDB_SKIP, + OPT_BDB_NO_RECOVER, OPT_BDB_SHARED, + OPT_MASTER_HOST, OPT_MASTER_USER, + OPT_MASTER_PASSWORD, OPT_MASTER_PORT, + OPT_MASTER_INFO_FILE, OPT_MASTER_CONNECT_RETRY, + OPT_MASTER_RETRY_COUNT, + OPT_MASTER_SSL, OPT_MASTER_SSL_KEY, + OPT_MASTER_SSL_CERT, + OPT_SQL_BIN_UPDATE_SAME, OPT_REPLICATE_DO_DB, + OPT_REPLICATE_IGNORE_DB, OPT_LOG_SLAVE_UPDATES, + OPT_BINLOG_DO_DB, OPT_BINLOG_IGNORE_DB, + OPT_WANT_CORE, OPT_CONCURRENT_INSERT, + OPT_MEMLOCK, OPT_MYISAM_RECOVER, + OPT_REPLICATE_REWRITE_DB, OPT_SERVER_ID, + OPT_SKIP_SLAVE_START, OPT_SKIP_INNOBASE, + OPT_SAFEMALLOC_MEM_LIMIT, OPT_REPLICATE_DO_TABLE, + OPT_REPLICATE_IGNORE_TABLE, OPT_REPLICATE_WILD_DO_TABLE, + OPT_REPLICATE_WILD_IGNORE_TABLE, + OPT_DISCONNECT_SLAVE_EVENT_COUNT, + OPT_ABORT_SLAVE_EVENT_COUNT, + OPT_INNODB_DATA_HOME_DIR, + OPT_INNODB_DATA_FILE_PATH, + OPT_INNODB_LOG_GROUP_HOME_DIR, + OPT_INNODB_LOG_ARCH_DIR, + OPT_INNODB_LOG_ARCHIVE, + OPT_INNODB_FLUSH_LOG_AT_TRX_COMMIT, + OPT_INNODB_FLUSH_METHOD, + OPT_INNODB_FAST_SHUTDOWN, + OPT_SAFE_SHOW_DB, + OPT_INNODB_SKIP, OPT_SKIP_SAFEMALLOC, + OPT_TEMP_POOL, OPT_TX_ISOLATION, + OPT_SKIP_STACK_TRACE, OPT_SKIP_SYMLINKS, + OPT_MAX_BINLOG_DUMP_EVENTS, OPT_SPORADIC_BINLOG_DUMP_FAIL, + OPT_SAFE_USER_CREATE, OPT_SQL_MODE, + OPT_HAVE_NAMED_PIPE, + OPT_DO_PSTACK, OPT_REPORT_HOST, + OPT_REPORT_USER, OPT_REPORT_PASSWORD, OPT_REPORT_PORT, + OPT_SHOW_SLAVE_AUTH_INFO, OPT_OLD_RPL_COMPAT, + OPT_SLAVE_LOAD_TMPDIR, OPT_NO_MIX_TYPE, + OPT_RPL_RECOVERY_RANK,OPT_INIT_RPL_ROLE, + OPT_RELAY_LOG, OPT_RELAY_LOG_INDEX, OPT_RELAY_LOG_INFO_FILE, + OPT_SLAVE_SKIP_ERRORS, OPT_DES_KEY_FILE, OPT_LOCAL_INFILE, + OPT_RECKLESS_SLAVE, + OPT_SSL_SSL, OPT_SSL_KEY, OPT_SSL_CERT, OPT_SSL_CA, + OPT_SSL_CAPATH, OPT_SSL_CIPHER, + OPT_BACK_LOG, OPT_BINLOG_CACHE_SIZE, + OPT_CONNECT_TIMEOUT, OPT_DELAYED_INSERT_TIMEOUT, + OPT_DELAYED_INSERT_LIMIT, OPT_DELAYED_QUEUE_SIZE, + OPT_FLUSH_TIME, OPT_FT_MIN_WORD_LEN, + OPT_FT_MAX_WORD_LEN, OPT_FT_MAX_WORD_LEN_FOR_SORT, + OPT_INTERACTIVE_TIMEOUT, OPT_JOIN_BUFF_SIZE, + OPT_KEY_BUFFER_SIZE, OPT_LONG_QUERY_TIME, + OPT_LOWER_CASE_TABLE_NAMES, OPT_MAX_ALLOWED_PACKET, + OPT_MAX_BINLOG_CACHE_SIZE, OPT_MAX_BINLOG_SIZE, + OPT_MAX_CONNECTIONS, OPT_MAX_CONNECT_ERRORS, + OPT_MAX_DELAYED_THREADS, OPT_MAX_HEP_TABLE_SIZE, + OPT_MAX_JOIN_SIZE, OPT_MAX_SORT_LENGTH, + OPT_MAX_TMP_TABLES, OPT_MAX_USER_CONNECTIONS, + OPT_MAX_WRITE_LOCK_COUNT, OPT_MYISAM_BULK_INSERT_TREE_SIZE, + OPT_MYISAM_BLOCK_SIZE, OPT_MYISAM_MAX_EXTRA_SORT_FILE_SIZE, + OPT_MYISAM_MAX_SORT_FILE_SIZE, OPT_MYISAM_SORT_BUFFER_SIZE, + OPT_NET_BUFFER_LENGTH, OPT_NET_RETRY_COUNT, + OPT_NET_READ_TIMEOUT, OPT_NET_WRITE_TIMEOUT, + OPT_OPEN_FILES_LIMIT, OPT_QUERY_BUFFER_SIZE, + OPT_QUERY_CACHE_LIMIT, OPT_QUERY_CACHE_SIZE, + OPT_QUERY_CACHE_STARTUP_TYPE, OPT_RECORD_BUFFER, + OPT_RECORD_RND_BUFFER, OPT_RELAY_LOG_SPACE_LIMIT, + OPT_SLAVE_NET_TIMEOUT, OPT_SLOW_LAUNCH_TIME, + OPT_SORT_BUFFER, OPT_TABLE_CACHE, + OPT_THREAD_CONCURRENCY, OPT_THREAD_CACHE_SIZE, + OPT_TMP_TABLE_SIZE, OPT_THREAD_STACK, + OPT_WAIT_TIMEOUT, + OPT_INNODB_MIRRORED_LOG_GROUPS, + OPT_INNODB_LOG_FILES_IN_GROUP, + OPT_INNODB_LOG_FILE_SIZE, + OPT_INNODB_LOG_BUFFER_SIZE, + OPT_INNODB_BUFFER_POOL_SIZE, + OPT_INNODB_ADDITIONAL_MEM_POOL_SIZE, + OPT_INNODB_FILE_IO_THREADS, + OPT_INNODB_LOCK_WAIT_TIMEOUT, + OPT_INNODB_THREAD_CONCURRENCY, + OPT_INNODB_FORCE_RECOVERY, + OPT_BDB_CACHE_SIZE, + OPT_BDB_LOG_BUFFER_SIZE, + OPT_BDB_MAX_LOCK }; @@ -4020,123 +4022,125 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), opt_bin_log=1; break; case (int) OPT_INIT_RPL_ROLE: + { + int role; + if ((role=find_type(argument, &rpl_role_typelib, 2)) <= 0) { - int role; - if ((role=find_type(argument, &rpl_role_typelib, 2)) <= 0) - { - fprintf(stderr, "Unknown replication role: %s\n", argument); - exit(1); - } - rpl_status = (role == 1) ? RPL_AUTH_MASTER : RPL_IDLE_SLAVE; - break; + fprintf(stderr, "Unknown replication role: %s\n", argument); + exit(1); } + rpl_status = (role == 1) ? RPL_AUTH_MASTER : RPL_IDLE_SLAVE; + break; + } case (int)OPT_REPLICATE_IGNORE_DB: + { + i_string *db = new i_string(argument); + replicate_ignore_db.push_back(db); + break; + } + case (int)OPT_REPLICATE_DO_DB: + { + i_string *db = new i_string(argument); + replicate_do_db.push_back(db); + break; + } + case (int)OPT_REPLICATE_REWRITE_DB: + { + char* key = argument,*p, *val; + + if (!(p= strstr(argument, "->"))) { - i_string *db = new i_string(argument); - replicate_ignore_db.push_back(db); - break; + fprintf(stderr, + "Bad syntax in replicate-rewrite-db - missing '->'!\n"); + exit(1); } - case (int)OPT_REPLICATE_DO_DB: + val= p--; + while (isspace(*p) && p > argument) + *p-- = 0; + if (p == argument) { - i_string *db = new i_string(argument); - replicate_do_db.push_back(db); - break; + fprintf(stderr, + "Bad syntax in replicate-rewrite-db - empty FROM db!\n"); + exit(1); } - case (int)OPT_REPLICATE_REWRITE_DB: + *val= 0; + val+= 2; + while (*val && isspace(*val)) + *val++; + if (!*val) { - char* key = argument,*p, *val; - p = strstr(argument, "->"); - if (!p) - { - fprintf(stderr, - "Bad syntax in replicate-rewrite-db - missing '->'!\n"); - exit(1); - } - val = p--; - while(isspace(*p) && p > argument) *p-- = 0; - if(p == argument) - { - fprintf(stderr, - "Bad syntax in replicate-rewrite-db - empty FROM db!\n"); - exit(1); - } - *val = 0; - val += 2; - while(*val && isspace(*val)) *val++; - if (!*val) - { - fprintf(stderr, - "Bad syntax in replicate-rewrite-db - empty TO db!\n"); - exit(1); - } - - i_string_pair* db_pair = new i_string_pair(key, val); - replicate_rewrite_db.push_back(db_pair); - break; + fprintf(stderr, + "Bad syntax in replicate-rewrite-db - empty TO db!\n"); + exit(1); } + i_string_pair *db_pair = new i_string_pair(key, val); + replicate_rewrite_db.push_back(db_pair); + break; + } + case (int)OPT_BINLOG_IGNORE_DB: - { - i_string *db = new i_string(argument); - binlog_ignore_db.push_back(db); - break; - } + { + i_string *db = new i_string(argument); + binlog_ignore_db.push_back(db); + break; + } case (int)OPT_BINLOG_DO_DB: - { - i_string *db = new i_string(argument); - binlog_do_db.push_back(db); - break; - } + { + i_string *db = new i_string(argument); + binlog_do_db.push_back(db); + break; + } case (int)OPT_REPLICATE_DO_TABLE: + { + if (!do_table_inited) + init_table_rule_hash(&replicate_do_table, &do_table_inited); + if (add_table_rule(&replicate_do_table, argument)) { - if (!do_table_inited) - init_table_rule_hash(&replicate_do_table, &do_table_inited); - if(add_table_rule(&replicate_do_table, argument)) - { - fprintf(stderr, "Could not add do table rule '%s'!\n", argument); - exit(1); - } - table_rules_on = 1; - break; + fprintf(stderr, "Could not add do table rule '%s'!\n", argument); + exit(1); } + table_rules_on = 1; + break; + } case (int)OPT_REPLICATE_WILD_DO_TABLE: + { + if (!wild_do_table_inited) + init_table_rule_array(&replicate_wild_do_table, + &wild_do_table_inited); + if (add_wild_table_rule(&replicate_wild_do_table, argument)) { - if (!wild_do_table_inited) - init_table_rule_array(&replicate_wild_do_table, - &wild_do_table_inited); - if(add_wild_table_rule(&replicate_wild_do_table, argument)) - { - fprintf(stderr, "Could not add do table rule '%s'!\n", argument); - exit(1); - } - table_rules_on = 1; - break; + fprintf(stderr, "Could not add do table rule '%s'!\n", argument); + exit(1); } + table_rules_on = 1; + break; + } case (int)OPT_REPLICATE_WILD_IGNORE_TABLE: + { + if (!wild_ignore_table_inited) + init_table_rule_array(&replicate_wild_ignore_table, + &wild_ignore_table_inited); + if (add_wild_table_rule(&replicate_wild_ignore_table, argument)) { - if (!wild_ignore_table_inited) - init_table_rule_array(&replicate_wild_ignore_table, - &wild_ignore_table_inited); - if(add_wild_table_rule(&replicate_wild_ignore_table, argument)) - { - fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument); - exit(1); - } - table_rules_on = 1; - break; + fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument); + exit(1); } + table_rules_on = 1; + break; + } case (int)OPT_REPLICATE_IGNORE_TABLE: + { + if (!ignore_table_inited) + init_table_rule_hash(&replicate_ignore_table, &ignore_table_inited); + if (add_table_rule(&replicate_ignore_table, argument)) { - if (!ignore_table_inited) - init_table_rule_hash(&replicate_ignore_table, &ignore_table_inited); - if(add_table_rule(&replicate_ignore_table, argument)) - { - fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument); - exit(1); - } - table_rules_on = 1; - break; + fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument); + exit(1); } + table_rules_on = 1; + break; + } case (int) OPT_SLOW_QUERY_LOG: opt_slow_log=1; break; @@ -4260,16 +4264,16 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), opt_noacl=opt_bootstrap=1; break; case OPT_TABLE_TYPE: + { + int type; + if ((type=find_type(argument, &ha_table_typelib, 2)) <= 0) { - int type; - if ((type=find_type(argument, &ha_table_typelib, 2)) <= 0) - { - fprintf(stderr,"Unknown table type: %s\n",argument); - exit(1); - } - default_table_type= (enum db_type) type; - break; + fprintf(stderr,"Unknown table type: %s\n",argument); + exit(1); } + default_table_type= (enum db_type) type; + break; + } case OPT_SERVER_ID: server_id_supplied = 1; break; @@ -4293,16 +4297,16 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), #endif break; case OPT_TX_ISOLATION: + { + int type; + if ((type=find_type(argument, &tx_isolation_typelib, 2)) <= 0) { - int type; - if ((type=find_type(argument, &tx_isolation_typelib, 2)) <= 0) - { - fprintf(stderr,"Unknown transaction isolation type: %s\n",argument); - exit(1); - } - default_tx_isolation= (enum_tx_isolation) (type-1); - break; + fprintf(stderr,"Unknown transaction isolation type: %s\n",argument); + exit(1); } + default_tx_isolation= (enum_tx_isolation) (type-1); + break; + } #ifdef HAVE_BERKELEY_DB case OPT_BDB_NOSYNC: berkeley_env_flags|=DB_TXN_NOSYNC; @@ -4311,22 +4315,22 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), berkeley_init_flags&= ~(DB_RECOVER); break; case OPT_BDB_LOCK: + { + int type; + if ((type=find_type(argument, &berkeley_lock_typelib, 2)) > 0) + berkeley_lock_type=berkeley_lock_types[type-1]; + else { - int type; - if ((type=find_type(argument, &berkeley_lock_typelib, 2)) > 0) - berkeley_lock_type=berkeley_lock_types[type-1]; + if (test_if_int(argument,(uint) strlen(argument))) + berkeley_lock_scan_time=atoi(argument); else { - if (test_if_int(argument,(uint) strlen(argument))) - berkeley_lock_scan_time=atoi(argument); - else - { - fprintf(stderr,"Unknown lock type: %s\n",argument); - exit(1); - } + fprintf(stderr,"Unknown lock type: %s\n",argument); + exit(1); } - break; } + break; + } case OPT_BDB_SHARED: berkeley_init_flags&= ~(DB_PRIVATE); berkeley_shared_data=1; @@ -4361,39 +4365,39 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), break; #endif /* HAVE_INNOBASE_DB */ case OPT_MYISAM_RECOVER: + { + if (!argument || !argument[0]) { - if (!argument || !argument[0]) - { - myisam_recover_options= HA_RECOVER_DEFAULT; - myisam_recover_options_str= myisam_recover_typelib.type_names[0]; - } - else - { - myisam_recover_options_str=argument; - if ((myisam_recover_options= - find_bit_type(argument, &myisam_recover_typelib)) == ~(ulong) 0) - { - fprintf(stderr, "Unknown option to myisam-recover: %s\n",argument); - exit(1); - } - } - ha_open_options|=HA_OPEN_ABORT_IF_CRASHED; - break; + myisam_recover_options= HA_RECOVER_DEFAULT; + myisam_recover_options_str= myisam_recover_typelib.type_names[0]; } - case OPT_SQL_MODE: + else { - sql_mode_str = argument; - if ((opt_sql_mode = - find_bit_type(argument, &sql_mode_typelib)) == ~(ulong) 0) + myisam_recover_options_str=argument; + if ((myisam_recover_options= + find_bit_type(argument, &myisam_recover_typelib)) == ~(ulong) 0) { - fprintf(stderr, "Unknown option to sql-mode: %s\n", argument); + fprintf(stderr, "Unknown option to myisam-recover: %s\n",argument); exit(1); } - default_tx_isolation= ((opt_sql_mode & MODE_SERIALIZABLE) ? - ISO_SERIALIZABLE : - ISO_READ_COMMITTED); - break; } + ha_open_options|=HA_OPEN_ABORT_IF_CRASHED; + break; + } + case OPT_SQL_MODE: + { + sql_mode_str = argument; + if ((opt_sql_mode = + find_bit_type(argument, &sql_mode_typelib)) == ~(ulong) 0) + { + fprintf(stderr, "Unknown option to sql-mode: %s\n", argument); + exit(1); + } + default_tx_isolation= ((opt_sql_mode & MODE_SERIALIZABLE) ? + ISO_SERIALIZABLE : + ISO_READ_COMMITTED); + break; + } case OPT_MASTER_PASSWORD: master_password=argument; break; @@ -4576,10 +4580,10 @@ static uint set_maximum_open_files(uint max_file_limit) } #endif - /* - Return a bitfield from a string of substrings separated by ',' - returns ~(ulong) 0 on error. - */ +/* + Return a bitfield from a string of substrings separated by ',' + returns ~(ulong) 0 on error. +*/ static ulong find_bit_type(const char *x, TYPELIB *bit_lib) { @@ -4637,7 +4641,7 @@ skipp: ; /***************************************************************************** -** Instantiate templates + Instantiate templates *****************************************************************************/ #ifdef __GNUC__ diff --git a/sql/net_pkg.cc b/sql/net_pkg.cc index 1ab3e18424f..f7c28d3d7fe 100644 --- a/sql/net_pkg.cc +++ b/sql/net_pkg.cc @@ -87,9 +87,9 @@ void send_warning(NET *net, uint sql_errno, const char *err) DBUG_VOID_RETURN; } -/** -** write error package and flush to client -** It's a little too low level, but I don't want to allow another buffer +/* + Write error package and flush to client + It's a little too low level, but I don't want to allow another buffer */ /* VARARGS3 */ @@ -339,9 +339,9 @@ bool net_store_data(String* packet, I_List<i_string>* str_list) I_List_iterator<i_string> it(*str_list); i_string* s; - while((s=it++)) + while ((s=it++)) { - if(tmp.length()) + if (tmp.length()) tmp.append(','); tmp.append(s->ptr); } diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 0d6e548a873..f9bef94470c 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -815,7 +815,7 @@ my_net_read(NET *net) return len; } -int net_request_file(NET* net, const char* fname) +bool net_request_file(NET* net, const char* fname) { char tmp [FN_REFLEN+1],*end; DBUG_ENTER("net_request_file"); diff --git a/sql/nt_servc.cc b/sql/nt_servc.cc index be2ceb9cb7a..129df9864e2 100644 --- a/sql/nt_servc.cc +++ b/sql/nt_servc.cc @@ -501,11 +501,9 @@ BOOL NTService::IsService(LPCSTR ServiceName) -------------------------------------------------------------------------- */ BOOL NTService::got_service_option(char **argv, char *service_option) { - char *option = argv[1]; - - while (*option) - if (!strcmp(option++, service_option)) - return TRUE; - + char *option; + for (option= argv[1]; *option; option++) + if (!strcmp(option, service_option)) + return TRUE; return FALSE; } diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 7d2d04dbdf1..1d30437e15a 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -885,7 +885,7 @@ get_mm_parts(PARAM *param,Field *field, Item_func::Functype type,Item *value, if (value && value->used_tables() & ~(param->prev_tables | param->read_tables)) DBUG_RETURN(0); - for ( ; key_part != end ; key_part++) + for (; key_part != end ; key_part++) { if (field->eq(key_part->field)) { diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc index 961047d883a..6645f7a1eed 100644 --- a/sql/repl_failsafe.cc +++ b/sql/repl_failsafe.cc @@ -40,16 +40,20 @@ const char *rpl_role_type[] = {"MASTER","SLAVE",NullS}; TYPELIB rpl_role_typelib = {array_elements(rpl_role_type)-1,"", rpl_role_type}; -const char* rpl_status_type[] = {"AUTH_MASTER","ACTIVE_SLAVE","IDLE_SLAVE", - "LOST_SOLDIER","TROOP_SOLDIER", - "RECOVERY_CAPTAIN","NULL",NullS}; +const char* rpl_status_type[]= +{ + "AUTH_MASTER","ACTIVE_SLAVE","IDLE_SLAVE", "LOST_SOLDIER","TROOP_SOLDIER", + "RECOVERY_CAPTAIN","NULL",NullS +}; TYPELIB rpl_status_typelib= {array_elements(rpl_status_type)-1,"", rpl_status_type}; + static Slave_log_event* find_slave_event(IO_CACHE* log, const char* log_file_name, char* errmsg); + static int init_failsafe_rpl_thread(THD* thd) { DBUG_ENTER("init_failsafe_rpl_thread"); @@ -93,6 +97,7 @@ static int init_failsafe_rpl_thread(THD* thd) DBUG_RETURN(0); } + void change_rpl_status(RPL_STATUS from_status, RPL_STATUS to_status) { pthread_mutex_lock(&LOCK_rpl_status); @@ -102,6 +107,7 @@ void change_rpl_status(RPL_STATUS from_status, RPL_STATUS to_status) pthread_mutex_unlock(&LOCK_rpl_status); } + #define get_object(p, obj) \ {\ uint len = (uint)*p++; \ @@ -111,28 +117,33 @@ void change_rpl_status(RPL_STATUS from_status, RPL_STATUS to_status) p+= len; \ }\ + static inline int cmp_master_pos(Slave_log_event* sev, LEX_MASTER_INFO* mi) { return cmp_master_pos(sev->master_log, sev->master_pos, mi->log_file_name, mi->pos); } + void unregister_slave(THD* thd, bool only_mine, bool need_mutex) { - if (need_mutex) - pthread_mutex_lock(&LOCK_slave_list); if (thd->server_id) { + if (need_mutex) + pthread_mutex_lock(&LOCK_slave_list); + SLAVE_INFO* old_si; if ((old_si = (SLAVE_INFO*)hash_search(&slave_list, (byte*)&thd->server_id, 4)) && (!only_mine || old_si->thd == thd)) hash_delete(&slave_list, (byte*)old_si); + + if (need_mutex) + pthread_mutex_unlock(&LOCK_slave_list); } - if (need_mutex) - pthread_mutex_unlock(&LOCK_slave_list); } + int register_slave(THD* thd, uchar* packet, uint packet_length) { SLAVE_INFO *si; @@ -199,16 +210,15 @@ void end_slave_list() } } -static int find_target_pos(LEX_MASTER_INFO* mi, IO_CACHE* log, char* errmsg) +static int find_target_pos(LEX_MASTER_INFO *mi, IO_CACHE *log, char *errmsg) { - uint32 log_pos = (uint32) mi->pos; + my_off_t log_pos = (my_off_t) mi->pos; uint32 target_server_id = mi->server_id; for (;;) { Log_event* ev; - if (!(ev = Log_event::read_log_event(log, (pthread_mutex_t*)0, - 0))) + if (!(ev = Log_event::read_log_event(log, (pthread_mutex_t*) 0, 0))) { if (log->error > 0) strmov(errmsg, "Binary log truncated in the middle of event"); @@ -225,9 +235,9 @@ static int find_target_pos(LEX_MASTER_INFO* mi, IO_CACHE* log, char* errmsg) mi->pos = my_b_tell(log); return 0; } - delete ev; } + /* Impossible */ } @@ -258,8 +268,6 @@ int translate_master(THD* thd, LEX_MASTER_INFO* mi, char* errmsg) } linfo.index_file_offset = 0; - - search_file_name[0] = 0; if (mysql_bin_log.find_first_log(&linfo, search_file_name)) @@ -357,7 +365,11 @@ err: return error; } -// caller must delete result when done + +/* + Caller must delete result when done +*/ + static Slave_log_event* find_slave_event(IO_CACHE* log, const char* log_file_name, char* errmsg) @@ -431,6 +443,7 @@ int show_new_master(THD* thd) } } + int update_slave_list(MYSQL* mysql) { MYSQL_RES* res=0; @@ -446,8 +459,7 @@ int update_slave_list(MYSQL* mysql) goto err; } - switch (mc_mysql_num_fields(res)) - { + switch (mc_mysql_num_fields(res)) { case 5: have_auth_info = 0; port_ind=2; @@ -463,13 +475,13 @@ int update_slave_list(MYSQL* mysql) pthread_mutex_lock(&LOCK_slave_list); - while ((row = mc_mysql_fetch_row(res))) + while ((row= mc_mysql_fetch_row(res))) { uint32 server_id; SLAVE_INFO* si, *old_si; server_id = atoi(row[0]); - if ((old_si = (SLAVE_INFO*)hash_search(&slave_list, - (byte*)&server_id,4))) + if ((old_si= (SLAVE_INFO*)hash_search(&slave_list, + (byte*)&server_id,4))) si = old_si; else { @@ -482,17 +494,18 @@ int update_slave_list(MYSQL* mysql) si->server_id = server_id; hash_insert(&slave_list, (byte*)si); } - strnmov(si->host, row[1], sizeof(si->host)); + strmake(si->host, row[1], sizeof(si->host)-1); si->port = atoi(row[port_ind]); si->rpl_recovery_rank = atoi(row[port_ind+1]); si->master_id = atoi(row[port_ind+2]); if (have_auth_info) { - strnmov(si->user, row[2], sizeof(si->user)); - strnmov(si->password, row[3], sizeof(si->password)); + strmake(si->user, row[2], sizeof(si->user)-1); + strmake(si->password, row[3], sizeof(si->password)-1); } } pthread_mutex_unlock(&LOCK_slave_list); + err: if (res) mc_mysql_free_result(res); @@ -504,12 +517,13 @@ err: return 0; } + int find_recovery_captain(THD* thd, MYSQL* mysql) { - return 0; } + pthread_handler_decl(handle_failsafe_rpl,arg) { DBUG_ENTER("handle_failsafe_rpl"); @@ -532,8 +546,7 @@ pthread_handler_decl(handle_failsafe_rpl,arg) thd->proc_info="Processing request"; while (!break_req_chain) { - switch (rpl_status) - { + switch (rpl_status) { case RPL_LOST_SOLDIER: if (find_recovery_captain(thd, recovery_captain)) rpl_status=RPL_TROOP_SOLDIER; @@ -558,6 +571,7 @@ err: DBUG_RETURN(0); } + int show_slave_hosts(THD* thd) { List<Item> field_list; @@ -606,6 +620,7 @@ int show_slave_hosts(THD* thd) DBUG_RETURN(0); } + int connect_to_master(THD *thd, MYSQL* mysql, MASTER_INFO* mi) { if (!mi->host || !*mi->host) /* empty host */ @@ -623,9 +638,9 @@ int connect_to_master(THD *thd, MYSQL* mysql, MASTER_INFO* mi) static inline void cleanup_mysql_results(MYSQL_RES* db_res, - MYSQL_RES** cur, MYSQL_RES** start) + MYSQL_RES** cur, MYSQL_RES** start) { - for( ; cur >= start; --cur) + for (; cur >= start; --cur) { if (*cur) mc_mysql_free_result(*cur); @@ -638,7 +653,7 @@ static inline int fetch_db_tables(THD* thd, MYSQL* mysql, const char* db, MYSQL_RES* table_res, MASTER_INFO* mi) { MYSQL_ROW row; - for( row = mc_mysql_fetch_row(table_res); row; + for (row = mc_mysql_fetch_row(table_res); row; row = mc_mysql_fetch_row(table_res)) { TABLE_LIST table; @@ -690,7 +705,7 @@ int load_master_data(THD* thd) if (connect_to_master(thd, &mysql, active_mi)) { net_printf(&thd->net, error = ER_CONNECT_TO_MASTER, - mc_mysql_error(&mysql)); + mc_mysql_error(&mysql)); goto err; } @@ -742,8 +757,8 @@ int load_master_data(THD* thd) table_res_end = table_res + num_dbs; - for(cur_table_res = table_res; cur_table_res < table_res_end; - cur_table_res++) + for (cur_table_res = table_res; cur_table_res < table_res_end; + cur_table_res++) { // since we know how many rows we have, this can never be NULL MYSQL_ROW row = mc_mysql_fetch_row(db_res); @@ -761,7 +776,7 @@ int load_master_data(THD* thd) */ if (!db_ok(db, replicate_do_db, replicate_ignore_db) || - !strcmp(db,"mysql")) + !strcmp(db,"mysql")) { *cur_table_res = 0; continue; @@ -777,7 +792,7 @@ int load_master_data(THD* thd) if (mc_mysql_select_db(&mysql, db) || mc_mysql_query(&mysql, "show tables", 0) || - !(*cur_table_res = mc_mysql_store_result(&mysql))) + !(*cur_table_res = mc_mysql_store_result(&mysql))) { net_printf(&thd->net, error = ER_QUERY_ON_MASTER, mc_mysql_error(&mysql)); @@ -804,7 +819,7 @@ int load_master_data(THD* thd) We need this check because the master may not be running with log-bin, but it will still allow us to do all the steps of LOAD DATA FROM MASTER - no reason to forbid it, really, - although it does not make much sense for the user to do it + although it does not make much sense for the user to do it */ if (row[0] && row[1]) { @@ -838,18 +853,18 @@ int load_master_data(THD* thd) } pthread_mutex_lock(&active_mi->rli.data_lock); active_mi->rli.master_log_pos = active_mi->master_log_pos; - strnmov(active_mi->rli.master_log_name,active_mi->master_log_name, - sizeof(active_mi->rli.master_log_name)); + strmake(active_mi->rli.master_log_name,active_mi->master_log_name, + sizeof(active_mi->rli.master_log_name)-1); flush_relay_log_info(&active_mi->rli); pthread_cond_broadcast(&active_mi->rli.data_cond); pthread_mutex_unlock(&active_mi->rli.data_lock); thd->proc_info = "starting slave"; if (restart_thread_mask) { - error=start_slave_threads(0 /* mutex not needed*/, - 1 /* wait for start*/, - active_mi,master_info_file,relay_log_info_file, - restart_thread_mask); + error=start_slave_threads(0 /* mutex not needed */, + 1 /* wait for start */, + active_mi,master_info_file,relay_log_info_file, + restart_thread_mask); } err: diff --git a/sql/slave.cc b/sql/slave.cc index a6205e18192..fc51c483131 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -221,8 +221,8 @@ int init_relay_log_pos(RELAY_LOG_INFO* rli,const char* log, *errmsg="Could not find target log during relay log initialization"; goto err; } - strnmov(rli->relay_log_name,rli->linfo.log_file_name, - sizeof(rli->relay_log_name)); + strmake(rli->relay_log_name,rli->linfo.log_file_name, + sizeof(rli->relay_log_name)-1); // to make end_io_cache(&rli->cache_buf) safe in all cases if (!rli->inited) bzero((char*) &rli->cache_buf, sizeof(IO_CACHE)); @@ -315,7 +315,7 @@ int purge_relay_logs(RELAY_LOG_INFO* rli, bool just_reset, const char** errmsg) error=1; goto err; } - strnmov(rli->relay_log_name,rli->linfo.log_file_name, + strmake(rli->relay_log_name,rli->linfo.log_file_name, sizeof(rli->relay_log_name)-1); // Just first log with magic number and nothing else rli->log_space_total= BIN_LOG_HEADER_SIZE; @@ -635,7 +635,7 @@ int add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec) static void free_string_array(DYNAMIC_ARRAY *a) { uint i; - for(i = 0; i < a->elements; i++) + for (i = 0; i < a->elements; i++) { char* p; get_dynamic(a, (gptr) &p, i); @@ -2656,8 +2656,8 @@ Log_event* next_event(RELAY_LOG_INFO* rli) } rli->relay_log_pos = BIN_LOG_HEADER_SIZE; rli->pending=0; - strnmov(rli->relay_log_name,rli->linfo.log_file_name, - sizeof(rli->relay_log_name)); + strmake(rli->relay_log_name,rli->linfo.log_file_name, + sizeof(rli->relay_log_name)-1); flush_relay_log_info(rli); } diff --git a/sql/slave.h b/sql/slave.h index d6992a8b839..8657566654a 100644 --- a/sql/slave.h +++ b/sql/slave.h @@ -70,6 +70,7 @@ struct st_master_info; typedef struct st_relay_log_info { /*** The following variables can only be read when protect by data lock ****/ + /* info_fd - file descriptor of the info file. set only during initialization or clean up - safe to read anytime @@ -126,7 +127,7 @@ typedef struct st_relay_log_info uint32 cur_log_old_open_count; /* - current offset in the relay log. + Current offset in the relay log. pending - in some cases we do not increment offset immediately after processing an event, because the following event needs to be processed atomically together with this one ( so far, there is only one type of diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 0b2d4ad76e8..7657bdd8133 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -255,7 +255,7 @@ int acl_init(bool dont_read_acl_tables) protocol_version == PROTOCOL_VERSION) { sql_print_error( - "Found old style password for user '%s'. Ignoring user. (You may want to restart using --old-protocol)", + "Found old style password for user '%s'. Ignoring user. (You may want to restart mysqld using --old-protocol)", user.user ? user.user : ""); /* purecov: tested */ } else if (length % 8) // This holds true for passwords @@ -269,8 +269,9 @@ int acl_init(bool dont_read_acl_tables) get_salt_from_password(user.salt,user.password); user.access=get_access(table,3); user.sort=get_sort(2,user.host.hostname,user.user); - user.hostname_length=user.host.hostname ? (uint) strlen(user.host.hostname) : 0; - if (table->fields >=23) + user.hostname_length= (user.host.hostname ? + (uint) strlen(user.host.hostname) : 0); + if (table->fields >= 23) { /* Table has new MySQL usage limits */ char *ptr = get_field(&mem, table, 21); @@ -279,7 +280,8 @@ int acl_init(bool dont_read_acl_tables) user.user_resource.updates=atoi(ptr); ptr = get_field(&mem, table, 23); user.user_resource.connections=atoi(ptr); - if (user.user_resource.questions || user.user_resource.updates || user.user_resource.connections) + if (user.user_resource.questions || user.user_resource.updates || + user.user_resource.connections) mqh_used=1; } else @@ -829,7 +831,7 @@ int wild_case_compare(const char *str,const char *wildstr) { reg3 int flag; DBUG_ENTER("wild_case_compare"); - DBUG_PRINT("enter",("str='%s', wildstr='%s'",str,wildstr)); + DBUG_PRINT("enter",("str: '%s' wildstr: '%s'",str,wildstr)); while (*wildstr) { while (*wildstr && *wildstr != wild_many && *wildstr != wild_one) @@ -954,7 +956,8 @@ bool change_password(THD *thd, const char *host, const char *user, { uint length=0; DBUG_ENTER("change_password"); - DBUG_PRINT("enter",("thd=%x, host='%s', user='%s', new_password='%s'",thd,host,user,new_password)); + DBUG_PRINT("enter",("host: '%s' user: '%s' new_password: '%s'", + host,user,new_password)); if (!initialized) { @@ -1027,7 +1030,7 @@ static ACL_USER * find_acl_user(const char *host, const char *user) { DBUG_ENTER("find_acl_user"); - DBUG_PRINT("enter",("host='%s', user='%s'",host,user)); + DBUG_PRINT("enter",("host: '%s' user: '%s'",host,user)); for (uint i=0 ; i < acl_users.elements ; i++) { ACL_USER *acl_user=dynamic_element(&acl_users,i,ACL_USER*); @@ -1238,7 +1241,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, rights=get_access(table,3); #ifdef HAVE_OPENSSL /* We write down SSL related ACL stuff */ - DBUG_PRINT("info",("table->fields=%d",table->fields)); + DBUG_PRINT("info",("table->fields: %d",table->fields)); if (table->fields >= 21) /* From 4.0.0 we have more fields */ { table->field[18]->store("",0); @@ -1883,9 +1886,9 @@ int mysql_table_grant (THD *thd, TABLE_LIST *table_list, TABLE_LIST tables[3]; bool create_new_users=0; DBUG_ENTER("mysql_table_grant"); - DBUG_PRINT("info",("ssl_cipher=%s",thd->lex.ssl_cipher)); - DBUG_PRINT("info",("x509_issuer=%s",thd->lex.x509_issuer)); - DBUG_PRINT("info",("x509_subject=%s",thd->lex.x509_subject)); + DBUG_PRINT("info",("ssl_cipher: %s",thd->lex.ssl_cipher)); + DBUG_PRINT("info",("x509_issuer: %s",thd->lex.x509_issuer)); + DBUG_PRINT("info",("x509_subject: %s",thd->lex.x509_subject)); if (!initialized) { @@ -2601,7 +2604,6 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) { uint counter, want_access,index; int error = 0; - int ssl_options = 0; ACL_USER *acl_user; ACL_DB *acl_db; char buff[1024]; DBUG_ENTER("mysql_show_grants"); @@ -2699,18 +2701,18 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) /* "show grants" SSL related stuff */ if (acl_user->ssl_type == SSL_TYPE_ANY) global.append(" REQUIRE SSL",12); - else if (acl_user->ssl_type==SSL_TYPE_X509) + else if (acl_user->ssl_type == SSL_TYPE_X509) global.append(" REQUIRE X509",13); - else if (acl_user->ssl_type==SSL_TYPE_SPECIFIED) + else if (acl_user->ssl_type == SSL_TYPE_SPECIFIED) { + int ssl_options = 0; global.append(" REQUIRE ",9); if (acl_user->x509_issuer) { - if (ssl_options++) - global.append(" AND ",5); + ssl_options++; global.append("ISSUER \"",8); global.append(acl_user->x509_issuer,strlen(acl_user->x509_issuer)); - global.append("\"",1); + global.append('\''); } if (acl_user->x509_subject) { @@ -2718,15 +2720,15 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) global.append(" AND ",5); global.append("SUBJECT \"",9); global.append(acl_user->x509_subject,strlen(acl_user->x509_subject)); - global.append("\"",1); + global.append('\''); } if (acl_user->ssl_cipher) { if (ssl_options++) global.append(" AND ",5); - global.append("CIPHER \"",8); + global.append("CIPHER '",8); global.append(acl_user->ssl_cipher,strlen(acl_user->ssl_cipher)); - global.append("\"",1); + global.append('\''); } } #endif /* HAVE_OPENSSL */ @@ -2735,21 +2737,21 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) if (acl_user->user_resource.questions) { char buff[65], *p; // just as in int2str - global.append(" WITH MAX_QUERIES_PER_HOUR = ",29); + global.append(" WITH MAX_QUERIES_PER_HOUR ",27); p=int2str(acl_user->user_resource.questions,buff,10); global.append(buff,p-buff); } if (acl_user->user_resource.updates) { char buff[65], *p; // just as in int2str - global.append(" WITH MAX_UPDATES_PER_HOUR = ",29); + global.append(" WITH MAX_UPDATES_PER_HOUR ",27); p=int2str(acl_user->user_resource.updates,buff,10); global.append(buff,p-buff); } if (acl_user->user_resource.connections) { char buff[65], *p; // just as in int2str - global.append(" WITH MAX_CONNECTIONS_PER_HOUR = ",33); + global.append(" WITH MAX_CONNECTIONS_PER_HOUR ",31); p=int2str(acl_user->user_resource.connections,buff,10); global.append(buff,p-buff); } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 4d6c4ba1bb9..8577533fdd6 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -691,6 +691,7 @@ void wait_for_refresh(THD *thd) pthread_mutex_unlock(&thd->mysys_var->mutex); } + TABLE *reopen_name_locked_table(THD* thd, TABLE_LIST* table_list) { DBUG_ENTER("reopen_name_locked_table"); diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index ec6f4cf2736..eb4316efca2 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -508,7 +508,7 @@ my_bool Query_cache_query::try_lock_writing() void Query_cache_query::lock_reading() { MUTEX_LOCK(&clients_guard); - if ( ++clients == 1 ) + if (++clients == 1) SEM_LOCK(&lock); MUTEX_UNLOCK(&clients_guard); } @@ -961,7 +961,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) // Check access; block_table= query_block->table(0); block_table_end= block_table+query_block->n_tables; - for ( ; block_table != block_table_end; block_table++) + for (; block_table != block_table_end; block_table++) { TABLE_LIST table_list; bzero((char*) &table_list,sizeof(table_list)); @@ -1040,7 +1040,7 @@ void Query_cache::invalidate(THD *thd, TABLE_LIST *tables_used, using_transactions = using_transactions && (thd->options & (OPTION_NOT_AUTO_COMMIT | OPTION_BEGIN)); - for ( ; tables_used; tables_used=tables_used->next) + for (; tables_used; tables_used=tables_used->next) { DBUG_ASSERT(!using_transactions || tables_used->table!=0); if (using_transactions && @@ -1069,7 +1069,7 @@ void Query_cache::invalidate(CHANGED_TABLE_LIST *tables_used) if (query_cache_size > 0) { DUMP(this); - for ( ; tables_used; tables_used=tables_used->next) + for (; tables_used; tables_used=tables_used->next) { invalidate_table((byte*) tables_used->key, tables_used->key_length); DBUG_PRINT("qcache", (" db %s, table %s", tables_used->key, @@ -1188,15 +1188,17 @@ void Query_cache::pack(ulong join_limit, uint iteration_limit) void Query_cache::destroy() { - if ( !initialized ) + DBUG_ENTER("Query_cache::destroy"); + if (!initialized) { DBUG_PRINT("qcache", ("Query Cache not initialized")); - return; } - DBUG_ENTER("Query_cache::destroy"); - free_cache(1); - pthread_mutex_destroy(&structure_guard_mutex); - initialized = 0; + else + { + free_cache(1); + pthread_mutex_destroy(&structure_guard_mutex); + initialized = 0; + } DBUG_VOID_RETURN; } @@ -2138,8 +2140,10 @@ void Query_cache::split_block(Query_cache_block *block, ulong len) new_block->pnext->pprev = new_block; if (block->type == Query_cache_block::FREE) + { // if block was free then it already joined with all free neighbours insert_into_free_memory_list(new_block); + } else free_memory_block(new_block); @@ -2870,7 +2874,7 @@ void Query_cache::bins_dump() { uint i; - if ( !initialized ) + if (!initialized) { DBUG_PRINT("qcache", ("Query Cache not initialized")); return; @@ -2911,8 +2915,7 @@ void Query_cache::bins_dump() void Query_cache::cache_dump() { - - if ( !initialized ) + if (!initialized) { DBUG_PRINT("qcache", ("Query Cache not initialized")); return; @@ -2939,7 +2942,7 @@ void Query_cache::cache_dump() void Query_cache::queries_dump() { - if ( !initialized ) + if (!initialized) { DBUG_PRINT("qcache", ("Query Cache not initialized")); return; @@ -3001,8 +3004,7 @@ void Query_cache::queries_dump() void Query_cache::tables_dump() { - - if ( !initialized ) + if (!initialized) { DBUG_PRINT("qcache", ("Query Cache not initialized")); return; @@ -3072,8 +3074,8 @@ my_bool Query_cache::check_integrity(bool not_locked) // Check memory allocation if (block->pnext == first_block) // Is it last block? { - if ( ((byte*)block) + block->length != - ((byte*)first_block) + query_cache_size ) + if (((byte*)block) + block->length != + ((byte*)first_block) + query_cache_size) { DBUG_PRINT("error", ("block 0x%lx, type %u, ended at 0x%lx, but cache ended at 0x%lx", @@ -3093,16 +3095,16 @@ my_bool Query_cache::check_integrity(bool not_locked) (ulong) ((byte*)block->pnext))); } if (block->type == Query_cache_block::FREE) - free+=block->length; + free+= block->length; else - used+=block->length; + used+= block->length; switch(block->type) { case Query_cache_block::FREE: { Query_cache_memory_bin *bin = *((Query_cache_memory_bin **) block->data()); //is it correct pointer? - if ( ((byte*)bin) < ((byte*)bins) || + if (((byte*)bin) < ((byte*)bins) || ((byte*)bin) >= ((byte*)first_block)) { DBUG_PRINT("error", @@ -3153,7 +3155,7 @@ my_bool Query_cache::check_integrity(bool not_locked) case Query_cache_block::RESULT: { Query_cache_block * query_block = block->result()->parent(); - if ( ((byte*)query_block) < ((byte*)first_block) || + if (((byte*)query_block) < ((byte*)first_block) || ((byte*)query_block) >= (((byte*)first_block) + query_cache_size)) { DBUG_PRINT("error", @@ -3305,7 +3307,7 @@ my_bool Query_cache::in_blocks(Query_cache_block * point) (ulong) block->pprev->pnext, (ulong) point)); //back trace - for(; block != point; block = block->pnext) + for (; block != point; block = block->pnext) DBUG_PRINT("error", ("back trace 0x%lx", (ulong) block)); result = 1; goto err1; @@ -3333,7 +3335,7 @@ err1: (ulong) block->pnext->pprev, (ulong) point)); //back trace - for(; block != point; block = block->pprev) + for (; block != point; block = block->pprev) DBUG_PRINT("error", ("back trace 0x%lx", (ulong) block)); result = 1; goto err2; @@ -3362,7 +3364,7 @@ my_bool Query_cache::in_list(Query_cache_block * root, (ulong) block->prev->next, (ulong) point)); //back trace - for(; block != point; block = block->next) + for (; block != point; block = block->next) DBUG_PRINT("error", ("back trace 0x%lx", (ulong) block)); result = 1; goto err1; @@ -3436,7 +3438,7 @@ my_bool Query_cache::in_table_list(Query_cache_block_table * root, (ulong) table->prev->next->block(), (ulong) point, (ulong) point->block())); //back trace - for(; table != point; table = table->next) + for (; table != point; table = table->next) DBUG_PRINT("error", ("back trace 0x%lx(0x%lx)", (ulong) table, (ulong) table->block())); result = 1; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 84de7e6ad4a..5099a3c56a7 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -286,17 +286,18 @@ inline static void list_include(CHANGED_TABLE_LIST** prev, } /* add table to list of changed in transaction tables */ + void THD::add_changed_table(TABLE *table) { - DBUG_ENTER("THD::add_changed_table (table)"); + DBUG_ENTER("THD::add_changed_table(table)"); DBUG_ASSERT((options & (OPTION_NOT_AUTO_COMMIT | OPTION_BEGIN)) && - table->file->has_transactions()); + table->file->has_transactions()); CHANGED_TABLE_LIST** prev = &transaction.changed_tables; CHANGED_TABLE_LIST* curr = transaction.changed_tables; - for(; curr; prev = &(curr->next), curr = curr->next) + for (; curr; prev = &(curr->next), curr = curr->next) { int cmp = (long)curr->key_length - (long)table->key_length; if (cmp < 0) @@ -313,7 +314,8 @@ void THD::add_changed_table(TABLE *table) { list_include(prev, curr, changed_table_dup(table)); DBUG_PRINT("info", - ("key_length %u %u", table->key_length, (*prev)->key_length)); + ("key_length %u %u", table->key_length, + (*prev)->key_length)); DBUG_VOID_RETURN; } else if (cmp == 0) @@ -324,10 +326,12 @@ void THD::add_changed_table(TABLE *table) } } *prev = changed_table_dup(table); - DBUG_PRINT("info", ("key_length %u %u", table->key_length, (*prev)->key_length)); + DBUG_PRINT("info", ("key_length %u %u", table->key_length, + (*prev)->key_length)); DBUG_VOID_RETURN; } + CHANGED_TABLE_LIST* THD::changed_table_dup(TABLE *table) { CHANGED_TABLE_LIST* new_table = @@ -603,7 +607,7 @@ bool select_export::send_data(List<Item> &items) bfill(space,sizeof(space),' '); } uint length=item->max_length-used_length; - for ( ; length > sizeof(space) ; length-=sizeof(space)) + for (; length > sizeof(space) ; length-=sizeof(space)) { if (my_b_write(&cache,(byte*) space,sizeof(space))) goto err; diff --git a/sql/sql_class.h b/sql/sql_class.h index da0b2090c97..6608c75a9f5 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -185,9 +185,9 @@ typedef struct st_copy_info { ha_rows records; ha_rows deleted; ha_rows copied; - ha_rows error; + ha_rows error_count; enum enum_duplicates handle_duplicates; - int escape_char, errorno; + int escape_char, last_errno; } COPY_INFO; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index fd8ef4fb123..5f6cce147b7 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -198,7 +198,7 @@ cleanup: /*************************************************************************** -** delete multiple tables from join + Delete multiple tables from join ***************************************************************************/ #define MEM_STRIP_BUF_SIZE sortbuff_size @@ -357,7 +357,7 @@ void multi_delete::send_error(uint errcode,const char *err) if (!deleted) DBUG_VOID_RETURN; - /* Somthing alredy deleted consequently we have to invalidate cache */ + /* Something already deleted so we have to invalidate cache */ query_cache_invalidate3(thd, delete_tables, 1); /* Below can happen when thread is killed early ... */ @@ -436,6 +436,8 @@ int multi_delete::do_deletes(bool from_send_error) /* + Send ok to the client + return: 0 sucess 1 error */ @@ -484,7 +486,7 @@ bool multi_delete::send_eof() /*************************************************************************** -* TRUNCATE TABLE + TRUNCATE TABLE ****************************************************************************/ /* @@ -527,9 +529,9 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) if ((error= (int) !(open_temporary_table(thd, path, table_list->db, table_list->real_name, 1)))) (void) rm_temporary_table(table_type, path); - /* Sasha: if we return here we will not have binloged the truncation and - we will not send_ok() to the client. Yes, we do need better coverage - testing, this bug has been here for a few months :-). + /* + Sasha: if we return here we will not have binloged the truncation and + we will not send_ok() to the client. */ goto end; } diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index f1dc5599f46..a23e2185e59 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -212,7 +212,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, if (cond) { err=err; - if(!cond->val_int()) + if (!cond->val_int()) continue; } if (num_rows>=offset_limit) diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 8db2c13b51d..813af3d92b7 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -449,7 +449,7 @@ int write_record(TABLE *table,COPY_INFO *info) err: if (key) my_afree(key); - info->errorno= error; + info->last_errno= error; table->file->print_error(error,MYF(0)); return 1; } @@ -1181,7 +1181,7 @@ bool delayed_insert::handle_inserts(void) thd.net.last_errno = 0; // reset error for binlog if (write_record(table,&info)) { - info.error++; // Ignore errors + info.error_count++; // Ignore errors thread_safe_increment(delayed_insert_errors,&LOCK_delayed_status); row->log_query = 0; } diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 42a8a700da3..575aea5c947 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -507,7 +507,7 @@ int yylex(void *arg) length= (uint) (lex->ptr - lex->tok_start)-1; if (lex->ignore_space) { - for ( ; state_map[c] == STATE_SKIP ; c= yyGet()); + for (; state_map[c] == STATE_SKIP ; c= yyGet()); } if (c == '.' && (state_map[yyPeek()] == STATE_IDENT || state_map[yyPeek()] == STATE_NUMBER_IDENT)) diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 8713e8f0be7..2ec61ff0879 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -22,8 +22,10 @@ class Table_ident; class sql_exchange; class LEX_COLUMN; -// The following hack is needed because mysql_yacc.cc does not define -// YYSTYPE before including this file +/* + The following hack is needed because mysql_yacc.cc does not define + YYSTYPE before including this file +*/ #ifdef MYSQL_YACC #define LEX_YYSTYPE void * @@ -94,20 +96,24 @@ typedef List<Item> List_item; typedef struct st_lex_master_info { - char* host, *user, *password,*log_file_name; + char *host, *user, *password, *log_file_name; uint port, connect_retry; ulonglong pos; ulong server_id; - char* relay_log_name; + char *relay_log_name; ulong relay_log_pos; } LEX_MASTER_INFO; -enum sub_select_type {UNSPECIFIED_TYPE,UNION_TYPE, INTERSECT_TYPE, EXCEPT_TYPE, NOT_A_SELECT}; +enum sub_select_type +{ + UNSPECIFIED_TYPE, UNION_TYPE, INTERSECT_TYPE, EXCEPT_TYPE, NOT_A_SELECT +}; /* The state of the lex parsing for selects */ -typedef struct st_select_lex { +typedef struct st_select_lex +{ enum sub_select_type linkage; char *db,*db1,*table1,*db2,*table2; /* For outer join using .. */ Item *where,*having; @@ -126,7 +132,8 @@ typedef struct st_select_lex { } SELECT_LEX; -class Set_option :public Sql_alloc { +class Set_option :public Sql_alloc +{ public: const char *name; Item *item; @@ -140,7 +147,8 @@ public: /* The state of the lex parsing. This is saved in the THD struct */ -typedef struct st_lex { +typedef struct st_lex +{ uint yylineno,yytoklen; /* Simulate lex */ LEX_YYSTYPE yylval; SELECT_LEX select_lex, *select; diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 419e3fccabd..820d85d5117 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -285,7 +285,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, info.records-info.copied,thd->cuted_fields); send_ok(&thd->net,info.copied+info.deleted,0L,name); // on the slave thd->query is never initialized - if(!thd->slave_thread) + if (!thd->slave_thread) mysql_update_log.write(thd,thd->query,thd->query_length); if (!using_transactions) @@ -435,7 +435,7 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table, { // Last record if (sql_field == (Item_field*) fields.head()) break; - for ( ; sql_field ; sql_field=(Item_field*) it++) + for (; sql_field ; sql_field=(Item_field*) it++) { sql_field->field->set_null(); sql_field->field->reset(); @@ -475,8 +475,10 @@ READ_INFO::unescape(char chr) } - /* Read a line using buffering */ - /* If last line is empty (in line mode) then it isn't outputed */ +/* + Read a line using buffering + If last line is empty (in line mode) then it isn't outputed +*/ READ_INFO::READ_INFO(File file_par, uint tot_length, String &field_term, @@ -535,10 +537,11 @@ READ_INFO::READ_INFO(File file_par, uint tot_length, String &field_term, } else { - /* init_io_cache() will not initialize read_function member - if the cache is READ_NET. The reason is explained in - mysys/mf_iocache.c. So we work around the problem with a - manual assignment + /* + init_io_cache() will not initialize read_function member + if the cache is READ_NET. The reason is explained in + mysys/mf_iocache.c. So we work around the problem with a + manual assignment */ if (get_it_from_net) cache.read_function = _my_b_net_read; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index f63f7e2f626..161077bebae 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -101,7 +101,7 @@ static void test_signal(int sig_ptr) static void init_signals(void) { int signals[7] = {SIGINT,SIGILL,SIGFPE,SIGSEGV,SIGTERM,SIGBREAK,SIGABRT } ; - for(int i=0 ; i < 7 ; i++) + for (int i=0 ; i < 7 ; i++) signal( signals[i], test_signal) ; } #endif @@ -2216,8 +2216,8 @@ mysql_execute_command(void) } if (check_db_used(thd,tables) || end_active_trans(thd)) goto error; - if (check_table_access(thd, SELECT_ACL | INSERT_ACL | UPDATE_ACL | DELETE_ACL , tables) - || (grant_option && check_grant(thd,SELECT_ACL | INSERT_ACL | UPDATE_ACL | DELETE_ACL,tables))) + if (check_table_access(thd, SELECT_ACL | INSERT_ACL | UPDATE_ACL | + DELETE_ACL, tables)) goto error; thd->in_lock_tables=1; thd->options|= OPTION_TABLE_LOCK; diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 39c84090bb7..fa2a6e2d28a 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -752,7 +752,7 @@ int change_master(THD* thd, MASTER_INFO* mi) { need_relay_log_purge = 0; mi->rli.skip_log_purge=1; - strnmov(mi->rli.relay_log_name,lex_mi->relay_log_name, + strmake(mi->rli.relay_log_name,lex_mi->relay_log_name, sizeof(mi->rli.relay_log_name)-1); } @@ -790,8 +790,8 @@ int change_master(THD* thd, MASTER_INFO* mi) } mi->rli.master_log_pos = mi->master_log_pos; DBUG_PRINT("info", ("master_log_pos: %d", (ulong) mi->master_log_pos)); - strnmov(mi->rli.master_log_name,mi->master_log_name, - sizeof(mi->rli.master_log_name)); + strmake(mi->rli.master_log_name,mi->master_log_name, + sizeof(mi->rli.master_log_name)-1); if (!mi->rli.master_log_name[0]) // uninitialized case mi->rli.master_log_pos=0; diff --git a/sql/sql_repl.h b/sql/sql_repl.h index b15c72a0bde..207c2e110a7 100644 --- a/sql/sql_repl.h +++ b/sql/sql_repl.h @@ -1,6 +1,3 @@ -#ifndef SQL_REPL_H -#define SQL_REPL_H - #include "slave.h" typedef struct st_slave_info @@ -27,7 +24,7 @@ extern bool opt_sporadic_binlog_dump_fail; #define KICK_SLAVE(thd) thd->awake(0 /* do not prepare to die*/); File open_binlog(IO_CACHE *log, const char *log_file_name, - const char **errmsg); + const char **errmsg); int start_slave(THD* thd, MASTER_INFO* mi, bool net_report); int stop_slave(THD* thd, MASTER_INFO* mi, bool net_report); @@ -58,6 +55,3 @@ typedef struct st_load_file_info } LOAD_FILE_INFO; int log_loaded_block(IO_CACHE* file); - -#endif - diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 315211f63c5..3a52da5a084 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -175,8 +175,8 @@ int handle_select(THD *thd, LEX *lex, select_result *result) /***************************************************************************** -** check fields, find best join, do the select and output fields. -** mysql_select assumes that all tables are already opened + Check fields, find best join, do the select and output fields. + mysql_select assumes that all tables are already opened *****************************************************************************/ int @@ -731,11 +731,11 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds, } /* - ** If we have different sort & group then we must sort the data by group - ** and copy it to another tmp table - ** This code is also used if we are using distinct something - ** we haven't been able to store in the temporary table yet - ** like SEC_TO_TIME(SUM(...)). + If we have different sort & group then we must sort the data by group + and copy it to another tmp table + This code is also used if we are using distinct something + we haven't been able to store in the temporary table yet + like SEC_TO_TIME(SUM(...)). */ if (group && (!test_if_subpart(group,order) || select_distinct) || @@ -889,8 +889,8 @@ err: } /***************************************************************************** -** Create JOIN_TABS, make a guess about the table types, -** Approximate how many records will be used in each table + Create JOIN_TABS, make a guess about the table types, + Approximate how many records will be used in each table *****************************************************************************/ static ha_rows get_quick_record_count(SQL_SELECT *select,TABLE *table, @@ -1210,11 +1210,11 @@ make_join_statistics(JOIN *join,TABLE_LIST *tables,COND *conds, /***************************************************************************** -** check with keys are used and with tables references with tables -** updates in stat: -** keys Bitmap of all used keys -** const_keys Bitmap of all keys with may be used with quick_select -** keyuse Pointer to possible keys + Check with keys are used and with tables references with tables + Updates in stat: + keys Bitmap of all used keys + const_keys Bitmap of all keys with may be used with quick_select + keyuse Pointer to possible keys *****************************************************************************/ typedef struct key_field_t { // Used when finding key fields @@ -1446,8 +1446,8 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level, } /* -** Add all keys with uses 'field' for some keypart -** If field->and_level != and_level then only mark key_part as const_part + Add all keys with uses 'field' for some keypart + If field->and_level != and_level then only mark key_part as const_part */ static uint @@ -1582,9 +1582,9 @@ sort_keyuse(KEYUSE *a,KEYUSE *b) /* -** Update keyuse array with all possible keys we can use to fetch rows -** join_tab is a array in tablenr_order -** stat is a reference array in 'prefered' order. + Update keyuse array with all possible keys we can use to fetch rows + join_tab is a array in tablenr_order + stat is a reference array in 'prefered' order. */ static bool @@ -1623,9 +1623,9 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, } /* - ** remove ref if there is a keypart which is a ref and a const. - ** remove keyparts without previous keyparts. - ** Special treatment for ft-keys. + Remove ref if there is a keypart which is a ref and a const. + Remove keyparts without previous keyparts. + Special treatment for ft-keys. */ if (keyuse->elements) { @@ -1675,8 +1675,8 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, /***************************************************************************** -** Go through all combinations of not marked tables and find the one -** which uses least records + Go through all combinations of not marked tables and find the one + which uses least records *****************************************************************************/ /* Save const tables first as used tables */ @@ -1691,7 +1691,7 @@ set_position(JOIN *join,uint idx,JOIN_TAB *table,KEYUSE *key) /* Move the const table as down as possible in best_ref */ JOIN_TAB **pos=join->best_ref+idx+1; JOIN_TAB *next=join->best_ref[idx]; - for ( ;next != table ; pos++) + for (;next != table ; pos++) { JOIN_TAB *tmp=pos[0]; pos[0]=next; @@ -1782,12 +1782,12 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, found_ref|= keyuse->used_tables; } /* - ** If we find a ref, assume this table matches a proportional - ** part of this table. - ** For example 100 records matching a table with 5000 records - ** gives 5000/100 = 50 records per key - ** Constant tables are ignored and to avoid bad matches, - ** we don't make rec less than 100. + If we find a ref, assume this table matches a proportional + part of this table. + For example 100 records matching a table with 5000 records + gives 5000/100 = 50 records per key + Constant tables are ignored and to avoid bad matches, + we don't make rec less than 100. */ if (keyuse->used_tables & (map=(keyuse->used_tables & ~join->const_table_map))) @@ -1808,7 +1808,7 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, } while (keyuse->table == table && keyuse->key == key); /* - ** Assume that that each key matches a proportional part of table. + Assume that that each key matches a proportional part of table. */ if (!found_part && !ft_key) continue; // Nothing usable found @@ -1816,13 +1816,13 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, rec=1L; // Fix for small tables /* - ** ft-keys require special treatment + ft-keys require special treatment */ if (ft_key) { /* - ** Really, there should be records=0.0 (yes!) - ** but 1.0 would be probably safer + Really, there should be records=0.0 (yes!) + but 1.0 would be probably safer */ tmp=prev_record_reads(join,found_ref); records=1.0; @@ -1830,7 +1830,7 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, else { /* - ** Check if we found full key + Check if we found full key */ if (found_part == PREV_BITS(uint,keyinfo->key_parts)) { /* use eq key */ @@ -1877,17 +1877,18 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, else { /* - ** Use as much key-parts as possible and a uniq key is better - ** than a not unique key - ** Set tmp to (previous record count) * (records / combination) + Use as much key-parts as possible and a uniq key is better + than a not unique key + Set tmp to (previous record count) * (records / combination) */ if ((found_part & 1) && !(table->file->index_flags(key) & HA_ONLY_WHOLE_INDEX)) { max_key_part=max_part_bit(found_part); - /* Check if quick_range could determinate how many rows we - will match */ - + /* + Check if quick_range could determinate how many rows we + will match + */ if (table->quick_keys & ((key_map) 1 << key) && table->quick_key_parts[key] <= max_key_part) tmp=records= (double) table->quick_rows[key]; @@ -1899,18 +1900,18 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, else { /* - ** Assume that the first key part matches 1% of the file - ** and that the hole key matches 10 (dupplicates) or 1 - ** (unique) records. - ** Assume also that more key matches proportionally more - ** records - ** This gives the formula: - ** records= (x * (b-a) + a*c-b)/(c-1) - ** - ** b = records matched by whole key - ** a = records matched by first key part (10% of all records?) - ** c = number of key parts in key - ** x = used key parts (1 <= x <= c) + Assume that the first key part matches 1% of the file + and that the hole key matches 10 (dupplicates) or 1 + (unique) records. + Assume also that more key matches proportionally more + records + This gives the formula: + records= (x * (b-a) + a*c-b)/(c-1) + + b = records matched by whole key + a = records matched by first key part (10% of all records?) + c = number of key parts in key + x = used key parts (1 <= x <= c) */ double rec_per_key; if (!(rec_per_key=(double) @@ -2034,7 +2035,7 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, /* -** Find how much space the prevous read not const tables takes in cache + Find how much space the prevous read not const tables takes in cache */ static void calc_used_field_length(THD *thd, JOIN_TAB *join_tab) @@ -2110,7 +2111,7 @@ prev_record_reads(JOIN *join,table_map found_ref) /***************************************************************************** -** Set up join struct according to best position. + Set up join struct according to best position. *****************************************************************************/ static bool @@ -2176,7 +2177,7 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, KEYUSE *org_keyuse, KEY *keyinfo; /* - ** Use best key from find_best + Use best key from find_best */ table=j->table; key=keyuse->key; @@ -2325,8 +2326,8 @@ get_store_key(THD *thd, KEYUSE *keyuse, table_map used_tables, } /* -** This function is only called for const items on fields which are keys -** returns 1 if there was some conversion made when the field was stored. + This function is only called for const items on fields which are keys + returns 1 if there was some conversion made when the field was stored. */ bool @@ -2603,7 +2604,7 @@ make_join_readinfo(JOIN *join,uint options) break; case JT_ALL: /* - ** if previous table use cache + If previous table use cache */ table->status=STATUS_NO_RECORD; if (i != join->const_tables && !(options & SELECT_NO_JOIN_CACHE) && @@ -2715,8 +2716,10 @@ join_free(JOIN *join) } join->table=0; } - // We are not using tables anymore - // Unlock all tables. We may be in an INSERT .... SELECT statement. + /* + We are not using tables anymore + Unlock all tables. We may be in an INSERT .... SELECT statement. + */ if (join->lock && join->thd->lock && !(join->select_options & SELECT_NO_UNLOCK)) { @@ -2733,19 +2736,19 @@ join_free(JOIN *join) /***************************************************************************** -** Remove the following expressions from ORDER BY and GROUP BY: -** Constant expressions -** Expression that only uses tables that are of type EQ_REF and the reference -** is in the ORDER list or if all refereed tables are of the above type. -** -** In the following, the X field can be removed: -** SELECT * FROM t1,t2 WHERE t1.a=t2.a ORDER BY t1.a,t2.X -** SELECT * FROM t1,t2,t3 WHERE t1.a=t2.a AND t2.b=t3.b ORDER BY t1.a,t3.X -** -** These can't be optimized: -** SELECT * FROM t1,t2 WHERE t1.a=t2.a ORDER BY t2.X,t1.a -** SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b=t2.b ORDER BY t1.a,t2.c -** SELECT * FROM t1,t2 WHERE t1.a=t2.a ORDER BY t2.b,t1.a + Remove the following expressions from ORDER BY and GROUP BY: + Constant expressions + Expression that only uses tables that are of type EQ_REF and the reference + is in the ORDER list or if all refereed tables are of the above type. + + In the following, the X field can be removed: + SELECT * FROM t1,t2 WHERE t1.a=t2.a ORDER BY t1.a,t2.X + SELECT * FROM t1,t2,t3 WHERE t1.a=t2.a AND t2.b=t3.b ORDER BY t1.a,t3.X + + These can't be optimized: + SELECT * FROM t1,t2 WHERE t1.a=t2.a ORDER BY t2.X,t1.a + SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b=t2.b ORDER BY t1.a,t2.c + SELECT * FROM t1,t2 WHERE t1.a=t2.a ORDER BY t2.b,t1.a *****************************************************************************/ static bool @@ -2785,7 +2788,7 @@ eq_ref_table(JOIN *join, ORDER *start_order, JOIN_TAB *tab) } } /* Check that there was no reference to table before sort order */ - for ( ; found && start_order ; start_order=start_order->next) + for (; found && start_order ; start_order=start_order->next) { if (start_order->used & map) { @@ -2803,7 +2806,7 @@ static bool only_eq_ref_tables(JOIN *join,ORDER *order,table_map tables) { if (specialflag & SPECIAL_SAFE_MODE) - return 0; // skip this optimize /* purecov: inspected */ + return 0; // skip this optimize /* purecov: inspected */ for (JOIN_TAB **tab=join->map2table ; tables ; tab++, tables>>=1) { if (tables & 1 && !eq_ref_table(join, order, *tab)) @@ -2819,7 +2822,7 @@ static void update_depend_map(JOIN *join) { JOIN_TAB *join_tab=join->join_tab, *end=join_tab+join->tables; - for ( ; join_tab != end ; join_tab++) + for (; join_tab != end ; join_tab++) { TABLE_REF *ref= &join_tab->ref; table_map depend_map=0; @@ -2843,7 +2846,7 @@ static void update_depend_map(JOIN *join) static void update_depend_map(JOIN *join, ORDER *order) { - for ( ; order ; order=order->next) + for (; order ; order=order->next) { table_map depend_map; order->item[0]->update_used_tables(); @@ -2973,12 +2976,12 @@ static void clear_tables(JOIN *join) } /***************************************************************************** -** Make som simple condition optimization: -** If there is a test 'field = const' change all refs to 'field' to 'const' -** Remove all dummy tests 'item = item', 'const op const'. -** Remove all 'item is NULL', when item can never be null! -** item->marker should be 0 for all items on entry -** Return in cond_value FALSE if condition is impossible (1 = 2) + Make som simple condition optimization: + If there is a test 'field = const' change all refs to 'field' to 'const' + Remove all dummy tests 'item = item', 'const op const'. + Remove all 'item is NULL', when item can never be null! + item->marker should be 0 for all items on entry + Return in cond_value FALSE if condition is impossible (1 = 2) *****************************************************************************/ class COND_CMP :public ilink { @@ -3000,8 +3003,8 @@ template class List_iterator<Item_func_match>; #endif /* -** change field = field to field = const for each found field = const in the -** and_level + change field = field to field = const for each found field = const in the + and_level */ static void @@ -3146,8 +3149,8 @@ optimize_cond(COND *conds,Item::cond_result *cond_value) DBUG_EXECUTE("where",print_where(conds,"original");); propagate_cond_constants((I_List<COND_CMP> *) 0,conds,conds); /* - ** Remove all instances of item == item - ** Remove all and-levels where CONST item != CONST item + Remove all instances of item == item + Remove all and-levels where CONST item != CONST item */ DBUG_EXECUTE("where",print_where(conds,"after const change");); conds=remove_eq_conds(conds,cond_value) ; @@ -3157,11 +3160,11 @@ optimize_cond(COND *conds,Item::cond_result *cond_value) /* -** remove const and eq items. Return new item, or NULL if no condition -** cond_value is set to according: -** COND_OK query is possible (field = constant) -** COND_TRUE always true ( 1 = 1 ) -** COND_FALSE always false ( 1 = 2 ) + Remove const and eq items. Return new item, or NULL if no condition + cond_value is set to according: + COND_OK query is possible (field = constant) + COND_TRUE always true ( 1 = 1 ) + COND_FALSE always false ( 1 = 2 ) */ static COND * @@ -3299,7 +3302,7 @@ remove_eq_conds(COND *cond,Item::cond_result *cond_value) } /* -** Return 1 if the item is a const value in all the WHERE clause + Return 1 if the item is a const value in all the WHERE clause */ static bool @@ -3358,10 +3361,10 @@ const_expression_in_where(COND *cond, Item *comp_item, Item **const_item) /**************************************************************************** -** Create a temp table according to a field list. -** Set distinct if duplicates could be removed -** Given fields field pointers are changed to point at tmp_table -** for send_fields + Create a temp table according to a field list. + Set distinct if duplicates could be removed + Given fields field pointers are changed to point at tmp_table + for send_fields ****************************************************************************/ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, @@ -3824,7 +3827,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, key_part_info->null_offset= (uint) (field->null_ptr - (uchar*) table->record[0]); group->field->move_field((char*) ++group->buff); - ++group_buff; + group_buff++; } else group->field->move_field((char*) group_buff); @@ -4168,7 +4171,7 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure) join->procedure=procedure; /* - ** Tell the client how many fields there are in a row + Tell the client how many fields there are in a row */ if (!table) join->result->send_fields(*fields,1); @@ -4430,10 +4433,9 @@ flush_cached_records(JOIN *join,JOIN_TAB *join_tab,bool skipp_last) /***************************************************************************** -** The different ways to read a record -** Returns -1 if row was not found, 0 if row was found and 1 on errors + The different ways to read a record + Returns -1 if row was not found, 0 if row was found and 1 on errors *****************************************************************************/ - static int join_read_const_table(JOIN_TAB *tab, POSITION *pos) { @@ -4870,12 +4872,12 @@ join_ft_read_next(READ_RECORD *info) /***************************************************************************** -** The different end of select functions -** These functions returns < 0 when end is reached, 0 on ok and > 0 if a -** fatal error (like table corruption) was detected + The different end of select functions + These functions returns < 0 when end is reached, 0 on ok and > 0 if a + fatal error (like table corruption) was detected *****************************************************************************/ - /* ARGSUSED */ +/* ARGSUSED */ static int end_send(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), bool end_of_records) @@ -5268,11 +5270,11 @@ end_write_group(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), /***************************************************************************** -** Remove calculation with tables that aren't yet read. Remove also tests -** against fields that are read through key where the table is not a -** outer join table. -** We can't remove tests that are made against columns which are stored -** in sorted order. + Remove calculation with tables that aren't yet read. Remove also tests + against fields that are read through key where the table is not a + outer join table. + We can't remove tests that are made against columns which are stored + in sorted order. *****************************************************************************/ /* Return 1 if right_item is used removable reference key on left_item */ @@ -5290,8 +5292,10 @@ static bool test_if_ref(Item_field *left_item,Item *right_item) return (field->eq_def(((Item_field *) right_item)->field)); if (right_item->const_item() && !(right_item->is_null())) { - // We can remove binary fields and numerical fields except float, - // as float comparison isn't 100 % secure + /* + We can remove binary fields and numerical fields except float, + as float comparison isn't 100 % secure + */ if (field->binary() && (field->type() != FIELD_TYPE_FLOAT || field->decimals() == 0)) { @@ -5355,9 +5359,9 @@ make_cond_for_table(COND *cond,table_map tables,table_map used_table) } /* - ** Because the following test takes a while and it can be done - ** table_count times, we mark each item that we have examined with the result - ** of the test + Because the following test takes a while and it can be done + table_count times, we mark each item that we have examined with the result + of the test */ if (cond->marker == 3 || (cond->used_tables() & ~tables)) @@ -5405,11 +5409,11 @@ part_of_refkey(TABLE *table,Field *field) /***************************************************************************** -** Test if one can use the key to resolve ORDER BY -** Returns: 1 if key is ok. -** 0 if key can't be used -** -1 if reverse key can be used -** used_key_parts is set to key parts used if length != 0 + Test if one can use the key to resolve ORDER BY + Returns: 1 if key is ok. + 0 if key can't be used + -1 if reverse key can be used + used_key_parts is set to key parts used if length != 0 *****************************************************************************/ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx, @@ -5676,7 +5680,7 @@ err: } /* -** Add the HAVING criteria to table->select + Add the HAVING criteria to table->select */ #ifdef NOT_YET @@ -5711,11 +5715,11 @@ static bool fix_having(JOIN *join, Item **having) /***************************************************************************** -** Remove duplicates from tmp table -** This should be recoded to add a uniuqe index to the table and remove -** dupplicates -** Table is a locked single thread table -** fields is the number of fields to check (from the end) + Remove duplicates from tmp table + This should be recoded to add a unique index to the table and remove + duplicates + Table is a locked single thread table + fields is the number of fields to check (from the end) *****************************************************************************/ static bool compare_record(TABLE *table, Field **ptr) @@ -6145,7 +6149,7 @@ store_record_in_cache(JOIN_CACHE *cache) cache->ptr_record=cache->records; /* - ** There is room in cache. Put record there + There is room in cache. Put record there */ cache->records++; for (copy=cache->field ; copy < end_field; copy++) @@ -6271,13 +6275,13 @@ cp_buffer_from_ref(TABLE_REF *ref) /***************************************************************************** -** Group and order functions + Group and order functions *****************************************************************************/ /* -** Find order/group item in requested columns and change the item to point at -** it. If item doesn't exists, add it first in the field list -** Return 0 if ok. + Find order/group item in requested columns and change the item to point at + it. If item doesn't exists, add it first in the field list + Return 0 if ok. */ static int @@ -6322,8 +6326,8 @@ find_order_in_list(THD *thd,TABLE_LIST *tables,ORDER *order,List<Item> &fields, /* -** Change order to point at item in select list. If item isn't a number -** and doesn't exits in the select list, add it the the field list. + Change order to point at item in select list. If item isn't a number + and doesn't exits in the select list, add it the the field list. */ int setup_order(THD *thd,TABLE_LIST *tables,List<Item> &fields, @@ -6357,7 +6361,7 @@ setup_group(THD *thd,TABLE_LIST *tables,List<Item> &fields, uint org_fields=all_fields.elements; thd->where="group statement"; - for ( ; order; order=order->next) + for (; order; order=order->next) { if (find_order_in_list(thd,tables,order,fields,all_fields)) return 1; @@ -6392,7 +6396,7 @@ setup_group(THD *thd,TABLE_LIST *tables,List<Item> &fields, } /* -** Add fields with aren't used at start of field list. Return FALSE if ok + Add fields with aren't used at start of field list. Return FALSE if ok */ static bool @@ -6404,7 +6408,7 @@ setup_new_fields(THD *thd,TABLE_LIST *tables,List<Item> &fields, thd->set_query_id=1; // Not really needed, but... thd->where=0; // Don't give error - for ( ; new_field ; new_field=new_field->next) + for (; new_field ; new_field=new_field->next) { if ((item=find_item_in_list(*new_field->item,fields))) new_field->item=item; /* Change to shared Item */ @@ -6422,9 +6426,9 @@ setup_new_fields(THD *thd,TABLE_LIST *tables,List<Item> &fields, } /* -** Create a group by that consist of all non const fields. Try to use -** the fields in the order given by 'order' to allow one to optimize -** away 'order by'. + Create a group by that consist of all non const fields. Try to use + the fields in the order given by 'order' to allow one to optimize + away 'order by'. */ static ORDER * @@ -6473,7 +6477,7 @@ create_distinct_group(ORDER *order_list,List<Item> &fields) /***************************************************************************** -** Update join with count of the different type of fields + Update join with count of the different type of fields *****************************************************************************/ void @@ -6564,7 +6568,7 @@ get_sort_by_table(ORDER *a,ORDER *b,TABLE_LIST *tables) if (!map || (map & RAND_TABLE_BIT)) DBUG_RETURN(0); - for ( ; !(map & tables->table->map) ; tables=tables->next) ; + for (; !(map & tables->table->map) ; tables=tables->next) ; if (map != tables->table->map) DBUG_RETURN(0); // More than one table DBUG_PRINT("exit",("sort by table: %d",tables->table->tablenr)); @@ -6608,8 +6612,8 @@ calc_group_buffer(JOIN *join,ORDER *group) /* -** Get a list of buffers for saveing last group -** Groups are saved in reverse order for easyer check loop + Get a list of buffers for saveing last group + Groups are saved in reverse order for easyer check loop */ static bool @@ -6647,10 +6651,10 @@ test_if_group_changed(List<Item_buff> &list) /* -** Setup copy_fields to save fields at start of new group -** Only FIELD_ITEM:s and FUNC_ITEM:s needs to be saved between groups. -** Change old item_field to use a new field with points at saved fieldvalue -** This function is only called before use of send_fields + Setup copy_fields to save fields at start of new group + Only FIELD_ITEM:s and FUNC_ITEM:s needs to be saved between groups. + Change old item_field to use a new field with points at saved fieldvalue + This function is only called before use of send_fields */ bool @@ -6719,7 +6723,7 @@ err2: /* -** Copy fields and null values between two tables + Copy fields and null values between two tables */ void @@ -6728,7 +6732,7 @@ copy_fields(TMP_TABLE_PARAM *param) Copy_field *ptr=param->copy_field; Copy_field *end=param->copy_field_end; - for ( ; ptr != end; ptr++) + for (; ptr != end; ptr++) (*ptr->do_copy)(ptr); List_iterator_fast<Item> &it=param->copy_funcs_it; @@ -6740,7 +6744,7 @@ copy_fields(TMP_TABLE_PARAM *param) /***************************************************************************** -** Make an array of pointer to sum_functions to speed up sum_func calculation + Make an array of pointer to sum_functions to speed up sum_func calculation *****************************************************************************/ static bool @@ -6772,7 +6776,7 @@ make_sum_func_list(JOIN *join,List<Item> &fields) /* -** Change all funcs and sum_funcs to fields in tmp table + Change all funcs and sum_funcs to fields in tmp table */ static bool @@ -6822,8 +6826,8 @@ change_to_use_tmp_fields(List<Item> &items) /* -** Change all sum_func refs to fields to point at fields in tmp table -** Change all funcs to be fields in tmp table + Change all sum_func refs to fields to point at fields in tmp table + Change all funcs to be fields in tmp table */ static bool @@ -6879,7 +6883,7 @@ change_refs_to_tmp_fields(THD *thd,List<Item> &items) /****************************************************************************** -** code for calculating functions + Code for calculating functions ******************************************************************************/ static void @@ -6947,8 +6951,8 @@ copy_funcs(Item_result_field **func_ptr) /***************************************************************************** -** Create a condition for a const reference and add this to the -** currenct select for the table + Create a condition for a const reference and add this to the + currenct select for the table *****************************************************************************/ static bool add_ref_to_table_cond(THD *thd, JOIN_TAB *join_tab) @@ -6989,7 +6993,7 @@ static bool add_ref_to_table_cond(THD *thd, JOIN_TAB *join_tab) } /**************************************************************************** -** Send a description about what how the select will be done to stdout + Send a description about what how the select will be done to stdout ****************************************************************************/ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, diff --git a/sql/sql_show.cc b/sql/sql_show.cc index e0ce0f0f793..a282c6dde5b 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -116,7 +116,7 @@ int mysqld_show_open_tables(THD *thd,const char *wild) if (!(open_list=list_open_tables(thd,wild)) && thd->fatal_error) DBUG_RETURN(-1); - for ( ; open_list ; open_list=open_list->next) + for (; open_list ; open_list=open_list->next) { thd->packet.length(0); net_store_data(&thd->packet,convert, open_list->db); @@ -1301,7 +1301,7 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables) net_store_data(&packet2,"NONE" ); break; } - switch(SSL_CTX_get_session_cache_mode(ssl_acceptor_fd->ssl_context_)) + switch (SSL_CTX_get_session_cache_mode(ssl_acceptor_fd->ssl_context_)) { case SSL_SESS_CACHE_OFF: net_store_data(&packet2,"OFF" ); diff --git a/sql/sql_string.cc b/sql/sql_string.cc index b0ac378c861..2dcda2d40c2 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -615,7 +615,7 @@ int wild_case_compare(const char *str,const char *str_end, { // Found wild_many wildstr++; /* Remove any '%' and '_' from the wild search string */ - for ( ; wildstr != wildend ; wildstr++) + for (; wildstr != wildend ; wildstr++) { if (*wildstr == wild_many) continue; @@ -744,7 +744,7 @@ int wild_compare(const char *str,const char *str_end, { // Found wild_many wildstr++; /* Remove any '%' and '_' from the wild search string */ - for ( ; wildstr != wildend ; wildstr++) + for (; wildstr != wildend ; wildstr++) { if (*wildstr == wild_many) continue; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index fe66b14d697..9695f273327 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -872,8 +872,9 @@ static int send_check_errmsg(THD* thd, TABLE_LIST* table, return 1; } + static int prepare_for_restore(THD* thd, TABLE_LIST* table, - HA_CHECK_OPT *check_opt) + HA_CHECK_OPT *check_opt) { DBUG_ENTER("prepare_for_restore"); @@ -915,15 +916,18 @@ static int prepare_for_restore(THD* thd, TABLE_LIST* table, } } - // now we should be able to open the partially restored table - // to finish the restore in the handler later on + /* + Now we should be able to open the partially restored table + to finish the restore in the handler later on + */ if (!(table->table = reopen_name_locked_table(thd, table))) - unlock_table_name(thd, table); + unlock_table_name(thd, table); DBUG_RETURN(0); } + static int prepare_for_repair(THD* thd, TABLE_LIST* table, - HA_CHECK_OPT *check_opt) + HA_CHECK_OPT *check_opt) { DBUG_ENTER("prepare_for_repair"); @@ -966,13 +970,16 @@ static int prepare_for_repair(THD* thd, TABLE_LIST* table, } } - // now we should be able to open the partially repaired table - // to finish the repair in the handler later on + /* + Now we should be able to open the partially repaired table + to finish the repair in the handler later on. + */ if (!(table->table = reopen_name_locked_table(thd, table))) unlock_table_name(thd, table); DBUG_RETURN(0); } + static int mysql_admin_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt, const char *operator_name, diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 7f00ddad99f..983ff44dc73 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -255,7 +255,7 @@ bool select_union::send_data(List<Item> &values) fill_record(table->field,values); if ((write_record(table,&info))) { - if (create_myisam_from_heap(table, tmp_table_param, info.errorno, 0)) + if (create_myisam_from_heap(table, tmp_table_param, info.last_errno, 0)) return 1; } return 0; diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 5108c991aba..b4216adc2cd 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -16,9 +16,7 @@ /* Update of records - Multi-table updates were introduced by Monty and Sinisa <sinisa@mysql.com> - */ #include "mysql_priv.h" @@ -347,7 +345,7 @@ int mysql_update(THD *thd, } /*************************************************************************** -** update multiple tables from join + Update multiple tables from join ***************************************************************************/ multi_update::multi_update(THD *thd_arg, TABLE_LIST *ut, List<Item> &fs, @@ -363,7 +361,7 @@ multi_update::multi_update(THD *thd_arg, TABLE_LIST *ut, List<Item> &fs, for (TABLE_LIST *dt=ut ; dt ; dt=dt->next,counter++) { TABLE *table=ut->table; -// (void) ut->table->file->extra(HA_EXTRA_NO_KEYREAD); + // (void) ut->table->file->extra(HA_EXTRA_NO_KEYREAD); dt->table->used_keys=0; if (table->timestamp_field) { @@ -402,10 +400,14 @@ multi_update::prepare(List<Item> &values) } } } -// Here I have to connect fields with tables and only update tables that need to be updated ... + /* + Here I have to connect fields with tables and only update tables that + need to be updated. + I calculate num_updated and fill-up table_sequence + Set table_list->shared to true or false, depending on whether table is + to be updated or not + */ -// I calculate num_updated and fill-up table_sequence -// Set table_list->shared to true or false, depending on whether table is to be updated or not Item_field *item; List_iterator<Item> it(fields); num_fields=fields.elements; @@ -414,7 +416,8 @@ multi_update::prepare(List<Item> &values) while ((item= (Item_field *)it++)) { unsigned int counter=0; - for (table_ref=update_tables; table_ref; table_ref=table_ref->next, counter++) + for (table_ref=update_tables; table_ref; + table_ref=table_ref->next, counter++) { if (table_ref->table == item->field->table && !table_ref->shared) { @@ -422,7 +425,8 @@ multi_update::prepare(List<Item> &values) table_ref->shared=1; if (!not_trans_safe && !table_ref->table->file->has_transactions()) not_trans_safe=true; - table_ref->table->no_keyread=1; // to be moved if initialize_tables has to be used + // to be moved if initialize_tables has to be used + table_ref->table->no_keyread=1; break; } } @@ -440,8 +444,10 @@ multi_update::prepare(List<Item> &values) DBUG_RETURN(1); } -// Here, I have to allocate the array of temporary tables -// I have to treat a case of num_updated=1 differently in send_data() method. + /* + Here, I have to allocate the array of temporary tables + I have to treat a case of num_updated=1 differently in send_data() method. + */ if (num_updated > 1) { tmp_tables = (TABLE **) sql_calloc(sizeof(TABLE *) * (num_updated - 1)); @@ -453,7 +459,7 @@ multi_update::prepare(List<Item> &values) { if (!table_ref->shared) continue; -// Here we have to add row offset as an additional field ... + // Here we have to add row offset as an additional field ... if (!(temp_fields = (List_item *)sql_calloc(sizeof(List_item)))) { error = 1; // A proper error message is due here @@ -470,13 +476,15 @@ multi_update::prepare(List<Item> &values) { Field_string offset(table_ref->table->file->ref_length,false,"offset",table_ref->table,true); temp_fields->push_front(new Item_field(((Field *)&offset))); -// Here I make tmp tables + // Here I make tmp tables int cnt=counter-1; TMP_TABLE_PARAM tmp_table_param; bzero((char*) &tmp_table_param,sizeof(tmp_table_param)); tmp_table_param.field_count=temp_fields->elements; - if (!(tmp_tables[cnt]=create_tmp_table(thd, &tmp_table_param, *temp_fields, - (ORDER*) 0, 1, 0, 0, TMP_TABLE_ALL_COLUMNS))) + if (!(tmp_tables[cnt]=create_tmp_table(thd, &tmp_table_param, + *temp_fields, + (ORDER*) 0, 1, 0, 0, + TMP_TABLE_ALL_COLUMNS))) { error = 1; // A proper error message is due here DBUG_RETURN(1); @@ -498,7 +506,8 @@ multi_update::prepare(List<Item> &values) void multi_update::initialize_tables(JOIN *join) { -/* We skip it as it only makes a mess ........... +/* + We skip it as it only makes a mess ........... TABLE_LIST *walk; table_map tables_to_update_from=0; for (walk= update_tables ; walk ; walk=walk->next) @@ -546,7 +555,7 @@ bool multi_update::send_data(List<Item> &values) List<Item> real_values(values); for (uint counter = 0; counter < fields.elements; counter++) real_values.pop(); -// We have skipped fields .... + // We have skipped fields .... if (num_updated == 1) { for (table_being_updated=update_tables ; @@ -560,7 +569,7 @@ bool multi_update::send_data(List<Item> &values) if (table->status & (STATUS_NULL_ROW | STATUS_UPDATED)) return 0; table->file->position(table->record[0]); -// Only one table being updated receives a completely different treatment + // Only one table being updated receives a completely different treatment table->status|= STATUS_UPDATED; store_record(table,1); if (fill_record(fields,real_values)) @@ -596,7 +605,7 @@ bool multi_update::send_data(List<Item> &values) if (*int_ptr++ == (uint) (secure_counter + 1)) values_by_table.push_back(item); } -// Here I am breaking values as per each table + // Here I am breaking values as per each table if (secure_counter < 0) { table->status|= STATUS_UPDATED; @@ -639,13 +648,13 @@ void multi_update::send_error(uint errcode,const char *err) ::send_error(&thd->net,errcode,err); /* reset used flags */ -// update_tables->table->no_keyread=0; + // update_tables->table->no_keyread=0; /* If nothing updated return */ if (!updated) return; - /* Somthing alredy updated consequently we have to invalidate cache */ + /* Something already updated so we have to invalidate cache */ query_cache_invalidate3(thd, update_tables, 1); /* Below can happen when thread is killed early ... */ diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 2dd25a57478..7b9d1f03dd0 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -3654,17 +3654,17 @@ grant_option_list: grant_option: GRANT OPTION { Lex->grant |= GRANT_ACL;} - | MAX_QUERIES_PER_HOUR EQ ULONG_NUM + | MAX_QUERIES_PER_HOUR ULONG_NUM { - Lex->mqh.questions=$3; + Lex->mqh.questions=$2; } - | MAX_UPDATES_PER_HOUR EQ ULONG_NUM + | MAX_UPDATES_PER_HOUR ULONG_NUM { - Lex->mqh.updates=$3; + Lex->mqh.updates=$2; } - | MAX_CONNECTIONS_PER_HOUR EQ ULONG_NUM + | MAX_CONNECTIONS_PER_HOUR ULONG_NUM { - Lex->mqh.connections=$3; + Lex->mqh.connections=$2; } begin: diff --git a/sql/table.cc b/sql/table.cc index 315f8bacf34..5664099adda 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -922,7 +922,7 @@ ulong next_io_size(register ulong pos) void append_unescaped(String *res,const char *pos) { - for ( ; *pos ; pos++) + for (; *pos ; pos++) { switch (*pos) { case 0: /* Must be escaped for 'mysql' */ diff --git a/sql/table.h b/sql/table.h index 78f80045b21..e8280a7d7e6 100644 --- a/sql/table.h +++ b/sql/table.h @@ -135,7 +135,8 @@ struct st_table { #define JOIN_TYPE_LEFT 1 #define JOIN_TYPE_RIGHT 2 -typedef struct st_table_list { +typedef struct st_table_list +{ struct st_table_list *next; char *db,*name,*real_name; uint32 db_length, real_name_length; @@ -152,12 +153,15 @@ typedef struct st_table_list { bool shared; /* Used twice in union */ } TABLE_LIST; -typedef struct st_changed_table_list { + +typedef struct st_changed_table_list +{ struct st_changed_table_list *next; char *key; uint32 key_length; } CHANGED_TABLE_LIST; + typedef struct st_open_table_list { struct st_open_table_list *next; diff --git a/sql/time.cc b/sql/time.cc index aab886648e3..1597368908d 100644 --- a/sql/time.cc +++ b/sql/time.cc @@ -496,7 +496,7 @@ str_to_TIME(const char *str, uint length, TIME *l_time,bool fuzzy_date) } if (str != end && current_thd->count_cuted_fields) { - for ( ; str != end ; str++) + for (; str != end ; str++) { if (!isspace(*str)) { diff --git a/sql/udf_example.cc b/sql/udf_example.cc index a5ec77f88e4..f5ff9fe67b5 100644 --- a/sql/udf_example.cc +++ b/sql/udf_example.cc @@ -271,7 +271,7 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result, * characters and converting to uppercase. *-------------------------------------------------------*/ - for ( n = ntrans + 1, n_end = ntrans + sizeof(ntrans)-2; + for (n = ntrans + 1, n_end = ntrans + sizeof(ntrans)-2; word != w_end && n < n_end; word++ ) if ( isalpha ( *word )) *n++ = toupper ( *word ); @@ -324,7 +324,7 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result, KSflag = 0; /* state flag for KS translation */ - for ( metaph_end = result + MAXMETAPH, n_start = n; + for (metaph_end = result + MAXMETAPH, n_start = n; n <= n_end && result < metaph_end; n++ ) { @@ -402,7 +402,7 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result, n[2] != 'G' ) ? (char)'J' : (char)'K'; else - if( n[1] == 'H' && + if ( n[1] == 'H' && !NOGHTOF( *( n - 3 )) && *( n - 4 ) != 'H') *result++ = 'F'; @@ -440,7 +440,7 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result, case 'T': /* TIO, TIA = X ("sh" sound) */ /* TH = 0, ("th" sound ) */ - if( *( n + 1 ) == 'I' && ( n[2] == 'O' + if ( *( n + 1 ) == 'I' && ( n[2] == 'O' || n[2] == 'A') ) *result++ = 'X'; else diff --git a/sql/unireg.cc b/sql/unireg.cc index 1c35f7a6a08..7d0201f75ae 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -105,7 +105,7 @@ int rea_create_table(my_string file_name, fileinfo[26]= (uchar) test((create_info->max_rows == 1) && (create_info->min_rows == 1) && (keys == 0)); int2store(fileinfo+28,key_info_length); - strnmov((char*) forminfo+47,create_info->comment ? create_info->comment : "", + strmake((char*) forminfo+47,create_info->comment ? create_info->comment : "", 60); forminfo[46]=(uchar) strlen((char*)forminfo+47); // Length of comment |