~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "hash0hash.h"
32
32
#include "ut0byte.h"
33
33
#include "os0proc.h"
 
34
#include "page0types.h"
34
35
 
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! */
42
36
/* Modes for buf_page_get_gen */
43
37
#define BUF_GET                 10      /* get always */
44
38
#define BUF_GET_IF_IN_POOL      11      /* get if in pool */
61
55
                                        prints info whenever read or flush
62
56
                                        occurs */
63
57
#endif /* UNIV_DEBUG */
64
 
extern ulint srv_buf_pool_write_requests; /* variable to count write request
65
 
                                          issued */
 
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
};
66
78
 
67
79
/************************************************************************
68
80
Creates the buffer pool. */
69
 
 
 
81
UNIV_INTERN
70
82
buf_pool_t*
71
 
buf_pool_init(
72
 
/*==========*/
 
83
buf_pool_init(void);
 
84
/*===============*/
73
85
                                /* out, own: buf_pool object, NULL if not
74
86
                                enough memory or error */
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 */
 
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
/*=================*/
85
114
/*************************************************************************
86
 
Gets the current size of buffer buf_pool in bytes. In the case of AWE, the
87
 
size of AWE window (= the frames). */
 
115
Gets the current size of buffer buf_pool in bytes. */
88
116
UNIV_INLINE
89
117
ulint
90
118
buf_pool_get_curr_size(void);
91
119
/*========================*/
92
120
                        /* 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 */
101
121
/************************************************************************
102
122
Gets the smallest oldest_modification lsn for any page in the pool. Returns
103
 
ut_dulint_zero if all modified pages have been flushed to disk. */
 
123
zero if all modified pages have been flushed to disk. */
104
124
UNIV_INLINE
105
 
dulint
 
125
ib_uint64_t
106
126
buf_pool_get_oldest_modification(void);
107
127
/*==================================*/
108
128
                                /* out: oldest modification in pool,
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
 
 
 
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
120
143
void
121
 
buf_frame_free(
 
144
buf_block_free(
122
145
/*===========*/
123
 
        buf_frame_t*    frame); /* in: buffer frame */
 
146
        buf_block_t*    block); /* in, own: block to be freed */
124
147
/*************************************************************************
125
148
Copies contents of a buffer frame to a given buffer. */
126
149
UNIV_INLINE
127
150
byte*
128
151
buf_frame_copy(
129
152
/*===========*/
130
 
                                /* out: buf */
131
 
        byte*           buf,    /* in: buffer to copy to */
132
 
        buf_frame_t*    frame); /* in: buffer frame */
 
153
                                        /* out: buf */
 
154
        byte*                   buf,    /* in: buffer to copy to */
 
155
        const buf_frame_t*      frame); /* in: buffer frame */
133
156
/******************************************************************
134
157
NOTE! The following macros should be used instead of buf_page_get_gen,
135
158
to improve debugging. Only values RW_S_LATCH and RW_X_LATCH are allowed
136
159
in LA! */
137
 
#define buf_page_get(SP, OF, LA, MTR)    buf_page_get_gen(\
138
 
                                SP, OF, LA, NULL,\
 
160
#define buf_page_get(SP, ZS, OF, LA, MTR)        buf_page_get_gen(\
 
161
                                SP, ZS, OF, LA, NULL,\
139
162
                                BUF_GET, __FILE__, __LINE__, MTR)
140
163
/******************************************************************
141
164
Use these macros to bufferfix a page with no latching. Remember not to
143
166
the contents of the page! We have separated this case, because it is
144
167
error-prone programming not to set a latch, and it should be used
145
168
with care. */
146
 
#define buf_page_get_with_no_latch(SP, OF, MTR)    buf_page_get_gen(\
147
 
                                SP, OF, RW_NO_LATCH, NULL,\
 
169
#define buf_page_get_with_no_latch(SP, ZS, OF, MTR)        buf_page_get_gen(\
 
170
                                SP, ZS, OF, RW_NO_LATCH, NULL,\
148
171
                                BUF_GET_NO_LATCH, __FILE__, __LINE__, MTR)
