MySQL 9.3.0
Source Code Documentation
buf0buf.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 2025, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/buf0buf.h
29 The database buffer pool high-level routines
30
31 Created 11/5/1995 Heikki Tuuri
32 *******************************************************/
33
34#ifndef buf0buf_h
35#define buf0buf_h
36
37#include "buf0types.h"
38#include "fil0fil.h"
39#include "hash0hash.h"
40#include "mtr0types.h"
41#include "os0proc.h"
42#include "page0types.h"
43#include "srv0shutdown.h"
44#include "srv0srv.h"
45#include "univ.i"
46#include "ut0byte.h"
47
48#include "buf/buf.h"
49
50#include <ostream>
51
52// Forward declaration
53struct fil_addr_t;
54
55/** @name Modes for buf_page_get_gen */
56/** @{ */
57enum class Page_fetch {
58 /** Get always */
59 NORMAL,
60
61 /** Same as NORMAL, but hint that the fetch is part of a large scan.
62 Try not to flood the buffer pool with pages that may not be accessed again
63 any time soon. */
64 SCAN,
65
66 /** get if in pool */
68
69 /** get if in pool, do not make the block young in the LRU list */
71
72 /** get and bufferfix, but set no latch; we have separated this case, because
73 it is error-prone programming not to set a latch, and it should be used with
74 care */
76
77 /** Get the page only if it's in the buffer pool, if not then set a watch on
78 the page. */
80
81 /** Like Page_fetch::NORMAL, but do not mind if the file page has been
82 freed. */
84
85 /** Like Page_fetch::POSSIBLY_FREED, but do not initiate read ahead. */
87};
88/** @} */
89
90/** @name Modes for buf_page_get_known_nowait */
91
92/** @{ */
93enum class Cache_hint {
94 /** Move the block to the start of the LRU list if there is a danger that the
95 block would drift out of the buffer pool*/
96 MAKE_YOUNG = 51,
97
98 /** Preserve the current LRU position of the block. */
99 KEEP_OLD = 52
100};
101
102/** @} */
103
104/** Number of bits to representing a buffer pool ID */
106
107/** The maximum number of buffer pools that can be defined */
109
110/** Maximum number of concurrent buffer pool watches */
111#define BUF_POOL_WATCH_SIZE (srv_n_purge_threads + 1)
112
113/** The maximum number of page_hash locks */
114constexpr ulint MAX_PAGE_HASH_LOCKS = 1024;
115
116/** The buffer pools of the database */
118
119#ifdef UNIV_HOTBACKUP
120/** first block, for --apply-log */
121extern buf_block_t *back_block1;
122/** second block, for page reorganize */
123extern buf_block_t *back_block2;
124#endif /* UNIV_HOTBACKUP */
125
126/** @brief States of a control block
127@see buf_page_t
128
129The enumeration values must be 0..7. */
130enum buf_page_state : uint8_t {
131 /** A sentinel for the buffer pool watch, element of buf_pool->watch[] */
133 /** Contains a clean compressed page */
135 /** Contains a compressed page that is in the buf_pool->flush_list */
137
138 /** Is in the free list; must be after the BUF_BLOCK_ZIP_ constants for
139 compressed-only pages @see buf_block_state_valid() */
141
142 /** When buf_LRU_get_free_block returns a block, it is in this state */
144
145 /** Contains a buffered file page */
147
148 /** Contains some main memory object */
150
151 /** Hash index should be removed before putting to the free list */
154
155const std::unordered_map<buf_page_state, std::string_view> buf_page_state_str{
156 /* First three states are for compression pages and are not states we would
157 get as we scan pages through buffer blocks */
159 {BUF_BLOCK_ZIP_PAGE, ""},
161 {BUF_BLOCK_NOT_USED, "NOT_USED"},
162 {BUF_BLOCK_READY_FOR_USE, "READY_FOR_USE"},
163 {BUF_BLOCK_FILE_PAGE, "FILE_PAGE"},
164 {BUF_BLOCK_MEMORY, "MEMORY"},
165 {BUF_BLOCK_REMOVE_HASH, "REMOVE_HASH"}};
166
167/** This structure defines information we will fetch from each buffer pool. It
168will be used to print table IO stats */
170 /* General buffer pool info */
171
172 /** Buffer Pool ID */
174 /** Buffer Pool size in pages */
176 /** Length of buf_pool->LRU */
178 /** buf_pool->LRU_old_len */
180 /** Length of buf_pool->free list */
182 /** Length of buf_pool->flush_list */
184 /** buf_pool->n_pend_unzip, pages pending decompress */
186 /** buf_pool->n_pend_reads, pages pending read */
188 /** Number of pages pending flush of given type */
189 std::array<size_t, BUF_FLUSH_N_TYPES> n_pending_flush;
190 /** number of pages made young */
192 /** number of pages not made young */
194 /** buf_pool->n_pages_read */
196 /** buf_pool->n_pages_created */
198 /** buf_pool->n_pages_written */
200 /** buf_pool->n_page_gets */
202 /** buf_pool->n_ra_pages_read_rnd, number of pages readahead */
204 /** buf_pool->n_ra_pages_read, number of pages readahead */
206 /** buf_pool->n_ra_pages_evicted, number of readahead pages evicted without
207 access */
209 /** num of buffer pool page gets since last printout */
211
212 /* Buffer pool access stats */
213 double page_made_young_rate; /*!< page made young rate in pages
214 per second */
215 double page_not_made_young_rate; /*!< page not made young rate
216 in pages per second */
217 double pages_read_rate; /*!< num of pages read per second */
218 double pages_created_rate; /*!< num of pages create per second */
219 double pages_written_rate; /*!< num of pages written per second */
220 ulint page_read_delta; /*!< num of pages read since last
221 printout */
222 ulint young_making_delta; /*!< num of pages made young since
223 last printout */
224 ulint not_young_making_delta; /*!< num of pages not make young since
225 last printout */
226
227 /* Statistics about read ahead algorithm. */
228 double pages_readahead_rnd_rate; /*!< random readahead rate in pages per
229 second */
230 double pages_readahead_rate; /*!< readahead rate in pages per
231 second */
232 double pages_evicted_rate; /*!< rate of readahead page evicted
233 without access, in pages per second */
234
235 /* Stats about LRU eviction */
236 ulint unzip_lru_len; /*!< length of buf_pool->unzip_LRU
237 list */
238 /* Counters for LRU policy */
239 ulint io_sum; /*!< buf_LRU_stat_sum.io */
240 ulint io_cur; /*!< buf_LRU_stat_cur.io, num of IO
241 for current interval */
242 ulint unzip_sum; /*!< buf_LRU_stat_sum.unzip */
243 ulint unzip_cur; /*!< buf_LRU_stat_cur.unzip, num
244 pages decompressed in current
245 interval */
246};
247
248/** The occupied bytes of lists in all buffer pools */
250 ulint LRU_bytes; /*!< LRU size in bytes */
251 ulint unzip_LRU_bytes; /*!< unzip_LRU size in bytes */
252 ulint flush_list_bytes; /*!< flush_list size in bytes */
253};
254
255#ifndef UNIV_HOTBACKUP
256/** Creates the buffer pool.
257@param[in] total_size Size of the total pool in bytes.
258@param[in] n_instances Number of buffer pool instances to create.
259@return DB_SUCCESS if success, DB_ERROR if not enough memory or error */
260dberr_t buf_pool_init(ulint total_size, ulint n_instances);
261
262/** Frees the buffer pool at shutdown. This must not be invoked before
263 freeing all mutexes. */
264void buf_pool_free_all();
265
266/** Determines if a block is intended to be withdrawn. The caller must ensure
267that there was a sufficient memory barrier to read curr_size and old_size.
268@param[in] buf_pool buffer pool instance
269@param[in] block pointer to control block
270@retval true if will be withdrawn */
271bool buf_block_will_withdrawn(buf_pool_t *buf_pool, const buf_block_t *block);
272
273/** Determines if a frame is intended to be withdrawn. The caller must ensure
274that there was a sufficient memory barrier to read curr_size and old_size.
275@param[in] buf_pool buffer pool instance
276@param[in] ptr pointer to a frame
277@retval true if will be withdrawn */
278bool buf_frame_will_withdrawn(buf_pool_t *buf_pool, const byte *ptr);
279
280/** This is the thread for resizing buffer pool. It waits for an event and
281when waked up either performs a resizing and sleeps again. */
282void buf_resize_thread();
283
284/** Checks if innobase_should_madvise_buf_pool() value has changed since we've
285last check and if so, then updates buf_pool_should_madvise and calls madvise
286for all chunks in all srv_buf_pool_instances.
287@see buf_pool_should_madvise comment for a longer explanation. */
289
290/** Clears the adaptive hash index on all pages in the buffer pool. */
292
293/** Gets the current size of buffer buf_pool in bytes.
294 @return size in bytes */
295static inline ulint buf_pool_get_curr_size(void);
296/** Gets the current size of buffer buf_pool in frames.
297 @return size in pages */
298static inline ulint buf_pool_get_n_pages(void);
299
300/** @return true if buffer pool resize is in progress. */
302
303#endif /* !UNIV_HOTBACKUP */
304
305/** Gets the smallest oldest_modification lsn among all of the earliest
306added pages in flush lists. In other words - takes the last dirty page
307from each flush list, and calculates minimum oldest_modification among
308all of them. Does not acquire global lock for the whole process, so the
309result might come from inconsistent view on flush lists.
310
311@note Note that because of the relaxed order in each flush list, this
312functions no longer returns the smallest oldest_modification among all
313of the dirty pages. If you wanted to have a safe lsn, which is smaller
314than every oldest_modification, you would need to use another function:
315 buf_pool_get_oldest_modification_lwm().
316
317Returns zero if there were no dirty pages (flush lists were empty).
318
319@return minimum oldest_modification of last pages from flush lists,
320 zero if flush lists were empty */
322
323/** Gets a safe low watermark for oldest_modification. It's guaranteed
324that there were no dirty pages with smaller oldest_modification in the
325whole flush lists.
326
327Returns zero if flush lists were empty, be careful in such case, because
328taking the newest lsn is probably not a good idea. If you wanted to rely
329on some lsn in such case, you would need to follow pattern:
330
331 dpa_lsn = buf_flush_list_added->smallest_not_added_lsn();
332
333 lwm_lsn = buf_pool_get_oldest_modification_lwm();
334
335 if (lwm_lsn == 0) lwm_lsn = dpa_lsn;
336
337The order is important to avoid race conditions.
338
339@remarks
340It's guaranteed that the returned value will not be smaller than the
341last checkpoint lsn. It's not guaranteed that the returned value is
342the maximum possible. It's just the best effort for the low cost.
343It basically takes result of buf_pool_get_oldest_modification_approx()
344and subtracts maximum possible lag introduced by relaxed order in
345flush lists (srv_buf_flush_list_added_size).
346
347@return safe low watermark for oldest_modification of dirty pages,
348 or zero if flush lists were empty; if non-zero, it is then
349 guaranteed not to be at block boundary (and it points to lsn
350 inside data fragment of block) */
352
353#ifndef UNIV_HOTBACKUP
354
355/** Allocates a buf_page_t descriptor. This function must succeed. In case
356 of failure we assert in this function. */
358 MY_ATTRIBUTE((malloc));
359
360/** Free a buf_page_t descriptor.
361@param[in] bpage bpage descriptor to free */
363
364/** Allocates a buffer block.
365 @return own: the allocated block, in state BUF_BLOCK_MEMORY */
367 buf_pool_t *buf_pool); /*!< in: buffer pool instance,
368 or NULL for round-robin selection
369 of the buffer pool */
370/** Frees a buffer block which does not contain a file page. */
371static inline void buf_block_free(
372 buf_block_t *block); /*!< in, own: block to be freed */
373#endif /* !UNIV_HOTBACKUP */
374
375/** Copies contents of a buffer frame to a given buffer.
376@param[in] buf buffer to copy to
377@param[in] frame buffer frame
378@return buf */
379static inline byte *buf_frame_copy(byte *buf, const buf_frame_t *frame);
380
381#ifndef UNIV_HOTBACKUP
382/** This is the general function used to get optimistic access to a database
383page.
384@param[in] rw_latch RW_S_LATCH, RW_X_LATCH
385@param[in,out] block Guessed block
386@param[in] modify_clock Modify clock value
387@param[in] fetch_mode Fetch mode
388@param[in] file File name
389@param[in] line Line where called
390@param[in,out] mtr Mini-transaction
391@return true if success */
392bool buf_page_optimistic_get(ulint rw_latch, buf_block_t *block,
393 uint64_t modify_clock, Page_fetch fetch_mode,
394 const char *file, ulint line, mtr_t *mtr);
395
396/** This is used to get access to a known database page, when no waiting can be
397done.
398@param[in] rw_latch RW_S_LATCH or RW_X_LATCH.
399@param[in] block The known page.
400@param[in] hint Cache_hint::MAKE_YOUNG or Cache_hint::KEEP_OLD
401@param[in] file File name from where it was called.
402@param[in] line Line from where it was called.
403@param[in,out] mtr Mini-transaction covering the fetch
404@return true if success */
405bool buf_page_get_known_nowait(ulint rw_latch, buf_block_t *block,
406 Cache_hint hint, const char *file, ulint line,
407 mtr_t *mtr);
408
409/** Given a tablespace id and page number tries to get that page. If the
410page is not in the buffer pool it is not loaded and NULL is returned.
411Suitable for using when holding the lock_sys latches (as it avoids deadlock).
412@param[in] page_id page Id
413@param[in] location Location where called
414@param[in] mtr Mini-transaction
415@return pointer to a page or NULL */
416const buf_block_t *buf_page_try_get(const page_id_t &page_id,
417 ut::Location location, mtr_t *mtr);
418
419/** Get read access to a compressed page (usually of type
420FIL_PAGE_TYPE_ZBLOB or FIL_PAGE_TYPE_ZBLOB2).
421The page must be released with buf_page_release_zip().
422NOTE: the page is not protected by any latch. Mutual exclusion has to
423be implemented at a higher level. In other words, all possible
424accesses to a given page through this function must be protected by
425the same set of mutexes or latches.
426@param[in] page_id page id
427@param[in] page_size page size
428@return pointer to the block */
430 const page_size_t &page_size);
431
432/** This is the general function used to get access to a database page.
433@param[in] page_id Page id
434@param[in] page_size Page size
435@param[in] rw_latch RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH
436@param[in] guess Guessed block or NULL
437@param[in] mode Fetch mode.
438@param[in] location Location from where this method was called.
439@param[in] mtr Mini-transaction
440@param[in] dirty_with_no_latch Mark page as dirty even if page is being
441 pinned without any latch
442@return pointer to the block or NULL */
444 const page_size_t &page_size, ulint rw_latch,
446 ut::Location location, mtr_t *mtr,
447 bool dirty_with_no_latch = false);
448
449/** NOTE! The following macros should be used instead of buf_page_get_gen,
450 to improve debugging. Only values RW_S_LATCH and RW_X_LATCH are allowed
451 in LA! */
453 ulint latch, ut::Location location,
454 mtr_t *mtr) {
455 return buf_page_get_gen(id, size, latch, nullptr, Page_fetch::NORMAL,
456 location, mtr);
457}
458/** Use these macros to bufferfix a page with no latching. Remember not to
459 read the contents of the page unless you know it is safe. Do not modify
460 the contents of the page! We have separated this case, because it is
461 error-prone programming not to set a latch, and it should be used
462 with care. */
464 const page_size_t &size,
465 ut::Location location,
466 mtr_t *mtr) {
468 location, mtr);
469}
470
471/** Initializes a page to the buffer buf_pool. The page is usually not read
472from a file even if it cannot be found in the buffer buf_pool. This is one
473of the functions which perform to a block a state transition NOT_USED =>
474FILE_PAGE (the other is buf_page_get_gen). The page is latched by passed mtr.
475@param[in] page_id Page id
476@param[in] page_size Page size
477@param[in] rw_latch RW_SX_LATCH, RW_X_LATCH
478@param[in] mtr Mini-transaction
479@return pointer to the block, page bufferfixed */
481 const page_size_t &page_size,
482 rw_lock_type_t rw_latch, mtr_t *mtr);
483
484#else /* !UNIV_HOTBACKUP */
485
486/** Inits a page to the buffer buf_pool, for use in mysqlbackup --restore.
487@param[in] page_id page id
488@param[in] page_size page size
489@param[in,out] block block to init */
490void meb_page_init(const page_id_t &page_id, const page_size_t &page_size,
491 buf_block_t *block);
492#endif /* !UNIV_HOTBACKUP */
493
494#ifndef UNIV_HOTBACKUP
495/** Releases a compressed-only page acquired with buf_page_get_zip(). */
496static inline void buf_page_release_zip(
497 buf_page_t *bpage); /*!< in: buffer block */
498
499/** Releases a latch, if specified.
500@param[in] block buffer block
501@param[in] rw_latch RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
502static inline void buf_page_release_latch(buf_block_t *block, ulint rw_latch);
503
504/** Moves a page to the start of the buffer pool LRU list. This high-level
505function can be used to prevent an important page from slipping out of
506the buffer pool.
507@param[in,out] bpage buffer block of a file page */
509
510/** Moved a page to the end of the buffer pool LRU list so that it can be
511flushed out at the earliest.
512@param[in] bpage buffer block of a file page */
513void buf_page_make_old(buf_page_t *bpage);
514
515/** Returns true if the page can be found in the buffer pool hash table.
516NOTE that it is possible that the page is not yet read from disk,
517though.
518@param[in] page_id page id
519@return true if found in the page hash table */
520static inline bool buf_page_peek(const page_id_t &page_id);
521
522#ifdef UNIV_DEBUG
523
524/** Sets file_page_was_freed true if the page is found in the buffer pool.
525This function should be called when we free a file page and want the
526debug version to check that it is not accessed any more unless
527reallocated.
528@param[in] page_id page id
529@return control block if found in page hash table, otherwise NULL */
531
532/** Sets file_page_was_freed false if the page is found in the buffer pool.
533This function should be called when we free a file page and want the
534debug version to check that it is not accessed any more unless
535reallocated.
536@param[in] page_id page id
537@return control block if found in page hash table, otherwise NULL */
539
540#endif /* UNIV_DEBUG */
541/** Reads the freed_page_clock of a buffer block.
542 @return freed_page_clock */
543[[nodiscard]] static inline ulint buf_page_get_freed_page_clock(
544 const buf_page_t *bpage); /*!< in: block */
545/** Reads the freed_page_clock of a buffer block.
546 @return freed_page_clock */
547[[nodiscard]] static inline ulint buf_block_get_freed_page_clock(
548 const buf_block_t *block); /*!< in: block */
549
550/** Tells, for heuristics, if a block is still close enough to the MRU end of
551the LRU list meaning that it is not in danger of getting evicted and also
552implying that it has been accessed recently.
553The page must be either buffer-fixed, either its page hash must be locked.
554@param[in] bpage block
555@return true if block is close to MRU end of LRU */
556static inline bool buf_page_peek_if_young(const buf_page_t *bpage);
557
558/** Recommends a move of a block to the start of the LRU list if there is
559danger of dropping from the buffer pool.
560NOTE: does not reserve the LRU list mutex.
561@param[in] bpage block to make younger
562@return true if should be made younger */
563static inline bool buf_page_peek_if_too_old(const buf_page_t *bpage);
564
565/** Gets the youngest modification log sequence number for a frame.
566 Returns zero if not file page or no modification occurred yet.
567 @return newest modification to page */
569 const buf_page_t *bpage); /*!< in: block containing the
570 page frame */
571
572/** Increment the modify clock.
573The caller must
574(1) own the buf_pool->mutex and block bufferfix count has to be zero,
575(2) own X or SX latch on the block->lock, or
576(3) operate on a thread-private temporary table
577@param[in,out] block buffer block */
578static inline void buf_block_modify_clock_inc(buf_block_t *block);
579
580/** Increments the bufferfix count.
581@param[in] location location
582@param[in,out] block block to bufferfix */
584 buf_block_t *block);
585
586/** Increments the bufferfix count.
587@param[in,out] bpage block to bufferfix
588@return the count */
589static inline ulint buf_block_fix(buf_page_t *bpage);
590
591/** Increments the bufferfix count.
592@param[in,out] block block to bufferfix
593@return the count */
594static inline ulint buf_block_fix(buf_block_t *block);
595
596/** Decrements the bufferfix count.
597@param[in,out] bpage block to bufferunfix
598@return the remaining buffer-fix count */
599static inline ulint buf_block_unfix(buf_page_t *bpage);
600
601/** Decrements the bufferfix count.
602@param[in,out] block block to bufferunfix
603@return the remaining buffer-fix count */
604static inline ulint buf_block_unfix(buf_block_t *block);
605
606/** Unfixes the page, unlatches the page,
607removes it from page_hash and removes it from LRU.
608@param[in,out] bpage pointer to the block */
610
611/** Increments the bufferfix count.
612@param[in,out] b block to bufferfix
613@param[in] l location where requested */
615 ut::Location l [[maybe_unused]]) {
617}
618#else /* !UNIV_HOTBACKUP */
619static inline void buf_block_modify_clock_inc(buf_block_t *block) {}
620#endif /* !UNIV_HOTBACKUP */
621
622#ifndef UNIV_HOTBACKUP
623
624/** Gets the space id, page offset, and byte offset within page of a pointer
625pointing to a buffer frame containing a file page.
626@param[in] ptr pointer to a buffer frame
627@param[out] space space id
628@param[out] addr page offset and byte offset */
629static inline void buf_ptr_get_fsp_addr(const void *ptr, space_id_t *space,
630 fil_addr_t *addr);
631
632#ifdef UNIV_DEBUG
633/** Finds a block in the buffer pool that points to a
634given compressed page. Used only to confirm that buffer pool does not contain a
635given pointer, thus protected by zip_free_mutex.
636@param[in] buf_pool buffer pool instance
637@param[in] data pointer to compressed page
638@return buffer block pointing to the compressed page, or NULL */
639buf_block_t *buf_pool_contains_zip(buf_pool_t *buf_pool, const void *data);
640#endif /* UNIV_DEBUG */
641
642/***********************************************************************
643FIXME_FTS: Gets the frame the pointer is pointing to. */
645 /* out: pointer to frame */
646 byte *ptr); /* in: pointer to a frame */
647
648#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
649/** Validates the buffer pool data structure.
650 @return true */
651bool buf_validate(void);
652#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
653#if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
654/** Prints info of the buffer pool data structure. */
655void buf_print(void);
656#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
657#endif /* !UNIV_HOTBACKUP */
659 /** Do not crash at the end of buf_page_print(). */
661 /** Do not print the full page dump. */
664
665/** Prints a page to stderr.
666@param[in] read_buf a database page
667@param[in] page_size page size
668@param[in] flags 0 or BUF_PAGE_PRINT_NO_CRASH or
669BUF_PAGE_PRINT_NO_FULL */
670void buf_page_print(const byte *read_buf, const page_size_t &page_size,
671 ulint flags);
672
673/** Decompress a block.
674 @return true if successful */
675bool buf_zip_decompress(buf_block_t *block, /*!< in/out: block */
676 bool check); /*!< in: true=verify the page checksum */
677#ifndef UNIV_HOTBACKUP
678#ifdef UNIV_DEBUG
679/** Returns the number of latched pages in the buffer pool.
680 @return number of latched pages */
682#endif /* UNIV_DEBUG */
683/** Returns the number of pending buf pool read ios.
684 @return number of pending read I/O operations */
686/** Prints info of the buffer i/o. */
687void buf_print_io(FILE *file); /*!< in: file where to print */
688/** Collect buffer pool stats information for a buffer pool. Also
689 record aggregated stats if there are more than one buffer pool
690 in the server */
692 buf_pool_t *buf_pool, /*!< in: buffer pool */
693 ulint pool_id, /*!< in: buffer pool ID */
694 buf_pool_info_t *all_pool_info); /*!< in/out: buffer pool info
695 to fill */
696/** Return the ratio in percents of modified pages in the buffer pool /
697database pages in the buffer pool.
698@return modified page percentage ratio */
699double buf_get_modified_ratio_pct(void);
700/** Refresh the statistics used to print per-second averages. */
702
703/** Assert that all file pages in the buffer are in a replaceable state. */
705
706/** Computes number of pending I/O read operations for the buffer pool.
707@return number of pending i/o reads */
709
710/** Computes number of pending I/O write operations for the buffer pool.
711@return number of pending i/o writes */
713
714/** Waits until there are no pending I/O operations for the buffer pool.
715Keep waiting in loop with sleeps, emitting information every minute.
716This is used to avoid risk of some pending async IO (e.g. enqueued by
717the linear read-ahead), which would involve ibuf merge and create new
718redo records. */
720
721/** Invalidates the file pages in the buffer pool when an archive recovery is
722 completed. All the file pages buffered must be in a replaceable state when
723 this function is called: not latched and not modified. */
724void buf_pool_invalidate(void);
725
726/*========================================================================
727--------------------------- LOWER LEVEL ROUTINES -------------------------
728=========================================================================*/
729
730#ifdef UNIV_DEBUG
731/** Adds latch level info for the rw-lock protecting the buffer frame. This
732should be called in the debug version after a successful latching of a page if
733we know the latching order level of the acquired latch.
734@param[in] block buffer page where we have acquired latch
735@param[in] level latching order level */
736static inline void buf_block_dbg_add_level(buf_block_t *block,
737 latch_level_t level);
738#else /* UNIV_DEBUG */
739#define buf_block_dbg_add_level(block, level) /* nothing */
740#endif /* UNIV_DEBUG */
741
742#endif /* !UNIV_HOTBACKUP */
743
744/** Gets the state of a block.
745 @return state */
747 const buf_page_t *bpage); /*!< in: pointer to the control block */
748/** Gets the state of a block.
749 @return state */
750[[nodiscard]] static inline enum buf_page_state buf_block_get_state(
751 const buf_block_t *block); /*!< in: pointer to the control block */
752
753/** Sets the state of a block.
754@param[in,out] bpage pointer to control block
755@param[in] state state */
756static inline void buf_page_set_state(buf_page_t *bpage,
757 enum buf_page_state state);
758
759/** Sets the state of a block.
760@param[in,out] block pointer to control block
761@param[in] state state */
762static inline void buf_block_set_state(buf_block_t *block,
763 enum buf_page_state state);
764
765/** Determines if a block is mapped to a tablespace.
766 @return true if mapped */
767[[nodiscard]] static inline bool buf_page_in_file(
768 const buf_page_t *bpage); /*!< in: pointer to control block */
769#ifndef UNIV_HOTBACKUP
770/** Determines if a block should be on unzip_LRU list.
771 @return true if block belongs to unzip_LRU */
772[[nodiscard]] static inline bool buf_page_belongs_to_unzip_LRU(
773 const buf_page_t *bpage); /*!< in: pointer to control block */
774
775/** Gets the mutex of a block.
776 @return pointer to mutex protecting bpage */
777[[nodiscard]] static inline BPageMutex *buf_page_get_mutex(
778 const buf_page_t *bpage); /*!< in: pointer to control block */
779
780/** Get the flush type of a page.
781 @return flush type */
782[[nodiscard]] static inline buf_flush_t buf_page_get_flush_type(
783 const buf_page_t *bpage); /*!< in: buffer page */
784
785/** Set the flush type of a page.
786@param[in] bpage buffer page
787@param[in] flush_type flush type */
788static inline void buf_page_set_flush_type(buf_page_t *bpage,
790
791/** Map a block to a file page.
792@param[in,out] block pointer to control block
793@param[in] page_id page id */
794static inline void buf_block_set_file_page(buf_block_t *block,
795 const page_id_t &page_id);
796
797/** Gets the io_fix state of a block.
798 @return io_fix state */
799[[nodiscard]] static inline enum buf_io_fix buf_page_get_io_fix(
800 const buf_page_t *bpage); /*!< in: pointer to the control block */
801/** Gets the io_fix state of a block.
802 @return io_fix state */
803[[nodiscard]] static inline enum buf_io_fix buf_block_get_io_fix(
804 const buf_block_t *block); /*!< in: pointer to the control block */
805
806/** Sets the io_fix state of a block.
807@param[in,out] bpage control block
808@param[in] io_fix io_fix state */
809static inline void buf_page_set_io_fix(buf_page_t *bpage,
810 enum buf_io_fix io_fix);
811
812/** Sets the io_fix state of a block.
813@param[in,out] block control block
814@param[in] io_fix io_fix state */
815static inline void buf_block_set_io_fix(buf_block_t *block,
816 enum buf_io_fix io_fix);
817
818/** Makes a block sticky. A sticky block implies that even after we release
819the buf_pool->LRU_list_mutex and the block->mutex:
820* it cannot be removed from the flush_list
821* the block descriptor cannot be relocated
822* it cannot be removed from the LRU list
823Note that:
824* the block can still change its position in the LRU list
825* the next and previous pointers can change.
826@param[in,out] bpage control block */
827static inline void buf_page_set_sticky(buf_page_t *bpage);
828
829/** Removes stickiness of a block. */
830static inline void buf_page_unset_sticky(
831 buf_page_t *bpage); /*!< in/out: control block */
832/** Determine if a buffer block can be relocated in memory. The block
833 can be dirty, but it must not be I/O-fixed or bufferfixed. */
834[[nodiscard]] static inline bool buf_page_can_relocate(
835 const buf_page_t *bpage); /*!< control block being relocated */
836
837/** Determine if a block has been flagged old.
838@param[in] bpage control block
839@return true if old */
840[[nodiscard]] static inline bool buf_page_is_old(const buf_page_t *bpage);
841
842/** Flag a block old.
843@param[in,out] bpage control block
844@param[in] old old */
845static inline void buf_page_set_old(buf_page_t *bpage, bool old);
846
847/** Determine the time of first access of a block in the buffer pool.
848 @return Time of first access, zero if not accessed
849 */
850[[nodiscard]] static inline std::chrono::steady_clock::time_point
851buf_page_is_accessed(const buf_page_t *bpage); /*!< in: control block */
852/** Flag a block accessed. */
853static inline void buf_page_set_accessed(
854 buf_page_t *bpage); /*!< in/out: control block */
855
856/** Gets the buf_block_t handle of a buffered file block if an uncompressed
857page frame exists, or NULL. page frame exists, or NULL. The caller must hold
858either the appropriate hash lock in any mode, either the LRU list mutex. Note:
859even though bpage is not declared a const we don't update its value. It is safe
860to make this pure.
861@param[in] bpage control block, or NULL
862@return control block, or NULL */
863[[nodiscard]] static inline buf_block_t *buf_page_get_block(buf_page_t *bpage);
864#ifdef UNIV_DEBUG
865/** Gets a pointer to the memory frame of a block.
866 @return pointer to the frame */
867[[nodiscard]] static inline buf_frame_t *buf_block_get_frame(
868 const buf_block_t *block); /*!< in: pointer to the control block */
869#else /* UNIV_DEBUG */
870#define buf_block_get_frame(block) (block)->frame
871#endif /* UNIV_DEBUG */
872#else /* !UNIV_HOTBACKUP */
873#define buf_block_get_frame(block) (block)->frame
874#endif /* !UNIV_HOTBACKUP */
875
876/** Get a buffer block from an adaptive hash index pointer.
877This function does not return if the block is not identified.
878@param[in] ptr pointer to within a page frame
879@return pointer to block, never NULL */
880buf_block_t *buf_block_from_ahi(const byte *ptr);
881
882/** Find out if a block pointer points into one of currently used chunks of
883the buffer pool. This is useful if you stored the pointer some time ago, and
884want to dereference it now, and are afraid that buffer pool resize could free
885the memory pointed by it. Thus calling this function requires holding at least
886one of the latches which prevent freeing memory from buffer pool for the
887duration of the call and until you pin the block in some other way, as otherwise
888the result of this function might be obsolete by the time you dereference the
889block (an s-latch on buf_page_hash_lock_get for any hash cell is enough).
890@param buf_pool The buffer pool instance to search in.
891@param ptr A pointer which you want to check. This function will not
892 dereference it.
893@return true iff `block` points inside one of the chunks of the `buf_pool`
894*/
895bool buf_is_block_in_instance(const buf_pool_t *buf_pool,
896 const buf_block_t *ptr);
897
898#ifndef UNIV_HOTBACKUP
899
900/** Inits a page for read to the buffer buf_pool. If the page is
901(1) already in buf_pool, or
902(2) if we specify to read only ibuf pages and the page is not an ibuf page, or
903(3) if the space is deleted or being deleted,
904then this function does nothing.
905Sets the io_fix flag to BUF_IO_READ and sets a non-recursive exclusive lock
906on the buffer frame. The io-handler must take care that the flag is cleared
907and the lock released later.
908@param[in] mode BUF_READ_IBUF_PAGES_ONLY, ...
909@param[in] page_id page id
910@param[in] page_size page size
911@param[in] unzip true=request uncompressed page
912@return pointer to the block or NULL */
914 const page_size_t &page_size, bool unzip);
915
916/** Completes an asynchronous read or write request of a file page to or from
917the buffer pool.
918@param[in] bpage pointer to the block in question
919@param[in] evict whether or not to evict the page from LRU list
920@param[in] type i/o request type for which this completion routine is
921 called.
922@param[in] node file node in which the disk copy of the page exists.
923@return true if successful */
924bool buf_page_io_complete(buf_page_t *bpage, bool evict,
925 IORequest *type = nullptr,
926 fil_node_t *node = nullptr);
927
928/** Free a stale page. Caller must hold the LRU mutex. Upon successful page
929free the LRU mutex will be released.
930@param[in,out] buf_pool Buffer pool the page belongs to.
931@param[in,out] bpage Page to free.
932@return true if page was freed. */
933bool buf_page_free_stale(buf_pool_t *buf_pool, buf_page_t *bpage) noexcept;
934
935/** Evict a page from the buffer pool.
936@param[in] page_id page to be evicted.
937@param[in] page_size page size of the tablespace.
938@param[in] dirty_is_ok if true, it is OK for the page to be dirty. */
939void buf_page_force_evict(const page_id_t &page_id,
940 const page_size_t &page_size,
941 const bool dirty_is_ok = true) noexcept;
942
943/** Free a stale page. Caller must be holding the hash_lock in S mode if
944hash_lock parameter is not nullptr. The hash lock will be released upon return
945always. Caller must hold the LRU mutex if and only if the hash_lock parameter
946is nullptr. Upon unsuccessful page free the LRU mutex will not be released if
947hash_lock is nullptr.
948@param[in,out] buf_pool Buffer pool the page belongs to.
949@param[in,out] bpage Page to free.
950@param[in,out] hash_lock Hash lock covering the fetch from the hash table if
951latched in S mode. nullptr otherwise.
952@return true if page was freed. */
953bool buf_page_free_stale(buf_pool_t *buf_pool, buf_page_t *bpage,
954 rw_lock_t *hash_lock) noexcept;
955
956/** Free a stale page that is being written. The caller must be within the
957page's write code path.
958@param[in,out] bpage Page to free.
959@param[in] owns_sx_lock SX lock on block->lock is set. */
961 bool owns_sx_lock = false) noexcept;
962
963/** Calculates the index of a buffer pool to the buf_pool[] array.
964 @return the position of the buffer pool in buf_pool[] */
965[[nodiscard]] static inline ulint buf_pool_index(
966 const buf_pool_t *buf_pool); /*!< in: buffer pool */
967/** Returns the buffer pool instance given a page instance
968 @return buf_pool */
970 const buf_page_t *bpage); /*!< in: buffer pool page */
971/** Returns the buffer pool instance given a block instance
972 @return buf_pool */
974 const buf_block_t *block); /*!< in: block */
975
976/** Returns the buffer pool instance given a page id.
977@param[in] page_id page id
978@return buffer pool */
979static inline buf_pool_t *buf_pool_get(const page_id_t &page_id);
980
981/** Returns the buffer pool instance given its array index
982 @return buffer pool */
984 ulint index); /*!< in: array index to get
985 buffer pool instance from */
986
987/** Returns the control block of a file page, NULL if not found.
988@param[in] buf_pool buffer pool instance
989@param[in] page_id page id
990@return block, NULL if not found */
992 const page_id_t &page_id);
993
994/** Returns the control block of a file page, NULL if not found.
995If the block is found and lock is not NULL then the appropriate
996page_hash lock is acquired in the specified lock mode. Otherwise,
997mode value is ignored. It is up to the caller to release the
998lock. If the block is found and the lock is NULL then the page_hash
999lock is released by this function.
1000@param[in] buf_pool buffer pool instance
1001@param[in] page_id page id
1002@param[in,out] lock lock of the page hash acquired if bpage is
1003found, NULL otherwise. If NULL is passed then the hash_lock is released by
1004this function.
1005@param[in] lock_mode RW_LOCK_X or RW_LOCK_S. Ignored if
1006lock == NULL
1007@param[in] watch if true, return watch sentinel also.
1008@return pointer to the bpage or NULL; if NULL, lock is also NULL or
1009a watch sentinel. */
1011 const page_id_t &page_id,
1012 rw_lock_t **lock,
1014 bool watch = false);
1015
1016/** Returns the control block of a file page, NULL if not found.
1017If the block is found and lock is not NULL then the appropriate
1018page_hash lock is acquired in the specified lock mode. Otherwise,
1019mode value is ignored. It is up to the caller to release the
1020lock. If the block is found and the lock is NULL then the page_hash
1021lock is released by this function.
1022@param[in] buf_pool buffer pool instance
1023@param[in] page_id page id
1024@param[in,out] lock lock of the page hash acquired if bpage is
1025found, NULL otherwise. If NULL is passed then the hash_lock is released by
1026this function.
1027@param[in] lock_mode RW_LOCK_X or RW_LOCK_S. Ignored if
1028lock == NULL
1029@return pointer to the block or NULL; if NULL, lock is also NULL. */
1031 const page_id_t &page_id,
1032 rw_lock_t **lock,
1034
1035/* There are four different ways we can try to get a bpage or block
1036from the page hash:
10371) Caller already holds the appropriate page hash lock: in the case call
1038buf_page_hash_get_low() function.
10392) Caller wants to hold page hash lock in x-mode
10403) Caller wants to hold page hash lock in s-mode
10414) Caller doesn't want to hold page hash lock */
1043 const page_id_t &page_id,
1044 rw_lock_t **l) {
1045 return buf_page_hash_get_locked(b, page_id, l, RW_LOCK_S);
1046}
1048 const page_id_t &page_id,
1049 rw_lock_t **l) {
1050 return buf_page_hash_get_locked(b, page_id, l, RW_LOCK_X);
1051}
1053 return buf_page_hash_get_locked(b, page_id, nullptr, 0);
1054}
1056 const page_id_t &page_id) {
1057 return buf_page_hash_get_locked(b, page_id, nullptr, 0, true);
1058}
1059
1061 const page_id_t &page_id,
1062 rw_lock_t **l) {
1063 return buf_block_hash_get_locked(b, page_id, l, RW_LOCK_S);
1064}
1066 const page_id_t &page_id,
1067 rw_lock_t **l) {
1068 return buf_block_hash_get_locked(b, page_id, l, RW_LOCK_X);
1069}
1071 const page_id_t &page_id) {
1072 return buf_block_hash_get_locked(b, page_id, nullptr, 0);
1073}
1074
1075/** Gets the current length of the free list of buffer blocks.
1076 @return length of the free list */
1078
1079/** Determine if a block is a sentinel for a buffer pool watch.
1080@param[in] buf_pool buffer pool instance
1081@param[in] bpage block
1082@return true if a sentinel for a buffer pool watch, false if not */
1083[[nodiscard]] bool buf_pool_watch_is_sentinel(const buf_pool_t *buf_pool,
1084 const buf_page_t *bpage);
1085
1086/** Stop watching if the page has been read in.
1087buf_pool_watch_set(same_page_id) must have returned NULL before.
1088@param[in] page_id page id */
1089void buf_pool_watch_unset(const page_id_t &page_id);
1090
1091/** Check if the page has been read in.
1092This may only be called after buf_pool_watch_set(same_page_id)
1093has returned NULL and before invoking buf_pool_watch_unset(same_page_id).
1094@param[in] page_id page id
1095@return false if the given page was not read in, true if it was */
1096[[nodiscard]] bool buf_pool_watch_occurred(const page_id_t &page_id);
1097
1098/** Get total buffer pool statistics.
1099@param[out] LRU_len Length of all lru lists
1100@param[out] free_len Length of all free lists
1101@param[out] flush_list_len Length of all flush lists */
1102void buf_get_total_list_len(ulint *LRU_len, ulint *free_len,
1103 ulint *flush_list_len);
1104
1105/** Get total list size in bytes from all buffer pools. */
1107 buf_pools_list_size_t *buf_pools_list_size); /*!< out: list sizes
1108 in all buffer pools */
1109/** Get total buffer pool statistics. */
1111 buf_pool_stat_t *tot_stat); /*!< out: buffer pool stats */
1112
1113/** Get the nth chunk's buffer block in the specified buffer pool.
1114@param[in] buf_pool buffer pool instance
1115@param[in] n nth chunk in the buffer pool
1116@param[in] chunk_size chunk_size
1117@return the nth chunk's buffer block. */
1118static inline buf_block_t *buf_get_nth_chunk_block(const buf_pool_t *buf_pool,
1119 ulint n, ulint *chunk_size);
1120
1121/** Calculate aligned buffer pool size based on srv_buf_pool_chunk_unit,
1122if needed.
1123@param[in] size size in bytes
1124@return aligned size */
1126
1127/** Adjust the proposed chunk unit size so that it satisfies all invariants
1128@param[in] size proposed size of buffer pool chunk unit in bytes
1129@return adjusted size which meets invariants */
1131
1132/** Calculate the checksum of a page from compressed table and update the
1133page.
1134@param[in,out] page page to update
1135@param[in] size compressed page size
1136@param[in] lsn LSN to stamp on the page
1137@param[in] skip_lsn_check true to skip check for lsn (in DEBUG) */
1139 bool skip_lsn_check);
1140
1141/** Return how many more pages must be added to the withdraw list to reach the
1142withdraw target of the currently ongoing buffer pool resize.
1143@param[in] buf_pool buffer pool instance
1144@return page count to be withdrawn or zero if the target is already achieved or
1145if the buffer pool is not currently being resized. */
1146static inline ulint buf_get_withdraw_depth(buf_pool_t *buf_pool);
1147
1148#endif /* !UNIV_HOTBACKUP */
1149
1150/** The common buffer control block structure
1151for compressed and uncompressed frames */
1152
1153/** Number of bits used for buffer page states. */
1154constexpr uint32_t BUF_PAGE_STATE_BITS = 3;
1155
1156template <typename T>
1157class copyable_atomic_t : public std::atomic<T> {
1158 public:
1160 : std::atomic<T>(other.load(std::memory_order_relaxed)) {}
1161};
1162
1165 public:
1166 /** Copy constructor.
1167 @param[in] other Instance to copy from. */
1169 : id(other.id),
1170 size(other.size),
1172 io_fix(other.io_fix),
1173 state(other.state),
1174 flush_type(other.flush_type),
1176#ifndef UNIV_HOTBACKUP
1177 hash(other.hash),
1178#endif /* !UNIV_HOTBACKUP */
1179 list(other.list),
1182 LRU(other.LRU),
1183 zip(other.zip)
1184#ifndef UNIV_HOTBACKUP
1185 ,
1187 m_space(other.m_space),
1189 m_version(other.m_version),
1190 access_time(other.access_time),
1191 m_dblwr_id(other.m_dblwr_id),
1192 old(other.old)
1193#ifdef UNIV_DEBUG
1194 ,
1198 in_LRU_list(other.in_LRU_list),
1201#endif /* UNIV_DEBUG */
1202#endif /* !UNIV_HOTBACKUP */
1203 {
1204#ifndef UNIV_HOTBACKUP
1205 m_space->inc_ref();
1206#endif /* !UNIV_HOTBACKUP */
1207 }
1208
1209 public:
1210 /** Check if the given ptr lies in a memory block of type BUF_BLOCK_MEMORY.
1211 This is checked by looking at the FIL_PAGE_LSN. If the FIL_PAGE_LSN is zero,
1212 then the block state is assumed to be BUF_BLOCK_MEMORY.
1213 @return true if the FIL_PAGE_LSN is zero, false otherwise. */
1214 [[nodiscard]] static bool is_memory(const page_t *const ptr) noexcept;
1215
1216 /** Check if the state of this page is BUF_BLOCK_MEMORY.
1217 @return true if the state is BUF_BLOCK_MEMORY, or false. */
1218 [[nodiscard]] bool is_memory() const noexcept {
1219 return state == BUF_BLOCK_MEMORY;
1220 }
1221
1222#ifndef UNIV_HOTBACKUP
1223 /** Set the doublewrite buffer ID.
1224 @param[in] batch_id Double write batch ID that flushed the page. */
1225 void set_dblwr_batch_id(uint16_t batch_id) { m_dblwr_id = batch_id; }
1226
1227 /** @return the double write batch id, or uint16_t max if undefined. */
1228 [[nodiscard]] uint16_t get_dblwr_batch_id() const { return (m_dblwr_id); }
1229
1230 /** Retrieve the tablespace id.
1231 @return tablespace id */
1232 [[nodiscard]] space_id_t space() const noexcept { return id.space(); }
1233
1234 /** Retrieve the page number.
1235 @return page number */
1236 [[nodiscard]] page_no_t page_no() const noexcept { return id.page_no(); }
1237
1238 /** Checks if this space reference saved during last page ID initialization
1239 was deleted or truncated since.
1240 @return true when space reference stored leads was deleted or truncated and
1241 this page should be discarded. Result is up to date until the fil_shard mutex
1242 is released. */
1243 inline bool is_stale() const {
1244 ut_a(m_space != nullptr);
1245 ut_a(id.space() == m_space->id);
1246 ut_a(m_version <= m_space->get_current_version());
1248 ut_a(!m_space->is_deleted());
1249 return false;
1250 } else {
1251 return true;
1252 }
1253 }
1254
1255 /** Checks if this space reference saved during last page ID initialization
1256 was deleted or truncated since.
1257 @return true when space reference stored leads was deleted or truncated and
1258 this page should be discarded. When false is returned, the status of stale is
1259 checked to be guaranteed. */
1260 inline bool was_stale() const {
1261 ut_a(m_space != nullptr);
1262 ut_a(id.space() == m_space->id);
1263 /* If the the version is OK, then the space must not be deleted.
1264 However, version is modified before the deletion flag is set, so reading
1265 these values need to be executed in reversed order. The atomic reads
1266 cannot be relaxed for it to work. */
1267 bool was_not_deleted = m_space->was_not_deleted();
1269 ut_a(was_not_deleted);
1270 return false;
1271 } else {
1272 return true;
1273 }
1274 }
1275
1276 /** Retrieve the tablespace object if one was available during page ID
1277 initialization. The returned object is safe to use as long as this buf_page_t
1278 object is not changed. Caller should have a IO fix, buffer fix, mutex or any
1279 other mean to assure the page will not be freed. After that is released the
1280 space object may be freed.
1281 @return tablespace object */
1282 inline fil_space_t *get_space() const { return m_space; }
1283
1284 /** Set the stored page id to a new value. This is used only on a buffer
1285 block with BUF_BLOCK_MEMORY state.
1286 @param[in] page_id the new value of the page id. */
1287 void set_page_id(const page_id_t page_id) {
1289 id = page_id;
1290 }
1291
1292 /** Set the page size to a new value. This can be used during initialization
1293 of a newly allocated buffer page.
1294 @param[in] page_size the new value of the page size. */
1295 void set_page_size(const page_size_t &page_size) {
1297 size = page_size;
1298 }
1299
1300 /** Sets stored page ID to the new value. Handles space object reference
1301 count.
1302 @param[in] new_page_id new page ID to be set. */
1303 inline void reset_page_id(page_id_t new_page_id) {
1304 if (m_space != nullptr) {
1305 /* If we reach this line through a call chain:
1306 srv_shutdown -> buf_pool_free_all -> buf_pool_free_instance ->
1307 buf_page_free_descriptor, then we are already past the fil system
1308 shutdown, and all fil_space_t objects were already freed. */
1310 m_space->dec_ref();
1311 }
1312 }
1313 id = new_page_id;
1315 }
1316
1317 /** Sets stored value to invalid/empty value. Handles space object reference
1318 count. */
1319 inline void reset_page_id() {
1321 }
1322
1323 private:
1324 /** Updates new space reference and acquires "reference count latch" and the
1325 current version of the space object. */
1326 inline void space_id_changed() {
1327 m_space = nullptr;
1328 m_version = 0;
1329 if (id.space() != UINT32_UNDEFINED) {
1330 m_space = fil_space_get(id.space());
1331 /* There could be non-existent tablespace while importing it */
1332 if (m_space) {
1333 m_space->inc_ref();
1334 /* We don't have a way to check the MDL locks, which are guarding the
1335 version number, so we don't use get_current_version(). */
1337 }
1338 }
1339 }
1340
1341 public:
1342 /** @return the flush observer instance. */
1344
1345 /** Set the flush observer for the page.
1346 @param[in] flush_observer The flush observer to set. */
1347 void set_flush_observer(Flush_observer *flush_observer) noexcept {
1348 /* Don't allow to set flush observer from non-null to null, or from one
1349 observer to another. */
1350 ut_a(m_flush_observer == nullptr || m_flush_observer == flush_observer);
1351 m_flush_observer = flush_observer;
1352 }
1353
1354 /** Remove the flush observer. */
1355 void reset_flush_observer() noexcept { m_flush_observer = nullptr; }
1356#endif /* !UNIV_HOTBACKUP */
1357
1358 /** @return the LSN of the latest modification. */
1359 lsn_t get_newest_lsn() const noexcept { return newest_modification; }
1360
1361 /** @return the LSN of the first modification since the last time
1362 it was clean. */
1363 lsn_t get_oldest_lsn() const noexcept { return oldest_modification; }
1364
1365 /** @return true if the page is dirty. */
1366 bool is_dirty() const noexcept { return get_oldest_lsn() > 0; }
1367
1368 /** Set the latest modification LSN.
1369 @param[in] lsn Latest modification lSN. */
1371
1372 /** Set the LSN when the page is modified for the first time.
1373 @param[in] lsn First modification LSN. */
1374 void set_oldest_lsn(lsn_t lsn) noexcept;
1375
1376 /** Set page to clean state. */
1377 void set_clean() noexcept { set_oldest_lsn(0); }
1378
1379 /** @name General fields
1380 None of these bit-fields must be modified without holding
1381 buf_page_get_mutex() [buf_block_t::mutex or
1382 buf_pool->zip_mutex], since they can be stored in the same
1383 machine word. */
1384 /** @{ */
1385
1386 /** Page id. */
1388
1389 /** Page size. */
1391
1392 /** Count of how many fold this block is currently bufferfixed. */
1394
1395 private:
1396 /** Type of pending I/O operation.
1397 Modified under protection of buf_page_get_mutex(this).
1398 Read under protection of rules described in @see Buf_io_fix_latching_rules */
1400
1401 public:
1402 /** Checks if io_fix has any of the known enum values.
1403 @param[in] io_fix the value to test
1404 @return true iff io_fix has any of the known enum values
1405 */
1407 switch (io_fix) {
1408 case BUF_IO_NONE:
1409 case BUF_IO_READ:
1410 case BUF_IO_WRITE:
1411 case BUF_IO_PIN:
1412 return true;
1413 }
1414 return false;
1415 }
1416
1417#ifdef UNIV_DEBUG
1418 private:
1419 /** Checks if io_fix has any of the known enum values.
1420 @return true iff io_fix has any of the known enum values
1421 */
1424 }
1425 /* Helper debug-only functions related latching rules are moved to a separate
1426 class so that this header doesn't have to pull in Stateful_latching_rules.*/
1429
1430 /* Helper debug-only class used to track which thread is currently responsible
1431 for performing I/O operation on this page. There's at most one such thread and
1432 the responsibility might be passed from one to another during async I/O. This
1433 is used to prove correctness of io_fix state transitions and checking it
1434 without a latch in the io_completion threads. */
1436 /** The thread responsible for I/O on this page, or an impossible value if
1437 no thread is currently responsible for I/O*/
1438 std::thread::id responsible_thread{std::thread().get_id()};
1439
1440 public:
1441 /** Checks if there is any thread responsible for I/O on this page now.
1442 @return true iff there is a thread responsible for I/O on this page.*/
1444 return responsible_thread != std::thread().get_id();
1445 }
1446
1447 /** Checks if the current thread is responsible for I/O on this page now.
1448 @return true iff the current thread is responsible for I/O on this page.*/
1451 }
1452
1453 /** Called by the thread responsible for I/O on this page to release its
1454 responsibility. */
1455 void release() {
1457 responsible_thread = std::thread().get_id();
1458 }
1459
1460 /** Called by the thread which becomes responsible for I/O on this page to
1461 indicate that it takes the responsibility. */
1462 void take() {
1465 }
1466 };
1467 /** Tracks which thread is responsible for I/O on this page. */
1469
1470 public:
1471 /** Checks if there is any thread responsible for I/O on this page now.
1472 @return true iff there is a thread responsible for I/O on this page.*/
1475 }
1476
1477 /** Checks if the current thread is responsible for I/O on this page now.
1478 @return true iff the current thread is responsible for I/O on this page.*/
1481 }
1482
1483 /** Called by the thread responsible for I/O on this page to release its
1484 responsibility. */
1486
1487 /** Called by the thread which becomes responsible for I/O on this page to
1488 indicate that it takes the responsibility. */
1491 io_fix.load(std::memory_order_relaxed) == BUF_IO_WRITE ||
1492 io_fix.load(std::memory_order_relaxed) == BUF_IO_READ);
1494 }
1495#endif /* UNIV_DEBUG */
1496 private:
1497 /** Retrieves a value of io_fix without requiring or acquiring any latches.
1498 Note that this implies that the value might be stale unless caller establishes
1499 happens-before relation in some other way.
1500 This is a low-level function which shouldn't be used directly, but
1501 rather via wrapper methods which check if proper latches are taken or via one
1502 of the many `was_io_fix_something()` methods with name explicitly warning the
1503 developer about the uncertainty involved.
1504 @return the value of io_fix at some moment "during" the call */
1507 return io_fix.load(std::memory_order_relaxed);
1508 }
1509
1510 public:
1511 /** This is called only when having full ownership of the page object and no
1512 other thread can reach it. This currently happens during buf_pool_create(),
1513 buf_pool_resize() (which latch quite a lot) or from fil_tablespace_iterate()
1514 which creates a fake, private block which is not really a part of the buffer
1515 pool.
1516 Therefore we allow this function to set io_fix without checking for any
1517 latches.
1518 Please use set_io_fix(BUF_IO_NONE) to change state in a regular situation. */
1520 io_fix.store(BUF_IO_NONE, std::memory_order_relaxed);
1521 /* This is only needed because places which call init_io_fix() do not call
1522 buf_page_t's constructor */
1524 }
1525
1526 /** This is called only when having full ownership of the page object and no
1527 other thread can reach it. This currently happens during buf_page_init_low()
1528 under buf_page_get_mutex(this), on a previously initialized page for reuse,
1529 yet should be treated as initialization of the field, not a state transition.
1530 Please use set_io_fix(BUF_IO_NONE) to change state in a regular situation. */
1532 ut_ad(io_fix.load(std::memory_order_relaxed) == BUF_IO_NONE);
1534 io_fix.store(BUF_IO_NONE, std::memory_order_relaxed);
1535 }
1536
1537 /** Sets io_fix to specified value.
1538 Assumes the caller holds buf_page_get_mutex(this).
1539 Might require additional latches depending on particular state transition.
1540 Calls take_io_responsibility() or release_io_responsibility() as needed.
1541 @see Buf_io_fix_latching_rules for specific rules. */
1543
1544 /** Retrieves the current value of io_fix.
1545 Assumes the caller holds buf_page_get_mutex(this).
1546 @return the current value of io_fix */
1549 return get_io_fix_snapshot();
1550 }
1551
1552 /** Checks if the current value of io_fix is BUF_IO_WRITE.
1553 Assumes the caller holds buf_page_get_mutex(this) or some other latches which
1554 prevent state transition from/to BUF_IO_WRITE.
1555 @see Buf_io_fix_latching_rules for specific rules.
1556 @return true iff the current value of io_fix == BUF_IO_WRITE */
1557 bool is_io_fix_write() const;
1558
1559 /** Checks if the current value of io_fix is BUF_IO_READ.
1560 Assumes the caller holds buf_page_get_mutex(this) or some other latches which
1561 prevent state transition from/to BUF_IO_READ.
1562 @see Buf_io_fix_latching_rules for specific rules.
1563 @return true iff the current value of io_fix == BUF_IO_READ */
1564 bool is_io_fix_read() const;
1565
1566 /** Assuming that io_fix is either BUF_IO_READ or BUF_IO_WRITE determines
1567 which of the two it is. Additionally it assumes the caller holds
1568 buf_page_get_mutex(this) or some other latches which prevent state transition
1569 from BUF_IO_READ or from BUF_IO_WRITE to another state.
1570 @see Buf_io_fix_latching_rules for specific rules.
1571 @return true iff the current value of io_fix == BUF_IO_READ */
1573
1574 /** Checks if io_fix is BUF_IO_READ without requiring or acquiring any
1575 latches.
1576 Note that this implies calling this function twice in a row could produce
1577 different results.
1578 @return true iff io_fix equal to BUF_IO_READ was noticed*/
1580
1581 /** Checks if io_fix is BUF_IO_FIX or BUF_IO_READ or BUF_IO_WRITE without
1582 requiring or acquiring any latches.
1583 Note that this implies calling this function twice in a row could produce
1584 different results.
1585 @return true iff io_fix not equal to BUF_IO_NONE was noticed */
1586 bool was_io_fixed() const { return get_io_fix_snapshot() != BUF_IO_NONE; }
1587
1588 /** Checks if io_fix is BUF_IO_NONE without requiring or acquiring any
1589 latches.
1590 Note that this implies calling this function twice in a row could produce
1591 different results.
1592 Please, prefer this function over !was_io_fixed() to avoid the misleading
1593 interpretation as "not(Exists time such that io_fix(time))", while in fact we
1594 want and get "Exists time such that !io_fix(time)".
1595 @return true iff io_fix equal to BUF_IO_NONE was noticed */
1597
1598 /** Block state. @see buf_page_in_file */
1600
1601 /** If this block is currently being flushed to disk, this tells
1602 the flush_type. @see buf_flush_t */
1604
1605 /** Index number of the buffer pool that this block belongs to */
1607
1608 static_assert(MAX_BUFFER_POOLS <= 64,
1609 "MAX_BUFFER_POOLS > 64; redefine buf_pool_index");
1610
1611 /** @} */
1612#ifndef UNIV_HOTBACKUP
1613 /** Node used in chaining to buf_pool->page_hash or buf_pool->zip_hash */
1615#endif /* !UNIV_HOTBACKUP */
1616
1617 /** @name Page flushing fields
1618 All these are protected by buf_pool->mutex. */
1619 /** @{ */
1620
1621 /** Based on state, this is a list node, protected by the corresponding list
1622 mutex, in one of the following lists in buf_pool:
1623
1624 - BUF_BLOCK_NOT_USED: free, withdraw
1625 - BUF_BLOCK_FILE_PAGE: flush_list
1626 - BUF_BLOCK_ZIP_DIRTY: flush_list
1627 - BUF_BLOCK_ZIP_PAGE: zip_clean
1628
1629 The node pointers are protected by the corresponding list mutex.
1630
1631 The contents of the list node is undefined if !in_flush_list &&
1632 state == BUF_BLOCK_FILE_PAGE, or if state is one of
1633 BUF_BLOCK_MEMORY,
1634 BUF_BLOCK_REMOVE_HASH or
1635 BUF_BLOCK_READY_IN_USE. */
1636
1638
1639 private:
1640 /** The flush LSN, LSN when this page was written to the redo log. For
1641 non redo logged pages this is set using: buf_flush_borrow_lsn() */
1643
1644 /** log sequence number of the youngest modification to this block, zero
1645 if not modified. Protected by block mutex */
1647
1648 public:
1649 /** log sequence number of the START of the log entry written of the oldest
1650 modification to this block which has not yet been flushed on disk; zero if
1651 all modifications are on disk. Writes to this field must be covered by both
1652 block->mutex and buf_pool->flush_list_mutex. Hence reads can happen while
1653 holding any one of the two mutexes */
1654 /** @} */
1655
1656 /** @name LRU replacement algorithm fields
1657 These fields are protected by both buf_pool->LRU_list_mutex and the
1658 block mutex. */
1659 /** @{ */
1660
1661 /** node of the LRU list */
1663
1664 /** compressed page; zip.data (but not the data it points to) is
1665 protected by buf_pool->zip_mutex; state == BUF_BLOCK_ZIP_PAGE and
1666 zip.data == NULL means an active buf_pool->watch */
1668
1669#ifndef UNIV_HOTBACKUP
1670 /** Flush observer instance. */
1672
1673 /** Tablespace instance that this page belongs to. */
1675
1676 /** The value of buf_pool->freed_page_clock when this block was the last
1677 time put to the head of the LRU list; a thread is allowed to read this
1678 for heuristic purposes without holding any mutex or latch */
1680
1681 /** @} */
1682 /** Version of fil_space_t when the page was updated. It can also be viewed as
1683 the truncation number. */
1684 uint32_t m_version{};
1685
1686 /** Time of first access, or 0 if the block was never accessed in the
1687 buffer pool. Protected by block mutex */
1688 std::chrono::steady_clock::time_point access_time;
1689
1690 private:
1691 /** Double write instance ordinal value during writes. This is used
1692 by IO completion (writes) to select the double write instance.*/
1693 uint16_t m_dblwr_id{};
1694
1695 public:
1696 /** true if the block is in the old blocks in buf_pool->LRU_old */
1697 bool old;
1698
1699#ifdef UNIV_DEBUG
1700 /** This is set to true when fsp frees a page in buffer pool;
1701 protected by buf_pool->zip_mutex or buf_block_t::mutex. */
1703
1704 /** true if in buf_pool->flush_list; when buf_pool->flush_list_mutex
1705 is free, the following should hold:
1706 in_flush_list == (state == BUF_BLOCK_FILE_PAGE ||
1707 state == BUF_BLOCK_ZIP_DIRTY)
1708 Writes to this field must be covered by both buf_pool->flush_list_mutex
1709 and block->mutex. Hence reads can happen while holding any one of the
1710 two mutexes */
1712
1713 /** true if in buf_pool->free; when buf_pool->free_list_mutex is free, the
1714 following should hold: in_free_list == (state == BUF_BLOCK_NOT_USED) */
1716
1717 /** true if the page is in the LRU list; used in debugging */
1719
1720 /** true if in buf_pool->page_hash */
1722
1723 /** true if in buf_pool->zip_hash */
1725#endif /* UNIV_DEBUG */
1726
1727 /** Print page metadata in JSON format {"key":"value"}. Asserts that caller
1728 holds page mutex and page if file page
1729 @param[in,out] outs the output stream
1730 @param[in] page the page whose metadata needs to be printed
1731 @return same output stream */
1732 friend std::ostream &operator<<(std::ostream &outs, const buf_page_t &page);
1733#endif /* !UNIV_HOTBACKUP */
1734};
1735
1736/** Structure used by AHI to contain information on record prefixes to be
1737considered in hash index subsystem. It is meant for using as a single 64bit
1738atomic value, thus it needs to be aligned properly. */
1739struct alignas(alignof(uint64_t)) btr_search_prefix_info_t {
1740 /** recommended prefix: number of bytes in an incomplete field
1741 @see BTR_PAGE_MAX_REC_SIZE */
1742 uint32_t n_bytes;
1743 /** recommended prefix length for hash search: number of full fields */
1744 uint16_t n_fields;
1745 /** true or false, depending on whether the leftmost record of several records
1746 with the same prefix should be indexed in the hash index */
1748
1750 return n_bytes == other.n_bytes && n_fields == other.n_fields;
1751 }
1752
1753 bool operator==(const btr_search_prefix_info_t &other) const {
1754 return n_bytes == other.n_bytes && n_fields == other.n_fields &&
1755 left_side == other.left_side;
1756 }
1757
1758 bool operator!=(const btr_search_prefix_info_t &other) const {
1759 return !(*this == other);
1760 }
1761};
1762
1763/** The buffer control block structure */
1765 /** @name General fields */
1766 /** @{ */
1767
1768 /** page information; this must be the first field, so
1769 that buf_pool->page_hash can point to buf_page_t or buf_block_t */
1771
1772#ifndef UNIV_HOTBACKUP
1773 /** read-write lock of the buffer frame */
1775
1776#ifdef UNIV_DEBUG
1777 /** Check if the buffer block was freed.
1778 @return true if the block was freed, false otherwise. */
1779 bool was_freed() const { return page.file_page_was_freed; }
1780#endif /* UNIV_DEBUG */
1781
1782#endif /* UNIV_HOTBACKUP */
1783
1784 /** pointer to buffer frame which is of size UNIV_PAGE_SIZE, and aligned
1785 to an address divisible by UNIV_PAGE_SIZE */
1786 byte *frame;
1787
1788 /** node of the decompressed LRU list; a block is in the unzip_LRU list if
1789 page.state == BUF_BLOCK_FILE_PAGE and page.zip.data != NULL. Protected by
1790 both LRU_list_mutex and the block mutex. */
1792#ifdef UNIV_DEBUG
1793 /** true if the page is in the decompressed LRU list; used in debugging */
1795
1797#endif /* UNIV_DEBUG */
1798
1799 /** @} */
1800
1801 /** Structure that holds most AHI-related fields. */
1802 struct ahi_t {
1803 public:
1804 /** Recommended prefix info for hash search. It is atomically copied
1805 from the index's current recommendation for the prefix info and should
1806 eventually get to the block's actual prefix info used. It is used to decide
1807 when the n_hash_helps should be reset. It is modified only while having S-
1808 or X- latch on block's lock. */
1809 std::atomic<btr_search_prefix_info_t> recommended_prefix_info;
1810 /** Prefix info that was used for building hash index. It cannot be modified
1811 while there are any record entries added in the AHI. It's invariant that all
1812 records added to AHI from this block were folded using this prefix info. It
1813 may only be modified when we are holding the appropriate X-latch in
1814 btr_search_sys->parts[]->latch. Also, it happens that it is modified
1815 to not-empty value only when the block is held in private or the block's
1816 lock is S- or X-latched. This implies that the field's non-empty value may
1817 be read and use reliably when the appropriate
1818 btr_search_sys->parts[]->latch S-latch or X-latch is being held, or
1819 the block's lock is X-latched. */
1820 std::atomic<btr_search_prefix_info_t> prefix_info;
1821 static_assert(decltype(prefix_info)::is_always_lock_free);
1822
1823 /** Index for which the adaptive hash index has been created, or nullptr if
1824 the page does not exist in the index. Note that it does not guarantee that
1825 the AHI index is complete, though: there may have been hash collisions etc.
1826 It may be modified:
1827 - to nullptr if btr_search_enabled is false and block's mutex is held and
1828 block's state is BUF_BLOCK_FILE_PAGE and btr_search_enabled_mutex is
1829 owned, protecting the btr_search_enabled from being changed,
1830 - to nullptr if btr_search_enabled is false and block is held in private in
1831 BUF_BLOCK_REMOVE_HASH state in buf_LRU_free_page().
1832 - to any value under appropriate X-latch in btr_search_sys->parts[]->latch
1833 if btr_search_enabled is true (and setting btr_search_enabled to false in
1834 turn is protected by having all btr_search_sys->parts[]->latch X-latched).
1835 */
1836 std::atomic<dict_index_t *> index;
1837
1838#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
1839 /** Used in debugging. The number of pointers in the adaptive hash index
1840 pointing to this frame; Modified under appropriate X-latch in
1841 btr_search_sys->parts[]->latch. */
1842 std::atomic<uint16_t> n_pointers;
1843
1844 inline void validate() const {
1845 /* These fields are read without holding any AHI latches. Adding or
1846 removing a block from AHI requires having only an appropriate AHI part
1847 X-latched. If we have at least S-latched the correct AHI part (for which
1848 we would need at least S-latch on block for the block's index to not be
1849 changed in meantime) this check is certain. If we don't have necessary AHI
1850 latches, then:
1851 - it can't happen that the check fails while the block is removed from
1852 AHI. Both btr_search_drop_page_hash_index() and
1853 buf_pool_clear_hash_index() will first make the n_pointers be 0 and then
1854 set index to nullptr. As the index is an atomic variable, so if we
1855 synchronize with a reset to nullptr which is sequenced after the reset of
1856 n_pointers, we should see the n_pointers set to 0 here.
1857 - it can happen that the check fails while the block is added to the AHI
1858 right after we read the index is nullptr. In such case, if the n_pointers
1859 is not 0, we double check the index member. It can still be nullptr, if
1860 the block is removed after reading the n_pointers, but that should be near
1861 impossible. */
1862 ut_a(this->index.load() != nullptr || this->n_pointers.load() == 0 ||
1863 this->index.load() != nullptr);
1864 }
1865
1866 inline void assert_empty() const { ut_a(this->n_pointers.load() == 0); }
1867
1868 inline void assert_empty_on_init() const {
1869 UNIV_MEM_VALID(&this->n_pointers, sizeof(this->n_pointers));
1870 assert_empty();
1871 }
1872#else
1873 inline void validate() const {}
1874
1875 inline void assert_empty() const {}
1876
1877 inline void assert_empty_on_init() const {}
1878#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1880
1881 /** Counter which controls how many times the current prefix recommendation
1882 would help in searches. If it is helpful enough, it will be used as the
1883 actual prefix to build hash for this block. It is modified similarly as
1884 recommended_prefix_info, that is only while having S- or X- latch on block's
1885 lock. Because it is modified concurrently, it may not have fully reliable
1886 count, but it is enough for this use case.
1887 Mind the n_hash_helps is AHI-related, and should be in the ahi_t struct above,
1888 but having it outside causes the made_dirty_with_no_latch to occupy the common
1889 8byte aligned 8byte long space, so basically it saves us 8bytes of the object
1890 that is used in high volumes. */
1891 std::atomic<uint32_t> n_hash_helps;
1892 /** true if block has been made dirty without acquiring X/SX latch as the
1893 block belongs to temporary tablespace and block is always accessed by a
1894 single thread. */
1896
1897#ifndef UNIV_HOTBACKUP
1898#ifdef UNIV_DEBUG
1899 /** @name Debug fields */
1900 /** @{ */
1901 /** In the debug version, each thread which bufferfixes the block acquires
1902 an s-latch here; so we can use the debug utilities in sync0rw */
1904 /** @} */
1905#endif /* UNIV_DEBUG */
1906#endif /* !UNIV_HOTBACKUP */
1907
1908 /** @name Optimistic search field */
1909 /** @{ */
1910
1911 /** This clock is incremented every time a pointer to a record on the page
1912 may become obsolete; this is used in the optimistic cursor positioning: if
1913 the modify clock has not changed, we know that the pointer is still valid;
1914 this field may be changed if the thread (1) owns the LRU list mutex and the
1915 page is not bufferfixed, or (2) the thread has an x-latch on the block,
1916 or (3) the block must belong to an intrinsic table */
1918
1919 /** @} */
1920
1921 /** mutex protecting this block: state (also protected by the buffer
1922 pool mutex), io_fix, buf_fix_count, and accessed; we introduce this
1923 new mutex in InnoDB-5.1 to relieve contention on the buffer pool mutex */
1925
1926 /** Get the modified clock (version) value.
1927 @param[in] single_threaded Thread can only be written to or read by a
1928 single thread
1929 @return the modified clock vlue. */
1930 uint64_t get_modify_clock(IF_DEBUG(bool single_threaded)) const noexcept {
1931#if defined(UNIV_DEBUG) && !defined(UNIV_LIBRARY) && !defined(UNIV_HOTBACKUP)
1932 /* No block latch is acquired when blocks access is guaranteed to be
1933 in single threaded mode. */
1935 ut_ad(single_threaded || rw_lock_own_flagged(&lock, mode));
1936#endif /* UNIV_DEBUG && !UNIV_LIBRARY */
1937
1938 return modify_clock;
1939 }
1940
1941 /** Get the page number and space id of the current buffer block.
1942 @return page number of the current buffer block. */
1943 const page_id_t &get_page_id() const { return page.id; }
1944
1945 /** Get the page number of the current buffer block.
1946 @return page number of the current buffer block. */
1947 page_no_t get_page_no() const { return (page.id.page_no()); }
1948
1949 /** Get the next page number of the current buffer block.
1950 @return next page number of the current buffer block. */
1953 }
1954
1955 /** Get the prev page number of the current buffer block.
1956 @return prev page number of the current buffer block. */
1959 }
1960
1961 /** Get the page type of the current buffer block.
1962 @return page type of the current buffer block. */
1965 }
1966
1967#ifndef UNIV_HOTBACKUP
1968 /** Mark the frame with jumbled page_id, while initiating i/o read
1969 (BUF_IO_READ).*/
1971 memset(frame, 0x00, page.size.logical());
1974 }
1975
1976 /** Print control block information in JSON format: {"key":"value"}
1977 @param[in,out] outs the output stream
1978 @param[in] block the control block whose information needs to be printed
1979 @return same output stream */
1980 friend std::ostream &operator<<(std::ostream &outs, const buf_block_t &block);
1981#endif /* UNIV_HOTBACKUP */
1982
1983 uint16_t get_page_level() const;
1984 bool is_leaf() const;
1985 bool is_root() const;
1986 bool is_index_page() const;
1987
1988 /** Check if this index page is empty. An index page is considered empty
1989 if the next record of an infimum record is supremum record. Presence of
1990 del-marked records will make the page non-empty.
1991 @return true if this index page is empty. */
1992 bool is_empty() const;
1993
1994 /** Get the page type of the current buffer block as string.
1995 @return page type of the current buffer block as string. */
1996 [[nodiscard]] const char *get_page_type_str() const noexcept;
1997
1998 /** Gets the compressed page descriptor corresponding to an uncompressed page
1999 if applicable.
2000 @return page descriptor or nullptr. */
2002 return page.zip.data != nullptr ? &page.zip : nullptr;
2003 }
2004
2005 /** Const version.
2006 @return page descriptor or nullptr. */
2007 page_zip_des_t const *get_page_zip() const noexcept {
2008 return page.zip.data != nullptr ? &page.zip : nullptr;
2009 }
2010
2011 [[nodiscard]] bool is_memory() const noexcept { return page.is_memory(); }
2012};
2013
2014inline bool buf_block_t::is_root() const {
2015 return ((get_next_page_no() == FIL_NULL) && (get_prev_page_no() == FIL_NULL));
2016}
2017
2018inline bool buf_block_t::is_leaf() const { return get_page_level() == 0; }
2019
2020inline bool buf_block_t::is_index_page() const {
2021 return get_page_type() == FIL_PAGE_INDEX;
2022}
2023
2024/** Check if a buf_block_t object is in a valid state
2025@param block buffer block
2026@return true if valid */
2028 return buf_block_get_state(block) >= BUF_BLOCK_NOT_USED &&
2030}
2031
2032/** Compute the hash value for blocks in buf_pool->zip_hash. */
2033/** @{ */
2034static inline uint64_t buf_pool_hash_zip_frame(void *ptr) {
2035 return ut::hash_uint64(reinterpret_cast<uintptr_t>(ptr) >>
2037}
2038static inline uint64_t buf_pool_hash_zip(buf_block_t *b) {
2039 return buf_pool_hash_zip_frame(b->frame);
2040}
2041/** @} */
2042
2043/** A "Hazard Pointer" class used to iterate over page lists
2044inside the buffer pool. A hazard pointer is a buf_page_t pointer
2045which we intend to iterate over next and we want it remain valid
2046even after we release the buffer pool mutex. */
2048 public:
2049 /** Constructor
2050 @param buf_pool buffer pool instance
2051 @param mutex mutex that is protecting the hp. */
2052 HazardPointer(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
2053 : m_buf_pool(buf_pool) IF_DEBUG(, m_mutex(mutex)), m_hp() {}
2054
2055 /** Destructor */
2056 virtual ~HazardPointer() = default;
2057
2058 /** Get current value */
2059 buf_page_t *get() const {
2061 return (m_hp);
2062 }
2063
2064 /** Set current value
2065 @param bpage buffer block to be set as hp */
2066 void set(buf_page_t *bpage);
2067
2068 /** Checks if a bpage is the hp
2069 @param bpage buffer block to be compared
2070 @return true if it is hp */
2071 bool is_hp(const buf_page_t *bpage);
2072
2073 /** Adjust the value of hp. This happens when some
2074 other thread working on the same list attempts to
2075 remove the hp from the list. Must be implemented
2076 by the derived classes.
2077 @param bpage buffer block to be compared */
2078 virtual void adjust(const buf_page_t *bpage) = 0;
2079
2080 /** Adjust the value of hp for moving. This happens
2081 when some other thread working on the same list
2082 attempts to relocate the hp of the page.
2083 @param bpage buffer block to be compared
2084 @param dpage buffer block to be moved to */
2085 void move(const buf_page_t *bpage, buf_page_t *dpage);
2086
2087 protected:
2088 /** Disable copying */
2091
2092 /** Buffer pool instance */
2094
2095#ifdef UNIV_DEBUG
2096 /** mutex that protects access to the m_hp. */
2097 const ib_mutex_t *m_mutex;
2098#endif /* UNIV_DEBUG */
2099
2100 /** hazard pointer. */
2102};
2103
2104/** Class implementing buf_pool->flush_list hazard pointer */
2105class FlushHp : public HazardPointer {
2106 public:
2107 /** Constructor
2108 @param buf_pool buffer pool instance
2109 @param mutex mutex that is protecting the hp. */
2110 FlushHp(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
2111 : HazardPointer(buf_pool, mutex) {}
2112
2113 /** Destructor */
2114 ~FlushHp() override = default;
2115
2116 /** Adjust the value of hp. This happens when some
2117 other thread working on the same list attempts to
2118 remove the hp from the list.
2119 @param bpage buffer block to be compared */
2120 void adjust(const buf_page_t *bpage) override;
2121};
2122
2123/** Class implementing buf_pool->LRU hazard pointer */
2124class LRUHp : public HazardPointer {
2125 public:
2126 /** Constructor
2127 @param buf_pool buffer pool instance
2128 @param mutex mutex that is protecting the hp. */
2129 LRUHp(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
2130 : HazardPointer(buf_pool, mutex) {}
2131
2132 /** Destructor */
2133 ~LRUHp() override = default;
2134
2135 /** Adjust the value of hp. This happens when some
2136 other thread working on the same list attempts to
2137 remove the hp from the list.
2138 @param bpage buffer block to be compared */
2139 void adjust(const buf_page_t *bpage) override;
2140};
2141
2142/** Special purpose iterators to be used when scanning the LRU list.
2143The idea is that when one thread finishes the scan it leaves the
2144itr in that position and the other thread can start scan from
2145there */
2146class LRUItr : public LRUHp {
2147 public:
2148 /** Constructor
2149 @param buf_pool buffer pool instance
2150 @param mutex mutex that is protecting the hp. */
2151 LRUItr(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
2152 : LRUHp(buf_pool, mutex) {}
2153
2154 /** Destructor */
2155 ~LRUItr() override = default;
2156
2157 /** Selects from where to start a scan. If we have scanned
2158 too deep into the LRU list it resets the value to the tail
2159 of the LRU list.
2160 @return buf_page_t from where to start scan. */
2161 buf_page_t *start();
2162};
2163
2164/** Struct that is embedded in the free zip blocks */
2166 union {
2167 ulint size; /*!< size of the block */
2169 /*!< stamp[FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID]
2170 == BUF_BUDDY_FREE_STAMP denotes a free
2171 block. If the space_id field of buddy
2172 block != BUF_BUDDY_FREE_STAMP, the block
2173 is not in any zip_free list. If the
2174 space_id is BUF_BUDDY_FREE_STAMP then
2175 stamp[0] will contain the
2176 buddy block size. */
2178
2179 buf_page_t bpage; /*!< Embedded bpage descriptor */
2181 /*!< Node of zip_free list */
2182};
2183
2184/** @brief The buffer pool statistics structure. */
2187
2188 /** Number of page gets performed; also successful searches through the
2189 adaptive hash index are counted as page gets; this field is NOT protected
2190 by the buffer pool mutex */
2192
2193 /** Number of read operations. */
2194 std::atomic<uint64_t> n_pages_read;
2195
2196 /** Number of write operations. */
2197 std::atomic<uint64_t> n_pages_written;
2198
2199 /** number of pages created in the pool with no read. */
2200 std::atomic<uint64_t> n_pages_created;
2201
2202 /** Number of pages read in as part of random read ahead. */
2203 std::atomic<uint64_t> n_ra_pages_read_rnd;
2204
2205 /** Number of pages read in as part of read ahead. */
2206 std::atomic<uint64_t> n_ra_pages_read;
2207
2208 /** Number of read ahead pages that are evicted without being accessed.
2209 Protected by LRU_list_mutex. */
2211
2212 /** Number of pages made young, in calls to buf_LRU_make_block_young().
2213 Protected by LRU_list_mutex. */
2215
2216 /** Number of pages not made young because the first access was not long
2217 enough ago, in buf_page_peek_if_too_old(). Not protected. */
2219
2220 /** LRU size in bytes. Protected by LRU_list_mutex. */
2221 uint64_t LRU_bytes;
2222
2223 /** Flush_list size in bytes. Protected by flush_list_mutex */
2225
2226 static void copy(buf_pool_stat_t &dst, const buf_pool_stat_t &src) noexcept {
2227 Counter::copy(dst.m_n_page_gets, src.m_n_page_gets);
2228
2229 dst.n_pages_read.store(src.n_pages_read.load());
2230
2231 dst.n_pages_written.store(src.n_pages_written.load());
2232
2233 dst.n_pages_created.store(src.n_pages_created.load());
2234
2235 dst.n_ra_pages_read_rnd.store(src.n_ra_pages_read_rnd.load());
2236
2237 dst.n_ra_pages_read.store(src.n_ra_pages_read.load());
2238
2239 dst.n_ra_pages_evicted = src.n_ra_pages_evicted;
2240
2241 dst.n_pages_made_young = src.n_pages_made_young;
2242
2243 dst.n_pages_not_made_young = src.n_pages_not_made_young;
2244
2245 dst.LRU_bytes = src.LRU_bytes;
2246
2247 dst.flush_list_bytes = src.flush_list_bytes;
2248 }
2249
2250 void reset() {
2252
2253 n_pages_read = 0;
2254 n_pages_written = 0;
2255 n_pages_created = 0;
2257 n_ra_pages_read = 0;
2261 LRU_bytes = 0;
2262 flush_list_bytes = 0;
2263 }
2264};
2265
2266/** Statistics of buddy blocks of a given size. */
2268 /** Number of blocks allocated from the buddy system. */
2269 std::atomic<ulint> used;
2270 /** Number of blocks relocated by the buddy system.
2271 Protected by buf_pool zip_free_mutex. */
2272 uint64_t relocated;
2273 /** Total duration of block relocations.
2274 Protected by buf_pool zip_free_mutex. */
2275 std::chrono::steady_clock::duration relocated_duration;
2276
2277 struct snapshot_t {
2279 uint64_t relocated;
2280 std::chrono::steady_clock::duration relocated_duration;
2281 };
2282
2284 return {used.load(), relocated, relocated_duration};
2285 }
2286};
2287
2288/** @brief The buffer pool structure.
2289
2290NOTE! The definition appears here only for other modules of this
2291directory (buf) to see it. Do not use from outside! */
2292
2294 /** @name General fields */
2295 /** @{ */
2296 /** protects (de)allocation of chunks:
2297 - changes to chunks, n_chunks are performed while holding this latch,
2298 - reading buf_pool_should_madvise requires holding this latch for any
2299 buf_pool_t
2300 - writing to buf_pool_should_madvise requires holding these latches
2301 for all buf_pool_t-s */
2303
2304 /** LRU list mutex */
2306
2307 /** free and withdraw list mutex */
2309
2310 /** buddy allocator mutex */
2312
2313 /** zip_hash mutex */
2315
2316 /** Flush state protection mutex */
2318
2319 /** Zip mutex of this buffer pool instance, protects compressed only pages (of
2320 type buf_page_t, not buf_block_t */
2322
2323 /** Array index of this buffer pool instance */
2325
2326 /** Current pool size in bytes */
2328
2329 /** Reserve this much of the buffer pool for "old" blocks */
2331#ifdef UNIV_DEBUG
2332 /** Number of frames allocated from the buffer pool to the buddy system.
2333 Protected by zip_hash_mutex. */
2335#endif
2336
2337 /** Number of buffer pool chunks */
2338 volatile ulint n_chunks;
2339
2340 /** New number of buffer pool chunks */
2342
2343 /** buffer pool chunks */
2345
2346 /** old buffer pool chunks to be freed after resizing buffer pool */
2348
2349 /** Current pool size in pages */
2351
2352 /** Previous pool size in pages */
2354
2355 /** Size in pages of the area which the read-ahead algorithms read
2356 if invoked */
2358
2359 /** Hash table of buf_page_t or buf_block_t file pages, buf_page_in_file() ==
2360 true, indexed by (space_id, offset). page_hash is protected by an array of
2361 mutexes. */
2363
2364 /** Hash table of buf_block_t blocks whose frames are allocated to the zip
2365 buddy system, indexed by block->frame */
2367
2368 /** Number of pending read operations. Accessed atomically */
2369 std::atomic<ulint> n_pend_reads;
2370
2371 /** number of pending decompressions. Accessed atomically. */
2372 std::atomic<ulint> n_pend_unzip;
2373
2374 /** when buf_print_io was last time called. Accesses not protected. */
2375 std::chrono::steady_clock::time_point last_printout_time;
2376
2377 /** Statistics of buddy system, indexed by block size. Protected by zip_free
2378 mutex, except for the used field, which is also accessed atomically */
2380
2381 /** Current statistics */
2383
2384 /** Old statistics */
2386
2387 /** @} */
2388
2389 /** @name Page flushing algorithm fields */
2390
2391 /** @{ */
2392
2393 /** Mutex protecting the flush list access. This mutex protects flush_list and
2394 bpage::list pointers when the bpage is on flush_list. It also protects writes
2395 to bpage::oldest_modification and flush_list_hp */
2397
2398 /** "Hazard pointer" used during scan of flush_list while doing flush list
2399 batch. Protected by flush_list_mutex */
2401
2402 /** Entry pointer to scan the oldest page except for system temporary */
2404
2405 /** Base node of the modified block list */
2407
2408 /** This is true when a flush of the given type is being initialized.
2409 Protected by flush_state_mutex. */
2411
2412 /** This is the number of pending writes in the given flush type. Protected
2413 by flush_state_mutex. */
2414 std::array<size_t, BUF_FLUSH_N_TYPES> n_flush;
2415
2416 /** This is in the set state when there is no flush batch of the given type
2417 running. Protected by flush_state_mutex. */
2419
2420 /** A sequence number used to count the number of buffer blocks removed from
2421 the end of the LRU list; NOTE that this counter may wrap around at 4
2422 billion! A thread is allowed to read this for heuristic purposes without
2423 holding any mutex or latch. For non-heuristic purposes protected by
2424 LRU_list_mutex */
2426
2427 /** Set to false when an LRU scan for free block fails. This flag is used to
2428 avoid repeated scans of LRU list when we know that there is no free block
2429 available in the scan depth for eviction. Set to true whenever we flush a
2430 batch from the buffer pool. Accessed protected by memory barriers. */
2432
2433 /** Page Tracking start LSN. */
2435
2436 /** Check if the page modifications are tracked.
2437 @return true if page modifications are tracked, false otherwise. */
2438 bool is_tracking() { return track_page_lsn != LSN_MAX; }
2439
2440 /** Maximum LSN for which write io has already started. */
2442
2443 /** @} */
2444
2445 /** @name LRU replacement algorithm fields */
2446 /** @{ */
2447
2448 /** Base node of the free block list */
2450
2451 /** base node of the withdraw block list. It is only used during shrinking
2452 buffer pool size, not to reuse the blocks will be removed. Protected by
2453 free_list_mutex */
2455
2456 /** Target length of withdraw block list, when withdrawing */
2458
2459 /** "hazard pointer" used during scan of LRU while doing
2460 LRU list batch. Protected by buf_pool::LRU_list_mutex */
2462
2463 /** Iterator used to scan the LRU list when searching for
2464 replaceable victim. Protected by buf_pool::LRU_list_mutex. */
2466
2467 /** Iterator used to scan the LRU list when searching for
2468 single page flushing victim. Protected by buf_pool::LRU_list_mutex. */
2470
2471 /** Base node of the LRU list */
2473
2474 /** Pointer to the about LRU_old_ratio/BUF_LRU_OLD_RATIO_DIV oldest blocks in
2475 the LRU list; NULL if LRU length less than BUF_LRU_OLD_MIN_LEN; NOTE: when
2476 LRU_old != NULL, its length should always equal LRU_old_len */
2478
2479 /** Length of the LRU list from the block to which LRU_old points onward,
2480 including that block; see buf0lru.cc for the restrictions on this value; 0
2481 if LRU_old == NULL; NOTE: LRU_old_len must be adjusted whenever LRU_old
2482 shrinks or grows! */
2484
2485 /** Base node of the unzip_LRU list. The list is protected by the
2486 LRU_list_mutex. */
2487 UT_LIST_BASE_NODE_T(buf_block_t, unzip_LRU) unzip_LRU;
2488
2489 /** @} */
2490 /** @name Buddy allocator fields
2491 The buddy allocator is used for allocating compressed page
2492 frames and buf_page_t descriptors of blocks that exist
2493 in the buffer pool only in compressed form. */
2494 /** @{ */
2495#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2496 /** Unmodified compressed pages */
2498#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
2499
2500 /** Buddy free lists */
2502
2503 /** Sentinel records for buffer pool watches. Scanning the array is protected
2504 by taking all page_hash latches in X. Updating or reading an individual
2505 watch page is protected by a corresponding individual page_hash latch. */
2507
2508 /** A wrapper for buf_pool_t::allocator.alocate_large which also advices the
2509 OS that this chunk should not be dumped to a core file if that was requested.
2510 Emits a warning to the log and disables @@global.core_file if advising was
2511 requested but could not be performed, but still return true as the allocation
2512 itself succeeded.
2513 @param[in] mem_size number of bytes to allocate
2514 @param[in,out] chunk mem and mem_pfx fields of this chunk will be updated
2515 to contain information about allocated memory region
2516 @return true iff allocated successfully */
2517 bool allocate_chunk(ulonglong mem_size, buf_chunk_t *chunk);
2518
2519 /** A wrapper for buf_pool_t::allocator.deallocate_large which also advices
2520 the OS that this chunk can be dumped to a core file.
2521 Emits a warning to the log and disables @@global.core_file if advising was
2522 requested but could not be performed.
2523 @param[in] chunk mem and mem_pfx fields of this chunk will be used to
2524 locate the memory region to free */
2525 void deallocate_chunk(buf_chunk_t *chunk);
2526
2527 /** Advices the OS that all chunks in this buffer pool instance can be dumped
2528 to a core file.
2529 Emits a warning to the log if could not succeed.
2530 @return true iff succeeded, false if no OS support or failed */
2531 bool madvise_dump();
2532
2533 /** Advices the OS that all chunks in this buffer pool instance should not
2534 be dumped to a core file.
2535 Emits a warning to the log if could not succeed.
2536 @return true iff succeeded, false if no OS support or failed */
2537 bool madvise_dont_dump();
2538
2539 /** Checks if the batch is running, which is basically equivalent to
2540 !os_event_is_set(no_flush[type]) if you hold flush_state_mutex.
2541 It is used as source of truth to know when to set or reset this event.
2542 Caller should hold flush_state_mutex.
2543 @param[in] flush_type The type of the flush we are interested in
2544 @return Should no_flush[type] be in the "unset" state? */
2547 return init_flush[flush_type] || 0 < n_flush[flush_type];
2548 }
2549
2550#ifndef UNIV_HOTBACKUP
2551 /** Executes change() which modifies fields protected by flush_state_mutex.
2552 If it caused a change to is_flushing(flush_type) then it sets or resets the
2553 no_flush[flush_type] to keep it in sync.
2554 @param[in] flush_type The type of the flush this change of state concerns
2555 @param[in] change A callback to execute within flush_state_mutex
2556 */
2557 template <typename F>
2560 const bool was_set = !is_flushing(flush_type);
2562 std::forward<F>(change)();
2563 const bool should_be_set = !is_flushing(flush_type);
2564 if (was_set && !should_be_set) {
2566 } else if (!was_set && should_be_set) {
2568 }
2569 ut_ad(should_be_set == os_event_is_set(no_flush[flush_type]));
2571 }
2572#endif /*! UNIV_HOTBACKUP */
2573
2574 static_assert(BUF_BUDDY_LOW <= UNIV_ZIP_SIZE_MIN,
2575 "BUF_BUDDY_LOW > UNIV_ZIP_SIZE_MIN");
2576 /** @} */
2577};
2578
2579/** Print the given buf_pool_t object.
2580@param[in,out] out the output stream
2581@param[in] buf_pool the buf_pool_t object to be printed
2582@return the output stream */
2583std::ostream &operator<<(std::ostream &out, const buf_pool_t &buf_pool);
2584
2585/** @name Accessors for buffer pool mutexes
2586Use these instead of accessing buffer pool mutexes directly. */
2587/** @{ */
2588
2589#ifndef UNIV_HOTBACKUP
2590/** Test if flush list mutex is owned. */
2591#define buf_flush_list_mutex_own(b) mutex_own(&(b)->flush_list_mutex)
2592
2593/** Acquire the flush list mutex. */
2594#define buf_flush_list_mutex_enter(b) \
2595 do { \
2596 mutex_enter(&(b)->flush_list_mutex); \
2597 } while (0)
2598/** Release the flush list mutex. */
2599#define buf_flush_list_mutex_exit(b) \
2600 do { \
2601 mutex_exit(&(b)->flush_list_mutex); \
2602 } while (0)
2603/** Acquire the block->mutex. */
2604#define buf_page_mutex_enter(b) \
2605 do { \
2606 mutex_enter(&(b)->mutex); \
2607 } while (0)
2608
2609/** Release the block->mutex. */
2610#define buf_page_mutex_exit(b) \
2611 do { \
2612 (b)->mutex.exit(); \
2613 } while (0)
2614
2615/** Get appropriate page_hash_lock. */
2617 const page_id_t page_id) {
2618 return hash_get_lock(buf_pool->page_hash, page_id.hash());
2619}
2620
2621/** If not appropriate page_hash_lock, relock until appropriate. */
2623 const buf_pool_t *buf_pool,
2624 const page_id_t page_id) {
2625 return hash_lock_s_confirm(hash_lock, buf_pool->page_hash, page_id.hash());
2626}
2627
2629 buf_pool_t *buf_pool,
2630 const page_id_t &page_id) {
2631 return hash_lock_x_confirm(hash_lock, buf_pool->page_hash, page_id.hash());
2632}
2633#endif /* !UNIV_HOTBACKUP */
2634
2635#if defined(UNIV_DEBUG) && !defined(UNIV_HOTBACKUP)
2636/** Test if page_hash lock is held in s-mode. */
2638 const buf_page_t *bpage) {
2639 return rw_lock_own(buf_page_hash_lock_get(buf_pool, bpage->id), RW_LOCK_S);
2640}
2641
2642/** Test if page_hash lock is held in x-mode. */
2644 const buf_page_t *bpage) {
2645 return rw_lock_own(buf_page_hash_lock_get((buf_pool), (bpage)->id),
2646 RW_LOCK_X);
2647}
2648
2649/** Test if page_hash lock is held in x or s-mode. */
2650inline bool buf_page_hash_lock_held_s_or_x(const buf_pool_t *buf_pool,
2651 const buf_page_t *bpage) {
2652 return buf_page_hash_lock_held_s(buf_pool, bpage) ||
2653 buf_page_hash_lock_held_x(buf_pool, bpage);
2654}
2655
2656inline bool buf_block_hash_lock_held_s(const buf_pool_t *buf_pool,
2657 const buf_block_t *block) {
2658 return buf_page_hash_lock_held_s(buf_pool, &block->page);
2659}
2660
2661inline bool buf_block_hash_lock_held_x(const buf_pool_t *buf_pool,
2662 const buf_block_t *block) {
2663 return buf_page_hash_lock_held_x(buf_pool, &block->page);
2664}
2665
2667 const buf_block_t *block) {
2668 return buf_page_hash_lock_held_s_or_x(buf_pool, &block->page);
2669}
2670#else /* UNIV_DEBUG && !UNIV_HOTBACKUP */
2671#define buf_page_hash_lock_held_s(b, p) (true)
2672#define buf_page_hash_lock_held_x(b, p) (true)
2673#define buf_page_hash_lock_held_s_or_x(b, p) (true)
2674#define buf_block_hash_lock_held_s(b, p) (true)
2675#define buf_block_hash_lock_held_x(b, p) (true)
2676#define buf_block_hash_lock_held_s_or_x(b, p) (true)
2677#endif /* UNIV_DEBUG && !UNIV_HOTBACKUP */
2678
2679/** @} */
2680
2681/**********************************************************************
2682Let us list the consistency conditions for different control block states.
2683
2684NOT_USED: is in free list, not in LRU list, not in flush list, nor
2685 page hash table
2686READY_FOR_USE: is not in free list, LRU list, or flush list, nor page
2687 hash table
2688MEMORY: is not in free list, LRU list, or flush list, nor page
2689 hash table
2690FILE_PAGE: space and offset are defined, is in page hash table
2691 if io_fix == BUF_IO_WRITE,
2692 pool: no_flush[flush_type] is in reset state,
2693 pool: n_flush[flush_type] > 0
2694
2695 (1) if buf_fix_count == 0, then
2696 is in LRU list, not in free list
2697 is in flush list,
2698 if and only if oldest_modification > 0
2699 is x-locked,
2700 if and only if io_fix == BUF_IO_READ
2701 is s-locked,
2702 if and only if io_fix == BUF_IO_WRITE
2703
2704 (2) if buf_fix_count > 0, then
2705 is not in LRU list, not in free list
2706 is in flush list,
2707 if and only if oldest_modification > 0
2708 if io_fix == BUF_IO_READ,
2709 is x-locked
2710 if io_fix == BUF_IO_WRITE,
2711 is s-locked
2712
2713State transitions:
2714
2715NOT_USED => READY_FOR_USE
2716READY_FOR_USE => MEMORY
2717READY_FOR_USE => FILE_PAGE
2718MEMORY => NOT_USED
2719FILE_PAGE => NOT_USED NOTE: This transition is allowed if and only if
2720 (1) buf_fix_count == 0,
2721 (2) oldest_modification == 0, and
2722 (3) io_fix == 0.
2723*/
2724
2725#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2726#ifndef UNIV_HOTBACKUP
2727/** Functor to validate the LRU list. */
2729 void operator()(const buf_page_t *elem) const { ut_a(elem->in_LRU_list); }
2730
2731 static void validate(const buf_pool_t *buf_pool) {
2732 CheckInLRUList check;
2733 ut_list_validate(buf_pool->LRU, check);
2734 }
2735};
2736
2737/** Functor to validate the LRU list. */
2739 void operator()(const buf_page_t *elem) const { ut_a(elem->in_free_list); }
2740
2741 static void validate(const buf_pool_t *buf_pool) {
2742 CheckInFreeList check;
2743 ut_list_validate(buf_pool->free, check);
2744 }
2745};
2746
2748 void operator()(const buf_block_t *elem) const {
2749 ut_a(elem->page.in_LRU_list);
2750 ut_a(elem->in_unzip_LRU_list);
2751 }
2752
2753 static void validate(const buf_pool_t *buf_pool) {
2755 ut_list_validate(buf_pool->unzip_LRU, check);
2756 }
2757};
2758#endif /* !UNIV_HOTBACKUP */
2759#endif /* UNIV_DEBUG || defined UNIV_BUF_DEBUG */
2760
2761#ifndef UNIV_HOTBACKUP
2762/** Prepare a page before adding to the free list.
2763@param[in,out] bpage Buffer page to prepare for freeing. */
2764inline void buf_page_prepare_for_free(buf_page_t *bpage) noexcept {
2765 bpage->reset_page_id();
2766}
2767#endif /* !UNIV_HOTBACKUP */
2768
2769/** Gets the compressed page descriptor corresponding to an uncompressed
2770page if applicable.
2771@param[in] block Get the zip descriptor for this block. */
2773 return block->get_page_zip();
2774}
2775
2776/** Gets the compressed page descriptor corresponding to an uncompressed
2777page if applicable. Const version.
2778@param[in] block Get the zip descriptor for this block.
2779@return page descriptor or nullptr. */
2781 const buf_block_t *block) noexcept {
2782 return block->get_page_zip();
2783}
2784
2785inline bool buf_page_in_memory(const buf_page_t *bpage) {
2786 switch (buf_page_get_state(bpage)) {
2787 case BUF_BLOCK_MEMORY:
2788 return true;
2789 default:
2790 break;
2791 }
2792 return false;
2793}
2794
2795/** Verify the page contained by the block. If there is page type
2796mismatch then reset it to expected page type. Data files created
2797before MySQL 5.7 GA may contain garbage in the FIL_PAGE_TYPE field.
2798@param[in,out] block block that may possibly have invalid
2799 FIL_PAGE_TYPE
2800@param[in] type Expected page type
2801@param[in,out] mtr Mini-transaction */
2804 mtr_t &mtr) {
2805 byte *page = block.frame;
2806 page_type_t page_type = fil_page_get_type(page);
2807 if (page_type != type) {
2808 const page_id_t &page_id = block.page.id;
2809 fil_page_reset_type(page_id, page, type, &mtr);
2810 }
2811}
2812
2813#include "buf0buf.ic"
2814
2815#endif /* !buf0buf_h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:48
uint32_t page_no_t
Page number.
Definition: api0api.h:46
Cache_hint
Definition: buf0buf.h:93
@ MAKE_YOUNG
Move the block to the start of the LRU list if there is a danger that the block would drift out of th...
@ KEEP_OLD
Preserve the current LRU position of the block.
static void buf_block_dbg_add_level(buf_block_t *block, latch_level_t level)
Adds latch level info for the rw-lock protecting the buffer frame.
bool buf_block_hash_lock_held_x(const buf_pool_t *buf_pool, const buf_block_t *block)
Definition: buf0buf.h:2661
static buf_block_t * buf_page_get_block(buf_page_t *bpage)
Gets the buf_block_t handle of a buffered file block if an uncompressed page frame exists,...
static bool buf_page_belongs_to_unzip_LRU(const buf_page_t *bpage)
Determines if a block should be on unzip_LRU list.
static bool buf_page_can_relocate(const buf_page_t *bpage)
Determine if a buffer block can be relocated in memory.
buf_page_t * buf_page_get_zip(const page_id_t &page_id, const page_size_t &page_size)
Get read access to a compressed page (usually of type FIL_PAGE_TYPE_ZBLOB or FIL_PAGE_TYPE_ZBLOB2).
Definition: buf0buf.cc:3295
dberr_t buf_pool_init(ulint total_size, ulint n_instances)
Creates the buffer pool.
Definition: buf0buf.cc:1496
void buf_page_print(const byte *read_buf, const page_size_t &page_size, ulint flags)
Prints a page to stderr.
Definition: buf0buf.cc:607
ulint buf_get_n_pending_read_ios(void)
Returns the number of pending buf pool read ios.
Definition: buf0buf.cc:6536
bool buf_page_hash_lock_held_s_or_x(const buf_pool_t *buf_pool, const buf_page_t *bpage)
Test if page_hash lock is held in x or s-mode.
Definition: buf0buf.h:2650
static ulint buf_pool_get_curr_size(void)
Gets the current size of buffer buf_pool in bytes.
ulint buf_page_hash_lock_held_x(const buf_pool_t *buf_pool, const buf_page_t *bpage)
Test if page_hash lock is held in x-mode.
Definition: buf0buf.h:2643
void buf_page_force_evict(const page_id_t &page_id, const page_size_t &page_size, const bool dirty_is_ok=true) noexcept
Evict a page from the buffer pool.
Definition: buf0buf.cc:5412
bool buf_validate(void)
Validates the buffer pool data structure.
Definition: buf0buf.cc:6322
void buf_flush_update_zip_checksum(buf_frame_t *page, ulint size, lsn_t lsn, bool skip_lsn_check)
Calculate the checksum of a page from compressed table and update the page.
Definition: buf0flu.cc:696
static enum buf_page_state buf_block_get_state(const buf_block_t *block)
Gets the state of a block.
static void buf_page_set_state(buf_page_t *bpage, enum buf_page_state state)
Sets the state of a block.
buf_block_t * buf_block_from_ahi(const byte *ptr)
Get a buffer block from an adaptive hash index pointer.
Definition: buf0buf.cc:3505
bool buf_page_io_complete(buf_page_t *bpage, bool evict, IORequest *type=nullptr, fil_node_t *node=nullptr)
Completes an asynchronous read or write request of a file page to or from the buffer pool.
Definition: buf0buf.cc:5773
lsn_t buf_pool_get_oldest_modification_lwm(void)
Gets a safe low watermark for oldest_modification.
Definition: buf0buf.cc:488
bool buf_frame_will_withdrawn(buf_pool_t *buf_pool, const byte *ptr)
Determines if a frame is intended to be withdrawn.
Definition: buf0buf.cc:1874
void buf_pool_update_madvise()
Checks if innobase_should_madvise_buf_pool() value has changed since we've last check and if so,...
Definition: buf0buf.cc:1012
ulonglong buf_pool_adjust_chunk_unit(ulonglong size)
Adjust the proposed chunk unit size so that it satisfies all invariants.
Definition: buf0buf.cc:2143
static buf_page_t * buf_page_hash_get_locked(buf_pool_t *buf_pool, const page_id_t &page_id, rw_lock_t **lock, ulint lock_mode, bool watch=false)
Returns the control block of a file page, NULL if not found.
static enum buf_io_fix buf_page_get_io_fix(const buf_page_t *bpage)
Gets the io_fix state of a block.
static void buf_page_set_io_fix(buf_page_t *bpage, enum buf_io_fix io_fix)
Sets the io_fix state of a block.
buf_page_t * buf_page_set_file_page_was_freed(const page_id_t &page_id)
Sets file_page_was_freed true if the page is found in the buffer pool.
Definition: buf0buf.cc:3208
static void buf_page_set_accessed(buf_page_t *bpage)
Flag a block accessed.
static void buf_block_set_io_fix(buf_block_t *block, enum buf_io_fix io_fix)
Sets the io_fix state of a block.
void buf_page_make_young(buf_page_t *bpage)
Moves a page to the start of the buffer pool LRU list.
Definition: buf0buf.cc:3162
buf_pool_t * buf_pool_ptr
The buffer pools of the database.
Definition: buf0buf.cc:306
void buf_pool_clear_hash_index(void)
Clears the adaptive hash index on all pages in the buffer pool.
Definition: buf0buf.cc:2700
void buf_get_total_stat(buf_pool_stat_t *tot_stat)
Get total buffer pool statistics.
Definition: buf0buf.cc:552
static buf_pool_t * buf_pool_from_bpage(const buf_page_t *bpage)
Returns the buffer pool instance given a page instance.
static buf_flush_t buf_page_get_flush_type(const buf_page_t *bpage)
Get the flush type of a page.
static ulint buf_page_get_freed_page_clock(const buf_page_t *bpage)
Reads the freed_page_clock of a buffer block.
ulint buf_page_hash_lock_held_s(const buf_pool_t *buf_pool, const buf_page_t *bpage)
Test if page_hash lock is held in s-mode.
Definition: buf0buf.h:2637
static std::chrono::steady_clock::time_point buf_page_is_accessed(const buf_page_t *bpage)
Determine the time of first access of a block in the buffer pool.
constexpr ulint MAX_PAGE_HASH_LOCKS
The maximum number of page_hash locks.
Definition: buf0buf.h:114
bool buf_page_optimistic_get(ulint rw_latch, buf_block_t *block, uint64_t modify_clock, Page_fetch fetch_mode, const char *file, ulint line, mtr_t *mtr)
This is the general function used to get optimistic access to a database page.
Definition: buf0buf.cc:4494
void buf_pool_watch_unset(const page_id_t &page_id)
Stop watching if the page has been read in.
Definition: buf0buf.cc:3111
static byte * buf_frame_copy(byte *buf, const buf_frame_t *frame)
Copies contents of a buffer frame to a given buffer.
void buf_assert_all_are_replaceable()
Assert that all file pages in the buffer are in a replaceable state.
Definition: buf0buf.cc:6880
bool buf_pool_watch_occurred(const page_id_t &page_id)
Check if the page has been read in.
Definition: buf0buf.cc:3138
buf_page_t * buf_page_init_for_read(ulint mode, const page_id_t &page_id, const page_size_t &page_size, bool unzip)
Inits a page for read to the buffer buf_pool.
Definition: buf0buf.cc:4858
static bool buf_page_peek_if_young(const buf_page_t *bpage)
Tells, for heuristics, if a block is still close enough to the MRU end of the LRU list meaning that i...
bool buf_page_free_stale(buf_pool_t *buf_pool, buf_page_t *bpage) noexcept
Free a stale page.
Definition: buf0buf.cc:5379
buf_page_t * buf_page_hash_get_x_locked(buf_pool_t *b, const page_id_t &page_id, rw_lock_t **l)
Definition: buf0buf.h:1047
static void buf_page_set_old(buf_page_t *bpage, bool old)
Flag a block old.
size_t buf_pool_pending_io_reads_count()
Computes number of pending I/O read operations for the buffer pool.
Definition: buf0buf.cc:6886
size_t buf_pool_pending_io_writes_count()
Computes number of pending I/O write operations for the buffer pool.
Definition: buf0buf.cc:6894
void buf_read_page_handle_error(buf_page_t *bpage)
Unfixes the page, unlatches the page, removes it from page_hash and removes it from LRU.
Definition: buf0buf.cc:5344
static ulint buf_block_unfix(buf_page_t *bpage)
Decrements the bufferfix count.
static void buf_page_set_flush_type(buf_page_t *bpage, buf_flush_t flush_type)
Set the flush type of a page.
void buf_page_free_stale_during_write(buf_page_t *bpage, bool owns_sx_lock=false) noexcept
Free a stale page that is being written.
Definition: buf0buf.cc:5520
static buf_pool_t * buf_pool_from_block(const buf_block_t *block)
Returns the buffer pool instance given a block instance.
bool buf_is_block_in_instance(const buf_pool_t *buf_pool, const buf_block_t *ptr)
Find out if a block pointer points into one of currently used chunks of the buffer pool.
Definition: buf0buf.cc:3541
rw_lock_t * buf_page_hash_lock_get(const buf_pool_t *buf_pool, const page_id_t page_id)
Get appropriate page_hash_lock.
Definition: buf0buf.h:2616
std::ostream & operator<<(std::ostream &out, const buf_pool_t &buf_pool)
Print the given buf_pool_t object.
Definition: buf0buf.cc:6967
static BPageMutex * buf_page_get_mutex(const buf_page_t *bpage)
Gets the mutex of a block.
static uint64_t buf_pool_hash_zip_frame(void *ptr)
Compute the hash value for blocks in buf_pool->zip_hash.
Definition: buf0buf.h:2034
static buf_frame_t * buf_block_get_frame(const buf_block_t *block)
Gets a pointer to the memory frame of a block.
void buf_block_reset_page_type_on_mismatch(buf_block_t &block, page_type_t type, mtr_t &mtr)
Verify the page contained by the block.
Definition: buf0buf.h:2802
void buf_pool_free_all()
Frees the buffer pool at shutdown.
Definition: buf0buf.cc:7001
static enum buf_page_state buf_page_get_state(const buf_page_t *bpage)
Gets the state of a block.
static ulint buf_pool_index(const buf_pool_t *buf_pool)
Calculates the index of a buffer pool to the buf_pool[] array.
buf_block_t * buf_page_get_gen(const page_id_t &page_id, const page_size_t &page_size, ulint rw_latch, buf_block_t *guess, Page_fetch mode, ut::Location location, mtr_t *mtr, bool dirty_with_no_latch=false)
This is the general function used to get access to a database page.
Definition: buf0buf.cc:4427
ulint buf_get_free_list_len(void)
Gets the current length of the free list of buffer blocks.
rw_lock_t * buf_page_hash_lock_x_confirm(rw_lock_t *hash_lock, buf_pool_t *buf_pool, const page_id_t &page_id)
Definition: buf0buf.h:2628
static lsn_t buf_page_get_newest_modification(const buf_page_t *bpage)
Gets the youngest modification log sequence number for a frame.
ulint buf_get_latched_pages_number(void)
Returns the number of latched pages in the buffer pool.
Definition: buf0buf.cc:6517
static buf_page_t * buf_page_hash_get_low(buf_pool_t *buf_pool, const page_id_t &page_id)
Returns the control block of a file page, NULL if not found.
static ulint buf_block_fix(buf_page_t *bpage)
Increments the bufferfix count.
constexpr ulint MAX_BUFFER_POOLS
The maximum number of buffer pools that can be defined.
Definition: buf0buf.h:108
static buf_block_t * buf_block_hash_get_locked(buf_pool_t *buf_pool, const page_id_t &page_id, rw_lock_t **lock, ulint lock_mode)
Returns the control block of a file page, NULL if not found.
void buf_print_io(FILE *file)
Prints info of the buffer i/o.
Definition: buf0buf.cc:6813
static buf_pool_t * buf_pool_from_array(ulint index)
Returns the buffer pool instance given its array index.
static void buf_page_release_latch(buf_block_t *block, ulint rw_latch)
Releases a latch, if specified.
void buf_stats_get_pool_info(buf_pool_t *buf_pool, ulint pool_id, buf_pool_info_t *all_pool_info)
Collect buffer pool stats information for a buffer pool.
Definition: buf0buf.cc:6620
void buf_resize_thread()
This is the thread for resizing buffer pool.
Definition: buf0buf.cc:2673
void buf_print(void)
Prints info of the buffer pool data structure.
Definition: buf0buf.cc:6423
const buf_block_t * buf_page_try_get(const page_id_t &page_id, ut::Location location, mtr_t *mtr)
Given a tablespace id and page number tries to get that page.
Definition: buf0buf.cc:4687
static ulint buf_block_get_freed_page_clock(const buf_block_t *block)
Reads the freed_page_clock of a buffer block.
static void buf_ptr_get_fsp_addr(const void *ptr, space_id_t *space, fil_addr_t *addr)
Gets the space id, page offset, and byte offset within page of a pointer pointing to a buffer frame c...
static bool buf_page_peek_if_too_old(const buf_page_t *bpage)
Recommends a move of a block to the start of the LRU list if there is danger of dropping from the buf...
bool buf_block_will_withdrawn(buf_pool_t *buf_pool, const buf_block_t *block)
Determines if a block is intended to be withdrawn.
Definition: buf0buf.cc:1853
void buf_page_make_old(buf_page_t *bpage)
Moved a page to the end of the buffer pool LRU list so that it can be flushed out at the earliest.
Definition: buf0buf.cc:3174
lsn_t buf_pool_get_oldest_modification_approx(void)
Gets the smallest oldest_modification lsn among all of the earliest added pages in flush lists.
Definition: buf0buf.cc:435
buf_block_t * buf_block_hash_get_s_locked(buf_pool_t *b, const page_id_t &page_id, rw_lock_t **l)
Definition: buf0buf.h:1060
Page_fetch
Definition: buf0buf.h:57
@ NO_LATCH
get and bufferfix, but set no latch; we have separated this case, because it is error-prone programmi...
@ NORMAL
Get always.
@ IF_IN_POOL
get if in pool
@ POSSIBLY_FREED_NO_READ_AHEAD
Like Page_fetch::POSSIBLY_FREED, but do not initiate read ahead.
@ IF_IN_POOL_OR_WATCH
Get the page only if it's in the buffer pool, if not then set a watch on the page.
@ PEEK_IF_IN_POOL
get if in pool, do not make the block young in the LRU list
@ POSSIBLY_FREED
Like Page_fetch::NORMAL, but do not mind if the file page has been freed.
@ SCAN
Same as NORMAL, but hint that the fetch is part of a large scan.
rw_lock_t * buf_page_hash_lock_s_confirm(rw_lock_t *hash_lock, const buf_pool_t *buf_pool, const page_id_t page_id)
If not appropriate page_hash_lock, relock until appropriate.
Definition: buf0buf.h:2622
static void buf_page_unset_sticky(buf_page_t *bpage)
Removes stickiness of a block.
buf_page_print_flags
Definition: buf0buf.h:658
@ BUF_PAGE_PRINT_NO_FULL
Do not print the full page dump.
Definition: buf0buf.h:662
@ BUF_PAGE_PRINT_NO_CRASH
Do not crash at the end of buf_page_print().
Definition: buf0buf.h:660
buf_page_t * buf_page_get_also_watch(buf_pool_t *b, const page_id_t &page_id)
Definition: buf0buf.h:1055
bool buf_pool_watch_is_sentinel(const buf_pool_t *buf_pool, const buf_page_t *bpage)
Determine if a block is a sentinel for a buffer pool watch.
Definition: buf0buf.cc:2956
buf_block_t * buf_page_get_with_no_latch(const page_id_t &id, const page_size_t &size, ut::Location location, mtr_t *mtr)
Use these macros to bufferfix a page with no latching.
Definition: buf0buf.h:463
constexpr ulint MAX_BUFFER_POOLS_BITS
Number of bits to representing a buffer pool ID.
Definition: buf0buf.h:105
bool buf_block_hash_lock_held_s(const buf_pool_t *buf_pool, const buf_block_t *block)
Definition: buf0buf.h:2656
buf_block_t * buf_block_hash_get(buf_pool_t *b, const page_id_t &page_id)
Definition: buf0buf.h:1070
bool buf_page_in_memory(const buf_page_t *bpage)
Definition: buf0buf.h:2785
bool is_buffer_pool_resize_in_progress()
Definition: buf0buf.cc:7011
static bool buf_page_peek(const page_id_t &page_id)
Returns true if the page can be found in the buffer pool hash table.
bool buf_page_get_known_nowait(ulint rw_latch, buf_block_t *block, Cache_hint hint, const char *file, ulint line, mtr_t *mtr)
This is used to get access to a known database page, when no waiting can be done.
Definition: buf0buf.cc:4594
buf_page_t * buf_page_hash_get_s_locked(buf_pool_t *b, const page_id_t &page_id, rw_lock_t **l)
Definition: buf0buf.h:1042
static void buf_page_release_zip(buf_page_t *bpage)
Releases a compressed-only page acquired with buf_page_get_zip().
static void buf_block_free(buf_block_t *block)
Frees a buffer block which does not contain a file page.
static uint64_t buf_pool_hash_zip(buf_block_t *b)
Definition: buf0buf.h:2038
buf_page_t * buf_page_hash_get(buf_pool_t *b, const page_id_t &page_id)
Definition: buf0buf.h:1052
static void buf_block_set_state(buf_block_t *block, enum buf_page_state state)
Sets the state of a block.
constexpr uint32_t BUF_PAGE_STATE_BITS
The common buffer control block structure for compressed and uncompressed frames.
Definition: buf0buf.h:1154
static void buf_block_buf_fix_inc_func(ut::Location location, buf_block_t *block)
Increments the bufferfix count.
static buf_pool_t * buf_pool_get(const page_id_t &page_id)
Returns the buffer pool instance given a page id.
static ulint buf_get_withdraw_depth(buf_pool_t *buf_pool)
Return how many more pages must be added to the withdraw list to reach the withdraw target of the cur...
buf_page_state
States of a control block.
Definition: buf0buf.h:130
@ BUF_BLOCK_NOT_USED
Is in the free list; must be after the BUF_BLOCK_ZIP_ constants for compressed-only pages.
Definition: buf0buf.h:140
@ BUF_BLOCK_ZIP_PAGE
Contains a clean compressed page.
Definition: buf0buf.h:134
@ BUF_BLOCK_REMOVE_HASH
Hash index should be removed before putting to the free list.
Definition: buf0buf.h:152
@ BUF_BLOCK_MEMORY
Contains some main memory object.
Definition: buf0buf.h:149
@ BUF_BLOCK_ZIP_DIRTY
Contains a compressed page that is in the buf_pool->flush_list.
Definition: buf0buf.h:136
@ BUF_BLOCK_POOL_WATCH
A sentinel for the buffer pool watch, element of buf_pool->watch[].
Definition: buf0buf.h:132
@ BUF_BLOCK_READY_FOR_USE
When buf_LRU_get_free_block returns a block, it is in this state.
Definition: buf0buf.h:143
@ BUF_BLOCK_FILE_PAGE
Contains a buffered file page.
Definition: buf0buf.h:146
void buf_refresh_io_stats_all()
Refresh the statistics used to print per-second averages.
Definition: buf0buf.cc:6874
static ulint buf_pool_get_n_pages(void)
Gets the current size of buffer buf_pool in frames.
buf_block_t * buf_block_alloc(buf_pool_t *buf_pool)
Allocates a buffer block.
Definition: buf0buf.cc:578
static buf_block_t * buf_get_nth_chunk_block(const buf_pool_t *buf_pool, ulint n, ulint *chunk_size)
Get the nth chunk's buffer block in the specified buffer pool.
static ulint buf_pool_size_align(ulint size)
Calculate aligned buffer pool size based on srv_buf_pool_chunk_unit, if needed.
buf_block_t * buf_page_get(const page_id_t &id, const page_size_t &size, ulint latch, ut::Location location, mtr_t *mtr)
NOTE! The following macros should be used instead of buf_page_get_gen, to improve debugging.
Definition: buf0buf.h:452
static void buf_block_modify_clock_inc(buf_block_t *block)
Increment the modify clock.
static bool buf_page_in_file(const buf_page_t *bpage)
Determines if a block is mapped to a tablespace.
page_zip_des_t * buf_block_get_page_zip(buf_block_t *block) noexcept
Gets the compressed page descriptor corresponding to an uncompressed page if applicable.
Definition: buf0buf.h:2772
void buf_pool_invalidate(void)
Invalidates the file pages in the buffer pool when an archive recovery is completed.
Definition: buf0buf.cc:6128
void buf_page_free_descriptor(buf_page_t *bpage)
Free a buf_page_t descriptor.
Definition: buf0buf.cc:1410
buf_block_t * buf_page_create(const page_id_t &page_id, const page_size_t &page_size, rw_lock_type_t rw_latch, mtr_t *mtr)
Initializes a page to the buffer buf_pool.
Definition: buf0buf.cc:5064
double buf_get_modified_ratio_pct(void)
Return the ratio in percents of modified pages in the buffer pool / database pages in the buffer pool...
Definition: buf0buf.cc:6550
static buf_frame_t * buf_frame_align(byte *ptr)
void buf_page_prepare_for_free(buf_page_t *bpage) noexcept
Prepare a page before adding to the free list.
Definition: buf0buf.h:2764
buf_block_t * buf_pool_contains_zip(buf_pool_t *buf_pool, const void *data)
Finds a block in the buffer pool that points to a given compressed page.
Definition: buf0buf.cc:1169
static void buf_block_set_file_page(buf_block_t *block, const page_id_t &page_id)
Map a block to a file page.
void buf_pool_wait_for_no_pending_io()
Waits until there are no pending I/O operations for the buffer pool.
Definition: buf0buf.cc:6906
static buf_page_t * buf_page_alloc_descriptor(void)
Allocates a buf_page_t descriptor.
static enum buf_io_fix buf_block_get_io_fix(const buf_block_t *block)
Gets the io_fix state of a block.
bool buf_block_hash_lock_held_s_or_x(const buf_pool_t *buf_pool, const buf_block_t *block)
Definition: buf0buf.h:2666
bool buf_block_state_valid(buf_block_t *block)
Check if a buf_block_t object is in a valid state.
Definition: buf0buf.h:2027
buf_block_t * buf_block_hash_get_x_locked(buf_pool_t *b, const page_id_t &page_id, rw_lock_t **l)
Definition: buf0buf.h:1065
const std::unordered_map< buf_page_state, std::string_view > buf_page_state_str
Definition: buf0buf.h:155
buf_page_t * buf_page_reset_file_page_was_freed(const page_id_t &page_id)
Sets file_page_was_freed false if the page is found in the buffer pool.
Definition: buf0buf.cc:3234
static bool buf_page_is_old(const buf_page_t *bpage)
Determine if a block has been flagged old.
void buf_block_buf_fix_inc(buf_block_t *b, ut::Location l)
Increments the bufferfix count.
Definition: buf0buf.h:614
static void buf_page_set_sticky(buf_page_t *bpage)
Makes a block sticky.
void buf_get_total_list_size_in_bytes(buf_pools_list_size_t *buf_pools_list_size)
Get total list size in bytes from all buffer pools.
Definition: buf0buf.cc:531
void buf_get_total_list_len(ulint *LRU_len, ulint *free_len, ulint *flush_list_len)
Get total buffer pool statistics.
Definition: buf0buf.cc:515
bool buf_zip_decompress(buf_block_t *block, bool check)
Decompress a block.
Definition: buf0buf.cc:3437
The database buffer buf_pool.
The database buffer pool global types for the directory.
byte buf_frame_t
A buffer frame.
Definition: buf0types.h:62
BPageMutex BufPoolZipMutex
Definition: buf0types.h:201
constexpr uint32_t BUF_BUDDY_LOW
Smallest buddy page size.
Definition: buf0types.h:183
constexpr uint32_t BUF_BUDDY_SIZES_MAX
Maximum number of buddy sizes based on the max page size.
Definition: buf0types.h:189
buf_flush_t
Flags for flush types.
Definition: buf0types.h:68
@ BUF_FLUSH_N_TYPES
Index of last element + 1
Definition: buf0types.h:79
ib_mutex_t BufListMutex
Definition: buf0types.h:199
ib_bpmutex_t BPageMutex
Definition: buf0types.h:198
buf_io_fix
Flags for io_fix types.
Definition: buf0types.h:99
@ BUF_IO_NONE
no pending I/O
Definition: buf0types.h:101
@ BUF_IO_WRITE
write pending
Definition: buf0types.h:107
@ BUF_IO_READ
read pending
Definition: buf0types.h:104
@ BUF_IO_PIN
disallow relocation of block and its removal from the flush_list
Definition: buf0types.h:110
The database buffer pool high-level routines.
Class implementing buf_pool->flush_list hazard pointer.
Definition: buf0buf.h:2105
~FlushHp() override=default
Destructor.
FlushHp(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
Constructor.
Definition: buf0buf.h:2110
void adjust(const buf_page_t *bpage) override
Adjust the value of hp.
Definition: buf0buf.cc:2916
We use Flush_observer to track flushing of non-redo logged pages in bulk create index(btr0load....
Definition: buf0flu.h:258
A "Hazard Pointer" class used to iterate over page lists inside the buffer pool.
Definition: buf0buf.h:2047
bool is_hp(const buf_page_t *bpage)
Checks if a bpage is the hp.
Definition: buf0buf.cc:2891
void set(buf_page_t *bpage)
Set current value.
Definition: buf0buf.cc:2878
virtual void adjust(const buf_page_t *bpage)=0
Adjust the value of hp.
const ib_mutex_t * m_mutex
mutex that protects access to the m_hp.
Definition: buf0buf.h:2097
void move(const buf_page_t *bpage, buf_page_t *dpage)
Adjust the value of hp for moving.
Definition: buf0buf.cc:2903
buf_page_t * m_hp
hazard pointer.
Definition: buf0buf.h:2101
virtual ~HazardPointer()=default
Destructor.
const buf_pool_t * m_buf_pool
Buffer pool instance.
Definition: buf0buf.h:2093
HazardPointer(const HazardPointer &)
Disable copying.
buf_page_t * get() const
Get current value.
Definition: buf0buf.h:2059
HazardPointer(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
Constructor.
Definition: buf0buf.h:2052
HazardPointer & operator=(const HazardPointer &)
The IO Context that is passed down to the low level IO code.
Definition: os0file.h:266
Class implementing buf_pool->LRU hazard pointer.
Definition: buf0buf.h:2124
~LRUHp() override=default
Destructor.
void adjust(const buf_page_t *bpage) override
Adjust the value of hp.
Definition: buf0buf.cc:2931
LRUHp(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
Constructor.
Definition: buf0buf.h:2129
Special purpose iterators to be used when scanning the LRU list.
Definition: buf0buf.h:2146
~LRUItr() override=default
Destructor.
buf_page_t * start()
Selects from where to start a scan.
Definition: buf0buf.cc:2946
LRUItr(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
Constructor.
Definition: buf0buf.h:2151
The purpose of this class is to hide the knowledge that Buf_io_fix_latching_rules even exists from us...
Definition: buf0buf.cc:5614
Definition: buf0buf.h:1435
bool someone_is_responsible() const
Checks if there is any thread responsible for I/O on this page now.
Definition: buf0buf.h:1443
void release()
Called by the thread responsible for I/O on this page to release its responsibility.
Definition: buf0buf.h:1455
bool current_thread_is_responsible() const
Checks if the current thread is responsible for I/O on this page now.
Definition: buf0buf.h:1449
void take()
Called by the thread which becomes responsible for I/O on this page to indicate that it takes the res...
Definition: buf0buf.h:1462
std::thread::id responsible_thread
The thread responsible for I/O on this page, or an impossible value if no thread is currently respons...
Definition: buf0buf.h:1438
Definition: buf0buf.h:1164
uint32_t freed_page_clock
The value of buf_pool->freed_page_clock when this block was the last time put to the head of the LRU ...
Definition: buf0buf.h:1679
buf_page_t(const buf_page_t &other)
Copy constructor.
Definition: buf0buf.h:1168
void space_id_changed()
Updates new space reference and acquires "reference count latch" and the current version of the space...
Definition: buf0buf.h:1326
void take_io_responsibility()
Called by the thread which becomes responsible for I/O on this page to indicate that it takes the res...
Definition: buf0buf.h:1489
bool is_stale() const
Checks if this space reference saved during last page ID initialization was deleted or truncated sinc...
Definition: buf0buf.h:1243
void init_io_fix()
This is called only when having full ownership of the page object and no other thread can reach it.
Definition: buf0buf.h:1519
void set_io_fix(buf_io_fix io_fix)
Sets io_fix to specified value.
Definition: buf0buf.cc:5688
bool someone_has_io_responsibility() const
Checks if there is any thread responsible for I/O on this page now.
Definition: buf0buf.h:1473
bool has_correct_io_fix_value() const
Checks if io_fix has any of the known enum values.
Definition: buf0buf.h:1422
lsn_t get_newest_lsn() const noexcept
Definition: buf0buf.h:1359
bool current_thread_has_io_responsibility() const
Checks if the current thread is responsible for I/O on this page now.
Definition: buf0buf.h:1479
void set_newest_lsn(lsn_t lsn) noexcept
Set the latest modification LSN.
Definition: buf0buf.h:1370
buf_page_t * hash
Node used in chaining to buf_pool->page_hash or buf_pool->zip_hash.
Definition: buf0buf.h:1609
bool is_io_fix_write() const
Checks if the current value of io_fix is BUF_IO_WRITE.
Definition: buf0buf.cc:5668
Flush_observer * get_flush_observer() noexcept
Definition: buf0buf.h:1343
fil_space_t * get_space() const
Retrieve the tablespace object if one was available during page ID initialization.
Definition: buf0buf.h:1282
bool is_io_fix_read_as_opposed_to_write() const
Assuming that io_fix is either BUF_IO_READ or BUF_IO_WRITE determines which of the two it is.
Definition: buf0buf.cc:5680
space_id_t space() const noexcept
Retrieve the tablespace id.
Definition: buf0buf.h:1232
bool in_zip_hash
true if in buf_pool->zip_hash
Definition: buf0buf.h:1724
bool in_free_list
true if in buf_pool->free; when buf_pool->free_list_mutex is free, the following should hold: in_free...
Definition: buf0buf.h:1715
std::chrono::steady_clock::time_point access_time
Time of first access, or 0 if the block was never accessed in the buffer pool.
Definition: buf0buf.h:1688
Flush_observer * m_flush_observer
Flush observer instance.
Definition: buf0buf.h:1671
buf_fix_count_atomic_t buf_fix_count
Count of how many fold this block is currently bufferfixed.
Definition: buf0buf.h:1393
bool in_flush_list
true if in buf_pool->flush_list; when buf_pool->flush_list_mutex is free, the following should hold: ...
Definition: buf0buf.h:1711
void reset_page_id()
Sets stored value to invalid/empty value.
Definition: buf0buf.h:1319
bool is_dirty() const noexcept
Definition: buf0buf.h:1366
bool old
true if the block is in the old blocks in buf_pool->LRU_old
Definition: buf0buf.h:1697
bool was_io_fix_read() const
Checks if io_fix is BUF_IO_READ without requiring or acquiring any latches.
Definition: buf0buf.h:1579
void reinit_io_fix()
This is called only when having full ownership of the page object and no other thread can reach it.
Definition: buf0buf.h:1531
void reset_page_id(page_id_t new_page_id)
Sets stored page ID to the new value.
Definition: buf0buf.h:1303
void set_oldest_lsn(lsn_t lsn) noexcept
Set the LSN when the page is modified for the first time.
Definition: buf0buf.ic:746
uint16_t get_dblwr_batch_id() const
Definition: buf0buf.h:1228
bool was_stale() const
Checks if this space reference saved during last page ID initialization was deleted or truncated sinc...
Definition: buf0buf.h:1260
void set_page_id(const page_id_t page_id)
Set the stored page id to a new value.
Definition: buf0buf.h:1287
friend std::ostream & operator<<(std::ostream &outs, const buf_page_t &page)
Print page metadata in JSON format {"key":"value"}.
Definition: buf0buf.cc:7052
lsn_t newest_modification
The flush LSN, LSN when this page was written to the redo log.
Definition: buf0buf.h:1642
void release_io_responsibility()
Called by the thread responsible for I/O on this page to release its responsibility.
Definition: buf0buf.h:1485
static bool is_memory(const page_t *const ptr) noexcept
Check if the given ptr lies in a memory block of type BUF_BLOCK_MEMORY.
Definition: buf0buf.cc:7018
lsn_t get_oldest_lsn() const noexcept
Definition: buf0buf.h:1363
lsn_t oldest_modification
log sequence number of the youngest modification to this block, zero if not modified.
Definition: buf0buf.h:1646
page_id_t id
Page id.
Definition: buf0buf.h:1387
copyable_atomic_t< buf_io_fix > io_fix
Type of pending I/O operation.
Definition: buf0buf.h:1399
UT_LIST_NODE_T(buf_page_t) list
Based on state, this is a list node, protected by the corresponding list mutex, in one of the followi...
buf_io_fix get_io_fix_snapshot() const
Retrieves a value of io_fix without requiring or acquiring any latches.
Definition: buf0buf.h:1505
page_size_t size
Page size.
Definition: buf0buf.h:1390
io_responsibility_t io_responsibility
Tracks which thread is responsible for I/O on this page.
Definition: buf0buf.h:1468
uint8_t buf_pool_index
Index number of the buffer pool that this block belongs to.
Definition: buf0buf.h:1606
uint16_t m_dblwr_id
Double write instance ordinal value during writes.
Definition: buf0buf.h:1693
bool was_io_fix_none() const
Checks if io_fix is BUF_IO_NONE without requiring or acquiring any latches.
Definition: buf0buf.h:1596
void set_clean() noexcept
Set page to clean state.
Definition: buf0buf.h:1377
buf_io_fix get_io_fix() const
Retrieves the current value of io_fix.
Definition: buf0buf.h:1547
bool is_io_fix_read() const
Checks if the current value of io_fix is BUF_IO_READ.
Definition: buf0buf.cc:5674
uint32_t m_version
Version of fil_space_t when the page was updated.
Definition: buf0buf.h:1684
bool in_LRU_list
true if the page is in the LRU list; used in debugging
Definition: buf0buf.h:1718
void set_flush_observer(Flush_observer *flush_observer) noexcept
Set the flush observer for the page.
Definition: buf0buf.h:1347
buf_page_state state
Block state.
Definition: buf0buf.h:1599
page_no_t page_no() const noexcept
Retrieve the page number.
Definition: buf0buf.h:1236
fil_space_t * m_space
Tablespace instance that this page belongs to.
Definition: buf0buf.h:1674
bool was_io_fixed() const
Checks if io_fix is BUF_IO_FIX or BUF_IO_READ or BUF_IO_WRITE without requiring or acquiring any latc...
Definition: buf0buf.h:1586
void reset_flush_observer() noexcept
Remove the flush observer.
Definition: buf0buf.h:1355
void set_dblwr_batch_id(uint16_t batch_id)
Set the doublewrite buffer ID.
Definition: buf0buf.h:1225
bool file_page_was_freed
This is set to true when fsp frees a page in buffer pool; protected by buf_pool->zip_mutex or buf_blo...
Definition: buf0buf.h:1702
UT_LIST_NODE_T(buf_page_t) LRU
node of the LRU list
friend class Latching_rules_helpers
Definition: buf0buf.h:1427
bool is_memory() const noexcept
Check if the state of this page is BUF_BLOCK_MEMORY.
Definition: buf0buf.h:1218
buf_flush_t flush_type
If this block is currently being flushed to disk, this tells the flush_type.
Definition: buf0buf.h:1603
void set_page_size(const page_size_t &page_size)
Set the page size to a new value.
Definition: buf0buf.h:1295
bool in_page_hash
true if in buf_pool->page_hash
Definition: buf0buf.h:1721
page_zip_des_t zip
compressed page; zip.data (but not the data it points to) is protected by buf_pool->zip_mutex; state ...
Definition: buf0buf.h:1667
static bool is_correct_io_fix_value(buf_io_fix io_fix)
Checks if io_fix has any of the known enum values.
Definition: buf0buf.h:1406
Definition: buf0buf.h:1157
copyable_atomic_t(const copyable_atomic_t< T > &other)
Definition: buf0buf.h:1159
Definition: hash0hash.h:375
Page identifier.
Definition: buf0types.h:207
uint64_t hash() const
Retrieve the hash value.
Definition: buf0types.h:247
page_no_t page_no() const
Retrieve the page number.
Definition: buf0types.h:243
Page size descriptor.
Definition: page0size.h:50
size_t logical() const
Retrieve the logical page size (in-memory).
Definition: page0size.h:129
int page
Definition: ctype-mb.cc:1226
dberr_t
Definition: db0err.h:39
fil_space_t * fil_space_get(space_id_t space_id)
Look up a tablespace.
Definition: fil0fil.cc:2235
void fil_page_reset_type(const page_id_t &page_id, byte *page, ulint type, mtr_t *mtr)
Reset the page type.
Definition: fil0fil.cc:8184
The low-level file system.
uint16_t page_type_t
Definition: fil0fil.h:1223
constexpr page_type_t FIL_PAGE_INDEX
File page types (values of FIL_PAGE_TYPE)
Definition: fil0fil.h:1227
constexpr page_no_t FIL_NULL
'null' (undefined) page offset in the context of file spaces
Definition: fil0fil.h:1161
page_type_t fil_page_get_type(const byte *page)
Get the file page type.
Definition: fil0fil.h:1340
constexpr uint32_t FIL_PAGE_TYPE
file page type: FIL_PAGE_INDEX,..., 2 bytes.
Definition: fil0types.h:76
constexpr uint32_t FIL_PAGE_OFFSET
page offset inside space
Definition: fil0types.h:46
constexpr uint32_t FIL_PAGE_DATA
start of the data on the page
Definition: fil0types.h:111
constexpr uint32_t FIL_PAGE_SPACE_ID
alias for space id
Definition: fil0types.h:108
constexpr uint32_t FIL_PAGE_NEXT
if there is a 'natural' successor of the page, its offset.
Definition: fil0types.h:61
constexpr uint32_t FIL_PAGE_PREV
if there is a 'natural' predecessor of the page, its offset.
Definition: fil0types.h:51
flush_type
Definition: my_sys.h:295
The simple hash table utility.
static rw_lock_t * hash_lock_s_confirm(rw_lock_t *hash_lock, hash_table_t *table, uint64_t hash_value)
If not appropriate rw_lock for a hash value in a hash table, relock S-lock the another rw_lock until ...
static rw_lock_t * hash_lock_x_confirm(rw_lock_t *hash_lock, hash_table_t *table, uint64_t hash_value)
If not appropriate rw_lock for a hash value in a hash table, relock X-lock the another rw_lock until ...
static rw_lock_t * hash_get_lock(hash_table_t *table, uint64_t hash_value)
Gets the rw_lock for a hash value in a hash table.
static int flags[50]
Definition: hp_test1.cc:40
#define T
Definition: jit_executor_value.cc:373
#define F
Definition: jit_executor_value.cc:374
#define malloc(A)
Definition: lexyy.cc:914
#define free(A)
Definition: lexyy.cc:915
lock_mode
Definition: lock0types.h:54
constexpr lsn_t LSN_MAX
Maximum possible lsn value is slightly higher than the maximum sn value, because lsn sequence enumera...
Definition: log0constants.h:159
uint64_t lsn_t
Type used for all log sequence number storage and arithmetic.
Definition: log0types.h:63
static uint16_t mach_read_from_2(const byte *b)
The following function is used to fetch data from 2 consecutive bytes.
static uint32_t mach_read_from_4(const byte *b)
The following function is used to fetch data from 4 consecutive bytes.
static void mach_write_to_4(byte *b, ulint n)
The following function is used to store data in 4 consecutive bytes.
Mini-transaction buffer global types.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
void copy(Shards< COUNT > &dst, const Shards< COUNT > &src) noexcept
Copy the counters, overwrite destination.
Definition: ut0counter.h:354
void clear(Shards< COUNT > &shards) noexcept
Clear the counter - reset to 0.
Definition: ut0counter.h:344
Definition: buf0block_hint.cc:30
const std::string FILE("FILE")
bool load(THD *, const dd::String_type &fname, dd::String_type *buf)
Read an sdi file from disk and store in a buffer.
Definition: sdi_file.cc:308
Definition: os0file.h:89
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:75
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:79
size_t size(const char *const c)
Definition: base64.h:46
Definition: gcs_xcom_synode.h:64
mode
Definition: file_handle.h:61
pid_type get_id()
Definition: process.h:48
static uint64_t hash_uint64(uint64_t value)
Hashes a 64-bit integer.
Definition: ut0rnd.h:199
std::list< T, ut::allocator< T > > list
Specialization of list which uses ut_allocator.
Definition: ut0new.h:2880
void os_event_set(os_event_t event)
Sets an event semaphore to the signaled state: lets waiting threads proceed.
Definition: os0event.cc:553
bool os_event_is_set(const os_event_t event)
Check if the event is set.
Definition: os0event.cc:545
int64_t os_event_reset(os_event_t event)
Resets an event semaphore to the non-signaled state.
Definition: os0event.cc:568
The interface to the operating system process control primitives.
Index page routines.
byte page_t
Type of the index page.
Definition: page0types.h:152
required string type
Definition: replication_group_member_actions.proto:34
Shutdowns the Innobase database server.
std::atomic< enum srv_shutdown_t > srv_shutdown_state
At a shutdown this value climbs from SRV_SHUTDOWN_NONE to SRV_SHUTDOWN_EXIT_THREADS.
Definition: srv0start.cc:162
@ SRV_SHUTDOWN_EXIT_THREADS
Exit all threads and free resources.
Definition: srv0shutdown.h:111
The server main program.
Functor to validate the LRU list.
Definition: buf0buf.h:2738
static void validate(const buf_pool_t *buf_pool)
Definition: buf0buf.h:2741
void operator()(const buf_page_t *elem) const
Definition: buf0buf.h:2739
Functor to validate the LRU list.
Definition: buf0buf.h:2728
void operator()(const buf_page_t *elem) const
Definition: buf0buf.h:2729
static void validate(const buf_pool_t *buf_pool)
Definition: buf0buf.h:2731
Definition: buf0buf.h:2747
static void validate(const buf_pool_t *buf_pool)
Definition: buf0buf.h:2753
void operator()(const buf_block_t *elem) const
Definition: buf0buf.h:2748
Structure used by AHI to contain information on record prefixes to be considered in hash index subsys...
Definition: buf0buf.h:1739
bool operator==(const btr_search_prefix_info_t &other) const
Definition: buf0buf.h:1753
bool operator!=(const btr_search_prefix_info_t &other) const
Definition: buf0buf.h:1758
bool equals_without_left_side(const btr_search_prefix_info_t &other) const
Definition: buf0buf.h:1749
uint32_t n_bytes
recommended prefix: number of bytes in an incomplete field
Definition: buf0buf.h:1742
uint16_t n_fields
recommended prefix length for hash search: number of full fields
Definition: buf0buf.h:1744
bool left_side
true or false, depending on whether the leftmost record of several records with the same prefix shoul...
Definition: buf0buf.h:1747
Structure that holds most AHI-related fields.
Definition: buf0buf.h:1802
void assert_empty_on_init() const
Definition: buf0buf.h:1868
std::atomic< dict_index_t * > index
Index for which the adaptive hash index has been created, or nullptr if the page does not exist in th...
Definition: buf0buf.h:1821
void assert_empty() const
Definition: buf0buf.h:1866
void validate() const
Definition: buf0buf.h:1844
std::atomic< btr_search_prefix_info_t > prefix_info
Prefix info that was used for building hash index.
Definition: buf0buf.h:1820
std::atomic< uint16_t > n_pointers
Used in debugging.
Definition: buf0buf.h:1842
std::atomic< btr_search_prefix_info_t > recommended_prefix_info
Recommended prefix info for hash search.
Definition: buf0buf.h:1809
The buffer control block structure.
Definition: buf0buf.h:1764
rw_lock_t debug_latch
In the debug version, each thread which bufferfixes the block acquires an s-latch here; so we can use...
Definition: buf0buf.h:1903
uint64_t modify_clock
This clock is incremented every time a pointer to a record on the page may become obsolete; this is u...
Definition: buf0buf.h:1917
BPageLock lock
read-write lock of the buffer frame
Definition: buf0buf.h:1774
std::atomic< uint32_t > n_hash_helps
Counter which controls how many times the current prefix recommendation would help in searches.
Definition: buf0buf.h:1891
page_type_t get_page_type() const
Get the page type of the current buffer block.
Definition: buf0buf.h:1963
struct buf_block_t::ahi_t ahi
buf_page_t page
page information; this must be the first field, so that buf_pool->page_hash can point to buf_page_t o...
Definition: buf0buf.h:1770
page_no_t get_next_page_no() const
Get the next page number of the current buffer block.
Definition: buf0buf.h:1951
page_zip_des_t const * get_page_zip() const noexcept
Const version.
Definition: buf0buf.h:2007
const char * get_page_type_str() const noexcept
Get the page type of the current buffer block as string.
Definition: buf0buf.cc:6994
bool in_withdraw_list
Definition: buf0buf.h:1796
UT_LIST_NODE_T(buf_block_t) unzip_LRU
node of the decompressed LRU list; a block is in the unzip_LRU list if page.state == BUF_BLOCK_FILE_P...
page_no_t get_prev_page_no() const
Get the prev page number of the current buffer block.
Definition: buf0buf.h:1957
bool is_leaf() const
Definition: buf0buf.h:2018
void mark_for_read_io()
Mark the frame with jumbled page_id, while initiating i/o read (BUF_IO_READ).
Definition: buf0buf.h:1970
uint64_t get_modify_clock(bool single_threaded) const noexcept
Get the modified clock (version) value.
Definition: buf0buf.h:1930
bool in_unzip_LRU_list
true if the page is in the decompressed LRU list; used in debugging
Definition: buf0buf.h:1794
bool is_empty() const
Check if this index page is empty.
Definition: buf0buf.cc:7031
const page_id_t & get_page_id() const
Get the page number and space id of the current buffer block.
Definition: buf0buf.h:1943
BPageMutex mutex
mutex protecting this block: state (also protected by the buffer pool mutex), io_fix,...
Definition: buf0buf.h:1924
byte * frame
pointer to buffer frame which is of size UNIV_PAGE_SIZE, and aligned to an address divisible by UNIV_...
Definition: buf0buf.h:1786
page_no_t get_page_no() const
Get the page number of the current buffer block.
Definition: buf0buf.h:1947
bool is_index_page() const
Definition: buf0buf.h:2020
bool is_root() const
Definition: buf0buf.h:2014
bool was_freed() const
Check if the buffer block was freed.
Definition: buf0buf.h:1779
bool made_dirty_with_no_latch
true if block has been made dirty without acquiring X/SX latch as the block belongs to temporary tabl...
Definition: buf0buf.h:1895
page_zip_des_t * get_page_zip() noexcept
Gets the compressed page descriptor corresponding to an uncompressed page if applicable.
Definition: buf0buf.h:2001
bool is_memory() const noexcept
Definition: buf0buf.h:2011
uint16_t get_page_level() const
Definition: buf0buf.cc:7023
friend std::ostream & operator<<(std::ostream &outs, const buf_block_t &block)
Print control block information in JSON format: {"key":"value"}.
Definition: buf0buf.cc:7086
Struct that is embedded in the free zip blocks.
Definition: buf0buf.h:2165
UT_LIST_NODE_T(buf_buddy_free_t) list
Node of zip_free list.
ulint size
size of the block
Definition: buf0buf.h:2167
union buf_buddy_free_t::@201 stamp
byte bytes[FIL_PAGE_DATA]
stamp[FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID] == BUF_BUDDY_FREE_STAMP denotes a free block.
Definition: buf0buf.h:2168
buf_page_t bpage
Embedded bpage descriptor.
Definition: buf0buf.h:2179
Definition: buf0buf.h:2277
uint64_t relocated
Definition: buf0buf.h:2279
ulint used
Definition: buf0buf.h:2278
std::chrono::steady_clock::duration relocated_duration
Definition: buf0buf.h:2280
Statistics of buddy blocks of a given size.
Definition: buf0buf.h:2267
uint64_t relocated
Number of blocks relocated by the buddy system.
Definition: buf0buf.h:2272
snapshot_t take_snapshot()
Definition: buf0buf.h:2283
std::atomic< ulint > used
Number of blocks allocated from the buddy system.
Definition: buf0buf.h:2269
std::chrono::steady_clock::duration relocated_duration
Total duration of block relocations.
Definition: buf0buf.h:2275
A chunk of buffers.
Definition: buf0buf.ic:53
This structure defines information we will fetch from each buffer pool.
Definition: buf0buf.h:169
ulint young_making_delta
num of pages made young since last printout
Definition: buf0buf.h:222
std::array< size_t, BUF_FLUSH_N_TYPES > n_pending_flush
Number of pages pending flush of given type.
Definition: buf0buf.h:189
double pages_created_rate
num of pages create per second
Definition: buf0buf.h:218
ulint n_pages_read
buf_pool->n_pages_read
Definition: buf0buf.h:195
ulint pool_unique_id
Buffer Pool ID.
Definition: buf0buf.h:173
ulint n_pend_reads
buf_pool->n_pend_reads, pages pending read
Definition: buf0buf.h:187
ulint n_ra_pages_read_rnd
buf_pool->n_ra_pages_read_rnd, number of pages readahead
Definition: buf0buf.h:203
ulint lru_len
Length of buf_pool->LRU.
Definition: buf0buf.h:177
ulint unzip_cur
buf_LRU_stat_cur.unzip, num pages decompressed in current interval
Definition: buf0buf.h:243
ulint page_read_delta
num of pages read since last printout
Definition: buf0buf.h:220
double pages_written_rate
num of pages written per second
Definition: buf0buf.h:219
double page_made_young_rate
page made young rate in pages per second
Definition: buf0buf.h:213
ulint io_sum
buf_LRU_stat_sum.io
Definition: buf0buf.h:239
ulint io_cur
buf_LRU_stat_cur.io, num of IO for current interval
Definition: buf0buf.h:240
ulint old_lru_len
buf_pool->LRU_old_len
Definition: buf0buf.h:179
double pages_readahead_rnd_rate
random readahead rate in pages per second
Definition: buf0buf.h:228
ulint unzip_sum
buf_LRU_stat_sum.unzip
Definition: buf0buf.h:242
ulint n_pages_made_young
number of pages made young
Definition: buf0buf.h:191
ulint n_ra_pages_read
buf_pool->n_ra_pages_read, number of pages readahead
Definition: buf0buf.h:205
ulint n_pages_not_made_young
number of pages not made young
Definition: buf0buf.h:193
ulint n_ra_pages_evicted
buf_pool->n_ra_pages_evicted, number of readahead pages evicted without access
Definition: buf0buf.h:208
ulint n_pages_created
buf_pool->n_pages_created
Definition: buf0buf.h:197
ulint n_page_get_delta
num of buffer pool page gets since last printout
Definition: buf0buf.h:210
ulint free_list_len
Length of buf_pool->free list.
Definition: buf0buf.h:181
double pages_evicted_rate
rate of readahead page evicted without access, in pages per second
Definition: buf0buf.h:232
ulint not_young_making_delta
num of pages not make young since last printout
Definition: buf0buf.h:224
ulint n_pend_unzip
buf_pool->n_pend_unzip, pages pending decompress
Definition: buf0buf.h:185
double pages_readahead_rate
readahead rate in pages per second
Definition: buf0buf.h:230
ulint unzip_lru_len
length of buf_pool->unzip_LRU list
Definition: buf0buf.h:236
ulint pool_size
Buffer Pool size in pages.
Definition: buf0buf.h:175
ulint flush_list_len
Length of buf_pool->flush_list.
Definition: buf0buf.h:183
double page_not_made_young_rate
page not made young rate in pages per second
Definition: buf0buf.h:215
ulint n_page_gets
buf_pool->n_page_gets
Definition: buf0buf.h:201
double pages_read_rate
num of pages read per second
Definition: buf0buf.h:217
ulint n_pages_written
buf_pool->n_pages_written
Definition: buf0buf.h:199
The buffer pool statistics structure.
Definition: buf0buf.h:2185
uint64_t n_pages_not_made_young
Number of pages not made young because the first access was not long enough ago, in buf_page_peek_if_...
Definition: buf0buf.h:2218
std::atomic< uint64_t > n_pages_read
Number of read operations.
Definition: buf0buf.h:2194
std::atomic< uint64_t > n_pages_created
number of pages created in the pool with no read.
Definition: buf0buf.h:2200
uint64_t n_pages_made_young
Number of pages made young, in calls to buf_LRU_make_block_young().
Definition: buf0buf.h:2214
uint64_t n_ra_pages_evicted
Number of read ahead pages that are evicted without being accessed.
Definition: buf0buf.h:2210
std::atomic< uint64_t > n_ra_pages_read_rnd
Number of pages read in as part of random read ahead.
Definition: buf0buf.h:2203
uint64_t flush_list_bytes
Flush_list size in bytes.
Definition: buf0buf.h:2224
std::atomic< uint64_t > n_ra_pages_read
Number of pages read in as part of read ahead.
Definition: buf0buf.h:2206
Shards m_n_page_gets
Number of page gets performed; also successful searches through the adaptive hash index are counted a...
Definition: buf0buf.h:2191
uint64_t LRU_bytes
LRU size in bytes.
Definition: buf0buf.h:2221
void reset()
Definition: buf0buf.h:2250
static void copy(buf_pool_stat_t &dst, const buf_pool_stat_t &src) noexcept
Definition: buf0buf.h:2226
std::atomic< uint64_t > n_pages_written
Number of write operations.
Definition: buf0buf.h:2197
The buffer pool structure.
Definition: buf0buf.h:2293
UT_LIST_BASE_NODE_T(buf_buddy_free_t, list) zip_free[BUF_BUDDY_SIZES_MAX]
Buddy free lists.
UT_LIST_BASE_NODE_T(buf_page_t, list) free
Base node of the free block list.
buf_chunk_t * chunks_old
old buffer pool chunks to be freed after resizing buffer pool
Definition: buf0buf.h:2347
void change_flush_state(buf_flush_t flush_type, F &&change)
Executes change() which modifies fields protected by flush_state_mutex.
Definition: buf0buf.h:2558
hash_table_t * zip_hash
Hash table of buf_block_t blocks whose frames are allocated to the zip buddy system,...
Definition: buf0buf.h:2366
FlushHp flush_hp
"Hazard pointer" used during scan of flush_list while doing flush list batch.
Definition: buf0buf.h:2400
buf_buddy_stat_t buddy_stat[BUF_BUDDY_SIZES_MAX+1]
Statistics of buddy system, indexed by block size.
Definition: buf0buf.h:2379
LRUItr single_scan_itr
Iterator used to scan the LRU list when searching for single page flushing victim.
Definition: buf0buf.h:2469
buf_pool_stat_t old_stat
Old statistics.
Definition: buf0buf.h:2385
void deallocate_chunk(buf_chunk_t *chunk)
A wrapper for buf_pool_t::allocator.deallocate_large which also advices the OS that this chunk can be...
Definition: buf0buf.cc:975
bool try_LRU_scan
Set to false when an LRU scan for free block fails.
Definition: buf0buf.h:2431
ulint buddy_n_frames
Number of frames allocated from the buffer pool to the buddy system.
Definition: buf0buf.h:2334
std::atomic< ulint > n_pend_reads
Number of pending read operations.
Definition: buf0buf.h:2369
UT_LIST_BASE_NODE_T(buf_page_t, list) zip_clean
Unmodified compressed pages.
UT_LIST_BASE_NODE_T(buf_page_t, list) flush_list
Base node of the modified block list.
LRUHp lru_hp
"hazard pointer" used during scan of LRU while doing LRU list batch.
Definition: buf0buf.h:2461
bool allocate_chunk(ulonglong mem_size, buf_chunk_t *chunk)
A wrapper for buf_pool_t::allocator.alocate_large which also advices the OS that this chunk should no...
Definition: buf0buf.cc:941
bool is_tracking()
Check if the page modifications are tracked.
Definition: buf0buf.h:2438
UT_LIST_BASE_NODE_T(buf_block_t, unzip_LRU) unzip_LRU
Base node of the unzip_LRU list.
std::chrono::steady_clock::time_point last_printout_time
when buf_print_io was last time called.
Definition: buf0buf.h:2375
ulint LRU_old_ratio
Reserve this much of the buffer pool for "old" blocks.
Definition: buf0buf.h:2330
BufListMutex chunks_mutex
protects (de)allocation of chunks:
Definition: buf0buf.h:2302
lsn_t track_page_lsn
Page Tracking start LSN.
Definition: buf0buf.h:2434
BufListMutex zip_free_mutex
buddy allocator mutex
Definition: buf0buf.h:2311
volatile ulint n_chunks
Number of buffer pool chunks.
Definition: buf0buf.h:2338
LRUItr lru_scan_itr
Iterator used to scan the LRU list when searching for replaceable victim.
Definition: buf0buf.h:2465
bool madvise_dump()
Advices the OS that all chunks in this buffer pool instance can be dumped to a core file.
Definition: buf0buf.cc:986
ulint old_size
Previous pool size in pages.
Definition: buf0buf.h:2353
UT_LIST_BASE_NODE_T(buf_page_t, LRU) LRU
Base node of the LRU list.
FlushHp oldest_hp
Entry pointer to scan the oldest page except for system temporary.
Definition: buf0buf.h:2403
buf_page_t * LRU_old
Pointer to the about LRU_old_ratio/BUF_LRU_OLD_RATIO_DIV oldest blocks in the LRU list; NULL if LRU l...
Definition: buf0buf.h:2477
buf_page_t * watch
Sentinel records for buffer pool watches.
Definition: buf0buf.h:2506
BufListMutex flush_list_mutex
Mutex protecting the flush list access.
Definition: buf0buf.h:2396
ib_mutex_t flush_state_mutex
Flush state protection mutex.
Definition: buf0buf.h:2317
buf_chunk_t * chunks
buffer pool chunks
Definition: buf0buf.h:2344
BufListMutex LRU_list_mutex
LRU list mutex.
Definition: buf0buf.h:2305
hash_table_t * page_hash
Hash table of buf_page_t or buf_block_t file pages, buf_page_in_file() == true, indexed by (space_id,...
Definition: buf0buf.h:2362
ulint withdraw_target
Target length of withdraw block list, when withdrawing.
Definition: buf0buf.h:2457
os_event_t no_flush[BUF_FLUSH_N_TYPES]
This is in the set state when there is no flush batch of the given type running.
Definition: buf0buf.h:2418
buf_pool_stat_t stat
Current statistics.
Definition: buf0buf.h:2382
page_no_t read_ahead_area
Size in pages of the area which the read-ahead algorithms read if invoked.
Definition: buf0buf.h:2357
ulint curr_pool_size
Current pool size in bytes.
Definition: buf0buf.h:2327
bool init_flush[BUF_FLUSH_N_TYPES]
This is true when a flush of the given type is being initialized.
Definition: buf0buf.h:2410
ulint curr_size
Current pool size in pages.
Definition: buf0buf.h:2350
ulint instance_no
Array index of this buffer pool instance.
Definition: buf0buf.h:2324
ulint LRU_old_len
Length of the LRU list from the block to which LRU_old points onward, including that block; see buf0l...
Definition: buf0buf.h:2483
std::array< size_t, BUF_FLUSH_N_TYPES > n_flush
This is the number of pending writes in the given flush type.
Definition: buf0buf.h:2414
std::atomic< ulint > n_pend_unzip
number of pending decompressions.
Definition: buf0buf.h:2372
UT_LIST_BASE_NODE_T(buf_page_t, list) withdraw
base node of the withdraw block list.
lsn_t max_lsn_io
Maximum LSN for which write io has already started.
Definition: buf0buf.h:2441
ulint freed_page_clock
A sequence number used to count the number of buffer blocks removed from the end of the LRU list; NOT...
Definition: buf0buf.h:2425
BufListMutex free_list_mutex
free and withdraw list mutex
Definition: buf0buf.h:2308
BufPoolZipMutex zip_mutex
Zip mutex of this buffer pool instance, protects compressed only pages (of type buf_page_t,...
Definition: buf0buf.h:2321
bool madvise_dont_dump()
Advices the OS that all chunks in this buffer pool instance should not be dumped to a core file.
Definition: buf0buf.cc:996
volatile ulint n_chunks_new
New number of buffer pool chunks.
Definition: buf0buf.h:2341
BufListMutex zip_hash_mutex
zip_hash mutex
Definition: buf0buf.h:2314
bool is_flushing(buf_flush_t flush_type) const
Checks if the batch is running, which is basically equivalent to !os_event_is_set(no_flush[type]) if ...
Definition: buf0buf.h:2545
The occupied bytes of lists in all buffer pools.
Definition: buf0buf.h:249
ulint LRU_bytes
LRU size in bytes.
Definition: buf0buf.h:250
ulint unzip_LRU_bytes
unzip_LRU size in bytes
Definition: buf0buf.h:251
ulint flush_list_bytes
flush_list size in bytes
Definition: buf0buf.h:252
File space address.
Definition: fil0fil.h:1178
File node of a tablespace or the log data space.
Definition: fil0fil.h:160
Tablespace or log data space.
Definition: fil0fil.h:240
space_id_t id
Tablespace ID.
Definition: fil0fil.h:336
void dec_ref() noexcept
Decrement the page reference count.
Definition: fil0fil.h:298
uint32_t get_current_version() const
Returns current version of the space object.
Definition: fil0fil.cc:11733
uint32_t get_recent_version() const
Returns current version of the space object.
Definition: fil0fil.cc:11737
bool was_not_deleted() const
Definition: fil0fil.cc:11725
void inc_ref() noexcept
Increment the page reference count.
Definition: fil0fil.h:287
bool is_deleted() const
Definition: fil0fil.cc:11720
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:177
InnoDB condition variable.
Definition: os0event.cc:63
Compressed page descriptor.
Definition: page0types.h:201
page_zip_t * data
Compressed page data.
Definition: page0types.h:203
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:363
Definition: ut0core.h:36
bool rw_lock_own(const rw_lock_t *lock, ulint lock_type)
Checks if the thread has locked the rw-lock in the specified mode, with the pass value == 0.
Definition: sync0rw.cc:858
rw_lock_type_t
Definition: sync0rw.h:97
@ RW_NO_LATCH
Definition: sync0rw.h:101
bool rw_lock_own_flagged(const rw_lock_t *lock, rw_lock_flags_t flags)
Checks if the thread has locked the rw-lock in the specified mode, with the pass value == 0.
Definition: sync0rw.cc:898
latch_level_t
Latching order levels.
Definition: sync0types.h:201
@ RW_LOCK_S
Definition: sync0types.h:208
@ RW_LOCK_X
Definition: sync0types.h:209
@ RW_LOCK_FLAG_X
Definition: sync0types.h:1216
@ RW_LOCK_FLAG_SX
Definition: sync0types.h:1217
@ RW_LOCK_FLAG_S
Definition: sync0types.h:1215
Version control for database, common definitions, and include files.
constexpr uint32_t UINT32_UNDEFINED
The 'undefined' value for a 32-bit unsigned integer.
Definition: univ.i:428
#define UNIV_PAGE_SIZE_SHIFT
The 2-logarithm of UNIV_PAGE_SIZE:
Definition: univ.i:291
#define IF_DEBUG(...)
Definition: univ.i:674
unsigned long int ulint
Definition: univ.i:406
#define UNIV_MEM_VALID(addr, size)
Definition: univ.i:591
constexpr uint32_t UNIV_ZIP_SIZE_MIN
Smallest compressed page size.
Definition: univ.i:330
Utilities for byte operations.
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
#define ut_d(EXPR)
Debug statement.
Definition: ut0dbg.h:107
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93
void ut_list_validate(const List &list, Functor &functor)
Checks the consistency of a two-way list.
Definition: ut0lst.h:493
#define mutex_own(M)
Checks that the current thread owns the mutex.
Definition: ut0mutex.h:165
#define mutex_exit(M)
Definition: ut0mutex.h:123
#define mutex_enter(M)
Definition: ut0mutex.h:117
static uint64_t lsn
Definition: xcom_base.cc:446
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510
int n
Definition: xcom_base.cc:509