byte* mach_dulint_parse_compressed( /*=========================*/ /* out: pointer to end of the stored field, NULL if not complete */ byte* ptr, /* in: pointer to buffer from where to read */ byte* end_ptr,/* in: pointer to end of the buffer */ dulint* val) /* out: read value */ { ulint high; ulint low; ulint size; ut_ad(ptr && end_ptr && val); if (end_ptr < ptr + 5) { return(NULL); } high = mach_read_compressed(ptr); size = mach_get_compressed_size(high); ptr += size; if (end_ptr < ptr + 4) { return(NULL); } low = mach_read_from_4(ptr); *val = ut_dulint_create(high, low); return(ptr + 4); }
read_view_t* read_view_open_now( /*===============*/ /* out, own: read view struct */ dulint cr_trx_id, /* in: trx_id of creating transaction, or (0, 0) used in purge */ mem_heap_t* heap) /* in: memory heap from which allocated */ { read_view_t* view; trx_t* trx; ulint n; ut_ad(mutex_own(&kernel_mutex)); view = read_view_create_low(UT_LIST_GET_LEN(trx_sys->trx_list), heap); view->creator_trx_id = cr_trx_id; view->type = VIEW_NORMAL; view->undo_no = ut_dulint_create(0, 0); /* No future transactions should be visible in the view */ view->low_limit_no = trx_sys->max_trx_id; view->low_limit_id = view->low_limit_no; n = 0; trx = UT_LIST_GET_FIRST(trx_sys->trx_list); /* No active transaction should be visible, except cr_trx */ while (trx) { if (ut_dulint_cmp(trx->id, cr_trx_id) != 0 && (trx->conc_state == TRX_ACTIVE || trx->conc_state == TRX_PREPARED)) { read_view_set_nth_trx_id(view, n, trx->id); n++; /* NOTE that a transaction whose trx number is < trx_sys->max_trx_id can still be active, if it is in the middle of its commit! Note that when a transaction starts, we initialize trx->no to ut_dulint_max. */ if (ut_dulint_cmp(view->low_limit_no, trx->no) > 0) { view->low_limit_no = trx->no; } } trx = UT_LIST_GET_NEXT(trx_list, trx); } view->n_trx_ids = n; if (n > 0) { /* The last active transaction has the smallest id: */ view->up_limit_id = read_view_get_nth_trx_id(view, n - 1); } else { view->up_limit_id = view->low_limit_id; } UT_LIST_ADD_FIRST(view_list, trx_sys->view_list, view); return(view); }
read_view_t* read_view_oldest_copy_or_open_new( /*==============================*/ /* out, own: read view struct */ dulint cr_trx_id, /* in: trx_id of creating transaction, or (0, 0) used in purge*/ mem_heap_t* heap) /* in: memory heap from which allocated */ { read_view_t* old_view; read_view_t* view_copy; ibool needs_insert = TRUE; ulint insert_done = 0; ulint n; ulint i; ut_ad(mutex_own(&kernel_mutex)); old_view = UT_LIST_GET_LAST(trx_sys->view_list); if (old_view == NULL) { return(read_view_open_now(cr_trx_id, heap)); } n = old_view->n_trx_ids; if (ut_dulint_cmp(old_view->creator_trx_id, ut_dulint_create(0,0)) != 0) { n++; } else { needs_insert = FALSE; } view_copy = read_view_create_low(n, heap); /* Insert the id of the creator in the right place of the descending array of ids, if needs_insert is TRUE: */ i = 0; while (i < n) { if (needs_insert && (i >= old_view->n_trx_ids || ut_dulint_cmp(old_view->creator_trx_id, read_view_get_nth_trx_id(old_view, i)) > 0)) { read_view_set_nth_trx_id(view_copy, i, old_view->creator_trx_id); needs_insert = FALSE; insert_done = 1; } else { read_view_set_nth_trx_id(view_copy, i, read_view_get_nth_trx_id( old_view, i - insert_done)); } i++; } view_copy->creator_trx_id = cr_trx_id; view_copy->low_limit_no = old_view->low_limit_no; view_copy->low_limit_id = old_view->low_limit_id; if (n > 0) { /* The last active transaction has the smallest id: */ view_copy->up_limit_id = read_view_get_nth_trx_id( view_copy, n - 1); } else { view_copy->up_limit_id = old_view->up_limit_id; } UT_LIST_ADD_LAST(view_list, trx_sys->view_list, view_copy); return(view_copy); }
/*****************************************************************//** 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); }