Merge lp:~tplavcic/percona-server/bld-212-5.6-tokudb into lp:percona-server/5.6

Proposed by Tomislav Plavcic
Status: Merged
Merged at revision: 732
Proposed branch: lp:~tplavcic/percona-server/bld-212-5.6-tokudb
Merge into: lp:percona-server/5.6
Diff against target: 462 lines (+341/-23)
6 files modified
build-ps/debian/percona-server-tokudb-5.6.files (+1/-0)
build-ps/debian/percona-server-tokudb-5.6.postinst (+4/-9)
build-ps/percona-server.spec (+10/-14)
scripts/CMakeLists.txt (+1/-0)
scripts/mysqld_safe.sh (+59/-0)
scripts/ps_tokudb_admin.sh (+266/-0)
To merge this branch: bzr merge lp:~tplavcic/percona-server/bld-212-5.6-tokudb
Reviewer Review Type Date Requested Status
David Bennett (community) Approve
Laurynas Biveinis (community) Approve
Review via email: mp+247802@code.launchpad.net

This proposal supersedes a proposal from 2015-01-15.

Description of the change

This change is for BLD-212 (simplify TokuDB installation).
It adds ps_tokudb_admin script which can install/uninstall TokuDB plugin and disable transparent huge pages.
Mysqld_safe was changed to read thp-setting option from my.cnf

Extensive testing was done in BLD-212 so here I only show how install/uninstall works on centos7.
Test packages are available here:
http://jenkins.percona.com/job/percona-server-5.6-RELEASE/96/

INSTALL
-------
[vagrant@t-centos7-64 ~]$ sudo ps_tokudb_admin -e -u root
Checking transparent huge pages status on the system...
>> Transparent huge pages are enabled (should be disabled).

Checking if thp-setting=never option is already set in config file...
>> Option thp-setting=never is not set in the config file.
>> (needed only if THP is not disabled permanently on the system)

Checking TokuDB plugin status...
>> TokuDB plugin is not installed.

Disabling transparent huge pages for the current session...
>> Successfuly disabled transparent huge pages for this session.

Adding thp-setting=never option into /etc/my.cnf
>> Successfuly added thp-setting=never option into /etc/my.cnf

Installing TokuDB engine...
>> Successfuly installed TokuDB plugin.

mysql> show plugins;
...
| TokuDB | ACTIVE | STORAGE ENGINE | ha_tokudb.so | GPL |
| TokuDB_file_map | ACTIVE | INFORMATION SCHEMA | ha_tokudb.so | GPL |
| TokuDB_fractal_tree_info | ACTIVE | INFORMATION SCHEMA | ha_tokudb.so | GPL |
| TokuDB_fractal_tree_block_map | ACTIVE | INFORMATION SCHEMA | ha_tokudb.so | GPL |
| TokuDB_trx | ACTIVE | INFORMATION SCHEMA | ha_tokudb.so | GPL |
| TokuDB_locks | ACTIVE | INFORMATION SCHEMA | ha_tokudb.so | GPL |
| TokuDB_lock_waits | ACTIVE | INFORMATION SCHEMA | ha_tokudb.so | GPL |
+-------------------------------+----------+--------------------+--------------+---------+

UNINSTALL
---------
[vagrant@t-centos7-64 ~]$ sudo ps_tokudb_admin -d -u root
Checking transparent huge pages status on the system...
>> Transparent huge pages are currently disabled on the system.

Checking if thp-setting=never option is already set in config file...
>> Option thp-setting=never is set in the config file.

Checking TokuDB plugin status...
>> TokuDB plugin is installed.

Removing thp-setting=never option from /etc/my.cnf
>> Successfuly removed thp-setting=never option from /etc/my.cnf

Uninstalling TokuDB plugin...
>> Successfuly uninstalled TokuDB plugin.

To post a comment you must log in.
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote : Posted in a previous version of this proposal

It needs a blueprint?

review: Needs Information
Revision history for this message
Tomislav Plavcic (tplavcic) wrote : Posted in a previous version of this proposal

Created some blueprint - please check.

Revision history for this message
Roel Van de Paar (roel11) wrote : Posted in a previous version of this proposal

The script does not allow specification of host/socket/port. Thus, it assumes that PS is installed in a standard way (yum/apt), on a standard port, etc.