149
172
/******************************************************************
150
173
NOTE! The following macros should be used instead of buf_page_get_gen, to
151
174
improve debugging. Only values RW_S_LATCH and RW_X_LATCH are allowed as LA! */
152
 
#define buf_page_get_nowait(SP, OF, LA, MTR)    buf_page_get_gen(\
153
 
                                SP, OF, LA, NULL,\
 
175
#define buf_page_get_nowait(SP, ZS, OF, LA, MTR)        buf_page_get_gen(\
 
176
                                SP, ZS, OF, LA, NULL,\
154
177
                                BUF_GET_NOWAIT, __FILE__, __LINE__, MTR)
155
178
/******************************************************************
156
179
NOTE! The following macros should be used instead of
157
180
buf_page_optimistic_get_func, to improve debugging. Only values RW_S_LATCH and
158
181
RW_X_LATCH are allowed as LA! */
159
 
#define buf_page_optimistic_get(LA, BL, G, MC, MTR)                          \
160
 
        buf_page_optimistic_get_func(LA, BL, G, MC, __FILE__, __LINE__, MTR)
 
182
#define buf_page_optimistic_get(LA, BL, MC, MTR)                             \
 
183
        buf_page_optimistic_get_func(LA, BL, MC, __FILE__, __LINE__, MTR)
161
184
/************************************************************************
162
185
This is the general function used to get optimistic access to a database
163
186
page. */
164
 
 
 
187
UNIV_INTERN
165
188
ibool
166
189
buf_page_optimistic_get_func(
167
190
/*=========================*/
168
191
                                /* out: TRUE if success */
169
192
        ulint           rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */
170
193
        buf_block_t*    block,  /* in: guessed block */
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
 
194
        ib_uint64_t     modify_clock,/* in: modify clock value if mode is
174
195
                                ..._GUESS_ON_CLOCK */
175
196
        const char*     file,   /* in: file name */
176
197
        ulint           line,   /* in: line where called */
177
198
        mtr_t*          mtr);   /* in: mini-transaction */
178
199
/************************************************************************
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
 
/************************************************************************
198
200
This is used to get access to a known database page, when no waiting can be
199
201
done. */
200
 
 
 
