From e439e7c649132351c7807a15ff76917d0a6d7280 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 19 May 2005 12:34:15 +0200 Subject: CSC#4944: Adding File_size to output of SHOW BINARY lOGS mysql-test/r/rpl_log.result: Adding File_size to output of SHOW BINARY lOGS mysql-test/r/rpl_rotate_logs.result: Adding File_size to output of SHOW BINARY lOGS sql/sql_repl.cc: Adding File_size to output of SHOW BINARY lOGS --- sql/sql_repl.cc | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'sql/sql_repl.cc') diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index d02bb5ff0a3..24b78bc9a3d 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1337,6 +1337,11 @@ int show_binlog_info(THD* thd) int show_binlogs(THD* thd) { IO_CACHE *index_file; + LOG_INFO cur; + IO_CACHE log; + File file; + const char *errmsg= 0; + MY_STAT stat_area; char fname[FN_REFLEN]; List field_list; uint length; @@ -1351,20 +1356,42 @@ int show_binlogs(THD* thd) } field_list.push_back(new Item_empty_string("Log_name", 255)); + field_list.push_back(new Item_return_int("File_size", 20, + MYSQL_TYPE_LONGLONG)); if (protocol->send_fields(&field_list, 1)) DBUG_RETURN(1); mysql_bin_log.lock_index(); index_file=mysql_bin_log.get_index_file(); - + + mysql_bin_log.get_current_log(&cur); + int cur_dir_len = dirname_length(cur.log_file_name); + reinit_io_cache(index_file, READ_CACHE, (my_off_t) 0, 0, 0); /* The file ends with EOF or empty line */ while ((length=my_b_gets(index_file, fname, sizeof(fname))) > 1) { + fname[--length] = '\0'; /* remove the newline */ + protocol->prepare_for_resend(); int dir_len = dirname_length(fname); - /* The -1 is for removing newline from fname */ - protocol->store(fname + dir_len, length-1-dir_len, &my_charset_bin); + protocol->store(fname + dir_len, length-dir_len, &my_charset_bin); + if(!(strncmp(fname+dir_len, cur.log_file_name+cur_dir_len, length-dir_len))) + { + /* this is the active log, use the active position */ + protocol->store((ulonglong) cur.pos); + } else { + /* this is an old log, open it and find the size */ + if ((file=open_binlog(&log, fname+dir_len, &errmsg)) >= 0) + { + protocol->store((ulonglong) my_b_filelength(&log)); + end_io_cache(&log); + my_close(file, MYF(0)); + } else { + /* the file wasn't openable, but 0 is an invalid value anyway */ + protocol->store((ulonglong) 0); + } + } if (protocol->write()) goto err; } -- cgit v1.2.1 From 549f56dc3d7fdae2cf7d8ebfbc8a118bf21f12a0 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 25 May 2005 12:56:47 +0300 Subject: Cleanup during code review Faster detection of wrong table names (like PRN) on windows include/my_sys.h: Added check_if_legal_filename() mysys/my_access.c: Added check_if_legal_filename() Set errno if my_access() fails mysys/my_fopen.c: USe check_if_legal_filename() instead of my_access() to detect wrong file names on windows mysys/my_open.c: USe check_if_legal_filename() instead of my_access() to detect wrong file names on windows sql/sql_lex.cc: Portability fix sql/sql_parse.cc: Simple cleanup sql/sql_repl.cc: Cleanup during code review --- sql/sql_repl.cc | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'sql/sql_repl.cc') diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 24b78bc9a3d..4249c9e1809 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -152,7 +152,8 @@ File open_binlog(IO_CACHE *log, const char *log_file_name, File file; DBUG_ENTER("open_binlog"); - if ((file = my_open(log_file_name, O_RDONLY | O_BINARY, MYF(MY_WME))) < 0) + if ((file = my_open(log_file_name, O_RDONLY | O_BINARY | O_SHARE, + MYF(MY_WME))) < 0) { sql_print_error("Failed to open log (\ file '%s', errno %d)", log_file_name, my_errno); @@ -1338,13 +1339,11 @@ int show_binlogs(THD* thd) { IO_CACHE *index_file; LOG_INFO cur; - IO_CACHE log; File file; - const char *errmsg= 0; - MY_STAT stat_area; char fname[FN_REFLEN]; List field_list; uint length; + int cur_dir_len; Protocol *protocol= thd->protocol; DBUG_ENTER("show_binlogs"); @@ -1364,34 +1363,35 @@ int show_binlogs(THD* thd) index_file=mysql_bin_log.get_index_file(); mysql_bin_log.get_current_log(&cur); - int cur_dir_len = dirname_length(cur.log_file_name); + cur_dir_len= dirname_length(cur.log_file_name); reinit_io_cache(index_file, READ_CACHE, (my_off_t) 0, 0, 0); /* The file ends with EOF or empty line */ while ((length=my_b_gets(index_file, fname, sizeof(fname))) > 1) { - fname[--length] = '\0'; /* remove the newline */ + int dir_len; + ulonglong file_length= 0; // Length if open fails + fname[--length] = '\0'; // remove the newline protocol->prepare_for_resend(); - int dir_len = dirname_length(fname); - protocol->store(fname + dir_len, length-dir_len, &my_charset_bin); - if(!(strncmp(fname+dir_len, cur.log_file_name+cur_dir_len, length-dir_len))) + dir_len= dirname_length(fname); + length-= dir_len; + protocol->store(fname + dir_len, length, &my_charset_bin); + + if (!(strncmp(fname+dir_len, cur.log_file_name+cur_dir_len, length))) + file_length= cur.pos; /* The active log, use the active position */ + else { - /* this is the active log, use the active position */ - protocol->store((ulonglong) cur.pos); - } else { /* this is an old log, open it and find the size */ - if ((file=open_binlog(&log, fname+dir_len, &errmsg)) >= 0) + if ((file= my_open(fname+dir_len, O_RDONLY | O_SHARE | O_BINARY, + MYF(0))) >= 0) { - protocol->store((ulonglong) my_b_filelength(&log)); - end_io_cache(&log); + file_length= (ulonglong) my_seek(file, 0L, MY_SEEK_END, MYF(0)); my_close(file, MYF(0)); - } else { - /* the file wasn't openable, but 0 is an invalid value anyway */ - protocol->store((ulonglong) 0); } } + protocol->store(file_length); if (protocol->write()) goto err; } -- cgit v1.2.1