Skip to content

Commit 0ef91c8

Browse files
committed
Simplify InnoDB transaction system initialization.
trx_rseg_mem_create(): Remove the parameter rseg_array. Update trx_sys->rseg_array directly.
1 parent 1417839 commit 0ef91c8

File tree

1 file changed

+24
-51
lines changed

1 file changed

+24
-51
lines changed

storage/innobase/trx/trx0rseg.cc

Lines changed: 24 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,14 @@ array in the trx system object.
167167
@param[in] space space where the segment is placed
168168
@param[in] page_no page number of the segment header
169169
@param[in] page_size page size
170-
@param[out] rseg_array add rseg reference to this central array
171-
@param[in,out] mtr mini-transaction
172-
@return own: rollback segment object */
170+
@param[in,out] mtr mini-transaction */
173171
static
174-
trx_rseg_t*
172+
void
175173
trx_rseg_mem_create(
176174
ulint id,
177175
ulint space,
178176
ulint page_no,
179177
const page_size_t& page_size,
180-
trx_rseg_t** rseg_array,
181178
mtr_t* mtr)
182179
{
183180
ulint len;
@@ -207,7 +204,7 @@ trx_rseg_mem_create(
207204
UT_LIST_INIT(rseg->insert_undo_list, &trx_undo_t::undo_list);
208205
UT_LIST_INIT(rseg->insert_undo_cached, &trx_undo_t::undo_list);
209206

210-
*((trx_rseg_t**) rseg_array + rseg->id) = rseg;
207+
trx_sys->rseg_array[id] = rseg;
211208

212209
rseg_header = trx_rsegf_get_new(space, page_no, page_size, mtr);
213210

@@ -256,28 +253,25 @@ trx_rseg_mem_create(
256253
} else {
257254
rseg->last_page_no = FIL_NULL;
258255
}
259-
260-
return(rseg);
261256
}
262257

263258
/** Initialize the rollback segments in memory at database startup. */
264259
void
265260
trx_rseg_array_init()
266261
{
262+
mtr_t mtr;
263+
267264
for (ulint i = 0; i < TRX_SYS_N_RSEGS; i++) {
265+
ut_a(!trx_rseg_get_on_id(i));
268266
ulint page_no;
269267

270-
mtr_t mtr;
271268
mtr.start();
272269
trx_sysf_t* sys_header = trx_sysf_get(&mtr);
273270

274271
page_no = trx_sysf_rseg_get_page_no(sys_header, i, &mtr);
275272

276273
if (page_no != FIL_NULL) {
277274
ulint space;
278-
trx_rseg_t* rseg = NULL;
279-
280-
ut_a(!trx_rseg_get_on_id(i));
281275

282276
space = trx_sysf_rseg_get_space(sys_header, i, &mtr);
283277

@@ -289,17 +283,10 @@ trx_rseg_array_init()
289283

290284
ut_ad(found);
291285

292-
trx_rseg_t** rseg_array =
293-
static_cast<trx_rseg_t**>(trx_sys->rseg_array);
294-
295-
rseg = trx_rseg_mem_create(
296-
i, space, page_no, page_size,
297-
rseg_array, &mtr);
298-
299-
ut_a(rseg->id == i);
300-
} else {
301-
ut_a(trx_sys->rseg_array[i] == NULL);
286+
trx_rseg_mem_create(
287+
i, space, page_no, page_size, &mtr);
302288
}
289+
303290
mtr.commit();
304291
}
305292
}
@@ -315,10 +302,8 @@ trx_rseg_create(
315302
0 means next free slots. */
316303
{
317304
mtr_t mtr;
318-
ulint slot_no;
319-
trx_rseg_t* rseg = NULL;
320305

321-
mtr_start(&mtr);
306+
mtr.start();
322307

323308
/* To obey the latching order, acquire the file space
324309
x-latch before the trx_sys->mutex. */
@@ -329,46 +314,34 @@ trx_rseg_create(
329314
case FIL_TYPE_IMPORT:
330315
ut_ad(0);
331316
case FIL_TYPE_TEMPORARY:
332-
mtr_set_log_mode(&mtr, MTR_LOG_NO_REDO);
317+
mtr.set_log_mode(MTR_LOG_NO_REDO);
333318
break;
334319
case FIL_TYPE_TABLESPACE:
335320
break;
336321
}
337322

338-
slot_no = trx_sysf_rseg_find_free(
323+
page_size_t page_size(space->flags);
324+
ulint slot_no = trx_sysf_rseg_find_free(
339325
&mtr, space->purpose == FIL_TYPE_TEMPORARY, nth_free_slot);
340-
341-
if (slot_no != ULINT_UNDEFINED) {
342-
ulint id;
343-
ulint page_no;
344-
trx_sysf_t* sys_header;
345-
page_size_t page_size(space->flags);
346-
347-
page_no = trx_rseg_header_create(
326+
ulint page_no = slot_no == ULINT_UNDEFINED
327+
? FIL_NULL
328+
: trx_rseg_header_create(
348329
space_id, page_size, ULINT_MAX, slot_no, &mtr);
349330

350-
if (page_no == FIL_NULL) {
351-
mtr_commit(&mtr);
331+
if (page_no != FIL_NULL) {
332+
trx_sysf_t* sys_header = trx_sysf_get(&mtr);
352333

353-
return(rseg);
354-
}
355-
356-
sys_header = trx_sysf_get(&mtr);
357-
358-
id = trx_sysf_rseg_get_space(sys_header, slot_no, &mtr);
334+
ulint id = trx_sysf_rseg_get_space(
335+
sys_header, slot_no, &mtr);
359336
ut_a(id == space_id || trx_sys_is_noredo_rseg_slot(slot_no));
360337

361-
trx_rseg_t** rseg_array =
362-
((trx_rseg_t**) trx_sys->rseg_array);
363-
364-
rseg = trx_rseg_mem_create(
365-
slot_no, space_id, page_no, page_size,
366-
rseg_array, &mtr);
338+
trx_rseg_mem_create(
339+
slot_no, space_id, page_no, page_size, &mtr);
367340
}
368341

369-
mtr_commit(&mtr);
342+
mtr.commit();
370343

371-
return(rseg);
344+
return(page_no == FIL_NULL ? NULL : trx_sys->rseg_array[slot_no]);
372345
}
373346

374347
/********************************************************************

0 commit comments

Comments
 (0)