~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "hash0hash.h"
32
32
#include "ut0byte.h"
33
33
#include "os0proc.h"
34
 
#include "page0types.h"
35
34
 
 
35
/* Flags for flush types */
 
36
#define BUF_FLUSH_LRU           1
 
37
#define BUF_FLUSH_SINGLE_PAGE   2
 
38
#define BUF_FLUSH_LIST          3       /* An array in the pool struct
 
39
                                        has size BUF_FLUSH_LIST + 1: if you
 
40
                                        add more flush types, put them in
 
41
                                        the middle! */
36
42
/* Modes for buf_page_get_gen */
37
43
#define BUF_GET                 10      /* get always */
38
44
#define BUF_GET_IF_IN_POOL      11      /* get if in pool */
55
61
                                        prints info whenever read or flush
56
62
                                        occurs */
57
63
#endif /* UNIV_DEBUG */
58
 
 
59
 
/* States of a control block (@see buf_page_struct).
60
 
The enumeration values must be 0..7. */
61
 
enum buf_page_state {
62
 
        BUF_BLOCK_ZIP_FREE = 0,         /* contains a free compressed page */
63
 
        BUF_BLOCK_ZIP_PAGE,             /* contains a clean compressed page */
64
 
        BUF_BLOCK_ZIP_DIRTY,            /* contains a compressed page that is
65
 
                                        in the buf_pool->flush_list */
66
 
 
67
 
        /* The constants for compressed-only pages must precede
68
 
        BUF_BLOCK_NOT_USED; @see buf_block_state_valid() */
69
 
 
70
 
        BUF_BLOCK_NOT_USED,             /* is in the free list */
71
 
        BUF_BLOCK_READY_FOR_USE,        /* when buf_LRU_get_free_block returns
72
 
                                        a block, it is in this state */
73
 
        BUF_BLOCK_FILE_PAGE,            /* contains a buffered file page */
74
 
        BUF_BLOCK_MEMORY,               /* contains some main memory object */
75
 
        BUF_BLOCK_REMOVE_HASH           /* hash index should be removed
76
 
                                        before putting to the free list */
77
 
};
 
64
extern ulint srv_buf_pool_write_requests; /* variable to count write request
 
65
                                          issued */
78
66
 
79
67
/************************************************************************
80
68
Creates the buffer pool. */
81
 
UNIV_INTERN
 
69
 
82
70
buf_pool_t*
83
 
buf_pool_init(void);
84
 
/*===============*/
 
71
buf_pool_init(
 
72
/*==========*/
85
73
                                /* out, own: buf_pool object, NULL if not
86
74
                                enough memory or error */
87
 
/************************************************************************
88
 
Frees the buffer pool at shutdown.  This must not be invoked before
89
 
freeing all mutexes. */
90
 
UNIV_INTERN
91
 
void
92
 
buf_pool_free(void);
93
 
/*===============*/
94
 
 
95
 
/************************************************************************
96
 
Relocate a buffer control block.  Relocates the block on the LRU list
97
 
and in buf_pool->page_hash.  Does not relocate bpage->list.
98
 
The caller must take care of relocating bpage->list. */
99
 
UNIV_INTERN
100
 
void
101
 
buf_relocate(
102
 
/*=========*/
103
 
        buf_page_t*     bpage,  /* in/out: control block being relocated;
104
 
                                buf_page_get_state(bpage) must be
105
 
                                BUF_BLOCK_ZIP_DIRTY or BUF_BLOCK_ZIP_PAGE */
106
 
        buf_page_t*     dpage)  /* in/out: destination control block */
107
 
        __attribute__((nonnull));
108
 
/************************************************************************
109
 
Resizes the buffer pool. */
110
 
UNIV_INTERN
111
 
void
112
 
buf_pool_resize(void);
113
 
/*=================*/
 
75
        ulint   max_size,       /* in: maximum size of the buf_pool in
 
76
                                blocks */
 
77
        ulint   curr_size,      /* in: current size to use, must be <=
 
78
                                max_size, currently must be equal to
 
79
                                max_size */
 
80
        ulint   n_frames);      /* in: number of frames; if AWE is used,
 
81
                                this is the size of the address space window
 
82
                                where physical memory pages are mapped; if
 
83
                                AWE is not used then this must be the same
 
84
                                as max_size */
114
85
/*************************************************************************
115
 
Gets the current size of buffer buf_pool in bytes. */
 
86
Gets the current size of buffer buf_pool in bytes. In the case of AWE, the
 
87
size of AWE window (= the frames). */
116
88
UNIV_INLINE
117
89
ulint
118
90
buf_pool_get_curr_size(void);
119
91
/*========================*/
120
92
                        /* out: size in bytes */
 
93
/*************************************************************************
 
94
Gets the maximum size of buffer pool in bytes. In the case of AWE, the
 
95
size of AWE window (= the frames). */
 
96
UNIV_INLINE
 
97
ulint
 
98
buf_pool_get_max_size(void);
 
99
/*=======================*/
 
100
                        /* out: size in bytes */
121
101
/************************************************************************
122
102
Gets the smallest oldest_modification lsn for any page in the pool. Returns
123
 
zero if all modified pages have been flushed to disk. */
 
103
ut_dulint_zero if all modified pages have been flushed to disk. */
124
104
UNIV_INLINE
125
 
ib_uint64_t
 
105
dulint
126
106
buf_pool_get_oldest_modification(void);
127
107
/*==================================*/
128
108
                                /* out: oldest modification in pool,
129
 
                                zero if none */
130
 
/************************************************************************
131
 
Allocates a buffer block. */
132
 
UNIV_INLINE
133
 
buf_block_t*
134
 
buf_block_alloc(
135
 
/*============*/
136
 
                                /* out, own: the allocated block,
137
 
                                in state BUF_BLOCK_MEMORY */
138
 
        ulint   zip_size);      /* in: compressed page size in bytes,
139
 
                                or 0 if uncompressed tablespace */
140
 
/************************************************************************
141
 
Frees a buffer block which does not contain a file page. */
142
 
UNIV_INLINE
 
109
                                ut_dulint_zero if none */
 
110
/*************************************************************************
 
111
Allocates a buffer frame. */
 
112
 
 
113
buf_frame_t*
 
114
buf_frame_alloc(void);
 
115
/*==================*/
 
116
                                /* out: buffer frame */
 
117
/*************************************************************************
 
118
Frees a buffer frame which does not contain a file page. */
 
119
 
143
120
void
144
 
buf_block_free(
 
121
buf_frame_free(
145
122
/*===========*/
146
 
        buf_block_t*    block); /* in, own: block to be freed */
 
123
        buf_frame_t*    frame); /* in: buffer frame */
147
124
/*************************************************************************
148
125
Copies contents of a buffer frame to a given buffer. */
149
126
UNIV_INLINE
150
127
byte*
151
128
buf_frame_copy(
152
129
/*===========*/
153
 
                                        /* out: buf */
154
 
        byte*                   buf,    /* in: buffer to copy to */
155
 
        const buf_frame_t*      frame); /* in: buffer frame */
 
130
                                /* out: buf */
 
131
        byte*           buf,    /* in: buffer to copy to */
 
132
        buf_frame_t*    frame); /* in: buffer frame */
156
133
/******************************************************************
157
134
NOTE! The following macros should be used instead of buf_page_get_gen,
158
135
to improve debugging. Only values RW_S_LATCH and RW_X_LATCH are allowed
159
136
in LA! */
160
 
#define buf_page_get(SP, ZS, OF, LA, MTR)        buf_page_get_gen(\
161
 
                                SP, ZS, OF, LA, NULL,\
 
137
#define buf_page_get(SP, OF, LA, MTR)    buf_page_get_gen(\
 
138
                                SP, OF, LA, NULL,\
162
139
                                BUF_GET, __FILE__, __LINE__, MTR)
163
140
/******************************************************************
164
141
Use these macros to bufferfix a page with no latching. Remember not to
166
143
the contents of the page! We have separated this case, because it is
167
144
error-prone programming not to set a latch, and it should be used
168
145
with care. */
169
 
#define buf_page_get_with_no_latch(SP, ZS, OF, MTR)        buf_page_get_gen(\
170
 
                                SP, ZS, OF, RW_NO_LATCH, NULL,\
 
146
#define buf_page_get_with_no_latch(SP, OF, MTR)    buf_page_get_gen(\
 
147
                                SP, OF, RW_NO_LATCH, NULL,\
171
148
                                BUF_GET_NO_LATCH, __FILE__, __LINE__, MTR)
172
149
/******************************************************************
173
150
NOTE! The following macros should be used instead of buf_page_get_gen, to
174
151
improve debugging. Only values RW_S_LATCH and RW_X_LATCH are allowed as LA! */
175
 
#define buf_page_get_nowait(SP, ZS, OF, LA, MTR)        buf_page_get_gen(\
176
 
                                SP, ZS, OF, LA, NULL,\
 
152
#define buf_page_get_nowait(SP, OF, LA, MTR)    buf_page_get_gen(\
 
153
                                SP, OF, LA, NULL,\
177
154
                                BUF_GET_NOWAIT, __FILE__, __LINE__, MTR)
178
155
/******************************************************************
179
156
NOTE! The following macros should be used instead of
180
157
buf_page_optimistic_get_func, to improve debugging. Only values RW_S_LATCH and
181
158
RW_X_LATCH are allowed as LA! */
182
 
#define buf_page_optimistic_get(LA, BL, MC, MTR)                             \
183
 
        buf_page_optimistic_get_func(LA, BL, MC, __FILE__, __LINE__, MTR)
 
159
#define buf_page_optimistic_get(LA, BL, G, MC, MTR)                          \
 
160
        buf_page_optimistic_get_func(LA, BL, G, MC, __FILE__, __LINE__, MTR)