202
UNIV_INTERN
201
203
ibool
202
204
buf_page_get_known_nowait(
203
205
/*======================*/
204
206
                                /* out: TRUE if success */
205
207
        ulint           rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */
206
 
        buf_frame_t*    guess,  /* in: the known page frame */
 
208
        buf_block_t*    block,  /* in: the known page */
207
209
        ulint           mode,   /* in: BUF_MAKE_YOUNG or BUF_KEEP_OLD */
208
210
        const char*     file,   /* in: file name */
209
211
        ulint           line,   /* in: line where called */
210
212
        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 */
211
248
/************************************************************************
212
249
This is the general function used to get access to a database page. */
213
 
 
214
 
buf_frame_t*
 
250
UNIV_INTERN
 
251
buf_block_t*
215
252
buf_page_get_gen(
216
253
/*=============*/
217
 
                                /* out: pointer to the frame or NULL */
 
254
                                /* out: pointer to the block or NULL */
218
255
        ulint           space,  /* in: space id */
 
256
        ulint           zip_size,/* in: compressed page size in bytes
 
257
                                or 0 for uncompressed pages */
219
258
        ulint           offset, /* in: page number */
220
259
        ulint           rw_latch,/* in: RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
221
 
        buf_frame_t*    guess,  /* in: guessed frame or NULL */
 
260
        buf_block_t*    guess,  /* in: guessed block or NULL */
222
261
        ulint           mode,   /* in: BUF_GET, BUF_GET_IF_IN_POOL,
223
262
                                BUF_GET_NO_LATCH */
224
263
        const char*     file,   /* in: file name */
228
267
Initializes a page to the buffer buf_pool. The page is usually not read
229
268
from a file even if it cannot be found in the buffer buf_pool. This is one
230
269
of the functions which perform to a block a state transition NOT_USED =>
231
 
FILE_PAGE (the other is buf_page_init_for_read above). */
232
 
 
233
 
buf_frame_t*
 
270
FILE_PAGE (the other is buf_page_get_gen). */
 
271
UNIV_INTERN
 
272
buf_block_t*
234
273
buf_page_create(
235
274
/*============*/
236
 
                        /* out: pointer to the frame, page bufferfixed */
 
275
                        /* out: pointer to the block, page bufferfixed */
237
276
        ulint   space,  /* in: space id */
238
277
        ulint   offset, /* in: offset of the page within space in units of
239
278
                        a page */
 
279
        ulint   zip_size,/* in: compressed page size, or 0 */
240
280
        mtr_t*  mtr);   /* in: mini-transaction handle */
 
281
#ifdef UNIV_HOTBACKUP
241
282
/************************************************************************
242
283
Inits a page to the buffer buf_pool, for use in ibbackup --restore. */
243
 
 
 
284
UNIV_INTERN
244
285
void
245
286
buf_page_init_for_backup_restore(
246
287
/*=============================*/
247
288
        ulint           space,  /* in: space id */
248
289
        ulint           offset, /* in: offset of the page within space
249
290
                                in units of a page */
 
291
        ulint           zip_size,/* in: compressed page size in bytes
 
292
                                or 0 for uncompressed pages */
250
293
        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 */
251
302
/************************************************************************
252
303
Decrements the bufferfix count of a buffer control block and releases
253
304
a latch, if specified. */
263
314
Moves a page to the start of the buffer pool LRU list. This high-level
264
315
function can be used to prevent an important page from from slipping out of
265
316
the buffer pool. */
266
 
 
 
317
UNIV_INTERN
267
318
void
268
319
buf_page_make_young(
269
320
/*================*/
270
 
        buf_frame_t*    frame); /* in: buffer frame of a file page */
 
321
        buf_page_t*     bpage); /* in: buffer block of a file page */
271
322
/************************************************************************
272
323
Returns TRUE if the page can be found in the buffer pool hash table. NOTE
273
324
that it is possible that the page is not yet read from disk, though. */
274
 
 
 
325
UNIV_INLINE
275
326
ibool
276
327
buf_page_peek(
277
328
/*==========*/
281
332
        ulint   space,  /* in: space id */
282
333
        ulint   offset);/* in: page number */
283
334
/************************************************************************
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
 
/************************************************************************
297
335
Resets the check_index_page_at_flush field of a page if found in the buffer
298
336
pool. */
299
 
 
 
337
UNIV_INTERN
300
338
void
301
339
buf_reset_check_index_page_at_flush(
302
340
/*================================*/
303
341
        ulint   space,  /* in: space id */
304
342
        ulint   offset);/* in: page number */
 
343
#ifdef UNIV_DEBUG_FILE_ACCESSES
305
344
/************************************************************************
306
345
Sets file_page_was_freed TRUE if the page is found in the buffer pool.
307
346
This function should be called when we free a file page and want the
308
347
debug version to check that it is not accessed any more unless
309
348
reallocated. */
310
 
 
311
 
buf_block_t*
 
349
UNIV_INTERN
 
350
buf_page_t*
312
351
buf_page_set_file_page_was_freed(
313
352
/*=============================*/
314
 
                        /* out: control block if found from page hash table,
 
353
                        /* out: control block if found in page hash table,
315
354
                        otherwise NULL */
316
355
        ulint   space,  /* in: space id */
317
 
        ulint   offset);        /* in: page number */
 
356
        ulint   offset);/* in: page number */
318
357
/************************************************************************
319
358
Sets file_page_was_freed FALSE if the page is found in the buffer pool.
320
359
This function should be called when we free a file page and want the
321
360
debug version to check that it is not accessed any more unless
322
361
reallocated. */
323
 
 
324
 
buf_block_t*
 
362
UNIV_INTERN
 
363
buf_page_t*
325
364
buf_page_reset_file_page_was_freed(
326
365
/*===============================*/
327
 
                        /* out: control block if found from page hash table,
 
366
                        /* out: control block if found in page hash table,
328
367
                        otherwise NULL */
329
368
        ulint   space,  /* in: space id */
330
369
        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
 
331
390
/************************************************************************
332
391
Recommends a move of a block to the start of the LRU list if there is danger
333
392
of dropping from the buffer pool. NOTE: does not reserve the buffer pool
334
393
mutex. */
335
394
UNIV_INLINE
336
395
ibool
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 */
 
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 */
341
401
/************************************************************************
342
402
Returns the current state of is_hashed of a page. FALSE if the page is
343
403
not in the pool. NOTE that this operation does not fix the page in the
344
404
pool if it is found there. */
345
 
 
 
405
UNIV_INTERN
346
406
ibool
347
407
buf_page_peek_if_search_hashed(
348
408
/*===========================*/
354
414
Gets the youngest modification log sequence number for a frame.
355
415
Returns zero if not file page or no modification occurred yet. */
356
416
UNIV_INLINE
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 */
 
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 */
372
423
/************************************************************************
373
424
Increments the modify clock of a frame by 1. The caller must (1) own the
374
425
buf_pool mutex and block bufferfix count has to be zero, (2) or own an x-lock
375
426
on the block. */
376
427
UNIV_INLINE
377
 
dulint
 
428
void
378
429
buf_block_modify_clock_inc(
379
430
/*=======================*/
380
 
                                /* out: new value */
381
431
        buf_block_t*    block); /* in: block */
382
432
/************************************************************************
383
433
Returns the value of the modify clock. The caller must have an s-lock
384
434
or x-lock on the block. */
385
435
UNIV_INLINE
386
 
dulint
 
436
ib_uint64_t
387
437
buf_block_get_modify_clock(
388
438
/*=======================*/
389
439
                                /* out: value */
392
442
Calculates a page checksum which is stored to the page when it is written
393
443
to a file. Note that we must be careful to calculate the same value
394
444
on 32-bit and 64-bit architectures. */
395
 
 
 
445
UNIV_INTERN
396
446
ulint
397
447
buf_calc_page_new_checksum(
398
448
/*=======================*/
399
 
                        /* out: checksum */
400
 
        byte*   page);  /* in: buffer page */
 
449
                                /* out: checksum */
 
450
        const byte*     page);  /* in: buffer page */
401
451
/************************************************************************
402
452
In versions < 4.0.14 and < 4.1.1 there was a bug that the checksum only
403
453
looked at the first few bytes of the page. This calculates that old
405
455
NOTE: we must first store the new formula checksum to
406
456
FIL_PAGE_SPACE_OR_CHKSUM before calculating and storing this old checksum
407
457
because this takes that field as an input! */
408
 
 
 
458
UNIV_INTERN
409
459
ulint
410
460
buf_calc_page_old_checksum(
411
461
/*=======================*/
412
 
                        /* out: checksum */
413
 
        byte*    page); /* in: buffer page */
 
462
                                /* out: checksum */
 
463
        const byte*      page); /* in: buffer page */
414
464
/************************************************************************
415
465
Checks if a page is corrupt. */
416
 
 
 
466
UNIV_INTERN
417
467
ibool
418
468
buf_page_is_corrupted(
419
469
/*==================*/
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 */
 
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 */
440
474
/**************************************************************************
441
475
Gets the space id, page offset, and byte offset within page of a
442
476
pointer pointing to a buffer frame containing a file page. */
444
478
void
445
479
buf_ptr_get_fsp_addr(
446
480
/*=================*/
447
 
        byte*           ptr,    /* in: pointer to a buffer frame */
 
481
        const void*     ptr,    /* in: pointer to a buffer frame */
448
482
        ulint*          space,  /* out: space id */
449
483
        fil_addr_t*     addr);  /* out: page offset and byte offset */
450
484
/**************************************************************************
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. */
 
485
Gets the hash value of a block. This can be used in searches in the
 
486
lock hash table. */
453
487
UNIV_INLINE
454
488
ulint
455
 
buf_frame_get_lock_hash_val(
 
489
buf_block_get_lock_hash_val(
456
490
/*========================*/
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 */
 
491
                                        /* out: lock hash value */
 
492
        const buf_block_t*      block)  /* in: block */
 
493
        __attribute__((pure));
485
494
#ifdef UNIV_DEBUG
486
495
/*************************************************************************
 
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
/*************************************************************************
487
508
Validates the buffer pool data structure. */
488
 
 
 
509
UNIV_INTERN
489
510
ibool
490
511
buf_validate(void);
491
512
/*==============*/
 
513
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
 
514
#if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
492
515
/*************************************************************************
493
516
Prints info of the buffer pool data structure. */
494
 
 
 
517
UNIV_INTERN
495
518
void
496
519
buf_print(void);
497
520
/*============*/
498
 
#endif /* UNIV_DEBUG */
 
521
#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
499
522
/************************************************************************
500
523
Prints a page to stderr. */
501
 
 
 
524
UNIV_INTERN
502
525
void
503
526
buf_page_print(
504
527
/*===========*/
505
 
        byte*   read_buf);      /* in: a database page */
 
528
        const byte*     read_buf,       /* in: a database page */
 
529
        ulint           zip_size);      /* in: compressed page size, or
 
530
                                        0 for uncompressed pages */
506
531
/*************************************************************************
507
532
Returns the number of latched pages in the buffer pool. */
508
 
 
 
533
UNIV_INTERN
509
534
ulint
510
535
buf_get_latched_pages_number(void);
511
536
/*==============================*/
512
537
/*************************************************************************
513
538
Returns the number of pending buf pool ios. */
514
 
 
 
539
UNIV_INTERN
515
540
ulint
516
541
buf_get_n_pending_ios(void);
517
542
/*=======================*/
518
543
/*************************************************************************
519
544
Prints info of the buffer i/o. */
520
 
 
 
545
UNIV_INTERN
521
546
void
522
547
buf_print_io(
523
548
/*=========*/
525
550
/*************************************************************************
526
551
Returns the ratio in percents of modified pages in the buffer pool /
527
552
database pages in the buffer pool. */
528
 
 
 
553
UNIV_INTERN
529
554
ulint
530
555
buf_get_modified_ratio_pct(void);
531
556
/*============================*/
532
557
/**************************************************************************
533
558
Refreshes the statistics used to print per-second averages. */
534
 
 
 
559
UNIV_INTERN
535
560
void
536
561
buf_refresh_io_stats(void);
537
562
/*======================*/
538
563
/*************************************************************************
539
564
Checks that all file pages in the buffer are in a replaceable state. */
540
 
 
 
565
UNIV_INTERN
541
566
ibool
542
567
buf_all_freed(void);
543
568
/*===============*/
544
569
/*************************************************************************
545
570
Checks that there currently are no pending i/o-operations for the buffer
546
571
pool. */
547
 
 
 
572
UNIV_INTERN
548
573
ibool
549
574
buf_pool_check_no_pending_io(void);
550
575
/*==============================*/
553
578
Invalidates the file pages in the buffer pool when an archive recovery is
554
579
completed. All the file pages buffered must be in a replaceable state when
555
580
this function is called: not latched and not modified. */
556
 
 
 
581
UNIV_INTERN
557
582
void
558
583
buf_pool_invalidate(void);
559
584
/*=====================*/
562
587
--------------------------- LOWER LEVEL ROUTINES -------------------------
563
588
=========================================================================*/
564
589
 
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 */
578
590
#ifdef UNIV_SYNC_DEBUG
579
591
/*************************************************************************
580
592
Adds latch level info for the rw-lock protecting the buffer frame. This
582
594
page if we know the latching order level of the acquired latch. */
583
595
UNIV_INLINE
584
596
void
585
 
buf_page_dbg_add_level(
586
 
/*===================*/
587
 
        buf_frame_t*    frame,  /* in: buffer page where we have acquired
588
 
                                a latch */
 
597
buf_block_dbg_add_level(
 
598
/*====================*/
 
599
        buf_block_t*    block,  /* in: buffer page
 
600
                                where we have acquired latch */
589
601
        ulint           level); /* in: latching order level */
590
602
#endif /* UNIV_SYNC_DEBUG */
591
603
/*************************************************************************
 
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
/*************************************************************************
592
793
Gets a pointer to the memory frame of a block. */
593
794
UNIV_INLINE
594
795
buf_frame_t*
595
796
buf_block_get_frame(
596
797
/*================*/
597
 
                                /* out: pointer to the frame */
598
 
        buf_block_t*    block); /* in: pointer to the control block */
 
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));
599
813
/*************************************************************************
600
814
Gets the space id of a block. */
601
815
UNIV_INLINE
602
816
ulint
603
817
buf_block_get_space(
604
818
/*================*/
605
 
                                /* out: space id */
606
 
        buf_block_t*    block); /* in: pointer to the control block */
 
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));
607
831
/*************************************************************************
608
832
Gets the page number of a block. */
609
833
UNIV_INLINE
610
834
ulint
611
835
buf_block_get_page_no(
612
836
/*==================*/
613
 
                                /* out: page number */
614
 
        buf_block_t*    block); /* in: pointer to the control block */
 
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
615
864
/***********************************************************************
616
865
Gets the block to whose frame the pointer is pointing to. */
617
866
UNIV_INLINE
618
 
buf_block_t*
 
867
const buf_block_t*
619
868
buf_block_align(
620
869
/*============*/
621
 
                        /* out: pointer to block */
622
 
        byte*   ptr);   /* in: pointer to a frame */
 
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 */
623
882
/************************************************************************
624
883
This function is used to get info if there is an io operation
625
884
going on on a buffer page. */
628
887
buf_page_io_query(
629
888
/*==============*/
630
889
                                /* out: TRUE if io going on */
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 */
 
890
        buf_page_t*     bpage); /* in: pool block, must be bufferfixed */
641
891
/************************************************************************
642
892
Function which inits a page for read to the buffer buf_pool. If the page is
643
893
(1) already in buf_pool, or
646
896
then this function does nothing.
647
897
Sets the io_fix flag to BUF_IO_READ and sets a non-recursive exclusive lock
648
898
on the buffer frame. The io-handler must take care that the flag is cleared
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*
 
899
and the lock released later. */
 
900
UNIV_INTERN
 
901
buf_page_t*
654
902
buf_page_init_for_read(
655
903
/*===================*/
656
904
                                /* out: pointer to the block or NULL */
657
905
        ulint*          err,    /* out: DB_SUCCESS or DB_TABLESPACE_DELETED */
658
906
        ulint           mode,   /* in: BUF_READ_IBUF_PAGES_ONLY, ... */
659
907
        ulint           space,  /* in: space id */
660
 
        ib_longlong     tablespace_version,/* in: prevents reading from a wrong
 
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
661
911
                                version of the tablespace in case we have done
662
912
                                DISCARD + IMPORT */
663
913
        ulint           offset);/* in: page number */
664
914
/************************************************************************
665
915
Completes an asynchronous read or write request of a file page to or from
666
916
the buffer pool. */
667
 
 
 
917
UNIV_INTERN
668
918
void
669
919
buf_page_io_complete(
670
920
/*=================*/
671
 
        buf_block_t*    block); /* in: pointer to the block in question */
 
921
        buf_page_t*     bpage); /* in: pointer to the block in question */
672
922
/************************************************************************
673
923
Calculates a folded value of a file page address to use in the page hash
674
924
table. */
678
928
/*==================*/
679
929
                        /* out: the folded value */
680
930
        ulint   space,  /* in: space id */
681
 
        ulint   offset);/* in: offset of the page within space */
 
931
        ulint   offset) /* in: offset of the page within space */
 
932
        __attribute__((__const__));
682
933
/**********************************************************************
683
934
Returns the control block of a file page, NULL if not found. */
684
935
UNIV_INLINE
685
 
buf_block_t*
 
936
buf_page_t*
686
937
buf_page_hash_get(
687
938
/*==============*/
688
939
                        /* out: block, NULL if not found */
689
940
        ulint   space,  /* in: space id */
690
941
        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 */
691
952
/***********************************************************************
692
953
Increments the pool clock by one and returns its new value. Remember that
693
954
in the 32 bit version the clock wraps around at 4 billion! */
698
959
                        /* out: new clock value */
699
960
/*************************************************************************
700
961
Gets the current length of the free list of buffer blocks. */
701
 
 
 
962
UNIV_INTERN
702
963
ulint
703
964
buf_get_free_list_len(void);
704
965
/*=======================*/
705
966
 
706
967
 
707
968
 
 
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
 
708
1080
/* The buffer control block structure */
709
1081
 
710
1082
struct buf_block_struct{
711
1083
 
712
1084
        /* 1. General fields */
713
1085
 
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 */
 
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 */
720
1100
        byte*           frame;          /* pointer to buffer frame which
721
1101
                                        is of size UNIV_PAGE_SIZE, and
722
1102
                                        aligned to an address divisible by
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 */
 
1103
                                        UNIV_PAGE_SIZE */
737
1104
        mutex_t         mutex;          /* mutex protecting this block:
738
1105
                                        state (also protected by the buffer
739
1106
                                        pool mutex), io_fix, buf_fix_count,
742
1109
                                        contention on the buffer pool mutex */
743
1110
        rw_lock_t       lock;           /* read-write lock of the buffer
744
1111
                                        frame */
745
 
        buf_block_t*    hash;           /* node used in chaining to the page
746
 
                                        hash table */
747
 
        ibool           check_index_page_at_flush;
 
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;
748
1115
                                        /* TRUE if we know that this is
749
1116
                                        an index page, and want the database
750
1117
                                        to check its consistency before flush;
752
1119
                                        buffer pool which are index pages,
753
1120
                                        but this flag is not set because
754
1121
                                        we do not keep track of all pages */
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
 
1122
 
 
1123
        /* 2. Optimistic search field */
 
1124
 
 
1125
        ib_uint64_t     modify_clock;   /* this clock is incremented every
822
1126
                                        time a pointer to a record on the
823
1127
                                        page may become obsolete; this is
824
1128
                                        used in the optimistic cursor
830
1134
                                        bufferfixed, or (2) the thread has an
831
1135
                                        x-latch on the block */
832
1136
 
833
 
        /* 5. Hash search fields: NOTE that the first 4 fields are NOT
 
1137
        /* 3. Hash search fields: NOTE that the first 4 fields are NOT
834
1138
        protected by any semaphore! */
835
1139
 
836
1140
        ulint           n_hash_helps;   /* counter which controls building
852
1156
        An exception to this is when we init or create a page
853
1157
        in the buffer pool in buf0buf.c. */
854
1158
 
855
 
        ibool           is_hashed;      /* TRUE if hash index has already been
 
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
856
1165
                                        built on this page; note that it does
857
1166
                                        not guarantee that the index is
858
1167
                                        complete, though: there may have been
859
1168
                                        hash collisions, record deletions,
860
1169
                                        etc. */
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:
 
1170
        unsigned        curr_n_fields:10;/* prefix length for hash indexing:
865
1171
                                        number of full fields */
866
 
        ulint           curr_n_bytes;   /* number of bytes in hash indexing */
867
 
        ibool           curr_left_side; /* TRUE or FALSE in hash indexing */
 
1172
        unsigned        curr_n_bytes:15;/* number of bytes in hash indexing */
 
1173
        unsigned        curr_left_side:1;/* TRUE or FALSE in hash indexing */
868
1174
        dict_index_t*   index;          /* Index for which the adaptive
869
1175
                                        hash index has been created. */
870
 
        /* 6. Debug fields */
 
1176
        /* 4. Debug fields */
871
1177
#ifdef UNIV_SYNC_DEBUG
872
1178
        rw_lock_t       debug_latch;    /* in the debug version, each thread
873
1179
                                        which bufferfixes the block acquires
874
1180
                                        an s-latch here; so we can use the
875
1181
                                        debug utilities in sync0rw */
876
1182
#endif
877
 
        ibool           file_page_was_freed;
878
 
                                        /* this is set to TRUE when fsp
879
 
                                        frees a page in buffer pool */
880
1183
};
881
1184
 
882
 
#define BUF_BLOCK_MAGIC_N       41526563
 
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))
883
1195
 
