30
27
#include "fil0fil.h"
31
28
#include "mtr0types.h"
32
29
#include "buf0types.h"
33
31
#include "hash0hash.h"
34
32
#include "ut0byte.h"
35
34
#include "page0types.h"
36
#ifndef UNIV_HOTBACKUP
40
/** @name Modes for buf_page_get_gen */
42
#define BUF_GET 10 /*!< get always */
43
#define BUF_GET_IF_IN_POOL 11 /*!< get if in pool */
44
#define BUF_GET_NO_LATCH 14 /*!< get and bufferfix, but
46
separated this case, because
47
it is error-prone programming
48
not to set a latch, and it
49
should be used with care */
50
#define BUF_GET_IF_IN_POOL_OR_WATCH 15
51
/*!< Get the page only if it's in the
52
buffer pool, if not then set a watch
55
/** @name Modes for buf_page_get_known_nowait */
57
#define BUF_MAKE_YOUNG 51 /*!< Move the block to the
58
start of the LRU list if there
59
is a danger that the block
60
would drift out of the buffer
62
#define BUF_KEEP_OLD 52 /*!< Preserve the current LRU
63
position of the block. */
66
#define MAX_BUFFER_POOLS 64 /*!< The maximum number of buffer
67
pools that can be defined */
69
#define BUF_POOL_WATCH_SIZE 1 /*!< Maximum number of concurrent
70
buffer pool watches */
72
extern buf_pool_t* buf_pool_ptr[MAX_BUFFER_POOLS]; /*!< The buffer pools
36
/* Modes for buf_page_get_gen */
37
#define BUF_GET 10 /* get always */
38
#define BUF_GET_IF_IN_POOL 11 /* get if in pool */
39
#define BUF_GET_NOWAIT 12 /* get if can set the latch without
41
#define BUF_GET_NO_LATCH 14 /* get and bufferfix, but set no latch;
42
we have separated this case, because
43
it is error-prone programming not to
44
set a latch, and it should be used
46
/* Modes for buf_page_get_known_nowait */
47
#define BUF_MAKE_YOUNG 51
48
#define BUF_KEEP_OLD 52
49
/* Magic value to use instead of checksums when they are disabled */
50
#define BUF_NO_CHECKSUM_MAGIC 0xDEADBEEFUL
52
extern buf_pool_t* buf_pool; /* The buffer pool of the database */
75
extern ibool buf_debug_prints;/*!< If this is set TRUE, the program
54
extern ibool buf_debug_prints;/* If this is set TRUE, the program
76
55
prints info whenever read or flush
78
57
#endif /* UNIV_DEBUG */
79
#else /* !UNIV_HOTBACKUP */
80
extern buf_block_t* back_block1; /*!< first block, for --apply-log */
81
extern buf_block_t* back_block2; /*!< second block, for page reorganize */
82
#endif /* !UNIV_HOTBACKUP */
84
/** Magic value to use instead of checksums when they are disabled */
85
#define BUF_NO_CHECKSUM_MAGIC 0xDEADBEEFUL
87
/** @brief States of a control block
59
/* States of a control block (@see buf_page_struct).
90
60
The enumeration values must be 0..7. */
91
61
enum buf_page_state {
92
BUF_BLOCK_ZIP_FREE = 0, /*!< contains a free
94
BUF_BLOCK_POOL_WATCH = 0, /*!< a sentinel for the buffer pool
95
watch, element of buf_pool_watch[] */
96
BUF_BLOCK_ZIP_PAGE, /*!< contains a clean
98
BUF_BLOCK_ZIP_DIRTY, /*!< contains a compressed
100
buf_pool->flush_list */
102
BUF_BLOCK_NOT_USED, /*!< is in the free list;
103
must be after the BUF_BLOCK_ZIP_
104
constants for compressed-only pages
105
@see buf_block_state_valid() */
106
BUF_BLOCK_READY_FOR_USE, /*!< when buf_LRU_get_free_block
107
returns a block, it is in this state */
108
BUF_BLOCK_FILE_PAGE, /*!< contains a buffered file page */
109
BUF_BLOCK_MEMORY, /*!< contains some main memory
111
BUF_BLOCK_REMOVE_HASH /*!< hash index should be removed
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 */
67
/* The constants for compressed-only pages must precede
68
BUF_BLOCK_NOT_USED; @see buf_block_state_valid() */
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
112
76
before putting to the free list */
115
#ifndef UNIV_HOTBACKUP
116
/********************************************************************//**
117
Acquire mutex on all buffer pool instances */
120
buf_pool_mutex_enter_all(void);
121
/*===========================*/
123
/********************************************************************//**
124
Release mutex on all buffer pool instances */
127
buf_pool_mutex_exit_all(void);
128
/*==========================*/
130
/********************************************************************//**
131
Creates the buffer pool.
132
@return own: buf_pool object, NULL if not enough memory or error */
79
/************************************************************************
80
Creates the buffer pool. */
137
ulint size, /*!< in: Size of the total pool in bytes */
138
ulint n_instances); /*!< in: Number of instances */
139
/********************************************************************//**
85
/* out, own: buf_pool object, NULL if not
86
enough memory or error */
87
/************************************************************************
140
88
Frees the buffer pool at shutdown. This must not be invoked before
141
89
freeing all mutexes. */
146
ulint n_instances); /*!< in: numbere of instances to free */
148
/********************************************************************//**
149
Drops the adaptive hash index. To prevent a livelock, this function
150
is only to be called while holding btr_search_latch and while
151
btr_search_enabled == FALSE. */
154
buf_pool_drop_hash_index(void);
155
/*==========================*/
157
/********************************************************************//**
95
/************************************************************************
158
96
Relocate a buffer control block. Relocates the block on the LRU list
159
97
and in buf_pool->page_hash. Does not relocate bpage->list.
160
98
The caller must take care of relocating bpage->list. */
239
169
#define buf_page_get_with_no_latch(SP, ZS, OF, MTR) buf_page_get_gen(\
240
170
SP, ZS, OF, RW_NO_LATCH, NULL,\
241
171
BUF_GET_NO_LATCH, __FILE__, __LINE__, MTR)
242
/********************************************************************//**
172
/******************************************************************
173
NOTE! The following macros should be used instead of buf_page_get_gen, to
174
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,\
177
BUF_GET_NOWAIT, __FILE__, __LINE__, MTR)
178
/******************************************************************
179
NOTE! The following macros should be used instead of
180
buf_page_optimistic_get_func, to improve debugging. Only values RW_S_LATCH and
181
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)
184
/************************************************************************
243
185
This is the general function used to get optimistic access to a database
245
@return TRUE if success */
248
buf_page_optimistic_get(
249
/*====================*/
250
ulint rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH */
251
buf_block_t* block, /*!< in: guessed block */
252
ib_uint64_t modify_clock,/*!< in: modify clock value if mode is
189
buf_page_optimistic_get_func(
190
/*=========================*/
191
/* out: TRUE if success */
192
ulint rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */
193
buf_block_t* block, /* in: guessed block */
194
ib_uint64_t modify_clock,/* in: modify clock value if mode is
253
195
..._GUESS_ON_CLOCK */
254
const char* file, /*!< in: file name */
255
ulint line, /*!< in: line where called */
256
mtr_t* mtr); /*!< in: mini-transaction */
257
/********************************************************************//**
196
const char* file, /* in: file name */
197
ulint line, /* in: line where called */
198
mtr_t* mtr); /* in: mini-transaction */
199
/************************************************************************
258
200
This is used to get access to a known database page, when no waiting can be
260
@return TRUE if success */
263
204
buf_page_get_known_nowait(
264
205
/*======================*/
265
ulint rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH */
266
buf_block_t* block, /*!< in: the known page */
267
ulint mode, /*!< in: BUF_MAKE_YOUNG or BUF_KEEP_OLD */
268
const char* file, /*!< in: file name */
269
ulint line, /*!< in: line where called */
270
mtr_t* mtr); /*!< in: mini-transaction */
206
/* out: TRUE if success */
207
ulint rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */
208
buf_block_t* block, /* in: the known page */
209
ulint mode, /* in: BUF_MAKE_YOUNG or BUF_KEEP_OLD */
210
const char* file, /* in: file name */
211
ulint line, /* in: line where called */
212
mtr_t* mtr); /* in: mini-transaction */
272
/*******************************************************************//**
214
/***********************************************************************
273
215
Given a tablespace id and page number tries to get that page. If the
274
216
page is not in the buffer pool it is not loaded and NULL is returned.
275
217
Suitable for using when holding the kernel mutex. */
277
219
const buf_block_t*
278
220
buf_page_try_get_func(
279
221
/*==================*/
280
ulint space_id,/*!< in: tablespace id */
281
ulint page_no,/*!< in: page number */
282
const char* file, /*!< in: file name */
283
ulint line, /*!< in: line where called */
284
mtr_t* mtr); /*!< in: mini-transaction */
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 */
286
/** Tries to get a page. If the page is not in the buffer pool it is
287
not loaded. Suitable for using when holding the kernel mutex.
288
@param space_id in: tablespace id
289
@param page_no in: page number
290
@param mtr in: mini-transaction
291
@return the page if in buffer pool, NULL if not */
292
228
#define buf_page_try_get(space_id, page_no, mtr) \
293
229
buf_page_try_get_func(space_id, page_no, __FILE__, __LINE__, mtr);
295
/********************************************************************//**
231
/************************************************************************
296
232
Get read access to a compressed page (usually of type
297
233
FIL_PAGE_TYPE_ZBLOB or FIL_PAGE_TYPE_ZBLOB2).
298
234
The page must be released with buf_page_release_zip().
299
235
NOTE: the page is not protected by any latch. Mutual exclusion has to
300
236
be implemented at a higher level. In other words, all possible
301
237
accesses to a given page through this function must be protected by
302
the same set of mutexes or latches.
303
@return pointer to the block, or NULL if not compressed */
238
the same set of mutexes or latches. */
306
241
buf_page_get_zip(
307
242
/*=============*/
308
ulint space, /*!< in: space id */
309
ulint zip_size,/*!< in: compressed page size */
310
ulint offset);/*!< in: page number */
311
/********************************************************************//**
312
This is the general function used to get access to a database page.
313
@return pointer to the block or NULL */
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
/************************************************************************
249
This is the general function used to get access to a database page. */
316
252
buf_page_get_gen(
317
253
/*=============*/
318
ulint space, /*!< in: space id */
319
ulint zip_size,/*!< in: compressed page size in bytes
254
/* out: pointer to the block or NULL */
255
ulint space, /* in: space id */
256
ulint zip_size,/* in: compressed page size in bytes
320
257
or 0 for uncompressed pages */
321
ulint offset, /*!< in: page number */
322
ulint rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
323
buf_block_t* guess, /*!< in: guessed block or NULL */
324
ulint mode, /*!< in: BUF_GET, BUF_GET_IF_IN_POOL,
326
BUF_GET_IF_IN_POOL_OR_WATCH */
327
const char* file, /*!< in: file name */
328
ulint line, /*!< in: line where called */
329
mtr_t* mtr); /*!< in: mini-transaction */
330
/********************************************************************//**
258
ulint offset, /* in: page number */
259
ulint rw_latch,/* in: RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
260
buf_block_t* guess, /* in: guessed block or NULL */
261
ulint mode, /* in: BUF_GET, BUF_GET_IF_IN_POOL,
263
const char* file, /* in: file name */
264
ulint line, /* in: line where called */
265
mtr_t* mtr); /* in: mini-transaction */
266
/************************************************************************
331
267
Initializes a page to the buffer buf_pool. The page is usually not read
332
268
from a file even if it cannot be found in the buffer buf_pool. This is one
333
269
of the functions which perform to a block a state transition NOT_USED =>
334
FILE_PAGE (the other is buf_page_get_gen).
335
@return pointer to the block, page bufferfixed */
270
FILE_PAGE (the other is buf_page_get_gen). */
340
ulint space, /*!< in: space id */
341
ulint offset, /*!< in: offset of the page within space in units of
275
/* out: pointer to the block, page bufferfixed */
276
ulint space, /* in: space id */
277
ulint offset, /* in: offset of the page within space in units of
343
ulint zip_size,/*!< in: compressed page size, or 0 */
344
mtr_t* mtr); /*!< in: mini-transaction handle */
345
#else /* !UNIV_HOTBACKUP */
346
/********************************************************************//**
279
ulint zip_size,/* in: compressed page size, or 0 */
280
mtr_t* mtr); /* in: mini-transaction handle */
281
#ifdef UNIV_HOTBACKUP
282
/************************************************************************
347
283
Inits a page to the buffer buf_pool, for use in ibbackup --restore. */
350
286
buf_page_init_for_backup_restore(
351
287
/*=============================*/
352
ulint space, /*!< in: space id */
353
ulint offset, /*!< in: offset of the page within space
288
ulint space, /* in: space id */
289
ulint offset, /* in: offset of the page within space
354
290
in units of a page */
355
ulint zip_size,/*!< in: compressed page size in bytes
291
ulint zip_size,/* in: compressed page size in bytes
356
292
or 0 for uncompressed pages */
357
buf_block_t* block); /*!< in: block to init */
358
#endif /* !UNIV_HOTBACKUP */
360
#ifndef UNIV_HOTBACKUP
361
/********************************************************************//**
293
buf_block_t* block); /* in: block to init */
294
#endif /* UNIV_HOTBACKUP */
295
/************************************************************************
362
296
Releases a compressed-only page acquired with buf_page_get_zip(). */
365
299
buf_page_release_zip(
366
300
/*=================*/
367
buf_page_t* bpage); /*!< in: buffer block */
368
/********************************************************************//**
301
buf_page_t* bpage); /* in: buffer block */
302
/************************************************************************
369
303
Decrements the bufferfix count of a buffer control block and releases
370
304
a latch, if specified. */
373
307
buf_page_release(
374
308
/*=============*/
375
buf_block_t* block, /*!< in: buffer block */
376
ulint rw_latch); /*!< in: RW_S_LATCH, RW_X_LATCH,
309
buf_block_t* block, /* in: buffer block */
310
ulint rw_latch, /* in: RW_S_LATCH, RW_X_LATCH,
378
/********************************************************************//**
312
mtr_t* mtr); /* in: mtr */
313
/************************************************************************
379
314
Moves a page to the start of the buffer pool LRU list. This high-level
380
function can be used to prevent an important page from slipping out of
315
function can be used to prevent an important page from from slipping out of
381
316
the buffer pool. */
384
319
buf_page_make_young(
385
320
/*================*/
386
buf_page_t* bpage); /*!< in: buffer block of a file page */
387
/********************************************************************//**
388
Returns TRUE if the page can be found in the buffer pool hash table.
390
NOTE that it is possible that the page is not yet read from disk,
393
@return TRUE if found in the page hash table */
321
buf_page_t* bpage); /* in: buffer block of a file page */
322
/************************************************************************
323
Returns TRUE if the page can be found in the buffer pool hash table. NOTE
324
that it is possible that the page is not yet read from disk, though. */
398
ulint space, /*!< in: space id */
399
ulint offset);/*!< in: page number */
400
/********************************************************************//**
329
/* out: TRUE if found from page hash table,
330
NOTE that the page is not necessarily yet read
332
ulint space, /* in: space id */
333
ulint offset);/* in: page number */
334
/************************************************************************
401
335
Resets the check_index_page_at_flush field of a page if found in the buffer
405
339
buf_reset_check_index_page_at_flush(
406
340
/*================================*/
407
ulint space, /*!< in: space id */
408
ulint offset);/*!< in: page number */
341
ulint space, /* in: space id */
342
ulint offset);/* in: page number */
409
343
#ifdef UNIV_DEBUG_FILE_ACCESSES
410
/********************************************************************//**
344
/************************************************************************
411
345
Sets file_page_was_freed TRUE if the page is found in the buffer pool.
412
346
This function should be called when we free a file page and want the
413
347
debug version to check that it is not accessed any more unless
415
@return control block if found in page hash table, otherwise NULL */
418
351
buf_page_set_file_page_was_freed(
419
352
/*=============================*/
420
ulint space, /*!< in: space id */
421
ulint offset);/*!< in: page number */
422
/********************************************************************//**
353
/* out: control block if found in page hash table,
355
ulint space, /* in: space id */
356
ulint offset);/* in: page number */
357
/************************************************************************
423
358
Sets file_page_was_freed FALSE if the page is found in the buffer pool.
424
359
This function should be called when we free a file page and want the
425
360
debug version to check that it is not accessed any more unless
427
@return control block if found in page hash table, otherwise NULL */
430
364
buf_page_reset_file_page_was_freed(
431
365
/*===============================*/
432
ulint space, /*!< in: space id */
433
ulint offset); /*!< in: page number */
366
/* out: control block if found in page hash table,
368
ulint space, /* in: space id */
369
ulint offset); /* in: page number */
434
370
#endif /* UNIV_DEBUG_FILE_ACCESSES */
435
/********************************************************************//**
436
Reads the freed_page_clock of a buffer block.
437
@return freed_page_clock */
371
/************************************************************************
372
Reads the freed_page_clock of a buffer block. */
440
375
buf_page_get_freed_page_clock(
441
376
/*==========================*/
442
const buf_page_t* bpage) /*!< in: block */
377
/* out: freed_page_clock */
378
const buf_page_t* bpage) /* in: block */
443
379
__attribute__((pure));
444
/********************************************************************//**
445
Reads the freed_page_clock of a buffer block.
446
@return freed_page_clock */
380
/************************************************************************
381
Reads the freed_page_clock of a buffer block. */
449
384
buf_block_get_freed_page_clock(
450
385
/*===========================*/
451
const buf_block_t* block) /*!< in: block */
386
/* out: freed_page_clock */
387
const buf_block_t* block) /* in: block */
452
388
__attribute__((pure));
454
/********************************************************************//**
390
/************************************************************************
455
391
Recommends a move of a block to the start of the LRU list if there is danger
456
392
of dropping from the buffer pool. NOTE: does not reserve the buffer pool
458
@return TRUE if should be made younger */
461
396
buf_page_peek_if_too_old(
462
397
/*=====================*/
463
const buf_page_t* bpage); /*!< in: block to make younger */
464
/********************************************************************//**
398
/* out: TRUE if should be made
400
const buf_page_t* bpage); /* in: block to make younger */
401
/************************************************************************
465
402
Returns the current state of is_hashed of a page. FALSE if the page is
466
403
not in the pool. NOTE that this operation does not fix the page in the
467
pool if it is found there.
468
@return TRUE if page hash index is built in search system */
404
pool if it is found there. */
471
407
buf_page_peek_if_search_hashed(
472
408
/*===========================*/
473
ulint space, /*!< in: space id */
474
ulint offset);/*!< in: page number */
475
/********************************************************************//**
409
/* out: TRUE if page hash index is built in search
411
ulint space, /* in: space id */
412
ulint offset);/* in: page number */
413
/************************************************************************
476
414
Gets the youngest modification log sequence number for a frame.
477
Returns zero if not file page or no modification occurred yet.
478
@return newest modification to page */
415
Returns zero if not file page or no modification occurred yet. */
481
418
buf_page_get_newest_modification(
482
419
/*=============================*/
483
const buf_page_t* bpage); /*!< in: block containing the
420
/* out: newest modification to page */
421
const buf_page_t* bpage); /* in: block containing the
485
/********************************************************************//**
423
/************************************************************************
486
424
Increments the modify clock of a frame by 1. The caller must (1) own the
487
buf_pool->mutex and block bufferfix count has to be zero, (2) or own an x-lock
425
buf_pool mutex and block bufferfix count has to be zero, (2) or own an x-lock
491
429
buf_block_modify_clock_inc(
492
430
/*=======================*/
493
buf_block_t* block); /*!< in: block */
494
/********************************************************************//**
431
buf_block_t* block); /* in: block */
432
/************************************************************************
495
433
Returns the value of the modify clock. The caller must have an s-lock
496
or x-lock on the block.
434
or x-lock on the block. */
500
437
buf_block_get_modify_clock(
501
438
/*=======================*/
502
buf_block_t* block); /*!< in: block */
503
#else /* !UNIV_HOTBACKUP */
504
# define buf_block_modify_clock_inc(block) ((void) 0)
505
#endif /* !UNIV_HOTBACKUP */
506
/********************************************************************//**
440
buf_block_t* block); /* in: block */
441
/************************************************************************
507
442
Calculates a page checksum which is stored to the page when it is written
508
443
to a file. Note that we must be careful to calculate the same value
509
on 32-bit and 64-bit architectures.
444
on 32-bit and 64-bit architectures. */
513
447
buf_calc_page_new_checksum(
514
448
/*=======================*/
515
const byte* page); /*!< in: buffer page */
516
/********************************************************************//**
450
const byte* page); /* in: buffer page */
451
/************************************************************************
517
452
In versions < 4.0.14 and < 4.1.1 there was a bug that the checksum only
518
453
looked at the first few bytes of the page. This calculates that old
520
455
NOTE: we must first store the new formula checksum to
521
456
FIL_PAGE_SPACE_OR_CHKSUM before calculating and storing this old checksum
522
because this takes that field as an input!
457
because this takes that field as an input! */
526
460
buf_calc_page_old_checksum(
527
461
/*=======================*/
528
const byte* page); /*!< in: buffer page */
529
/********************************************************************//**
530
Checks if a page is corrupt.
531
@return TRUE if corrupted */
463
const byte* page); /* in: buffer page */
464
/************************************************************************
465
Checks if a page is corrupt. */
534
468
buf_page_is_corrupted(
535
469
/*==================*/
536
const byte* read_buf, /*!< in: a database page */
537
ulint zip_size); /*!< in: size of compressed page;
470
/* out: TRUE if corrupted */
471
const byte* read_buf, /* in: a database page */
472
ulint zip_size); /* in: size of compressed page;
538
473
0 for uncompressed pages */
539
#ifndef UNIV_HOTBACKUP
540
/**********************************************************************//**
474
/**************************************************************************
541
475
Gets the space id, page offset, and byte offset within page of a
542
476
pointer pointing to a buffer frame containing a file page. */
545
479
buf_ptr_get_fsp_addr(
546
480
/*=================*/
547
const void* ptr, /*!< in: pointer to a buffer frame */
548
ulint* space, /*!< out: space id */
549
fil_addr_t* addr); /*!< out: page offset and byte offset */
550
/**********************************************************************//**
481
const void* ptr, /* in: pointer to a buffer frame */
482
ulint* space, /* out: space id */
483
fil_addr_t* addr); /* out: page offset and byte offset */
484
/**************************************************************************
551
485
Gets the hash value of a block. This can be used in searches in the
553
@return lock hash value */
556
489
buf_block_get_lock_hash_val(
557
490
/*========================*/
558
const buf_block_t* block) /*!< in: block */
491
/* out: lock hash value */
492
const buf_block_t* block) /* in: block */
559
493
__attribute__((pure));
560
494
#ifdef UNIV_DEBUG
561
/*********************************************************************//**
495
/*************************************************************************
562
496
Finds a block in the buffer pool that points to a
563
given compressed page.
564
@return buffer block pointing to the compressed page, or NULL */
497
given compressed page. */
567
500
buf_pool_contains_zip(
568
501
/*==================*/
569
buf_pool_t* buf_pool, /*!< in: buffer pool instance */
570
const void* data); /*!< in: pointer to compressed page */
502
/* out: buffer block pointing to
503
the compressed page, or NULL */
504
const void* data); /* in: pointer to compressed page */
571
505
#endif /* UNIV_DEBUG */
572
506
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
573
/*********************************************************************//**
574
Validates the buffer pool data structure.
507
/*************************************************************************
508
Validates the buffer pool data structure. */
578
511
buf_validate(void);
579
512
/*==============*/
580
513
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
581
514
#if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
582
/*********************************************************************//**
515
/*************************************************************************
583
516
Prints info of the buffer pool data structure. */
588
521
#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
589
#endif /* !UNIV_HOTBACKUP */
590
/********************************************************************//**
522
/************************************************************************
591
523
Prints a page to stderr. */
596
const byte* read_buf, /*!< in: a database page */
597
ulint zip_size); /*!< in: compressed page size, or
528
const byte* read_buf, /* in: a database page */
529
ulint zip_size); /* in: compressed page size, or
598
530
0 for uncompressed pages */
599
/********************************************************************//**
601
@return TRUE if successful */
606
buf_block_t* block, /*!< in/out: block */
607
ibool check); /*!< in: TRUE=verify the page checksum */
608
#ifndef UNIV_HOTBACKUP
609
531
#ifdef UNIV_DEBUG
610
/*********************************************************************//**
611
Returns the number of latched pages in the buffer pool.
612
@return number of latched pages */
532
/*************************************************************************
533
Returns the number of latched pages in the buffer pool. */
615
536
buf_get_latched_pages_number(void);
616
537
/*==============================*/
617
538
#endif /* UNIV_DEBUG */
618
/*********************************************************************//**
619
Returns the number of pending buf pool ios.
620
@return number of pending I/O operations */
539
/*************************************************************************
540
Returns the number of pending buf pool ios. */
623
543
buf_get_n_pending_ios(void);
624
544
/*=======================*/
625
/*********************************************************************//**
545
/*************************************************************************
626
546
Prints info of the buffer i/o. */
631
FILE* file); /*!< in: file where to print */
632
/*********************************************************************//**
551
FILE* file); /* in: file where to print */
552
/*************************************************************************
633
553
Returns the ratio in percents of modified pages in the buffer pool /
634
database pages in the buffer pool.
635
@return modified page percentage ratio */
554
database pages in the buffer pool. */
638
557
buf_get_modified_ratio_pct(void);
639
558
/*============================*/
640
/**********************************************************************//**
641
Refreshes the statistics used to print per-second averages. */
644
buf_refresh_io_stats(
645
/*=================*/
646
buf_pool_t* buf_pool); /*!< buffer pool instance */
647
/**********************************************************************//**
648
Refreshes the statistics used to print per-second averages. */
651
buf_refresh_io_stats_all(void);
652
/*=================*/
653
/*********************************************************************//**
654
Asserts that all file pages in the buffer are in a replaceable state.
559
/**************************************************************************
560
Refreshes the statistics used to print per-second averages. */
563
buf_refresh_io_stats(void);
564
/*======================*/
565
/*************************************************************************
566
Checks that all file pages in the buffer are in a replaceable state. */
658
569
buf_all_freed(void);
659
570
/*===============*/
660
/*********************************************************************//**
571
/*************************************************************************
661
572
Checks that there currently are no pending i/o-operations for the buffer
663
@return TRUE if there is no pending i/o */
666
576
buf_pool_check_no_pending_io(void);
667
577
/*==============================*/
668
/*********************************************************************//**
578
/* out: TRUE if there is no pending i/o */
579
/*************************************************************************
669
580
Invalidates the file pages in the buffer pool when an archive recovery is
670
581
completed. All the file pages buffered must be in a replaceable state when
671
582
this function is called: not latched and not modified. */
689
599
buf_block_dbg_add_level(
690
600
/*====================*/
691
buf_block_t* block, /*!< in: buffer page
601
buf_block_t* block, /* in: buffer page
692
602
where we have acquired latch */
693
ulint level); /*!< in: latching order level */
603
ulint level); /* in: latching order level */
694
604
#else /* UNIV_SYNC_DEBUG */
695
605
# define buf_block_dbg_add_level(block, level) /* nothing */
696
606
#endif /* UNIV_SYNC_DEBUG */
697
/*********************************************************************//**
698
Gets the state of a block.
607
/*************************************************************************
608
Gets the state of a block. */
701
610
enum buf_page_state
702
611
buf_page_get_state(
703
612
/*===============*/
704
const buf_page_t* bpage); /*!< in: pointer to the control block */
705
/*********************************************************************//**
706
Gets the state of a block.
614
const buf_page_t* bpage); /* in: pointer to the control block */
615
/*************************************************************************
616
Gets the state of a block. */
709
618
enum buf_page_state
710
619
buf_block_get_state(
711
620
/*================*/
712
const buf_block_t* block) /*!< in: pointer to the control block */
622
const buf_block_t* block) /* in: pointer to the control block */
713
623
__attribute__((pure));
714
/*********************************************************************//**
624
/*************************************************************************
715
625
Sets the state of a block. */
718
628
buf_page_set_state(
719
629
/*===============*/
720
buf_page_t* bpage, /*!< in/out: pointer to control block */
721
enum buf_page_state state); /*!< in: state */
722
/*********************************************************************//**
630
buf_page_t* bpage, /* in/out: pointer to control block */
631
enum buf_page_state state); /* in: state */
632
/*************************************************************************
723
633
Sets the state of a block. */
726
636
buf_block_set_state(
727
637
/*================*/
728
buf_block_t* block, /*!< in/out: pointer to control block */
729
enum buf_page_state state); /*!< in: state */
730
/*********************************************************************//**
731
Determines if a block is mapped to a tablespace.
732
@return TRUE if mapped */
638
buf_block_t* block, /* in/out: pointer to control block */
639
enum buf_page_state state); /* in: state */
640
/*************************************************************************
641
Determines if a block is mapped to a tablespace. */
735
644
buf_page_in_file(
736
645
/*=============*/
737
const buf_page_t* bpage) /*!< in: pointer to control block */
646
/* out: TRUE if mapped */
647
const buf_page_t* bpage) /* in: pointer to control block */
738
648
__attribute__((pure));
739
#ifndef UNIV_HOTBACKUP
740
/*********************************************************************//**
741
Determines if a block should be on unzip_LRU list.
742
@return TRUE if block belongs to unzip_LRU */
649
/*************************************************************************
650
Determines if a block should be on unzip_LRU list. */
745
653
buf_page_belongs_to_unzip_LRU(
746
654
/*==========================*/
747
const buf_page_t* bpage) /*!< in: pointer to control block */
655
/* out: TRUE if block belongs
657
const buf_page_t* bpage) /* in: pointer to control block */
658
__attribute__((pure));
659
/*************************************************************************
660
Determine the approximate LRU list position of a block. */
663
buf_page_get_LRU_position(
664
/*======================*/
665
/* out: LRU list position */
666
const buf_page_t* bpage) /* in: control block */
748
667
__attribute__((pure));
750
/*********************************************************************//**
751
Gets the mutex of a block.
752
@return pointer to mutex protecting bpage */
669
/*************************************************************************
670
Gets the mutex of a block. */
755
673
buf_page_get_mutex(
756
674
/*===============*/
757
const buf_page_t* bpage) /*!< in: pointer to control block */
675
/* out: pointer to mutex
677
const buf_page_t* bpage) /* in: pointer to control block */
758
678
__attribute__((pure));
760
/*********************************************************************//**
761
Get the flush type of a page.
762
@return flush type */
680
/*************************************************************************
681
Get the flush type of a page. */
765
684
buf_page_get_flush_type(
766
685
/*====================*/
767
const buf_page_t* bpage) /*!< in: buffer page */
686
/* out: flush type */
687
const buf_page_t* bpage) /* in: buffer page */
768
688
__attribute__((pure));
769
/*********************************************************************//**
689
/*************************************************************************
770
690
Set the flush type of a page. */
773
693
buf_page_set_flush_type(
774
694
/*====================*/
775
buf_page_t* bpage, /*!< in: buffer page */
776
enum buf_flush flush_type); /*!< in: flush type */
777
/*********************************************************************//**
695
buf_page_t* bpage, /* in: buffer page */
696
enum buf_flush flush_type); /* in: flush type */
697
/*************************************************************************
778
698
Map a block to a file page. */
781
701
buf_block_set_file_page(
782
702
/*====================*/
783
buf_block_t* block, /*!< in/out: pointer to control block */
784
ulint space, /*!< in: tablespace id */
785
ulint page_no);/*!< in: page number */
786
/*********************************************************************//**
787
Gets the io_fix state of a block.
788
@return io_fix state */
703
buf_block_t* block, /* in/out: pointer to control block */
704
ulint space, /* in: tablespace id */
705
ulint page_no);/* in: page number */
706
/*************************************************************************
707
Gets the io_fix state of a block. */
791
710
buf_page_get_io_fix(
792
711
/*================*/
793
const buf_page_t* bpage) /*!< in: pointer to the control block */
712
/* out: io_fix state */
713
const buf_page_t* bpage) /* in: pointer to the control block */
794
714
__attribute__((pure));
795
/*********************************************************************//**
796
Gets the io_fix state of a block.
797
@return io_fix state */
715
/*************************************************************************
716
Gets the io_fix state of a block. */
800
719
buf_block_get_io_fix(
801
720
/*================*/
802
const buf_block_t* block) /*!< in: pointer to the control block */
721
/* out: io_fix state */
722
const buf_block_t* block) /* in: pointer to the control block */
803
723
__attribute__((pure));
804
/*********************************************************************//**
724
/*************************************************************************
805
725
Sets the io_fix state of a block. */
808
728
buf_page_set_io_fix(
809
729
/*================*/
810
buf_page_t* bpage, /*!< in/out: control block */
811
enum buf_io_fix io_fix);/*!< in: io_fix state */
812
/*********************************************************************//**
730
buf_page_t* bpage, /* in/out: control block */
731
enum buf_io_fix io_fix);/* in: io_fix state */
732
/*************************************************************************
813
733
Sets the io_fix state of a block. */
816
736
buf_block_set_io_fix(
817
737
/*=================*/
818
buf_block_t* block, /*!< in/out: control block */
819
enum buf_io_fix io_fix);/*!< in: io_fix state */
738
buf_block_t* block, /* in/out: control block */
739
enum buf_io_fix io_fix);/* in: io_fix state */
821
/********************************************************************//**
741
/************************************************************************
822
742
Determine if a buffer block can be relocated in memory. The block
823
743
can be dirty, but it must not be I/O-fixed or bufferfixed. */
826
746
buf_page_can_relocate(
827
747
/*==================*/
828
const buf_page_t* bpage) /*!< control block being relocated */
748
const buf_page_t* bpage) /* control block being relocated */
829
749
__attribute__((pure));
831
/*********************************************************************//**
832
Determine if a block has been flagged old.
833
@return TRUE if old */
751
/*************************************************************************
752
Determine if a block has been flagged old. */
838
const buf_page_t* bpage) /*!< in: control block */
757
/* out: TRUE if old */
758
const buf_page_t* bpage) /* in: control block */
839
759
__attribute__((pure));
840
/*********************************************************************//**
760
/*************************************************************************
841
761
Flag a block old. */
844
764
buf_page_set_old(
845
765
/*=============*/
846
buf_page_t* bpage, /*!< in/out: control block */
847
ibool old); /*!< in: old */
848
/*********************************************************************//**
849
Determine the time of first access of a block in the buffer pool.
850
@return ut_time_ms() at the time of first access, 0 if not accessed */
766
buf_page_t* bpage, /* in/out: control block */
767
ibool old); /* in: old */
768
/*************************************************************************
769
Determine if a block has been accessed in the buffer pool. */
853
772
buf_page_is_accessed(
854
773
/*=================*/
855
const buf_page_t* bpage) /*!< in: control block */
856
__attribute__((nonnull, pure));
857
/*********************************************************************//**
774
/* out: TRUE if accessed */
775
const buf_page_t* bpage) /* in: control block */
776
__attribute__((pure));
777
/*************************************************************************
858
778
Flag a block accessed. */
861
781
buf_page_set_accessed(
862
782
/*==================*/
863
buf_page_t* bpage, /*!< in/out: control block */
864
ulint time_ms) /*!< in: ut_time_ms() */
865
__attribute__((nonnull));
866
/*********************************************************************//**
783
buf_page_t* bpage, /* in/out: control block */
784
ibool accessed); /* in: accessed */
785
/*************************************************************************
867
786
Gets the buf_block_t handle of a buffered file block if an uncompressed
868
page frame exists, or NULL. Note: even though bpage is not declared a
869
const we don't update its value. It is safe to make this pure.
870
@return control block, or NULL */
787
page frame exists, or NULL. */
873
790
buf_page_get_block(
874
791
/*===============*/
875
buf_page_t* bpage) /*!< in: control block, or NULL */
792
/* out: control block, or NULL */
793
buf_page_t* bpage) /* in: control block, or NULL */
876
794
__attribute__((pure));
877
#endif /* !UNIV_HOTBACKUP */
878
795
#ifdef UNIV_DEBUG
879
/*********************************************************************//**
880
Gets a pointer to the memory frame of a block.
881
@return pointer to the frame */
796
/*************************************************************************
797
Gets a pointer to the memory frame of a block. */
884
800
buf_block_get_frame(
885
801
/*================*/
886
const buf_block_t* block) /*!< in: pointer to the control block */
802
/* out: pointer to the frame */
803
const buf_block_t* block) /* in: pointer to the control block */
887
804
__attribute__((pure));
888
805
#else /* UNIV_DEBUG */
889
806
# define buf_block_get_frame(block) (block)->frame
890
807
#endif /* UNIV_DEBUG */
891
/*********************************************************************//**
892
Gets the space id of a block.
808
/*************************************************************************
809
Gets the space id of a block. */
896
812
buf_page_get_space(
897
813
/*===============*/
898
const buf_page_t* bpage) /*!< in: pointer to the control block */
815
const buf_page_t* bpage) /* in: pointer to the control block */
899
816
__attribute__((pure));
900
/*********************************************************************//**
901
Gets the space id of a block.
817
/*************************************************************************
818
Gets the space id of a block. */
905
821
buf_block_get_space(
906
822
/*================*/
907
const buf_block_t* block) /*!< in: pointer to the control block */
824
const buf_block_t* block) /* in: pointer to the control block */
908
825
__attribute__((pure));
909
/*********************************************************************//**
910
Gets the page number of a block.
911
@return page number */
826
/*************************************************************************
827
Gets the page number of a block. */
914
830
buf_page_get_page_no(
915
831
/*=================*/
916
const buf_page_t* bpage) /*!< in: pointer to the control block */
832
/* out: page number */
833
const buf_page_t* bpage) /* in: pointer to the control block */
917
834
__attribute__((pure));
918
/*********************************************************************//**
919
Gets the page number of a block.
920
@return page number */
835
/*************************************************************************
836
Gets the page number of a block. */
923
839
buf_block_get_page_no(
924
840
/*==================*/
925
const buf_block_t* block) /*!< in: pointer to the control block */
841
/* out: page number */
842
const buf_block_t* block) /* in: pointer to the control block */
926
843
__attribute__((pure));
927
/*********************************************************************//**
928
Gets the compressed page size of a block.
929
@return compressed page size, or 0 */
844
/*************************************************************************
845
Gets the compressed page size of a block. */
932
848
buf_page_get_zip_size(
933
849
/*==================*/
934
const buf_page_t* bpage) /*!< in: pointer to the control block */
850
/* out: compressed page size, or 0 */
851
const buf_page_t* bpage) /* in: pointer to the control block */
935
852
__attribute__((pure));
936
/*********************************************************************//**
937
Gets the compressed page size of a block.
938
@return compressed page size, or 0 */
853
/*************************************************************************
854
Gets the compressed page size of a block. */
941
857
buf_block_get_zip_size(
942
858
/*===================*/
943
const buf_block_t* block) /*!< in: pointer to the control block */
859
/* out: compressed page size, or 0 */
860
const buf_block_t* block) /* in: pointer to the control block */
944
861
__attribute__((pure));
945
/*********************************************************************//**
862
/*************************************************************************
946
863
Gets the compressed page descriptor corresponding to an uncompressed page
947
864
if applicable. */
948
865
#define buf_block_get_page_zip(block) \
949
866
(UNIV_LIKELY_NULL((block)->page.zip.data) ? &(block)->page.zip : NULL)
950
#ifndef UNIV_HOTBACKUP
951
/*******************************************************************//**
952
Gets the block to whose frame the pointer is pointing to.
953
@return pointer to block, never NULL */
867
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
868
/***********************************************************************
869
Gets the block to whose frame the pointer is pointing to. */
958
const byte* ptr); /*!< in: pointer to a frame */
959
/********************************************************************//**
960
Find out if a pointer belongs to a buf_block_t. It can be a pointer to
961
the buf_block_t itself or a member of it
962
@return TRUE if ptr belongs to a buf_block_t struct */
965
buf_pointer_is_block_field(
966
/*=======================*/
967
const void* ptr); /*!< in: pointer not
969
/** Find out if a pointer corresponds to a buf_block_t::mutex.
970
@param m in: mutex candidate
971
@return TRUE if m is a buf_block_t::mutex */
972
#define buf_pool_is_block_mutex(m) \
973
buf_pointer_is_block_field((const void*)(m))
974
/** Find out if a pointer corresponds to a buf_block_t::lock.
975
@param l in: rw-lock candidate
976
@return TRUE if l is a buf_block_t::lock */
977
#define buf_pool_is_block_lock(l) \
978
buf_pointer_is_block_field((const void*)(l))
980
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
981
/*********************************************************************//**
874
/* out: pointer to block */
875
const byte* ptr); /* in: pointer to a frame */
876
/*************************************************************************
982
877
Gets the compressed page descriptor corresponding to an uncompressed page
984
@return compressed page descriptor, or NULL */
986
880
const page_zip_des_t*
987
881
buf_frame_get_page_zip(
988
882
/*===================*/
989
const byte* ptr); /*!< in: pointer to the page */
883
/* out: compressed page descriptor, or NULL */
884
const byte* ptr); /* in: pointer to the page */
990
885
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
991
/********************************************************************//**
886
/************************************************************************
887
This function is used to get info if there is an io operation
888
going on on a buffer page. */
893
/* out: TRUE if io going on */
894
buf_page_t* bpage); /* in: pool block, must be bufferfixed */
895
/************************************************************************
992
896
Function which inits a page for read to the buffer buf_pool. If the page is
993
897
(1) already in buf_pool, or
994
898
(2) if we specify to read only ibuf pages and the page is not an ibuf page, or
996
900
then this function does nothing.
997
901
Sets the io_fix flag to BUF_IO_READ and sets a non-recursive exclusive lock
998
902
on the buffer frame. The io-handler must take care that the flag is cleared
999
and the lock released later.
1000
@return pointer to the block or NULL */
903
and the lock released later. */
1003
906
buf_page_init_for_read(
1004
907
/*===================*/
1005
ulint* err, /*!< out: DB_SUCCESS or DB_TABLESPACE_DELETED */
1006
ulint mode, /*!< in: BUF_READ_IBUF_PAGES_ONLY, ... */
1007
ulint space, /*!< in: space id */
1008
ulint zip_size,/*!< in: compressed page size, or 0 */
1009
ibool unzip, /*!< in: TRUE=request uncompressed page */
1010
ib_int64_t tablespace_version,/*!< in: prevents reading from a wrong
908
/* out: pointer to the block or NULL */
909
ulint* err, /* out: DB_SUCCESS or DB_TABLESPACE_DELETED */
910
ulint mode, /* in: BUF_READ_IBUF_PAGES_ONLY, ... */
911
ulint space, /* in: space id */
912
ulint zip_size,/* in: compressed page size, or 0 */
913
ibool unzip, /* in: TRUE=request uncompressed page */
914
ib_int64_t tablespace_version,/* in: prevents reading from a wrong
1011
915
version of the tablespace in case we have done
1012
916
DISCARD + IMPORT */
1013
ulint offset);/*!< in: page number */
1014
/********************************************************************//**
917
ulint offset);/* in: page number */
918
/************************************************************************
1015
919
Completes an asynchronous read or write request of a file page to or from
1016
920
the buffer pool. */
1019
923
buf_page_io_complete(
1020
924
/*=================*/
1021
buf_page_t* bpage); /*!< in: pointer to the block in question */
1022
/********************************************************************//**
925
buf_page_t* bpage); /* in: pointer to the block in question */
926
/************************************************************************
1023
927
Calculates a folded value of a file page address to use in the page hash
1025
@return the folded value */
1028
931
buf_page_address_fold(
1029
932
/*==================*/
1030
ulint space, /*!< in: space id */
1031
ulint offset) /*!< in: offset of the page within space */
1032
__attribute__((const));
1033
/******************************************************************//**
1034
Returns the buffer pool instance given a page instance
1038
buf_pool_from_bpage(
1039
/*================*/
1040
const buf_page_t* bpage); /*!< in: buffer pool page */
1041
/******************************************************************//**
1042
Returns the buffer pool instance given a block instance
1046
buf_pool_from_block(
1047
/*================*/
1048
const buf_block_t* block); /*!< in: block */
1049
/******************************************************************//**
1050
Returns the buffer pool instance given space and offset of page
1051
@return buffer pool */
1056
ulint space, /*!< in: space id */
1057
ulint offset);/*!< in: offset of the page within space */
1058
/******************************************************************//**
1059
Returns the buffer pool instance given its array index
1060
@return buffer pool */
1063
buf_pool_from_array(
1064
/*====================*/
1065
ulint index); /*!< in: array index to get buffer pool instance from */
1066
/******************************************************************//**
1067
Returns the control block of a file page, NULL if not found.
1068
@return block, NULL if not found */
1071
buf_page_hash_get_low(
1072
/*==================*/
1073
buf_pool_t* buf_pool, /*!< buffer pool instance */
1074
ulint space, /*!< in: space id */
1075
ulint offset, /*!< in: offset of the page
1077
ulint fold); /*!< in: buf_page_address_fold(
1079
/******************************************************************//**
1080
Returns the control block of a file page, NULL if not found.
1081
@return block, NULL if not found or not a real control block */
933
/* out: the folded value */
934
ulint space, /* in: space id */
935
ulint offset) /* in: offset of the page within space */
936
__attribute__((__const__));
937
/**********************************************************************
938
Returns the control block of a file page, NULL if not found. */
1084
941
buf_page_hash_get(
1085
942
/*==============*/
1086
buf_pool_t* buf_pool, /*!< in: buffer pool instance */
1087
ulint space, /*!< in: space id */
1088
ulint offset); /*!< in: offset of the page
1090
/******************************************************************//**
943
/* out: block, NULL if not found */
944
ulint space, /* in: space id */
945
ulint offset);/* in: offset of the page within space */
946
/**********************************************************************
1091
947
Returns the control block of a file page, NULL if not found
1092
or an uncompressed page frame does not exist.
1093
@return block, NULL if not found */
948
or an uncompressed page frame does not exist. */
1096
951
buf_block_hash_get(
1097
952
/*===============*/
1098
buf_pool_t* buf_pool, /*!< in: buffer pool instance */
1099
ulint space, /*!< in: space id */
1100
ulint offset); /*!< in: offset of the page
1102
/*********************************************************************//**
1103
Gets the current length of the free list of buffer blocks.
1104
@return length of the free list */
953
/* out: block, NULL if not found */
954
ulint space, /* in: space id */
955
ulint offset);/* in: offset of the page within space */
956
/***********************************************************************
957
Increments the pool clock by one and returns its new value. Remember that
958
in the 32 bit version the clock wraps around at 4 billion! */
961
buf_pool_clock_tic(void);
962
/*====================*/
963
/* out: new clock value */
964
/*************************************************************************
965
Gets the current length of the free list of buffer blocks. */
1107
968
buf_get_free_list_len(void);
1108
969
/*=======================*/
1110
/********************************************************************
1111
Determine if a block is a sentinel for a buffer pool watch.
1112
@return TRUE if a sentinel for a buffer pool watch, FALSE if not */
1115
buf_pool_watch_is_sentinel(
1116
/*=======================*/
1117
buf_pool_t* buf_pool, /*!< buffer pool instance */
1118
const buf_page_t* bpage) /*!< in: block */
1119
UNIV_WARN_UNUSED_RESULT;
1120
/****************************************************************//**
1121
Add watch for the given page to be read in. Caller must have the buffer pool
1122
@return NULL if watch set, block if the page is in the buffer pool */
1127
ulint space, /*!< in: space id */
1128
ulint offset, /*!< in: page number */
1129
ulint fold) /*!< in: buf_page_address_fold(space, offset) */
1130
UNIV_WARN_UNUSED_RESULT;
1131
/****************************************************************//**
1132
Stop watching if the page has been read in.
1133
buf_pool_watch_set(space,offset) must have returned NULL before. */
1136
buf_pool_watch_unset(
1137
/*=================*/
1138
ulint space, /*!< in: space id */
1139
ulint offset);/*!< in: page number */
1140
/****************************************************************//**
1141
Check if the page has been read in.
1142
This may only be called after buf_pool_watch_set(space,offset)
1143
has returned NULL and before invoking buf_pool_watch_unset(space,offset).
1144
@return FALSE if the given page was not read in, TRUE if it was */
1147
buf_pool_watch_occurred(
1148
/*====================*/
1149
ulint space, /*!< in: space id */
1150
ulint offset) /*!< in: page number */
1151
UNIV_WARN_UNUSED_RESULT;
1152
/********************************************************************//**
1153
Get total buffer pool statistics. */
1156
buf_get_total_list_len(
1157
/*===================*/
1158
ulint* LRU_len, /*!< out: length of all LRU lists */
1159
ulint* free_len, /*!< out: length of all free lists */
1160
ulint* flush_list_len);/*!< out: length of all flush lists */
1161
/********************************************************************//**
1162
Get total buffer pool statistics. */
1167
buf_pool_stat_t*tot_stat); /*!< out: buffer pool stats */
1169
#endif /* !UNIV_HOTBACKUP */
1171
/** The common buffer control block structure
973
/* The common buffer control block structure
1172
974
for compressed and uncompressed frames */
1174
976
struct buf_page_struct{
1175
/** @name General fields
1176
None of these bit-fields must be modified without holding
1177
buf_page_get_mutex() [buf_block_struct::mutex or
1178
buf_pool->zip_mutex], since they can be stored in the same
1179
machine word. Some of these fields are additionally protected
1180
by buf_pool->mutex. */
1183
unsigned space:32; /*!< tablespace id; also protected
1184
by buf_pool->mutex. */
1185
unsigned offset:32; /*!< page number; also protected
1186
by buf_pool->mutex. */
1188
unsigned state:3; /*!< state of the control block; also
1189
protected by buf_pool->mutex.
977
/* None of the following bit-fields must be modified without
978
holding buf_page_get_mutex() [block->mutex or buf_pool_zip_mutex],
979
since they can be stored in the same machine word. Some of them are
980
additionally protected by buf_pool_mutex. */
982
unsigned space:32; /* tablespace id */
983
unsigned offset:32; /* page number */
985
unsigned state:3; /* state of the control block
986
(@see enum buf_page_state); also
987
protected by buf_pool_mutex.
1190
988
State transitions from
1191
989
BUF_BLOCK_READY_FOR_USE to
1192
990
BUF_BLOCK_MEMORY need not be
1193
protected by buf_page_get_mutex().
1194
@see enum buf_page_state */
1195
#ifndef UNIV_HOTBACKUP
1196
unsigned flush_type:2; /*!< if this block is currently being
991
protected by buf_page_get_mutex(). */
992
unsigned flush_type:2; /* if this block is currently being
1197
993
flushed to disk, this tells the
1199
@see enum buf_flush */
1200
unsigned io_fix:2; /*!< type of pending I/O operation;
1201
also protected by buf_pool->mutex
1202
@see enum buf_io_fix */
1203
unsigned buf_fix_count:25;/*!< count of how manyfold this block
994
flush_type (@see enum buf_flush) */
995
unsigned accessed:1; /* TRUE if the page has been accessed
996
while in the buffer pool: read-ahead
997
may read in pages which have not been
998
accessed yet; a thread is allowed to
999
read this for heuristic purposes
1000
without holding any mutex or latch */
1001
unsigned io_fix:2; /* type of pending I/O operation
1002
(@see enum buf_io_fix); also
1003
protected by buf_pool_mutex */
1004
unsigned buf_fix_count:24;/* count of how manyfold this block
1204
1005
is currently bufferfixed */
1206
#endif /* !UNIV_HOTBACKUP */
1207
page_zip_des_t zip; /*!< compressed page; zip.data
1007
page_zip_des_t zip; /* compressed page; zip.data
1208
1008
(but not the data it points to) is
1209
also protected by buf_pool_mutex;
1210
state == BUF_BLOCK_ZIP_PAGE and
1211
zip.data == NULL means an active
1213
#ifndef UNIV_HOTBACKUP
1214
buf_page_t* hash; /*!< node used in chaining to
1009
also protected by buf_pool_mutex */
1010
buf_page_t* hash; /* node used in chaining to
1215
1011
buf_pool->page_hash or
1216
1012
buf_pool->zip_hash */
1217
1013
#ifdef UNIV_DEBUG
1218
ibool in_page_hash; /*!< TRUE if in buf_pool->page_hash */
1219
ibool in_zip_hash; /*!< TRUE if in buf_pool->zip_hash */
1014
ibool in_page_hash; /* TRUE if in buf_pool->page_hash */
1015
ibool in_zip_hash; /* TRUE if in buf_pool->zip_hash */
1220
1016
#endif /* UNIV_DEBUG */
1222
/** @name Page flushing fields
1223
All these are protected by buf_pool_mutex. */
1018
/* 2. Page flushing fields; protected by buf_pool_mutex */
1226
1020
UT_LIST_NODE_T(buf_page_t) list;
1227
/*!< based on state, this is a
1228
list node, protected either by
1229
buf_pool_mutex or by
1230
flush_list_mutex, in one of the
1231
following lists in buf_pool:
1233
- BUF_BLOCK_NOT_USED: free
1234
- BUF_BLOCK_FILE_PAGE: flush_list
1235
- BUF_BLOCK_ZIP_DIRTY: flush_list
1236
- BUF_BLOCK_ZIP_PAGE: zip_clean
1237
- BUF_BLOCK_ZIP_FREE: zip_free[]
1239
If bpage is part of flush_list
1240
then the node pointers are
1241
covered by flush_list_mutex.
1242
Otherwise these pointers are
1243
protected by buf_pool_mutex.
1245
The contents of the list node
1246
is undefined if !in_flush_list
1247
&& state == BUF_BLOCK_FILE_PAGE,
1248
or if state is one of
1250
BUF_BLOCK_REMOVE_HASH or
1251
BUF_BLOCK_READY_IN_USE. */
1021
/* based on state, this is a list
1022
node in one of the following lists
1025
BUF_BLOCK_NOT_USED: free
1026
BUF_BLOCK_FILE_PAGE: flush_list
1027
BUF_BLOCK_ZIP_DIRTY: flush_list
1028
BUF_BLOCK_ZIP_PAGE: zip_clean
1029
BUF_BLOCK_ZIP_FREE: zip_free[] */
1253
1030
#ifdef UNIV_DEBUG
1254
ibool in_flush_list; /*!< TRUE if in buf_pool->flush_list;
1255
when flush_list_mutex is free, the
1031
ibool in_flush_list; /* TRUE if in buf_pool->flush_list;
1032
when buf_pool_mutex is free, the
1256
1033
following should hold: in_flush_list
1257
1034
== (state == BUF_BLOCK_FILE_PAGE
1258
|| state == BUF_BLOCK_ZIP_DIRTY)
1259
Writes to this field must be
1260
covered by both block->mutex
1261
and flush_list_mutex. Hence
1262
reads can happen while holding
1263
any one of the two mutexes */
1264
ibool in_free_list; /*!< TRUE if in buf_pool->free; when
1035
|| state == BUF_BLOCK_ZIP_DIRTY) */
1036
ibool in_free_list; /* TRUE if in buf_pool->free; when
1265
1037
buf_pool_mutex is free, the following
1266
1038
should hold: in_free_list
1267
1039
== (state == BUF_BLOCK_NOT_USED) */
1268
1040
#endif /* UNIV_DEBUG */
1269
1041
ib_uint64_t newest_modification;
1270
/*!< log sequence number of
1271
the youngest modification to
1272
this block, zero if not
1273
modified. Protected by block
1042
/* log sequence number of the youngest
1043
modification to this block, zero if
1275
1045
ib_uint64_t oldest_modification;
1276
/*!< log sequence number of
1277
the START of the log entry
1278
written of the oldest
1279
modification to this block
1280
which has not yet been flushed
1281
on disk; zero if all
1282
modifications are on disk.
1283
Writes to this field must be
1284
covered by both block->mutex
1285
and flush_list_mutex. Hence
1286
reads can happen while holding
1287
any one of the two mutexes */
1289
/** @name LRU replacement algorithm fields
1290
These fields are protected by buf_pool->mutex only (not
1291
buf_pool->zip_mutex or buf_block_struct::mutex). */
1046
/* log sequence number of the START of
1047
the log entry written of the oldest
1048
modification to this block which has
1049
not yet been flushed on disk; zero if
1050
all modifications are on disk */
1052
/* 3. LRU replacement algorithm fields; protected by buf_pool_mutex */
1294
1054
UT_LIST_NODE_T(buf_page_t) LRU;
1295
/*!< node of the LRU list */
1055
/* node of the LRU list */
1296
1056
#ifdef UNIV_DEBUG
1297
ibool in_LRU_list; /*!< TRUE if the page is in
1298
the LRU list; used in
1057
ibool in_LRU_list; /* TRUE if the page is in the LRU list;
1058
used in debugging */
1300
1059
#endif /* UNIV_DEBUG */
1301
unsigned old:1; /*!< TRUE if the block is in the old
1302
blocks in buf_pool->LRU_old */
1303
unsigned freed_page_clock:31;/*!< the value of
1304
buf_pool->freed_page_clock
1305
when this block was the last
1306
time put to the head of the
1307
LRU list; a thread is allowed
1308
to read this for heuristic
1309
purposes without holding any
1311
unsigned access_time:32; /*!< time of first access, or
1312
0 if the block was never accessed
1313
in the buffer pool */
1315
# ifdef UNIV_DEBUG_FILE_ACCESSES
1060
unsigned old:1; /* TRUE if the block is in the old
1061
blocks in the LRU list */
1062
unsigned LRU_position:31;/* value which monotonically decreases
1063
(or may stay constant if old==TRUE)
1064
toward the end of the LRU list, if
1065
buf_pool->ulint_clock has not wrapped
1066
around: NOTE that this value can only
1067
be used in heuristic algorithms,
1068
because of the possibility of a
1070
unsigned freed_page_clock:32;/* the value of
1071
buf_pool->freed_page_clock when this
1072
block was the last time put to the
1073
head of the LRU list; a thread is
1074
allowed to read this for heuristic
1075
purposes without holding any mutex or
1077
#ifdef UNIV_DEBUG_FILE_ACCESSES
1316
1078
ibool file_page_was_freed;
1317
/*!< this is set to TRUE when fsp
1079
/* this is set to TRUE when fsp
1318
1080
frees a page in buffer pool */
1319
# endif /* UNIV_DEBUG_FILE_ACCESSES */
1320
#endif /* !UNIV_HOTBACKUP */
1321
buf_pool_t* buf_pool; /*!< buffer pool instance this
1081
#endif /* UNIV_DEBUG_FILE_ACCESSES */
1325
/** The buffer control block structure */
1084
/* The buffer control block structure */
1327
1086
struct buf_block_struct{
1329
/** @name General fields */
1088
/* 1. General fields */
1332
buf_page_t page; /*!< page information; this must
1090
buf_page_t page; /* page information; this must
1333
1091
be the first field, so that
1334
1092
buf_pool->page_hash can point
1335
1093
to buf_page_t or buf_block_t */
1336
byte* frame; /*!< pointer to buffer frame which
1337
is of size UNIV_PAGE_SIZE, and
1338
aligned to an address divisible by
1340
#ifndef UNIV_HOTBACKUP
1341
1094
UT_LIST_NODE_T(buf_block_t) unzip_LRU;
1342
/*!< node of the decompressed LRU list;
1095
/* node of the decompressed LRU list;
1343
1096
a block is in the unzip_LRU list
1344
1097
if page.state == BUF_BLOCK_FILE_PAGE
1345
1098
and page.zip.data != NULL */
1346
1099
#ifdef UNIV_DEBUG
1347
ibool in_unzip_LRU_list;/*!< TRUE if the page is in the
1100
ibool in_unzip_LRU_list;/* TRUE if the page is in the
1348
1101
decompressed LRU list;
1349
1102
used in debugging */
1350
1103
#endif /* UNIV_DEBUG */
1351
mutex_t mutex; /*!< mutex protecting this block:
1104
byte* frame; /* pointer to buffer frame which
1105
is of size UNIV_PAGE_SIZE, and
1106
aligned to an address divisible by
1108
mutex_t mutex; /* mutex protecting this block:
1352
1109
state (also protected by the buffer
1353
1110
pool mutex), io_fix, buf_fix_count,
1354
1111
and accessed; we introduce this new
1355
1112
mutex in InnoDB-5.1 to relieve
1356
1113
contention on the buffer pool mutex */
1357
rw_lock_t lock; /*!< read-write lock of the buffer
1114
rw_lock_t lock; /* read-write lock of the buffer
1359
unsigned lock_hash_val:32;/*!< hashed value of the page address
1360
in the record lock hash table;
1361
protected by buf_block_t::lock
1362
(or buf_block_t::mutex, buf_pool->mutex
1363
in buf_page_get_gen(),
1364
buf_page_init_for_read()
1365
and buf_page_create()) */
1366
ibool check_index_page_at_flush;
1367
/*!< TRUE if we know that this is
1116
unsigned lock_hash_val:32;/* hashed value of the page address
1117
in the record lock hash table */
1118
unsigned check_index_page_at_flush:1;
1119
/* TRUE if we know that this is
1368
1120
an index page, and want the database
1369
1121
to check its consistency before flush;
1370
1122
note that there may be pages in the
1371
1123
buffer pool which are index pages,
1372
1124
but this flag is not set because
1373
we do not keep track of all pages;
1374
NOT protected by any mutex */
1376
/** @name Optimistic search field */
1379
ib_uint64_t modify_clock; /*!< this clock is incremented every
1125
we do not keep track of all pages */
1127
/* 2. Optimistic search field */
1129
ib_uint64_t modify_clock; /* this clock is incremented every
1380
1130
time a pointer to a record on the
1381
1131
page may become obsolete; this is
1382
1132
used in the optimistic cursor
1387
1137
pool mutex and the page is not
1388
1138
bufferfixed, or (2) the thread has an
1389
1139
x-latch on the block */
1391
/** @name Hash search fields (unprotected)
1392
NOTE that these fields are NOT protected by any semaphore! */
1395
ulint n_hash_helps; /*!< counter which controls building
1141
/* 3. Hash search fields: NOTE that the first 4 fields are NOT
1142
protected by any semaphore! */
1144
ulint n_hash_helps; /* counter which controls building
1396
1145
of a new hash index for the page */
1397
ulint n_fields; /*!< recommended prefix length for hash
1146
ulint n_fields; /* recommended prefix length for hash
1398
1147
search: number of full fields */
1399
ulint n_bytes; /*!< recommended prefix: number of bytes
1148
ulint n_bytes; /* recommended prefix: number of bytes
1400
1149
in an incomplete field */
1401
ibool left_side; /*!< TRUE or FALSE, depending on
1150
ibool left_side; /* TRUE or FALSE, depending on
1402
1151
whether the leftmost record of several
1403
1152
records with the same prefix should be
1404
1153
indexed in the hash index */
1407
/** @name Hash search fields
1408
These 6 fields may only be modified when we have
1155
/* These 6 fields may only be modified when we have
1409
1156
an x-latch on btr_search_latch AND
1410
- we are holding an s-latch or x-latch on buf_block_struct::lock or
1411
- we know that buf_block_struct::buf_fix_count == 0.
1157
a) we are holding an s-latch or x-latch on block->lock or
1158
b) we know that block->buf_fix_count == 0.
1413
1160
An exception to this is when we init or create a page
1414
1161
in the buffer pool in buf0buf.c. */
1418
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
1419
ulint n_pointers; /*!< used in debugging: the number of
1164
ulint n_pointers; /* used in debugging: the number of
1420
1165
pointers in the adaptive hash index
1421
1166
pointing to this frame */
1422
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1423
unsigned is_hashed:1; /*!< TRUE if hash index has
1424
already been built on this
1425
page; note that it does not
1426
guarantee that the index is
1427
complete, though: there may
1428
have been hash collisions,
1429
record deletions, etc. */
1430
unsigned curr_n_fields:10;/*!< prefix length for hash indexing:
1167
#endif /* UNIV_DEBUG */
1168
unsigned is_hashed:1; /* TRUE if hash index has already been
1169
built on this page; note that it does
1170
not guarantee that the index is
1171
complete, though: there may have been
1172
hash collisions, record deletions,
1174
unsigned curr_n_fields:10;/* prefix length for hash indexing:
1431
1175
number of full fields */
1432
unsigned curr_n_bytes:15;/*!< number of bytes in hash
1434
unsigned curr_left_side:1;/*!< TRUE or FALSE in hash indexing */
1435
dict_index_t* index; /*!< Index for which the adaptive
1176
unsigned curr_n_bytes:15;/* number of bytes in hash indexing */
1177
unsigned curr_left_side:1;/* TRUE or FALSE in hash indexing */
1178
dict_index_t* index; /* Index for which the adaptive
1436
1179
hash index has been created. */
1438
# ifdef UNIV_SYNC_DEBUG
1439
/** @name Debug fields */
1441
rw_lock_t debug_latch; /*!< in the debug version, each thread
1180
/* 4. Debug fields */
1181
#ifdef UNIV_SYNC_DEBUG
1182
rw_lock_t debug_latch; /* in the debug version, each thread
1442
1183
which bufferfixes the block acquires
1443
1184
an s-latch here; so we can use the
1444
1185
debug utilities in sync0rw */
1447
#endif /* !UNIV_HOTBACKUP */
1450
/** Check if a buf_block_t object is in a valid state
1451
@param block buffer block
1452
@return TRUE if valid */
1189
/* Check if a buf_block_t object is in a valid state. */
1453
1190
#define buf_block_state_valid(block) \
1454
1191
(buf_block_get_state(block) >= BUF_BLOCK_NOT_USED \
1455
1192
&& (buf_block_get_state(block) <= BUF_BLOCK_REMOVE_HASH))
1457
#ifndef UNIV_HOTBACKUP
1458
/**********************************************************************//**
1194
/**************************************************************************
1459
1195
Compute the hash fold value for blocks in buf_pool->zip_hash. */
1461
1196
#define BUF_POOL_ZIP_FOLD_PTR(ptr) ((ulint) (ptr) / UNIV_PAGE_SIZE)
1462
1197
#define BUF_POOL_ZIP_FOLD(b) BUF_POOL_ZIP_FOLD_PTR((b)->frame)
1463
1198
#define BUF_POOL_ZIP_FOLD_BPAGE(b) BUF_POOL_ZIP_FOLD((buf_block_t*) (b))
1466
/** @brief The buffer pool statistics structure. */
1467
struct buf_pool_stat_struct{
1468
ulint n_page_gets; /*!< number of page gets performed;
1469
also successful searches through
1470
the adaptive hash index are
1471
counted as page gets; this field
1472
is NOT protected by the buffer
1474
ulint n_pages_read; /*!< number read operations */
1475
ulint n_pages_written;/*!< number write operations */
1476
ulint n_pages_created;/*!< number of pages created
1477
in the pool with no read */
1478
ulint n_ra_pages_read;/*!< number of pages read in
1479
as part of read ahead */
1480
ulint n_ra_pages_evicted;/*!< number of read ahead
1481
pages that are evicted without
1483
ulint n_pages_made_young; /*!< number of pages made young, in
1484
calls to buf_LRU_make_block_young() */
1485
ulint n_pages_not_made_young; /*!< number of pages not made
1486
young because the first access
1487
was not long enough ago, in
1488
buf_page_peek_if_too_old() */
1491
/** Statistics of buddy blocks of a given size. */
1492
struct buf_buddy_stat_struct {
1493
/** Number of blocks allocated from the buddy system. */
1495
/** Number of blocks relocated by the buddy system. */
1496
ib_uint64_t relocated;
1497
/** Total duration of block relocations, in microseconds. */
1498
ib_uint64_t relocated_usec;
1501
/** @brief The buffer pool structure.
1503
NOTE! The definition appears here only for other modules of this
1504
directory (buf) to see it. Do not use from outside! */
1200
/* The buffer pool structure. NOTE! The definition appears here only for
1201
other modules of this directory (buf) to see it. Do not use from outside! */
1506
1203
struct buf_pool_struct{
1508
/** @name General fields */
1510
mutex_t mutex; /*!< Buffer pool mutex of this
1512
mutex_t zip_mutex; /*!< Zip mutex of this buffer
1513
pool instance, protects compressed
1514
only pages (of type buf_page_t, not
1516
ulint instance_no; /*!< Array index of this buffer
1518
ulint old_pool_size; /*!< Old pool size in bytes */
1519
ulint curr_pool_size; /*!< Current pool size in bytes */
1520
ulint LRU_old_ratio; /*!< Reserve this much of the buffer
1521
pool for "old" blocks */
1523
ulint buddy_n_frames; /*!< Number of frames allocated from
1524
the buffer pool to the buddy system */
1526
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
1527
ulint mutex_exit_forbidden; /*!< Forbid release mutex */
1529
ulint n_chunks; /*!< number of buffer pool chunks */
1530
buf_chunk_t* chunks; /*!< buffer pool chunks */
1531
ulint curr_size; /*!< current pool size in pages */
1532
hash_table_t* page_hash; /*!< hash table of buf_page_t or
1205
/* 1. General fields */
1207
ulint n_chunks; /* number of buffer pool chunks */
1208
buf_chunk_t* chunks; /* buffer pool chunks */
1209
ulint curr_size; /* current pool size in pages */
1210
hash_table_t* page_hash; /* hash table of buf_page_t or
1533
1211
buf_block_t file pages,
1534
1212
buf_page_in_file() == TRUE,
1535
1213
indexed by (space_id, offset) */
1536
hash_table_t* zip_hash; /*!< hash table of buf_block_t blocks
1214
hash_table_t* zip_hash; /* hash table of buf_block_t blocks
1537
1215
whose frames are allocated to the
1538
1216
zip buddy system,
1539
1217
indexed by block->frame */
1540
ulint n_pend_reads; /*!< number of pending read
1542
ulint n_pend_unzip; /*!< number of pending decompressions */
1218
ulint n_pend_reads; /* number of pending read operations */
1219
ulint n_pend_unzip; /* number of pending decompressions */
1544
time_t last_printout_time;
1545
/*!< when buf_print_io was last time
1221
time_t last_printout_time; /* when buf_print was last time
1547
buf_buddy_stat_t buddy_stat[BUF_BUDDY_SIZES + 1];
1548
/*!< Statistics of buddy system,
1549
indexed by block size */
1550
buf_pool_stat_t stat; /*!< current statistics */
1551
buf_pool_stat_t old_stat; /*!< old statistics */
1555
/** @name Page flushing algorithm fields */
1559
mutex_t flush_list_mutex;/*!< mutex protecting the
1560
flush list access. This mutex
1561
protects flush_list, flush_rbt
1562
and bpage::list pointers when
1563
the bpage is on flush_list. It
1564
also protects writes to
1565
bpage::oldest_modification */
1223
ulint n_pages_read; /* number read operations */
1224
ulint n_pages_written;/* number write operations */
1225
ulint n_pages_created;/* number of pages created in the pool
1227
ulint n_page_gets; /* number of page gets performed;
1228
also successful searches through
1229
the adaptive hash index are
1230
counted as page gets; this field
1231
is NOT protected by the buffer
1233
ulint n_page_gets_old;/* n_page_gets when buf_print was
1234
last time called: used to calculate
1236
ulint n_pages_read_old;/* n_pages_read when buf_print was
1238
ulint n_pages_written_old;/* number write operations */
1239
ulint n_pages_created_old;/* number of pages created in
1240
the pool with no read */
1241
/* 2. Page flushing algorithm fields */
1566
1243
UT_LIST_BASE_NODE_T(buf_page_t) flush_list;
1567
/*!< base node of the modified block
1244
/* base node of the modified block
1569
1246
ibool init_flush[BUF_FLUSH_N_TYPES];
1570
/*!< this is TRUE when a flush of the
1247
/* this is TRUE when a flush of the
1571
1248
given type is being initialized */
1572
1249
ulint n_flush[BUF_FLUSH_N_TYPES];
1573
/*!< this is the number of pending
1250
/* this is the number of pending
1574
1251
writes in the given flush type */
1575
1252
os_event_t no_flush[BUF_FLUSH_N_TYPES];
1576
/*!< this is in the set state
1577
when there is no flush batch
1578
of the given type running */
1579
ib_rbt_t* flush_rbt; /*!< a red-black tree is used
1580
exclusively during recovery to
1581
speed up insertions in the
1582
flush_list. This tree contains
1584
oldest_modification LSN and is
1585
kept in sync with the
1587
Each member of the tree MUST
1588
also be on the flush_list.
1589
This tree is relevant only in
1590
recovery and is set to NULL
1591
once the recovery is over.
1592
Protected by flush_list_mutex */
1593
ulint freed_page_clock;/*!< a sequence number used
1594
to count the number of buffer
1595
blocks removed from the end of
1596
the LRU list; NOTE that this
1597
counter may wrap around at 4
1598
billion! A thread is allowed
1599
to read this for heuristic
1600
purposes without holding any
1602
ulint LRU_flush_ended;/*!< when an LRU flush ends for a page,
1253
/* this is in the set state when there
1254
is no flush batch of the given type
1256
ulint ulint_clock; /* a sequence number used to count
1257
time. NOTE! This counter wraps
1258
around at 4 billion (if ulint ==
1260
ulint freed_page_clock;/* a sequence number used to count the
1261
number of buffer blocks removed from
1262
the end of the LRU list; NOTE that
1263
this counter may wrap around at 4
1264
billion! A thread is allowed to
1265
read this for heuristic purposes
1266
without holding any mutex or latch */
1267
ulint LRU_flush_ended;/* when an LRU flush ends for a page,
1603
1268
this is incremented by one; this is
1604
1269
set to zero when a buffer block is
1608
/** @name LRU replacement algorithm fields */
1272
/* 3. LRU replacement algorithm fields */
1611
1274
UT_LIST_BASE_NODE_T(buf_page_t) free;
1612
/*!< base node of the free
1275
/* base node of the free block list */
1614
1276
UT_LIST_BASE_NODE_T(buf_page_t) LRU;
1615
/*!< base node of the LRU list */
1616
buf_page_t* LRU_old; /*!< pointer to the about
1617
buf_LRU_old_ratio/BUF_LRU_OLD_RATIO_DIV
1618
oldest blocks in the LRU list;
1619
NULL if LRU length less than
1620
BUF_LRU_OLD_MIN_LEN;
1277
/* base node of the LRU list */
1278
buf_page_t* LRU_old; /* pointer to the about 3/8 oldest
1279
blocks in the LRU list; NULL if LRU
1280
length less than BUF_LRU_OLD_MIN_LEN;
1621
1281
NOTE: when LRU_old != NULL, its length
1622
1282
should always equal LRU_old_len */
1623
ulint LRU_old_len; /*!< length of the LRU list from
1283
ulint LRU_old_len; /* length of the LRU list from
1624
1284
the block to which LRU_old points
1625
1285
onward, including that block;
1626
1286
see buf0lru.c for the restrictions
1627
on this value; 0 if LRU_old == NULL;
1287
on this value; not defined if
1628
1289
NOTE: LRU_old_len must be adjusted
1629
1290
whenever LRU_old shrinks or grows! */
1631
1292
UT_LIST_BASE_NODE_T(buf_block_t) unzip_LRU;
1632
/*!< base node of the
1293
/* base node of the unzip_LRU list */
1636
/** @name Buddy allocator fields
1637
The buddy allocator is used for allocating compressed page
1638
frames and buf_page_t descriptors of blocks that exist
1639
in the buffer pool only in compressed form. */
1295
/* 4. Fields for the buddy allocator of compressed pages */
1641
1296
UT_LIST_BASE_NODE_T(buf_page_t) zip_clean;
1642
/*!< unmodified compressed pages */
1297
/* unmodified compressed pages */
1643
1298
UT_LIST_BASE_NODE_T(buf_page_t) zip_free[BUF_BUDDY_SIZES];
1644
/*!< buddy free lists */
1646
buf_page_t watch[BUF_POOL_WATCH_SIZE];
1647
/*!< Sentinel records for buffer
1648
pool watches. Protected by
1299
/* buddy free lists */
1651
1300
#if BUF_BUDDY_HIGH != UNIV_PAGE_SIZE
1652
1301
# error "BUF_BUDDY_HIGH != UNIV_PAGE_SIZE"
1654
1303
#if BUF_BUDDY_LOW > PAGE_ZIP_MIN_SIZE
1655
1304
# error "BUF_BUDDY_LOW > PAGE_ZIP_MIN_SIZE"
1660
/** mutex protecting the buffer pool struct and control blocks, except the
1308
/* mutex protecting the buffer pool struct and control blocks, except the
1661
1309
read-write lock in them */
1662
1310
extern mutex_t buf_pool_mutex;
1663
/** mutex protecting the control blocks of compressed-only pages
1311
/* mutex protecting the control blocks of compressed-only pages
1664
1312
(of type buf_page_t, not buf_block_t) */
1665
1313
extern mutex_t buf_pool_zip_mutex;
1667
/** @name Accessors for buf_pool_mutex.
1668
Use these instead of accessing buf_pool_mutex directly. */
1671
/** Test if buf_pool_mutex is owned. */
1672
#define buf_pool_mutex_own(b) mutex_own(&b->mutex)
1673
/** Acquire the buffer pool mutex. */
1674
#define buf_pool_mutex_enter(b) do { \
1675
ut_ad(!mutex_own(&b->zip_mutex)); \
1676
mutex_enter(&b->mutex); \
1679
/** Test if flush list mutex is owned. */
1680
#define buf_flush_list_mutex_own(b) mutex_own(&b->flush_list_mutex)
1682
/** Acquire the flush list mutex. */
1683
#define buf_flush_list_mutex_enter(b) do { \
1684
mutex_enter(&b->flush_list_mutex); \
1686
/** Release the flush list mutex. */
1687
# define buf_flush_list_mutex_exit(b) do { \
1688
mutex_exit(&b->flush_list_mutex); \
1315
/* Accessors for buf_pool_mutex. Use these instead of accessing
1316
buf_pool_mutex directly. */
1318
/* Test if buf_pool_mutex is owned. */
1319
#define buf_pool_mutex_own() mutex_own(&buf_pool_mutex)
1320
/* Acquire the buffer pool mutex. */
1321
#define buf_pool_mutex_enter() do { \
1322
ut_ad(!mutex_own(&buf_pool_zip_mutex)); \
1323
mutex_enter(&buf_pool_mutex); \
1693
1326
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
1694
/** Forbid the release of the buffer pool mutex. */
1695
# define buf_pool_mutex_exit_forbid(b) do { \
1696
ut_ad(buf_pool_mutex_own(b)); \
1697
b->mutex_exit_forbidden++; \
1699
/** Allow the release of the buffer pool mutex. */
1700
# define buf_pool_mutex_exit_allow(b) do { \
1701
ut_ad(buf_pool_mutex_own(b)); \
1702
ut_a(b->mutex_exit_forbidden); \
1703
b->mutex_exit_forbidden--; \
1705
/** Release the buffer pool mutex. */
1706
# define buf_pool_mutex_exit(b) do { \
1707
ut_a(!b->mutex_exit_forbidden); \
1708
mutex_exit(&b->mutex); \
1327
/** Flag to forbid the release of the buffer pool mutex.
1328
Protected by buf_pool_mutex. */
1329
extern ulint buf_pool_mutex_exit_forbidden;
1330
/* Forbid the release of the buffer pool mutex. */
1331
# define buf_pool_mutex_exit_forbid() do { \
1332
ut_ad(buf_pool_mutex_own()); \
1333
buf_pool_mutex_exit_forbidden++; \
1335
/* Allow the release of the buffer pool mutex. */
1336
# define buf_pool_mutex_exit_allow() do { \
1337
ut_ad(buf_pool_mutex_own()); \
1338
ut_a(buf_pool_mutex_exit_forbidden); \
1339
buf_pool_mutex_exit_forbidden--; \
1341
/* Release the buffer pool mutex. */
1342
# define buf_pool_mutex_exit() do { \
1343
ut_a(!buf_pool_mutex_exit_forbidden); \
1344
mutex_exit(&buf_pool_mutex); \
1711
/** Forbid the release of the buffer pool mutex. */
1712
# define buf_pool_mutex_exit_forbid(b) ((void) 0)
1713
/** Allow the release of the buffer pool mutex. */
1714
# define buf_pool_mutex_exit_allow(b) ((void) 0)
1715
/** Release the buffer pool mutex. */
1716
# define buf_pool_mutex_exit(b) mutex_exit(&b->mutex)
1347
/* Forbid the release of the buffer pool mutex. */
1348
# define buf_pool_mutex_exit_forbid() ((void) 0)
1349
/* Allow the release of the buffer pool mutex. */
1350
# define buf_pool_mutex_exit_allow() ((void) 0)
1351
/* Release the buffer pool mutex. */
1352
# define buf_pool_mutex_exit() mutex_exit(&buf_pool_mutex)
1718
#endif /* !UNIV_HOTBACKUP */
1721
/**********************************************************************
1355
/************************************************************************
1722
1356
Let us list the consistency conditions for different control block states.
1724
1358
NOT_USED: is in free list, not in LRU list, not in flush list, nor