~stewart/percona-xtrabackup/bug1213036

« back to all changes in this revision

Viewing changes to src/libarchive/libarchive/test/test_read_format_isorr_new_bz2.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-2007 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: head/lib/libarchive/test/test_read_format_isorr_new_bz2.c 201247 2009-12-30 05:59:21Z kientzle $");
 
27
 
 
28
 
 
29
/*
 
30
PLEASE use latest cdrtools at least mkisofs version is 2.01.01a63 or later.
 
31
Old version mkisofs made wrong "SL" System Use Entry of RRIP.
 
32
 
 
33
Execute the following command to rebuild the data for this program:
 
34
   tail -n +34 test_read_format_isorr_new_bz2.c | /bin/sh
 
35
 
 
36
rm -rf /tmp/iso
 
37
mkdir /tmp/iso
 
38
mkdir /tmp/iso/dir
 
39
echo "hello" >/tmp/iso/file
 
40
dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file
 
41
ln /tmp/iso/file /tmp/iso/hardlink
 
42
(cd /tmp/iso; ln -s file symlink)
 
43
(cd /tmp/iso; ln -s /tmp/ symlink2)
 
44
(cd /tmp/iso; ln -s /tmp/../ symlink3)
 
45
(cd /tmp/iso; ln -s .././../tmp/ symlink4)
 
46
(cd /tmp/iso; ln -s .///file symlink5)
 
47
(cd /tmp/iso; ln -s /tmp//../ symlink6)
 
48
TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir
 
49
TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink
 
50
F=test_read_format_iso_rockridge_new.iso.Z
 
51
mkhybrid -R -uid 1 -gid 2 /tmp/iso | compress > $F
 
52
uuencode $F $F > $F.uu
 
53
exit 1
 
54
 */
 
55
 
 
56
DEFINE_TEST(test_read_format_isorr_new_bz2)
 
