]> git.pld-linux.org Git - packages/mysql.git/blob - mysql-sql_no_fcache.patch
remove id expansion
[packages/mysql.git] / mysql-sql_no_fcache.patch
1 # name       : sql_no_fcache.patch
2 # introduced : 12
3 # maintainer : Oleg
4 #
5 #!!! notice !!!
6 # Any small change to this file in the main branch
7 # should be done or reviewed by the maintainer!
8 --- a/client/mysqldump.c
9 +++ b/client/mysqldump.c
10 @@ -136,6 +136,8 @@
11  #endif
12  static uint opt_protocol= 0;
13  
14 +static my_bool server_supports_sql_no_fcache= FALSE;
15 +
16  /*
17  Dynamic_string wrapper functions. In this file use these
18  wrappers, they will terminate the process if there is
19 @@ -1521,6 +1523,17 @@
20      /* Don't switch charsets for 4.1 and earlier.  (bug#34192). */
21      server_supports_switching_charsets= FALSE;
22    } 
23 +  
24 +  /* Check to see if we support SQL_NO_FCACHE on this server. */ 
25 +  if (mysql_query(mysql, "SELECT SQL_NO_FCACHE NOW()") == 0)
26 +  {
27 +    MYSQL_RES *res = mysql_store_result(mysql);
28 +    if (res)
29 +    {
30 +      mysql_free_result(res);
31 +    }
32 +    server_supports_sql_no_fcache= TRUE;
33 +  }
34    /*
35      As we're going to set SQL_MODE, it would be lost on reconnect, so we
36      cannot reconnect.
37 @@ -3184,7 +3197,12 @@
38  
39      /* now build the query string */
40  
41 -    dynstr_append_checked(&query_string, "SELECT /*!40001 SQL_NO_CACHE */ * INTO OUTFILE '");
42 +    dynstr_append_checked(&query_string, "SELECT /*!40001 SQL_NO_CACHE */ ");
43 +    if (server_supports_sql_no_fcache)
44 +    {
45 +      dynstr_append_checked(&query_string, "/*!50084 SQL_NO_FCACHE */ ");
46 +    }
47 +    dynstr_append_checked(&query_string, "* INTO OUTFILE '");
48      dynstr_append_checked(&query_string, filename);
49      dynstr_append_checked(&query_string, "'");
50  
51 @@ -3234,7 +3252,12 @@
52        check_io(md_result_file);
53      }
54      
55 -    dynstr_append_checked(&query_string, "SELECT /*!40001 SQL_NO_CACHE */ * FROM ");
56 +    dynstr_append_checked(&query_string, "SELECT /*!40001 SQL_NO_CACHE */ ");
57 +    if (server_supports_sql_no_fcache)
58 +    {
59 +      dynstr_append_checked(&query_string, "/*!50084 SQL_NO_FCACHE */ ");
60 +    }
61 +    dynstr_append_checked(&query_string, "* FROM ");
62      dynstr_append_checked(&query_string, result_table);
63  
64      if (where)
65 --- /dev/null
66 +++ b/include/flashcache_ioctl.h
67 @@ -0,0 +1,53 @@
68 +/****************************************************************************
69 + *  flashcache_ioctl.h
70 + *  FlashCache: Device mapper target for block-level disk caching
71 + *
72 + *  Copyright 2010 Facebook, Inc.
73 + *  Author: Mohan Srinivasan (mohan@facebook.com)
74 + *
75 + *  Based on DM-Cache:
76 + *   Copyright (C) International Business Machines Corp., 2006
77 + *   Author: Ming Zhao (mingzhao@ufl.edu)
78 + *
79 + *  This program is free software; you can redistribute it and/or modify
80 + *  it under the terms of the GNU General Public License as published by
81 + *  the Free Software Foundation; under version 2 of the License.
82 + *
83 + *  This program is distributed in the hope that it will be useful,
84 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
85 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
86 + *  GNU General Public License for more details.
87 + *
88 + * You should have received a copy of the GNU General Public License
89 + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
90 + ****************************************************************************/
91 +
92 +#ifndef FLASHCACHE_IOCTL_H
93 +#define FLASHCACHE_IOCTL_H
94 +
95 +#include <linux/types.h>
96 +
97 +#define FLASHCACHE_IOCTL 0xfe
98 +
99 +enum {
100 +       FLASHCACHEADDNCPID_CMD=200,
101 +       FLASHCACHEDELNCPID_CMD,
102 +       FLASHCACHEDELNCALL_CMD,
103 +       FLASHCACHEADDWHITELIST_CMD,
104 +       FLASHCACHEDELWHITELIST_CMD,
105 +       FLASHCACHEDELWHITELISTALL_CMD,
106 +};
107 +
108 +#define FLASHCACHEADDNCPID     _IOW(FLASHCACHE_IOCTL, FLASHCACHEADDNCPID_CMD, pid_t)
109 +#define FLASHCACHEDELNCPID     _IOW(FLASHCACHE_IOCTL, FLASHCACHEDELNCPID_CMD, pid_t)
110 +#define FLASHCACHEDELNCALL     _IOW(FLASHCACHE_IOCTL, FLASHCACHEDELNCALL_CMD, pid_t)
111 +
112 +#define FLASHCACHEADDBLACKLIST         FLASHCACHEADDNCPID
113 +#define FLASHCACHEDELBLACKLIST         FLASHCACHEDELNCPID
114 +#define FLASHCACHEDELALLBLACKLIST      FLASHCACHEDELNCALL
115 +
116 +#define FLASHCACHEADDWHITELIST         _IOW(FLASHCACHE_IOCTL, FLASHCACHEADDWHITELIST_CMD, pid_t)
117 +#define FLASHCACHEDELWHITELIST         _IOW(FLASHCACHE_IOCTL, FLASHCACHEDELWHITELIST_CMD, pid_t)
118 +#define FLASHCACHEDELALLWHITELIST      _IOW(FLASHCACHE_IOCTL, FLASHCACHEDELWHITELISTALL_CMD, pid_t)
119 +
120 +#endif
121 --- a/mysql-test/r/mysqldump.result
122 +++ b/mysql-test/r/mysqldump.result
123 @@ -1832,7 +1832,7 @@
124  # Bug#21288 mysqldump segmentation fault when using --where
125  #
126  create table t1 (a int);
127 -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)
128 +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)
129  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
130  
131  /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
132 --- /dev/null
133 +++ b/patch_info/sql_no_fcache.info
134 @@ -0,0 +1,6 @@
135 +File=sql_no_fcache.patch
136 +Name=Support for flashcache including the SQL_NO_FCACHE option that prevents blocks from being cached during a query.
137 +Version=1.0
138 +Author=Facebook
139 +License=GPL
140 +Comment=
141 --- a/sql/lex.h
142 +++ b/sql/lex.h
143 @@ -503,6 +503,7 @@
144    { "SQL_CACHE",        SYM(SQL_CACHE_SYM)},
145    { "SQL_CALC_FOUND_ROWS", SYM(SQL_CALC_FOUND_ROWS)},
146    { "SQL_NO_CACHE",    SYM(SQL_NO_CACHE_SYM)},
147 +  { "SQL_NO_FCACHE",   SYM(SQL_NO_FCACHE_SYM)},
148    { "SQL_SMALL_RESULT", SYM(SQL_SMALL_RESULT)},
149    { "SQL_THREAD",      SYM(SQL_THREAD)},
150    { "SQL_TSI_FRAC_SECOND", SYM(FRAC_SECOND_SYM)},
151 --- a/sql/mysqld.cc
152 +++ b/sql/mysqld.cc
153 @@ -46,6 +46,11 @@
154  #define OPT_NDB_SHM_DEFAULT 0
155  #endif
156  #endif
157 +#if defined(__linux__)
158 +#include <mntent.h>
159 +#include <sys/statfs.h>
160 +#include "flashcache_ioctl.h"
161 +#endif//__linux__
162  
163  #ifndef DEFAULT_SKIP_THREAD_PRIORITY
164  #define DEFAULT_SKIP_THREAD_PRIORITY 0
165 @@ -608,6 +613,11 @@
166  ulong max_long_data_size;
167  uint  max_user_connections= 0;
168  ulonglong denied_connections = 0;
169 +
170 +/* flashcache */
171 +int cachedev_fd;
172 +my_bool cachedev_enabled= FALSE;
173 +
174  /**
175    Limit of the total number of prepared statements in the server.
176    Is necessary to protect the server against out-of-memory attacks.
177 @@ -4412,6 +4422,97 @@
178  }
179  #endif//DBUG_OFF
180  
181 +#if defined(__linux__)
182 +/*
183 + * Auto detect if we support flash cache on the host system.
184 + * This needs to be called before we setuid away from root
185 + * to avoid permission problems on opening the device node.
186 + */
187 +static void init_cachedev(void)
188 +{
189 +  struct statfs stfs_data_home_dir;
190 +  struct statfs stfs;
191 +  struct mntent *ent;
192 +  pid_t pid = getpid();
193 +  FILE *mounts;
194 +  const char *error_message= NULL;
195 +
196 +  // disabled by default
197 +  cachedev_fd = -1;
198 +  cachedev_enabled= FALSE;
199 +
200 +  if (!mysql_data_home)
201 +  {
202 +    error_message= "mysql_data_home not set";
203 +    goto epilogue;
204 +  }
205 +
206 +  if (statfs(mysql_data_home, &stfs_data_home_dir) < 0)
207 +  {
208 +    error_message= "statfs failed";
209 +    goto epilogue;
210 +  }
211 +
212 +  mounts = setmntent("/etc/mtab", "r");
213 +  if (mounts == NULL)
214 +  {
215 +    error_message= "setmntent failed";
216 +    goto epilogue;
217 +  }
218 +
219 +  while ((ent = getmntent(mounts)) != NULL)
220 +  {
221 +    if (statfs(ent->mnt_dir, &stfs) < 0)
222 +      continue;
223 +    if (memcmp(&stfs.f_fsid, &stfs_data_home_dir.f_fsid, sizeof(fsid_t)) == 0)
224 +      break;
225 +  }
226 +  endmntent(mounts);
227 +
228 +  if (ent == NULL)
229 +  {
230 +    error_message= "getmntent loop failed";
231 +    goto epilogue;
232 +  }
233 +
234 +  cachedev_fd = open(ent->mnt_fsname, O_RDONLY);
235 +  if (cachedev_fd < 0)
236 +  {
237 +    error_message= "open flash device failed";
238 +    goto epilogue;
239 +  }
240 +
241 +  /* cleanup previous whitelistings */
242 +  if (ioctl(cachedev_fd, FLASHCACHEDELALLWHITELIST, &pid) < 0)
243 +  {
244 +    close(cachedev_fd);
245 +    cachedev_fd = -1;
246 +    error_message= "ioctl failed";
247 +  } else {
248 +    ioctl(cachedev_fd, FLASHCACHEADDWHITELIST, &pid);
249 +  }
250 +
251 +epilogue:
252 +  sql_print_information("Flashcache bypass: %s",
253 +      (cachedev_fd > 0) ? "enabled" : "disabled");
254 +  if (error_message)
255 +    sql_print_information("Flashcache setup error is : %s\n", error_message);
256 +  else
257 +    cachedev_enabled= TRUE;
258 +
259 +}
260 +
261 +static void cleanup_cachedev(void)
262 +{
263 +  pid_t pid = getpid();
264 +
265 +  if (cachedev_enabled) {
266 +    ioctl(cachedev_fd, FLASHCACHEDELWHITELIST, &pid);
267 +    close(cachedev_fd);
268 +    cachedev_fd = -1;
269 +  }
270 +}
271 +#endif//__linux__
272  
273  #ifdef __WIN__
274  int win_main(int argc, char **argv)
275 @@ -4516,6 +4617,10 @@
276    test_lc_time_sz();
277  #endif
278  
279 +#if defined(__linux__)
280 +  init_cachedev();
281 +#endif//__linux__
282 +
283    /*
284      We have enough space for fiddling with the argv, continue
285    */
286 @@ -4717,6 +4822,10 @@
287    clean_up_mutexes();
288    my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
289  
290 +#if defined(__linux__)
291 +  cleanup_cachedev();
292 +#endif//__linux__
293 +
294    exit(0);
295    return(0);                                   /* purecov: deadcode */
296  }
297 @@ -7890,6 +7999,7 @@
298    {"Delayed_errors",           (char*) &delayed_insert_errors,  SHOW_LONG},
299    {"Delayed_insert_threads",   (char*) &delayed_insert_threads, SHOW_LONG_NOFLUSH},
300    {"Delayed_writes",           (char*) &delayed_insert_writes,  SHOW_LONG},
301 +  {"Flashcache_enabled",       (char*) &cachedev_enabled,       SHOW_BOOL },
302    {"Flush_commands",           (char*) &refresh_version,        SHOW_LONG_NOFLUSH},
303    {"Handler_commit",           (char*) offsetof(STATUS_VAR, ha_commit_count), SHOW_LONG_STATUS},
304    {"Handler_delete",           (char*) offsetof(STATUS_VAR, ha_delete_count), SHOW_LONG_STATUS},
305 --- a/sql/mysql_priv.h
306 +++ b/sql/mysql_priv.h
307 @@ -825,6 +825,8 @@
308  */
309  extern ulong server_id, concurrency;
310  
311 +/* flashcache */
312 +extern int cachedev_fd;
313  
314  typedef my_bool (*qc_engine_callback)(THD *thd, char *table_key,
315                                        uint key_length,
316 --- a/sql/sql_lex.cc
317 +++ b/sql/sql_lex.cc
318 @@ -308,6 +308,7 @@
319    lex->describe= 0;
320    lex->subqueries= FALSE;
321    lex->context_analysis_only= 0;
322 +  lex->disable_flashcache= FALSE;
323    lex->derived_tables= 0;
324    lex->lock_option= TL_READ;
325    lex->safe_to_cache_query= 1;
326 --- a/sql/sql_lex.h
327 +++ b/sql/sql_lex.h
328 @@ -1730,6 +1730,7 @@
329  
330    uint8 context_analysis_only;
331    bool safe_to_cache_query;
332 +  bool disable_flashcache;
333    bool subqueries, ignore;
334    st_parsing_options parsing_options;
335    Alter_info alter_info;
336 --- a/sql/sql_select.cc
337 +++ b/sql/sql_select.cc
338 @@ -37,6 +37,12 @@
339  #include <hash.h>
340  #include <ft_global.h>
341  
342 +#include <sys/syscall.h>
343 +#include <sys/ioctl.h>
344 +#if defined(__linux__)
345 +#include "flashcache_ioctl.h"
346 +#endif//__linux__
347 +
348  const char *join_type_str[]={ "UNKNOWN","system","const","eq_ref","ref",
349                               "MAYBE_REF","ALL","range","index","fulltext",
350                               "ref_or_null","unique_subquery","index_subquery",
351 @@ -239,9 +245,20 @@
352                     ulong setup_tables_done_option)
353  {
354    bool res;
355 +#if defined(__linux__)
356 +  pid_t pid;
357 +#endif
358    register SELECT_LEX *select_lex = &lex->select_lex;
359    DBUG_ENTER("handle_select");
360  
361 +#if defined(__linux__)
362 +  if(lex->disable_flashcache && cachedev_fd > 0)
363 +  {
364 +    pid = syscall(SYS_gettid);
365 +    ioctl(cachedev_fd, FLASHCACHEADDNCPID, &pid);
366 +  }
367 +#endif//__linux__
368
369    if (select_lex->master_unit()->is_union() || 
370        select_lex->master_unit()->fake_select_lex)
371      res= mysql_union(thd, lex, result, &lex->unit, setup_tables_done_option);
372 @@ -274,6 +291,12 @@
373    if (unlikely(res))
374      result->abort();
375  
376 +#if defined(__linux__)
377 +  if (lex->disable_flashcache && cachedev_fd > 0)
378 +  {
379 +    ioctl(cachedev_fd, FLASHCACHEDELNCPID, &pid);
380 +  }
381 +#endif//__linux__ 
382    DBUG_RETURN(res);
383  }
384  
385 --- a/sql/sql_yacc.yy
386 +++ b/sql/sql_yacc.yy
387 @@ -1166,6 +1166,7 @@
388  %token  SQL_CACHE_SYM
389  %token  SQL_CALC_FOUND_ROWS
390  %token  SQL_NO_CACHE_SYM
391 +%token  SQL_NO_FCACHE_SYM
392  %token  SQL_SMALL_RESULT
393  %token  SQL_SYM                       /* SQL-2003-R */
394  %token  SQL_THREAD
395 @@ -6757,6 +6758,10 @@
396              Lex->select_lex.options&= ~OPTION_TO_QUERY_CACHE;
397              Lex->select_lex.sql_cache= SELECT_LEX::SQL_NO_CACHE;
398            }
399 +       | SQL_NO_FCACHE_SYM
400 +         {
401 +           Lex->disable_flashcache= TRUE;
402 +         }
403          | SQL_CACHE_SYM
404            {
405              /*
406 --- /dev/null
407 +++ b/mysql-test/r/percona_sql_no_fcache.result
408 @@ -0,0 +1,12 @@
409 +drop table if exists t1;
410 +create table t (a int not null);
411 +insert into t values (1),(2),(3);
412 +SELECT SQL_NO_FCACHE SLEEP(0);
413 +SLEEP(0)
414 +0
415 +SELECT /*!40001 SQL_NO_CACHE */ /*!50084 SQL_NO_FCACHE */ * FROM t;
416 +a
417 +1
418 +2
419 +3
420 +DROP TABLE t;
421 --- /dev/null
422 +++ b/mysql-test/t/percona_sql_no_fcache.test
423 @@ -0,0 +1,11 @@
424 +--disable_warnings
425 +drop table if exists t1;
426 +--enable_warnings
427 +
428 +create table t (a int not null);
429 +insert into t values (1),(2),(3);
430 +
431 +SELECT SQL_NO_FCACHE SLEEP(0);
432 +SELECT /*!40001 SQL_NO_CACHE */ /*!50084 SQL_NO_FCACHE */ * FROM t;
433 +
434 +DROP TABLE t;
This page took 0.281417 seconds and 3 git commands to generate.