~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/ibuf0ibuf.h

Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (c) 1997, 2009, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
13
 
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file include/ibuf0ibuf.h
21
 
Insert buffer
22
 
 
23
 
Created 7/19/1997 Heikki Tuuri
24
 
*******************************************************/
25
 
 
26
 
#ifndef ibuf0ibuf_h
27
 
#define ibuf0ibuf_h
28
 
 
29
 
#include "univ.i"
30
 
 
31
 
#include "mtr0mtr.h"
32
 
#include "dict0mem.h"
33
 
#include "fsp0fsp.h"
34
 
 
35
 
#ifndef UNIV_HOTBACKUP
36
 
# include "ibuf0types.h"
37
 
 
38
 
/* Possible operations buffered in the insert/whatever buffer. See
39
 
ibuf_insert(). DO NOT CHANGE THE VALUES OF THESE, THEY ARE STORED ON DISK. */
40
 
typedef enum {
41
 
        IBUF_OP_INSERT = 0,
42
 
        IBUF_OP_DELETE_MARK = 1,
43
 
        IBUF_OP_DELETE = 2,
44
 
 
45
 
        /* Number of different operation types. */
46
 
        IBUF_OP_COUNT = 3
47
 
} ibuf_op_t;
48
 
 
49
 
/** Combinations of operations that can be buffered.  Because the enum
50
 
values are used for indexing innobase_change_buffering_values[], they
51
 
should start at 0 and there should not be any gaps. */
52
 
typedef enum {
53
 
        IBUF_USE_NONE = 0,
54
 
        IBUF_USE_INSERT,        /* insert */
55
 
        IBUF_USE_DELETE_MARK,   /* delete */
56
 
        IBUF_USE_INSERT_DELETE_MARK,    /* insert+delete */
57
 
        IBUF_USE_DELETE,        /* delete+purge */
58
 
        IBUF_USE_ALL,           /* insert+delete+purge */
59
 
 
60
 
        IBUF_USE_COUNT          /* number of entries in ibuf_use_t */
61
 
} ibuf_use_t;
62
 
 
63
 
/** Operations that can currently be buffered. */
64
 
extern ibuf_use_t       ibuf_use;
65
 
 
66
 
/** The insert buffer control structure */
67
 
extern ibuf_t*          ibuf;
68
 
 
69
 
/* The purpose of the insert buffer is to reduce random disk access.
70
 
When we wish to insert a record into a non-unique secondary index and
71
 
the B-tree leaf page where the record belongs to is not in the buffer
72
 
pool, we insert the record into the insert buffer B-tree, indexed by
73
 
(space_id, page_no).  When the page is eventually read into the buffer
74
 
pool, we look up the insert buffer B-tree for any modifications to the
75
 
page, and apply these upon the completion of the read operation.  This
76
 
is called the insert buffer merge. */
77
 
 
78
 
/* The insert buffer merge must always succeed.  To guarantee this,
79
 
the insert buffer subsystem keeps track of the free space in pages for
80
 
which it can buffer operations.  Two bits per page in the insert
81
 
buffer bitmap indicate the available space in coarse increments.  The
82
 
free bits in the insert buffer bitmap must never exceed the free space
83
 
on a page.  It is safe to decrement or reset the bits in the bitmap in
84
 
a mini-transaction that is committed before the mini-transaction that
85
 
affects the free space.  It is unsafe to increment the bits in a
86
 
separately committed mini-transaction, because in crash recovery, the
87
 
free bits could momentarily be set too high. */
88
 
 
89
 
/******************************************************************//**
90
 
Creates the insert buffer data structure at a database startup. */
91
 
UNIV_INTERN
92
 
void
93
 
ibuf_init_at_db_start(void);
94
 
/*=======================*/
95
 
/*********************************************************************//**
96
 
Reads the biggest tablespace id from the high end of the insert buffer
97
 
tree and updates the counter in fil_system. */
98
 
UNIV_INTERN
99
 
void
100
 
ibuf_update_max_tablespace_id(void);
101
 
/*===============================*/
102
 
/*********************************************************************//**
103
 
Initializes an ibuf bitmap page. */
104
 
UNIV_INTERN
105
 
void
106
 
ibuf_bitmap_page_init(
107
 
/*==================*/
108
 
        buf_block_t*    block,  /*!< in: bitmap page */
109
 
        mtr_t*          mtr);   /*!< in: mtr */
110
 
/************************************************************************//**
111
 
Resets the free bits of the page in the ibuf bitmap. This is done in a
112
 
separate mini-transaction, hence this operation does not restrict
113
 
further work to only ibuf bitmap operations, which would result if the
114
 
latch to the bitmap page were kept.  NOTE: The free bits in the insert
115
 
buffer bitmap must never exceed the free space on a page.  It is safe
116
 
to decrement or reset the bits in the bitmap in a mini-transaction
117
 
that is committed before the mini-transaction that affects the free
118
 
space. */
119
 
