/**********************************************************************//** Returns a new table, index, or tree id. @return the new id */ UNIV_INTERN dulint dict_hdr_get_new_id( /*================*/ ulint type) /*!< in: DICT_HDR_ROW_ID, ... */ { dict_hdr_t* dict_hdr; dulint id; mtr_t mtr; ut_ad((type == DICT_HDR_TABLE_ID) || (type == DICT_HDR_INDEX_ID)); mtr_start(&mtr); dict_hdr = dict_hdr_get(&mtr); id = mtr_read_dulint(dict_hdr + type, &mtr); id = ut_dulint_add(id, 1); mlog_write_dulint(dict_hdr + type, id, &mtr); mtr_commit(&mtr); return(id); }
/**********************************************************************//** Writes the current value of the row id counter to the dictionary header file page. */ UNIV_INTERN void dict_hdr_flush_row_id(void) /*=======================*/ { dict_hdr_t* dict_hdr; dulint id; mtr_t mtr; ut_ad(mutex_own(&(dict_sys->mutex))); id = dict_sys->row_id; mtr_start(&mtr); dict_hdr = dict_hdr_get(&mtr); mlog_write_dulint(dict_hdr + DICT_HDR_ROW_ID, id, &mtr); mtr_commit(&mtr); }
/********************************************************************//** Adds the update undo log as the first log in the history list. Removes the update undo log segment from the rseg slot if it is too big for reuse. */ UNIV_INTERN void trx_purge_add_update_undo_to_history( /*=================================*/ trx_t* trx, /*!< in: transaction */ page_t* undo_page, /*!< in: update undo log header page, x-latched */ mtr_t* mtr) /*!< in: mtr */ { trx_undo_t* undo; trx_rseg_t* rseg; trx_rsegf_t* rseg_header; #ifdef UNIV_DEBUG trx_usegf_t* seg_header; #endif /* UNIV_DEBUG */ trx_ulogf_t* undo_header; ulint hist_size; undo = trx->update_undo; ut_ad(undo); rseg = undo->rseg; ut_ad(mutex_own(&(rseg->mutex))); rseg_header = trx_rsegf_get(rseg->space, rseg->zip_size, rseg->page_no, mtr); undo_header = undo_page + undo->hdr_offset; #ifdef UNIV_DEBUG seg_header = undo_page + TRX_UNDO_SEG_HDR; #endif /* UNIV_DEBUG */ if (undo->state != TRX_UNDO_CACHED) { /* The undo log segment will not be reused */ if (undo->id >= TRX_RSEG_N_SLOTS) { fprintf(stderr, "InnoDB: Error: undo->id is %lu\n", (ulong) undo->id); ut_error; } trx_rsegf_set_nth_undo(rseg_header, undo->id, FIL_NULL, mtr); hist_size = mtr_read_ulint(rseg_header + TRX_RSEG_HISTORY_SIZE, MLOG_4BYTES, mtr); ut_ad(undo->size == flst_get_len( seg_header + TRX_UNDO_PAGE_LIST, mtr)); mlog_write_ulint(rseg_header + TRX_RSEG_HISTORY_SIZE, hist_size + undo->size, MLOG_4BYTES, mtr); } /* Add the log as the first in the history list */ flst_add_first(rseg_header + TRX_RSEG_HISTORY, undo_header + TRX_UNDO_HISTORY_NODE, mtr); mutex_enter(&kernel_mutex); trx_sys->rseg_history_len++; mutex_exit(&kernel_mutex); /* Write the trx number to the undo log header */ mlog_write_dulint(undo_header + TRX_UNDO_TRX_NO, trx->no, mtr); /* Write information about delete markings to the undo log header */ if (!undo->del_marks) { mlog_write_ulint(undo_header + TRX_UNDO_DEL_MARKS, FALSE, MLOG_2BYTES, mtr); } if (rseg->last_page_no == FIL_NULL) { rseg->last_page_no = undo->hdr_page_no; rseg->last_offset = undo->hdr_offset; rseg->last_trx_no = trx->no; rseg->last_del_marks = undo->del_marks; } }
/*****************************************************************//** Creates the file page for the dictionary header. This function is called only at the database creation. @return TRUE if succeed */ static ibool dict_hdr_create( /*============*/ mtr_t* mtr) /*!< in: mtr */ { buf_block_t* block; dict_hdr_t* dict_header; ulint root_page_no; ut_ad(mtr); /* Create the dictionary header file block in a new, allocated file segment in the system tablespace */ block = fseg_create(DICT_HDR_SPACE, 0, DICT_HDR + DICT_HDR_FSEG_HEADER, mtr); ut_a(DICT_HDR_PAGE_NO == buf_block_get_page_no(block)); dict_header = dict_hdr_get(mtr); /* Start counting row, table, index, and tree ids from DICT_HDR_FIRST_ID */ mlog_write_dulint(dict_header + DICT_HDR_ROW_ID, ut_dulint_create(0, DICT_HDR_FIRST_ID), mtr); mlog_write_dulint(dict_header + DICT_HDR_TABLE_ID, ut_dulint_create(0, DICT_HDR_FIRST_ID), mtr); mlog_write_dulint(dict_header + DICT_HDR_INDEX_ID, ut_dulint_create(0, DICT_HDR_FIRST_ID), mtr); /* Obsolete, but we must initialize it to 0 anyway. */ mlog_write_dulint(dict_header + DICT_HDR_MIX_ID, ut_dulint_create(0, DICT_HDR_FIRST_ID), mtr); /* Create the B-tree roots for the clustered indexes of the basic system tables */ /*--------------------------*/ root_page_no = btr_create(DICT_CLUSTERED | DICT_UNIQUE, DICT_HDR_SPACE, 0, DICT_TABLES_ID, dict_ind_redundant, mtr); if (root_page_no == FIL_NULL) { return(FALSE); } mlog_write_ulint(dict_header + DICT_HDR_TABLES, root_page_no, MLOG_4BYTES, mtr); /*--------------------------*/ root_page_no = btr_create(DICT_UNIQUE, DICT_HDR_SPACE, 0, DICT_TABLE_IDS_ID, dict_ind_redundant, mtr); if (root_page_no == FIL_NULL) { return(FALSE); } mlog_write_ulint(dict_header + DICT_HDR_TABLE_IDS, root_page_no, MLOG_4BYTES, mtr); /*--------------------------*/ root_page_no = btr_create(DICT_CLUSTERED | DICT_UNIQUE, DICT_HDR_SPACE, 0, DICT_COLUMNS_ID, dict_ind_redundant, mtr); if (root_page_no == FIL_NULL) { return(FALSE); } mlog_write_ulint(dict_header + DICT_HDR_COLUMNS, root_page_no, MLOG_4BYTES, mtr); /*--------------------------*/ root_page_no = btr_create(DICT_CLUSTERED | DICT_UNIQUE, DICT_HDR_SPACE, 0, DICT_INDEXES_ID, dict_ind_redundant, mtr); if (root_page_no == FIL_NULL) { return(FALSE); } mlog_write_ulint(dict_header + DICT_HDR_INDEXES, root_page_no, MLOG_4BYTES, mtr); /*--------------------------*/ root_page_no = btr_create(DICT_CLUSTERED | DICT_UNIQUE, DICT_HDR_SPACE, 0, DICT_FIELDS_ID, dict_ind_redundant, mtr); if (root_page_no == FIL_NULL) { return(FALSE); } mlog_write_ulint(dict_header + DICT_HDR_FIELDS, root_page_no, MLOG_4BYTES, mtr); /*--------------------------*/ return(TRUE); }