]> git.pld-linux.org Git - packages/mysql.git/blob - innodb_fast_checksum.patch
- up to 5.5.11
[packages/mysql.git] / innodb_fast_checksum.patch
1 # name       : innodb_fast_checksum.patch
2 # introduced : 11 or before
3 # maintainer : Yasufumi
4 #
5 #!!! notice !!!
6 # Any small change to this file in the main branch
7 # should be done or reviewed by the maintainer!
8 diff -ruN a/storage/innobase/buf/buf0buf.c b/storage/innobase/buf/buf0buf.c
9 --- a/storage/innobase/buf/buf0buf.c    2010-12-04 15:52:23.391514910 +0900
10 +++ b/storage/innobase/buf/buf0buf.c    2010-12-04 15:53:45.013513772 +0900
11 @@ -511,6 +511,27 @@
12         return(checksum);
13  }
14  
15 +UNIV_INTERN
16 +ulint
17 +buf_calc_page_new_checksum_32(
18 +/*==========================*/
19 +       const byte*     page)   /*!< in: buffer page */
20 +{
21 +       ulint checksum;
22 +
23 +       checksum = ut_fold_binary(page + FIL_PAGE_OFFSET,
24 +                                 FIL_PAGE_FILE_FLUSH_LSN - FIL_PAGE_OFFSET)
25 +               + ut_fold_binary(page + FIL_PAGE_DATA,
26 +                                FIL_PAGE_DATA_ALIGN_32 - FIL_PAGE_DATA)
27 +               + ut_fold_binary_32(page + FIL_PAGE_DATA_ALIGN_32,
28 +                                   UNIV_PAGE_SIZE - FIL_PAGE_DATA_ALIGN_32
29 +                                   - FIL_PAGE_END_LSN_OLD_CHKSUM);
30 +
31 +       checksum = checksum & 0xFFFFFFFFUL;
32 +
33 +       return(checksum);
34 +}
35 +
36  /********************************************************************//**
37  In versions < 4.0.14 and < 4.1.1 there was a bug that the checksum only
38  looked at the first few bytes of the page. This calculates that old
39 @@ -627,9 +648,21 @@
40                 /* InnoDB versions < 4.0.14 and < 4.1.1 stored the space id
41                 (always equal to 0), to FIL_PAGE_SPACE_OR_CHKSUM */
42  
43 -               if (checksum_field != 0
44 +               if (!srv_fast_checksum
45 +                   && checksum_field != 0
46 +                   && checksum_field != BUF_NO_CHECKSUM_MAGIC
47 +                   && checksum_field
48 +                   != buf_calc_page_new_checksum(read_buf)) {
49 +
50 +                       return(TRUE);
51 +               }
52 +
53 +               if (srv_fast_checksum
54 +                   && checksum_field != 0
55                     && checksum_field != BUF_NO_CHECKSUM_MAGIC
56                     && checksum_field
57 +                   != buf_calc_page_new_checksum_32(read_buf)
58 +                   && checksum_field
59                     != buf_calc_page_new_checksum(read_buf)) {
60  
61                         return(TRUE);
62 @@ -653,6 +686,7 @@
63         dict_index_t*   index;
64  #endif /* !UNIV_HOTBACKUP */
65         ulint           checksum;
66 +       ulint           checksum_32;
67         ulint           old_checksum;
68         ulint           size    = zip_size;
69  
70 @@ -739,12 +773,14 @@
71  
72         checksum = srv_use_checksums
73                 ? buf_calc_page_new_checksum(read_buf) : BUF_NO_CHECKSUM_MAGIC;
74 +       checksum_32 = srv_use_checksums
75 +               ? buf_calc_page_new_checksum_32(read_buf) : BUF_NO_CHECKSUM_MAGIC;
76         old_checksum = srv_use_checksums
77                 ? buf_calc_page_old_checksum(read_buf) : BUF_NO_CHECKSUM_MAGIC;
78  
79         ut_print_timestamp(stderr);
80         fprintf(stderr,
81 -               "  InnoDB: Page checksum %lu, prior-to-4.0.14-form"
82 +               "  InnoDB: Page checksum %lu (32bit_calc: %lu), prior-to-4.0.14-form"
83                 " checksum %lu\n"
84                 "InnoDB: stored checksum %lu, prior-to-4.0.14-form"
85                 " stored checksum %lu\n"
86 @@ -753,7 +789,7 @@
87                 "InnoDB: Page number (if stored to page already) %lu,\n"
88                 "InnoDB: space id (if created with >= MySQL-4.1.1"
89                 " and stored already) %lu\n",
90 -               (ulong) checksum, (ulong) old_checksum,
91 +               (ulong) checksum, (ulong) checksum_32, (ulong) old_checksum,
92                 (ulong) mach_read_from_4(read_buf + FIL_PAGE_SPACE_OR_CHKSUM),
93                 (ulong) mach_read_from_4(read_buf + UNIV_PAGE_SIZE
94                                          - FIL_PAGE_END_LSN_OLD_CHKSUM),
95 diff -ruN a/storage/innobase/buf/buf0flu.c b/storage/innobase/buf/buf0flu.c
96 --- a/storage/innobase/buf/buf0flu.c    2010-12-04 15:37:50.555568346 +0900
97 +++ b/storage/innobase/buf/buf0flu.c    2010-12-04 15:53:45.015513917 +0900
98 @@ -1055,7 +1055,9 @@
99  
100         mach_write_to_4(page + FIL_PAGE_SPACE_OR_CHKSUM,
101                         srv_use_checksums
102 -                       ? buf_calc_page_new_checksum(page)
103 +                       ? (!srv_fast_checksum
104 +                          ? buf_calc_page_new_checksum(page)
105 +                          : buf_calc_page_new_checksum_32(page))
106                         : BUF_NO_CHECKSUM_MAGIC);
107  
108         /* We overwrite the first 4 bytes of the end lsn field to store
109 diff -ruN a/storage/innobase/fil/fil0fil.c b/storage/innobase/fil/fil0fil.c
110 --- a/storage/innobase/fil/fil0fil.c    2010-12-04 15:52:23.406513743 +0900
111 +++ b/storage/innobase/fil/fil0fil.c    2010-12-04 15:53:45.020513800 +0900
112 @@ -3199,7 +3199,9 @@
113                         mach_write_to_8(page + FIL_PAGE_FILE_FLUSH_LSN, current_lsn);
114                 mach_write_to_4(page + FIL_PAGE_SPACE_OR_CHKSUM,
115                                 srv_use_checksums
116 -                               ? buf_calc_page_new_checksum(page)
117 +                               ? (!srv_fast_checksum
118 +                                  ? buf_calc_page_new_checksum(page)
119 +                                  : buf_calc_page_new_checksum_32(page))
120                                                 : BUF_NO_CHECKSUM_MAGIC);
121                 mach_write_to_4(page + UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM,
122                                 srv_use_checksums
123 @@ -3331,7 +3333,8 @@
124                                         page_is_corrupt = TRUE;
125                                 }
126  
127 -                               if (checksum_field != 0
128 +                               if (!srv_fast_checksum
129 +                                   && checksum_field != 0
130                                     && checksum_field != BUF_NO_CHECKSUM_MAGIC
131                                     && checksum_field
132                                     != buf_calc_page_new_checksum(page)) {
133 @@ -3339,6 +3342,17 @@
134                                         page_is_corrupt = TRUE;
135                                 }
136  
137 +                               if (srv_fast_checksum
138 +                                   && checksum_field != 0
139 +                                   && checksum_field != BUF_NO_CHECKSUM_MAGIC
140 +                                   && checksum_field
141 +                                   != buf_calc_page_new_checksum_32(page)
142 +                                   && checksum_field
143 +                                   != buf_calc_page_new_checksum(page)) {
144 +
145 +                                       page_is_corrupt = TRUE;
146 +                               }
147 +
148                                 /* if it is free page, inconsistency is acceptable */
149                                 if (!offset) {
150                                         /* header page*/
151 @@ -3484,7 +3498,9 @@
152  
153                                         mach_write_to_4(page + FIL_PAGE_SPACE_OR_CHKSUM,
154                                                         srv_use_checksums
155 -                                                       ? buf_calc_page_new_checksum(page)
156 +                                                       ? (!srv_fast_checksum
157 +                                                          ? buf_calc_page_new_checksum(page)
158 +                                                          : buf_calc_page_new_checksum_32(page))
159                                                                         : BUF_NO_CHECKSUM_MAGIC);
160                                         mach_write_to_4(page + UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM,
161                                                         srv_use_checksums
162 diff -ruN a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
163 --- a/storage/innobase/handler/ha_innodb.cc     2010-12-04 15:52:23.420480329 +0900
164 +++ b/storage/innobase/handler/ha_innodb.cc     2010-12-04 15:53:45.029551892 +0900
165 @@ -183,6 +183,7 @@
166  #endif /* UNIV_LOG_ARCHIVE */
167  static my_bool innobase_use_doublewrite                = TRUE;
168  static my_bool innobase_use_checksums                  = TRUE;
169 +static my_bool innobase_fast_checksum                  = FALSE;
170  static my_bool innobase_recovery_stats                 = TRUE;
171  static my_bool innobase_locks_unsafe_for_binlog        = FALSE;
172  static my_bool innobase_overwrite_relay_log_info       = FALSE;
173 @@ -2593,6 +2594,7 @@
174  
175         srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite;
176         srv_use_checksums = (ibool) innobase_use_checksums;
177 +       srv_fast_checksum = (ibool) innobase_fast_checksum;
178  
179  #ifdef HAVE_LARGE_PAGES
180          if ((os_use_large_pages = (ibool) my_use_large_pages))
181 @@ -11401,6 +11403,15 @@
182    "Disable with --skip-innodb-checksums.",
183    NULL, NULL, TRUE);
184  
185 +static MYSQL_SYSVAR_BOOL(fast_checksum, innobase_fast_checksum,
186 +  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
187 +  "Change the algorithm of checksum for the whole of datapage to 4-bytes word based. "
188 +  "The original checksum is checked after the new one. It may be slow for reading page"
189 +  " which has orginal checksum. Overwrite the page or recreate the InnoDB database, "
190 +  "if you want the entire benefit for performance at once. "
191 +  "#### Attention: The checksum is not compatible for normal or disabled version! ####",
192 +  NULL, NULL, FALSE);
193 +
194  static MYSQL_SYSVAR_STR(data_home_dir, innobase_data_home_dir,
195    PLUGIN_VAR_READONLY,
196    "The common part for InnoDB table spaces.",
197 @@ -11909,6 +11920,7 @@
198    MYSQL_SYSVAR(buffer_pool_size),
199    MYSQL_SYSVAR(buffer_pool_instances),
200    MYSQL_SYSVAR(checksums),
201 +  MYSQL_SYSVAR(fast_checksum),
202    MYSQL_SYSVAR(commit_concurrency),
203    MYSQL_SYSVAR(concurrency_tickets),
204    MYSQL_SYSVAR(data_file_path),
205 diff -ruN a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h
206 --- a/storage/innobase/include/buf0buf.h        2010-12-04 15:52:23.458514045 +0900
207 +++ b/storage/innobase/include/buf0buf.h        2010-12-04 15:53:45.044514150 +0900
208 @@ -602,6 +602,11 @@
209  buf_calc_page_new_checksum(
210  /*=======================*/
211         const byte*     page);  /*!< in: buffer page */
212 +UNIV_INTERN
213 +ulint
214 +buf_calc_page_new_checksum_32(
215 +/*==========================*/
216 +       const byte*     page);  /*!< in: buffer page */
217  /********************************************************************//**
218  In versions < 4.0.14 and < 4.1.1 there was a bug that the checksum only
219  looked at the first few bytes of the page. This calculates that old
220 diff -ruN a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h
221 --- a/storage/innobase/include/fil0fil.h        2010-12-04 15:52:23.466513796 +0900
222 +++ b/storage/innobase/include/fil0fil.h        2010-12-04 15:53:45.046513558 +0900
223 @@ -118,6 +118,7 @@
224  #define FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID  34 /*!< starting from 4.1.x this
225                                         contains the space id of the page */
226  #define FIL_PAGE_DATA          38      /*!< start of the data on the page */
227 +#define FIL_PAGE_DATA_ALIGN_32 40
228  /* @} */
229  /** File page trailer @{ */
230  #define FIL_PAGE_END_LSN_OLD_CHKSUM 8  /*!< the low 4 bytes of this are used
231 diff -ruN a/storage/innobase/include/srv0srv.h b/storage/innobase/include/srv0srv.h
232 --- a/storage/innobase/include/srv0srv.h        2010-12-04 15:52:23.474482590 +0900
233 +++ b/storage/innobase/include/srv0srv.h        2010-12-04 15:53:45.048512100 +0900
234 @@ -227,6 +227,7 @@
235  
236  extern ibool   srv_use_doublewrite_buf;
237  extern ibool   srv_use_checksums;
238 +extern ibool   srv_fast_checksum;
239  
240  extern ulong   srv_max_buf_pool_modified_pct;
241  extern ulong   srv_max_purge_lag;
242 diff -ruN a/storage/innobase/include/ut0rnd.h b/storage/innobase/include/ut0rnd.h
243 --- a/storage/innobase/include/ut0rnd.h 2010-11-03 07:01:13.000000000 +0900
244 +++ b/storage/innobase/include/ut0rnd.h 2010-12-04 15:53:45.049510146 +0900
245 @@ -124,6 +124,13 @@
246         const byte*     str,    /*!< in: string of bytes */
247         ulint           len)    /*!< in: length */
248         __attribute__((pure));
249 +UNIV_INLINE
250 +ulint
251 +ut_fold_binary_32(
252 +/*==============*/
253 +       const byte*     str,    /*!< in: string of bytes */
254 +       ulint           len)    /*!< in: length */
255 +       __attribute__((pure));
256  /***********************************************************//**
257  Looks for a prime number slightly greater than the given argument.
258  The prime is chosen so that it is not near any power of 2.
259 diff -ruN a/storage/innobase/include/ut0rnd.ic b/storage/innobase/include/ut0rnd.ic
260 --- a/storage/innobase/include/ut0rnd.ic        2010-11-03 07:01:13.000000000 +0900
261 +++ b/storage/innobase/include/ut0rnd.ic        2010-12-04 15:53:45.050565975 +0900
262 @@ -226,3 +226,28 @@
263  
264         return(fold);
265  }
266 +
267 +UNIV_INLINE
268 +ulint
269 +ut_fold_binary_32(
270 +/*==============*/
271 +       const byte*     str,    /*!< in: string of bytes */
272 +       ulint           len)    /*!< in: length */
273 +{
274 +       const ib_uint32_t*      str_end = (const ib_uint32_t*) (str + len);
275 +       const ib_uint32_t*      str_32 = (const ib_uint32_t*) str;
276 +       ulint                   fold = 0;
277 +
278 +       ut_ad(str);
279 +       /* This function is only for word-aligned data */
280 +       ut_ad(len % 4 == 0);
281 +       ut_ad((ulint)str % 4 == 0);
282 +
283 +       while (str_32 < str_end) {
284 +               fold = ut_fold_ulint_pair(fold, (ulint)(*str_32));
285 +
286 +               str_32++;
287 +       }
288 +
289 +       return(fold);
290 +}
291 diff -ruN a/storage/innobase/srv/srv0srv.c b/storage/innobase/srv/srv0srv.c
292 --- a/storage/innobase/srv/srv0srv.c    2010-12-04 15:52:23.498513634 +0900
293 +++ b/storage/innobase/srv/srv0srv.c    2010-12-04 15:53:45.053550283 +0900
294 @@ -421,6 +421,7 @@
295  
296  UNIV_INTERN ibool      srv_use_doublewrite_buf = TRUE;
297  UNIV_INTERN ibool      srv_use_checksums = TRUE;
298 +UNIV_INTERN ibool      srv_fast_checksum = FALSE;
299  
300  UNIV_INTERN ulong      srv_replication_delay           = 0;
301  
This page took 0.061969 seconds and 4 git commands to generate.