UNIV_INTERN
120
 
void
121
 
ibuf_reset_free_bits(
122
 
/*=================*/
123
 
        buf_block_t*    block); /*!< in: index page; free bits are set to 0
124
 
                                if the index is a non-clustered
125
 
                                non-unique, and page level is 0 */
126
 
/************************************************************************//**
127
 
Updates the free bits of an uncompressed page in the ibuf bitmap if
128
 
there is not enough free on the page any more.  This is done in a
129
 
separate mini-transaction, hence this operation does not restrict
130
 
further work to only ibuf bitmap operations, which would result if the
131
 
latch to the bitmap page were kept.  NOTE: The free bits in the insert
132
 
buffer bitmap must never exceed the free space on a page.  It is
133
 
unsafe to increment the bits in a separately committed
134
 
mini-transaction, because in crash recovery, the free bits could
135
 
momentarily be set too high.  It is only safe to use this function for
136
 
decrementing the free bits.  Should more free space become available,
137
 
we must not update the free bits here, because that would break crash
138
 
recovery. */
139
 
UNIV_INLINE
140
 
void
141
 
ibuf_update_free_bits_if_full(
142
 
/*==========================*/
143
 
        buf_block_t*    block,  /*!< in: index page to which we have added new
144
 
                                records; the free bits are updated if the
145
 
                                index is non-clustered and non-unique and
146
 
                                the page level is 0, and the page becomes
147
 
                                fuller */
148
 
        ulint           max_ins_size,/*!< in: value of maximum insert size with
149
 
                                reorganize before the latest operation
150
 
                                performed to the page */
151
 
        ulint           increase);/*!< in: upper limit for the additional space
152
 
                                used in the latest operation, if known, or
153
 
                                ULINT_UNDEFINED */
154
 
/**********************************************************************//**
155
 
Updates the free bits for an uncompressed page to reflect the present
156
 
state.  Does this in the mtr given, which means that the latching
157
 
order rules virtually prevent any further operations for this OS
158
 
thread until mtr is committed.  NOTE: The free bits in the insert
159
 
buffer bitmap must never exceed the free space on a page.  It is safe
160
 
to set the free bits in the same mini-transaction that updated the
161
 
page. */
162
 
UNIV_INTERN
163
 
void
164
 
ibuf_update_free_bits_low(
165
 
/*======================*/
166
 
        const buf_block_t*      block,          /*!< in: index page */
167
 
        ulint                   max_ins_size,   /*!< in: value of
168
 
                                                maximum insert size
169
 
                                                with reorganize before
170
 
                                                the latest operation
171
 
                                                performed to the page */
172
 
        mtr_t*                  mtr);           /*!< in/out: mtr */
173
 
/**********************************************************************//**
174
 
Updates the free bits for a compressed page to reflect the present
175
 
state.  Does this in the mtr given, which means that the latching
176
 
order rules virtually prevent any further operations for this OS
177
 
thread until mtr is committed.  NOTE: The free bits in the insert
178
 
buffer bitmap must never exceed the free space on a page.  It is safe
179
 
to set the free bits in the same mini-transaction that updated the
180
 
page. */
181
 
UNIV_INTERN
182
 
void
183
 
ibuf_update_free_bits_zip(
184
 
/*======================*/
185
 
        buf_block_t*    block,  /*!< in/out: index page */
186
 
        mtr_t*          mtr);   /*!< in/out: mtr */
187
 
/**********************************************************************//**
188
 
Updates the free bits for the two pages to reflect the present state.
189
 
Does this in the mtr given, which means that the latching order rules
190
 
virtually prevent any further operations until mtr is committed.
191
 
NOTE: The free bits in the insert buffer bitmap must never exceed the
192
 
free space on a page.  It is safe to set the free bits in the same
193
 
mini-transaction that updated the pages. */
194
 
UNIV_INTERN
195
 
void
196
 
ibuf_update_free_bits_for_two_pages_low(
197
 
/*====================================*/
198
 
        ulint           zip_size,/*!< in: compressed page size in bytes;
199
 
                                0 for uncompressed pages */
200
 
        buf_block_t*    block1, /*!< in: index page */
201
 
        buf_block_t*    block2, /*!< in: index page */
202
 
        mtr_t*          mtr);   /*!< in: mtr */
203
 
/**********************************************************************//**
204
 
A basic partial test if an insert to the insert buffer could be possible and
205
 
recommended. */
206
 
UNIV_INLINE
207
 
ibool
208
 
