1 # name : innodb_fast_checksum.patch
2 # introduced : 11 or before
3 # maintainer : Yasufumi
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
17 +buf_calc_page_new_checksum_32(
18 +/*==========================*/
19 + const byte* page) /*!< in: buffer page */
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);
31 + checksum = checksum & 0xFFFFFFFFUL;
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
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 */
43 - if (checksum_field != 0
44 + if (!srv_fast_checksum
45 + && checksum_field != 0
46 + && checksum_field != BUF_NO_CHECKSUM_MAGIC
48 + != buf_calc_page_new_checksum(read_buf)) {
53 + if (srv_fast_checksum
54 + && checksum_field != 0
55 && checksum_field != BUF_NO_CHECKSUM_MAGIC
57 + != buf_calc_page_new_checksum_32(read_buf)
59 != buf_calc_page_new_checksum(read_buf)) {
64 #endif /* !UNIV_HOTBACKUP */
68 ulint size = zip_size;
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;
79 ut_print_timestamp(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"
84 "InnoDB: stored checksum %lu, prior-to-4.0.14-form"
85 " stored checksum %lu\n"
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
100 mach_write_to_4(page + FIL_PAGE_SPACE_OR_CHKSUM,
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);
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,
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,
123 @@ -3331,7 +3333,8 @@
124 page_is_corrupt = TRUE;
127 - if (checksum_field != 0
128 + if (!srv_fast_checksum
129 + && checksum_field != 0
130 && checksum_field != BUF_NO_CHECKSUM_MAGIC
132 != buf_calc_page_new_checksum(page)) {
133 @@ -3339,6 +3342,17 @@
134 page_is_corrupt = TRUE;
137 + if (srv_fast_checksum
138 + && checksum_field != 0
139 + && checksum_field != BUF_NO_CHECKSUM_MAGIC
141 + != buf_calc_page_new_checksum_32(page)
143 + != buf_calc_page_new_checksum(page)) {
145 + page_is_corrupt = TRUE;
148 /* if it is free page, inconsistency is acceptable */
151 @@ -3484,7 +3498,9 @@
153 mach_write_to_4(page + FIL_PAGE_SPACE_OR_CHKSUM,
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,
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
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 @@ -2574,6 +2575,7 @@
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;
179 #ifdef HAVE_LARGE_PAGES
180 if ((os_use_large_pages = (ibool) my_use_large_pages))
181 @@ -11324,6 +11326,15 @@
182 "Disable with --skip-innodb-checksums.",
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);
194 static MYSQL_SYSVAR_STR(data_home_dir, innobase_data_home_dir,
196 "The common part for InnoDB table spaces.",
197 @@ -11831,6 +11842,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
209 buf_calc_page_new_checksum(
210 /*=======================*/
211 const byte* page); /*!< in: buffer page */
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
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
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
236 extern ibool srv_use_doublewrite_buf;
237 extern ibool srv_use_checksums;
238 +extern ibool srv_fast_checksum;
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
246 const byte* str, /*!< in: string of bytes */
247 ulint len) /*!< in: length */
248 __attribute__((pure));
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
271 + const byte* str, /*!< in: string of bytes */
272 + ulint len) /*!< in: length */
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;
279 + /* This function is only for word-aligned data */
280 + ut_ad(len % 4 == 0);
281 + ut_ad((ulint)str % 4 == 0);
283 + while (str_32 < str_end) {
284 + fold = ut_fold_ulint_pair(fold, (ulint)(*str_32));
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
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;
300 UNIV_INTERN ulong srv_replication_delay = 0;