884
1196
/* The buffer pool structure. NOTE! The definition appears here only for
885
1197
other modules of this directory (buf) to see it. Do not use from outside! */
888
1200
 
889
1201
        /* 1. General fields */
890
1202
 
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
 
 
 
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 */
927
1214
        ulint           n_pend_reads;   /* number of pending read operations */
 
1215
        ulint           n_pend_unzip;   /* number of pending decompressions */
928
1216
 
929
1217
        time_t          last_printout_time; /* when buf_print was last time
930
1218
                                        called */
938
1226
                                        counted as page gets; this field
939
1227
                                        is NOT protected by the buffer
940
1228
                                        pool mutex */
941
 
        ulint           n_pages_awe_remapped; /* if AWE is enabled, the
942
 
                                        number of remaps of blocks to
943
 
                                        buffer frames */
944
1229
        ulint           n_page_gets_old;/* n_page_gets when buf_print was
945
1230
                                        last time called: used to calculate
946
1231
                                        hit rate */
949
1234
        ulint           n_pages_written_old;/* number write operations */
950
1235
        ulint           n_pages_created_old;/* number of pages created in
951
1236
                                        the pool with no read */
952
 
        ulint           n_pages_awe_remapped_old;
953
1237
        /* 2. Page flushing algorithm fields */
