1
1
/* ****************************************************************************
2
2
3
3
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.
5
5
6
6
This program is free software; you can redistribute it and/or modify it under
7
7
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;
50
50
/* * Checks if a page address is the trx sys header page.
51
51
@param[in] page_id page id
52
52
@return true if trx sys header page */
53
- UNIV_INLINE
53
+ inline
54
54
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
+ }
57
60
58
61
/* * Initialize the transaction system main-memory data structures. */
59
62
void trx_sys_init_at_db_start ();
@@ -63,89 +66,53 @@ Creates and initializes the transaction system at the database creation. */
63
66
void
64
67
trx_sys_create_sys_pages (void );
65
68
/* ==========================*/
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
67
72
@retval ULINT_UNDEFINED if not found */
68
73
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
+ }
123
91
124
92
#ifdef UNIV_DEBUG
125
93
/* Flag to control TRX_RSEG_N_SLOTS behavior debugging. */
126
94
extern uint trx_rseg_n_slots_debug;
127
95
#endif
128
96
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 */
133
100
UNIV_INLINE
134
101
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
+ }
139
108
140
109
/* * Read a transaction identifier.
141
110
@return id */
142
111
inline
143
112
trx_id_t
144
113
trx_read_trx_id (const byte* ptr)
145
114
{
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 );
149
116
return (mach_read_from_6 (ptr));
150
117
}
151
118
@@ -171,23 +138,23 @@ trx_sys_update_mysql_binlog_offset(
171
138
/* ===============================*/
172
139
const char * file_name,/* !< in: MySQL log file name */
173
140
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 */
176
143
/* * Display the MySQL binlog offset info if it is present in the trx
177
144
system header. */
178
145
void
179
146
trx_sys_print_mysql_binlog_offset ();
180
147
#ifdef WITH_WSREP
181
148
182
- /* * Update WSREP XID info in sys_header of TRX_SYS_PAGE_NO = 5 .
149
+ /* * Update WSREP XID info in the TRX_SYS page .
183
150
@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 */
186
153
UNIV_INTERN
187
154
void
188
155
trx_sys_update_wsrep_checkpoint (
189
156
const XID* xid,
190
- trx_sysf_t * sys_header,
157
+ buf_block_t * sys_header,
191
158
mtr_t * mtr);
192
159
193
160
/* * Read WSREP checkpoint XID from sys header.
@@ -232,15 +199,50 @@ trx_sys_create_rsegs();
232
199
slots */
233
200
/* ------------------------------------------------------------- @} */
234
201
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. */
240
204
#define TRX_SYS_N_RSEGS 128
241
205
/* * Maximum number of undo tablespaces (not counting the system tablespace) */
242
206
#define TRX_SYS_MAX_UNDO_SPACES (TRX_SYS_N_RSEGS - 1 )
243
207
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
+
244
246
/* * Maximum length of MySQL binlog file name, in bytes. */
245
247
#define TRX_SYS_MYSQL_LOG_NAME_LEN 512
246
248
/* * Contents of TRX_SYS_MYSQL_LOG_MAGIC_N_FLD */
@@ -1018,6 +1020,4 @@ struct trx_sys_t {
1018
1020
/* * The transaction system */
1019
1021
extern trx_sys_t trx_sys;
1020
1022
1021
- #include " trx0sys.ic"
1022
-
1023
1023
#endif
0 commit comments