Commit 137d8ed3 authored by Julius Goryavsky's avatar Julius Goryavsky

MDEV-18863: Galera SST scripts can't read [mysqldN] option groups

Some users and some scripts (for example, mysqld_multi.sh) use special
option groups with names like [mysqld1], [mysqld2], ..., [mysqldN].

But SST scripts can't currently fully support these option groups.
The only option group-related value it gets from the server is
--defaults-group-suffix, if that option was set for mysqld when
the server was started.

However, the SST scripts does not get told by the server to read
these option groups, so this means that the SST script will fail
to read options like innodb-data-home-dir when it is in a option
group like [mysqld1]...[mysqldN].

Moreover, SST scripts ignore many parameters that can be passed
to them explicitly and cannot transfer them further, for example,
to the input of mariabackup utility. Ideally, we want to transfer
all the parameters of the original mysqld call to utilities such
as mariabackup, however the SST script does not receive these
parameters from the server and therefore cannot transfer them to
mariabackup.

To correct these shortcomings, we need to transfer to the scripts
all of the parameters of the original mysqld call, and in the SST
scripts themselves provide for the transfer all of these parameters
to utilities such as mariabackup. To prevent these parameters from
mixing with the script's own parameters, they should be transferred
to SST script after the special option "--mysqld-args", followed by
the string argument with the original parameters, as it received by
the mysqld call at the time of launch (further all these parameters
will be passed to mariabackup, for example).

