~akopytov/percona-xtrabackup/bug1166888-2.1

« back to all changes in this revision

Viewing changes to src/libarchive/libarchive/test/test_read_format_isorr_rr_moved.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
 * Copyright (c) 2009 Michihiro NAKAJIMA
 
4
 * All rights reserved.
 
5
 *
 
6
 * Redistribution and use in source and binary forms, with or without
 
7
 * modification, are permitted provided that the following conditions
 
8
 * are met:
 
9
 * 1. Redistributions of source code must retain the above copyright
 
10
 *    notice, this list of conditions and the following disclaimer.
 
11
 * 2. Redistributions in binary form must reproduce the above copyright
 
12
 *    notice, this list of conditions and the following disclaimer in the
 
13
 *    documentation and/or other materials provided with the distribution.
 
14
 *
 
15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 
16
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
17
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 
18
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
 
19
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 
20
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
21
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
22
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
23
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 
24
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
25
 */
 
26
#include "test.h"
 
27
__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_isorr_rr_moved.c 201247 2009-12-30 05:59:21Z kientzle $");
 
28
 
 
29
/*
 
30
Execute the following command to rebuild the data for this program:
 
31
   tail -n +32 test_read_format_isorr_rr_moved.c | /bin/sh
 
32
 
 
33
dirname=/tmp/iso
 
34
rm -rf $dirname
 
35
mkdir -p $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10
 
36
echo "hello" >$dirname/file
 
37
dd if=/dev/zero count=1 bs=12345678 >>$dirname/file
 
38
deepfile=$dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/deep
 
39
echo "hello" >$deepfile
 
40
dd if=/dev/zero count=1 bs=12345678 >>$deepfile
 
41
time="197001020000.01"
 
42
TZ=utc touch -afhm -t $time $deepfile
 
43
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10
 
44
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9
 
45
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8
 
46
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7
 
47
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6
 
48
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5
 
49
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4
 
50
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3
 
51
TZ=utc touch -afhm -t $time $dirname/dir1/dir2
 
52
TZ=utc touch -afhm -t $time $dirname/dir1
 
53
TZ=utc touch -afhm -t $time $dirname/file
 
54
TZ=utc touch -afhm -t $time $dirname
 
55
F=test_read_format_isorr_rockridge_moved.iso.Z
 
56
mkhybrid -R -uid 1 -gid 2 $dirname | compress > $F
 
57
uuencode $F $F > $F.uu
 
58
exit 1
 
59
 */
 
60
 
 
61
DEFINE_TEST(test_read_format_isorr_rr_moved)
 