184
161
/************************************************************************
185
162
This is the general function used to get optimistic access to a database
186
163
page. */
187
 
UNIV_INTERN
 
164
 
188
165
ibool
189
166
buf_page_optimistic_get_func(
190
167
/*=========================*/
191
168
                                /* out: TRUE if success */
192
169
        ulint           rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */
193
170
        buf_block_t*    block,  /* in: guessed block */
194
 
        ib_uint64_t     modify_clock,/* in: modify clock value if mode is
 
171
        buf_frame_t*    guess,  /* in: guessed frame; note that AWE may move
 
172
                                frames */
 
173
        dulint          modify_clock,/* in: modify clock value if mode is
195
174
                                ..._GUESS_ON_CLOCK */
196
175
        const char*     file,   /* in: file name */
197
176
        ulint           line,   /* in: line where called */
198
177
        mtr_t*          mtr);   /* in: mini-transaction */
199
178
/************************************************************************
 
179
Tries to get the page, but if file io is required, releases all latches
 
180
in mtr down to the given savepoint. If io is required, this function
 
181
retrieves the page to buffer buf_pool, but does not bufferfix it or latch
 
182
it. */
 
183
UNIV_INLINE
 
184
buf_frame_t*
 
185
buf_page_get_release_on_io(
 
186
/*=======================*/
 
187
                                /* out: pointer to the frame, or NULL
 
188
                                if not in buffer buf_pool */
 
189
        ulint   space,          /* in: space id */
 
190
        ulint   offset,         /* in: offset of the page within space
 
191
                                in units of a page */
 
192
        buf_frame_t* guess,     /* in: guessed frame or NULL */
 
193
        ulint   rw_latch,       /* in: RW_X_LATCH, RW_S_LATCH,
 
194
                                or RW_NO_LATCH */
 
195
        ulint   savepoint,      /* in: mtr savepoint */
 
196
        mtr_t*  mtr);           /* in: mtr */
 
197
/************************************************************************
200
198
This is used to get access to a known database page, when no waiting can be
201
199
done. */
202
 
UNIV_INTERN
 
200
 
203
201
ibool
204
202
buf_page_get_known_nowait(
205
203
/*======================*/
206
204
                                /* out: TRUE if success */
207
205
        ulint           rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */
208
 
        buf_block_t*    block,  /* in: the known page */
 
206
        buf_frame_t*    guess,  /* in: the known page frame */
209
207
        ulint           mode,   /* in: BUF_MAKE_YOUNG or BUF_KEEP_OLD */
210
208
        const char*     file,   /* in: file name */
211
209
        ulint           line,   /* in: line where called */
212
210
        mtr_t*          mtr);   /* in: mini-transaction */
213
 
 
214
 
/***********************************************************************
215
 
Given a tablespace id and page number tries to get that page. If the
216
 
page is not in the buffer pool it is not loaded and NULL is returned.
217
 
Suitable for using when holding the kernel mutex. */
218
 
 
219
 
const buf_block_t*
220
 
buf_page_try_get_func(
221
 
/*==================*/
222
 
        ulint           space_id,/* in: tablespace id */
223
 
        ulint           page_no,/* in: page number */
224
 
        const char*     file,   /* in: file name */
225
 
        ulint           line,   /* in: line where called */
226
 
        mtr_t*          mtr);   /* in: mini-transaction */
227
 
 
228
 
#define buf_page_try_get(space_id, page_no, mtr)        \
229
 
        buf_page_try_get_func(space_id, page_no, __FILE__, __LINE__, mtr);
230
 
 
231
 
/************************************************************************
232
 
Get read access to a compressed page (usually of type
233
 
FIL_PAGE_TYPE_ZBLOB or FIL_PAGE_TYPE_ZBLOB2).
234
 
The page must be released with buf_page_release_zip().
235
 
NOTE: the page is not protected by any latch.  Mutual exclusion has to
236
 
be implemented at a higher level.  In other words, all possible
237
 
accesses to a given page through this function must be protected by
238
 
the same set of mutexes or latches. */
239
 
UNIV_INTERN
240
 
buf_page_t*
241
 
buf_page_get_zip(
242
 
/*=============*/
243
 
                                /* out: pointer to the block,
244
 
                                or NULL if not compressed */
245
 
        ulint           space,  /* in: space id */
246
 
        ulint           zip_size,/* in: compressed page size */
247
 
        ulint           offset);/* in: page number */
248
211
/************************************************************************
249
212
This is the general function used to get access to a database page. */
250
 
UNIV_INTERN
251
 
buf_block_t*
 
213
 
 
214
buf_frame_t*
252
215
buf_page_get_gen(
253
216
/*=============*/
254
 
                                /* out: pointer to the block or NULL */
 
217
                                /* out: pointer to the frame or NULL */
255
218
        ulint           space,  /* in: space id */
256
 
        ulint           zip_size,/* in: compressed page size in bytes
257
 
                                or 0 for uncompressed pages */
258
219
        ulint           offset, /* in: page number */
259
220
        ulint           rw_latch,/* in: RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
260
 
        buf_block_t*    guess,  /* in: guessed block or NULL */
 
221
        buf_frame_t*    guess,  /* in: guessed frame or NULL */
261
222
        ulint           mode,   /* in: BUF_GET, BUF_GET_IF_IN_POOL,
262
223
                                BUF_GET_NO_LATCH */
263
224
        const char*     file,   /* in: file name */
267
228
Initializes a page to the buffer buf_pool. The page is usually not read
268
229
from a file even if it cannot be found in the buffer buf_pool. This is one
269
230
of the functions which perform to a block a state transition NOT_USED =>
270
 
FILE_PAGE (the other is buf_page_get_gen). */
271
 
UNIV_INTERN
272
 
buf_block_t*
 
231
FILE_PAGE (the other is buf_page_init_for_read above). */
 
232
 
 
233
buf_frame_t*
273
234
buf_page_create(
274
235
/*============*/
275
 
                        /* out: pointer to the block, page bufferfixed */
 
236
                        /* out: pointer to the frame, page bufferfixed */
276
237
        ulint   space,  /* in: space id */
277
238
        ulint   offset, /* in: offset of the page within space in units of
278
239
                        a page */
279
 
        ulint   zip_size,/* in: compressed page size, or 0 */
280
240
        mtr_t*  mtr);   /* in: mini-transaction handle */
281
 
#ifdef UNIV_HOTBACKUP
282
241
/************************************************************************
283
242
Inits a page to the buffer buf_pool, for use in ibbackup --restore. */
284
 
UNIV_INTERN
 
243
 
285
244
void
286
245
buf_page_init_for_backup_restore(
287
246
/*=============================*/
288
247
        ulint           space,  /* in: space id */
289
248
        ulint           offset, /* in: offset of the page within space
290
249
                                in units of a page */
291
 
        ulint           zip_size,/* in: compressed page size in bytes
292
 
                                or 0 for uncompressed pages */
293
250
        buf_block_t*    block); /* in: block to init */
294
 
#endif /* UNIV_HOTBACKUP */
295
 
/************************************************************************
296
 
Releases a compressed-only page acquired with buf_page_get_zip(). */
297
 
UNIV_INLINE
298
 
void
299
 
buf_page_release_zip(
300
 
/*=================*/
301
 
        buf_page_t*     bpage);         /* in: buffer block */
302
251
/************************************************************************
303
252
Decrements the bufferfix count of a buffer control block and releases
304
253
a latch, if specified. */
314
263
Moves a page to the start of the buffer pool LRU list. This high-level
315
264
function can be used to prevent an important page from from slipping out of
316
265
the buffer pool. */
317
 
UNIV_INTERN
 
266
 
318
267
void
319
268
buf_page_make_young(
320
269
/*================*/
321
 
        buf_page_t*     bpage); /* in: buffer block of a file page */
 
270
        buf_frame_t*    frame); /* in: buffer frame of a file page */
322
271
/************************************************************************
323
272
Returns TRUE if the page can be found in the buffer pool hash table. NOTE
324
273
that it is possible that the page is not yet read from disk, though. */
325
 
UNIV_INLINE
 
274
 
326
275
ibool
327
276
buf_page_peek(
328
277
/*==========*/
332
281
        ulint   space,  /* in: space id */
333
282
        ulint   offset);/* in: page number */
334
283
/************************************************************************
 
284
Returns the buffer control block if the page can be found in the buffer
 
285
pool. NOTE that it is possible that the page is not yet read
 
286
from disk, though. This is a very low-level function: use with care! */
 
287
 
 
288
buf_block_t*
 
289
buf_page_peek_block(
 
290
/*================*/
 
291
                        /* out: control block if found from page hash table,
 
292
                        otherwise NULL; NOTE that the page is not necessarily
 
293
                        yet read from disk! */
 
294
        ulint   space,  /* in: space id */
 
295
        ulint   offset);/* in: page number */
 
296
/************************************************************************
335
297
Resets the check_index_page_at_flush field of a page if found in the buffer
336
298
pool. */
337
 
UNIV_INTERN
 
299
 
338
300
void
339
301
buf_reset_check_index_page_at_flush(
340
302
/*================================*/
341
303
        ulint   space,  /* in: space id */
342
304
        ulint   offset);/* in: page number */
343
 
#ifdef UNIV_DEBUG_FILE_ACCESSES
344
305
/************************************************************************
345
306
Sets file_page_was_freed TRUE if the page is found in the buffer pool.
346
307
This function should be called when we free a file page and want the
347
308
debug version to check that it is not accessed any more unless
348
309
reallocated. */
349
 
UNIV_INTERN
350
 
buf_page_t*
 
310
 
 
311
buf_block_t*
351
312
buf_page_set_file_page_was_freed(
352
313
/*=============================*/
353
 
                        /* out: control block if found in page hash table,
 
314
                        /* out: control block if found from page hash table,
354
315
                        otherwise NULL */
355
316
        ulint   space,  /* in: space id */
356
 
        ulint   offset);/* in: page number */
 
