mariadb/trx/trx0rseg.c

283 lines
7.4 KiB
C
Raw Normal View History

/*****************************************************************************
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
2005-10-27 07:29:40 +00:00
/******************************************************
Rollback segment
Created 3/26/1996 Heikki Tuuri
*******************************************************/
#include "trx0rseg.h"
#ifdef UNIV_NONINL
#include "trx0rseg.ic"
#endif
#include "trx0undo.h"
#include "fut0lst.h"
#include "srv0srv.h"
#include "trx0purge.h"
/**********************************************************************
Looks for a rollback segment, based on the rollback segment id. */
UNIV_INTERN
2005-10-27 07:29:40 +00:00
trx_rseg_t*
trx_rseg_get_on_id(
/*===============*/
/* out: rollback segment */
ulint id) /* in: rollback segment id */
{
trx_rseg_t* rseg;
rseg = UT_LIST_GET_FIRST(trx_sys->rseg_list);
ut_ad(rseg);
while (rseg->id != id) {
rseg = UT_LIST_GET_NEXT(rseg_list, rseg);
ut_ad(rseg);
}
return(rseg);
}
/********************************************************************
Creates a rollback segment header. This function is called only when
a new rollback segment is created in the database. */
UNIV_INTERN
2005-10-27 07:29:40 +00:00
ulint
trx_rseg_header_create(
/*===================*/
/* out: page number of the created segment,
FIL_NULL if fail */
ulint space, /* in: space id */
ulint zip_size, /* in: compressed page size in bytes
or 0 for uncompressed pages */
2005-10-27 07:29:40 +00:00
ulint max_size, /* in: max size in pages */
ulint* slot_no, /* out: rseg id == slot number in trx sys */
mtr_t* mtr) /* in: mtr */
{
ulint page_no;
trx_rsegf_t* rsegf;
trx_sysf_t* sys_header;
ulint i;
buf_block_t* block;
2005-10-27 07:29:40 +00:00
ut_ad(mtr);
ut_ad(mutex_own(&kernel_mutex));
ut_ad(mtr_memo_contains(mtr, fil_space_get_latch(space, NULL),
MTR_MEMO_X_LOCK));
2005-10-27 07:29:40 +00:00
sys_header = trx_sysf_get(mtr);
*slot_no = trx_sysf_rseg_find_free(mtr);
if (*slot_no == ULINT_UNDEFINED) {
return(FIL_NULL);
}
/* Allocate a new file segment for the rollback segment */
block = fseg_create(space, 0,
TRX_RSEG + TRX_RSEG_FSEG_HEADER, mtr);
2005-10-27 07:29:40 +00:00
if (block == NULL) {
2005-10-27 07:29:40 +00:00
/* No space left */
return(FIL_NULL);
}
buf_block_dbg_add_level(block, SYNC_RSEG_HEADER_NEW);
2005-10-27 07:29:40 +00:00
page_no = buf_block_get_page_no(block);
2005-10-27 07:29:40 +00:00
/* Get the rollback segment file page */
rsegf = trx_rsegf_get_new(space, zip_size, page_no, mtr);
2005-10-27 07:29:40 +00:00
/* Initialize max size field */
mlog_write_ulint(rsegf + TRX_RSEG_MAX_SIZE, max_size,
MLOG_4BYTES, mtr);
2005-10-27 07:29:40 +00:00
/* Initialize the history list */
mlog_write_ulint(rsegf + TRX_RSEG_HISTORY_SIZE, 0, MLOG_4BYTES, mtr);
flst_init(rsegf + TRX_RSEG_HISTORY, mtr);
/* Reset the undo log slots */
for (i = 0; i < TRX_RSEG_N_SLOTS; i++) {
trx_rsegf_set_nth_undo(rsegf, i, FIL_NULL, mtr);
}
/* Add the rollback segment info to the free slot in the trx system
header */
trx_sysf_rseg_set_space(sys_header, *slot_no, space, mtr);
2005-10-27 07:29:40 +00:00
trx_sysf_rseg_set_page_no(sys_header, *slot_no, page_no, mtr);
return(page_no);
}
/***************************************************************************
Creates and initializes a rollback segment object. The values for the
fields are read from the header. The object is inserted to the rseg
list of the trx system object and a pointer is inserted in the rseg
array in the trx system object. */
static
trx_rseg_t*
trx_rseg_mem_create(
/*================*/
/* out, own: rollback segment object */
ulint id, /* in: rollback segment id */
ulint space, /* in: space where the segment placed */
ulint zip_size, /* in: compressed page size in bytes
or 0 for uncompressed pages */
2005-10-27 07:29:40 +00:00
ulint page_no, /* in: page number of the segment header */
mtr_t* mtr) /* in: mtr */
{
trx_rsegf_t* rseg_header;
trx_rseg_t* rseg;
trx_ulogf_t* undo_log_hdr;
fil_addr_t node_addr;
ulint sum_of_undo_sizes;
ulint len;
ut_ad(mutex_own(&kernel_mutex));
rseg = mem_alloc(sizeof(trx_rseg_t));
rseg->id = id;
rseg->space = space;
rseg->zip_size = zip_size;
2005-10-27 07:29:40 +00:00
rseg->page_no = page_no;
mutex_create(&rseg->mutex, SYNC_RSEG);
2005-10-27 07:29:40 +00:00
UT_LIST_ADD_LAST(rseg_list, trx_sys->rseg_list, rseg);
trx_sys_set_nth_rseg(trx_sys, id, rseg);
rseg_header = trx_rsegf_get_new(space, zip_size, page_no, mtr);
2005-10-27 07:29:40 +00:00
rseg->max_size = mtr_read_ulint(rseg_header + TRX_RSEG_MAX_SIZE,
MLOG_4BYTES, mtr);
2005-10-27 07:29:40 +00:00
/* Initialize the undo log lists according to the rseg header */
sum_of_undo_sizes = trx_undo_lists_init(rseg);
rseg->curr_size = mtr_read_ulint(rseg_header + TRX_RSEG_HISTORY_SIZE,
MLOG_4BYTES, mtr)
+ 1 + sum_of_undo_sizes;
2005-10-27 07:29:40 +00:00
len = flst_get_len(rseg_header + TRX_RSEG_HISTORY, mtr);
if (len > 0) {
trx_sys->rseg_history_len += len;
node_addr = trx_purge_get_log_from_hist(
flst_get_last(rseg_header + TRX_RSEG_HISTORY, mtr));
2005-10-27 07:29:40 +00:00
rseg->last_page_no = node_addr.page;
rseg->last_offset = node_addr.boffset;
undo_log_hdr = trx_undo_page_get(rseg->space, rseg->zip_size,
node_addr.page,
mtr) + node_addr.boffset;
rseg->last_trx_no = mtr_read_dulint(
undo_log_hdr + TRX_UNDO_TRX_NO, mtr);
rseg->last_del_marks = mtr_read_ulint(
undo_log_hdr + TRX_UNDO_DEL_MARKS, MLOG_2BYTES, mtr);
2005-10-27 07:29:40 +00:00
} else {
rseg->last_page_no = FIL_NULL;
}
return(rseg);
}
/*************************************************************************
Creates the memory copies for rollback segments and initializes the
rseg list and array in trx_sys at a database startup. */
UNIV_INTERN
2005-10-27 07:29:40 +00:00
void
trx_rseg_list_and_array_init(
/*=========================*/
trx_sysf_t* sys_header, /* in: trx system header */
mtr_t* mtr) /* in: mtr */
{
ulint i;
ulint page_no;
ulint space;
UT_LIST_INIT(trx_sys->rseg_list);
trx_sys->rseg_history_len = 0;
for (i = 0; i < TRX_SYS_N_RSEGS; i++) {
page_no = trx_sysf_rseg_get_page_no(sys_header, i, mtr);
if (page_no == FIL_NULL) {
trx_sys_set_nth_rseg(trx_sys, i, NULL);
} else {
ulint zip_size;
2005-10-27 07:29:40 +00:00
space = trx_sysf_rseg_get_space(sys_header, i, mtr);
zip_size = space ? fil_space_get_zip_size(space) : 0;
trx_rseg_mem_create(i, space, zip_size, page_no, mtr);
2005-10-27 07:29:40 +00:00
}
}
}
/********************************************************************
Creates a new rollback segment to the database. */
UNIV_INTERN
2005-10-27 07:29:40 +00:00
trx_rseg_t*
trx_rseg_create(
/*============*/
/* out: the created segment object, NULL if
fail */
ulint space, /* in: space id */
ulint max_size, /* in: max size in pages */
ulint* id, /* out: rseg id */
mtr_t* mtr) /* in: mtr */
{
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
2008-03-10 11:05:32 +00:00
ulint flags;
ulint zip_size;
2005-10-27 07:29:40 +00:00
ulint page_no;
trx_rseg_t* rseg;
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
2008-03-10 11:05:32 +00:00
mtr_x_lock(fil_space_get_latch(space, &flags), mtr);
zip_size = dict_table_flags_to_zip_size(flags);
2005-10-27 07:29:40 +00:00
mutex_enter(&kernel_mutex);
page_no = trx_rseg_header_create(space, zip_size, max_size, id, mtr);
2005-10-27 07:29:40 +00:00
if (page_no == FIL_NULL) {
mutex_exit(&kernel_mutex);
return(NULL);
}
rseg = trx_rseg_mem_create(*id, space, zip_size, page_no, mtr);
2005-10-27 07:29:40 +00:00
mutex_exit(&kernel_mutex);
return(rseg);
}