Merge lp:~sergei.glushchenko/percona-xtrabackup/xb21-bug932623 into lp:percona-xtrabackup/2.1

Proposed by Sergei Glushchenko
Status: Merged
Approved by: Alexey Kopytov
Approved revision: no longer in the source branch.
Merged at revision: 416
Proposed branch: lp:~sergei.glushchenko/percona-xtrabackup/xb21-bug932623
Merge into: lp:percona-xtrabackup/2.1
Diff against target: 955 lines (+594/-111)
9 files modified
patches/innodb51_builtin.patch (+67/-4)
src/fil_cur.c (+1/-0)
src/fil_cur.h (+1/-0)
src/innodb_int.c (+76/-0)
src/innodb_int.h (+29/-0)
src/write_filt.c (+1/-0)
src/xtrabackup.c (+333/-107)
src/xtrabackup.h (+1/-0)
test/t/bug932623.sh (+85/-0)
To merge this branch: bzr merge lp:~sergei.glushchenko/percona-xtrabackup/xb21-bug932623
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) Approve
Review via email: mp+114363@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Alexey Kopytov (akopytov) :
review: Approve
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote :

This branch introduces many messages like this one:

2012-07-31 13:58:32: xb_incremental.sh: ===> /home/laurynas/percona/src/xb21-bug932623/test/../src/xtrabackup --no-defaults --datadir=/home/laurynas/percona/src/xb21-bug932623/test/var1/data --backup --target-dir=/home/laurynas/percona/src/xb21-bug932623/test/var1/data/full
/home/laurynas/percona/src/xb21-bug932623/test/../src/xtrabackup version 2.0.0 for Percona Server 5.1.59 unknown-linux-gnu (x86_64) (revision id: undefined)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /home/laurynas/percona/src/xb21-bug932623/test/var1/data
xtrabackup: Target instance is assumed as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 5242880
120731 13:58:32 InnoDB: Warning: allocated tablespace 10, old maximum was 9
120731 13:58:32 InnoDB: Warning: trying to init to the tablespace memory cache
InnoDB: a tablespace 10 of name './incremental_sample/test.ibd',
InnoDB: but a tablespace 10 of the same name
InnoDB: already exists in the tablespace memory cache!
InnoDB: We assume that InnoDB did a crash recovery, and you had
InnoDB: an .ibd file for which the table did not exist in the
InnoDB: InnoDB internal data dictionary in the ibdata files.
InnoDB: We assume that you later removed the .ibd and .frm files,
InnoDB: and are now trying to recreate the table. We now remove the
InnoDB: conflicting tablespace object from the memory cache and try
InnoDB: the init again.

Since Sergei is on vacation and I depend on this code, let's keep this "Approved" and merge and I will fix as a follow-up.

Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote :

