~gl-az/percona-xtrabackup/2.1-io-block-size

« back to all changes in this revision

Viewing changes to src/libarchive/libarchive/test/test_extattr_freebsd.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-2009 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_extattr_freebsd.c 201247 2009-12-30 05:59:21Z kientzle $");
 
27
 
 
28
#if defined(__FreeBSD__) && __FreeBSD__ > 4
 
29
#include <sys/extattr.h>
 
30
#endif
 
31
 
 
32
/*
 
33
 * Verify extended attribute restore-to-disk.  This test is FreeBSD-specific.
 
34
 */
 
35
 
 
36
DEFINE_TEST(test_extattr_freebsd)
 
37
{
 
38
#if !defined(__FreeBSD__)
 
39
        skipping("FreeBSD-specific extattr restore test");
 
40
#elif __FreeBSD__ < 5
 
41
        skipping("extattr restore supported only on FreeBSD 5.0 and later");
 
42
#else
 
43
        char buff[64];
 
44
        const char *xname;
 
45
        const void *xval;
 
46
        size_t xsize;
 
47
        struct stat st;
 
48
        struct archive *a;
 
49
        struct archive_entry *ae;
 
50
        int n, fd;
 
51
        int extattr_privilege_bug = 0;
 
52
 
 
53
        /*
 
54
         * First, do a quick manual set/read of an extended attribute
 
55
         * to verify that the local filesystem does support it.  If it
 
56
         * doesn't, we'll simply skip the remaining tests.
 
57
         */
 
58
        /* Create a test file and try to set an ACL on it. */
 
59
        fd = open("pretest", O_RDWR | O_CREAT, 0777);
 
60
        failure("Could not create test file?!");
 
61
        if (!assert(fd >= 0))
 
62
                return;
 
63
 
 
64
        errno = 0;
 
65
        n = extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, "testattr", "1234", 4);
 
66
        if (n != 4 && errno == EOPNOTSUPP) {
 
67
                close(fd);
 
68
                skipping("extattr tests require that extattr support be enabled on the filesystem");
 
69
                return;
 
70
        }
 
71
        failure("extattr_set_fd(): errno=%d (%s)", errno, strerror(errno));
 
72
        assertEqualInt(4, n);
 
73
        close(fd);
 
74
 
 
75
        /*
 
76
         * Repeat the above, but with file permissions set to 0000.
 
77
         * This should work (extattr_set_fd() should follow fd
 
78
         * permissions, not file permissions), but is known broken on
 
79
         * some versions of FreeBSD.
 
80
         */
 
81
        fd = open("pretest2", O_RDWR | O_CREAT, 00000);
 
82
        failure("Could not create test file?!");
 
83
        if (!assert(fd >= 0))
 
84
                return;
 
85
 
 
86
        n = extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, "testattr", "1234", 4);
 
87
        if (n != 4) {
 
88
                skipping("Restoring xattr to an unwritable file seems to be broken on this platform");
 
89
                extattr_privilege_bug = 1;
 
90
        }
 
91
        close(fd);
 
92
 
 
93
        /* Create a write-to-disk object. */
 
94
        assert(NULL != (a = archive_write_disk_new()));
 
95
        archive_write_disk_set_options(a,
 
96
            ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_XATTR);
 
97
 
 
98
        /* Populate an archive entry with an extended attribute. */
 
99
        ae = archive_entry_new();
 
100
        assert(ae != NULL);
 
101
        archive_entry_set_pathname(ae, "test0");
 
102
        archive_entry_set_mtime(ae, 123456, 7890);
 
103
        archive_entry_set_size(ae, 0);
 
104
        archive_entry_set_mode(ae, 0755);
 
105
        archive_entry_xattr_add_entry(ae, "user.foo", "12345", 5);
 
106
        assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
 
107
        archive_entry_free(ae);
 
108
 
 
109
        /* Another entry; similar but with mode = 0. */
 
110
        ae = archive_entry_new();
 
111
        assert(ae != NULL);
 
112
        archive_entry_set_pathname(ae, "test1");
 
113
        archive_entry_set_mtime(ae, 12345678, 7890);
 
114
        archive_entry_set_size(ae, 0);
 
115
        archive_entry_set_mode(ae, 0);
 
116
        archive_entry_xattr_add_entry(ae, "user.bar", "123456", 6);
 
117
        assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
 
118
        archive_entry_free(ae);
 
119
 
 
120
        /* Close the archive. */
 
121
        if (extattr_privilege_bug)
 
122
                /* If the bug is here, write_close will return warning. */
 
123
                assertEqualIntA(a, ARCHIVE_WARN, archive_write_close(a));
 
124
        else
 
125
                assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
 
126
        assertEqualInt(ARCHIVE_OK, archive_write_finish(a));
 
127
 
 
128
        /* Verify the data on disk. */
 
129
        assertEqualInt(0, stat("test0", &st));
 
130
        assertEqualInt(st.st_mtime, 123456);
 
131
        /* Verify extattr */
 
132
        n = extattr_get_file("test0", EXTATTR_NAMESPACE_USER,
 
133
            "foo", buff, sizeof(buff));
 
134
        if (assertEqualInt(n, 5)) {
 
135
                buff[n] = '\0';
 
136
                assertEqualString(buff, "12345");
 
137
        }
 
138
 
 
139
        /* Verify the data on disk. */
 
140
        assertEqualInt(0, stat("test1", &st));
 
141
        assertEqualInt(st.st_mtime, 12345678);
 
142
        /* Verify extattr */
 
143
        n = extattr_get_file("test1", EXTATTR_NAMESPACE_USER,
 
144
            "bar", buff, sizeof(buff));
 
145
        if (extattr_privilege_bug) {
 
146
                /* If we have the bug, the extattr won't have been written. */
 
147
                assertEqualInt(n, -1);
 
148
        } else {
 
149
                if (assertEqualInt(n, 6)) {
 
150
                        buff[n] = '\0';
 
151
                        assertEqualString(buff, "123456");
 
152
                }
 
153
        }
 
154
 
 
155
        /* Use libarchive APIs to read the file back into an entry and
 
156
         * verify that the extattr was read correctly. */
 
157
        assert((a = archive_read_disk_new()) != NULL);
 
158
        assert((ae = archive_entry_new()) != NULL);
 
159
        archive_entry_set_pathname(ae, "test0");
 
160
        assertEqualInt(ARCHIVE_OK,
 
161
            archive_read_disk_entry_from_file(a, ae, -1, NULL));
 
162
        assertEqualInt(1, archive_entry_xattr_reset(ae));
 
163
        assertEqualInt(ARCHIVE_OK,
 
164
            archive_entry_xattr_next(ae, &xname, &xval, &xsize));
 
165
        assertEqualString(xname, "user.foo");
 
166
        assertEqualInt(xsize, 5);
 
167
        assertEqualMem(xval, "12345", xsize);
 
168
        assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
 
169
        assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
 
170
        archive_entry_free(ae);
 
171
#endif
 
172
}