Skip to content

Commit 8d1d38f

Browse files
committed
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().
1 parent 54c715a commit 8d1d38f

File tree

11 files changed

+282
-476
lines changed

11 files changed

+282
-476
lines changed

extra/mariabackup/xtrabackup.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4849,19 +4849,19 @@ xtrabackup_prepare_func(char** argv)
48494849
if (ok) {
48504850
mtr_t mtr;
48514851
mtr.start();
4852-
const trx_sysf_t* sys_header = trx_sysf_get(&mtr);
4852+
const buf_block_t* sys_header = trx_sysf_get(&mtr, false);
48534853

48544854
if (mach_read_from_4(TRX_SYS_MYSQL_LOG_INFO
48554855
+ TRX_SYS_MYSQL_LOG_MAGIC_N_FLD
4856-
+ sys_header)
4856+
+ TRX_SYS + sys_header->frame)
48574857
== TRX_SYS_MYSQL_LOG_MAGIC_N) {
48584858
ulonglong pos = mach_read_from_8(
48594859
TRX_SYS_MYSQL_LOG_INFO
48604860
+ TRX_SYS_MYSQL_LOG_OFFSET
4861-
+ sys_header);
4861+
+ TRX_SYS + sys_header->frame);
48624862
const char* name = reinterpret_cast<const char*>(
48634863
TRX_SYS_MYSQL_LOG_INFO + TRX_SYS_MYSQL_LOG_NAME
4864-
+ sys_header);
4864+
+ TRX_SYS + sys_header->frame);
48654865
msg("Last binlog file %s, position %llu\n", name, pos);
48664866

48674867
/* output to xtrabackup_binlog_pos_innodb and

storage/innobase/handler/ha_innodb.cc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19715,17 +19715,18 @@ innobase_wsrep_set_checkpoint(
1971519715
{
1971619716
DBUG_ASSERT(hton == innodb_hton_ptr);
1971719717

19718-
if (wsrep_is_wsrep_xid(xid)) {
19719-
mtr_t mtr;
19720-
mtr_start(&mtr);
19721-
trx_sysf_t* sys_header = trx_sysf_get(&mtr);
19722-
trx_sys_update_wsrep_checkpoint(xid, sys_header, &mtr);
19723-
mtr_commit(&mtr);
19724-
innobase_flush_logs(hton, false);
19725-
return 0;
19726-
} else {
19727-
return 1;
19728-
}
19718+
if (wsrep_is_wsrep_xid(xid)) {
19719+
mtr_t mtr;
19720+
mtr_start(&mtr);
19721+
if (buf_block_t* sys_header = trx_sysf_get(&mtr)) {
19722+
trx_sys_update_wsrep_checkpoint(xid, sys_header, &mtr);
19723+
}
19724+
mtr_commit(&mtr);
19725+
innobase_flush_logs(hton, false);
19726+
return 0;
19727+
} else {
19728+
return 1;
19729+
}
1972919730
}
1973019731

1973119732
static

storage/innobase/include/trx0rseg.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2017, MariaDB Corporation.
4+
Copyright (c) 2017, 2018, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
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
9191
the database.
9292
@param[in] space space id
9393
@param[in] max_size max size in pages
94-
@param[in] rseg_slot_no rseg id == slot number in trx sys
94+
@param[in] rseg_id rollback segment identifier
95+
@param[in,out] sys_header the TRX_SYS page (NULL for temporary rseg)
9596
@param[in,out] mtr mini-transaction
9697
@return page number of the created segment, FIL_NULL if fail */
9798
ulint
9899
trx_rseg_header_create(
99100
ulint space,
100101
ulint max_size,
101-
ulint rseg_slot_no,
102+
ulint rseg_id,
103+
buf_block_t* sys_header,
102104
mtr_t* mtr);
103105

104106
/** Initialize the rollback segments in memory at database startup. */

storage/innobase/include/trx0sys.h

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2017, MariaDB Corporation.
4+
Copyright (c) 2017, 2018, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
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;
5050
/** Checks if a page address is the trx sys header page.
5151
@param[in] page_id page id
5252
@return true if trx sys header page */
53-
UNIV_INLINE
53+
inline
5454
bool
55-
trx_sys_hdr_page(
56-
const page_id_t& page_id);
55+
trx_sys_hdr_page(const page_id_t& page_id)
56+
{
57+
return(page_id.space() == TRX_SYS_SPACE
58+
&& page_id.page_no() == TRX_SYS_PAGE_NO);
59+
}
5760

