~stewart/percona-xtrabackup/bug1213036

« back to all changes in this revision

Viewing changes to src/xtrabackup.c

  • Committer: Alexey Kopytov
  • Date: 2012-02-10 20:05:56 UTC
  • mto: (391.1.5 staging)
  • mto: This revision was merged to the branch mainline in revision 390.
  • Revision ID: akopytov@gmail.com-20120210200556-6kx41z8wwrqfucro
Rebase of the parallel compression patch on new trunk + post-review
fixes.

Implementation of parallel compression and streaming for XtraBackup.

This revision implements the following changes:

* InnoDB files are now streamed by the xtrabackup binary rather than
innobackupex. As a result, integrity is now verified by xtrabackup and
thus tar4ibd is no longer needed, so it was removed.

* xtrabackup binary now accepts the new '--stream' option which has
exactly the same semantics as the '--stream' option in
innobackupex: it tells xtrabackup to stream all files to the standard
output in the specified format rather than storing them locally.

* The xtrabackup binary can now do parallel compression using the
quicklz library. Two new options were added to xtrabackup to support
this feature:

- '--compress' tells xtrabackup to compress all output data, including
the transaction log file and meta data files, using the specified
compression algorithm. The only currently supported algorithm is
'quicklz'. The resulting files have the qpress archive format,
i.e. every *.qp file produced by xtrabackup is essentially a one-file
qpress archive and can be extracted and uncompressed by the qpress
file archiver (http://www.quicklz.com/).

- '--compress-threads' specifies the number of worker threads used by
xtrabackup for parallel data compression. This option defaults to 1.

Parallel compression ('--compress-threads') can be used together with
parallel file copying ('--parallel'). For example, '--parallel=4
--compress --compress-threads=2' will create 4 IO threads that will
read the data and pipe it to 2 compression threads.

* To support simultaneous compression and streaming, a new custom
streaming format called 'xbstream' was introduced to XtraBackup in
addition to the 'tar' format. That was required to overcome some
limitations of traditional archive formats such as 'tar', 'cpio' and
others that do not allow streaming dynamically generated files, for
example dynamically compressed files.  Other advantages of xbstream over
traditional streaming/archive formats include ability to stream multiple
files concurrently (so it is possible to use streaming in the xbstream
format together with the --parallel option) and more compact data
storage.

* To allow streaming and extracting files to/from the xbstream format
produced by xtrabackup, a new utility aptly called 'xbstream' was
added to the XtraBackup distribution. This utility has a tar-like
interface:

- with the '-x' option it extracts files from the stream read from its
standard input to the current directory unless specified otherwise
with the '-C' option.

- with the '-c' option it streams files specified on the command line
to its standard output.

The utility also tries to minimize its impact on the OS page cache by
using the appropriate posix_fadvise() calls when available.

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
#include <sync0sync.h>
84
84
#include <fil0fil.h>
85
85
#include <trx0xa.h>
 
86
#include <btr0sea.h>
 
87
#include <log0recv.h>
86
88
#include <fcntl.h>
87
89
 
88
90
#ifdef INNODB_VERSION_SHORT
89
91
#include <ibuf0ibuf.h>
90
92
#endif
91
93
 
 
94
#include "common.h"
 
95
#include "datasink.h"
 
96
#include "local.h"
 
97
#include "stream.h"
 
98
#include "compress.h"
 
99
 
92
100
#include "xb_regex.h"
93
101
 
94
102
#ifndef INNODB_VERSION_SHORT
131
139
#ifndef UNIV_PAGE_SIZE_SHIFT_MAX
132
140
#define UNIV_PAGE_SIZE_SHIFT_MAX UNIV_PAGE_SIZE_SHIFT
133
141
#endif
134
 
        
 
142
 
135
143
#if MYSQL_VERSION_ID >= 50507
136
144
/*
137
145
   As of MySQL 5.5.7, InnoDB uses thd_wait plugin service.
338
346
/*==========*/
339
347
        os_file_t       file);  /*!< in, own: handle to a file */
340
348
 
341
 
#ifdef POSIX_FADV_NORMAL
342
 
#define USE_POSIX_FADVISE
343
 
#endif
344
 
 
345
349
/* ==start === definition at fil0fil.c === */
346
350
// ##################################################################
347
351
// NOTE: We should check the following definitions fit to the source.
680
684
lint io_ticket;
681
685
os_event_t wait_throttle = NULL;
682
686
 
683
 
my_bool xtrabackup_stream = FALSE;
 
687
my_bool xtrabackup_log_only = FALSE;
684
688
char *xtrabackup_incremental = NULL;
685
689
LSN64 incremental_lsn;
686
690
LSN64 incremental_to_lsn;
715
719
LSN64 checkpoint_lsn_start;
716
720
LSN64 checkpoint_no_start;
717
721
LSN64 log_copy_scanned_lsn;
718
 
IB_INT64 log_copy_offset = 0;
719
722
ibool log_copying = TRUE;
720
723
ibool log_copying_running = FALSE;
721
724
ibool log_copying_succeed = FALSE;
722
725
 
723
726
ibool xtrabackup_logfile_is_renamed = FALSE;
724
727
 
725
 
int parallel;
 
728
int xtrabackup_parallel;
 
729
 
 
730
char *xtrabackup_stream_str = NULL;
 
731
xb_stream_fmt_t xtrabackup_stream_fmt;
 
732
ibool xtrabackup_stream = FALSE;
 
733
 
 
734
char *xtrabackup_compress_alg = NULL;
 
735
ibool xtrabackup_compress = FALSE;
 
736
uint xtrabackup_compress_threads;
726
737
 
727
738
/* === metadata of backup === */
728
739
#define XTRABACKUP_METADATA_FILENAME "xtrabackup_checkpoints"
739
750
 
740
751
#define XB_DELTA_INFO_SUFFIX ".meta"
741
752
 
 
753
#define XB_LOG_FILENAME "xtrabackup_logfile"
 
754
 
742
755
#ifdef __WIN__
743
756
#define XB_FILE_UNDEFINED NULL
744
757
#else
745
758
#define XB_FILE_UNDEFINED (-1)
746
759
#endif
747
760
 
748
 
/* === sharing with thread === */
749
 
os_file_t       dst_log = XB_FILE_UNDEFINED;
750
 
char            dst_log_path[FN_REFLEN];
 
761
int     dst_log_fd = XB_FILE_UNDEFINED;
 
762
char    dst_log_path[FN_REFLEN];
751
763
 
752
764
/* === some variables from mysqld === */
753
765
char mysql_real_data_home[FN_REFLEN] = "./";
856
868
 
857
869
static
858
870
fil_node_t *
859
 
datafiles_iter_next(datafiles_iter_t *it, ibool *space_changed)
 
871
datafiles_iter_next(datafiles_iter_t *it)
860
872
{
861
873
        os_mutex_enter(it->mutex);
862
874
 
863
 
        *space_changed = FALSE;
864
 
 
865
875
        if (it->node == NULL) {
866
876
                if (it->started)
867
877
                        goto end;
882
892
                it->space = UT_LIST_GET_NEXT(space_list, it->space);
883
893
        if (it->space == NULL)
884
894
                goto end;
885
 
        *space_changed = TRUE;
886
895
 
887
896
        it->node = UT_LIST_GET_FIRST(it->space->chain);
888
897
 
908
917
        uint                    *count;
909
918
        os_mutex_t              count_mutex;
910
919
        os_thread_id_t          id;
 
920
        ds_ctxt_t               *ds_ctxt;
911
921
} data_thread_ctxt_t;
912
922
 
913
923
/* ======== for option and variables ======== */
924
934
  OPT_XTRA_SUSPEND_AT_END,
925
935
  OPT_XTRA_USE_MEMORY,
926
936
  OPT_XTRA_THROTTLE,
927
 
  OPT_XTRA_STREAM,
 
937
  OPT_XTRA_LOG_ONLY,
928
938
  OPT_XTRA_INCREMENTAL,
929
939
  OPT_XTRA_INCREMENTAL_BASEDIR,
930
940
  OPT_XTRA_EXTRA_LSNDIR,
933
943
  OPT_XTRA_TABLES_FILE,
934
944
  OPT_XTRA_CREATE_IB_LOGFILE,
935
945
  OPT_XTRA_PARALLEL,
 
946
  OPT_XTRA_STREAM,
 
947
  OPT_XTRA_COMPRESS,
 
948
  OPT_XTRA_COMPRESS_THREADS,
936
949
  OPT_INNODB_CHECKSUMS,
937
950
  OPT_INNODB_DATA_FILE_PATH,
938
951
  OPT_INNODB_DATA_HOME_DIR,
1017
1030
  {"throttle", OPT_XTRA_THROTTLE, "limit count of IO operations (pairs of read&write) per second to IOS values (for '--backup')",
1018
1031
   (G_PTR*) &xtrabackup_throttle, (G_PTR*) &xtrabackup_throttle,
1019
1032
   0, GET_LONG, REQUIRED_ARG, 0, 0, LONG_MAX, 0, 1, 0},
1020
 
  {"log-stream", OPT_XTRA_STREAM, "outputs the contents of 'xtrabackup_logfile' to stdout only until the file 'xtrabackup_suspended' deleted (for '--backup').",
1021
 
   (G_PTR*) &xtrabackup_stream, (G_PTR*) &xtrabackup_stream,
 
1033
  {"log-stream", OPT_XTRA_LOG_ONLY, "outputs the contents of 'xtrabackup_logfile' to stdout only until the file 'xtrabackup_suspended' deleted (for '--backup').",
 
1034
   (G_PTR*) &xtrabackup_log_only, (G_PTR*) &xtrabackup_log_only,
1022
1035
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1023
1036
  {"extra-lsndir", OPT_XTRA_EXTRA_LSNDIR, "(for --backup): save an extra copy of the xtrabackup_checkpoints file in this directory.",
1024
1037
   (G_PTR*) &xtrabackup_extra_lsndir, (G_PTR*) &xtrabackup_extra_lsndir,
1057
1070
  {"parallel", OPT_XTRA_PARALLEL,
1058
1071
   "Number of threads to use for parallel datafiles transfer. Does not have "
1059
1072
   "any effect in the stream mode. The default value is 1.",
1060
 
   (G_PTR*) &parallel, (G_PTR*) &parallel, 0, GET_INT, REQUIRED_ARG,
1061
 
   1, 1, INT_MAX, 0, 0, 0},
 
1073
   (G_PTR*) &xtrabackup_parallel, (G_PTR*) &xtrabackup_parallel, 0, GET_INT,
 
1074
   REQUIRED_ARG, 1, 1, INT_MAX, 0, 0, 0},
 
1075
 
 
1076
  {"stream", OPT_XTRA_STREAM, "Stream all backup files to the standard output "
 
1077
   "in the specified format. Currently the only supported format is 'tar'.",
 
1078
   (G_PTR*) &xtrabackup_stream_str, (G_PTR*) &xtrabackup_stream_str, 0, GET_STR,
 
1079
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1080
 
 
1081
  {"compress", OPT_XTRA_COMPRESS, "Compress individual backup files using the "
 
1082
   "specified compression algorithm. Currently the only supported algorithm "
 
1083
   "is 'quicklz'. It is also the default algorithm, i.e. the one used when "
 
1084
   "--compress is used without an argument.",
 
1085
   (G_PTR*) &xtrabackup_compress_alg, (G_PTR*) &xtrabackup_compress_alg, 0,
 
1086
   GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1087
 
 
1088
  {"compress-threads", OPT_XTRA_COMPRESS_THREADS,
 
1089
   "Number of threads for parallel data compression. The default value is 1.",
 
1090
   (G_PTR*) &xtrabackup_compress_threads, (G_PTR*) &xtrabackup_compress_threads,
 
1091
   0, GET_UINT, REQUIRED_ARG, 1, 1, UINT_MAX, 0, 0, 0},
1062
1092
 
1063
1093
  {"innodb_adaptive_hash_index", OPT_INNODB_ADAPTIVE_HASH_INDEX,
1064
1094
   "Enable InnoDB adaptive hash index (enabled by default).  "
1283
1313
                 xtrabackup_target_dir);
1284
1314
        fp = fopen(pid_path, "w");
1285
1315
        if (fp == NULL) {
1286
 
                fprintf(stderr, "xtrabackup: Error: cannot open %s\n",
1287
 
                        pid_path);
 
1316
                msg("xtrabackup: Error: cannot open %s\n", pid_path);
1288
1317
                exit(EXIT_FAILURE);
1289
1318
        }
1290
1319
        fprintf(fp, "%u\n", (uint) pid);
1291
1320
        fclose(fp);
1292
1321
 
1293
 
        fprintf(stderr, "xtrabackup: DEBUG: "
1294
 
                "Suspending at debug sync point '%s'. "
1295
 
                "Resume with 'kill -SIGCONT %u'.\n", name, (uint) pid);
 
1322
        msg("xtrabackup: DEBUG: Suspending at debug sync point '%s'. "
 
1323
            "Resume with 'kill -SIGCONT %u'.\n", name, (uint) pid);
1296
1324
 
1297
1325
        debug_sync_resumed= 0;
1298
1326
        kill(pid, SIGSTOP);
1301
1329
        }
1302
1330
 
1303
1331
        /* On resume */
1304
 
        fprintf(stderr, "xtrabackup: DEBUG: removing the pid file.\n");
 
1332
        msg("xtrabackup: DEBUG: removing the pid file.\n");
1305
1333
        my_delete(pid_path, MYF(MY_WME));
1306
1334
#endif
1307
1335
}
1310
1338
 
1311
1339
static void print_version(void)
1312
1340
{
1313
 
  printf("%s version %s for %s %s %s (%s) (revision id: %s)\n", my_progname,
1314
 
         XTRABACKUP_VERSION,
1315
1341
#ifdef XTRADB_BASED
1316
 
         "Percona Server",
 
1342
  msg("%s version %s for Percona Server %s %s (%s) (revision id: %s)\n",
 
1343
      my_progname, XTRABACKUP_VERSION, MYSQL_SERVER_VERSION, SYSTEM_TYPE,
 
1344
      MACHINE_TYPE, XTRABACKUP_REVISION);
1317
1345
#else
1318
 
         "MySQL server",
 
1346
  msg("%s version %s for MySQL server %s %s (%s) (revision id: %s)\n",
 
1347
      my_progname, XTRABACKUP_VERSION, MYSQL_SERVER_VERSION, SYSTEM_TYPE,
 
1348
      MACHINE_TYPE, XTRABACKUP_REVISION);
1319
1349
#endif
1320
 
         MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE, XTRABACKUP_REVISION);
1321
1350
}
1322
1351
 
1323
1352
static void usage(void)
1358
1387
    strmake(xtrabackup_real_target_dir,argument, sizeof(xtrabackup_real_target_dir)-1);
1359
1388
    xtrabackup_target_dir= xtrabackup_real_target_dir;
1360
1389
    break;
 
1390
  case OPT_XTRA_STREAM:
 
1391
    if (!strcasecmp(argument, "tar"))
 
1392
      xtrabackup_stream_fmt = XB_STREAM_FMT_TAR;
 
1393
    else if (!strcasecmp(argument, "xbstream"))
 
1394
      xtrabackup_stream_fmt = XB_STREAM_FMT_XBSTREAM;
 
1395
    else
 
1396
    {
 
1397
      msg("Invalid --stream argument: %s\n", argument);
 
1398
      return 1;
 
1399
    }
 
1400
    xtrabackup_stream = TRUE;
 
1401
    break;
 
1402
  case OPT_XTRA_COMPRESS:
 
1403
    if (argument == NULL)
 
1404
      xtrabackup_compress_alg = "quicklz";
 
1405
    else if (strcasecmp(argument, "quicklz"))
 
1406
    {
 
1407
      msg("Invalid --compress argument: %s\n", argument);
 
1408
      return 1;
 
1409
    }
 
1410
    xtrabackup_compress = TRUE;
 
1411
    break;
1361
1412
  case '?':
1362
1413
    usage();
1363
1414
    exit(EXIT_SUCCESS);
1379
1430
        void*   thd)
1380
1431
{
1381
1432
        (void)thd;
1382
 
        fprintf(stderr, "xtrabackup: thd_is_replication_slave_thread() is called\n");
 
1433
        msg("xtrabackup: thd_is_replication_slave_thread() is called\n");
1383
1434
        return(FALSE);
1384
1435
}
1385
1436
 
1388
1439
        void*   thd)
1389
1440
{
1390
1441
        (void)thd;
1391
 
        fprintf(stderr, "xtrabackup: thd_has_edited_nontrans_tables() is called\n");
 
1442
        msg("xtrabackup: thd_has_edited_nontrans_tables() is called\n");
1392
1443
        return(FALSE);
1393
1444
}
1394
1445
 
1397
1448
        const void*     thd)
1398
1449
{
1399
1450
        (void)thd;
1400
 
        fprintf(stderr, "xtrabackup: thd_is_select() is called\n");
 
1451
        msg("xtrabackup: thd_is_select() is called\n");
1401
1452
        return(FALSE);
1402
1453
}
1403
1454
 
1422
1473
        (void)f;
1423
1474
        (void)input_thd;
1424
1475
        (void)max_query_len;
1425
 
        fprintf(stderr, "xtrabackup: innobase_mysql_print_thd() is called\n");
 
1476
        msg("xtrabackup: innobase_mysql_print_thd() is called\n");
1426
1477
}
1427
1478
 
1428
1479
void
1462
1513
        (void)from;
1463
1514
        (void)len;
1464
1515
 
1465
 
        fprintf(stderr, "xtrabackup: innobase_convert_from_table_id() is called\n");
 
1516
        msg("xtrabackup: innobase_convert_from_table_id() is called\n");
1466
1517
}
1467
1518
 
1468
1519
void
1480
1531
        (void)to;
1481
1532
        (void)from;
1482
1533
        (void)len;
