1
# name : sql_no_fcache.patch
6
# Any small change to this file in the main branch
7
# should be done or reviewed by the maintainer!
8
diff -ruN a/client/mysqldump.c b/client/mysqldump.c
9
--- a/client/mysqldump.c 2010-07-28 16:47:58.264067653 +0400
10
+++ b/client/mysqldump.c 2010-07-28 16:47:59.604985656 +0400
13
static uint opt_protocol= 0;
15
+static my_bool server_supports_sql_no_fcache= FALSE;
18
Dynamic_string wrapper functions. In this file use these
19
wrappers, they will terminate the process if there is
20
@@ -1471,6 +1473,17 @@
21
/* Don't switch charsets for 4.1 and earlier. (bug#34192). */
22
server_supports_switching_charsets= FALSE;
25
+ /* Check to see if we support SQL_NO_FCACHE on this server. */
26
+ if (mysql_query(mysql, "SELECT SQL_NO_FCACHE NOW()") == 0)
28
+ MYSQL_RES *res = mysql_store_result(mysql);
31
+ mysql_free_result(res);
33
+ server_supports_sql_no_fcache= TRUE;
36
As we're going to set SQL_MODE, it would be lost on reconnect, so we
38
@@ -3143,7 +3156,12 @@
40
/* now build the query string */
42
- dynstr_append_checked(&query_string, "SELECT /*!40001 SQL_NO_CACHE */ * INTO OUTFILE '");
43
+ dynstr_append_checked(&query_string, "SELECT /*!40001 SQL_NO_CACHE */ ");
44
+ if (server_supports_sql_no_fcache)
46
+ dynstr_append_checked(&query_string, "/*!50084 SQL_NO_FCACHE */ ");
48
+ dynstr_append_checked(&query_string, "* INTO OUTFILE '");
49
dynstr_append_checked(&query_string, filename);
50
dynstr_append_checked(&query_string, "'");
52
@@ -3193,7 +3211,12 @@
53
check_io(md_result_file);
56
- dynstr_append_checked(&query_string, "SELECT /*!40001 SQL_NO_CACHE */ * FROM ");
57
+ dynstr_append_checked(&query_string, "SELECT /*!40001 SQL_NO_CACHE */ ");
58
+ if (server_supports_sql_no_fcache)
60
+ dynstr_append_checked(&query_string, "/*!50084 SQL_NO_FCACHE */ ");
62
+ dynstr_append_checked(&query_string, "* FROM ");
63
dynstr_append_checked(&query_string, result_table);
66
diff -ruN a/include/flashcache_ioctl.h b/include/flashcache_ioctl.h
67
--- a/include/flashcache_ioctl.h 1970-01-01 03:00:00.000000000 +0300
68
+++ b/include/flashcache_ioctl.h 2010-07-28 16:47:59.744079911 +0400
70
+/****************************************************************************
71
+ * flashcache_ioctl.h
72
+ * FlashCache: Device mapper target for block-level disk caching
74
+ * Copyright 2010 Facebook, Inc.
75
+ * Author: Mohan Srinivasan (mohan@facebook.com)
77
+ * Based on DM-Cache:
78
+ * Copyright (C) International Business Machines Corp., 2006
79
+ * Author: Ming Zhao (mingzhao@ufl.edu)
81
+ * This program is free software; you can redistribute it and/or modify
82
+ * it under the terms of the GNU General Public License as published by
83
+ * the Free Software Foundation; under version 2 of the License.
85
+ * This program is distributed in the hope that it will be useful,
86
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
87
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
88
+ * GNU General Public License for more details.
90
+ * You should have received a copy of the GNU General Public License
91
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
92
+ ****************************************************************************/
94
+#ifndef FLASHCACHE_IOCTL_H
95
+#define FLASHCACHE_IOCTL_H
97
+#include <linux/types.h>
99
+#define FLASHCACHE_IOCTL 0xfe
102
+ FLASHCACHEADDNCPID_CMD=200,
103
+ FLASHCACHEDELNCPID_CMD,
104
+ FLASHCACHEDELNCALL_CMD,
105
+ FLASHCACHEADDWHITELIST_CMD,
106
+ FLASHCACHEDELWHITELIST_CMD,
107
+ FLASHCACHEDELWHITELISTALL_CMD,
110
+#define FLASHCACHEADDNCPID _IOW(FLASHCACHE_IOCTL, FLASHCACHEADDNCPID_CMD, pid_t)
111
+#define FLASHCACHEDELNCPID _IOW(FLASHCACHE_IOCTL, FLASHCACHEDELNCPID_CMD, pid_t)
112
+#define FLASHCACHEDELNCALL _IOW(FLASHCACHE_IOCTL, FLASHCACHEDELNCALL_CMD, pid_t)
114
+#define FLASHCACHEADDBLACKLIST FLASHCACHEADDNCPID
115
+#define FLASHCACHEDELBLACKLIST FLASHCACHEDELNCPID
116
+#define FLASHCACHEDELALLBLACKLIST FLASHCACHEDELNCALL
118
+#define FLASHCACHEADDWHITELIST _IOW(FLASHCACHE_IOCTL, FLASHCACHEADDWHITELIST_CMD, pid_t)
119
+#define FLASHCACHEDELWHITELIST _IOW(FLASHCACHE_IOCTL, FLASHCACHEDELWHITELIST_CMD, pid_t)
120
+#define FLASHCACHEDELALLWHITELIST _IOW(FLASHCACHE_IOCTL, FLASHCACHEDELWHITELISTALL_CMD, pid_t)
123
diff -ruN a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result
124
--- a/mysql-test/r/mysqldump.result 2010-07-28 16:47:58.334083833 +0400
125
+++ b/mysql-test/r/mysqldump.result 2010-07-28 16:48:14.805318437 +0400
126
@@ -1832,7 +1832,7 @@
127
# Bug#21288 mysqldump segmentation fault when using --where
129
create table t1 (a int);
130
-mysqldump: Couldn't execute 'SELECT /*!40001 SQL_NO_CACHE */ * FROM `t1` WHERE xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx': You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' at line 1 (1064)
131
+mysqldump: Couldn't execute 'SELECT /*!40001 SQL_NO_CACHE */ /*!50084 SQL_NO_FCACHE */ * FROM `t1` WHERE xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx': You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' at line 1 (1064)
132
mysqldump: Got error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' at line 1 when retrieving data from server
134
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
135
diff -ruN a/patch_info/sql_no_fcache.info b/patch_info/sql_no_fcache.info
136
--- a/patch_info/sql_no_fcache.info 1970-01-01 03:00:00.000000000 +0300
137
+++ b/patch_info/sql_no_fcache.info 2010-07-28 16:47:59.915439165 +0400
139
+File=sql_no_fcache.patch
140
+Name=Support for flashcache including the SQL_NO_FCACHE option that prevents blocks from being cached during a query.
145
diff -ruN a/sql/lex.h b/sql/lex.h
146
--- a/sql/lex.h 2010-07-28 16:47:58.575318748 +0400
147
+++ b/sql/lex.h 2010-07-28 16:48:00.134078469 +0400
149
{ "SQL_CACHE", SYM(SQL_CACHE_SYM)},
150
{ "SQL_CALC_FOUND_ROWS", SYM(SQL_CALC_FOUND_ROWS)},
151
{ "SQL_NO_CACHE", SYM(SQL_NO_CACHE_SYM)},
152
+ { "SQL_NO_FCACHE", SYM(SQL_NO_FCACHE_SYM)},
153
{ "SQL_SMALL_RESULT", SYM(SQL_SMALL_RESULT)},
154
{ "SQL_THREAD", SYM(SQL_THREAD)},
155
{ "SQL_TSI_SECOND", SYM(SECOND_SYM)},
156
diff -ruN a/sql/mysqld.h b/sql/mysqld.h
157
--- a/sql/mysqld.h 2010-07-28 16:47:58.565318871 +0400
158
+++ b/sql/mysqld.h 2010-07-28 16:48:03.004544367 +0400
160
extern ulong back_log;
161
extern char language[FN_REFLEN];
162
extern ulong server_id, concurrency;
164
+extern int cachedev_fd;
165
extern time_t server_start_time, flush_status_time;
166
extern char *opt_mysql_tmpdir, mysql_charsets_dir[];
167
extern int mysql_unpacked_real_data_home_len;
168
diff -ruN a/sql/mysqld.cc b/sql/mysqld.cc
169
--- a/sql/mysqld.cc 2010-07-28 16:47:58.565318871 +0400
170
+++ b/sql/mysqld.cc 2010-07-28 16:48:03.004544367 +0400
172
#ifdef HAVE_SYS_PRCTL_H
173
#include <sys/prctl.h>
175
+#if defined(__linux__)
177
+#include <sys/statfs.h>
178
+#include "flashcache_ioctl.h"
181
#include <thr_alarm.h>
182
#include <ft_global.h>
185
ulong binlog_cache_use= 0, binlog_cache_disk_use= 0;
186
ulong max_connections, max_connect_errors;
190
+my_bool cachedev_enabled= FALSE;
193
Limit of the total number of prepared statements in the server.
194
Is necessary to protect the server against out-of-memory attacks.
195
@@ -4176,6 +4186,97 @@
196
#define decrement_handler_count()
197
#endif /* defined(_WIN32) || defined(HAVE_SMEM) */
199
+#if defined(__linux__)
201
+ * Auto detect if we support flash cache on the host system.
202
+ * This needs to be called before we setuid away from root
203
+ * to avoid permission problems on opening the device node.
205
+static void init_cachedev(void)
207
+ struct statfs stfs_data_home_dir;
208
+ struct statfs stfs;
209
+ struct mntent *ent;
210
+ pid_t pid = getpid();
212
+ char *error_message= NULL;
214
+ // disabled by default
216
+ cachedev_enabled= FALSE;
218
+ if (!mysql_data_home)
220
+ error_message= "mysql_data_home not set";
224
+ if (statfs(mysql_data_home, &stfs_data_home_dir) < 0)
226
+ error_message= "statfs failed";
230
+ mounts = setmntent("/etc/mtab", "r");
231
+ if (mounts == NULL)
233
+ error_message= "setmntent failed";
237
+ while ((ent = getmntent(mounts)) != NULL)
239
+ if (statfs(ent->mnt_dir, &stfs) < 0)
241
+ if (memcmp(&stfs.f_fsid, &stfs_data_home_dir.f_fsid, sizeof(fsid_t)) == 0)
248
+ error_message= "getmntent loop failed";
252
+ cachedev_fd = open(ent->mnt_fsname, O_RDONLY);
253
+ if (cachedev_fd < 0)
255
+ error_message= "open flash device failed";
259
+ /* cleanup previous whitelistings */
260
+ if (ioctl(cachedev_fd, FLASHCACHEDELALLWHITELIST, &pid) < 0)
262
+ close(cachedev_fd);
264
+ error_message= "ioctl failed";
266
+ ioctl(cachedev_fd, FLASHCACHEADDWHITELIST, &pid);
270
+ sql_print_information("Flashcache bypass: %s",
271
+ (cachedev_fd > 0) ? "enabled" : "disabled");
273
+ sql_print_information("Flashcache setup error is : %s\n", error_message);
275
+ cachedev_enabled= TRUE;
279
+static void cleanup_cachedev(void)
281
+ pid_t pid = getpid();
283
+ if (cachedev_enabled) {
284
+ ioctl(cachedev_fd, FLASHCACHEDELWHITELIST, &pid);
285
+ close(cachedev_fd);
291
#ifndef EMBEDDED_LIBRARY
293
@@ -4430,6 +4531,10 @@
297
+#if defined(__linux__)
302
We have enough space for fiddling with the argv, continue
304
@@ -4633,6 +4738,10 @@
308
+#if defined(__linux__)
309
+ cleanup_cachedev();
315
@@ -6446,6 +6555,7 @@
316
{"Delayed_errors", (char*) &delayed_insert_errors, SHOW_LONG},
317
{"Delayed_insert_threads", (char*) &delayed_insert_threads, SHOW_LONG_NOFLUSH},
318
{"Delayed_writes", (char*) &delayed_insert_writes, SHOW_LONG},
319
+ {"Flashcache_enabled", (char*) &cachedev_enabled, SHOW_BOOL },
320
{"Flush_commands", (char*) &refresh_version, SHOW_LONG_NOFLUSH},
321
{"Handler_commit", (char*) offsetof(STATUS_VAR, ha_commit_count), SHOW_LONG_STATUS},
322
{"Handler_delete", (char*) offsetof(STATUS_VAR, ha_delete_count), SHOW_LONG_STATUS},
323
diff -ruN a/sql/sql_lex.cc b/sql/sql_lex.cc
324
--- a/sql/sql_lex.cc 2010-07-28 16:47:58.555318714 +0400
325
+++ b/sql/sql_lex.cc 2010-07-28 16:48:07.794069239 +0400
328
lex->subqueries= FALSE;
329
lex->view_prepare_mode= FALSE;
330
+ lex->disable_flashcache= FALSE;
331
lex->derived_tables= 0;
332
lex->safe_to_cache_query= 1;
333
lex->leaf_tables_insert= 0;
334
diff -ruN a/sql/sql_lex.h b/sql/sql_lex.h
335
--- a/sql/sql_lex.h 2010-07-28 16:47:58.575318748 +0400
336
+++ b/sql/sql_lex.h 2010-07-28 16:48:08.405691834 +0400
337
@@ -2297,6 +2297,7 @@
339
bool view_prepare_mode;
340
bool safe_to_cache_query;
341
+ bool disable_flashcache;
342
bool subqueries, ignore;
343
st_parsing_options parsing_options;
344
Alter_info alter_info;
345
diff -ruN a/sql/sql_select.cc b/sql/sql_select.cc
346
--- a/sql/sql_select.cc 2010-07-28 16:47:58.555318714 +0400
347
+++ b/sql/sql_select.cc 2010-07-28 16:48:13.414069437 +0400
350
#define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1))
352
+#include <sys/syscall.h>
353
+#include <sys/ioctl.h>
354
+#if defined(__linux__)
355
+#include "flashcache_ioctl.h"
358
const char *join_type_str[]={ "UNKNOWN","system","const","eq_ref","ref",
359
"MAYBE_REF","ALL","range","index","fulltext",
360
"ref_or_null","unique_subquery","index_subquery",
362
ulong setup_tables_done_option)
366
register SELECT_LEX *select_lex = &lex->select_lex;
367
DBUG_ENTER("handle_select");
368
+#if defined(__linux__)
369
+ if(lex->disable_flashcache && cachedev_fd > 0)
371
+ pid = syscall(SYS_gettid);
372
+ ioctl(cachedev_fd, FLASHCACHEADDNCPID, &pid);
376
MYSQL_SELECT_START(thd->query());
378
if (select_lex->master_unit()->is_union() ||
381
result->abort_result_set();
383
+#if defined(__linux__)
384
+ if (lex->disable_flashcache && cachedev_fd > 0)
386
+ ioctl(cachedev_fd, FLASHCACHEDELNCPID, &pid);
389
MYSQL_SELECT_DONE((int) res, (ulong) thd->limit_found_rows);
392
diff -ruN a/sql/sql_yacc.yy b/sql/sql_yacc.yy
393
--- a/sql/sql_yacc.yy 2010-07-28 16:47:58.565318871 +0400
394
+++ b/sql/sql_yacc.yy 2010-07-28 16:48:14.205317990 +0400
395
@@ -1284,6 +1284,7 @@
397
%token SQL_CALC_FOUND_ROWS
398
%token SQL_NO_CACHE_SYM
399
+%token SQL_NO_FCACHE_SYM
400
%token SQL_SMALL_RESULT
401
%token SQL_SYM /* SQL-2003-R */
403
@@ -7350,6 +7351,10 @@
404
Lex->select_lex.sql_cache= SELECT_LEX::SQL_NO_CACHE;
407
+ | SQL_NO_FCACHE_SYM
409
+ Lex->disable_flashcache= TRUE;