~ignacio-nin/percona-server/5.1-issue26684

102.1.1 by kinoyasu
add header and rule, as the first step of the reordering patch for separate release
1
# name       : innodb_expand_import.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!
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
8
diff -ruN a/storage/innodb_plugin/fil/fil0fil.c b/storage/innodb_plugin/fil/fil0fil.c
9
--- a/storage/innodb_plugin/fil/fil0fil.c	2010-04-29 15:44:28.000000000 +0900
10
+++ b/storage/innodb_plugin/fil/fil0fil.c	2010-04-30 10:43:13.000000000 +0900
83.2.3 by kinoyasu
adjust not to cause warnings with -Wall
11
@@ -40,6 +40,12 @@
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
12
 #include "dict0dict.h"
13
 #include "page0page.h"
14
 #include "page0zip.h"
15
+#include "trx0trx.h"
16
+#include "trx0sys.h"
17
+#include "pars0pars.h"
18
+#include "row0mysql.h"
83.2.3 by kinoyasu
adjust not to cause warnings with -Wall
19
+#include "row0row.h"
83.2.2 by Oleg Tsarev
fix one more
20
+#include "que0que.h"
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
21
 #ifndef UNIV_HOTBACKUP
22
 # include "buf0lru.h"
23
 # include "ibuf0ibuf.h"
175 by kinoyasu
Yasufumi patches are ported to 5.1.54
24
@@ -3029,7 +3035,7 @@
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
25
 	ut_a(!(flags & (~0UL << DICT_TF_BITS)));
26
 
