diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2018-03-22 14:17:43 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2018-03-29 20:47:29 +0300 |
commit | c577192d6ccd8cfa64320d8fe77ffb549b8237fd (patch) | |
tree | 02fe1707dd74b6692712717b00cb041ac732ee4f | |
parent | 2ac8b1a90709f3484377aae72d4280ee9000e794 (diff) | |
download | mariadb-git-c577192d6ccd8cfa64320d8fe77ffb549b8237fd.tar.gz |
MDEV-12266: fsp_flags_try_adjust(): Remove a lookup
fsp_header_init(): Take fil_space_t* as a parameter.
-rw-r--r-- | mysql-test/suite/innodb/t/101_compatibility.test | 2 | ||||
-rw-r--r-- | mysql-test/suite/innodb/t/table_flags.test | 2 | ||||
-rw-r--r-- | storage/innobase/dict/dict0crea.cc | 14 | ||||
-rw-r--r-- | storage/innobase/fil/fil0fil.cc | 189 | ||||
-rw-r--r-- | storage/innobase/fsp/fsp0fsp.cc | 63 | ||||
-rw-r--r-- | storage/innobase/include/fil0fil.h | 11 | ||||
-rw-r--r-- | storage/innobase/include/fsp0fsp.h | 10 | ||||
-rw-r--r-- | storage/innobase/row/row0trunc.cc | 23 | ||||
-rw-r--r-- | storage/innobase/srv/srv0start.cc | 28 | ||||
-rw-r--r-- | storage/innobase/trx/trx0undo.cc | 26 |
10 files changed, 168 insertions, 200 deletions
diff --git a/mysql-test/suite/innodb/t/101_compatibility.test b/mysql-test/suite/innodb/t/101_compatibility.test index eb3d3b0c014..470f543cd91 100644 --- a/mysql-test/suite/innodb/t/101_compatibility.test +++ b/mysql-test/suite/innodb/t/101_compatibility.test @@ -10,7 +10,7 @@ # buggy 10.1 files (by manually converting the flags in the files). --disable_query_log -call mtr.add_suppression("InnoDB: adjusting FSP_SPACE_FLAGS of tablespace"); +call mtr.add_suppression("InnoDB: adjusting FSP_SPACE_FLAGS of file "); FLUSH TABLES; --enable_query_log let INNODB_PAGE_SIZE=`select @@innodb_page_size`; diff --git a/mysql-test/suite/innodb/t/table_flags.test b/mysql-test/suite/innodb/t/table_flags.test index 2d2a32e9547..6c9b5e7a8cd 100644 --- a/mysql-test/suite/innodb/t/table_flags.test +++ b/mysql-test/suite/innodb/t/table_flags.test @@ -14,7 +14,7 @@ call mtr.add_suppression("InnoDB: Ignoring tablespace for `test`.`td` because it call mtr.add_suppression("InnoDB: Operating system error number .* in a file operation"); call mtr.add_suppression("InnoDB: The error means the system cannot find the path specified"); call mtr.add_suppression("InnoDB: If you are installing InnoDB, remember that you must create directories yourself"); -call mtr.add_suppression("InnoDB: adjusting FSP_SPACE_FLAGS of tablespace"); +call mtr.add_suppression("InnoDB: adjusting FSP_SPACE_FLAGS of file "); FLUSH TABLES; --enable_query_log diff --git a/storage/innobase/dict/dict0crea.cc b/storage/innobase/dict/dict0crea.cc index 454e8608be0..42fe528c888 100644 --- a/storage/innobase/dict/dict0crea.cc +++ b/storage/innobase/dict/dict0crea.cc @@ -402,21 +402,23 @@ dict_build_table_def_step( - page 3 will contain the root of the clustered index of the table we create here. */ - dberr_t err = fil_ibd_create( + dberr_t err; + fil_space_t* space = fil_ibd_create( space_id, table->name.m_name, filepath, fsp_flags, FIL_IBD_FILE_INITIAL_SIZE, - node->mode, node->key_id); + node->mode, node->key_id, &err); ut_free(filepath); - if (err != DB_SUCCESS) { - return(err); + if (!space) { + ut_ad(err != DB_SUCCESS); + return err; } mtr_t mtr; mtr.start(); - mtr.set_named_space(table->space); - fsp_header_init(table->space, FIL_IBD_FILE_INITIAL_SIZE, &mtr); + mtr.set_named_space(space); + fsp_header_init(space, FIL_IBD_FILE_INITIAL_SIZE, &mtr); mtr.commit(); } else { ut_ad(dict_tf_get_rec_format(table->flags) diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 6f7f4fef293..6eaa66ba3c4 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -2485,16 +2485,15 @@ fil_recreate_tablespace( return(DB_ERROR); } - bool found; - const page_size_t& page_size = - fil_space_get_page_size(space_id, &found); - - if (!found) { + fil_space_t* space = fil_space_acquire(space_id); + if (!space) { ib::info() << "Missing .ibd file for table '" << name << "' with tablespace " << space_id; return(DB_ERROR); } + const page_size_t page_size(space->flags); + /* Step-3: Initialize Header. */ if (page_size.is_compressed()) { byte* buf; @@ -2531,7 +2530,7 @@ fil_recreate_tablespace( ib::info() << "Failed to clean header of the" " table '" << name << "' with tablespace " << space_id; - return(err); + goto func_exit; } } @@ -2543,7 +2542,7 @@ fil_recreate_tablespace( /* Initialize the first extent descriptor page and the second bitmap page for the new tablespace. */ - fsp_header_init(space_id, FIL_IBD_FILE_INITIAL_SIZE, &mtr); + fsp_header_init(space, FIL_IBD_FILE_INITIAL_SIZE, &mtr); mtr_commit(&mtr); /* Step-4: Re-Create Indexes to newly re-created tablespace. @@ -2552,7 +2551,7 @@ fil_recreate_tablespace( err = truncate.create_indexes( name, space_id, page_size, flags, format_flags); if (err != DB_SUCCESS) { - return(err); + goto func_exit; } /* Step-5: Write new created pages into ibd file handle and @@ -2562,15 +2561,8 @@ fil_recreate_tablespace( mtr_set_log_mode(&mtr, MTR_LOG_NO_REDO); - mutex_enter(&fil_system.mutex); - - fil_space_t* space = fil_space_get_by_id(space_id); - - mutex_exit(&fil_system.mutex); - - fil_node_t* node = UT_LIST_GET_FIRST(space->chain); - - for (ulint page_no = 0; page_no < node->size; ++page_no) { + for (ulint page_no = 0; + page_no < UT_LIST_GET_FIRST(space->chain)->size; ++page_no) { const page_id_t cur_page_id(space_id, page_no); @@ -2627,7 +2619,8 @@ fil_recreate_tablespace( mtr_commit(&mtr); truncate_t::s_fix_up_active = false; - +func_exit: + fil_space_release(space); return(err); } @@ -3234,27 +3227,24 @@ fil_reinit_space_header_for_table( ibuf_delete_for_discarded_space(id); mutex_enter(&fil_system.mutex); - - fil_space_t* space = fil_space_get_by_id(id); - - /* The following code must change when InnoDB supports - multiple datafiles per tablespace. */ - ut_a(UT_LIST_GET_LEN(space->chain) == 1); - - fil_node_t* node = UT_LIST_GET_FIRST(space->chain); - - space->size = node->size = size; - + fil_space_t* space = fil_space_get_by_id(id); + /* TRUNCATE TABLE is protected by an exclusive table lock. + The table cannot be dropped or the tablespace discarded + while we are holding the transactional table lock. Thus, + there is no need to invoke fil_space_acquire(). */ mutex_exit(&fil_system.mutex); mtr_t mtr; - mtr_start(&mtr); - mtr.set_named_space(id); + mtr.start(); + mtr.set_named_space(space); + mtr_x_lock(&space->latch, &mtr); - fsp_header_init(id, size, &mtr); + ut_ad(UT_LIST_GET_LEN(space->chain) == 1); + space->size = UT_LIST_GET_FIRST(space->chain)->size = size; + fsp_header_init(space, size, &mtr); - mtr_commit(&mtr); + mtr.commit(); } #ifdef UNIV_DEBUG @@ -3676,12 +3666,14 @@ func_exit: @param[in] name Tablespace name in dbname/tablename format. @param[in] path Path and filename of the datafile to create. @param[in] flags Tablespace flags -@param[in] size Initial size of the tablespace file in - pages, must be >= FIL_IBD_FILE_INITIAL_SIZE +@param[in] size Initial size of the tablespace file in pages, +must be >= FIL_IBD_FILE_INITIAL_SIZE @param[in] mode MariaDB encryption mode @param[in] key_id MariaDB encryption key_id -@return DB_SUCCESS or error code */ -dberr_t +@param[out] err DB_SUCCESS or error code +@return the created tablespace +@retval NULL on error */ +fil_space_t* fil_ibd_create( ulint space_id, const char* name, @@ -3689,10 +3681,10 @@ fil_ibd_create( ulint flags, ulint size, fil_encryption_t mode, - uint32_t key_id) + uint32_t key_id, + dberr_t* err) { pfs_os_file_t file; - dberr_t err; byte* buf2; byte* page; bool success; @@ -3708,9 +3700,9 @@ fil_ibd_create( /* Create the subdirectories in the path, if they are not there already. */ - err = os_file_create_subdirs_if_needed(path); - if (err != DB_SUCCESS) { - return(err); + *err = os_file_create_subdirs_if_needed(path); + if (*err != DB_SUCCESS) { + return NULL; } file = os_file_create( @@ -3723,26 +3715,24 @@ fil_ibd_create( if (!success) { /* The following call will print an error message */ - ulint error = os_file_get_last_error(true); - - ib::error() << "Cannot create file '" << path << "'"; - - if (error == OS_FILE_ALREADY_EXISTS) { + switch (os_file_get_last_error(true)) { + case OS_FILE_ALREADY_EXISTS: ib::info() << "The file '" << path << "'" " already exists though the" " corresponding table did not exist" " in the InnoDB data dictionary." " You can resolve the problem by removing" " the file."; - - return(DB_TABLESPACE_EXISTS); - } - - if (error == OS_FILE_DISK_FULL) { - return(DB_OUT_OF_FILE_SPACE); + *err = DB_TABLESPACE_EXISTS; + break; + case OS_FILE_DISK_FULL: + *err = DB_OUT_OF_FILE_SPACE; + break; + default: + *err = DB_ERROR; } - - return(DB_ERROR); + ib::error() << "Cannot create file '" << path << "'"; + return NULL; } const bool is_compressed = FSP_FLAGS_HAS_PAGE_COMPRESSION(flags); @@ -3753,14 +3743,14 @@ fil_ibd_create( } #endif - success = os_file_set_size( + if (!os_file_set_size( path, file, - os_offset_t(size) << UNIV_PAGE_SIZE_SHIFT, is_compressed); - - if (!success) { + os_offset_t(size) << UNIV_PAGE_SIZE_SHIFT, is_compressed)) { + *err = DB_OUT_OF_FILE_SPACE; +err_exit: os_file_close(file); os_file_delete(innodb_data_file_key, path); - return(DB_OUT_OF_FILE_SPACE); + return NULL; } bool punch_hole = os_is_sparse_file_supported(file); @@ -3793,7 +3783,7 @@ fil_ibd_create( buf_flush_init_for_writing(NULL, page, NULL, 0); - err = os_file_write( + *err = os_file_write( request, path, file, page, 0, page_size.physical()); } else { page_zip_des_t page_zip; @@ -3807,43 +3797,33 @@ fil_ibd_create( buf_flush_init_for_writing(NULL, page, &page_zip, 0); - err = os_file_write( + *err = os_file_write( request, path, file, page_zip.data, 0, page_size.physical()); } ut_free(buf2); - if (err != DB_SUCCESS) { - + if (*err != DB_SUCCESS) { ib::error() << "Could not write the first page to" << " tablespace '" << path << "'"; - - os_file_close(file); - os_file_delete(innodb_data_file_key, path); - - return(DB_ERROR); + goto err_exit; } - success = os_file_flush(file); - - if (!success) { + if (!os_file_flush(file)) { ib::error() << "File flush of tablespace '" << path << "' failed"; - os_file_close(file); - os_file_delete(innodb_data_file_key, path); - return(DB_ERROR); + *err = DB_ERROR; + goto err_exit; } if (has_data_dir) { /* Make the ISL file if the IBD file is not in the default location. */ - err = RemoteDatafile::create_link_file(name, path); - if (err != DB_SUCCESS) { - os_file_close(file); - os_file_delete(innodb_data_file_key, path); - return(err); + *err = RemoteDatafile::create_link_file(name, path); + if (*err != DB_SUCCESS) { + goto err_exit; } } @@ -3856,39 +3836,29 @@ fil_ibd_create( space = fil_space_create(name, space_id, flags, FIL_TYPE_TABLESPACE, crypt_data, mode); - - fil_node_t* node = NULL; - - if (space) { - node = fil_node_create_low(path, size, space, false, true); - } - - if (!space || !node) { - if (crypt_data) { - free(crypt_data); - } - - err = DB_ERROR; + if (!space) { + free(crypt_data); + *err = DB_ERROR; } else { - mtr_t mtr; - const fil_node_t* file = UT_LIST_GET_FIRST(space->chain); - + fil_node_t* node = fil_node_create_low(path, size, space, + false, true); + mtr_t mtr; mtr.start(); fil_op_write_log( - MLOG_FILE_CREATE2, space_id, 0, file->name, + MLOG_FILE_CREATE2, space_id, 0, node->name, NULL, space->flags & ~FSP_FLAGS_MEM_MASK, &mtr); - fil_name_write(space, 0, file, &mtr); + fil_name_write(space, 0, node, &mtr); mtr.commit(); node->block_size = block_size; space->punch_hole = punch_hole; - err = DB_SUCCESS; + *err = DB_SUCCESS; } os_file_close(file); - if (err != DB_SUCCESS) { + if (*err != DB_SUCCESS) { if (has_data_dir) { RemoteDatafile::delete_link_file(name); } @@ -3896,7 +3866,7 @@ fil_ibd_create( os_file_delete(innodb_data_file_key, path); } - return(err); + return space; } /** Try to open a single-table tablespace and optionally check that the @@ -4644,9 +4614,16 @@ fsp_flags_try_adjust(ulint space_id, ulint flags) { ut_ad(!srv_read_only_mode); ut_ad(fsp_flags_is_valid(flags, space_id)); - if (!fil_space_get_size(space_id)) { + mutex_enter(&fil_system.mutex); + fil_space_t* space = fil_space_get_space(space_id); + if (!space || !space->size) { + mutex_exit(&fil_system.mutex); return; } + /* This code is executed during server startup while no + connections are allowed. We do not need to protect against + DROP TABLE by fil_space_acquire(). */ + mutex_exit(&fil_system.mutex); mtr_t mtr; mtr.start(); if (buf_block_t* b = buf_page_get( @@ -4656,13 +4633,13 @@ fsp_flags_try_adjust(ulint space_id, ulint flags) /* Suppress the message if only the DATA_DIR flag to differs. */ if ((f ^ flags) & ~(1U << FSP_FLAGS_POS_RESERVED)) { ib::warn() - << "adjusting FSP_SPACE_FLAGS of tablespace " - << space_id - << " from " << ib::hex(f) + << "adjusting FSP_SPACE_FLAGS of file '" + << UT_LIST_GET_FIRST(space->chain)->name + << "' from " << ib::hex(f) << " to " << ib::hex(flags); } if (f != flags) { - mtr.set_named_space(space_id); + mtr.set_named_space(space); mlog_write_ulint(FSP_HEADER_OFFSET + FSP_SPACE_FLAGS + b->frame, flags, MLOG_4BYTES, &mtr); diff --git a/storage/innobase/fsp/fsp0fsp.cc b/storage/innobase/fsp/fsp0fsp.cc index fb1a650b3f5..a348eced948 100644 --- a/storage/innobase/fsp/fsp0fsp.cc +++ b/storage/innobase/fsp/fsp0fsp.cc @@ -720,24 +720,16 @@ fsp_header_init_fields( } /** Initialize a tablespace header. -@param[in] space_id space id -@param[in] size current size in blocks -@param[in,out] mtr mini-transaction */ -void -fsp_header_init(ulint space_id, ulint size, mtr_t* mtr) +@param[in,out] space tablespace +@param[in] size current size in blocks +@param[in,out] mtr mini-transaction */ +void fsp_header_init(fil_space_t* space, ulint size, mtr_t* mtr) { - fsp_header_t* header; - buf_block_t* block; - page_t* page; - - ut_ad(mtr); - - fil_space_t* space = mtr_x_lock_space(space_id, mtr); - - const page_id_t page_id(space_id, 0); + const page_id_t page_id(space->id, 0); const page_size_t page_size(space->flags); - block = buf_page_create(page_id, page_size, mtr); + mtr_x_lock(&space->latch, mtr); + buf_block_t* block = buf_page_create(page_id, page_size, mtr); buf_page_get(page_id, page_size, RW_SX_LATCH, mtr); buf_block_dbg_add_level(block, SYNC_FSP_PAGE); @@ -748,40 +740,41 @@ fsp_header_init(ulint space_id, ulint size, mtr_t* mtr) /* The prior contents of the file page should be ignored */ fsp_init_file_page(space, block, mtr); - page = buf_block_get_frame(block); - mlog_write_ulint(page + FIL_PAGE_TYPE, FIL_PAGE_TYPE_FSP_HDR, + mlog_write_ulint(block->frame + FIL_PAGE_TYPE, FIL_PAGE_TYPE_FSP_HDR, MLOG_2BYTES, mtr); - header = FSP_HEADER_OFFSET + page; - - mlog_write_ulint(header + FSP_SPACE_ID, space_id, MLOG_4BYTES, mtr); - mlog_write_ulint(header + FSP_NOT_USED, 0, MLOG_4BYTES, mtr); - - mlog_write_ulint(header + FSP_SIZE, size, MLOG_4BYTES, mtr); - mlog_write_ulint(header + FSP_FREE_LIMIT, 0, MLOG_4BYTES, mtr); - mlog_write_ulint(header + FSP_SPACE_FLAGS, + mlog_write_ulint(FSP_HEADER_OFFSET + FSP_SPACE_ID + block->frame, + space->id, MLOG_4BYTES, mtr); + mlog_write_ulint(FSP_HEADER_OFFSET + FSP_NOT_USED + block->frame, 0, + MLOG_4BYTES, mtr); + mlog_write_ulint(FSP_HEADER_OFFSET + FSP_SIZE + block->frame, size, + MLOG_4BYTES, mtr); + mlog_write_ulint(FSP_HEADER_OFFSET + FSP_FREE_LIMIT + block->frame, 0, + MLOG_4BYTES, mtr); + mlog_write_ulint(FSP_HEADER_OFFSET + FSP_SPACE_FLAGS + block->frame, space->flags & ~FSP_FLAGS_MEM_MASK, MLOG_4BYTES, mtr); - mlog_write_ulint(header + FSP_FRAG_N_USED, 0, MLOG_4BYTES, mtr); + mlog_write_ulint(FSP_HEADER_OFFSET + FSP_FRAG_N_USED + block->frame, 0, + MLOG_4BYTES, mtr); - flst_init(header + FSP_FREE, mtr); - flst_init(header + FSP_FREE_FRAG, mtr); - flst_init(header + FSP_FULL_FRAG, mtr); - flst_init(header + FSP_SEG_INODES_FULL, mtr); - flst_init(header + FSP_SEG_INODES_FREE, mtr); + flst_init(FSP_HEADER_OFFSET + FSP_FREE + block->frame, mtr); + flst_init(FSP_HEADER_OFFSET + FSP_FREE_FRAG + block->frame, mtr); + flst_init(FSP_HEADER_OFFSET + FSP_FULL_FRAG + block->frame, mtr); + flst_init(FSP_HEADER_OFFSET + FSP_SEG_INODES_FULL + block->frame, mtr); + flst_init(FSP_HEADER_OFFSET + FSP_SEG_INODES_FREE + block->frame, mtr); - mlog_write_ull(header + FSP_SEG_ID, 1, mtr); + mlog_write_ull(FSP_HEADER_OFFSET + FSP_SEG_ID + block->frame, 1, mtr); - fsp_fill_free_list(!is_system_tablespace(space_id), - space, header, mtr); + fsp_fill_free_list(!is_system_tablespace(space->id), + space, FSP_HEADER_OFFSET + block->frame, mtr); /* Write encryption metadata to page 0 if tablespace is encrypted or encryption is disabled by table option. */ if (space->crypt_data && (space->crypt_data->should_encrypt() || space->crypt_data->not_encrypted())) { - space->crypt_data->write_page0(space, page, mtr); + space->crypt_data->write_page0(space, block->frame, mtr); } } diff --git a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h index a78eb5debb1..7f9162c4a6e 100644 --- a/storage/innobase/include/fil0fil.h +++ b/storage/innobase/include/fil0fil.h @@ -1081,8 +1081,10 @@ fil_make_filepath( must be >= FIL_IBD_FILE_INITIAL_SIZE @param[in] mode MariaDB encryption mode @param[in] key_id MariaDB encryption key_id -@return DB_SUCCESS or error code */ -dberr_t +@param[out] err DB_SUCCESS or error code +@return the created tablespace +@retval NULL on error */ +fil_space_t* fil_ibd_create( ulint space_id, const char* name, @@ -1090,8 +1092,9 @@ fil_ibd_create( ulint flags, ulint size, fil_encryption_t mode, - uint32_t key_id) - MY_ATTRIBUTE((nonnull(2), warn_unused_result)); + uint32_t key_id, + dberr_t* err) + MY_ATTRIBUTE((nonnull(2,8), warn_unused_result)); /** Try to adjust FSP_SPACE_FLAGS if they differ from the expectations. (Typically when upgrading from MariaDB 10.1.0..10.1.20.) diff --git a/storage/innobase/include/fsp0fsp.h b/storage/innobase/include/fsp0fsp.h index 9dafd5cdc3a..96f846a71f2 100644 --- a/storage/innobase/include/fsp0fsp.h +++ b/storage/innobase/include/fsp0fsp.h @@ -381,11 +381,11 @@ fsp_header_init_fields( ulint flags); /*!< in: tablespace flags (FSP_SPACE_FLAGS): 0, or table->flags if newer than COMPACT */ /** Initialize a tablespace header. -@param[in] space_id space id -@param[in] size current size in blocks -@param[in,out] mtr mini-transaction */ -void -fsp_header_init(ulint space_id, ulint size, mtr_t* mtr); +@param[in,out] space tablespace +@param[in] size current size in blocks +@param[in,out] mtr mini-transaction */ +void fsp_header_init(fil_space_t* space, ulint size, mtr_t* mtr) + MY_ATTRIBUTE((nonnull)); /**********************************************************************//** Creates a new segment. diff --git a/storage/innobase/row/row0trunc.cc b/storage/innobase/row/row0trunc.cc index 192f4c17b8d..08d19137823 100644 --- a/storage/innobase/row/row0trunc.cc +++ b/storage/innobase/row/row0trunc.cc @@ -2177,23 +2177,22 @@ truncate_t::fixup_tables_in_non_system_tablespace() "residing in file-per-table tablespace with " "id (" << (*it)->m_space_id << ")"; - if (!fil_space_get((*it)->m_space_id)) { + fil_space_t* space = fil_space_get((*it)->m_space_id); + if (!space) { /* Create the database directory for name, if it does not exist yet */ fil_create_directory_for_tablename( (*it)->m_tablename); - err = fil_ibd_create( - (*it)->m_space_id, - (*it)->m_tablename, - (*it)->m_dir_path, - (*it)->m_tablespace_flags, - FIL_IBD_FILE_INITIAL_SIZE, - (*it)->m_encryption, - (*it)->m_key_id); - - if (err != DB_SUCCESS) { + space = fil_ibd_create((*it)->m_space_id, + (*it)->m_tablename, + (*it)->m_dir_path, + (*it)->m_tablespace_flags, + FIL_IBD_FILE_INITIAL_SIZE, + (*it)->m_encryption, + (*it)->m_key_id, &err); + if (!space) { /* If checkpoint is not yet done and table is dropped and then we might still have REDO entries for this table @@ -2207,8 +2206,6 @@ truncate_t::fixup_tables_in_non_system_tablespace() } } - ut_ad(fil_space_get((*it)->m_space_id)); - err = fil_recreate_tablespace( (*it)->m_space_id, (*it)->m_format_flags, diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index af60e846c7e..cbfdb729a87 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -1039,17 +1039,13 @@ srv_undo_tablespaces_init(bool create_new_db) if (create_new_db) { mtr_t mtr; - mtr_start(&mtr); - - /* The undo log tablespace */ for (i = 0; i < n_undo_tablespaces; ++i) { - - fsp_header_init( - undo_tablespace_ids[i], - SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr); + mtr.start(); + fsp_header_init(fil_space_get(undo_tablespace_ids[i]), + SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, + &mtr); + mtr.commit(); } - - mtr_commit(&mtr); } if (!undo::Truncate::s_fix_up_spaces.empty()) { @@ -1077,10 +1073,9 @@ srv_undo_tablespaces_init(bool create_new_db) undo::Truncate::add_space_to_trunc_list(*it); - fsp_header_init( - *it, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr); - - mtr_x_lock(fil_space_get_latch(*it, NULL), &mtr); + fsp_header_init(fil_space_get(*it), + SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, + &mtr); for (ulint i = 0; i < TRX_SYS_N_RSEGS; i++) { if (trx_sysf_rseg_get_space(sys_header, i) @@ -1187,7 +1182,7 @@ srv_open_tmp_tablespace(bool create_new_db) mtr_t mtr; mtr.start(); mtr.set_log_mode(MTR_LOG_NO_REDO); - fsp_header_init(SRV_TMP_SPACE_ID, + fsp_header_init(fil_system.temp_space, srv_tmp_space.get_sum_of_sizes(), &mtr); mtr.commit(); @@ -2129,11 +2124,10 @@ files_checked: ut_a(!srv_read_only_mode); mtr_start(&mtr); - - fsp_header_init(0, sum_of_new_sizes, &mtr); - + ut_ad(fil_system.sys_space->id == 0); compile_time_assert(TRX_SYS_SPACE == 0); compile_time_assert(IBUF_SPACE_ID == 0); + fsp_header_init(fil_system.sys_space, sum_of_new_sizes, &mtr); ulint ibuf_root = btr_create( DICT_CLUSTERED | DICT_IBUF, diff --git a/storage/innobase/trx/trx0undo.cc b/storage/innobase/trx/trx0undo.cc index 88ac0257540..b99425e24fc 100644 --- a/storage/innobase/trx/trx0undo.cc +++ b/storage/innobase/trx/trx0undo.cc @@ -1695,15 +1695,15 @@ trx_undo_truncate_tablespace( undo::Truncate* undo_trunc) { - bool success = true; - ulint space_id = undo_trunc->get_marked_space_id(); + fil_space_t* space = fil_space_acquire( + undo_trunc->get_marked_space_id()); + if (!space) return false; /* Step-1: Truncate tablespace. */ - success = fil_truncate_tablespace( - space_id, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES); - - if (!success) { - return(success); + if (!fil_truncate_tablespace( + space->id, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES)) { + fil_space_release(space); + return false; } /* Step-2: Re-initialize tablespace header. @@ -1712,14 +1712,14 @@ trx_undo_truncate_tablespace( mtr_t mtr; mtr_start(&mtr); mtr_set_log_mode(&mtr, MTR_LOG_NO_REDO); - fsp_header_init(space_id, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr); + fsp_header_init(space, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr); mtr_commit(&mtr); /* Step-3: Re-initialize rollback segment header that resides in truncated tablespaced. */ mtr_start(&mtr); mtr_set_log_mode(&mtr, MTR_LOG_NO_REDO); - mtr_x_lock(fil_space_get_latch(space_id, NULL), &mtr); + mtr_x_lock(&space->latch, &mtr); buf_block_t* sys_header = trx_sysf_get(&mtr); for (ulint i = 0; i < undo_trunc->rsegs_size(); ++i) { @@ -1728,9 +1728,10 @@ trx_undo_truncate_tablespace( trx_rseg_t* rseg = undo_trunc->get_ith_rseg(i); rseg->page_no = trx_rseg_header_create( - space_id, rseg->id, sys_header, &mtr); + space->id, rseg->id, sys_header, &mtr); - rseg_header = trx_rsegf_get_new(space_id, rseg->page_no, &mtr); + rseg_header = trx_rsegf_get_new(space->id, rseg->page_no, + &mtr); /* Before re-initialization ensure that we free the existing structure. There can't be any active transactions. */ @@ -1765,6 +1766,7 @@ trx_undo_truncate_tablespace( rseg->needs_purge = false; } mtr_commit(&mtr); + fil_space_release(space); - return(success); + return true; } |