~stewart/percona-xtrabackup/bug1213036

« back to all changes in this revision

Viewing changes to src/quicklz/quicklz.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
#ifndef QLZ_HEADER
 
2
#define QLZ_HEADER
 
3
 
 
4
// Fast data compression library
 
5
// Copyright (C) 2006-2011 Lasse Mikkel Reinhold
 
6
// lar@quicklz.com
 
7
//
 
8
// QuickLZ can be used for free under the GPL 1, 2 or 3 license (where anything 
 
9
// released into public must be open source) or under a commercial license if such 
 
10
// has been acquired (see http://www.quicklz.com/order.html). The commercial license 
 
11
// does not cover derived or ported versions created by third parties under GPL.
 
12
 
 
13
// You can edit following user settings. Data must be decompressed with the same 
 
14
// setting of QLZ_COMPRESSION_LEVEL and QLZ_STREAMING_BUFFER as it was compressed
 
15
// (see manual). If QLZ_STREAMING_BUFFER > 0, scratch buffers must be initially
 
16
// zeroed out (see manual). First #ifndef makes it possible to define settings from 
 
17
// the outside like the compiler command line.
 
18
 
 
19
// 1.5.0 final
 
20
 
 
21
#ifndef QLZ_COMPRESSION_LEVEL
 
22
        #define QLZ_COMPRESSION_LEVEL 1
 
23
        //#define QLZ_COMPRESSION_LEVEL 2
 
24
        //#define QLZ_COMPRESSION_LEVEL 3
 
25
 
 
26
        #define QLZ_STREAMING_BUFFER 0
 
27
        //#define QLZ_STREAMING_BUFFER 100000
 
28
        //#define QLZ_STREAMING_BUFFER 1000000
 
29
 
 
30
        //#define QLZ_MEMORY_SAFE
 
31
#endif
 
32
 
 
33
#define QLZ_VERSION_MAJOR 1
 
34
#define QLZ_VERSION_MINOR 5
 
35
#define QLZ_VERSION_REVISION 0
 
36
 
 
37
// Using size_t, memset() and memcpy()
 
38
#include <string.h>
 
39
 
 
40
// Verify compression level
 
41
#if QLZ_COMPRESSION_LEVEL != 1 && QLZ_COMPRESSION_LEVEL != 2 && QLZ_COMPRESSION_LEVEL != 3
 
42
#error QLZ_COMPRESSION_LEVEL must be 1, 2 or 3
 
43
#endif
 
44
 
 
45
typedef unsigned int ui32;
 
46
typedef unsigned short int ui16;
 
47
 
 
48
// Decrease QLZ_POINTERS for level 3 to increase compression speed. Do not touch any other values!
 
49
#if QLZ_COMPRESSION_LEVEL == 1
 
50
#define QLZ_POINTERS 1
 
51
#define QLZ_HASH_VALUES 4096
 
52
#elif QLZ_COMPRESSION_LEVEL == 2
 
53
#define QLZ_POINTERS 4
 
54
#define QLZ_HASH_VALUES 2048
 
55
#elif QLZ_COMPRESSION_LEVEL == 3
 
56
#define QLZ_POINTERS 16
 
57
#define QLZ_HASH_VALUES 4096
 
58
#endif
 
59
 
 
60
// Detect if pointer size is 64-bit. It's not fatal if some 64-bit target is not detected because this is only for adding an optional 64-bit optimization.
 
61
#if defined _LP64 || defined __LP64__ || defined __64BIT__ || _ADDR64 || defined _WIN64 || defined __arch64__ || __WORDSIZE == 64 || (defined __sparc && defined __sparcv9) || defined __x86_64 || defined __amd64 || defined __x86_64__ || defined _M_X64 || defined _M_IA64 || defined __ia64 || defined __IA64__
 
62
        #define QLZ_PTR_64
 
63
#endif
 
64
 
 
65
// hash entry
 
66
typedef struct 
 
67
{
 
68
#if QLZ_COMPRESSION_LEVEL == 1
 
69
        ui32 cache;
 
70
#if defined QLZ_PTR_64 && QLZ_STREAMING_BUFFER == 0
 
71
        unsigned int offset;
 
72
#else
 
73
        const unsigned char *offset;
 
74
#endif
 
75
#else
 
76
        const unsigned char *offset[QLZ_POINTERS];
 
77
#endif
 
78
 
 
79
} qlz_hash_compress;
 
80
 
 
81
typedef struct 
 
82
{
 
83
#if QLZ_COMPRESSION_LEVEL == 1
 
84
        const unsigned char *offset;
 
85
#else
 
86
        const unsigned char *offset[QLZ_POINTERS];
 
87
#endif
 
88
} qlz_hash_decompress;
 
89
 
 
90
 
 
91
// states
 
92
typedef struct
 
93
{
 
94
        #if QLZ_STREAMING_BUFFER > 0
 
95
                unsigned char stream_buffer[QLZ_STREAMING_BUFFER];
 
96
        #endif
 
97
        size_t stream_counter;
 
98
        qlz_hash_compress hash[QLZ_HASH_VALUES];
 
99
        unsigned char hash_counter[QLZ_HASH_VALUES];
 
100
} qlz_state_compress;
 
101
 
 
102
 
 
103
#if QLZ_COMPRESSION_LEVEL == 1 || QLZ_COMPRESSION_LEVEL == 2
 
104
        typedef struct
 
105
        {
 
106
#if QLZ_STREAMING_BUFFER > 0
 
107
                unsigned char stream_buffer[QLZ_STREAMING_BUFFER];
 
108
#endif
 
109
                qlz_hash_decompress hash[QLZ_HASH_VALUES];
 
110
                unsigned char hash_counter[QLZ_HASH_VALUES];
 
111
                size_t stream_counter;
 
112
        } qlz_state_decompress;
 
113
#elif QLZ_COMPRESSION_LEVEL == 3
 
114
        typedef struct
 
115
        {
 
116
#if QLZ_STREAMING_BUFFER > 0
 
117
                unsigned char stream_buffer[QLZ_STREAMING_BUFFER];
 
118
#endif
 
119
#if QLZ_COMPRESSION_LEVEL <= 2
 
120
                qlz_hash_decompress hash[QLZ_HASH_VALUES];
 
121
#endif
 
122
                size_t stream_counter;
 
123
        } qlz_state_decompress;
 
124
#endif
 
125
 
 
126
 
 
127
#if defined (__cplusplus)
 
128
extern "C" {
 
129
#endif
 
130
 
 
131
// Public functions of QuickLZ
 
132
size_t qlz_size_decompressed(const char *source);
 
133
size_t qlz_size_compressed(const char *source);
 
134
size_t qlz_compress(const void *source, char *destination, size_t size, qlz_state_compress *state);
 
135
size_t qlz_decompress(const char *source, void *destination, qlz_state_decompress *state);
 
136
int qlz_get_setting(int setting);
 
137
 
 
138
#if defined (__cplusplus)
 
139
}
 
140
#endif
 
141
 
 
142
#endif
 
143