~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty
  • Date: 2008-11-07 05:51:15 UTC
  • mto: This revision was merged to the branch mainline in revision 579.
  • Revision ID: mordred@palanthas.inaugust.com-20081107055115-0275gvq62buzls77
Fixed a decimal sign thing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
Insert buffer
 
3
 
 
4
(c) 1997 Innobase Oy
 
5
 
 
6
Created 7/19/1997 Heikki Tuuri
 
7
*******************************************************/
 
8
 
 
9
#ifndef ibuf0ibuf_h
 
10
#define ibuf0ibuf_h
 
11
 
 
12
#include "univ.i"
 
13
 
 
14
#include "dict0mem.h"
 
15
#include "dict0dict.h"
 
16
#include "mtr0mtr.h"
 
17
#include "que0types.h"
 
18
#include "ibuf0types.h"
 
19
#include "fsp0fsp.h"
 
20
 
 
21
extern ibuf_t*  ibuf;
 
22
 
 
23
/**********************************************************************
 
24
Creates the insert buffer data struct for a single tablespace. Reads the
 
25
root page of the insert buffer tree in the tablespace. This function can
 
26
be called only after the dictionary system has been initialized, as this
 
27
creates also the insert buffer table and index for this tablespace. */
 
28
UNIV_INTERN
 
29
ibuf_data_t*
 
30
ibuf_data_init_for_space(
 
31
/*=====================*/
 
32
                        /* out, own: ibuf data struct, linked to the list
 
33
                        in ibuf control structure. */
 
34
        ulint   space); /* in: space id */
 
35
/**********************************************************************
 
36
Creates the insert buffer data structure at a database startup and
 
37
initializes the data structures for the insert buffer of each tablespace. */
 
38
UNIV_INTERN
 
39
void
 
40
ibuf_init_at_db_start(void);
 
41
/*=======================*/
 
42
/*************************************************************************
 
43
Reads the biggest tablespace id from the high end of the insert buffer
 
44
tree and updates the counter in fil_system. */
 
45
UNIV_INTERN
 
46
void
 
47
ibuf_update_max_tablespace_id(void);
 
48
/*===============================*/
 
49
/*************************************************************************
 
50
Initializes an ibuf bitmap page. */
 
51
UNIV_INTERN
 
52
void
 
53
ibuf_bitmap_page_init(
 
54
/*==================*/
 
55
        buf_block_t*    block,  /* in: bitmap page */
 
56
        mtr_t*          mtr);   /* in: mtr */
 
57
/****************************************************************************
 
58
Resets the free bits of the page in the ibuf bitmap. This is done in a
 
59
separate mini-transaction, hence this operation does not restrict further
 
60
work to only ibuf bitmap operations, which would result if the latch to the
 
61
bitmap page were kept. */
 
62
UNIV_INTERN
 
63
void
 
64
ibuf_reset_free_bits(
 
65
/*=================*/
 
66
        buf_block_t*    block); /* in: index page; free bits are set to 0
 
67
                                if the index is a non-clustered
 
68
                                non-unique, and page level is 0 */
 
69
/****************************************************************************
 
70
Updates the free bits of an uncompressed page in the ibuf bitmap if
 
71
there is not enough free on the page any more. This is done in a
 
72
separate mini-transaction, hence this operation does not restrict
 
73
further work to only ibuf bitmap operations, which would result if the
 
74
latch to the bitmap page were kept. */
 
75
UNIV_INLINE
 
76
void
 
77
ibuf_update_free_bits_if_full(
 
78
/*==========================*/
 
79
        buf_block_t*    block,  /* in: index page to which we have added new
 
80
                                records; the free bits are updated if the
 
81
                                index is non-clustered and non-unique and
 
82
                                the page level is 0, and the page becomes
 
83
                                fuller */
 
84
        ulint           max_ins_size,/* in: value of maximum insert size with
 
85
                                reorganize before the latest operation
 
86
                                performed to the page */
 
87
        ulint           increase);/* in: upper limit for the additional space
 
88
                                used in the latest operation, if known, or
 
89
                                ULINT_UNDEFINED */
 
90
/**************************************************************************
 
91
Updates the free bits for an uncompressed page to reflect the present state.
 
92
Does this in the mtr given, which means that the latching order rules virtually
 
93
prevent any further operations for this OS thread until mtr is committed. */
 
94
UNIV_INTERN
 
95
void
 
96
ibuf_update_free_bits_low(
 
97
/*======================*/
 
98
        const buf_block_t*      block,          /* in: index page */
 
99
        ulint                   max_ins_size,   /* in: value of
 
100
                                                maximum insert size
 
101
                                                with reorganize before
 
102
                                                the latest operation
 
103
                                                performed to the page */
 
104
        mtr_t*                  mtr);           /* in/out: mtr */
 
105
/**************************************************************************
 
106
Updates the free bits for a compressed page to reflect the present state.
 
107
Does this in the mtr given, which means that the latching order rules virtually
 
108
prevent any further operations for this OS thread until mtr is committed. */
 
