~akopytov/percona-xtrabackup/bug1166888-2.0

« back to all changes in this revision

Viewing changes to src/libarchive/cpio/test/test_option_a.c

  • Committer: Alexey Kopytov
  • Date: 2012-02-10 20:05:56 UTC
  • 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:
 
1
/*-
 
2
 * Copyright (c) 2003-2008 Tim Kientzle
 
3
 * All rights reserved.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
8
 * 1. Redistributions of source code must retain the above copyright
 
9
 *    notice, this list of conditions and the following disclaimer.
 
10
 * 2. Redistributions in binary form must reproduce the above copyright
 
11
 *    notice, this list of conditions and the following disclaimer in the
 
12
 *    documentation and/or other materials provided with the distribution.
 
13
 *
 
14
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 
15
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
16
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 
17
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
 
18
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 
19
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
20
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
21
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 
23
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
24
 */
 
25
#include "test.h"
 
26
#if defined(HAVE_UTIME_H)
 
27
#include <utime.h>
 
28
#elif defined(HAVE_SYS_UTIME_H)
 
29
#include <sys/utime.h>
 
30
#endif
 
31
__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_option_a.c,v 1.3 2008/08/24 06:21:00 kientzle Exp $");
 
32
 
 
33
static struct {
 
34
        const char *name;
 
35
        time_t atime_sec;
 
36
} files[] = {
 
37
        { "f0", 0 },
 
38
        { "f1", 0 },
 
39
        { "f2", 0 },
 
40
        { "f3", 0 },
 
41
        { "f4", 0 },
 
42
        { "f5", 0 }
 
43
};
 
44
 
 
45
/*
 
46
 * Create a bunch of test files and record their atimes.
 
47
 * For the atime preserve/change tests, the files must have
 
48
 * atimes in the past.  We can accomplish this by explicitly invoking
 
49
 * utime() on platforms that support it or by simply sleeping
 
50
 * for a second after creating the files.  (Creating all of the files
 
51
 * at once means we only need to sleep once.)
 
52
 */
 
53
static void
 
54
test_create(void)
 
55
{
 
56
        struct stat st;
 
57
        struct utimbuf times;
 
58
        static const int numfiles = sizeof(files) / sizeof(files[0]);
 
59
        int i;
 
60
 
 
61
        for (i = 0; i < numfiles; ++i) {
 
62
                /*
 
63
                 * Note: Have to write at least one byte to the file.
 
64
                 * cpio doesn't bother reading the file if it's zero length,
 
65
                 * so the atime never gets changed in that case, which
 
66
                 * makes the tests below rather pointless.
 
67
                 */
 
68
                assertMakeFile(files[i].name, 0644, "a");
 
69
 
 
70
                /* If utime() isn't supported on your platform, just
 
71
                 * #ifdef this section out.  Most of the test below is
 
72
                 * still valid. */
 
73
                memset(&times, 0, sizeof(times));
 
74
                times.actime = 1;
 
75
                times.modtime = 3;
 
76
                assertEqualInt(0, utime(files[i].name, &times));
 
77
 
 
78
                /* Record whatever atime the file ended up with. */
 
79
                /* If utime() is available, this should be 1, but there's
 
80
                 * no harm in being careful. */
 
81
                assertEqualInt(0, stat(files[i].name, &st));
 
82
                files[i].atime_sec = st.st_atime;
 
83
        }
 
84
 
 
85
        /* Wait until the atime on the last file is actually in the past. */
 
86
        sleepUntilAfter(files[numfiles - 1].atime_sec);
 
87
}
 
88
 
 
89
DEFINE_TEST(test_option_a)
 
90
{
 
91
        struct stat st;
 
92
        int r;
 
93
        char *p;
 
94
 
 
95
        /* Create all of the test files. */
 
96
        test_create();
 
97
 
 
98
        /* Sanity check; verify that atimes really do get modified. */
 
99
        assert((p = slurpfile(NULL, "f0")) != NULL);
 
100
        free(p);
 
101
        assertEqualInt(0, stat("f0", &st));
 
102
        if (st.st_atime == files[0].atime_sec) {
 
103
                skipping("Cannot verify -a option\n"
 
104
                    "      Your system appears to not support atime.");
 
105
        }
 
106
        else
 
107
        {
 
108
                /*
 
109
                 * If this disk is mounted noatime, then we can't
 
110
                 * verify correct operation without -a.
 
111
                 */
 
112
 
 
113
                /* Copy the file without -a; should change the atime. */
 
114
                r = systemf("echo %s | %s -pd copy-no-a > copy-no-a.out 2>copy-no-a.err", files[1].name, testprog);
 
115
                assertEqualInt(r, 0);
 
116
                assertTextFileContents("1 block\n", "copy-no-a.err");
 
117
                assertEmptyFile("copy-no-a.out");
 
118
                assertEqualInt(0, stat(files[1].name, &st));
 
119
                failure("Copying file without -a should have changed atime.");
 
120
                assert(st.st_atime != files[1].atime_sec);
 
121
 
 
122
                /* Archive the file without -a; should change the atime. */
 
123
                r = systemf("echo %s | %s -o > archive-no-a.out 2>archive-no-a.err", files[2].name, testprog);
 
124
                assertEqualInt(r, 0);
 
125
                assertTextFileContents("1 block\n", "copy-no-a.err");
 
126
                assertEqualInt(0, stat(files[2].name, &st));
 
127
                failure("Archiving file without -a should have changed atime.");
 
128
                assert(st.st_atime != files[2].atime_sec);
 
129
        }
 
130
 
 
131
        /*
 
132
         * We can, of course, still verify that the atime is unchanged
 
133
         * when using the -a option.
 
134
         */
 
135
 
 
136
        /* Copy the file with -a; should not change the atime. */
 
137
        r = systemf("echo %s | %s -pad copy-a > copy-a.out 2>copy-a.err",
 
138
            files[3].name, testprog);
 
139
        assertEqualInt(r, 0);
 
140
        assertTextFileContents("1 block\n", "copy-a.err");
 
141
        assertEmptyFile("copy-a.out");
 
142
        assertEqualInt(0, stat(files[3].name, &st));
 
143
        failure("Copying file with -a should not have changed atime.");
 
144
        assertEqualInt(st.st_atime, files[3].atime_sec);
 
145
 
 
146
        /* Archive the file with -a; should not change the atime. */
 
147
        r = systemf("echo %s | %s -oa > archive-a.out 2>archive-a.err",
 
148
            files[4].name, testprog);
 
149
        assertEqualInt(r, 0);
 
150
        assertTextFileContents("1 block\n", "copy-a.err");
 
151
        assertEqualInt(0, stat(files[4].name, &st));
 
152
        failure("Archiving file with -a should not have changed atime.");
 
153
        assertEqualInt(st.st_atime, files[4].atime_sec);
 
154
}