MySQL 8.3.0
Source Code Documentation
fsp0fsp.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 2023, 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 also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/fsp0fsp.h
28 File space management
29
30 Created 12/18/1995 Heikki Tuuri
31 *******************************************************/
32
33#ifndef fsp0fsp_h
34#define fsp0fsp_h
35
36#include "univ.i"
37
38#include "fsp0space.h"
39#include "fut0lst.h"
40#include "mtr0mtr.h"
43#include "page0types.h"
44#include "rem0types.h"
45#include "ut0byte.h"
46
47#include <random>
48#include "fsp0types.h"
49
50#ifdef UNIV_HOTBACKUP
51#include "buf0buf.h"
52#endif /* UNIV_HOTBACKUP */
53
54class DDL_Record;
55extern std::vector<DDL_Record *> ts_encrypt_ddl_records;
58
59/** @defgroup Tablespace Header Constants (moved from fsp0fsp.c)
60@{ */
61#ifdef UNIV_DEBUG
62extern std::vector<space_id_t> flag_mismatch_spaces;
63#endif
64
65/** Offset of the space header within a file page */
66constexpr uint32_t FSP_HEADER_OFFSET = FIL_PAGE_DATA;
67
68/** The number of bytes required to store SDI root page number(4)
69and SDI version(4) at Page 0 */
70constexpr uint32_t FSP_SDI_HEADER_LEN = 8;
71
72/* The data structures in files are defined just as byte strings in C */
73typedef byte fsp_header_t;
74typedef byte xdes_t;
75
76#ifdef UNIV_DEBUG
77/** Check if the state of extent descriptor is valid.
78@param[in] state the extent descriptor state
79@return true if state is valid, false otherwise */
80bool xdes_state_is_valid(ulint state);
81#endif /* UNIV_DEBUG */
82
83#ifdef UNIV_DEBUG
84struct xdes_mem_t {
85 xdes_mem_t(const xdes_t *xdes) : m_xdes(xdes) {}
86
87 const char *state_name() const;
88
89 bool is_valid() const;
90 const xdes_t *m_xdes;
91
92 std::ostream &print(std::ostream &out) const;
93};
94
95inline std::ostream &operator<<(std::ostream &out, const xdes_mem_t &obj) {
96 return (obj.print(out));
97}
98
99/** In-memory representation of the fsp_header_t file structure. */
101 fsp_header_mem_t(const fsp_header_t *header, mtr_t *mtr);
102
115
116 std::ostream &print(std::ostream &out) const;
117};
118
119inline std::ostream &operator<<(std::ostream &out,
120 const fsp_header_mem_t &obj) {
121 return (obj.print(out));
122}
123#endif /* UNIV_DEBUG */
124
125/* SPACE HEADER
126 ============
127
128File space header data structure: this data structure is contained in the
129first page of a space. The space for this header is reserved in every extent
130descriptor page, but used only in the first. */
131
132/*-------------------------------------*/
133/** space id */
134constexpr uint32_t FSP_SPACE_ID = 0;
135/** this field contained a value up to which we know that the modifications in
136 the database have been flushed to the file space; not used now */
137constexpr uint32_t FSP_NOT_USED = 4;
138/** Current size of the space in pages */
139constexpr uint32_t FSP_SIZE = 8;
140/** Minimum page number for which the free list has not been initialized: the
141 pages >= this limit are, bydefinition, free; note that in a single-table
142 tablespace where size < 64 pages, this number is 64, i.e.,we have initialized
143 the space about the first extent, but have not physically allocated those
144 pages to thefile */
145constexpr uint32_t FSP_FREE_LIMIT = 12;
146/** fsp_space_t.flags, similar to dict_table_t::flags */
147constexpr uint32_t FSP_SPACE_FLAGS = 16;
148/** number of used pages in the FSP_FREE_FRAG list */
149constexpr uint32_t FSP_FRAG_N_USED = 20;
150/** list of free extents */
151constexpr uint32_t FSP_FREE = 24;
152/** list of partially free extents not belonging to any segment */
153constexpr uint32_t FSP_FREE_FRAG = 24 + FLST_BASE_NODE_SIZE;
154
155/** list of full extents not belonging to any segment */
156constexpr uint32_t FSP_FULL_FRAG = 24 + 2 * FLST_BASE_NODE_SIZE;
157
158/** 8 bytes which give the first unused segment id */
159constexpr uint32_t FSP_SEG_ID = 24 + 3 * FLST_BASE_NODE_SIZE;
160
161/** list of pages containing segment headers, where all the segment inode slots
162 are reserved */
163constexpr uint32_t FSP_SEG_INODES_FULL = 32 + 3 * FLST_BASE_NODE_SIZE;
164
165/** list of pages containing segment headers, where not all the segment header
166 slots are reserved */
167constexpr uint32_t FSP_SEG_INODES_FREE = 32 + 4 * FLST_BASE_NODE_SIZE;
168
169/*-------------------------------------*/
170/* File space header size */
171constexpr uint32_t FSP_HEADER_SIZE = 32 + 5 * FLST_BASE_NODE_SIZE;
172
173/** This many free extents are added to the free list from above FSP_FREE_LIMIT
174 at a time */
175constexpr uint32_t FSP_FREE_ADD = 4;
176
177/** @} */
178
179/* Maximum allowed value of AUTOEXTEND_SIZE attribute */
180constexpr uint64_t FSP_MAX_AUTOEXTEND_SIZE = 4 * 1024 * 1024 * 1024ULL;
181
182/** @defgroup File Segment Inode Constants (moved from fsp0fsp.c)
183@{ */
184
185/* FILE SEGMENT INODE
186 ==================
187
188Segment inode which is created for each segment in a tablespace. NOTE: in
189purge we assume that a segment having only one currently used page can be
190freed in a few steps, so that the freeing cannot fill the file buffer with
191bufferfixed file pages. */
192
193typedef byte fseg_inode_t;
194
196/* the list node for linking
197segment inode pages */
198
200/*-------------------------------------*/
201/* 8 bytes of segment id: if this is 0, it means that the header is unused */
202constexpr uint32_t FSEG_ID = 0;
203/** number of used segment pages in the FSEG_NOT_FULL list */
204constexpr uint32_t FSEG_NOT_FULL_N_USED = 8;
205/** list of free extents of this segment */
206constexpr uint32_t FSEG_FREE = 12;
207/** list of partially free extents */
208constexpr uint32_t FSEG_NOT_FULL = 12 + FLST_BASE_NODE_SIZE;
209/** list of full extents */
210constexpr uint32_t FSEG_FULL = 12 + 2 * FLST_BASE_NODE_SIZE;
211/** magic number used in debugging */
212constexpr uint32_t FSEG_MAGIC_N = 12 + 3 * FLST_BASE_NODE_SIZE;
213/** array of individual pages belonging to this segment in fsp fragment extent
214 lists */
215constexpr uint32_t FSEG_FRAG_ARR = 16 + 3 * FLST_BASE_NODE_SIZE;
216/* number of slots in the array for the fragment pages */
217#define FSEG_FRAG_ARR_N_SLOTS (FSP_EXTENT_SIZE / 2)
218/** a fragment page slot contains its page number within space, FIL_NULL means
219 that the slot is not in use */
220constexpr uint32_t FSEG_FRAG_SLOT_SIZE = 4;
221
222/*-------------------------------------*/
223#define FSEG_INODE_SIZE \
224 (16 + 3 * FLST_BASE_NODE_SIZE + FSEG_FRAG_ARR_N_SLOTS * FSEG_FRAG_SLOT_SIZE)
225
226static inline uint32_t FSP_SEG_INODES_PER_PAGE(page_size_t page_size) {
227 return (page_size.physical() - FSEG_ARR_OFFSET - 10) / FSEG_INODE_SIZE;
228}
229/* Number of segment inodes which fit on a
230single page */
231
232constexpr uint32_t FSEG_MAGIC_N_VALUE = 97937874;
233
234/** The segment_reserve_factor is the ratio x/y expressed in percentage,
235where x is the number of free pages in the segment, and y is the total number
236of pages in the segment. The number of used pages in the segment is given by
237(y-x). The number of free pages in the segment (x) will be maintained such
238that the actual segment_reserve_factor will be >= the requested
239segment_reserve_factor, which is contained in this variable. */
240extern double fseg_reserve_pct;
241
242/* Various constants related to segment reserve factor */
243constexpr double FSEG_RESERVE_PCT_DFLT = 12.50;
244constexpr double FSEG_RESERVE_PCT_MIN = 0.03;
245constexpr double FSEG_RESERVE_PCT_MAX = 40.00;
246
247#define FSEG_FRAG_LIMIT FSEG_FRAG_ARR_N_SLOTS
248
249/** If the reserved size of a segment is at least this many extents, we allow
250extents to be put to the free list of the extent: at most
251FSEG_FREE_LIST_MAX_LEN many */
252constexpr uint32_t FSEG_FREE_LIST_LIMIT = 40;
253constexpr uint32_t FSEG_FREE_LIST_MAX_LEN = 4;
254/** @} */
255
256/** @defgroup Extent Descriptor Constants (moved from fsp0fsp.c)
257@{ */
258
259/* EXTENT DESCRIPTOR
260 =================
261
262File extent descriptor data structure: contains bits to tell which pages in
263the extent are free and which contain old tuple version to clean. */
264
265/*-------------------------------------*/
266/** The identifier of the segment to which this extent belongs */
267constexpr uint32_t XDES_ID = 0;
268/** The list node data structure for the descriptors */
269constexpr uint32_t XDES_FLST_NODE = 8;
270/** contains state information of the extent */
271constexpr uint32_t XDES_STATE = FLST_NODE_SIZE + 8;
272/** Descriptor bitmap of the pages in the extent */
273constexpr uint32_t XDES_BITMAP = FLST_NODE_SIZE + 12;
274
275/*-------------------------------------*/
276
277/** How many bits are there per page */
278constexpr uint32_t XDES_BITS_PER_PAGE = 2;
279/** Index of the bit which tells if the page is free */
280constexpr uint32_t XDES_FREE_BIT = 0;
281/** NOTE: currently not used! Index of the bit which tells if there are old
282versions of tuples on the page */
283constexpr uint32_t XDES_CLEAN_BIT = 1;
284
285/** States of a descriptor */
287
288 /** extent descriptor is not initialized */
290
291 /** extent is in free list of space */
293
294 /** extent is in free fragment list of space */
296
297 /** extent is in full fragment list of space */
299
300 /** extent belongs to a segment */
302
303 /** fragment extent leased to segment */
306
307/** File extent data structure size in bytes. */
308#define XDES_SIZE \
309 (XDES_BITMAP + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE * XDES_BITS_PER_PAGE))
310
311/** File extent data structure size in bytes for MAX page size. */
312#define XDES_SIZE_MAX \
313 (XDES_BITMAP + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE_MAX * XDES_BITS_PER_PAGE))
314
315/** File extent data structure size in bytes for MIN page size. */
316#define XDES_SIZE_MIN \
317 (XDES_BITMAP + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE_MIN * XDES_BITS_PER_PAGE))
318
319/** Offset of the descriptor array on a descriptor page */
321
322/** The number of reserved pages in a fragment extent. */
324
325/** @} */
326
327/** Initializes the file space system. */
328void fsp_init(void);
329
330/** Gets the size of the system tablespace from the tablespace header. If
331 we do not have an auto-extending data file, this should be equal to
332 the size of the data files. If there is an auto-extending data file,
333 this can be smaller.
334 @return size in pages */
336
337/** Calculate the number of pages to extend a datafile.
338We extend single-table and general tablespaces first one extent at a time,
339but 4 at a time for bigger tablespaces. It is not enough to extend always
340by one extent, because we need to add at least one extent to FSP_FREE.
341A single extent descriptor page will track many extents. And the extent
342that uses its extent descriptor page is put onto the FSP_FREE_FRAG list.
343Extents that do not use their extent descriptor page are added to FSP_FREE.
344The physical page size is used to determine how many extents are tracked
345on one extent descriptor page. See xdes_calc_descriptor_page().
346@param[in] page_size page_size of the datafile
347@param[in] size current number of pages in the datafile
348@return number of pages to extend the file. */
350 page_no_t size);
351
352/** Calculate the number of physical pages in an extent for this file.
353@param[in] page_size page_size of the datafile
354@return number of pages in an extent for this file. */
356 const page_size_t &page_size) {
357 return (static_cast<page_no_t>(FSP_EXTENT_SIZE * UNIV_PAGE_SIZE /
358 page_size.physical()));
359}
360
361/** Reads the space id from the first page of a tablespace.
362 @return space id, ULINT UNDEFINED if error */
364 const page_t *page); /*!< in: first page of a tablespace */
365
366/** Read the server version number from the DD tablespace header.
367@param[out] version server version from tablespace header
368@return false if success. */
370
371/** Read a tablespace header field.
372@param[in] page first page of a tablespace
373@param[in] field the header field
374@return the contents of the header field */
375inline uint32_t fsp_header_get_field(const page_t *page, uint32_t field) {
376 return (mach_read_from_4(FSP_HEADER_OFFSET + field + page));
377}
378
379/** Update a tablespace header field.
380@param[in] page first page of a tablespace
381@param[in] field the header field
382@param[in] val field value */
383inline void fsp_header_set_field(page_t *page, uint32_t field, uint32_t val) {
384 mach_write_to_4(page + FSP_HEADER_OFFSET + field, val);
385}
386
387/** Read the flags from the tablespace header page.
388@param[in] page first page of a tablespace
389@return the contents of FSP_SPACE_FLAGS */
390inline uint32_t fsp_header_get_flags(const page_t *page) {
392}
393
394/** Reads the page size from the first page of a tablespace.
395@param[in] page first page of a tablespace
396@return page size */
398
399/** Reads the encryption key from the first page of a tablespace.
400@param[in] fsp_flags tablespace flags
401@param[in,out] e_key tablespace key, iv
402@param[in] page first page of a tablespace
403@return true if success */
404bool fsp_header_get_encryption_key(uint32_t fsp_flags, Encryption_key &e_key,
405 page_t *page);
406
407/** Get encryption operation type in progress from the first
408page of a tablespace.
409@param[in] page first page of a tablespace
410@param[in] page_size tablespace page size
411@return operation type
412*/
414 const page_t *page, page_size_t page_size);
415
416/** Check if the tablespace size information is valid.
417@param[in] space_id the tablespace identifier
418@return true if valid, false if invalid. */
420
421/** Writes the space id and flags to a tablespace header. The flags contain
422 row type, physical/compressed page size, and logical/uncompressed page
423 size of the tablespace. */
425 page_t *page, /*!< in/out: first page in the space */
426 space_id_t space_id, /*!< in: space id */
427 uint32_t flags); /*!< in: tablespace flags
428 (FSP_SPACE_FLAGS): 0, or
429 table->flags if newer than COMPACT */
430
431/** Get the offset of encryption information in page 0.
432@param[in] page_size page size.
433@return offset on success, otherwise 0. */
435
436/** Write the encryption info into the space header.
437@param[in] space_id Tablespace id
438@param[in] space_flags Tablespace flags
439@param[in] encrypt_info Buffer for re-encrypt key
440@param[in] update_fsp_flags If it need to update the space flags
441@param[in] rotate_encryption If it is called during key rotation
442@param[in,out] mtr Mini-transaction
443@return true if success. */
444bool fsp_header_write_encryption(space_id_t space_id, uint32_t space_flags,
445 byte *encrypt_info, bool update_fsp_flags,
446 bool rotate_encryption, mtr_t *mtr);
447
448/** Write the encryption progress info into the space header.
449@param[in] space_id Tablespace id
450@param[in] space_flags Tablespace flags
451@param[in] progress_info Max pages (un)encrypted
452@param[in] operation_type Type of operation
453@param[in] update_operation_type Is operation to be updated
454@param[in,out] mtr Mini-transaction
455@return true if success. */
457 space_id_t space_id, ulint space_flags, ulint progress_info,
458 byte operation_type, bool update_operation_type, mtr_t *mtr);
459
460/** Rotate the encryption info in the space header.
461@param[in] space Tablespace
462@param[in] encrypt_info Buffer for re-encrypt key.
463@param[in,out] mtr Mini-transaction
464@return true if success. */
465bool fsp_header_rotate_encryption(fil_space_t *space, byte *encrypt_info,
466 mtr_t *mtr);
467
468/** Initializes the space header of a new created space and creates also the
469insert buffer tree root if space == 0.
470@param[in] space_id Space id
471@param[in] size Current size in blocks
472@param[in,out] mtr Mini-transaction
473@return true on success, otherwise false. */
474bool fsp_header_init(space_id_t space_id, page_no_t size, mtr_t *mtr);
475
476/** Increases the space size field of a space.
477@param[in] space_id Space id
478@param[in] size_inc Size increment in pages
479@param[in,out] mtr Mini-transaction */
480void fsp_header_inc_size(space_id_t space_id, page_no_t size_inc, mtr_t *mtr);
481
482/** Creates a new segment.
483 @return the block where the segment header is placed, x-latched, NULL
484 if could not create segment because of lack of space */
486 space_id_t space, /*!< in: space id */
487 page_no_t page, /*!< in: page where the segment header is
488 placed: if this is != 0, the page must belong
489 to another segment, if this is 0, a new page
490 will be allocated and it will belong to the
491 created segment */
492 ulint byte_offset, /*!< in: byte offset of the created
493 segment header on the page */
494 mtr_t *mtr); /*!< in/out: mini-transaction */
495
496/** Creates a new segment.
497@param[in] space_id Space id
498@param[in,out] page Page where the segment header is placed: if this is != 0,
499the page must belong to another segment, if this is 0, a new page will be
500allocated and it will belong to the created segment
501@param[in] byte_offset Byte offset of the created segment header on the page
502@param[in,out] has_done_reservation True if the caller has already done the
503reservation for the pages with fsp_reserve_free_extents (at least 2 extents: one
504for the inode and the other for the segment) then there is no need to do the
505check for this individual operation
506@param[in,out] mtr Mini-transaction
507@return the block where the segment header is placed, x-latched, NULL
508if could not create segment because of lack of space */
510 ulint byte_offset, bool has_done_reservation,
511 mtr_t *mtr);
512
513/** Calculates the number of pages reserved by a segment, and how many pages are
514 currently used.
515 @return number of reserved pages */
517 fseg_header_t *header, /*!< in: segment header */
518 ulint *used, /*!< out: number of pages used (<= reserved) */
519 mtr_t *mtr); /*!< in/out: mini-transaction */
520
521/** Allocates a single free page from a segment. This function implements
522 the intelligent allocation strategy which tries to minimize file space
523 fragmentation.
524@param[in,out] seg_header Segment header
525@param[in] hint Hint of which page would be desirable
526@param[in,out] direction If the new page is needed because of an index page
527split, and records are inserted there in order, into which direction they go
528alphabetically: fsp_down, fsp_up, fsp_no_dir
529@param[in] has_done_reservation True if the caller has already done the
530reservation for the page with fsp_reserve_free_extents, then there is no need to
531do the check for this individual page
532@param[in,out] mtr Mini-transaction
533@param[in,out] init_mtr mtr or another mini-transaction in which
534the page should be initialized. if init_mtr!=mtr, but the page is already
535latched in mtr, do not initialize the page.
536@retval NULL if no page could be allocated
537@retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded
538(init_mtr == mtr, or the page was not previously freed in mtr),
539returned block is not allocated nor initialized otherwise */
541 fseg_header_t *seg_header, page_no_t hint, byte direction,
542 bool has_done_reservation, mtr_t *mtr, mtr_t *init_mtr);
543
544/** Allocates a single free page from a segment. This function implements
545 the intelligent allocation strategy which tries to minimize
546 file space fragmentation.
547 @param[in,out] seg_header Segment header
548 @param[in] hint Hint of which page would be desirable
549 @param[in] direction If the new page is needed because
550 of an index page split, and records are
551 inserted there in order, into which
552 direction they go alphabetically: FSP_DOWN,
553 FSP_UP, FSP_NO_DIR
554 @param[in,out] mtr Mini-transaction
555 @return X-latched block, or NULL if no page could be allocated */
557 page_no_t hint, byte direction,
558 mtr_t *mtr) {
559 return fseg_alloc_free_page_general(seg_header, hint, direction, false, mtr,
560 mtr);
561}
562
563/** Reserves free pages from a tablespace. All mini-transactions which may
564use several pages from the tablespace should call this function beforehand
565and reserve enough free extents so that they certainly will be able
566to do their operation, like a B-tree page split, fully. Reservations
567must be released with function fil_space_release_free_extents!
568
569The alloc_type below has the following meaning: FSP_NORMAL means an
570operation which will probably result in more space usage, like an
571insert in a B-tree; FSP_UNDO means allocation to undo logs: if we are
572deleting rows, then this allocation will in the long run result in
573less space usage (after a purge); FSP_CLEANING means allocation done
574in a physical record delete (like in a purge) or other cleaning operation
575which will result in less space usage in the long run. We prefer the latter
576two types of allocation: when space is scarce, FSP_NORMAL allocations
577will not succeed, but the latter two allocations will succeed, if possible.
578The purpose is to avoid dead end where the database is full but the
579user cannot free any space because these freeing operations temporarily
580reserve some space.
581
582Single-table tablespaces whose size is < FSP_EXTENT_SIZE pages are a special
583case. In this function we would liberally reserve several extents for
584every page split or merge in a B-tree. But we do not want to waste disk space
585if the table only occupies < FSP_EXTENT_SIZE pages. That is why we apply
586different rules in that special case, just ensuring that there are n_pages
587free pages available.
588
589@param[out] n_reserved Number of extents actually reserved; if we
590 return true and the tablespace size is <
591 FSP_EXTENT_SIZE pages, then this can be 0,
592 otherwise it is n_ext
593@param[in] space_id Tablespace identifier
594@param[in] n_ext Number of extents to reserve
595@param[in] alloc_type Page reservation type (FSP_BLOB, etc)
596@param[in,out] mtr Mini-transaction
597@param[in] n_pages For small tablespaces (tablespace size is
598 less than FSP_EXTENT_SIZE), number of free
599 pages to reserve.
600@return true if we were able to make the reservation */
601bool fsp_reserve_free_extents(ulint *n_reserved, space_id_t space_id,
602 ulint n_ext, fsp_reserve_t alloc_type, mtr_t *mtr,
603 page_no_t n_pages = 2);
604
605/** Calculate how many KiB of new data we will be able to insert to the
606tablespace without running out of space.
607@param[in] space_id tablespace ID
608@return available space in KiB
609@retval UINTMAX_MAX if unknown */
611
612/** Calculate how many KiB of new data we will be able to insert to the
613tablespace without running out of space. Start with a space object that has
614been acquired by the caller who holds it for the calculation,
615@param[in] space tablespace object from fil_space_acquire()
616@return available space in KiB */
618
619/** Frees a single page of a segment.
620@param[in] seg_header Segment header
621@param[in] space_id Space id
622@param[in] page Page offset
623@param[in] ahi Whether we may need to drop the adaptive hash index
624@param[in,out] mtr Mini-transaction */
625void fseg_free_page(fseg_header_t *seg_header, space_id_t space_id,
626 page_no_t page, bool ahi, mtr_t *mtr);
627
628/** Checks if a single page of a segment is free.
629 @return true if free */
630[[nodiscard]] bool fseg_page_is_free(
631 fseg_header_t *seg_header, /*!< in: segment header */
632 space_id_t space_id, /*!< in: space id */
633 page_no_t page); /*!< in: page offset */
634/** Frees part of a segment. This function can be used to free a segment
635 by repeatedly calling this function in different mini-transactions.
636 Doing the freeing in a single mini-transaction might result in
637 too big a mini-transaction.
638 @return true if freeing completed */
639[[nodiscard]] bool fseg_free_step(
640 fseg_header_t *header, /*!< in, own: segment header; NOTE: if the header
641 resides on the first page of the frag list
642 of the segment, this pointer becomes obsolete
643 after the last freeing step */
644 bool ahi, /*!< in: whether we may need to drop
645 the adaptive hash index */
646 mtr_t *mtr); /*!< in/out: mini-transaction */
647/** Frees part of a segment. Differs from fseg_free_step because this function
648 leaves the header page unfreed.
649 @return true if freeing completed, except the header page */
650[[nodiscard]] bool fseg_free_step_not_header(
651 fseg_header_t *header, /*!< in: segment header which must reside on
652 the first fragment page of the segment */
653 bool ahi, /*!< in: whether we may need to drop
654 the adaptive hash index */
655 mtr_t *mtr); /*!< in/out: mini-transaction */
656
657/** Checks if a page address is an extent descriptor page address.
658@param[in] page_id page id
659@param[in] page_size page size
660@return true if a descriptor page */
661static inline bool fsp_descr_page(const page_id_t &page_id,
662 const page_size_t &page_size);
663
664/** Parses a redo log record of a file page init.
665@param[in] ptr Buffer.
666@param[in] end_ptr Buffer end.
667@param[in] block Block or nullptr.
668@return end of log record or nullptr */
669byte *fsp_parse_init_file_page(byte *ptr, byte *end_ptr, buf_block_t *block);
670
671#ifdef UNIV_BTR_PRINT
672/** Writes info of a segment. */
673void fseg_print(fseg_header_t *header, /*!< in: segment header */
674 mtr_t *mtr); /*!< in/out: mini-transaction */
675#endif /* UNIV_BTR_PRINT */
676
677/** Check whether a space id is an undo tablespace ID
678Undo tablespaces have space_id's starting 1 less than the redo logs.
679They are numbered down from this. Since rseg_id=0 always refers to the
680system tablespace, undo_space_num values start at 1. The current limit
681is 127. The translation from an undo_space_num is:
682 undo space_id = log_first_space_id - undo_space_num
683@param[in] space_id space id to check
684@return true if it is undo tablespace else false. */
686
687static inline bool fsp_is_system_tablespace(space_id_t space_id) {
688 return (space_id == TRX_SYS_SPACE);
689}
690
691/** Check if the space_id is for a system-tablespace (shared + temp).
692@param[in] space_id tablespace ID
693@return true if id is a system tablespace, false if not. */
694static inline bool fsp_is_system_or_temp_tablespace(space_id_t space_id) {
695 return (fsp_is_system_tablespace(space_id) ||
696 fsp_is_system_temporary(space_id));
697}
698
699/** Determine if the space ID is an IBD tablespace, either file_per_table
700or a general shared tablespace, where user tables exist.
701@param[in] space_id tablespace ID
702@return true if it is a user tablespace ID */
703static inline bool fsp_is_ibd_tablespace(space_id_t space_id) {
704 return (space_id != TRX_SYS_SPACE && !fsp_is_undo_tablespace(space_id) &&
705 !fsp_is_system_temporary(space_id));
706}
707
708/** Check if tablespace is file-per-table.
709@param[in] space_id tablespace ID
710@param[in] fsp_flags tablespace flags
711@return true if tablespace is file-per-table. */
712static inline bool fsp_is_file_per_table(space_id_t space_id,
713 uint32_t fsp_flags) {
714 return (!fsp_is_shared_tablespace(fsp_flags) &&
715 fsp_is_ibd_tablespace(space_id));
716}
717
718/** Check if tablespace is dd tablespace.
719@param[in] space_id tablespace ID
720@return true if tablespace is dd tablespace. */
721bool fsp_is_dd_tablespace(space_id_t space_id);
722
723/** Determine if the tablespace is compressed from tablespace flags.
724@param[in] flags Tablespace flags
725@return true if compressed, false if not compressed */
726static inline bool fsp_flags_is_compressed(uint32_t flags);
727
728/** Determine if two tablespaces are equivalent or compatible.
729@param[in] flags1 First tablespace flags
730@param[in] flags2 Second tablespace flags
731@return true the flags are compatible, false if not */
732static inline bool fsp_flags_are_equal(uint32_t flags1, uint32_t flags2);
733
734/** Initialize an FSP flags integer.
735@param[in] page_size page sizes in bytes and compression flag.
736@param[in] atomic_blobs Used by Dynamic and Compressed.
737@param[in] has_data_dir This tablespace is in a remote location.
738@param[in] is_shared This tablespace can be shared by many tables.
739@param[in] is_temporary This tablespace is temporary.
740@param[in] is_encrypted This tablespace is encrypted.
741@return tablespace flags after initialization */
742static inline uint32_t fsp_flags_init(const page_size_t &page_size,
743 bool atomic_blobs, bool has_data_dir,
744 bool is_shared, bool is_temporary,
745 bool is_encrypted = false);
746
747/** Convert a 32 bit integer tablespace flags to the 32 bit table flags.
748This can only be done for a tablespace that was built as a file-per-table
749tablespace. Note that the fsp_flags cannot show the difference between a
750Compact and Redundant table, so an extra Compact boolean must be supplied.
751 Low order bit
752 | REDUNDANT | COMPACT | COMPRESSED | DYNAMIC
753fil_space_t::flags | 0 | 0 | 1 | 1
754dict_table_t::flags | 0 | 1 | 1 | 1
755@param[in] fsp_flags fil_space_t::flags
756@param[in] compact true if not Redundant row format
757@return tablespace flags (fil_space_t::flags) */
758uint32_t fsp_flags_to_dict_tf(uint32_t fsp_flags, bool compact);
759
760/** Calculates the descriptor index within a descriptor page.
761@param[in] page_size page size
762@param[in] offset page offset
763@return descriptor index */
764static inline ulint xdes_calc_descriptor_index(const page_size_t &page_size,
765 ulint offset);
766
767/** Mark all the pages of the extent as used.
768@param[in] descr extent descriptor
769@param[in] mtr mini transaction context. */
770void xdes_mark_all_used(xdes_t *descr, mtr_t *mtr);
771
772/** Mark all the pages of the extent from given page_no as free.
773@param[in] descr extent descriptor
774@param[in] mtr mini transaction context.
775@param[in] from all pages from this page_no is marked as free. */
776void xdes_mark_pages_free(xdes_t *descr, mtr_t *mtr, const page_no_t from);
777
778/** Gets a descriptor bit of a page.
779@param[in] descr descriptor
780@param[in] bit XDES_FREE_BIT or XDES_CLEAN_BIT
781@param[in] offset page offset within extent: 0 ... FSP_EXTENT_SIZE - 1
782@return true if free */
783static inline bool xdes_get_bit(const xdes_t *descr, ulint bit,
784 page_no_t offset);
785
786/** Calculates the page where the descriptor of a page resides.
787@param[in] page_size page size
788@param[in] offset page offset
789@return descriptor page offset */
790static inline page_no_t xdes_calc_descriptor_page(const page_size_t &page_size,
791 page_no_t offset);
792
793/** Gets a pointer to the space header and acquires a
794SX lock on the page.
795@param[in] id Space id
796@param[in] page_size Page size
797@param[in,out] mtr Mini-transaction
798@param[out] block Block
799@return pointer to the space header, page x-locked */
801 const page_size_t &page_size,
802 mtr_t *mtr, buf_block_t **block);
803
804/** Gets a pointer to the space header and acquires a
805SX lock on the page.
806@param[in] id Space id
807@param[in] page_size Page size
808@param[in,out] mtr Mini-transaction
809@return pointer to the space header, page x-locked */
811 mtr_t *mtr);
812
813/** Retrieve tablespace dictionary index root page number stored in the
814page 0
815@param[in] space Tablespace id
816@param[in] page_size Page size
817@param[in,out] mtr Mini-transaction
818@return root page num of the tablespace dictionary index copy */
820 const page_size_t &page_size, mtr_t *mtr);
821
822/** Write SDI Index root page num to page 0 of tablespace.
823@param[in,out] page Page 0 frame
824@param[in] page_size Size of page
825@param[in] root_page_num Root page number of SDI
826@param[in,out] mtr Mini-transaction */
827void fsp_sdi_write_root_to_page(page_t *page, const page_size_t &page_size,
828 page_no_t root_page_num, mtr_t *mtr);
829
830#include "fsp0fsp.ic"
831
832/** Reads the server version from the first page of a tablespace.
833@param[in] page first page of a tablespace
834@return space server version */
836
837/** Reads the server space version from the first page of a tablespace.
838@param[in] page first page of a tablespace
839@return space server version */
841
842/** Get the state of an xdes.
843@param[in] descr extent descriptor
844@param[in,out] mtr Mini-transaction.
845@return state */
846inline xdes_state_t xdes_get_state(const xdes_t *descr, mtr_t *mtr) {
847 ut_ad(descr && mtr);
849
850 const ulint state = mach_read_from_4(descr + XDES_STATE);
851
853 return (static_cast<xdes_state_t>(state));
854}
855
856#ifdef UNIV_DEBUG
857/** Print the extent descriptor page in user-friendly format.
858@param[in] out The output file stream
859@param[in] xdes The extent descriptor page
860@param[in] page_no The page number of xdes page
861@param[in] mtr Mini-transaction.
862@return None. */
863std::ostream &xdes_page_print(std::ostream &out, const page_t *xdes,
864 page_no_t page_no, mtr_t *mtr);
865
866inline bool xdes_mem_t::is_valid() const {
867 const ulint state = mach_read_from_4(m_xdes + XDES_STATE);
868 return (xdes_state_is_valid(state));
869}
870
871inline const char *xdes_mem_t::state_name() const {
873
875
876 xdes_state_t state = static_cast<xdes_state_t>(val);
877
878 switch (state) {
879 case XDES_NOT_INITED:
880 return ("XDES_NOT_INITED");
881 case XDES_FREE:
882 return ("XDES_FREE");
883 case XDES_FREE_FRAG:
884 return ("XDES_FREE_FRAG");
885 case XDES_FULL_FRAG:
886 return ("XDES_FULL_FRAG");
887 case XDES_FSEG:
888 return ("XDES_FSEG");
889 case XDES_FSEG_FRAG:
890 return ("XDES_FSEG_FRAG");
891 }
892 return ("UNKNOWN");
893}
894
895#endif /* UNIV_DEBUG */
896
897/** Update the tablespace size information and generate redo log for it.
898@param[in] header Tablespace header.
899@param[in] size New tablespace size in pages.
900@param[in] mtr Mini-transaction context. */
901inline void fsp_header_size_update(fsp_header_t *header, ulint size,
902 mtr_t *mtr) {
904
905 DBUG_LOG("ib_log", "old_size=" << mach_read_from_4(header + FSP_SIZE)
906 << ", new_size=" << size);
907
908 mlog_write_ulint(header + FSP_SIZE, size, MLOG_4BYTES, mtr);
909}
910
911/** Check if a specified page is inode page or not. This is used for
912index root pages of hard-coded DD tables, we can safely assume that the passed
913in page number is in the range of pages which are only either index root page
914or inode page
915@param[in] page Page number to check
916@return true if it's inode page, otherwise false */
917inline bool fsp_is_inode_page(page_no_t page);
918
919/** Get the offset of SDI root page number in page 0.
920@param[in] page_size Page size.
921@return offset on success, else 0 */
922inline ulint fsp_header_get_sdi_offset(const page_size_t &page_size);
923
924/** Get the offset of encryption progress information in page 0.
925@param[in] page_size page size.
926@return offset on success, otherwise 0. */
928 const page_size_t &page_size);
929
930/** Determine if the tablespace has SDI.
931@param[in] space_id Tablespace id
932@return DB_SUCCESS if SDI is present else DB_ERROR
933or DB_TABLESPACE_NOT_FOUND */
935
936/** Encrypt/Unencrypt a tablespace.
937@param[in] thd current thread
938@param[in] space_id Tablespace id
939@param[in] to_encrypt true if to encrypt, false if to decrypt
940@param[in,out] dd_space_in dd tablespace object
941@return 0 for success, otherwise error code */
943 bool to_encrypt, void *dd_space_in);
944
945/** Initiate roll-forward of alter encrypt in background thread */
947
948/** A wrapper class to operate on a file segment inode pointer (fseg_inode_t*)
949 */
951 public:
952 /** Constructor
953 @param[in] space_id Table space identifier
954 @param[in] page_size Size of each page in the tablespace.
955 @param[in] inode File segment inode pointer
956 @param[in] mtr Mini-transaction context. */
957 File_segment_inode(space_id_t space_id, const page_size_t &page_size,
958 fseg_inode_t *inode, mtr_t *mtr)
959 : m_space_id(space_id),
960 m_page_size(page_size),
961 m_fseg_inode(inode),
962 m_mtr(mtr) IF_DEBUG(, m_random_engine(m_rd()), m_dist(1, 100)) {}
963
964 /** Update the value of FSEG_NOT_FULL_N_USED.
965 @param[in] n_used the new value of FSEG_NOT_FULL_N_USED. */
966 void write_not_full_n_used(uint32_t n_used);
967
968 /** Get the current value of FSEG_NOT_FULL_N_USED.
969 @return the current value of FSEG_NOT_FULL_N_USED. */
970 uint32_t read_not_full_n_used() const;
971
972 /** Get the segment identifier value.
973 @return the segment identifier value. */
974 uint64_t get_seg_id() const {
976 }
977
978 /** Print the current object into the given output stream.
979 @return the output stream. */
980 std::ostream &print(std::ostream &out) const;
981
982 private:
983 /** Unique tablespace identifier */
985
986 /** The page size used in this tablespace. */
988
989 /** file segment inode pointer that is being wrapped by this object. */
991
992 /** The mini-transaction operation context. */
994
995#ifdef UNIV_DEBUG
996 public:
997 /** Verify the stored FSEG_NOT_FULL_N_USED value.
998 @return true if correct value, false if incorrect. */
1000
1001 private:
1002 /** Calculate the value of FSEG_NOT_FULL_N_USED by traversing
1003 the FSEG_NOT_FULL list.
1004 @return the calculated value of FSEG_NOT_FULL_N_USED. */
1006
1007 std::random_device m_rd;
1008 std::default_random_engine m_random_engine;
1009 std::uniform_int_distribution<int> m_dist;
1010
1011 /** To reduce the cost of verification of FSEG_NOT_FULL_N_USED, do it
1012 only when this function returns true.
1013 @return true for 10% of the time. */
1014 bool do_verify() { return (m_dist(m_random_engine) > 90); }
1015#endif /* UNIV_DEBUG */
1016};
1017
1018/** The global output stream operator is overloaded to work with an object
1019 of type File_segment_inode.
1020@param[in] out the output stream.
1021@param[in] obj an object of type File_segment_inode.
1022@return the output stream. */
1023inline std::ostream &operator<<(std::ostream &out,
1024 const File_segment_inode &obj) {
1025 return (obj.print(out));
1026}
1027
1028/** Returns the file segment inode, page x-latched.
1029@param[in] header Segment header
1030@param[in] space Space id
1031@param[in] page_size Page size
1032@param[in,out] mtr Mini-transaction
1033@param[out] block Inode block
1034@return segment inode, page x-latched */
1036 const page_size_t &page_size, mtr_t *mtr,
1037 buf_block_t **block = nullptr);
1038
1040 Page_alloc_info(space_id_t space_id, const page_size_t &page_size,
1041 fseg_header_t *fseg_hdr)
1042 : m_space_id(space_id), m_page_size(page_size), m_fseg_header(fseg_hdr) {}
1043
1044 /** Tablespace ID. */
1046
1047 /** Page size. */
1049
1050 /** File segment header. */
1052};
1053
1054using Page_range_t = std::pair<page_no_t, page_no_t>;
1055
1056/** Allocate pages in bulk. */
1058 Page_range_t &page_range);
1059
1061
1062/** Allocate a page number.
1063@param[in] space tablespace object
1064@param[in] page_size page size in the given tablespace.
1065@param[in] seg_inode file segment inode where page number is to be allocated.
1066@param[in] hint hint of which page would be desirable.
1067@param[in] direction If the new page is needed because of an index page split,
1068 and records are inserted there in order, into which direction
1069 they go alphabetically: FSP_DOWN, FSP_UP, FSP_NO_DIR
1070@param[in] mtr mini-transaction context.
1071@param[in,out] has_done_reservation true if caller has done reservation.
1072@return the allocated page number. */
1073page_no_t fseg_alloc_page_no(fil_space_t *space, const page_size_t &page_size,
1074 fseg_inode_t *seg_inode, page_no_t hint,
1075 byte direction,
1076 mtr_t *mtr IF_DEBUG(, bool has_done_reservation));
1077
1078/** Extend space by default extension size.
1079@param[in] space_id space ID
1080@param[in] make_old add the header to LRU tail to flush at the earliest.
1081@param[out] space_size size after extending the space
1082@return true iff successful. */
1083bool fsp_extend_by_default_size(space_id_t space_id, bool make_old,
1084 size_t &space_size);
1085
1086#endif
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:46
uint32_t page_no_t
Page number.
Definition: api0api.h:44
std::pair< page_no_t, page_no_t > Page_range_t
Definition: btr0btr.h:130
The database buffer pool high-level routines.
DDL log record.
Definition: log0ddl.h:77
Progress
Encryption progress type.
Definition: os0enc.h:79
A wrapper class to operate on a file segment inode pointer (fseg_inode_t*)
Definition: fsp0fsp.h:950
const page_size_t & m_page_size
The page size used in this tablespace.
Definition: fsp0fsp.h:987
space_id_t m_space_id
Unique tablespace identifier.
Definition: fsp0fsp.h:984
page_no_t calculate_not_full_n_used()
Calculate the value of FSEG_NOT_FULL_N_USED by traversing the FSEG_NOT_FULL list.
Definition: fsp0fsp.cc:4996
mtr_t * m_mtr
The mini-transaction operation context.
Definition: fsp0fsp.h:993
fseg_inode_t * m_fseg_inode
file segment inode pointer that is being wrapped by this object.
Definition: fsp0fsp.h:990
std::random_device m_rd
Definition: fsp0fsp.h:1007
std::default_random_engine m_random_engine
Definition: fsp0fsp.h:1008
std::ostream & print(std::ostream &out) const
Print the current object into the given output stream.
Definition: fsp0fsp.cc:5017
bool verify_not_full_n_used()
Verify the stored FSEG_NOT_FULL_N_USED value.
Definition: fsp0fsp.cc:4986
void write_not_full_n_used(uint32_t n_used)
Update the value of FSEG_NOT_FULL_N_USED.
Definition: fsp0fsp.cc:4955
uint64_t get_seg_id() const
Get the segment identifier value.
Definition: fsp0fsp.h:974
bool do_verify()
To reduce the cost of verification of FSEG_NOT_FULL_N_USED, do it only when this function returns tru...
Definition: fsp0fsp.h:1014
std::uniform_int_distribution< int > m_dist
Definition: fsp0fsp.h:1009
uint32_t read_not_full_n_used() const
Get the current value of FSEG_NOT_FULL_N_USED.
Definition: fsp0fsp.cc:5011
File_segment_inode(space_id_t space_id, const page_size_t &page_size, fseg_inode_t *inode, mtr_t *mtr)
Constructor.
Definition: fsp0fsp.h:957
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
Page identifier.
Definition: buf0types.h:206
Page size descriptor.
Definition: page0size.h:49
size_t physical() const
Retrieve the physical page size (on-disk).
Definition: page0size.h:120
int page
Definition: ctype-mb.cc:1233
dberr_t
Definition: db0err.h:38
#define is_shared(S, V)
Definition: dbug.cc:204
constexpr uint32_t FIL_PAGE_DATA
start of the data on the page
Definition: fil0types.h:110
bool fsp_is_system_temporary(space_id_t space_id)
Check if tablespace is system temporary.
Definition: fsp0fsp.cc:304
xdes_state_t xdes_get_state(const xdes_t *descr, mtr_t *mtr)
Get the state of an xdes.
Definition: fsp0fsp.h:846
static bool fsp_flags_are_equal(uint32_t flags1, uint32_t flags2)
Determine if two tablespaces are equivalent or compatible.
std::ostream & xdes_page_print(std::ostream &out, const page_t *xdes, page_no_t page_no, mtr_t *mtr)
Print the extent descriptor page in user-friendly format.
Definition: fsp0fsp.cc:4021
static page_no_t fsp_get_extent_size_in_pages(const page_size_t &page_size)
Calculate the number of physical pages in an extent for this file.
Definition: fsp0fsp.h:355
dberr_t fsp_alter_encrypt_tablespace(THD *thd, space_id_t space_id, bool to_encrypt, void *dd_space_in)
Encrypt/Unencrypt a tablespace.
Definition: fsp0fsp.cc:4681
static buf_block_t * fseg_alloc_free_page(fseg_header_t *seg_header, page_no_t hint, byte direction, mtr_t *mtr)
Allocates a single free page from a segment.
Definition: fsp0fsp.h:556
void fsp_sdi_write_root_to_page(page_t *page, const page_size_t &page_size, page_no_t root_page_num, mtr_t *mtr)
Write SDI Index root page num to page 0 of tablespace.
Definition: fsp0fsp.cc:3943
static bool fsp_is_file_per_table(space_id_t space_id, uint32_t fsp_flags)
Check if tablespace is file-per-table.
Definition: fsp0fsp.h:712
dberr_t fseg_alloc_pages_of_extent(const Page_alloc_info &info, mtr_t *mtr, Page_range_t &page_range)
Allocate pages in bulk.
Definition: fsp0fsp.cc:5024
void fsp_header_set_field(page_t *page, uint32_t field, uint32_t val)
Update a tablespace header field.
Definition: fsp0fsp.h:383
bool fsp_extend_by_default_size(space_id_t space_id, bool make_old, size_t &space_size)
Extend space by default extension size.
Definition: fsp0fsp.cc:3260
bool fsp_reserve_free_extents(ulint *n_reserved, space_id_t space_id, ulint n_ext, fsp_reserve_t alloc_type, mtr_t *mtr, page_no_t n_pages=2)
Reserves free pages from a tablespace.
Definition: fsp0fsp.cc:3128
ulint fsp_header_get_encryption_progress_offset(const page_size_t &page_size)
Get the offset of encryption progress information in page 0.
Definition: fsp0fsp.ic:395
uint32_t fsp_flags_to_dict_tf(uint32_t fsp_flags, bool compact)
Convert a 32 bit integer tablespace flags to the 32 bit table flags.
Definition: fsp0fsp.cc:236
static ulint xdes_calc_descriptor_index(const page_size_t &page_size, ulint offset)
Calculates the descriptor index within a descriptor page.
static bool fsp_is_system_or_temp_tablespace(space_id_t space_id)
Check if the space_id is for a system-tablespace (shared + temp).
Definition: fsp0fsp.h:694
bool fsp_check_tablespace_size(space_id_t space_id)
Check if the tablespace size information is valid.
Definition: fsp0fsp.cc:4064
buf_block_t * fseg_alloc_free_page_general(fseg_header_t *seg_header, page_no_t hint, byte direction, bool has_done_reservation, mtr_t *mtr, mtr_t *init_mtr)
Allocates a single free page from a segment.
Definition: fsp0fsp.cc:3003
bool fsp_header_dict_get_server_version(uint *version)
Read the server version number from the DD tablespace header.
Definition: fsp0fsp.cc:987
bool fsp_header_write_encryption_progress(space_id_t space_id, ulint space_flags, ulint progress_info, byte operation_type, bool update_operation_type, mtr_t *mtr)
Write the encryption progress info into the space header.
bool fseg_free_step_not_header(fseg_header_t *header, bool ahi, mtr_t *mtr)
Frees part of a segment.
Definition: fsp0fsp.cc:3744
void fsp_init_file_page_low(buf_block_t *block)
Inits a file page whose prior contents should be ignored.
Definition: fsp0fsp.cc:693
fsp_header_t * fsp_get_space_header_block(space_id_t id, const page_size_t &page_size, mtr_t *mtr, buf_block_t **block)
Gets a pointer to the space header and acquires a SX lock on the page.
Definition: fsp0fsp.cc:195
byte * fsp_parse_init_file_page(byte *ptr, byte *end_ptr, buf_block_t *block)
Parses a redo log record of a file page init.
Definition: fsp0fsp.cc:779
uint32_t fsp_header_get_space_version(const page_t *page)
Reads the server space version from the first page of a tablespace.
buf_block_t * fseg_create(space_id_t space, page_no_t page, ulint byte_offset, mtr_t *mtr)
Creates a new segment.
Definition: fsp0fsp.cc:2425
fseg_inode_t * fseg_inode_get(const fseg_header_t *header, space_id_t space, const page_size_t &page_size, mtr_t *mtr, buf_block_t **block=nullptr)
Returns the file segment inode, page x-latched.
Definition: fsp0fsp.cc:2174
void xdes_mark_all_used(xdes_t *descr, mtr_t *mtr)
Mark all the pages of the extent as used.
Definition: fsp0fsp.cc:419
bool fseg_page_is_free(fseg_header_t *seg_header, space_id_t space_id, page_no_t page)
Checks if a single page of a segment is free.
Definition: fsp0fsp.cc:3552
constexpr uint64_t FSP_MAX_AUTOEXTEND_SIZE
Definition: fsp0fsp.h:180
page_no_t fsp_get_pages_to_extend_ibd(const page_size_t &page_size, page_no_t size)
Calculate the number of pages to extend a datafile.
Definition: fsp0fsp.cc:1405
bool fsp_is_inode_page(page_no_t page)
Check if a specified page is inode page or not.
Definition: fsp0fsp.ic:280
uint32_t fsp_header_get_flags(const page_t *page)
Read the flags from the tablespace header page.
Definition: fsp0fsp.h:390
bool fsp_header_init(space_id_t space_id, page_no_t size, mtr_t *mtr)
Initializes the space header of a new created space and creates also the insert buffer tree root if s...
Definition: fsp0fsp.cc:1012
dberr_t fsp_has_sdi(space_id_t space_id)
Determine if the tablespace has SDI.
Definition: fsp0fsp.cc:4094
uint32_t fsp_header_get_field(const page_t *page, uint32_t field)
Read a tablespace header field.
Definition: fsp0fsp.h:375
static bool fsp_descr_page(const page_id_t &page_id, const page_size_t &page_size)
Checks if a page address is an extent descriptor page address.
static bool fsp_flags_is_compressed(uint32_t flags)
Determine if the tablespace is compressed from tablespace flags.
void fsp_init(void)
Initializes the file space system.
Definition: fsp0fsp.cc:789
ulint fsp_header_get_sdi_offset(const page_size_t &page_size)
Get the offset of SDI root page number in page 0.
Definition: fsp0fsp.ic:383
mysql_cond_t resume_encryption_cond
Definition: ha_innodb.cc:295
static uint32_t fsp_flags_init(const page_size_t &page_size, bool atomic_blobs, bool has_data_dir, bool is_shared, bool is_temporary, bool is_encrypted=false)
Initialize an FSP flags integer.
Encryption::Progress fsp_header_encryption_op_type_in_progress(const page_t *page, page_size_t page_size)
Get encryption operation type in progress from the first page of a tablespace.
Definition: fsp0fsp.cc:879
static bool fsp_is_ibd_tablespace(space_id_t space_id)
Determine if the space ID is an IBD tablespace, either file_per_table or a general shared tablespace,...
Definition: fsp0fsp.h:703
uint32_t fsp_header_get_server_version(const page_t *page)
Reads the server version from the first page of a tablespace.
static page_no_t xdes_calc_descriptor_page(const page_size_t &page_size, page_no_t offset)
Calculates the page where the descriptor of a page resides.
void fsp_header_size_update(fsp_header_t *header, ulint size, mtr_t *mtr)
Update the tablespace size information and generate redo log for it.
Definition: fsp0fsp.h:901
void fseg_free_page(fseg_header_t *seg_header, space_id_t space_id, page_no_t page, bool ahi, mtr_t *mtr)
Frees a single page of a segment.
Definition: fsp0fsp.cc:3529
std::vector< DDL_Record * > ts_encrypt_ddl_records
DDL records for tablespace (un)encryption.
Definition: fsp0fsp.cc:81
void xdes_mark_pages_free(xdes_t *descr, mtr_t *mtr, const page_no_t from)
Mark all the pages of the extent from given page_no as free.
Definition: fsp0fsp.cc:428
bool fsp_header_write_encryption(space_id_t space_id, uint32_t space_flags, byte *encrypt_info, bool update_fsp_flags, bool rotate_encryption, mtr_t *mtr)
Write the encryption info into the space header.
Definition: fsp0fsp.cc:910
bool fsp_is_undo_tablespace(space_id_t space_id)
Check whether a space id is an undo tablespace ID Undo tablespaces have space_id's starting 1 less th...
Definition: fsp0fsp.cc:270
bool fseg_free_step(fseg_header_t *header, bool ahi, mtr_t *mtr)
Frees part of a segment.
Definition: fsp0fsp.cc:3659
page_no_t fsp_header_get_tablespace_size(void)
Gets the size of the system tablespace from the tablespace header.
Definition: fsp0fsp.cc:1202
ulint fseg_n_reserved_pages(fseg_header_t *header, ulint *used, mtr_t *mtr)
Calculates the number of pages reserved by a segment, and how many pages are currently used.
Definition: fsp0fsp.cc:2491
space_id_t fsp_header_get_space_id(const page_t *page)
Reads the space id from the first page of a tablespace.
Definition: fsp0fsp.cc:1122
bool fsp_header_rotate_encryption(fil_space_t *space, byte *encrypt_info, mtr_t *mtr)
Rotate the encryption info in the space header.
Definition: fsp0fsp.cc:966
fsp_header_t * fsp_get_space_header(space_id_t id, const page_size_t &page_size, mtr_t *mtr)
Gets a pointer to the space header and acquires a SX lock on the page.
Definition: fsp0fsp.cc:217
page_no_t fsp_sdi_get_root_page_num(space_id_t space, const page_size_t &page_size, mtr_t *mtr)
Retrieve tablespace dictionary index root page number stored in the page 0.
Definition: fsp0fsp.cc:3911
void fsp_header_inc_size(space_id_t space_id, page_no_t size_inc, mtr_t *mtr)
Increases the space size field of a space.
Definition: fsp0fsp.cc:1175
static bool xdes_get_bit(const xdes_t *descr, ulint bit, page_no_t offset)
Gets a descriptor bit of a page.
void fsp_init_resume_alter_encrypt_tablespace()
Initiate roll-forward of alter encrypt in background thread.
Definition: fsp0fsp.cc:4947
page_size_t fsp_header_get_page_size(const page_t *page)
Reads the page size from the first page of a tablespace.
Definition: fsp0fsp.cc:1146
static bool fsp_is_system_tablespace(space_id_t space_id)
Definition: fsp0fsp.h:687
buf_block_t * fseg_create_general(space_id_t space_id, page_no_t page, ulint byte_offset, bool has_done_reservation, mtr_t *mtr)
Creates a new segment.
Definition: fsp0fsp.cc:2285
mysql_mutex_t resume_encryption_cond_m
Definition: ha_innodb.cc:296
void fsp_header_init_fields(page_t *page, space_id_t space_id, uint32_t flags)
Writes the space id and flags to a tablespace header.
Definition: fsp0fsp.cc:806
bool fsp_header_get_encryption_key(uint32_t fsp_flags, Encryption_key &e_key, page_t *page)
Reads the encryption key from the first page of a tablespace.
Definition: fsp0fsp.cc:1155
page_no_t fseg_alloc_page_no(fil_space_t *space, const page_size_t &page_size, fseg_inode_t *seg_inode, page_no_t hint, byte direction, mtr_t *mtr, bool has_done_reservation)
Allocate a page number.
Definition: fsp0fsp.cc:2741
uintmax_t fsp_get_available_space_in_free_extents(space_id_t space_id)
Calculate how many KiB of new data we will be able to insert to the tablespace without running out of...
Definition: fsp0fsp.cc:3289
ulint fsp_header_get_encryption_offset(const page_size_t &page_size)
Get the offset of encryption information in page 0.
Definition: fsp0fsp.cc:818
bool fsp_is_dd_tablespace(space_id_t space_id)
Check if tablespace is dd tablespace.
Definition: fsp0fsp.cc:258
File space management.
General shared tablespace implementation.
#define FSP_EXTENT_SIZE
File space extent size in pages page size | file space extent size -------—+--------------------— 4 K...
Definition: fsp0types.h:63
constexpr uint32_t FSEG_PAGE_DATA
On a page of any file segment, data may be put starting from this offset.
Definition: fsp0types.h:78
fsp_reserve_t
Flags for fsp_reserve_free_extents.
Definition: fsp0types.h:135
byte fseg_header_t
Data type for file segment header.
Definition: fsp0types.h:84
File-based list utilities.
constexpr ulint FLST_BASE_NODE_SIZE
Definition: fut0lst.h:49
constexpr ulint FLST_NODE_SIZE
Definition: fut0lst.h:52
constexpr uint32_t XDES_FLST_NODE
The list node data structure for the descriptors.
Definition: fsp0fsp.h:269
constexpr uint32_t XDES_ID
The identifier of the segment to which this extent belongs.
Definition: fsp0fsp.h:267
constexpr uint32_t XDES_STATE
contains state information of the extent
Definition: fsp0fsp.h:271
constexpr uint32_t XDES_FREE_BIT
Index of the bit which tells if the page is free.
Definition: fsp0fsp.h:280
constexpr uint32_t XDES_BITMAP
Descriptor bitmap of the pages in the extent.
Definition: fsp0fsp.h:273
constexpr uint32_t XDES_ARR_OFFSET
Offset of the descriptor array on a descriptor page.
Definition: fsp0fsp.h:320
const ulint XDES_FRAG_N_USED
The number of reserved pages in a fragment extent.
Definition: fsp0fsp.h:323
xdes_state_t
States of a descriptor.
Definition: fsp0fsp.h:286
constexpr uint32_t XDES_BITS_PER_PAGE
How many bits are there per page.
Definition: fsp0fsp.h:278
constexpr uint32_t XDES_CLEAN_BIT
NOTE: currently not used! Index of the bit which tells if there are old versions of tuples on the pag...
Definition: fsp0fsp.h:283
@ XDES_NOT_INITED
extent descriptor is not initialized
Definition: fsp0fsp.h:289
@ XDES_FULL_FRAG
extent is in full fragment list of space
Definition: fsp0fsp.h:298
@ XDES_FSEG
extent belongs to a segment
Definition: fsp0fsp.h:301
@ XDES_FSEG_FRAG
fragment extent leased to segment
Definition: fsp0fsp.h:304
@ XDES_FREE
extent is in free list of space
Definition: fsp0fsp.h:292
@ XDES_FREE_FRAG
extent is in free fragment list of space
Definition: fsp0fsp.h:295
#define FSEG_INODE_SIZE
Definition: fsp0fsp.h:223
constexpr uint32_t FSEG_FREE_LIST_MAX_LEN
Definition: fsp0fsp.h:253
constexpr uint32_t FSEG_NOT_FULL
list of partially free extents
Definition: fsp0fsp.h:208
constexpr uint32_t FSEG_INODE_PAGE_NODE
Definition: fsp0fsp.h:195
constexpr uint32_t FSEG_MAGIC_N
magic number used in debugging
Definition: fsp0fsp.h:212
constexpr double FSEG_RESERVE_PCT_MIN
Definition: fsp0fsp.h:244
constexpr uint32_t FSEG_FRAG_ARR
array of individual pages belonging to this segment in fsp fragment extent lists
Definition: fsp0fsp.h:215
constexpr double FSEG_RESERVE_PCT_DFLT
Definition: fsp0fsp.h:243
constexpr uint32_t FSEG_MAGIC_N_VALUE
Definition: fsp0fsp.h:232
constexpr uint32_t FSEG_NOT_FULL_N_USED
number of used segment pages in the FSEG_NOT_FULL list
Definition: fsp0fsp.h:204
static uint32_t FSP_SEG_INODES_PER_PAGE(page_size_t page_size)
Definition: fsp0fsp.h:226
constexpr uint32_t FSEG_FRAG_SLOT_SIZE
a fragment page slot contains its page number within space, FIL_NULL means that the slot is not in us...
Definition: fsp0fsp.h:220
constexpr uint32_t FSEG_FREE_LIST_LIMIT
If the reserved size of a segment is at least this many extents, we allow extents to be put to the fr...
Definition: fsp0fsp.h:252
constexpr uint32_t FSEG_ID
Definition: fsp0fsp.h:202
double fseg_reserve_pct
The segment_reserve_factor is the ratio x/y expressed in percentage, where x is the number of free pa...
Definition: fsp0fsp.cc:66
byte fseg_inode_t
Definition: fsp0fsp.h:193
constexpr double FSEG_RESERVE_PCT_MAX
Definition: fsp0fsp.h:245
constexpr uint32_t FSEG_FULL
list of full extents
Definition: fsp0fsp.h:210
constexpr uint32_t FSEG_FREE
list of free extents of this segment
Definition: fsp0fsp.h:206
constexpr uint32_t FSEG_ARR_OFFSET
Definition: fsp0fsp.h:199
byte xdes_t
Definition: fsp0fsp.h:74
constexpr uint32_t FSP_FREE_ADD
This many free extents are added to the free list from above FSP_FREE_LIMIT at a time.
Definition: fsp0fsp.h:175
constexpr uint32_t FSP_NOT_USED
this field contained a value up to which we know that the modifications in the database have been flu...
Definition: fsp0fsp.h:137
constexpr uint32_t FSP_SEG_INODES_FREE
list of pages containing segment headers, where not all the segment header slots are reserved
Definition: fsp0fsp.h:167
constexpr uint32_t FSP_FRAG_N_USED
number of used pages in the FSP_FREE_FRAG list
Definition: fsp0fsp.h:149
std::vector< space_id_t > flag_mismatch_spaces
Definition: fsp0fsp.cc:84
constexpr uint32_t FSP_SDI_HEADER_LEN
The number of bytes required to store SDI root page number(4) and SDI version(4) at Page 0.
Definition: fsp0fsp.h:70
constexpr uint32_t FSP_SPACE_ID
space id
Definition: fsp0fsp.h:134
constexpr uint32_t FSP_SEG_INODES_FULL
list of pages containing segment headers, where all the segment inode slots are reserved
Definition: fsp0fsp.h:163
constexpr uint32_t FSP_SEG_ID
8 bytes which give the first unused segment id
Definition: fsp0fsp.h:159
constexpr uint32_t FSP_FREE
list of free extents
Definition: fsp0fsp.h:151
constexpr uint32_t FSP_FULL_FRAG
list of full extents not belonging to any segment
Definition: fsp0fsp.h:156
bool xdes_state_is_valid(ulint state)
Check if the state of extent descriptor is valid.
Definition: fsp0fsp.cc:456
constexpr uint32_t FSP_HEADER_SIZE
Definition: fsp0fsp.h:171
constexpr uint32_t FSP_HEADER_OFFSET
Offset of the space header within a file page.
Definition: fsp0fsp.h:66
std::ostream & operator<<(std::ostream &out, const xdes_mem_t &obj)
Definition: fsp0fsp.h:95
constexpr uint32_t FSP_FREE_LIMIT
Minimum page number for which the free list has not been initialized: the pages >= this limit are,...
Definition: fsp0fsp.h:145
constexpr uint32_t FSP_SPACE_FLAGS
fsp_space_t.flags, similar to dict_table_t::flags
Definition: fsp0fsp.h:147
constexpr uint32_t FSP_FREE_FRAG
list of partially free extents not belonging to any segment
Definition: fsp0fsp.h:153
byte fsp_header_t
Definition: fsp0fsp.h:73
constexpr uint32_t FSP_SIZE
Current size of the space in pages.
Definition: fsp0fsp.h:139
constexpr uint32_t fsp_is_shared_tablespace(uint32_t flags)
Use an alias in the code for FSP_FLAGS_GET_SHARED()
Definition: fsp0types.h:387
static int flags[50]
Definition: hp_test1.cc:39
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.
static uint64_t mach_read_from_8(const byte *b)
The following function is used to fetch data from 8 consecutive bytes.
void mlog_write_ulint(byte *ptr, ulint val, mlog_id_t type, mtr_t *mtr)
Writes 1, 2 or 4 bytes to a file page.
Definition: mtr0log.cc:255
Mini-transaction buffer.
#define mtr_memo_contains_page(m, p, t)
Check if memo contains the given page.
Definition: mtr0mtr.h:110
@ MLOG_4BYTES
4 bytes ...
Definition: mtr0types.h:75
@ MTR_MEMO_PAGE_SX_FIX
Definition: mtr0types.h:274
#define DBUG_LOG(keyword, v)
Definition: my_dbug.h:314
#define DBUG_TRACE
Definition: my_dbug.h:145
Instrumentation helpers for conditions.
ABI for instrumented mutexes.
ulong n_pages
Number of pages per doublewrite thread/segment.
Definition: buf0dblwr.cc:82
bool is_encrypted(const String_type &type)
Definition: dd_table.h:421
Index page routines.
byte page_t
Type of the index page.
Definition: page0types.h:151
Record manager global types.
required uint64 version
Definition: replication_group_member_actions.proto:40
Definition: os0enc.h:460
Definition: fsp0fsp.h:1039
Page_alloc_info(space_id_t space_id, const page_size_t &page_size, fseg_header_t *fseg_hdr)
Definition: fsp0fsp.h:1040
fseg_header_t * m_fseg_header
File segment header.
Definition: fsp0fsp.h:1051
page_size_t m_page_size
Page size.
Definition: fsp0fsp.h:1048
space_id_t m_space_id
Tablespace ID.
Definition: fsp0fsp.h:1045
The buffer control block structure.
Definition: buf0buf.h:1750
Tablespace or log data space.
Definition: fil0fil.h:233
In-memory representation of flst_base_node_t.
Definition: fut0lst.h:147
In-memory representation of the fsp_header_t file structure.
Definition: fsp0fsp.h:100
ulint m_space_id
Definition: fsp0fsp.h:103
flst_bnode_t m_free_frag
Definition: fsp0fsp.h:110
flst_bnode_t m_inodes_free
Definition: fsp0fsp.h:114
ulint m_notused
Definition: fsp0fsp.h:104
ulint m_free_limit
Definition: fsp0fsp.h:106
ulint m_fsp_frag_n_used
Definition: fsp0fsp.h:108
ulint m_flags
Definition: fsp0fsp.h:107
ib_id_t m_segid
Definition: fsp0fsp.h:112
ulint m_fsp_size
Definition: fsp0fsp.h:105
flst_bnode_t m_fsp_free
Definition: fsp0fsp.h:109
flst_bnode_t m_full_frag
Definition: fsp0fsp.h:111
std::ostream & print(std::ostream &out) const
Definition: fsp0fsp.cc:4003
fsp_header_mem_t(const fsp_header_t *header, mtr_t *mtr)
Definition: fsp0fsp.cc:3989
flst_bnode_t m_inodes_full
Definition: fsp0fsp.h:113
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:176
An instrumented cond structure.
Definition: mysql_cond_bits.h:49
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
Definition: fsp0fsp.h:84
const xdes_t * m_xdes
Definition: fsp0fsp.h:90
bool is_valid() const
Definition: fsp0fsp.h:866
const char * state_name() const
Definition: fsp0fsp.h:871
xdes_mem_t(const xdes_t *xdes)
Definition: fsp0fsp.h:85
std::ostream & print(std::ostream &out) const
Definition: fsp0fsp.cc:4045
static const space_id_t TRX_SYS_SPACE
Space id of the transaction system page (the system tablespace)
Definition: trx0types.h:51
Version control for database, common definitions, and include files.
uint64_t ib_id_t
The generic InnoDB system object identifier data type.
Definition: univ.i:442
#define UNIV_PAGE_SIZE
The universal page size of the database.
Definition: univ.i:293
#define IF_DEBUG(...)
Definition: univ.i:673
unsigned long int ulint
Definition: univ.i:405
Utilities for byte operations.
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:104