Merge lp:~laurynas-biveinis/percona-xtrabackup/bug1049174-2.1 into lp:percona-xtrabackup/2.1

Proposed by Laurynas Biveinis on 2012-09-14
Status: Merged
Approved by: Alexey Kopytov on 2012-09-19
Approved revision: 433
Merged at revision: 436
Proposed branch: lp:~laurynas-biveinis/percona-xtrabackup/bug1049174-2.1
Merge into: lp:percona-xtrabackup/2.1
Diff against target: 370 lines (+181/-61)
5 files modified
src/innodb_int.c (+116/-0)
src/innodb_int.h (+35/-1)
src/write_filt.c (+2/-17)
src/xtrabackup.c (+25/-41)
src/xtrabackup.h (+3/-2)
To merge this branch: bzr merge lp:~laurynas-biveinis/percona-xtrabackup/bug1049174-2.1
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) 2012-09-14 Approve on 2012-09-19
Review via email: mp+124412@code.launchpad.net

Description of the change

Merge bug 1049174, bug 1044398, bug 1043762 fixes from 2.0.

Differences from 2.0 version:
- xb_delta_create_space_file() is named xb_space_create_file() and put
  into innodb_int.[hc].
- dict_table_flags_to_zip_size() definition provided for pre-InnoDB
  plugin configurations, to remove #ifndef INNODB_VERSION_SHORT in
  xb_delta_open_matching_space().
- The compression flag constants are defined in innodb_int.h instead
  of xtrabackup.c.
- Define fil_space_create() wrapper xb_fil_space_create() in
  innodb_int.h that accepts but ignores zip_size arg on pre-InnoDB
  plugin configurations.
- Moved SRV_SHUTDOWN_NONE definition to the main compatibility #define
  section in innodb_int.h.
- The suboptimal fix for bug 1022562 is reverted by removing
  wf_common_filter() function and updating its caller.

Jenkins: http://jenkins.percona.com/job/percona-xtrabackup-2.1-param/46/

Issue #16274

