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?

730. By Tomislav Plavcic on 2015-01-29

Simplify tokudb installation (BLD-212)

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
1=== modified file 'build-ps/debian/percona-server-tokudb-5.6.files'
2--- build-ps/debian/percona-server-tokudb-5.6.files 2014-09-27 13:49:22 +0000
3+++ build-ps/debian/percona-server-tokudb-5.6.files 2015-01-29 14:13:34 +0000
4@@ -1,3 +1,4 @@
5 usr/lib/mysql/plugin/ha_tokudb.so
6 usr/lib/mysql/plugin/debug/ha_tokudb.so
7 usr/bin/tokuftdump
8+usr/bin/ps_tokudb_admin
9
10=== modified file 'build-ps/debian/percona-server-tokudb-5.6.postinst'
11--- build-ps/debian/percona-server-tokudb-5.6.postinst 2014-05-20 21:04:08 +0000
12+++ build-ps/debian/percona-server-tokudb-5.6.postinst 2015-01-29 14:13:34 +0000
13@@ -3,15 +3,10 @@
14 # Some postinstall info about TokuDB
15 if [ -z "$2" ]; then
16 echo -e "\n\n * This release of Percona Server is distributed with TokuDB storage engine."
17- echo -e " * Run the following commands to enable the TokuDB storage engine in Percona Server:\n"
18- echo -e "\tmysql -e \"INSTALL PLUGIN tokudb SONAME 'ha_tokudb.so';\""
19- echo -e "\tmysql -e \"INSTALL PLUGIN tokudb_file_map SONAME 'ha_tokudb.so';\""
20- echo -e "\tmysql -e \"INSTALL PLUGIN tokudb_fractal_tree_info SONAME 'ha_tokudb.so';\""
21- echo -e "\tmysql -e \"INSTALL PLUGIN tokudb_fractal_tree_block_map SONAME 'ha_tokudb.so';\""
22- echo -e "\tmysql -e \"INSTALL PLUGIN tokudb_trx SONAME 'ha_tokudb.so';\""
23- echo -e "\tmysql -e \"INSTALL PLUGIN tokudb_locks SONAME 'ha_tokudb.so';\""
24- echo -e "\tmysql -e \"INSTALL PLUGIN tokudb_lock_waits SONAME 'ha_tokudb.so';\""
25- echo -e "\n * See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_intro.html for more details\n\n"
26+ echo -e " * Run the following script to enable the TokuDB storage engine in Percona Server:\n"
27+ echo -e "\tps_tokudb_admin --enable -u <mysql_admin_user> -p[mysql_admin_pass] [-S <socket>] [-h <host> -P <port>]\n"
28+ echo -e " * See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_installation.html for more installation details\n"
29+ echo -e " * See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_intro.html for an introduction to TokuDB\n\n"
30 fi
31
32 #DEBHELPER#
33
34=== modified file 'build-ps/percona-server.spec'
35--- build-ps/percona-server.spec 2015-01-19 10:11:09 +0000
36+++ build-ps/percona-server.spec 2015-01-29 14:13:34 +0000
37@@ -651,6 +651,10 @@
38 %if 0%{?systemd}
39 rm -rf $RBR%{_sysconfdir}/init.d/mysql
40 %endif
41+# Not needed if TokuDB package is not created
42+%if ! %{with tokudb}
43+rm -rf $RBR%{_bindir}/ps_tokudb_admin
44+%endif
45
46 ##############################################################################
47 # Post processing actions, i.e. when installed
48@@ -1097,20 +1101,11 @@
49 %post -n Percona-Server-tokudb%{product_suffix}
50
51 if [ $1 -eq 1 ] ; then
52- echo ""
53- echo "* This release of Percona Server is distributed with TokuDB storage engine."
54- echo "* Run the following commands to enable the TokuDB storage engine in Percona Server:"
55- echo ""
56- echo "mysql -e \"INSTALL PLUGIN tokudb SONAME 'ha_tokudb.so';\""
57- echo "mysql -e \"INSTALL PLUGIN tokudb_file_map SONAME 'ha_tokudb.so';\""
58- echo "mysql -e \"INSTALL PLUGIN tokudb_fractal_tree_info SONAME 'ha_tokudb.so';\""
59- echo "mysql -e \"INSTALL PLUGIN tokudb_fractal_tree_block_map SONAME 'ha_tokudb.so';\""
60- echo "mysql -e \"INSTALL PLUGIN tokudb_trx SONAME 'ha_tokudb.so';\""
61- echo "mysql -e \"INSTALL PLUGIN tokudb_locks SONAME 'ha_tokudb.so';\""
62- echo "mysql -e \"INSTALL PLUGIN tokudb_lock_waits SONAME 'ha_tokudb.so';\""
63- echo ""
64- echo "* See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_intro.html for more details"
65- echo ""
66+ echo -e "\n\n * This release of Percona Server is distributed with TokuDB storage engine."
67+ echo -e " * Run the following script to enable the TokuDB storage engine in Percona Server:\n"
68+ echo -e "\tps_tokudb_admin --enable -u <mysql_admin_user> -p[mysql_admin_pass] [-S <socket>] [-h <host> -P <port>]\n"
69+ echo -e " * See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_installation.html for more installation details\n"
70+ echo -e " * See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_intro.html for an introduction to TokuDB\n\n"
71 fi
72 # If upgrade is in question and the server was started before upgrade we need to start it
73 # after upgrading TokuDB package and not before because TokuDB will fail on init
74@@ -1412,6 +1407,7 @@
75 %{_bindir}/tokuftdump
76 %{_libdir}/mysql/plugin/ha_tokudb.so
77 %attr(755, root, root) %{_libdir}/mysql/plugin/debug/ha_tokudb.so
78+%attr(755, root, root) %{_bindir}/ps_tokudb_admin
79 %endif
80
81 # ----------------------------------------------------------------------------
82
83=== modified file 'scripts/CMakeLists.txt'
84--- scripts/CMakeLists.txt 2014-12-16 06:00:17 +0000
85+++ scripts/CMakeLists.txt 2015-01-29 14:13:34 +0000
86@@ -339,6 +339,7 @@
87 mysqldumpslow
88 mysqld_multi
89 mysqld_safe
90+ ps_tokudb_admin
91 )
92 FOREACH(file ${BIN_SCRIPTS})
93 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.sh)
94
95=== modified file 'scripts/mysqld_safe.sh'
96--- scripts/mysqld_safe.sh 2014-12-01 07:53:48 +0000
97+++ scripts/mysqld_safe.sh 2015-01-29 14:13:34 +0000
98@@ -20,6 +20,8 @@
99 load_jemalloc=1
100 flush_caches=0
101 numa_interleave=0
102+# Change (disable) transparent huge pages (TokuDB requirement)
103+thp_setting=
104
105 # Initial logging status: error log is not open, and not using syslog
106 logging=init
107@@ -66,6 +68,14 @@
108 esac
109
110 usage () {
111+ thp_usage=""
112+ if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]; then
113+ thp_usage=$(cat <<'EOF'
114+ --thp-setting=SETTING Change transparent huge pages setting
115+ on the system before starting mysqld
116+EOF
117+);
118+ fi
119 cat <<EOF
120 Usage: $0 [OPTIONS]
121 --no-defaults Don't read the system defaults file
122@@ -89,6 +99,7 @@
123 starting the server
124 --numa-interleave Run mysqld with its memory interleaved
125 on all NUMA nodes
126+${thp_usage}
127
128 All other options are passed to the mysqld program.
129
130@@ -233,6 +244,7 @@
131 --open-files-limit=*) open_files="$val" ;;
132 --open_files_limit=*) open_files="$val" ;;
133 --skip-kill-mysqld*) KILL_MYSQLD=0 ;;
134+ --thp-setting=*) thp_setting="$val" ;;
135 --syslog) want_syslog=1 ;;
136 --skip-syslog) want_syslog=0 ;;
137 --syslog-tag=*) syslog_tag="$val" ;;
138@@ -799,6 +811,53 @@
139 exit 1
140 fi
141
142+# If thp-setting is specified, check to see if thp is supported
143+# on this kernel and clear the value if it isn't
144+if [ -n "$thp_setting" ] && [ ! -f /sys/kernel/mm/transparent_hugepage/enabled ]
145+then
146+ log_notice "Transparent huge pages is not supported on this system, ignoring thp-setting."
147+ thp_setting=
148+fi
149+
150+# Change transparent huge pages setting if thp-setting option specified
151+if [ -n "$thp_setting" ]
152+then
153+ if [ $(id -u) -ne 0 ]; then
154+ log_error "mysqld_safe must be run as root for setting transparent huge pages!"
155+ exit 1
156+ elif [ $thp_setting != "always" -a $thp_setting != "madvise" -a $thp_setting != "never" ]; then
157+ log_error "Invalid value for thp-setting=$thp_setting in config file. Valid values are: always, madvise or never"
158+ exit 1
159+ else
160+ if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]; then
161+ CONTENT_THP=$(cat /sys/kernel/mm/transparent_hugepage/enabled)
162+ STATUS_THP=0
163+ set +e
164+ STATUS_THP=$(echo $CONTENT_THP | grep -cv "\[${thp_setting}\]")
165+ set -e
166+ fi
167+ if [ $STATUS_THP -eq 0 ]; then
168+ log_notice "Transparent huge pages are already set to: ${thp_setting}."
169+ else
170+ if [ -f /sys/kernel/mm/transparent_hugepage/defrag ]; then
171+ echo $thp_setting > /sys/kernel/mm/transparent_hugepage/defrag
172+ if [ $? -ne 0 ]; then
173+ log_error "Error setting transparent huge pages to: ${thp_setting}."
174+ exit 1
175+ fi
176+ fi
177+ if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]; then
178+ echo $thp_setting > /sys/kernel/mm/transparent_hugepage/enabled
179+ if [ $? -ne 0 ]; then
180+ log_error "Error setting transparent huge pages to: ${thp_setting}."
181+ exit 1
182+ fi
183+ fi
184+ log_notice "Successfuly set transparent huge pages to: ${thp_setting}."
185+ fi
186+ fi
187+fi
188+
189 #
190 # Uncomment the following lines if you want all tables to be automatically
191 # checked and repaired during startup. You should add sensible key_buffer
192
193=== added file 'scripts/ps_tokudb_admin.sh'
194--- scripts/ps_tokudb_admin.sh 1970-01-01 00:00:00 +0000
195+++ scripts/ps_tokudb_admin.sh 2015-01-29 14:13:34 +0000
196@@ -0,0 +1,266 @@
197+#!/bin/bash
198+#
199+# Script for installing TokuDB plugin in Percona Server
200+#
201+set -u
202+
203+# Examine parameters
204+# default user
205+USER="root"
206+# default pass
207+PASSWORD=""
208+SOCKET=""
209+HOST=""
210+PORT=""
211+STATUS_THP_SYSTEM=0
212+STATUS_THP_MYCNF=0
213+STATUS_PLUGIN=0
214+ENABLE=0
215+DISABLE=0
216+MYCNF_LOCATION=
217+MYSQLD_SAFE_STATUS=0
218+
219+# Check if we have a functional getopt(1)
220+if ! getopt --test
221+ then
222+ go_out="$(getopt --options=u:p::S:h:P:ed \
223+ --longoptions=user:,password::,socket:,host:,port:,enable,disable,help \
224+ --name="$(basename "$0")" -- "$@")"
225+ test $? -eq 0 || exit 1
226+ eval set -- $go_out
227+fi
228+
229+for arg
230+do
231+ case "$arg" in
232+ -- ) shift; break;;
233+ -u | --user )
234+ USER="$2"
235+ shift 2
236+ ;;
237+ -p | --password )
238+ case "$2" in
239+ "")
240+ read -s -p "Enter password:" INPUT_PASS
241+ if [ -z "$INPUT_PASS" ]; then
242+ PASSWORD=""
243+ printf "\nContinuing without password...\n";
244+ else
245+ PASSWORD="-p$INPUT_PASS"
246+ fi
247+ printf "\n\n"
248+ ;;
249+ *)
250+ PASSWORD="-p$2"
251+ ;;
252+ esac
253+ shift 2
254+ ;;
255+ -S | --socket )
256+ SOCKET="-S $2"
257+ shift 2
258+ ;;
259+ -h | --host )
260+ HOST="-h $2"
261+ shift 2
262+ ;;
263+ -P | --port )
264+ PORT="-P $2"
265+ shift 2
266+ ;;
267+ -e | --enable )
268+ shift
269+ ENABLE=1
270+ ;;
271+ -d | --disable )
272+ shift
273+ DISABLE=1
274+ ;;
275+ --help )
276+ printf "This script is used for installing and uninstalling TokuDB plugin for Percona Server 5.6.\n"
277+ printf "If transparent huge pages are enabled on the system it adds thp-setting=never option to my.cnf\n"
278+ printf "to disable it on runtime.\n\n"
279+ printf "Valid options are:\n"
280+ printf " --user=user_name, -u user_name\t mysql admin username\n"
281+ printf " --password[=password], -p[password]\t mysql admin password (on empty will prompt to enter)\n"
282+ printf " --socket=path, -S path\t\t the socket file to use for connection\n"
283+ printf " --host=host_name, -h host_name\t connect to given host\n"
284+ printf " --port=port_num, -P port_num\t\t port number to use for connection\n"
285+ printf " --enable, -e\t\t\t\t enable TokuDB plugin and disable transparent huge pages in my.cnf\n"
286+ printf " --disable, d\t\t\t\t disable TokuDB plugin and remove thp-setting=never option in my.cnf\n"
287+ printf " --help\t\t\t\t show this help\n\n"
288+ printf "For TokuDB requirements and manual steps for installation please visit this webpage:\n"
289+ printf "http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_installation.html\n\n"
290+ exit 0
291+ ;;
292+ esac
293+done
294+
295+# Make sure only root can run this script
296+if [ $(id -u) -ne 0 ]; then
297+ echo "This script must be run as root!" 1>&2
298+ exit 1
299+fi
300+
301+if [ $ENABLE = 1 -a $DISABLE = 1 ]; then
302+ printf "Only --enable OR --disable can be specified - not both!\n"
303+ exit 1
304+elif [ $ENABLE = 0 -a $DISABLE = 0 ]; then
305+ printf "You should specify --enable or --disable option. Use --help for printing options.\n"
306+ exit 1
307+fi
308+
309+# Check if server is running with jemalloc - if not warn that restart is needed
310+printf "Checking if Percona server is running with jemalloc enabled...\n"
311+PID_LOCATION=$(mysql -e "show variables like 'pid_file';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null|grep pid_file|awk '{print $2}')
312+if [ $? -ne 0 ] || [ "${PID_LOCATION}" == "" ]; then
313+ printf ">> Error checking pid file location! Please check username, password and other options...\n";
314+ exit 1
315+fi
316+PID_NUM=$(cat ${PID_LOCATION})
317+JEMALLOC_STATUS=$(grep -c jemalloc /proc/${PID_NUM}/environ)
318+if [ $JEMALLOC_STATUS = 0 ]; then
319+ printf ">> Percona server is not running with jemalloc, please restart server to enable it and then run this script...\n\n";
320+ exit 1
321+else
322+ printf ">> Percona server is running with jemalloc enabled.\n\n";
323+fi
324+
325+# Check transparent huge pages status on the system
326+printf "Checking transparent huge pages status on the system...\n"
327+if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]; then
328+ CONTENT_TRANSHP=$(</sys/kernel/mm/transparent_hugepage/enabled)
329+ STATUS_THP_SYSTEM=$(echo $CONTENT_TRANSHP | grep -cv '\[never\]')
330+fi
331+if [ $STATUS_THP_SYSTEM = 0 ]; then
332+ printf ">> Transparent huge pages are currently disabled on the system.\n\n"
333+else
334+ printf ">> Transparent huge pages are enabled (should be disabled).\n\n"
335+fi
336+
337+# Check thp-setting=never option in my.cnf
338+printf "Checking if thp-setting=never option is already set in config file...\n"
339+STATUS_THP_MYCNF=$(my_print_defaults server mysqld mysqld_safe|grep -c thp-setting=never)
340+if [ $STATUS_THP_MYCNF = 0 ]; then
341+ printf ">> Option thp-setting=never is not set in the config file.\n"
342+ printf ">> (needed only if THP is not disabled permanently on the system)\n\n"
343+else
344+ printf ">> Option thp-setting=never is set in the config file.\n\n"
345+fi
346+
347+# Check location of my.cnf
348+if [ -f /etc/my.cnf ]; then
349+ MYCNF_LOCATION=/etc/my.cnf
350+elif [ -f /etc/mysql/my.cnf ]; then
351+ MYCNF_LOCATION=/etc/mysql/my.cnf
352+elif [ -f /usr/etc/my.cnf ]; then
353+ MYCNF_LOCATION=/usr/etc/my.cnf
354+else
355+ if [ -d /etc/mysql ]; then
356+ MYCNF_LOCATION=/etc/mysql/my.cnf
357+ else
358+ MYCNF_LOCATION=/etc/my.cnf
359+ fi
360+ echo -n "" >> ${MYCNF_LOCATION}
361+fi
362+
363+# Check TokuDB plugin status
364+printf "Checking TokuDB plugin status...\n"
365+LIST_ENGINE=$(mysql -e "show plugins;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null)
366+if [ $? -ne 0 ]; then
367+ printf ">> Error checking TokuDB plugin status! Please check username, password and other options...\n";
368+ exit 1
369+fi
370+STATUS_PLUGIN=$(echo "$LIST_ENGINE" | grep -c "TokuDB")
371+if [ $STATUS_PLUGIN = 0 ]; then
372+ printf ">> TokuDB plugin is not installed.\n\n"
373+elif [ $STATUS_PLUGIN = 7 ]; then
374+ printf ">> TokuDB plugin is installed.\n\n"
375+ exit 0
376+else
377+ printf ">> TokuDB plugin is partially installed. Please cleanup manually.\n\n"
378+ exit 1
379+fi
380+
381+# Disable transparent huge pages in the current session so
382+# that the plugin can be installed without restarting PS
383+if [ $ENABLE = 1 -a $STATUS_THP_SYSTEM = 1 ]; then
384+ printf "Disabling transparent huge pages for the current session...\n"
385+ if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
386+ echo never > /sys/kernel/mm/transparent_hugepage/defrag
387+ fi
388+ if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
389+ echo never > /sys/kernel/mm/transparent_hugepage/enabled
390+ fi
391+ if [ $? -eq 0 ]; then
392+ printf ">> Successfuly disabled transparent huge pages for this session.\n\n"
393+ else
394+ printf ">> Error disabling transparent huge pages for this session.\n\n"
395+ exit 1
396+ fi
397+fi
398+
399+# Add option to disable transparent huge pages into my.cnf
400+if [ $ENABLE = 1 -a $STATUS_THP_MYCNF = 0 ]; then
401+ printf "Adding thp-setting=never option into $MYCNF_LOCATION\n"
402+ MYSQLD_SAFE_STATUS=$(grep -c "^\[mysqld_safe\]$" $MYCNF_LOCATION)
403+ if [ $MYSQLD_SAFE_STATUS = 0 ]; then
404+ echo -e "\n[mysqld_safe]\nthp-setting=never" >> $MYCNF_LOCATION
405+ else
406+ sed -i '/^\[mysqld_safe\]$/a thp-setting=never' $MYCNF_LOCATION
407+ fi
408+ if [ $? -eq 0 ]; then
409+ printf ">> Successfuly added thp-setting=never option into $MYCNF_LOCATION\n\n";
410+ else
411+ printf ">> Error adding thp-setting=never option into $MYCNF_LOCATION\n\n";
412+ exit 1
413+ fi
414+fi
415+
416+# Remove option for disabling transparent huge pages from my.cnf
417+if [ $DISABLE = 1 -a $STATUS_THP_MYCNF = 1 ]; then
418+ printf "Removing thp-setting=never option from $MYCNF_LOCATION\n"
419+ sed -i '/^thp-setting=never$/d' $MYCNF_LOCATION
420+ if [ $? -eq 0 ]; then
421+ printf ">> Successfuly removed thp-setting=never option from $MYCNF_LOCATION\n\n";
422+ else
423+ printf ">> Error removing thp-setting=never option from $MYCNF_LOCATION\n\n";
424+ exit 1
425+ fi
426+fi
427+
428+# Installing TokuDB plugin
429+if [ $ENABLE = 1 -a $STATUS_PLUGIN = 0 ]; then
430+ printf "Installing TokuDB engine...\n"
431+ mysql -e "INSTALL PLUGIN tokudb SONAME 'ha_tokudb.so';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
432+ mysql -e "INSTALL PLUGIN tokudb_file_map SONAME 'ha_tokudb.so';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
433+ mysql -e "INSTALL PLUGIN tokudb_fractal_tree_info SONAME 'ha_tokudb.so';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
434+ mysql -e "INSTALL PLUGIN tokudb_fractal_tree_block_map SONAME 'ha_tokudb.so';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
435+ mysql -e "INSTALL PLUGIN tokudb_trx SONAME 'ha_tokudb.so';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
436+ mysql -e "INSTALL PLUGIN tokudb_locks SONAME 'ha_tokudb.so';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
437+ mysql -e "INSTALL PLUGIN tokudb_lock_waits SONAME 'ha_tokudb.so';" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null
438+ if [ $? -eq 0 ]; then
439+ printf ">> Successfuly installed TokuDB plugin.\n\n"
440+ else
441+ printf ">> Error installing TokuDB plugin. Please check error log.\n\n"
442+ exit 1
443+ fi
444+fi
445+
446+# Uninstalling TokuDB plugin
447+if [ $DISABLE = 1 -a $STATUS_PLUGIN = 7 ]; then
448+ printf "Uninstalling TokuDB plugin...\n"
449+ mysql -e "UNINSTALL PLUGIN tokudb;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
450+ mysql -e "UNINSTALL PLUGIN tokudb_file_map;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
451+ mysql -e "UNINSTALL PLUGIN tokudb_fractal_tree_info;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
452+ mysql -e "UNINSTALL PLUGIN tokudb_fractal_tree_block_map;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
453+ mysql -e "UNINSTALL PLUGIN tokudb_trx;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
454+ mysql -e "UNINSTALL PLUGIN tokudb_locks;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null &&
455+ mysql -e "UNINSTALL PLUGIN tokudb_lock_waits;" -u $USER $PASSWORD $SOCKET $HOST $PORT 2>/dev/null
456+ if [ $? -eq 0 ]; then
457+ printf ">> Successfuly uninstalled TokuDB plugin.\n\n"
458+ else
459+ printf ">> Error uninstalling TokuDB plugin. Please check error log.\n\n"
460+ exit 1
461+ fi
462+fi

Subscribers

People subscribed via source and target branches