/**********************************************************************//** Allocates a single free page from a space. The page is marked as used. @retval NULL if no page could be allocated @retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded (init_mtr == mtr, or the page was not previously freed in mtr) @retval block (not allocated or initialized) otherwise */ static __attribute__((nonnull, warn_unused_result)) buf_block_t* fsp_alloc_free_page( /*================*/ ulint space, /*!< in: space id */ ulint zip_size,/*!< in: compressed page size in bytes or 0 for uncompressed pages */ ulint hint, /*!< in: hint of which page would be desirable */ mtr_t* mtr, /*!< in/out: mini-transaction */ mtr_t* init_mtr)/*!< in/out: mini-transaction in which the page should be initialized (may be the same as mtr) */ { fsp_header_t* header; fil_addr_t first; xdes_t* descr; ulint free; ulint page_no; ulint space_size; ut_ad(mtr); ut_ad(init_mtr); header = fsp_get_space_header(space, zip_size, mtr); /* Get the hinted descriptor */ descr = xdes_get_descriptor_with_space_hdr(header, space, hint, mtr); if (descr && (xdes_get_state(descr, mtr) == XDES_FREE_FRAG)) { /* Ok, we can take this extent */ } else { /* Else take the first extent in free_frag list */ first = flst_get_first(header + FSP_FREE_FRAG, mtr); if (fil_addr_is_null(first)) { /* There are no partially full fragments: allocate a free extent and add it to the FREE_FRAG list. NOTE that the allocation may have as a side-effect that an extent containing a descriptor page is added to the FREE_FRAG list. But we will allocate our page from the the free extent anyway. */ descr = fsp_alloc_free_extent(space, zip_size, hint, mtr); if (descr == NULL) { /* No free space left */ return(NULL); } xdes_set_state(descr, XDES_FREE_FRAG, mtr); flst_add_last(header + FSP_FREE_FRAG, descr + XDES_FLST_NODE, mtr); } else { descr = xdes_lst_get_descriptor(space, zip_size, first, mtr); } /* Reset the hint */ hint = 0; } /* Now we have in descr an extent with at least one free page. Look for a free page in the extent. */ free = xdes_find_bit(descr, XDES_FREE_BIT, TRUE, hint % FSP_EXTENT_SIZE, mtr); if (free == ULINT_UNDEFINED) { ut_print_buf(stderr, ((byte*)descr) - 500, 1000); putc(‘\n‘, stderr); ut_error; } page_no = xdes_get_offset(descr) + free; space_size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr); if (space_size <= page_no) { /* It must be that we are extending a single-table tablespace whose size is still < 64 pages */ ut_a(space != 0); if (page_no >= FSP_EXTENT_SIZE) { fprintf(stderr, "InnoDB: Error: trying to extend a" " single-table tablespace %lu\n" "InnoDB: by single page(s) though the" " space size %lu. Page no %lu.\n", (ulong) space, (ulong) space_size, (ulong) page_no); return(NULL); } if (!fsp_try_extend_data_file_with_pages(space, page_no, header, mtr)) { /* No disk space left */ return(NULL); } } fsp_alloc_from_free_frag(header, descr, free, mtr); return(fsp_page_create(space, zip_size, page_no, mtr, init_mtr)); }
时间: 2024-12-18 22:11:26