109
UNIV_INTERN
 
110
void
 
111
ibuf_update_free_bits_zip(
 
112
/*======================*/
 
113
        buf_block_t*    block,  /* in/out: index page */
 
114
        mtr_t*          mtr);   /* in/out: mtr */
 
115
/**************************************************************************
 
116
Updates the free bits for the two pages to reflect the present state. Does
 
117
this in the mtr given, which means that the latching order rules virtually
 
118
prevent any further operations until mtr is committed. */
 
119
UNIV_INTERN
 
120
void
 
121
ibuf_update_free_bits_for_two_pages_low(
 
122
/*====================================*/
 
123
        ulint           zip_size,/* in: compressed page size in bytes;
 
124
                                0 for uncompressed pages */
 
125
        buf_block_t*    block1, /* in: index page */
 
126
        buf_block_t*    block2, /* in: index page */
 
127
        mtr_t*          mtr);   /* in: mtr */
 
128
/**************************************************************************
 
129
A basic partial test if an insert to the insert buffer could be possible and
 
130
recommended. */
 
131
UNIV_INLINE
 
132
ibool
 
133
ibuf_should_try(
 
134
/*============*/
 
135
        dict_index_t*   index,                  /* in: index where to insert */
 
136
        ulint           ignore_sec_unique);     /* in: if != 0, we should
 
137
                                                ignore UNIQUE constraint on
 
138
                                                a secondary index when we
 
139
                                                decide */
 
140
/**********************************************************************
 
141
Returns TRUE if the current OS thread is performing an insert buffer
 
142
routine. */
 
143
UNIV_INTERN
 
144
ibool
 
145
ibuf_inside(void);
 
146
/*=============*/
 
147
                /* out: TRUE if inside an insert buffer routine: for instance,
 
148
                a read-ahead of non-ibuf pages is then forbidden */
 
149
/***************************************************************************
 
150
Checks if a page address is an ibuf bitmap page (level 3 page) address. */
 
151
UNIV_INLINE
 
152
ibool
 
153
ibuf_bitmap_page(
 
154
/*=============*/
 
155
                        /* out: TRUE if a bitmap page */
 
156
        ulint   zip_size,/* in: compressed page size in bytes;
 
157
                        0 for uncompressed pages */
 
158
        ulint   page_no);/* in: page number */
 
159
/***************************************************************************
 
160
Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages. */
 
161
UNIV_INTERN
 
162
ibool
 
163
ibuf_page(
 
164
/*======*/
 
165
                        /* out: TRUE if level 2 or level 3 page */
 
166
        ulint   space,  /* in: space id */
 
167
        ulint   zip_size,/* in: compressed page size in bytes, or 0 */
 
168
        ulint   page_no);/* in: page number */
 
169
/***************************************************************************
 
170
Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages. */
 
171
UNIV_INTERN
 
172
ibool
 
173
ibuf_page_low(
 
174
/*==========*/
 
175
                        /* out: TRUE if level 2 or level 3 page */
 
176
        ulint   space,  /* in: space id */
 
177
        ulint   zip_size,/* in: compressed page size in bytes, or 0 */
 
178
        ulint   page_no,/* in: page number */
 
179
        mtr_t*  mtr);   /* in: mtr which will contain an x-latch to the
 
180
                        bitmap page if the page is not one of the fixed
 
181
                        address ibuf pages */
 
182
/***************************************************************************
 
183
Frees excess pages from the ibuf free list. This function is called when an OS
 
184
thread calls fsp services to allocate a new file segment, or a new page to a
 
185
file segment, and the thread did not own the fsp latch before this call. */
 
186
UNIV_INTERN
 
187
void
 
188
ibuf_free_excess_pages(
 
189
/*===================*/
 
190
        ulint   space);         /* in: space id */
 
191
/*************************************************************************
 
192
Makes an index insert to the insert buffer, instead of directly to the disk
 
193
page, if this is possible. Does not do insert if the index is clustered
 
194
or unique. */
 
195
UNIV_INTERN
 
196
ibool
 
197
ibuf_insert(
 
198
/*========*/
 
199
                                /* out: TRUE if success */
 
200
        const dtuple_t* entry,  /* in: index entry to insert */
 
201
        dict_index_t*   index,  /* in: index where to insert */
 
202
        ulint           space,  /* in: space id where to insert */
 
203
        ulint           zip_size,/* in: compressed page size in bytes, or 0 */
 
204
        ulint           page_no,/* in: page number where to insert */
 
205
        que_thr_t*      thr);   /* in: query thread */
 
206
/*************************************************************************
 
207
When an index page is read from a disk to the buffer pool, this function
 
208
inserts to the page the possible index entries buffered in the insert buffer.
 
209
The entries are deleted from the insert buffer. If the page is not read, but
 
210
created in the buffer pool, this function deletes its buffered entries from
 
211
the insert buffer; there can exist entries for such a page if the page
 
212
belonged to an index which subsequently was dropped. */
 
