~akopytov/percona-xtrabackup/bug1166888-2.0

« back to all changes in this revision

Viewing changes to src/libarchive/libarchive/test/test_compat_lzma.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) 2009 Michihiro NAKAJIMA
 
3
 * Copyright (c) 2003-2008 Tim Kientzle
 
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_compat_lzma.c 201247 2009-12-30 05:59:21Z kientzle $");
 
28
 
 
29
/*
 
30
Execute the following to rebuild the data for this program:
 
31
   tail -n +33 test_compat_lzma.c | /bin/sh
 
32
 
 
33
# Use lzma command of XZ Utils.
 
34
name=test_compat_lzma_1
 
35
zcmd=lzma
 
36
zsuffix=lzma
 
37
ztar_suffix=tlz
 
38
dir="$name`date +%Y%m%d%H%M%S`.$USER"
 
39
mktarfile()
 
40
{
 
41
mkdir $dir
 
42
echo "f1" > $dir/f1
 
43
echo "f2" > $dir/f2
 
44
echo "f3" > $dir/f3
 
45
mkdir $dir/d1
 
46
echo "f1" > $dir/d1/f1
 
47
echo "f2" > $dir/d1/f2
 
48
echo "f3" > $dir/d1/f3
 
49
(cd $dir; tar cf ../$name.tar f1 f2 f3 d1/f1 d1/f2 d1/f3)
 
50
rm -r $dir
 
51
}
 
52
mktarfile
 
53
$zcmd $name.tar
 
54
mv $name.tar.$zsuffix $name.$ztar_suffix
 
55
echo "This is unrelated junk data at the end of the file" >> $name.$ztar_suffix
 
56
uuencode $name.$ztar_suffix $name.$ztar_suffix > $name.$ztar_suffix.uu
 
57
rm -f $name.$ztar_suffix
 
58
#
 
59
# Use option -e
 
60
#
 
61
name=test_compat_lzma_2
 
62
dir="$name`date +%Y%m%d%H%M%S`.$USER"
 
63
mktarfile
 
64
$zcmd -e $name.tar
 
65
mv $name.tar.$zsuffix $name.$ztar_suffix
 
66
uuencode $name.$ztar_suffix $name.$ztar_suffix > $name.$ztar_suffix.uu
 
67
rm -f $name.$ztar_suffix
 
68
#
 
69
# Use lzma command of LZMA SDK with option -d12.
 
70
#
 
71
name=test_compat_lzma_3
 
72
zcmd=lzmasdk    # Change this path to use lzma of LZMA SDK.
 
73
dir="$name`date +%Y%m%d%H%M%S`.$USER"
 
74
mktarfile
 
75
$zcmd e -d12 $name.tar $name.$ztar_suffix
 
76
rm -f $name.tar
 
77
uuencode $name.$ztar_suffix $name.$ztar_suffix > $name.$ztar_suffix.uu
 
78
rm -f $name.$ztar_suffix
 
79
 
 
80
exit 0
 
81
*/
 
82
 
 
83
/*
 
84
 * Verify our ability to read sample files compatibly with unlzma.
 
85
 *
 
86
 * In particular:
 
87
 *  * unlzma will read multiple lzma streams, concatenating the output
 
88
 *  * unlzma will read lzma streams which is made by lzma with option -e,
 
89
 *    concatenating the output
 
90
 *
 
91
 * Verify our ability to read sample files compatibly with lzma of
 
92
 * LZMA SDK.
 
93
 *  * lzma will read lzma streams which is made by lzma with option -d12,
 
94
 *    concatenating the output
 
95
 */
 
96
 
 
97
/*
 
98
 * All of the sample files have the same contents; they're just
 
99
 * compressed in different ways.
 
100
 */
 
101
static void
 
102
compat_lzma(const char *name)
 
103
{
 
104
        const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL };
 
105
        struct archive_entry *ae;
 
106
        struct archive *a;
 
107
        int i, r;
 
108
 
 
109
        assert((a = archive_read_new()) != NULL);
 
110
        assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a));
 
111
        r = archive_read_support_compression_lzma(a);
 
112
        if (r == ARCHIVE_WARN) {
 
113
                skipping("lzma reading not fully supported on this platform");
 
114
                assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
 
115
                return;
 
116
        }
 
117
        assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
 
118
        extract_reference_file(name);
 
119
        assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2));
 
120
 
 
121
        /* Read entries, match up names with list above. */
 
122
        for (i = 0; i < 6; ++i) {
 
123
                failure("Could not read file %d (%s) from %s", i, n[i], name);
 
124
                assertEqualIntA(a, ARCHIVE_OK,
 
125
                    archive_read_next_header(a, &ae));
 
126
                assertEqualString(n[i], archive_entry_pathname(ae));
 
127
        }
 
128
 
 
129
        /* Verify the end-of-archive. */
 
130
        assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
 
131
 
 
132
        /* Verify that the format detection worked. */
 
133
        assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_LZMA);
 
134
        assertEqualString(archive_compression_name(a), "lzma");
 
135
        assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
 
136
 
 
137
        assertEqualInt(ARCHIVE_OK, archive_read_close(a));
 
138
        assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
 
139
}
 
140
 
 
141
 
 
142
DEFINE_TEST(test_compat_lzma)
 
143
{
 
144
        /* This sample has been added junk datas to its tail. */
 
145
        compat_lzma("test_compat_lzma_1.tlz");
 
146
        /* This sample has been made by lzma with option -e,
 
147
         * the first byte of which is 0x5e.
 
148
         * Not supported in libarchive 2.7.* and earlier */
 
149
        compat_lzma("test_compat_lzma_2.tlz");
 
150
        /* This sample has been made by lzma of LZMA SDK with
 
151
         * option -d12, second byte and third byte of which is
 
152
         * not zero.
 
153
         * Not supported in libarchive 2.7.* and earlier */
 
154
        compat_lzma("test_compat_lzma_3.tlz");
 
155
}