Merge lp:~akopytov/percona-xtrabackup/bug1183793-2.1 into lp:percona-xtrabackup/2.1

Proposed by Alexey Kopytov
Status: Merged
Approved by: Sergei Glushchenko
Approved revision: 738
Merged at revision: 738
Proposed branch: lp:~akopytov/percona-xtrabackup/bug1183793-2.1
Merge into: lp:percona-xtrabackup/2.1
Diff against target: 138 lines (+87/-1)
2 files modified
src/xtrabackup.cc (+73/-1)
test/t/bug1183793.sh (+14/-0)
To merge this branch: bzr merge lp:~akopytov/percona-xtrabackup/bug1183793-2.1
Reviewer Review Type Date Requested Status
Sergei Glushchenko (community) g2 Approve
Review via email: mp+217459@code.launchpad.net

Description of the change

    Bug #1183794: XtraBackup should raise the open files limit if possible

    The xtrabackup binaries now recognizes a new my.cnf option,
    open_files_limit. The effect is the same as for the server: it changes
    the maximum number of file descriptors available to the xtrabackup
    process. The actual limit depends on the platform and ulimit settings.

http://jenkins.percona.com/view/PXB%202.1/job/percona-xtrabackup-2.1-param/559/

To post a comment you must log in.
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :

Are lines

88 + rlimit.rlim_cur = 0; /* Safety if next call fails */
89 +
90 + (void) getrlimit(RLIMIT_NOFILE, &rlimit);
91 +
92 + if (rlimit.rlim_cur) {

work different from

nn + if (!getrlimit(RLIMIT_NOFILE, &rlimit)) {

man page suggest to use return value for error handling and says nothing about using rlim_cur for this purpose.

review: Needs Information (g2)
Revision history for this message
Alexey Kopytov (akopytov) wrote :

I think the logic there is: "if setrlimit() succeeds, check what limit has actually been set". That code doesn't expect getrlimit() call to fail (since the same call succeeded previously), but assumes the actually set limit may be different from what was requested. In which case it returns the actual limit instead.

Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :

Yes, I understand that logic and it normally can be achieved without zeroing rlimit.rlim_cur.
But since it work for server code should also work for XtraBackup.

review: Approve (g2)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/xtrabackup.cc'
2--- src/xtrabackup.cc 2014-02-24 20:21:05 +0000
3+++ src/xtrabackup.cc 2014-04-28 14:43:27 +0000
4@@ -63,6 +63,8 @@
5 # include <sys/prctl.h>
6 #endif
7
8+#include <sys/resource.h>
9+
10 #define G_PTR uchar*
11
12 #include "common.h"
13@@ -292,6 +294,8 @@
14 /* The maximum LSN of found archived log files */
15 lsn_t xtrabackup_arch_last_file_lsn = 0ULL;
16
17+ulong xb_open_files_limit= 0;
18+
19 /* Datasinks */
20 ds_ctxt_t *ds_data = NULL;
21 ds_ctxt_t *ds_meta = NULL;
22@@ -478,7 +482,8 @@
23 OPT_INNODB_LOG_CHECKSUM_ALGORITHM,
24 #endif
25 OPT_XTRA_INCREMENTAL_FORCE_SCAN,
26- OPT_DEFAULTS_GROUP
27+ OPT_DEFAULTS_GROUP,
28+ OPT_OPEN_FILES_LIMIT
29 };
30
31 #if MYSQL_VERSION_ID >= 50600
32@@ -896,6 +901,12 @@
33 {"defaults_group", OPT_DEFAULTS_GROUP, "defaults group in config file (default \"mysqld\").",
34 (G_PTR*) &defaults_group, (G_PTR*) &defaults_group,
35 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
36+
37+ {"open_files_limit", OPT_OPEN_FILES_LIMIT, "the maximum number of file "
38+ "descriptors to reserve with setrlimit().",
39+ (G_PTR*) &xb_open_files_limit, (G_PTR*) &xb_open_files_limit, 0, GET_ULONG,
40+ REQUIRED_ARG, 0, 0, UINT_MAX, 0, 1, 0},
41+
42 { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
43 };
44
45@@ -2949,6 +2960,63 @@
46 }
47 }
48
49+/***********************************************************************
50+Set the open files limit. Based on set_max_open_files().
51+
52+@return the resulting open files limit. May be less or more than the requested
53+value. */
54+static uint
55+xb_set_max_open_files(
56+/*==================*/
57+ uint max_file_limit) /*!<in: open files limit */
58+{
59+#if defined(RLIMIT_NOFILE)
60+ struct rlimit rlimit;
61+ uint old_cur;
62+
63+ if (getrlimit(RLIMIT_NOFILE, &rlimit)) {
64+
65+ goto end;
66+ }
67+
68+ old_cur = (uint) rlimit.rlim_cur;
69+
70+ if (rlimit.rlim_cur == RLIM_INFINITY) {
71+
72+ rlimit.rlim_cur = max_file_limit;
73+ }
74+
75+ if (rlimit.rlim_cur >= max_file_limit) {
76+
77+ max_file_limit = rlimit.rlim_cur;
78+ goto end;
79+ }
80+
81+ rlimit.rlim_cur = rlimit.rlim_max = max_file_limit;
82+
83+ if (setrlimit(RLIMIT_NOFILE, &rlimit)) {
84+
85+ max_file_limit = old_cur; /* Use original value */
86+ } else {
87+
88+ rlimit.rlim_cur = 0; /* Safety if next call fails */
89+
90+ (void) getrlimit(RLIMIT_NOFILE, &rlimit);
91+
92+ if (rlimit.rlim_cur) {
93+
94+ /* If call didn't fail */
95+ max_file_limit = (uint) rlimit.rlim_cur;
96+ }
97+ }
98+
99+end:
100+ return(max_file_limit);
101+#else
102+ return(0);
103+#endif
104+}
105+
106 static void
107 xtrabackup_backup_func(void)
108 {
109@@ -2972,6 +3040,10 @@
110 }
111 msg("xtrabackup: cd to %s\n", mysql_real_data_home);
112
113+ msg("xtrabackup: open files limit requested %u, set to %u\n",
114+ (uint) xb_open_files_limit,
115+ xb_set_max_open_files(xb_open_files_limit));
116+
117 mysql_data_home= mysql_data_home_buff;
118 mysql_data_home[0]=FN_CURLIB; // all paths are relative from here
119 mysql_data_home[1]=0;
120
121=== added file 'test/t/bug1183793.sh'
122--- test/t/bug1183793.sh 1970-01-01 00:00:00 +0000
123+++ test/t/bug1183793.sh 2014-04-28 14:43:27 +0000
124@@ -0,0 +1,14 @@
125+########################################################################
126+# Bug #1183793: XtraBackup should raise the open files limit if possible
127+########################################################################
128+
129+MYSQLD_EXTRA_MY_CNF_OPTS="
130+open_files_limit=1234
131+"
132+
133+start_server
134+
135+innobackupex --no-timestamp $topdir/backup
136+
137+grep -q 'open files limit requested 1234' $OUTFILE \
138+ || die "Could not set the open files limit"

Subscribers

People subscribed via source and target branches

to all changes: