Commit 7de98f2f authored by Michael Widenius's avatar Michael Widenius

Added --log-basename to mysqld to allow one to set the prefix for all logs with one command

Changed test suite to use --log-basename (to get the code tested)
Added --sync-sys=1 to test suite to speed it up.
Better error messages if something goes wrong with mysql_install_db


mysql-test/Makefile.am:
  Removed not existing directory
mysql-test/lib/My/ConfigFactory.pm:
  Use log-basename
  We had to also set 'log_error' as some test was explicitely using the old name
  Added 'sync-sys=1' to speed up test suite
mysql-test/r/variables-notembedded.result:
  Updated test results (variable relay_log is now set)
mysql-test/suite/binlog/t/binlog_delete_and_flush_index-master.opt:
  Force specific names for some log files.
mysql-test/suite/binlog/t/binlog_index-master.opt:
  Force specific names for some log files.
mysql-test/suite/binlog/t/binlog_stm_unsafe_warning-master.opt:
  Force specific names for some log files.
mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test:
  Better error message if something goes wrong
mysql-test/suite/rpl/r/rpl_flushlog_loop.result:
  Updated results
mysql-test/suite/rpl/rpl_1slave_base.cnf:
  Use --log-basename
scripts/mysql_install_db.sh:
  More information to --help
  Write url to knowledge base if something goes wrong
  Fail at once if we can't create a database directory (no reason to continue and write a screenful of not related text)
scripts/mysqld_safe.sh:
  Also allow one to use --data for --datadir (common shortening)
  Added support for --log-basename
  Fail at once if we can't create a log directory
  Fixed bug where we used a pid file name without '.pid' extension
sql/log.cc:
  Create a log file name trough my_once_alloc()  (To get it automaticly freed at exit)
sql/mysql_priv.h:
  Added new prototype
sql/mysqld.cc:
  Added support for --log-basename
  Better help for a lot of log-filename related variables.
sql/rpl_rli.cc:
  Write information that one can use --log-basename
sql/set_var.cc:
  Add log_basename as a readonly variable