1483
 
        fprintf(stderr, "xtrabackup: innobase_convert_from_id() is called\n");
 
1534
        msg("xtrabackup: innobase_convert_from_id() is called\n");
1484
1535
}
1485
1536
 
1486
1537
int
1503
1554
        void*   mysql_thd)
1504
1555
{
1505
1556
        (void)mysql_thd;
1506
 
        fprintf(stderr, "xtrabackup: innobase_get_charset() is called\n");
 
1557
        msg("xtrabackup: innobase_get_charset() is called\n");
1507
1558
        return(NULL);
1508
1559
}
1509
1560
 
1514
1565
{
1515
1566
        (void)mysql_thd;
1516
1567
        (void)length;
1517
 
        fprintf(stderr, "xtrabackup: innobase_get_stmt() is called\n");
 
1568
        msg("xtrabackup: innobase_get_stmt() is called\n");
1518
1569
        return("nothing");
1519
1570
}
1520
1571
 
1569
1620
                fd2 = dup(fd);
1570
1621
#endif
1571
1622
                if (fd2 < 0) {
1572
 
                        fprintf(stderr, "xtrabackup: Got error %d on dup\n",fd2);
 
1623
                        msg("xtrabackup: Got error %d on dup\n",fd2);
1573
1624
                }
1574
1625
                my_close(fd, MYF(MY_WME));
1575
1626
        }
1576
1627
        return(fd2);
1577
1628
}
1578
1629
 
 
1630
/***********************************************************************
 
1631
Creates a temporary file in tmpdir with a specified prefix in the file
 
1632
name. The file will be automatically removed on close.
 
1633
Unlike innobase_mysql_tmpfile(), dup() is not used, so the returned
 
1634
file must be closed with my_close().
 
1635
@return file descriptor or a negative number in case of error.*/
 
1636
File
 
1637
xtrabackup_create_tmpfile(char *path, const char *prefix)
 
1638
{
 
1639
        File    fd = create_temp_file(path, my_tmpdir(&mysql_tmpdir_list),
 
1640
                                      prefix,
 
1641
#ifdef __WIN__
 
1642
                                O_BINARY | O_TRUNC | O_SEQUENTIAL |
 
1643
                                O_TEMPORARY | O_SHORT_LIVED |
 
1644
#endif /* __WIN__ */
 
1645
                                O_CREAT | O_EXCL | O_RDWR,
 
1646
                                MYF(MY_WME));
 
1647
#ifndef __WIN__
 
1648
        if (fd >= 0) {
 
1649
                /* On Windows, open files cannot be removed, but files can be
 
1650
                created with the O_TEMPORARY flag to the same effect
 
1651
                ("delete on close"). */
 
1652
                unlink(path);
 
1653
        }
 
1654
#endif /* !__WIN__ */
 
1655
 
 
1656
        return(fd);
 
1657
}
 
1658
 
1579
1659
void
1580
1660
innobase_invalidate_query_cache(
1581
1661
        trx_t*  trx,
1826
1906
                        charset = get_charset(charset_number, MYF(MY_WME));
1827
1907
 
1828
1908
                        if (charset == NULL) {
1829
 
                          fprintf(stderr, "xtrabackup: InnoDB needs charset %lu for doing "
1830
 
                                          "a comparison, but MySQL cannot "
1831
 
                                          "find that charset.\n",
1832
 
                                          (ulong) charset_number);
 
1909
                                msg("xtrabackup: InnoDB needs charset %lu for "
 
1910
                                    "doing a comparison, but MySQL cannot "
 
1911
                                    "find that charset.\n",
 
1912
                                    (ulong) charset_number);
1833
1913
                                ut_a(0);
1834
1914
                        }
1835
1915
                }
1919
1999
ibool
1920
2000
innobase_query_is_update(void)
1921
2001
{
1922
 
        fprintf(stderr, "xtrabackup: innobase_query_is_update() is called\n");
 
2002
        msg("xtrabackup: innobase_query_is_update() is called\n");
1923
2003
        return(0);
1924
2004
}
1925
2005
 
1941
2021
        (void)buf;
1942
2022
        (void)buf_size;
1943
2023
 
1944
 
        fprintf(stderr, "xtrabackup: innobase_raw_format() is called\n");
 
2024
        msg("xtrabackup: innobase_raw_format() is called\n");
1945
2025
        return(0);
1946
2026
}
1947
2027
 
2048
2128
                int n_shift = get_bit_shift(innobase_page_size);
2049
2129
 
2050
2130
                if (n_shift >= 12 && n_shift <= UNIV_PAGE_SIZE_SHIFT_MAX) {
2051
 
                        fprintf(stderr,
2052
 
                                "InnoDB: Warning: innodb_page_size has been "
2053
 
                                "changed from default value 16384.\n");
 
2131
                        msg("InnoDB: Warning: innodb_page_size has been "
 
2132
                            "changed from default value 16384.\n");
2054
2133
                        srv_page_size_shift = n_shift;
2055
2134
                        srv_page_size = 1 << n_shift;
2056
 
                        fprintf(stderr,
2057
 
                                "InnoDB: The universal page size of the "
2058
 
                                "database is set to %lu.\n", srv_page_size);
 
2135
                        msg("InnoDB: The universal page size of the "
 
2136
                            "database is set to %lu.\n", srv_page_size);
2059
2137
                } else {
2060
 
                        fprintf(stderr, "InnoDB: Error: invalid value of "
2061
 
                               "innobase_page_size: %lu", innobase_page_size);
 
2138
                        msg("InnoDB: Error: invalid value of "
 
2139
                            "innobase_page_size: %lu", innobase_page_size);
2062
2140
                        exit(EXIT_FAILURE);
2063
2141
                }