Bug 1031324, one-liner fix MP'ed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'patches/innodb51_builtin.patch'
--- patches/innodb51_builtin.patch 2012-02-10 05:04:04 +0000
+++ patches/innodb51_builtin.patch 2012-07-11 09:06:21 +0000
@@ -613,7 +613,21 @@
613 613
614--- a/storage/innobase/include/mem0mem.h614--- a/storage/innobase/include/mem0mem.h
615+++ b/storage/innobase/include/mem0mem.h615+++ b/storage/innobase/include/mem0mem.h
616@@ -401,6 +401,7 @@616@@ -63,6 +63,13 @@
617 mem_init(
618 /*=====*/
619 ulint size); /* in: common pool size in bytes */
620+
621+/******************************************************************//**
622+Closes the memory system. */
623+void
624+mem_close(void);
625+/*===========*/
626+
627 /******************************************************************
628 Use this macro instead of the corresponding function! Macro for memory
629 heap creation. */
630@@ -401,6 +409,7 @@
617 allocated buffer frame, which can be appended as a631 allocated buffer frame, which can be appended as a
618 free block to the heap, if we need more space;632 free block to the heap, if we need more space;
619 otherwise, this is NULL */633 otherwise, this is NULL */
@@ -654,6 +668,21 @@
654 668
655 if (heap->free_block) {669 if (heap->free_block) {
656 size += UNIV_PAGE_SIZE;670 size += UNIV_PAGE_SIZE;
671--- a/storage/innobase/include/mem0pool.h
672+++ b/storage/innobase/include/mem0pool.h
673@@ -42,6 +42,12 @@
674 /*============*/
675 /* out: memory pool */
676 ulint size); /* in: pool size in bytes */
677+/********************************************************************//**
678+Frees a memory pool. */
679+void
680+mem_pool_free(
681+/*==========*/
682+ mem_pool_t* pool); /*!< in, own: memory pool */
683 /************************************************************************
684 Allocates memory from a pool. NOTE: This low-level function should only be
685 used in mem0mem.*! */
657--- a/storage/innobase/include/srv0srv.h686--- a/storage/innobase/include/srv0srv.h
658+++ b/storage/innobase/include/srv0srv.h687+++ b/storage/innobase/include/srv0srv.h
659@@ -60,6 +60,8 @@688@@ -60,6 +60,8 @@
@@ -958,7 +987,7 @@
958 /**********************************************************987 /**********************************************************
959--- a/storage/innobase/mem/mem0dbg.c988--- a/storage/innobase/mem/mem0dbg.c
960+++ b/storage/innobase/mem/mem0dbg.c989+++ b/storage/innobase/mem/mem0dbg.c
961@@ -133,6 +133,14 @@990@@ -133,9 +133,30 @@
962 mem_hash_initialized = TRUE;991 mem_hash_initialized = TRUE;
963 #endif992 #endif
964 993
@@ -973,6 +1002,22 @@
973 mem_comm_pool = mem_pool_create(size);1002 mem_comm_pool = mem_pool_create(size);
974 }1003 }
975 1004
1005+/******************************************************************//**
1006+Closes the memory system. */
1007+void
1008+mem_close(void)
1009+/*===========*/
1010+{
1011+ mem_pool_free(mem_comm_pool);
1012+ mem_comm_pool = NULL;
1013+#ifdef UNIV_MEM_DEBUG
1014+ mem_hash_initialized = FALSE;
1015+#endif /* UNIV_MEM_DEBUG */
1016+}
1017+
1018 #ifdef UNIV_MEM_DEBUG
1019 /**********************************************************************
1020 Initializes an allocated memory field in the debug version. */
976--- a/storage/innobase/mem/mem0mem.c1021--- a/storage/innobase/mem/mem0mem.c
977+++ b/storage/innobase/mem/mem0mem.c1022+++ b/storage/innobase/mem/mem0mem.c
978@@ -472,6 +472,7 @@1023@@ -472,6 +472,7 @@
@@ -1026,7 +1071,25 @@
1026 pool = ut_malloc(sizeof(mem_pool_t));1071 pool = ut_malloc(sizeof(mem_pool_t));
1027 1072
1028 /* We do not set the memory to zero (FALSE) in the pool,1073 /* We do not set the memory to zero (FALSE) in the pool,
1029@@ -333,6 +332,10 @@1074@@ -244,6 +243,17 @@
1075 return(pool);
1076 }
1077
1078+/********************************************************************//**
1079+Frees a memory pool. */
1080+void
1081+mem_pool_free(
1082+/*==========*/
1083+ mem_pool_t* pool) /*!< in, own: memory pool */
1084+{
1085+ ut_free(pool->buf);
1086+ ut_free(pool);
1087+}
1088+
1089 /************************************************************************
1090 Fills the specified free list. */
1091 static
1092@@ -333,6 +344,10 @@
1030 ulint n;1093 ulint n;
1031 ibool ret;1094 ibool ret;
1032 1095
@@ -1037,7 +1100,7 @@
1037 n = ut_2_log(ut_max(size + MEM_AREA_EXTRA_SIZE, MEM_AREA_MIN_SIZE));1100 n = ut_2_log(ut_max(size + MEM_AREA_EXTRA_SIZE, MEM_AREA_MIN_SIZE));
1038 1101
1039 mutex_enter(&(pool->mutex));1102 mutex_enter(&(pool->mutex));
1040@@ -465,6 +468,11 @@1103@@ -465,6 +480,11 @@
1041 ulint size;1104 ulint size;
1042 ulint n;1105 ulint n;
1043 1106
10441107
=== modified file 'src/fil_cur.c'
--- src/fil_cur.c 2012-05-28 16:49:14 +0000
+++ src/fil_cur.c 2012-07-11 09:06:21 +0000
@@ -54,6 +54,7 @@
54 cursor->orig_buf = NULL;54 cursor->orig_buf = NULL;
55 cursor->file = XB_FILE_UNDEFINED;55 cursor->file = XB_FILE_UNDEFINED;
5656
57 cursor->space_id = node->space->id;
57 cursor->is_system = trx_sys_sys_space(node->space->id);58 cursor->is_system = trx_sys_sys_space(node->space->id);
5859
59 /* Make the file path relative to the backup root,60 /* Make the file path relative to the backup root,
6061
=== modified file 'src/fil_cur.h'
--- src/fil_cur.h 2012-05-25 11:38:15 +0000
+++ src/fil_cur.h 2012-07-11 09:06:21 +0000
@@ -53,6 +53,7 @@
53 ulint buf_page_no; /*!< number of the first page in53 ulint buf_page_no; /*!< number of the first page in
54 buffer */54 buffer */
55 ulint thread_n; /*!< thread number for diagnostics */55 ulint thread_n; /*!< thread number for diagnostics */
56 ulint space_id; /*!< ID of tablespace */
56} xb_fil_cur_t;57} xb_fil_cur_t;
5758
58typedef enum {59typedef enum {
5960
=== modified file 'src/innodb_int.c'
--- src/innodb_int.c 2012-02-16 18:02:07 +0000
+++ src/innodb_int.c 2012-07-11 09:06:21 +0000
@@ -151,6 +151,82 @@
151 return os_file_flush(file);151 return os_file_flush(file);
152#endif152#endif
153}153}
154/*******************************************************************//**
155Returns the table space by a given id, NULL if not found. */
156fil_space_t*
157xb_space_get_by_id(
158/*================*/
159 ulint id) /*!< in: space id */
160{
161 fil_space_t* space;
162
163 ut_ad(mutex_own(&fil_system->mutex));
164
165#ifdef INNODB_VERSION_SHORT
166 HASH_SEARCH(hash, fil_system->spaces, id,
167 fil_space_t*, space,
168 ut_ad(space->magic_n == FIL_SPACE_MAGIC_N),
169 space->id == id);
170#else
171 HASH_SEARCH(hash, fil_system->spaces, id, space, space->id == id);
172#endif
173
174 return(space);
175}
176
177/*******************************************************************//**
178Returns the table space by a given name, NULL if not found. */
179fil_space_t*
180xb_space_get_by_name(
181/*==================*/
182 const char* name) /*!< in: space name */
183{
184 fil_space_t* space;
185 ulint fold;
186
187 ut_ad(mutex_own(&fil_system->mutex));
188
189#ifdef INNODB_VERSION_SHORT
190 fold = ut_fold_string(name);
191 HASH_SEARCH(name_hash, fil_system->name_hash, fold,
192 fil_space_t*, space,
193 ut_ad(space->magic_n == FIL_SPACE_MAGIC_N),
194 !strcmp(name, space->name));
195#else
196 HASH_SEARCH(name_hash, fil_system->name_hash, ut_fold_string(name),
197 space, 0 == strcmp(name, space->name));
198#endif
199
200 return(space);
201}
202
203#ifndef INNODB_VERSION_SHORT
204
205/*******************************************************************//**
206Free all spaces in space_list. */
207void
208fil_free_all_spaces(void)
209/*=====================*/
210{
211 fil_space_t* space;
212
213 mutex_enter(&fil_system->mutex);
214
215 space = UT_LIST_GET_FIRST(fil_system->space_list);
216
217 while (space != NULL) {
218 fil_node_t* node;
219 fil_space_t* prev_space = space;
220
221 space = UT_LIST_GET_NEXT(space_list, space);
222
223 fil_space_free(prev_space->id, FALSE);
224 }
225
226 mutex_exit(&fil_system->mutex);
227}
228
229#endif
154230
155void231void
156innobase_invalidate_query_cache(232innobase_invalidate_query_cache(
157233
=== modified file 'src/innodb_int.h'
--- src/innodb_int.h 2012-05-25 11:38:15 +0000
+++ src/innodb_int.h 2012-07-11 09:06:21 +0000
@@ -410,6 +410,9 @@
410extern char *opt_mysql_tmpdir;410extern char *opt_mysql_tmpdir;
411extern MY_TMPDIR mysql_tmpdir_list;411extern MY_TMPDIR mysql_tmpdir_list;
412412
413/** Value of fil_space_struct::magic_n */
414#define FIL_SPACE_MAGIC_N 89472
415
413/* ==end=== definition at fil0fil.c === */416/* ==end=== definition at fil0fil.c === */
414417
415/* prototypes for static functions in original */418/* prototypes for static functions in original */
@@ -581,6 +584,32 @@
581/*==========*/584/*==========*/
582 os_file_t file); /*!< in, own: handle to a file */585 os_file_t file); /*!< in, own: handle to a file */
583586
587/*******************************************************************//**
588Returns the table space by a given id, NULL if not found. */
589fil_space_t*
590xb_space_get_by_id(
591/*================*/
592 ulint id); /*!< in: space id */
593
594/*******************************************************************//**
595Returns the table space by a given name, NULL if not found. */
596fil_space_t*
597xb_space_get_by_name(
598/*==================*/
599 const char* name); /*!< in: space name */
600
601#ifndef INNODB_VERSION_SHORT
602
603#define SRV_SHUTDOWN_NONE 0
604
605/*******************************************************************//**
606Free all spaces in space_list. */
607void
608fil_free_all_spaces(void);
609/*=====================*/
610
611#endif
612
584void613void
585innobase_mysql_prepare_print_arbitrary_thd(void);614innobase_mysql_prepare_print_arbitrary_thd(void);
586615
587616
=== modified file 'src/write_filt.c'
--- src/write_filt.c 2012-05-25 11:38:15 +0000
+++ src/write_filt.c 2012-07-11 09:06:21 +0000
@@ -102,6 +102,7 @@
102 snprintf(meta_name, sizeof(meta_name), "%s%s", dst_name,102 snprintf(meta_name, sizeof(meta_name), "%s%s", dst_name,
103 XB_DELTA_INFO_SUFFIX);103 XB_DELTA_INFO_SUFFIX);
104 info.page_size = cursor->page_size;104 info.page_size = cursor->page_size;
105 info.space_id = cursor->space_id;
105 if (!xb_write_delta_metadata(meta_name, &info)) {106 if (!xb_write_delta_metadata(meta_name, &info)) {
106 msg("[%02lu] xtrabackup: Error: "107 msg("[%02lu] xtrabackup: Error: "
107 "failed to write meta info for %s\n",108 "failed to write meta info for %s\n",
108109
=== modified file 'src/xtrabackup.c'
--- src/xtrabackup.c 2012-06-20 16:23:58 +0000
+++ src/xtrabackup.c 2012-07-11 09:06:21 +0000
@@ -1500,7 +1500,8 @@
1500 return(TRUE);1500 return(TRUE);
1501 }1501 }
15021502
1503 if (fscanf(fp, "page_size = %lu\n", &info->page_size) != 1)1503 if (fscanf(fp, "page_size = %lu\nspace_id = %lu\n",
1504 &info->page_size, &info->space_id) != 2)
1504 r= FALSE;1505 r= FALSE;
15051506
1506 fclose(fp);1507 fclose(fp);
@@ -1515,14 +1516,16 @@
1515xb_write_delta_metadata(const char *filename, const xb_delta_info_t *info)1516xb_write_delta_metadata(const char *filename, const xb_delta_info_t *info)
1516{1517{
1517 ds_file_t *f;1518 ds_file_t *f;
1518 char buf[32];1519 char buf[64];
1519 my_bool ret;1520 my_bool ret;
1520 size_t len;1521 size_t len;
1521 MY_STAT mystat;1522 MY_STAT mystat;
15221523
1523 snprintf(buf, sizeof(buf), "page_size = %lu\n", info->page_size);1524 snprintf(buf, sizeof(buf),
15241525 "page_size = %lu\nspace_id = %lu\n",
1526 info->page_size, info->space_id);
1525 len = strlen(buf);1527 len = strlen(buf);
1528
1526 mystat.st_size = len;1529 mystat.st_size = len;
1527 mystat.st_mtime = my_time(0);1530 mystat.st_mtime = my_time(0);
15281531
@@ -2108,11 +2111,11 @@
2108 void* arg)2111 void* arg)
2109{2112{
2110 ulint segment;2113 ulint segment;
2111 ulint i;2114
21122115
2113 segment = *((ulint*)arg);2116 segment = *((ulint*)arg);
21142117
2115 for (i = 0;; i++) {2118 while (srv_shutdown_state != SRV_SHUTDOWN_EXIT_THREADS) {
2116 fil_aio_wait(segment);2119 fil_aio_wait(segment);
2117 }2120 }
21182121
@@ -2265,6 +2268,141 @@
2265 ds_meta = NULL;2268 ds_meta = NULL;
2266}2269}
22672270
2271#define SRV_N_PENDING_IOS_PER_THREAD OS_AIO_N_PENDING_IOS_PER_THREAD
2272#define SRV_MAX_N_PENDING_SYNC_IOS 100
2273
2274/************************************************************************
2275Initialize the tablespace memory cache and populate it by scanning for and
2276opening data files.
2277@returns DB_SUCCESS or error code.*/
2278ulint
2279xb_data_files_init(void)
2280/*====================*/
2281{
2282 ulint i;
2283 ibool create_new_db;
2284#ifdef XTRADB_BASED
2285 ibool create_new_doublewrite_file;
2286#endif
2287 ulint err;
2288 LSN64 min_flushed_lsn;
2289 LSN64 max_flushed_lsn;
2290 ulint sum_of_new_sizes;
2291
2292#ifndef INNODB_VERSION_SHORT
2293 os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD
2294 * srv_n_file_io_threads,
2295 srv_n_file_io_threads,
2296 SRV_MAX_N_PENDING_SYNC_IOS);
2297
2298 fil_init(srv_max_n_open_files);
2299#else
2300 srv_n_file_io_threads = 2 + srv_n_read_io_threads +
2301 srv_n_write_io_threads;
2302
2303 os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD,
2304 srv_n_read_io_threads,
2305 srv_n_write_io_threads,
2306 SRV_MAX_N_PENDING_SYNC_IOS);
2307
2308 fil_init(srv_file_per_table ? 50000 : 5000,
2309 srv_max_n_open_files);
2310#endif
2311
2312 fsp_init();
2313
2314 for (i = 0; i < srv_n_file_io_threads; i++) {
2315 thread_nr[i] = i;
2316
2317 os_thread_create(io_handler_thread, thread_nr + i,
2318 thread_ids + i);
2319 }
2320
2321 os_thread_sleep(200000); /*0.2 sec*/
2322
2323 err = open_or_create_data_files(&create_new_db,
2324#ifdef XTRADB_BASED
2325 &create_new_doublewrite_file,
2326#endif
2327 &min_flushed_lsn, &max_flushed_lsn,
2328 &sum_of_new_sizes);
2329 if (err != DB_SUCCESS) {
2330 msg("xtrabackup: Could not open or create data files.\n"
2331 "xtrabackup: If you tried to add new data files, and it "
2332 "failed here,\n"
2333 "xtrabackup: you should now edit innodb_data_file_path in "
2334 "my.cnf back\n"
2335 "xtrabackup: to what it was, and remove the new ibdata "
2336 "files InnoDB created\n"
2337 "xtrabackup: in this failed attempt. InnoDB only wrote "
2338 "those files full of\n"
2339 "xtrabackup: zeros, but did not yet use them in any way. "
2340 "But be careful: do not\n"
2341 "xtrabackup: remove old data files which contain your "
2342 "precious data!\n");
2343 return(err);
2344 }
2345
2346 /* create_new_db must not be TRUE.. */
2347 if (create_new_db) {
2348 msg("xtrabackup: could not find data files at the "
2349 "specified datadir\n");
2350 return(DB_ERROR);
2351 }
2352
2353 return(fil_load_single_table_tablespaces());
2354}
2355
2356/************************************************************************
2357Destroy the tablespace memory cache. */
2358void
2359xb_data_files_close(void)
2360/*====================*/
2361{
2362 ulint i;
2363
2364 /* Shutdown the aio threads. This has been copied from
2365 innobase_shutdown_for_mysql(). */
2366
2367 srv_shutdown_state = SRV_SHUTDOWN_EXIT_THREADS;
2368
2369 for (i = 0; i < 1000; i++) {
2370 os_aio_wake_all_threads_at_shutdown();
2371
2372 os_mutex_enter(os_sync_mutex);
2373
2374 if (os_thread_count == 0) {
2375
2376 os_mutex_exit(os_sync_mutex);
2377
2378 os_thread_sleep(10000);
2379
2380 break;
2381 }
2382
2383 os_mutex_exit(os_sync_mutex);
2384
2385 os_thread_sleep(10000);
2386 }
2387
2388 if (i == 1000) {
2389 msg("xtrabackup: Warning: %lu threads created by InnoDB"
2390 " had not exited at shutdown!\n",
2391 (ulong) os_thread_count);
2392 }
2393
2394#ifdef INNODB_VERSION_SHORT
2395 os_aio_free();
2396#endif
2397 fil_close_all_files();
2398#ifndef INNODB_VERSION_SHORT
2399 fil_free_all_spaces();
2400#endif
2401 fil_system = NULL;
2402
2403 srv_shutdown_state = SRV_SHUTDOWN_NONE;
2404}
2405
2268static void2406static void
2269xtrabackup_backup_func(void)2407xtrabackup_backup_func(void)
2270{2408{
@@ -2418,85 +2556,25 @@
2418 srv_general_init();2556 srv_general_init();
24192557
2420 {2558 {
2421 ibool create_new_db;
2422#ifdef XTRADB_BASED
2423 ibool create_new_doublewrite_file;
2424#endif
2425 ibool log_file_created;2559 ibool log_file_created;
2426 ibool log_created = FALSE;2560 ibool log_created = FALSE;
2427 ibool log_opened = FALSE;2561 ibool log_opened = FALSE;
2428 LSN64 min_flushed_lsn;
2429 LSN64 max_flushed_lsn;
2430 ulint sum_of_new_sizes;
2431 ulint err;2562 ulint err;
2432 ulint i;2563 ulint i;
24332564
24342565 err = xb_data_files_init();
24352566 if (err != DB_SUCCESS) {
24362567 msg("xtrabackup: error: xb_data_files_init() failed with"
2437#define SRV_N_PENDING_IOS_PER_THREAD OS_AIO_N_PENDING_IOS_PER_THREAD2568 "error code %lu\n", err);
2438#define SRV_MAX_N_PENDING_SYNC_IOS 1002569 exit(EXIT_FAILURE);
24392570 }
2440#ifndef INNODB_VERSION_SHORT2571
2441 os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD
2442 * srv_n_file_io_threads,
2443 srv_n_file_io_threads,
2444 SRV_MAX_N_PENDING_SYNC_IOS);
2445
2446 fil_init(srv_max_n_open_files);
2447#else
2448 srv_n_file_io_threads = 2 + srv_n_read_io_threads + srv_n_write_io_threads;
2449
2450 os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD,
2451 srv_n_read_io_threads,
2452 srv_n_write_io_threads,
2453 SRV_MAX_N_PENDING_SYNC_IOS);
2454
2455 fil_init(srv_file_per_table ? 50000 : 5000,
2456 srv_max_n_open_files);
2457#endif
2458
2459 fsp_init();
2460 log_init();2572 log_init();
24612573
2462 lock_sys_create(srv_lock_table_size);2574 lock_sys_create(srv_lock_table_size);
24632575
2464 for (i = 0; i < srv_n_file_io_threads; i++) {
2465 thread_nr[i] = i;
2466
2467 os_thread_create(io_handler_thread, thread_nr + i, thread_ids + i);
2468 }
2469
2470 os_thread_sleep(200000); /*0.2 sec*/
2471
2472 err = open_or_create_data_files(&create_new_db,
2473#ifdef XTRADB_BASED
2474 &create_new_doublewrite_file,
2475#endif
2476 &min_flushed_lsn, &max_flushed_lsn,
2477 &sum_of_new_sizes);
2478 if (err != DB_SUCCESS) {
2479 msg(
2480"xtrabackup: Could not open or create data files.\n"
2481"xtrabackup: If you tried to add new data files, and it failed here,\n"
2482"xtrabackup: you should now edit innodb_data_file_path in my.cnf back\n"
2483"xtrabackup: to what it was, and remove the new ibdata files InnoDB created\n"
2484"xtrabackup: in this failed attempt. InnoDB only wrote those files full of\n"
2485"xtrabackup: zeros, but did not yet use them in any way. But be careful: do not\n"
2486"xtrabackup: remove old data files which contain your precious data!\n");
2487
2488 //return((int) err);
2489 exit(EXIT_FAILURE);
2490 }
2491
2492 /* create_new_db must not be TRUE.. */
2493 if (create_new_db) {
2494 msg("xtrabackup: Something wrong with source files...\n");
2495 exit(EXIT_FAILURE);
2496 }
2497
2498 for (i = 0; i < srv_n_log_files; i++) {2576 for (i = 0; i < srv_n_log_files; i++) {
2499 err = open_or_create_log_file(create_new_db, &log_file_created,2577 err = open_or_create_log_file(FALSE, &log_file_created,
2500 log_opened, 0, i);2578 log_opened, 0, i);
2501 if (err != DB_SUCCESS) {2579 if (err != DB_SUCCESS) {
25022580
@@ -2509,8 +2587,7 @@
2509 } else {2587 } else {
2510 log_opened = TRUE;2588 log_opened = TRUE;
2511 }2589 }
2512 if ((log_opened && create_new_db)2590 if ((log_opened && log_created)) {
2513 || (log_opened && log_created)) {
2514 msg(2591 msg(
2515 "xtrabackup: Error: all log files must be created at the same time.\n"2592 "xtrabackup: Error: all log files must be created at the same time.\n"
2516 "xtrabackup: All log files must be created also in database creation.\n"2593 "xtrabackup: All log files must be created also in database creation.\n"
@@ -2830,6 +2907,8 @@
2830 msg("xtrabackup: Transaction log of lsn (%llu) to (%llu) was copied.\n",2907 msg("xtrabackup: Transaction log of lsn (%llu) to (%llu) was copied.\n",
2831 checkpoint_lsn_start, log_copy_scanned_lsn);2908 checkpoint_lsn_start, log_copy_scanned_lsn);
2832#endif2909#endif
2910
2911 xb_data_files_close();
2833}2912}
28342913
2835/* ================= stats ================= */2914/* ================= stats ================= */
@@ -3717,6 +3796,155 @@
3717 return TRUE;3796 return TRUE;
3718}3797}
37193798
3799
3800/***********************************************************************
3801Searches for matching tablespace file for given .delta file and space_id
3802in given directory. When matching tablespace found, renames it to match the
3803name of .delta file. If there was a tablespace with matching name and
3804mismatching ID, renames it to xtrabackup_tmp_#ID.ibd. If there was no
3805matching file, creates the new one.
3806@return file handle of matched or created file */
3807static
3808os_file_t
3809xb_delta_open_matching_space(
3810 const char* dbname, /* in: path to destination database dir */
3811 const char* name, /* in: name of delta file (without .delta) */
3812 ulint space_id, /* in: space id of delta file */
3813 ulint zip_size, /* in: zip_size of tablespace */
3814 char* real_name, /* out: full path of destination file */
3815 size_t real_name_len, /* out: buffer size for real_name */
3816 ibool* success) /* out: indicates error. TRUE = success */
3817{
3818 char dest_dir[FN_REFLEN];
3819 char dest_space_name[FN_REFLEN];
3820 ibool ok;
3821 fil_space_t* fil_space;
3822 os_file_t file = 0;
3823
3824 ut_a(dbname || space_id == 0);
3825
3826 *success = FALSE;
3827
3828 if (dbname) {
3829 snprintf(dest_dir, FN_REFLEN, "%s/%s",
3830 xtrabackup_target_dir, dbname);
3831 srv_normalize_path_for_win(dest_dir);
3832
3833 snprintf(dest_space_name, FN_REFLEN, "./%s/%s",
3834 dbname, name);
3835 } else {
3836 snprintf(dest_dir, FN_REFLEN, "%s", xtrabackup_target_dir);
3837 srv_normalize_path_for_win(dest_dir);
3838
3839 snprintf(dest_space_name, FN_REFLEN, "./%s", name);
3840 }
3841
3842 snprintf(real_name, real_name_len,
3843 "%s/%s",
3844 xtrabackup_target_dir, dest_space_name);
3845 srv_normalize_path_for_win(real_name);
3846
3847 /* Create the database directory if it doesn't exist yet */
3848 if (!os_file_create_directory(dest_dir, FALSE)) {
3849 msg("xtrabackup: error: cannot create dir %s\n", dest_dir);
3850 return file;
3851 }
3852
3853 mutex_enter(&fil_system->mutex);
3854 fil_space = xb_space_get_by_name(dest_space_name);
3855 mutex_exit(&fil_system->mutex);
3856
3857 if (fil_space != NULL) {
3858 if (fil_space->id == space_id) {
3859 /* we found matching space */
3860 goto found;
3861 } else {
3862
3863 char tmpname[FN_REFLEN];
3864
3865 snprintf(tmpname, FN_REFLEN, "./%s/xtrabackup_tmp_#%lu",
3866 dbname, fil_space->id);
3867
3868 msg("xtrabackup: Renaming %s to %s.ibd\n",
3869 fil_space->name, tmpname);
3870
3871 if (!fil_rename_tablespace(NULL,
3872 fil_space->id, tmpname))
3873 {
3874 msg("xtrabackup: Cannot rename %s to %s\n",
3875 fil_space->name, tmpname);
3876 goto exit;
3877 }
3878 }
3879 }
3880
3881 mutex_enter(&fil_system->mutex);
3882 fil_space = xb_space_get_by_id(space_id);
3883 mutex_exit(&fil_system->mutex);
3884 if (fil_space != NULL) {
3885 char tmpname[FN_REFLEN];
3886
3887 strncpy(tmpname, dest_space_name, FN_REFLEN);
3888 tmpname[strlen(tmpname) - 4] = 0;
3889
3890 msg("xtrabackup: Renaming %s to %s\n",
3891 fil_space->name, dest_space_name);
3892
3893 if (!fil_rename_tablespace(NULL,
3894 fil_space->id, tmpname))
3895 {
3896 msg("xtrabackup: Cannot rename %s to %s\n",
3897 fil_space->name, dest_space_name);
3898 goto exit;
3899 }
3900
3901 goto found;
3902 }
3903
3904 /* no matching space found. create the new one */
3905
3906#ifdef INNODB_VERSION_SHORT
3907 if (!fil_space_create(dest_space_name, space_id,
3908 zip_size, FIL_TABLESPACE)) {
3909#else
3910 if (!fil_space_create(dest_space_name, space_id,
3911 FIL_TABLESPACE)) {
3912#endif
3913 msg("xtrabackup: Cannot create tablespace %s\n",
3914 dest_space_name);
3915 goto exit;
3916 }
3917
3918 file = xb_file_create_no_error_handling(real_name, OS_FILE_CREATE,
3919 OS_FILE_READ_WRITE,
3920 &ok);
3921
3922 if (ok) {
3923 *success = TRUE;
3924 } else {
3925 msg("xtrabackup: Cannot open file %s\n", real_name);
3926 }
3927
3928 goto exit;
3929
3930found:
3931 /* open the file and return it's handle */
3932
3933 file = xb_file_create_no_error_handling(real_name, OS_FILE_OPEN,
3934 OS_FILE_READ_WRITE,
3935 &ok);
3936
3937 if (ok) {
3938 *success = TRUE;
3939 } else {
3940 msg("xtrabackup: Cannot open file %s\n", real_name);
3941 }
3942
3943exit:
3944
3945 return file;
3946}
3947
3720/************************************************************************3948/************************************************************************
3721Applies a given .delta file to the corresponding data file.3949Applies a given .delta file to the corresponding data file.
3722@return TRUE on success */3950@return TRUE on success */
@@ -3734,6 +3962,7 @@
3734 char src_path[FN_REFLEN];3962 char src_path[FN_REFLEN];
3735 char dst_path[FN_REFLEN];3963 char dst_path[FN_REFLEN];
3736 char meta_path[FN_REFLEN];3964 char meta_path[FN_REFLEN];
3965 char space_name[FN_REFLEN];
3737 ibool success;3966 ibool success;
37383967
3739 ibool last_buffer = FALSE;3968 ibool last_buffer = FALSE;
@@ -3761,6 +3990,9 @@
3761 }3990 }
3762 dst_path[strlen(dst_path) - 6] = '\0';3991 dst_path[strlen(dst_path) - 6] = '\0';
37633992
3993 strncpy(space_name, filename, FN_REFLEN);
3994 space_name[strlen(space_name) - 6] = 0;
3995
3764 if (!get_meta_path(src_path, meta_path)) {3996 if (!get_meta_path(src_path, meta_path)) {
3765 goto error;3997 goto error;
3766 }3998 }
@@ -3798,36 +4030,11 @@
37984030
3799 xb_file_set_nocache(src_file, src_path, "OPEN");4031 xb_file_set_nocache(src_file, src_path, "OPEN");
38004032
3801 dst_file = xb_file_create_no_error_handling(dst_path, OS_FILE_OPEN,4033 dst_file = xb_delta_open_matching_space(
3802 OS_FILE_READ_WRITE,4034 dbname, space_name, info.space_id,
3803 &success);4035 info.page_size == UNIV_PAGE_SIZE ? 0 : info.page_size,
3804again:4036 dst_path, sizeof(dst_path), &success);
3805 if (!success) {4037 if (!success) {
3806 ulint errcode = os_file_get_last_error(TRUE);
3807
3808 if (errcode == OS_FILE_NOT_FOUND) {
3809 msg("xtrabackup: target data file %s "
3810 "is not found, creating a new one\n", dst_path);
3811 /* Create the database directory if it doesn't exist yet
3812 */
3813 if (dbname) {
3814 char dst_dir[FN_REFLEN];
3815
3816 snprintf(dst_dir, sizeof(dst_dir), "%s/%s",
3817 xtrabackup_real_target_dir, dbname);
3818 srv_normalize_path_for_win(dst_dir);
3819
3820 if (!os_file_create_directory(dst_dir, FALSE))
3821 goto error;
3822 }
3823 dst_file =
3824 xb_file_create_no_error_handling(dst_path,
3825 OS_FILE_CREATE,
3826 OS_FILE_READ_WRITE,
3827 &success);
3828 goto again;
3829 }
3830
3831 msg("xtrabackup: error: cannot open %s\n", dst_path);4038 msg("xtrabackup: error: cannot open %s\n", dst_path);
3832 goto error;4039 goto error;
3833 }4040 }
@@ -3842,7 +4049,7 @@
3842 incremental_buffer = ut_align(incremental_buffer_base,4049 incremental_buffer = ut_align(incremental_buffer_base,
3843 UNIV_PAGE_SIZE_MAX);4050 UNIV_PAGE_SIZE_MAX);
38444051
3845 msg("Applying %s ...\n", src_path);4052 msg("Applying %s to %s...\n", src_path, dst_path);
38464053
3847 while (!last_buffer) {4054 while (!last_buffer) {
3848 ulint cluster_header;4055 ulint cluster_header;
@@ -4150,6 +4357,8 @@
4150static void4357static void
4151xtrabackup_prepare_func(void)4358xtrabackup_prepare_func(void)
4152{4359{
4360 ulint err;
4361
4153 /* cd to target-dir */4362 /* cd to target-dir */
41544363
4155 if (my_setwd(xtrabackup_real_target_dir,MYF(MY_WME)))4364 if (my_setwd(xtrabackup_real_target_dir,MYF(MY_WME)))
@@ -4220,12 +4429,29 @@
4220 if(xtrabackup_init_temp_log())4429 if(xtrabackup_init_temp_log())
4221 goto error;4430 goto error;
42224431
4223 if(xtrabackup_incremental && !xtrabackup_apply_deltas(TRUE))4432 if(innodb_init_param())
4224 goto error;4433 goto error;
42254434
4435 mem_init(srv_mem_pool_size);
4436 if (xtrabackup_incremental) {
4437 err = xb_data_files_init();
4438 if (err != DB_SUCCESS) {
4439 msg("xtrabackup: error: xb_data_files_init() failed with"
4440 "error code %lu\n", err);
4441 goto error;
4442 }
4443
4444 if(!xtrabackup_apply_deltas(TRUE)) {
4445 xb_data_files_close();
4446 goto error;
4447 }
4448
4449 xb_data_files_close();
4450 }
4226 sync_close();4451 sync_close();
4227 sync_initialized = FALSE;4452 sync_initialized = FALSE;
4228 os_sync_free();4453 os_sync_free();
4454 mem_close();
4229 os_sync_mutex = NULL;4455 os_sync_mutex = NULL;
4230 ut_free_all_mem();4456 ut_free_all_mem();
42314457
42324458
=== modified file 'src/xtrabackup.h'
--- src/xtrabackup.h 2012-05-28 16:49:14 +0000
+++ src/xtrabackup.h 2012-07-11 09:06:21 +0000
@@ -23,6 +23,7 @@
2323
24typedef struct {24typedef struct {
25 ulint page_size;25 ulint page_size;
26 ulint space_id;
26} xb_delta_info_t;27} xb_delta_info_t;
2728
28typedef enum {29typedef enum {
2930
=== added file 'test/t/bug932623.sh'
--- test/t/bug932623.sh 1970-01-01 00:00:00 +0000
+++ test/t/bug932623.sh 2012-07-11 09:06:21 +0000
@@ -0,0 +1,85 @@
1########################################################################
2# Bug #932623: RENAME TABLE causes incremental prepare to fail
3########################################################################
4
5. inc/common.sh
6
7start_server --innodb_file_per_table
8
9run_cmd $MYSQL $MYSQL_ARGS test <<EOF
10CREATE TABLE t1_old(a INT) ENGINE=InnoDB;
11INSERT INTO t1_old VALUES (1), (2), (3);
12
13CREATE TABLE t1(a INT) ENGINE=InnoDB;
14INSERT INTO t1 VALUES (4), (5), (6);
15EOF
16
17# Full backup
18# backup root directory
19vlog "Starting backup"
20innobackupex --no-timestamp $topdir/full
21
22vlog "Rotating the table"
23
24run_cmd $MYSQL $MYSQL_ARGS test <<EOF
25CREATE TABLE t1_new(a int) ENGINE=InnoDB;
26INSERT INTO t1_new VALUES (7), (8), (9);
27
28CREATE DATABASE db2;
29RENAME TABLE t1_old TO db2.t1;
30
31RENAME TABLE t1 TO t1_old;
32RENAME TABLE t1_new TO t1;
33
34INSERT INTO t1_old VALUES (10), (11), (12);
35INSERT INTO t1 VALUES (13), (14), (15);
36
37EOF
38
39vlog "Creating incremental backup"
40
41innobackupex --incremental --no-timestamp \
42 --incremental-basedir=$topdir/full $topdir/inc
43
44vlog "Preparing backup"
45
46innobackupex --apply-log --redo-only $topdir/full
47vlog "Log applied to full backup"
48
49innobackupex --apply-log --redo-only --incremental-dir=$topdir/inc \
50 $topdir/full
51vlog "Delta applied to full backup"
52
53innobackupex --apply-log $topdir/full
54vlog "Data prepared for restore"
55
56checksum_t1_a=`checksum_table test t1`
57checksum_t1_old_a=`checksum_table test t1_old`
58checksum_t1_db2_a=`checksum_table db2 t1`
59
60# Destroying mysql data
61stop_server
62rm -rf $mysql_datadir/*
63vlog "Data destroyed"
64
65# Restore backup
66vlog "Copying files"
67
68innobackupex --copy-back $topdir/full
69vlog "Data restored"
70
71start_server --innodb_file_per_table
72
73vlog "Checking checksums"
74checksum_t1_b=`checksum_table test t1`
75checksum_t1_old_b=`checksum_table test t1_old`
76checksum_t1_db2_b=`checksum_table db2 t1`
77
78if [ "$checksum_t1_a" != "$checksum_t1_b" -o "$checksum_t1_old_a" != "$checksum_t1_old_b" \
79 -o "$checksum_t1_db2_a" != "$checksum_t1_db2_b" ]
80then
81 vlog "Checksums do not match"
82 exit -1
83fi
84
85vlog "Checksums are OK"

Subscribers

People subscribed via source and target branches