~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/page0zip.h

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
Compressed page interface
 
3
 
 
4
(c) 2005 Innobase Oy
 
5
 
 
6
Created June 2005 by Marko Makela
 
7
*******************************************************/
 
8
 
 
9
#ifndef page0zip_h
 
10
#define page0zip_h
 
11
 
 
12
#ifdef UNIV_MATERIALIZE
 
13
# undef UNIV_INLINE
 
14
# define UNIV_INLINE
 
15
#endif
 
16
 
 
17
#include "mtr0types.h"
 
18
#include "page0types.h"
 
19
#include "buf0types.h"
 
20
#include "dict0types.h"
 
21
#include "mem0mem.h"
 
22
 
 
23
/**************************************************************************
 
24
Determine the size of a compressed page in bytes. */
 
25
UNIV_INLINE
 
26
ulint
 
27
page_zip_get_size(
 
28
/*==============*/
 
29
                                                /* out: size in bytes */
 
30
        const page_zip_des_t*   page_zip)       /* in: compressed page */
 
31
        __attribute__((nonnull, pure));
 
32
/**************************************************************************
 
33
Set the size of a compressed page in bytes. */
 
34
UNIV_INLINE
 
35
void
 
36
page_zip_set_size(
 
37
/*==============*/
 
38
        page_zip_des_t* page_zip,       /* in/out: compressed page */
 
39
        ulint           size);          /* in: size in bytes */
 
40
 
 
41
/**************************************************************************
 
42
Determine if a record is so big that it needs to be stored externally. */
 
43
UNIV_INLINE
 
44
ibool
 
45
page_zip_rec_needs_ext(
 
46
/*===================*/
 
47
                                /* out: FALSE if the entire record
 
48
                                can be stored locally on the page */
 
49
        ulint   rec_size,       /* in: length of the record in bytes */
 
50
        ulint   comp,           /* in: nonzero=compact format */
 
51
        ulint   zip_size)       /* in: compressed page size in bytes, or 0 */
 
52
        __attribute__((__const__));
 
53
 
 
54
/**************************************************************************
 
55
Determine the guaranteed free space on an empty page. */
 
56
UNIV_INTERN
 
57
ulint
 
58
page_zip_empty_size(
 
59
/*================*/
 
60
                                /* out: minimum payload size on the page */
 
61
        ulint   n_fields,       /* in: number of columns in the index */
 
62
        ulint   zip_size)       /* in: compressed page size in bytes */
 
63
        __attribute__((const));
 
64
 
 
65
/**************************************************************************
 
66
Initialize a compressed page descriptor. */
 
67
UNIV_INLINE
 
68
void
 
69
page_zip_des_init(
 
70
/*==============*/
 
71
        page_zip_des_t* page_zip);      /* in/out: compressed page
 
72
                                        descriptor */
 
73
 
 
74
/**************************************************************************
 
75
Configure the zlib allocator to use the given memory heap. */
 
76
UNIV_INTERN
 
77
void
 
78
page_zip_set_alloc(
 
79
/*===============*/
 
80
        void*           stream,         /* in/out: zlib stream */
 
81
        mem_heap_t*     heap);          /* in: memory heap to use */
 
82
 
 
83
/**************************************************************************
 
84
Compress a page. */
 
85
UNIV_INTERN
 
86
ibool
 
87
page_zip_compress(
 
88
/*==============*/
 
89
                                /* out: TRUE on success, FALSE on failure;
 
90
                                page_zip will be left intact on failure. */
 
91
        page_zip_des_t* page_zip,/* in: size; out: data, n_blobs,
 
92
                                m_start, m_end, m_nonempty */
 
93
        const page_t*   page,   /* in: uncompressed page */
 
94
        dict_index_t*   index,  /* in: index of the B-tree node */
 
95
        mtr_t*          mtr)    /* in: mini-transaction, or NULL */
 
96
        __attribute__((nonnull(1,2,3)));
 
97
 
 
98
/**************************************************************************
 
99
Decompress a page.  This function should tolerate errors on the compressed
 
100
page.  Instead of letting assertions fail, it will return FALSE if an
 
101
inconsistency is detected. */
 
