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