2064
2142
        } else {
2070
2148
        if (innobase_log_block_size != 512) {
2071
2149
                uint    n_shift = get_bit_shift(innobase_log_block_size);;
2072
2150
 
2073
 
                fprintf(stderr,
2074
 
                        "InnoDB: Warning: innodb_log_block_size has "
2075
 
                        "been changed from its default value. "
2076
 
                        "(###EXPERIMENTAL### operation)\n");
 
2151
                msg("InnoDB: Warning: innodb_log_block_size has "
 
2152
                    "been changed from its default value. "
 
2153
                    "(###EXPERIMENTAL### operation)\n");
2077
2154
                if (n_shift > 0) {
2078
2155
                        srv_log_block_size = (1 << n_shift);
2079
 
                        fprintf(stderr,
2080
 
                                "InnoDB: The log block size is set to %lu.\n",
2081
 
                                srv_log_block_size);
 
2156
                        msg("InnoDB: The log block size is set to %lu.\n",
 
2157
                            srv_log_block_size);
2082
2158
                }
2083
2159
        } else {
2084
2160
                srv_log_block_size = 512;
2085
2161
        }
2086
2162
 
2087
2163
        if (!srv_log_block_size) {
2088
 
                fprintf(stderr,
2089
 
                        "InnoDB: Error: %lu is not valid value for "
2090
 
                        "innodb_log_block_size.\n", innobase_log_block_size);
 
2164
                msg("InnoDB: Error: %lu is not valid value for "
 
2165
                    "innodb_log_block_size.\n", innobase_log_block_size);
2091
2166
                goto error;
2092
2167
        }
2093
2168
 
2097
2172
        /* Check that values don't overflow on 32-bit systems. */
2098
2173
        if (sizeof(ulint) == 4) {
2099
2174
                if (xtrabackup_use_memory > UINT_MAX32) {
2100
 
                        fprintf(stderr,
2101
 
                                "xtrabackup: use-memory can't be over 4GB"
2102
 
                                " on 32-bit systems\n");
 
2175
                        msg("xtrabackup: use-memory can't be over 4GB"
 
2176
                            " on 32-bit systems\n");
2103
2177
                }
2104
2178
 
2105
2179
                if (innobase_buffer_pool_size > UINT_MAX32) {
2106
 
                        fprintf(stderr,
2107
 
                                "xtrabackup: innobase_buffer_pool_size can't be over 4GB"
2108
 
                                " on 32-bit systems\n");
 
2180
                        msg("xtrabackup: innobase_buffer_pool_size can't be "
 
2181
                            "over 4GB on 32-bit systems\n");
2109
2182
 
2110
2183
                        goto error;
2111
2184
                }
2112
2185
 
2113
2186
                if (innobase_log_file_size > UINT_MAX32) {
2114
 
                        fprintf(stderr,
2115
 
                                "xtrabackup: innobase_log_file_size can't be over 4GB"
2116
 
                                " on 32-bit systemsi\n");
 
2187
                        msg("xtrabackup: innobase_log_file_size can't be "
 
2188
                            "over 4GB on 32-bit systemsi\n");
2117
2189
 
2118
2190
                        goto error;
2119
2191
                }
2148
2220
        read from MySQL .cnf file */
2149
2221
 
2150
2222
        if (xtrabackup_backup || xtrabackup_stats) {
2151
 
                fprintf(stderr, "xtrabackup: Target instance is assumed as followings.\n");
 
2223
                msg("xtrabackup: Target instance is assumed as followings.\n");
2152
2224
        } else {
2153
 
                fprintf(stderr, "xtrabackup: Temporary instance for recovery is set as followings.\n");
 
2225
                msg("xtrabackup: Temporary instance for recovery is set as "
 
2226
                    "followings.\n");
2154
2227
        }
2155
2228
 
2156
2229
        /*--------------- Data files -------------------------*/
2159
2232
 
2160
2233
        srv_data_home = ((xtrabackup_backup || xtrabackup_stats) && innobase_data_home_dir
2161
2234
                         ? innobase_data_home_dir : default_path);
2162
 
        fprintf(stderr, "xtrabackup:   innodb_data_home_dir = %s\n", srv_data_home);
 
2235
        msg("xtrabackup:   innodb_data_home_dir = %s\n", srv_data_home);
2163
2236
 
2164
2237
        /* Set default InnoDB data file size to 10 MB and let it be
2165
2238
        auto-extending. Thus users can use InnoDB in >= 4.0 without having
2168
2241
        if (!innobase_data_file_path) {
2169
2242
                innobase_data_file_path = (char*) "ibdata1:10M:autoextend";
2170
2243
        }
2171
 
        fprintf(stderr, "xtrabackup:   innodb_data_file_path = %s\n",
2172
 
                innobase_data_file_path);
 
2244
        msg("xtrabackup:   innodb_data_file_path = %s\n",
 
2245
            innobase_data_file_path);
2173
2246
 
2174
2247
        /* Since InnoDB edits the argument in the next call, we make another
2175
2248
        copy of it: */
2189
2262
                        internal_innobase_data_file_path);
2190
2263
#endif
2191
2264
        if (ret == FALSE) {
2192
 
                fprintf(stderr,
2193
 
                        "xtrabackup: syntax error in innodb_data_file_path\n");
 
2265
                msg("xtrabackup: syntax error in innodb_data_file_path\n");
2194
2266
mem_free_and_error:
2195
2267
                free(internal_innobase_data_file_path);
2196
2268
                goto error;
2229
2301
        if (xtrabackup_prepare && xtrabackup_incremental_dir) {
2230
2302
                innobase_log_group_home_dir = xtrabackup_incremental_dir;
2231
2303
        }
2232
 
        fprintf(stderr, "xtrabackup:   innodb_log_group_home_dir = %s\n",
2233
 
                innobase_log_group_home_dir);
 
2304
        msg("xtrabackup:   innodb_log_group_home_dir = %s\n",
 
2305
            innobase_log_group_home_dir);
2234
2306
 
2235
2307
#ifdef UNIV_LOG_ARCHIVE
2236
2308
        /* Since innodb_log_arch_dir has no relevance under MySQL,
2251
2323
#endif
2252
2324
 
2253
2325
        if (ret == FALSE || innobase_mirrored_log_groups != 1) {
2254
 
          fprintf(stderr, "xtrabackup: syntax error in innodb_log_group_home_dir, or a "
2255
 
                          "wrong number of mirrored log groups\n");
 
2326
                msg("xtrabackup: syntax error in innodb_log_group_home_dir, "
 
2327
                    "or a wrong number of mirrored log groups\n");
2256
2328
 
2257
2329
                goto mem_free_and_error;
2258
2330
        }
2274
2346
        srv_n_log_groups = (ulint) innobase_mirrored_log_groups;
2275
2347
        srv_n_log_files = (ulint) innobase_log_files_in_group;
2276
2348
        srv_log_file_size = (ulint) innobase_log_file_size;
2277
 
        fprintf(stderr, "xtrabackup:   innodb_log_files_in_group = %ld\n",
2278
 
                srv_n_log_files);
2279
 
        fprintf(stderr, "xtrabackup:   innodb_log_file_size = %ld\n",
2280
 
                srv_log_file_size);
 
2349
        msg("xtrabackup:   innodb_log_files_in_group = %ld\n",
 
2350
            srv_n_log_files);
 
2351
        msg("xtrabackup:   innodb_log_file_size = %ld\n",
 
2352
            srv_log_file_size);
2281
2353
 
2282
2354
#ifdef UNIV_LOG_ARCHIVE
2283
2355
        srv_log_archive_on = (ulint) innobase_log_archive;
2419
2491
 
2420
2492
        if (srv_use_native_aio) {
2421
2493
                ut_print_timestamp(stderr);
2422
 
                fprintf(stderr,
2423
 
                        " InnoDB: Using Linux native AIO\n");
 
2494
                msg(" InnoDB: Using Linux native AIO\n");
2424
2495
        }
2425
2496
#else
2426
2497
        /* Currently native AIO is supported only on windows and linux
2434
2505
        return(FALSE);
2435
2506
 
2436
2507
error:
2437
 
        fprintf(stderr, "xtrabackup: innodb_init_param(): Error occured.\n");
 
2508
        msg("xtrabackup: innodb_init_param(): Error occured.\n");
2438
2509
        return(TRUE);
2439
2510
}
2440
2511
 
2464
2535
        return(FALSE);
2465
2536
 
2466
2537
error:
2467
 
        fprintf(stderr, "xtrabackup: innodb_init(): Error occured.\n");
 
2538
        msg("xtrabackup: innodb_init(): Error occured.\n");
2468
2539
        return(TRUE);
2469
2540
}
2470
2541
 
2474
2545
        srv_fast_shutdown = (ulint) innobase_fast_shutdown;
2475
2546
        innodb_inited = 0;
2476
2547
 
2477
 
        fprintf(stderr, "xtrabackup: starting shutdown with innodb_fast_shutdown = %lu\n",
2478
 
                srv_fast_shutdown);
 
2548
        msg("xtrabackup: starting shutdown with innodb_fast_shutdown = %lu\n",
 
2549
            srv_fast_shutdown);
2479
2550
 
2480
2551
        if (innobase_shutdown_for_mysql() != DB_SUCCESS) {
2481
2552
                goto error;
2493
2564
        return(FALSE);
2494
2565
 
2495
2566
error:
2496
 
        fprintf(stderr, "xtrabackup: innodb_end(): Error occured.\n");
 
2567
        msg("xtrabackup: innodb_end(): Error occured.\n");
2497
2568
        return(TRUE);
2498
2569
}
2499
2570
 
2500
2571
/* ================= common ================= */
2501
 
static my_bool
 
2572
 
 
2573
/***********************************************************************
 
2574
Read backup meta info.
 
2575
@return TRUE on success, FALSE on failure. */
 
2576
static
 
2577
my_bool
2502
2578
xtrabackup_read_metadata(char *filename)
2503
2579
{
2504
2580
        FILE *fp;
2505
 
        my_bool r = FALSE;
 
2581
        my_bool r = TRUE;
2506
2582
 
2507
2583
        fp = fopen(filename,"r");
2508
2584
        if(!fp) {
2509
 
                fprintf(stderr, "xtrabackup: Error: cannot open %s\n", filename);
2510
 
                return(TRUE);
 
2585
                msg("xtrabackup: Error: cannot open %s\n", filename);
 
2586
                return(FALSE);
2511
2587
        }
2512
2588
 
2513
2589
        if (fscanf(fp, "backup_type = %29s\n", metadata_type)
2514
2590
            != 1) {
2515
 
                r = TRUE;
 
2591
                r = FALSE;
2516
2592
                goto end;
2517
2593
        }
2518
2594
#ifndef INNODB_VERSION_SHORT
2519
2595
        if (fscanf(fp, "from_lsn = %lu:%lu\n", &metadata_from_lsn.high, &metadata_from_lsn.low)
2520
2596
            != 2) {
2521
 
                r = TRUE;
 
2597
                r = FALSE;
2522
2598
                goto end;
2523
2599
        }
2524
2600
        if (fscanf(fp, "to_lsn = %lu:%lu\n", &metadata_to_lsn.high, &metadata_to_lsn.low)
2525
2601
                        != 2) {
2526
 
                r = TRUE;
 
2602
                r = FALSE;
2527
2603
                goto end;
2528
2604
        }
2529
2605
        if (fscanf(fp, "last_lsn = %lu:%lu\n", &metadata_last_lsn.high, &metadata_last_lsn.low)
2533
2609
#else
2534
2610
        if (fscanf(fp, "from_lsn = %llu\n", &metadata_from_lsn)
2535
2611
                        != 1) {
2536
 
                r = TRUE;
 
2612
                r = FALSE;
2537
2613
                goto end;
2538
2614
        }
2539
2615
        if (fscanf(fp, "to_lsn = %llu\n", &metadata_to_lsn)
2540
2616
                        != 1) {
2541
 
                r = TRUE;
 
2617
                r = FALSE;
2542
2618
                goto end;
2543
2619
        }
2544
2620
        if (fscanf(fp, "last_lsn = %llu\n", &metadata_last_lsn)
2553
2629
        return(r);
2554
2630
}
2555
2631
 
2556
 
static my_bool
2557
 
xtrabackup_write_metadata(char *filename)
 
2632
/***********************************************************************
 
2633
Print backup meta info to a specified buffer. */
 
2634
static
 
2635
void
 
2636
xtrabackup_print_metadata(char *buf, size_t buf_len)
2558
2637
{
2559
 
        FILE *fp;
2560
 
        my_bool r = FALSE;
2561
 
 
2562
 
        fp = fopen(filename,"w");
2563
 
        if(!fp) {
2564
 
                fprintf(stderr, "xtrabackup: Error: cannot open %s\n", filename);
2565
 
                return(TRUE);
2566
 
        }
2567
 
 
2568
 
        if (fprintf(fp, "backup_type = %s\n", metadata_type)
2569
 
            < 0) {
2570
 
                r = TRUE;
2571
 
                goto end;
2572
 
        }
2573
2638
#ifndef INNODB_VERSION_SHORT
2574
 
        if (fprintf(fp, "from_lsn = %lu:%lu\n", metadata_from_lsn.high, metadata_from_lsn.low)
2575
 
                        < 0) {
2576
 
                r = TRUE;
2577
 
                goto end;
2578
 
        }
2579
 
        if (fprintf(fp, "to_lsn = %lu:%lu\n", metadata_to_lsn.high, metadata_to_lsn.low)
2580
 
                        < 0) {
2581
 
                r = TRUE;
2582
 
                goto end;
2583
 
        }
2584
 
        if (fprintf(fp, "last_lsn = %lu:%lu\n", metadata_last_lsn.high, metadata_last_lsn.low)
2585
 
                        < 0) {
2586
 
                r = TRUE;
2587
 
                goto end;
2588
 
        }
 
2639
        snprintf(buf, buf_len,
 
2640
                 "backup_type = %s\n"
 
2641
                 "from_lsn = %lu:%lu\n"
 
2642
                 "to_lsn = %lu:%lu\n"
 
2643
                 "last_lsn = %lu:%lu\n",
 
2644
                 metadata_type,
 
2645
                 metadata_from_lsn.high, metadata_from_lsn.low,
 
2646
                 metadata_to_lsn.high, metadata_to_lsn.low,
 
2647
                 metadata_last_lsn.high, metadata_last_lsn.low);
2589
2648
#else
2590
 
        if (fprintf(fp, "from_lsn = %llu\n", metadata_from_lsn)
2591
 
                        < 0) {
2592
 
                r = TRUE;
2593
 
                goto end;
2594
 
        }
2595
 
        if (fprintf(fp, "to_lsn = %llu\n", metadata_to_lsn)
2596
 
                        < 0) {
2597
 
                r = TRUE;
2598
 
                goto end;
2599
 
        }
2600
 
        if (fprintf(fp, "last_lsn = %llu\n", metadata_last_lsn)
2601
 
                        < 0) {
2602
 
                r = TRUE;
2603
 
                goto end;
2604
 
        }
 
2649
        snprintf(buf, buf_len,
 
2650
                 "backup_type = %s\n"
 
2651
                 "from_lsn = %llu\n"
 
2652
                 "to_lsn = %llu\n"
 
2653
                 "last_lsn = %llu\n",
 
2654
                 metadata_type,
 
2655
                 metadata_from_lsn,
 
2656
                 metadata_to_lsn,
 
2657
                 metadata_last_lsn);
2605
2658
#endif
2606
 
 end:
 
2659
}
 
2660
 
 
2661
/***********************************************************************
 
2662
Stream backup meta info to a specified datasink.
 
2663
@return TRUE on success, FALSE on failure. */
 
2664
static
 
2665
my_bool
 
2666
xtrabackup_stream_metadata(ds_ctxt_t *ds_ctxt)
 
2667
{
 
2668
        char            buf[1024];
 
2669
        size_t          len;
 
2670
        datasink_t      *ds = ds_ctxt->datasink;
 
2671
        ds_file_t       *stream;
 
2672
        MY_STAT         mystat;
 
2673
 
 
2674
        xtrabackup_print_metadata(buf, sizeof(buf));
 
2675
 
 
2676
        len = strlen(buf);
 
2677
 
 
2678
        mystat.st_size = len;
 
2679
        mystat.st_mtime = my_time(0);
 
2680
 
 
2681
        stream = ds->open(ds_ctxt, XTRABACKUP_METADATA_FILENAME,
 
2682
                          &mystat);
 
2683
        if (stream == NULL) {
 
2684
                msg("xtrabackup: Error: cannot open output stream "
 
2685
                    "for %s\n", XTRABACKUP_METADATA_FILENAME);
 
2686
                return(FALSE);
 
2687
        }
 
2688
 
 
2689
        if (ds->write(stream, buf, len)) {
 
2690
                ds->close(stream);
 
2691
                return(FALSE);
 
2692
        }
 
2693
 
 
2694
        ds->close(stream);
 
2695
 
 
2696
        return(TRUE);
 
2697
}
 
2698
 
 
2699
/***********************************************************************
 
2700
Write backup meta info to a specified file.
 
2701
@return TRUE on success, FALSE on failure. */
 
2702
static
 
2703
my_bool
 
2704
xtrabackup_write_metadata(const char *filepath)
 
2705
{
 
2706
        char            buf[1024];
 
2707
        size_t          len;
 
2708
        FILE            *fp;
 
2709
 
 
2710
        xtrabackup_print_metadata(buf, sizeof(buf));
 
2711
 
 
2712
        len = strlen(buf);
 
2713
 
 
2714
        fp = fopen(filepath, "w");
 
2715
        if(!fp) {
 
2716
                msg("xtrabackup: Error: cannot open %s\n", filepath);
 
2717
                return(FALSE);
 
2718
        }
 
2719
        if (fwrite(buf, len, 1, fp) < 1) {
 
2720
                fclose(fp);
 
2721
                return(FALSE);
 
2722
        }
 
2723
 
2607
2724
        fclose(fp);
2608
2725
 
2609
 
        return(r);
 
2726
        return(TRUE);
2610
2727
}
2611
2728
 
2612
2729
/***********************************************************************
2637
2754
/***********************************************************************
2638
2755
Write meta info for an incremental delta.
2639
2756
@return TRUE on success, FALSE on failure. */
2640
 
static my_bool
2641
 
xb_write_delta_metadata(const char *filepath, const xb_delta_info_t *info)
 
2757
static
 
2758
my_bool
 
2759
xb_write_delta_metadata(ds_ctxt_t *ds_ctxt, const char *filename,
 
2760
                        const xb_delta_info_t *info)
2642
2761
{
2643
 
        FILE *fp;
2644
 
        my_bool r= TRUE;
2645
 
 
2646
 
        fp = fopen(filepath, "w");
2647
 
        if (!fp) {
2648
 
                fprintf(stderr, "xtrabackup: Error: cannot open %s\n", filepath);
 
2762
        datasink_t      *ds = ds_ctxt->datasink;
 
2763
        ds_file_t       *f;
 
2764
        char            buf[32];
 
2765
        my_bool         ret;
 
2766
        size_t          len;
 
2767
        MY_STAT         mystat;
 
2768
 
 
2769
        snprintf(buf, sizeof(buf), "page_size = %lu\n", info->page_size);
 
2770
 
 
2771
        len = strlen(buf);
 
2772
        mystat.st_size = len;
 
2773
        mystat.st_mtime = my_time(0);
 
2774
 
 
2775
        f = ds->open(ds_ctxt, filename, &mystat);
 
2776
        if (f == NULL) {
 
2777
                msg("xtrabackup: Error: cannot open output stream for %s\n",
 
2778
                    filename);
2649
2779
                return(FALSE);
2650
2780
        }
2651
2781
 
2652
 
        if (fprintf(fp, "page_size = %lu\n", info->page_size) < 0)
2653
 
                r= FALSE;
2654
 
 
2655
 
        fclose(fp);
2656
 
 
2657
 
        return(r);
 
2782
        ret = ds->write(f, buf, len) == 0;
 
2783
 
 
2784
        ds->close(f);
 
2785
 
 
2786
        return(ret);
2658
2787
}
2659
2788
 
2660
2789
/* ================= backup ================= */
2784
2913
/* TODO: We may tune the behavior (e.g. by fil_aio)*/
2785
2914
#define COPY_CHUNK 64
2786
2915
 
2787
 
static my_bool
2788
 
xtrabackup_copy_datafile(fil_node_t* node, uint thread_n)
 
2916
static
 
2917
my_bool
 
2918
xtrabackup_copy_datafile(fil_node_t* node, uint thread_n, ds_ctxt_t *ds_ctxt)
2789
2919
{
2790
2920
        os_file_t       src_file = XB_FILE_UNDEFINED;
2791
 
        os_file_t       dst_file = XB_FILE_UNDEFINED;
2792
 
        char            dst_path[FN_REFLEN];
2793
 
        char            meta_path[FN_REFLEN];
 
2921
        MY_STAT         src_stat;
 
2922
        char            dst_name[FN_REFLEN];
 
2923
        char            meta_name[FN_REFLEN];
2794
2924
        ibool           success;
2795
2925
        byte*           page;
2796
2926
        byte*           buf2 = NULL;
2806
2936
        ulint           zip_size;
2807
2937
#endif
2808
2938
        xb_delta_info_t info;
 
2939
        datasink_t      *ds = ds_ctxt->datasink;
 
2940
        ds_file_t       *dstfile = NULL;
2809
2941
 
2810
2942
        info.page_size = 0;
2811
2943
 
2816
2948
#endif
2817
2949
        { /* must backup id==0 */
2818
2950
                char *p;
2819
 
                int p_len, regres= 0;
 
2951
                int p_len, regres = REG_NOMATCH;
2820
2952
                char *next, *prev;
2821
2953
                char tmp;
2822
2954
                int i;
2851
2983
                *(p - 1) = SRV_PATH_SEPARATOR;
2852
2984
 
2853
2985
                if ( regres == REG_NOMATCH ) {
2854
 
                        printf("[%02u] Copying %s is skipped.\n",
2855
 
                               thread_n, node->name);
 
2986
                        msg("[%02u] Skipping %s\n",
 
2987
                            thread_n, node->name);
2856
2988
                        return(FALSE);
2857
2989
                }
2858
2990
        }
2895
3027
                p[p_len] = tmp;
2896
3028
 
2897
3029
                if (!table) {
2898
 
                        printf("[%02u] Copying %s is skipped.\n",
2899
 
                               thread_n, node->name);
 
3030
                        msg("[%02u] Skipping %s\n",
 
3031
                             thread_n, node->name);
2900
3032
                        return(FALSE);
2901
3033
                }
2902
3034
        }
2912
3044
        } else if (zip_size) {
2913
3045
                page_size = zip_size;
2914
3046
                page_size_shift = get_bit_shift(page_size);
2915
 
                fprintf(stderr, "[%02u] %s is compressed with page size = "
2916
 
                        "%lu bytes\n", thread_n, node->name, page_size);
 
3047
                msg("[%02u] %s is compressed with page size = "
 
3048
                    "%lu bytes\n", thread_n, node->name, page_size);
2917
3049
                if (page_size_shift < 10 || page_size_shift > 14) {
2918
 
                        fprintf(stderr, "[%02u] xtrabackup: Error: Invalid "
2919
 
                                "page size.\n", thread_n);
 
3050
                        msg("[%02u] xtrabackup: Error: Invalid "
 
3051
                            "page size: %lu.\n", thread_n, page_size);
2920
3052
                        ut_error;
2921
3053
                }
2922
3054
        } else {
2938
3070
                {
2939
3071
                        p = next + 1;
2940
3072
                }
2941
 
                sprintf(dst_path, "%s/%s", xtrabackup_target_dir, p);
 
3073
                strncpy(dst_name, p, sizeof(dst_name));
2942
3074
        } else {
2943
3075
                /* file per table style "./database/table.ibd" */
2944
 
                sprintf(dst_path, "%s%s", xtrabackup_target_dir, strstr(node->name, SRV_PATH_SEPARATOR_STR));
 
3076
                strncpy(dst_name, node->name, sizeof(dst_name));
2945
3077
        }
2946
3078
 
2947
3079
        if (xtrabackup_incremental) {
2951
3083
                incremental_buffer = ut_align(incremental_buffer_base,
2952
3084
                                      UNIV_PAGE_SIZE_MAX);
2953
3085
 
2954
 
                snprintf(meta_path, sizeof(meta_path),
2955
 
                         "%s%s", dst_path, XB_DELTA_INFO_SUFFIX);
2956
 
                strcat(dst_path, ".delta");
 
3086
                snprintf(meta_name, sizeof(meta_name),
 
3087
                         "%s%s", dst_name, XB_DELTA_INFO_SUFFIX);
 
3088
                strcat(dst_name, ".delta");
2957
3089
 
2958
3090
                /* clear buffer */
2959
3091
                bzero(incremental_buffer, (page_size/4) * page_size);
2962
3094
                page_in_buffer++;
2963
3095
 
2964
3096
                info.page_size = page_size;
2965
 
        }
 
3097
        } else
 
3098
                info.page_size = 0;
2966
3099
 
2967
3100
        /* open src_file*/
2968
3101
        if (!node->open) {
2974
3107
                        /* The following call prints an error message */
2975
3108
                        os_file_get_last_error(TRUE);
2976
3109
 
2977
 
                        fprintf(stderr,
2978
 
                                "[%02u] xtrabackup: Warning: cannot open %s\n"
2979
 
                                "[%02u] xtrabackup: Warning: We assume the "
2980
 
                                "table was dropped or renamed during "
2981
 
                                "xtrabackup execution and ignore the file.\n",
2982
 
                                thread_n, node->name, thread_n);
 
3110
                        msg("[%02u] xtrabackup: Warning: cannot open %s\n"
 
3111
                            "[%02u] xtrabackup: Warning: We assume the "
 
3112
                            "table was dropped or renamed during "
 
3113
                            "xtrabackup execution and ignore the file.\n",
 
3114
                            thread_n, node->name, thread_n);
2983
3115
                        goto skip;
2984
3116
                }
2985
3117
 
2993
3125
        posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
2994
3126
#endif
2995
3127
 
2996
 
        /* open dst_file */
2997
 
        /* xb_file_create reads srv_unix_file_flush_method */
2998
 
        dst_file = xb_file_create(dst_path, OS_FILE_CREATE,
2999
 
                                  OS_FILE_NORMAL, OS_DATA_FILE, &success);
3000
 
        if (!success) {
3001
 
                /* The following call prints an error message */
3002
 
                os_file_get_last_error(TRUE);
3003
 
 
3004
 
                fprintf(stderr,"[%02u] xtrabackup: error: "
3005
 
                        "cannot open %s\n", thread_n, dst_path);
 
3128
        if (my_stat(node->name, &src_stat, MYF(MY_WME)) == NULL) {
 
3129
                msg("[%02u] xtrabackup: Warning: cannot stat %s\n",
 
3130
                    thread_n, node->name);
 
3131
                goto skip;
 
3132
        }
 
3133
        dstfile = ds->open(ds_ctxt, dst_name, &src_stat);
 
3134
        if (dstfile == NULL) {
 
3135
                msg("[%02u] xtrabackup: error: "
 
3136
                    "cannot open the destination stream for %s\n",
 
3137
                    thread_n, dst_name);
3006
3138
                goto error;
3007
3139
        }
3008
3140
 
3009
 
#ifdef USE_POSIX_FADVISE
3010
 
        posix_fadvise(dst_file, 0, 0, POSIX_FADV_DONTNEED);
3011
 
#endif
 
3141
        if (xtrabackup_stream) {
 
3142
                const char *action = xtrabackup_compress ?
 
3143
                        "Compressing and streaming" : "Streaming";
 
3144
                msg("[%02u] %s %s\n", thread_n, action, node->name);
 
3145
        } else {
 
3146
                const char *action;
3012
3147
 
3013
 
        /* copy : TODO: tune later */
3014
 
        printf("[%02u] Copying %s \n     to %s\n", thread_n,
3015
 
               node->name, dst_path);
 
3148
                if (xtrabackup_compress) {
 
3149
                        action = "Compressing";
 
3150
                } else {
 
3151
                        action = "Copying";
 
3152
                }
 
3153
                msg("[%02u] %s %s to %s\n", thread_n, action,
 
3154
                    node->name, dstfile->path);
 
3155
        }
3016
3156
 
3017
3157
        buf2 = ut_malloc(COPY_CHUNK * page_size + UNIV_PAGE_SIZE);
3018
3158
        page = ut_align(buf2, UNIV_PAGE_SIZE);
3022
3162
                goto error;
3023
3163
        }
3024
3164
 
3025
 
        file_size = os_file_get_size_as_iblonglong(src_file);
 
3165
        file_size = src_stat.st_size;;
3026
3166
 
3027
3167
        for (offset = 0; offset < file_size; offset += COPY_CHUNK * page_size) {
3028
3168
                ulint chunk;
3029
3169
                ulint chunk_offset;
3030
3170
                ulint retry_count = 10;
3031
 
//copy_loop:
 
3171
 
3032
3172
                if (file_size - offset > COPY_CHUNK * page_size) {
3033
3173
                        chunk = COPY_CHUNK * page_size;
3034
3174
                } else {
3067
3207
                                           or it may contain the other format page like COMPRESSED.
3068
3208
                                           So, we can pass the check of double write buffer.*/
3069
3209
                                        ut_a(page_size == UNIV_PAGE_SIZE);
3070
 
                                        fprintf(stderr, "[%02u] xtrabackup: "
3071
 
                                                "Page %lu seems double write "
3072
 
                                                "buffer. passing the check.\n",
3073
 
                                                thread_n,
3074
 
                                                (ulint)((offset +
3075
 
                                                         (IB_INT64)chunk_offset) >>
3076
 
                                                        page_size_shift));
 
3210
                                        msg("[%02u] xtrabackup: "
 
3211
                                            "Page %lu seems double write "
 
3212
                                            "buffer. passing the check.\n",
 
3213
                                            thread_n,
 
3214
                                            (ulint)((offset +
 
3215
                                                     (IB_INT64)chunk_offset) >>
 
3216
                                                    page_size_shift));
3077
3217
                                } else {
3078
3218
                                        retry_count--;
3079
3219
                                        if (retry_count == 0) {
3080
 
                                                fprintf(stderr,
3081
 
                                                        "[%02u] xtrabackup: "
3082
 
                                                        "Error: 10 retries "
3083
 
                                                        "resulted in fail. This"
3084
 
                                                        "file seems to be "
3085
 
                                                        "corrupted.\n",
3086
 
                                                        thread_n);
 
3220
                                                msg("[%02u] xtrabackup: "
 
3221
                                                    "Error: 10 retries "
 
3222
                                                    "resulted in fail. This"
 
3223
                                                    "file seems to be "
 
3224
                                                    "corrupted.\n",
 
3225
                                                    thread_n);
3087
3226
                                                goto error;
3088
3227
                                        }
3089
 
                                        fprintf(stderr, "[%02u] xtrabackup: "
3090
 
                                                "Database page corruption "
3091
 
                                                "detected at page %lu. "
3092
 
                                                "retrying...\n",
3093
 
                                                thread_n,
3094
 
                                                (ulint)((offset +
3095
 
                                                         (IB_INT64)chunk_offset)
3096
 
                                                        >> page_size_shift));
 
3228
                                        msg("[%02u] xtrabackup: "
 
3229
                                            "Database page corruption "
 
3230
                                            "detected at page %lu. "
 
3231
                                            "retrying...\n",
 
3232
                                            thread_n,
 
3233
                                            (ulint)((offset +
 
3234
                                                     (IB_INT64)chunk_offset)
 
3235
                                                    >> page_size_shift));
3097
3236
                                        goto read_retry;
3098
3237
                                }
3099
3238
                        }
3110
3249
 
3111
3250
        if (page_in_buffer == page_size/4) {
3112
3251
                /* flush buffer */
3113
 
                success = os_file_write(dst_path, dst_file, incremental_buffer,
3114
 
                        ((incremental_buffers * (page_size/4))
3115
 
                                << page_size_shift) & 0xFFFFFFFFUL,
3116
 
                        (incremental_buffers * (page_size/4))
3117
 
                                >> (32 - page_size_shift),
3118
 
                        page_in_buffer * page_size);
3119
 
                if (!success) {
 
3252
                if (ds->write(dstfile, incremental_buffer,
 
3253
                              page_in_buffer * page_size)) {
3120
3254
                        goto error;
3121
3255
                }
3122
3256
 
3141
3275
                                }
3142
3276
                        }
3143
3277
                } else {
3144
 
                        success = os_file_write(dst_path, dst_file, page,
3145
 
                                (ulint)(offset & 0xFFFFFFFFUL),
3146
 
                                (ulint)(offset >> 32), chunk);
3147
 
                        if (!success) {
 
3278
                        if (ds->write(dstfile, page, chunk)) {
3148
3279
                                goto error;
3149
3280
                        }
3150
3281
                }
3160
3291
                mach_write_to_4(incremental_buffer, 0x58545241UL);/*"XTRA"*/
3161
3292
 
3162
3293
                /* flush buffer */
3163
 
                success = os_file_write(dst_path, dst_file, incremental_buffer,
3164
 
                        ((incremental_buffers * (page_size/4))
3165
 
                                << page_size_shift) & 0xFFFFFFFFUL,
3166
 
                        (incremental_buffers * (page_size/4))
3167
 
                                >> (32 - page_size_shift),
3168
 
                        page_in_buffer * page_size);
3169
 
                if (!success) {
3170
 
                        goto error;
3171
 
                }
3172
 
                if (!xb_write_delta_metadata(meta_path, &info)) {
3173
 
                        fprintf(stderr, "[%02u] xtrabackup: Error: "
3174
 
                                "failed to write meta info for %s\n",
3175
 
                                thread_n, dst_path);
3176
 
                        goto error;
3177
 
                }
3178
 
        }
3179
 
 
3180
 
        success = xb_file_flush(dst_file);
3181
 
        if (!success) {
3182
 
                goto error;
3183
 
        }
3184
 
 
3185
 
 
3186
 
        /* check size again */
3187
 
        /* TODO: but is it needed ?? */
3188
 
//      if (file_size < os_file_get_size_as_iblonglong(src_file)) {
3189
 
//              offset -= COPY_CHUNK * page_size;
3190
 
//              file_size = os_file_get_size_as_iblonglong(src_file);
3191
 
//              goto copy_loop;
3192
 
//      }
 
3294
                if (ds->write(dstfile, incremental_buffer,
 
3295
                              page_in_buffer * page_size)) {
 
3296
                        goto error;
 
3297
                }
 
3298
                if (!xb_write_delta_metadata(ds_ctxt, meta_name, &info)) {
 
3299
                        msg("[%02u] xtrabackup: Error: "
 
3300
                            "failed to write meta info for %s\n",
 
3301
                            thread_n, dst_name);
 
3302
                        goto error;
 
3303
                }
 
3304
        }
3193
3305
 
3194
3306
        /* TODO: How should we treat double_write_buffer here? */
3195
3307
        /* (currently, don't care about. Because,
3196
3308
            the blocks is newer than the last checkpoint anyway.) */
3197
3309
 
3198
3310
        /* close */
3199
 
        printf("[%02u]        ...done\n", thread_n);
 
3311
        msg("[%02u]        ...done\n", thread_n);
3200
3312
        if (!node->open) {
3201
3313
                os_file_close(src_file);
3202
3314
        }
3203
 
        os_file_close(dst_file);
 
3315
        ds->close(dstfile);
3204
3316
        if (incremental_buffer_base)
3205
3317
                ut_free(incremental_buffer_base);
3206
3318
        ut_free(buf2);
3208
3320
error:
3209
3321
        if (src_file != XB_FILE_UNDEFINED && !node->open)
3210
3322
                os_file_close(src_file);
3211
 
        if (dst_file != XB_FILE_UNDEFINED)
3212
 
                os_file_close(dst_file);
 
3323
        if (dstfile != NULL)
 
3324
                ds->close(dstfile);
3213
3325
        if (incremental_buffer_base)
3214
3326
                ut_free(incremental_buffer_base);
3215
3327
        if (buf2)
3216
3328
                ut_free(buf2);
3217
 
        fprintf(stderr, "[%02u] xtrabackup: Error: "
3218
 
                "xtrabackup_copy_datafile() failed.\n", thread_n);
 
3329
        msg("[%02u] xtrabackup: Error: "
 
3330
            "xtrabackup_copy_datafile() failed.\n", thread_n);
3219
3331
        return(TRUE); /*ERROR*/
3220
3332
 
3221
3333
skip:
3222
3334
        if (src_file != XB_FILE_UNDEFINED && !node->open)
3223
3335
                os_file_close(src_file);
3224
 
        if (dst_file != XB_FILE_UNDEFINED)
3225
 
                os_file_close(dst_file);
 
3336
        if (dstfile != NULL)
 
3337
                ds->close(dstfile);
3226
3338
        if (incremental_buffer_base)
3227
3339
                ut_free(incremental_buffer_base);
3228
3340
        if (buf2)
3229
3341
                ut_free(buf2);
3230
 
        fprintf(stderr, "[%02u] xtrabackup: Warning: skipping file %s.\n",
3231
 
                thread_n, node->name);
 
3342
        msg("[%02u] xtrabackup: Warning: We assume the "
 
3343
            "table was dropped during xtrabackup execution "
 
3344
            "and ignore the file.\n", thread_n);
 
3345
        msg("[%02u] xtrabackup: Warning: skipping file %s.\n",
 
3346
            thread_n, node->name);
3232
3347
        return(FALSE);
3233
3348
}
3234
3349
 