ibuf_should_try(
209
 
/*============*/
210
 
        dict_index_t*   index,                  /*!< in: index where to insert */
211
 
        ulint           ignore_sec_unique);     /*!< in: if != 0, we should
212
 
                                                ignore UNIQUE constraint on
213
 
                                                a secondary index when we
214
 
                                                decide */
215
 
/******************************************************************//**
216
 
Returns TRUE if the current OS thread is performing an insert buffer
217
 
routine.
218
 
 
219
 
For instance, a read-ahead of non-ibuf pages is forbidden by threads
220
 
that are executing an insert buffer routine.
221
 
@return TRUE if inside an insert buffer routine */
222
 
UNIV_INTERN
223
 
ibool
224
 
ibuf_inside(void);
225
 
/*=============*/
226
 
/***********************************************************************//**
227
 
Checks if a page address is an ibuf bitmap page (level 3 page) address.
228
 
@return TRUE if a bitmap page */
229
 
UNIV_INLINE
230
 
ibool
231
 
ibuf_bitmap_page(
232
 
/*=============*/
233
 
        ulint   zip_size,/*!< in: compressed page size in bytes;
234
 
                        0 for uncompressed pages */
235
 
        ulint   page_no);/*!< in: page number */
236
 
/***********************************************************************//**
237
 
Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages.
238
 
Must not be called when recv_no_ibuf_operations==TRUE.
239
 
@return TRUE if level 2 or level 3 page */
240
 
UNIV_INTERN
241
 
ibool
242
 
ibuf_page(
243
 
/*======*/
244
 
        ulint   space,  /*!< in: space id */
245
 
        ulint   zip_size,/*!< in: compressed page size in bytes, or 0 */
246
 
        ulint   page_no,/*!< in: page number */
247
 
        mtr_t*  mtr);   /*!< in: mtr which will contain an x-latch to the
248
 
                        bitmap page if the page is not one of the fixed
249
 
                        address ibuf pages, or NULL, in which case a new
250
 
                        transaction is created. */
251
 
/***********************************************************************//**
252
 
Frees excess pages from the ibuf free list. This function is called when an OS
253
 
thread calls fsp services to allocate a new file segment, or a new page to a
254
 
file segment, and the thread did not own the fsp latch before this call. */
255
 
UNIV_INTERN
256
 
void
257
 
ibuf_free_excess_pages(void);
258
 
/*========================*/
259
 
/*********************************************************************//**
260
 
Buffer an operation in the insert/delete buffer, instead of doing it
261
 
directly to the disk page, if this is possible. Does not do it if the index
262
 
is clustered or unique.
263
 
@return TRUE if success */
264
 
UNIV_INTERN
265
 
ibool
266
 
ibuf_insert(
267
 
/*========*/
268
 
        ibuf_op_t       op,     /*!< in: operation type */
269
 
        const dtuple_t* entry,  /*!< in: index entry to insert */
270
 
        dict_index_t*   index,  /*!< in: index where to insert */
271
 
        ulint           space,  /*!< in: space id where to insert */
272
 
        ulint           zip_size,/*!< in: compressed page size in bytes, or 0 */
273
 
        ulint           page_no,/*!< in: page number where to insert */
274
 
        que_thr_t*      thr);   /*!< in: query thread */
275
 
/*********************************************************************//**
276
 
When an index page is read from a disk to the buffer pool, this function
277
 
applies any buffered operations to the page and deletes the entries from the
278
 
insert buffer. If the page is not read, but created in the buffer pool, this
279
 
function deletes its buffered entries from the insert buffer; there can
280
 
exist entries for such a page if the page belonged to an index which
281
 
subsequently was dropped. */
282
 
UNIV_INTERN
283
 
void
284
 
ibuf_merge_or_delete_for_page(
285
 
/*==========================*/
286
 
        buf_block_t*    block,  /*!< in: if page has been read from
287
 
                                disk, pointer to the page x-latched,
288
 
                                else NULL */
289
 
        ulint           space,  /*!< in: space id of the index page */
290
 
        ulint           page_no,/*!< in: page number of the index page */
291
 
        ulint           zip_size,/*!< in: compressed page size in bytes,
292
 
                                or 0 */
293
 
        ibool           update_ibuf_bitmap);/*!< in: normally this is set
294
 
                                to TRUE, but if we have deleted or are
295
 
                                deleting the tablespace, then we
296
 
                                naturally do not want to update a
297
 
                                non-existent bitmap page */
298
 
/*********************************************************************//**
299
 
Deletes all entries in the insert buffer for a given space id. This is used
300
 
in DISCARD TABLESPACE and IMPORT TABLESPACE.
301
 
NOTE: this does not update the page free bitmaps in the space. The space will
302
 
become CORRUPT when you call this function! */
303
 