317
        ulint   offset);        /* in: page number */
357
318
/************************************************************************
358
319
Sets file_page_was_freed FALSE if the page is found in the buffer pool.
359
320
This function should be called when we free a file page and want the
360
321
debug version to check that it is not accessed any more unless
361
322
reallocated. */
362
 
UNIV_INTERN
363
 
buf_page_t*
 
323
 
 
324
buf_block_t*
364
325
buf_page_reset_file_page_was_freed(
365
326
/*===============================*/
366
 
                        /* out: control block if found in page hash table,
 
327
                        /* out: control block if found from page hash table,
367
328
                        otherwise NULL */
368
329
        ulint   space,  /* in: space id */
369
330
        ulint   offset);        /* in: page number */
370
 
#endif /* UNIV_DEBUG_FILE_ACCESSES */
371
 
/************************************************************************
372
 
Reads the freed_page_clock of a buffer block. */
373
 
UNIV_INLINE
374
 
ulint
375
 
buf_page_get_freed_page_clock(
376
 
/*==========================*/
377
 
                                        /* out: freed_page_clock */
378
 
        const buf_page_t*       bpage)  /* in: block */
379
 
        __attribute__((pure));
380
 
/************************************************************************
381
 
Reads the freed_page_clock of a buffer block. */
382
 
UNIV_INLINE
383
 
ulint
384
 
buf_block_get_freed_page_clock(
385
 
/*===========================*/
386
 
                                        /* out: freed_page_clock */
387
 
        const buf_block_t*      block)  /* in: block */
388
 
        __attribute__((pure));
389
 
 
390
331
/************************************************************************
391
332
Recommends a move of a block to the start of the LRU list if there is danger
392
333
of dropping from the buffer pool. NOTE: does not reserve the buffer pool
393
334
mutex. */
394
335
UNIV_INLINE
395
336
ibool
396
 
buf_page_peek_if_too_old(
397
 
/*=====================*/
398
 
                                        /* out: TRUE if should be made
399
 
                                        younger */
400
 
        const buf_page_t*       bpage); /* in: block to make younger */
 
337
buf_block_peek_if_too_old(
 
338
/*======================*/
 
339
                                /* out: TRUE if should be made younger */
 
340
        buf_block_t*    block); /* in: block to make younger */
401
341
/************************************************************************
402
342
Returns the current state of is_hashed of a page. FALSE if the page is
403
343
not in the pool. NOTE that this operation does not fix the page in the
404
344
pool if it is found there. */
405
 
UNIV_INTERN
 
345
 
406
346
ibool
407
347
buf_page_peek_if_search_hashed(
408
348
/*===========================*/
414
354
Gets the youngest modification log sequence number for a frame.
415
355
Returns zero if not file page or no modification occurred yet. */
416
356
UNIV_INLINE
417
 
ib_uint64_t
418
 
buf_page_get_newest_modification(
419
 
/*=============================*/
420
 
                                        /* out: newest modification to page */
421
 
        const buf_page_t*       bpage); /* in: block containing the
422
 
                                        page frame */
 
357
dulint
 
358
buf_frame_get_newest_modification(
 
359
/*==============================*/
 
360
                                /* out: newest modification to page */
 
361
        buf_frame_t*    frame); /* in: pointer to a frame */
 
362
/************************************************************************
 
363
Increments the modify clock of a frame by 1. The caller must (1) own the
 
364
pool mutex and block bufferfix count has to be zero, (2) or own an x-lock
 
365
on the block. */
 
366
UNIV_INLINE
 
367
dulint
 
368
buf_frame_modify_clock_inc(
 
369
/*=======================*/
 
370
                                /* out: new value */
 
371
        buf_frame_t*    frame); /* in: pointer to a frame */
423
372
/************************************************************************
424
373
Increments the modify clock of a frame by 1. The caller must (1) own the
425
374
buf_pool mutex and block bufferfix count has to be zero, (2) or own an x-lock
426
375
on the block. */
427
376
UNIV_INLINE
428
 
void
 
377
dulint
429
378
buf_block_modify_clock_inc(
430
379
/*=======================*/
 
380
                                /* out: new value */
431
381
        buf_block_t*    block); /* in: block */
432
382
/************************************************************************
433
383
Returns the value of the modify clock. The caller must have an s-lock
434
384
or x-lock on the block. */
435
385
UNIV_INLINE
436
 
ib_uint64_t
 
386
dulint
437
387
buf_block_get_modify_clock(
438
388
/*=======================*/
439
389
                                /* out: value */
442
392
Calculates a page checksum which is stored to the page when it is written
443
393
to a file. Note that we must be careful to calculate the same value
444
394
on 32-bit and 64-bit architectures. */
445
 
UNIV_INTERN
 
395
 
446
396
ulint
447
397
buf_calc_page_new_checksum(
448
398
/*=======================*/
449
 
                                /* out: checksum */
450
 
        const byte*     page);  /* in: buffer page */
 
399
                        /* out: checksum */
 
400
        byte*   page);  /* in: buffer page */
451
401
/************************************************************************
452
402
In versions < 4.0.14 and < 4.1.1 there was a bug that the checksum only
453
403
looked at the first few bytes of the page. This calculates that old
455
405
NOTE: we must first store the new formula checksum to
456
406
FIL_PAGE_SPACE_OR_CHKSUM before calculating and storing this old checksum
457
407
because this takes that field as an input! */
458
 
UNIV_INTERN
 
408
 
459
409
ulint
460
410
buf_calc_page_old_checksum(
461
411
/*=======================*/
462
 
                                /* out: checksum */
463
 
        const byte*      page); /* in: buffer page */
 
412
                        /* out: checksum */
 
413
        byte*    page); /* in: buffer page */
464
414
/************************************************************************
465
415
Checks if a page is corrupt. */
466
 
UNIV_INTERN
 
416
 
467
417
ibool
468
418
buf_page_is_corrupted(
469
419
/*==================*/
470
 
                                        /* out: TRUE if corrupted */
471
 
        const byte*     read_buf,       /* in: a database page */
472
 
        ulint           zip_size);      /* in: size of compressed page;
473
 
                                        0 for uncompressed pages */
 
420
                                /* out: TRUE if corrupted */
 
421
        byte*   read_buf);      /* in: a database page */
 
422
/**************************************************************************
 
423
Gets the page number of a pointer pointing within a buffer frame containing
 
424
a file page. */
 
425
UNIV_INLINE
 
426
ulint
 
427
buf_frame_get_page_no(
 
428
/*==================*/
 
429
                        /* out: page number */
 
430
        byte*   ptr);   /* in: pointer to within a buffer frame */
 
431
/**************************************************************************
 
432
Gets the space id of a pointer pointing within a buffer frame containing a
 
433
file page. */
 
434
UNIV_INLINE
 
435
ulint
 
436
buf_frame_get_space_id(
 
437
/*===================*/
 
438
                        /* out: space id */
 
439
        byte*   ptr);   /* in: pointer to within a buffer frame */
474
440
/**************************************************************************
475
441
Gets the space id, page offset, and byte offset within page of a
476
442
pointer pointing to a buffer frame containing a file page. */
478
444
void
479
445
buf_ptr_get_fsp_addr(
480
446
/*=================*/
481
 
        const void*     ptr,    /* in: pointer to a buffer frame */
 
447
        byte*           ptr,    /* in: pointer to a buffer frame */
482
448
        ulint*          space,  /* out: space id */
483
449
        fil_addr_t*     addr);  /* out: page offset and byte offset */
484
450
/**************************************************************************
485
 
Gets the hash value of a block. This can be used in searches in the
486
 
lock hash table. */
 
451
Gets the hash value of the page the pointer is pointing to. This can be used
 
452
in searches in the lock hash table. */
487
453
UNIV_INLINE
488
454
ulint
489
 
buf_block_get_lock_hash_val(
 
455
buf_frame_get_lock_hash_val(
490
456
/*========================*/
491
 
                                        /* out: lock hash value */
492
 
        const buf_block_t*      block)  /* in: block */
493
 
        __attribute__((pure));
 
457
                        /* out: lock hash value */
 
458
        byte*   ptr);   /* in: pointer to within a buffer frame */
 
459
/**************************************************************************
 
460
Gets the mutex number protecting the page record lock hash chain in the lock
 
461
table. */
 
462
UNIV_INLINE
 
463
mutex_t*
 
464
buf_frame_get_mutex(
 
465
/*================*/
 
466
                        /* out: mutex */
 
467
        byte*   ptr);   /* in: pointer to within a buffer frame */
 
468
/***********************************************************************
 
469
Gets the frame the pointer is pointing to. */
 
470
UNIV_INLINE
 
471
buf_frame_t*
 
472
buf_frame_align(
 
473
/*============*/
 
474
                        /* out: pointer to frame */
 
475
        byte*   ptr);   /* in: pointer to a frame */
 
476
/***********************************************************************
 
477
Checks if a pointer points to the block array of the buffer pool (blocks, not
 
478
the frames). */
 
479
UNIV_INLINE
 
480
ibool
 
481
buf_pool_is_block(
 
482
/*==============*/
 
483
                        /* out: TRUE if pointer to block */
 
484
        void*   ptr);   /* in: pointer to memory */
494
485
#ifdef UNIV_DEBUG
495
486
/*************************************************************************
496
 
Finds a block in the buffer pool that points to a
497
 
given compressed page. */
498
 
UNIV_INTERN
499
 
buf_block_t*
500
 
buf_pool_contains_zip(
501
 
/*==================*/
502
 
                                /* out: buffer block pointing to
503
 
                                the compressed page, or NULL */
504
 
        const void*     data);  /* in: pointer to compressed page */
505
 
