~stewart/percona-xtrabackup/bug1213036

« back to all changes in this revision

Viewing changes to src/libarchive/libarchive/archive_string.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_string.h 201092 2009-12-28 02:26:06Z kientzle $
 
26
 *
 
27
 */
 
28
 
 
29
#ifndef __LIBARCHIVE_BUILD
 
30
#error This header is only to be used internally to libarchive.
 
31
#endif
 
32
 
 
33
#ifndef ARCHIVE_STRING_H_INCLUDED
 
34
#define ARCHIVE_STRING_H_INCLUDED
 
35
 
 
36
#include <stdarg.h>
 
37
#ifdef HAVE_STDLIB_H
 
38
#include <stdlib.h>  /* required for wchar_t on some systems */
 
39
#endif
 
40
#ifdef HAVE_STRING_H
 
41
#include <string.h>
 
42
#endif
 
43
#ifdef HAVE_WCHAR_H
 
44
#include <wchar.h>
 
45
#endif
 
46
 
 
47
/*
 
48
 * Basic resizable/reusable string support a la Java's "StringBuffer."
 
49
 *
 
50
 * Unlike sbuf(9), the buffers here are fully reusable and track the
 
51
 * length throughout.
 
52
 *
 
53
 * Note that all visible symbols here begin with "__archive" as they
 
54
 * are internal symbols not intended for anyone outside of this library
 
55
 * to see or use.
 
56
 */
 
57
 
 
58
struct archive_string {
 
59
        char    *s;  /* Pointer to the storage */
 
60
        size_t   length; /* Length of 's' */
 
61
        size_t   buffer_length; /* Length of malloc-ed storage */
 
62
};
 
63
 
 
64
/* Initialize an archive_string object on the stack or elsewhere. */
 
65
#define archive_string_init(a)  \
 
66
        do { (a)->s = NULL; (a)->length = 0; (a)->buffer_length = 0; } while(0)
 
67
 
 
68
/* Append a C char to an archive_string, resizing as necessary. */
 
69
struct archive_string *
 
70
__archive_strappend_char(struct archive_string *, char);
 
71
#define archive_strappend_char __archive_strappend_char
 
72
 
 
73
/* Convert a wide-char string to UTF-8 and append the result. */
 
74
struct archive_string *
 
75
__archive_strappend_w_utf8(struct archive_string *, const wchar_t *);
 
76
#define archive_strappend_w_utf8        __archive_strappend_w_utf8
 
77
 
 
78
/* Convert a wide-char string to current locale and append the result. */
 
79
/* Returns NULL if conversion fails. */
 
80
struct archive_string *
 
81
__archive_strappend_w_mbs(struct archive_string *, const wchar_t *);
 
82
#define archive_strappend_w_mbs __archive_strappend_w_mbs
 
83
 
 
84
/* Basic append operation. */
 
85
struct archive_string *
 
86
__archive_string_append(struct archive_string *as, const char *p, size_t s);
 
87
 
 
88
/* Copy one archive_string to another */
 
89
void
 
90
__archive_string_copy(struct archive_string *dest, struct archive_string *src);
 
91
#define archive_string_copy(dest, src) \
 
92
        __archive_string_copy(dest, src)
 
93
 
 
94
/* Concatenate one archive_string to another */
 
95
void
 
96
__archive_string_concat(struct archive_string *dest, struct archive_string *src);
 
97
#define archive_string_concat(dest, src) \
 
98
        __archive_string_concat(dest, src)
 
99
 
 
100
/* Ensure that the underlying buffer is at least as large as the request. */
 
101
struct archive_string *
 
102
__archive_string_ensure(struct archive_string *, size_t);
 
103
#define archive_string_ensure __archive_string_ensure
 
104
 
 
105
/* Append C string, which may lack trailing \0. */
 
106
/* The source is declared void * here because this gets used with
 
107
 * "signed char *", "unsigned char *" and "char *" arguments.
 
108
 * Declaring it "char *" as with some of the other functions just
 
109
 * leads to a lot of extra casts. */
 
110
struct archive_string *
 
111
__archive_strncat(struct archive_string *, const void *, size_t);
 
112
#define archive_strncat  __archive_strncat
 
113
 
 
114
/* Append a C string to an archive_string, resizing as necessary. */
 
115
#define archive_strcat(as,p) __archive_string_append((as),(p),strlen(p))
 
116
 
 
117
/* Copy a C string to an archive_string, resizing as necessary. */
 
118
#define archive_strcpy(as,p) \
 
119
        ((as)->length = 0, __archive_string_append((as), (p), p == NULL ? 0 : strlen(p)))
 
120
 
 
121
/* Copy a C string to an archive_string with limit, resizing as necessary. */
 
122
#define archive_strncpy(as,p,l) \
 
123
        ((as)->length=0, archive_strncat((as), (p), (l)))
 
124
 
 
125
/* Return length of string. */
 
126
#define archive_strlen(a) ((a)->length)
 
127
 
 
128
/* Set string length to zero. */
 
129
#define archive_string_empty(a) ((a)->length = 0)
 
130
 
 
131
/* Release any allocated storage resources. */
 
132
void    __archive_string_free(struct archive_string *);
 
133
#define archive_string_free  __archive_string_free
 
134
 
 
135
/* Like 'vsprintf', but resizes the underlying string as necessary. */
 
136
void    __archive_string_vsprintf(struct archive_string *, const char *,
 
137
            va_list);
 
138
#define archive_string_vsprintf __archive_string_vsprintf
 
139
 
 
140
void    __archive_string_sprintf(struct archive_string *, const char *, ...);
 
141
#define archive_string_sprintf  __archive_string_sprintf
 
142
 
 
143
/* Allocates a fresh buffer and converts as (assumed to be UTF-8) into it.
 
144
 * Returns NULL if conversion failed in any way. */
 
145
wchar_t *__archive_string_utf8_w(struct archive_string *as);
 
146
 
 
147
 
 
148
#endif