62
{
 
63
        const char *refname = "test_read_format_iso_rockridge_rr_moved.iso.Z";
 
64
        struct archive_entry *ae;
 
65
        struct archive *a;
 
66
        const void *p;
 
67
        size_t size;
 
68
        off_t offset;
 
69
        int i;
 
70
 
 
71
        extract_reference_file(refname);
 
72
        assert((a = archive_read_new()) != NULL);
 
73
        assertEqualInt(0, archive_read_support_compression_all(a));
 
74
        assertEqualInt(0, archive_read_support_format_all(a));
 
75
        assertEqualInt(ARCHIVE_OK,
 
76
            archive_read_open_filename(a, refname, 10240));
 
77
 
 
78
        /* Retrieve each of the 8 files on the ISO image and
 
79
         * verify that each one is what we expect. */
 
80
        for (i = 0; i < 13; ++i) {
 
81
                assertEqualInt(0, archive_read_next_header(a, &ae));
 
82
 
 
83
                if (strcmp(".", archive_entry_pathname(ae)) == 0) {
 
84
                        /* '.' root directory. */
 
85
                        assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
 
86
                        assertEqualInt(2048, archive_entry_size(ae));
 
87
                        /* Now, we read timestamp recorded by RRIP "TF". */
 
88
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
89
                        assertEqualInt(0, archive_entry_mtime_nsec(ae));
 
90
                        /* Now, we read links recorded by RRIP "PX". */
 
91
                        assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
 
92
                        assertEqualInt(1, archive_entry_uid(ae));
 
93
                        assertEqualIntA(a, ARCHIVE_EOF,
 
94
                            archive_read_data_block(a, &p, &size, &offset));
 
95
                        assertEqualInt((int)size, 0);
 
96
                } else if (strcmp("dir1", archive_entry_pathname(ae)) == 0) {
 
97
                        /* A directory. */
 
98
                        assertEqualString("dir1", archive_entry_pathname(ae));
 
99
                        assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
 
100
                        assertEqualInt(2048, archive_entry_size(ae));
 
101
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
102
                        assertEqualInt(86401, archive_entry_atime(ae));
 
103
                        assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
 
104
                        assertEqualInt(1, archive_entry_uid(ae));
 
105
                        assertEqualInt(2, archive_entry_gid(ae));
 
106
                } else if (strcmp("dir1/dir2",
 
107
                    archive_entry_pathname(ae)) == 0) {
 
108
                        /* A directory. */
 
109
                        assertEqualString("dir1/dir2",
 
110
                            archive_entry_pathname(ae));
 
111
                        assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
 
112
                        assertEqualInt(2048, archive_entry_size(ae));
 
113
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
114
                        assertEqualInt(86401, archive_entry_atime(ae));
 
115
                        assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
 
116
                        assertEqualInt(1, archive_entry_uid(ae));
 
117
                        assertEqualInt(2, archive_entry_gid(ae));
 
118
                } else if (strcmp("dir1/dir2/dir3",
 
119
                    archive_entry_pathname(ae)) == 0) {
 
120
                        /* A directory. */
 
121
                        assertEqualString("dir1/dir2/dir3",
 
122
                            archive_entry_pathname(ae));
 
123
                        assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
 
124
                        assertEqualInt(2048, archive_entry_size(ae));
 
125
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
126
                        assertEqualInt(86401, archive_entry_atime(ae));
 
127
                        assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
 
128
                        assertEqualInt(1, archive_entry_uid(ae));
 
129
                        assertEqualInt(2, archive_entry_gid(ae));
 
130
                } else if (strcmp("dir1/dir2/dir3/dir4",
 
131
                    archive_entry_pathname(ae)) == 0) {
 
132
                        /* A directory. */
 
133
                        assertEqualString("dir1/dir2/dir3/dir4",
 
134
                            archive_entry_pathname(ae));
 
135
                        assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
 
136
                        assertEqualInt(2048, archive_entry_size(ae));
 
137
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
138
                        assertEqualInt(86401, archive_entry_atime(ae));
 
139
                        assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
 
140
                        assertEqualInt(1, archive_entry_uid(ae));
 
141
                        assertEqualInt(2, archive_entry_gid(ae));
 
142
                } else if (strcmp("dir1/dir2/dir3/dir4/dir5",
 
143
                    archive_entry_pathname(ae)) == 0) {
 
144
                        /* A directory. */
 
145
                        assertEqualString("dir1/dir2/dir3/dir4/dir5",
 
146
                            archive_entry_pathname(ae));
 
147
                        assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
 
148
                        assertEqualInt(2048, archive_entry_size(ae));
 
149
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
150
                        assertEqualInt(86401, archive_entry_atime(ae));
 
151
                        assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
 
152
                        assertEqualInt(1, archive_entry_uid(ae));
 
153
                        assertEqualInt(2, archive_entry_gid(ae));
 
154
                } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6",
 
155
                    archive_entry_pathname(ae)) == 0) {
 
156
                        /* A directory. */
 
157
                        assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6",
 
158
                            archive_entry_pathname(ae));
 
159
                        assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
 
160
                        assertEqualInt(2048, archive_entry_size(ae));
 
161
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
162
                        assertEqualInt(86401, archive_entry_atime(ae));
 
163
                        assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
 
164
                        assertEqualInt(1, archive_entry_uid(ae));
 
165
                        assertEqualInt(2, archive_entry_gid(ae));
 
166
                } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7",
 
167
                    archive_entry_pathname(ae)) == 0) {
 
168
                        /* A directory. */
 
169
                        assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7",
 
170
                            archive_entry_pathname(ae));
 
171
                        assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
 
172
                        assertEqualInt(2048, archive_entry_size(ae));
 
173
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
174
                        assertEqualInt(86401, archive_entry_atime(ae));
 
175
                        assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
 
176
                        assertEqualInt(1, archive_entry_uid(ae));
 
177
                        assertEqualInt(2, archive_entry_gid(ae));
 