213
UNIV_INTERN
 
214
void
 
215
ibuf_merge_or_delete_for_page(
 
216
/*==========================*/
 
217
        buf_block_t*    block,  /* in: if page has been read from
 
218
                                disk, pointer to the page x-latched,
 
219
                                else NULL */
 
220
        ulint           space,  /* in: space id of the index page */
 
221
        ulint           page_no,/* in: page number of the index page */
 
222
        ulint           zip_size,/* in: compressed page size in bytes,
 
223
                                or 0 */
 
224
        ibool           update_ibuf_bitmap);/* in: normally this is set
 
225
                                to TRUE, but if we have deleted or are
 
226
                                deleting the tablespace, then we
 
227
                                naturally do not want to update a
 
228
                                non-existent bitmap page */
 
229
/*************************************************************************
 
230
Deletes all entries in the insert buffer for a given space id. This is used
 
231
in DISCARD TABLESPACE and IMPORT TABLESPACE.
 
232
NOTE: this does not update the page free bitmaps in the space. The space will
 
233
become CORRUPT when you call this function! */
 
234
UNIV_INTERN
 
235
void
 
236
ibuf_delete_for_discarded_space(
 
237
/*============================*/
 
238
        ulint   space); /* in: space id */
 
239
/*************************************************************************
 
240
Contracts insert buffer trees by reading pages to the buffer pool. */
 
241
UNIV_INTERN
 
242
ulint
 
243
ibuf_contract(
 
244
/*==========*/
 
245
                        /* out: a lower limit for the combined size in bytes
 
246
                        of entries which will be merged from ibuf trees to the
 
247
                        pages read, 0 if ibuf is empty */
 
248
        ibool   sync);  /* in: TRUE if the caller wants to wait for the
 
249
                        issued read with the highest tablespace address
 
250
                        to complete */
 
251
/*************************************************************************
 
252
Contracts insert buffer trees by reading pages to the buffer pool. */
 
253
UNIV_INTERN
 
254
ulint
 
255
ibuf_contract_for_n_pages(
 
256
/*======================*/
 
257
                        /* out: a lower limit for the combined size in bytes
 
258
                        of entries which will be merged from ibuf trees to the
 
259
                        pages read, 0 if ibuf is empty */
 
260
        ibool   sync,   /* in: TRUE if the caller wants to wait for the
 
261
                        issued read with the highest tablespace address
 
262
                        to complete */
 
263
        ulint   n_pages);/* in: try to read at least this many pages to
 
264
                        the buffer pool and merge the ibuf contents to
 
265
                        them */
 
266
/*************************************************************************
 
267
Parses a redo log record of an ibuf bitmap page init. */
 
268
UNIV_INTERN
 
269
byte*
 
270
ibuf_parse_bitmap_init(
 
271
/*===================*/
 
272
                                /* out: end of log record or NULL */
 
273
        byte*           ptr,    /* in: buffer */
 
274
        byte*           end_ptr,/* in: buffer end */
 
275
        buf_block_t*    block,  /* in: block or NULL */
 
276
        mtr_t*          mtr);   /* in: mtr or NULL */
 
277
#ifdef UNIV_IBUF_COUNT_DEBUG
 
278
/**********************************************************************
 
279
Gets the ibuf count for a given page. */
 
280
UNIV_INTERN
 
281
ulint
 
282
ibuf_count_get(
 
283
/*===========*/
 
284
                        /* out: number of entries in the insert buffer
 
285
                        currently buffered for this page */
 
286
        ulint   space,  /* in: space id */
 
287
        ulint   page_no);/* in: page number */
 
288
#endif
 
289
/**********************************************************************
 
290
Looks if the insert buffer is empty. */
 
291
UNIV_INTERN
 
292
ibool
 
293
ibuf_is_empty(void);
 
294
/*===============*/
 
295
                        /* out: TRUE if empty */
 
296
/**********************************************************************
 
297
Prints info of ibuf. */
 
298
UNIV_INTERN
 
299
void
 
300
ibuf_print(
 
301
/*=======*/
 
302
        FILE*   file);  /* in: file where to print */
 
303
 
 
304
#define IBUF_HEADER_PAGE_NO     FSP_IBUF_HEADER_PAGE_NO
 
305
#define IBUF_TREE_ROOT_PAGE_NO  FSP_IBUF_TREE_ROOT_PAGE_NO
 
306
 
 
307
/* The ibuf header page currently contains only the file segment header
 
308
for the file segment from which the pages for the ibuf tree are allocated */
 
309
#define IBUF_HEADER             PAGE_DATA
 
310
#define IBUF_TREE_SEG_HEADER    0       /* fseg header for ibuf tree */
 
311
 
 
312
#ifndef UNIV_NONINL
 
313
#include "ibuf0ibuf.ic"
 
314
#endif
 
315
 
 
316
#endif