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