drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
xtrabackup.cc
1/******************************************************
2XtraBackup: The another hot backup tool for InnoDB
3(c) 2009 Percona Inc.
4(C) 2011 Stewart Smith
5Created 3/3/2009 Yasufumi Kinoshita
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20*******************************************************/
21
22#ifndef XTRABACKUP_VERSION
23#define XTRABACKUP_VERSION "undefined"
24#endif
25#ifndef XTRABACKUP_REVISION
26#define XTRABACKUP_REVISION "undefined"
27#endif
28
29#include <config.h>
30#include <algorithm>
31#include <string>
32#include <drizzled/internal/my_sys.h>
33#include <drizzled/charset.h>
34#include <drizzled/gettext.h>
35#include <drizzled/constrained_value.h>
36#include <drizzled/configmake.h>
37#include <drizzled/error/priority_t.h>
38
39#include "ha_prototypes.h"
40 //#define XTRABACKUP_TARGET_IS_PLUGIN
41#include <boost/program_options.hpp>
42#include <boost/scoped_array.hpp>
43#include <boost/scoped_ptr.hpp>
44
45typedef drizzled::charset_info_st CHARSET_INFO;
46
47#define my_progname "xtrabackup"
48
49#define MYSQL_VERSION_ID 50507 /* Drizzle is much greater */
50
51#include <univ.i>
52#include <os0file.h>
53#include <os0thread.h>
54#include <srv0start.h>
55#include <srv0srv.h>
56#include <trx0roll.h>
57#include <trx0trx.h>
58#include <trx0sys.h>
59#include <mtr0mtr.h>
60#include <row0ins.h>
61#include <row0mysql.h>
62#include <row0sel.h>
63#include <row0upd.h>
64#include <log0log.h>
65#include <log0recv.h>
66#include <lock0lock.h>
67#include <dict0crea.h>
68#include <btr0cur.h>
69#include <btr0btr.h>
70#include <btr0sea.h>
71#include <fsp0fsp.h>
72#include <sync0sync.h>
73#include <fil0fil.h>
74#include <trx0xa.h>
75
76#ifdef INNODB_VERSION_SHORT
77#include <ibuf0ibuf.h>
78#else
79#error ENOCOOL
80#endif
81
82#define IB_INT64 ib_int64_t
83#define LSN64 ib_uint64_t
84#define MACH_READ_64 mach_read_from_8
85#define MACH_WRITE_64 mach_write_to_8
86#define OS_MUTEX_CREATE() os_mutex_create()
87#define ut_dulint_zero 0
88#define ut_dulint_cmp(A, B) (A > B ? 1 : (A == B ? 0 : -1))
89#define ut_dulint_add(A, B) (A + B)
90#define ut_dulint_minus(A, B) (A - B)
91#define ut_dulint_align_down(A, B) (A & ~((ib_int64_t)B - 1))
92#define ut_dulint_align_up(A, B) ((A + B - 1) & ~((ib_int64_t)B - 1))
93
94#ifdef __WIN__
95#define SRV_PATH_SEPARATOR '\\'
96#define SRV_PATH_SEPARATOR_STR "\\"
97#else
98#define SRV_PATH_SEPARATOR '/'
99#define SRV_PATH_SEPARATOR_STR "/"
100#endif
101
102#ifndef UNIV_PAGE_SIZE_MAX
103#define UNIV_PAGE_SIZE_MAX UNIV_PAGE_SIZE
104#endif
105#ifndef UNIV_PAGE_SIZE_SHIFT_MAX
106#define UNIV_PAGE_SIZE_SHIFT_MAX UNIV_PAGE_SIZE_SHIFT
107#endif
108
109using namespace drizzled;
110namespace po=boost::program_options;
111
112static void xb_copy_padded(char* to, size_t to_size, const char* from)
113{
114 size_t copy_size = std::min(strlen(from), to_size);
115
116 memset(to, 0, to_size);
117 memcpy(to, from, copy_size);
118}
119
120namespace drizzled {
121 bool errmsg_printf (error::priority_t, char const *format, ...);
122
123 bool errmsg_printf (error::priority_t, char const *format, ...)
124 {
125 bool rv;
126 va_list args;
127 va_start(args, format);
128 rv= vfprintf(stderr, format, args);
129 va_end(args);
130 fprintf(stderr, "\n");
131 return rv;
132 }
133
134}
135
136#include "xtrabackup_api.h"
137
138 #include <fcntl.h>
139 #include <regex.h>
140
141 #ifdef POSIX_FADV_NORMAL
142 #define USE_POSIX_FADVISE
143 #endif
144
145 /* ==start === definition at fil0fil.c === */
146 // ##################################################################
147 // NOTE: We should check the following definitions fit to the source.
148 // ##################################################################
149
150 //Plugin ?
152 struct fil_node_struct {
153 fil_space_t* space;
155 char* name;
156 ibool open;
158 ibool is_raw_disk;
160 ulint size;
163 ulint n_pending;
167 ulint n_pending_flushes;
171 ib_int64_t modification_counter;
173 ib_int64_t flush_counter;
180 ulint magic_n;
181 };
182
183 struct fil_space_struct {
184 char* name;
186 ulint id;
187 ib_int64_t tablespace_version;
193 ibool mark;
197 ibool stop_ios;
201 ibool stop_ibuf_merges;
204 ibool is_being_deleted;
211 ulint purpose;
215 ulint size;
219 ulint flags;
220 ulint n_reserved_extents;
223 ulint n_pending_flushes;
232 hash_node_t hash;
233 hash_node_t name_hash;
234 #ifndef UNIV_HOTBACKUP
235 rw_lock_t latch;
237 #endif /* !UNIV_HOTBACKUP */
238 UT_LIST_NODE_T(fil_space_t) unflushed_spaces;
243 #ifdef XTRADB_BASED
244 ibool is_corrupt;
245 #endif
246 UT_LIST_NODE_T(fil_space_t) space_list;
248 ulint magic_n;
249 };
250
251 typedef struct fil_system_struct fil_system_t;
252
253 struct fil_system_struct {
254 #ifndef UNIV_HOTBACKUP
255 mutex_t mutex;
256 #ifdef XTRADB55
257 mutex_t file_extend_mutex;
258 #endif
259 #endif /* !UNIV_HOTBACKUP */
260 hash_table_t* spaces;
263 hash_table_t* name_hash;
276 UT_LIST_BASE_NODE_T(fil_space_t) unflushed_spaces;
282 ulint n_open;
283 ulint max_n_open;
285 ib_int64_t modification_counter;
287 ulint max_assigned_id;
293 ib_int64_t tablespace_version;
301 UT_LIST_BASE_NODE_T(fil_space_t) space_list;
303 };
304
305 typedef struct {
306 ulint page_size;
308
309 extern fil_system_t* fil_system;
310
311 /* ==end=== definition at fil0fil.c === */
312
313
314 bool innodb_inited= 0;
315
316 /* === xtrabackup specific options === */
317 char xtrabackup_real_target_dir[FN_REFLEN] = "./xtrabackup_backupfiles/";
318 const char *xtrabackup_target_dir= xtrabackup_real_target_dir;
319 bool xtrabackup_backup = false;
320 bool xtrabackup_stats = false;
321 bool xtrabackup_prepare = false;
322 bool xtrabackup_print_param = false;
323
324 bool xtrabackup_export = false;
325 bool xtrabackup_apply_log_only = false;
326
327 bool xtrabackup_suspend_at_end = false;
328 uint64_t xtrabackup_use_memory = 100*1024*1024L;
329 bool xtrabackup_create_ib_logfile = false;
330
331 long xtrabackup_throttle = 0; /* 0:unlimited */
332 lint io_ticket;
333 os_event_t wait_throttle = NULL;
334
335 bool xtrabackup_stream = false;
336const char *xtrabackup_incremental = NULL;
337 LSN64 incremental_lsn;
338 LSN64 incremental_to_lsn;
339 LSN64 incremental_last_lsn;
340 byte* incremental_buffer = NULL;
341 byte* incremental_buffer_base = NULL;
342
343const char *xtrabackup_incremental_basedir = NULL; /* for --backup */
344const char *xtrabackup_extra_lsndir = NULL; /* for --backup with --extra-lsndir */
345char *xtrabackup_incremental_dir = NULL; /* for --prepare */
346
347 char *xtrabackup_tables = NULL;
348 int tables_regex_num;
349 regex_t *tables_regex;
350 regmatch_t tables_regmatch[1];
351
352const char *xtrabackup_tables_file = NULL;
353 hash_table_t* tables_hash;
354
356 char* name;
357 hash_node_t name_hash;
358 };
359 typedef struct xtrabackup_tables_struct xtrabackup_tables_t;
360
361 #ifdef XTRADB_BASED
362 static ulint thread_nr[SRV_MAX_N_IO_THREADS + 6 + 64];
363 static os_thread_id_t thread_ids[SRV_MAX_N_IO_THREADS + 6 + 64];
364 #else
365 static ulint thread_nr[SRV_MAX_N_IO_THREADS + 6];
366 static os_thread_id_t thread_ids[SRV_MAX_N_IO_THREADS + 6];
367 #endif
368
369 LSN64 checkpoint_lsn_start;
370 LSN64 checkpoint_no_start;
371 LSN64 log_copy_scanned_lsn;
372 IB_INT64 log_copy_offset = 0;
373 ibool log_copying = TRUE;
374 ibool log_copying_running = FALSE;
375 ibool log_copying_succeed = FALSE;
376
377 ibool xtrabackup_logfile_is_renamed = FALSE;
378
379 uint parallel;
380
381 /* === metadata of backup === */
382 #define XTRABACKUP_METADATA_FILENAME "xtrabackup_checkpoints"
383 char metadata_type[30] = ""; /*[full-backuped|full-prepared|incremental]*/
384
385 ib_uint64_t metadata_from_lsn = 0;
386 ib_uint64_t metadata_to_lsn = 0;
387 ib_uint64_t metadata_last_lsn = 0;
388
389 #define XB_DELTA_INFO_SUFFIX ".meta"
390
391 /* === sharing with thread === */
392 os_file_t dst_log = -1;
393 char dst_log_path[FN_REFLEN];
394
395 /* === some variables from mysqld === */
396 char mysql_real_data_home[FN_REFLEN] = "./";
397 char *mysql_data_home= mysql_real_data_home;
398std::string mysql_data_home_arg;
399 static char mysql_data_home_buff[2];
400
401const char *opt_mysql_tmpdir = NULL;
402
403/* === static parameters in ha_innodb.cc */
404
405#define HA_INNOBASE_ROWS_IN_TABLE 10000 /* to get optimization right */
406#define HA_INNOBASE_RANGE_COUNT 100
407
408ulong innobase_large_page_size = 0;
409
410/* The default values for the following, type long or longlong, start-up
411parameters are declared in mysqld.cc: */
412
413long innobase_additional_mem_pool_size = 1*1024*1024L;
414long innobase_buffer_pool_awe_mem_mb = 0;
415long innobase_file_io_threads = 4;
416long innobase_read_io_threads = 4;
417long innobase_write_io_threads = 4;
418long innobase_force_recovery = 0;
419long innobase_lock_wait_timeout = 50;
420long innobase_log_buffer_size = 1024*1024L;
421long innobase_log_files_in_group = 2;
422long innobase_log_files_in_group_backup;
423long innobase_mirrored_log_groups = 1;
424long innobase_open_files = 300L;
425
426long innobase_page_size = (1 << 14); /* 16KB */
427static ulong innobase_log_block_size = 512;
428bool innobase_fast_checksum = false;
429bool innobase_extra_undoslots = false;
430char* innobase_doublewrite_file = NULL;
431
432uint64_t innobase_buffer_pool_size = 8*1024*1024L;
433
435static log_file_constraint innobase_log_file_size;
436
437uint64_t innobase_log_file_size_backup;
438
439/* The default values for the following char* start-up parameters
440are determined in innobase_init below: */
441
442char* innobase_data_home_dir = NULL;
443const char* innobase_data_file_path = NULL;
444char* innobase_log_group_home_dir = NULL;
445char* innobase_log_group_home_dir_backup = NULL;
446char* innobase_log_arch_dir = NULL;/* unused */
447/* The following has a misleading name: starting from 4.0.5, this also
448affects Windows: */
449char* innobase_unix_file_flush_method = NULL;
450
451/* Below we have boolean-valued start-up parameters, and their default
452values */
453
454ulong innobase_fast_shutdown = 1;
455bool innobase_log_archive = FALSE;/* unused */
456bool innobase_use_doublewrite = TRUE;
457bool innobase_use_checksums = TRUE;
458bool innobase_use_large_pages = FALSE;
459bool innobase_file_per_table = FALSE;
460bool innobase_locks_unsafe_for_binlog = FALSE;
461bool innobase_rollback_on_timeout = FALSE;
462bool innobase_create_status_file = FALSE;
463bool innobase_adaptive_hash_index = TRUE;
464
465static char *internal_innobase_data_file_path = NULL;
466
467/* The following counter is used to convey information to InnoDB
468about server activity: in selects it is not sensible to call
469srv_active_wake_master_thread after each fetch or search, we only do
470it every INNOBASE_WAKE_INTERVAL'th step. */
471
472#define INNOBASE_WAKE_INTERVAL 32
473ulong innobase_active_counter = 0;
474
475UNIV_INTERN
476bool
477innobase_isspace(
478 const void *cs,
479 char char_to_test)
480{
481 return static_cast<const CHARSET_INFO*>(cs)->isspace(char_to_test);
482}
483
484/******************************************************************/
487const char*
489/*==============*/
490 const char* path_name)
491{
492 const char* name = path_name + drizzled::internal::dirname_length(path_name);
493
494 return((name) ? name : "null");
495}
496
497UNIV_INTERN
498void
500 Table* ,
501 const rec_t* ,
502 const dict_index_t* ,
503 const ulint* );
504
505UNIV_INTERN
506void
508/*==================*/
509 Table* ,
510 const rec_t* ,
511 const dict_index_t* ,
512 const ulint* )
514{
515 fprintf(stderr, "ERROR: innobase_rec_to_mysql called\n");
516 return;
517}
518
519UNIV_INTERN
520void
522
523UNIV_INTERN
524void
526/*===============*/
527 Table* )
528{
529 fprintf(stderr, "ERROR: innobase_rec_reset called\n");
530 return;
531}
532
533UNIV_INTERN
534void
536/*===================*/
538 ulint )
539{
540 return;
541}
542
543
544
545/* ======== Datafiles iterator ======== */
546typedef struct {
547 fil_system_t *system;
548 fil_space_t *space;
549 fil_node_t *node;
550 ibool started;
551 os_mutex_t mutex;
553
554static
556datafiles_iter_new(fil_system_t *f_system)
557{
559
561 it->mutex = OS_MUTEX_CREATE();
562
563 it->system = f_system;
564 it->space = NULL;
565 it->node = NULL;
566 it->started = FALSE;
567
568 return it;
569}
570
571static
573datafiles_iter_next(datafiles_iter_t *it, ibool *space_changed)
574{
575 os_mutex_enter(it->mutex);
576
577 *space_changed = FALSE;
578
579 if (it->node == NULL) {
580 if (it->started)
581 goto end;
582 it->started = TRUE;
583 } else {
584 it->node = UT_LIST_GET_NEXT(chain, it->node);
585 if (it->node != NULL)
586 goto end;
587 }
588
589 it->space = (it->space == NULL) ?
590 UT_LIST_GET_FIRST(it->system->space_list) :
591 UT_LIST_GET_NEXT(space_list, it->space);
592
593 while (it->space != NULL &&
594 (it->space->purpose != FIL_TABLESPACE ||
595 UT_LIST_GET_LEN(it->space->chain) == 0))
596 it->space = UT_LIST_GET_NEXT(space_list, it->space);
597 if (it->space == NULL)
598 goto end;
599 *space_changed = TRUE;
600
601 it->node = UT_LIST_GET_FIRST(it->space->chain);
602
603end:
604 os_mutex_exit(it->mutex);
605
606 return it->node;
607}
608
609static
610void
611datafiles_iter_free(datafiles_iter_t *it)
612{
613 os_mutex_free(it->mutex);
614 ut_free(it);
615}
616
617/* ======== Date copying thread context ======== */
618
619typedef struct {
621 uint num;
622 uint *count;
623 os_mutex_t count_mutex;
626
627static void print_version(void)
628{
629 printf("%s Ver %s Rev %s for %s %s (%s)\n" ,my_progname,
630 XTRABACKUP_VERSION, XTRABACKUP_REVISION, "Drizzle",
631 TARGET_OS, TARGET_CPU);
632}
633
634static void usage(void)
635{
636 puts("Open source backup tool for InnoDB and XtraDB\n\
637\n\
638Copyright (C) 2009 Percona Inc.\n\
639\n\
640This program is free software; you can redistribute it and/or\n\
641modify it under the terms of the GNU General Public License\n\
642as published by the Free Software Foundation version 2\n\
643of the License.\n\
644\n\
645This program is distributed in the hope that it will be useful,\n\
646but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
647MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
648GNU General Public License for more details.\n\
649\n\
650You can download full text of the license on http://www.gnu.org/licenses/gpl-2.0.txt\n");
651
652 printf("Usage: [%s [--defaults-file=#] --backup | %s [--defaults-file=#] --prepare] [OPTIONS]\n",my_progname,my_progname);
653 // FIXME: print what variables we have
654}
655
656/* ================ Dummys =================== */
657
658UNIV_INTERN
659ibool
661/*============================*/
663{
664 fprintf(stderr, "xtrabackup: thd_is_replication_slave_thread() is called\n");
665 return(FALSE);
666}
667
668UNIV_INTERN
669ibool
671/*===========================*/
673{
674 fprintf(stderr, "xtrabackup: thd_has_edited_nontrans_tables() is called\n");
675 return(FALSE);
676}
677
678UNIV_INTERN
679ibool
681/*==========*/
682 const drizzled::Session *)
683{
684 fprintf(stderr, "xtrabackup: thd_is_select() is called\n");
685 return(false);
686}
687
688UNIV_INTERN
689void
691 FILE*,
693 uint)
694{
695 fprintf(stderr, "xtrabackup: innobase_mysql_print_thd() is called\n");
696}
697
698void
700 ulint cset,
701 ulint* mbminlen,
702 ulint* mbmaxlen)
703{
704 CHARSET_INFO* cs;
705 ut_ad(cset < 256);
706 ut_ad(mbminlen);
707 ut_ad(mbmaxlen);
708
709 cs = all_charsets[cset];
710 if (cs) {
711 *mbminlen = cs->mbminlen;
712 *mbmaxlen = cs->mbmaxlen;
713 } else {
714 ut_a(cset == 0);
715 *mbminlen = *mbmaxlen = 0;
716 }
717}
718
719UNIV_INTERN
720void
722/*===========================*/
723 const void*,
724 char* ,
725 const char* ,
726 ulint )
727{
728 fprintf(stderr, "xtrabackup: innobase_convert_from_table_id() is called\n");
729}
730
731UNIV_INTERN
732void
734/*=====================*/
735 const void*,
736 char* ,
737 const char* ,
738 ulint )
739{
740 fprintf(stderr, "xtrabackup: innobase_convert_from_id() is called\n");
741}
742
743int
745 const char* a,
746 const char* b)
747{
748 return my_charset_utf8_general_ci.strcasecmp(a, b);
749}
750
751void
753 char* a)
754{
755 my_charset_utf8_general_ci.casedn_str(a);
756}
757
758UNIV_INTERN
759const char*
761/*==============*/
763 size_t* )
764{
765 fprintf(stderr, "xtrabackup: innobase_get_stmt() is called\n");
766 return("nothing");
767}
768
769int
771{
772 char filename[FN_REFLEN];
773 int fd2 = -1;
774 int fd = internal::create_temp_file(filename, opt_mysql_tmpdir,
775 "ib",
776#ifdef __WIN__
777 O_BINARY | O_TRUNC | O_SEQUENTIAL |
778 O_TEMPORARY | O_SHORT_LIVED |
779#endif /* __WIN__ */
780 O_CREAT | O_EXCL | O_RDWR);
781 if (fd >= 0) {
782#ifndef __WIN__
783 /* On Windows, open files cannot be removed, but files can be
784 created with the O_TEMPORARY flag to the same effect
785 ("delete on close"). */
786 unlink(filename);
787#endif /* !__WIN__ */
788 /* Copy the file descriptor, so that the additional resources
789 allocated by create_temp_file() can be freed by invoking
790 my_close().
791
792 Because the file descriptor returned by this function
793 will be passed to fdopen(), it will be closed by invoking
794 fclose(), which in turn will invoke close() instead of
795 my_close(). */
796 fd2 = dup(fd);
797 if (fd2 < 0) {
798 fprintf(stderr, "xtrabackup: Got error %d on dup\n",fd2);
799 }
800 close(fd);
801 }
802 return(fd2);
803}
804
805void
807 trx_t* ,
808 const char* ,
809 ulint )
810{
811 /* do nothing */
812}
813
814/*****************************************************************/
818static
819char*
821/*========================*/
822 char* buf,
823 ulint buflen,
824 const char* id,
825 ulint idlen,
826 void* ,
827 ibool )
829{
830 const char* s = id;
831 int q;
832
833 /* See if the identifier needs to be quoted. */
834 q = '"';
835
836 if (q == EOF) {
837 if (UNIV_UNLIKELY(idlen > buflen)) {
838 idlen = buflen;
839 }
840 memcpy(buf, s, idlen);
841 return(buf + idlen);
842 }
843
844 /* Quote the identifier. */
845 if (buflen < 2) {
846 return(buf);
847 }
848
849 *buf++ = q;
850 buflen--;
851
852 for (; idlen; idlen--) {
853 int c = *s++;
854 if (UNIV_UNLIKELY(c == q)) {
855 if (UNIV_UNLIKELY(buflen < 3)) {
856 break;
857 }
858
859 *buf++ = c;
860 *buf++ = c;
861 buflen -= 2;
862 } else {
863 if (UNIV_UNLIKELY(buflen < 2)) {
864 break;
865 }
866
867 *buf++ = c;
868 buflen--;
869 }
870 }
871
872 *buf++ = q;
873 return(buf);
874}
875
876/*****************************************************************/
880UNIV_INTERN
881char*
883/*==================*/
884 char* buf,
885 ulint buflen,
886 const char* id,
887 ulint idlen,
888 drizzled::Session *session,
889 ibool table_id)
891{
892 char* s = buf;
893 const char* bufend = buf + buflen;
894
895 if (table_id) {
896 const char* slash = (const char*) memchr(id, '/', idlen);
897 if (!slash) {
898
899 goto no_db_name;
900 }
901
902 /* Print the database name and table name separately. */
903 s = innobase_convert_identifier(s, bufend - s, id, slash - id,
904 session, TRUE);
905 if (UNIV_LIKELY(s < bufend)) {
906 *s++ = '.';
907 s = innobase_convert_identifier(s, bufend - s,
908 slash + 1, idlen
909 - (slash - id) - 1,
910 session, TRUE);
911 }
912 } else if (UNIV_UNLIKELY(*id == TEMP_INDEX_PREFIX)) {
913 /* Temporary index name (smart ALTER TABLE) */
914 const char temp_index_suffix[]= "--temporary--";
915
916 s = innobase_convert_identifier(buf, buflen, id + 1, idlen - 1,
917 session, FALSE);
918 if (s - buf + (sizeof temp_index_suffix - 1) < buflen) {
919 memcpy(s, temp_index_suffix,
920 sizeof temp_index_suffix - 1);
921 s += sizeof temp_index_suffix - 1;
922 }
923 } else {
924no_db_name:
925 s = innobase_convert_identifier(buf, buflen, id, idlen,
926 session, table_id);
927 }
928
929 return(s);
930
931}
932
933ibool
935 trx_t* )
936{
937 /* There are no mysql_thd */
938 return(FALSE);
939}
940
941UNIV_INTERN int
943/*===============*/
944 int mysql_type,
945 uint charset_number,
946 const unsigned char* a,
947 unsigned int a_length,
949 const unsigned char* b, /* in: data field */
950 unsigned int b_length); /* in: data field length,
951 not UNIV_SQL_NULL */
952
953int
955/*===============*/
956 /* out: 1, 0, -1, if a is greater, equal, less than b, respectively */
957 int mysql_type, /* in: MySQL type */
958 uint charset_number, /* in: number of the charset */
959 const unsigned char* a, /* in: data field */
960 unsigned int a_length, /* in: data field length, not UNIV_SQL_NULL */
961 const unsigned char* b, /* in: data field */
962 unsigned int b_length) /* in: data field length, not UNIV_SQL_NULL */
963{
964 const CHARSET_INFO* charset;
965 enum_field_types mysql_tp;
966 int ret;
967
968 assert(a_length != UNIV_SQL_NULL);
969 assert(b_length != UNIV_SQL_NULL);
970
971 mysql_tp = (enum_field_types) mysql_type;
972
973 switch (mysql_tp) {
974
975 case DRIZZLE_TYPE_BLOB:
976 case DRIZZLE_TYPE_VARCHAR:
977 /* Use the charset number to pick the right charset struct for
978 the comparison. Since the MySQL function get_charset may be
979 slow before Bar removes the mutex operation there, we first
980 look at 2 common charsets directly. */
981
982 if (charset_number == default_charset_info->number) {
983 charset = default_charset_info;
984 } else {
985 charset = get_charset(charset_number);
986
987 if (charset == NULL) {
988 fprintf(stderr, "xtrabackup needs charset %lu for doing "
989 "a comparison, but MySQL cannot "
990 "find that charset.",
991 (ulong) charset_number);
992 ut_a(0);
993 }
994 }
995
996 /* Starting from 4.1.3, we use strnncollsp() in comparisons of
997 non-latin1_swedish_ci strings. NOTE that the collation order
998 changes then: 'b\0\0...' is ordered BEFORE 'b ...'. Users
999 having indexes on such data need to rebuild their tables! */
1000
1001 ret = charset->coll->strnncollsp(charset,
1002 a, a_length,
1003 b, b_length, 0);
1004 if (ret < 0) {
1005 return(-1);
1006 } else if (ret > 0) {
1007 return(1);
1008 } else {
1009 return(0);
1010 }
1011 default:
1012 ut_error;
1013 }
1014
1015 return(0);
1016}
1017
1018ulint
1020 ulint charset_id,
1021 ulint prefix_len,
1022 ulint data_len,
1023 const char* str)
1024{
1025 ulint char_length; /* character length in bytes */
1026 ulint n_chars; /* number of characters in prefix */
1027 const CHARSET_INFO* charset; /* charset used in the field */
1028
1029 charset = get_charset((uint) charset_id);
1030
1031 ut_ad(charset);
1032 ut_ad(charset->mbmaxlen);
1033
1034 /* Calculate how many characters at most the prefix index contains */
1035
1036 n_chars = prefix_len / charset->mbmaxlen;
1037
1038 /* If the charset is multi-byte, then we must find the length of the
1039 first at most n chars in the string. If the string contains less
1040 characters than n, then we return the length to the end of the last
1041 character. */
1042
1043 if (charset->mbmaxlen > 1) {
1044 /* my_charpos() returns the byte length of the first n_chars
1045 characters, or a value bigger than the length of str, if
1046 there were not enough full characters in str.
1047
1048 Why does the code below work:
1049 Suppose that we are looking for n UTF-8 characters.
1050
1051 1) If the string is long enough, then the prefix contains at
1052 least n complete UTF-8 characters + maybe some extra
1053 characters + an incomplete UTF-8 character. No problem in
1054 this case. The function returns the pointer to the
1055 end of the nth character.
1056
1057 2) If the string is not long enough, then the string contains
1058 the complete value of a column, that is, only complete UTF-8
1059 characters, and we can store in the column prefix index the
1060 whole string. */
1061
1062 char_length = my_charpos(charset, str,
1063 str + data_len, (int) n_chars);
1064 if (char_length > data_len) {
1065 char_length = data_len;
1066 }
1067 } else {
1068 if (data_len < prefix_len) {
1069 char_length = data_len;
1070 } else {
1071 char_length = prefix_len;
1072 }
1073 }
1074
1075 return(char_length);
1076}
1077
1078UNIV_INTERN
1079ulint
1081/*================*/
1082 const char* ,
1083 ulint ,
1085 ulint ,
1086 char* ,
1087 ulint )
1089{
1090 fprintf(stderr, "xtrabackup: innobase_raw_format() is called\n");
1091 return(0);
1092}
1093
1094UNIV_INTERN
1095ulong
1097/*==================*/
1100{
1101 return(innobase_lock_wait_timeout);
1102}
1103
1104UNIV_INTERN
1105ibool
1107/*============*/
1110{
1111 return(FALSE);
1112}
1113
1114ibool
1116/*==========*/
1117 trx_t*)
1118{
1119 return(FALSE);
1120}
1121
1122#ifdef XTRADB_BASED
1123trx_t*
1124innobase_get_trx()
1125{
1126 return(NULL);
1127}
1128
1129ibool
1130innobase_get_slow_log()
1131{
1132 return(FALSE);
1133}
1134#endif
1135
1136/***********************************************************************
1137Computes bit shift for a given value. If the argument is not a power
1138of 2, returns 0.*/
1139UNIV_INLINE
1140ulint
1141get_bit_shift(ulint value)
1142{
1143 ulint shift;
1144
1145 if (value == 0)
1146 return 0;
1147
1148 for (shift = 0; !(value & 1UL); shift++) {
1149 value >>= 1;
1150 }
1151 return (value >> 1) ? 0 : shift;
1152}
1153
1154static bool
1155innodb_init_param(void)
1156{
1157 /* innobase_init */
1158 static char current_dir[3]; /* Set if using current lib */
1159 bool ret;
1160 char *default_path;
1161
1162 /* dummy for initialize all_charsets[] */
1163 get_charset_name(0);
1164
1165#ifdef XTRADB_BASED
1166 srv_page_size = 0;
1167 srv_page_size_shift = 0;
1168
1169 if (innobase_page_size != (1 << 14)) {
1170 int n_shift = get_bit_shift(innobase_page_size);
1171
1172 if (n_shift >= 12 && n_shift <= UNIV_PAGE_SIZE_SHIFT_MAX) {
1173 fprintf(stderr,
1174 "InnoDB: Warning: innodb_page_size has been "
1175 "changed from default value 16384.\n");
1176 srv_page_size_shift = n_shift;
1177 srv_page_size = 1 << n_shift;
1178 fprintf(stderr,
1179 "InnoDB: The universal page size of the "
1180 "database is set to %lu.\n", srv_page_size);
1181 } else {
1182 fprintf(stderr, "InnoDB: Error: invalid value of "
1183 "innobase_page_size: %lu", innobase_page_size);
1184 exit(EXIT_FAILURE);
1185 }
1186 } else {
1187 srv_page_size_shift = 14;
1188 srv_page_size = (1 << srv_page_size_shift);
1189 }
1190
1191 srv_log_block_size = 0;
1192 if (innobase_log_block_size != 512) {
1193 uint n_shift = get_bit_shift(innobase_log_block_size);;
1194
1195 fprintf(stderr,
1196 "InnoDB: Warning: innodb_log_block_size has "
1197 "been changed from its default value. "
1198 "(###EXPERIMENTAL### operation)\n");
1199 if (n_shift > 0) {
1200 srv_log_block_size = (1 << n_shift);
1201 fprintf(stderr,
1202 "InnoDB: The log block size is set to %lu.\n",
1203 srv_log_block_size);
1204 }
1205 } else {
1206 srv_log_block_size = 512;
1207 }
1208
1209 if (!srv_log_block_size) {
1210 fprintf(stderr,
1211 "InnoDB: Error: %lu is not valid value for "
1212 "innodb_log_block_size.\n", innobase_log_block_size);
1213 goto error;
1214 }
1215
1216 srv_fast_checksum = (ibool) innobase_fast_checksum;
1217#endif
1218
1219 /* Check that values don't overflow on 32-bit systems. */
1220 if (sizeof(ulint) == 4) {
1221 if (xtrabackup_use_memory > UINT32_MAX) {
1222 fprintf(stderr,
1223 "xtrabackup: use-memory can't be over 4GB"
1224 " on 32-bit systems\n");
1225 }
1226
1227 if (innobase_buffer_pool_size > UINT32_MAX) {
1228 fprintf(stderr,
1229 "xtrabackup: innobase_buffer_pool_size can't be over 4GB"
1230 " on 32-bit systems\n");
1231
1232 goto error;
1233 }
1234
1235 if (innobase_log_file_size > UINT32_MAX) {
1236 fprintf(stderr,
1237 "xtrabackup: innobase_log_file_size can't be over 4GB"
1238 " on 32-bit systemsi\n");
1239
1240 goto error;
1241 }
1242 }
1243
1244 os_innodb_umask = (ulint)0664;
1245
1246 /* First calculate the default path for innodb_data_home_dir etc.,
1247 in case the user has not given any value.
1248
1249 Note that when using the embedded server, the datadirectory is not
1250 necessarily the current directory of this program. */
1251
1252 /* It's better to use current lib, to keep paths short */
1253 current_dir[0] = FN_CURLIB;
1254 current_dir[1] = FN_LIBCHAR;
1255 current_dir[2] = 0;
1256 default_path = current_dir;
1257
1258 ut_a(default_path);
1259
1260 /* Set InnoDB initialization parameters according to the values
1261 read from MySQL .cnf file */
1262
1263 if (xtrabackup_backup || xtrabackup_stats) {
1264 fprintf(stderr, "xtrabackup: Target instance is assumed as followings.\n");
1265 } else {
1266 fprintf(stderr, "xtrabackup: Temporary instance for recovery is set as followings.\n");
1267 }
1268
1269 /*--------------- Data files -------------------------*/
1270
1271 /* The default dir for data files is the datadir of MySQL */
1272
1273 srv_data_home = ((xtrabackup_backup || xtrabackup_stats) && innobase_data_home_dir
1274 ? innobase_data_home_dir : default_path);
1275 fprintf(stderr, "xtrabackup: innodb_data_home_dir = %s\n", srv_data_home);
1276
1277 /* Set default InnoDB data file size to 10 MB and let it be
1278 auto-extending. Thus users can use InnoDB in >= 4.0 without having
1279 to specify any startup options. */
1280
1281 if (!innobase_data_file_path) {
1282 innobase_data_file_path = (char*) "ibdata1:10M:autoextend";
1283 }
1284 fprintf(stderr, "xtrabackup: innodb_data_file_path = %s\n",
1285 innobase_data_file_path);
1286
1287 /* Since InnoDB edits the argument in the next call, we make another
1288 copy of it: */
1289
1290 internal_innobase_data_file_path = strdup(innobase_data_file_path);
1291
1293 internal_innobase_data_file_path);
1294 if (ret == FALSE) {
1295 fprintf(stderr,
1296 "xtrabackup: syntax error in innodb_data_file_path\n");
1297mem_free_and_error:
1298 free(internal_innobase_data_file_path);
1299 goto error;
1300 }
1301
1302 if (xtrabackup_prepare) {
1303 /* "--prepare" needs filenames only */
1304 ulint i;
1305
1306 for (i=0; i < srv_n_data_files; i++) {
1307 char *p;
1308
1309 p = srv_data_file_names[i];
1310 while ((p = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1311 {
1312 p++;
1313 srv_data_file_names[i] = p;
1314 }
1315 }
1316 }
1317
1318#ifdef XTRADB_BASED
1319 srv_doublewrite_file = innobase_doublewrite_file;
1320#ifndef XTRADB55
1321 srv_extra_undoslots = (ibool) innobase_extra_undoslots;
1322#endif
1323#endif
1324
1325 /* -------------- Log files ---------------------------*/
1326
1327 /* The default dir for log files is the datadir of MySQL */
1328
1329 if (!((xtrabackup_backup || xtrabackup_stats) && innobase_log_group_home_dir)) {
1330 innobase_log_group_home_dir = default_path;
1331 }
1332 if (xtrabackup_prepare && xtrabackup_incremental_dir) {
1333 innobase_log_group_home_dir = xtrabackup_incremental_dir;
1334 }
1335 fprintf(stderr, "xtrabackup: innodb_log_group_home_dir = %s\n",
1336 innobase_log_group_home_dir);
1337
1338#ifdef UNIV_LOG_ARCHIVE
1339 /* Since innodb_log_arch_dir has no relevance under MySQL,
1340 starting from 4.0.6 we always set it the same as
1341 innodb_log_group_home_dir: */
1342
1343 innobase_log_arch_dir = innobase_log_group_home_dir;
1344
1345 srv_arch_dir = innobase_log_arch_dir;
1346#endif /* UNIG_LOG_ARCHIVE */
1347
1348 ret = (bool)
1349 srv_parse_log_group_home_dirs(innobase_log_group_home_dir);
1350
1351 if (ret == FALSE || innobase_mirrored_log_groups != 1) {
1352 fprintf(stderr, "xtrabackup: syntax error in innodb_log_group_home_dir, or a "
1353 "wrong number of mirrored log groups\n");
1354
1355 goto mem_free_and_error;
1356 }
1357
1358 srv_adaptive_flushing = FALSE;
1359 srv_use_sys_malloc = TRUE;
1360 srv_file_format = 1; /* Barracuda */
1362
1363 /* --------------------------------------------------*/
1364
1365 srv_file_flush_method_str = innobase_unix_file_flush_method;
1366
1367 srv_n_log_groups = (ulint) innobase_mirrored_log_groups;
1368 srv_n_log_files = (ulint) innobase_log_files_in_group;
1369 srv_log_file_size = (ulint) innobase_log_file_size;
1370 fprintf(stderr, "xtrabackup: innodb_log_files_in_group = %ld\n",
1371 srv_n_log_files);
1372 fprintf(stderr, "xtrabackup: innodb_log_file_size = %ld\n",
1373 srv_log_file_size);
1374
1375#ifdef UNIV_LOG_ARCHIVE
1376 srv_log_archive_on = (ulint) innobase_log_archive;
1377#endif /* UNIV_LOG_ARCHIVE */
1378 srv_log_buffer_size = (ulint) innobase_log_buffer_size;
1379
1380 /* We set srv_pool_size here in units of 1 kB. InnoDB internally
1381 changes the value so that it becomes the number of database pages. */
1382
1383 //srv_buf_pool_size = (ulint) innobase_buffer_pool_size;
1384 srv_buf_pool_size = (ulint) xtrabackup_use_memory;
1385
1386 srv_mem_pool_size = (ulint) innobase_additional_mem_pool_size;
1387
1388 srv_n_file_io_threads = (ulint) innobase_file_io_threads;
1389
1390 srv_n_read_io_threads = (ulint) innobase_read_io_threads;
1391 srv_n_write_io_threads = (ulint) innobase_write_io_threads;
1392
1393 srv_force_recovery = (ulint) innobase_force_recovery;
1394
1395 srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite;
1396 srv_use_checksums = (ibool) innobase_use_checksums;
1397
1398 btr_search_enabled = innobase_adaptive_hash_index ? true : false;
1399
1400 os_use_large_pages = (ibool) innobase_use_large_pages;
1401 os_large_page_size = (ulint) innobase_large_page_size;
1402
1403 row_rollback_on_timeout = (ibool) innobase_rollback_on_timeout;
1404
1405 srv_file_per_table = innobase_file_per_table ? true : false;
1406
1407 srv_locks_unsafe_for_binlog = (ibool) innobase_locks_unsafe_for_binlog;
1408
1409 srv_max_n_open_files = (ulint) innobase_open_files;
1410 srv_innodb_status = (ibool) innobase_create_status_file;
1411
1412 srv_print_verbose_log = 1;
1413
1414 /* Store the default charset-collation number of this MySQL
1415 installation */
1416
1417 /* We cannot treat characterset here for now!! */
1418 data_mysql_default_charset_coll = (ulint)default_charset_info->number;
1419
1420 ut_a(DATA_MYSQL_BINARY_CHARSET_COLL == my_charset_bin.number);
1421
1422 //innobase_commit_concurrency_init_default();
1423
1424 /* Since we in this module access directly the fields of a trx
1425 struct, and due to different headers and flags it might happen that
1426 mutex_t has a different size in this module and in InnoDB
1427 modules, we check at run time that the size is the same in
1428 these compilation modules. */
1429
1430
1431 /* On 5.5 srv_use_native_aio is TRUE by default. It is later reset
1432 if it is not supported by the platform in
1433 innobase_start_or_create_for_mysql(). As we don't call it in xtrabackup,
1434 we have to duplicate checks from that function here. */
1435
1436#ifdef __WIN__
1437 switch (os_get_os_version()) {
1438 case OS_WIN95:
1439 case OS_WIN31:
1440 case OS_WINNT:
1441 /* On Win 95, 98, ME, Win32 subsystem for Windows 3.1,
1442 and NT use simulated aio. In NT Windows provides async i/o,
1443 but when run in conjunction with InnoDB Hot Backup, it seemed
1444 to corrupt the data files. */
1445
1446 srv_use_native_aio = FALSE;
1447 break;
1448
1449 case OS_WIN2000:
1450 case OS_WINXP:
1451 /* On 2000 and XP, async IO is available. */
1452 srv_use_native_aio = TRUE;
1453 break;
1454
1455 default:
1456 /* Vista and later have both async IO and condition variables */
1457 srv_use_native_aio = TRUE;
1458 srv_use_native_conditions = TRUE;
1459 break;
1460 }
1461
1462#elif defined(LINUX_NATIVE_AIO)
1463
1464 if (srv_use_native_aio) {
1465 ut_print_timestamp(stderr);
1466 fprintf(stderr,
1467 " InnoDB: Using Linux native AIO\n");
1468 }
1469#else
1470 /* Currently native AIO is supported only on windows and linux
1471 and that also when the support is compiled in. In all other
1472 cases, we ignore the setting of innodb_use_native_aio. */
1473 srv_use_native_aio = FALSE;
1474
1475#endif
1476
1477 return(FALSE);
1478
1479error:
1480 fprintf(stderr, "xtrabackup: innodb_init_param(): Error occured.\n");
1481 return(TRUE);
1482}
1483
1484static bool
1485innodb_init(void)
1486{
1487 int err;
1488
1490
1491 if (err != DB_SUCCESS) {
1492 free(internal_innobase_data_file_path);
1493 goto error;
1494 }
1495
1496 /* They may not be needed for now */
1497// (void) hash_init(&innobase_open_tables,system_charset_info, 32, 0, 0,
1498// (hash_get_key) innobase_get_key, 0, 0);
1499// pthread_mutex_init(&innobase_share_mutex, MY_MUTEX_INIT_FAST);
1500// pthread_mutex_init(&prepare_commit_mutex, MY_MUTEX_INIT_FAST);
1501// pthread_mutex_init(&commit_threads_m, MY_MUTEX_INIT_FAST);
1502// pthread_mutex_init(&commit_cond_m, MY_MUTEX_INIT_FAST);
1503// pthread_cond_init(&commit_cond, NULL);
1504
1505 innodb_inited= 1;
1506
1507 return(FALSE);
1508
1509error:
1510 fprintf(stderr, "xtrabackup: innodb_init(): Error occured.\n");
1511 return(TRUE);
1512}
1513
1514static bool
1515innodb_end(void)
1516{
1517 srv_fast_shutdown = (ulint) innobase_fast_shutdown;
1518 innodb_inited = 0;
1519
1520 fprintf(stderr, "xtrabackup: starting shutdown with innodb_fast_shutdown = %lu\n",
1521 srv_fast_shutdown);
1522
1523 if (innobase_shutdown_for_mysql() != DB_SUCCESS) {
1524 goto error;
1525 }
1526 free(internal_innobase_data_file_path);
1527
1528 /* They may not be needed for now */
1529// hash_free(&innobase_open_tables);
1530// pthread_mutex_destroy(&innobase_share_mutex);
1531// pthread_mutex_destroy(&prepare_commit_mutex);
1532// pthread_mutex_destroy(&commit_threads_m);
1533// pthread_mutex_destroy(&commit_cond_m);
1534// pthread_cond_destroy(&commit_cond);
1535
1536 return(FALSE);
1537
1538error:
1539 fprintf(stderr, "xtrabackup: innodb_end(): Error occured.\n");
1540 return(TRUE);
1541}
1542
1543/* ================= common ================= */
1544static bool
1545xtrabackup_read_metadata(char *filename)
1546{
1547 FILE *fp;
1548
1549 fp = fopen(filename,"r");
1550 if(!fp) {
1551 fprintf(stderr, "xtrabackup: Error: cannot open %s\n", filename);
1552 return(TRUE);
1553 }
1554
1555 if (fscanf(fp, "backup_type = %29s\n", metadata_type)
1556 != 1)
1557 return(TRUE);
1558 if (fscanf(fp, "from_lsn = %" PRIu64 "\n", &metadata_from_lsn)
1559 != 1)
1560 return(TRUE);
1561 if (fscanf(fp, "to_lsn = %" PRIu64 "\n", &metadata_to_lsn)
1562 != 1)
1563 return(TRUE);
1564 if (fscanf(fp, "last_lsn = %" PRIu64 "\n", &metadata_last_lsn)
1565 != 1) {
1566 metadata_last_lsn = 0;
1567 }
1568
1569 fclose(fp);
1570
1571 return(FALSE);
1572}
1573
1574static bool
1575xtrabackup_write_metadata(char *filename)
1576{
1577 FILE *fp;
1578
1579 fp = fopen(filename,"w");
1580 if(!fp) {
1581 fprintf(stderr, "xtrabackup: Error: cannot open %s\n", filename);
1582 return(TRUE);
1583 }
1584
1585 if (fprintf(fp, "backup_type = %s\n", metadata_type)
1586 < 0)
1587 return(TRUE);
1588 if (fprintf(fp, "from_lsn = %" PRIu64 "\n", metadata_from_lsn)
1589 < 0)
1590 return(TRUE);
1591 if (fprintf(fp, "to_lsn = %" PRIu64 "\n", metadata_to_lsn)
1592 < 0)
1593 return(TRUE);
1594 if (fprintf(fp, "last_lsn = %" PRIu64 "\n", metadata_last_lsn)
1595 < 0)
1596 return(TRUE);
1597
1598 fclose(fp);
1599
1600 return(FALSE);
1601}
1602
1603/***********************************************************************
1604Read meta info for an incremental delta.
1605@return TRUE on success, FALSE on failure. */
1606static bool
1607xb_read_delta_metadata(const char *filepath, xb_delta_info_t *info)
1608{
1609 FILE *fp;
1610
1611 memset(info, 0, sizeof(xb_delta_info_t));
1612
1613 fp = fopen(filepath, "r");
1614 if (!fp) {
1615 /* Meta files for incremental deltas are optional */
1616 return(TRUE);
1617 }
1618
1619 if (fscanf(fp, "page_size = %lu\n", &info->page_size) != 1)
1620 return(FALSE);
1621
1622 fclose(fp);
1623
1624 return(TRUE);
1625}
1626
1627/***********************************************************************
1628Write meta info for an incremental delta.
1629@return TRUE on success, FALSE on failure. */
1630static bool
1631xb_write_delta_metadata(const char *filepath, const xb_delta_info_t *info)
1632{
1633 FILE *fp;
1634
1635 fp = fopen(filepath, "w");
1636 if (!fp) {
1637 fprintf(stderr, "xtrabackup: Error: cannot open %s\n", filepath);
1638 return(FALSE);
1639 }
1640
1641 if (fprintf(fp, "page_size = %lu\n", info->page_size) < 0)
1642 return(FALSE);
1643
1644 fclose(fp);
1645
1646 return(TRUE);
1647}
1648
1649/* ================= backup ================= */
1650static void
1651xtrabackup_io_throttling(void)
1652{
1653 if (xtrabackup_throttle && (io_ticket--) < 0) {
1654 os_event_reset(wait_throttle);
1655 os_event_wait(wait_throttle);
1656 }
1657}
1658
1659
1660/* TODO: We may tune the behavior (e.g. by fil_aio)*/
1661#define COPY_CHUNK 64
1662
1663static bool
1664xtrabackup_copy_datafile(fil_node_t* node, uint thread_n)
1665{
1666 os_file_t src_file = -1;
1667 os_file_t dst_file = -1;
1668 char dst_path[OS_FILE_MAX_PATH + sizeof(".delta") +
1669 sizeof(XB_DELTA_INFO_SUFFIX)];
1670 char meta_path[OS_FILE_MAX_PATH + sizeof(".delta") +
1671 sizeof(XB_DELTA_INFO_SUFFIX)];
1672 ibool success;
1673 byte* page;
1674 byte* buf2 = NULL;
1675 IB_INT64 file_size;
1676 IB_INT64 offset;
1677 ulint page_in_buffer= 0;
1678 ulint incremental_buffers = 0;
1679 ulint page_size;
1680 ulint page_size_shift;
1681 ulint zip_size;
1682 xb_delta_info_t info;
1683
1684 info.page_size = 0;
1685
1686#ifdef XTRADB_BASED
1687 if (xtrabackup_tables && (!trx_sys_sys_space(node->space->id)))
1688#else
1689 if (xtrabackup_tables && (node->space->id != 0))
1690#endif
1691 { /* must backup id==0 */
1692 char *p;
1693 int p_len, regres= 0;
1694 char *next, *prev;
1695 char tmp;
1696 int i;
1697
1698 p = node->name;
1699 prev = NULL;
1700 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1701 {
1702 prev = p;
1703 p = next + 1;
1704 }
1705 p_len = strlen(p) - strlen(".ibd");
1706
1707 if (p_len < 1) {
1708 /* unknown situation: skip filtering */
1709 goto skip_filter;
1710 }
1711
1712 /* TODO: Fix this lazy implementation... */
1713 tmp = p[p_len];
1714 p[p_len] = 0;
1715 *(p - 1) = '.';
1716
1717 for (i = 0; i < tables_regex_num; i++) {
1718 regres = regexec(&tables_regex[i], prev, 1, tables_regmatch, 0);
1719 if (regres != REG_NOMATCH)
1720 break;
1721 }
1722
1723 p[p_len] = tmp;
1724 *(p - 1) = SRV_PATH_SEPARATOR;
1725
1726 if ( regres == REG_NOMATCH ) {
1727 printf("[%02u] Copying %s is skipped.\n",
1728 thread_n, node->name);
1729 return(FALSE);
1730 }
1731 }
1732
1733#ifdef XTRADB_BASED
1734 if (xtrabackup_tables_file && (!trx_sys_sys_space(node->space->id)))
1735#else
1736 if (xtrabackup_tables_file && (node->space->id != 0))
1737#endif
1738 { /* must backup id==0 */
1739 xtrabackup_tables_t* table;
1740 char *p;
1741 int p_len;
1742 char *next, *prev;
1743 char tmp;
1744
1745 p = node->name;
1746 prev = NULL;
1747 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1748 {
1749 prev = p;
1750 p = next + 1;
1751 }
1752 p_len = strlen(p) - strlen(".ibd");
1753
1754 if (p_len < 1) {
1755 /* unknown situation: skip filtering */
1756 goto skip_filter;
1757 }
1758
1759 /* TODO: Fix this lazy implementation... */
1760 tmp = p[p_len];
1761 p[p_len] = 0;
1762
1763 HASH_SEARCH(name_hash, tables_hash, ut_fold_string(prev),
1764 xtrabackup_tables_t*,
1765 table,
1766 ut_ad(table->name),
1767 !strcmp(table->name, prev));
1768
1769 p[p_len] = tmp;
1770
1771 if (!table) {
1772 printf("[%02u] Copying %s is skipped.\n",
1773 thread_n, node->name);
1774 return(FALSE);
1775 }
1776 }
1777
1778skip_filter:
1779 zip_size = fil_space_get_zip_size(node->space->id);
1780 if (zip_size == ULINT_UNDEFINED) {
1781 fprintf(stderr, "[%02u] xtrabackup: Warning: "
1782 "Failed to determine page size for %s.\n"
1783 "[%02u] xtrabackup: Warning: We assume the table was "
1784 "dropped during xtrabackup execution and ignore the "
1785 "file.\n", thread_n, node->name, thread_n);
1786 goto skip;
1787 } else if (zip_size) {
1788 page_size = zip_size;
1789 page_size_shift = get_bit_shift(page_size);
1790 fprintf(stderr, "[%02u] %s is compressed with page size = "
1791 "%lu bytes\n", thread_n, node->name, page_size);
1792 if (page_size_shift < 10 || page_size_shift > 14) {
1793 fprintf(stderr, "[%02u] xtrabackup: Error: Invalid "
1794 "page size.\n", thread_n);
1795 ut_error;
1796 }
1797 } else {
1798 page_size = UNIV_PAGE_SIZE;
1799 page_size_shift = UNIV_PAGE_SIZE_SHIFT;
1800 }
1801
1802#ifdef XTRADB_BASED
1803 if (trx_sys_sys_space(node->space->id))
1804#else
1805 if (node->space->id == 0)
1806#endif
1807 {
1808 char *next, *p;
1809 /* system datafile "/fullpath/datafilename.ibd" or "./datafilename.ibd" */
1810 p = node->name;
1811 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1812 {
1813 p = next + 1;
1814 }
1815 sprintf(dst_path, "%s/%s", xtrabackup_target_dir, p);
1816 } else {
1817 /* file per table style "./database/table.ibd" */
1818 sprintf(dst_path, "%s%s", xtrabackup_target_dir, strstr(node->name, SRV_PATH_SEPARATOR_STR));
1819 }
1820
1821 if (xtrabackup_incremental) {
1822 size_t dst_path_len = strlen(dst_path);
1823 if (dst_path_len + sizeof(XB_DELTA_INFO_SUFFIX)
1824 > sizeof(meta_path)
1825 || dst_path_len + sizeof(".delta") > sizeof(dst_path)) {
1826 goto error;
1827 }
1828 memcpy(meta_path, dst_path, dst_path_len);
1829 memcpy(meta_path + dst_path_len, XB_DELTA_INFO_SUFFIX,
1830 sizeof(XB_DELTA_INFO_SUFFIX));
1831 memcpy(dst_path + dst_path_len, ".delta", sizeof(".delta"));
1832
1833 /* clear buffer */
1834 bzero(incremental_buffer, (page_size/4) * page_size);
1835 page_in_buffer = 0;
1836 mach_write_to_4(incremental_buffer, 0x78747261UL);/*"xtra"*/
1837 page_in_buffer++;
1838
1839 info.page_size = page_size;
1840 }
1841
1842 /* open src_file*/
1843 if (!node->open) {
1844 src_file = os_file_create_simple_no_error_handling(
1845 0 /* dummy of innodb_file_data_key */,
1846 node->name, OS_FILE_OPEN,
1847 OS_FILE_READ_ONLY, &success);
1848 if (!success) {
1849 /* The following call prints an error message */
1851
1852 fprintf(stderr,
1853 "[%02u] xtrabackup: Warning: cannot open %s\n"
1854 "[%02u] xtrabackup: Warning: We assume the "
1855 "table was dropped during xtrabackup execution "
1856 "and ignore the file.\n",
1857 thread_n, node->name, thread_n);
1858 goto skip;
1859 }
1860
1861 if (srv_unix_file_flush_method == SRV_UNIX_O_DIRECT) {
1862 os_file_set_nocache(src_file, node->name, "OPEN");
1863 }
1864 } else {
1865 src_file = node->handle;
1866 }
1867
1868#ifdef USE_POSIX_FADVISE
1869 posix_fadvise(src_file, 0, 0, POSIX_FADV_SEQUENTIAL);
1870 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
1871#endif
1872
1873 /* open dst_file */
1874 /* os_file_create reads srv_unix_file_flush_method */
1875 dst_file = os_file_create(
1876 0 /* dummy of innodb_file_data_key */,
1877 dst_path, OS_FILE_CREATE,
1878 OS_FILE_NORMAL, OS_DATA_FILE, &success);
1879 if (!success) {
1880 /* The following call prints an error message */
1882
1883 fprintf(stderr,"[%02u] xtrabackup: error: "
1884 "cannot open %s\n", thread_n, dst_path);
1885 goto error;
1886 }
1887
1888#ifdef USE_POSIX_FADVISE
1889 posix_fadvise(dst_file, 0, 0, POSIX_FADV_DONTNEED);
1890#endif
1891
1892 /* copy : TODO: tune later */
1893 printf("[%02u] Copying %s \n to %s\n", thread_n,
1894 node->name, dst_path);
1895
1896 buf2 = (unsigned char*) ut_malloc(COPY_CHUNK * page_size + UNIV_PAGE_SIZE);
1897 page = (unsigned char*) ut_align(buf2, UNIV_PAGE_SIZE);
1898
1899 success = os_file_read(src_file, page, 0, 0, UNIV_PAGE_SIZE);
1900 if (!success) {
1901 goto error;
1902 }
1903
1904 file_size = os_file_get_size_as_iblonglong(src_file);
1905
1906 for (offset = 0; offset < file_size; offset += COPY_CHUNK * page_size) {
1907 ulint chunk;
1908 ulint chunk_offset;
1909 ulint retry_count = 10;
1910//copy_loop:
1911 if ((ulint)(file_size - offset) > COPY_CHUNK * page_size) {
1912 chunk = COPY_CHUNK * page_size;
1913 } else {
1914 chunk = (ulint)(file_size - offset);
1915 }
1916
1917read_retry:
1918 xtrabackup_io_throttling();
1919
1920 success = os_file_read(src_file, page,
1921 (ulint)(offset & 0xFFFFFFFFUL),
1922 (ulint)(offset >> 32), chunk);
1923 if (!success) {
1924 goto error;
1925 }
1926
1927 /* check corruption and retry */
1928 for (chunk_offset = 0; chunk_offset < chunk; chunk_offset += page_size) {
1929 if (buf_page_is_corrupted(page + chunk_offset, zip_size))
1930 {
1931 if (
1932#ifdef XTRADB_BASED
1933 trx_sys_sys_space(node->space->id)
1934#else
1935 node->space->id == 0
1936#endif
1937 && ((offset + (IB_INT64)chunk_offset) >> page_size_shift)
1938 >= FSP_EXTENT_SIZE
1939 && ((offset + (IB_INT64)chunk_offset) >> page_size_shift)
1940 < FSP_EXTENT_SIZE * 3) {
1941 /* double write buffer may have old data in the end
1942 or it may contain the other format page like COMPRESSED.
1943 So, we can pass the check of double write buffer.*/
1944 ut_a(page_size == UNIV_PAGE_SIZE);
1945 fprintf(stderr, "[%02u] xtrabackup: "
1946 "Page %lu seems double write "
1947 "buffer. passing the check.\n",
1948 thread_n,
1949 (ulint)((offset +
1950 (IB_INT64)chunk_offset) >>
1951 page_size_shift));
1952 } else {
1953 retry_count--;
1954 if (retry_count == 0) {
1955 fprintf(stderr,
1956 "[%02u] xtrabackup: "
1957 "Error: 10 retries "
1958 "resulted in fail. This"
1959 "file seems to be "
1960 "corrupted.\n",
1961 thread_n);
1962 goto error;
1963 }
1964 fprintf(stderr, "[%02u] xtrabackup: "
1965 "Database page corruption "
1966 "detected at page %lu. "
1967 "retrying...\n",
1968 thread_n,
1969 (ulint)((offset +
1970 (IB_INT64)chunk_offset)
1971 >> page_size_shift));
1972 goto read_retry;
1973 }
1974 }
1975 }
1976
1977 if (xtrabackup_incremental) {
1978 for (chunk_offset = 0; chunk_offset < chunk; chunk_offset += page_size) {
1979 /* newer page */
1980 /* This condition may be OK for header, ibuf and fsp */
1981 if (ut_dulint_cmp(incremental_lsn,
1982 MACH_READ_64(page + chunk_offset + FIL_PAGE_LSN)) < 0) {
1983 /* ========================================= */
1984 IB_INT64 offset_on_page;
1985
1986 if (page_in_buffer == page_size/4) {
1987 /* flush buffer */
1988 success = os_file_write(dst_path, dst_file, incremental_buffer,
1989 ((incremental_buffers * (page_size/4))
1990 << page_size_shift) & 0xFFFFFFFFUL,
1991 (incremental_buffers * (page_size/4))
1992 >> (32 - page_size_shift),
1993 page_in_buffer * page_size);
1994 if (!success) {
1995 goto error;
1996 }
1997
1998 incremental_buffers++;
1999
2000 /* clear buffer */
2001 bzero(incremental_buffer, (page_size/4) * page_size);
2002 page_in_buffer = 0;
2003 mach_write_to_4(incremental_buffer, 0x78747261UL);/*"xtra"*/
2004 page_in_buffer++;
2005 }
2006
2007 offset_on_page = ((offset + (IB_INT64)chunk_offset) >> page_size_shift);
2008 ut_a(offset_on_page >> 32 == 0);
2009
2010 mach_write_to_4(incremental_buffer + page_in_buffer * 4, (ulint)offset_on_page);
2011 memcpy(incremental_buffer + page_in_buffer * page_size,
2012 page + chunk_offset, page_size);
2013
2014 page_in_buffer++;
2015 /* ========================================= */
2016 }
2017 }
2018 } else {
2019 success = os_file_write(dst_path, dst_file, page,
2020 (ulint)(offset & 0xFFFFFFFFUL),
2021 (ulint)(offset >> 32), chunk);
2022 if (!success) {
2023 goto error;
2024 }
2025 }
2026
2027 }
2028
2029 if (xtrabackup_incremental) {
2030 /* termination */
2031 if (page_in_buffer != page_size/4) {
2032 mach_write_to_4(incremental_buffer + page_in_buffer * 4, 0xFFFFFFFFUL);
2033 }
2034
2035 mach_write_to_4(incremental_buffer, 0x58545241UL);/*"XTRA"*/
2036
2037 /* flush buffer */
2038 success = os_file_write(dst_path, dst_file, incremental_buffer,
2039 ((incremental_buffers * (page_size/4))
2040 << page_size_shift) & 0xFFFFFFFFUL,
2041 (incremental_buffers * (page_size/4))
2042 >> (32 - page_size_shift),
2043 page_in_buffer * page_size);
2044 if (!success) {
2045 goto error;
2046 }
2047 if (!xb_write_delta_metadata(meta_path, &info)) {
2048 fprintf(stderr, "[%02u] xtrabackup: Error: "
2049 "failed to write meta info for %s\n",
2050 thread_n, dst_path);
2051 goto error;
2052 }
2053 }
2054
2055 success = os_file_flush(dst_file);
2056 if (!success) {
2057 goto error;
2058 }
2059
2060
2061 /* check size again */
2062 /* TODO: but is it needed ?? */
2063// if (file_size < os_file_get_size_as_iblonglong(src_file)) {
2064// offset -= COPY_CHUNK * page_size;
2065// file_size = os_file_get_size_as_iblonglong(src_file);
2066// goto copy_loop;
2067// }
2068
2069 /* TODO: How should we treat double_write_buffer here? */
2070 /* (currently, don't care about. Because,
2071 the blocks is newer than the last checkpoint anyway.) */
2072
2073 /* close */
2074 printf("[%02u] ...done\n", thread_n);
2075 if (!node->open) {
2076 os_file_close(src_file);
2077 }
2078 os_file_close(dst_file);
2079 ut_free(buf2);
2080 return(FALSE);
2081error:
2082 if (src_file != -1 && !node->open)
2083 os_file_close(src_file);
2084 if (dst_file != -1)
2085 os_file_close(dst_file);
2086 if (buf2)
2087 ut_free(buf2);
2088 fprintf(stderr, "[%02u] xtrabackup: Error: "
2089 "xtrabackup_copy_datafile() failed.\n", thread_n);
2090 return(TRUE); /*ERROR*/
2091
2092skip:
2093 if (src_file != -1 && !node->open)
2094 os_file_close(src_file);
2095 if (dst_file != -1)
2096 os_file_close(dst_file);
2097 if (buf2)
2098 ut_free(buf2);
2099 fprintf(stderr, "[%02u] xtrabackup: Warning: skipping file %s.\n",
2100 thread_n, node->name);
2101 return(FALSE);
2102}
2103
2104static bool
2105xtrabackup_copy_logfile(LSN64 from_lsn, bool is_last)
2106{
2107 /* definition from recv_recovery_from_checkpoint_start() */
2108 log_group_t* group;
2109 LSN64 group_scanned_lsn;
2110 LSN64 contiguous_lsn;
2111
2112 ibool success;
2113
2114 if (!xtrabackup_stream)
2115 ut_a(dst_log != -1);
2116
2117 /* read from checkpoint_lsn_start to current */
2118 contiguous_lsn = ut_dulint_align_down(from_lsn,
2120
2121 /* TODO: We must check the contiguous_lsn still exists in log file.. */
2122
2123 group = UT_LIST_GET_FIRST(log_sys->log_groups);
2124
2125 while (group) {
2126 ibool finished;
2127 LSN64 start_lsn;
2128 LSN64 end_lsn;
2129
2130
2131 /* reference recv_group_scan_log_recs() */
2132 finished = FALSE;
2133
2134 start_lsn = contiguous_lsn;
2135
2136 while (!finished) {
2137 end_lsn = ut_dulint_add(start_lsn, RECV_SCAN_SIZE);
2138
2139 xtrabackup_io_throttling();
2140
2141 log_group_read_log_seg(LOG_RECOVER, log_sys->buf,
2142 group, start_lsn, end_lsn);
2143
2144 //printf("log read from (%lu %lu) to (%lu %lu)\n",
2145 // start_lsn.high, start_lsn.low, end_lsn.high, end_lsn.low);
2146
2147 /* reference recv_scan_log_recs() */
2148 {
2149 byte* log_block;
2150 ulint no;
2151 LSN64 scanned_lsn;
2152 ulint data_len;
2153
2154 ulint scanned_checkpoint_no = 0;
2155
2156 finished = FALSE;
2157
2158 log_block = log_sys->buf;
2159 scanned_lsn = start_lsn;
2160
2161 while (log_block < log_sys->buf + RECV_SCAN_SIZE && !finished) {
2162
2163 no = log_block_get_hdr_no(log_block);
2164
2165 if (no != log_block_convert_lsn_to_no(scanned_lsn)
2166 || !log_block_checksum_is_ok_or_old_format(log_block)) {
2167
2168 if (no > log_block_convert_lsn_to_no(scanned_lsn)
2169 && log_block_checksum_is_ok_or_old_format(log_block)) {
2170 fprintf(stderr,
2171">> ###Warning###: The copying transaction log migh be overtaken already by the target.\n"
2172">> : Waiting log block no %lu, but the bumber is already %lu.\n"
2173">> : If the number equals %lu + n * %lu, it should be overtaken already.\n",
2174 (ulong) log_block_convert_lsn_to_no(scanned_lsn),
2175 (ulong) no,
2176 (ulong) log_block_convert_lsn_to_no(scanned_lsn),
2179 ) - 1));
2180
2181 } else if (no == log_block_convert_lsn_to_no(scanned_lsn)
2182 && !log_block_checksum_is_ok_or_old_format(
2183 log_block)) {
2184 fprintf(stderr,
2185"xtrabackup: Log block no %lu at lsn %" PRIu64 " has\n"
2186"xtrabackup: ok header, but checksum field contains %lu, should be %lu\n",
2187 (ulong) no,
2188 scanned_lsn,
2189 (ulong) log_block_get_checksum(log_block),
2190 (ulong) log_block_calc_checksum(log_block));
2191 }
2192
2193 /* Garbage or an incompletely written log block */
2194
2195 finished = TRUE;
2196
2197 break;
2198 }
2199
2200 if (log_block_get_flush_bit(log_block)) {
2201 /* This block was a start of a log flush operation:
2202 we know that the previous flush operation must have
2203 been completed for all log groups before this block
2204 can have been flushed to any of the groups. Therefore,
2205 we know that log data is contiguous up to scanned_lsn
2206 in all non-corrupt log groups. */
2207
2208 if (ut_dulint_cmp(scanned_lsn, contiguous_lsn) > 0) {
2209 contiguous_lsn = scanned_lsn;
2210 }
2211 }
2212
2213 data_len = log_block_get_data_len(log_block);
2214
2215 if (
2216 (scanned_checkpoint_no > 0)
2217 && (log_block_get_checkpoint_no(log_block)
2218 < scanned_checkpoint_no)
2219 && (scanned_checkpoint_no
2220 - log_block_get_checkpoint_no(log_block)
2221 > 0x80000000UL)) {
2222
2223 /* Garbage from a log buffer flush which was made
2224 before the most recent database recovery */
2225
2226 finished = TRUE;
2227 break;
2228 }
2229
2230 scanned_lsn = ut_dulint_add(scanned_lsn, data_len);
2231 scanned_checkpoint_no = log_block_get_checkpoint_no(log_block);
2232
2233 if (data_len < OS_FILE_LOG_BLOCK_SIZE) {
2234 /* Log data for this group ends here */
2235
2236 finished = TRUE;
2237 } else {
2238 log_block += OS_FILE_LOG_BLOCK_SIZE;
2239 }
2240 } /* while (log_block < log_sys->buf + RECV_SCAN_SIZE && !finished) */
2241
2242 group_scanned_lsn = scanned_lsn;
2243
2244
2245
2246 }
2247
2248 /* ===== write log to 'xtrabackup_logfile' ====== */
2249 {
2250 ulint write_size;
2251
2252 if (!finished) {
2253 write_size = RECV_SCAN_SIZE;
2254 } else {
2255 write_size = ut_dulint_minus(
2256 ut_dulint_align_up(group_scanned_lsn, OS_FILE_LOG_BLOCK_SIZE),
2257 start_lsn);
2258 }
2259
2260 //printf("Wrinting offset= %lld, size= %lu\n", log_copy_offset, write_size);
2261
2262 if (!xtrabackup_stream) {
2263 success = os_file_write(dst_log_path, dst_log, log_sys->buf,
2264 (ulint)(log_copy_offset & 0xFFFFFFFFUL),
2265 (ulint)(log_copy_offset >> 32), write_size);
2266 } else {
2267 ulint ret;
2268 ulint stdout_write_size = write_size;
2269 if (finished && !is_last
2270 && group_scanned_lsn % OS_FILE_LOG_BLOCK_SIZE
2271 )
2272 stdout_write_size -= OS_FILE_LOG_BLOCK_SIZE;
2273 if (stdout_write_size) {
2274 ret = write(fileno(stdout), log_sys->buf, stdout_write_size);
2275 if (ret == stdout_write_size) {
2276 success = TRUE;
2277 } else {
2278 fprintf(stderr, "write: %lu > %lu\n", stdout_write_size, ret);
2279 success = FALSE;
2280 }
2281 } else {
2282 success = TRUE; /* do nothing */
2283 }
2284 }
2285
2286 log_copy_offset += write_size;
2287
2288 if (finished && group_scanned_lsn % OS_FILE_LOG_BLOCK_SIZE)
2289 {
2290 /* if continue, it will start from align_down(group_scanned_lsn) */
2291 log_copy_offset -= OS_FILE_LOG_BLOCK_SIZE;
2292 }
2293
2294 if(!success) {
2295 if (!xtrabackup_stream) {
2296 fprintf(stderr, "xtrabackup: Error: os_file_write to %s\n", dst_log_path);
2297 } else {
2298 fprintf(stderr, "xtrabackup: Error: write to stdout\n");
2299 }
2300 goto error;
2301 }
2302
2303
2304 }
2305
2306
2307
2308
2309
2310 start_lsn = end_lsn;
2311 }
2312
2313
2314
2315 group->scanned_lsn = group_scanned_lsn;
2316
2317
2318 fprintf(stderr, ">> log scanned up to (%" PRIu64 ")\n",group->scanned_lsn);
2319
2320 group = UT_LIST_GET_NEXT(log_groups, group);
2321
2322 /* update global variable*/
2323 log_copy_scanned_lsn = group_scanned_lsn;
2324
2325 /* innodb_mirrored_log_groups must be 1, no other groups */
2326 ut_a(group == NULL);
2327 }
2328
2329
2330 if (!xtrabackup_stream) {
2331 success = os_file_flush(dst_log);
2332 } else {
2333 fflush(stdout);
2334 success = TRUE;
2335 }
2336
2337 if(!success) {
2338 goto error;
2339 }
2340
2341 return(FALSE);
2342
2343error:
2344 if (!xtrabackup_stream)
2345 os_file_close(dst_log);
2346 fprintf(stderr, "xtrabackup: Error: xtrabackup_copy_logfile() failed.\n");
2347 return(TRUE);
2348}
2349
2350/* copying logfile in background */
2351#define SLEEPING_PERIOD 5
2352
2353static
2354#ifndef __WIN__
2355void*
2356#else
2357ulint
2358#endif
2359log_copying_thread(
2360 void* )
2361{
2362 ulint counter = 0;
2363
2364 if (!xtrabackup_stream)
2365 ut_a(dst_log != -1);
2366
2367 log_copying_running = TRUE;
2368
2369 while(log_copying) {
2370 os_thread_sleep(200000); /*0.2 sec*/
2371
2372 counter++;
2373 if(counter >= SLEEPING_PERIOD * 5) {
2374 if(xtrabackup_copy_logfile(log_copy_scanned_lsn, FALSE))
2375 goto end;
2376 counter = 0;
2377 }
2378 }
2379
2380 /* last copying */
2381 if(xtrabackup_copy_logfile(log_copy_scanned_lsn, TRUE))
2382 goto end;
2383
2384 log_copying_succeed = TRUE;
2385end:
2386 log_copying_running = FALSE;
2387 os_thread_exit(NULL);
2388
2389 return(0);
2390}
2391
2392/* io throttle watching (rough) */
2393static
2394#ifndef __WIN__
2395void*
2396#else
2397ulint
2398#endif
2399io_watching_thread(
2400 void* )
2401{
2402 /* currently, for --backup only */
2403 ut_a(xtrabackup_backup);
2404
2405 while (log_copying) {
2406 os_thread_sleep(1000000); /*1 sec*/
2407
2408 //for DEBUG
2409 //if (io_ticket == xtrabackup_throttle) {
2410 // fprintf(stderr, "There seem to be no IO...?\n");
2411 //}
2412
2413 io_ticket = xtrabackup_throttle;
2414 os_event_set(wait_throttle);
2415 }
2416
2417 /* stop io throttle */
2418 xtrabackup_throttle = 0;
2419 os_event_set(wait_throttle);
2420
2421 os_thread_exit(NULL);
2422
2423 return(0);
2424}
2425
2426/************************************************************************
2427I/o-handler thread function. */
2428static
2429
2430#ifndef __WIN__
2431void*
2432#else
2433ulint
2434#endif
2435io_handler_thread(
2436/*==============*/
2437 void* arg)
2438{
2439 ulint segment;
2440
2441 segment = *((ulint*)arg);
2442
2443 for (;;) {
2444 fil_aio_wait(segment);
2445 }
2446
2447 /* We count the number of threads in os_thread_exit(). A created
2448 thread should always use that to exit and not use return() to exit.
2449 The thread actually never comes here because it is exited in an
2450 os_event_wait(). */
2451
2452 os_thread_exit(NULL);
2453
2454#ifndef __WIN__
2455 return(NULL); /* Not reached */
2456#else
2457 return(0);
2458#endif
2459}
2460
2461/***************************************************************************
2462Creates an output directory for a given tablespace, if it does not exist */
2463static
2464int
2465xtrabackup_create_output_dir(
2466/*==========================*/
2467 /* out: 0 if succes, -1 if failure */
2468 fil_space_t *space) /* in: tablespace */
2469{
2470 char path[FN_REFLEN];
2471 char *ptr1, *ptr2;
2472
2473 /* mkdir if not exist */
2474 ptr1 = strstr(space->name, SRV_PATH_SEPARATOR_STR);
2475 if (ptr1) {
2476 ptr2 = strstr(ptr1 + 1, SRV_PATH_SEPARATOR_STR);
2477 } else {
2478 ptr2 = NULL;
2479 }
2480#ifdef XTRADB_BASED
2481 if(!trx_sys_sys_space(space->id) && ptr2)
2482#else
2483 if(space->id && ptr2)
2484#endif
2485 {
2486 /* single table space */
2487 *ptr2 = 0; /* temporary (it's my lazy..)*/
2488 snprintf(path, sizeof(path), "%s%s", xtrabackup_target_dir,
2489 ptr1);
2490 *ptr2 = SRV_PATH_SEPARATOR;
2491
2492 if (mkdir(path, 0777) != 0 && errno != EEXIST) {
2493 fprintf(stderr,
2494 "xtrabackup: Error: cannot mkdir %d: %s\n",
2495 errno, path);
2496 return -1;
2497 }
2498 }
2499 return 0;
2500}
2501
2502/**************************************************************************
2503Datafiles copying thread.*/
2504static
2505os_thread_ret_t
2506data_copy_thread_func(
2507/*==================*/
2508 void *arg) /* thread context */
2509{
2510 data_thread_ctxt_t *ctxt = (data_thread_ctxt_t *) arg;
2511 uint num = ctxt->num;
2512 fil_space_t* space;
2513 ibool space_changed;
2514 fil_node_t* node;
2515
2516 while ((node = datafiles_iter_next(ctxt->it, &space_changed)) != NULL) {
2517 space = node->space;
2518
2519 if (space_changed && xtrabackup_create_output_dir(space))
2520 exit(EXIT_FAILURE);
2521
2522 /* copy the datafile */
2523 if(xtrabackup_copy_datafile(node, num)) {
2524 fprintf(stderr, "[%02u] xtrabackup: Error: "
2525 "failed to copy datafile.\n",
2526 num);
2527 exit(EXIT_FAILURE);
2528 }
2529 }
2530
2531 os_mutex_enter(ctxt->count_mutex);
2532 (*ctxt->count)--;
2533 os_mutex_exit(ctxt->count_mutex);
2534
2535 os_thread_exit(NULL);
2536 OS_THREAD_DUMMY_RETURN;
2537}
2538
2539/* CAUTION(?): Don't rename file_per_table during backup */
2540static void
2541xtrabackup_backup_func(void)
2542{
2543 struct stat stat_info;
2544 LSN64 latest_cp;
2545
2546#ifdef USE_POSIX_FADVISE
2547 fprintf(stderr, "xtrabackup: uses posix_fadvise().\n");
2548#endif
2549
2550 /* cd to datadir */
2551
2552 if (chdir(mysql_real_data_home) != 0)
2553 {
2554 fprintf(stderr, "xtrabackup: cannot my_setwd %s\n", mysql_real_data_home);
2555 exit(EXIT_FAILURE);
2556 }
2557 fprintf(stderr, "xtrabackup: cd to %s\n", mysql_real_data_home);
2558
2559 mysql_data_home= mysql_data_home_buff;
2560 mysql_data_home[0]=FN_CURLIB; // all paths are relative from here
2561 mysql_data_home[1]=0;
2562
2563 /* set read only */
2564 srv_read_only = TRUE;
2565
2566 /* initialize components */
2567 if(innodb_init_param())
2568 exit(EXIT_FAILURE);
2569
2570 if (srv_file_flush_method_str == NULL) {
2571 /* These are the default options */
2572 srv_unix_file_flush_method = SRV_UNIX_FSYNC;
2573
2574 srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
2575#ifndef __WIN__
2576 } else if (0 == ut_strcmp(srv_file_flush_method_str, "fsync")) {
2577 srv_unix_file_flush_method = SRV_UNIX_FSYNC;
2578
2579 } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DSYNC")) {
2580 srv_unix_file_flush_method = SRV_UNIX_O_DSYNC;
2581
2582 } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT")) {
2583 srv_unix_file_flush_method = SRV_UNIX_O_DIRECT;
2584 fprintf(stderr,"xtrabackup: use O_DIRECT\n");
2585 } else if (0 == ut_strcmp(srv_file_flush_method_str, "littlesync")) {
2586 srv_unix_file_flush_method = SRV_UNIX_LITTLESYNC;
2587
2588 } else if (0 == ut_strcmp(srv_file_flush_method_str, "nosync")) {
2589 srv_unix_file_flush_method = SRV_UNIX_NOSYNC;
2590#else
2591 } else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) {
2592 srv_win_file_flush_method = SRV_WIN_IO_NORMAL;
2593 os_aio_use_native_aio = FALSE;
2594
2595 } else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) {
2596 srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
2597 os_aio_use_native_aio = FALSE;
2598
2599 } else if (0 == ut_strcmp(srv_file_flush_method_str,
2600 "async_unbuffered")) {
2601 srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
2602#endif
2603 } else {
2604 fprintf(stderr,
2605 "xtrabackup: Unrecognized value %s for innodb_flush_method\n",
2606 srv_file_flush_method_str);
2607 exit(EXIT_FAILURE);
2608 }
2609
2610 if (srv_buf_pool_size >= 1000 * 1024 * 1024) {
2611 /* Here we still have srv_pool_size counted
2612 in kilobytes (in 4.0 this was in bytes)
2613 srv_boot() converts the value to
2614 pages; if buffer pool is less than 1000 MB,
2615 assume fewer threads. */
2616 srv_max_n_threads = 50000;
2617
2618
2619 } else if (srv_buf_pool_size >= 8 * 1024 * 1024) {
2620
2621 srv_max_n_threads = 10000;
2622 } else {
2623 srv_max_n_threads = 1000; /* saves several MB of memory,
2624 especially in 64-bit
2625 computers */
2626 }
2627
2628 {
2629 ulint nr;
2630 ulint i;
2631
2632 nr = srv_n_data_files;
2633
2634 for (i = 0; i < nr; i++) {
2635 srv_data_file_sizes[i] = srv_data_file_sizes[i]
2636 * ((1024 * 1024) / UNIV_PAGE_SIZE);
2637 }
2638
2639 srv_last_file_size_max = srv_last_file_size_max
2640 * ((1024 * 1024) / UNIV_PAGE_SIZE);
2641
2642 srv_log_file_size = srv_log_file_size / UNIV_PAGE_SIZE;
2643
2644 srv_log_buffer_size = srv_log_buffer_size / UNIV_PAGE_SIZE;
2645
2646 srv_lock_table_size = 5 * (srv_buf_pool_size / UNIV_PAGE_SIZE);
2647 }
2648
2649 os_sync_mutex = NULL;
2651
2652 {
2653 ibool create_new_db;
2654#ifdef XTRADB_BASED
2655 ibool create_new_doublewrite_file;
2656#endif
2657 ibool log_file_created;
2658 ibool log_created = FALSE;
2659 ibool log_opened = FALSE;
2660 LSN64 min_flushed_lsn;
2661 LSN64 max_flushed_lsn;
2662 ulint sum_of_new_sizes;
2663 ulint err;
2664 ulint i;
2665
2666
2667
2668
2669#define SRV_N_PENDING_IOS_PER_THREAD OS_AIO_N_PENDING_IOS_PER_THREAD
2670#define SRV_MAX_N_PENDING_SYNC_IOS 100
2671
2672 srv_n_file_io_threads = 2 + srv_n_read_io_threads + srv_n_write_io_threads;
2673
2674 os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD,
2675 srv_n_read_io_threads,
2676 srv_n_write_io_threads,
2677 SRV_MAX_N_PENDING_SYNC_IOS);
2678
2679 fil_init(srv_file_per_table ? 50000 : 5000,
2680 srv_max_n_open_files);
2681
2682 fsp_init();
2683 log_init();
2684
2685 lock_sys_create(srv_lock_table_size);
2686
2687 for (i = 0; i < srv_n_file_io_threads; i++) {
2688 thread_nr[i] = i;
2689
2690 os_thread_create(io_handler_thread, thread_nr + i, thread_ids + i);
2691 }
2692
2693 os_thread_sleep(200000); /*0.2 sec*/
2694
2695 err = open_or_create_data_files(&create_new_db,
2696#ifdef XTRADB_BASED
2697 &create_new_doublewrite_file,
2698#endif
2699 &min_flushed_lsn, &max_flushed_lsn,
2700 &sum_of_new_sizes);
2701 if (err != DB_SUCCESS) {
2702 fprintf(stderr,
2703"xtrabackup: Could not open or create data files.\n"
2704"xtrabackup: If you tried to add new data files, and it failed here,\n"
2705"xtrabackup: you should now edit innodb_data_file_path in my.cnf back\n"
2706"xtrabackup: to what it was, and remove the new ibdata files InnoDB created\n"
2707"xtrabackup: in this failed attempt. InnoDB only wrote those files full of\n"
2708"xtrabackup: zeros, but did not yet use them in any way. But be careful: do not\n"
2709"xtrabackup: remove old data files which contain your precious data!\n");
2710
2711 //return((int) err);
2712 exit(EXIT_FAILURE);
2713 }
2714
2715 /* create_new_db must not be TRUE.. */
2716 if (create_new_db) {
2717 fprintf(stderr, "xtrabackup: Something wrong with source files...\n");
2718 exit(EXIT_FAILURE);
2719 }
2720
2721 for (i = 0; i < srv_n_log_files; i++) {
2722 err = open_or_create_log_file(create_new_db, &log_file_created,
2723 log_opened, 0, i);
2724 if (err != DB_SUCCESS) {
2725
2726 //return((int) err);
2727 exit(EXIT_FAILURE);
2728 }
2729
2730 if (log_file_created) {
2731 log_created = TRUE;
2732 } else {
2733 log_opened = TRUE;
2734 }
2735 if ((log_opened && create_new_db)
2736 || (log_opened && log_created)) {
2737 fprintf(stderr,
2738 "xtrabackup: Error: all log files must be created at the same time.\n"
2739 "xtrabackup: All log files must be created also in database creation.\n"
2740 "xtrabackup: If you want bigger or smaller log files, shut down the\n"
2741 "xtrabackup: database and make sure there were no errors in shutdown.\n"
2742 "xtrabackup: Then delete the existing log files. Edit the .cnf file\n"
2743 "xtrabackup: and start the database again.\n");
2744
2745 //return(DB_ERROR);
2746 exit(EXIT_FAILURE);
2747 }
2748 }
2749
2750 /* log_file_created must not be TRUE, if online */
2751 if (log_file_created) {
2752 fprintf(stderr, "xtrabackup: Something wrong with source files...\n");
2753 exit(EXIT_FAILURE);
2754 }
2755
2757
2758 }
2759
2760 /* create extra LSN dir if it does not exist. */
2761 if (xtrabackup_extra_lsndir
2762 && (stat(xtrabackup_extra_lsndir,&stat_info) != 0)
2763 && (mkdir(xtrabackup_extra_lsndir,0777) != 0)){
2764 fprintf(stderr,"xtrabackup: Error: cannot mkdir %d: %s\n",errno,xtrabackup_extra_lsndir);
2765 exit(EXIT_FAILURE);
2766 }
2767
2768
2769 if (!xtrabackup_stream) {
2770
2771 /* create target dir if not exist */
2772 if (stat(xtrabackup_target_dir,&stat_info) != 0
2773 && (mkdir(xtrabackup_target_dir,0777) != 0)){
2774 fprintf(stderr,"xtrabackup: Error: cannot mkdir %d: %s\n",errno,xtrabackup_target_dir);
2775 exit(EXIT_FAILURE);
2776 }
2777
2778 } else {
2779 fprintf(stderr,"xtrabackup: Stream mode.\n");
2780 /* stdout can treat binary at Linux */
2781 //setmode(fileno(stdout), O_BINARY);
2782 }
2783
2784 {
2785 fil_system_t* f_system = fil_system;
2786
2787 /* definition from recv_recovery_from_checkpoint_start() */
2788 log_group_t* max_cp_group;
2789 ulint max_cp_field;
2790 byte* buf;
2791 boost::scoped_array<byte> log_hdr_buf_(
2792 new byte[LOG_FILE_HDR_SIZE + OS_FILE_LOG_BLOCK_SIZE]);
2793 byte* log_hdr_buf;
2794 ulint err;
2795
2796 ibool success;
2797
2798 /* start back ground thread to copy newer log */
2799 os_thread_id_t log_copying_thread_id;
2800 datafiles_iter_t *it;
2801
2802 log_hdr_buf = (byte*)ut_align(log_hdr_buf_.get(),
2804
2805 /* log space */
2806 //space = UT_LIST_GET_NEXT(space_list, UT_LIST_GET_FIRST(f_system->space_list));
2807 //printf("space: name=%s, id=%d, purpose=%d, size=%d\n",
2808 // space->name, space->id, space->purpose, space->size);
2809
2810 /* get current checkpoint_lsn */
2811 /* Look for the latest checkpoint from any of the log groups */
2812
2813 err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field);
2814
2815 if (err != DB_SUCCESS) {
2816
2817 exit(EXIT_FAILURE);
2818 }
2819
2820 log_group_read_checkpoint_info(max_cp_group, max_cp_field);
2821 buf = log_sys->checkpoint_buf;
2822
2823 checkpoint_lsn_start = MACH_READ_64(buf + LOG_CHECKPOINT_LSN);
2824 checkpoint_no_start = MACH_READ_64(buf + LOG_CHECKPOINT_NO);
2825
2826reread_log_header:
2827 fil_io(OS_FILE_READ | OS_FILE_LOG, TRUE, max_cp_group->space_id,
2828 0,
2829 0, 0, LOG_FILE_HDR_SIZE,
2830 log_hdr_buf, max_cp_group);
2831
2832 /* check consistency of log file header to copy */
2833 err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field);
2834
2835 if (err != DB_SUCCESS) {
2836
2837 exit(EXIT_FAILURE);
2838 }
2839
2840 log_group_read_checkpoint_info(max_cp_group, max_cp_field);
2841 buf = log_sys->checkpoint_buf;
2842
2843 if(ut_dulint_cmp(checkpoint_no_start,
2844 MACH_READ_64(buf + LOG_CHECKPOINT_NO)) != 0) {
2845 checkpoint_lsn_start = MACH_READ_64(buf + LOG_CHECKPOINT_LSN);
2846 checkpoint_no_start = MACH_READ_64(buf + LOG_CHECKPOINT_NO);
2847 goto reread_log_header;
2848 }
2849
2850 if (!xtrabackup_stream) {
2851
2852 /* open 'xtrabackup_logfile' */
2853 sprintf(dst_log_path, "%s%s", xtrabackup_target_dir, "/xtrabackup_logfile");
2854 srv_normalize_path_for_win(dst_log_path);
2855 /* os_file_create reads srv_unix_file_flush_method for OS_DATA_FILE*/
2856 dst_log = os_file_create(
2857 0 /* dummy of innodb_file_data_key */,
2858 dst_log_path, OS_FILE_CREATE,
2859 OS_FILE_NORMAL, OS_DATA_FILE, &success);
2860
2861 if (!success) {
2862 /* The following call prints an error message */
2864
2865 fprintf(stderr,
2866"xtrabackup: error: cannot open %s\n",
2867 dst_log_path);
2868 exit(EXIT_FAILURE);
2869 }
2870
2871#ifdef USE_POSIX_FADVISE
2872 posix_fadvise(dst_log, 0, 0, POSIX_FADV_DONTNEED);
2873#endif
2874
2875 }
2876
2877 /* label it */
2878 strcpy((char*) log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
2879 "xtrabkup ");
2881 (char*) log_hdr_buf + (LOG_FILE_WAS_CREATED_BY_HOT_BACKUP
2882 + (sizeof "xtrabkup ") - 1));
2883
2884 if (!xtrabackup_stream) {
2885 success = os_file_write(dst_log_path, dst_log, log_hdr_buf,
2886 0, 0, LOG_FILE_HDR_SIZE);
2887 } else {
2888 /* Stream */
2889 if ((write(fileno(stdout), log_hdr_buf, LOG_FILE_HDR_SIZE)
2890 - LOG_FILE_HDR_SIZE) == 0)
2891 {
2892 success = TRUE;
2893 } else {
2894 success = FALSE;
2895 }
2896 }
2897
2898 log_copy_offset += LOG_FILE_HDR_SIZE;
2899 if (!success) {
2900 if (dst_log != -1)
2901 os_file_close(dst_log);
2902 exit(EXIT_FAILURE);
2903 }
2904
2905 /* start flag */
2906 log_copying = TRUE;
2907
2908 /* start io throttle */
2909 if(xtrabackup_throttle) {
2910 os_thread_id_t io_watching_thread_id;
2911
2912 io_ticket = xtrabackup_throttle;
2913 wait_throttle = os_event_create(NULL);
2914
2915 os_thread_create(io_watching_thread, NULL, &io_watching_thread_id);
2916 }
2917
2918
2919 /* copy log file by current position */
2920 if(xtrabackup_copy_logfile(checkpoint_lsn_start, FALSE))
2921 exit(EXIT_FAILURE);
2922
2923
2924 os_thread_create(log_copying_thread, NULL, &log_copying_thread_id);
2925
2926
2927
2928 if (!xtrabackup_stream) { /* stream mode is transaction log only */
2929 uint i;
2930 uint count;
2931 os_mutex_t count_mutex;
2932 data_thread_ctxt_t *data_threads;
2933
2934 ut_a(parallel > 0);
2935
2936 if (parallel > 1)
2937 printf("xtrabackup: Starting %u threads for parallel "
2938 "data files transfer\n", parallel);
2939
2940 it = datafiles_iter_new(f_system);
2941 if (it == NULL) {
2942 fprintf(stderr,
2943 "xtrabackup: Error: "
2944 "datafiles_iter_new() failed.\n");
2945 exit(EXIT_FAILURE);
2946 }
2947
2948 /* Create data copying threads */
2949 ut_a(parallel > 0);
2950
2951 data_threads = (data_thread_ctxt_t *)
2952 ut_malloc(sizeof(data_thread_ctxt_t) * parallel);
2953 count = parallel;
2954 count_mutex = OS_MUTEX_CREATE();
2955
2956 for (i = 0; i < parallel; i++) {
2957 data_threads[i].it = it;
2958 data_threads[i].num = i+1;
2959 data_threads[i].count = &count;
2960 data_threads[i].count_mutex = count_mutex;
2961 os_thread_create(data_copy_thread_func,
2962 data_threads + i,
2963 &data_threads[i].id);
2964 }
2965
2966 /* Wait for threads to exit */
2967 while (1) {
2968 os_thread_sleep(1000000);
2969 os_mutex_enter(count_mutex);
2970 if (count == 0) {
2971 os_mutex_exit(count_mutex);
2972 break;
2973 }
2974 os_mutex_exit(count_mutex);
2975 }
2976 /* NOTE: It may not needed at "--backup" for now */
2977 /* mutex_enter(&(f_system->mutex)); */
2978
2979 os_mutex_free(count_mutex);
2980 datafiles_iter_free(it);
2981
2982 } //if (!xtrabackup_stream)
2983
2984 //mutex_exit(&(f_system->mutex));
2985 }
2986
2987
2988 /* suspend-at-end */
2989 if (xtrabackup_suspend_at_end) {
2990 os_file_t suspend_file = -1;
2991 char suspend_path[FN_REFLEN];
2992 ibool success, exists;
2993 os_file_type_t type;
2994
2995 sprintf(suspend_path, "%s%s", xtrabackup_target_dir,
2996 "/xtrabackup_suspended");
2997
2998 srv_normalize_path_for_win(suspend_path);
2999 /* os_file_create reads srv_unix_file_flush_method */
3000 suspend_file = os_file_create(
3001 0 /* dummy of innodb_file_data_key */,
3002 suspend_path, OS_FILE_OVERWRITE,
3003 OS_FILE_NORMAL, OS_DATA_FILE, &success);
3004
3005 if (!success) {
3006 fprintf(stderr, "xtrabackup: Error: failed to create file 'xtrabackup_suspended'\n");
3007 }
3008
3009 if (suspend_file != -1)
3010 os_file_close(suspend_file);
3011
3012 exists = TRUE;
3013 while (exists) {
3014 os_thread_sleep(200000); /*0.2 sec*/
3015 success = os_file_status(suspend_path, &exists, &type);
3016 if (!success)
3017 break;
3018 }
3019 xtrabackup_suspend_at_end = FALSE; /* suspend is 1 time */
3020 }
3021
3022 /* read the latest checkpoint lsn */
3023 latest_cp = ut_dulint_zero;
3024 {
3025 log_group_t* max_cp_group;
3026 ulint max_cp_field;
3027 ulint err;
3028
3029 err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field);
3030
3031 if (err != DB_SUCCESS) {
3032 fprintf(stderr, "xtrabackup: Error: recv_find_max_checkpoint() failed.\n");
3033 goto skip_last_cp;
3034 }
3035
3036 log_group_read_checkpoint_info(max_cp_group, max_cp_field);
3037
3038 latest_cp = MACH_READ_64(log_sys->checkpoint_buf + LOG_CHECKPOINT_LSN);
3039
3040 if (!xtrabackup_stream) {
3041 printf("xtrabackup: The latest check point (for incremental): '%" PRIu64 "'\n",
3042 latest_cp);
3043 } else {
3044 fprintf(stderr, "xtrabackup: The latest check point (for incremental): '%" PRIu64 "'\n",
3045 latest_cp);
3046 }
3047 }
3048skip_last_cp:
3049 /* stop log_copying_thread */
3050 log_copying = FALSE;
3051 if (!xtrabackup_stream) {
3052 printf("xtrabackup: Stopping log copying thread");
3053 while (log_copying_running) {
3054 printf(".");
3055 os_thread_sleep(200000); /*0.2 sec*/
3056 }
3057 printf("\n");
3058 } else {
3059 while (log_copying_running)
3060 os_thread_sleep(200000); /*0.2 sec*/
3061 }
3062
3063 /* output to metadata file */
3064 {
3065 char filename[FN_REFLEN];
3066
3067 if(!xtrabackup_incremental) {
3068 strcpy(metadata_type, "full-backuped");
3069 metadata_from_lsn = ut_dulint_zero;
3070 } else {
3071 strcpy(metadata_type, "incremental");
3072 metadata_from_lsn = incremental_lsn;
3073 }
3074 metadata_to_lsn = latest_cp;
3075 metadata_last_lsn = log_copy_scanned_lsn;
3076
3077 sprintf(filename, "%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
3078 if (xtrabackup_write_metadata(filename))
3079 fprintf(stderr, "xtrabackup: error: xtrabackup_write_metadata(xtrabackup_target_dir)\n");
3080
3081 if(xtrabackup_extra_lsndir) {
3082 sprintf(filename, "%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
3083 if (xtrabackup_write_metadata(filename))
3084 fprintf(stderr, "xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
3085 }
3086 }
3087
3088 if (!log_copying_succeed) {
3089 fprintf(stderr, "xtrabackup: Error: log_copying_thread failed.\n");
3090 exit(EXIT_FAILURE);
3091 }
3092
3093 if (!xtrabackup_stream)
3094 os_file_close(dst_log);
3095
3096 if (wait_throttle)
3097 os_event_free(wait_throttle);
3098
3099 if (!xtrabackup_stream) {
3100 printf("xtrabackup: Transaction log of lsn (%" PRIu64 ") to (%" PRIu64 ") was copied.\n",
3101 checkpoint_lsn_start, log_copy_scanned_lsn);
3102 } else {
3103 fprintf(stderr, "xtrabackup: Transaction log of lsn (%" PRIu64 ") to (%" PRIu64 ") was copied.\n",
3104 checkpoint_lsn_start, log_copy_scanned_lsn);
3105 if(xtrabackup_extra_lsndir) {
3106 char filename[FN_REFLEN];
3107 sprintf(filename, "%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
3108 if (xtrabackup_write_metadata(filename))
3109 fprintf(stderr, "xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
3110 }
3111 }
3112}
3113
3114/* ================= stats ================= */
3115static bool
3116xtrabackup_stats_level(
3117 dict_index_t* index,
3118 ulint level)
3119{
3120 ulint space;
3121 page_t* page;
3122
3123 rec_t* node_ptr;
3124
3125 ulint right_page_no;
3126
3127 page_cur_t cursor;
3128
3129 mtr_t mtr;
3130 mem_heap_t* heap = mem_heap_create(256);
3131
3132 ulint* offsets = NULL;
3133
3134 uint64_t n_pages, n_pages_extern;
3135 uint64_t sum_data, sum_data_extern;
3136 uint64_t n_recs;
3137 ulint page_size;
3138
3139 n_pages = sum_data = n_recs = 0;
3140 n_pages_extern = sum_data_extern = 0;
3141
3142 buf_block_t* block;
3143 ulint zip_size;
3144
3145 if (level == 0)
3146 fprintf(stdout, " leaf pages: ");
3147 else
3148 fprintf(stdout, " level %lu pages: ", level);
3149
3150 mtr_start(&mtr);
3151
3152 mtr_x_lock(&(index->lock), &mtr);
3153 block = btr_root_block_get(index, &mtr);
3154 page = buf_block_get_frame(block);
3155
3156 space = page_get_space_id(page);
3157 zip_size = fil_space_get_zip_size(space);
3158
3159 while (level != btr_page_get_level(page, &mtr)) {
3160
3161 ut_a(space == buf_block_get_space(block));
3162 ut_a(space == page_get_space_id(page));
3163 ut_a(!page_is_leaf(page));
3164
3165 page_cur_set_before_first(block, &cursor);
3166 page_cur_move_to_next(&cursor);
3167
3168 node_ptr = page_cur_get_rec(&cursor);
3169 offsets = rec_get_offsets(node_ptr, index, offsets,
3170 ULINT_UNDEFINED, &heap);
3171
3172 block = btr_node_ptr_get_child(node_ptr, index, offsets, &mtr);
3173 page = buf_block_get_frame(block);
3174 }
3175
3176loop:
3177 mem_heap_empty(heap);
3178 offsets = NULL;
3179 mtr_x_lock(&(index->lock), &mtr);
3180
3181 right_page_no = btr_page_get_next(page, &mtr);
3182
3183
3184 /*=================================*/
3185 //fprintf(stdout, "%lu ", (ulint) buf_frame_get_page_no(page));
3186
3187 n_pages++;
3188 sum_data += page_get_data_size(page);
3189 n_recs += page_get_n_recs(page);
3190
3191
3192 if (level == 0) {
3193 page_cur_t cur;
3194 ulint n_fields;
3195 ulint i;
3196 mem_heap_t* local_heap = NULL;
3197 ulint offsets_[REC_OFFS_NORMAL_SIZE];
3198 ulint* local_offsets = offsets_;
3199
3200 *offsets_ = (sizeof offsets_) / sizeof *offsets_;
3201
3202 page_cur_set_before_first(block, &cur);
3203
3205
3206 for (;;) {
3207 if (page_cur_is_after_last(&cur)) {
3208 break;
3209 }
3210
3211 local_offsets = rec_get_offsets(cur.rec, index, local_offsets,
3212 ULINT_UNDEFINED, &local_heap);
3213 n_fields = rec_offs_n_fields(local_offsets);
3214
3215 for (i = 0; i < n_fields; i++) {
3216 if (rec_offs_nth_extern(local_offsets, i)) {
3217 page_t* local_page;
3218 ulint space_id;
3219 ulint page_no;
3220 ulint offset;
3221 byte* blob_header;
3222 ulint part_len;
3223 mtr_t local_mtr;
3224 ulint local_len;
3225 byte* data;
3226 buf_block_t* local_block;
3227
3228 data = rec_get_nth_field(cur.rec, local_offsets, i, &local_len);
3229
3230 ut_a(local_len >= BTR_EXTERN_FIELD_REF_SIZE);
3231 local_len -= BTR_EXTERN_FIELD_REF_SIZE;
3232
3233 space_id = mach_read_from_4(data + local_len + BTR_EXTERN_SPACE_ID);
3234 page_no = mach_read_from_4(data + local_len + BTR_EXTERN_PAGE_NO);
3235 offset = mach_read_from_4(data + local_len + BTR_EXTERN_OFFSET);
3236
3237 if (offset != FIL_PAGE_DATA)
3238 fprintf(stderr, "\nWarning: several record may share same external page.\n");
3239
3240 for (;;) {
3241 mtr_start(&local_mtr);
3242
3243 local_block = btr_block_get(space_id, zip_size, page_no, RW_S_LATCH, &local_mtr);
3244 local_page = buf_block_get_frame(local_block);
3245
3246 blob_header = local_page + offset;
3247#define BTR_BLOB_HDR_PART_LEN 0
3248#define BTR_BLOB_HDR_NEXT_PAGE_NO 4
3249 //part_len = btr_blob_get_part_len(blob_header);
3250 part_len = mach_read_from_4(blob_header + BTR_BLOB_HDR_PART_LEN);
3251
3252 //page_no = btr_blob_get_next_page_no(blob_header);
3253 page_no = mach_read_from_4(blob_header + BTR_BLOB_HDR_NEXT_PAGE_NO);
3254
3255 offset = FIL_PAGE_DATA;
3256
3257
3258
3259
3260 /*=================================*/
3261 //fprintf(stdout, "[%lu] ", (ulint) buf_frame_get_page_no(page));
3262
3263 n_pages_extern++;
3264 sum_data_extern += part_len;
3265
3266
3267 mtr_commit(&local_mtr);
3268
3269 if (page_no == FIL_NULL)
3270 break;
3271 }
3272 }
3273 }
3274
3276 }
3277 }
3278
3279
3280
3281
3282 mtr_commit(&mtr);
3283 if (right_page_no != FIL_NULL) {
3284 mtr_start(&mtr);
3285 block = btr_block_get(space, zip_size, right_page_no, RW_X_LATCH, &mtr);
3286 page = buf_block_get_frame(block);
3287 goto loop;
3288 }
3289 mem_heap_free(heap);
3290
3291 if (zip_size) {
3292 page_size = zip_size;
3293 } else {
3294 page_size = UNIV_PAGE_SIZE;
3295 }
3296
3297 if (level == 0)
3298 fprintf(stdout, "recs=%" PRIu64 ", ", n_recs);
3299
3300 fprintf(stdout, "pages=%" PRIu64 ", data=%" PRIu64 " bytes, data/pages=%" PRIu64 "%%",
3301 n_pages, sum_data,
3302 ((sum_data * 100)/ page_size)/n_pages);
3303
3304
3305 if (level == 0 && n_pages_extern) {
3306 putc('\n', stdout);
3307 /* also scan blob pages*/
3308 fprintf(stdout, " external pages: ");
3309
3310 fprintf(stdout, "pages=%" PRIu64 ", data=%" PRIu64 " bytes, data/pages=%" PRIu64 "%%",
3311 n_pages_extern, sum_data_extern,
3312 ((sum_data_extern * 100)/ page_size)/n_pages_extern);
3313 }
3314
3315 putc('\n', stdout);
3316
3317 if (level > 0) {
3318 xtrabackup_stats_level(index, level - 1);
3319 }
3320
3321 return(TRUE);
3322}
3323
3324static void
3325xtrabackup_stats_func(void)
3326{
3327 ulint n;
3328
3329 /* cd to datadir */
3330
3331 if (chdir(mysql_real_data_home) != 0)
3332 {
3333 fprintf(stderr, "xtrabackup: cannot my_setwd %s\n", mysql_real_data_home);
3334 exit(EXIT_FAILURE);
3335 }
3336 fprintf(stderr, "xtrabackup: cd to %s\n", mysql_real_data_home);
3337
3338 mysql_data_home= mysql_data_home_buff;
3339 mysql_data_home[0]=FN_CURLIB; // all paths are relative from here
3340 mysql_data_home[1]=0;
3341
3342 /* set read only */
3343 srv_read_only = TRUE;
3344 srv_fake_write = TRUE;
3345
3346 /* initialize components */
3347 if(innodb_init_param())
3348 exit(EXIT_FAILURE);
3349
3350 /* Check if the log files have been created, otherwise innodb_init()
3351 will crash when called with srv_read_only == TRUE */
3352 for (n = 0; n < srv_n_log_files; n++) {
3353 char logname[FN_REFLEN];
3354 ibool exists;
3355 os_file_type_t type;
3356
3357 sprintf(logname, "ib_logfile%lu", (ulong) n);
3358 if (!os_file_status(logname, &exists, &type) || !exists ||
3359 type != OS_FILE_TYPE_FILE) {
3360 fprintf(stderr, "xtrabackup: Error: "
3361 "Cannot find log file %s.\n", logname);
3362 fprintf(stderr, "xtrabackup: Error: "
3363 "to use the statistics feature, you need a "
3364 "clean copy of the database including "
3365 "correctly sized log files, so you need to "
3366 "execute with --prepare twice to use this "
3367 "functionality on a backup.\n");
3368 exit(EXIT_FAILURE);
3369 }
3370 }
3371
3372 fprintf(stderr, "xtrabackup: Starting 'read-only' InnoDB instance to gather index statistics.\n"
3373 "xtrabackup: Using %" PRIu64 " bytes for buffer pool (set by --use-memory parameter)\n",
3374 xtrabackup_use_memory);
3375
3376 if(innodb_init())
3377 exit(EXIT_FAILURE);
3378
3379 fprintf(stdout, "\n\n<INDEX STATISTICS>\n");
3380
3381 /* gather stats */
3382
3383 {
3384 dict_table_t* sys_tables;
3385 dict_index_t* sys_index;
3386 dict_table_t* table;
3387 btr_pcur_t pcur;
3388 rec_t* rec;
3389 byte* field;
3390 ulint len;
3391 mtr_t mtr;
3392
3393 /* Enlarge the fatal semaphore wait timeout during the InnoDB table
3394 monitor printout */
3395
3396 mutex_enter(&kernel_mutex);
3397 srv_fatal_semaphore_wait_threshold += 72000; /* 20 hours */
3398 mutex_exit(&kernel_mutex);
3399
3400 mutex_enter(&(dict_sys->mutex));
3401
3402 mtr_start(&mtr);
3403
3404 sys_tables = dict_table_get_low("SYS_TABLES");
3405 sys_index = UT_LIST_GET_FIRST(sys_tables->indexes);
3406
3407 btr_pcur_open_at_index_side(TRUE, sys_index, BTR_SEARCH_LEAF, &pcur,
3408 TRUE, &mtr);
3409loop:
3410 btr_pcur_move_to_next_user_rec(&pcur, &mtr);
3411
3412 rec = btr_pcur_get_rec(&pcur);
3413
3414 if (!btr_pcur_is_on_user_rec(&pcur))
3415 {
3416 /* end of index */
3417
3418 btr_pcur_close(&pcur);
3419 mtr_commit(&mtr);
3420
3421 mutex_exit(&(dict_sys->mutex));
3422
3423 /* Restore the fatal semaphore wait timeout */
3424
3425 mutex_enter(&kernel_mutex);
3426 srv_fatal_semaphore_wait_threshold -= 72000; /* 20 hours */
3427 mutex_exit(&kernel_mutex);
3428
3429 goto end;
3430 }
3431
3432 field = rec_get_nth_field_old(rec, 0, &len);
3433
3434 if (!rec_get_deleted_flag(rec, 0))
3435 {
3436
3437 /* We found one */
3438
3439 char* table_name = mem_strdupl((char*) field, len);
3440
3441 btr_pcur_store_position(&pcur, &mtr);
3442
3443 mtr_commit(&mtr);
3444
3445 table = dict_table_get_low(table_name);
3446 mem_free(table_name);
3447
3448
3449 if (xtrabackup_tables) {
3450 char *p;
3451 int regres= 0;
3452 int i;
3453
3454 p = strstr(table->name, SRV_PATH_SEPARATOR_STR);
3455
3456 if (p)
3457 *p = '.';
3458
3459 for (i = 0; i < tables_regex_num; i++) {
3460 regres = regexec(&tables_regex[i], table->name, 1, tables_regmatch, 0);
3461 if (regres != REG_NOMATCH)
3462 break;
3463 }
3464
3465 if (p)
3466 *p = SRV_PATH_SEPARATOR;
3467
3468 if ( regres == REG_NOMATCH )
3469 goto skip;
3470 }
3471
3472 if (xtrabackup_tables_file) {
3473 xtrabackup_tables_t* xtable;
3474
3475 HASH_SEARCH(name_hash, tables_hash, ut_fold_string(table->name),
3476 xtrabackup_tables_t*,
3477 xtable,
3478 ut_ad(xtable->name),
3479 !strcmp(xtable->name, table->name));
3480
3481 if (!xtable)
3482 goto skip;
3483 }
3484
3485
3486 if (table == NULL) {
3487 fputs("InnoDB: Failed to load table ", stderr);
3488 ut_print_namel(stderr, NULL, TRUE, (char*) field, len);
3489 putc('\n', stderr);
3490 } else {
3491 dict_index_t* index;
3492
3493 /* The table definition was corrupt if there
3494 is no index */
3495
3496 if (dict_table_get_first_index(table)) {
3497#ifdef XTRADB_BASED
3498 dict_update_statistics(table, TRUE, FALSE);
3499#elif defined(INNODB_VERSION_SHORT)
3500 dict_update_statistics(table, TRUE);
3501#else
3502 dict_update_statistics_low(table, TRUE);
3503#endif
3504 }
3505
3506 //dict_table_print_low(table);
3507
3508 index = UT_LIST_GET_FIRST(table->indexes);
3509 while (index != NULL) {
3510{
3511 IB_INT64 n_vals;
3512
3513 if (index->n_user_defined_cols > 0) {
3514 n_vals = index->stat_n_diff_key_vals[
3515 index->n_user_defined_cols];
3516 } else {
3517 n_vals = index->stat_n_diff_key_vals[1];
3518 }
3519
3520 fprintf(stdout,
3521 " table: %s, index: %s, space id: %lu, root page: %lu"
3522 ", zip size: %lu"
3523 "\n estimated statistics in dictionary:\n"
3524 " key vals: %lu, leaf pages: %lu, size pages: %lu\n"
3525 " real statistics:\n",
3526 table->name, index->name,
3527 (ulong) index->space,
3528 (ulong) index->page,
3529 (ulong) fil_space_get_zip_size(index->space),
3530 (ulong) n_vals,
3531 (ulong) index->stat_n_leaf_pages,
3532 (ulong) index->stat_index_size);
3533
3534 {
3535 mtr_t local_mtr;
3536 page_t* root;
3537 ulint page_level;
3538
3539 mtr_start(&local_mtr);
3540
3541 mtr_x_lock(&(index->lock), &local_mtr);
3542 root = btr_root_get(index, &local_mtr);
3543
3544 page_level = btr_page_get_level(root, &local_mtr);
3545
3546 xtrabackup_stats_level(index, page_level);
3547
3548 mtr_commit(&local_mtr);
3549 }
3550
3551 putc('\n', stdout);
3552}
3553 index = UT_LIST_GET_NEXT(indexes, index);
3554 }
3555 }
3556
3557skip:
3558 mtr_start(&mtr);
3559
3560 btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr);
3561 }
3562
3563 goto loop;
3564 }
3565
3566end:
3567 putc('\n', stdout);
3568
3569 /* shutdown InnoDB */
3570 if(innodb_end())
3571 exit(EXIT_FAILURE);
3572}
3573
3574/* ================= prepare ================= */
3575
3576static bool
3577xtrabackup_init_temp_log(void)
3578{
3579 os_file_t src_file = -1;
3580 char src_path[FN_REFLEN];
3581 char dst_path[FN_REFLEN];
3582 ibool success;
3583
3584 ulint field;
3585 byte* log_buf;
3586 byte* log_buf_ = NULL;
3587
3588 IB_INT64 file_size;
3589
3590 LSN64 max_no;
3591 LSN64 max_lsn= 0;
3592 LSN64 checkpoint_no;
3593
3594 ulint fold;
3595
3596 max_no = ut_dulint_zero;
3597
3598 if(!xtrabackup_incremental_dir) {
3599 sprintf(dst_path, "%s%s", xtrabackup_target_dir, "/ib_logfile0");
3600 sprintf(src_path, "%s%s", xtrabackup_target_dir, "/xtrabackup_logfile");
3601 } else {
3602 sprintf(dst_path, "%s%s", xtrabackup_incremental_dir, "/ib_logfile0");
3603 sprintf(src_path, "%s%s", xtrabackup_incremental_dir, "/xtrabackup_logfile");
3604 }
3605
3608retry:
3609 src_file = os_file_create_simple_no_error_handling(
3610 0 /* dummy of innodb_file_data_key */,
3611 src_path, OS_FILE_OPEN,
3612 OS_FILE_READ_WRITE /* OS_FILE_READ_ONLY */, &success);
3613 if (!success) {
3614 /* The following call prints an error message */
3616
3617 fprintf(stderr,
3618"xtrabackup: Warning: cannot open %s. will try to find.\n",
3619 src_path);
3620
3621 /* check if ib_logfile0 may be xtrabackup_logfile */
3622 src_file = os_file_create_simple_no_error_handling(
3623 0 /* dummy of innodb_file_data_key */,
3624 dst_path, OS_FILE_OPEN,
3625 OS_FILE_READ_WRITE /* OS_FILE_READ_ONLY */, &success);
3626 if (!success) {
3628 fprintf(stderr,
3629" xtrabackup: Fatal error: cannot find %s.\n",
3630 src_path);
3631
3632 goto error;
3633 }
3634
3635 log_buf_ = (unsigned char*) ut_malloc(LOG_FILE_HDR_SIZE * 2);
3636 log_buf = (unsigned char*) ut_align(log_buf_, LOG_FILE_HDR_SIZE);
3637
3638 success = os_file_read(src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
3639 if (!success) {
3640 goto error;
3641 }
3642
3643 if ( ut_memcmp(log_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
3644 (byte*)"xtrabkup", (sizeof "xtrabkup") - 1) == 0) {
3645 fprintf(stderr,
3646" xtrabackup: 'ib_logfile0' seems to be 'xtrabackup_logfile'. will retry.\n");
3647
3648 ut_free(log_buf_);
3649 log_buf_ = NULL;
3650
3651 os_file_close(src_file);
3652 src_file = -1;
3653
3654 /* rename and try again */
3655 success = os_file_rename(
3656 0 /* dummy of innodb_file_data_key */,
3657 dst_path, src_path);
3658 if (!success) {
3659 goto error;
3660 }
3661
3662 goto retry;
3663 }
3664
3665 fprintf(stderr,
3666" xtrabackup: Fatal error: cannot find %s.\n",
3667 src_path);
3668
3669 ut_free(log_buf_);
3670 log_buf_ = NULL;
3671
3672 os_file_close(src_file);
3673 src_file = -1;
3674
3675 goto error;
3676 }
3677
3678#ifdef USE_POSIX_FADVISE
3679 posix_fadvise(src_file, 0, 0, POSIX_FADV_SEQUENTIAL);
3680 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
3681#endif
3682
3683 if (srv_unix_file_flush_method == SRV_UNIX_O_DIRECT) {
3684 os_file_set_nocache(src_file, src_path, "OPEN");
3685 }
3686
3687 file_size = os_file_get_size_as_iblonglong(src_file);
3688
3689
3690 /* TODO: We should skip the following modifies, if it is not the first time. */
3691 log_buf_ = (unsigned char*) ut_malloc(UNIV_PAGE_SIZE * 129);
3692 log_buf = (unsigned char*) ut_align(log_buf_, UNIV_PAGE_SIZE);
3693
3694 /* read log file header */
3695 success = os_file_read(src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
3696 if (!success) {
3697 goto error;
3698 }
3699
3700 if ( ut_memcmp(log_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
3701 (byte*)"xtrabkup", (sizeof "xtrabkup") - 1) != 0 ) {
3702 printf("xtrabackup: notice: xtrabackup_logfile was already used to '--prepare'.\n");
3703 goto skip_modify;
3704 } else {
3705 /* clear it later */
3706 //memset(log_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
3707 // ' ', 4);
3708 }
3709
3710 /* read last checkpoint lsn */
3711 for (field = LOG_CHECKPOINT_1; field <= LOG_CHECKPOINT_2;
3712 field += LOG_CHECKPOINT_2 - LOG_CHECKPOINT_1) {
3713 if (!recv_check_cp_is_consistent(log_buf + field))
3714 goto not_consistent;
3715
3716 checkpoint_no = MACH_READ_64(log_buf + field + LOG_CHECKPOINT_NO);
3717
3718 if (ut_dulint_cmp(checkpoint_no, max_no) >= 0) {
3719 max_no = checkpoint_no;
3720 max_lsn = MACH_READ_64(log_buf + field + LOG_CHECKPOINT_LSN);
3721/*
3722 mach_write_to_4(log_buf + field + LOG_CHECKPOINT_OFFSET,
3723 LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3724 ut_dulint_align_down(max_lsn,OS_FILE_LOG_BLOCK_SIZE)));
3725
3726 ulint fold;
3727 fold = ut_fold_binary(log_buf + field, LOG_CHECKPOINT_CHECKSUM_1);
3728 mach_write_to_4(log_buf + field + LOG_CHECKPOINT_CHECKSUM_1, fold);
3729
3730 fold = ut_fold_binary(log_buf + field + LOG_CHECKPOINT_LSN,
3731 LOG_CHECKPOINT_CHECKSUM_2 - LOG_CHECKPOINT_LSN);
3732 mach_write_to_4(log_buf + field + LOG_CHECKPOINT_CHECKSUM_2, fold);
3733*/
3734 }
3735not_consistent:
3736 ;
3737 }
3738
3739 if (ut_dulint_cmp(max_no, ut_dulint_zero) == 0) {
3740 fprintf(stderr, "xtrabackup: No valid checkpoint found.\n");
3741 goto error;
3742 }
3743
3744
3745 /* It seems to be needed to overwrite the both checkpoint area. */
3746 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_LSN, max_lsn);
3747 mach_write_to_4(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_OFFSET,
3748 LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3749 ut_dulint_align_down(max_lsn,OS_FILE_LOG_BLOCK_SIZE)));
3750#ifdef XTRADB_BASED
3751 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_ARCHIVED_LSN,
3752 (ib_uint64_t)(LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3753 ut_dulint_align_down(max_lsn,OS_FILE_LOG_BLOCK_SIZE))));
3754#endif
3755 fold = ut_fold_binary(log_buf + LOG_CHECKPOINT_1, LOG_CHECKPOINT_CHECKSUM_1);
3756 mach_write_to_4(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_CHECKSUM_1, fold);
3757
3758 fold = ut_fold_binary(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_LSN,
3759 LOG_CHECKPOINT_CHECKSUM_2 - LOG_CHECKPOINT_LSN);
3760 mach_write_to_4(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_CHECKSUM_2, fold);
3761
3762 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_LSN, max_lsn);
3763 mach_write_to_4(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_OFFSET,
3764 LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3765 ut_dulint_align_down(max_lsn,OS_FILE_LOG_BLOCK_SIZE)));
3766#ifdef XTRADB_BASED
3767 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_ARCHIVED_LSN,
3768 (ib_uint64_t)(LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3769 ut_dulint_align_down(max_lsn,OS_FILE_LOG_BLOCK_SIZE))));
3770#endif
3771 fold = ut_fold_binary(log_buf + LOG_CHECKPOINT_2, LOG_CHECKPOINT_CHECKSUM_1);
3772 mach_write_to_4(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_CHECKSUM_1, fold);
3773
3774 fold = ut_fold_binary(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_LSN,
3775 LOG_CHECKPOINT_CHECKSUM_2 - LOG_CHECKPOINT_LSN);
3776 mach_write_to_4(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_CHECKSUM_2, fold);
3777
3778
3779 success = os_file_write(src_path, src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
3780 if (!success) {
3781 goto error;
3782 }
3783
3784 /* expand file size (9/8) and align to UNIV_PAGE_SIZE */
3785
3786 if (file_size % UNIV_PAGE_SIZE) {
3787 memset(log_buf, 0, UNIV_PAGE_SIZE);
3788 success = os_file_write(src_path, src_file, log_buf,
3789 (ulint)(file_size & 0xFFFFFFFFUL),
3790 (ulint)(file_size >> 32),
3791 UNIV_PAGE_SIZE - (file_size % UNIV_PAGE_SIZE));
3792 if (!success) {
3793 goto error;
3794 }
3795
3796 file_size = os_file_get_size_as_iblonglong(src_file);
3797 }
3798
3799 /* TODO: We should judge whether the file is already expanded or not... */
3800 {
3801 ulint expand;
3802
3803 memset(log_buf, 0, UNIV_PAGE_SIZE * 128);
3804 expand = file_size / UNIV_PAGE_SIZE / 8;
3805
3806 for (; expand > 128; expand -= 128) {
3807 success = os_file_write(src_path, src_file, log_buf,
3808 (ulint)(file_size & 0xFFFFFFFFUL),
3809 (ulint)(file_size >> 32),
3810 UNIV_PAGE_SIZE * 128);
3811 if (!success) {
3812 goto error;
3813 }
3814 file_size += UNIV_PAGE_SIZE * 128;
3815 }
3816
3817 if (expand) {
3818 success = os_file_write(src_path, src_file, log_buf,
3819 (ulint)(file_size & 0xFFFFFFFFUL),
3820 (ulint)(file_size >> 32),
3821 expand * UNIV_PAGE_SIZE);
3822 if (!success) {
3823 goto error;
3824 }
3825 file_size += UNIV_PAGE_SIZE * expand;
3826 }
3827 }
3828
3829 /* make larger than 2MB */
3830 if (file_size < 2*1024*1024L) {
3831 memset(log_buf, 0, UNIV_PAGE_SIZE);
3832 while (file_size < 2*1024*1024L) {
3833 success = os_file_write(src_path, src_file, log_buf,
3834 (ulint)(file_size & 0xFFFFFFFFUL),
3835 (ulint)(file_size >> 32),
3836 UNIV_PAGE_SIZE);
3837 if (!success) {
3838 goto error;
3839 }
3840 file_size += UNIV_PAGE_SIZE;
3841 }
3842 file_size = os_file_get_size_as_iblonglong(src_file);
3843 }
3844
3845 printf("xtrabackup: xtrabackup_logfile detected: size=%" PRIu64 ", start_lsn=(%" PRIu64 ")\n",
3846 file_size, max_lsn);
3847
3848 os_file_close(src_file);
3849 src_file = -1;
3850
3851 /* Backup log parameters */
3852 innobase_log_group_home_dir_backup = innobase_log_group_home_dir;
3853 innobase_log_file_size_backup = innobase_log_file_size;
3854 innobase_log_files_in_group_backup = innobase_log_files_in_group;
3855
3856 /* fake InnoDB */
3857 innobase_log_group_home_dir = NULL;
3858 innobase_log_file_size = file_size;
3859 innobase_log_files_in_group = 1;
3860
3861 srv_thread_concurrency = 0;
3862
3863 /* rename 'xtrabackup_logfile' to 'ib_logfile0' */
3864 success = os_file_rename(
3865 0 /* dummy of innodb_file_data_key */,
3866 src_path, dst_path);
3867 if (!success) {
3868 goto error;
3869 }
3870 xtrabackup_logfile_is_renamed = TRUE;
3871
3872 ut_free(log_buf_);
3873
3874 return(FALSE);
3875
3876skip_modify:
3877 os_file_close(src_file);
3878 src_file = -1;
3879 ut_free(log_buf_);
3880 return(FALSE);
3881
3882error:
3883 if (src_file != -1)
3884 os_file_close(src_file);
3885 if (log_buf_)
3886 ut_free(log_buf_);
3887 fprintf(stderr, "xtrabackup: Error: xtrabackup_init_temp_log() failed.\n");
3888 return(TRUE); /*ERROR*/
3889}
3890
3891/***********************************************************************
3892Generates path to the meta file path from a given path to an incremental .delta
3893by replacing trailing ".delta" with ".meta", or returns error if 'delta_path'
3894does not end with the ".delta" character sequence.
3895@return TRUE on success, FALSE on error. */
3896static
3897ibool
3898get_meta_path(
3899 const char *delta_path, /* in: path to a .delta file */
3900 char *meta_path) /* out: path to the corresponding .meta
3901 file */
3902{
3903 size_t len = strlen(delta_path);
3904
3905 if (len <= 6 || strcmp(delta_path + len - 6, ".delta")) {
3906 return FALSE;
3907 }
3908 memcpy(meta_path, delta_path, len - 6);
3909 strcpy(meta_path + len - 6, XB_DELTA_INFO_SUFFIX);
3910
3911 return TRUE;
3912}
3913
3914static void
3915xtrabackup_apply_delta(
3916 const char* dirname, /* in: dir name of incremental */
3917 const char* dbname, /* in: database name (ibdata: NULL) */
3918 const char* filename, /* in: file name (not a path),
3919 including the .delta extension */
3920 bool )
3921{
3922 os_file_t src_file = -1;
3923 os_file_t dst_file = -1;
3924 const size_t path_buffer_size = OS_FILE_MAX_PATH * 3 + 3;
3925 boost::scoped_array<char> src_path_buf(new char[path_buffer_size]);
3926 boost::scoped_array<char> dst_path_buf(new char[path_buffer_size]);
3927 boost::scoped_array<char> meta_path_buf(new char[path_buffer_size]);
3928 char* src_path = src_path_buf.get();
3929 char* dst_path = dst_path_buf.get();
3930 char* meta_path = meta_path_buf.get();
3931 ibool success;
3932
3933 ibool last_buffer = FALSE;
3934 ulint page_in_buffer;
3935 ulint incremental_buffers = 0;
3936
3937 xb_delta_info_t info;
3938 ulint page_size;
3939 ulint page_size_shift;
3940
3941 ut_a(xtrabackup_incremental);
3942
3943 if (dbname) {
3944 snprintf(src_path, path_buffer_size, "%s/%s/%s",
3945 dirname, dbname, filename);
3946 snprintf(dst_path, path_buffer_size, "%s/%s/%s",
3947 xtrabackup_real_target_dir, dbname, filename);
3948 } else {
3949 snprintf(src_path, path_buffer_size, "%s/%s",
3950 dirname, filename);
3951 snprintf(dst_path, path_buffer_size, "%s/%s",
3952 xtrabackup_real_target_dir, filename);
3953 }
3954 dst_path[strlen(dst_path) - 6] = '\0';
3955
3956 if (!get_meta_path(src_path, meta_path)) {
3957 goto error;
3958 }
3959
3962 srv_normalize_path_for_win(meta_path);
3963
3964 if (!xb_read_delta_metadata(meta_path, &info)) {
3965 goto error;
3966 }
3967
3968 page_size = info.page_size;
3969 page_size_shift = get_bit_shift(page_size);
3970 fprintf(stderr, "xtrabackup: page size for %s is %lu bytes\n",
3971 src_path, page_size);
3972 if (page_size_shift < 10 ||
3973 page_size_shift > UNIV_PAGE_SIZE_SHIFT_MAX) {
3974 fprintf(stderr,
3975 "xtrabackup: error: invalid value of page_size "
3976 "(%lu bytes) read from %s\n", page_size, meta_path);
3977 goto error;
3978 }
3979
3980 src_file = os_file_create_simple_no_error_handling(
3981 0 /* dummy of innodb_file_data_key */,
3982 src_path, OS_FILE_OPEN, OS_FILE_READ_WRITE, &success);
3983 if (!success) {
3985 fprintf(stderr,
3986 "xtrabackup: error: cannot open %s\n",
3987 src_path);
3988 goto error;
3989 }
3990
3991#ifdef USE_POSIX_FADVISE
3992 posix_fadvise(src_file, 0, 0, POSIX_FADV_SEQUENTIAL);
3993 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
3994#endif
3995
3996 if (srv_unix_file_flush_method == SRV_UNIX_O_DIRECT) {
3997 os_file_set_nocache(src_file, src_path, "OPEN");
3998 }
3999
4000 dst_file = os_file_create_simple_no_error_handling(
4001 0 /* dummy of innodb_file_data_key */,
4002 dst_path, OS_FILE_OPEN, OS_FILE_READ_WRITE, &success);
4003 if (!success) {
4005 fprintf(stderr,
4006 "xtrabackup: error: cannot open %s\n",
4007 dst_path);
4008 goto error;
4009 }
4010
4011#ifdef USE_POSIX_FADVISE
4012 posix_fadvise(dst_file, 0, 0, POSIX_FADV_DONTNEED);
4013#endif
4014
4015 if (srv_unix_file_flush_method == SRV_UNIX_O_DIRECT) {
4016 os_file_set_nocache(dst_file, dst_path, "OPEN");
4017 }
4018
4019 printf("Applying %s ...\n", src_path);
4020
4021 while (!last_buffer) {
4022 ulint cluster_header;
4023
4024 /* read to buffer */
4025 /* first block of block cluster */
4026 success = os_file_read(src_file, incremental_buffer,
4027 ((incremental_buffers * (page_size / 4))
4028 << page_size_shift) & 0xFFFFFFFFUL,
4029 (incremental_buffers * (page_size / 4))
4030 >> (32 - page_size_shift),
4031 page_size);
4032 if (!success) {
4033 goto error;
4034 }
4035
4036 cluster_header = mach_read_from_4(incremental_buffer);
4037 switch(cluster_header) {
4038 case 0x78747261UL: /*"xtra"*/
4039 break;
4040 case 0x58545241UL: /*"XTRA"*/
4041 last_buffer = TRUE;
4042 break;
4043 default:
4044 fprintf(stderr,
4045 "xtrabackup: error: %s seems not .delta file.\n",
4046 src_path);
4047 goto error;
4048 }
4049
4050 for (page_in_buffer = 1; page_in_buffer < page_size / 4;
4051 page_in_buffer++) {
4052 if (mach_read_from_4(incremental_buffer + page_in_buffer * 4)
4053 == 0xFFFFFFFFUL)
4054 break;
4055 }
4056
4057 ut_a(last_buffer || page_in_buffer == page_size / 4);
4058
4059 /* read whole of the cluster */
4060 success = os_file_read(src_file, incremental_buffer,
4061 ((incremental_buffers * (page_size / 4))
4062 << page_size_shift) & 0xFFFFFFFFUL,
4063 (incremental_buffers * (page_size / 4))
4064 >> (32 - page_size_shift),
4065 page_in_buffer * page_size);
4066 if (!success) {
4067 goto error;
4068 }
4069
4070 for (page_in_buffer = 1; page_in_buffer < page_size / 4;
4071 page_in_buffer++) {
4072 ulint offset_on_page;
4073
4074 offset_on_page = mach_read_from_4(incremental_buffer + page_in_buffer * 4);
4075
4076 if (offset_on_page == 0xFFFFFFFFUL)
4077 break;
4078
4079 /* apply blocks in the cluster */
4080// if (ut_dulint_cmp(incremental_lsn,
4081// MACH_READ_64(incremental_buffer
4082// + page_in_buffer * page_size
4083// + FIL_PAGE_LSN)) >= 0)
4084// continue;
4085
4086 success = os_file_write(dst_path, dst_file,
4087 incremental_buffer +
4088 page_in_buffer * page_size,
4089 (offset_on_page << page_size_shift) &
4090 0xFFFFFFFFUL,
4091 offset_on_page >> (32 - page_size_shift),
4092 page_size);
4093 if (!success) {
4094 goto error;
4095 }
4096 }
4097
4098 incremental_buffers++;
4099 }
4100
4101 if (src_file != -1)
4102 os_file_close(src_file);
4103 if (dst_file != -1)
4104 os_file_close(dst_file);
4105 return;
4106
4107error:
4108 if (src_file != -1)
4109 os_file_close(src_file);
4110 if (dst_file != -1)
4111 os_file_close(dst_file);
4112 fprintf(stderr, "xtrabackup: Error: xtrabackup_apply_delta() failed.\n");
4113 return;
4114}
4115
4116static void
4117xtrabackup_apply_deltas(bool check_newer)
4118{
4119 int ret;
4120 char dbpath[OS_FILE_MAX_PATH * 2 + 2];
4121 os_file_dir_t dir;
4122 os_file_dir_t dbdir;
4123 os_file_stat_t dbinfo;
4124 os_file_stat_t fileinfo;
4125 ulint err = DB_SUCCESS;
4126 static char current_dir[2];
4127
4128 current_dir[0] = FN_CURLIB;
4129 current_dir[1] = 0;
4130 srv_data_home = current_dir;
4131
4132 /* datafile */
4133 dbdir = os_file_opendir(xtrabackup_incremental_dir, FALSE);
4134
4135 if (dbdir != NULL) {
4136 ret = fil_file_readdir_next_file(&err, xtrabackup_incremental_dir, dbdir,
4137 &fileinfo);
4138 while (ret == 0) {
4139 if (fileinfo.type == OS_FILE_TYPE_DIR) {
4140 goto next_file_item_1;
4141 }
4142
4143 if (strlen(fileinfo.name) > 6
4144 && 0 == strcmp(fileinfo.name +
4145 strlen(fileinfo.name) - 6,
4146 ".delta")) {
4147 xtrabackup_apply_delta(
4148 xtrabackup_incremental_dir, NULL,
4149 fileinfo.name, check_newer);
4150 }
4151next_file_item_1:
4152 ret = fil_file_readdir_next_file(&err,
4153 xtrabackup_incremental_dir, dbdir,
4154 &fileinfo);
4155 }
4156
4157 os_file_closedir(dbdir);
4158 } else {
4159 fprintf(stderr, "xtrabackup: Cannot open dir %s\n", xtrabackup_incremental_dir);
4160 }
4161
4162 /* single table tablespaces */
4163 dir = os_file_opendir(xtrabackup_incremental_dir, FALSE);
4164
4165 if (dir == NULL) {
4166 fprintf(stderr, "xtrabackup: Cannot open dir %s\n", xtrabackup_incremental_dir);
4167 }
4168
4169 ret = fil_file_readdir_next_file(&err, xtrabackup_incremental_dir, dir,
4170 &dbinfo);
4171 while (ret == 0) {
4172 if (dbinfo.type == OS_FILE_TYPE_FILE
4173 || dbinfo.type == OS_FILE_TYPE_UNKNOWN) {
4174
4175 goto next_datadir_item;
4176 }
4177
4178 snprintf(dbpath, sizeof(dbpath), "%s/%s",
4179 xtrabackup_incremental_dir, dbinfo.name);
4181
4182 dbdir = os_file_opendir(dbpath, FALSE);
4183
4184 if (dbdir != NULL) {
4185
4186 ret = fil_file_readdir_next_file(&err, dbpath, dbdir,
4187 &fileinfo);
4188 while (ret == 0) {
4189
4190 if (fileinfo.type == OS_FILE_TYPE_DIR) {
4191
4192 goto next_file_item_2;
4193 }
4194
4195 if (strlen(fileinfo.name) > 6
4196 && 0 == strcmp(fileinfo.name +
4197 strlen(fileinfo.name) - 6,
4198 ".delta")) {
4199 /* The name ends in .delta; try opening
4200 the file */
4201 xtrabackup_apply_delta(
4202 xtrabackup_incremental_dir, dbinfo.name,
4203 fileinfo.name, check_newer);
4204 }
4205next_file_item_2:
4206 ret = fil_file_readdir_next_file(&err,
4207 dbpath, dbdir,
4208 &fileinfo);
4209 }
4210
4211 os_file_closedir(dbdir);
4212 }
4213next_datadir_item:
4214 ret = fil_file_readdir_next_file(&err,
4215 xtrabackup_incremental_dir,
4216 dir, &dbinfo);
4217 }
4218
4219 os_file_closedir(dir);
4220
4221}
4222
4223static bool
4224xtrabackup_close_temp_log(bool clear_flag)
4225{
4226 os_file_t src_file = -1;
4227 char src_path[FN_REFLEN];
4228 char dst_path[FN_REFLEN];
4229 ibool success;
4230
4231 byte* log_buf;
4232 byte* log_buf_ = NULL;
4233
4234
4235 if (!xtrabackup_logfile_is_renamed)
4236 return(FALSE);
4237
4238 /* Restore log parameters */
4239 innobase_log_group_home_dir = innobase_log_group_home_dir_backup;
4240 innobase_log_file_size = innobase_log_file_size_backup;
4241 innobase_log_files_in_group = innobase_log_files_in_group_backup;
4242
4243 /* rename 'ib_logfile0' to 'xtrabackup_logfile' */
4244 if(!xtrabackup_incremental_dir) {
4245 sprintf(dst_path, "%s%s", xtrabackup_target_dir, "/ib_logfile0");
4246 sprintf(src_path, "%s%s", xtrabackup_target_dir, "/xtrabackup_logfile");
4247 } else {
4248 sprintf(dst_path, "%s%s", xtrabackup_incremental_dir, "/ib_logfile0");
4249 sprintf(src_path, "%s%s", xtrabackup_incremental_dir, "/xtrabackup_logfile");
4250 }
4251
4254
4255 success = os_file_rename(
4256 0 /* dummy of innodb_file_data_key */,
4257 dst_path, src_path);
4258 if (!success) {
4259 goto error;
4260 }
4261 xtrabackup_logfile_is_renamed = FALSE;
4262
4263 if (!clear_flag)
4264 return(FALSE);
4265
4266 /* clear LOG_FILE_WAS_CREATED_BY_HOT_BACKUP field */
4267 src_file = os_file_create_simple_no_error_handling(
4268 0 /* dummy of innodb_file_data_key */,
4269 src_path, OS_FILE_OPEN,
4270 OS_FILE_READ_WRITE, &success);
4271 if (!success) {
4272 goto error;
4273 }
4274
4275#ifdef USE_POSIX_FADVISE
4276 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
4277#endif
4278
4279 if (srv_unix_file_flush_method == SRV_UNIX_O_DIRECT) {
4280 os_file_set_nocache(src_file, src_path, "OPEN");
4281 }
4282
4283 log_buf_ = (unsigned char*) ut_malloc(LOG_FILE_HDR_SIZE * 2);
4284 log_buf = (unsigned char*) ut_align(log_buf_, LOG_FILE_HDR_SIZE);
4285
4286 success = os_file_read(src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
4287 if (!success) {
4288 goto error;
4289 }
4290
4291 memset(log_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP, ' ', 4);
4292
4293 success = os_file_write(src_path, src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
4294 if (!success) {
4295 goto error;
4296 }
4297
4298 os_file_close(src_file);
4299 src_file = -1;
4300
4301 return(FALSE);
4302error:
4303 if (src_file != -1)
4304 os_file_close(src_file);
4305 if (log_buf_)
4306 ut_free(log_buf_);
4307 fprintf(stderr, "xtrabackup: Error: xtrabackup_close_temp_log() failed.\n");
4308 return(TRUE); /*ERROR*/
4309}
4310
4311static void
4312xtrabackup_prepare_func(void)
4313{
4314 /* cd to target-dir */
4315
4316 if (chdir(xtrabackup_real_target_dir) != 0)
4317 {
4318 fprintf(stderr, "xtrabackup: cannot my_setwd %s\n", xtrabackup_real_target_dir);
4319 exit(EXIT_FAILURE);
4320 }
4321 fprintf(stderr, "xtrabackup: cd to %s\n", xtrabackup_real_target_dir);
4322
4323 xtrabackup_target_dir= mysql_data_home_buff;
4324 mysql_data_home_buff[0]=FN_CURLIB; // all paths are relative from here
4325 mysql_data_home_buff[1]=0;
4326
4327 /* read metadata of target */
4328 {
4329 char filename[FN_REFLEN];
4330
4331 sprintf(filename, "%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
4332
4333 if (xtrabackup_read_metadata(filename))
4334 fprintf(stderr, "xtrabackup: error: xtrabackup_read_metadata()\n");
4335
4336 if (!strcmp(metadata_type, "full-backuped")) {
4337 fprintf(stderr, "xtrabackup: This target seems to be not prepared yet.\n");
4338 } else if (!strcmp(metadata_type, "full-prepared")) {
4339 fprintf(stderr, "xtrabackup: This target seems to be already prepared.\n");
4340 goto skip_check;
4341 } else {
4342 fprintf(stderr, "xtrabackup: This target seems not to have correct metadata...\n");
4343 }
4344
4345 if (xtrabackup_incremental) {
4346 fprintf(stderr,
4347 "xtrabackup: error: applying incremental backup needs target prepared.\n");
4348 exit(EXIT_FAILURE);
4349 }
4350skip_check:
4351 if (xtrabackup_incremental
4352 && ut_dulint_cmp(metadata_to_lsn, incremental_lsn) != 0) {
4353 fprintf(stderr,
4354 "xtrabackup: error: This incremental backup seems not to be proper for the target.\n"
4355 "xtrabackup: Check 'to_lsn' of the target and 'from_lsn' of the incremental.\n");
4356 exit(EXIT_FAILURE);
4357 }
4358 }
4359
4360 /* Create logfiles for recovery from 'xtrabackup_logfile', before start InnoDB */
4361 srv_max_n_threads = 1000;
4362 os_sync_mutex = NULL;
4363 ut_mem_init();
4364#ifdef XTRADB_BASED
4365 /* temporally dummy value to avoid crash */
4366 srv_page_size_shift = 14;
4367 srv_page_size = (1 << srv_page_size_shift);
4368#endif
4369 os_sync_init();
4370 sync_init();
4372 if(xtrabackup_init_temp_log())
4373 goto error;
4374
4375 if(xtrabackup_incremental)
4376 xtrabackup_apply_deltas(TRUE);
4377
4378 sync_close();
4379 sync_initialized = FALSE;
4380 os_sync_free();
4381 os_sync_mutex = NULL;
4383
4384 /* check the accessibility of target-dir */
4385 /* ############# TODO ##################### */
4386
4387 if(innodb_init_param())
4388 goto error;
4389
4390 srv_apply_log_only = (ibool) xtrabackup_apply_log_only;
4391
4392 /* increase IO threads */
4393 if(srv_n_file_io_threads < 10) {
4394 srv_n_file_io_threads = 10;
4395 }
4396
4397 fprintf(stderr, "xtrabackup: Starting InnoDB instance for recovery.\n"
4398 "xtrabackup: Using %" PRIu64 " bytes for buffer pool (set by --use-memory parameter)\n",
4399 xtrabackup_use_memory);
4400
4401 if(innodb_init())
4402 goto error;
4403
4404 //printf("Hello InnoDB world!\n");
4405
4406 /* TEST: innodb status*/
4407/*
4408 ulint trx_list_start = ULINT_UNDEFINED;
4409 ulint trx_list_end = ULINT_UNDEFINED;
4410 srv_printf_innodb_monitor(stdout, &trx_list_start, &trx_list_end);
4411*/
4412 /* TEST: list of datafiles and transaction log files and LSN*/
4413/*
4414 {
4415 fil_system_t* f_system = fil_system;
4416 fil_space_t* space;
4417 fil_node_t* node;
4418
4419 mutex_enter(&(f_system->mutex));
4420
4421 space = UT_LIST_GET_FIRST(f_system->space_list);
4422
4423 while (space != NULL) {
4424 printf("space: name=%s, id=%d, purpose=%d, size=%d\n",
4425 space->name, space->id, space->purpose, space->size);
4426
4427 node = UT_LIST_GET_FIRST(space->chain);
4428
4429 while (node != NULL) {
4430 printf("node: name=%s, open=%d, size=%d\n",
4431 node->name, node->open, node->size);
4432
4433 node = UT_LIST_GET_NEXT(chain, node);
4434 }
4435 space = UT_LIST_GET_NEXT(space_list, space);
4436 }
4437
4438 mutex_exit(&(f_system->mutex));
4439 }
4440*/
4441 /* align space sizes along with fsp header */
4442 {
4443 fil_system_t* f_system = fil_system;
4444 fil_space_t* space;
4445
4446 mutex_enter(&(f_system->mutex));
4447 space = UT_LIST_GET_FIRST(f_system->space_list);
4448
4449 while (space != NULL) {
4450 byte* header;
4451 ulint size;
4452 ulint actual_size;
4453 mtr_t mtr;
4454 buf_block_t* block;
4455 ulint flags;
4456
4457 if (space->purpose == FIL_TABLESPACE) {
4458 mutex_exit(&(f_system->mutex));
4459
4460 mtr_start(&mtr);
4461
4462 mtr_s_lock(fil_space_get_latch(space->id, &flags), &mtr);
4463
4464 block = buf_page_get(space->id,
4466 0, RW_S_LATCH, &mtr);
4467 header = FIL_PAGE_DATA /*FSP_HEADER_OFFSET*/
4468 + buf_block_get_frame(block);
4469
4470 size = mtr_read_ulint(header + 8 /* FSP_SIZE */, MLOG_4BYTES, &mtr);
4471
4472 mtr_commit(&mtr);
4473
4474 //printf("%d, %d\n", space->id, size);
4475
4476 fil_extend_space_to_desired_size(&actual_size, space->id, size);
4477
4478 mutex_enter(&(f_system->mutex));
4479 }
4480
4481 space = UT_LIST_GET_NEXT(space_list, space);
4482 }
4483
4484 mutex_exit(&(f_system->mutex));
4485 }
4486
4487
4488
4489 if (xtrabackup_export) {
4490 printf("xtrabackup: export option is specified.\n");
4491 if (innobase_file_per_table) {
4492 fil_system_t* f_system = fil_system;
4493 fil_space_t* space;
4494 fil_node_t* node;
4495 os_file_t info_file = -1;
4496 char info_file_path[FN_REFLEN];
4497 ibool success;
4498 char table_name[FN_REFLEN];
4499
4500 byte* page;
4501 byte* buf = NULL;
4502
4503 buf = (byte*) ut_malloc(UNIV_PAGE_SIZE * 2);
4504 page = (byte*) ut_align(buf, UNIV_PAGE_SIZE);
4505
4506 /* flush insert buffer at shutdwon */
4507 innobase_fast_shutdown = 0;
4508
4509 mutex_enter(&(f_system->mutex));
4510
4511 space = UT_LIST_GET_FIRST(f_system->space_list);
4512 while (space != NULL) {
4513 /* treat file_per_table only */
4514 if (space->purpose != FIL_TABLESPACE
4515#ifdef XTRADB_BASED
4516 || trx_sys_sys_space(space->id)
4517#else
4518 || space->id == 0
4519#endif
4520 )
4521 {
4522 space = UT_LIST_GET_NEXT(space_list, space);
4523 continue;
4524 }
4525
4526 node = UT_LIST_GET_FIRST(space->chain);
4527 while (node != NULL) {
4528 int len;
4529 char *next, *prev, *p;
4530 dict_table_t* table;
4531 dict_index_t* index;
4532 ulint n_index;
4533
4534 /* node exist == file exist, here */
4535 snprintf(info_file_path,
4536 sizeof(info_file_path), "%s",
4537 node->name);
4538 len = strlen(info_file_path);
4539 info_file_path[len - 3] = 'e';
4540 info_file_path[len - 2] = 'x';
4541 info_file_path[len - 1] = 'p';
4542
4543 p = info_file_path;
4544 prev = NULL;
4545 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
4546 {
4547 prev = p;
4548 p = next + 1;
4549 }
4550 info_file_path[len - 4] = 0;
4551 snprintf(table_name, sizeof(table_name),
4552 "%s", prev);
4553
4554 info_file_path[len - 4] = '.';
4555
4556 mutex_exit(&(f_system->mutex));
4557 mutex_enter(&(dict_sys->mutex));
4558
4559 table = dict_table_get_low(table_name);
4560 if (!table) {
4561 fprintf(stderr,
4562"xtrabackup: error: cannot find dictionary record of table %s\n", table_name);
4563 goto next_node;
4564 }
4565 index = dict_table_get_first_index(table);
4566 n_index = UT_LIST_GET_LEN(table->indexes);
4567 if (n_index > 31) {
4568 fprintf(stderr,
4569"xtrabackup: error: sorry, cannot export over 31 indexes for now.\n");
4570 goto next_node;
4571 }
4572
4573 /* init exp file */
4574 bzero(page, UNIV_PAGE_SIZE);
4575 mach_write_to_4(page , 0x78706f72UL);
4576 mach_write_to_4(page + 4, 0x74696e66UL);/*"xportinf"*/
4577 mach_write_to_4(page + 8, n_index);
4578 xb_copy_padded((char*)page + 12, 500,
4579 table_name);
4580
4581 printf(
4582"xtrabackup: export metadata of table '%s' to file `%s` (%lu indexes)\n",
4583 table_name, info_file_path, n_index);
4584
4585 n_index = 1;
4586 while (index) {
4587 mach_write_to_8(page + n_index * 512, index->id);
4588 mach_write_to_4(page + n_index * 512 + 8,
4589 index->page);
4590
4591 xb_copy_padded((char*)page + n_index * 512 + 12,
4592 500, index->name);
4593
4594 printf(
4595"xtrabackup: name=%s, id.low=%lu, page=%lu\n",
4596 index->name,
4597 (ulint)(index->id & 0xFFFFFFFFUL),
4598
4599 (ulint) index->page);
4600
4601 index = dict_table_get_next_index(index);
4602 n_index++;
4603 }
4604
4605 srv_normalize_path_for_win(info_file_path);
4606 info_file = os_file_create(
4607 0 /* dummy of innodb_file_data_key */,
4608 info_file_path, OS_FILE_OVERWRITE,
4609 OS_FILE_NORMAL, OS_DATA_FILE, &success);
4610 if (!success) {
4612 goto next_node;
4613 }
4614 success = os_file_write(info_file_path, info_file, page,
4615 0, 0, UNIV_PAGE_SIZE);
4616 if (!success) {
4618 goto next_node;
4619 }
4620 success = os_file_flush(info_file);
4621 if (!success) {
4623 goto next_node;
4624 }
4625next_node:
4626 if (info_file != -1) {
4627 os_file_close(info_file);
4628 info_file = -1;
4629 }
4630 mutex_exit(&(dict_sys->mutex));
4631 mutex_enter(&(f_system->mutex));
4632
4633 node = UT_LIST_GET_NEXT(chain, node);
4634 }
4635
4636 space = UT_LIST_GET_NEXT(space_list, space);
4637 }
4638 mutex_exit(&(f_system->mutex));
4639
4640 ut_free(buf);
4641 } else {
4642 printf("xtrabackup: export option is for file_per_table only, disabled.\n");
4643 }
4644 }
4645
4646 /* print binlog position (again?) */
4647 printf("\n[notice (again)]\n"
4648 " If you use binary log and don't use any hack of group commit,\n"
4649 " the binary log position seems to be:\n");
4650// FIXME: trx_sys_print_mysql_binlog_offset();
4651 printf("\n");
4652
4653 /* output to xtrabackup_binlog_pos_innodb */
4654 if (false) {
4655//FIXME if (*trx_sys_mysql_bin_log_name != '\0') {
4656 FILE *fp;
4657
4658 fp = fopen("xtrabackup_binlog_pos_innodb", "w");
4659 if (fp) {
4660 fprintf(fp, "%s\t%llu\n",
4661 "none", 0ULL);
4662 /* FIXME
4663 trx_sys_mysql_bin_log_name,
4664 trx_sys_mysql_bin_log_pos);*/
4665 fclose(fp);
4666 } else {
4667 printf("xtrabackup: failed to open 'xtrabackup_binlog_pos_innodb'\n");
4668 }
4669 }
4670
4671 /* Check whether the log is applied enough or not. */
4672 if ((xtrabackup_incremental
4673 && ut_dulint_cmp(srv_start_lsn, incremental_last_lsn) < 0)
4674 ||(!xtrabackup_incremental
4675 && ut_dulint_cmp(srv_start_lsn, metadata_last_lsn) < 0)) {
4676 printf( "xtrabackup: ########################################################\n"
4677 "xtrabackup: # !!WARNING!! #\n"
4678 "xtrabackup: # The transaction log file should be wrong or corrupt. #\n"
4679 "xtrabackup: # The log was not applied to the intended LSN! #\n"
4680 "xtrabackup: ########################################################\n");
4681 if (xtrabackup_incremental) {
4682 printf("xtrabackup: The intended lsn is %" PRIu64 "\n",
4683 incremental_last_lsn);
4684 } else {
4685 printf("xtrabackup: The intended lsn is %" PRIu64 "\n",
4686 metadata_last_lsn);
4687 }
4688 }
4689
4690 if(innodb_end())
4691 goto error;
4692
4693 sync_initialized = FALSE;
4694 os_sync_mutex = NULL;
4695
4696 /* re-init necessary components */
4697 ut_mem_init();
4698
4699 os_sync_init();
4700 sync_init();
4702
4703 if(xtrabackup_close_temp_log(TRUE))
4704 exit(EXIT_FAILURE);
4705
4706 /* output to metadata file */
4707 {
4708 char filename[FN_REFLEN];
4709
4710 strcpy(metadata_type, "full-prepared");
4711
4712 if(xtrabackup_incremental
4713 && ut_dulint_cmp(metadata_to_lsn, incremental_to_lsn) < 0)
4714 {
4715 metadata_to_lsn = incremental_to_lsn;
4716 metadata_last_lsn = incremental_last_lsn;
4717 }
4718
4719 sprintf(filename, "%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
4720 if (xtrabackup_write_metadata(filename))
4721 fprintf(stderr, "xtrabackup: error: xtrabackup_write_metadata(xtrabackup_target_dir)\n");
4722
4723 if(xtrabackup_extra_lsndir) {
4724 sprintf(filename, "%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
4725 if (xtrabackup_write_metadata(filename))
4726 fprintf(stderr, "xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
4727 }
4728 }
4729
4730 if(!xtrabackup_create_ib_logfile)
4731 return;
4732
4733 /* TODO: make more smart */
4734
4735 printf("\n[notice]\nWe cannot call InnoDB second time during the process lifetime.\n");
4736 printf("Please re-execte to create ib_logfile*. Sorry.\n");
4737/*
4738 printf("Restart InnoDB to create ib_logfile*.\n");
4739
4740 if(innodb_init_param())
4741 goto error;
4742
4743 if(innodb_init())
4744 goto error;
4745
4746 if(innodb_end())
4747 goto error;
4748*/
4749
4750 return;
4751
4752error:
4753 xtrabackup_close_temp_log(FALSE);
4754
4755 exit(EXIT_FAILURE);
4756}
4757
4758/* ================= main =================== */
4759
4760int main(int argc, char **argv)
4761{
4762 po::options_description commandline_options(_("Options used only in command line"));
4763 commandline_options.add_options()
4764 ("target-dir", po::value<std::string>(), _("destination directory"))
4765 ("backup", po::value<bool>(&xtrabackup_backup)->default_value(false)->zero_tokens(), _("take backup to target-dir"))
4766 ("stats", po::value<bool>(&xtrabackup_stats)->default_value(false)->zero_tokens(), _("calc statistic of datadir (offline mysqld is recommended)"))
4767 ("prepare", po::value<bool>(&xtrabackup_prepare)->default_value(false)->zero_tokens(), _("prepare a backup for starting mysql server on the backup."))
4768 ("export", po::value<bool>(&xtrabackup_export)->default_value(false)->zero_tokens(), _("create files to import to another database when prepare."))
4769 ("apply-log-only", po::value<bool>(&xtrabackup_apply_log_only)->default_value(false)->zero_tokens(), _("stop recovery process not to progress LSN after applying log when prepare."))
4770 ("print-param", po::value<bool>(&xtrabackup_print_param)->default_value(false)->zero_tokens(), _("print parameter of mysqld needed for copyback."))
4771 ("use-memory", po::value<uint64_t>(&xtrabackup_use_memory)->default_value(100*1024*1024), _("The value is used instead of buffer_pool_size"))
4772 ("suspend-at-end", po::value<bool>(&xtrabackup_suspend_at_end)->default_value(false)->zero_tokens(), _("creates a file 'xtrabackup_suspended' and waits until the user deletes that file at the end of '--backup'"))
4773 ("throttle", po::value<long>(&xtrabackup_throttle), _("limit count of IO operations (pairs of read&write) per second to IOS values (for '--backup')"))
4774 ("log-stream", po::value<bool>(&xtrabackup_stream)->default_value(false)->zero_tokens(), _("outputs the contents of 'xtrabackup_logfile' to stdout only until the file 'xtrabackup_suspended' deleted (for '--backup')."))
4775 ("extra-lsndir", po::value<std::string>(), _("(for --backup): save an extra copy of the xtrabackup_checkpoints file in this directory."))
4776 ("incremental-lsn", po::value<std::string>(), _("(for --backup): copy only .ibd pages newer than specified LSN 'high:low'. ##ATTENTION##: checkpoint lsn must be used. anyone can detect your mistake. be carefully!"))
4777 ("incremental-basedir", po::value<std::string>(), _("(for --backup): copy only .ibd pages newer than backup at specified directory."))
4778 ("incremental-dir", po::value<std::string>(), _("(for --prepare): apply .delta files and logfile in the specified directory."))
4779 ("tables", po::value<std::string>(), _("filtering by regexp for table names."))
4780 ("tables-file", po::value<std::string>(), _("filtering by list of the exact database.table name in the file."))
4781 ("create-ib-logfile", po::value<bool>(&xtrabackup_create_ib_logfile), _("** not work for now** creates ib_logfile* also after '--prepare'. ### If you want create ib_logfile*, only re-execute this command in same options. ###"))
4782 ("datadir,h", po::value<std::string>(), _("Path to the database root."))
4783 ("tmpdir,t", po::value<std::string>(), _("Path for temporary files. Several paths may be specified, separated by a colon (:), in this case they are used in a round-robin fashion."))
4784 ("parallel", po::value<uint32_t>(&parallel)->default_value(1), _("Number of threads to use for parallel datafiles transfer. Does not have any effect in the stream mode. The default value is 1."))
4785 ("innodb-adaptive-hash-index", po::value<bool>(&innobase_adaptive_hash_index)->default_value(true), _("Enable InnoDB adaptive hash index (enabled by default). Disable with --skip-innodb-adaptive-hash-index."))
4786 ("innodb-additional-mem-pool-size", po::value<long>(&innobase_additional_mem_pool_size)->default_value(1*1024*1024), _("Size of a memory pool InnoDB uses to store data dictionary information and other internal data structures."))
4787 ("innodb-autoextend-increment", po::value<uint32_t>(&srv_auto_extend_increment)->default_value(8), _("Data file autoextend increment in megabytes"))
4788 ("innodb-buffer-pool-size", po::value<uint64_t>(&innobase_buffer_pool_size)->default_value(8*1024*1024), _("The size of the memory buffer InnoDB uses to cache data and indexes of its tables."))
4789 ("innodb-checksums", po::value<bool>(&innobase_use_checksums)->default_value(true), _("Enable InnoDB checksums validation (enabled by default). Disable with --skip-innodb-checksums."))
4790 ("innodb-data-file-path", po::value<std::string>(), _("Path to individual files and their sizes."))
4791 ("innodb-data-home-dir", po::value<std::string>(), _("The common part for InnoDB table spaces."))
4792 ("innodb-doublewrite", po::value<bool>(&innobase_use_doublewrite)->default_value(true), _("Enable InnoDB doublewrite buffer (enabled by default). Disable with --skip-innodb-doublewrite."))
4793 ("innodb-file-io-threads", po::value<long>(&innobase_file_io_threads)->default_value(4), _("Number of file I/O threads in InnoDB."))
4794 ("innodb-file-per-table", po::value<bool>(&innobase_file_per_table), _("Stores each InnoDB table to an .ibd file in the database dir."))
4795 ("innodb-flush-log-at-trx-commit", po::value<ulong>(&srv_flush_log_at_trx_commit)->default_value(1), _("Set to 0 (write and flush once per second), 1 (write and flush at each commit) or 2 (write at commit, flush once per second)."))
4796 ("innodb-flush-method", po::value<std::string>(), _("With which method to flush data."))
4797/* ####### Should we use this option? ####### */
4798 ("innodb-force-recovery", po::value<long>(&innobase_force_recovery)->default_value(0), _("Helps to save your data in case the disk image of the database becomes corrupt."))
4799 ("innodb-lock-wait-timeout", po::value<long>(&innobase_lock_wait_timeout)->default_value(50), _("Timeout in seconds an InnoDB transaction may wait for a lock before being rolled back."))
4800 ("innodb-log-buffer-size", po::value<long>(&innobase_log_buffer_size)->default_value(1024*1024), _("The size of the buffer which InnoDB uses to write log to the log files on disk."))
4801 ("innodb-log-file-size", po::value<log_file_constraint>(&innobase_log_file_size)->default_value(20*1024*1024L), _("Size of each log file in a log group."))
4802 ("innodb-log-files-in-group", po::value<long>(&innobase_log_files_in_group)->default_value(2), _("Number of log files in the log group. InnoDB writes to the files in a circular fashion. Value 3 is recommended here."))
4803 ("innodb-log-group-home-dir", po::value<std::string>(), _("Path to InnoDB log files."))
4804 ("innodb-max_dirty-pages-pct", po::value<ulong>(&srv_max_buf_pool_modified_pct)->default_value(90), _("Percentage of dirty pages allowed in bufferpool."))
4805 ("innodb-open-files", po::value<long>(&innobase_open_files)->default_value(300), _("How many files at the maximum InnoDB keeps open at the same time."))
4806#ifdef XTRADB_BASED
4807 ("innodb-page-size", po::value<uint32_t>(&innobase_page_size)->default_value(1 << 14), _("The universal page size of the database."))
4808 ("innodb-log-block-size", po::value<uint32_t>(&innobase_log_block_size)->default_value(512), _("###EXPERIMENTAL###: The log block size of the transaction log file. Changing for created log file is not supported. Use on your own risk!"))
4809 ("innodb-fast-checksum", po::value<bool>(&innobase_fast_checksum), _("Change the algorithm of checksum for the whole of datapage to 4-bytes word based."))
4810 ("innodb-extra-undoslots", po::value<bool>(&innobase_extra_undoslots), _("Enable to use about 4000 undo slots instead of default 1024. Not recommended to use, Because it is not change back to disable, once it is used."))
4811 ("innodb-doublewrite-file", po::value<char *>(&innobase_doublewrite_file), _("Path to special datafile for doublewrite buffer. (default is "": not used)"))
4812#endif
4813 ;
4814
4815 po::variables_map vm;
4816 // Disable allow_guessing, it is evil and broken
4817 int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
4818 po::store(po::command_line_parser(argc, argv).options(commandline_options).style(style).run(), vm);
4819 po::notify(vm);
4820
4821 if (vm.count("target-dir"))
4822 xtrabackup_target_dir= vm["target-dir"].as<std::string>().c_str();
4823
4824 if (vm.count("extra-lsndir"))
4825 xtrabackup_extra_lsndir= vm["extra-lsndir"].as<std::string>().c_str();
4826
4827 if (vm.count("incremental-lsn"))
4828 xtrabackup_incremental= vm["incremental-lsn"].as<std::string>().c_str();
4829
4830 if (vm.count("incremental-basedir"))
4831 xtrabackup_incremental_basedir= vm["incremental-basedir"].as<std::string>().c_str();
4832
4833 boost::scoped_ptr<char> xtrabackup_tables_autoptr(new char[(vm.count("tables")) ? vm["tables"].as<std::string>().length() + 1: 0]);
4834 if (vm.count("tables"))
4835 {
4836 xtrabackup_tables= xtrabackup_tables_autoptr.get();
4837 strcpy(xtrabackup_tables, vm["tables"].as<std::string>().c_str());
4838 }
4839
4840 if (vm.count("tables-file"))
4841 xtrabackup_tables_file= vm["tables-file"].as<std::string>().c_str();
4842
4843 if (vm.count("tmpdir"))
4844 opt_mysql_tmpdir= vm["tmpdir"].as<std::string>().c_str();
4845
4846 if (vm.count("innodb-data-file-path"))
4847 innobase_data_file_path= vm["innodb-data-file-path"].as<std::string>().c_str();
4848
4849 boost::scoped_ptr<char> xtrabackup_incremental_dir_autoptr(new char[(vm.count("incremental-dir")) ? vm["incremental-dir"].as<std::string>().length() + 1: 0]);
4850 if (vm.count("incremental-dir"))
4851 {
4852 xtrabackup_incremental_dir= xtrabackup_incremental_dir_autoptr.get();
4853 strcpy(xtrabackup_incremental_dir, vm["incremental-dir"].as<std::string>().c_str());
4854 }
4855
4856 boost::scoped_ptr<char> innobase_data_home_dir_autoptr(new char[(vm.count("innodb-data-home-dir")) ? vm["innodb-data-home-dir"].as<std::string>().length() + 1 : 0]);
4857 if (vm.count("innodb-data-home-dir"))
4858 {
4859 innobase_data_home_dir= innobase_data_home_dir_autoptr.get();
4860 strcpy(innobase_data_home_dir, vm["innodb-data-home-dir"].as<std::string>().c_str());
4861 }
4862
4863 boost::scoped_ptr<char> innobase_flush_method_autoptr(new char[(vm.count("innodb-flush-method")) ? vm["innodb-flush-method"].as<std::string>().length() + 1 : 0]);
4864 if (vm.count("innodb-flush-method"))
4865 {
4866 innobase_unix_file_flush_method= innobase_flush_method_autoptr.get();
4867 strcpy(innobase_unix_file_flush_method, vm["innodb-flush-method"].as<std::string>().c_str());
4868 }
4869
4870 boost::scoped_ptr<char> innobase_log_group_home_dir_autoptr(new char[(vm.count("innodb-log-group-home-dir")) ? vm["innodb-log-group-home-dir"].as<std::string>().length() + 1: 0]);
4871
4872 if (vm.count("innodb-log-group-home-dir"))
4873 {
4874 innobase_log_group_home_dir= innobase_log_group_home_dir_autoptr.get();
4875 strcpy(innobase_log_group_home_dir, vm["innodb-log-group-home-dir"].as<std::string>().c_str());
4876 }
4877
4878 xtrabackup_use_memory-= xtrabackup_use_memory % (1024*1024);
4879 if (xtrabackup_use_memory < (1024*1024)) {
4880 fprintf(stderr, "xtrabackup: use-memory out of range\n");
4881 exit(EXIT_FAILURE);
4882 }
4883
4884 if (parallel < 1) {
4885 fprintf(stderr, "xtrabackup: parallel needs to be greater than 0\n");
4886 exit(EXIT_FAILURE);
4887 }
4888
4889 innobase_additional_mem_pool_size-= innobase_additional_mem_pool_size % 1024;
4890 if (innobase_additional_mem_pool_size < (512*1024)) {
4891 fprintf(stderr, "xtrabackup: innodb-additional-mem-pool-size out of range\n");
4892 exit(EXIT_FAILURE);
4893 }
4894
4895 if ((srv_auto_extend_increment < 1) || (srv_auto_extend_increment > 8)) {
4896 fprintf(stderr, "xtrabackup: innodb-auto-extend-increment out of range\n");
4897 exit(EXIT_FAILURE);
4898 }
4899
4900 innobase_buffer_pool_size-= innobase_buffer_pool_size % (1024*1024);
4901 if (innobase_buffer_pool_size < (1024*1024)) {
4902 fprintf(stderr, "xtrabackup: innodb-buffer-pool-size out of range\n");
4903 exit(EXIT_FAILURE);
4904 }
4905
4906 if ((innobase_file_io_threads < 4) || (innobase_file_io_threads > 64)) {
4907 fprintf(stderr, "xtrabackup: innodb-file-io-threads out of range\n");
4908 exit(EXIT_FAILURE);
4909 }
4910
4911 if (srv_flush_log_at_trx_commit > 2) {
4912 fprintf(stderr, "xtrabackup: innodb-flush-log-at-trx-commit out of range\n");
4913 exit(EXIT_FAILURE);
4914 }
4915
4916 if (innobase_force_recovery > 6) {
4917 fprintf(stderr, "xtrabackup: innodb-force-recovery out of range\n");
4918 exit(EXIT_FAILURE);
4919 }
4920
4921 if ((innobase_lock_wait_timeout < 1) || (innobase_lock_wait_timeout > (1024*1024*1024))) {
4922 fprintf(stderr, "xtrabackup: innodb-lock-wait-timeout out of range\n");
4923 exit(EXIT_FAILURE);
4924 }
4925
4926 innobase_log_buffer_size-= innobase_log_buffer_size % 1024;
4927 if (innobase_additional_mem_pool_size < (256*1024)) {
4928 fprintf(stderr, "xtrabackup: innodb-log-buffer-size out of range\n");
4929 exit(EXIT_FAILURE);
4930 }
4931
4932 if (innobase_additional_mem_pool_size < (1024*1024)) {
4933 fprintf(stderr, "xtrabackup: innodb-log-file-size out of range\n");
4934 exit(EXIT_FAILURE);
4935 }
4936
4937 if ((innobase_log_files_in_group < 2) || (innobase_log_files_in_group > (100))) {
4938 fprintf(stderr, "xtrabackup: innodb-log-files-in-group out of range\n");
4939 exit(EXIT_FAILURE);
4940 }
4941
4942 if (srv_max_buf_pool_modified_pct > 100) {
4943 fprintf(stderr, "xtrabackup: innodb-max-buf-pool-modified-pct out of range\n");
4944 exit(EXIT_FAILURE);
4945 }
4946
4947 if (innobase_open_files < 10) {
4948 fprintf(stderr, "xtrabackup: innodb-open-files out of range\n");
4949 exit(EXIT_FAILURE);
4950 }
4951
4952 if ((innobase_page_size < (1 << 12)) || (innobase_page_size > (1 << UNIV_PAGE_SIZE_SHIFT_MAX))) {
4953 fprintf(stderr, "xtrabackup: innodb-page-size out of range\n");
4954 exit(EXIT_FAILURE);
4955 }
4956
4957 if ((innobase_log_block_size < (512)) || (innobase_log_block_size > (1 << UNIV_PAGE_SIZE_SHIFT_MAX))) {
4958 fprintf(stderr, "xtrabackup: innodb-log-block-size out of range\n");
4959 exit(EXIT_FAILURE);
4960 }
4961
4962 if (vm.count("datadir"))
4963 {
4964 mysql_data_home_arg.assign(vm["datadir"].as<std::string>());
4965 }
4966 else
4967 {
4968 mysql_data_home_arg.assign(LOCALSTATEDIR);
4969 }
4970
4971 mysql_data_home= (char*)malloc(mysql_data_home_arg.length());
4972 strcpy(mysql_data_home, mysql_data_home_arg.c_str());
4973
4974 if ((!xtrabackup_prepare) && (strcmp(mysql_data_home, "./") == 0)) {
4975 if (!xtrabackup_print_param)
4976 usage();
4977 printf("\nxtrabackup: Error: Please set parameter 'datadir'\n");
4978 exit(EXIT_FAILURE);
4979 }
4980
4981 if (xtrabackup_tables) {
4982 /* init regexp */
4983 char *p, *next;
4984 int i;
4985 char errbuf[100];
4986
4987 tables_regex_num = 1;
4988
4989 p = xtrabackup_tables;
4990 while ((p = strchr(p, ',')) != NULL) {
4991 p++;
4992 tables_regex_num++;
4993 }
4994
4995 tables_regex = (regex_t*) ut_malloc(sizeof(regex_t) * tables_regex_num);
4996
4997 p = xtrabackup_tables;
4998 for (i=0; i < tables_regex_num; i++) {
4999 next = strchr(p, ',');
5000 ut_a(next || i == tables_regex_num - 1);
5001
5002 next++;
5003 if (i != tables_regex_num - 1)
5004 *(next - 1) = '\0';
5005
5006 regerror(regcomp(&tables_regex[i],p,REG_EXTENDED),
5007 &tables_regex[i],errbuf,sizeof(errbuf));
5008 fprintf(stderr, "xtrabackup: tables regcomp(%s): %s\n",p,errbuf);
5009
5010 if (i != tables_regex_num - 1)
5011 *(next - 1) = ',';
5012 p = next;
5013 }
5014 }
5015
5016 if (xtrabackup_tables_file) {
5017 char name_buf[NAME_LEN*2+2];
5018 FILE *fp;
5019
5020 if (xtrabackup_stream) {
5021 fprintf(stderr, "xtrabackup: Warning: --tables_file option doesn't affect with --stream.\n");
5022 xtrabackup_tables_file = NULL;
5023 goto skip_tables_file_register;
5024 }
5025
5026 name_buf[NAME_LEN*2+1] = '\0';
5027
5028 /* init tables_hash */
5029 tables_hash = hash_create(1000);
5030
5031 /* read and store the filenames */
5032 fp = fopen(xtrabackup_tables_file,"r");
5033 if (!fp) {
5034 fprintf(stderr, "xtrabackup: cannot open %s\n", xtrabackup_tables_file);
5035 exit(EXIT_FAILURE);
5036 }
5037 for (;;) {
5038 xtrabackup_tables_t* table;
5039 char* p = name_buf;
5040
5041 if ( fgets(name_buf, NAME_LEN*2+1, fp) == 0 ) {
5042 break;
5043 }
5044
5045 while (*p != '\0') {
5046 if (*p == '.') {
5047 *p = '/';
5048 }
5049 p++;
5050 }
5051 p = strchr(name_buf, '\n');
5052 if (p)
5053 {
5054 *p = '\0';
5055 }
5056
5057 table = (xtrabackup_tables_t*) malloc(sizeof(xtrabackup_tables_t) + strlen(name_buf) + 1);
5058 memset(table, '\0', sizeof(xtrabackup_tables_t) + strlen(name_buf) + 1);
5059 table->name = ((char*)table) + sizeof(xtrabackup_tables_t);
5060 strcpy(table->name, name_buf);
5061
5062 HASH_INSERT(xtrabackup_tables_t, name_hash, tables_hash,
5063 ut_fold_string(table->name), table);
5064
5065 printf("xtrabackup: table '%s' is registerd to the list.\n", table->name);
5066 }
5067 }
5068skip_tables_file_register:
5069
5070#ifdef XTRADB_BASED
5071 /* temporary setting of enough size */
5072 srv_page_size_shift = UNIV_PAGE_SIZE_SHIFT_MAX;
5073 srv_page_size = UNIV_PAGE_SIZE_MAX;
5074 srv_log_block_size = 512;
5075#endif
5076 if (xtrabackup_backup && xtrabackup_incremental) {
5077 /* direct specification is only for --backup */
5078 /* and the lsn is prior to the other option */
5079
5080 char* endchar;
5081 int error = 0;
5082
5083 incremental_lsn = strtoll(xtrabackup_incremental, &endchar, 10);
5084 if (*endchar != '\0')
5085 error = 1;
5086
5087 if (error) {
5088 fprintf(stderr, "xtrabackup: value '%s' may be wrong format for incremental option.\n",
5089 xtrabackup_incremental);
5090 exit(EXIT_FAILURE);
5091 }
5092
5093 /* allocate buffer for incremental backup (4096 pages) */
5094 incremental_buffer_base = (byte*) malloc((UNIV_PAGE_SIZE_MAX / 4 + 1) *
5095 UNIV_PAGE_SIZE_MAX);
5096 incremental_buffer = (byte*) ut_align(incremental_buffer_base,
5097 UNIV_PAGE_SIZE_MAX);
5098 } else if (xtrabackup_backup && xtrabackup_incremental_basedir) {
5099 char filename[FN_REFLEN];
5100
5101 sprintf(filename, "%s/%s", xtrabackup_incremental_basedir, XTRABACKUP_METADATA_FILENAME);
5102
5103 if (xtrabackup_read_metadata(filename)) {
5104 fprintf(stderr,
5105 "xtrabackup: error: failed to read metadata from %s\n",
5106 filename);
5107 exit(EXIT_FAILURE);
5108 }
5109
5110 incremental_lsn = metadata_to_lsn;
5111 xtrabackup_incremental = xtrabackup_incremental_basedir; //dummy
5112
5113 /* allocate buffer for incremental backup (4096 pages) */
5114 incremental_buffer_base = (byte*) malloc((UNIV_PAGE_SIZE_MAX / 4 + 1) *
5115 UNIV_PAGE_SIZE_MAX);
5116 incremental_buffer = (byte*) ut_align(incremental_buffer_base,
5117 UNIV_PAGE_SIZE_MAX);
5118 } else if (xtrabackup_prepare && xtrabackup_incremental_dir) {
5119 char filename[FN_REFLEN];
5120
5121 sprintf(filename, "%s/%s", xtrabackup_incremental_dir, XTRABACKUP_METADATA_FILENAME);
5122
5123 if (xtrabackup_read_metadata(filename)) {
5124 fprintf(stderr,
5125 "xtrabackup: error: failed to read metadata from %s\n",
5126 filename);
5127 exit(EXIT_FAILURE);
5128 }
5129
5130 incremental_lsn = metadata_from_lsn;
5131 incremental_to_lsn = metadata_to_lsn;
5132 incremental_last_lsn = metadata_last_lsn;
5133 xtrabackup_incremental = xtrabackup_incremental_dir; //dummy
5134
5135 /* allocate buffer for incremental backup (4096 pages) */
5136 incremental_buffer_base = (byte*) malloc((UNIV_PAGE_SIZE / 4 + 1) *
5137 UNIV_PAGE_SIZE);
5138 incremental_buffer = (byte*) ut_align(incremental_buffer_base,
5139 UNIV_PAGE_SIZE);
5140 } else {
5141 /* allocate buffer for applying incremental (for header page only) */
5142 incremental_buffer_base = (byte*) malloc((1 + 1) * UNIV_PAGE_SIZE_MAX);
5143 incremental_buffer = (byte*) ut_align(incremental_buffer_base,
5144 UNIV_PAGE_SIZE_MAX);
5145
5146 xtrabackup_incremental = NULL;
5147 }
5148
5149 /* --print-param */
5150 if (xtrabackup_print_param) {
5151 printf("# This MySQL options file was generated by XtraBackup.\n");
5152 printf("[mysqld]\n");
5153 printf("datadir = \"%s\"\n", mysql_data_home);
5154 printf("tmpdir = \"%s\"\n", opt_mysql_tmpdir);
5155 printf("innodb_data_home_dir = \"%s\"\n",
5156 innobase_data_home_dir ? innobase_data_home_dir : mysql_data_home);
5157 printf("innodb_data_file_path = \"%s\"\n",
5158 innobase_data_file_path ? innobase_data_file_path : "ibdata1:10M:autoextend");
5159 printf("innodb_log_group_home_dir = \"%s\"\n",
5160 innobase_log_group_home_dir ? innobase_log_group_home_dir : mysql_data_home);
5161 printf("innodb_log_files_in_group = %ld\n", innobase_log_files_in_group);
5162 printf("innodb_log_file_size = %" PRIu64 "\n", (uint64_t)innobase_log_file_size);
5163 printf("innodb_flush_method = \"%s\"\n",
5164 (innobase_unix_file_flush_method != NULL) ?
5165 innobase_unix_file_flush_method : "");
5166 exit(EXIT_SUCCESS);
5167 }
5168
5169 if (!xtrabackup_stream) {
5170 print_version();
5171 if (xtrabackup_incremental) {
5172 printf("incremental backup from %" PRIu64 " is enabled.\n",
5173 incremental_lsn);
5174 }
5175 } else {
5176 if (xtrabackup_backup) {
5177 xtrabackup_suspend_at_end = TRUE;
5178 fprintf(stderr, "xtrabackup: suspend-at-end is enabled.\n");
5179 }
5180 }
5181
5182 /* cannot execute both for now */
5183 {
5184 int num = 0;
5185
5186 if (xtrabackup_backup) num++;
5187 if (xtrabackup_stats) num++;
5188 if (xtrabackup_prepare) num++;
5189 if (num != 1) { /* !XOR (for now) */
5190 usage();
5191 exit(EXIT_FAILURE);
5192 }
5193 }
5194
5195 /* --backup */
5196 if (xtrabackup_backup)
5197 xtrabackup_backup_func();
5198
5199 /* --stats */
5200 if (xtrabackup_stats)
5201 xtrabackup_stats_func();
5202
5203 /* --prepare */
5204 if (xtrabackup_prepare)
5205 xtrabackup_prepare_func();
5206
5207 free(incremental_buffer_base);
5208
5209 if (xtrabackup_tables) {
5210 /* free regexp */
5211 int i;
5212
5213 for (i = 0; i < tables_regex_num; i++) {
5214 regfree(&tables_regex[i]);
5215 }
5216 ut_free(tables_regex);
5217 }
5218
5219 if (xtrabackup_tables_file) {
5220 ulint i;
5221
5222 /* free the hash elements */
5223 for (i = 0; i < hash_get_n_cells(tables_hash); i++) {
5224 xtrabackup_tables_t* table;
5225
5226 table = (xtrabackup_tables_t*)
5227 HASH_GET_FIRST(tables_hash, i);
5228
5229 while (table) {
5230 xtrabackup_tables_t* prev_table = table;
5231
5232 table = (xtrabackup_tables_t*)
5233 HASH_GET_NEXT(name_hash, prev_table);
5234
5235 HASH_DELETE(xtrabackup_tables_t, name_hash, tables_hash,
5236 ut_fold_string(prev_table->name), prev_table);
5237 free(prev_table);
5238 }
5239 }
5240
5241 /* free tables_hash */
5242 hash_table_free(tables_hash);
5243 }
5244
5245 exit(EXIT_SUCCESS);
5246}
#define btr_block_get(space, zip_size, page_no, mode, mtr)
Definition btr0btr.h:212
UNIV_INLINE ulint btr_page_get_level(const page_t *page, mtr_t *mtr)
@ BTR_SEARCH_LEAF
Definition btr0btr.h:57
UNIV_INLINE ulint btr_page_get_next(const page_t *page, mtr_t *mtr)
#define BTR_EXTERN_SPACE_ID
Definition btr0cur.h:787
#define BTR_EXTERN_PAGE_NO
Definition btr0cur.h:788
#define BTR_EXTERN_OFFSET
Definition btr0cur.h:789
UNIV_INLINE ibool btr_pcur_move_to_next_user_rec(btr_pcur_t *cursor, mtr_t *mtr)
UNIV_INLINE ibool btr_pcur_is_on_user_rec(const btr_pcur_t *cursor)
UNIV_INLINE void btr_pcur_open_at_index_side(ibool from_left, dict_index_t *index, ulint latch_mode, btr_pcur_t *pcur, ibool do_init, mtr_t *mtr)
UNIV_INLINE void btr_pcur_close(btr_pcur_t *cursor)
#define BTR_EXTERN_FIELD_REF_SIZE
Definition btr0types.h:170
struct btr_pcur_struct btr_pcur_t
Definition btr0types.h:36
UNIV_INLINE ulint buf_block_get_space(const buf_block_t *block) __attribute__((pure))
#define buf_page_get(SP, ZS, OF, LA, MTR)
Definition buf0buf.h:303
struct buf_block_struct buf_block_t
Definition buf0types.h:33
UNIV_INLINE ulint dict_table_flags_to_zip_size(ulint flags) __attribute__((const))
UNIV_INLINE dict_table_t * dict_table_get_low(const char *table_name)
#define DICT_TF_FORMAT_51
Definition dict0mem.h:82
#define FIL_TABLESPACE
Definition fil0fil.h:149
#define FIL_PAGE_DATA
Definition fil0fil.h:121
#define FIL_NULL
Definition fil0fil.h:48
#define FIL_PAGE_LSN
Definition fil0fil.h:97
UNIV_INTERN ulint fil_load_single_table_tablespaces(void)
Definition fil0fil.cc:3521
UNIV_INTERN void fsp_init(void)
Definition fsp0fsp.cc:874
UNIV_INTERN void thd_set_lock_wait_time(drizzled::Session *in_session, ulint value)
UNIV_INTERN void innobase_casedn_str(char *a)
UNIV_INTERN ulong thd_lock_wait_timeout(drizzled::Session *)
Definition ha_innodb.cc:997
ulint innobase_get_at_most_n_mbchars(ulint charset_id, ulint prefix_len, ulint data_len, const char *str)
UNIV_INTERN ibool thd_has_edited_nontrans_tables(drizzled::Session *session)
Definition ha_innodb.cc:958
UNIV_INTERN int innobase_mysql_cmp(int mysql_type, uint charset_number, const unsigned char *a, unsigned int a_length, const unsigned char *b, unsigned int b_length)
UNIV_INTERN ibool trx_is_interrupted(trx_t *trx)
UNIV_INTERN void innobase_convert_from_table_id(const void *, char *to, const char *from, ulint len)
UNIV_INTERN char * innobase_convert_name(char *buf, ulint buflen, const char *id, ulint idlen, drizzled::Session *session, ibool table_id)
UNIV_INTERN ibool thd_is_select(const drizzled::Session *session)
Definition ha_innodb.cc:970
UNIV_INTERN void innobase_get_cset_width(ulint cset, ulint *mbminlen, ulint *mbmaxlen)
UNIV_INTERN ibool trx_is_strict(trx_t *trx)
UNIV_INTERN void innobase_mysql_print_thd(FILE *f, drizzled::Session *in_session, uint)
UNIV_INTERN int innobase_mysql_tmpfile(void)
UNIV_INTERN ibool thd_is_replication_slave_thread(drizzled::Session *)
Definition ha_innodb.cc:884
static char * innobase_convert_identifier(char *buf, ulint buflen, const char *id, ulint idlen, drizzled::Session *session, ibool file_id)
UNIV_INTERN void innobase_convert_from_id(const void *, char *to, const char *from, ulint len)
UNIV_INTERN int innobase_strcasecmp(const char *a, const char *b)
UNIV_INTERN ulint innobase_raw_format(const char *data, ulint data_len, ulint, char *buf, ulint buf_size)
UNIV_INTERN ibool thd_supports_xa(drizzled::Session *)
Definition ha_innodb.cc:983
const char * innobase_basename(const char *path_name)
UNIV_INTERN void innobase_invalidate_query_cache(trx_t *trx, const char *full_name, ulint full_name_len)
UNIV_INTERN const char * innobase_get_stmt(drizzled::Session *mysql_thd, size_t *length) __attribute__((nonnull))
UNIV_INTERN void innobase_rec_to_mysql(Table *table, const rec_t *rec, const dict_index_t *index, const ulint *offsets)
UNIV_INTERN void innobase_rec_reset(Table *table)
#define HASH_INSERT(TYPE, NAME, TABLE, FOLD, DATA)
Definition hash0hash.h:101
UNIV_INLINE ulint hash_get_n_cells(hash_table_t *table)
#define HASH_SEARCH(NAME, TABLE, FOLD, TYPE, DATA, ASSERTION, TEST)
Definition hash0hash.h:176
#define HASH_GET_NEXT(NAME, DATA)
Definition hash0hash.h:172
#define HASH_DELETE(TYPE, NAME, TABLE, FOLD, DATA)
Definition hash0hash.h:137
#define HASH_GET_FIRST(TABLE, HASH_VAL)
Definition hash0hash.h:166
UNIV_INTERN void lock_sys_create(ulint n_cells)
Definition lock0lock.cc:565
UNIV_INTERN void log_group_read_checkpoint_info(log_group_t *group, ulint field)
Definition log0log.cc:1969
UNIV_INLINE ulint log_block_get_checkpoint_no(const byte *log_block)
UNIV_INLINE ulint log_block_get_data_len(const byte *log_block)
UNIV_INTERN ulint log_group_get_capacity(const log_group_t *group)
Definition log0log.cc:527
UNIV_INLINE ulint log_block_get_hdr_no(const byte *log_block)
UNIV_INLINE ulint log_block_convert_lsn_to_no(ib_uint64_t lsn)
UNIV_INLINE ulint log_block_calc_checksum(const byte *block)
UNIV_INLINE ibool log_block_get_flush_bit(const byte *log_block)
UNIV_INLINE ulint log_block_get_checksum(const byte *log_block)
UNIV_INTERN void log_group_read_log_seg(ulint type, byte *buf, log_group_t *group, ib_uint64_t start_lsn, ib_uint64_t end_lsn)
Definition log0log.cc:2229
struct log_group_struct log_group_t
Definition log0log.h:48
UNIV_INTERN void log_init(void)
Definition log0log.cc:801
#define RECV_SCAN_SIZE
Definition log0recv.h:486
UNIV_INLINE void mach_write_to_8(byte *b, ib_uint64_t n)
UNIV_INLINE void mach_write_to_4(byte *b, ulint n)
UNIV_INLINE ulint mach_read_from_4(const byte *b) __attribute__((nonnull
#define mem_heap_create(N)
Definition mem0mem.h:91
#define mem_free(PTR)
Definition mem0mem.h:243
UNIV_INLINE void mem_heap_empty(mem_heap_t *heap)
UNIV_INLINE char * mem_strdupl(const char *str, ulint len)
#define mem_heap_free(heap)
Definition mem0mem.h:111
UNIV_INTERN ulint mtr_read_ulint(const byte *ptr, ulint type, mtr_t *mtr)
Definition mtr0mtr.cc:362
UNIV_INTERN void mtr_commit(mtr_t *mtr) __attribute__((nonnull))
Definition mtr0mtr.cc:247
#define mtr_s_lock(B, MTR)
Definition mtr0mtr.h:269
#define mtr_x_lock(B, MTR)
Definition mtr0mtr.h:273
UNIV_INLINE void mtr_start(mtr_t *mtr) __attribute__((nonnull))
#define MLOG_4BYTES
Definition mtr0mtr.h:68
Convert from decimal to binary representation.
Definition common_fwd.h:215
TODO: Rename this file - func.h is stupid.
UNIV_INTERN ibool os_file_status(const char *path, ibool *exists, os_file_type_t *type)
Definition os0file.cc:2890
#define OS_DATA_FILE
Definition os0file.h:124
#define OS_WIN31
Definition os0file.h:175
UNIV_INTERN ulint os_file_get_last_error(ibool report_all_errors)
Definition os0file.cc:385
UNIV_INTERN int os_file_closedir(os_file_dir_t dir)
Definition os0file.cc:817
#define OS_WINNT
Definition os0file.h:177
struct fil_node_struct fil_node_t
Definition os0file.h:48
#define OS_WIN2000
Definition os0file.h:178
UNIV_INTERN void os_file_set_nocache(int fd, const char *file_name, const char *operation_name)
Definition os0file.cc:1327
int os_file_t
Definition os0file.h:87
#define OS_WIN95
Definition os0file.h:176
#define OS_FILE_LOG_BLOCK_SIZE
Definition os0file.h:104
DIR * os_file_dir_t
Definition os0file.h:374
#define OS_FILE_OPEN
Definition os0file.h:107
#define OS_WINXP
Definition os0file.h:179
UNIV_INTERN void os_io_init_simple(void)
Definition os0file.cc:711
ulint os_innodb_umask
Definition os0file.cc:71
#define OS_FILE_READ
Definition os0file.h:142
UNIV_INTERN ib_int64_t os_file_get_size_as_iblonglong(os_file_t file)
Definition os0file.cc:1930
UNIV_INTERN os_file_dir_t os_file_opendir(const char *dirname, ibool error_is_fatal)
Definition os0file.cc:761
os_mutex_t os_sync_mutex
Definition os0sync.cc:59
UNIV_INTERN ib_int64_t os_event_reset(os_event_t event)
Definition os0sync.cc:472
UNIV_INTERN void os_mutex_enter(os_mutex_t mutex)
Definition os0sync.cc:809
UNIV_INTERN os_event_t os_event_create(const char *name)
Definition os0sync.cc:365
UNIV_INTERN void os_sync_free(void)
Definition os0sync.cc:325
UNIV_INTERN void os_event_set(os_event_t event)
Definition os0sync.cc:434
UNIV_INTERN void os_event_free(os_event_t event)
Definition os0sync.cc:535
os_event_struct_t * os_event_t
Definition os0sync.h:58
os_mutex_str_t * os_mutex_t
Definition os0sync.h:89
UNIV_INTERN void os_mutex_exit(os_mutex_t mutex)
Definition os0sync.cc:824
UNIV_INTERN void os_sync_init(void)
Definition os0sync.cc:304
UNIV_INTERN void os_mutex_free(os_mutex_t mutex)
Definition os0sync.cc:840
os_thread_t os_thread_id_t
Definition os0thread.h:53
UNIV_INTERN os_thread_t os_thread_create(os_posix_f_t start_f, void *arg, os_thread_id_t *thread_id)
Definition os0thread.cc:110
UNIV_INTERN void os_thread_exit(void *exit_value)
Definition os0thread.cc:199
UNIV_INTERN void os_thread_sleep(ulint tm)
Definition os0thread.cc:265
UNIV_INLINE void page_cur_move_to_next(page_cur_t *cur)
UNIV_INLINE void page_cur_set_before_first(const buf_block_t *block, page_cur_t *cur)
UNIV_INLINE ibool page_cur_is_after_last(const page_cur_t *cur)
UNIV_INLINE ulint page_get_n_recs(const page_t *page)
UNIV_INLINE ulint page_get_space_id(const page_t *page)
UNIV_INLINE ibool page_is_leaf(const page_t *page) __attribute__((nonnull
UNIV_INLINE ulint page_get_data_size(const page_t *page)
struct page_cur_struct page_cur_t
Definition page0types.h:39
#define page_t
Definition page0types.h:35
UNIV_INLINE ulint rec_offs_n_fields(const ulint *offsets)
UNIV_INLINE ulint rec_offs_nth_extern(const ulint *offsets, ulint n)
UNIV_INLINE ulint rec_get_deleted_flag(const rec_t *rec, ulint comp)
ibool row_rollback_on_timeout
Definition row0mysql.cc:58
ulint srv_buf_pool_size
Definition srv0srv.cc:253
UNIV_INTERN void srv_general_init(void)
Definition srv0srv.cc:1192
ibool srv_locks_unsafe_for_binlog
Definition srv0srv.cc:138
@ SRV_UNIX_O_DSYNC
Definition srv0srv.h:416
@ SRV_UNIX_FSYNC
Definition srv0srv.h:415
@ SRV_UNIX_NOSYNC
Definition srv0srv.h:420
@ SRV_UNIX_LITTLESYNC
Definition srv0srv.h:417
@ SRV_UNIX_O_DIRECT
Definition srv0srv.h:421
@ SRV_WIN_IO_UNBUFFERED
Definition srv0srv.h:429
@ SRV_WIN_IO_NORMAL
Definition srv0srv.h:428
my_bool srv_file_per_table
Definition srv0srv.cc:125
ulint srv_file_format
Definition srv0srv.cc:127
ulint srv_max_file_format_at_startup
Definition srv0srv.cc:131
UNIV_INTERN void srv_normalize_path_for_win(char *str)
Definition srv0start.cc:513
UNIV_INTERN int innobase_shutdown_for_mysql(void)
UNIV_INTERN ibool srv_parse_data_file_paths_and_sizes(char *str)
Definition srv0start.cc:195
ib_uint64_t srv_start_lsn
Definition srv0start.cc:99
UNIV_INTERN int innobase_start_or_create_for_mysql(void)
Definition srv0start.cc:971
UNIV_INTERN ibool srv_parse_log_group_home_dirs(char *str)
Definition srv0start.cc:379
ibool is_raw_disk
Definition fil0fil.cc:141
ib_int64_t flush_counter
Definition fil0fil.cc:156
ulint n_pending_flushes
Definition fil0fil.cc:150
UT_LIST_NODE_T(fil_node_t) LRU
UT_LIST_NODE_T(fil_node_t) chain
fil_space_t * space
Definition fil0fil.cc:136
os_file_t handle
Definition fil0fil.cc:140
ib_int64_t modification_counter
Definition fil0fil.cc:154
ulint n_pending_flushes
Definition fil0fil.cc:210
hash_node_t hash
Definition fil0fil.cc:219
ibool is_being_deleted
Definition fil0fil.cc:191
hash_node_t name_hash
Definition fil0fil.cc:220
ib_int64_t tablespace_version
Definition fil0fil.cc:174
UT_LIST_BASE_NODE_T(fil_node_t) chain
ulint n_reserved_extents
Definition fil0fil.cc:207
UT_LIST_NODE_T(fil_space_t) space_list
ulint n_pending_ibuf_merges
Definition fil0fil.cc:213
ibool stop_ibuf_merges
Definition fil0fil.cc:188
ibool is_in_unflushed_spaces
Definition fil0fil.cc:228
rw_lock_t latch
Definition fil0fil.cc:222
UT_LIST_NODE_T(fil_space_t) unflushed_spaces
UT_LIST_BASE_NODE_T(fil_space_t) space_list
ib_int64_t modification_counter
Definition fil0fil.cc:274
UT_LIST_BASE_NODE_T(fil_space_t) unflushed_spaces
ib_int64_t tablespace_version
Definition fil0fil.cc:282
ulint max_assigned_id
Definition fil0fil.cc:276
hash_table_t * name_hash
Definition fil0fil.cc:252
hash_table_t * spaces
Definition fil0fil.cc:249
UT_LIST_BASE_NODE_T(fil_node_t) LRU
ib_uint64_t scanned_lsn
Definition log0log.h:721
char name[OS_FILE_MAX_PATH]
Definition os0file.h:362
os_file_type_t type
Definition os0file.h:363
UNIV_INTERN void sync_close(void)
ibool sync_initialized
Definition sync0sync.cc:192
UNIV_INTERN void sync_init(void)
#define mutex_t
Definition sync0types.h:31
UNIV_INLINE void * ut_align(const void *ptr, ulint align_no)
#define ut_error
Definition ut0dbg.h:115
#define ut_ad(EXPR)
Definition ut0dbg.h:127
#define ut_a(EXPR)
Definition ut0dbg.h:105
#define UT_LIST_GET_LEN(BASE)
Definition ut0lst.h:216
#define UT_LIST_GET_FIRST(BASE)
Definition ut0lst.h:223
#define UT_LIST_GET_NEXT(NAME, N)
Definition ut0lst.h:200
UNIV_INLINE int ut_strcmp(const char *str1, const char *str2)
UNIV_INLINE int ut_memcmp(const void *str1, const void *str2, ulint n)
UNIV_INTERN void ut_mem_init(void)
Definition ut0mem.cc:77
UNIV_INTERN void ut_free(void *ptr)
Definition ut0mem.cc:294
UNIV_INTERN void ut_free_all_mem(void)
Definition ut0mem.cc:411
UNIV_INTERN void * ut_malloc(ulint n)
Definition ut0mem.cc:235
UNIV_INLINE ulint ut_fold_string(const char *str) __attribute__((pure))
UNIV_INLINE ulint ut_fold_binary(const byte *str, ulint len) __attribute__((pure))
#define TEMP_INDEX_PREFIX
Definition ut0ut.h:51
UNIV_INTERN void ut_print_timestamp(FILE *file)
Definition ut0ut.cc:239
UNIV_INTERN void ut_sprintf_timestamp(char *buf)
Definition ut0ut.cc:282
UNIV_INTERN void ut_print_namel(FILE *f, struct trx_struct *trx, ibool table_id, const char *name, ulint namelen)
Definition ut0ut.cc:538