5861
/** Initialize the transaction system main-memory data structures. */
5962
void trx_sys_init_at_db_start();
@@ -63,89 +66,53 @@ Creates and initializes the transaction system at the database creation. */
6366
void
6467
trx_sys_create_sys_pages(void);
6568
/*==========================*/
66-
/** @return an unallocated rollback segment slot in the TRX_SYS header
69+
/** Find an available rollback segment.
70+
@param[in] sys_header
71+
@return an unallocated rollback segment slot in the TRX_SYS header
6772
@retval ULINT_UNDEFINED if not found */
6873
ulint
69-
trx_sysf_rseg_find_free(mtr_t* mtr);
70-
/**********************************************************************//**
71-
Gets a pointer to the transaction system file copy and x-locks its page.
72-
@return pointer to system file copy, page x-locked */
73-
UNIV_INLINE
74-
trx_sysf_t*
75-
trx_sysf_get(
76-
/*=========*/
77-
mtr_t* mtr); /*!< in: mtr */
78-
/*****************************************************************//**
79-
Gets the space of the nth rollback segment slot in the trx system
80-
file copy.
81-
@return space id */
82-
UNIV_INLINE
83-
ulint
84-
trx_sysf_rseg_get_space(
85-
/*====================*/
86-
trx_sysf_t* sys_header, /*!< in: trx sys file copy */
87-
ulint i, /*!< in: slot index == rseg id */
88-
mtr_t* mtr); /*!< in: mtr */
89-
/*****************************************************************//**
90-
Gets the page number of the nth rollback segment slot in the trx system
91-
file copy.
92-
@return page number, FIL_NULL if slot unused */
93-
UNIV_INLINE
94-
ulint
95-
trx_sysf_rseg_get_page_no(
96-
/*======================*/
97-
trx_sysf_t* sys_header, /*!< in: trx sys file copy */
98-
ulint i, /*!< in: slot index == rseg id */
99-
mtr_t* mtr); /*!< in: mtr */
100-
/*****************************************************************//**
101-
Sets the space id of the nth rollback segment slot in the trx system
102-
file copy. */
103-
UNIV_INLINE
104-
void
105-
trx_sysf_rseg_set_space(
106-
/*====================*/
107-
trx_sysf_t* sys_header, /*!< in: trx sys file copy */
108-
ulint i, /*!< in: slot index == rseg id */
109-
ulint space, /*!< in: space id */
110-
mtr_t* mtr); /*!< in: mtr */
111-
/*****************************************************************//**
112-
Sets the page number of the nth rollback segment slot in the trx system
113-
file copy. */
114-
UNIV_INLINE
115-
void
116-
trx_sysf_rseg_set_page_no(
117-
/*======================*/
118-
trx_sysf_t* sys_header, /*!< in: trx sys file copy */
119-
ulint i, /*!< in: slot index == rseg id */
120-
ulint page_no, /*!< in: page number, FIL_NULL if
121-
the slot is reset to unused */
122-
mtr_t* mtr); /*!< in: mtr */
74+
trx_sys_rseg_find_free(const buf_block_t* sys_header);
75+
/** Request the TRX_SYS page.
76+
@param[in] rw whether to lock the page for writing
77+
@return the TRX_SYS page
78+
@retval NULL if the page cannot be read */
79+
inline
80+
buf_block_t*
81+
trx_sysf_get(mtr_t* mtr, bool rw = true)
82+
{
83+
buf_block_t* block = buf_page_get(
84+
page_id_t(TRX_SYS_SPACE, TRX_SYS_PAGE_NO),
85+
univ_page_size, rw ? RW_X_LATCH : RW_S_LATCH, mtr);
86+
if (block) {
87+
buf_block_dbg_add_level(block, SYNC_TRX_SYS_HEADER);
88+
}
89+
return block;
90+
}
12391

12492
#ifdef UNIV_DEBUG
12593
/* Flag to control TRX_RSEG_N_SLOTS behavior debugging. */
12694
extern uint trx_rseg_n_slots_debug;
12795
#endif
12896

129-
/*****************************************************************//**
130-
Writes a trx id to an index page. In case that the id size changes in
131-
some future version, this function should be used instead of
132-
mach_write_... */
97+
/** Write DB_TRX_ID.
98+
@param[out] db_trx_id the DB_TRX_ID field to be written to
99+
@param[in] id transaction ID */
133100
UNIV_INLINE
134101
void
135-
trx_write_trx_id(
136-
/*=============*/
137-
byte* ptr, /*!< in: pointer to memory where written */
138-
trx_id_t id); /*!< in: id */
102+
trx_write_trx_id(byte* db_trx_id, trx_id_t id)
103+
{
104+
compile_time_assert(DATA_TRX_ID_LEN == 6);
105+
ut_ad(id);
106+
mach_write_to_6(db_trx_id, id);
107+
}
139108

140109
/** Read a transaction identifier.
141110
@return id */
142111
inline
143112
trx_id_t
144113
trx_read_trx_id(const byte* ptr)
145114
{
146-
#if DATA_TRX_ID_LEN != 6
147-
# error "DATA_TRX_ID_LEN != 6"
148-
#endif
115+
compile_time_assert(DATA_TRX_ID_LEN == 6);
149116
return(mach_read_from_6(ptr));
150117
}
151118

