~akopytov/percona-xtrabackup/bug1166888-2.1

« back to all changes in this revision

Viewing changes to src/libarchive/libarchive/archive_endian.h

  • 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) 2002 Thomas Moestl <tmm@FreeBSD.org>
 
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 AND CONTRIBUTORS ``AS IS'' AND
 
15
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
17
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 
18
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
19
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
20
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
21
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
22
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
23
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
24
 * SUCH DAMAGE.
 
25
 *
 
26
 * $FreeBSD: head/lib/libarchive/archive_endian.h 201085 2009-12-28 02:17:15Z kientzle $
 
27
 *
 
28
 * Borrowed from FreeBSD's <sys/endian.h>
 
29
 */
 
30
 
 
31
#ifndef __LIBARCHIVE_BUILD
 
32
#error This header is only to be used internally to libarchive.
 
33
#endif
 
34
 
 
35
/* Note:  This is a purely internal header! */
 
36
/* Do not use this outside of libarchive internal code! */
 
37
 
 
38
#ifndef ARCHIVE_ENDIAN_H_INCLUDED
 
39
#define ARCHIVE_ENDIAN_H_INCLUDED
 
40
 
 
41
 
 
42
/*
 
43
 * Disabling inline keyword for compilers known to choke on it:
 
44
 * - Watcom C++ in C code.  (For any version?)
 
45
 * - SGI MIPSpro
 
46
 * - Microsoft Visual C++ 6.0 (supposedly newer versions too)
 
47
 */
 
48
#if defined(__WATCOMC__) || defined(__sgi) || defined(__hpux) || defined(__BORLANDC__)
 
49
#define inline
 
50
#elif defined(_MSC_VER)
 
51
#define inline __inline
 
52
#endif
 
53
 
 
54
/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */
 
55
 
 
56
static inline uint16_t
 
57
archive_be16dec(const void *pp)
 
58
{
 
59
        unsigned char const *p = (unsigned char const *)pp;
 
60
 
 
61
        return ((p[0] << 8) | p[1]);
 
62
}
 
63
 
 
64
static inline uint32_t
 
65
archive_be32dec(const void *pp)
 
66
{
 
67
        unsigned char const *p = (unsigned char const *)pp;
 
68
 
 
69
        return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
 
70
}
 
71
 
 
72
static inline uint64_t
 
73
archive_be64dec(const void *pp)
 
74
{
 
75
        unsigned char const *p = (unsigned char const *)pp;
 
76
 
 
77
        return (((uint64_t)archive_be32dec(p) << 32) | archive_be32dec(p + 4));
 
78
}
 
79
 
 
80
static inline uint16_t
 
81
archive_le16dec(const void *pp)
 
82
{
 
83
        unsigned char const *p = (unsigned char const *)pp;
 
84
 
 
85
        return ((p[1] << 8) | p[0]);
 
86
}
 
87
 
 
88
static inline uint32_t
 
89
archive_le32dec(const void *pp)
 
90
{
 
91
        unsigned char const *p = (unsigned char const *)pp;
 
92
 
 
93
        return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
 
94
}
 
95
 
 
96
static inline uint64_t
 
97
archive_le64dec(const void *pp)
 
98
{
 
99
        unsigned char const *p = (unsigned char const *)pp;
 
100
 
 
101
        return (((uint64_t)archive_le32dec(p + 4) << 32) | archive_le32dec(p));
 
102
}
 
103
 
 
104
static inline void
 
105
archive_be16enc(void *pp, uint16_t u)
 
106
{
 
107
        unsigned char *p = (unsigned char *)pp;
 
108
 
 
109
        p[0] = (u >> 8) & 0xff;
 
110
        p[1] = u & 0xff;
 
111
}
 
112
 
 
113
static inline void
 
114
archive_be32enc(void *pp, uint32_t u)
 
115
{
 
116
        unsigned char *p = (unsigned char *)pp;
 
117
 
 
118
        p[0] = (u >> 24) & 0xff;
 
119
        p[1] = (u >> 16) & 0xff;
 
120
        p[2] = (u >> 8) & 0xff;
 
121
        p[3] = u & 0xff;
 
122
}
 
123
 
 
124
static inline void
 
125
archive_be64enc(void *pp, uint64_t u)
 
126
{
 
127
        unsigned char *p = (unsigned char *)pp;
 
128
 
 
129
        archive_be32enc(p, u >> 32);
 
130
        archive_be32enc(p + 4, u & 0xffffffff);
 
131
}
 
132
 
 
133
static inline void
 
134
archive_le16enc(void *pp, uint16_t u)
 
135
{
 
136
        unsigned char *p = (unsigned char *)pp;
 
137
 
 
138
        p[0] = u & 0xff;
 
139
        p[1] = (u >> 8) & 0xff;
 
140
}
 
141
 
 
142
static inline void
 
143
archive_le32enc(void *pp, uint32_t u)
 
144
{
 
145
        unsigned char *p = (unsigned char *)pp;
 
146
 
 
147
        p[0] = u & 0xff;
 
148
        p[1] = (u >> 8) & 0xff;
 
149
        p[2] = (u >> 16) & 0xff;
 
150
        p[3] = (u >> 24) & 0xff;
 
151
}
 
152
 
 
153
static inline void
 
154
archive_le64enc(void *pp, uint64_t u)
 
155
{
 
156
        unsigned char *p = (unsigned char *)pp;
 
157
 
 
158
        archive_le32enc(p, u & 0xffffffff);
 
159
        archive_le32enc(p + 4, u >> 32);
 
160
}
 
161
 
 
162
#endif