]>
Commit | Line | Data |
---|---|---|
b4e1fa2c AM |
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 | |
d8778560 | 98 | @@ -1055,7 +1055,9 @@ |
b4e1fa2c AM |
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 | |
adf0fb13 AM |
112 | @@ -3094,13 +3094,24 @@ |
113 | return(TRUE); | |
114 | } | |
115 | ||
116 | - if (checksum_field != 0 | |
117 | + if (!srv_fast_checksum | |
118 | + && checksum_field != 0 | |
119 | && checksum_field != BUF_NO_CHECKSUM_MAGIC | |
120 | && checksum_field | |
121 | != buf_calc_page_new_checksum(page)) { | |
122 | return(TRUE); | |
123 | } | |
124 | ||
125 | + if (srv_fast_checksum | |
126 | + && checksum_field != 0 | |
127 | + && checksum_field != BUF_NO_CHECKSUM_MAGIC | |
128 | + && checksum_field | |
129 | + != buf_calc_page_new_checksum_32(page) | |
130 | + && checksum_field | |
131 | + != buf_calc_page_new_checksum(page)) { | |
132 | + return(TRUE); | |
133 | + } | |
134 | + | |
135 | return(FALSE); | |
136 | } | |
137 | ||
138 | @@ -3116,7 +3127,9 @@ | |
139 | if (!zip_size) { | |
b4e1fa2c AM |
140 | mach_write_to_4(page + FIL_PAGE_SPACE_OR_CHKSUM, |
141 | srv_use_checksums | |
142 | - ? buf_calc_page_new_checksum(page) | |
143 | + ? (!srv_fast_checksum | |
144 | + ? buf_calc_page_new_checksum(page) | |
145 | + : buf_calc_page_new_checksum_32(page)) | |
146 | : BUF_NO_CHECKSUM_MAGIC); | |
147 | mach_write_to_4(page + UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM, | |
148 | srv_use_checksums | |
b4e1fa2c AM |
149 | diff -ruN a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc |
150 | --- a/storage/innobase/handler/ha_innodb.cc 2010-12-04 15:52:23.420480329 +0900 | |
151 | +++ b/storage/innobase/handler/ha_innodb.cc 2010-12-04 15:53:45.029551892 +0900 | |
152 | @@ -183,6 +183,7 @@ | |
153 | #endif /* UNIV_LOG_ARCHIVE */ | |
154 | static my_bool innobase_use_doublewrite = TRUE; | |
155 | static my_bool innobase_use_checksums = TRUE; | |
156 | +static my_bool innobase_fast_checksum = FALSE; | |
157 | static my_bool innobase_recovery_stats = TRUE; | |
158 | static my_bool innobase_locks_unsafe_for_binlog = FALSE; | |
159 | static my_bool innobase_overwrite_relay_log_info = FALSE; | |
adf0fb13 | 160 | @@ -2620,6 +2621,7 @@ |
b4e1fa2c AM |
161 | |
162 | srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite; | |
163 | srv_use_checksums = (ibool) innobase_use_checksums; | |
164 | + srv_fast_checksum = (ibool) innobase_fast_checksum; | |
165 | ||
166 | #ifdef HAVE_LARGE_PAGES | |
167 | if ((os_use_large_pages = (ibool) my_use_large_pages)) | |
adf0fb13 | 168 | @@ -11421,6 +11423,15 @@ |
b4e1fa2c AM |
169 | "Disable with --skip-innodb-checksums.", |
170 | NULL, NULL, TRUE); | |
171 | ||
172 | +static MYSQL_SYSVAR_BOOL(fast_checksum, innobase_fast_checksum, | |
173 | + PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY, | |
174 | + "Change the algorithm of checksum for the whole of datapage to 4-bytes word based. " | |
175 | + "The original checksum is checked after the new one. It may be slow for reading page" | |
176 | + " which has orginal checksum. Overwrite the page or recreate the InnoDB database, " | |
177 | + "if you want the entire benefit for performance at once. " | |
178 | + "#### Attention: The checksum is not compatible for normal or disabled version! ####", | |
179 | + NULL, NULL, FALSE); | |
180 | + | |
181 | static MYSQL_SYSVAR_STR(data_home_dir, innobase_data_home_dir, | |
182 | PLUGIN_VAR_READONLY, | |
183 | "The common part for InnoDB table spaces.", | |
adf0fb13 | 184 | @@ -11930,6 +11941,7 @@ |
b4e1fa2c AM |
185 | MYSQL_SYSVAR(buffer_pool_size), |
186 | MYSQL_SYSVAR(buffer_pool_instances), | |
187 | MYSQL_SYSVAR(checksums), | |
188 | + MYSQL_SYSVAR(fast_checksum), | |
189 | MYSQL_SYSVAR(commit_concurrency), | |
190 | MYSQL_SYSVAR(concurrency_tickets), | |
191 | MYSQL_SYSVAR(data_file_path), | |
192 | diff -ruN a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h | |
193 | --- a/storage/innobase/include/buf0buf.h 2010-12-04 15:52:23.458514045 +0900 | |
194 | +++ b/storage/innobase/include/buf0buf.h 2010-12-04 15:53:45.044514150 +0900 | |
adf0fb13 | 195 | @@ -604,6 +604,11 @@ |
b4e1fa2c AM |
196 | buf_calc_page_new_checksum( |
197 | /*=======================*/ | |
198 | const byte* page); /*!< in: buffer page */ | |
199 | +UNIV_INTERN | |
200 | +ulint | |
201 | +buf_calc_page_new_checksum_32( | |
202 | +/*==========================*/ | |
203 | + const byte* page); /*!< in: buffer page */ | |
204 | /********************************************************************//** | |
205 | In versions < 4.0.14 and < 4.1.1 there was a bug that the checksum only | |
206 | looked at the first few bytes of the page. This calculates that old | |
207 | diff -ruN a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h | |
208 | --- a/storage/innobase/include/fil0fil.h 2010-12-04 15:52:23.466513796 +0900 | |
209 | +++ b/storage/innobase/include/fil0fil.h 2010-12-04 15:53:45.046513558 +0900 | |
210 | @@ -118,6 +118,7 @@ | |
211 | #define FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID 34 /*!< starting from 4.1.x this | |
212 | contains the space id of the page */ | |
213 | #define FIL_PAGE_DATA 38 /*!< start of the data on the page */ | |
214 | +#define FIL_PAGE_DATA_ALIGN_32 40 | |
215 | /* @} */ | |
216 | /** File page trailer @{ */ | |
217 | #define FIL_PAGE_END_LSN_OLD_CHKSUM 8 /*!< the low 4 bytes of this are used | |
218 | diff -ruN a/storage/innobase/include/srv0srv.h b/storage/innobase/include/srv0srv.h | |
219 | --- a/storage/innobase/include/srv0srv.h 2010-12-04 15:52:23.474482590 +0900 | |
220 | +++ b/storage/innobase/include/srv0srv.h 2010-12-04 15:53:45.048512100 +0900 | |
adf0fb13 | 221 | @@ -224,6 +224,7 @@ |
b4e1fa2c AM |
222 | |
223 | extern ibool srv_use_doublewrite_buf; | |
224 | extern ibool srv_use_checksums; | |
225 | +extern ibool srv_fast_checksum; | |
226 | ||
227 | extern ulong srv_max_buf_pool_modified_pct; | |
228 | extern ulong srv_max_purge_lag; | |
229 | diff -ruN a/storage/innobase/include/ut0rnd.h b/storage/innobase/include/ut0rnd.h | |
230 | --- a/storage/innobase/include/ut0rnd.h 2010-11-03 07:01:13.000000000 +0900 | |
231 | +++ b/storage/innobase/include/ut0rnd.h 2010-12-04 15:53:45.049510146 +0900 | |
232 | @@ -124,6 +124,13 @@ | |
233 | const byte* str, /*!< in: string of bytes */ | |
234 | ulint len) /*!< in: length */ | |
235 | __attribute__((pure)); | |
236 | +UNIV_INLINE | |
237 | +ulint | |
238 | +ut_fold_binary_32( | |
239 | +/*==============*/ | |
240 | + const byte* str, /*!< in: string of bytes */ | |
241 | + ulint len) /*!< in: length */ | |
242 | + __attribute__((pure)); | |
243 | /***********************************************************//** | |
244 | Looks for a prime number slightly greater than the given argument. | |
245 | The prime is chosen so that it is not near any power of 2. | |
246 | diff -ruN a/storage/innobase/include/ut0rnd.ic b/storage/innobase/include/ut0rnd.ic | |
247 | --- a/storage/innobase/include/ut0rnd.ic 2010-11-03 07:01:13.000000000 +0900 | |
248 | +++ b/storage/innobase/include/ut0rnd.ic 2010-12-04 15:53:45.050565975 +0900 | |
249 | @@ -226,3 +226,28 @@ | |
250 | ||
251 | return(fold); | |
252 | } | |
253 | + | |
254 | +UNIV_INLINE | |
255 | +ulint | |
256 | +ut_fold_binary_32( | |
257 | +/*==============*/ | |
258 | + const byte* str, /*!< in: string of bytes */ | |
259 | + ulint len) /*!< in: length */ | |
260 | +{ | |
261 | + const ib_uint32_t* str_end = (const ib_uint32_t*) (str + len); | |
262 | + const ib_uint32_t* str_32 = (const ib_uint32_t*) str; | |
263 | + ulint fold = 0; | |
264 | + | |
265 | + ut_ad(str); | |
266 | + /* This function is only for word-aligned data */ | |
267 | + ut_ad(len % 4 == 0); | |
268 | + ut_ad((ulint)str % 4 == 0); | |
269 | + | |
270 | + while (str_32 < str_end) { | |
271 | + fold = ut_fold_ulint_pair(fold, (ulint)(*str_32)); | |
272 | + | |
273 | + str_32++; | |
274 | + } | |
275 | + | |
276 | + return(fold); | |
277 | +} | |
278 | diff -ruN a/storage/innobase/srv/srv0srv.c b/storage/innobase/srv/srv0srv.c | |
279 | --- a/storage/innobase/srv/srv0srv.c 2010-12-04 15:52:23.498513634 +0900 | |
280 | +++ b/storage/innobase/srv/srv0srv.c 2010-12-04 15:53:45.053550283 +0900 | |
adf0fb13 | 281 | @@ -414,6 +414,7 @@ |
b4e1fa2c AM |
282 | |
283 | UNIV_INTERN ibool srv_use_doublewrite_buf = TRUE; | |
284 | UNIV_INTERN ibool srv_use_checksums = TRUE; | |
285 | +UNIV_INTERN ibool srv_fast_checksum = FALSE; | |
286 | ||
287 | UNIV_INTERN ulong srv_replication_delay = 0; | |
288 |