@@ -171,23 +138,23 @@ trx_sys_update_mysql_binlog_offset(
171138
/*===============================*/
172139
const char* file_name,/*!< in: MySQL log file name */
173140
int64_t offset, /*!< in: position in that log file */
174-
trx_sysf_t* sys_header, /*!< in: trx sys header */
175-
mtr_t* mtr); /*!< in: mtr */
141+
buf_block_t* sys_header, /*!< in,out: trx sys header */
142+
mtr_t* mtr); /*!< in,out: mini-transaction */
176143
/** Display the MySQL binlog offset info if it is present in the trx
177144
system header. */
178145
void
179146
trx_sys_print_mysql_binlog_offset();
180147
#ifdef WITH_WSREP
181148

182-
/** Update WSREP XID info in sys_header of TRX_SYS_PAGE_NO = 5.
149+
/** Update WSREP XID info in the TRX_SYS page.
183150
@param[in] xid Transaction XID
184-
@param[in,out] sys_header sys_header
185-
@param[in] mtr minitransaction */
151+
@param[in,out] sys_header TRX_SYS page
152+
@param[in,out] mtr mini-transaction */
186153
UNIV_INTERN
187154
void
188155
trx_sys_update_wsrep_checkpoint(
189156
const XID* xid,
190-
trx_sysf_t* sys_header,
157+
buf_block_t* sys_header,
191158
mtr_t* mtr);
192159

193160
/** Read WSREP checkpoint XID from sys header.
@@ -232,15 +199,50 @@ trx_sys_create_rsegs();
232199
slots */
233200
/*------------------------------------------------------------- @} */
234201

235-
/* Max number of rollback segments: the number of segment specification slots
236-
in the transaction system array; rollback segment id must fit in one (signed)
237-
byte, therefore 128; each slot is currently 8 bytes in size. If you want
238-
to raise the level to 256 then you will need to fix some assertions that
239-
impose the 7 bit restriction. e.g., mach_write_to_3() */
202+
/** The number of rollback segments; rollback segment id must fit in
203+
the 7 bits reserved for it in DB_ROLL_PTR. */
240204
#define TRX_SYS_N_RSEGS 128
241205
/** Maximum number of undo tablespaces (not counting the system tablespace) */
242206
#define TRX_SYS_MAX_UNDO_SPACES (TRX_SYS_N_RSEGS - 1)
243207

208+
/* Rollback segment specification slot offsets */
209+
210+
/** the tablespace ID of an undo log header; starting with
211+
MySQL/InnoDB 5.1.7, this is FIL_NULL if the slot is unused */
212+
#define TRX_SYS_RSEG_SPACE 0
213+
/** the page number of an undo log header, or FIL_NULL if unused */
214+
#define TRX_SYS_RSEG_PAGE_NO 4
215+
/** Size of a rollback segment specification slot */
216+
#define TRX_SYS_RSEG_SLOT_SIZE 8
217+
218+
/** Read the tablespace ID of a rollback segment slot.
219+
@param[in] sys_header TRX_SYS page
220+
@param[in] rseg_id rollback segment identifier
221+
@return undo tablespace id */
222+
inline
223+
uint32_t
224+
trx_sysf_rseg_get_space(const buf_block_t* sys_header, ulint rseg_id)
225+
{
226+
ut_ad(rseg_id < TRX_SYS_N_RSEGS);
227+
return mach_read_from_4(TRX_SYS + TRX_SYS_RSEGS + TRX_SYS_RSEG_SPACE
228+
+ rseg_id * TRX_SYS_RSEG_SLOT_SIZE
229+
+ sys_header->frame);
230+
}
231+
232+
/** Read the page number of a rollback segment slot.
233+
@param[in] sys_header TRX_SYS page
234+
@param[in] rseg_id rollback segment identifier
235+
@return undo page number */
236+
inline
237+
uint32_t
238+
trx_sysf_rseg_get_page_no(const buf_block_t* sys_header, ulint rseg_id)
239+
{
240+
ut_ad(rseg_id < TRX_SYS_N_RSEGS);
241+
return mach_read_from_4(TRX_SYS + TRX_SYS_RSEGS + TRX_SYS_RSEG_PAGE_NO
242+
+ rseg_id * TRX_SYS_RSEG_SLOT_SIZE
243+
+ sys_header->frame);
244+
}
245+
244246
/** Maximum length of MySQL binlog file name, in bytes. */
245247
#define TRX_SYS_MYSQL_LOG_NAME_LEN 512
246248
/** Contents of TRX_SYS_MYSQL_LOG_MAGIC_N_FLD */
@@ -1018,6 +1020,4 @@ struct trx_sys_t {
10181020
/** The transaction system */
10191021
extern trx_sys_t trx_sys;
10201022

1021-
#include "trx0sys.ic"
1022-
10231023
#endif

0 commit comments

Comments
 (0)