102
UNIV_INTERN
 
103
ibool
 
104
page_zip_decompress(
 
105
/*================*/
 
106
                                /* out: TRUE on success, FALSE on failure */
 
107
        page_zip_des_t* page_zip,/* in: data, ssize;
 
108
                                out: m_start, m_end, m_nonempty, n_blobs */
 
109
        page_t*         page)   /* out: uncompressed page, may be trashed */
 
110
        __attribute__((nonnull));
 
111
 
 
112
#ifdef UNIV_DEBUG
 
113
/**************************************************************************
 
114
Validate a compressed page descriptor. */
 
115
UNIV_INLINE
 
116
ibool
 
117
page_zip_simple_validate(
 
118
/*=====================*/
 
119
                                                /* out: TRUE if ok */
 
120
        const page_zip_des_t*   page_zip);      /* in: compressed page
 
121
                                                descriptor */
 
122
#endif /* UNIV_DEBUG */
 
123
 
 
124
#ifdef UNIV_ZIP_DEBUG
 
125
/**************************************************************************
 
126
Check that the compressed and decompressed pages match. */
 
127
UNIV_INTERN
 
128
ibool
 
129
page_zip_validate(
 
130
/*==============*/
 
131
        const page_zip_des_t*   page_zip,/* in: compressed page */
 
132
        const page_t*           page)   /* in: uncompressed page */
 
133
        __attribute__((nonnull));
 
134
#endif /* UNIV_ZIP_DEBUG */
 
135
 
 
136
/**************************************************************************
 
137
Determine how big record can be inserted without recompressing the page. */
 
138
UNIV_INLINE
 
139
lint
 
140
page_zip_max_ins_size(
 
141
/*==================*/
 
142
                                        /* out: a positive number
 
143
                                        indicating the maximum size of
 
144
                                        a record whose insertion is
 
145
                                        guaranteed to succeed, or
 
146
                                        zero or negative */
 
147
        const page_zip_des_t*   page_zip,/* in: compressed page */
 
148
        ibool                   is_clust)/* in: TRUE if clustered index */
 
149
        __attribute__((nonnull, pure));
 
150
 
 
151
/**************************************************************************
 
152
Determine if enough space is available in the modification log. */
 
153
UNIV_INLINE
 
154
ibool
 
155
page_zip_available(
 
156
/*===============*/
 
157
                                        /* out: TRUE if page_zip_write_rec()
 
158
                                        will succeed */
 
159
        const page_zip_des_t*   page_zip,/* in: compressed page */
 
160
        ibool                   is_clust,/* in: TRUE if clustered index */
 
161
        ulint                   length, /* in: combined size of the record */
 
162
        ulint                   create) /* in: nonzero=add the record to
 
163
                                        the heap */
 
164
        __attribute__((nonnull, pure));
 
165
 
 
166
/**************************************************************************
 
167
Write an entire record on the compressed page.  The data must already
 
168
have been written to the uncompressed page. */
 
169
UNIV_INTERN
 
170
void
 
171
page_zip_write_rec(
 
172
/*===============*/
 
173
        page_zip_des_t* page_zip,/* in/out: compressed page */
 
174
        const byte*     rec,    /* in: record being written */
 
175
        dict_index_t*   index,  /* in: the index the record belongs to */
 
176
        const ulint*    offsets,/* in: rec_get_offsets(rec, index) */
 
177
        ulint           create) /* in: nonzero=insert, zero=update */
 
178
        __attribute__((nonnull));
 
179
 
 
180
/***************************************************************
 
181
Parses a log record of writing a BLOB pointer of a record. */
 
182
UNIV_INTERN
 
183
byte*
 
184
page_zip_parse_write_blob_ptr(
 
185
/*==========================*/
 
186
                                /* out: end of log record or NULL */
 
187
        byte*           ptr,    /* in: redo log buffer */
 
188
        byte*           end_ptr,/* in: redo log buffer end */
 
189
        page_t*         page,   /* in/out: uncompressed page */
 
190
        page_zip_des_t* page_zip);/* in/out: compressed page */
 
