~akopytov/percona-xtrabackup/bug1166888-2.1

« back to all changes in this revision

Viewing changes to src/libarchive/libarchive/test/test_read_uu.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_uu.c 201248 2009-12-30 06:12:03Z kientzle $");
 
28
 
 
29
static const char archive[] = {
 
30
"begin 644 test_read_uu.Z\n"
 
31
"M'YV0+@`('$BPH,&#\"!,J7,BP(4(8$&_4J`$\"`,08$F%4O)AQ(\\2/(#7&@#%C\n"
 
32
"M!@T8-##.L`$\"QL@:-F(``%'#H<V;.'/J!%!G#ITP<BS\"H).FS<Z$1(T>/1A2\n"
 
33
"IHU\"0%9=*G4JUJM6K6+-JW<JUJ]>O8,.*'4NVK-FS:-.J7<NVK=NW9P$`\n"
 
34
"`\n"
 
35
"end\n"
 
36
};
 
37
 
 
38
static const char archive64[] = {
 
39
"begin-base64 644 test_read_uu.Z\n"
 
40
"H52QLgAIHEiwoMGDCBMqXMiwIUIYEG/UqAECAMQYEmFUvJhxI8SPIDXGgDFjBg0YNDDOsAECxsga\n"
 
41
"NmIAAFHDoc2bOHPqBFBnDp0wcizCoJOmzc6ERI0ePRhSo1CQFZdKnUq1qtWrWLNq3cq1q9evYMOK\n"
 
42
"HUu2rNmzaNOqXcu2rdu3ZwE=\n"
 
43
"====\n"
 
44
};
 
45
 
 
46
static const char extradata[] = {
 
47
"From uudecode@libarchive Mon Jun  2 03:03:31 2008\n"
 
48
"Return-Path: <uudecode@libarchive>\n"
 
49
"Received: from libarchive (localhost [127.0.0.1])\n"
 
50
"        by libarchive (8.14.2/8.14.2) with ESMTP id m5233UT1006448\n"
 
51
"        for <uudecode@libarchive>; Mon, 2 Jun 2008 03:03:31 GMT\n"
 
52
"        (envelope-from uudecode@libarchive)\n"
 
53
"Received: (from uudecode@localhost)\n"
 
54
"        by libarchive (8.14.2/8.14.2/Submit) id m5233U3e006406\n"
 
55
"        for uudecode; Mon, 2 Jun 2008 03:03:30 GMT\n"
 
56
"        (envelope-from root)\n"
 
57
"Date: Mon, 2 Jun 2008 03:03:30 GMT\n"
 
58
"From: Libarchive Test <uudecode@libarchive>\n"
 
59
"Message-Id: <200806020303.m5233U3e006406@libarchive>\n"
 
60
"To: uudecode@libarchive\n"
 
61
"Subject: Libarchive uudecode test\n"
 
62
"\n"
 
63
"* Redistribution and use in source and binary forms, with or without\n"
 
64
"* modification, are permitted provided that the following conditions\n"
 
65
"* are met:\n"
 
66
"\n"
 
67
"01234567890abcdeghijklmnopqrstuvwxyz\n"
 
68
"01234567890ABCEFGHIJKLMNOPQRSTUVWXYZ\n"
 
69
"\n"
 
70
};
 
71
 
 
72
static void
 
73
test_read_uu_sub(const char *uudata, size_t uusize)
 
74
{
 
75
        struct archive_entry *ae;
 
76
        struct archive *a;
 
77
        char *buff;
 
78
        int extra;
 
79
 
 
80
        assert(NULL != (buff = malloc(uusize + 64 * 1024)));
 
81
        if (buff == NULL)
 
82
                return;
 
83
        for (extra = 0; extra <= 64; extra = extra==0?1:extra*2) {
 
84
                size_t size = extra * 1024;
 
85
                char *p = buff;
 
86
 
 
87
                /* Add extra text size of which is from 1K bytes to
 
88
                 * 64Kbytes before uuencoded data. */
 
89
                while (size) {
 
90
                        if (size > sizeof(extradata)-1) {
 
91
                                memcpy(p, extradata, sizeof(extradata)-1);
 
92
                                p += sizeof(extradata)-1;
 
93
                                size -= sizeof(extradata)-1;
 
94
                        } else {
 
95
                                memcpy(p, extradata, size-1);
 
96
                                p += size-1;
 
97
                                *p++ = '\n';/* the last of extra text must have
 
98
                                             * '\n' character. */
 
99
                                break;
 
100
                        }
 
101
                }
 
102
                memcpy(p, uudata, uusize);
 
103
                size = extra * 1024 + uusize;
 
104
 
 
105
                assert((a = archive_read_new()) != NULL);
 
106
                assertEqualIntA(a, ARCHIVE_OK,
 
107
                    archive_read_support_compression_all(a));
 
108
                assertEqualIntA(a, ARCHIVE_OK,
 
109
                    archive_read_support_format_all(a));
 
110
                assertEqualIntA(a, ARCHIVE_OK,
 
111
                    read_open_memory(a, buff, size, 2));
 
112
                assertEqualIntA(a, ARCHIVE_OK,
 
113
                    archive_read_next_header(a, &ae));
 
114
                failure("archive_compression_name(a)=\"%s\"",
 
115
                    archive_compression_name(a));
 
116
                assertEqualInt(archive_compression(a),
 
117
                    ARCHIVE_COMPRESSION_COMPRESS);
 
118
                failure("archive_format_name(a)=\"%s\"",
 
119
                    archive_format_name(a));
 
120
                assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
 
121
                assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
 
122
                assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
 
123
        }
 
124
        free(buff);
 
125
}
 
126
 
 
127
DEFINE_TEST(test_read_uu)
 
128
{
 
129
        /* Read the traditional uuencoded data. */
 
130
        test_read_uu_sub(archive, sizeof(archive)-1);
 
131
        /* Read the Base64 uuencoded data. */
 
132
        test_read_uu_sub(archive64, sizeof(archive64)-1);
 
133
}
 
134