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

« back to all changes in this revision

Viewing changes to src/libarchive/libarchive/archive_read_private.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) 2003-2007 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
 * $FreeBSD: head/lib/libarchive/archive_read_private.h 201088 2009-12-28 02:18:55Z kientzle $
 
26
 */
 
27
 
 
28
#ifndef __LIBARCHIVE_BUILD
 
29
#error This header is only to be used internally to libarchive.
 
30
#endif
 
31
 
 
32
#ifndef ARCHIVE_READ_PRIVATE_H_INCLUDED
 
33
#define ARCHIVE_READ_PRIVATE_H_INCLUDED
 
34
 
 
35
#include "archive.h"
 
36
#include "archive_string.h"
 
37
#include "archive_private.h"
 
38
 
 
39
struct archive_read;
 
40
struct archive_read_filter_bidder;
 
41
struct archive_read_filter;
 
42
 
 
43
/*
 
44
 * How bidding works for filters:
 
45
 *   * The bid manager reads the first block from the current source.
 
46
 *   * It shows that block to each registered bidder.
 
47
 *   * The bid manager creates a new filter structure for the winning
 
48
 *     bidder and gives the winning bidder a chance to initialize it.
 
49
 *   * The new filter becomes the top filter in the archive_read structure
 
50
 *     and we repeat the process.
 
51
 * This ends only when no bidder provides a non-zero bid.
 
52
 */
 
53
struct archive_read_filter_bidder {
 
54
        /* Configuration data for the bidder. */
 
55
        void *data;
 
56
        /* Taste the upstream filter to see if we handle this. */
 
57
        int (*bid)(struct archive_read_filter_bidder *,
 
58
            struct archive_read_filter *);
 
59
        /* Initialize a newly-created filter. */
 
60
        int (*init)(struct archive_read_filter *);
 
61
        /* Set an option for the filter bidder. */
 
62
        int (*options)(struct archive_read_filter_bidder *,
 
63
            const char *key, const char *value);
 
64
        /* Release the bidder's configuration data. */
 
65
        int (*free)(struct archive_read_filter_bidder *);
 
66
};
 
67
 
 
68
/*
 
69
 * This structure is allocated within the archive_read core
 
70
 * and initialized by archive_read and the init() method of the
 
71
 * corresponding bidder above.
 
72
 */
 
73
struct archive_read_filter {
 
74
        /* Essentially all filters will need these values, so
 
75
         * just declare them here. */
 
76
        struct archive_read_filter_bidder *bidder; /* My bidder. */
 
77
        struct archive_read_filter *upstream; /* Who I read from. */
 
78
        struct archive_read *archive; /* Associated archive. */
 
79
        /* Return next block. */
 
80
        ssize_t (*read)(struct archive_read_filter *, const void **);
 
81
        /* Skip forward this many bytes. */
 
82
        int64_t (*skip)(struct archive_read_filter *self, int64_t request);
 
83
        /* Close (just this filter) and free(self). */
 
84
        int (*close)(struct archive_read_filter *self);
 
85
        /* My private data. */
 
86
        void *data;
 
87
 
 
88
        const char      *name;
 
89
        int              code;
 
90
 
 
91
        /* Used by reblocking logic. */
 
92
        char            *buffer;
 
93
        size_t           buffer_size;
 
94
        char            *next;          /* Current read location. */
 
95
        size_t           avail;         /* Bytes in my buffer. */
 
96
        const void      *client_buff;   /* Client buffer information. */
 
97
        size_t           client_total;
 
98
        const char      *client_next;
 
99
        size_t           client_avail;
 
100
        int64_t          position;
 
101
        char             end_of_file;
 
102
        char             fatal;
 
103
};
 
104
 
 
105
/*
 
106
 * The client looks a lot like a filter, so we just wrap it here.
 
107
 *
 
108
 * TODO: Make archive_read_filter and archive_read_client identical so
 
109
 * that users of the library can easily register their own
 
110
 * transformation filters.  This will probably break the API/ABI and
 
111
 * so should be deferred at least until libarchive 3.0.
 
112
 */
 
113
struct archive_read_client {
 
114
        archive_read_callback   *reader;
 
115
        archive_skip_callback   *skipper;
 
116
        archive_close_callback  *closer;
 
117
};
 
118
 
 
119
struct archive_read {
 
120
        struct archive  archive;
 
121
 
 
122
        struct archive_entry    *entry;
 
123
 
 
124
        /* Dev/ino of the archive being read/written. */
 
125
        dev_t             skip_file_dev;
 
126
        ino_t             skip_file_ino;
 
127
 
 
128
        /*
 
129
         * Used by archive_read_data() to track blocks and copy
 
130
         * data to client buffers, filling gaps with zero bytes.
 
131
         */
 
132
        const char       *read_data_block;
 
133
        off_t             read_data_offset;
 
134
        off_t             read_data_output_offset;
 
135
        size_t            read_data_remaining;
 
136
 
 
137
        /* Callbacks to open/read/write/close client archive stream. */
 
138
        struct archive_read_client client;
 
139
 
 
140
        /* Registered filter bidders. */
 
141
        struct archive_read_filter_bidder bidders[8];
 
142
 
 
143
        /* Last filter in chain */
 
144
        struct archive_read_filter *filter;
 
145
 
 
146
        /* File offset of beginning of most recently-read header. */
 
147
        off_t             header_position;
 
148
 
 
149
        /*
 
150
         * Format detection is mostly the same as compression
 
151
         * detection, with one significant difference: The bidders
 
152
         * use the read_ahead calls above to examine the stream rather
 
153
         * than having the supervisor hand them a block of data to
 
154
         * examine.
 
155
         */
 
156
 
 
157
        struct archive_format_descriptor {
 
158
                void     *data;
 
159
                const char *name;
 
160
                int     (*bid)(struct archive_read *);
 
161
                int     (*options)(struct archive_read *, const char *key,
 
162
                    const char *value);
 
163
                int     (*read_header)(struct archive_read *, struct archive_entry *);
 
164
                int     (*read_data)(struct archive_read *, const void **, size_t *, off_t *);
 
165
                int     (*read_data_skip)(struct archive_read *);
 
166
                int     (*cleanup)(struct archive_read *);
 
167
        }       formats[9];
 
168
        struct archive_format_descriptor        *format; /* Active format. */
 
169
 
 
170
        /*
 
171
         * Various information needed by archive_extract.
 
172
         */
 
173
        struct extract           *extract;
 
174
        int                     (*cleanup_archive_extract)(struct archive_read *);
 
175
};
 
176
 
 
177
int     __archive_read_register_format(struct archive_read *a,
 
178
            void *format_data,
 
179
            const char *name,
 
180
            int (*bid)(struct archive_read *),
 
181
            int (*options)(struct archive_read *, const char *, const char *),
 
182
            int (*read_header)(struct archive_read *, struct archive_entry *),
 
183
            int (*read_data)(struct archive_read *, const void **, size_t *, off_t *),
 
184
            int (*read_data_skip)(struct archive_read *),
 
185
            int (*cleanup)(struct archive_read *));
 
186
 
 
187
struct archive_read_filter_bidder
 
188
        *__archive_read_get_bidder(struct archive_read *a);
 
189
 
 
190
const void *__archive_read_ahead(struct archive_read *, size_t, ssize_t *);
 
191
const void *__archive_read_filter_ahead(struct archive_read_filter *,
 
192
    size_t, ssize_t *);
 
193
ssize_t __archive_read_consume(struct archive_read *, size_t);
 
194
ssize_t __archive_read_filter_consume(struct archive_read_filter *, size_t);
 
195
int64_t __archive_read_skip(struct archive_read *, int64_t);
 
196
int64_t __archive_read_skip_lenient(struct archive_read *, int64_t);
 
197
int64_t __archive_read_filter_skip(struct archive_read_filter *, int64_t);
 
198
int __archive_read_program(struct archive_read_filter *, const char *);
 
199
#endif