191
 
 
192
/**************************************************************************
 
193
Write a BLOB pointer of a record on the leaf page of a clustered index.
 
194
The information must already have been updated on the uncompressed page. */
 
195
UNIV_INTERN
 
196
void
 
197
page_zip_write_blob_ptr(
 
198
/*====================*/
 
199
        page_zip_des_t* page_zip,/* in/out: compressed page */
 
200
        const byte*     rec,    /* in/out: record whose data is being
 
201
                                written */
 
202
        dict_index_t*   index,  /* in: index of the page */
 
203
        const ulint*    offsets,/* in: rec_get_offsets(rec, index) */
 
204
        ulint           n,      /* in: column index */
 
205
        mtr_t*          mtr)    /* in: mini-transaction handle,
 
206
                                or NULL if no logging is needed */
 
207
        __attribute__((nonnull(1,2,3,4)));
 
208
 
 
209
/***************************************************************
 
210
Parses a log record of writing the node pointer of a record. */
 
211
UNIV_INTERN
 
212
byte*
 
213
page_zip_parse_write_node_ptr(
 
214
/*==========================*/
 
215
                                /* out: end of log record or NULL */
 
216
        byte*           ptr,    /* in: redo log buffer */
 
217
        byte*           end_ptr,/* in: redo log buffer end */
 
218
        page_t*         page,   /* in/out: uncompressed page */
 
219
        page_zip_des_t* page_zip);/* in/out: compressed page */
 
220
 
 
221
/**************************************************************************
 
222
Write the node pointer of a record on a non-leaf compressed page. */
 
223
UNIV_INTERN
 
224
void
 
225
page_zip_write_node_ptr(
 
226
/*====================*/
 
227
        page_zip_des_t* page_zip,/* in/out: compressed page */
 
228
        byte*           rec,    /* in/out: record */
 
229
        ulint           size,   /* in: data size of rec */
 
230
        ulint           ptr,    /* in: node pointer */
 
231
        mtr_t*          mtr)    /* in: mini-transaction, or NULL */
 
232
        __attribute__((nonnull(1,2)));
 
233
 
 
234
/**************************************************************************
 
235
Write the trx_id and roll_ptr of a record on a B-tree leaf node page. */
 
236
UNIV_INTERN
 
237
void
 
238
page_zip_write_trx_id_and_roll_ptr(
 
239
/*===============================*/
 
240
        page_zip_des_t* page_zip,/* in/out: compressed page */
 
241
        byte*           rec,    /* in/out: record */
 
242
        const ulint*    offsets,/* in: rec_get_offsets(rec, index) */
 
243
        ulint           trx_id_col,/* in: column number of TRX_ID in rec */
 
244
        dulint          trx_id, /* in: transaction identifier */
 
245
        dulint          roll_ptr)/* in: roll_ptr */
 
246
        __attribute__((nonnull));
 
247
 
 
248
/**************************************************************************
 
249
Insert a record to the dense page directory. */
 
250
UNIV_INTERN
 
251
void
 
252
page_zip_dir_insert(
 
253
/*================*/
 
254
        page_zip_des_t* page_zip,/* in/out: compressed page */
 
255
        const byte*     prev_rec,/* in: record after which to insert */
 
256
        const byte*     free_rec,/* in: record from which rec was
 
257
                                allocated, or NULL */
 
258
        byte*           rec);   /* in: record to insert */
 
259
 
 
260
/***************************************************************
 
261
Parses a log record of writing to the header of a page. */
 
262
UNIV_INTERN
 
263
byte*
 
264
page_zip_parse_write_header(
 
265
/*========================*/
 
266
                                /* out: end of log record or NULL */
 
267
        byte*           ptr,    /* in: redo log buffer */
 
268
        byte*           end_ptr,/* in: redo log buffer end */
 
269
        page_t*         page,   /* in/out: uncompressed page */
 
270
        page_zip_des_t* page_zip);/* in/out: compressed page */
 
271
 
 
272
/**************************************************************************
 
273
Write data to the uncompressed header portion of a page.  The data must
 
274
already have been written to the uncompressed page.
 
275
However, the data portion of the uncompressed page may differ from
 
276
the compressed page when a record is being inserted in
 
277
page_cur_insert_rec_low(). */
 