27
 	file = os_file_create_simple_no_error_handling(
28
-		filepath, OS_FILE_OPEN, OS_FILE_READ_ONLY, &success);
29
+		filepath, OS_FILE_OPEN, OS_FILE_READ_WRITE, &success);
30
 	if (!success) {
31
 		/* The following call prints an error message */
32
 		os_file_get_last_error(TRUE);
203.1.1 by kinoyasu
fix bug716575 and bug727704
33
@@ -3076,6 +3082,466 @@
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
34
 	space_id = fsp_header_get_space_id(page);
35
 	space_flags = fsp_header_get_flags(page);
36
 
189.2.2 by Yasufumi Kinoshita
innodb_expand_import always treats as expand_import, even if the space_id is equal; optimize innodb_dict_size_limit as issue 13634
37
+	if (srv_expand_import) {
38
+
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
39
+		ibool		file_is_corrupt = FALSE;
40
+		byte*		buf3;
41
+		byte*		descr_page;
42
+		ibool		descr_is_corrupt = FALSE;
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
43
+		dulint		old_id[31];
44
+		dulint		new_id[31];
45
+		ulint		root_page[31];
46
+		ulint		n_index;
47
+		os_file_t	info_file = -1;
48
+		char*		info_file_path;
49
+		ulint	i;
50
+		int		len;
51
+		ib_uint64_t	current_lsn;
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
52
+		ulint		size_low, size_high, size, free_limit;
53
+		ib_int64_t	size_bytes, free_limit_bytes;
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
54
+		dict_table_t*	table;
55
+		dict_index_t*	index;
56
+		fil_system_t*	system;
57
+		fil_node_t*	node = NULL;
58
+		fil_space_t*	space;
59
+
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
60
+		buf3 = ut_malloc(2 * UNIV_PAGE_SIZE);
61
+		descr_page = ut_align(buf3, UNIV_PAGE_SIZE);
62
+
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
63
+		current_lsn = log_get_lsn();
64
+
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
65
+		/* check the header page's consistency */
66
+		if (buf_page_is_corrupted(page,
67
+					  dict_table_flags_to_zip_size(space_flags))) {
68
+			fprintf(stderr, "InnoDB: page 0 of %s seems corrupt.\n", filepath);
69
+			file_is_corrupt = TRUE;
70
+			descr_is_corrupt = TRUE;
71
+		}
72
+
73
+		/* store as first descr page */
74
+		memcpy(descr_page, page, UNIV_PAGE_SIZE);
75
+
76
+		/* get free limit (page number) of the table space */
77
+/* these should be same to the definition in fsp0fsp.c */
78
+#define FSP_HEADER_OFFSET	FIL_PAGE_DATA
79
+#define	FSP_FREE_LIMIT		12
80
+		free_limit = mach_read_from_4(FSP_HEADER_OFFSET + FSP_FREE_LIMIT + page);
81
+		free_limit_bytes = (ib_int64_t)free_limit * (ib_int64_t)UNIV_PAGE_SIZE;
82
+
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
83
+		/* overwrite fsp header */
84
+		fsp_header_init_fields(page, id, flags);
85
+		mach_write_to_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, id);
86
+		space_id = id;
87
+		space_flags = flags;
88
+		if (mach_read_ull(page + FIL_PAGE_FILE_FLUSH_LSN) > current_lsn)
89
+			mach_write_ull(page + FIL_PAGE_FILE_FLUSH_LSN, current_lsn);
90
+		mach_write_to_4(page + FIL_PAGE_SPACE_OR_CHKSUM,
91
+				srv_use_checksums
92
+				? buf_calc_page_new_checksum(page)
93
+						: BUF_NO_CHECKSUM_MAGIC);
94
+		mach_write_to_4(page + UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM,
95
+				srv_use_checksums
96
+				? buf_calc_page_old_checksum(page)
97
+						: BUF_NO_CHECKSUM_MAGIC);
98
+		success = os_file_write(filepath, file, page, 0, 0, UNIV_PAGE_SIZE);
99
+
100
+		/* get file size */
101
+		os_file_get_size(file, &size_low, &size_high);
102
+		size_bytes = (((ib_int64_t)size_high) << 32)
103
+				+ (ib_int64_t)size_low;
104
+
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
105
+		if (size_bytes < free_limit_bytes) {
106
+			free_limit_bytes = size_bytes;
217 by Alexey Kopytov
Fixed a recently introduced compiler warning in innodb_expand_import.patch
107
+			if (size_bytes >= (ib_int64_t) (FSP_EXTENT_SIZE * UNIV_PAGE_SIZE)) {
203.1.1 by kinoyasu
fix bug716575 and bug727704
108
+				fprintf(stderr, "InnoDB: free limit of %s is larger than its real size.\n", filepath);
109
+				file_is_corrupt = TRUE;
110
+			}
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
111
+		}
112
+
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
113
+		/* get cruster index information */
114
+		table = dict_table_get_low(name);
115
+		index = dict_table_get_first_index(table);
116
+		ut_a(index->page==3);
117
+
118
+		/* read metadata from .exp file */
119
+		n_index = 0;
120
+		memset(old_id, 0, sizeof(old_id));
121
+		memset(new_id, 0, sizeof(new_id));
122
+		memset(root_page, 0, sizeof(root_page));
123
+
124
+		info_file_path = fil_make_ibd_name(name, FALSE);
125
+		len = strlen(info_file_path);
126
+		info_file_path[len - 3] = 'e';
127
+		info_file_path[len - 2] = 'x';
128
+		info_file_path[len - 1] = 'p';
129
+
130
+		info_file = os_file_create_simple_no_error_handling(
131
+				info_file_path, OS_FILE_OPEN, OS_FILE_READ_ONLY, &success);
132
+		if (!success) {
133
+			fprintf(stderr, "InnoDB: cannot open %s\n", info_file_path);
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
134
+			file_is_corrupt = TRUE;
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
135
+			goto skip_info;
136
+		}
137
+		success = os_file_read(info_file, page, 0, 0, UNIV_PAGE_SIZE);
138
+		if (!success) {
139
+			fprintf(stderr, "InnoDB: cannot read %s\n", info_file_path);
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
140
+			file_is_corrupt = TRUE;
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
141
+			goto skip_info;
142
+		}
143
+		if (mach_read_from_4(page) != 0x78706f72UL
144
+		    || mach_read_from_4(page + 4) != 0x74696e66UL) {
145
+			fprintf(stderr, "InnoDB: %s seems not to be a correct .exp file\n", info_file_path);
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
146
+			file_is_corrupt = TRUE;
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
147
+			goto skip_info;
148
+		}
149
+
150
+		fprintf(stderr, "InnoDB: import: extended import of %s is started.\n", name);
151
+
152
+		n_index = mach_read_from_4(page + 8);
153
+		fprintf(stderr, "InnoDB: import: %lu indexes are detected.\n", (ulong)n_index);
154
+		for (i = 0; i < n_index; i++) {
155
+			new_id[i] =
156
+				dict_table_get_index_on_name(table,
83.2.3 by kinoyasu
adjust not to cause warnings with -Wall
157
+						(char*)(page + (i + 1) * 512 + 12))->id;
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
158
+			old_id[i] = mach_read_from_8(page + (i + 1) * 512);
159
+			root_page[i] = mach_read_from_4(page + (i + 1) * 512 + 8);
160
+		}
161
+
162
+skip_info:
163
+		if (info_file != -1)
164
+			os_file_close(info_file);
165
+
166
+		/*
167
+		if (size_bytes >= 1024 * 1024) {
168
+			size_bytes = ut_2pow_round(size_bytes, 1024 * 1024);
169
+		}
170
+		*/
171
+		if (!(flags & DICT_TF_ZSSIZE_MASK)) {
172
+			mem_heap_t*	heap = NULL;
173
+			ulint		offsets_[REC_OFFS_NORMAL_SIZE];
174
+			ulint*		offsets = offsets_;
175
+			ib_int64_t	offset;
176
+
177
+			size = (ulint) (size_bytes / UNIV_PAGE_SIZE);
178
+			/* over write space id of all pages */
179
+			rec_offs_init(offsets_);
180
+
83.2.2 by Oleg Tsarev
fix one more
181
+			fprintf(stderr, "InnoDB: Progress in %%:");
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
182
+
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
183
+			for (offset = 0; offset < free_limit_bytes; offset += UNIV_PAGE_SIZE) {
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
184
+				ulint		checksum_field;
185
+				ulint		old_checksum_field;
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
186
+				ibool		page_is_corrupt;
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
187
+
188
+				success = os_file_read(file, page,
189
+							(ulint)(offset & 0xFFFFFFFFUL),
190
+							(ulint)(offset >> 32), UNIV_PAGE_SIZE);
191
+
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
192
+				page_is_corrupt = FALSE;
193
+
194
+				/* check consistency */
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
195
+				if (memcmp(page + FIL_PAGE_LSN + 4,
196
+					   page + UNIV_PAGE_SIZE
197
+					   - FIL_PAGE_END_LSN_OLD_CHKSUM + 4, 4)) {
198
+
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
199
+					page_is_corrupt = TRUE;
200
+				}
201
+
202
+				if (mach_read_from_4(page + FIL_PAGE_OFFSET)
203
+				    != offset / UNIV_PAGE_SIZE) {
204
+
205
+					page_is_corrupt = TRUE;
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
206
+				}
207
+
208
+				checksum_field = mach_read_from_4(page
209
+								  + FIL_PAGE_SPACE_OR_CHKSUM);
210
+
211
+				old_checksum_field = mach_read_from_4(
212
+					page + UNIV_PAGE_SIZE
213
+					- FIL_PAGE_END_LSN_OLD_CHKSUM);
214
+
215
+				if (old_checksum_field != mach_read_from_4(page
216
+									   + FIL_PAGE_LSN)
217
+				    && old_checksum_field != BUF_NO_CHECKSUM_MAGIC
218
+				    && old_checksum_field
219
+				    != buf_calc_page_old_checksum(page)) {
220
+
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
221
+					page_is_corrupt = TRUE;
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
222
+				}
223
+
224
+				if (checksum_field != 0
225
+				    && checksum_field != BUF_NO_CHECKSUM_MAGIC
226
+				    && checksum_field
227
+				    != buf_calc_page_new_checksum(page)) {
228
+
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
229
+					page_is_corrupt = TRUE;
230
+				}
231
+
232
+				/* if it is free page, inconsistency is acceptable */
233
+				if (!offset) {
234
+					/* header page*/
235
+					/* it should be overwritten already */
236
+					ut_a(!page_is_corrupt);
237
+
238
+				} else if (!((offset / UNIV_PAGE_SIZE) % UNIV_PAGE_SIZE)) {
239
+					/* descr page (not header) */
240
+					if (page_is_corrupt) {
241
+						file_is_corrupt = TRUE;
242
+						descr_is_corrupt = TRUE;
243
+					} else {
203.1.2 by Yasufumi Kinoshita
remove the problematic assertion code completely
244
+
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
245
+						descr_is_corrupt = FALSE;
246
+					}
247
+
248
+					/* store as descr page */
249
+					memcpy(descr_page, page, UNIV_PAGE_SIZE);
250
+
251
+				} else if (descr_is_corrupt) {
252
+					/* unknown state of the page */
253
+					if (page_is_corrupt) {
254
+						file_is_corrupt = TRUE;
255
+					}
256
+
257
+				} else {
258
+					/* check free page or not */
259
+					/* These definitions should be same to fsp0fsp.c */
260
+#define	FSP_HEADER_SIZE		(32 + 5 * FLST_BASE_NODE_SIZE)
261
+
262
+#define	XDES_BITMAP		(FLST_NODE_SIZE + 12)
263
+#define	XDES_BITS_PER_PAGE	2
264
+#define	XDES_FREE_BIT		0
265
+#define	XDES_SIZE							\
266
+	(XDES_BITMAP + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE * XDES_BITS_PER_PAGE))
267
+#define	XDES_ARR_OFFSET		(FSP_HEADER_OFFSET + FSP_HEADER_SIZE)
268
+
269
+					/*descr = descr_page + XDES_ARR_OFFSET + XDES_SIZE * xdes_calc_descriptor_index(zip_size, offset)*/
270
+					/*xdes_get_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, mtr)*/
271
+					byte*	descr;
272
+					ulint	index;
273
+					ulint	byte_index;
274
+					ulint	bit_index;
275
+
276
+					descr = descr_page + XDES_ARR_OFFSET
277
+						+ XDES_SIZE * (ut_2pow_remainder((offset / UNIV_PAGE_SIZE), UNIV_PAGE_SIZE) / FSP_EXTENT_SIZE);
278
+
279
+					index = XDES_FREE_BIT + XDES_BITS_PER_PAGE * ((offset / UNIV_PAGE_SIZE) % FSP_EXTENT_SIZE);
280
+					byte_index = index / 8;
281
+					bit_index = index % 8;
282
+
283
+					if (ut_bit_get_nth(mach_read_from_1(descr + XDES_BITMAP + byte_index), bit_index)) {
284
+						/* free page */
285
+						if (page_is_corrupt) {
286
+							goto skip_write;
287
+						}
288
+					} else {
289
+						/* not free */
290
+						if (page_is_corrupt) {
291
+							file_is_corrupt = TRUE;
292
+						}
293
+					}
294
+				}
295
+
296
+				if (page_is_corrupt) {
297
+					fprintf(stderr, " [errp:%lld]", offset / UNIV_PAGE_SIZE);
298
+
299
+					/* cannot treat corrupt page */
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
300
+					goto skip_write;
301
+				}
302
+
303
+				if (mach_read_from_4(page + FIL_PAGE_OFFSET) || !offset) {
304
+					mach_write_to_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, id);
305
+
306
+					for (i = 0; i < n_index; i++) {
307
+						if (offset / UNIV_PAGE_SIZE == root_page[i]) {
308
+							/* this is index root page */
309
+							mach_write_to_4(page + FIL_PAGE_DATA + PAGE_BTR_SEG_LEAF
310
+											+ FSEG_HDR_SPACE, id);
311
+							mach_write_to_4(page + FIL_PAGE_DATA + PAGE_BTR_SEG_TOP
312
+											+ FSEG_HDR_SPACE, id);
313
+							break;
314
+						}
315
+					}
316
+
317
+					if (fil_page_get_type(page) == FIL_PAGE_INDEX) {
318
+						dulint tmp = mach_read_from_8(page + (PAGE_HEADER + PAGE_INDEX_ID));
319
+
320
+						if (mach_read_from_2(page + PAGE_HEADER + PAGE_LEVEL) == 0
321
+						    && ut_dulint_cmp(old_id[0], tmp) == 0) {
322
+							/* leaf page of cluster index, reset trx_id of records */
323
+							rec_t*	rec;
324
+							rec_t*	supremum;
325
+							ulint	n_recs;
326
+
327
+							supremum = page_get_supremum_rec(page);
328
+							rec = page_rec_get_next(page_get_infimum_rec(page));
329
+							n_recs = page_get_n_recs(page);
330
+
331
+							while (rec && rec != supremum && n_recs > 0) {
332
+								ulint	n_fields;
333
+								ulint	i;
334
+								ulint	offset = index->trx_id_offset;
335
+								offsets = rec_get_offsets(rec, index, offsets,
336
+										ULINT_UNDEFINED, &heap);
337
+								n_fields = rec_offs_n_fields(offsets);
338
+								if (!offset) {
339
+									offset = row_get_trx_id_offset(rec, index, offsets);
340
+								}
341
+								trx_write_trx_id(rec + offset, ut_dulint_create(0, 1));
342
+
343
+								for (i = 0; i < n_fields; i++) {
344
+									if (rec_offs_nth_extern(offsets, i)) {
345
+										ulint	local_len;
346
+										byte*	data;
347
+
348
+										data = rec_get_nth_field(rec, offsets, i, &local_len);
349
+
350
+										local_len -= BTR_EXTERN_FIELD_REF_SIZE;
351
+
352
+										mach_write_to_4(data + local_len + BTR_EXTERN_SPACE_ID, id);
353
+									}
354
+								}
355
+
356
+								rec = page_rec_get_next(rec);
357
+								n_recs--;
358
+							}
359
+						}
360
+
361
+						for (i = 0; i < n_index; i++) {
362
+							if (ut_dulint_cmp(old_id[i], tmp) == 0) {
363
+								mach_write_to_8(page + (PAGE_HEADER + PAGE_INDEX_ID), new_id[i]);
364
+								break;
365
+							}
366
+						}
367
+					}
368
+
369
+					if (mach_read_ull(page + FIL_PAGE_LSN) > current_lsn) {
370
+						mach_write_ull(page + FIL_PAGE_LSN, current_lsn);
371
+						mach_write_ull(page + UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM,
372
+										current_lsn);
373
+					}
374
+
375
+					mach_write_to_4(page + FIL_PAGE_SPACE_OR_CHKSUM,
376
+							srv_use_checksums
377
+							? buf_calc_page_new_checksum(page)
378
+									: BUF_NO_CHECKSUM_MAGIC);
379
+					mach_write_to_4(page + UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM,
380
+							srv_use_checksums
381
+							? buf_calc_page_old_checksum(page)
382
+									: BUF_NO_CHECKSUM_MAGIC);
383
+
384
+					success = os_file_write(filepath, file, page,
385
+								(ulint)(offset & 0xFFFFFFFFUL),
386
+								(ulint)(offset >> 32), UNIV_PAGE_SIZE);
387
+				}
388
+
389
+skip_write:
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
390
+				if (free_limit_bytes
391
+				    && ((ib_int64_t)((offset + UNIV_PAGE_SIZE) * 100) / free_limit_bytes)
392
+					!= ((offset * 100) / free_limit_bytes)) {
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
393
+					fprintf(stderr, " %lu",
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
394
+						(ulong)((ib_int64_t)((offset + UNIV_PAGE_SIZE) * 100) / free_limit_bytes));
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
395
+				}
396
+			}
397
+
398
+			fprintf(stderr, " done.\n");
399
+
400
+			/* update SYS_INDEXES set root page */
401
+			index = dict_table_get_first_index(table);
402
+			while (index) {
403
+				for (i = 0; i < n_index; i++) {
404
+					if (ut_dulint_cmp(new_id[i], index->id) == 0) {
405
+						break;
406
+					}
407
+				}
408
+
409
+				if (i != n_index
410
+				    && root_page[i] != index->page) {
411
+					/* must update */
412
+					ulint	error;
413
+					trx_t*	trx;
414
+					pars_info_t*	info = NULL;
415
+
416
+					trx = trx_allocate_for_mysql();
417
+					trx->op_info = "extended import";
418
+
419
+					info = pars_info_create();
420
+
421
+					pars_info_add_dulint_literal(info, "indexid", new_id[i]);
422
+					pars_info_add_int4_literal(info, "new_page", (lint) root_page[i]);
423
+
424
+					error = que_eval_sql(info,
425
+						"PROCEDURE UPDATE_INDEX_PAGE () IS\n"
426
+						"BEGIN\n"
427
+						"UPDATE SYS_INDEXES"
428
+						" SET PAGE_NO = :new_page"
429
+						" WHERE ID = :indexid;\n"
430
+						"COMMIT WORK;\n"
431
+						"END;\n",
432
+						FALSE, trx);
433
+
434
+					if (error != DB_SUCCESS) {
435
+						fprintf(stderr, "InnoDB: failed to update SYS_INDEXES\n");
436
+					}
437
+
438
+					trx_commit_for_mysql(trx);
439
+
440
+					trx_free_for_mysql(trx);
441
+
442
+					index->page = root_page[i];
443
+				}
444
+
445
+				index = dict_table_get_next_index(index);
446
+			}
447
+			if (UNIV_LIKELY_NULL(heap)) {
448
+				mem_heap_free(heap);
449
+			}
450
+		} else {
451
+			/* zip page? */
452
+			size = (ulint)
453
+			(size_bytes
454
+					/ dict_table_flags_to_zip_size(flags));
455
+			fprintf(stderr, "InnoDB: import: table %s seems to be in newer format."
456
+					" It may not be able to treated for now.\n", name);
457
+		}
458
+		/* .exp file should be removed */
459
+		success = os_file_delete(info_file_path);
460
+		if (!success) {
461
+			success = os_file_delete_if_exists(info_file_path);
462
+		}
463
+		mem_free(info_file_path);
464
+
465
+		system	= fil_system;
466
+		mutex_enter(&(system->mutex));
467
+		space = fil_space_get_by_id(id);
468
+		if (space)
469
+			node = UT_LIST_GET_FIRST(space->chain);
470
+		if (node && node->size < size) {
471
+			space->size += (size - node->size);
472
+			node->size = size;
473
+		}
474
+		mutex_exit(&(system->mutex));
109.1.1 by Yasufumi Kinoshita
more exact checking corruption of .ibd file at innodb_expand_import. The other line-adjustment will be done later.
475
+
476
+		ut_free(buf3);
477
+
478
+		if (file_is_corrupt) {
479
+			ut_print_timestamp(stderr);
480
+			fputs("  InnoDB: Error: file ",
481
+			      stderr);
482
+			ut_print_filename(stderr, filepath);
483
+			fprintf(stderr, " seems to be corrupt.\n"
484
+				"InnoDB: anyway, all not corrupt pages were tried to be converted to salvage.\n"
485
+				"InnoDB: ##### CAUTION #####\n"
486
+				"InnoDB: ## The .ibd must cause to crash InnoDB, though re-import would seem to be succeeded.\n"
487
+				"InnoDB: ## If you don't have knowledge about salvaging data from .ibd, you should not use the file.\n"
488
+				"InnoDB: ###################\n");
489
+			success = FALSE;
490
+
491
+			ut_free(buf2);
492
+
493
+			goto func_exit;
494
+		}
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
495
+	}
496
+
497
 	ut_free(buf2);
