Commit 527ce30c authored by Seppo Jaakola's avatar Seppo Jaakola

References: MDEV-4572 - merge with lp:codership-mysql/5.5-23 revisions 3874..3878

parent 7d2a0e9d
......@@ -18,6 +18,8 @@ niceness=0
nowatch=0
mysqld_ld_preload=
mysqld_ld_library_path=
flush_caches=0
numa_interleave=0
# Initial logging status: error log is not open, and not using syslog
logging=init
......@@ -85,6 +87,10 @@ Usage: $0 [OPTIONS]
--syslog Log messages to syslog with 'logger'
--skip-syslog Log messages to error log (default)
--syslog-tag=TAG Pass -t "mysqld-TAG" to 'logger'
--flush-caches Flush and purge buffers/caches before
starting the server
--numa-interleave Run mysqld with its memory interleaved
on all NUMA nodes
All other options are passed to the mysqld program.
......@@ -225,9 +231,11 @@ wsrep_recover_position() {
[ "$euid" = "0" ] && chown $user $wr_logfile
chmod 600 $wr_logfile
log_notice "WSREP: Running position recovery with --log_error=$wr_logfile"
log_notice "WSREP: Running position recovery with --log_error=$wr_logfile \
--pid-file="$DATADIR/`@HOSTNAME@`-recover.pid""
eval_log_error $mysqld_cmd --log_error=$wr_logfile --wsrep-recover
eval_log_error "$mysqld_cmd --log_error=$wr_logfile --wsrep-recover \
--pid-file="$DATADIR/`@HOSTNAME@`-recover.pid""
local rp="$(grep 'WSREP: Recovered position:' $wr_logfile)"
if [ -z "$rp" ]; then
......@@ -312,6 +320,8 @@ parse_arguments() {
--syslog-tag=*) syslog_tag="$val" ;;
--timezone=*) TZ="$val"; export TZ; ;;
--wsrep[-_]urls=*) wsrep_urls="$val"; ;;
--flush-caches) flush_caches=1 ;;
--numa-interleave) numa_interleave=1 ;;
--wsrep[-_]provider=*)
if test -n "$val" && test "$val" != "none"
then
......@@ -834,6 +844,41 @@ mysqld daemon not started"
fi
fi
#
# Flush and purge buffers/caches.
#
if @TARGET_LINUX@ && test $flush_caches -eq 1
then
# Locate sync, ensure it exists.
if ! my_which sync > /dev/null 2>&1
then
log_error "sync command not found, required for --flush-caches"
exit 1
# Flush file system buffers.
elif ! sync
then
# Huh, the sync() function is always successful...
log_error "sync failed, check if sync is properly installed"
fi
# Locate sysctl, ensure it exists.
if ! my_which sysctl > /dev/null 2>&1
then
log_error "sysctl command not found, required for --flush-caches"
exit 1
# Purge page cache, dentries and inodes.
elif ! sysctl -q -w vm.drop_caches=3
then
log_error "sysctl failed, check the error message for details"
exit 1
fi
elif test $flush_caches -eq 1
then
log_error "--flush-caches is not supported on this platform"
exit 1
fi
#
# Uncomment the following lines if you want all tables to be automatically
# checked and repaired during startup. You should add sensible key_buffer
......@@ -854,6 +899,31 @@ fi
cmd="`mysqld_ld_preload_text`$NOHUP_NICENESS"
#
# Set mysqld's memory interleave policy.
#
if @TARGET_LINUX@ && test $numa_interleave -eq 1
then
# Locate numactl, ensure it exists.
if ! my_which numactl > /dev/null 2>&1
then
log_error "numactl command not found, required for --numa-interleave"
exit 1
# Attempt to run a command, ensure it works.
elif ! numactl --interleave=all true
then
log_error "numactl failed, check if numactl is properly installed"
fi
# Launch mysqld with numactl.
cmd="$cmd numactl --interleave=all"
elif test $numa_interleave -eq 1
then
log_error "--numa-interleave is not supported on this platform"
exit 1
fi
for i in "$ledir/$MYSQLD" "$defaults" "--basedir=$MY_BASEDIR_VERSION" \
"--datadir=$DATADIR" "--plugin-dir=$plugin_dir" "$USER_OPTION"
do
......
......@@ -86,6 +86,8 @@ shift
done
readonly WSREP_SST_OPT_BYPASS
SST_PROGRESS_FILE="$WSREP_SST_OPT_DATA/sst_in_progress"
wsrep_log()
{
# echo everything to stderr so that it gets into common error log
......@@ -104,3 +106,8 @@ wsrep_log_info()
wsrep_log "[INFO] $*"
}
wsrep_cleanup_progress_file()
{
rm -f $SST_PROGRESS_FILE 2>/dev/null
}
......@@ -117,5 +117,5 @@ else
wsrep_log_info "Bypassing state dump."
echo $SET_START_POSITION | $MYSQL
fi
wsrep_cleanup_progress_file
#
......@@ -33,6 +33,9 @@ cleanup_joiner()
rm -rf "$MAGIC_FILE"
rm -rf "$RSYNC_PID"
wsrep_log_info "Joiner cleanup done."
if [ "${WSREP_SST_OPT_ROLE}" = "joiner" ];then
wsrep_cleanup_progress_file
fi
}
check_pid()
......@@ -89,11 +92,13 @@ then
# --exclude '*.[0-9][0-9][0-9][0-9][0-9][0-9]' --exclude '*.index')
# New filter - exclude everything except dirs (schemas) and innodb files
FILTER=(-f '- lost+found' -f '+ /ibdata*' -f '+ /ib_logfile*' -f '+ */' -f '-! */*')
FILTER=(-f '- lost+found' -f '+ /ib_lru_dump' -f '+ /ibdata*' -f '+ /ib_logfile*' -f '+ */' -f '-! */*')
# first, the normal directories, so that we can detect incompatible protocol
RC=0
rsync --archive --no-times --ignore-times --inplace --delete --quiet \
$WHOLE_FILE_OPT "${FILTER[@]}" "$WSREP_SST_OPT_DATA" \
--no-recursive --dirs \
$WHOLE_FILE_OPT "${FILTER[@]}" "$WSREP_SST_OPT_DATA/" \
rsync://$WSREP_SST_OPT_ADDR || RC=$?
[ $RC -ne 0 ] && wsrep_log_error "rsync returned code $RC:"
......@@ -114,6 +119,30 @@ then
[ $RC -ne 0 ] && exit $RC
# then, we parallelize the transfer of database directories, use . so that pathconcatenation works
pushd "$WSREP_SST_OPT_DATA" 1>/dev/null
count=$(grep -c processor /proc/cpuinfo)
find . -maxdepth 1 -mindepth 1 -type d -print0 | xargs -i -0 -P $count \
rsync --archive --no-times --ignore-times --inplace --delete --quiet \
$WHOLE_FILE_OPT "$WSREP_SST_OPT_DATA"/{}/ \
rsync://$WSREP_SST_OPT_ADDR/{} || RC=$?
popd 1>/dev/null
[ $RC -ne 0 ] && wsrep_log_error "find/rsync returned code $RC:"
case $RC in
0) RC=0 # Success
;;
*) RC=255 # unknown error
;;
esac
[ $RC -ne 0 ] && exit $RC
else # BYPASS
wsrep_log_info "Bypassing state dump."
STATE="$WSREP_SST_OPT_GTID"
......@@ -128,6 +157,7 @@ then
elif [ "$WSREP_SST_OPT_ROLE" = "joiner" ]
then
touch $SST_PROGRESS_FILE
MYSQLD_PID=$WSREP_SST_OPT_PARENT
MODULE="rsync_sst"
......@@ -201,7 +231,7 @@ EOF
# this message should cause joiner to abort
echo "rsync process ended without creating '$MAGIC_FILE'"
fi
wsrep_cleanup_progress_file
# cleanup_joiner
else
wsrep_log_error "Unrecognized role: '$WSREP_SST_OPT_ROLE'"
......
......@@ -22,12 +22,13 @@
cleanup_joiner()
{
#set -x
local PID=$(ps -aef |grep nc| grep $NC_PORT | awk '{ print $2 }')
wsrep_log_info "Killing nc pid $PID"
[ -n "$PID" -a "0" != "$PID" ] && kill $PID && (kill $PID && kill -9 $PID) || :
rm -f "$MAGIC_FILE"
#set +x
if [ "${WSREP_SST_OPT_ROLE}" = "joiner" ];then
wsrep_cleanup_progress_file
fi
}
check_pid()
......@@ -87,6 +88,7 @@ rm -f "${MAGIC_FILE}"
if [ "$WSREP_SST_OPT_ROLE" = "donor" ]
then
encrypt=0
# UUID=$6
# SEQNO=$7
......@@ -97,10 +99,9 @@ then
if [ $WSREP_SST_OPT_BYPASS -eq 0 ]
then
TMPDIR="/tmp"
TMPDIR=${TMPDIR:-"/tmp"}
INNOBACKUPEX_ARGS="--galera-info --stream=tar
INNOBACKUPEX_ARGS="--galera-info --stream=xbstream
--defaults-file=${WSREP_SST_OPT_CONF}
--socket=${WSREP_SST_OPT_SOCKET}"
......@@ -110,10 +111,39 @@ then
if [ ${#AUTH[*]} -eq 2 ]; then
INNOBACKUPEX_ARGS="${INNOBACKUPEX_ARGS} --password=${AUTH[1]}"
fi
else
# Empty password, used for testing, debugging etc.
INNOBACKUPEX_ARGS="${INNOBACKUPEX_ARGS} --password="
fi
set +e
if my_print_defaults -c $WSREP_SST_OPT_CONF xtrabackup | grep -q encrypt; then
wsrep_log_info "Encryption enabled in my.cnf - NOT SUPPORTED - look at lp:1190343"
#encrypt=1
fi
if [[ $encrypt -eq 1 ]];then
ealgo=$(my_print_defaults -c $WSREP_SST_OPT_CONF xtrabackup | grep -- '--encrypt=' | cut -d= -f2)
ekey=$(my_print_defaults -c $WSREP_SST_OPT_CONF xtrabackup | grep -- '--encrypt-key=' | cut -d= -f2)
ekeyfile=$(my_print_defaults -c $WSREP_SST_OPT_CONF xtrabackup | grep -- '--encrypt-key-file=' | cut -d= -f2)
if [[ -z $ealgo || (-z $ekey && -z $ekeyfile) ]];then
wsrep_log_error "FATAL: Encryption parameters empty from my.cnf, bailing out"
exit 3
fi
if [[ -n $ekey ]];then
INNOBACKUPEX_ARGS="${INNOBACKUPEX_ARGS} --encrypt=$ealgo --encrypt-key=$ekey"
else
if [[ ! -r $ekeyfile ]];then
wsrep_log_error "FATAL: Key file not readable"
exit 3
fi
INNOBACKUPEX_ARGS="${INNOBACKUPEX_ARGS} --encrypt=$ealgo --encrypt-key-file=$ekeyfile"
fi
fi
${INNOBACKUPEX_BIN} ${INNOBACKUPEX_ARGS} ${TMPDIR} \
2> ${DATA}/innobackup.backup.log | \
${NC_BIN} ${REMOTEIP} ${NC_PORT}
......@@ -155,6 +185,15 @@ then
elif [ "${WSREP_SST_OPT_ROLE}" = "joiner" ]
then
touch $SST_PROGRESS_FILE
sencrypted=1
encrypt=0
ekey=""
ealgo=""
ekeyfile=""
ecode=0
MODULE="xtrabackup_sst"
rm -f ${DATA}/xtrabackup_*
......@@ -169,23 +208,58 @@ then
wait_for_nc ${NC_PORT} ${ADDR} ${MODULE} &
# trap "exit 32" HUP PIPE
# trap "exit 3" INT TERM
trap cleanup_joiner HUP PIPE INT TERM
trap "exit 32" HUP PIPE
trap "exit 3" INT TERM
trap cleanup_joiner EXIT
# There is no metadata in the stream to indicate that it is encrypted
# So, if the cnf file on joiner contains 'encrypt' under [xtrabackup] section then
# it means encryption is being used
if my_print_defaults -c $WSREP_SST_OPT_CONF xtrabackup | grep -q encrypt; then
#wsrep_log_info "Encryption enabled in my.cnf, decrypting the stream/backup"
wsrep_log_error "Encryption enabled in my.cnf - NOT SUPPORTED - look at lp:1190343"
#encrypt=1
fi
set +e
${NC_BIN} -dl ${NC_PORT} | tar xfi - -C ${DATA} 1>&2
RC=( "${PIPESTATUS[@]}" )
if [[ $encrypt -eq 1 && $sencrypted -eq 1 ]];then
ealgo=$(my_print_defaults -c $WSREP_SST_OPT_CONF xtrabackup | grep -- '--encrypt=' | cut -d= -f2)
ekey=$(my_print_defaults -c $WSREP_SST_OPT_CONF xtrabackup | grep -- '--encrypt-key=' | cut -d= -f2)
ekeyfile=$(my_print_defaults -c $WSREP_SST_OPT_CONF xtrabackup | grep -- '--encrypt-key-file=' | cut -d= -f2)
if [[ -z $ealgo || (-z $ekey && -z $ekeyfile) ]];then
wsrep_log_error "FATAL: Encryption parameters empty from my.cnf, bailing out"
exit 3
fi
if [[ -n $ekey ]];then
${NC_BIN} -dl ${NC_PORT} | xbcrypt -d --encrypt-algo=$ealgo --encrypt-key=$ekey | xbstream -x -C ${DATA} 1>&2
RC=( "${PIPESTATUS[@]}" )
else
if [[ ! -r $ekeyfile ]];then
wsrep_log_error "FATAL: Key file not readable"
exit 3
fi
${NC_BIN} -dl ${NC_PORT} | xbcrypt -d --encrypt-algo=$ealgo --encrypt-key-file=$ekeyfile | xbstream -x -C ${DATA} 1>&2
RC=( "${PIPESTATUS[@]}" )
fi
else
${NC_BIN} -dl ${NC_PORT} | xbstream -x -C ${DATA} 1>&2
RC=( "${PIPESTATUS[@]}" )
fi
set -e
wait %% # join wait_for_nc thread
if [ ${RC[0]} -ne 0 -o ${RC[1]} -ne 0 ];
then
wsrep_log_error "Error while getting st data from donor node: " \
"${RC[0]}, ${RC[1]}"
exit 32
fi
for ecode in "${RC[@]}";do
if [[ $ecode -ne 0 ]];then
wsrep_log_error "Error while getting st data from donor node: " \
"exit codes: ${RC[@]}"
exit 32
fi
done
if [ ! -r "${MAGIC_FILE}" ]
then
......@@ -196,24 +270,105 @@ then
if ! ps -p ${WSREP_SST_OPT_PARENT} >/dev/null
then
wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly." >&2
wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly."
exit 32
fi
if [ ! -r "${IST_FILE}" ]
then
wsrep_log_info "Removing existing ib_logfile files"
rm -f ${DATA}/ib_logfile*
${INNOBACKUPEX_BIN} --defaults-file=${WSREP_SST_OPT_CONF} --apply-log \
--ibbackup=xtrabackup ${DATA} 1>&2 2> ${DATA}/innobackup.prepare.log
rebuild=""
# Decrypt only if not encrypted in stream.
# NOT USED NOW.
# Till https://blueprints.launchpad.net/percona-xtrabackup/+spec/add-support-for-rsync-url
# is implemented
if [[ $encrypt -eq 1 && $sencrypted -eq 0 ]];then
ealgo=$(my_print_defaults -c $WSREP_SST_OPT_CONF xtrabackup | grep -- '--encrypt=' | cut -d= -f2)
ekey=$(my_print_defaults -c $WSREP_SST_OPT_CONF xtrabackup | grep -- '--encrypt-key=' | cut -d= -f2)
ekeyfile=$(my_print_defaults -c $WSREP_SST_OPT_CONF xtrabackup | grep -- '--encrypt-key-file=' | cut -d= -f2)
# Decrypt the files if any
find ${DATA} -type f -name '*.xbcrypt' -printf '%p\n' | while read line;do
if [[ -z $ealgo || (-z $ekey && -z $ekeyfile) ]];then
wsrep_log_error "FATAL: Encryption parameters empty from my.cnf, bailing out"
exit 3
fi
input=$line
output=${input%.xbcrypt}
if [[ -n $ekey ]];then
xbcrypt -d --encrypt-algo=$ealgo --encrypt-key=$ekey -i $input > $output
else
if [[ ! -r $ekeyfile ]];then
wsrep_log_error "FATAL: Key file not readable"
exit 3
fi
xbcrypt -d --encrypt-algo=$ealgo --encrypt-key-file=$ekeyfile -i $input > $output
fi
done
if [[ $? = 0 ]];then
find ${DATA} -type f -name '*.xbcrypt' -delete
fi
fi
# Rebuild indexes for compact backups
if grep -q 'compact = 1' ${DATA}/xtrabackup_checkpoints;then
wsrep_log_info "Index compaction detected"
rebuild="--rebuild-indexes"
fi
if test -n "$(find ${DATA} -maxdepth 1 -name '*.qp' -print -quit)";then
wsrep_log_info "Compressed qpress files found"
if [[ ! -x `which qpress` ]];then
wsrep_log_error "qpress not found in PATH"
exit 22
fi
set +e
wsrep_log_info "Removing existing ibdata1 file"
rm -f ${DATA}/ibdata1
# Decompress the qpress files
find ${DATA} -type f -name '*.qp' -printf '%p\n%h\n' | xargs -P $(grep -c processor /proc/cpuinfo) -n 2 qpress -d
extcode=$?
set -e
if [[ $extcode -eq 0 ]];then
wsrep_log_info "Removing qpress files after decompression"
find ${DATA} -type f -name '*.qp' -delete
if [[ $? -ne 0 ]];then
wsrep_log_error "Something went wrong with deletion of qpress files. Investigate"
fi
else
wsrep_log_error "Decompression failed. Exit code: $extcode"
exit 22
fi
fi
${INNOBACKUPEX_BIN} --defaults-file=${WSREP_SST_OPT_CONF} --apply-log $rebuild \
${DATA} 1>&2 2> ${DATA}/innobackup.prepare.log
if [ $? -ne 0 ];
then
wsrep_log_error "${INNOBACKUPEX_BIN} finished with errors. Check ${DATA}/innobackup.prepare.log" >&2
wsrep_log_error "${INNOBACKUPEX_BIN} finished with errors. Check ${DATA}/innobackup.prepare.log"
exit 22
fi
fi
cat "${MAGIC_FILE}" # output UUID:seqno
#Cleanup not required here since EXIT trap should be called
#wsrep_cleanup_progress_file
else
wsrep_log_error "Unrecognized role: ${WSREP_SST_OPT_ROLE}"
exit 22 # EINVAL
......
......@@ -2557,6 +2557,9 @@ main(int argc, char **argv)
return 1;
}
// Replicate MyISAM DDL for this session, cf. lp:1161432
printf("SET SESSION wsrep_replicate_myisam=ON;\n");
if (argc == 2)
{
root_name_end= strmake_buf(fullname, argv[1]);
......
......@@ -52,6 +52,7 @@ datadir=
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900
startup_sleep=1
# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
......@@ -157,6 +158,7 @@ wait_for_pid () {
pid="$2" # process ID of the program operating on the pid-file
pid_file_path="$3" # path to the PID file.
sst_progress_file=$datadir/sst_in_progress
i=0
avoid_race_condition="by checking again"
......@@ -194,9 +196,14 @@ wait_for_pid () {
fi
fi
if test -e $sst_progress_file && [ $startup_sleep -ne 100 ];then
echo $echo_n "SST in progress, setting sleep higher"
startup_sleep=100
fi
echo $echo_n ".$echo_c"
i=`expr $i + 1`
sleep 1
sleep $startup_sleep
done
......@@ -411,10 +418,16 @@ case "$mode" in
fi
exit $r
;;
'boostrap')
# Bootstrap the cluster, start the first node
# that initiate the cluster
echo $echo_n "Bootstrapping cluster)"
$0 start $other_args --wsrep-new-cluster
;;
*)
# usage
basename=`basename "$0"`
echo "Usage: $basename {start|stop|restart|reload|force-reload|status|configtest} [ MySQL server options ]"
echo "Usage: $basename {start|stop|restart|reload|force-reload|status|configtest|bootstrap} [ MySQL server options ]"
exit 1
;;
esac
......
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