1 /***************************************************************************** 2 3 Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, for more details. 20 21 You should have received a copy of the GNU General Public License along with 22 this program; if not, write to the Free Software Foundation, Inc., 23 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA 24 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 #ifndef UNIV_INNOCHECKSUM 40 41 #include "mtr0mtr.h" 42 #include "fut0lst.h" 43 #include "ut0byte.h" 44 #include "page0types.h" 45 #include "fsp0types.h" 46 47 #endif /* !UNIV_INNOCHECKSUM */ 48 49 /* @defgroup fsp_flags InnoDB Tablespace Flag Constants @{ */ 50 51 /** Width of the POST_ANTELOPE flag */ 52 #define FSP_FLAGS_WIDTH_POST_ANTELOPE 1 53 /** Number of flag bits used to indicate the tablespace zip page size */ 54 #define FSP_FLAGS_WIDTH_ZIP_SSIZE 4 55 /** Width of the ATOMIC_BLOBS flag. The ability to break up a long 56 column into an in-record prefix and an externally stored part is available 57 to the two Barracuda row formats COMPRESSED and DYNAMIC. */ 58 #define FSP_FLAGS_WIDTH_ATOMIC_BLOBS 1 59 /** Number of flag bits used to indicate the tablespace page size */ 60 #define FSP_FLAGS_WIDTH_PAGE_SSIZE 4 61 /** Width of the DATA_DIR flag. This flag indicates that the tablespace 62 is found in a remote location, not the default data directory. */ 63 #define FSP_FLAGS_WIDTH_DATA_DIR 1 64 /** Width of all the currently known tablespace flags */ 65 #define FSP_FLAGS_WIDTH (FSP_FLAGS_WIDTH_POST_ANTELOPE \ 66 + FSP_FLAGS_WIDTH_ZIP_SSIZE \ 67 + FSP_FLAGS_WIDTH_ATOMIC_BLOBS \ 68 + FSP_FLAGS_WIDTH_PAGE_SSIZE \ 69 + FSP_FLAGS_WIDTH_DATA_DIR) 70 71 /** A mask of all the known/used bits in tablespace flags */ 72 #define FSP_FLAGS_MASK (~(~0 << FSP_FLAGS_WIDTH)) 73 74 /** Zero relative shift position of the POST_ANTELOPE field */ 75 #define FSP_FLAGS_POS_POST_ANTELOPE 0 76 /** Zero relative shift position of the ZIP_SSIZE field */ 77 #define FSP_FLAGS_POS_ZIP_SSIZE (FSP_FLAGS_POS_POST_ANTELOPE \ 78 + FSP_FLAGS_WIDTH_POST_ANTELOPE) 79 /** Zero relative shift position of the ATOMIC_BLOBS field */ 80 #define FSP_FLAGS_POS_ATOMIC_BLOBS (FSP_FLAGS_POS_ZIP_SSIZE \ 81 + FSP_FLAGS_WIDTH_ZIP_SSIZE) 82 /** Zero relative shift position of the PAGE_SSIZE field */ 83 #define FSP_FLAGS_POS_PAGE_SSIZE (FSP_FLAGS_POS_ATOMIC_BLOBS \ 84 + FSP_FLAGS_WIDTH_ATOMIC_BLOBS) 85 /** Zero relative shift position of the start of the UNUSED bits */ 86 #define FSP_FLAGS_POS_DATA_DIR (FSP_FLAGS_POS_PAGE_SSIZE \ 87 + FSP_FLAGS_WIDTH_PAGE_SSIZE) 88 /** Zero relative shift position of the start of the UNUSED bits */ 89 #define FSP_FLAGS_POS_UNUSED (FSP_FLAGS_POS_DATA_DIR \ 90 + FSP_FLAGS_WIDTH_DATA_DIR) 91 92 /** Bit mask of the POST_ANTELOPE field */ 93 #define FSP_FLAGS_MASK_POST_ANTELOPE \ 94 ((~(~0U << FSP_FLAGS_WIDTH_POST_ANTELOPE)) \ 95 << FSP_FLAGS_POS_POST_ANTELOPE) 96 /** Bit mask of the ZIP_SSIZE field */ 97 #define FSP_FLAGS_MASK_ZIP_SSIZE \ 98 ((~(~0U << FSP_FLAGS_WIDTH_ZIP_SSIZE)) \ 99 << FSP_FLAGS_POS_ZIP_SSIZE) 100 /** Bit mask of the ATOMIC_BLOBS field */ 101 #define FSP_FLAGS_MASK_ATOMIC_BLOBS \ 102 ((~(~0U << FSP_FLAGS_WIDTH_ATOMIC_BLOBS)) \ 103 << FSP_FLAGS_POS_ATOMIC_BLOBS) 104 /** Bit mask of the PAGE_SSIZE field */ 105 #define FSP_FLAGS_MASK_PAGE_SSIZE \ 106 ((~(~0U << FSP_FLAGS_WIDTH_PAGE_SSIZE)) \ 107 << FSP_FLAGS_POS_PAGE_SSIZE) 108 /** Bit mask of the DATA_DIR field */ 109 #define FSP_FLAGS_MASK_DATA_DIR \ 110 ((~(~0U << FSP_FLAGS_WIDTH_DATA_DIR)) \ 111 << FSP_FLAGS_POS_DATA_DIR) 112 113 /** Return the value of the POST_ANTELOPE field */ 114 #define FSP_FLAGS_GET_POST_ANTELOPE(flags) \ 115 ((flags & FSP_FLAGS_MASK_POST_ANTELOPE) \ 116 >> FSP_FLAGS_POS_POST_ANTELOPE) 117 /** Return the value of the ZIP_SSIZE field */ 118 #define FSP_FLAGS_GET_ZIP_SSIZE(flags) \ 119 ((flags & FSP_FLAGS_MASK_ZIP_SSIZE) \ 120 >> FSP_FLAGS_POS_ZIP_SSIZE) 121 /** Return the value of the ATOMIC_BLOBS field */ 122 #define FSP_FLAGS_HAS_ATOMIC_BLOBS(flags) \ 123 ((flags & FSP_FLAGS_MASK_ATOMIC_BLOBS) \ 124 >> FSP_FLAGS_POS_ATOMIC_BLOBS) 125 /** Return the value of the PAGE_SSIZE field */ 126 #define FSP_FLAGS_GET_PAGE_SSIZE(flags) \ 127 ((flags & FSP_FLAGS_MASK_PAGE_SSIZE) \ 128 >> FSP_FLAGS_POS_PAGE_SSIZE) 129 /** Return the value of the DATA_DIR field */ 130 #define FSP_FLAGS_HAS_DATA_DIR(flags) \ 131 ((flags & FSP_FLAGS_MASK_DATA_DIR) \ 132 >> FSP_FLAGS_POS_DATA_DIR) 133 /** Return the contents of the UNUSED bits */ 134 #define FSP_FLAGS_GET_UNUSED(flags) \ 135 (flags >> FSP_FLAGS_POS_UNUSED) 136 137 /** Set a PAGE_SSIZE into the correct bits in a given 138 tablespace flags. */ 139 #define FSP_FLAGS_SET_PAGE_SSIZE(flags, ssize) \ 140 (flags | (ssize << FSP_FLAGS_POS_PAGE_SSIZE)) 141 142 /* @} */ 143 144 /* @defgroup Tablespace Header Constants (moved from fsp0fsp.c) @{ */ 145 146 /** Offset of the space header within a file page */ 147 #define FSP_HEADER_OFFSET FIL_PAGE_DATA 148 149 /* The data structures in files are defined just as byte strings in C */ 150 typedef byte fsp_header_t; 151 typedef byte xdes_t; 152 153 /* SPACE HEADER 154 ============ 155 156 File space header data structure: this data structure is contained in the 157 first page of a space. The space for this header is reserved in every extent 158 descriptor page, but used only in the first. */ 159 160 /*-------------------------------------*/ 161 #define FSP_SPACE_ID 0 /* space id */ 162 #define FSP_NOT_USED 4 /* this field contained a value up to 163 which we know that the modifications 164 in the database have been flushed to 165 the file space; not used now */ 166 #define FSP_SIZE 8 /* Current size of the space in 167 pages */ 168 #define FSP_FREE_LIMIT 12 /* Minimum page number for which the 169 free list has not been initialized: 170 the pages >= this limit are, by 171 definition, free; note that in a 172 single-table tablespace where size 173 < 64 pages, this number is 64, i.e., 174 we have initialized the space 175 about the first extent, but have not 176 physically allocted those pages to the 177 file */ 178 #define FSP_SPACE_FLAGS 16 /* fsp_space_t.flags, similar to 179 dict_table_t::flags */ 180 #define FSP_FRAG_N_USED 20 /* number of used pages in the 181 FSP_FREE_FRAG list */ 182 #define FSP_FREE 24 /* list of free extents */ 183 #define FSP_FREE_FRAG (24 + FLST_BASE_NODE_SIZE) 184 /* list of partially free extents not 185 belonging to any segment */ 186 #define FSP_FULL_FRAG (24 + 2 * FLST_BASE_NODE_SIZE) 187 /* list of full extents not belonging 188 to any segment */ 189 #define FSP_SEG_ID (24 + 3 * FLST_BASE_NODE_SIZE) 190 /* 8 bytes which give the first unused 191 segment id */ 192 #define FSP_SEG_INODES_FULL (32 + 3 * FLST_BASE_NODE_SIZE) 193 /* list of pages containing segment 194 headers, where all the segment inode 195 slots are reserved */ 196 #define FSP_SEG_INODES_FREE (32 + 4 * FLST_BASE_NODE_SIZE) 197 /* list of pages containing segment 198 headers, where not all the segment 199 header slots are reserved */ 200 /*-------------------------------------*/ 201 /* File space header size */ 202 #define FSP_HEADER_SIZE (32 + 5 * FLST_BASE_NODE_SIZE) 203 204 #define FSP_FREE_ADD 4 /* this many free extents are added 205 to the free list from above 206 FSP_FREE_LIMIT at a time */ 207 /* @} */ 208 209 #ifndef UNIV_INNOCHECKSUM 210 211 /* @defgroup File Segment Inode Constants (moved from fsp0fsp.c) @{ */ 212 213 /* FILE SEGMENT INODE 214 ================== 215 216 Segment inode which is created for each segment in a tablespace. NOTE: in 217 purge we assume that a segment having only one currently used page can be 218 freed in a few steps, so that the freeing cannot fill the file buffer with 219 bufferfixed file pages. */ 220 221 typedef byte fseg_inode_t; 222 223 #define FSEG_INODE_PAGE_NODE FSEG_PAGE_DATA 224 /* the list node for linking 225 segment inode pages */ 226 227 #define FSEG_ARR_OFFSET (FSEG_PAGE_DATA + FLST_NODE_SIZE) 228 /*-------------------------------------*/ 229 #define FSEG_ID 0 /* 8 bytes of segment id: if this is 0, 230 it means that the header is unused */ 231 #define FSEG_NOT_FULL_N_USED 8 232 /* number of used segment pages in 233 the FSEG_NOT_FULL list */ 234 #define FSEG_FREE 12 235 /* list of free extents of this 236 segment */ 237 #define FSEG_NOT_FULL (12 + FLST_BASE_NODE_SIZE) 238 /* list of partially free extents */ 239 #define FSEG_FULL (12 + 2 * FLST_BASE_NODE_SIZE) 240 /* list of full extents */ 241 #define FSEG_MAGIC_N (12 + 3 * FLST_BASE_NODE_SIZE) 242 /* magic number used in debugging */ 243 #define FSEG_FRAG_ARR (16 + 3 * FLST_BASE_NODE_SIZE) 244 /* array of individual pages 245 belonging to this segment in fsp 246 fragment extent lists */ 247 #define FSEG_FRAG_ARR_N_SLOTS (FSP_EXTENT_SIZE / 2) 248 /* number of slots in the array for 249 the fragment pages */ 250 #define FSEG_FRAG_SLOT_SIZE 4 /* a fragment page slot contains its 251 page number within space, FIL_NULL 252 means that the slot is not in use */ 253 /*-------------------------------------*/ 254 #define FSEG_INODE_SIZE \ 255 (16 + 3 * FLST_BASE_NODE_SIZE \ 256 + FSEG_FRAG_ARR_N_SLOTS * FSEG_FRAG_SLOT_SIZE) 257 258 #define FSP_SEG_INODES_PER_PAGE(zip_size) \ 259 (((zip_size ? zip_size : UNIV_PAGE_SIZE) \ 260 - FSEG_ARR_OFFSET - 10) / FSEG_INODE_SIZE) 261 /* Number of segment inodes which fit on a 262 single page */ 263 264 #define FSEG_MAGIC_N_VALUE 97937874 265 266 #define FSEG_FILLFACTOR 8 /* If this value is x, then if 267 the number of unused but reserved 268 pages in a segment is less than 269 reserved pages * 1/x, and there are 270 at least FSEG_FRAG_LIMIT used pages, 271 then we allow a new empty extent to 272 be added to the segment in 273 fseg_alloc_free_page. Otherwise, we 274 use unused pages of the segment. */ 275 276 #define FSEG_FRAG_LIMIT FSEG_FRAG_ARR_N_SLOTS 277 /* If the segment has >= this many 278 used pages, it may be expanded by 279 allocating extents to the segment; 280 until that only individual fragment 281 pages are allocated from the space */ 282 283 #define FSEG_FREE_LIST_LIMIT 40 /* If the reserved size of a segment 284 is at least this many extents, we 285 allow extents to be put to the free 286 list of the extent: at most 287 FSEG_FREE_LIST_MAX_LEN many */ 288 #define FSEG_FREE_LIST_MAX_LEN 4 289 /* @} */ 290 291 /* @defgroup Extent Descriptor Constants (moved from fsp0fsp.c) @{ */ 292 293 /* EXTENT DESCRIPTOR 294 ================= 295 296 File extent descriptor data structure: contains bits to tell which pages in 297 the extent are free and which contain old tuple version to clean. */ 298 299 /*-------------------------------------*/ 300 #define XDES_ID 0 /* The identifier of the segment 301 to which this extent belongs */ 302 #define XDES_FLST_NODE 8 /* The list node data structure 303 for the descriptors */ 304 #define XDES_STATE (FLST_NODE_SIZE + 8) 305 /* contains state information 306 of the extent */ 307 #define XDES_BITMAP (FLST_NODE_SIZE + 12) 308 /* Descriptor bitmap of the pages 309 in the extent */ 310 /*-------------------------------------*/ 311 312 #define XDES_BITS_PER_PAGE 2 /* How many bits are there per page */ 313 #define XDES_FREE_BIT 0 /* Index of the bit which tells if 314 the page is free */ 315 #define XDES_CLEAN_BIT 1 /* NOTE: currently not used! 316 Index of the bit which tells if 317 there are old versions of tuples 318 on the page */ 319 /* States of a descriptor */ 320 #define XDES_FREE 1 /* extent is in free list of space */ 321 #define XDES_FREE_FRAG 2 /* extent is in free fragment list of 322 space */ 323 #define XDES_FULL_FRAG 3 /* extent is in full fragment list of 324 space */ 325 #define XDES_FSEG 4 /* extent belongs to a segment */ 326 327 /** File extent data structure size in bytes. */ 328 #define XDES_SIZE \ 329 (XDES_BITMAP \ 330 + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE * XDES_BITS_PER_PAGE)) 331 332 /** File extent data structure size in bytes for MAX page size. */ 333 #define XDES_SIZE_MAX \ 334 (XDES_BITMAP \ 335 + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE_MAX * XDES_BITS_PER_PAGE)) 336 337 /** File extent data structure size in bytes for MIN page size. */ 338 #define XDES_SIZE_MIN \ 339 (XDES_BITMAP \ 340 + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE_MIN * XDES_BITS_PER_PAGE)) 341 342 /** Offset of the descriptor array on a descriptor page */ 343 #define XDES_ARR_OFFSET (FSP_HEADER_OFFSET + FSP_HEADER_SIZE) 344 345 /* @} */ 346 347 /**********************************************************************//** 348 Initializes the file space system. */ 349 UNIV_INTERN 350 void 351 fsp_init(void); 352 /*==========*/ 353 /**********************************************************************//** 354 Gets the size of the system tablespace from the tablespace header. If 355 we do not have an auto-extending data file, this should be equal to 356 the size of the data files. If there is an auto-extending data file, 357 this can be smaller. 358 @return size in pages */ 359 UNIV_INTERN 360 ulint 361 fsp_header_get_tablespace_size(void); 362 /*================================*/ 363 /**********************************************************************//** 364 Reads the file space size stored in the header page. 365 @return tablespace size stored in the space header */ 366 UNIV_INTERN 367 ulint 368 fsp_get_size_low( 369 /*=============*/ 370 page_t* page); /*!< in: header page (page 0 in the tablespace) */ 371 /**********************************************************************//** 372 Reads the space id from the first page of a tablespace. 373 @return space id, ULINT UNDEFINED if error */ 374 UNIV_INTERN 375 ulint 376 fsp_header_get_space_id( 377 /*====================*/ 378 const page_t* page); /*!< in: first page of a tablespace */ 379 /**********************************************************************//** 380 Reads the space flags from the first page of a tablespace. 381 @return flags */ 382 UNIV_INTERN 383 ulint 384 fsp_header_get_flags( 385 /*=================*/ 386 const page_t* page); /*!< in: first page of a tablespace */ 387 /**********************************************************************//** 388 Reads the compressed page size from the first page of a tablespace. 389 @return compressed page size in bytes, or 0 if uncompressed */ 390 UNIV_INTERN 391 ulint 392 fsp_header_get_zip_size( 393 /*====================*/ 394 const page_t* page); /*!< in: first page of a tablespace */ 395 /**********************************************************************//** 396 Writes the space id and flags to a tablespace header. The flags contain 397 row type, physical/compressed page size, and logical/uncompressed page 398 size of the tablespace. */ 399 UNIV_INTERN 400 void 401 fsp_header_init_fields( 402 /*===================*/ 403 page_t* page, /*!< in/out: first page in the space */ 404 ulint space_id, /*!< in: space id */ 405 ulint flags); /*!< in: tablespace flags (FSP_SPACE_FLAGS): 406 0, or table->flags if newer than COMPACT */ 407 /**********************************************************************//** 408 Initializes the space header of a new created space and creates also the 409 insert buffer tree root if space == 0. */ 410 UNIV_INTERN 411 void 412 fsp_header_init( 413 /*============*/ 414 ulint space, /*!< in: space id */ 415 ulint size, /*!< in: current size in blocks */ 416 mtr_t* mtr); /*!< in/out: mini-transaction */ 417 /**********************************************************************//** 418 Increases the space size field of a space. */ 419 UNIV_INTERN 420 void 421 fsp_header_inc_size( 422 /*================*/ 423 ulint space, /*!< in: space id */ 424 ulint size_inc, /*!< in: size increment in pages */ 425 mtr_t* mtr); /*!< in/out: mini-transaction */ 426 /**********************************************************************//** 427 Creates a new segment. 428 @return the block where the segment header is placed, x-latched, NULL 429 if could not create segment because of lack of space */ 430 UNIV_INTERN 431 buf_block_t* 432 fseg_create( 433 /*========*/ 434 ulint space, /*!< in: space id */ 435 ulint page, /*!< in: page where the segment header is placed: if 436 this is != 0, the page must belong to another segment, 437 if this is 0, a new page will be allocated and it 438 will belong to the created segment */ 439 ulint byte_offset, /*!< in: byte offset of the created segment header 440 on the page */ 441 mtr_t* mtr); /*!< in/out: mini-transaction */ 442 /**********************************************************************//** 443 Creates a new segment. 444 @return the block where the segment header is placed, x-latched, NULL 445 if could not create segment because of lack of space */ 446 UNIV_INTERN 447 buf_block_t* 448 fseg_create_general( 449 /*================*/ 450 ulint space, /*!< in: space id */ 451 ulint page, /*!< in: page where the segment header is placed: if 452 this is != 0, the page must belong to another segment, 453 if this is 0, a new page will be allocated and it 454 will belong to the created segment */ 455 ulint byte_offset, /*!< in: byte offset of the created segment header 456 on the page */ 457 ibool has_done_reservation, /*!< in: TRUE if the caller has already 458 done the reservation for the pages with 459 fsp_reserve_free_extents (at least 2 extents: one for 460 the inode and the other for the segment) then there is 461 no need to do the check for this individual 462 operation */ 463 mtr_t* mtr); /*!< in/out: mini-transaction */ 464 /**********************************************************************//** 465 Calculates the number of pages reserved by a segment, and how many pages are 466 currently used. 467 @return number of reserved pages */ 468 UNIV_INTERN 469 ulint 470 fseg_n_reserved_pages( 471 /*==================*/ 472 fseg_header_t* header, /*!< in: segment header */ 473 ulint* used, /*!< out: number of pages used (<= reserved) */ 474 mtr_t* mtr); /*!< in/out: mini-transaction */ 475 /**********************************************************************//** 476 Allocates a single free page from a segment. This function implements 477 the intelligent allocation strategy which tries to minimize 478 file space fragmentation. 479 @param[in/out] seg_header segment header 480 @param[in] hint hint of which page would be desirable 481 @param[in] direction if the new page is needed because 482 of an index page split, and records are 483 inserted there in order, into which 484 direction they go alphabetically: FSP_DOWN, 485 FSP_UP, FSP_NO_DIR 486 @param[in/out] mtr mini-transaction 487 @return X-latched block, or NULL if no page could be allocated */ 488 #define fseg_alloc_free_page(seg_header, hint, direction, mtr) \ 489 fseg_alloc_free_page_general(seg_header, hint, direction, \ 490 FALSE, mtr, mtr) 491 /**********************************************************************//** 492 Allocates a single free page from a segment. This function implements 493 the intelligent allocation strategy which tries to minimize file space 494 fragmentation. 495 @retval NULL if no page could be allocated 496 @retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded 497 (init_mtr == mtr, or the page was not previously freed in mtr) 498 @retval block (not allocated or initialized) otherwise */ 499 UNIV_INTERN 500 buf_block_t* 501 fseg_alloc_free_page_general( 502 /*=========================*/ 503 fseg_header_t* seg_header,/*!< in/out: segment header */ 504 ulint hint, /*!< in: hint of which page would be 505 desirable */ 506 byte direction,/*!< in: if the new page is needed because 507 of an index page split, and records are 508 inserted there in order, into which 509 direction they go alphabetically: FSP_DOWN, 510 FSP_UP, FSP_NO_DIR */ 511 ibool has_done_reservation, /*!< in: TRUE if the caller has 512 already done the reservation for the page 513 with fsp_reserve_free_extents, then there 514 is no need to do the check for this individual 515 page */ 516 mtr_t* mtr, /*!< in/out: mini-transaction */ 517 mtr_t* init_mtr)/*!< in/out: mtr or another mini-transaction 518 in which the page should be initialized. 519 If init_mtr!=mtr, but the page is already 520 latched in mtr, do not initialize the page. */ 521 MY_ATTRIBUTE((warn_unused_result, nonnull)); 522 /**********************************************************************//** 523 Reserves free pages from a tablespace. All mini-transactions which may 524 use several pages from the tablespace should call this function beforehand 525 and reserve enough free extents so that they certainly will be able 526 to do their operation, like a B-tree page split, fully. Reservations 527 must be released with function fil_space_release_free_extents! 528 529 The alloc_type below has the following meaning: FSP_NORMAL means an 530 operation which will probably result in more space usage, like an 531 insert in a B-tree; FSP_UNDO means allocation to undo logs: if we are 532 deleting rows, then this allocation will in the long run result in 533 less space usage (after a purge); FSP_CLEANING means allocation done 534 in a physical record delete (like in a purge) or other cleaning operation 535 which will result in less space usage in the long run. We prefer the latter 536 two types of allocation: when space is scarce, FSP_NORMAL allocations 537 will not succeed, but the latter two allocations will succeed, if possible. 538 The purpose is to avoid dead end where the database is full but the 539 user cannot free any space because these freeing operations temporarily 540 reserve some space. 541 542 Single-table tablespaces whose size is < 32 pages are a special case. In this 543 function we would liberally reserve several 64 page extents for every page 544 split or merge in a B-tree. But we do not want to waste disk space if the table 545 only occupies < 32 pages. That is why we apply different rules in that special 546 case, just ensuring that there are 3 free pages available. 547 @return TRUE if we were able to make the reservation */ 548 UNIV_INTERN 549 ibool 550 fsp_reserve_free_extents( 551 /*=====================*/ 552 ulint* n_reserved,/*!< out: number of extents actually reserved; if we 553 return TRUE and the tablespace size is < 64 pages, 554 then this can be 0, otherwise it is n_ext */ 555 ulint space, /*!< in: space id */ 556 ulint n_ext, /*!< in: number of extents to reserve */ 557 ulint alloc_type,/*!< in: FSP_NORMAL, FSP_UNDO, or FSP_CLEANING */ 558 mtr_t* mtr); /*!< in: mini-transaction */ 559 /**********************************************************************//** 560 This function should be used to get information on how much we still 561 will be able to insert new data to the database without running out the 562 tablespace. Only free extents are taken into account and we also subtract 563 the safety margin required by the above function fsp_reserve_free_extents. 564 @return available space in kB */ 565 UNIV_INTERN 566 ullint 567 fsp_get_available_space_in_free_extents( 568 /*====================================*/ 569 ulint space); /*!< in: space id */ 570 /**********************************************************************//** 571 Frees a single page of a segment. */ 572 UNIV_INTERN 573 void 574 fseg_free_page( 575 /*===========*/ 576 fseg_header_t* seg_header, /*!< in: segment header */ 577 ulint space, /*!< in: space id */ 578 ulint page, /*!< in: page offset */ 579 mtr_t* mtr); /*!< in/out: mini-transaction */ 580 /**********************************************************************//** 581 Checks if a single page of a segment is free. 582 @return true if free */ 583 UNIV_INTERN 584 bool 585 fseg_page_is_free( 586 /*==============*/ 587 fseg_header_t* seg_header, /*!< in: segment header */ 588 ulint space, /*!< in: space id */ 589 ulint page) /*!< in: page offset */ 590 MY_ATTRIBUTE((nonnull, warn_unused_result)); 591 /**********************************************************************//** 592 Frees part of a segment. This function can be used to free a segment 593 by repeatedly calling this function in different mini-transactions. 594 Doing the freeing in a single mini-transaction might result in 595 too big a mini-transaction. 596 @return TRUE if freeing completed */ 597 UNIV_INTERN 598 ibool 599 fseg_free_step( 600 /*===========*/ 601 fseg_header_t* header, /*!< in, own: segment header; NOTE: if the header 602 resides on the first page of the frag list 603 of the segment, this pointer becomes obsolete 604 after the last freeing step */ 605 mtr_t* mtr); /*!< in/out: mini-transaction */ 606 /**********************************************************************//** 607 Frees part of a segment. Differs from fseg_free_step because this function 608 leaves the header page unfreed. 609 @return TRUE if freeing completed, except the header page */ 610 UNIV_INTERN 611 ibool 612 fseg_free_step_not_header( 613 /*======================*/ 614 fseg_header_t* header, /*!< in: segment header which must reside on 615 the first fragment page of the segment */ 616 mtr_t* mtr); /*!< in/out: mini-transaction */ 617 /***********************************************************************//** 618 Checks if a page address is an extent descriptor page address. 619 @return TRUE if a descriptor page */ 620 UNIV_INLINE 621 ibool 622 fsp_descr_page( 623 /*===========*/ 624 ulint zip_size,/*!< in: compressed page size in bytes; 625 0 for uncompressed pages */ 626 ulint page_no);/*!< in: page number */ 627 /***********************************************************//** 628 Parses a redo log record of a file page init. 629 @return end of log record or NULL */ 630 UNIV_INTERN 631 byte* 632 fsp_parse_init_file_page( 633 /*=====================*/ 634 byte* ptr, /*!< in: buffer */ 635 byte* end_ptr, /*!< in: buffer end */ 636 buf_block_t* block); /*!< in: block or NULL */ 637 /*******************************************************************//** 638 Validates the file space system and its segments. 639 @return TRUE if ok */ 640 UNIV_INTERN 641 ibool 642 fsp_validate( 643 /*=========*/ 644 ulint space); /*!< in: space id */ 645 /*******************************************************************//** 646 Prints info of a file space. */ 647 UNIV_INTERN 648 void 649 fsp_print( 650 /*======*/ 651 ulint space); /*!< in: space id */ 652 #ifdef UNIV_DEBUG 653 /*******************************************************************//** 654 Validates a segment. 655 @return TRUE if ok */ 656 UNIV_INTERN 657 ibool 658 fseg_validate( 659 /*==========*/ 660 fseg_header_t* header, /*!< in: segment header */ 661 mtr_t* mtr); /*!< in/out: mini-transaction */ 662 #endif /* UNIV_DEBUG */ 663 #ifdef UNIV_BTR_PRINT 664 /*******************************************************************//** 665 Writes info of a segment. */ 666 UNIV_INTERN 667 void 668 fseg_print( 669 /*=======*/ 670 fseg_header_t* header, /*!< in: segment header */ 671 mtr_t* mtr); /*!< in/out: mini-transaction */ 672 #endif /* UNIV_BTR_PRINT */ 673 674 /********************************************************************//** 675 Validate and return the tablespace flags, which are stored in the 676 tablespace header at offset FSP_SPACE_FLAGS. They should be 0 for 677 ROW_FORMAT=COMPACT and ROW_FORMAT=REDUNDANT. The newer row formats, 678 COMPRESSED and DYNAMIC, use a file format > Antelope so they should 679 have a file format number plus the DICT_TF_COMPACT bit set. 680 @return true if check ok */ 681 UNIV_INLINE 682 bool 683 fsp_flags_is_valid( 684 /*===============*/ 685 ulint flags) /*!< in: tablespace flags */ 686 MY_ATTRIBUTE((warn_unused_result, const)); 687 /********************************************************************//** 688 Determine if the tablespace is compressed from dict_table_t::flags. 689 @return TRUE if compressed, FALSE if not compressed */ 690 UNIV_INLINE 691 ibool 692 fsp_flags_is_compressed( 693 /*====================*/ 694 ulint flags); /*!< in: tablespace flags */ 695 696 /********************************************************************//** 697 Calculates the descriptor index within a descriptor page. 698 @return descriptor index */ 699 UNIV_INLINE 700 ulint 701 xdes_calc_descriptor_index( 702 /*=======================*/ 703 ulint zip_size, /*!< in: compressed page size in bytes; 704 0 for uncompressed pages */ 705 ulint offset); /*!< in: page offset */ 706 707 /**********************************************************************//** 708 Gets a descriptor bit of a page. 709 @return TRUE if free */ 710 UNIV_INLINE 711 ibool 712 xdes_get_bit( 713 /*=========*/ 714 const xdes_t* descr, /*!< in: descriptor */ 715 ulint bit, /*!< in: XDES_FREE_BIT or XDES_CLEAN_BIT */ 716 ulint offset);/*!< in: page offset within extent: 717 0 ... FSP_EXTENT_SIZE - 1 */ 718 719 /********************************************************************//** 720 Calculates the page where the descriptor of a page resides. 721 @return descriptor page offset */ 722 UNIV_INLINE 723 ulint 724 xdes_calc_descriptor_page( 725 /*======================*/ 726 ulint zip_size, /*!< in: compressed page size in bytes; 727 0 for uncompressed pages */ 728 ulint offset); /*!< in: page offset */ 729 730 #endif /* !UNIV_INNOCHECKSUM */ 731 732 /********************************************************************//** 733 Extract the zip size from tablespace flags. A tablespace has only one 734 physical page size whether that page is compressed or not. 735 @return compressed page size of the file-per-table tablespace in bytes, 736 or zero if the table is not compressed. */ 737 UNIV_INLINE 738 ulint 739 fsp_flags_get_zip_size( 740 /*====================*/ 741 ulint flags); /*!< in: tablespace flags */ 742 /********************************************************************//** 743 Extract the page size from tablespace flags. 744 @return page size of the tablespace in bytes */ 745 UNIV_INLINE 746 ulint 747 fsp_flags_get_page_size( 748 /*====================*/ 749 ulint flags); /*!< in: tablespace flags */ 750 751 #ifndef UNIV_NONINL 752 #include "fsp0fsp.ic" 753 #endif 754 755 #endif 756