If the customer has both MS and PS on one box, on different ports, the wrong one may be auto-selected depending on which one is running on the default port, etc.

review: Needs Information
Revision history for this message
Roel Van de Paar (roel11) wrote : Posted in a previous version of this proposal

Also, I am not sure about removing the INSTALL PLUGIN information from postinst. It may still make sense for many DBA's to quickly hop in a CLI and execute this, rather then using a new tool.

Revision history for this message
David Bennett (dbpercona) wrote : Posted in a previous version of this proposal

Regarding the INSTALL PLUGIN postinst message, perhaps we could add a manual installation instructions under /usr/share/doc/{percona-server-tokudb-5.6} that gave complete instructions including the setting of THP. The manual instructions text file could be referenced in the postinst message.

This way the postinst message would remain concise and the DBA would have access to the full instructions which we could update if needed.

Revision history for this message
David Bennett (dbpercona) wrote : Posted in a previous version of this proposal

Regarding the manual installation text file, Tomislav points out that there is a link to the manual instructions referenced in the postinst message:

 * See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_intro.html for more details

This will be easier to maintain and provide us with a single point of maintenance.

Revision history for this message
Roel Van de Paar (roel11) wrote : Posted in a previous version of this proposal

@David/@Tomislav - manual link sounds great/fine.

Revision history for this message
Roel Van de Paar (roel11) wrote : Posted in a previous version of this proposal

However, the way it stands now;

+ echo -e " * Run the following script to enable the TokuDB storage engine in Percona Server:\n"
+ echo -e "\tps_tokudb_admin --enable -u <mysql_admin_user> -p <mysql_admin_pass>\n"
+ echo -e " * See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_intro.html for more details\n\n"

It looks like tokudb_intro.html will have more details on tps_tokudb_admin (it does not). Maybe instead it should be pointed at http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_installation.html and on that page (before we release this) info on tps_tokudb_admin.sh should be added.

Btw, the above should read" ps_tokudb_admin.sh" (.sh) + potentially list connect details? How about;

+ echo -e "\tps_tokudb_admin --enable -u <mysql_admin_user> -p <mysql_admin_pass> {-S <socket>} {-h <host> -P <port>} \n"

Revision history for this message
Roel Van de Paar (roel11) wrote : Posted in a previous version of this proposal

On second thoughts, both pages are of interest. So, how about this final update;

+ echo -e " * Run the following script to enable the TokuDB storage engine in Percona Server:\n"
+ echo -e "\tps_tokudb_admin.sh --enable -u <mysql_admin_user> -p <mysql_admin_pass> {-S <socket>} {-h <host> -P <port>}\n"
+ echo -e " * See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_installation.html for more installation details\n\n"
+ echo -e " * See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_intro.html for an Introduction to TokuDB\n\n"

Revision history for this message
Roel Van de Paar (roel11) wrote : Posted in a previous version of this proposal

