Commit 8d1d38f9 authored by Marko Mäkelä's avatar Marko Mäkelä

Simplify access to the TRX_SYS page

trx_sysf_t: Remove.

trx_sysf_get(): Return the TRX_SYS page, not a pointer within it.

trx_sysf_rseg_get_space(), trx_sysf_rseg_get_page_no():
Remove a parameter, and merge the declaration and definition.
Take the TRX_SYS page as a parameter.

TRX_SYS_N_RSEGS: Correct the comment.

trx_sysf_rseg_find_free(), trx_sys_update_mysql_binlog_offset(),
trx_sys_update_wsrep_checkpoint(): Take the TRX_SYS page as a parameter.

trx_rseg_header_create(): Add a parameter for the TRX_SYS page.

trx_sysf_rseg_set_space(), trx_sysf_rseg_set_page_no(): Remove;
merge to the only caller, trx_rseg_header_create().
parent 54c715ac
......@@ -4849,19 +4849,19 @@ xtrabackup_prepare_func(char** argv)
if (ok) {
mtr_t mtr;
mtr.start();
const trx_sysf_t* sys_header = trx_sysf_get(&mtr);
const buf_block_t* sys_header = trx_sysf_get(&mtr, false);
if (mach_read_from_4(TRX_SYS_MYSQL_LOG_INFO
+ TRX_SYS_MYSQL_LOG_MAGIC_N_FLD
+ sys_header)
+ TRX_SYS + sys_header->frame)
== TRX_SYS_MYSQL_LOG_MAGIC_N) {
ulonglong pos = mach_read_from_8(
TRX_SYS_MYSQL_LOG_INFO
+ TRX_SYS_MYSQL_LOG_OFFSET
+ sys_header);
+ TRX_SYS + sys_header->frame);
const char* name = reinterpret_cast<const char*>(
TRX_SYS_MYSQL_LOG_INFO + TRX_SYS_MYSQL_LOG_NAME
+ sys_header);
+ TRX_SYS + sys_header->frame);
msg("Last binlog file %s, position %llu\n", name, pos);
/* output to xtrabackup_binlog_pos_innodb and
......
......@@ -19715,17 +19715,18 @@ innobase_wsrep_set_checkpoint(
{
DBUG_ASSERT(hton == innodb_hton_ptr);
if (wsrep_is_wsrep_xid(xid)) {
mtr_t mtr;
mtr_start(&mtr);
trx_sysf_t* sys_header = trx_sysf_get(&mtr);
trx_sys_update_wsrep_checkpoint(xid, sys_header, &mtr);
mtr_commit(&mtr);
innobase_flush_logs(hton, false);
return 0;
} else {
return 1;
}
if (wsrep_is_wsrep_xid(xid)) {
mtr_t mtr;
mtr_start(&mtr);
if (buf_block_t* sys_header = trx_sysf_get(&mtr)) {
trx_sys_update_wsrep_checkpoint(xid, sys_header, &mtr);
}
mtr_commit(&mtr);
innobase_flush_logs(hton, false);
return 0;
} else {
return 1;
}
}
static
......
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation.
Copyright (c) 2017, 2018, MariaDB Corporation.
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
......@@ -91,14 +91,16 @@ This function is called only when a new rollback segment is created in
the database.
@param[in] space space id
@param[in] max_size max size in pages
@param[in] rseg_slot_no rseg id == slot number in trx sys
@param[in] rseg_id rollback segment identifier
@param[in,out] sys_header the TRX_SYS page (NULL for temporary rseg)
@param[in,out] mtr mini-transaction
@return page number of the created segment, FIL_NULL if fail */
ulint
trx_rseg_header_create(
ulint space,
ulint max_size,
ulint rseg_slot_no,
ulint rseg_id,
buf_block_t* sys_header,
mtr_t* mtr);
/** Initialize the rollback segments in memory at database startup. */
......
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation.
Copyright (c) 2017, 2018, MariaDB Corporation.
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
......@@ -50,10 +50,13 @@ typedef UT_LIST_BASE_NODE_T(trx_t) trx_ut_list_t;
/** Checks if a page address is the trx sys header page.
@param[in] page_id page id
@return true if trx sys header page */
UNIV_INLINE
inline
bool
trx_sys_hdr_page(
const page_id_t& page_id);
trx_sys_hdr_page(const page_id_t& page_id)
{
return(page_id.space() == TRX_SYS_SPACE
&& page_id.page_no() == TRX_SYS_PAGE_NO);
}
/** Initialize the transaction system main-memory data structures. */
void trx_sys_init_at_db_start();
......@@ -63,79 +66,45 @@ Creates and initializes the transaction system at the database creation. */
void
trx_sys_create_sys_pages(void);
/*==========================*/
/** @return an unallocated rollback segment slot in the TRX_SYS header
/** Find an available rollback segment.
@param[in] sys_header
@return an unallocated rollback segment slot in the TRX_SYS header
@retval ULINT_UNDEFINED if not found */
ulint
trx_sysf_rseg_find_free(mtr_t* mtr);
/**********************************************************************//**
Gets a pointer to the transaction system file copy and x-locks its page.
@return pointer to system file copy, page x-locked */
UNIV_INLINE
trx_sysf_t*
trx_sysf_get(
/*=========*/
mtr_t* mtr); /*!< in: mtr */
/*****************************************************************//**
Gets the space of the nth rollback segment slot in the trx system
file copy.
@return space id */
UNIV_INLINE
ulint
trx_sysf_rseg_get_space(
/*====================*/
trx_sysf_t* sys_header, /*!< in: trx sys file copy */
ulint i, /*!< in: slot index == rseg id */
mtr_t* mtr); /*!< in: mtr */
/*****************************************************************//**
Gets the page number of the nth rollback segment slot in the trx system
file copy.
@return page number, FIL_NULL if slot unused */
UNIV_INLINE
ulint
trx_sysf_rseg_get_page_no(
/*======================*/
trx_sysf_t* sys_header, /*!< in: trx sys file copy */
ulint i, /*!< in: slot index == rseg id */
mtr_t* mtr); /*!< in: mtr */
/*****************************************************************//**
Sets the space id of the nth rollback segment slot in the trx system
file copy. */
UNIV_INLINE
void
trx_sysf_rseg_set_space(
/*====================*/
trx_sysf_t* sys_header, /*!< in: trx sys file copy */
ulint i, /*!< in: slot index == rseg id */
ulint space, /*!< in: space id */
mtr_t* mtr); /*!< in: mtr */
/*****************************************************************//**
Sets the page number of the nth rollback segment slot in the trx system
file copy. */
UNIV_INLINE
void
trx_sysf_rseg_set_page_no(
/*======================*/
trx_sysf_t* sys_header, /*!< in: trx sys file copy */
ulint i, /*!< in: slot index == rseg id */
ulint page_no, /*!< in: page number, FIL_NULL if
the slot is reset to unused */
mtr_t* mtr); /*!< in: mtr */
trx_sys_rseg_find_free(const buf_block_t* sys_header);
/** Request the TRX_SYS page.
@param[in] rw whether to lock the page for writing
@return the TRX_SYS page
@retval NULL if the page cannot be read */
inline
buf_block_t*
trx_sysf_get(mtr_t* mtr, bool rw = true)
{
buf_block_t* block = buf_page_get(
page_id_t(TRX_SYS_SPACE, TRX_SYS_PAGE_NO),
univ_page_size, rw ? RW_X_LATCH : RW_S_LATCH, mtr);
if (block) {
buf_block_dbg_add_level(block, SYNC_TRX_SYS_HEADER);
}
return block;
}
#ifdef UNIV_DEBUG
/* Flag to control TRX_RSEG_N_SLOTS behavior debugging. */
extern uint trx_rseg_n_slots_debug;
#endif
/*****************************************************************//**
Writes a trx id to an index page. In case that the id size changes in
some future version, this function should be used instead of
mach_write_... */
/** Write DB_TRX_ID.
@param[out] db_trx_id the DB_TRX_ID field to be written to
@param[in] id transaction ID */
UNIV_INLINE
void
trx_write_trx_id(
/*=============*/
byte* ptr, /*!< in: pointer to memory where written */
trx_id_t id); /*!< in: id */
trx_write_trx_id(byte* db_trx_id, trx_id_t id)
{
compile_time_assert(DATA_TRX_ID_LEN == 6);
ut_ad(id);
mach_write_to_6(db_trx_id, id);
}
/** Read a transaction identifier.
@return id */
......@@ -143,9 +112,7 @@ inline
trx_id_t
trx_read_trx_id(const byte* ptr)
{
#if DATA_TRX_ID_LEN != 6
# error "DATA_TRX_ID_LEN != 6"
#endif
compile_time_assert(DATA_TRX_ID_LEN == 6);
return(mach_read_from_6(ptr));
}
......@@ -171,23 +138,23 @@ trx_sys_update_mysql_binlog_offset(
/*===============================*/
const char* file_name,/*!< in: MySQL log file name */
int64_t offset, /*!< in: position in that log file */
trx_sysf_t* sys_header, /*!< in: trx sys header */
mtr_t* mtr); /*!< in: mtr */
buf_block_t* sys_header, /*!< in,out: trx sys header */
mtr_t* mtr); /*!< in,out: mini-transaction */
/** Display the MySQL binlog offset info if it is present in the trx
system header. */
void
trx_sys_print_mysql_binlog_offset();
#ifdef WITH_WSREP
/** Update WSREP XID info in sys_header of TRX_SYS_PAGE_NO = 5.
/** Update WSREP XID info in the TRX_SYS page.
@param[in] xid Transaction XID
@param[in,out] sys_header sys_header
@param[in] mtr minitransaction */
@param[in,out] sys_header TRX_SYS page
@param[in,out] mtr mini-transaction */
UNIV_INTERN
void
trx_sys_update_wsrep_checkpoint(
const XID* xid,
trx_sysf_t* sys_header,
buf_block_t* sys_header,
mtr_t* mtr);
/** Read WSREP checkpoint XID from sys header.
......@@ -232,15 +199,50 @@ trx_sys_create_rsegs();
slots */
/*------------------------------------------------------------- @} */
/* Max number of rollback segments: the number of segment specification slots
in the transaction system array; rollback segment id must fit in one (signed)
byte, therefore 128; each slot is currently 8 bytes in size. If you want
to raise the level to 256 then you will need to fix some assertions that
impose the 7 bit restriction. e.g., mach_write_to_3() */
/** The number of rollback segments; rollback segment id must fit in
the 7 bits reserved for it in DB_ROLL_PTR. */
#define TRX_SYS_N_RSEGS 128
/** Maximum number of undo tablespaces (not counting the system tablespace) */
#define TRX_SYS_MAX_UNDO_SPACES (TRX_SYS_N_RSEGS - 1)
/* Rollback segment specification slot offsets */
/** the tablespace ID of an undo log header; starting with
MySQL/InnoDB 5.1.7, this is FIL_NULL if the slot is unused */
#define TRX_SYS_RSEG_SPACE 0
/** the page number of an undo log header, or FIL_NULL if unused */
#define TRX_SYS_RSEG_PAGE_NO 4
/** Size of a rollback segment specification slot */
#define TRX_SYS_RSEG_SLOT_SIZE 8
/** Read the tablespace ID of a rollback segment slot.
@param[in] sys_header TRX_SYS page
@param[in] rseg_id rollback segment identifier
@return undo tablespace id */
inline
uint32_t
trx_sysf_rseg_get_space(const buf_block_t* sys_header, ulint rseg_id)
{
ut_ad(rseg_id < TRX_SYS_N_RSEGS);
return mach_read_from_4(TRX_SYS + TRX_SYS_RSEGS + TRX_SYS_RSEG_SPACE
+ rseg_id * TRX_SYS_RSEG_SLOT_SIZE
+ sys_header->frame);
}
/** Read the page number of a rollback segment slot.
@param[in] sys_header TRX_SYS page
@param[in] rseg_id rollback segment identifier
@return undo page number */
inline
uint32_t
trx_sysf_rseg_get_page_no(const buf_block_t* sys_header, ulint rseg_id)
{
ut_ad(rseg_id < TRX_SYS_N_RSEGS);
return mach_read_from_4(TRX_SYS + TRX_SYS_RSEGS + TRX_SYS_RSEG_PAGE_NO
+ rseg_id * TRX_SYS_RSEG_SLOT_SIZE
+ sys_header->frame);
}
/** Maximum length of MySQL binlog file name, in bytes. */
#define TRX_SYS_MYSQL_LOG_NAME_LEN 512
/** Contents of TRX_SYS_MYSQL_LOG_MAGIC_N_FLD */
......@@ -1018,6 +1020,4 @@ struct trx_sys_t {
/** The transaction system */
extern trx_sys_t trx_sys;
#include "trx0sys.ic"
#endif
/*****************************************************************************
Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation.
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.,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
*****************************************************************************/
/**************************************************//**
@file include/trx0sys.ic
Transaction system
Created 3/26/1996 Heikki Tuuri
*******************************************************/
#include "trx0trx.h"
#include "data0type.h"
#include "srv0srv.h"
#include "mtr0log.h"
/* The typedef for rseg slot in the file copy */
typedef byte trx_sysf_rseg_t;
/* Rollback segment specification slot offsets */
/*-------------------------------------------------------------*/
#define TRX_SYS_RSEG_SPACE 0 /* space where the segment
header is placed; starting with
MySQL/InnoDB 5.1.7, this is
UNIV_UNDEFINED if the slot is unused */
#define TRX_SYS_RSEG_PAGE_NO 4 /* page number where the segment
header is placed; this is FIL_NULL
if the slot is unused */
/*-------------------------------------------------------------*/
/* Size of a rollback segment specification slot */
#define TRX_SYS_RSEG_SLOT_SIZE 8
/** Checks if a page address is the trx sys header page.
@param[in] page_id page id
@return true if trx sys header page */
UNIV_INLINE
bool
trx_sys_hdr_page(
const page_id_t& page_id)
{
return(page_id.space() == TRX_SYS_SPACE
&& page_id.page_no() == TRX_SYS_PAGE_NO);
}
/**********************************************************************//**
Gets a pointer to the transaction system header and x-latches its page.
@return pointer to system header, page x-latched. */
UNIV_INLINE
trx_sysf_t*
trx_sysf_get(
/*=========*/
mtr_t* mtr) /*!< in: mtr */
{
buf_block_t* block = NULL;
trx_sysf_t* header = NULL;
ut_ad(mtr);
block = buf_page_get(page_id_t(TRX_SYS_SPACE, TRX_SYS_PAGE_NO),
univ_page_size, RW_X_LATCH, mtr);
if (block) {
buf_block_dbg_add_level(block, SYNC_TRX_SYS_HEADER);
header = TRX_SYS + buf_block_get_frame(block);
}
return(header);
}
/*****************************************************************//**
Gets the space of the nth rollback segment slot in the trx system
file copy.
@return space id */
UNIV_INLINE
ulint
trx_sysf_rseg_get_space(
/*====================*/
trx_sysf_t* sys_header, /*!< in: trx sys header */
ulint i, /*!< in: slot index == rseg id */
mtr_t* mtr) /*!< in: mtr */
{
ut_ad(sys_header);
ut_ad(i < TRX_SYS_N_RSEGS);
return(mtr_read_ulint(sys_header + TRX_SYS_RSEGS
+ i * TRX_SYS_RSEG_SLOT_SIZE
+ TRX_SYS_RSEG_SPACE, MLOG_4BYTES, mtr));
}
/*****************************************************************//**
Gets the page number of the nth rollback segment slot in the trx system
header.
@return page number, FIL_NULL if slot unused */
UNIV_INLINE
ulint
trx_sysf_rseg_get_page_no(
/*======================*/
trx_sysf_t* sys_header, /*!< in: trx system header */
ulint i, /*!< in: slot index == rseg id */
mtr_t* mtr) /*!< in: mtr */
{
ut_ad(sys_header);
ut_ad(i < TRX_SYS_N_RSEGS);
return(mtr_read_ulint(sys_header + TRX_SYS_RSEGS
+ i * TRX_SYS_RSEG_SLOT_SIZE
+ TRX_SYS_RSEG_PAGE_NO, MLOG_4BYTES, mtr));
}
/*****************************************************************//**
Sets the space id of the nth rollback segment slot in the trx system
file copy. */
UNIV_INLINE
void
trx_sysf_rseg_set_space(
/*====================*/
trx_sysf_t* sys_header, /*!< in: trx sys file copy */
ulint i, /*!< in: slot index == rseg id */
ulint space, /*!< in: space id */
mtr_t* mtr) /*!< in: mtr */
{
ut_ad(sys_header);
ut_ad(i < TRX_SYS_N_RSEGS);
mlog_write_ulint(sys_header + TRX_SYS_RSEGS
+ i * TRX_SYS_RSEG_SLOT_SIZE
+ TRX_SYS_RSEG_SPACE,
space,
MLOG_4BYTES, mtr);
}
/*****************************************************************//**
Sets the page number of the nth rollback segment slot in the trx system
header. */
UNIV_INLINE
void
trx_sysf_rseg_set_page_no(
/*======================*/
trx_sysf_t* sys_header, /*!< in: trx sys header */
ulint i, /*!< in: slot index == rseg id */
ulint page_no, /*!< in: page number, FIL_NULL if the
slot is reset to unused */
mtr_t* mtr) /*!< in: mtr */
{
ut_ad(sys_header);
ut_ad(i < TRX_SYS_N_RSEGS);
mlog_write_ulint(sys_header + TRX_SYS_RSEGS
+ i * TRX_SYS_RSEG_SLOT_SIZE
+ TRX_SYS_RSEG_PAGE_NO,
page_no,
MLOG_4BYTES, mtr);
}
/*****************************************************************//**
Writes a trx id to an index page. In case that the id size changes in
some future version, this function should be used instead of
mach_write_... */
UNIV_INLINE
void
trx_write_trx_id(
/*=============*/
byte* ptr, /*!< in: pointer to memory where written */
trx_id_t id) /*!< in: id */
{
#if DATA_TRX_ID_LEN != 6
# error "DATA_TRX_ID_LEN != 6"
#endif
ut_ad(id > 0);
mach_write_to_6(ptr, id);
}
......@@ -144,8 +144,6 @@ struct trx_savept_t{
/** File objects */
/* @{ */
/** Transaction system header */
typedef byte trx_sysf_t;
/** Rollback segment header */
typedef byte trx_rsegf_t;
/** Undo segment header */
......
......@@ -1058,7 +1058,6 @@ srv_undo_tablespaces_init(bool create_new_db)
/* Step-1: Initialize the tablespace header and rsegs header. */
mtr_t mtr;
trx_sysf_t* sys_header;
mtr_start(&mtr);
/* Turn off REDO logging. We are in server start mode and fixing
......@@ -1067,7 +1066,11 @@ srv_undo_tablespaces_init(bool create_new_db)
as part of the current recovery process. We surely don't need
that as this is fix-up action parallel to REDO logging. */
mtr_set_log_mode(&mtr, MTR_LOG_NO_REDO);
sys_header = trx_sysf_get(&mtr);
buf_block_t* sys_header = trx_sysf_get(&mtr);
if (!sys_header) {
mtr.commit();
return DB_CORRUPTION;
}
for (undo::undo_spaces_t::const_iterator it
= undo::Truncate::s_fix_up_spaces.begin();
......@@ -1082,13 +1085,11 @@ srv_undo_tablespaces_init(bool create_new_db)
mtr_x_lock(fil_space_get_latch(*it, NULL), &mtr);
for (ulint i = 0; i < TRX_SYS_N_RSEGS; i++) {
ulint space_id = trx_sysf_rseg_get_space(
sys_header, i, &mtr);
if (space_id == *it) {
if (trx_sysf_rseg_get_space(sys_header, i)
== *it) {
trx_rseg_header_create(
*it, ULINT_MAX, i, &mtr);
*it, ULINT_MAX, i,
sys_header, &mtr);
}
}
......
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation.
Copyright (c) 2017, 2018, MariaDB Corporation.
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
......@@ -39,25 +39,26 @@ This function is called only when a new rollback segment is created in
the database.
@param[in] space space id
@param[in] max_size max size in pages
@param[in] rseg_slot_no rseg id == slot number in trx sys
@param[in] rseg_id rollback segment identifier
@param[in,out] sys_header the TRX_SYS page (NULL for temporary rseg)
@param[in,out] mtr mini-transaction
@return page number of the created segment, FIL_NULL if fail */
ulint
trx_rseg_header_create(
ulint space,
ulint max_size,
ulint rseg_slot_no,
ulint rseg_id,
buf_block_t* sys_header,
mtr_t* mtr)
{
ulint page_no;
trx_rsegf_t* rsegf;
trx_sysf_t* sys_header;
ulint i;
buf_block_t* block;
ut_ad(mtr);
ut_ad(mtr_memo_contains(mtr, fil_space_get_latch(space, NULL),
MTR_MEMO_X_LOCK));
ut_ad(!sys_header == (space == SRV_TMP_SPACE_ID));
/* Allocate a new file segment for the rollback segment */
block = fseg_create(space, 0, TRX_RSEG + TRX_RSEG_FSEG_HEADER, mtr);
......@@ -85,21 +86,25 @@ trx_rseg_header_create(
flst_init(rsegf + TRX_RSEG_HISTORY, mtr);
/* Reset the undo log slots */
for (i = 0; i < TRX_RSEG_N_SLOTS; i++) {
for (ulint i = 0; i < TRX_RSEG_N_SLOTS; i++) {
trx_rsegf_set_nth_undo(rsegf, i, FIL_NULL, mtr);
}
if (space != SRV_TMP_SPACE_ID) {
if (sys_header) {
/* Add the rollback segment info to the free slot in
the trx system header */
sys_header = trx_sysf_get(mtr);
trx_sysf_rseg_set_space(sys_header, rseg_slot_no, space, mtr);
trx_sysf_rseg_set_page_no(
sys_header, rseg_slot_no, page_no, mtr);
mlog_write_ulint(TRX_SYS + TRX_SYS_RSEGS
+ TRX_SYS_RSEG_SPACE
+ rseg_id * TRX_SYS_RSEG_SLOT_SIZE
+ sys_header->frame,
space, MLOG_4BYTES, mtr);
mlog_write_ulint(TRX_SYS + TRX_SYS_RSEGS
+ TRX_SYS_RSEG_PAGE_NO
+ rseg_id * TRX_SYS_RSEG_SLOT_SIZE
+ sys_header->frame,
page_no, MLOG_4BYTES, mtr);
}
return(page_no);
......@@ -228,21 +233,22 @@ trx_rseg_array_init()
{
mtr_t mtr;
for (ulint i = 0; i < TRX_SYS_N_RSEGS; i++) {
for (ulint rseg_id = 0; rseg_id < TRX_SYS_N_RSEGS; rseg_id++) {
mtr.start();
trx_sysf_t* sys_header = trx_sysf_get(&mtr);
ulint page_no = trx_sysf_rseg_get_page_no(
sys_header, i, &mtr);
if (page_no != FIL_NULL) {
trx_rseg_t* rseg = trx_rseg_mem_create(
i,
trx_sysf_rseg_get_space(sys_header, i, &mtr),
page_no);
ut_ad(rseg->is_persistent());
ut_ad(!trx_sys.rseg_array[rseg->id]);
trx_sys.rseg_array[rseg->id] = rseg;
trx_rseg_mem_restore(rseg, &mtr);
if (const buf_block_t* sys = trx_sysf_get(&mtr, false)) {
const uint32_t page_no = trx_sysf_rseg_get_page_no(
sys, rseg_id);
if (page_no != FIL_NULL) {
trx_rseg_t* rseg = trx_rseg_mem_create(
rseg_id, trx_sysf_rseg_get_space(
sys, rseg_id),
page_no);
ut_ad(rseg->is_persistent());
ut_ad(rseg->id == rseg_id);
ut_ad(!trx_sys.rseg_array[rseg_id]);
trx_sys.rseg_array[rseg_id] = rseg;
trx_rseg_mem_restore(rseg, &mtr);
}
}
mtr.commit();
......@@ -269,23 +275,22 @@ trx_rseg_create(ulint space_id)
mtr_x_lock_space(space_id, &mtr);
ut_ad(space->purpose == FIL_TYPE_TABLESPACE);
ulint slot_no = trx_sysf_rseg_find_free(&mtr);
ulint page_no = slot_no == ULINT_UNDEFINED
? FIL_NULL
: trx_rseg_header_create(space_id, ULINT_MAX, slot_no, &mtr);
if (page_no != FIL_NULL) {
trx_sysf_t* sys_header = trx_sysf_get(&mtr);
ulint id = trx_sysf_rseg_get_space(
sys_header, slot_no, &mtr);
ut_a(id == space_id);
rseg = trx_rseg_mem_create(slot_no, space_id, page_no);
ut_ad(rseg->is_persistent());
ut_ad(!trx_sys.rseg_array[rseg->id]);
trx_sys.rseg_array[rseg->id] = rseg;
trx_rseg_mem_restore(rseg, &mtr);
if (buf_block_t* sys_header = trx_sysf_get(&mtr)) {
ulint rseg_id = trx_sys_rseg_find_free(sys_header);
ulint page_no = rseg_id == ULINT_UNDEFINED
? FIL_NULL
: trx_rseg_header_create(space_id, ULINT_MAX,
rseg_id, sys_header, &mtr);
if (page_no != FIL_NULL) {
ut_ad(trx_sysf_rseg_get_space(sys_header, rseg_id)
== space_id);
rseg = trx_rseg_mem_create(rseg_id, space_id, page_no);
ut_ad(rseg->id == rseg_id);
ut_ad(rseg->is_persistent());
ut_ad(!trx_sys.rseg_array[rseg->id]);
trx_sys.rseg_array[rseg->id] = rseg;
trx_rseg_mem_restore(rseg, &mtr);
}
}
mtr.commit();
......@@ -309,7 +314,7 @@ trx_temp_rseg_create()
ut_ad(space->purpose == FIL_TYPE_TEMPORARY);
ulint page_no = trx_rseg_header_create(
SRV_TMP_SPACE_ID, ULINT_MAX, i, &mtr);
SRV_TMP_SPACE_ID, ULINT_MAX, i, NULL, &mtr);
trx_rseg_t* rseg = trx_rseg_mem_create(
i, SRV_TMP_SPACE_ID, page_no);
ut_ad(!rseg->is_persistent());
......@@ -332,54 +337,39 @@ trx_rseg_get_n_undo_tablespaces(
ulint* space_ids) /*!< out: array of space ids of
UNDO tablespaces */
{
ulint i;
mtr_t mtr;
trx_sysf_t* sys_header;
ulint n_undo_tablespaces = 0;
mtr_start(&mtr);
mtr_t mtr;
mtr.start();
sys_header = trx_sysf_get(&mtr);
buf_block_t* sys_header = trx_sysf_get(&mtr, false);
if (!sys_header) {
mtr.commit();
return 0;
}
for (i = 0; i < TRX_SYS_N_RSEGS; i++) {
ulint page_no;
ulint space;
ulint* end = space_ids;
page_no = trx_sysf_rseg_get_page_no(sys_header, i, &mtr);
for (ulint rseg_id = 0; rseg_id < TRX_SYS_N_RSEGS; rseg_id++) {
uint32_t page_no = trx_sysf_rseg_get_page_no(sys_header,
rseg_id);
if (page_no == FIL_NULL) {
continue;
}
space = trx_sysf_rseg_get_space(sys_header, i, &mtr);
if (space != 0) {
ulint j;
ibool found = FALSE;
for (j = 0; j < n_undo_tablespaces; ++j) {
if (space_ids[j] == space) {
found = TRUE;
break;
}
}
if (!found) {
ut_a(n_undo_tablespaces <= i);
space_ids[n_undo_tablespaces++] = space;
if (ulint space = trx_sysf_rseg_get_space(sys_header,
rseg_id)) {
if (std::find(space_ids, end, space) == end) {
*end++ = space;
}
}
}
mtr_commit(&mtr);
ut_a(n_undo_tablespaces <= TRX_SYS_N_RSEGS);
mtr.commit();
space_ids[n_undo_tablespaces] = ULINT_UNDEFINED;
ut_a(end - space_ids <= TRX_SYS_N_RSEGS);
*end = ULINT_UNDEFINED;
if (n_undo_tablespaces > 0) {
std::sort(space_ids, space_ids + n_undo_tablespaces);
}
std::sort(space_ids, end);
return(n_undo_tablespaces);
return ulint(end - space_ids);
}
This diff is collapsed.
......@@ -1333,11 +1333,11 @@ trx_write_serialisation_history(
MONITOR_INC(MONITOR_TRX_COMMIT_UNDO);
trx_sysf_t* sys_header = trx_sysf_get(mtr);
buf_block_t* block = trx_sysf_get(mtr);
#ifdef WITH_WSREP
/* Update latest MySQL wsrep XID in trx sys header. */
if (wsrep_is_wsrep_xid(trx->xid)) {
trx_sys_update_wsrep_checkpoint(trx->xid, sys_header, mtr);
trx_sys_update_wsrep_checkpoint(trx->xid, block, mtr);
}
#endif /* WITH_WSREP */
......@@ -1351,8 +1351,7 @@ trx_write_serialisation_history(
trx_sys_update_mysql_binlog_offset(
trx->mysql_log_file_name,
trx->mysql_log_offset,
sys_header,
mtr);
block, mtr);
trx->mysql_log_file_name = NULL;
}
......
......@@ -1745,6 +1745,7 @@ trx_undo_truncate_tablespace(
mtr_start(&mtr);
mtr_set_log_mode(&mtr, MTR_LOG_NO_REDO);
mtr_x_lock(fil_space_get_latch(space_id, NULL), &mtr);
buf_block_t* sys_header = trx_sysf_get(&mtr);
for (ulint i = 0; i < undo_trunc->rsegs_size(); ++i) {
trx_rsegf_t* rseg_header;
......@@ -1752,7 +1753,7 @@ trx_undo_truncate_tablespace(
trx_rseg_t* rseg = undo_trunc->get_ith_rseg(i);
rseg->page_no = trx_rseg_header_create(
space_id, ULINT_MAX, rseg->id, &mtr);
space_id, ULINT_MAX, rseg->id, sys_header, &mtr);
rseg_header = trx_rsegf_get_new(space_id, rseg->page_no, &mtr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment