函数fsp_try_extend_data_file

时间:2023-03-09 05:38:44
函数fsp_try_extend_data_file

扩展表空间

/***********************************************************************//**
Tries to extend the last data file of a tablespace if it is auto-extending.
@return    FALSE if not auto-extending */
static __attribute__((nonnull))
ibool
fsp_try_extend_data_file(
/*=====================*/
    ulint*        actual_increase,/*!< out: actual increase in pages, where
                    we measure the tablespace size from
                    what the header field says; it may be
                    the actual file size rounded down to
                    megabyte */
    ulint        space,        /*!< in: space */
    fsp_header_t*    header,        /*!< in/out: space header */
    mtr_t*        mtr)        /*!< in/out: mini-transaction */
{
    ulint    size;
    ulint    zip_size;
    ulint    new_size;
    ulint    old_size;
    ulint    size_increase;
    ulint    actual_size;
    ibool    success;

    *actual_increase = ;
    //UNIV_INTERN ibool    srv_auto_extend_last_data_file    = FALSE;
     && !srv_auto_extend_last_data_file) {

        /* We print the error message only once to avoid
        spamming the error log. Note that we don't need
        to reset the flag to FALSE as dealing with this
        error requires server restart. */
        if (fsp_tbs_full_error_printed == FALSE) {
            fprintf(stderr,
                "InnoDB: Error: Data file(s) ran"
                " out of space.\n"
                "Please add another data file or"
                " use \'autoextend\' for the last"
                " data file.\n");
            fsp_tbs_full_error_printed = TRUE;
        }
        return(FALSE);
    }

    size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr);
    zip_size = dict_table_flags_to_zip_size(
        mach_read_from_4(header + FSP_SPACE_FLAGS));

    old_size = size;

    ) {
        /**
         * if != 0, this tells the max size auto-extending may increase the last data file size
         * UNIV_INTERN ulint    srv_last_file_size_max    = 0;
         *
         *#define SRV_AUTO_EXTEND_INCREMENT    \
            (srv_auto_extend_increment * ((1024 * 1024) / UNIV_PAGE_SIZE))
            ====> 8*((1024*1024)/16k) 为512个page,共计8M (默认为8M)
         */
        if (!srv_last_file_size_max) {
            size_increase = SRV_AUTO_EXTEND_INCREMENT;
        } else {
            ...
        }
    } else {
        /* We extend single-table tablespaces first one extent
        at a time, but for bigger tablespaces more. It is not
        enough to extend always by one extent, because some
        extents are frag page extents. */
        ulint    extent_size;    /*!< one megabyte, in pages */

        if (!zip_size) {
            extent_size = FSP_EXTENT_SIZE;
        } else {
            extent_size = FSP_EXTENT_SIZE
                * UNIV_PAGE_SIZE / zip_size;
        }

        if (size < extent_size) {
            /* Let us first extend the file to extent_size */
            success = fsp_try_extend_data_file_with_pages(
                space, extent_size - , header, mtr);
            if (!success) {
                new_size = mtr_read_ulint(header + FSP_SIZE,
                              MLOG_4BYTES, mtr);

                *actual_increase = new_size - old_size;

                return(FALSE);
            }

            size = extent_size;
        }

         * extent_size) {
            size_increase = extent_size;
        } else {
            /* Below in fsp_fill_free_list() we assume
            that we add at most FSP_FREE_ADD extents at
            a time */
            size_increase = FSP_FREE_ADD * extent_size;
        }
    }

    ) {

        return(TRUE);
    }
    //当前size+512个page
    success = fil_extend_space_to_desired_size(&actual_size, space,size + size_increase);//详见    /* We ignore any fragments of a full megabyte when storing the size
    to the space header */

    if (!zip_size) {
        new_size = ut_calc_align_down(actual_size,
                          ( * ) / UNIV_PAGE_SIZE);
    } else {
        new_size = ut_calc_align_down(actual_size,
                          ( * ) / zip_size);
    }
    mlog_write_ulint(header + FSP_SIZE, new_size, MLOG_4BYTES, mtr);

    *actual_increase = new_size - old_size;

    return(TRUE);
}