(There is a second newline in between the URL's should it look fairly clean/uncluttered)

Revision history for this message
Tomislav Plavcic (tplavcic) wrote : Posted in a previous version of this proposal

Roel/David:
- I've changed postinst to what Roel suggested (with two links) - it should look ok
- host, port, socket are added as parameters
- and usage info is added in mysqld_safe for --thp-setting
Info about the new build with this changes is in BLD-212 - when we confirm it is ok I'll resubmit merge proposal.

Revision history for this message
Roel Van de Paar (roel11) wrote : Posted in a previous version of this proposal

I previously checked out the host etc. option addition, and - whilst not having tested it - the code looked good.

Revision history for this message
Roel Van de Paar (roel11) wrote : Posted in a previous version of this proposal

Script should still be tested with new options + user/pwd etc.

Revision history for this message
Roel Van de Paar (roel11) wrote : Posted in a previous version of this proposal

Btw, official release is on 28th

Revision history for this message
Tomislav Plavcic (tplavcic) wrote : Posted in a previous version of this proposal

Changed postinst messages, script running parameters and usage info in mysqld_safe so resubmitting MP.
Testing has been done in BLD-212.

Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote :

Looks good to me, but this should be reviewed by someone more involved with the task, e.g. David.

review: Approve
Revision history for this message
David Bennett (dbpercona) wrote :

There is an issue in Jira BLD-246:

  https://jira.percona.com/browse/BLD-246

PZ discovered that is Percona Server is installed and running without jemalloc prior to the installation of TokuDB (along with jemalloc dependency) then ps_tokudb_admin fails to load the plugin.

The solution that PZ recommend is the safest way to handle it. Have ps_tokudb_admin check to see if mysqld is running without jemalloc underneath. If that condition is true, then stop prior to installation of the plug-in with a message indicating a restart is required.

During restart, the updated mysqld_safe will detect and load the underlying jemalloc automatically and the ps_tokudb_admin --enable can proceed.

There is a command in the Jira issue that will check for jemalloc running underneath mysqld:

  grep -c jemalloc /proc/$(cat {path}/mysqld.pid)/environ

If this returns 0 then the process needs to stop with the restart notification.

Revision history for this message
David Bennett (dbpercona) wrote :

We need to address Jira BLD-246 then it's good.

review: Needs Fixing
Revision history for this message
Roel Van de Paar (roel11) wrote :

Some ideas on extracting the path (if there are none yet); from ps output, or via mysqladmin, or is there are a better/more reliable way?

Revision history for this message
David Bennett (dbpercona) wrote :

BLD-246 tested and closed looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'build-ps/debian/percona-server-tokudb-5.6.files'
--- build-ps/debian/percona-server-tokudb-5.6.files 2014-09-27 13:49:22 +0000
+++ build-ps/debian/percona-server-tokudb-5.6.files 2015-01-29 14:13:34 +0000
@@ -1,3 +1,4 @@
1usr/lib/mysql/plugin/ha_tokudb.so1usr/lib/mysql/plugin/ha_tokudb.so
2usr/lib/mysql/plugin/debug/ha_tokudb.so2usr/lib/mysql/plugin/debug/ha_tokudb.so
3usr/bin/tokuftdump3usr/bin/tokuftdump
4usr/bin/ps_tokudb_admin
45
=== modified file 'build-ps/debian/percona-server-tokudb-5.6.postinst'
--- build-ps/debian/percona-server-tokudb-5.6.postinst 2014-05-20 21:04:08 +0000
+++ build-ps/debian/percona-server-tokudb-5.6.postinst 2015-01-29 14:13:34 +0000
@@ -3,15 +3,10 @@
3# Some postinstall info about TokuDB3# Some postinstall info about TokuDB
4if [ -z "$2" ]; then4if [ -z "$2" ]; then
5 echo -e "\n\n * This release of Percona Server is distributed with TokuDB storage engine."5 echo -e "\n\n * This release of Percona Server is distributed with TokuDB storage engine."
6 echo -e " * Run the following commands to enable the TokuDB storage engine in Percona Server:\n"6 echo -e " * Run the following script to enable the TokuDB storage engine in Percona Server:\n"
7 echo -e "\tmysql -e \"INSTALL PLUGIN tokudb SONAME 'ha_tokudb.so';\""7 echo -e "\tps_tokudb_admin --enable -u <mysql_admin_user> -p[mysql_admin_pass] [-S <socket>] [-h <host> -P <port>]\n"
8 echo -e "\tmysql -e \"INSTALL PLUGIN tokudb_file_map SONAME 'ha_tokudb.so';\""8 echo -e " * See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_installation.html for more installation details\n"
9 echo -e "\tmysql -e \"INSTALL PLUGIN tokudb_fractal_tree_info SONAME 'ha_tokudb.so';\""9 echo -e " * See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_intro.html for an introduction to TokuDB\n\n"
10 echo -e "\tmysql -e \"INSTALL PLUGIN tokudb_fractal_tree_block_map SONAME 'ha_tokudb.so';\""
11 echo -e "\tmysql -e \"INSTALL PLUGIN tokudb_trx SONAME 'ha_tokudb.so';\""
12 echo -e "\tmysql -e \"INSTALL PLUGIN tokudb_locks SONAME 'ha_tokudb.so';\""
13 echo -e "\tmysql -e \"INSTALL PLUGIN tokudb_lock_waits SONAME 'ha_tokudb.so';\""
14 echo -e "\n * See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_intro.html for more details\n\n"
15fi10fi
1611
17#DEBHELPER#12#DEBHELPER#
1813
=== modified file 'build-ps/percona-server.spec'
--- build-ps/percona-server.spec 2015-01-19 10:11:09 +0000
+++ build-ps/percona-server.spec 2015-01-29 14:13:34 +0000
@@ -651,6 +651,10 @@
651%if 0%{?systemd}651%if 0%{?systemd}
652rm -rf $RBR%{_sysconfdir}/init.d/mysql652rm -rf $RBR%{_sysconfdir}/init.d/mysql
653%endif653%endif
654# Not needed if TokuDB package is not created
655%if ! %{with tokudb}
656rm -rf $RBR%{_bindir}/ps_tokudb_admin
657%endif
654658
655##############################################################################659##############################################################################
656# Post processing actions, i.e. when installed660# Post processing actions, i.e. when installed
@@ -1097,20 +1101,11 @@
1097%post -n Percona-Server-tokudb%{product_suffix}1101%post -n Percona-Server-tokudb%{product_suffix}
10981102
1099if [ $1 -eq 1 ] ; then1103if [ $1 -eq 1 ] ; then
1100 echo ""1104 echo -e "\n\n * This release of Percona Server is distributed with TokuDB storage engine."
1101 echo "* This release of Percona Server is distributed with TokuDB storage engine."1105 echo -e " * Run the following script to enable the TokuDB storage engine in Percona Server:\n"
1102 echo "* Run the following commands to enable the TokuDB storage engine in Percona Server:"1106 echo -e "\tps_tokudb_admin --enable -u <mysql_admin_user> -p[mysql_admin_pass] [-S <socket>] [-h <host> -P <port>]\n"
1103 echo ""1107 echo -e " * See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_installation.html for more installation details\n"
1104 echo "mysql -e \"INSTALL PLUGIN tokudb SONAME 'ha_tokudb.so';\""1108 echo -e " * See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_intro.html for an introduction to TokuDB\n\n"
1105 echo "mysql -e \"INSTALL PLUGIN tokudb_file_map SONAME 'ha_tokudb.so';\""
1106 echo "mysql -e \"INSTALL PLUGIN tokudb_fractal_tree_info SONAME 'ha_tokudb.so';\""
1107 echo "mysql -e \"INSTALL PLUGIN tokudb_fractal_tree_block_map SONAME 'ha_tokudb.so';\""
1108 echo "mysql -e \"INSTALL PLUGIN tokudb_trx SONAME 'ha_tokudb.so';\""
1109 echo "mysql -e \"INSTALL PLUGIN tokudb_locks SONAME 'ha_tokudb.so';\""
1110 echo "mysql -e \"INSTALL PLUGIN tokudb_lock_waits SONAME 'ha_tokudb.so';\""
1111 echo ""
1112 echo "* See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_intro.html for more details"
1113 echo ""
1114fi1109fi
1115# If upgrade is in question and the server was started before upgrade we need to start it1110# If upgrade is in question and the server was started before upgrade we need to start it
1116# after upgrading TokuDB package and not before because TokuDB will fail on init1111# after upgrading TokuDB package and not before because TokuDB will fail on init
@@ -1412,6 +1407,7 @@
1412%{_bindir}/tokuftdump1407%{_bindir}/tokuftdump
1413%{_libdir}/mysql/plugin/ha_tokudb.so1408%{_libdir}/mysql/plugin/ha_tokudb.so
1414%attr(755, root, root) %{_libdir}/mysql/plugin/debug/ha_tokudb.so1409%attr(755, root, root) %{_libdir}/mysql/plugin/debug/ha_tokudb.so
1410%attr(755, root, root) %{_bindir}/ps_tokudb_admin
1415%endif1411%endif
14161412
1417# ----------------------------------------------------------------------------1413# ----------------------------------------------------------------------------
14181414
=== modified file 'scripts/CMakeLists.txt'
--- scripts/CMakeLists.txt 2014-12-16 06:00:17 +0000
+++ scripts/CMakeLists.txt 2015-01-29 14:13:34 +0000
@@ -339,6 +339,7 @@
339 mysqldumpslow339 mysqldumpslow
340 mysqld_multi340 mysqld_multi
341 mysqld_safe341 mysqld_safe
342 ps_tokudb_admin
342 )343 )
343 FOREACH(file ${BIN_SCRIPTS})344 FOREACH(file ${BIN_SCRIPTS})
344 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.sh)345 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.sh)
345346
=== modified file 'scripts/mysqld_safe.sh'
--- scripts/mysqld_safe.sh 2014-12-01 07:53:48 +0000
+++ scripts/mysqld_safe.sh 2015-01-29 14:13:34 +0000
@@ -20,6 +20,8 @@
20load_jemalloc=120load_jemalloc=1
21flush_caches=021flush_caches=0
22numa_interleave=022numa_interleave=0
23# Change (disable) transparent huge pages (TokuDB requirement)
24thp_setting=
2325
24# Initial logging status: error log is not open, and not using syslog26# Initial logging status: error log is not open, and not using syslog
25logging=init27logging=init
@@ -66,6 +68,14 @@
66esac68esac
6769
68usage () {70usage () {
71 thp_usage=""
72 if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]; then
73 thp_usage=$(cat <<'EOF'
74 --thp-setting=SETTING Change transparent huge pages setting
75 on the system before starting mysqld
76EOF
77);
78 fi
69 cat <<EOF79 cat <<EOF
70Usage: $0 [OPTIONS]80Usage: $0 [OPTIONS]
71 --no-defaults Don't read the system defaults file81 --no-defaults Don't read the system defaults file
@@ -89,6 +99,7 @@
89 starting the server99 starting the server
90 --numa-interleave Run mysqld with its memory interleaved100 --numa-interleave Run mysqld with its memory interleaved
91 on all NUMA nodes101 on all NUMA nodes
102${thp_usage}
92103
93All other options are passed to the mysqld program.104All other options are passed to the mysqld program.
94105
@@ -233,6 +244,7 @@
233 --open-files-limit=*) open_files="$val" ;;244 --open-files-limit=*) open_files="$val" ;;
234 --open_files_limit=*) open_files="$val" ;;245 --open_files_limit=*) open_files="$val" ;;
235 --skip-kill-mysqld*) KILL_MYSQLD=0 ;;246 --skip-kill-mysqld*) KILL_MYSQLD=0 ;;
247 --thp-setting=*) thp_setting="$val" ;;
236 --syslog) want_syslog=1 ;;248 --syslog) want_syslog=1 ;;
237 --skip-syslog) want_syslog=0 ;;249 --skip-syslog) want_syslog=0 ;;
238 --syslog-tag=*) syslog_tag="$val" ;;250 --syslog-tag=*) syslog_tag="$val" ;;
@@ -799,6 +811,53 @@
799 exit 1811 exit 1
800fi812fi
801813
814# If thp-setting is specified, check to see if thp is supported
815# on this kernel and clear the value if it isn't
816if [ -n "$thp_setting" ] && [ ! -f /sys/kernel/mm/transparent_hugepage/enabled ]
817then
818 log_notice "Transparent huge pages is not supported on this system, ignoring thp-setting."
819 thp_setting=
820fi
821
822# Change transparent huge pages setting if thp-setting option specified
823if [ -n "$thp_setting" ]
824then
825 if [ $(id -u) -ne 0 ]; then
826 log_error "mysqld_safe must be run as root for setting transparent huge pages!"
827 exit 1
828 elif [ $thp_setting != "always" -a $thp_setting != "madvise" -a $thp_setting != "never" ]; then
829 log_error "Invalid value for thp-setting=$thp_setting in config file. Valid values are: always, madvise or never"
830 exit 1
831 else
832 if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]; then
833 CONTENT_THP=$(cat /sys/kernel/mm/transparent_hugepage/enabled)
834 STATUS_THP=0
835 set +e
836 STATUS_THP=$(echo $CONTENT_THP | grep -cv "\[${thp_setting}\]")
837 set -e
838 fi
839 if [ $STATUS_THP -eq 0 ]; then
840 log_notice "Transparent huge pages are already set to: ${thp_setting}."
841 else
842 if [ -f /sys/kernel/mm/transparent_hugepage/defrag ]; then
843 echo $thp_setting > /sys/kernel/mm/transparent_hugepage/defrag
844 if [ $? -ne 0 ]; then
845 log_error "Error setting transparent huge pages to: ${thp_setting}."
846 exit 1
847 fi
848 fi
849 if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]; then
850 echo $thp_setting > /sys/kernel/mm/transparent_hugepage/enabled
851 if [ $? -ne 0 ]; then
852 log_error "Error setting transparent huge pages to: ${thp_setting}."
853 exit 1
854 fi
855 fi
856 log_notice "Successfuly set transparent huge pages to: ${thp_setting}."
857 fi
858 fi
859fi
860
802#861#
803# Uncomment the following lines if you want all tables to be automatically862# Uncomment the following lines if you want all tables to be automatically
804# checked and repaired during startup. You should add sensible key_buffer863# checked and repaired during startup. You should add sensible key_buffer
805864
=== added file 'scripts/ps_tokudb_admin.sh'
--- scripts/ps_tokudb_admin.sh 1970-01-01 00:00:00 +0000
+++ scripts/ps_tokudb_admin.sh 2015-01-29 14:13:34 +0000
@@ -0,0 +1,266 @@
1#!/bin/bash
2#
3# Script for installing TokuDB plugin in Percona Server
4#
5set -u
6
7# Examine parameters
8# default user
9USER="root"
10# default pass
11PASSWORD=""
12SOCKET=""
13HOST=""
14PORT=""
15STATUS_THP_SYSTEM=0
16STATUS_THP_MYCNF=0
17STATUS_PLUGIN=0
18ENABLE=0
19DISABLE=0
20MYCNF_LOCATION=
21MYSQLD_SAFE_STATUS=0
22
23# Check if we have a functional getopt(1)
24if ! getopt --test
25 then
26 go_out="$(getopt --options=u:p::S:h:P:ed \
27 --longoptions=user:,password::,socket:,host:,port:,enable,disable,help \
28 --name="$(basename "$0")" -- "$@")"
29 test $? -eq 0 || exit 1
30 eval set -- $go_out
31fi
32
33for arg
34do
35 case "$arg" in
36 -- ) shift; break;;
37 -u | --user )
38 USER="$2"
39 shift 2
40 ;;
41 -p | --password )
42 case "$2" in
43 "")
44 read -s -p "Enter password:" INPUT_PASS
45 if [ -z "$INPUT_PASS" ]; then
46 PASSWORD=""
47 printf "\nContinuing without password...\n";
48 else
49 PASSWORD="-p$INPUT_PASS"
50 fi
51 printf "\n\n"
52 ;;
53 *)
54 PASSWORD="-p$2"
55 ;;
56 esac
57 shift 2
58 ;;
59 -S | --socket )
60 SOCKET="-S $2"
61 shift 2
62 ;;
63 -h | --host )
64 HOST="-h $2"
65 shift 2
66 ;;
67 -P | --port )
68 PORT="-P $2"
69 shift 2
70 ;;
71 -e | --enable )
72 shift
73 ENABLE=1
74 ;;
75 -d | --disable )
76 shift
77 DISABLE=1
78 ;;
79 --help )
80 printf "This script is used for installing and uninstalling TokuDB plugin for Percona Server 5.6.\n"
81 printf "If transparent huge pages are enabled on the system it adds thp-setting=never option to my.cnf\n"
82 printf "to disable it on runtime.\n\n"
83 printf "Valid options are:\n"
84 printf " --user=user_name, -u user_name\t mysql admin username\n"
85 printf " --password[=password], -p[password]\t mysql admin password (on empty will prompt to enter)\n"
86 printf " --socket=path, -S path\t\t the socket file to use for connection\n"
87 printf " --host=host_name, -h host_name\t connect to given host\n"
88 printf " --port=port_num, -P port_num\t\t port number to use for connection\n"
89 printf " --enable, -e\t\t\t\t enable TokuDB plugin and disable transparent huge pages in my.cnf\n"
90 printf " --disable, d\t\t\t\t disable TokuDB plugin and remove thp-setting=never option in my.cnf\n"
91 printf " --help\t\t\t\t show this help\n\n"
92 printf "For TokuDB requirements and manual steps for installation please visit this webpage:\n"
93 printf "http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_installation.html\n\n"
94 exit 0
95 ;;
96 esac
97done
98
99# Make sure only root can run this script
100if [ $(id -u) -ne 0 ]; then
101 echo "This script must be run as root!" 1>&2
102 exit 1
103fi
104
105if [ $ENABLE = 1 -a $DISABLE = 1 ]; then
106 printf "Only --enable OR --disable can be specified - not both!\n"
107 exit 1
108elif [ $ENABLE = 0 -a $DISABLE = 0 ]; then
109 printf "You should specify --enable or --disable option. Use --help for printing options.\n"
110 exit 1
111fi
112
113# Check if server is running with jemalloc - if not warn that restart is needed
114printf "Checking if Percona server is running with jemalloc enabled...\n"
115PID_LOCATION=$(mysql -e "show variables like 'pid_file';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null|grep pid_file|awk '{print $2}')
116if [ $? -ne 0 ] || [ "${PID_LOCATION}" == "" ]; then
117 printf ">> Error checking pid file location! Please check username, password and other options...\n";
118 exit 1
119fi
120PID_NUM=$(cat ${PID_LOCATION})
121JEMALLOC_STATUS=$(grep -c jemalloc /proc/${PID_NUM}/environ)
122if [ $JEMALLOC_STATUS = 0 ]; then
123 printf ">> Percona server is not running with jemalloc, please restart server to enable it and then run this script...\n\n";
124 exit 1
125else
126 printf ">> Percona server is running with jemalloc enabled.\n\n";
127fi
128
129# Check transparent huge pages status on the system
130printf "Checking transparent huge pages status on the system...\n"
131if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]; then
132 CONTENT_TRANSHP=$(</sys/kernel/mm/transparent_hugepage/enabled)
133 STATUS_THP_SYSTEM=$(echo $CONTENT_TRANSHP | grep -cv '\[never\]')
134fi
135if [ $STATUS_THP_SYSTEM = 0 ]; then
136 printf ">> Transparent huge pages are currently disabled on the system.\n\n"
137else
138 printf ">> Transparent huge pages are enabled (should be disabled).\n\n"
139fi
140
141# Check thp-setting=never option in my.cnf
142printf "Checking if thp-setting=never option is already set in config file...\n"
143STATUS_THP_MYCNF=$(my_print_defaults server mysqld mysqld_safe|grep -c thp-setting=never)
144if [ $STATUS_THP_MYCNF = 0 ]; then
145 printf ">> Option thp-setting=never is not set in the config file.\n"
146 printf ">> (needed only if THP is not disabled permanently on the system)\n\n"
147else
148 printf ">> Option thp-setting=never is set in the config file.\n\n"
149fi
150
151# Check location of my.cnf
152if [ -f /etc/my.cnf ]; then
153 MYCNF_LOCATION=/etc/my.cnf
154elif [ -f /etc/mysql/my.cnf ]; then
155 MYCNF_LOCATION=/etc/mysql/my.cnf
156elif [ -f /usr/etc/my.cnf ]; then
157 MYCNF_LOCATION=/usr/etc/my.cnf
158else
159 if [ -d /etc/mysql ]; then
160 MYCNF_LOCATION=/etc/mysql/my.cnf
161 else
162 MYCNF_LOCATION=/etc/my.cnf
163 fi
164 echo -n "" >> ${MYCNF_LOCATION}
165fi
166
167# Check TokuDB plugin status
168printf "Checking TokuDB plugin status...\n"
169LIST_ENGINE=$(mysql -e "show plugins;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null)
170if [ $? -ne 0 ]; then
171 printf ">> Error checking TokuDB plugin status! Please check username, password and other options...\n";
172 exit 1
173fi
174STATUS_PLUGIN=$(echo "$LIST_ENGINE" | grep -c "TokuDB")
175if [ $STATUS_PLUGIN = 0 ]; then
176 printf ">> TokuDB plugin is not installed.\n\n"
177elif [ $STATUS_PLUGIN = 7 ]; then
178 printf ">> TokuDB plugin is installed.\n\n"
179 exit 0
180else
181 printf ">> TokuDB plugin is partially installed. Please cleanup manually.\n\n"
182 exit 1
183fi
184
185# Disable transparent huge pages in the current session so
186# that the plugin can be installed without restarting PS
187if [ $ENABLE = 1 -a $STATUS_THP_SYSTEM = 1 ]; then
188 printf "Disabling transparent huge pages for the current session...\n"
189 if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
190 echo never > /sys/kernel/mm/transparent_hugepage/defrag
191 fi
192 if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
193 echo never > /sys/kernel/mm/transparent_hugepage/enabled
194 fi
195 if [ $? -eq 0 ]; then
196 printf ">> Successfuly disabled transparent huge pages for this session.\n\n"
197 else
198 printf ">> Error disabling transparent huge pages for this session.\n\n"
199 exit 1
200 fi
201fi
202
203# Add option to disable transparent huge pages into my.cnf
204if [ $ENABLE = 1 -a $STATUS_THP_MYCNF = 0 ]; then
205 printf "Adding thp-setting=never option into $MYCNF_LOCATION\n"
206 MYSQLD_SAFE_STATUS=$(grep -c "^\[mysqld_safe\]$" $MYCNF_LOCATION)
207 if [ $MYSQLD_SAFE_STATUS = 0 ]; then
208 echo -e "\n[mysqld_safe]\nthp-setting=never" >> $MYCNF_LOCATION
209 else
210 sed -i '/^\[mysqld_safe\]$/a thp-setting=never' $MYCNF_LOCATION
211 fi
212 if [ $? -eq 0 ]; then
213 printf ">> Successfuly added thp-setting=never option into $MYCNF_LOCATION\n\n";
214 else
215 printf ">> Error adding thp-setting=never option into $MYCNF_LOCATION\n\n";
216 exit 1
217 fi
218fi
219
220# Remove option for disabling transparent huge pages from my.cnf
221if [ $DISABLE = 1 -a $STATUS_THP_MYCNF = 1 ]; then
222 printf "Removing thp-setting=never option from $MYCNF_LOCATION\n"
223 sed -i '/^thp-setting=never$/d' $MYCNF_LOCATION
224 if [ $? -eq 0 ]; then
225 printf ">> Successfuly removed thp-setting=never option from $MYCNF_LOCATION\n\n";
226 else
227 printf ">> Error removing thp-setting=never option from $MYCNF_LOCATION\n\n";
228 exit 1
229 fi
230fi
231
232# Installing TokuDB plugin
233if [ $ENABLE = 1 -a $STATUS_PLUGIN = 0 ]; then
234 printf "Installing TokuDB engine...\n"
235 mysql -e "INSTALL PLUGIN tokudb SONAME 'ha_tokudb.so';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
236 mysql -e "INSTALL PLUGIN tokudb_file_map SONAME 'ha_tokudb.so';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
237 mysql -e "INSTALL PLUGIN tokudb_fractal_tree_info SONAME 'ha_tokudb.so';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
238 mysql -e "INSTALL PLUGIN tokudb_fractal_tree_block_map SONAME 'ha_tokudb.so';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
239 mysql -e "INSTALL PLUGIN tokudb_trx SONAME 'ha_tokudb.so';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
240 mysql -e "INSTALL PLUGIN tokudb_locks SONAME 'ha_tokudb.so';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
241 mysql -e "INSTALL PLUGIN tokudb_lock_waits SONAME 'ha_tokudb.so';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null
242 if [ $? -eq 0 ]; then
243 printf ">> Successfuly installed TokuDB plugin.\n\n"
244 else
245 printf ">> Error installing TokuDB plugin. Please check error log.\n\n"
246 exit 1
247 fi
248fi
249
250# Uninstalling TokuDB plugin
251if [ $DISABLE = 1 -a $STATUS_PLUGIN = 7 ]; then
252 printf "Uninstalling TokuDB plugin...\n"
253 mysql -e "UNINSTALL PLUGIN tokudb;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
254 mysql -e "UNINSTALL PLUGIN tokudb_file_map;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
255 mysql -e "UNINSTALL PLUGIN tokudb_fractal_tree_info;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
256 mysql -e "UNINSTALL PLUGIN tokudb_fractal_tree_block_map;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
257 mysql -e "UNINSTALL PLUGIN tokudb_trx;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
258 mysql -e "UNINSTALL PLUGIN tokudb_locks;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
259 mysql -e "UNINSTALL PLUGIN tokudb_lock_waits;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null
260 if [ $? -eq 0 ]; then
261 printf ">> Successfuly uninstalled TokuDB plugin.\n\n"
262 else
263 printf ">> Error uninstalling TokuDB plugin. Please check error log.\n\n"
264 exit 1
265 fi
266fi

Subscribers

People subscribed via source and target branches