278
UNIV_INLINE
 
279
void
 
280
page_zip_write_header(
 
281
/*==================*/
 
282
        page_zip_des_t* page_zip,/* in/out: compressed page */
 
283
        const byte*     str,    /* in: address on the uncompressed page */
 
284
        ulint           length, /* in: length of the data */
 
285
        mtr_t*          mtr)    /* in: mini-transaction, or NULL */
 
286
        __attribute__((nonnull(1,2)));
 
287
 
 
288
/**************************************************************************
 
289
Reorganize and compress a page.  This is a low-level operation for
 
290
compressed pages, to be used when page_zip_compress() fails.
 
291
On success, a redo log entry MLOG_ZIP_PAGE_COMPRESS will be written.
 
292
The function btr_page_reorganize() should be preferred whenever possible.
 
293
IMPORTANT: if page_zip_reorganize() is invoked on a leaf page of a
 
294
non-clustered index, the caller must update the insert buffer free
 
295
bits in the same mini-transaction in such a way that the modification
 
296
will be redo-logged. */
 
297
UNIV_INTERN
 
298
ibool
 
299
page_zip_reorganize(
 
300
/*================*/
 
301
                                /* out: TRUE on success, FALSE on failure;
 
302
                                page and page_zip will be left intact
 
303
                                on failure. */
 
304
        buf_block_t*    block,  /* in/out: page with compressed page;
 
305
                                on the compressed page, in: size;
 
306
                                out: data, n_blobs,
 
307
                                m_start, m_end, m_nonempty */
 
308
        dict_index_t*   index,  /* in: index of the B-tree node */
 
309
        mtr_t*          mtr)    /* in: mini-transaction */
 
310
        __attribute__((nonnull));
 
311
/**************************************************************************
 
312
Copy a page byte for byte, except for the file page header and trailer. */
 
313
UNIV_INTERN
 
314
void
 
315
page_zip_copy(
 
316
/*==========*/
 
317
        page_zip_des_t*         page_zip,       /* out: copy of src_zip
 
318
                                                (n_blobs, m_start, m_end,
 
319
                                                m_nonempty, data[0..size-1]) */
 
320
        page_t*                 page,           /* out: copy of src */
 
321
        const page_zip_des_t*   src_zip,        /* in: compressed page */
 
322
        const page_t*           src,            /* in: page */
 
323
        dict_index_t*           index,          /* in: index of the B-tree */
 
324
        mtr_t*                  mtr)            /* in: mini-transaction */
 
325
        __attribute__((nonnull(1,2,3,4)));
 
326
 
 
327
/**************************************************************************
 
328
Parses a log record of compressing an index page. */
 
329
UNIV_INTERN
 
330
byte*
 
331
page_zip_parse_compress(
 
332
/*====================*/
 
333
                                /* out: end of log record or NULL */
 
334
        byte*           ptr,    /* in: buffer */
 
335
        byte*           end_ptr,/* in: buffer end */
 
336
        page_t*         page,   /* out: uncompressed page */
 
337
        page_zip_des_t* page_zip)/* out: compressed page */
 
338
        __attribute__((nonnull(1,2)));
 
339
 
 
340
/**************************************************************************
 
341
Calculate the compressed page checksum. */
 
342
UNIV_INTERN
 
343
ulint
 
344
page_zip_calc_checksum(
 
345
/*===================*/
 
346
                                /* out: page checksum */
 
347
        const void*     data,   /* in: compressed page */
 
348
        ulint           size)   /* in: size of compressed page */
 
349
        __attribute__((nonnull));
 
350
 
 
351
#ifdef UNIV_MATERIALIZE
 
352
# undef UNIV_INLINE
 
353
# define UNIV_INLINE    UNIV_INLINE_ORIGINAL
 
354
#endif
 
355
 
 
356
#ifndef UNIV_NONINL
 
357
# include "page0zip.ic"
 
358
#endif
 
359
 
 
360
#endif /* page0zip_h */