3240
3355
        LSN64           group_scanned_lsn;
3241
3356
        LSN64           contiguous_lsn;
3242
3357
 
3243
 
        ibool           success;
3244
 
 
3245
 
        if (!xtrabackup_stream)
3246
 
                ut_a(dst_log != XB_FILE_UNDEFINED);
 
3358
        ut_a(dst_log_fd != XB_FILE_UNDEFINED);
3247
3359
 
3248
3360
        /* read from checkpoint_lsn_start to current */
3249
3361
        contiguous_lsn = ut_dulint_align_down(from_lsn,
3273
3385
                log_group_read_log_seg(LOG_RECOVER, log_sys->buf,
3274
3386
                                                group, start_lsn, end_lsn);
3275
3387
 
3276
 
                //printf("log read from (%lu %lu) to (%lu %lu)\n",
3277
 
                //      start_lsn.high, start_lsn.low, end_lsn.high, end_lsn.low);
3278
3388
 
3279
3389
                /* reference recv_scan_log_recs() */
3280
3390
                {
3313
3423
#endif
3314
3424
                                                            ) - 1;
3315
3425
 
3316
 
                        fprintf(stderr,
3317
 
                                "xtrabackup: error:"
3318
 
                                " log block numbers mismatch:\n"
3319
 
                                "xtrabackup: error: expected log block no. %lu,"
3320
 
                                " but got no. %lu from the log file.\n",
3321
 
                                (ulong) scanned_no, (ulong) no);
 
3426
                        msg("xtrabackup: error:"
 
3427
                            " log block numbers mismatch:\n"
 
3428
                            "xtrabackup: error: expected log block no. %lu,"
 
3429
                            " but got no. %lu from the log file.\n",
 
3430
                            (ulong) scanned_no, (ulong) no);
3322
3431
 
3323
3432
                        if ((no - scanned_no) % blocks_in_group == 0) {
3324
 
                                fprintf(stderr,
3325
 
                                        "xtrabackup: error:"
3326
 
                                        " it looks like InnoDB log has wrapped"
3327
 
                                        " around before xtrabackup could"
3328
 
                                        " process all records due to either"
3329
 
                                        " log copying being too slow, or "
3330
 
                                        " log files being too small.\n");
 
3433
                                msg("xtrabackup: error:"
 
3434
                                    " it looks like InnoDB log has wrapped"
 
3435
                                    " around before xtrabackup could"
 
3436
                                    " process all records due to either"
 
3437
                                    " log copying being too slow, or "
 
3438
                                    " log files being too small.\n");
3331
3439
                        }
3332
3440
 
3333
3441
                        goto error;
3334
3442
                } else if (!checksum_is_ok) {
3335
3443
                        /* Garbage or an incompletely written log block */
3336
3444
 
3337
 
                        fprintf(stderr,
3338
 
                                "xtrabackup: error:"
3339
 
                                " Log block checksum mismatch"
 
3445
                        msg("xtrabackup: error: Log block checksum mismatch"
3340
3446
#ifndef INNODB_VERSION_SHORT
3341
 
                                " (block no %lu at lsn %lu %lu): \n"
 
3447
                            " (block no %lu at lsn %lu %lu): \n"
3342
3448
#else
3343
 
                                " (block no %lu at lsn %llu): \n"
 
3449
                            " (block no %lu at lsn %llu): \n"
3344
3450
#endif
3345
 
                                "expected %lu, calculated checksum %lu\n",
 
3451
                            "expected %lu, calculated checksum %lu\n",
3346
3452
                                (ulong) no,
3347
3453
#ifndef INNODB_VERSION_SHORT
3348
3454
                                (ulong) ut_dulint_get_high(scanned_lsn),
3406
3512
 
3407
3513
                /* ===== write log to 'xtrabackup_logfile' ====== */
3408
3514
                {
3409
 
                ulint write_size;
 
3515
                ulint   write_size;
 
3516
                size_t  rc = 0;
3410
3517
 
3411
3518
                if (!finished) {
3412
3519
                        write_size = RECV_SCAN_SIZE;
3414
3521
                        write_size = (ulint) ut_dulint_minus(
3415
3522
                                        ut_dulint_align_up(group_scanned_lsn, OS_FILE_LOG_BLOCK_SIZE),
3416
3523
                                        start_lsn);
3417
 
                }
3418
 
 
3419
 
                //printf("Wrinting offset= %lld, size= %lu\n", log_copy_offset, write_size);
3420
 
 
3421
 
                if (!xtrabackup_stream) {
3422
 
                        success = os_file_write(dst_log_path, dst_log, log_sys->buf,
3423
 
                                        (ulint)(log_copy_offset & 0xFFFFFFFFUL),
3424
 
                                        (ulint)(log_copy_offset >> 32), write_size);
3425
 
                } else {
3426
 
                        ulint ret;
3427
 
                        ulint stdout_write_size = write_size;
3428
 
                        if (finished && !is_last
3429
 
#ifndef INNODB_VERSION_SHORT
3430
 
                            && group_scanned_lsn.low % OS_FILE_LOG_BLOCK_SIZE
3431
 
#else
3432
 
                            && group_scanned_lsn % OS_FILE_LOG_BLOCK_SIZE
3433
 
#endif
3434
 
                           )
3435
 
                                stdout_write_size -= OS_FILE_LOG_BLOCK_SIZE;
3436
 
                        if (stdout_write_size) {
3437
 
                                ret = fwrite(log_sys->buf, 1, stdout_write_size, stdout);
3438
 
                                if (ret == stdout_write_size) {
3439
 
                                        success = TRUE;
3440
 
                                } else {
3441
 
                                        fprintf(stderr, "write: %lu > %lu\n", stdout_write_size, ret);
3442
 
                                        success = FALSE;
3443
 
                                }
3444
 
                        } else {
3445
 
                                success = TRUE; /* do nothing */
3446
 
                        }
3447
 
                }
3448
 
 
3449
 
                log_copy_offset += write_size;
3450
 
 
3451
 
#ifndef INNODB_VERSION_SHORT
3452
 
                if (finished && group_scanned_lsn.low % OS_FILE_LOG_BLOCK_SIZE)
3453
 
#else
3454
 
                if (finished && group_scanned_lsn % OS_FILE_LOG_BLOCK_SIZE)
3455
 
#endif
3456
 
                {
3457
 
                        /* if continue, it will start from align_down(group_scanned_lsn) */
3458
 
                        log_copy_offset -= OS_FILE_LOG_BLOCK_SIZE;
3459
 
                }
3460
 
 
3461
 
                if(!success) {
3462
 
                        if (!xtrabackup_stream) {
3463
 
                                fprintf(stderr, "xtrabackup: Error: os_file_write to %s\n", dst_log_path);
3464
 
                        } else {
3465
 
                                fprintf(stderr, "xtrabackup: Error: write to stdout\n");
3466
 
                        }
 
3524
                        if (!is_last &&
 
3525
#ifndef INNODB_VERSION_SHORT
 
3526
                            group_scanned_lsn.low % OS_FILE_LOG_BLOCK_SIZE
 
3527
#else
 
3528
                            group_scanned_lsn % OS_FILE_LOG_BLOCK_SIZE
 
3529
#endif
 
3530
                            )
 
3531
                                write_size -= OS_FILE_LOG_BLOCK_SIZE;
 
3532
                }
 
3533
 
 
3534
 
 
3535
                rc = my_write(dst_log_fd, log_sys->buf, write_size,
 
3536
                              MYF(MY_WME | MY_NABP));
 
3537
 
 
3538
                if(rc) {
 
3539
                        msg("xtrabackup: Error: write to logfile failed\n");
3467
3540
                        goto error;
3468
3541
                }
3469
3542
 
3480
3553
                group->scanned_lsn = group_scanned_lsn;
3481
3554
 
3482
3555
#ifndef INNODB_VERSION_SHORT
3483
 
                fprintf(stderr, ">> log scanned up to (%lu %lu)\n",group->scanned_lsn.high,group->scanned_lsn.low);
 
3556
                msg(">> log scanned up to (%lu %lu)\n",
 
3557
                    group->scanned_lsn.high, group->scanned_lsn.low);
3484
3558
#else
3485
 
                fprintf(stderr, ">> log scanned up to (%llu)\n",group->scanned_lsn);
 
3559
                msg(">> log scanned up to (%llu)\n", group->scanned_lsn);
3486
3560
#endif
3487
3561
 
3488
3562
                group = UT_LIST_GET_NEXT(log_groups, group);
3495
3569
        }
3496
3570
 
3497
3571
 
3498
 
        if (!xtrabackup_stream) {
3499
 
                success = xb_file_flush(dst_log);
3500
 
        } else {
3501
 
                fflush(stdout);
3502
 
                success = TRUE;
3503
 
        }
3504
 
 
3505
 
        if(!success) {
3506
 
                goto error;
3507
 
        }
3508
 
 
3509
3572
        return(FALSE);
3510
3573
 
3511
3574
error:
3512
3575
        mutex_exit(&log_sys->mutex);
3513
 
        if (!xtrabackup_stream)
3514
 
                os_file_close(dst_log);
3515
 
        fprintf(stderr, "xtrabackup: Error: xtrabackup_copy_logfile() failed.\n");
 
3576
        my_close(dst_log_fd, MYF(MY_WME));
 
3577
        msg("xtrabackup: Error: xtrabackup_copy_logfile() failed.\n");
3516
3578
        return(TRUE);
3517
3579
}
3518
3580
 
3530
3592
{
3531
3593
        ulint   counter = 0;
3532
3594
 
3533
 
        if (!xtrabackup_stream)
3534
 
                ut_a(dst_log != XB_FILE_UNDEFINED);
 
3595
        ut_a(dst_log_fd != XB_FILE_UNDEFINED);
3535
3596
 
3536
3597
        log_copying_running = TRUE;
3537
3598
 
3577
3638
 
3578
3639
                //for DEBUG
3579
3640
                //if (io_ticket == xtrabackup_throttle) {
3580
 
                //      fprintf(stderr, "There seem to be no IO...?\n");
 
3641
                //      msg("There seem to be no IO...?\n");
3581
3642
                //}
3582
3643
 
3583
3644
                io_ticket = xtrabackup_throttle;
3661
3722
                *ptr2 = SRV_PATH_SEPARATOR;
3662
3723
 
3663
3724
                if (my_mkdir(path, 0777, MYF(0)) < 0 && my_errno != EEXIST) {
3664
 
                        fprintf(stderr,
3665
 
                                "xtrabackup: Error: cannot mkdir %d: %s\n",
3666
 
                                my_errno, path);
 
3725
                        msg("xtrabackup: Error: cannot mkdir %d: %s\n",
 
3726
                            my_errno, path);
3667
3727
                        return -1;
3668
3728
                }
3669
3729
        }
3681
3741
        data_thread_ctxt_t      *ctxt = (data_thread_ctxt_t *) arg;
3682
3742
        uint                    num = ctxt->num;
3683
3743
        fil_space_t*            space;
3684
 
        ibool                   space_changed;
3685
3744
        fil_node_t*             node;
3686
3745
 
3687
3746
        /*
3688
 
          We have to initialize mysys thread-specific memory because
3689
 
          of the my_stat() call in xtrabackup_create_output_dir().
 
3747
          Initialize mysys thread-specific memory so we can
 
3748
          use mysys functions in this thread.
3690
3749
        */
3691
3750
        my_thread_init();
3692
3751
 
3693
3752
        debug_sync_point("data_copy_thread_func");
3694
3753
 
3695
 
        while ((node = datafiles_iter_next(ctxt->it, &space_changed)) != NULL) {
 
3754
        while ((node = datafiles_iter_next(ctxt->it)) != NULL) {
3696
3755
                space = node->space;
3697
3756
 
3698
 
                if (space_changed && xtrabackup_create_output_dir(space))
3699
 
                        exit(EXIT_FAILURE);
3700
 
 
3701
3757
                /* copy the datafile */
3702
 
                if(xtrabackup_copy_datafile(node, num)) {
3703
 
                        fprintf(stderr, "[%02u] xtrabackup: Error: "
3704
 
                                "failed to copy datafile.\n",
3705
 
                                num);
 
3758
                if(xtrabackup_copy_datafile(node, num, ctxt->ds_ctxt)) {
 
3759
                        msg("[%02u] xtrabackup: Error: "
 
3760
                            "failed to copy datafile.\n", num);
3706
3761
                        exit(EXIT_FAILURE);
3707
3762
                }
3708
3763
        }
3716
3771
        OS_THREAD_DUMMY_RETURN;
3717
3772
}
3718
3773
 
 
3774
/***********************************************************************
 
3775
Stream the transaction log from a temporary file a specified datasink.
 
3776
@return FALSE on succees, TRUE on error. */
 
3777
static
 
3778
ibool
 
3779
xtrabackup_stream_temp_logfile(File src_file, ds_ctxt_t *ds_ctxt)
 
3780
{
 
3781
        datasink_t      *ds = ds_ctxt->datasink;
 
3782
        uchar           *buf = NULL;
 
3783
        const size_t    buf_size = 1024 * 1024;
 
3784
        size_t          bytes;
 
3785
        ds_file_t       *dst_file = NULL;
 
3786
        MY_STAT         mystat;
 
3787
 
 
3788
        msg("xtrabackup: Streaming transaction log from a temporary file...\n");
 
3789
 
 
3790
#ifdef USE_POSIX_FADVISE
 
3791
        posix_fadvise(src_file, 0, 0, POSIX_FADV_SEQUENTIAL);
 
3792
        posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
 
3793
#endif
 
3794
 
 
3795
        if (my_seek(src_file, 0, SEEK_SET, MYF(0)) == MY_FILEPOS_ERROR) {
 
3796
                msg("xtrabackup: error: my_seek() failed, errno = %d.\n",
 
3797
                    my_errno);
 
3798
                    goto err;
 
3799
        }
 
3800
 
 
3801
        if (my_fstat(src_file, &mystat, MYF(0))) {
 
3802
                msg("xtrabackup: error: my_fstat() failed.\n");
 
3803
                goto err;
 
3804
        }
 
3805
 
 
3806
        dst_file = ds->open(ds_ctxt, XB_LOG_FILENAME, &mystat);
 
3807
        if (dst_file == NULL) {
 
3808
                msg("xtrabackup: error: cannot open the destination stream "
 
3809
                    "for %s.\n", XB_LOG_FILENAME);
 
3810
                goto err;
 
3811
        }
 
3812
 
 
3813
        buf = (uchar *) ut_malloc(buf_size);
 
3814
 
 
3815
        while ((bytes = my_read(src_file, buf, buf_size, MYF(MY_WME))) > 0) {
 
3816
                if (ds->write(dst_file, buf, bytes)) {
 
3817
                        msg("xtrabackup: error: cannot write to stream "
 
3818
                            "for %s.\n", XB_LOG_FILENAME);
 
3819
                        goto err;
 
3820
                }
 
3821
        }
 
3822
        if (bytes == (size_t) -1) {
 
3823
                goto err;
 
3824
        }
 
3825
 
 
3826
        ut_free(buf);
 
3827
        ds->close(dst_file);
 
3828
        my_close(src_file, MYF(MY_WME));
 
3829
 
 
3830
        msg("xtrabackup: Done.\n");
 
3831
 
 
3832
        return(FALSE);
 
3833
 
 
3834
err:
 
3835
        if (buf)
 
3836
                ut_free(buf);
 
3837
        if (dst_file)
 
3838
                ds->close(dst_file);;
 
3839
        if (src_file >= 0)
 
3840
                my_close(src_file, MYF(MY_WME));
 
3841
        msg("xtrabackup: Failed.\n");
 
3842
        return(TRUE);
 
3843
}
 
3844
 
3719
3845
static void
3720
3846
xtrabackup_backup_func(void)
3721
3847
{
3722
3848
        MY_STAT stat_info;
3723
3849
        LSN64 latest_cp;
 
3850
        char logfile_temp_path[FN_REFLEN];
 
3851
        datasink_t              *ds;
 
3852
        ds_ctxt_t               *ds_ctxt = NULL;
3724
3853
 
3725
3854
#ifdef USE_POSIX_FADVISE
3726
 
        fprintf(stderr, "xtrabackup: uses posix_fadvise().\n");
 
3855
        msg("xtrabackup: uses posix_fadvise().\n");
3727
3856
#endif
3728
3857
 
3729
3858
        /* cd to datadir */
3730
3859
 
3731
3860
        if (my_setwd(mysql_real_data_home,MYF(MY_WME)))
3732
3861
        {
3733
 
                fprintf(stderr, "xtrabackup: cannot my_setwd %s\n", mysql_real_data_home);
 
3862
                msg("xtrabackup: cannot my_setwd %s\n", mysql_real_data_home);
3734
3863
                exit(EXIT_FAILURE);
3735
3864
        }
3736
 
        fprintf(stderr, "xtrabackup: cd to %s\n", mysql_real_data_home);
 
3865
        msg("xtrabackup: cd to %s\n", mysql_real_data_home);
3737
3866
 
3738
3867
        mysql_data_home= mysql_data_home_buff;
3739
3868
        mysql_data_home[0]=FN_CURLIB;           // all paths are relative from here
3767
3896
 
3768
3897
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT")) {
3769
3898
                srv_unix_file_flush_method = SRV_UNIX_O_DIRECT;
3770
 
                fprintf(stderr,"xtrabackup: use O_DIRECT\n");
 
3899
                msg("xtrabackup: using O_DIRECT\n");
3771
3900
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "littlesync")) {
3772
3901
                srv_unix_file_flush_method = SRV_UNIX_LITTLESYNC;
3773
3902
 
3776
3905
#ifdef XTRADB_BASED
3777
3906
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "ALL_O_DIRECT")) {
3778
3907
                srv_unix_file_flush_method = SRV_UNIX_ALL_O_DIRECT;
 
3908
                msg("xtrabackup: using ALL_O_DIRECT\n");
3779
3909
#endif
3780
3910
#ifdef XTRADB_BASED
3781
3911
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "ALL_O_DIRECT")) {
3782
3912
                srv_unix_file_flush_method = SRV_UNIX_ALL_O_DIRECT;
3783
3913
#endif
3784
3914
        } else {
3785
 
                fprintf(stderr, 
3786
 
                "xtrabackup: Unrecognized value %s for innodb_flush_method\n",
3787
 
                                        srv_file_flush_method_str);
 
3915
                msg("xtrabackup: Unrecognized value %s for "
 
3916
                    "innodb_flush_method\n", srv_file_flush_method_str);
3788
3917
                exit(EXIT_FAILURE);
3789
3918
        }