57
{
 
58
        const char *refname = "test_read_format_iso_rockridge_new.iso.Z";
 
59
        struct archive_entry *ae;
 
60
        struct archive *a;
 
61
        const void *p;
 
62
        size_t size;
 
63
        off_t offset;
 
64
        int i;
 
65
 
 
66
        extract_reference_file(refname);
 
67
        assert((a = archive_read_new()) != NULL);
 
68
        assertEqualInt(0, archive_read_support_compression_all(a));
 
69
        assertEqualInt(0, archive_read_support_format_all(a));
 
70
        assertEqualInt(ARCHIVE_OK,
 
71
            archive_read_open_filename(a, refname, 10240));
 
72
 
 
73
        /* Retrieve each of the 8 files on the ISO image and
 
74
         * verify that each one is what we expect. */
 
75
        for (i = 0; i < 10; ++i) {
 
76
                assertEqualInt(0, archive_read_next_header(a, &ae));
 
77
 
 
78
                if (strcmp(".", archive_entry_pathname(ae)) == 0) {
 
79
                        /* '.' root directory. */
 
80
                        assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
 
81
                        assertEqualInt(2048, archive_entry_size(ae));
 
82
                        /* Now, we read timestamp recorded by RRIP "TF". */
 
83
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
84
                        assertEqualInt(0, archive_entry_mtime_nsec(ae));
 
85
                        /* Now, we read links recorded by RRIP "PX". */
 
86
                        assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
 
87
                        assertEqualInt(1, archive_entry_uid(ae));
 
88
                        assertEqualIntA(a, ARCHIVE_EOF,
 
89
                            archive_read_data_block(a, &p, &size, &offset));
 
90
                        assertEqualInt((int)size, 0);
 
91
                } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) {
 
92
                        /* A directory. */
 
93
                        assertEqualString("dir", archive_entry_pathname(ae));
 
94
                        assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
 
95
                        assertEqualInt(2048, archive_entry_size(ae));
 
96
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
97
                        assertEqualInt(86401, archive_entry_atime(ae));
 
98
                        assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
 
99
                        assertEqualInt(1, archive_entry_uid(ae));
 
100
                        assertEqualInt(2, archive_entry_gid(ae));
 
101
                } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) {
 
102
                        /* A regular file. */
 
103
                        assertEqualString("hardlink", archive_entry_pathname(ae));
 
104
                        assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
 
105
                        assertEqualInt(12345684, archive_entry_size(ae));
 
106
                        assertEqualInt(0,
 
107
                            archive_read_data_block(a, &p, &size, &offset));
 
108
                        assertEqualInt(0, offset);
 
109
                        assertEqualMem(p, "hello\n", 6);
 
110
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
111
                        assertEqualInt(86401, archive_entry_atime(ae));
 
112
                        assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
 
113
                        assertEqualInt(1, archive_entry_uid(ae));
 
114
                        assertEqualInt(2, archive_entry_gid(ae));
 
115
                } else if (strcmp("file", archive_entry_pathname(ae)) == 0) {
 
116
                        /* A hardlink to the regular file. */
 
117
                        /* Note: If "hardlink" gets returned before "file",
 
118
                         * then "hardlink" will get returned as a regular file
 
119
                         * and "file" will get returned as the hardlink.
 
120
                         * This test should tolerate that, since it's a
 
121
                         * perfectly permissible thing for libarchive to do. */
 
122
                        assertEqualString("file", archive_entry_pathname(ae));
 
123
                        assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
 
124
                        assertEqualString("hardlink", archive_entry_hardlink(ae));
 
125
                        assertEqualInt(0, archive_entry_size_is_set(ae));
 
126
                        assertEqualInt(0, archive_entry_size(ae));
 
127
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
128
                        assertEqualInt(86401, archive_entry_atime(ae));
 
129
                        assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
 
130
                        assertEqualInt(1, archive_entry_uid(ae));
 
131
                        assertEqualInt(2, archive_entry_gid(ae));
 
132
                } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) {
 
133
                        /* A symlink to the regular file. */
 
134
                        assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
 
135
                        assertEqualString("file", archive_entry_symlink(ae));
 
136
                        assertEqualInt(0, archive_entry_size(ae));
 
137
                        assertEqualInt(172802, archive_entry_mtime(ae));
 
138
                        assertEqualInt(172802, archive_entry_atime(ae));
 
139
                        assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
 
140
                        assertEqualInt(1, archive_entry_uid(ae));
 
141
                        assertEqualInt(2, archive_entry_gid(ae));
 
142
                } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) {
 
143
                        /* A symlink to /tmp/ (an absolute path) */
 
144
                        assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
 
145
                        assertEqualString("/tmp/", archive_entry_symlink(ae));
 
146
                        assertEqualInt(0, archive_entry_size(ae));
 
147
                        assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
 
148
                        assertEqualInt(1, archive_entry_uid(ae));
 
149
                        assertEqualInt(2, archive_entry_gid(ae));
 
150
                } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) {
 
151
                        /* A symlink to /tmp/../ (with a ".." component) */
 
152
                        assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
 
153
                        assertEqualString("/tmp/../", archive_entry_symlink(ae));
 
154
                        assertEqualInt(0, archive_entry_size(ae));
 
155
                        assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
 
156
                        assertEqualInt(1, archive_entry_uid(ae));
 
157
                        assertEqualInt(2, archive_entry_gid(ae));
 
158
                } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) {
 
159
                        /* A symlink to a path with ".." and "." components */
 
160
                        assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
 
161
                        assertEqualString(".././../tmp/",
 
162
                            archive_entry_symlink(ae));
 
163
                        assertEqualInt(0, archive_entry_size(ae));
 
164
                        assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
 
165
                        assertEqualInt(1, archive_entry_uid(ae));
 
166
                        assertEqualInt(2, archive_entry_gid(ae));
 
167
                } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) {
 
168
                        /* A symlink to the regular file with "/" components. */
 
169
                        assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
 
170
                        assertEqualString(".///file", archive_entry_symlink(ae));
 
171
                        assertEqualInt(0, archive_entry_size(ae));
 
172
                        assertEqualInt(172802, archive_entry_mtime(ae));
 
173
                        assertEqualInt(172802, archive_entry_atime(ae));
 
174
                        assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
 
175
                        assertEqualInt(1, archive_entry_uid(ae));
 
176
                        assertEqualInt(2, archive_entry_gid(ae));
 
177
                } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) {
 
178
                        /* A symlink to /tmp//../
 
179
                         * (with "/" and ".." components) */
 
180
                        assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
 
181
                        assertEqualString("/tmp//../", archive_entry_symlink(ae));
 
182
                        assertEqualInt(0, archive_entry_size(ae));
 
183
                        assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
 
184
                        assertEqualInt(1, archive_entry_uid(ae));
 
185
                        assertEqualInt(2, archive_entry_gid(ae));
 
186
                } else {
 
187
                        failure("Saw a file that shouldn't have been there");
 
188
                        assertEqualString(archive_entry_pathname(ae), "");
 
189
                }
 
190
        }
 
191
 
 
192
        /* End of archive. */
 
193
        assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
 
194
 
 
195
        /* Verify archive format. */
 
196
        assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS);
 
197
        assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
 
198
 
 
199
        /* Close the archive. */
 
200
        assertEqualInt(0, archive_read_close(a));
 
201
        assertEqualInt(0, archive_read_finish(a));
 
202
}
 
203
 
 
204