~akopytov/percona-xtrabackup/bug1166888-2.1

« back to all changes in this revision

Viewing changes to src/libarchive/tar/test/test_option_T_upper.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:
 
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
__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_T.c,v 1.3 2008/08/15 06:12:02 kientzle Exp $");
 
27
 
 
28
static int
 
29
touch(const char *fn, int fail)
 
30
{
 
31
        FILE *f = fopen(fn, "w");
 
32
        if (fail) {
 
33
                failure("Couldn't create file '%s', errno=%d (%s)\n",
 
34
                    fn, errno, strerror(errno));
 
35
                if (!assert(f != NULL))
 
36
                        return (0); /* Failure. */
 
37
        } else {
 
38
                if (f == NULL)
 
39
                        return (0); /* Soft failure. */
 
40
        }
 
41
        fclose(f);
 
42
        return (1); /* Success */
 
43
}
 
44
 
 
45
DEFINE_TEST(test_option_T_upper)
 
46
{
 
47
        FILE *f;
 
48
        int r;
 
49
        struct stat st;
 
50
        int gnarlyFilesSupported;
 
51
 
 
52
        /* Create a simple dir heirarchy; bail if anything fails. */
 
53
        if (!assertMakeDir("d1", 0755)) return;
 
54
        if (!assertMakeDir("d1/d2", 0755))      return;
 
55
        if (!touch("f", 1)) return;
 
56
        if (!touch("d1/f1", 1)) return;
 
57
        if (!touch("d1/f2", 1)) return;
 
58
        if (!touch("d1/d2/f3", 1)) return;
 
59
        if (!touch("d1/d2/f4", 1)) return;
 
60
        if (!touch("d1/d2/f5", 1)) return;
 
61
        if (!touch("d1/d2/f6", 1)) return;
 
62
        /* Some platforms don't permit such things; just skip it. */
 
63
        gnarlyFilesSupported = touch("d1/d2/f\x0a", 0);
 
64
 
 
65
        /* Populate a file list */
 
66
        f = fopen("filelist", "w+");
 
67
        if (!assert(f != NULL))
 
68
                return;
 
69
        /* Use a variety of text line endings. */
 
70
        fprintf(f, "f\x0d"); /* CR */
 
71
        fprintf(f, "d1/f1\x0d\x0a"); /* CRLF */
 
72
        fprintf(f, "d1/d2/f4\x0a"); /* NL */
 
73
        fprintf(f, "d1/d2/f6"); /* EOF */
 
74
        fclose(f);
 
75
 
 
76
        /* Populate a second file list */
 
77
        f = fopen("filelist2", "w+");
 
78
        if (!assert(f != NULL))
 
79
                return;
 
80
        /* Use null-terminated names. */
 
81
        fprintf(f, "d1/d2/f3");
 
82
        fwrite("\0", 1, 1, f);
 
83
        fprintf(f, "d1/d2/f5");
 
84
        fwrite("\0", 1, 1, f);
 
85
        if (gnarlyFilesSupported) {
 
86
                fprintf(f, "d1/d2/f\x0a");
 
87
                fwrite("\0", 1, 1, f);
 
88
        }
 
89
        fclose(f);
 
90
 
 
91
        /* Use -c -T to archive up the files. */
 
92
        r = systemf("%s -c -f test1.tar -T filelist > test1.out 2> test1.err",
 
93
            testprog);
 
94
        assert(r == 0);
 
95
        assertEmptyFile("test1.out");
 
96
        assertEmptyFile("test1.err");
 
97
 
 
98
        /* Use -x -T to dearchive the files */
 
99
        if (!assertMakeDir("test1", 0755)) return;
 
100
        systemf("%s -x -f test1.tar -T filelist -C test1"
 
101
            " > test1b.out 2> test1b.err", testprog);
 
102
        assertEmptyFile("test1b.out");
 
103
        assertEmptyFile("test1b.err");
 
104
 
 
105
        /* Verify the files were extracted. */
 
106
        assertFileExists("test1/f");
 
107
        assertFileExists("test1/d1/f1");
 
108
        assertFileNotExists("test1/d1/f2");
 
109
        assertFileNotExists("test1/d1/d2/f3");
 
110
        assertFileExists("test1/d1/d2/f4");
 
111
        assertFileNotExists("test1/d1/d2/f5");
 
112
        assertFileExists("test1/d1/d2/f6");
 
113
        if (gnarlyFilesSupported) {
 
114
                assertFileNotExists("test1/d1/d2/f\x0a");
 
115
        }
 
116
 
 
117
        /* Use -r -T to add more files to the archive. */
 
118
        systemf("%s -r -f test1.tar --null -T filelist2 > test2.out 2> test2.err",
 
119
            testprog);
 
120
        assertEmptyFile("test2.out");
 
121
        assertEmptyFile("test2.err");
 
122
 
 
123
        /* Use -x without -T to dearchive the files (ensure -r worked) */
 
124
        if (!assertMakeDir("test3", 0755)) return;
 
125
        systemf("%s -x -f test1.tar -C test3"
 
126
            " > test3.out 2> test3.err", testprog);
 
127
        assertEmptyFile("test3.out");
 
128
        assertEmptyFile("test3.err");
 
129
        /* Verify the files were extracted.*/
 
130
        assertFileExists("test3/f");
 
131
        assertFileExists("test3/d1/f1");
 
132
        assertFileNotExists("test3/d1/f2");
 
133
        assertFileExists("test3/d1/d2/f3");
 
134
        assertFileExists("test3/d1/d2/f4");
 
135
        assertFileExists("test3/d1/d2/f5");
 
136
        assertFileExists("test3/d1/d2/f6");
 
137
        if (gnarlyFilesSupported) {
 
138
                assertFileExists("test3/d1/d2/f\x0a");
 
139
        }
 
140
 
 
141
        /* Use -x -T to dearchive the files (verify -x -T together) */
 
142
        if (!assertMakeDir("test2", 0755)) return;
 
143
        systemf("%s -x -f test1.tar -T filelist -C test2"
 
144
            " > test2b.out 2> test2b.err", testprog);
 
145
        assertEmptyFile("test2b.out");
 
146
        assertEmptyFile("test2b.err");
 
147
        /* Verify the files were extracted.*/
 
148
        assertFileExists("test2/f");
 
149
        assertFileExists("test2/d1/f1");
 
150
        assertFileNotExists("test2/d1/f2");
 
151
        assertFileNotExists("test2/d1/d2/f3");
 
152
        assertFileExists("test2/d1/d2/f4");
 
153
        assertFileNotExists("test2/d1/d2/f5");
 
154
        assertFileExists("test2/d1/d2/f6");
 
155
        if (gnarlyFilesSupported) {
 
156
                assertFileNotExists("test2/d1/d2/f\x0a");
 
157
        }
 
158
 
 
159
        assertMakeDir("test4", 0755);
 
160
        assertMakeDir("test4_out", 0755);
 
161
        assertMakeDir("test4_out2", 0755);
 
162
        assertMakeDir("test4/d1", 0755);
 
163
        assertEqualInt(1, touch("test4/d1/foo", 0));
 
164
 
 
165
        /* Does bsdtar support -s option ? */
 
166
        systemf("%s -cf - -s /foo/bar/ test4/d1/foo > check.out 2> check.err",
 
167
            testprog);
 
168
        assertEqualInt(0, stat("check.err", &st));
 
169
        if (st.st_size == 0) {
 
170
                systemf("%s -cf - -s /foo/bar/ test4/d1/foo | %s -xf - -C test4_out",
 
171
                    testprog, testprog);
 
172
                assertEmptyFile("test4_out/test4/d1/bar");
 
173
                systemf("%s -cf - -s /d1/d2/ test4/d1/foo | %s -xf - -C test4_out",
 
174
                    testprog, testprog);
 
175
                assertEmptyFile("test4_out/test4/d2/foo");
 
176
                systemf("%s -cf - -s ,test4/d1/foo,, test4/d1/foo | %s -tvf - > test4.lst",
 
177
                    testprog, testprog);
 
178
                assertEmptyFile("test4.lst");
 
179
                systemf("%s -cf - test4/d1/foo | %s -xf - -s /foo/bar/ -C test4_out2",
 
180
                    testprog, testprog);
 
181
                assertEmptyFile("test4_out2/test4/d1/bar");
 
182
        } else {
 
183
                skipping("bsdtar does not support -s option on this platform");
 
184
        }
 
185
 
 
186
        /* TODO: Include some use of -C directory-changing within the filelist. */
 
187
        /* I'm pretty sure -C within the filelist is broken on extract. */
 
188
}