#endif /* UNIV_DEBUG */
506
 
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
507
 
/*************************************************************************
508
487
Validates the buffer pool data structure. */
509
 
UNIV_INTERN
 
488
 
510
489
ibool
511
490
buf_validate(void);
512
491
/*==============*/
513
 
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
514
 
#if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
515
492
/*************************************************************************
516
493
Prints info of the buffer pool data structure. */
517
 
UNIV_INTERN
 
494
 
518
495
void
519
496
buf_print(void);
520
497
/*============*/
521
 
#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
 
498
#endif /* UNIV_DEBUG */
522
499
/************************************************************************
523
500
Prints a page to stderr. */
524
 
UNIV_INTERN
 
501
 
525
502
void
526
503
buf_page_print(
527
504
/*===========*/
528
 
        const byte*     read_buf,       /* in: a database page */
529
 
        ulint           zip_size);      /* in: compressed page size, or
530
 
                                        0 for uncompressed pages */
 
505
        byte*   read_buf);      /* in: a database page */
531
506
/*************************************************************************
532
507
Returns the number of latched pages in the buffer pool. */
533
 
UNIV_INTERN
 
508
 
534
509
ulint
535
510
buf_get_latched_pages_number(void);
536
511
/*==============================*/
537
512
/*************************************************************************
538
513
Returns the number of pending buf pool ios. */
539
 
UNIV_INTERN
 
514
 
540
515
ulint
541
516
buf_get_n_pending_ios(void);
542
517
/*=======================*/
543
518
/*************************************************************************
544
519
Prints info of the buffer i/o. */
545
 
UNIV_INTERN
 
520
 
546
521
void
547
522
buf_print_io(
548
523
/*=========*/
550
525
/*************************************************************************
551
526
Returns the ratio in percents of modified pages in the buffer pool /
552
527
database pages in the buffer pool. */
553
 
UNIV_INTERN
 
528
 
554
529
ulint
555
530
buf_get_modified_ratio_pct(void);
556
531
/*============================*/
557
532
/**************************************************************************
558
533
Refreshes the statistics used to print per-second averages. */
559
 
UNIV_INTERN
 
534
 
560
535
void
561
536
buf_refresh_io_stats(void);
562
537
/*======================*/
563
538
/*************************************************************************
564
539
Checks that all file pages in the buffer are in a replaceable state. */
565
 
UNIV_INTERN
 
540
 
566
541
ibool
567
542
buf_all_freed(void);
568
543
/*===============*/
569
544
/*************************************************************************
570
545
Checks that there currently are no pending i/o-operations for the buffer
571
546
pool. */
572
 
UNIV_INTERN
 
547
 
573
548
ibool
574
549
buf_pool_check_no_pending_io(void);
575
550
/*==============================*/
578
553
Invalidates the file pages in the buffer pool when an archive recovery is
579
554
completed. All the file pages buffered must be in a replaceable state when
580
555
this function is called: not latched and not modified. */
581
 
UNIV_INTERN
 
556
 
582
557
void
583
558
buf_pool_invalidate(void);
584
559
/*=====================*/
587
562
--------------------------- LOWER LEVEL ROUTINES -------------------------
588
563
=========================================================================*/
589
564
 
 
565
/************************************************************************
 
566
Maps the page of block to a frame, if not mapped yet. Unmaps some page
 
567
from the end of the awe_LRU_free_mapped. */
 
568
 
 
569
void
 
570
buf_awe_map_page_to_frame(
 
571
/*======================*/
 
572
        buf_block_t*    block,          /* in: block whose page should be
 
573
                                        mapped to a frame */
 
574
        ibool           add_to_mapped_list);/* in: TRUE if we in the case
 
575
                                        we need to map the page should also
 
576
                                        add the block to the
 
577
                                        awe_LRU_free_mapped list */
590
578
#ifdef UNIV_SYNC_DEBUG
591
579
/*************************************************************************
592
580
Adds latch level info for the rw-lock protecting the buffer frame. This
594
582
page if we know the latching order level of the acquired latch. */
595
583
UNIV_INLINE
596
584
void
597
 
buf_block_dbg_add_level(
598
 
/*====================*/
599
 
        buf_block_t*    block,  /* in: buffer page
600
 
                                where we have acquired latch */
 
585
buf_page_dbg_add_level(
 
586
/*===================*/
 
587
        buf_frame_t*    frame,  /* in: buffer page where we have acquired
 
588
                                a latch */
601
589
        ulint           level); /* in: latching order level */
602
590
#endif /* UNIV_SYNC_DEBUG */
603
591
/*************************************************************************
604
 
Gets the state of a block. */
605
 
UNIV_INLINE
606
 
enum buf_page_state
607
 
buf_page_get_state(
608
 
/*===============*/
609
 
                                        /* out: state */
610
 
        const buf_page_t*       bpage); /* in: pointer to the control block */
611
 
/*************************************************************************
612
 
Gets the state of a block. */
613
 
UNIV_INLINE
614
 
enum buf_page_state
615
 
buf_block_get_state(
616
 
/*================*/
617
 
                                        /* out: state */
618
 
        const buf_block_t*      block)  /* in: pointer to the control block */
619
 
        __attribute__((pure));
620
 
/*************************************************************************
621
 
Sets the state of a block. */
622
 
UNIV_INLINE
623
 
void
624
 
buf_page_set_state(
625
 
/*===============*/
626
 
        buf_page_t*             bpage,  /* in/out: pointer to control block */
627
 
        enum buf_page_state     state); /* in: state */
628
 
/*************************************************************************
629
 
Sets the state of a block. */
630
 
UNIV_INLINE
631
 
void
632
 
buf_block_set_state(
633
 
/*================*/
634
 
        buf_block_t*            block,  /* in/out: pointer to control block */
635
 
        enum buf_page_state     state); /* in: state */
636
 
/*************************************************************************
637
 
Determines if a block is mapped to a tablespace. */
638
 
UNIV_INLINE
639
 
ibool
640
 
buf_page_in_file(
641
 
/*=============*/
642
 
                                        /* out: TRUE if mapped */
643
 
        const buf_page_t*       bpage)  /* in: pointer to control block */
644
 
        __attribute__((pure));
645
 
/*************************************************************************
646
 
Determines if a block should be on unzip_LRU list. */
647
 
UNIV_INLINE
648
 
ibool
649
 
buf_page_belongs_to_unzip_LRU(
650
 
/*==========================*/
651
 
                                        /* out: TRUE if block belongs
652
 
                                        to unzip_LRU */
653
 
        const buf_page_t*       bpage)  /* in: pointer to control block */
654
 
        __attribute__((pure));
655
 
/*************************************************************************
656
 
Determine the approximate LRU list position of a block. */
657
 
UNIV_INLINE
658
 
ulint
659
 
buf_page_get_LRU_position(
660
 
/*======================*/
661
 
                                        /* out: LRU list position */
662
 
        const buf_page_t*       bpage)  /* in: control block */
663
 
        __attribute__((pure));
664
 
 
665
 
/*************************************************************************
666
 
Gets the mutex of a block. */
667
 
UNIV_INLINE
668
 
mutex_t*
669
 
buf_page_get_mutex(
670
 
/*===============*/
671
 
                                        /* out: pointer to mutex
672
 
                                        protecting bpage */
673
 
        const buf_page_t*       bpage)  /* in: pointer to control block */
674
 
        __attribute__((pure));
675
 
 
676
 
/*************************************************************************
677
 
Get the flush type of a page. */
678
 
UNIV_INLINE
679
 
enum buf_flush
680
 
buf_page_get_flush_type(
681
 
/*====================*/
682
 
                                        /* out: flush type */
683
 
        const buf_page_t*       bpage)  /* in: buffer page */
684
 
        __attribute__((pure));
685
 
/*************************************************************************
686
 
Set the flush type of a page. */
687
 
UNIV_INLINE
688
 
void
689
 
buf_page_set_flush_type(
690
 
/*====================*/
691
 
        buf_page_t*     bpage,          /* in: buffer page */
692
 
        enum buf_flush  flush_type);    /* in: flush type */
693
 
/*************************************************************************
694
 
Map a block to a file page. */
695
 
UNIV_INLINE
696
 
void
697
 
buf_block_set_file_page(
698
 
/*====================*/
699
 
        buf_block_t*            block,  /* in/out: pointer to control block */
700
 
        ulint                   space,  /* in: tablespace id */
701
 
        ulint                   page_no);/* in: page number */
702
 
/*************************************************************************
703
 
Gets the io_fix state of a block. */
704
 
UNIV_INLINE
705
 
enum buf_io_fix
706
 
buf_page_get_io_fix(
707
 
/*================*/
708
 
                                        /* out: io_fix state */
709
 
        const buf_page_t*       bpage)  /* in: pointer to the control block */
710
 
        __attribute__((pure));
711
 
/*************************************************************************
712
 
Gets the io_fix state of a block. */
713
 
UNIV_INLINE
714
 
enum buf_io_fix
715
 
buf_block_get_io_fix(
716
 
/*================*/
717
 
                                        /* out: io_fix state */
718
 
        const buf_block_t*      block)  /* in: pointer to the control block */
719
 
        __attribute__((pure));
720
 
/*************************************************************************
721
 
Sets the io_fix state of a block. */
722
 
UNIV_INLINE
723
 
void
724
 
buf_page_set_io_fix(
725
 
/*================*/
726
 
        buf_page_t*     bpage,  /* in/out: control block */
727
 
        enum buf_io_fix io_fix);/* in: io_fix state */
728
 
/*************************************************************************
729
 
Sets the io_fix state of a block. */
730
 
UNIV_INLINE
731
 
void
732
 
buf_block_set_io_fix(
733
 
/*=================*/
734
 
        buf_block_t*    block,  /* in/out: control block */
735
 
        enum buf_io_fix io_fix);/* in: io_fix state */
736
 
 
737
 
/************************************************************************
738
 
Determine if a buffer block can be relocated in memory.  The block
739
 
can be dirty, but it must not be I/O-fixed or bufferfixed. */
740
 
UNIV_INLINE
741
 
ibool
742
 
buf_page_can_relocate(
743
 
/*==================*/
744
 
        const buf_page_t*       bpage)  /* control block being relocated */
745
 
        __attribute__((pure));
746
 
 
747
 
/*************************************************************************
748
 
Determine if a block has been flagged old. */
749
 
UNIV_INLINE
750
 
ibool
751
 
buf_page_is_old(
752
 
/*============*/
753
 
                                        /* out: TRUE if old */
754
 
        const buf_page_t*       bpage)  /* in: control block */
755
 
        __attribute__((pure));
756
 
/*************************************************************************
757
 
Flag a block old. */
758
 
UNIV_INLINE
759
 
void
760
 
buf_page_set_old(
761
 
/*=============*/
762
 
        buf_page_t*     bpage,  /* in/out: control block */
763
 
        ibool           old);   /* in: old */
764
 
/*************************************************************************
765
 
Determine if a block has been accessed in the buffer pool. */
766
 
UNIV_INLINE
767
 
ibool
768
 
buf_page_is_accessed(
769
 
/*=================*/
770
 
                                        /* out: TRUE if accessed */
771
 
        const buf_page_t*       bpage)  /* in: control block */
772
 
        __attribute__((pure));
773
 
/*************************************************************************
774
 
Flag a block accessed. */
775
 
UNIV_INLINE
776
 
void
777
 
buf_page_set_accessed(
778
 
/*==================*/
779
 
        buf_page_t*     bpage,          /* in/out: control block */
780
 
        ibool           accessed);      /* in: accessed */
781
 
/*************************************************************************
782
 
Gets the buf_block_t handle of a buffered file block if an uncompressed
783
 
page frame exists, or NULL. */
784
 
UNIV_INLINE
785
 
buf_block_t*
786
 
buf_page_get_block(
787
 
/*===============*/
788
 
                                /* out: control block, or NULL */
789
 
        buf_page_t*     bpage)  /* in: control block, or NULL */
790
 
        __attribute__((pure));
791
 
#ifdef UNIV_DEBUG
792
 
/*************************************************************************
793
592
Gets a pointer to the memory frame of a block. */
794
593
UNIV_INLINE
795
594
buf_frame_t*
796
595
buf_block_get_frame(
797
596
/*================*/
798
 
                                        /* out: pointer to the frame */
799
 
        const buf_block_t*      block)  /* in: pointer to the control block */
800
 
        __attribute__((pure));
801
 
#else /* UNIV_DEBUG */
802
 
# define buf_block_get_frame(block) (block)->frame
803
 
#endif /* UNIV_DEBUG */
804
 
/*************************************************************************
805
 
Gets the space id of a block. */
806
 
UNIV_INLINE
807
 
ulint
808
 
buf_page_get_space(
809
 
/*===============*/
810
 
                                        /* out: space id */
811
 
        const buf_page_t*       bpage)  /* in: pointer to the control block */
812
 
        __attribute__((pure));
 
597
                                /* out: pointer to the frame */
 
598
        buf_block_t*    block); /* in: pointer to the control block */
813
599
/*************************************************************************
814
600
Gets the space id of a block. */
815
601
UNIV_INLINE
816
602
ulint
817
603
buf_block_get_space(
818
604
/*================*/
819
 
                                        /* out: space id */
820
 
        const buf_block_t*      block)  /* in: pointer to the control block */
821
 
        __attribute__((pure));
822
 
/*************************************************************************
823
 
Gets the page number of a block. */
824
 
UNIV_INLINE
825
 
ulint
826
 
buf_page_get_page_no(
827
 
/*=================*/
828
 
                                        /* out: page number */
829
 
        const buf_page_t*       bpage)  /* in: pointer to the control block */
830
 
        __attribute__((pure));
 
605
                                /* out: space id */
 
606
        buf_block_t*    block); /* in: pointer to the control block */