UNIV_INTERN
304
 
void
305
 
ibuf_delete_for_discarded_space(
306
 
/*============================*/
307
 
        ulint   space); /*!< in: space id */
308
 
/*********************************************************************//**
309
 
Contracts insert buffer trees by reading pages to the buffer pool.
310
 
@return a lower limit for the combined size in bytes of entries which
311
 
will be merged from ibuf trees to the pages read, 0 if ibuf is
312
 
empty */
313
 
UNIV_INTERN
314
 
ulint
315
 
ibuf_contract(
316
 
/*==========*/
317
 
        ibool   sync);  /*!< in: TRUE if the caller wants to wait for the
318
 
                        issued read with the highest tablespace address
319
 
                        to complete */
320
 
/*********************************************************************//**
321
 
Contracts insert buffer trees by reading pages to the buffer pool.
322
 
@return a lower limit for the combined size in bytes of entries which
323
 
will be merged from ibuf trees to the pages read, 0 if ibuf is
324
 
empty */
325
 
UNIV_INTERN
326
 
ulint
327
 
ibuf_contract_for_n_pages(
328
 
/*======================*/
329
 
        ibool   sync,   /*!< in: TRUE if the caller wants to wait for the
330
 
                        issued read with the highest tablespace address
331
 
                        to complete */
332
 
        ulint   n_pages);/*!< in: try to read at least this many pages to
333
 
                        the buffer pool and merge the ibuf contents to
334
 
                        them */
335
 
#endif /* !UNIV_HOTBACKUP */
336
 
/*********************************************************************//**
337
 
Parses a redo log record of an ibuf bitmap page init.
338
 
@return end of log record or NULL */
339
 
UNIV_INTERN
340
 
byte*
341
 
ibuf_parse_bitmap_init(
342
 
/*===================*/
343
 
        byte*           ptr,    /*!< in: buffer */
344
 
        byte*           end_ptr,/*!< in: buffer end */
345
 
        buf_block_t*    block,  /*!< in: block or NULL */
346
 
        mtr_t*          mtr);   /*!< in: mtr or NULL */
347
 
#ifndef UNIV_HOTBACKUP
348
 
#ifdef UNIV_IBUF_COUNT_DEBUG
349
 
/******************************************************************//**
350
 
Gets the ibuf count for a given page.
351
 
@return number of entries in the insert buffer currently buffered for
352
 
this page */
353
 
UNIV_INTERN
354
 
ulint
355
 
ibuf_count_get(
356
 
/*===========*/
357
 
        ulint   space,  /*!< in: space id */
358
 
        ulint   page_no);/*!< in: page number */
359
 
#endif
360
 
/******************************************************************//**
361
 
Looks if the insert buffer is empty.
362
 
@return TRUE if empty */
363
 
UNIV_INTERN
364
 
ibool
365
 
ibuf_is_empty(void);
366
 
/*===============*/
367
 
/******************************************************************//**
368
 
Prints info of ibuf. */
369
 
UNIV_INTERN
370
 
void
371
 
ibuf_print(
372
 
/*=======*/
373
 
        FILE*   file);  /*!< in: file where to print */
374
 
/********************************************************************
375
 
Read the first two bytes from a record's fourth field (counter field in new
376
 
records; something else in older records).
377
 
@return "counter" field, or ULINT_UNDEFINED if for some reason it can't be read */
378
 
UNIV_INTERN
379
 
ulint
380
 
ibuf_rec_get_counter(
381
 
/*=================*/
382
 
        const rec_t*    rec);   /*!< in: ibuf record */
383
 
/******************************************************************//**
384
 
Closes insert buffer and frees the data structures. */
385
 
UNIV_INTERN
386
 
void
387
 
ibuf_close(void);
388
 
/*============*/
389
 
 
390
 
#define IBUF_HEADER_PAGE_NO     FSP_IBUF_HEADER_PAGE_NO
391
 
#define IBUF_TREE_ROOT_PAGE_NO  FSP_IBUF_TREE_ROOT_PAGE_NO
392
 
 
393
 
#endif /* !UNIV_HOTBACKUP */
394
 
 
395
 
/* The ibuf header page currently contains only the file segment header
396
 
for the file segment from which the pages for the ibuf tree are allocated */
397
 
#define IBUF_HEADER             PAGE_DATA
398
 
#define IBUF_TREE_SEG_HEADER    0       /* fseg header for ibuf tree */
399
 
 
400
 
/* The insert buffer tree itself is always located in space 0. */
401
 
#define IBUF_SPACE_ID           0
402
 
 
403
 
#ifndef UNIV_NONINL
404
 
#include "ibuf0ibuf.ic"
405
 
#endif
406
 
 
407
 
#endif