3790
3919
#else /* __WIN__ */
3791
3920
        /* We can only use synchronous unbuffered IO on Windows for now */
3792
3921
        if (srv_file_flush_method_str != NULL) {
3793
 
                fprintf(stderr,
3794
 
                        "xtrabackupp: Warning: "
3795
 
                        "ignoring innodb_flush_method = %s on Windows.\n");
 
3922
                msg("xtrabackupp: Warning: "
 
3923
                    "ignoring innodb_flush_method = %s on Windows.\n");
3796
3924
        }
3797
3925
 
3798
3926
        srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
3923
4051
                                        &min_flushed_lsn, &max_flushed_lsn,
3924
4052
                                        &sum_of_new_sizes);
3925
4053
        if (err != DB_SUCCESS) {
3926
 
                fprintf(stderr,
 
4054
                msg(
3927
4055
"xtrabackup: Could not open or create data files.\n"
3928
4056
"xtrabackup: If you tried to add new data files, and it failed here,\n"
3929
4057
"xtrabackup: you should now edit innodb_data_file_path in my.cnf back\n"
3938
4066
 
3939
4067
        /* create_new_db must not be TRUE.. */
3940
4068
        if (create_new_db) {
3941
 
                fprintf(stderr, "xtrabackup: Something wrong with source files...\n");
 
4069
                msg("xtrabackup: Something wrong with source files...\n");
3942
4070
                exit(EXIT_FAILURE);
3943
4071
        }
3944
4072
 
3958
4086
                }
3959
4087
                if ((log_opened && create_new_db)
3960
4088
                                        || (log_opened && log_created)) {
3961
 
                        fprintf(stderr, 
 
4089
                        msg(
3962
4090
        "xtrabackup: Error: all log files must be created at the same time.\n"
3963
4091
        "xtrabackup: All log files must be created also in database creation.\n"
3964
4092
        "xtrabackup: If you want bigger or smaller log files, shut down the\n"
3973
4101
 
3974
4102
        /* log_file_created must not be TRUE, if online */
3975
4103
        if (log_file_created) {
3976
 
                fprintf(stderr, "xtrabackup: Something wrong with source files...\n");
 
4104
                msg("xtrabackup: Something wrong with source files...\n");
3977
4105
                exit(EXIT_FAILURE);
3978
4106
        }
3979
4107
 
3985
4113
        if (xtrabackup_extra_lsndir
3986
4114
                &&!my_stat(xtrabackup_extra_lsndir,&stat_info,MYF(0))
3987
4115
                && (my_mkdir(xtrabackup_extra_lsndir,0777,MYF(0)) < 0)){
3988
 
                fprintf(stderr,"xtrabackup: Error: cannot mkdir %d: %s\n",my_errno,xtrabackup_extra_lsndir);
 
4116
                msg("xtrabackup: Error: cannot mkdir %d: %s\n",
 
4117
                    my_errno, xtrabackup_extra_lsndir);
3989
4118
                exit(EXIT_FAILURE);
3990
4119
        }
3991
4120
 
3992
4121
 
3993
 
        if (!xtrabackup_stream) {
 
4122
        if (!xtrabackup_log_only) {
3994
4123
 
3995
4124
        /* create target dir if not exist */
3996
4125
        if (!my_stat(xtrabackup_target_dir,&stat_info,MYF(0))
3997
4126
                && (my_mkdir(xtrabackup_target_dir,0777,MYF(0)) < 0)){
3998
 
                fprintf(stderr,"xtrabackup: Error: cannot mkdir %d: %s\n",my_errno,xtrabackup_target_dir);
 
4127
                msg("xtrabackup: Error: cannot mkdir %d: %s\n",
 
4128
                    my_errno, xtrabackup_target_dir);
3999
4129
                exit(EXIT_FAILURE);
4000
4130
        }
4001
4131
 
4002
4132
        } else {
4003
 
                fprintf(stderr,"xtrabackup: Stream mode.\n");
4004
 
                /* stdout can treat binary at Linux */
4005
 
                //setmode(fileno(stdout), O_BINARY);
 
4133
                msg("xtrabackup: Log only mode.\n");
4006
4134
        }
4007
4135
 
4008
4136
        {
4016
4144
        byte*           log_hdr_buf;
4017
4145
        ulint           err;
4018
4146
 
4019
 
        ibool           success;
4020
 
 
4021
4147
        /* start back ground thread to copy newer log */
4022
4148
        os_thread_id_t log_copying_thread_id;
4023
4149
        datafiles_iter_t *it;
4024
4150
 
4025
4151
        log_hdr_buf = ut_align(log_hdr_buf_, OS_FILE_LOG_BLOCK_SIZE);
4026
4152
 
4027
 
        /* log space */
4028
 
        //space = UT_LIST_GET_NEXT(space_list, UT_LIST_GET_FIRST(f_system->space_list));
4029
 
        //printf("space: name=%s, id=%d, purpose=%d, size=%d\n",
4030
 
        //      space->name, space->id, space->purpose, space->size);
4031
 
 
4032
4153
        /* get current checkpoint_lsn */
4033
4154
        /* Look for the latest checkpoint from any of the log groups */
4034
4155
 
4080
4201
 
4081
4202
        mutex_exit(&log_sys->mutex);
4082
4203
 
4083
 
        if (!xtrabackup_stream) {
4084
 
 
4085
 
                /* open 'xtrabackup_logfile' */
4086
 
                sprintf(dst_log_path, "%s%s", xtrabackup_target_dir, "/xtrabackup_logfile");
4087
 
                srv_normalize_path_for_win(dst_log_path);
4088
 
                /* xb_file_create reads srv_unix_file_flush_method for
4089
 
                OS_DATA_FILE*/
4090
 
                dst_log = xb_file_create(dst_log_path, OS_FILE_CREATE,
4091
 
                                         OS_FILE_NORMAL, OS_DATA_FILE,
4092
 
                                         &success);
4093
 
 
4094
 
                if (!success) {
4095
 
                        /* The following call prints an error message */
4096
 
                        os_file_get_last_error(TRUE);
4097
 
 
4098
 
                        fprintf(stderr,
4099
 
"xtrabackup: error: cannot open %s\n",
4100
 
                                dst_log_path);
4101
 
                        exit(EXIT_FAILURE);
4102
 
                }
4103
 
 
 
4204
        /* open the log file */
 
4205
        if (!xtrabackup_log_only) {
 
4206
                /* The xbstream format allows concurrent files streaming */
 
4207
                if (xtrabackup_stream) {
 
4208
                        dst_log_fd = xtrabackup_create_tmpfile(
 
4209
                                logfile_temp_path, XB_LOG_FILENAME);
 
4210
                        if (dst_log_fd < 0) {
 
4211
                                msg("xtrabackup: error: "
 
4212
                                    "xtrabackup_create_tmpfile() failed. "
 
4213
                                    "(errno: %d)\n", my_errno);
 
4214
                                exit(EXIT_FAILURE);
 
4215
                        }
 
4216
                } else {
 
4217
                        fn_format(dst_log_path, XB_LOG_FILENAME,
 
4218
                                  xtrabackup_target_dir, "", MYF(0));
 
4219
                        dst_log_fd = my_create(dst_log_path, 0,
 
4220
                                               O_RDWR | O_BINARY | O_EXCL |
 
4221
                                               O_NOFOLLOW, MYF(MY_WME));
 
4222
                        if (dst_log_fd < 0) {
 
4223
                                msg("xtrabackup: error: cannot open %s "
 
4224
                                    "(errno: %d)\n", dst_log_path, my_errno);
 
4225
                                exit(EXIT_FAILURE);
 
4226
                        }
 
4227
                }
4104
4228
#ifdef USE_POSIX_FADVISE
4105
 
                posix_fadvise(dst_log, 0, 0, POSIX_FADV_DONTNEED);
 
4229
                posix_fadvise(dst_log_fd, 0, 0, POSIX_FADV_DONTNEED);
4106
4230
#endif
4107
 
 
 
4231
        } else {
 
4232
                dst_log_fd = dup(fileno(stdout));
 
4233
                if (dst_log_fd < 0) {
 
4234
                        msg("xtrabackup: error: dup() failed (errno: %d)",
 
4235
                            errno);
 
4236
                        exit(EXIT_FAILURE);
 
4237
                }
4108
4238
        }
4109
4239
 
4110
4240
        /* label it */
4114
4244
                (char*) log_hdr_buf + (LOG_FILE_WAS_CREATED_BY_HOT_BACKUP
4115
4245
                                + (sizeof "xtrabkup ") - 1));
4116
4246
 
4117
 
        if (!xtrabackup_stream) {
4118
 
                success = os_file_write(dst_log_path, dst_log, log_hdr_buf,
4119
 
                                0, 0, LOG_FILE_HDR_SIZE);
4120
 
        } else {
4121
 
                /* Stream */
4122
 
                if (fwrite(log_hdr_buf, 1, LOG_FILE_HDR_SIZE, stdout)
4123
 
                                == LOG_FILE_HDR_SIZE) {
4124
 
                        success = TRUE;
4125
 
                } else {
4126
 
                        success = FALSE;
4127
 
                }
4128
 
        }
4129
 
 
4130
 
        log_copy_offset += LOG_FILE_HDR_SIZE;
4131
 
        if (!success) {
4132
 
                if (dst_log != XB_FILE_UNDEFINED)
4133
 
                        os_file_close(dst_log);
 
4247
        if (my_write(dst_log_fd, log_hdr_buf, LOG_FILE_HDR_SIZE,
 
4248
                     MYF(MY_WME | MY_NABP))) {
4134
4249
                exit(EXIT_FAILURE);
4135
4250
        }
4136
4251
 
4155
4270
 
4156
4271
        os_thread_create(log_copying_thread, NULL, &log_copying_thread_id);
4157
4272
 
4158
 
 
4159
 
 
4160
 
        if (!xtrabackup_stream) { /* stream mode is transaction log only */
 
4273
        if (xtrabackup_parallel > 1 && xtrabackup_stream &&
 
4274
            xtrabackup_stream_fmt == XB_STREAM_FMT_TAR) {
 
4275
                msg("xtrabackup: warning: the --parallel option does not have "
 
4276
                    "any effect when streaming in the 'tar' format. "
 
4277
                    "You can use the 'xbstream' format instead.\n");
 
4278
                xtrabackup_parallel = 1;
 
4279
        }
 
4280
 
 
4281
        /* Initialize the appropriate datasink */
 
4282
        if (xtrabackup_log_only) {
 
4283
                ds = &datasink_local;
 
4284
        } else if (xtrabackup_compress) {
 
4285
                ds = &datasink_compress;
 
4286
        } else if (xtrabackup_stream) {
 
4287
                ds = &datasink_stream;
 
4288
        } else {
 
4289
                ds = &datasink_local;
 
4290
        }
 
4291
 
 
4292
        ds_ctxt = ds->init(xtrabackup_target_dir);
 
4293
        if (ds_ctxt == NULL) {
 
4294
                msg("xtrabackup: Error: failed to initialize the "
 
4295
                    "datasink.\n");
 
4296
                exit(EXIT_FAILURE);
 
4297
        }
 
4298
 
 
4299
        if (!xtrabackup_log_only) {
4161
4300
                uint                    i;
4162
4301
                uint                    count;
4163
4302
                os_mutex_t              count_mutex;
4164
4303
                data_thread_ctxt_t      *data_threads;
4165
4304
 
4166
 
                ut_a(parallel > 0);
 
4305
                ut_a(xtrabackup_parallel > 0);
4167
4306
 
4168
 
                if (parallel > 1)
4169
 
                        printf("xtrabackup: Starting %u threads for parallel "
4170
 
                               "data files transfer\n", parallel);
 
4307
                if (xtrabackup_parallel > 1) {
 
4308
                        msg("xtrabackup: Starting %u threads for parallel data "
 
4309
                            "files transfer\n", xtrabackup_parallel);
 
4310
                }
4171
4311
 
4172
4312
                it = datafiles_iter_new(f_system);
4173
4313
                if (it == NULL) {
4174
 
                        fprintf(stderr,
4175
 
                                "xtrabackup: Error: "
4176
 
                                "datafiles_iter_new() failed.\n");
 
4314
                        msg("xtrabackup: Error: "
 
4315
                            "datafiles_iter_new() failed.\n");
4177
4316
                        exit(EXIT_FAILURE);
4178
4317
                }
4179
4318
 
4180
4319
                /* Create data copying threads */
4181
 
                ut_a(parallel > 0);
4182
 
 
4183
4320
                data_threads = (data_thread_ctxt_t *)
4184
 
                        ut_malloc(sizeof(data_thread_ctxt_t) * parallel);
4185
 
                count = parallel;
 
4321
                        ut_malloc(sizeof(data_thread_ctxt_t) *
 
4322
                                  xtrabackup_parallel);
 
4323
                count = xtrabackup_parallel;
4186
4324
                count_mutex = OS_MUTEX_CREATE();
4187
4325
 
4188
 
                for (i = 0; i < (uint) parallel; i++) {
 
4326
                for (i = 0; i < (uint) xtrabackup_parallel; i++) {
4189
4327
                        data_threads[i].it = it;
4190
4328
                        data_threads[i].num = i+1;
4191
4329
                        data_threads[i].count = &count;
4192
4330
                        data_threads[i].count_mutex = count_mutex;
 
4331
                        data_threads[i].ds_ctxt = ds_ctxt;
4193
4332
                        os_thread_create(data_copy_thread_func,
4194
4333
                                         data_threads + i,
4195
4334
                                         &data_threads[i].id);
4205
4344
                        }
4206
4345
                        os_mutex_exit(count_mutex);
4207
4346
                }
4208
 
                /* NOTE: It may not needed at "--backup" for now */
4209
 
                /* mutex_enter(&(f_system->mutex)); */
4210
4347
 
4211
4348
                os_mutex_free(count_mutex);
 
4349
                ut_free(data_threads);
4212
4350
                datafiles_iter_free(it);
4213
4351
 
4214
 
        } //if (!xtrabackup_stream)
 
4352
        }
4215
4353
 
4216
 
        //mutex_exit(&(f_system->mutex));
4217
4354
        }
4218
4355
 
 
4356
        /* Close the datasync to flush any buffered data it might have,
 
4357
        so we don't end up with buffered data being written after the stream
 
4358
        produced by innobackupex. */
 
4359
        ds->deinit(ds_ctxt);
4219
4360
 
4220
4361
        /* suspend-at-end */
4221
4362
        if (xtrabackup_suspend_at_end) {
4234
4375
                                              &success);
4235
4376
 
4236
4377
                if (!success) {
4237
 
                        fprintf(stderr, "xtrabackup: Error: failed to create file 'xtrabackup_suspended'\n");
 
4378
                        msg("xtrabackup: Error: failed to create file "
 
4379
                            "'xtrabackup_suspended'\n");
4238
4380
                }
4239
4381
 
4240
4382
                if (suspend_file != XB_FILE_UNDEFINED)
4250
4392
                xtrabackup_suspend_at_end = FALSE; /* suspend is 1 time */
4251
4393
        }
4252
4394
 
 
4395
        /* Reinit the datasink */
 
4396
        ds_ctxt = ds->init(xtrabackup_target_dir);
 
4397
 
4253
4398
        /* read the latest checkpoint lsn */
4254
4399
        latest_cp = ut_dulint_zero;
4255
4400
        {
4262
4407
                err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field);
4263
4408
 
4264
4409
                if (err != DB_SUCCESS) {
4265
 
                        fprintf(stderr, "xtrabackup: Error: recv_find_max_checkpoint() failed.\n");
 
4410
                        msg("xtrabackup: Error: recv_find_max_checkpoint() failed.\n");
4266
4411
                        mutex_exit(&log_sys->mutex);
4267
4412
                        goto skip_last_cp;
4268
4413
                }
4273
4418
 
4274
4419
                mutex_exit(&log_sys->mutex);
4275
4420
 
4276
 
                if (!xtrabackup_stream) {
4277
 
#ifndef INNODB_VERSION_SHORT
4278
 
                        printf("xtrabackup: The latest check point (for incremental): '%lu:%lu'\n",
4279
 
                                latest_cp.high, latest_cp.low);
4280
 
#else
4281
 
                        printf("xtrabackup: The latest check point (for incremental): '%llu'\n",
4282
 
                                latest_cp);
4283
 
#endif
4284
 
                } else {
4285
 
#ifndef INNODB_VERSION_SHORT
4286
 
                        fprintf(stderr, "xtrabackup: The latest check point (for incremental): '%lu:%lu'\n",
4287
 
                                latest_cp.high, latest_cp.low);
4288
 
#else
4289
 
                        fprintf(stderr, "xtrabackup: The latest check point (for incremental): '%llu'\n",
4290
 
                                latest_cp);
4291
 
#endif
4292
 
                }
 
4421
#ifndef INNODB_VERSION_SHORT
 
4422
                msg("xtrabackup: The latest check point (for incremental): "
 
4423
                    "'%lu:%lu'\n", latest_cp.high, latest_cp.low);
 
4424
#else
 
4425
                msg("xtrabackup: The latest check point (for incremental): "
 
4426
                    "'%llu'\n", latest_cp);
 
4427
#endif
4293
4428
        }
4294
4429
skip_last_cp:
4295
4430
        /* stop log_copying_thread */
4296
4431
        log_copying = FALSE;
4297
 
        if (!xtrabackup_stream) {
4298
 
                printf("xtrabackup: Stopping log copying thread");
4299
 
                while (log_copying_running) {
4300
 
                        printf(".");
4301
 
                        os_thread_sleep(200000); /*0.2 sec*/
4302
 
                }
4303
 
                printf("\n");
 
4432
        msg("xtrabackup: Stopping log copying thread.\n");
 
4433
        while (log_copying_running) {
 
4434
                msg(".");
 
4435
                os_thread_sleep(200000); /*0.2 sec*/
 
4436
        }
 
4437
        msg("\n");
 
4438
 
 
4439
        if(!xtrabackup_incremental) {
 
4440
                strcpy(metadata_type, "full-backuped");
 
4441
                metadata_from_lsn = ut_dulint_zero;
4304
4442
        } else {
4305
 
                while (log_copying_running)
4306
 
                        os_thread_sleep(200000); /*0.2 sec*/
 
4443
                strcpy(metadata_type, "incremental");
 
4444
                metadata_from_lsn = incremental_lsn;
4307
4445
        }
 
4446
        metadata_to_lsn = latest_cp;
 
4447
        metadata_last_lsn = log_copy_scanned_lsn;
4308
4448
 
4309
 
        /* output to metadata file */
4310
 
        {
 
4449
        if (!xtrabackup_stream_metadata(ds_ctxt))
 
4450
                msg("xtrabackup: error: "
 
4451
                    "xtrabackup_stream_metadata() failed.\n"
 
4452
                    );
 
4453
        if (xtrabackup_extra_lsndir) {
4311
4454
                char    filename[FN_REFLEN];
4312
4455
 
4313
 
                if(!xtrabackup_incremental) {
4314
 
                        strcpy(metadata_type, "full-backuped");
4315
 
                        metadata_from_lsn = ut_dulint_zero;
4316
 
                } else {
4317
 
                        strcpy(metadata_type, "incremental");
4318
 
                        metadata_from_lsn = incremental_lsn;
4319
 
                }
4320
 
                metadata_to_lsn = latest_cp;
4321
 
                metadata_last_lsn = log_copy_scanned_lsn;
4322
 
 
4323
 
                sprintf(filename, "%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
4324
 
                if (xtrabackup_write_metadata(filename))
4325
 
                        fprintf(stderr, "xtrabackup: error: xtrabackup_write_metadata(xtrabackup_target_dir)\n");
4326
 
 
4327
 
                if(xtrabackup_extra_lsndir) {
4328
 
                        sprintf(filename, "%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
4329
 
                        if (xtrabackup_write_metadata(filename))
4330
 
                                fprintf(stderr, "xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
4331
 
                }
 
4456
                sprintf(filename, "%s/%s", xtrabackup_extra_lsndir,
 
4457
                        XTRABACKUP_METADATA_FILENAME);
 
4458
                if (!xtrabackup_write_metadata(filename))
 
4459
                        msg("xtrabackup: error: "
 
4460
                            "xtrabackup_write_metadata() failed.\n");
 
4461
 
4332
4462
        }
4333
4463
 
4334
4464
        if (!log_copying_succeed) {
4335
 
                fprintf(stderr, "xtrabackup: Error: log_copying_thread failed.\n");
4336
 
                exit(EXIT_FAILURE);
4337
 
        }
4338
 
 
4339
 
        if (!xtrabackup_stream)
4340
 
                os_file_close(dst_log);
 
4465
                msg("xtrabackup: Error: log_copying_thread failed.\n");
 
4466
                exit(EXIT_FAILURE);
 
4467
        }
 
4468
 
 
4469
        /* Stream the transaction log from the temporary file */
 
4470
        if (!xtrabackup_log_only && xtrabackup_stream &&
 
4471
            xtrabackup_stream_temp_logfile(dst_log_fd, ds_ctxt)) {
 
4472
                msg("xtrabackup: Error: failed to stream the log "
 
4473
                    "from the temporary file %s", logfile_temp_path);
 
4474
                exit(EXIT_FAILURE);
 
4475
        }
 
4476
 
 
4477
        ds->deinit(ds_ctxt);
4341
4478
 
4342
4479
        if (wait_throttle)
4343
4480
                os_event_free(wait_throttle);
4344
4481
 
4345
 
        if (!xtrabackup_stream) {
4346
 
#ifndef INNODB_VERSION_SHORT
4347
 
                printf("xtrabackup: Transaction log of lsn (%lu %lu) to (%lu %lu) was copied.\n",
4348
 
                        checkpoint_lsn_start.high, checkpoint_lsn_start.low,
4349
 
                        log_copy_scanned_lsn.high, log_copy_scanned_lsn.low);
4350
 
#else
4351
 
                printf("xtrabackup: Transaction log of lsn (%llu) to (%llu) was copied.\n",
4352
 
                        checkpoint_lsn_start, log_copy_scanned_lsn);
4353
 
#endif
4354
 
        } else {
4355
 
#ifndef INNODB_VERSION_SHORT
4356
 
                fprintf(stderr, "xtrabackup: Transaction log of lsn (%lu %lu) to (%lu %lu) was copied.\n",
4357
 
                        checkpoint_lsn_start.high, checkpoint_lsn_start.low,
4358
 
                        log_copy_scanned_lsn.high, log_copy_scanned_lsn.low);
4359
 
#else
4360
 
                fprintf(stderr, "xtrabackup: Transaction log of lsn (%llu) to (%llu) was copied.\n",
4361
 
                        checkpoint_lsn_start, log_copy_scanned_lsn);
4362
 
#endif
4363
 
                if(xtrabackup_extra_lsndir) {
4364
 
                        char    filename[FN_REFLEN];
4365
 
                        sprintf(filename, "%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
4366
 
                        if (xtrabackup_write_metadata(filename))
4367
 
                                fprintf(stderr, "xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
4368
 
                }
4369
 
        }
 
4482
#ifndef INNODB_VERSION_SHORT
 
4483
        msg("xtrabackup: Transaction log of lsn (%lu %lu) to (%lu %lu) was "
 
4484
            "copied.\n", checkpoint_lsn_start.high, checkpoint_lsn_start.low,
 
4485
            log_copy_scanned_lsn.high, log_copy_scanned_lsn.low);
 
4486
#else
 
4487
        msg("xtrabackup: Transaction log of lsn (%llu) to (%llu) was copied.\n",
 
4488
            checkpoint_lsn_start, log_copy_scanned_lsn);
 
4489
#endif
4370
4490
}
4371
4491
 
4372
4492
/* ================= stats ================= */
4527
4647
                                        offset = mach_read_from_4(data + local_len + BTR_EXTERN_OFFSET);
4528
4648
 
4529
4649
                                        if (offset != FIL_PAGE_DATA)
4530
 
                                                fprintf(stderr, "\nWarning: several record may share same external page.\n");
 
4650
                                                msg("\nWarning: several record may share same external page.\n");
4531
4651
 
4532
4652
                                        for (;;) {
4533
4653
                                                mtr_start(&local_mtr);
4646
4766
 
4647
4767
        if (my_setwd(mysql_real_data_home,MYF(MY_WME)))
4648
4768
        {
4649
 
                fprintf(stderr, "xtrabackup: cannot my_setwd %s\n", mysql_real_data_home);
 
4769
                msg("xtrabackup: cannot my_setwd %s\n", mysql_real_data_home);
4650
4770
                exit(EXIT_FAILURE);
4651
4771
        }
4652
 
        fprintf(stderr, "xtrabackup: cd to %s\n", mysql_real_data_home);
 
4772
        msg("xtrabackup: cd to %s\n", mysql_real_data_home);
4653
4773
 
4654
4774
        mysql_data_home= mysql_data_home_buff;
4655
4775
        mysql_data_home[0]=FN_CURLIB;           // all paths are relative from here
4677
4797
                sprintf(logname, "ib_logfile%lu", (ulong) n);
4678
4798
                if (!os_file_status(logname, &exists, &type) || !exists ||
4679
4799
                    type != OS_FILE_TYPE_FILE) {
4680
 
                        fprintf(stderr, "xtrabackup: Error: "
4681
 
                                "Cannot find log file %s.\n", logname);
4682
 
                        fprintf(stderr, "xtrabackup: Error: "
4683
 
                                "to use the statistics feature, you need a "
4684
 
                                "clean copy of the database including "
4685
 
                                "correctly sized log files, so you need to "
4686
 
                                "execute with --prepare twice to use this "
4687
 
                                "functionality on a backup.\n");
 
4800
                        msg("xtrabackup: Error: "
 
4801
                            "Cannot find log file %s.\n", logname);
 
4802
                        msg("xtrabackup: Error: "
 
4803
                            "to use the statistics feature, you need a "
 
4804
                            "clean copy of the database including "
 
4805
                            "correctly sized log files, so you need to "
 
4806
                            "execute with --prepare twice to use this "
 
4807
                            "functionality on a backup.\n");
4688
4808
                        exit(EXIT_FAILURE);
4689
4809
                }
4690
4810
        }
4691
4811
 
4692
 
        fprintf(stderr, "xtrabackup: Starting 'read-only' InnoDB instance to gather index statistics.\n"
4693
 
                "xtrabackup: Using %lld bytes for buffer pool (set by --use-memory parameter)\n",
4694
 
                xtrabackup_use_memory);
 
4812
        msg("xtrabackup: Starting 'read-only' InnoDB instance to gather "
 
4813
            "index statistics.\n"
 
4814
            "xtrabackup: Using %lld bytes for buffer pool (set by "
 
4815
            "--use-memory parameter)\n", xtrabackup_use_memory);
4695
4816
 
4696
4817
        if(innodb_init())
4697
4818
                exit(EXIT_FAILURE);
4776
4897
 
4777
4898
                if (xtrabackup_tables) {
4778
4899
                        char *p;
4779
 
                        int regres= 0;
 
4900
                        int regres = REG_NOMATCH;
4780
4901
                        int i;
4781
4902
 
4782
4903
                        p = strstr(table->name, SRV_PATH_SEPARATOR_STR);
4942
5063
        max_no = ut_dulint_zero;
4943
5064
 
4944
5065
        if(!xtrabackup_incremental_dir) {
4945
 
                sprintf(dst_path, "%s%s", xtrabackup_target_dir, "/ib_logfile0");
4946
 
                sprintf(src_path, "%s%s", xtrabackup_target_dir, "/xtrabackup_logfile");
 
5066
                sprintf(dst_path, "%s/ib_logfile0", xtrabackup_target_dir);
 
5067
                sprintf(src_path, "%s/%s", xtrabackup_target_dir,
 
5068
                        XB_LOG_FILENAME);
4947
5069
        } else {
4948
 
                sprintf(dst_path, "%s%s", xtrabackup_incremental_dir, "/ib_logfile0");
4949
 
                sprintf(src_path, "%s%s", xtrabackup_incremental_dir, "/xtrabackup_logfile");
 
5070
                sprintf(dst_path, "%s/ib_logfile0", xtrabackup_incremental_dir);
 
5071
                sprintf(src_path, "%s/%s", xtrabackup_incremental_dir,
 
5072
                        XB_LOG_FILENAME);
4950
5073
        }
4951
5074
 
4952
5075
        srv_normalize_path_for_win(dst_path);
4959
5082
                /* The following call prints an error message */
4960
5083
                os_file_get_last_error(TRUE);
4961
5084
 
4962
 
                fprintf(stderr,
4963
 
"xtrabackup: Warning: cannot open %s. will try to find.\n",
4964
 
                        src_path);
 
5085
                msg("xtrabackup: Warning: cannot open %s. will try to find.\n",
 
5086
                    src_path);
4965
5087
 
4966
5088
                /* check if ib_logfile0 may be xtrabackup_logfile */
4967
5089
                src_file = xb_file_create_no_error_handling(dst_path,
4970
5092
                                                            &success);
4971
5093
                if (!success) {
4972
5094
                        os_file_get_last_error(TRUE);
4973
 
                        fprintf(stderr,
4974
 
"  xtrabackup: Fatal error: cannot find %s.\n",
4975
 
                        src_path);
 
5095
                        msg("  xtrabackup: Fatal error: cannot find %s.\n",
 
5096
                            src_path);
4976
5097
 
4977
5098
                        goto error;
4978
5099
                }
4987
5108
 
4988
5109
                if ( ut_memcmp(log_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
4989
5110
                                (byte*)"xtrabkup", (sizeof "xtrabkup") - 1) == 0) {
4990
 
                        fprintf(stderr,
4991
 
"  xtrabackup: 'ib_logfile0' seems to be 'xtrabackup_logfile'. will retry.\n");
 
5111
                        msg("  xtrabackup: 'ib_logfile0' seems to be "
 
5112
                            "'xtrabackup_logfile'. will retry.\n");
4992
5113
 
4993
5114
                        ut_free(log_buf_);
4994
5115
                        log_buf_ = NULL;
5005
5126
                        goto retry;
5006
5127
                }
5007
5128
 
5008
 
                fprintf(stderr,
5009
 
"  xtrabackup: Fatal error: cannot find %s.\n",
 
5129
                msg("  xtrabackup: Fatal error: cannot find %s.\n",
5010
5130
                src_path);
5011
5131
 
5012
5132
                ut_free(log_buf_);
5040
5160
 
5041
5161
        if ( ut_memcmp(log_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
5042
5162
                        (byte*)"xtrabkup", (sizeof "xtrabkup") - 1) != 0 ) {
5043
 
                printf("xtrabackup: notice: xtrabackup_logfile was already used to '--prepare'.\n");
 
5163
                msg("xtrabackup: notice: xtrabackup_logfile was already used "
 
5164
                    "to '--prepare'.\n");
5044
5165
                goto skip_modify;
5045
5166
        } else {
5046
5167
                /* clear it later */
5078
5199
        }
5079
5200
 
5080
5201
        if (ut_dulint_cmp(max_no, ut_dulint_zero) == 0) {
5081
 
                fprintf(stderr, "xtrabackup: No valid checkpoint found.\n");
 
5202
                msg("xtrabackup: No valid checkpoint found.\n");
5082
5203
                goto error;
5083
5204
        }
5084
5205
 
5184
5305
        }
5185
5306
 
5186
5307
#ifndef INNODB_VERSION_SHORT
5187
 
        printf("xtrabackup: xtrabackup_logfile detected: size=%lld, start_lsn=(%lu %lu)\n",
5188
 
                file_size, max_lsn.high, max_lsn.low);
 
5308
        msg("xtrabackup: xtrabackup_logfile detected: size=%lld, "
 
5309
            "start_lsn=(%lu %lu)\n", file_size, max_lsn.high, max_lsn.low);
5189
5310
#else
5190
 
        printf("xtrabackup: xtrabackup_logfile detected: size=%lld, start_lsn=(%llu)\n",
5191
 
                file_size, max_lsn);
 
5311
        msg("xtrabackup: xtrabackup_logfile detected: size=%lld, "
 
5312
            "start_lsn=(%llu)\n", file_size, max_lsn);
5192
5313
#endif
5193
5314
 
5194
5315
        os_file_close(src_file);
5228
5349
                os_file_close(src_file);
5229
5350
        if (log_buf_)
5230
5351
                ut_free(log_buf_);
5231
 
        fprintf(stderr, "xtrabackup: Error: xtrabackup_init_temp_log() failed.\n");
 
5352
        msg("xtrabackup: Error: xtrabackup_init_temp_log() failed.\n");
5232
5353
        return(TRUE); /*ERROR*/
5233
5354
}
5234
5355
 
5313
5434
 
5314
5435
        page_size = info.page_size;
5315
5436
        page_size_shift = get_bit_shift(page_size);
5316
 
        fprintf(stderr, "xtrabackup: page size for %s is %lu bytes\n",
5317
 
                src_path, page_size);
 
5437
        msg("xtrabackup: page size for %s is %lu bytes\n",
 
5438
            src_path, page_size);
5318
5439
        if (page_size_shift < 10 ||
5319
5440
            page_size_shift > UNIV_PAGE_SIZE_SHIFT_MAX) {
5320
 
                fprintf(stderr,
5321
 
                        "xtrabackup: error: invalid value of page_size "
5322
 
                        "(%lu bytes) read from %s\n", page_size, meta_path);
 
5441
                msg("xtrabackup: error: invalid value of page_size "
 
5442
                    "(%lu bytes) read from %s\n", page_size, meta_path);
5323
5443
                goto error;
5324
5444
        }
5325
5445
        
5328
5448
                                                    &success);
5329
5449
        if (!success) {
5330
5450
                os_file_get_last_error(TRUE);
5331
 
                fprintf(stderr,
5332
 
                        "xtrabackup: error: cannot open %s\n",
5333
 
                        src_path);
 
5451
                msg("xtrabackup: error: cannot open %s\n", src_path);
5334
5452
                goto error;
5335
5453
        }
5336
5454
 
5349
5467
                ulint errcode = os_file_get_last_error(TRUE);
5350
5468
 
5351
5469
                if (errcode == OS_FILE_NOT_FOUND) {
5352
 
                        fprintf(stderr, "xtrabackup: target data file %s "
5353
 
                                "is not found, creating a new one\n", dst_path);
 
5470
                        msg("xtrabackup: target data file %s "
 
5471
                            "is not found, creating a new one\n", dst_path);
5354
5472
                        /* Create the database directory if it doesn't exist yet
5355
5473
                        */
5356
5474
                        if (dbname) {
5371
5489
                        goto again;
5372
5490
                }
5373
5491
 
5374
 
                fprintf(stderr,
5375
 
                        "xtrabackup: error: cannot open %s\n",
5376
 
                        dst_path);
 
5492
                msg("xtrabackup: error: cannot open %s\n", dst_path);
5377
5493
                goto error;
5378
5494
        }
5379
5495
 
5389
5505
        incremental_buffer = ut_align(incremental_buffer_base,
5390
5506
                                      UNIV_PAGE_SIZE_MAX);
5391
5507
 
5392
 
        fprintf(stderr, "Applying %s ...\n", src_path);
 
5508
        msg("Applying %s ...\n", src_path);
5393
5509
 
5394
5510
        while (!last_buffer) {
5395
5511
                ulint cluster_header;
5414
5530
                                last_buffer = TRUE;
5415
5531
                                break;
5416
5532
                        default:
5417
 
                                fprintf(stderr,
5418
 
                                        "xtrabackup: error: %s seems not .delta file.\n",
5419
 
                                        src_path);
 
5533
                                msg("xtrabackup: error: %s seems not "
 
5534
                                    ".delta file.\n", src_path);
5420
5535
                                goto error;
5421
5536
                }
5422
5537
 
5486
5601
                os_file_close(src_file);
5487
5602
        if (dst_file != XB_FILE_UNDEFINED)
5488
5603
                os_file_close(dst_file);
5489
 
        fprintf(stderr, "xtrabackup: Error: xtrabackup_apply_delta(): "
5490
 
                "failed to apply %s to %s.\n", src_path, dst_path);
 
5604
        msg("xtrabackup: Error: xtrabackup_apply_delta(): "
 
5605
            "failed to apply %s to %s.\n", src_path, dst_path);
5491
5606
        return FALSE;
5492
5607
}
5493
5608
 
5541
5656
 
5542
5657
                os_file_closedir(dbdir);
5543
5658
        } else {
5544
 
                fprintf(stderr, "xtrabackup: Cannot open dir %s\n", xtrabackup_incremental_dir);
 
5659
                msg("xtrabackup: Cannot open dir %s\n",
 
5660
                    xtrabackup_incremental_dir);
5545
5661
        }
5546
5662
 
5547
5663
        /* single table tablespaces */
5548
5664
        dir = os_file_opendir(xtrabackup_incremental_dir, FALSE);
5549
5665
 
5550
5666
        if (dir == NULL) {
5551
 
                fprintf(stderr, "xtrabackup: Cannot open dir %s\n", xtrabackup_incremental_dir);
 
5667
                msg("xtrabackup: Cannot open dir %s\n",
 
5668
                    xtrabackup_incremental_dir);
5552
5669
        }
5553
5670
 
5554
5671
                ret = fil_file_readdir_next_file(&err, xtrabackup_incremental_dir, dir,
5632
5749
 
5633
5750
        /* rename 'ib_logfile0' to 'xtrabackup_logfile' */
5634
5751
        if(!xtrabackup_incremental_dir) {
5635
 
                sprintf(dst_path, "%s%s", xtrabackup_target_dir, "/ib_logfile0");
5636
 
                sprintf(src_path, "%s%s", xtrabackup_target_dir, "/xtrabackup_logfile");
 
5752
                sprintf(dst_path, "%s/ib_logfile0", xtrabackup_target_dir);
 
5753
                sprintf(src_path, "%s/%s", xtrabackup_target_dir,
 
5754
                        XB_LOG_FILENAME);
5637
5755
        } else {
5638
 
                sprintf(dst_path, "%s%s", xtrabackup_incremental_dir, "/ib_logfile0");
5639
 
                sprintf(src_path, "%s%s", xtrabackup_incremental_dir, "/xtrabackup_logfile");
 
5756
                sprintf(dst_path, "%s/ib_logfile0", xtrabackup_incremental_dir);
 
5757
                sprintf(src_path, "%s/%s", xtrabackup_incremental_dir,
 
5758
                        XB_LOG_FILENAME);
5640
5759
        }
5641
5760
 
5642
5761
        srv_normalize_path_for_win(dst_path);
5689
5808
                os_file_close(src_file);
5690
5809
        if (log_buf_)
5691
5810
                ut_free(log_buf_);
5692
 
        fprintf(stderr, "xtrabackup: Error: xtrabackup_close_temp_log() failed.\n");
 
5811
        msg("xtrabackup: Error: xtrabackup_close_temp_log() failed.\n");
5693
5812
        return(TRUE); /*ERROR*/
5694
5813
}
5695
5814
 
5700
5819
 
5701
5820
        if (my_setwd(xtrabackup_real_target_dir,MYF(MY_WME)))
5702
5821
        {
5703
 
                fprintf(stderr, "xtrabackup: cannot my_setwd %s\n", xtrabackup_real_target_dir);
 
5822
                msg("xtrabackup: cannot my_setwd %s\n",
 
5823
                    xtrabackup_real_target_dir);
5704
5824
                exit(EXIT_FAILURE);
5705
5825
        }
5706
 
        fprintf(stderr, "xtrabackup: cd to %s\n", xtrabackup_real_target_dir);
 
5826
        msg("xtrabackup: cd to %s\n", xtrabackup_real_target_dir);
5707
5827
 
5708
5828
        xtrabackup_target_dir= mysql_data_home_buff;
5709
5829
        xtrabackup_target_dir[0]=FN_CURLIB;             // all paths are relative from here
5715
5835
 
5716
5836
                sprintf(filename, "%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
5717
5837
 
5718
 
                if (xtrabackup_read_metadata(filename))
5719
 
                        fprintf(stderr, "xtrabackup: error: xtrabackup_read_metadata()\n");
 
5838
                if (!xtrabackup_read_metadata(filename))
 
5839
                        msg("xtrabackup: error: xtrabackup_read_metadata()\n");
5720
5840
 
5721
5841
                if (!strcmp(metadata_type, "full-backuped")) {
5722
 
                        fprintf(stderr, "xtrabackup: This target seems to be not prepared yet.\n");
 
5842
                        msg("xtrabackup: This target seems to be not prepared "
 
5843
                            "yet.\n");
5723
5844
                } else if (!strcmp(metadata_type, "full-prepared")) {
5724
 
                        fprintf(stderr, "xtrabackup: This target seems to be already prepared.\n");
 
5845
                        msg("xtrabackup: This target seems to be already "
 
5846
                            "prepared.\n");
5725
5847
                        goto skip_check;
5726
5848
                } else {
5727
 
                        fprintf(stderr, "xtrabackup: This target seems not to have correct metadata...\n");
 
5849
                        msg("xtrabackup: This target seems not to have correct "
 
5850
                            "metadata...\n");
5728
5851
                }
5729
5852
 
5730
5853
                if (xtrabackup_incremental) {
5731
 
                        fprintf(stderr,
5732
 
                        "xtrabackup: error: applying incremental backup needs target prepared.\n");
 
5854
                        msg("xtrabackup: error: applying incremental backup "
 
5855
                            "needs target prepared.\n");
5733
5856
                        exit(EXIT_FAILURE);
5734
5857
                }
5735
5858
skip_check:
5736
5859
                if (xtrabackup_incremental
5737
5860
                    && ut_dulint_cmp(metadata_to_lsn, incremental_lsn) != 0) {
5738
 
                        fprintf(stderr,
5739
 
                        "xtrabackup: error: This incremental backup seems not to be proper for the target.\n"
5740
 
                        "xtrabackup:  Check 'to_lsn' of the target and 'from_lsn' of the incremental.\n");
 
5861
                        msg("xtrabackup: error: This incremental backup seems "
 
5862
                            "not to be proper for the target.\n"
 
5863
                            "xtrabackup:  Check 'to_lsn' of the target and "
 
5864
                            "'from_lsn' of the incremental.\n");
5741
5865
                        exit(EXIT_FAILURE);
5742
5866
                }
5743
5867
        }
5783
5907
                srv_n_file_io_threads = 10;
5784
5908
        }
5785
5909
 
5786
 
        fprintf(stderr, "xtrabackup: Starting InnoDB instance for recovery.\n"
5787
 
                "xtrabackup: Using %lld bytes for buffer pool (set by --use-memory parameter)\n",
5788
 
                xtrabackup_use_memory);
 
5910
        msg("xtrabackup: Starting InnoDB instance for recovery.\n"
 
5911
            "xtrabackup: Using %lld bytes for buffer pool "
 
5912
            "(set by --use-memory parameter)\n", xtrabackup_use_memory);
5789
5913
 
5790
5914
        if(innodb_init())
5791
5915
                goto error;
5792
5916
 
5793
 
        //printf("Hello InnoDB world!\n");
5794
 
 
5795
 
        /* TEST: innodb status*/
5796
 
/*
5797
 
        ulint   trx_list_start = ULINT_UNDEFINED;
5798
 
        ulint   trx_list_end = ULINT_UNDEFINED;
5799
 
        srv_printf_innodb_monitor(stdout, &trx_list_start, &trx_list_end);
5800
 
*/
5801
 
        /* TEST: list of datafiles and transaction log files and LSN*/
5802
 
/*
5803
 
        {
5804
 
        fil_system_t*   f_system = fil_system;
5805
 
        fil_space_t*    space;
5806
 
        fil_node_t*     node;
5807
 
 
5808
 
        mutex_enter(&(f_system->mutex));
5809
 
 
5810
 
        space = UT_LIST_GET_FIRST(f_system->space_list);
5811
 
 
5812
 
        while (space != NULL) {
5813
 
                printf("space: name=%s, id=%d, purpose=%d, size=%d\n",
5814
 
                        space->name, space->id, space->purpose, space->size);
5815
 
 
5816
 
                node = UT_LIST_GET_FIRST(space->chain);
5817
 
 
5818
 
                while (node != NULL) {
5819
 
                        printf("node: name=%s, open=%d, size=%d\n",
5820
 
                                node->name, node->open, node->size);
5821
 
 
5822
 
                        node = UT_LIST_GET_NEXT(chain, node);
5823
 
                }
5824
 
                space = UT_LIST_GET_NEXT(space_list, space);
5825
 
        }
5826
 
 
5827
 
        mutex_exit(&(f_system->mutex));
5828
 
        }
5829
 
*/
5830
5917
        /* align space sizes along with fsp header */
5831
5918
        {
5832
5919
        fil_system_t*   f_system = fil_system;
5873
5960
 
5874
5961
                        mtr_commit(&mtr);
5875
5962
 
5876
 
                        //printf("%d, %d\n", space->id, size);
5877
 
 
5878
5963
                        fil_extend_space_to_desired_size(&actual_size, space->id, size);
5879
5964
 
5880
5965
                        mutex_enter(&(f_system->mutex));
5889
5974
 
5890
5975
 
5891
5976
        if (xtrabackup_export) {
5892
 
                printf("xtrabackup: export option is specified.\n");
 
5977
                msg("xtrabackup: export option is specified.\n");
5893
5978
                if (innobase_file_per_table) {
5894
5979
                        fil_system_t*   f_system = fil_system;
5895
5980
                        fil_space_t*    space;
5957
6042
 
5958
6043
                                        table = dict_table_get_low(table_name);
5959
6044
                                        if (!table) {
5960
 
                                                fprintf(stderr,
5961
 
"xtrabackup: error: cannot find dictionary record of table %s\n", table_name);
 
6045
                                                msg("xtrabackup: error: "
 
6046
                                                    "cannot find dictionary "
 
6047
                                                    "record of table %s\n",
 
6048
                                                    table_name);
5962
6049
                                                goto next_node;
5963
6050
                                        }
5964
6051
                                        index = dict_table_get_first_index(table);
5965
6052
                                        n_index = UT_LIST_GET_LEN(table->indexes);
5966
6053
                                        if (n_index > 31) {
5967
 
                                                fprintf(stderr,
5968
 
"xtrabackup: error: sorry, cannot export over 31 indexes for now.\n");
 
6054
                                                msg("xtrabackup: error: "
 
6055
                                                    "sorry, cannot export over "
 
6056
                                                    "31 indexes for now.\n");
5969
6057
                                                goto next_node;
5970
6058
                                        }
5971
6059
 
5974
6062
                                        mach_write_to_4(page    , 0x78706f72UL);
5975
6063
                                        mach_write_to_4(page + 4, 0x74696e66UL);/*"xportinf"*/
5976
6064
                                        mach_write_to_4(page + 8, n_index);
5977
 
                                        strncpy((char*)page + 12, table_name, 500);
 
6065
                                        strncpy((char *) page + 12,
 
6066
                                                table_name, 500);
5978
6067
 
5979
 
                                        printf(
5980
 
"xtrabackup: export metadata of table '%s' to file `%s` (%lu indexes)\n",
5981
 
                                                table_name, info_file_path, n_index);
 
6068
                                        msg("xtrabackup: export metadata of "
 
6069
                                            "table '%s' to file `%s` "
 
6070
                                            "(%lu indexes)\n",
 
6071
                                            table_name, info_file_path,
 
6072
                                            n_index);
5982
6073
 
5983
6074
                                        n_index = 1;
5984
6075
                                        while (index) {
5989
6080
#else /* MYSQL_VERSION_ID < 51000 */
5990
6081
                                                                index->page);
5991
6082
#endif
5992
 
                                                strncpy((char*)page + n_index * 512 + 12, index->name, 500);
 
6083
                                        strncpy((char *) page + n_index * 512 +
 
6084
                                                12, index->name, 500);
5993
6085
 
5994
 
                                                printf(
5995
 
"xtrabackup:     name=%s, id.low=%lu, page=%lu\n",
5996
 
                                                        index->name,
 
6086
                                                msg("xtrabackup:     name=%s, "
 
6087
                                                    "id.low=%lu, page=%lu\n",
 
6088
                                                    index->name,
5997
6089
#if (MYSQL_VERSION_ID < 50500)
5998
 
                                                        index->id.low,
 
6090
                                                    index->id.low,
5999
6091
#else
6000
 
                                                        (ulint)(index->id & 0xFFFFFFFFUL),
 
6092
                                                    (ulint)(index->id &
 
6093
                                                            0xFFFFFFFFUL),
6001
6094
#endif
6002
6095
#if (MYSQL_VERSION_ID < 50100)
6003
 
                                                        index->tree->page);
 
6096
                                                    index->tree->page
6004
6097
#else /* MYSQL_VERSION_ID < 51000 */
6005
 
                                                        (ulint) index->page);
 
6098
                                                (ulint) index->page
6006
6099
#endif
6007
 
 
 
6100
                                                );
6008
6101
                                                index = dict_table_get_next_index(index);
6009
6102
                                                n_index++;
6010
6103
                                        }
6050
6143
        }
6051
6144
 
6052
6145
        /* print binlog position (again?) */
6053
 
        printf("\n[notice (again)]\n"
6054
 
                "  If you use binary log and don't use any hack of group commit,\n"
6055
 
                "  the binary log position seems to be:\n");
 
6146
        msg("\n[notice (again)]\n"
 
6147
            "  If you use binary log and don't use any hack of group commit,\n"
 
6148
            "  the binary log position seems to be:\n");
6056
6149
        trx_sys_print_mysql_binlog_offset();
6057
 
        printf("\n");
 
6150
        msg("\n");
6058
6151
 
6059
6152
        /* output to xtrabackup_binlog_pos_innodb */
6060
6153
        if (*trx_sys_mysql_bin_log_name != '\0') {
6067
6160
                                trx_sys_mysql_bin_log_pos);
6068
6161
                        fclose(fp);
6069
6162
                } else {
6070
 
                        printf("xtrabackup: failed to open 'xtrabackup_binlog_pos_innodb'\n");
 
6163
                        msg("xtrabackup: failed to open "
 
6164
                            "'xtrabackup_binlog_pos_innodb'\n");
6071
6165
                }
6072
6166
        }
6073
6167
 
6076
6170
             && ut_dulint_cmp(srv_start_lsn, incremental_last_lsn) < 0)
6077
6171
            ||(!xtrabackup_incremental
6078
6172
               && ut_dulint_cmp(srv_start_lsn, metadata_last_lsn) < 0)) {
6079
 
                printf( "xtrabackup: ########################################################\n"
6080
 
                        "xtrabackup: # !!WARNING!!                                          #\n"
6081
 
                        "xtrabackup: # The transaction log file should be wrong or corrupt. #\n"
6082
 
                        "xtrabackup: # The log was not applied to the intended LSN!         #\n"
6083
 
                        "xtrabackup: ########################################################\n");
 
6173
                msg(
 
6174
"xtrabackup: ########################################################\n"
 
6175
"xtrabackup: # !!WARNING!!                                          #\n"
 
6176
"xtrabackup: # The transaction log file is corrupted.               #\n"
 
6177
"xtrabackup: # The log was not applied to the intended LSN!         #\n"
 
6178
"xtrabackup: ########################################################\n"
 
6179
                    );
6084
6180
                if (xtrabackup_incremental) {
6085
6181
#ifndef INNODB_VERSION_SHORT
6086
 
                        printf("xtrabackup: The intended lsn is %lu:%lu\n",
6087
 
                                incremental_last_lsn.high, incremental_last_lsn.low);
 
6182
                        msg("xtrabackup: The intended lsn is %lu:%lu\n",
 
6183
                            incremental_last_lsn.high,
 
6184
                            incremental_last_lsn.low);
6088
6185
#else
6089
 
                        printf("xtrabackup: The intended lsn is %llu\n",
6090
 
                                incremental_last_lsn);
 
6186
                        msg("xtrabackup: The intended lsn is %llu\n",
 
6187
                            incremental_last_lsn);
6091
6188
#endif
6092
6189
                } else {
6093
6190
#ifndef INNODB_VERSION_SHORT
6094
 
                        printf("xtrabackup: The intended lsn is %lu:%lu\n",
6095
 
                                metadata_last_lsn.high, metadata_last_lsn.low);
 
6191
                        msg("xtrabackup: The intended lsn is %lu:%lu\n",
 
6192
                            metadata_last_lsn.high, metadata_last_lsn.low);
6096
6193
#else
6097
 
                        printf("xtrabackup: The intended lsn is %llu\n",
6098
 
                                metadata_last_lsn);
 
6194
                        msg("xtrabackup: The intended lsn is %llu\n",
 
6195
                            metadata_last_lsn);
6099
6196
#endif
6100
6197
                }
6101
6198
        }
6133
6230
                }
6134
6231
 
6135
6232
                sprintf(filename, "%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
6136
 
                if (xtrabackup_write_metadata(filename))
6137
 
                        fprintf(stderr, "xtrabackup: error: xtrabackup_write_metadata(xtrabackup_target_dir)\n");
 
6233
                if (!xtrabackup_write_metadata(filename))
 
6234
                        msg("xtrabackup: error: xtrabackup_write_metadata"
 
6235
                            "(xtrabackup_target_dir)\n");
6138
6236
 
6139
6237
                if(xtrabackup_extra_lsndir) {
6140
6238
                        sprintf(filename, "%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
6141
 
                        if (xtrabackup_write_metadata(filename))
6142
 
                                fprintf(stderr, "xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
 
6239
                        if (!xtrabackup_write_metadata(filename))
 
6240
                                msg("xtrabackup: error: "
 
6241
                                    "xtrabackup_write_metadata"
 
6242
                                    "(xtrabackup_extra_lsndir)\n");
6143
6243
                }
6144
6244
        }
6145
6245
 
6148
6248
 
6149
6249
        /* TODO: make more smart */
6150
6250
 
6151
 
        printf("\n[notice]\nWe cannot call InnoDB second time during the process lifetime.\n");
6152
 
        printf("Please re-execte to create ib_logfile*. Sorry.\n");
6153
 
/*
6154
 
        printf("Restart InnoDB to create ib_logfile*.\n");
6155
 
 
6156
 
        if(innodb_init_param())
6157
 
                goto error;
6158
 
 
6159
 
        if(innodb_init())
6160
 
                goto error;
6161
 
 
6162
 
        if(innodb_end())
6163
 
                goto error;
6164
 
*/
 
6251
        msg("\n[notice]\n"
 
6252
            "We cannot call InnoDB second time during the process lifetime.\n");
 
6253
        msg("Please re-execte to create ib_logfile*. Sorry.\n");
6165
6254
 
6166
6255
        return;
6167
6256
 
6185
6274
        /* ignore unsupported options */
6186
6275
        {
6187
6276
        int i,j,argc_new,find;
6188
 
        char *optend, *prev_found= NULL;
 
6277
        char *optend, *prev_found = NULL;
6189
6278
        argc_new = argc;
6190
6279
 
6191
6280
        j=1;
6195
6284
                optend= strcend((argv)[i], '=');
6196
6285
                if (!strncmp(argv[i], "--defaults-file", optend - argv[i]))
6197
6286
                {
6198
 
                        fprintf(stderr, "xtrabackup: Error: --defaults-file "
6199
 
                                "must be specified first on the command "
6200
 
                                "line\n");
 
6287
                        msg("xtrabackup: Error: --defaults-file "
 
6288
                            "must be specified first on the command "
 
6289
                            "line\n");
6201
6290
                        exit(EXIT_FAILURE);
6202
6291
                }
6203
6292
                for (count= 0; opt->name; opt++) {
6236
6325
        if ((!xtrabackup_prepare) && (strcmp(mysql_data_home, "./") == 0)) {
6237
6326
                if (!xtrabackup_print_param)
6238
6327
                        usage();
6239
 
                fprintf(stderr, "\n"
6240
 
                       "xtrabackup: Error: Please set parameter 'datadir'\n");
 
6328
                msg("\nxtrabackup: Error: Please set parameter 'datadir'\n");
6241
6329
                exit(EXIT_FAILURE);
6242
6330
        }
6243
6331
 
6244
 
        /* Redirect stdout to stderr for not doing a streaming backup or dumping
6245
 
        configuration for --print-param. */
6246
 
        if (!xtrabackup_stream && !xtrabackup_print_param && dup2(2, 1) < 0) {
6247
 
                fprintf(stderr, "Failed to redirect standard output.\n");
6248
 
        }
6249
 
 
6250
6332
        if (xtrabackup_tables) {
6251
6333
                /* init regexp */
6252
6334
                char *p, *next;
6275
6357
                        xb_regerror(xb_regcomp(&tables_regex[i], p,
6276
6358
                                               REG_EXTENDED),
6277
6359
                                    &tables_regex[i], errbuf, sizeof(errbuf));
6278
 
                        fprintf(stderr, "xtrabackup: tables regcomp(%s): %s\n",
6279
 
                                p, errbuf);
 
6360
                        msg("xtrabackup: tables regcomp(%s): %s\n", p, errbuf);
6280
6361
 
6281
6362
                        if (i != tables_regex_num - 1)
6282
6363
                                *(next - 1) = ',';
6288
6369
                char name_buf[NAME_LEN*2+2];
6289
6370
                FILE *fp;
6290
6371
 
6291
 
                if (xtrabackup_stream) {
6292
 
                        fprintf(stderr, "xtrabackup: Warning: --tables_file option doesn't affect with --stream.\n");
6293
 
                        xtrabackup_tables_file = NULL;
6294
 
                        goto skip_tables_file_register;
6295
 
                }
6296
 
 
6297
6372
                name_buf[NAME_LEN*2+1] = '\0';
6298
6373
 
6299
6374
                /* init tables_hash */
6302
6377
                /* read and store the filenames */
6303
6378
                fp = fopen(xtrabackup_tables_file,"r");
6304
6379
                if (!fp) {
6305
 
                        fprintf(stderr, "xtrabackup: cannot open %s\n", xtrabackup_tables_file);
 
6380
                        msg("xtrabackup: cannot open %s\n",
 
6381
                            xtrabackup_tables_file);
6306
6382
                        exit(EXIT_FAILURE);
6307
6383
                }
6308
6384
                for (;;) {
6333
6409
                        HASH_INSERT(xtrabackup_tables_t, name_hash, tables_hash,
6334
6410
                                        ut_fold_string(table->name), table);
6335
6411
 
6336
 
                        printf("xtrabackup: table '%s' is registerd to the list.\n", table->name);
 
6412
                        msg("xtrabackup: table '%s' is registerd to the "
 
6413
                            "list.\n", table->name);
6337
6414
                }
6338
6415
        }
6339
 
skip_tables_file_register:
6340
6416
 
6341
6417
#ifdef XTRADB_BASED
6342
6418
        /* temporary setting of enough size */
6350
6426
 
6351
6427
                char* endchar;
6352
6428
                int error = 0;
6353
 
 
6354
6429
#ifndef INNODB_VERSION_SHORT
6355
6430
                char* incremental_low;
6356
6431
                long long lsn_high, lsn_low;
6382
6457
#endif
6383
6458
 
6384
6459
                if (error) {
6385
 
                        fprintf(stderr, "xtrabackup: value '%s' may be wrong format for incremental option.\n",
6386
 
                                xtrabackup_incremental);
 
6460
                        msg("xtrabackup: value '%s' may be wrong format for "
 
6461
                            "incremental option.\n", xtrabackup_incremental);
6387
6462
                        exit(EXIT_FAILURE);
6388
6463
                }
6389
6464
        } else if (xtrabackup_backup && xtrabackup_incremental_basedir) {
6391
6466
 
6392
6467
                sprintf(filename, "%s/%s", xtrabackup_incremental_basedir, XTRABACKUP_METADATA_FILENAME);
6393
6468
 
6394
 
                if (xtrabackup_read_metadata(filename)) {
6395
 
                        fprintf(stderr,
6396
 
                                "xtrabackup: error: failed to read metadata from %s\n",
6397
 
                                filename);
 
6469
                if (!xtrabackup_read_metadata(filename)) {
 
6470
                        msg("xtrabackup: error: failed to read metadata from "
 
6471
                            "%s\n", filename);
6398
6472
                        exit(EXIT_FAILURE);
6399
6473
                }
6400
6474
 
6405
6479
 
6406
6480
                sprintf(filename, "%s/%s", xtrabackup_incremental_dir, XTRABACKUP_METADATA_FILENAME);
6407
6481
 
6408
 
                if (xtrabackup_read_metadata(filename)) {
6409
 
                        fprintf(stderr,
6410
 
                                "xtrabackup: error: failed to read metadata from %s\n",
6411
 
                                filename);
 
6482
                if (!xtrabackup_read_metadata(filename)) {
 
6483
                        msg("xtrabackup: error: failed to read metadata from "
 
6484
                            "%s\n", filename);
6412
6485
                        exit(EXIT_FAILURE);
6413
6486
                }
6414
6487
 
6452
6525
                exit(EXIT_SUCCESS);
6453
6526
        }
6454
6527
 
6455
 
        if (!xtrabackup_stream) {
6456
 
                print_version();
 
6528
        print_version();
 
6529
        if (!xtrabackup_log_only) {
6457
6530
                if (xtrabackup_incremental) {
6458
6531
#ifndef INNODB_VERSION_SHORT
6459
 
                        fprintf(stderr,
6460
 
                                "incremental backup from %lu:%lu is enabled.\n",
6461
 
                                incremental_lsn.high, incremental_lsn.low);
 
6532
                        msg("incremental backup from %lu:%lu is enabled.\n",
 
6533
                            incremental_lsn.high, incremental_lsn.low);
6462
6534
#else
6463
 
                        fprintf(stderr,
6464
 
                                "incremental backup from %llu is enabled.\n",
6465
 
                                incremental_lsn);
 
6535
                        msg("incremental backup from %llu is enabled.\n",
 
6536
                            incremental_lsn);
6466
6537
#endif
6467
6538
                }
6468
6539
        } else {
6469
6540
                if (xtrabackup_backup) {
6470
6541
                        xtrabackup_suspend_at_end = TRUE;
6471
 
                        fprintf(stderr, "xtrabackup: suspend-at-end is enabled.\n");
 
6542
                        msg("xtrabackup: suspend-at-end is enabled.\n");
6472
6543
                }
6473
6544
        }
6474
6545
 
6475
6546
        if (xtrabackup_export && innobase_file_per_table == FALSE) {
6476
 
                fprintf(stderr, "xtrabackup: error: --export option can only "
6477
 
                        "be used with --innodb-file-per-table=ON.\n");
 
6547
                msg("xtrabackup: error: --export option can only "
 
6548
                    "be used with --innodb-file-per-table=ON.\n");
6478
6549
                exit(EXIT_FAILURE);
6479
6550
        }
6480
6551