831
607
/*************************************************************************
832
608
Gets the page number of a block. */
833
609
UNIV_INLINE
834
610
ulint
835
611
buf_block_get_page_no(
836
612
/*==================*/
837
 
                                        /* out: page number */
838
 
        const buf_block_t*      block)  /* in: pointer to the control block */
839
 
        __attribute__((pure));
840
 
/*************************************************************************
841
 
Gets the compressed page size of a block. */
842
 
UNIV_INLINE
843
 
ulint
844
 
buf_page_get_zip_size(
845
 
/*==================*/
846
 
                                        /* out: compressed page size, or 0 */
847
 
        const buf_page_t*       bpage)  /* in: pointer to the control block */
848
 
        __attribute__((pure));
849
 
/*************************************************************************
850
 
Gets the compressed page size of a block. */
851
 
UNIV_INLINE
852
 
ulint
853
 
buf_block_get_zip_size(
854
 
/*===================*/
855
 
                                        /* out: compressed page size, or 0 */
856
 
        const buf_block_t*      block)  /* in: pointer to the control block */
857
 
        __attribute__((pure));
858
 
/*************************************************************************
859
 
Gets the compressed page descriptor corresponding to an uncompressed page
860
 
if applicable. */
861
 
#define buf_block_get_page_zip(block) \
862
 
        (UNIV_LIKELY_NULL((block)->page.zip.data) ? &(block)->page.zip : NULL)
863
 
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
 
613
                                /* out: page number */
 
614
        buf_block_t*    block); /* in: pointer to the control block */
864
615
/***********************************************************************
865
616
Gets the block to whose frame the pointer is pointing to. */
866
617
UNIV_INLINE
867
 
const buf_block_t*
 
618
buf_block_t*
868
619
buf_block_align(
869
620
/*============*/
870
 
                                /* out: pointer to block */
871
 
        const byte*     ptr);   /* in: pointer to a frame */
872
 
/*************************************************************************
873
 
Gets the compressed page descriptor corresponding to an uncompressed page
874
 
if applicable. */
875
 
UNIV_INLINE
876
 
const page_zip_des_t*
877
 
buf_frame_get_page_zip(
878
 
/*===================*/
879
 
                                /* out: compressed page descriptor, or NULL */
880
 
        const byte*     ptr);   /* in: pointer to the page */
881
 
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
 
621
                        /* out: pointer to block */
 
622
        byte*   ptr);   /* in: pointer to a frame */
882
623
/************************************************************************
883
624
This function is used to get info if there is an io operation
884
625
going on on a buffer page. */
887
628
buf_page_io_query(
888
629
/*==============*/
889
630
                                /* out: TRUE if io going on */
890
 
        buf_page_t*     bpage); /* in: pool block, must be bufferfixed */
 
631
        buf_block_t*    block); /* in: pool block, must be bufferfixed */
 
632
/***********************************************************************
 
633
Accessor function for block array. */
 
634
UNIV_INLINE
 
635
buf_block_t*
 
636
buf_pool_get_nth_block(
 
637
/*===================*/
 
638
                                /* out: pointer to block */
 
639
        buf_pool_t*     pool,   /* in: pool */
 
640
        ulint           i);     /* in: index of the block */
891
641
/************************************************************************
892
642
Function which inits a page for read to the buffer buf_pool. If the page is
893
643
(1) already in buf_pool, or
896
646
then this function does nothing.
897
647
Sets the io_fix flag to BUF_IO_READ and sets a non-recursive exclusive lock
898
648
on the buffer frame. The io-handler must take care that the flag is cleared
899
 
and the lock released later. */
900
 
UNIV_INTERN
901
 
buf_page_t*
 
649
and the lock released later. This is one of the functions which perform the
 
650
state transition NOT_USED => FILE_PAGE to a block (the other is
 
651
buf_page_create). */
 
652
 
 
653
buf_block_t*
902
654
buf_page_init_for_read(
903
655
/*===================*/
904
656
                                /* out: pointer to the block or NULL */
905
657
        ulint*          err,    /* out: DB_SUCCESS or DB_TABLESPACE_DELETED */
906
658
        ulint           mode,   /* in: BUF_READ_IBUF_PAGES_ONLY, ... */
907
659
        ulint           space,  /* in: space id */
908
 
        ulint           zip_size,/* in: compressed page size, or 0 */
909
 
        ibool           unzip,  /* in: TRUE=request uncompressed page */
910
 
        ib_int64_t      tablespace_version,/* in: prevents reading from a wrong
 
660
        ib_longlong     tablespace_version,/* in: prevents reading from a wrong
911
661
                                version of the tablespace in case we have done
912
662
                                DISCARD + IMPORT */
913
663
        ulint           offset);/* in: page number */
914
664
/************************************************************************
915
665
Completes an asynchronous read or write request of a file page to or from
916
666
the buffer pool. */
917
 
UNIV_INTERN
 
667
 
918
668
void
919
669
buf_page_io_complete(
920
670
/*=================*/
921
 
        buf_page_t*     bpage); /* in: pointer to the block in question */
 
671
        buf_block_t*    block); /* in: pointer to the block in question */
922
672
/************************************************************************
923
673
Calculates a folded value of a file page address to use in the page hash
924
674
table. */
928
678
/*==================*/
929
679
                        /* out: the folded value */
930
680
        ulint   space,  /* in: space id */
931
 
        ulint   offset) /* in: offset of the page within space */
932
 
        __attribute__((__const__));
 
681
        ulint   offset);/* in: offset of the page within space */
933
682
/**********************************************************************
934
683
Returns the control block of a file page, NULL if not found. */
935
684
UNIV_INLINE
936
 
buf_page_t*
 
685
buf_block_t*
937
686
buf_page_hash_get(
938
687
/*==============*/
939
688
                        /* out: block, NULL if not found */
940
689
        ulint   space,  /* in: space id */
941
690
        ulint   offset);/* in: offset of the page within space */