In addition, the SST scripts themselves must be refined so that
they can read the parameters from the user-selected group, not just
from the global mysqld configuration group. And also so that they
can receive the parameters (which important for their work) as
command-line arguments.
parent 93892521
...@@ -308,7 +308,9 @@ sub report_mysqlds ...@@ -308,7 +308,9 @@ sub report_mysqlds
sub start_mysqlds() sub start_mysqlds()
{ {
my (@groups, $com, $tmp, $i, @options, $j, $mysqld_found, $info_sent); my (@groups, $com, $tmp, $i, @options, $j, $mysqld_found, $suffix_found, $info_sent);
$suffix_found= 0;
if (!$opt_no_log) if (!$opt_no_log)
{ {
...@@ -347,6 +349,10 @@ sub start_mysqlds() ...@@ -347,6 +349,10 @@ sub start_mysqlds()
$options[$j]= quote_shell_word($options[$j]); $options[$j]= quote_shell_word($options[$j]);
$tmp.= " $options[$j]"; $tmp.= " $options[$j]";
} }
elseif ("--defaults-group-suffix=" eq substr($options[$j], 0, 24))
{
$suffix_found= 1;
}
else else
{ {
$options[$j]= quote_shell_word($options[$j]); $options[$j]= quote_shell_word($options[$j]);
...@@ -364,6 +370,12 @@ sub start_mysqlds() ...@@ -364,6 +370,12 @@ sub start_mysqlds()
} }
$com.= $tmp; $com.= $tmp;
if (!$suffix_found)
{
$com.= " --defaults-group-suffix=";
$com.= $groups[$i];
}
if ($opt_wsrep_new_cluster) { if ($opt_wsrep_new_cluster) {
$com.= " --wsrep-new-cluster"; $com.= " --wsrep-new-cluster";
} }
......
...@@ -28,7 +28,12 @@ WSREP_SST_OPT_PSWD=${WSREP_SST_OPT_PSWD:-} ...@@ -28,7 +28,12 @@ WSREP_SST_OPT_PSWD=${WSREP_SST_OPT_PSWD:-}
WSREP_SST_OPT_DEFAULT="" WSREP_SST_OPT_DEFAULT=""
WSREP_SST_OPT_EXTRA_DEFAULT="" WSREP_SST_OPT_EXTRA_DEFAULT=""
WSREP_SST_OPT_SUFFIX_DEFAULT="" WSREP_SST_OPT_SUFFIX_DEFAULT=""
WSREP_SST_OPT_SUFFIX_VALUE=""
WSREP_SST_OPT_MYSQLD=""
INNODB_DATA_HOME_DIR_ARG="" INNODB_DATA_HOME_DIR_ARG=""
INNODB_LOG_GROUP_HOME_ARG=""
INNODB_UNDO_DIR_ARG=""
LOG_BIN_ARG=""
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
...@@ -83,6 +88,18 @@ case "$1" in ...@@ -83,6 +88,18 @@ case "$1" in
readonly INNODB_DATA_HOME_DIR_ARG="$2" readonly INNODB_DATA_HOME_DIR_ARG="$2"
shift shift
;; ;;
'--innodb-log-group-home-dir')
readonly INNODB_LOG_GROUP_HOME_ARG="$2"
shift
;;
'--innodb-undo-directory')
readonly INNODB_UNDO_DIR_ARG="$2"
shift
;;
'--log-bin')
readonly LOG_BIN_ARG="$2"
shift
;;
'--defaults-file') '--defaults-file')
readonly WSREP_SST_OPT_DEFAULT="$1=$2" readonly WSREP_SST_OPT_DEFAULT="$1=$2"
shift shift
...@@ -93,6 +110,7 @@ case "$1" in ...@@ -93,6 +110,7 @@ case "$1" in
;; ;;
'--defaults-group-suffix') '--defaults-group-suffix')
readonly WSREP_SST_OPT_SUFFIX_DEFAULT="$1=$2" readonly WSREP_SST_OPT_SUFFIX_DEFAULT="$1=$2"
readonly WSREP_SST_OPT_SUFFIX_VALUE="$2"
shift shift
;; ;;
'--host') '--host')
...@@ -143,6 +161,46 @@ case "$1" in ...@@ -143,6 +161,46 @@ case "$1" in
readonly WSREP_SST_OPT_GTID_DOMAIN_ID="$2" readonly WSREP_SST_OPT_GTID_DOMAIN_ID="$2"
shift shift
;; ;;
'--mysqld-args')
original_cmd=""
shift
while [ $# -gt 0 ]; do
option=${1%%=*}
if [ "$option" != "--defaults-file" ]; then
value=${1#*=}
case "$option" in
'--innodb-data-home-dir')
if [ -z "$INNODB_DATA_HOME_DIR_ARG" ]; then
readonly INNODB_DATA_HOME_DIR_ARG="$value"
fi
;;
'--innodb-log-group-home-dir')
if [ -z "$INNODB_LOG_GROUP_HOME_ARG" ]; then
readonly INNODB_LOG_GROUP_HOME_ARG="$value"
fi
;;
'--innodb-undo-directory')
if [ -z "$INNODB_UNDO_DIR_ARG" ]; then
readonly INNODB_UNDO_DIR_ARG="$value"
fi
;;
'--log-bin')
if [ -z "$LOG_BIN_ARG" ]; then
readonly LOG_BIN_ARG="$value"
fi
;;
esac
if [ -z "$original_cmd" ]; then
original_cmd="$1"
else
original_cmd+=" $1"
fi
fi
shift
done
readonly WSREP_SST_OPT_MYSQLD="$original_cmd"
break
;;
*) # must be command *) # must be command
# usage # usage
# exit 1 # exit 1
......
...@@ -697,8 +697,7 @@ if [[ ${FORCE_FTWRL:-0} -eq 1 ]];then ...@@ -697,8 +697,7 @@ if [[ ${FORCE_FTWRL:-0} -eq 1 ]];then
iopts+=" --no-backup-locks " iopts+=" --no-backup-locks "
fi fi
INNOEXTRA=$WSREP_SST_OPT_MYSQLD
INNOEXTRA=""
INNODB_DATA_HOME_DIR=${INNODB_DATA_HOME_DIR:-""} INNODB_DATA_HOME_DIR=${INNODB_DATA_HOME_DIR:-""}
# Try to set INNODB_DATA_HOME_DIR from the command line: # Try to set INNODB_DATA_HOME_DIR from the command line:
...@@ -706,6 +705,9 @@ if [ ! -z "$INNODB_DATA_HOME_DIR_ARG" ]; then ...@@ -706,6 +705,9 @@ if [ ! -z "$INNODB_DATA_HOME_DIR_ARG" ]; then
INNODB_DATA_HOME_DIR=$INNODB_DATA_HOME_DIR_ARG INNODB_DATA_HOME_DIR=$INNODB_DATA_HOME_DIR_ARG
fi fi
# if INNODB_DATA_HOME_DIR env. variable is not set, try to get it from my.cnf # if INNODB_DATA_HOME_DIR env. variable is not set, try to get it from my.cnf
if [ -z "$INNODB_DATA_HOME_DIR" ]; then
INNODB_DATA_HOME_DIR=$(parse_cnf mysqld$WSREP_SST_OPT_SUFFIX_VALUE innodb-data-home-dir '')
fi
if [ -z "$INNODB_DATA_HOME_DIR" ]; then if [ -z "$INNODB_DATA_HOME_DIR" ]; then
INNODB_DATA_HOME_DIR=$(parse_cnf --mysqld innodb-data-home-dir '') INNODB_DATA_HOME_DIR=$(parse_cnf --mysqld innodb-data-home-dir '')
fi fi
...@@ -826,7 +828,9 @@ then ...@@ -826,7 +828,9 @@ then
exit 93 exit 93
fi fi
if [[ -z $(parse_cnf --mysqld tmpdir "") && -z $(parse_cnf xtrabackup tmpdir "") ]];then if [[ -z $(parse_cnf mysqld$WSREP_SST_OPT_SUFFIX_VALUE tmpdir "") && \
-z $(parse_cnf --mysqld tmpdir "") && \
-z $(parse_cnf xtrabackup tmpdir "") ]]; then
xtmpdir=$(mktemp -d) xtmpdir=$(mktemp -d)
tmpopts=" --tmpdir=$xtmpdir " tmpopts=" --tmpdir=$xtmpdir "
wsrep_log_info "Using $xtmpdir as xtrabackup temporary directory" wsrep_log_info "Using $xtmpdir as xtrabackup temporary directory"
...@@ -949,8 +953,24 @@ then ...@@ -949,8 +953,24 @@ then
[[ -n $SST_PROGRESS_FILE ]] && touch $SST_PROGRESS_FILE [[ -n $SST_PROGRESS_FILE ]] && touch $SST_PROGRESS_FILE
ib_home_dir=$INNODB_DATA_HOME_DIR ib_home_dir=$INNODB_DATA_HOME_DIR
# Try to set ib_log_dir from the command line:
ib_log_dir=$INNODB_LOG_GROUP_HOME_ARG
if [ -z "$ib_log_dir" ]; then
ib_log_dir=$(parse_cnf mysqld$WSREP_SST_OPT_SUFFIX_VALUE innodb-log-group-home-dir "")
fi
if [ -z "$ib_log_dir" ]; then
ib_log_dir=$(parse_cnf --mysqld innodb-log-group-home-dir "") ib_log_dir=$(parse_cnf --mysqld innodb-log-group-home-dir "")
fi
# Try to set ib_undo_dir from the command line:
ib_undo_dir=$INNODB_UNDO_DIR_ARG
if [ -z "$ib_undo_dir" ]; then
ib_undo_dir=$(parse_cnf mysqld$WSREP_SST_OPT_SUFFIX_VALUE innodb-undo-directory "")
fi
if [ -z "$ib_undo_dir" ]; then
ib_undo_dir=$(parse_cnf --mysqld innodb-undo-directory "") ib_undo_dir=$(parse_cnf --mysqld innodb-undo-directory "")
fi
stagemsg="Joiner-Recv" stagemsg="Joiner-Recv"
...@@ -1027,7 +1047,13 @@ then ...@@ -1027,7 +1047,13 @@ then
find $ib_home_dir $ib_log_dir $ib_undo_dir $DATA -mindepth 1 -prune -regex $cpat -o -exec rm -rfv {} 1>&2 \+ find $ib_home_dir $ib_log_dir $ib_undo_dir $DATA -mindepth 1 -prune -regex $cpat -o -exec rm -rfv {} 1>&2 \+
fi fi
tempdir=$LOG_BIN_ARG
if [ -z "$tempdir" ]; then
tempdir=$(parse_cnf mysqld$WSREP_SST_OPT_SUFFIX_VALUE log-bin "")
fi
if [ -z "$tempdir" ]; then
tempdir=$(parse_cnf --mysqld log-bin "") tempdir=$(parse_cnf --mysqld log-bin "")
fi
if [[ -n ${tempdir:-} ]];then if [[ -n ${tempdir:-} ]];then
binlog_dir=$(dirname $tempdir) binlog_dir=$(dirname $tempdir)
binlog_file=$(basename $tempdir) binlog_file=$(basename $tempdir)
......
...@@ -150,7 +150,14 @@ then ...@@ -150,7 +150,14 @@ then
fi fi
WSREP_LOG_DIR=${WSREP_LOG_DIR:-""} WSREP_LOG_DIR=${WSREP_LOG_DIR:-""}
# Try to set WSREP_LOG_DIR from the command line:
if [ -z "$WSREP_LOG_DIR" ]; then
WSREP_LOG_DIR=$INNODB_LOG_GROUP_HOME_ARG
fi
# if WSREP_LOG_DIR env. variable is not set, try to get it from my.cnf # if WSREP_LOG_DIR env. variable is not set, try to get it from my.cnf
if [ -z "$WSREP_LOG_DIR" ]; then
WSREP_LOG_DIR=$(parse_cnf mysqld$WSREP_SST_OPT_SUFFIX_VALUE innodb-log-group-home-dir '')
fi
if [ -z "$WSREP_LOG_DIR" ]; then if [ -z "$WSREP_LOG_DIR" ]; then
WSREP_LOG_DIR=$(parse_cnf --mysqld innodb-log-group-home-dir '') WSREP_LOG_DIR=$(parse_cnf --mysqld innodb-log-group-home-dir '')
fi fi
...@@ -169,6 +176,9 @@ if [ ! -z "$INNODB_DATA_HOME_DIR_ARG" ]; then ...@@ -169,6 +176,9 @@ if [ ! -z "$INNODB_DATA_HOME_DIR_ARG" ]; then
INNODB_DATA_HOME_DIR=$INNODB_DATA_HOME_DIR_ARG INNODB_DATA_HOME_DIR=$INNODB_DATA_HOME_DIR_ARG
fi fi
# if INNODB_DATA_HOME_DIR env. variable is not set, try to get it from my.cnf # if INNODB_DATA_HOME_DIR env. variable is not set, try to get it from my.cnf
if [ -z "$INNODB_DATA_HOME_DIR" ]; then
INNODB_DATA_HOME_DIR=$(parse_cnf mysqld$WSREP_SST_OPT_SUFFIX_VALUE innodb-data-home-dir '')
fi
if [ -z "$INNODB_DATA_HOME_DIR" ]; then if [ -z "$INNODB_DATA_HOME_DIR" ]; then
INNODB_DATA_HOME_DIR=$(parse_cnf --mysqld innodb-data-home-dir '') INNODB_DATA_HOME_DIR=$(parse_cnf --mysqld innodb-data-home-dir '')
fi fi
......
...@@ -642,17 +642,76 @@ static int sst_append_data_dir(wsp::env& env, const char* data_dir) ...@@ -642,17 +642,76 @@ static int sst_append_data_dir(wsp::env& env, const char* data_dir)
return -env.error(); return -env.error();
} }
static size_t estimate_cmd_len (bool* extra_args)
{
/*
The length of the area reserved for the control parameters
of the SST script (excluding the copying of the original
mysqld arguments):
*/
size_t cmd_len= 4096;
bool extra= false;
/*
If mysqld was started with arguments, add them all:
*/
if (orig_argc > 1)
{
for (int i = 1; i < orig_argc; i++)
{
cmd_len += strlen(orig_argv[i]);
}
extra = true;
cmd_len += strlen(WSREP_SST_OPT_MYSQLD);
/*
Add the separating spaces between arguments,
and one additional space before "--mysqld-args":
*/
cmd_len += orig_argc;
}
*extra_args= extra;
return cmd_len;
}
static void copy_orig_argv (char* cmd_str)
{
/*
If mysqld was started with arguments, copy them all:
*/
if (orig_argc > 1)
{
size_t n = strlen(WSREP_SST_OPT_MYSQLD);
*cmd_str++ = ' ';
memcpy(cmd_str, WSREP_SST_OPT_MYSQLD, n * sizeof(char));
cmd_str += n;
for (int i = 1; i < orig_argc; i++)
{
char* arg= orig_argv[i];
*cmd_str++ = ' ';
n = strlen(arg);
memcpy(cmd_str, arg, n * sizeof(char));
cmd_str += n;
}
/*
Add a terminating null character (not counted in the length,
since we've overwritten the original null character which
was previously added by snprintf:
*/
*cmd_str = 0;
}
}
static ssize_t sst_prepare_other (const char* method, static ssize_t sst_prepare_other (const char* method,
const char* sst_auth, const char* sst_auth,
const char* addr_in, const char* addr_in,
const char** addr_out) const char** addr_out)
{ {
int const cmd_len= 4096; bool extra_args;
size_t const cmd_len= estimate_cmd_len(&extra_args);
wsp::string cmd_str(cmd_len); wsp::string cmd_str(cmd_len);
if (!cmd_str()) if (!cmd_str())
{ {
WSREP_ERROR("sst_prepare_other(): could not allocate cmd buffer of %d bytes", WSREP_ERROR("sst_prepare_other(): could not allocate cmd buffer of %zd bytes",
cmd_len); cmd_len);
return -ENOMEM; return -ENOMEM;
} }
...@@ -703,6 +762,9 @@ static ssize_t sst_prepare_other (const char* method, ...@@ -703,6 +762,9 @@ static ssize_t sst_prepare_other (const char* method,
return (ret < 0 ? ret : -EMSGSIZE); return (ret < 0 ? ret : -EMSGSIZE);
} }
if (extra_args)
copy_orig_argv(cmd_str() + ret);
wsp::env env(NULL); wsp::env env(NULL);
if (env.error()) if (env.error())
{ {
...@@ -975,13 +1037,14 @@ static int sst_donate_mysqldump (const char* addr, ...@@ -975,13 +1037,14 @@ static int sst_donate_mysqldump (const char* addr,
} }
memcpy(host, address.get_address(), address.get_address_len()); memcpy(host, address.get_address(), address.get_address_len());
int port= address.get_port(); int port= address.get_port();
int const cmd_len= 4096; bool extra_args;
size_t const cmd_len= estimate_cmd_len(&extra_args);
wsp::string cmd_str(cmd_len); wsp::string cmd_str(cmd_len);
if (!cmd_str()) if (!cmd_str())
{ {
WSREP_ERROR("sst_donate_mysqldump(): " WSREP_ERROR("sst_donate_mysqldump(): "
"could not allocate cmd buffer of %d bytes", cmd_len); "could not allocate cmd buffer of %zd bytes", cmd_len);
return -ENOMEM; return -ENOMEM;
} }
...@@ -1010,6 +1073,9 @@ static int sst_donate_mysqldump (const char* addr, ...@@ -1010,6 +1073,9 @@ static int sst_donate_mysqldump (const char* addr,
return (ret < 0 ? ret : -EMSGSIZE); return (ret < 0 ? ret : -EMSGSIZE);
} }
if (extra_args)
copy_orig_argv(cmd_str() + ret);
WSREP_DEBUG("Running: '%s'", cmd_str()); WSREP_DEBUG("Running: '%s'", cmd_str());
ret= sst_run_shell (cmd_str(), env, 3); ret= sst_run_shell (cmd_str(), env, 3);
...@@ -1329,13 +1395,14 @@ static int sst_donate_other (const char* method, ...@@ -1329,13 +1395,14 @@ static int sst_donate_other (const char* method,
bool bypass, bool bypass,
char** env) // carries auth info char** env) // carries auth info
{ {
int const cmd_len= 4096; bool extra_args;
size_t const cmd_len= estimate_cmd_len(&extra_args);
wsp::string cmd_str(cmd_len); wsp::string cmd_str(cmd_len);
if (!cmd_str()) if (!cmd_str())
{ {
WSREP_ERROR("sst_donate_other(): " WSREP_ERROR("sst_donate_other(): "
"could not allocate cmd buffer of %d bytes", cmd_len); "could not allocate cmd buffer of %zd bytes", cmd_len);
return -ENOMEM; return -ENOMEM;
} }
...@@ -1376,6 +1443,9 @@ static int sst_donate_other (const char* method, ...@@ -1376,6 +1443,9 @@ static int sst_donate_other (const char* method,
return (ret < 0 ? ret : -EMSGSIZE); return (ret < 0 ? ret : -EMSGSIZE);
} }
if (extra_args)
copy_orig_argv(cmd_str() + ret);
if (!bypass && wsrep_sst_donor_rejects_queries) sst_reject_queries(FALSE); if (!bypass && wsrep_sst_donor_rejects_queries) sst_reject_queries(FALSE);
pthread_t tmp; pthread_t tmp;
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#define WSREP_SST_OPT_PARENT "--parent" #define WSREP_SST_OPT_PARENT "--parent"
#define WSREP_SST_OPT_BINLOG "--binlog" #define WSREP_SST_OPT_BINLOG "--binlog"
#define WSREP_SST_OPT_BINLOG_INDEX "--binlog-index" #define WSREP_SST_OPT_BINLOG_INDEX "--binlog-index"
#define WSREP_SST_OPT_MYSQLD "--mysqld-args"
// mysqldump-specific options // mysqldump-specific options
#define WSREP_SST_OPT_USER "--user" #define WSREP_SST_OPT_USER "--user"
......
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