498
 
499
 	if (UNIV_UNLIKELY(space_id != id
500
diff -ruN a/storage/innodb_plugin/handler/ha_innodb.cc b/storage/innodb_plugin/handler/ha_innodb.cc
501
--- a/storage/innodb_plugin/handler/ha_innodb.cc	2010-04-29 16:54:08.000000000 +0900
502
+++ b/storage/innodb_plugin/handler/ha_innodb.cc	2010-04-30 10:28:05.000000000 +0900
208 by Yasufumi Kinoshita
Yasufumi patches and several are ported to 5.1.56; Note: option innodb_stats_method was removed from innodb_stats.patch, because implemented officially. And, bug733317 should be fixed before release
503
@@ -7125,6 +7125,14 @@
169 by kinoyasu
lp:~percona-dev/percona-server/release-5.1.51-12-expand_import_fix4autoinc is merged... (apply fix for innodb_expand_import.patch from Vamsi@FaceBook about autoinc)
504
 		err = row_discard_tablespace_for_mysql(dict_table->name, trx);
505
 	} else {
506
 		err = row_import_tablespace_for_mysql(dict_table->name, trx);
507
+
508
+		/* in expanded import mode re-initialize auto_increment again */
509
+		if ((err == DB_SUCCESS) && srv_expand_import &&
510
+		    (table->found_next_number_field != NULL)) {
511
+			dict_table_autoinc_lock(dict_table);
512
+			innobase_initialize_autoinc();
513
+			dict_table_autoinc_unlock(dict_table);
514
+		}
515
 	}
516
 
517
 	err = convert_error_code_to_mysql(err, dict_table->flags, NULL);
208 by Yasufumi Kinoshita
Yasufumi patches and several are ported to 5.1.56; Note: option innodb_stats_method was removed from innodb_stats.patch, because implemented officially. And, bug733317 should be fixed before release
518
@@ -11387,6 +11395,11 @@
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
519
   "Enable/Disable unsafe group commit when support_xa=OFF and use with binlog or other XA storage engine.",
520
   NULL, NULL, 0, 0, 1, 0);