942
 
/**********************************************************************
943
 
Returns the control block of a file page, NULL if not found
944
 
or an uncompressed page frame does not exist. */
945
 
UNIV_INLINE
946
 
buf_block_t*
947
 
buf_block_hash_get(
948
 
/*===============*/
949
 
                        /* out: block, NULL if not found */
950
 
        ulint   space,  /* in: space id */
951
 
        ulint   offset);/* in: offset of the page within space */
952
691
/***********************************************************************
953
692
Increments the pool clock by one and returns its new value. Remember that
954
693
in the 32 bit version the clock wraps around at 4 billion! */
959
698
                        /* out: new clock value */
960
699
/*************************************************************************
961
700
Gets the current length of the free list of buffer blocks. */
962
 
UNIV_INTERN
 
701
 
963
702
ulint
964
703
buf_get_free_list_len(void);
965
704
/*=======================*/
966
705
 
967
706
 
968
707
 
969
 
/* The common buffer control block structure
970
 
for compressed and uncompressed frames */
971
 
 
972
 
struct buf_page_struct{
973
 
        /* None of the following bit-fields must be modified without
974
 
        holding buf_page_get_mutex() [block->mutex or buf_pool_zip_mutex],
975
 
        since they can be stored in the same machine word.  Some of them are
976
 
        additionally protected by buf_pool_mutex. */
977
 
 
978
 
        unsigned        space:32;       /* tablespace id */
979
 
        unsigned        offset:32;      /* page number */
980
 
 
981
 
        unsigned        state:3;        /* state of the control block
982
 
                                        (@see enum buf_page_state); also
983
 
                                        protected by buf_pool_mutex.
984
 
                                        State transitions from
985
 
                                        BUF_BLOCK_READY_FOR_USE to
986
 
                                        BUF_BLOCK_MEMORY need not be
987
 
                                        protected by buf_page_get_mutex(). */
988
 
        unsigned        flush_type:2;   /* if this block is currently being
989
 
                                        flushed to disk, this tells the
990
 
                                        flush_type (@see enum buf_flush) */
991
 
        unsigned        accessed:1;     /* TRUE if the page has been accessed
992
 
                                        while in the buffer pool: read-ahead
993
 
                                        may read in pages which have not been
994
 
                                        accessed yet; a thread is allowed to
995
 
                                        read this for heuristic purposes
996
 
                                        without holding any mutex or latch */
997
 
        unsigned        io_fix:2;       /* type of pending I/O operation
998
 
                                        (@see enum buf_io_fix); also
999
 
                                        protected by buf_pool_mutex */
1000
 
        unsigned        buf_fix_count:24;/* count of how manyfold this block
1001
 
                                        is currently bufferfixed */
1002
 
 
1003
 
        page_zip_des_t  zip;            /* compressed page; zip.data
1004
 
                                        (but not the data it points to) is
1005
 
                                        also protected by buf_pool_mutex */
1006
 
        buf_page_t*     hash;           /* node used in chaining to
1007
 
                                        buf_pool->page_hash or
1008
 
                                        buf_pool->zip_hash */
1009
 
#ifdef UNIV_DEBUG
1010
 
        ibool           in_page_hash;   /* TRUE if in buf_pool->page_hash */
1011
 
        ibool           in_zip_hash;    /* TRUE if in buf_pool->zip_hash */
1012
 
#endif /* UNIV_DEBUG */
1013
 
 
1014
 
        /* 2. Page flushing fields; protected by buf_pool_mutex */
1015
 
 
1016
 
        UT_LIST_NODE_T(buf_page_t) list;
1017
 
                                        /* based on state, this is a list
1018
 
                                        node in one of the following lists
1019
 
                                        in buf_pool:
1020
 
 
1021
 
                                        BUF_BLOCK_NOT_USED:     free
1022
 
                                        BUF_BLOCK_FILE_PAGE:    flush_list
1023
 
                                        BUF_BLOCK_ZIP_DIRTY:    flush_list
1024
 
                                        BUF_BLOCK_ZIP_PAGE:     zip_clean
1025
 
                                        BUF_BLOCK_ZIP_FREE:     zip_free[] */
1026
 
#ifdef UNIV_DEBUG
1027
 
        ibool           in_flush_list;  /* TRUE if in buf_pool->flush_list;
1028
 
                                        when buf_pool_mutex is free, the
1029
 
                                        following should hold: in_flush_list
1030
 
                                        == (state == BUF_BLOCK_FILE_PAGE
1031
 
                                            || state == BUF_BLOCK_ZIP_DIRTY) */
1032
 
        ibool           in_free_list;   /* TRUE if in buf_pool->free; when
1033
 
                                        buf_pool_mutex is free, the following
1034
 
                                        should hold: in_free_list
1035
 
                                        == (state == BUF_BLOCK_NOT_USED) */
1036
 
#endif /* UNIV_DEBUG */
1037
 
        ib_uint64_t     newest_modification;
1038
 
                                        /* log sequence number of the youngest
1039
 
                                        modification to this block, zero if
1040
 
                                        not modified */
1041
 
        ib_uint64_t     oldest_modification;
1042
 
                                        /* log sequence number of the START of
1043
 
                                        the log entry written of the oldest
1044
 
                                        modification to this block which has
1045
 
                                        not yet been flushed on disk; zero if
1046
 
                                        all modifications are on disk */
1047
 
 
1048
 
        /* 3. LRU replacement algorithm fields; protected by buf_pool_mutex */
1049
 
 
1050
 
        UT_LIST_NODE_T(buf_page_t) LRU;
1051
 
                                        /* node of the LRU list */
1052
 
#ifdef UNIV_DEBUG
1053
 
        ibool           in_LRU_list;    /* TRUE if the page is in the LRU list;
1054
 
                                        used in debugging */
1055
 
#endif /* UNIV_DEBUG */
1056
 
        unsigned        old:1;          /* TRUE if the block is in the old
1057
 
                                        blocks in the LRU list */
1058
 
        unsigned        LRU_position:31;/* value which monotonically decreases
1059
 
                                        (or may stay constant if old==TRUE)
1060
 
                                        toward the end of the LRU list, if
1061
 
                                        buf_pool->ulint_clock has not wrapped
1062
 
                                        around: NOTE that this value can only
1063
 
                                        be used in heuristic algorithms,
1064
 
                                        because of the possibility of a
1065
 
                                        wrap-around! */
1066
 
        unsigned        freed_page_clock:32;/* the value of
1067
 
                                        buf_pool->freed_page_clock when this
1068
 
                                        block was the last time put to the
1069
 
                                        head of the LRU list; a thread is
1070
 
                                        allowed to read this for heuristic
1071
 
                                        purposes without holding any mutex or
1072
 
                                        latch */
1073
 
#ifdef UNIV_DEBUG_FILE_ACCESSES
1074
 
        ibool           file_page_was_freed;
1075
 
                                        /* this is set to TRUE when fsp
1076
 
                                        frees a page in buffer pool */
1077
 
#endif /* UNIV_DEBUG_FILE_ACCESSES */
1078
 
};
1079
 
 
1080
708
/* The buffer control block structure */
1081
709
 
1082
710
struct buf_block_struct{
1083
711
 
1084
712
        /* 1. General fields */
1085
713
 
1086
 
        buf_page_t      page;           /* page information; this must
1087
 
                                        be the first field, so that
1088
 
                                        buf_pool->page_hash can point
1089
 
                                        to buf_page_t or buf_block_t */
1090
 
        UT_LIST_NODE_T(buf_block_t) unzip_LRU;
1091
 
                                        /* node of the decompressed LRU list;
1092
 
                                        a block is in the unzip_LRU list
1093
 
                                        if page.state == BUF_BLOCK_FILE_PAGE
1094
 
                                        and page.zip.data != NULL */
1095
 
#ifdef UNIV_DEBUG
1096
 
        ibool           in_unzip_LRU_list;/* TRUE if the page is in the
1097
 
                                        decompressed LRU list;
1098
 
                                        used in debugging */
1099
 
#endif /* UNIV_DEBUG */
 
714
        ulint           magic_n;        /* magic number to check */
 
715
        ulint           state;          /* state of the control block:
 
716
                                        BUF_BLOCK_NOT_USED, ...; changing
 
717
                                        this is only allowed when a thread
 
718
                                        has BOTH the buffer pool mutex AND
 
719
                                        block->mutex locked */
1100
720
        byte*           frame;          /* pointer to buffer frame which
1101
721
                                        is of size UNIV_PAGE_SIZE, and
1102
722
                                        aligned to an address divisible by
1103
 
                                        UNIV_PAGE_SIZE */
 
723
                                        UNIV_PAGE_SIZE; if AWE is used, this
 
724
                                        will be NULL for the pages which are
 
725
                                        currently not mapped into the virtual
 
726
                                        address space window of the buffer
 
727
                                        pool */
 
728
        os_awe_t*       awe_info;       /* if AWE is used, then an array of
 
729
                                        awe page infos for
 
730
                                        UNIV_PAGE_SIZE / OS_AWE_X86_PAGE_SIZE
 
731
                                        (normally = 4) physical memory
 
732
                                        pages; otherwise NULL */
 
733
        ulint           space;          /* space id of the page */
 
734
        ulint           offset;         /* page number within the space */
 
735
        ulint           lock_hash_val;  /* hashed value of the page address
 
736
                                        in the record lock hash table */
1104
737
        mutex_t         mutex;          /* mutex protecting this block:
1105
738
                                        state (also protected by the buffer
1106
739
                                        pool mutex), io_fix, buf_fix_count,
1109
742
                                        contention on the buffer pool mutex */
1110
743
        rw_lock_t       lock;           /* read-write lock of the buffer
1111
744
                                        frame */
1112
 
