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 /client/mysqlbinlog.cc | |
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 'client/mysqlbinlog.cc')
-rw-r--r-- | client/mysqlbinlog.cc | 81 |
1 files changed, 39 insertions, 42 deletions
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 3020e105954..f7b381d72fa 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -20,7 +20,9 @@ #include <time.h> #include "log_event.h" -#define PROBE_HEADER_LEN (4+EVENT_LEN_OFFSET+4) +#define BIN_LOG_HEADER_SIZE 4 +#define PROBE_HEADER_LEN (BIN_LOG_HEADER_SIZE+EVENT_LEN_OFFSET+4) + #define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | CLIENT_LOCAL_FILES) @@ -178,8 +180,7 @@ static my_bool get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *argument) { - switch(optid) - { + switch(optid) { #ifndef DBUG_OFF case '#': DBUG_PUSH(argument ? argument : default_dbug_option); @@ -234,7 +235,7 @@ static MYSQL* safe_connect() if(!local_mysql) die("Failed on mysql_init"); - if(!mysql_real_connect(local_mysql, host, user, pass, 0, port, 0, 0)) + if (!mysql_real_connect(local_mysql, host, user, pass, 0, port, 0, 0)) die("failed on connect: %s", mysql_error(local_mysql)); return local_mysql; @@ -242,7 +243,7 @@ static MYSQL* safe_connect() static void dump_log_entries(const char* logname) { - if(use_remote) + if (use_remote) dump_remote_log_entries(logname); else dump_local_log_entries(logname); @@ -254,7 +255,7 @@ static void dump_remote_table(NET* net, const char* db, const char* table) char * p = buf; uint table_len = (uint) strlen(table); uint db_len = (uint) strlen(db); - if(table_len + db_len > sizeof(buf) - 2) + if (table_len + db_len > sizeof(buf) - 2) die("Buffer overrun"); *p++ = db_len; @@ -263,14 +264,14 @@ static void dump_remote_table(NET* net, const char* db, const char* table) *p++ = table_len; memcpy(p, table, table_len); - if(simple_command(mysql, COM_TABLE_DUMP, buf, p - buf + table_len, 1)) + if (simple_command(mysql, COM_TABLE_DUMP, buf, p - buf + table_len, 1)) die("Error sending the table dump command"); - for(;;) + for (;;) { uint packet_len = my_net_read(net); - if(packet_len == 0) break; // end of file - if(packet_len == packet_error) + if (packet_len == 0) break; // end of file + if (packet_len == packet_error) die("Error reading packet in table dump"); my_fwrite(result_file, (byte*)net->read_pos, packet_len, MYF(MY_WME)); fflush(result_file); @@ -284,8 +285,8 @@ static int check_master_version(MYSQL* mysql) const char* version; int old_format = 0; - if (mysql_query(mysql, "SELECT VERSION()") - || !(res = mysql_store_result(mysql))) + if (mysql_query(mysql, "SELECT VERSION()") || + !(res = mysql_store_result(mysql))) { mysql_close(mysql); die("Error checking master version: %s", @@ -305,12 +306,12 @@ static int check_master_version(MYSQL* mysql) die("Master reported NULL for the version"); } - switch (*version) - { + switch (*version) { case '3': old_format = 1; break; case '4': + case '5': old_format = 0; break; default: @@ -324,6 +325,7 @@ static int check_master_version(MYSQL* mysql) return old_format; } + static void dump_remote_log_entries(const char* logname) { char buf[128]; @@ -333,38 +335,38 @@ static void dump_remote_log_entries(const char* logname) int old_format; old_format = check_master_version(mysql); - if(!position) position = 4; // protect the innocent from spam - if (position < 4) + if (!position) + position = BIN_LOG_HEADER_SIZE; // protect the innocent from spam + if (position < BIN_LOG_HEADER_SIZE) { - position = 4; + position = BIN_LOG_HEADER_SIZE; // warn the guity - sql_print_error("Warning: The position in the binary log can't be less than 4.\nStarting from position 4\n"); + sql_print_error("Warning: The position in the binary log can't be less than %d.\nStarting from position %d\n", BIN_LOG_HEADER_SIZE, BIN_LOG_HEADER_SIZE); } int4store(buf, position); - int2store(buf + 4, binlog_flags); + int2store(buf + BIN_LOG_HEADER_SIZE, binlog_flags); len = (uint) strlen(logname); int4store(buf + 6, 0); memcpy(buf + 10, logname,len); if (simple_command(mysql, COM_BINLOG_DUMP, buf, len + 10, 1)) die("Error sending the log dump command"); - for(;;) + for (;;) { const char *error; len = net_safe_read(mysql); if (len == packet_error) die("Error reading packet from server: %s", mysql_error(mysql)); - if(len == 1 && net->read_pos[0] == 254) + if (len == 1 && net->read_pos[0] == 254) break; // end of data DBUG_PRINT("info",( "len= %u, net->read_pos[5] = %d\n", len, net->read_pos[5])); - Log_event * ev = Log_event::read_log_event( - (const char*) net->read_pos + 1 , - len - 1, &error, old_format); + Log_event *ev = Log_event::read_log_event((const char*) net->read_pos + 1 , + len - 1, &error, old_format); if (ev) { ev->print(result_file, short_form, last_db); - if(ev->get_type_code() == LOAD_EVENT) + if (ev->get_type_code() == LOAD_EVENT) dump_remote_file(net, ((Load_log_event*)ev)->fname); delete ev; } @@ -373,10 +375,11 @@ static void dump_remote_log_entries(const char* logname) } } + static int check_header(IO_CACHE* file) { byte buf[PROBE_HEADER_LEN]; - int old_format; + int old_format=0; my_off_t pos = my_b_tell(file); my_b_seek(file, (my_off_t)0); @@ -388,8 +391,6 @@ static int check_header(IO_CACHE* file) event_len = uint4korr(buf + EVENT_LEN_OFFSET + 4); old_format = (event_len < LOG_EVENT_HEADER_LEN + START_HEADER_LEN); } - else - old_format = 0; my_b_seek(file, pos); return old_format; } @@ -425,7 +426,7 @@ static void dump_local_log_entries(const char* logname) for (length= (my_off_t) position ; length > 0 ; length-=tmp) { tmp=min(length,sizeof(buff)); - if (my_b_read(file,buff, (uint) tmp)) + if (my_b_read(file, buff, (uint) tmp)) exit(1); } } @@ -435,10 +436,10 @@ static void dump_local_log_entries(const char* logname) if (!position) { - char magic[4]; + char magic[BIN_LOG_HEADER_SIZE]; if (my_b_read(file, (byte*) magic, sizeof(magic))) die("I/O error reading binlog magic number"); - if(memcmp(magic, BINLOG_MAGIC, 4)) + if (memcmp(magic, BINLOG_MAGIC, 4)) die("Bad magic number; The file is probably not a MySQL binary log"); } @@ -498,7 +499,7 @@ Could not read entry at offset %s : Error in log format or read error", rec_count++; delete ev; } - if(fd >= 0) + if (fd >= 0) my_close(fd, MYF(MY_WME)); end_io_cache(file); } @@ -509,34 +510,30 @@ int main(int argc, char** argv) MY_INIT(argv[0]); parse_args(&argc, (char***)&argv); - if(!argc && !table) + if (!argc && !table) { usage(); return -1; } - if(use_remote) - { + if (use_remote) mysql = safe_connect(); - } if (table) { - if(!use_remote) + if (!use_remote) die("You must specify connection parameter to get table dump"); - char* db = (char*)table; + char* db = (char*) table; char* tbl = (char*) strchr(table, '.'); - if(!tbl) + if (!tbl) die("You must use database.table syntax to specify the table"); *tbl++ = 0; dump_remote_table(&mysql->net, db, tbl); } else { - while(--argc >= 0) - { + while (--argc >= 0) dump_log_entries(*(argv++)); - } } if (result_file != stdout) my_fclose(result_file, MYF(0)); |