To post a comment you must log in.
Alexey Kopytov (akopytov) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/innodb_int.c'
2--- src/innodb_int.c 2012-07-11 07:55:58 +0000
3+++ src/innodb_int.c 2012-09-14 13:04:19 +0000
4@@ -200,8 +200,124 @@
5 return(space);
6 }
7
8+/****************************************************************//**
9+Create a new tablespace on disk and return the handle to its opened
10+file. Code adopted from fil_create_new_single_table_tablespace with
11+the main difference that only disk file is created without updating
12+the InnoDB in-memory dictionary data structures.
13+
14+@return TRUE on success, FALSE on error. */
15+ibool
16+xb_space_create_file(
17+/*==================*/
18+ const char* path, /*!<in: path to tablespace */
19+ ulint space_id, /*!<in: space id */
20+ ulint flags __attribute__((unused)),/*!<in: tablespace
21+ flags */
22+ os_file_t* file) /*!<out: file handle */
23+{
24+ ibool ret;
25+ byte* buf;
26+ byte* page;
27+
28+ *file = xb_file_create_no_error_handling(path, OS_FILE_CREATE,
29+ OS_FILE_READ_WRITE, &ret);
30+ if (!ret) {
31+ msg("xtrabackup: cannot create file %s\n", path);
32+ return ret;
33+ }
34+
35+ ret = os_file_set_size(path, *file,
36+ FIL_IBD_FILE_INITIAL_SIZE * UNIV_PAGE_SIZE, 0);
37+ if (!ret) {
38+ msg("xtrabackup: cannot set size for file %s\n", path);
39+ os_file_close(*file);
40+ os_file_delete(path);
41+ return ret;
42+ }
43+
44+ buf = ut_malloc(3 * UNIV_PAGE_SIZE);
45+ /* Align the memory for file i/o if we might have O_DIRECT set */
46+ page = ut_align(buf, UNIV_PAGE_SIZE);
47+
48+ memset(page, '\0', UNIV_PAGE_SIZE);
49+
50+#ifdef INNODB_VERSION_SHORT
51+ fsp_header_init_fields(page, space_id, flags);
52+ mach_write_to_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, space_id);
53+
54+ if (!(flags & DICT_TF_ZSSIZE_MASK)) {
55+ buf_flush_init_for_writing(page, NULL, 0);
56+
57+ ret = os_file_write(path, *file, page, 0, 0, UNIV_PAGE_SIZE);
58+ }
59+ else {
60+ page_zip_des_t page_zip;
61+ ulint zip_size;
62+
63+ zip_size = (PAGE_ZIP_MIN_SIZE >> 1)
64+ << ((flags & DICT_TF_ZSSIZE_MASK)
65+ >> DICT_TF_ZSSIZE_SHIFT);
66+ page_zip_set_size(&page_zip, zip_size);
67+ page_zip.data = page + UNIV_PAGE_SIZE;
68+ fprintf(stderr, "zip_size = %lu\n", zip_size);
69+
70+#ifdef UNIV_DEBUG
71+ page_zip.m_start =
72+#endif /* UNIV_DEBUG */
73+ page_zip.m_end = page_zip.m_nonempty =
74+ page_zip.n_blobs = 0;
75+
76+ buf_flush_init_for_writing(page, &page_zip, 0);
77+
78+ ret = os_file_write(path, *file, page_zip.data, 0, 0,
79+ zip_size);
80+ }
81+#else
82+ fsp_header_write_space_id(page, space_id);
83+
84+ buf_flush_init_for_writing(page, ut_dulint_zero, space_id, 0);
85+
86+ ret = os_file_write(path, *file, page, 0, 0, UNIV_PAGE_SIZE);
87+#endif
88+
89+ ut_free(buf);
90+
91+ if (!ret) {
92+ msg("xtrabackup: could not write the first page to %s\n",
93+ path);
94+ os_file_close(*file);
95+ os_file_delete(path);
96+ return ret;
97+ }
98+
99+ return TRUE;
100+}
101+
102+
103 #ifndef INNODB_VERSION_SHORT
104
105+/********************************************************************//**
106+Extract the compressed page size from table flags.
107+@return compressed page size, or 0 if not compressed */
108+ulint
109+dict_table_flags_to_zip_size(
110+/*=========================*/
111+ ulint flags) /*!< in: flags */
112+{
113+ ulint zip_size = flags & DICT_TF_ZSSIZE_MASK;
114+
115+ if (UNIV_UNLIKELY(zip_size)) {
116+ zip_size = ((PAGE_ZIP_MIN_SIZE >> 1)
117+ << (zip_size >> DICT_TF_ZSSIZE_SHIFT));
118+
119+ ut_ad(zip_size <= UNIV_PAGE_SIZE);
120+ }
121+
122+ return(zip_size);
123+}
124+
125+
126 /*******************************************************************//**
127 Free all spaces in space_list. */
128 void
129
130=== modified file 'src/innodb_int.h'
131--- src/innodb_int.h 2012-07-11 07:55:58 +0000
132+++ src/innodb_int.h 2012-09-14 13:04:19 +0000
133@@ -42,6 +42,15 @@
134 # define MACH_WRITE_64 mach_write_to_8
135 # define OS_MUTEX_CREATE() os_mutex_create(NULL)
136 # define xb_buf_page_is_corrupted(page, zip_size) buf_page_is_corrupted(page)
137+# define xb_fil_space_create(name, space_id, zip_size, purpose) \
138+ fil_space_create(name, space_id, purpose)
139+# define PAGE_ZIP_MIN_SIZE_SHIFT 10
140+# define PAGE_ZIP_MIN_SIZE (1 << PAGE_ZIP_MIN_SIZE_SHIFT)
141+# define DICT_TF_ZSSIZE_SHIFT 1
142+# define DICT_TF_ZSSIZE_MASK (15 << DICT_TF_ZSSIZE_SHIFT)
143+# define DICT_TF_FORMAT_ZIP 1
144+# define DICT_TF_FORMAT_SHIFT 5
145+# define SRV_SHUTDOWN_NONE 0
146 #else
147 # define IB_INT64 ib_int64_t
148 # define LSN64 ib_uint64_t
149@@ -56,6 +65,8 @@
150 # endif
151 # define xb_buf_page_is_corrupted(page, zip_size) \
152 buf_page_is_corrupted(page, zip_size)
153+# define xb_fil_space_create(name, space_id, zip_size, purpose) \
154+ fil_space_create(name, space_id, zip_size, purpose)
155 # define ut_dulint_zero 0
156 # define ut_dulint_cmp(A, B) (A > B ? 1 : (A == B ? 0 : -1))
157 # define ut_dulint_add(A, B) (A + B)
158@@ -598,9 +609,32 @@
159 /*==================*/
160 const char* name); /*!< in: space name */
161
162+/****************************************************************//**
163+Create a new tablespace on disk and return the handle to its opened
164+file. Code adopted from fil_create_new_single_table_tablespace with
165+the main difference that only disk file is created without updating
166+the InnoDB in-memory dictionary data structures.
167+
168+@return TRUE on success, FALSE on error. */
169+ibool
170+xb_space_create_file(
171+/*==================*/
172+ const char* path, /*!<in: path to tablespace */
173+ ulint space_id, /*!<in: space id */
174+ ulint flags __attribute__((unused)),/*!<in: tablespace
175+ flags */
176+ os_file_t* file); /*!<out: file handle */
177+
178 #ifndef INNODB_VERSION_SHORT
179
180-#define SRV_SHUTDOWN_NONE 0
181+/********************************************************************//**
182+Extract the compressed page size from table flags.
183+@return compressed page size, or 0 if not compressed */
184+ulint
185+dict_table_flags_to_zip_size(
186+/*=========================*/
187+ ulint flags); /*!< in: flags */
188+
189
190 /*******************************************************************//**
191 Free all spaces in space_list. */
192
193=== modified file 'src/write_filt.c'
194--- src/write_filt.c 2012-08-01 10:10:44 +0000
195+++ src/write_filt.c 2012-09-14 13:04:19 +0000
196@@ -32,21 +32,6 @@
197 #include "xtrabackup.h"
198
199 /************************************************************************
200-The common tablespace-offset-based page filter. This is a subroutine for all
201-other filters that will select additional pages to be written by their
202-tablespace position, regardless of the main filter logic.
203-
204-@return TRUE if the page with given id should be selected, FALSE otherwise. */
205-static my_bool wf_common_filter(ulint offset) {
206- /* We always copy the 1st FIL_IBD_INITIAL_SIZE *
207- UNIV_PAGE_SIZE bytes of any tablespace. These pages are
208- guaranteed to be flushed upon tablespace create and they are
209- needed so that we have a good minimal tablespace image before
210- doing anything further with it. */
211- return (offset < FIL_IBD_FILE_INITIAL_SIZE * UNIV_PAGE_SIZE);
212-}
213-
214-/************************************************************************
215 Write-through page write filter. */
216 static my_bool wf_wt_init(xb_write_filt_ctxt_t *ctxt, char *dst_name,
217 xb_fil_cur_t *cursor);
218@@ -118,6 +103,7 @@
219 snprintf(meta_name, sizeof(meta_name), "%s%s", dst_name,
220 XB_DELTA_INFO_SUFFIX);
221 info.page_size = cursor->page_size;
222+ info.zip_size = cursor->zip_size;
223 info.space_id = cursor->space_id;
224 if (!xb_write_delta_metadata(meta_name, &info)) {
225 msg("[%02lu] xtrabackup: Error: "
226@@ -152,8 +138,7 @@
227 for (i = 0, page = cursor->buf; i < cursor->buf_npages;
228 i++, page += page_size) {
229 if (ut_dulint_cmp(incremental_lsn,
230- MACH_READ_64(page + FIL_PAGE_LSN)) >= 0
231- && !wf_common_filter(cursor->buf_offset + i * page_size)) {
232+ MACH_READ_64(page + FIL_PAGE_LSN)) >= 0) {
233 continue;
234 }
235
236
237=== modified file 'src/xtrabackup.c'
238--- src/xtrabackup.c 2012-09-05 08:35:45 +0000
239+++ src/xtrabackup.c 2012-09-14 13:04:19 +0000
240@@ -1506,6 +1506,7 @@
241
242 /* set defaults */
243 info->page_size = ULINT_UNDEFINED;
244+ info->zip_size = ULINT_UNDEFINED;
245 info->space_id = ULINT_UNDEFINED;
246
247 fp = fopen(filepath, "r");
248@@ -1518,6 +1519,8 @@
249 if (fscanf(fp, "%50s = %50s\n", key, value) == 2) {
250 if (strcmp(key, "page_size") == 0) {
251 info->page_size = strtoul(value, NULL, 10);
252+ } else if (strcmp(key, "zip_size") == 0) {
253+ info->zip_size = strtoul(value, NULL, 10);
254 } else if (strcmp(key, "space_id") == 0) {
255 info->space_id = strtoul(value, NULL, 10);
256 }
257@@ -1552,8 +1555,10 @@
258 MY_STAT mystat;
259
260 snprintf(buf, sizeof(buf),
261- "page_size = %lu\nspace_id = %lu\n",
262- info->page_size, info->space_id);
263+ "page_size = %lu\n"
264+ "zip_size = %lu\n"
265+ "space_id = %lu\n",
266+ info->page_size, info->zip_size, info->space_id);
267 len = strlen(buf);
268
269 mystat.st_size = len;
270@@ -3836,7 +3841,7 @@
271 in given directory. When matching tablespace found, renames it to match the
272 name of .delta file. If there was a tablespace with matching name and
273 mismatching ID, renames it to xtrabackup_tmp_#ID.ibd. If there was no
274-matching file, creates a placeholder for the new tablespace.
275+matching file, creates a new tablespace.
276 @return file handle of matched or created file */
277 static
278 os_file_t
279@@ -3937,19 +3942,17 @@
280 goto found;
281 }
282
283- /* No matching space found. create the new one. Note that this is not
284- a full-fledged tablespace create, as done by
285- fil_create_new_single_table_tablespace(): the minumum tablespace size
286- is not ensured and the 1st page fields are not set. We rely on backup
287- delta to contain the 1st FIL_IBD_FILE_INITIAL_SIZE * UNIV_PAGE_SIZE
288- to ensure the correct tablespace image. */
289-
290-#ifdef INNODB_VERSION_SHORT
291- /* Calculate correct tablespace flags for compressed tablespaces. Do
292- not bother to set all flags correctly, just enough for
293- fil_space_create() to work. The full flags will be restored from the
294- delta later. */
295- if (!zip_size) {
296+ /* No matching space found. create the new one. */
297+
298+ if (!xb_fil_space_create(dest_space_name, space_id, 0,
299+ FIL_TABLESPACE)) {
300+ msg("xtrabackup: Cannot create tablespace %s\n",
301+ dest_space_name);
302+ goto exit;
303+ }
304+
305+ /* Calculate correct tablespace flags for compressed tablespaces. */
306+ if (!zip_size || zip_size == ULINT_UNDEFINED) {
307 tablespace_flags = 0;
308 }
309 else {
310@@ -3959,29 +3962,11 @@
311 << DICT_TF_ZSSIZE_SHIFT)
312 | DICT_TF_COMPACT
313 | (DICT_TF_FORMAT_ZIP << DICT_TF_FORMAT_SHIFT);
314- }
315- ut_a(dict_table_flags_to_zip_size(tablespace_flags) == zip_size);
316- if (!fil_space_create(dest_space_name, space_id, tablespace_flags,
317- FIL_TABLESPACE)) {
318-#else
319- if (!fil_space_create(dest_space_name, space_id,
320- FIL_TABLESPACE)) {
321-#endif
322- msg("xtrabackup: Cannot create tablespace %s\n",
323- dest_space_name);
324- goto exit;
325- }
326-
327- file = xb_file_create_no_error_handling(real_name, OS_FILE_CREATE,
328- OS_FILE_READ_WRITE,
329- &ok);
330-
331- if (ok) {
332- *success = TRUE;
333- } else {
334- msg("xtrabackup: Cannot open file %s\n", real_name);
335- }
336-
337+ ut_a(dict_table_flags_to_zip_size(tablespace_flags)
338+ == zip_size);
339+ }
340+ *success = xb_space_create_file(real_name, space_id, tablespace_flags,
341+ &file);
342 goto exit;
343
344 found:
345@@ -4088,8 +4073,7 @@
346 xb_file_set_nocache(src_file, src_path, "OPEN");
347
348 dst_file = xb_delta_open_matching_space(
349- dbname, space_name, info.space_id,
350- info.page_size == UNIV_PAGE_SIZE ? 0 : info.page_size,
351+ dbname, space_name, info.space_id, info.zip_size,
352 dst_path, sizeof(dst_path), &success);
353 if (!success) {
354 msg("xtrabackup: error: cannot open %s\n", dst_path);
355
356=== modified file 'src/xtrabackup.h'
357--- src/xtrabackup.h 2012-07-11 07:55:58 +0000
358+++ src/xtrabackup.h 2012-09-14 13:04:19 +0000
359@@ -22,8 +22,9 @@
360 #define XB_XTRABACKUP_H
361
362 typedef struct {
363- ulint page_size;
364- ulint space_id;
365+ ulint page_size;
366+ ulint zip_size;
367+ ulint space_id;
368 } xb_delta_info_t;
369
370 typedef enum {

Subscribers

People subscribed via source and target branches