        unsigned        lock_hash_val:32;/* hashed value of the page address
1113
 
                                        in the record lock hash table */
1114
 
        unsigned        check_index_page_at_flush:1;
 
745
        buf_block_t*    hash;           /* node used in chaining to the page
 
746
                                        hash table */
 
747
        ibool           check_index_page_at_flush;
1115
748
                                        /* TRUE if we know that this is
1116
749
                                        an index page, and want the database
1117
750
                                        to check its consistency before flush;
1119
752
                                        buffer pool which are index pages,
1120
753
                                        but this flag is not set because
1121
754
                                        we do not keep track of all pages */
1122
 
 
1123
 
        /* 2. Optimistic search field */
1124
 
 
1125
 
        ib_uint64_t     modify_clock;   /* this clock is incremented every
 
755
        /* 2. Page flushing fields */
 
756
 
 
757
        UT_LIST_NODE_T(buf_block_t) flush_list;
 
758
                                        /* node of the modified, not yet
 
759
                                        flushed blocks list */
 
760
        dulint          newest_modification;
 
761
                                        /* log sequence number of the youngest
 
762
                                        modification to this block, zero if
 
763
                                        not modified */
 
764
        dulint          oldest_modification;
 
765
                                        /* log sequence number of the START of
 
766
                                        the log entry written of the oldest
 
767
                                        modification to this block which has
 
768
                                        not yet been flushed on disk; zero if
 
769
                                        all modifications are on disk */
 
770
        ulint           flush_type;     /* if this block is currently being
 
771
                                        flushed to disk, this tells the
 
772
                                        flush_type: BUF_FLUSH_LRU or
 
773
                                        BUF_FLUSH_LIST */
 
774
 
 
775
        /* 3. LRU replacement algorithm fields */
 
776
 
 
777
        UT_LIST_NODE_T(buf_block_t) free;
 
778
                                        /* node of the free block list */
 
779
        ibool           in_free_list;   /* TRUE if in the free list; used in
 
780
                                        debugging */
 
781
        UT_LIST_NODE_T(buf_block_t) LRU;
 
782
                                        /* node of the LRU list */
 
783
        UT_LIST_NODE_T(buf_block_t) awe_LRU_free_mapped;
 
784
                                        /* in the AWE version node in the
 
785
                                        list of free and LRU blocks which are
 
786
                                        mapped to a frame */
 
787
        ibool           in_LRU_list;    /* TRUE of the page is in the LRU list;
 
788
                                        used in debugging */
 
789
        ulint           LRU_position;   /* value which monotonically
 
790
                                        decreases (or may stay constant if
 
791
                                        the block is in the old blocks) toward
 
792
                                        the end of the LRU list, if the pool
 
793
                                        ulint_clock has not wrapped around:
 
794
                                        NOTE that this value can only be used
 
795
                                        in heuristic algorithms, because of
 
796
                                        the possibility of a wrap-around! */
 
797
        ulint           freed_page_clock;/* the value of freed_page_clock
 
798
                                        of the buffer pool when this block was
 
799
                                        the last time put to the head of the
 
800
                                        LRU list; a thread is allowed to
 
801
                                        read this for heuristic purposes
 
802
                                        without holding any mutex or latch */
 
803
        ibool           old;            /* TRUE if the block is in the old
 
804
                                        blocks in the LRU list */
 
805
        ibool           accessed;       /* TRUE if the page has been accessed
 
806
                                        while in the buffer pool: read-ahead
 
807
                                        may read in pages which have not been
 
808
                                        accessed yet; this is protected by
 
809
                                        block->mutex; a thread is allowed to
 
810
                                        read this for heuristic purposes
 
811
                                        without holding any mutex or latch */
 
812
        ulint           buf_fix_count;  /* count of how manyfold this block
 
813
                                        is currently bufferfixed; this is
 
814
                                        protected by block->mutex */
 
815
        ulint           io_fix;         /* if a read is pending to the frame,
 
816
                                        io_fix is BUF_IO_READ, in the case
 
817
                                        of a write BUF_IO_WRITE, otherwise 0;
 
818
                                        this is protected by block->mutex */
 
819
        /* 4. Optimistic search field */
 
820
 
 
821
        dulint          modify_clock;   /* this clock is incremented every
1126
822
                                        time a pointer to a record on the
1127
823
                                        page may become obsolete; this is
1128
824
                                        used in the optimistic cursor
1134
830
                                        bufferfixed, or (2) the thread has an
1135
831
                                        x-latch on the block */
1136
832
 
1137
 
        /* 3. Hash search fields: NOTE that the first 4 fields are NOT
 
833
        /* 5. Hash search fields: NOTE that the first 4 fields are NOT
1138
834
        protected by any semaphore! */
1139
835
 
1140
836
        ulint           n_hash_helps;   /* counter which controls building
1156
852
        An exception to this is when we init or create a page
1157
853
        in the buffer pool in buf0buf.c. */
1158
854
 
1159
 
#ifdef UNIV_DEBUG
1160
 
        ulint           n_pointers;     /* used in debugging: the number of
1161
 
                                        pointers in the adaptive hash index
1162
 
                                        pointing to this frame */
1163
 
#endif /* UNIV_DEBUG */
1164
 
        unsigned        is_hashed:1;    /* TRUE if hash index has already been
 
855
        ibool           is_hashed;      /* TRUE if hash index has already been
1165
856
                                        built on this page; note that it does
1166
857
                                        not guarantee that the index is
1167
858
                                        complete, though: there may have been
1168
859
                                        hash collisions, record deletions,
1169
860
                                        etc. */
1170
 
        unsigned        curr_n_fields:10;/* prefix length for hash indexing:
 
861
        ulint           n_pointers;     /* used in debugging: the number of
 
862
                                        pointers in the adaptive hash index
 
863
                                        pointing to this frame */
 
864
        ulint           curr_n_fields;  /* prefix length for hash indexing:
1171
865
                                        number of full fields */
1172
 
        unsigned        curr_n_bytes:15;/* number of bytes in hash indexing */
1173
 
        unsigned        curr_left_side:1;/* TRUE or FALSE in hash indexing */
 
866
        ulint           curr_n_bytes;   /* number of bytes in hash indexing */
 
867
        ibool           curr_left_side; /* TRUE or FALSE in hash indexing */
1174
868
        dict_index_t*   index;          /* Index for which the adaptive
1175
869
                                        hash index has been created. */
1176
 
        /* 4. Debug fields */
 
870
        /* 6. Debug fields */
1177
871
#ifdef UNIV_SYNC_DEBUG
1178
872
        rw_lock_t       debug_latch;    /* in the debug version, each thread
1179
873
                                        which bufferfixes the block acquires
1180
874
                                        an s-latch here; so we can use the
1181
875
                                        debug utilities in sync0rw */
1182
876
#endif
 
877
        ibool           file_page_was_freed;
 
878
                                        /* this is set to TRUE when fsp
 
879
                                        frees a page in buffer pool */
1183
880
};
1184
881
 
1185
 
/* Check if a buf_block_t object is in a valid state. */
1186
 
#define buf_block_state_valid(block)                            \
1187
 
(buf_block_get_state(block) >= BUF_BLOCK_NOT_USED               \
1188
 
 && (buf_block_get_state(block) <= BUF_BLOCK_REMOVE_HASH))
1189
 
 
1190
 
/**************************************************************************
1191
 
Compute the hash fold value for blocks in buf_pool->zip_hash. */
1192
 
#define BUF_POOL_ZIP_FOLD_PTR(ptr) ((ulint) (ptr) / UNIV_PAGE_SIZE)
1193
 
#define BUF_POOL_ZIP_FOLD(b) BUF_POOL_ZIP_FOLD_PTR((b)->frame)
1194
 
#define BUF_POOL_ZIP_FOLD_BPAGE(b) BUF_POOL_ZIP_FOLD((buf_block_t*) (b))
 
882
#define BUF_BLOCK_MAGIC_N       41526563
1195
883
 
1196
884
/* The buffer pool structure. NOTE! The definition appears here only for
1197
885
other modules of this directory (buf) to see it. Do not use from outside! */
1200
888
 
1201
889
        /* 1. General fields */
1202
890
 
1203
 
        ulint           n_chunks;       /* number of buffer pool chunks */
1204
 
        buf_chunk_t*    chunks;         /* buffer pool chunks */
1205
 
        ulint           curr_size;      /* current pool size in pages */
1206
 
        hash_table_t*   page_hash;      /* hash table of buf_page_t or
1207
 
                                        buf_block_t file pages,
1208
 
                                        buf_page_in_file() == TRUE,
1209
 
                                        indexed by (space_id, offset) */
1210
 
        hash_table_t*   zip_hash;       /* hash table of buf_block_t blocks
1211
 
                                        whose frames are allocated to the
1212
 
                                        zip buddy system,
1213
 
                                        indexed by block->frame */
 
891
        mutex_t         mutex;          /* mutex protecting the buffer pool
 
892
                                        struct and control blocks, except the
 
893
                                        read-write lock in them */
 
894
        byte*           frame_mem;      /* pointer to the memory area which
 
895
                                        was allocated for the frames; in AWE
 
896
                                        this is the virtual address space
 
897
                                        window where we map pages stored
 
898
                                        in physical memory */
 
899
        byte*           frame_zero;     /* pointer to the first buffer frame:
 
900
                                        this may differ from frame_mem, because
 
901
                                        this is aligned by the frame size */
 
902
        byte*           high_end;       /* pointer to the end of the buffer
 
903
                                        frames */
 
904
        ulint           n_frames;       /* number of frames */
 
905
        buf_block_t*    blocks;         /* array of buffer control blocks */
 