parent 0fae0335
...@@ -86,7 +86,7 @@ TEST_DIRS = t r include std_data std_data/parts collections \ ...@@ -86,7 +86,7 @@ TEST_DIRS = t r include std_data std_data/parts collections \
suite/federated \ suite/federated \
suite/pbxt/t suite/pbxt/r suite/pbxt \ suite/pbxt/t suite/pbxt/r suite/pbxt \
suite/vcol suite/vcol/t suite/vcol/r suite/vcol/inc \ suite/vcol suite/vcol/t suite/vcol/r suite/vcol/inc \
suite/oqgraph suite/oqgraph/t suite/oqgraph/r suite/oqgraph/include \ suite/oqgraph suite/oqgraph/t suite/oqgraph/r \
suite/percona suite/sphinx \ suite/percona suite/sphinx \
suite/funcs_1 suite/funcs_1/bitdata \ suite/funcs_1 suite/funcs_1/bitdata \
suite/funcs_1/include suite/funcs_1/lib suite/funcs_1/r \ suite/funcs_1/include suite/funcs_1/lib suite/funcs_1/r \
......
...@@ -200,6 +200,7 @@ my @mysqld_rules= ...@@ -200,6 +200,7 @@ my @mysqld_rules=
( (
{ 'basedir' => sub { return shift->{ARGS}->{basedir}; } }, { 'basedir' => sub { return shift->{ARGS}->{basedir}; } },
{ 'tmpdir' => \&fix_tmpdir }, { 'tmpdir' => \&fix_tmpdir },
{ 'log-basename' => sub { return "mysqld" } },
{ 'character-sets-dir' => \&fix_charset_dir }, { 'character-sets-dir' => \&fix_charset_dir },
{ 'language' => \&fix_language }, { 'language' => \&fix_language },
{ 'datadir' => \&fix_datadir }, { 'datadir' => \&fix_datadir },
...@@ -208,6 +209,7 @@ my @mysqld_rules= ...@@ -208,6 +209,7 @@ my @mysqld_rules=
{ 'port' => \&fix_port }, { 'port' => \&fix_port },
{ '#extra-port' => \&fix_port }, { '#extra-port' => \&fix_port },
{ 'socket' => \&fix_socket }, { 'socket' => \&fix_socket },
{ 'log-error' => \&fix_log_error },
{ '#log-error' => \&fix_log_error }, { '#log-error' => \&fix_log_error },
{ 'general-log' => sub { return 1; } }, { 'general-log' => sub { return 1; } },
{ 'general-log-file' => \&fix_log }, { 'general-log-file' => \&fix_log },
...@@ -216,6 +218,7 @@ my @mysqld_rules= ...@@ -216,6 +218,7 @@ my @mysqld_rules=
{ '#user' => sub { return shift->{ARGS}->{user} || ""; } }, { '#user' => sub { return shift->{ARGS}->{user} || ""; } },
{ '#password' => sub { return shift->{ARGS}->{password} || ""; } }, { '#password' => sub { return shift->{ARGS}->{password} || ""; } },
{ 'server-id' => \&fix_server_id, }, { 'server-id' => \&fix_server_id, },
{ 'sync-sys' => sub { return 1; } },
# By default, prevent the started mysqld to access files outside of vardir # By default, prevent the started mysqld to access files outside of vardir
{ 'secure-file-priv' => sub { return shift->{ARGS}->{vardir}; } }, { 'secure-file-priv' => sub { return shift->{ARGS}->{vardir}; } },
{ 'ssl-ca' => \&fix_ssl_ca }, { 'ssl-ca' => \&fix_ssl_ca },
......
...@@ -33,12 +33,12 @@ ERROR HY000: Variable 'log_slave_updates' is a read only variable ...@@ -33,12 +33,12 @@ ERROR HY000: Variable 'log_slave_updates' is a read only variable
# #
SHOW VARIABLES like 'relay_log'; SHOW VARIABLES like 'relay_log';
Variable_name Value Variable_name Value
relay_log relay_log mysqld-relay-bin
SELECT @@session.relay_log; SELECT @@session.relay_log;
ERROR HY000: Variable 'relay_log' is a GLOBAL variable ERROR HY000: Variable 'relay_log' is a GLOBAL variable
SELECT @@global.relay_log; SELECT @@global.relay_log;
@@global.relay_log @@global.relay_log
NULL mysqld-relay-bin
SET @@session.relay_log= 'x'; SET @@session.relay_log= 'x';
ERROR HY000: Variable 'relay_log' is a read only variable ERROR HY000: Variable 'relay_log' is a read only variable
SET @@global.relay_log= 'x'; SET @@global.relay_log= 'x';
...@@ -46,12 +46,12 @@ ERROR HY000: Variable 'relay_log' is a read only variable ...@@ -46,12 +46,12 @@ ERROR HY000: Variable 'relay_log' is a read only variable
# #
SHOW VARIABLES like 'relay_log_index'; SHOW VARIABLES like 'relay_log_index';
Variable_name Value Variable_name Value
relay_log_index relay_log_index mysqld-relay-bin.index
SELECT @@session.relay_log_index; SELECT @@session.relay_log_index;
ERROR HY000: Variable 'relay_log_index' is a GLOBAL variable ERROR HY000: Variable 'relay_log_index' is a GLOBAL variable
SELECT @@global.relay_log_index; SELECT @@global.relay_log_index;
@@global.relay_log_index @@global.relay_log_index
NULL mysqld-relay-bin.index
SET @@session.relay_log_index= 'x'; SET @@session.relay_log_index= 'x';
ERROR HY000: Variable 'relay_log_index' is a read only variable ERROR HY000: Variable 'relay_log_index' is a read only variable
SET @@global.relay_log_index= 'x'; SET @@global.relay_log_index= 'x';
......
--log-bin=master-bin --log-bin-index=master-bin
--force-restart --skip-stack-trace --test-expect-abort --log-warnings=0 --force-restart --skip-stack-trace --test-expect-abort --log-warnings=0 --log-bin=master-bin --log-bin-index=master-bin
--binlog-ignore-db=b42851 --log-error --binlog-ignore-db=b42851 --log-error --log-bin=master-bin --log-bin-index=master-bin
...@@ -101,6 +101,7 @@ if(!`select LENGTH('$log_error_')`) ...@@ -101,6 +101,7 @@ if(!`select LENGTH('$log_error_')`)
# does not know the location of its .err log, use default location # does not know the location of its .err log, use default location
let $log_error_ = $MYSQLTEST_VARDIR/log/mysqld.1.err; let $log_error_ = $MYSQLTEST_VARDIR/log/mysqld.1.err;
} }
# Assign env variable LOG_ERROR # Assign env variable LOG_ERROR
let LOG_ERROR=$log_error_; let LOG_ERROR=$log_error_;
...@@ -109,8 +110,9 @@ let LOG_ERROR=$log_error_; ...@@ -109,8 +110,9 @@ let LOG_ERROR=$log_error_;
perl; perl;
use strict; use strict;
use Cwd;
my $log_error= $ENV{'LOG_ERROR'} or die "LOG_ERROR not set"; my $log_error= $ENV{'LOG_ERROR'} or die "LOG_ERROR not set";
open(FILE, "$log_error") or die("Unable to open $log_error: $!\n"); open(FILE, "$log_error") or die("Unable to open '$log_error' from directory " . cwd() . "\n");
my $count = () = grep(/Bug#46265/g,<FILE>); my $count = () = grep(/Bug#46265/g,<FILE>);
print "Occurrences: $count\n"; print "Occurrences: $count\n";
close(FILE); close(FILE);
......
...@@ -2,7 +2,7 @@ include/rpl_init.inc [topology=1->2->1] ...@@ -2,7 +2,7 @@ include/rpl_init.inc [topology=1->2->1]
show variables like 'relay_log%'; show variables like 'relay_log%';
Variable_name Value Variable_name Value
relay_log master-relay-bin relay_log master-relay-bin
relay_log_index relay_log_index master-relay-bin.index
relay_log_info_file relay-log.info relay_log_info_file relay-log.info
relay_log_purge ON relay_log_purge ON
relay_log_space_limit 0 relay_log_space_limit 0
......
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
# Run the master.sh script before starting this process # Run the master.sh script before starting this process
#!run-master-sh #!run-master-sh
log-bin= master-bin log-basename= master
relay-log= master-relay-bin # log-bin= master-bin
# relay-log= master-relay-bin
[mysqld.2] [mysqld.2]
# Run the slave.sh script before starting this process # Run the slave.sh script before starting this process
...@@ -17,7 +18,8 @@ relay-log= master-relay-bin ...@@ -17,7 +18,8 @@ relay-log= master-relay-bin
# starting the mysqld # starting the mysqld
#!use-slave-opt #!use-slave-opt
relay-log= slave-relay-bin log-basename= slave
# relay-log= slave-relay-bin
init-rpl-role= slave init-rpl-role= slave
log-slave-updates log-slave-updates
......
...@@ -50,6 +50,8 @@ Usage: $0 [OPTIONS] ...@@ -50,6 +50,8 @@ Usage: $0 [OPTIONS]
use hostnames will use IP addresses. use hostnames will use IP addresses.
--ldata=path The path to the MariaDB data directory. Same as --ldata=path The path to the MariaDB data directory. Same as
--datadir. --datadir.
--no-defaults Don't read any configuration files (my.cnf).
--defaults-file=path Read only this configuration file.
--rpm For internal use. This option is used by RPM files --rpm For internal use. This option is used by RPM files
during the MariaDB installation process. during the MariaDB installation process.
--skip-name-resolve Use IP addresses rather than hostnames when creating --skip-name-resolve Use IP addresses rather than hostnames when creating
...@@ -79,6 +81,13 @@ s_echo() ...@@ -79,6 +81,13 @@ s_echo()
fi fi
} }
link_to_help()
{
echo
echo "The latest information about mysql_install_db is available at"
echo "http://kb.askmonty.org/v/installing-system-tables-mysql_install_db."
}
parse_arg() parse_arg()
{ {
echo "$1" | sed -e 's/^[^=]*=//' echo "$1" | sed -e 's/^[^=]*=//'
...@@ -194,7 +203,7 @@ cannot_find_file() ...@@ -194,7 +203,7 @@ cannot_find_file()
echo "If you are using a binary release, you must either be at the top" echo "If you are using a binary release, you must either be at the top"
echo "level of the extracted archive, or pass the --basedir option" echo "level of the extracted archive, or pass the --basedir option"
echo "pointing to that location." echo "pointing to that location."
echo link_to_help
} }
# Ok, let's go. We first need to parse arguments which are required by # Ok, let's go. We first need to parse arguments which are required by
...@@ -213,6 +222,7 @@ parse_arguments PICK-ARGS-FROM-ARGV "$@" ...@@ -213,6 +222,7 @@ parse_arguments PICK-ARGS-FROM-ARGV "$@"
if test -n "$srcdir" && test -n "$basedir" if test -n "$srcdir" && test -n "$basedir"
then then
echo "ERROR: Specify either --basedir or --srcdir, not both." echo "ERROR: Specify either --basedir or --srcdir, not both."
link_to_help
exit 1 exit 1
fi fi
if test -n "$srcdir" if test -n "$srcdir"
...@@ -335,6 +345,7 @@ then ...@@ -335,6 +345,7 @@ then
echo "hostname." echo "hostname."
echo "If you want to solve this at a later stage, restart this script" echo "If you want to solve this at a later stage, restart this script"
echo "with the --force option" echo "with the --force option"
link_to_help
exit 1 exit 1
fi fi
echo "WARNING: The host '$hostname' could not be looked up with resolveip." echo "WARNING: The host '$hostname' could not be looked up with resolveip."
...@@ -356,7 +367,12 @@ for dir in $ldata $ldata/mysql $ldata/test ...@@ -356,7 +367,12 @@ for dir in $ldata $ldata/mysql $ldata/test
do do
if test ! -d $dir if test ! -d $dir
then then
mkdir -p $dir if ! `mkdir -p $dir`
then
echo "Fatal error Can't create database directory '$dir'"
link_to_help
exit 1
fi
chmod 700 $dir chmod 700 $dir
fi fi
if test -w / -a ! -z "$user" if test -w / -a ! -z "$user"
...@@ -389,7 +405,7 @@ mysqld_install_cmd_line="$mysqld_bootstrap $defaults $mysqld_opt --bootstrap \ ...@@ -389,7 +405,7 @@ mysqld_install_cmd_line="$mysqld_bootstrap $defaults $mysqld_opt --bootstrap \
--net_buffer_length=16K" --net_buffer_length=16K"
# Create the system and help tables by passing them to "mysqld --bootstrap" # Create the system and help tables by passing them to "mysqld --bootstrap"
s_echo "Installing MariaDB/MySQL system tables..." s_echo "Installing MariaDB/MySQL system tables in '$ldata' ..."
if { echo "use mysql;"; cat $create_system_tables $fill_system_tables; } | eval "$filter_cmd_line" | $mysqld_install_cmd_line > /dev/null if { echo "use mysql;"; cat $create_system_tables $fill_system_tables; } | eval "$filter_cmd_line" | $mysqld_install_cmd_line > /dev/null
then then
s_echo "OK" s_echo "OK"
...@@ -410,9 +426,7 @@ else ...@@ -410,9 +426,7 @@ else
echo echo
echo "Try 'mysqld --help' if you have problems with paths. Using" echo "Try 'mysqld --help' if you have problems with paths. Using"
echo "--general-log gives you a log in $ldata that may be helpful." echo "--general-log gives you a log in $ldata that may be helpful."
echo link_to_help
echo "The latest information about mysql_install_db is available at"
echo "http://kb.askmonty.org/v/installing-system-tables-mysql_install_db."
echo "MariaDB is hosted on launchpad; You can find the latest source and" echo "MariaDB is hosted on launchpad; You can find the latest source and"
echo "email lists at http://launchpad.net/maria" echo "email lists at http://launchpad.net/maria"
echo echo
...@@ -454,13 +468,13 @@ then ...@@ -454,13 +468,13 @@ then
echo "databases and anonymous user created by default. This is" echo "databases and anonymous user created by default. This is"
echo "strongly recommended for production servers." echo "strongly recommended for production servers."
echo echo
echo "See the MySQL manual for more instructions." echo "See the MariaDB knowledge or the MySQL manual for more instructions."
if test "$in_rpm" -eq 0 if test "$in_rpm" -eq 0
then then
echo echo
echo "You can start the MariaDB daemon with:" echo "You can start the MariaDB daemon with:"
echo "cd $basedir ; $bindir/mysqld_safe &" echo "cd $basedir ; $bindir/mysqld_safe --datadir=$ldata"
echo echo
echo "You can test the MariaDB daemon with mysql-test-run.pl" echo "You can test the MariaDB daemon with mysql-test-run.pl"
echo "cd $basedir/mysql-test ; perl mysql-test-run.pl" echo "cd $basedir/mysql-test ; perl mysql-test-run.pl"
......
...@@ -159,9 +159,13 @@ parse_arguments() { ...@@ -159,9 +159,13 @@ parse_arguments() {
case "$arg" in case "$arg" in
# these get passed explicitly to mysqld # these get passed explicitly to mysqld
--basedir=*) MY_BASEDIR_VERSION="$val" ;; --basedir=*) MY_BASEDIR_VERSION="$val" ;;
--datadir=*) DATADIR="$val" ;; --datadir=*|--data=*) DATADIR="$val" ;;
--pid-file=*) pid_file="$val" ;; --pid-file=*) pid_file="$val" ;;
--user=*) user="$val"; SET_USER=1 ;; --user=*) user="$val"; SET_USER=1 ;;
--log-basename=*|--hostname=*|--loose-log-basename=*)
pid_file="$val.pid";
err_log="$val.err";
;;
# these might have been set in a [mysqld_safe] section of my.cnf # these might have been set in a [mysqld_safe] section of my.cnf
# they are added to mysqld command line to override settings from my.cnf # they are added to mysqld command line to override settings from my.cnf
...@@ -411,7 +415,11 @@ safe_mysql_unix_port=${mysql_unix_port:-${MYSQL_UNIX_PORT:-@MYSQL_UNIX_ADDR@}} ...@@ -411,7 +415,11 @@ safe_mysql_unix_port=${mysql_unix_port:-${MYSQL_UNIX_PORT:-@MYSQL_UNIX_ADDR@}}
mysql_unix_port_dir=`dirname $safe_mysql_unix_port` mysql_unix_port_dir=`dirname $safe_mysql_unix_port`
if [ ! -d $mysql_unix_port_dir ] if [ ! -d $mysql_unix_port_dir ]
then then
mkdir $mysql_unix_port_dir if ! `mkdir -p $mysql_unix_port_dir`
then
echo "Fatal error Can't create database directory '$mysql_unix_port'"
exit 1
fi
chown $user $mysql_unix_port_dir chown $user $mysql_unix_port_dir
chmod 755 $mysql_unix_port_dir chmod 755 $mysql_unix_port_dir
fi fi
...@@ -434,14 +442,14 @@ fi ...@@ -434,14 +442,14 @@ fi
if test -z "$pid_file" if test -z "$pid_file"
then then
pid_file="$DATADIR/`@HOSTNAME@`.pid" pid_file="`@HOSTNAME@`.pid"
else
case "$pid_file" in
/* ) ;;
* ) pid_file="$DATADIR/$pid_file" ;;
esac
fi fi
# MariaDB wants pid file without datadir
append_arg_to_args "--pid-file=$pid_file" append_arg_to_args "--pid-file=$pid_file"
case "$pid_file" in
/* ) ;;
* ) pid_file="$DATADIR/$pid_file" ;;
esac
if test -n "$mysql_unix_port" if test -n "$mysql_unix_port"
then then
......
...@@ -112,6 +112,27 @@ char *make_default_log_name(char *buff,const char* log_ext) ...@@ -112,6 +112,27 @@ char *make_default_log_name(char *buff,const char* log_ext)
MYF(MY_UNPACK_FILENAME|MY_REPLACE_EXT)); MYF(MY_UNPACK_FILENAME|MY_REPLACE_EXT));
} }
/*
Create a filename from a base with a given suffix.
The name is allocated trough my_once_alloc(), so one should only
use this for startup options that can all be freed at once.
*/
char *make_once_alloced_filename(const char *basename, const char *ext)
{
char buff[FN_REFLEN+10], *end, *res;
size_t length;
strmake(buff, basename, sizeof(buff)-10);
end= strmov(fn_ext(buff), ext);
length= (size_t) (end - buff) + 1;
if ((res= (char*) my_once_alloc(length, MYF(MY_WME))))
memcpy(res, buff, length);
return res;
}
/* /*
Helper class to hold a mutex for the duration of the Helper class to hold a mutex for the duration of the
block. block.
......
...@@ -1625,6 +1625,7 @@ void remove_db_from_cache(const char *db); ...@@ -1625,6 +1625,7 @@ void remove_db_from_cache(const char *db);
void flush_tables(); void flush_tables();
bool is_equal(const LEX_STRING *a, const LEX_STRING *b); bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
char *make_default_log_name(char *buff,const char* log_ext); char *make_default_log_name(char *buff,const char* log_ext);
char *make_once_alloced_filename(const char *basename, const char *ext);
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
uint fast_alter_partition_table(THD *thd, TABLE *table, uint fast_alter_partition_table(THD *thd, TABLE *table,
...@@ -1966,7 +1967,7 @@ extern MYSQL_PLUGIN_IMPORT uint reg_ext_length; ...@@ -1966,7 +1967,7 @@ extern MYSQL_PLUGIN_IMPORT uint reg_ext_length;
#ifdef MYSQL_SERVER #ifdef MYSQL_SERVER
extern char glob_hostname[FN_REFLEN], mysql_home[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 pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
extern char log_error_file[FN_REFLEN], *opt_tc_log_file; extern char log_error_file[FN_REFLEN], *opt_tc_log_file, *opt_log_basename;
extern ulonglong log_10_int[20]; extern ulonglong log_10_int[20];
extern ulonglong keybuff_size; extern ulonglong keybuff_size;
extern ulonglong thd_startup_options; extern ulonglong thd_startup_options;
......
This diff is collapsed.
...@@ -170,7 +170,8 @@ a file name for --relay-log-index option", opt_relaylog_index_name); ...@@ -170,7 +170,8 @@ a file name for --relay-log-index option", opt_relaylog_index_name);
" so replication " " so replication "
"may break when this MySQL server acts as a " "may break when this MySQL server acts as a "
"slave and has his hostname changed!! Please " "slave and has his hostname changed!! Please "
"use '--relay-log=%s' to avoid this problem.", ln); "use '--log-basename=%' or '--relay-log=%s' to avoid "
"this problem.", ln);
name_warning_sent= 1; name_warning_sent= 1;
} }
/* /*
......
...@@ -895,6 +895,8 @@ static sys_var_thd_set sys_log_slow_verbosity(&vars, ...@@ -895,6 +895,8 @@ static sys_var_thd_set sys_log_slow_verbosity(&vars,
/* Global read-only variable containing hostname */ /* Global read-only variable containing hostname */
static sys_var_const_str sys_hostname(&vars, "hostname", glob_hostname); static sys_var_const_str sys_hostname(&vars, "hostname", glob_hostname);
static sys_var_const_str_ptr sys_log_basename(&vars, "log_basename",
&opt_log_basename);
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
static sys_var_const_str_ptr sys_repl_report_host(&vars, "report_host", &report_host); static sys_var_const_str_ptr sys_repl_report_host(&vars, "report_host", &report_host);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment