~akopytov/percona-xtrabackup/bug1166888-2.0

« back to all changes in this revision

Viewing changes to src/xbstream.h

  • 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) 2011 Percona Inc.
 
3
 
 
4
The xbstream format interface.
 
5
 
 
6
This program is free software; you can redistribute it and/or modify
 
7
it under the terms of the GNU General Public License as published by
 
8
the Free Software Foundation; version 2 of the License.
 
9
 
 
10
This program is distributed in the hope that it will be useful,
 
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
GNU General Public License for more details.
 
14
 
 
15
You should have received a copy of the GNU General Public License
 
16
along with this program; if not, write to the Free Software
 
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
18
 
 
19
*******************************************************/
 
20
 
 
21
#ifndef XBSTREAM_H
 
22
#define XBSTREAM_H
 
23
 
 
24
#include <my_base.h>
 
25
 
 
26
/* Magic value in a chunk header */
 
27
#define XB_STREAM_CHUNK_MAGIC "XBSTCK01"
 
28
 
 
29
/* Chunk flags */
 
30
/* Chunk can be ignored if unknown version/format */
 
31
#define XB_STREAM_FLAG_IGNORABLE 0x01
 
32
 
 
33
typedef struct xb_wstream_struct xb_wstream_t;
 
34
 
 
35
typedef struct xb_wstream_file_struct xb_wstream_file_t;
 
36
 
 
37
/************************************************************************
 
38
Write interface. */
 
39
 
 
40
xb_wstream_t *xb_stream_write_new(void);
 
41
 
 
42
xb_wstream_file_t *xb_stream_write_open(xb_wstream_t *stream, const char *path,
 
43
                                        MY_STAT *mystat);
 
44
 
 
45
int xb_stream_write_data(xb_wstream_file_t *file, const void *buf, size_t len);
 
46
 
 
47
int xb_stream_write_close(xb_wstream_file_t *file);
 
48
 
 
49
int xb_stream_write_done(xb_wstream_t *stream);
 
50
 
 
51
/************************************************************************
 
52
Read interface. */
 
53
 
 
54
typedef enum {
 
55
        XB_STREAM_READ_CHUNK,
 
56
        XB_STREAM_READ_EOF,
 
57
        XB_STREAM_READ_ERROR
 
58
} xb_rstream_result_t;
 
59
 
 
60
typedef enum {
 
61
        XB_CHUNK_TYPE_UNKNOWN = '\0',
 
62
        XB_CHUNK_TYPE_PAYLOAD = 'P',
 
63
        XB_CHUNK_TYPE_EOF = 'E'
 
64
} xb_chunk_type_t;
 
65
 
 
66
typedef struct xb_rstream_struct xb_rstream_t;
 
67
 
 
68
typedef struct {
 
69
        uchar           flags;
 
70
        xb_chunk_type_t type;
 
71
        uint            pathlen;
 
72
        char            path[FN_REFLEN];
 
73
        size_t          length;
 
74
        my_off_t        offset;
 
75
        void            *data;
 
76
        ulong           checksum;
 
77
} xb_rstream_chunk_t;
 
78
 
 
79
xb_rstream_t *xb_stream_read_new(void);
 
80
 
 
81
xb_rstream_result_t xb_stream_read_chunk(xb_rstream_t *stream,
 
82
                                         xb_rstream_chunk_t *chunk);
 
83
 
 
84
int xb_stream_read_done(xb_rstream_t *stream);
 
85
 
 
86
#endif