521
 
522
+static MYSQL_SYSVAR_ULONG(expand_import, srv_expand_import,
523
+  PLUGIN_VAR_RQCMDARG,
524
+  "Enable/Disable converting automatically *.ibd files when import tablespace.",
525
+  NULL, NULL, 0, 0, 1, 0);
526
+
527
 static MYSQL_SYSVAR_ULONG(extra_rsegments, srv_extra_rsegments,
528
   PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
529
   "Number of extra user rollback segments when create new database.",
208 by Yasufumi Kinoshita
Yasufumi patches and several are ported to 5.1.56; Note: option innodb_stats_method was removed from innodb_stats.patch, because implemented officially. And, bug733317 should be fixed before release
530
@@ -11464,6 +11477,7 @@
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
531
   MYSQL_SYSVAR(adaptive_checkpoint),
71.1.1 by kinoyasu
session variables: innodb_flush_log_at_trx_commit_session and online_alter_index
532
   MYSQL_SYSVAR(flush_log_at_trx_commit_session),
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
533
   MYSQL_SYSVAR(enable_unsafe_group_commit),
534
+  MYSQL_SYSVAR(expand_import),
535
   MYSQL_SYSVAR(extra_rsegments),
536
   MYSQL_SYSVAR(dict_size_limit),
537
   MYSQL_SYSVAR(use_sys_malloc),
538
diff -ruN a/storage/innodb_plugin/handler/innodb_patch_info.h b/storage/innodb_plugin/handler/innodb_patch_info.h
539
--- a/storage/innodb_plugin/handler/innodb_patch_info.h	2010-04-29 18:58:20.000000000 +0900
540
+++ b/storage/innodb_plugin/handler/innodb_patch_info.h	2010-04-30 10:28:05.000000000 +0900
541
@@ -32,6 +32,7 @@
542
 {"innodb_extra_rseg","allow to create extra rollback segments","When create new db, the new parameter allows to create more rollback segments","http://www.percona.com/docs/wiki/percona-xtradb"},
543
 {"innodb_overwrite_relay_log_info","overwrite relay-log.info when slave recovery","Building as plugin, it is not used.","http://www.percona.com/docs/wiki/percona-xtradb:innodb_overwrite_relay_log_info"},
544
 {"innodb_thread_concurrency_timer_based","use InnoDB timer based concurrency throttling (backport from MySQL 5.4.0)","",""},
545
+{"innodb_expand_import","convert .ibd file automatically when import tablespace","the files are generated by xtrabackup export mode.","http://www.percona.com/docs/wiki/percona-xtradb"},
546
 {"innodb_dict_size_limit","Limit dictionary cache size","Variable innodb_dict_size_limit in bytes","http://www.percona.com/docs/wiki/percona-xtradb"},
547
 {"innodb_split_buf_pool_mutex","More fix of buffer_pool mutex","Spliting buf_pool_mutex and optimizing based on innodb_opt_lru_count","http://www.percona.com/docs/wiki/percona-xtradb"},
548
 {NULL, NULL, NULL, NULL}
549
diff -ruN a/storage/innodb_plugin/include/srv0srv.h b/storage/innodb_plugin/include/srv0srv.h
550
--- a/storage/innodb_plugin/include/srv0srv.h	2010-04-29 16:54:08.000000000 +0900
551
+++ b/storage/innodb_plugin/include/srv0srv.h	2010-04-30 10:28:05.000000000 +0900
208 by Yasufumi Kinoshita
Yasufumi patches and several are ported to 5.1.56; Note: option innodb_stats_method was removed from innodb_stats.patch, because implemented officially. And, bug733317 should be fixed before release
552
@@ -218,6 +218,8 @@
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
553
 extern ulint	srv_read_ahead;
554
 extern ulint	srv_adaptive_checkpoint;
555
 
556
+extern ulint	srv_expand_import;
557
+
558
 extern ulint	srv_extra_rsegments;
559
 extern ulint	srv_dict_size_limit;
560
 /*-------------------------------------------*/
561
diff -ruN a/storage/innodb_plugin/srv/srv0srv.c b/storage/innodb_plugin/srv/srv0srv.c
562
--- a/storage/innodb_plugin/srv/srv0srv.c	2010-04-29 18:58:20.000000000 +0900
563
+++ b/storage/innodb_plugin/srv/srv0srv.c	2010-04-30 10:28:05.000000000 +0900
208 by Yasufumi Kinoshita
Yasufumi patches and several are ported to 5.1.56; Note: option innodb_stats_method was removed from innodb_stats.patch, because implemented officially. And, bug733317 should be fixed before release
564
@@ -390,6 +390,8 @@
1 by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7
565
 UNIV_INTERN ulint	srv_read_ahead = 3; /* 1: random  2: linear  3: Both */
566
 UNIV_INTERN ulint	srv_adaptive_checkpoint = 0; /* 0: none  1: reflex  2: estimate */
567
 
568
+UNIV_INTERN ulint	srv_expand_import = 0; /* 0:disable 1:enable */
569
+
570
 UNIV_INTERN ulint	srv_extra_rsegments = 0; /* extra rseg for users */
571
 UNIV_INTERN ulint	srv_dict_size_limit = 0;
572
 /*-------------------------------------------*/