954
1238
 
955
 
        UT_LIST_BASE_NODE_T(buf_block_t) flush_list;
 
1239
        UT_LIST_BASE_NODE_T(buf_page_t) flush_list;
956
1240
                                        /* base node of the modified block
957
1241
                                        list */
958
 
        ibool           init_flush[BUF_FLUSH_LIST + 1];
 
1242
        ibool           init_flush[BUF_FLUSH_N_TYPES];
959
1243
                                        /* this is TRUE when a flush of the
960
1244
                                        given type is being initialized */
961
 
        ulint           n_flush[BUF_FLUSH_LIST + 1];
 
1245
        ulint           n_flush[BUF_FLUSH_N_TYPES];
962
1246
                                        /* this is the number of pending
963
1247
                                        writes in the given flush type */
964
 
        os_event_t      no_flush[BUF_FLUSH_LIST + 1];
 
1248
        os_event_t      no_flush[BUF_FLUSH_N_TYPES];
965
1249
                                        /* this is in the set state when there
966
1250
                                        is no flush batch of the given type
967
1251
                                        running */
983
1267
 
984
1268
        /* 3. LRU replacement algorithm fields */
985
1269
 
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;
 
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;
992
1273
                                        /* base node of the LRU list */
993
 
        buf_block_t*    LRU_old;        /* pointer to the about 3/8 oldest
 
1274
        buf_page_t*     LRU_old;        /* pointer to the about 3/8 oldest
994
1275
                                        blocks in the LRU list; NULL if LRU
995
1276
                                        length less than BUF_LRU_OLD_MIN_LEN */
996
1277
        ulint           LRU_old_len;    /* length of the LRU list from
999
1280
                                        see buf0lru.c for the restrictions
1000
1281
                                        on this value; not defined if
1001
1282
                                        LRU_old == NULL */
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 */
 
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
1008
1298
};
1009
1299
 
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
 
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
1022
1346
 
1023
1347
/************************************************************************
1024
1348
Let us list the consistency conditions for different control block states.
1031
1355
                hash table
1032
1356
FILE_PAGE:      space and offset are defined, is in page hash table
1033
1357
                if io_fix == BUF_IO_WRITE,
1034
 
                        pool: no_flush[block->flush_type] is in reset state,
1035
 
                        pool: n_flush[block->flush_type] > 0
 
1358
                        pool: no_flush[flush_type] is in reset state,
 
1359
                        pool: n_flush[flush_type] > 0
1036
1360
 
1037
1361
                (1) if buf_fix_count == 0, then
1038
1362
                        is in LRU list, not in free list