178
                } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
 
179
                   "/dir8",
 
180
                    archive_entry_pathname(ae)) == 0) {
 
181
                        /* A directory. */
 
182
                        assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
 
183
                            "/dir8",
 
184
                            archive_entry_pathname(ae));
 
185
                        assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
 
186
                        assertEqualInt(2048, archive_entry_size(ae));
 
187
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
188
                        assertEqualInt(86401, archive_entry_atime(ae));
 
189
                        assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
 
190
                        assertEqualInt(1, archive_entry_uid(ae));
 
191
                        assertEqualInt(2, archive_entry_gid(ae));
 
192
                } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
 
193
                   "/dir8/dir9",
 
194
                    archive_entry_pathname(ae)) == 0) {
 
195
                        /* A directory. */
 
196
                        assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
 
197
                            "/dir8/dir9",
 
198
                            archive_entry_pathname(ae));
 
199
                        assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
 
200
                        assertEqualInt(2048, archive_entry_size(ae));
 
201
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
202
                        assertEqualInt(86401, archive_entry_atime(ae));
 
203
                        assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
 
204
                        assertEqualInt(1, archive_entry_uid(ae));
 
205
                        assertEqualInt(2, archive_entry_gid(ae));
 
206
                } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
 
207
                   "/dir8/dir9/dir10",
 
208
                    archive_entry_pathname(ae)) == 0) {
 
209
                        /* A directory. */
 
210
                        assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
 
211
                            "/dir8/dir9/dir10",
 
212
                            archive_entry_pathname(ae));
 
213
                        assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
 
214
                        assertEqualInt(2048, archive_entry_size(ae));
 
215
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
216
                        assertEqualInt(86401, archive_entry_atime(ae));
 
217
                        assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
 
218
                        assertEqualInt(1, archive_entry_uid(ae));
 
219
                        assertEqualInt(2, archive_entry_gid(ae));
 
220
                } else if (strcmp("file", archive_entry_pathname(ae)) == 0) {
 
221
                        /* A regular file. */
 
222
                        assertEqualString("file", archive_entry_pathname(ae));
 
223
                        assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
 
224
                        assertEqualInt(12345684, archive_entry_size(ae));
 
225
                        assertEqualInt(0,
 
226
                            archive_read_data_block(a, &p, &size, &offset));
 
227
                        assertEqualInt(0, offset);
 
228
                        assertEqualMem(p, "hello\n", 6);
 
229
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
230
                        assertEqualInt(86401, archive_entry_atime(ae));
 
231
                        assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
 
232
                        assertEqualInt(1, archive_entry_uid(ae));
 
233
                        assertEqualInt(2, archive_entry_gid(ae));
 
234
                } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
 
235
                    "/dir8/dir9/dir10/deep",
 
236
                    archive_entry_pathname(ae)) == 0) {
 
237
                        /* A regular file. */
 
238
                        assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
 
239
                            "/dir8/dir9/dir10/deep",
 
240
                            archive_entry_pathname(ae));
 
241
                        assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
 
242
                        assertEqualInt(12345684, archive_entry_size(ae));
 
243
                        assertEqualInt(0,
 
244
                            archive_read_data_block(a, &p, &size, &offset));
 
245
                        assertEqualInt(0, offset);
 
246
                        assertEqualMem(p, "hello\n", 6);
 
247
                        assertEqualInt(86401, archive_entry_mtime(ae));
 
248
                        assertEqualInt(86401, archive_entry_atime(ae));
 
249
                        assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
 
250
                        assertEqualInt(1, archive_entry_uid(ae));
 
251
                        assertEqualInt(2, archive_entry_gid(ae));
 
252
                } else {
 
253
                        failure("Saw a file that shouldn't have been there");
 
254
                        assertEqualString(archive_entry_pathname(ae), "");
 
255
                }
 
256
        }
 
257
 
 
258
        /* End of archive. */
 
259
        assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
 
260
 
 
261
        /* Verify archive format. */
 
262
        assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS);
 
263
        assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
 
264
 
 
265
        /* Close the archive. */
 
266
        assertEqualInt(0, archive_read_close(a));
 
267
        assertEqualInt(0, archive_read_finish(a));
 
268
}
 
269
 
 
270