906
        buf_block_t**   blocks_of_frames;/* inverse mapping which can be used
 
907
                                        to retrieve the buffer control block
 
908
                                        of a frame; this is an array which
 
909
                                        lists the blocks of frames in the
 
910
                                        order frame_zero,
 
911
                                        frame_zero + UNIV_PAGE_SIZE, ...
 
912
                                        a control block is always assigned
 
913
                                        for each frame, even if the frame does
 
914
                                        not contain any data; note that in AWE
 
915
                                        there are more control blocks than
 
916
                                        buffer frames */
 
917
        os_awe_t*       awe_info;       /* if AWE is used, AWE info for the
 
918
                                        physical 4 kB memory pages associated
 
919
                                        with buffer frames */
 
920
        ulint           max_size;       /* number of control blocks ==
 
921
                                        maximum pool size in pages */
 
922
        ulint           curr_size;      /* current pool size in pages;
 
923
                                        currently always the same as
 
924
                                        max_size */
 
925
        hash_table_t*   page_hash;      /* hash table of the file pages */
 
926
 
1214
927
        ulint           n_pend_reads;   /* number of pending read operations */
1215
 
        ulint           n_pend_unzip;   /* number of pending decompressions */
1216
928
 
1217
929
        time_t          last_printout_time; /* when buf_print was last time
1218
930
                                        called */
1226
938
                                        counted as page gets; this field
1227
939
                                        is NOT protected by the buffer
1228
940
                                        pool mutex */
 
941
        ulint           n_pages_awe_remapped; /* if AWE is enabled, the
 
942
                                        number of remaps of blocks to
 
943
                                        buffer frames */
1229
944
        ulint           n_page_gets_old;/* n_page_gets when buf_print was
1230
945
                                        last time called: used to calculate
1231
946
                                        hit rate */
1234
949
        ulint           n_pages_written_old;/* number write operations */
1235
950
        ulint           n_pages_created_old;/* number of pages created in
1236
951
                                        the pool with no read */
 
952
        ulint           n_pages_awe_remapped_old;
1237
953
        /* 2. Page flushing algorithm fields */
1238
954
 
1239
 
        UT_LIST_BASE_NODE_T(buf_page_t) flush_list;
 
955
        UT_LIST_BASE_NODE_T(buf_block_t) flush_list;
1240
956
                                        /* base node of the modified block
1241
957
                                        list */
1242
 
        ibool           init_flush[BUF_FLUSH_N_TYPES];
 
958
        ibool           init_flush[BUF_FLUSH_LIST + 1];
1243
959
                                        /* this is TRUE when a flush of the
1244
960
                                        given type is being initialized */
1245
 
        ulint           n_flush[BUF_FLUSH_N_TYPES];
 
961
        ulint           n_flush[BUF_FLUSH_LIST + 1];
1246
962
                                        /* this is the number of pending
1247
963
                                        writes in the given flush type */
1248
 
        os_event_t      no_flush[BUF_FLUSH_N_TYPES];
 
964
        os_event_t      no_flush[BUF_FLUSH_LIST + 1];
1249
965
                                        /* this is in the set state when there
1250
966
                                        is no flush batch of the given type
1251
967
                                        running */
1267
983
 
1268
984
        /* 3. LRU replacement algorithm fields */
1269
985
 
1270
 
        UT_LIST_BASE_NODE_T(buf_page_t) free;
1271
 
                                        /* base node of the free block list */
1272
 
        UT_LIST_BASE_NODE_T(buf_page_t) LRU;
 
986
        UT_LIST_BASE_NODE_T(buf_block_t) free;
 
987
                                        /* base node of the free block list;
 
988
                                        in the case of AWE, at the start are
 
989
                                        always free blocks for which the
 
990
                                        physical memory is mapped to a frame */
 
991
        UT_LIST_BASE_NODE_T(buf_block_t) LRU;
1273
992
                                        /* base node of the LRU list */
1274
 
        buf_page_t*     LRU_old;        /* pointer to the about 3/8 oldest
 
993
        buf_block_t*    LRU_old;        /* pointer to the about 3/8 oldest
1275
994
                                        blocks in the LRU list; NULL if LRU
1276
995
                                        length less than BUF_LRU_OLD_MIN_LEN */
1277
996
        ulint           LRU_old_len;    /* length of the LRU list from
1280
999
                                        see buf0lru.c for the restrictions
1281
1000
                                        on this value; not defined if
1282
1001
                                        LRU_old == NULL */
1283
 
 
1284
 
        UT_LIST_BASE_NODE_T(buf_block_t) unzip_LRU;
1285
 
                                        /* base node of the unzip_LRU list */
1286
 
 
1287
 
        /* 4. Fields for the buddy allocator of compressed pages */
1288
 
        UT_LIST_BASE_NODE_T(buf_page_t) zip_clean;
1289
 
                                        /* unmodified compressed pages */
1290
 
        UT_LIST_BASE_NODE_T(buf_page_t) zip_free[BUF_BUDDY_SIZES];
1291
 
                                        /* buddy free lists */
1292
 
#if BUF_BUDDY_HIGH != UNIV_PAGE_SIZE
1293
 
# error "BUF_BUDDY_HIGH != UNIV_PAGE_SIZE"
1294
 
#endif
1295
 
#if BUF_BUDDY_LOW > PAGE_ZIP_MIN_SIZE
1296
 
# error "BUF_BUDDY_LOW > PAGE_ZIP_MIN_SIZE"
1297
 
#endif
 
1002
        UT_LIST_BASE_NODE_T(buf_block_t) awe_LRU_free_mapped;
 
1003
                                        /* list of those blocks which are
 
1004
                                        in the LRU list or the free list, and
 
1005
                                        where the page is mapped to a frame;
 
1006
                                        thus, frames allocated, e.g., to the
 
1007
                                        locki table, are not in this list */
1298
1008
};
1299
1009
 
1300
 
/* mutex protecting the buffer pool struct and control blocks, except the
1301
 
read-write lock in them */
1302
 
extern mutex_t  buf_pool_mutex;
1303
 
/* mutex protecting the control blocks of compressed-only pages
1304
 
(of type buf_page_t, not buf_block_t) */
1305
 
extern mutex_t  buf_pool_zip_mutex;
1306
 
 
1307
 
/* Accessors for buf_pool_mutex.  Use these instead of accessing
1308
 
buf_pool_mutex directly. */
1309
 
 
1310
 
/* Test if buf_pool_mutex is owned. */
1311
 
#define buf_pool_mutex_own() mutex_own(&buf_pool_mutex)
1312
 
/* Acquire the buffer pool mutex. */
1313
 
#define buf_pool_mutex_enter() do {             \
1314
 
        ut_ad(!mutex_own(&buf_pool_zip_mutex)); \
1315
 
        mutex_enter(&buf_pool_mutex);           \
1316
 
} while (0)
1317
 
 
1318
 
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
1319
 
/** Flag to forbid the release of the buffer pool mutex.
1320
 
Protected by buf_pool_mutex. */
1321
 
extern ulint    buf_pool_mutex_exit_forbidden;
1322
 
/* Forbid the release of the buffer pool mutex. */
1323
 
# define buf_pool_mutex_exit_forbid() do {      \
1324
 
        ut_ad(buf_pool_mutex_own());            \
1325
 
        buf_pool_mutex_exit_forbidden++;        \
1326
 
} while (0)
1327
 
/* Allow the release of the buffer pool mutex. */
1328
 
# define buf_pool_mutex_exit_allow() do {       \
1329
 
        ut_ad(buf_pool_mutex_own());            \
1330
 
        ut_a(buf_pool_mutex_exit_forbidden);    \
1331
 
        buf_pool_mutex_exit_forbidden--;        \
1332
 
} while (0)
1333
 
/* Release the buffer pool mutex. */
1334
 
# define buf_pool_mutex_exit() do {             \
1335
 
        ut_a(!buf_pool_mutex_exit_forbidden);   \
1336
 
        mutex_exit(&buf_pool_mutex);            \
1337
 
} while (0)
1338
 
#else
1339
 
/* Forbid the release of the buffer pool mutex. */
1340
 
# define buf_pool_mutex_exit_forbid() ((void) 0)
1341
 
/* Allow the release of the buffer pool mutex. */
1342
 
# define buf_pool_mutex_exit_allow() ((void) 0)
1343
 
/* Release the buffer pool mutex. */
1344
 
# define buf_pool_mutex_exit() mutex_exit(&buf_pool_mutex)
1345
 
#endif
 
1010
/* States of a control block */
 
1011
#define BUF_BLOCK_NOT_USED      211     /* is in the free list */
 
1012
#define BUF_BLOCK_READY_FOR_USE 212     /* when buf_get_free_block returns
 
1013
                                        a block, it is in this state */
 
1014
#define BUF_BLOCK_FILE_PAGE     213     /* contains a buffered file page */
 
1015
#define BUF_BLOCK_MEMORY        214     /* contains some main memory object */
 
1016
#define BUF_BLOCK_REMOVE_HASH   215     /* hash index should be removed
 
1017
                                        before putting to the free list */
 
1018
 
 
1019
/* Io_fix states of a control block; these must be != 0 */
 
1020
#define BUF_IO_READ             561
 
1021
#define BUF_IO_WRITE            562
1346
1022
 
1347
1023
/************************************************************************
1348
1024
Let us list the consistency conditions for different control block states.
1355
1031
                hash table
1356
1032
FILE_PAGE:      space and offset are defined, is in page hash table
1357
1033
                if io_fix == BUF_IO_WRITE,
1358
 
                        pool: no_flush[flush_type] is in reset state,
1359
 
                        pool: n_flush[flush_type] > 0
 
1034
                        pool: no_flush[block->flush_type] is in reset state,
 
1035
                        pool: n_flush[block->flush_type] > 0
1360
1036
 
1361
1037
                (1) if buf_fix_count == 0, then
1362
1038
                        is in LRU list, not in free list