From 3587de7eaad49d4459d602e2ad40a9d9383ca2da Mon Sep 17 00:00:00 2001 From: Mark Callaghan Date: Wed, 20 Oct 2010 18:36:18 -0700 Subject: [PATCH] Add global variables to list directory for binlog files and binlog index file Summary: The variables are binlog_file_basedir and binlog_index_basedir. Task ID: # Blame Rev: Reviewers: ryandmack CC: dba@lists.facebook.com Test Plan: mtr, test on real install Revert Plan: Database Impact: Memcache Impact: Other Notes: EImportant: - begin *PUBLIC* platform impact section - Bugzilla: # - end platform impact - DiffCamp Revision: 172441 --- mysql-test/r/binlog_basedir.result | 4 +++ mysql-test/suite/rpl/r/rpl_binlog_basedir.result | 10 ++++++++ mysql-test/suite/rpl/t/rpl_binlog_basedir.test | 3 ++ mysql-test/t/binlog_basedir.test | 1 + sql/mysql_priv.h | 1 + sql/mysqld.cc | 28 ++++++++++++++++++++++ sql/set_var.cc | 5 ++++ 7 files changed, 52 insertions(+), 0 deletions(-) create mode 100644 mysql-test/r/binlog_basedir.result create mode 100644 mysql-test/suite/rpl/r/rpl_binlog_basedir.result create mode 100644 mysql-test/suite/rpl/t/rpl_binlog_basedir.test create mode 100644 mysql-test/t/binlog_basedir.test diff --git a/mysql-test/r/binlog_basedir.result b/mysql-test/r/binlog_basedir.result new file mode 100644 index 0000000..95fa81e --- /dev/null +++ b/mysql-test/r/binlog_basedir.result @@ -0,0 +1,4 @@ +show global variables like "binlog%basedir"; +Variable_name Value +binlog_file_basedir +binlog_index_basedir diff --git a/mysql-test/suite/rpl/r/rpl_binlog_basedir.result b/mysql-test/suite/rpl/r/rpl_binlog_basedir.result new file mode 100644 index 0000000..6f774c7 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_binlog_basedir.result @@ -0,0 +1,10 @@ +stop slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +reset master; +reset slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +start slave; +show global variables like "binlog%basedir"; +Variable_name Value +binlog_file_basedir ./ +binlog_index_basedir ./ diff --git a/mysql-test/suite/rpl/t/rpl_binlog_basedir.test b/mysql-test/suite/rpl/t/rpl_binlog_basedir.test new file mode 100644 index 0000000..70eb900 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_binlog_basedir.test @@ -0,0 +1,3 @@ +-- source include/master-slave.inc + +show global variables like "binlog%basedir"; diff --git a/mysql-test/t/binlog_basedir.test b/mysql-test/t/binlog_basedir.test new file mode 100644 index 0000000..1ac2a45 --- /dev/null +++ b/mysql-test/t/binlog_basedir.test @@ -0,0 +1 @@ +show global variables like "binlog%basedir"; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index ed1841b..872ac78 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -1953,6 +1953,7 @@ extern MYSQL_PLUGIN_IMPORT char reg_ext[FN_EXTLEN]; extern MYSQL_PLUGIN_IMPORT uint reg_ext_length; #endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */ #ifdef MYSQL_SERVER +extern char binlog_file_basedir[FN_REFLEN], binlog_index_basedir[FN_REFLEN]; extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN]; extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file; extern char log_error_file[FN_REFLEN], *opt_tc_log_file; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 124832c..6f6cc2d 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -654,6 +654,8 @@ const char *log_output_str= "FILE"; time_t server_start_time, flush_status_time; +char binlog_file_basedir[FN_REFLEN]; +char binlog_index_basedir[FN_REFLEN]; char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN], system_time_zone[30]; char *default_tz_name; char log_error_file[FN_REFLEN], glob_hostname[FN_REFLEN]; @@ -4239,6 +4241,32 @@ a file name for --log-bin-index option", opt_binlog_index_name); WRITE_CACHE, 0, max_binlog_size, 0, TRUE)) unireg_abort(1); + if (opt_bin_log) + { + size_t ilen, llen; + const char* log_name = mysql_bin_log.get_log_fname(); + const char* index_name = mysql_bin_log.get_index_fname(); + + if (!log_name || !dirname_part(binlog_file_basedir, log_name, &llen)) + { + sql_print_error("Cannot get basedir for binlogs from (%s)\n", + log_name ? log_name : "NULL"); + unireg_abort(1); + } + if (!index_name || !dirname_part(binlog_index_basedir, index_name, &ilen)) + { + sql_print_error("Cannot get basedir for binlog-index from (%s)\n", + index_name ? index_name : "NULL"); + unireg_abort(1); + } + } + else + { + binlog_file_basedir[0] = '\0'; + binlog_index_basedir[0] = '\0'; + } + + #ifdef HAVE_REPLICATION if (opt_bin_log && expire_logs_days) { diff --git a/sql/set_var.cc b/sql/set_var.cc index a4a9c64..4f1d52a 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -189,6 +189,11 @@ static sys_var_const sys_back_log(&vars, "back_log", OPT_GLOBAL, SHOW_LONG, (uchar*) &back_log); static sys_var_const_os_str sys_basedir(&vars, "basedir", mysql_home); +static sys_var_const_os_str sys_binlog_file_basedir(&vars, "binlog_file_basedir", + binlog_file_basedir); +static sys_var_const_os_str sys_binlog_index_basedir(&vars, "binlog_index_basedir", + binlog_index_basedir); + static sys_var_long_ptr sys_binlog_cache_size(&vars, "binlog_cache_size", &binlog_cache_size); static sys_var_thd_binlog_format sys_binlog_format(&vars, "binlog_format", -- 1.6.0.4.609.g474fc