@@ -455,10 +455,12 @@ trx_purge_free_segment(trx_rseg_t* rseg, fil_addr_t hdr_addr)
455
455
456
456
/* * Remove unnecessary history data from a rollback segment.
457
457
@param[in,out] rseg rollback segment
458
- @param[in] limit truncate offset */
458
+ @param[in] limit truncate anything before this */
459
459
static
460
460
void
461
- trx_purge_truncate_rseg_history (trx_rseg_t * rseg, const purge_iter_t * limit)
461
+ trx_purge_truncate_rseg_history (
462
+ trx_rseg_t & rseg,
463
+ const purge_sys_t ::iterator& limit)
462
464
{
463
465
fil_addr_t hdr_addr;
464
466
fil_addr_t prev_hdr_addr;
@@ -469,48 +471,37 @@ trx_purge_truncate_rseg_history(trx_rseg_t* rseg, const purge_iter_t* limit)
469
471
mtr_t mtr;
470
472
trx_id_t undo_trx_no;
471
473
472
- mtr_start (& mtr);
473
- ut_ad (rseg-> is_persistent ());
474
- mutex_enter (&( rseg-> mutex ) );
474
+ mtr. start ( );
475
+ ut_ad (rseg. is_persistent ());
476
+ mutex_enter (&rseg. mutex );
475
477
476
- rseg_hdr = trx_rsegf_get (rseg-> space , rseg-> page_no , &mtr);
478
+ rseg_hdr = trx_rsegf_get (rseg. space , rseg. page_no , &mtr);
477
479
478
480
hdr_addr = trx_purge_get_log_from_hist (
479
481
flst_get_last (rseg_hdr + TRX_RSEG_HISTORY, &mtr));
480
482
loop:
481
483
if (hdr_addr.page == FIL_NULL) {
482
-
483
- mutex_exit (&(rseg->mutex ));
484
-
485
- mtr_commit (&mtr);
486
-
484
+ func_exit:
485
+ mutex_exit (&rseg.mutex );
486
+ mtr.commit ();
487
487
return ;
488
488
}
489
489
490
- undo_page = trx_undo_page_get (page_id_t (rseg-> space , hdr_addr.page ),
490
+ undo_page = trx_undo_page_get (page_id_t (rseg. space , hdr_addr.page ),
491
491
&mtr);
492
492
493
493
log_hdr = undo_page + hdr_addr.boffset ;
494
494
495
495
undo_trx_no = mach_read_from_8 (log_hdr + TRX_UNDO_TRX_NO);
496
496
497
- if (undo_trx_no >= limit->trx_no ) {
498
-
499
- /* limit space_id should match the rollback segment
500
- space id to avoid freeing of the page belongs to
501
- different rollback segment for the same trx_no. */
502
- if (undo_trx_no == limit->trx_no
503
- && rseg->space == limit->undo_rseg_space ) {
504
-
497
+ if (undo_trx_no >= limit.trx_no ) {
498
+ if (undo_trx_no == limit.trx_no ) {
505
499
trx_undo_truncate_start (
506
- rseg, hdr_addr.page ,
507
- hdr_addr.boffset , limit-> undo_no );
500
+ & rseg, hdr_addr.page ,
501
+ hdr_addr.boffset , limit. undo_no );
508
502
}
509
503
510
- mutex_exit (&(rseg->mutex ));
511
- mtr_commit (&mtr);
512
-
513
- return ;
504
+ goto func_exit;
514
505
}
515
506
516
507
prev_hdr_addr = trx_purge_get_log_from_hist (
@@ -523,24 +514,24 @@ trx_purge_truncate_rseg_history(trx_rseg_t* rseg, const purge_iter_t* limit)
523
514
524
515
/* We can free the whole log segment */
525
516
526
- mutex_exit (&( rseg-> mutex ) );
527
- mtr_commit (& mtr);
517
+ mutex_exit (&rseg. mutex );
518
+ mtr. commit ( );
528
519
529
520
/* calls the trx_purge_remove_log_hdr()
530
521
inside trx_purge_free_segment(). */
531
- trx_purge_free_segment (rseg, hdr_addr);
522
+ trx_purge_free_segment (& rseg, hdr_addr);
532
523
} else {
533
524
/* Remove the log hdr from the rseg history. */
534
525
trx_purge_remove_log_hdr (rseg_hdr, log_hdr, &mtr);
535
526
536
- mutex_exit (&( rseg-> mutex ) );
537
- mtr_commit (& mtr);
527
+ mutex_exit (&rseg. mutex );
528
+ mtr. commit ( );
538
529
}
539
530
540
- mtr_start (& mtr);
541
- mutex_enter (&( rseg-> mutex ) );
531
+ mtr. start ( );
532
+ mutex_enter (&rseg. mutex );
542
533
543
- rseg_hdr = trx_rsegf_get (rseg-> space , rseg-> page_no , &mtr);
534
+ rseg_hdr = trx_rsegf_get (rseg. space , rseg. page_no , &mtr);
544
535
545
536
hdr_addr = prev_hdr_addr;
546
537
@@ -929,7 +920,7 @@ that resides in the tablespace are free.
929
920
static
930
921
void
931
922
trx_purge_initiate_truncate (
932
- purge_iter_t * limit,
923
+ const purge_sys_t ::iterator& limit,
933
924
undo::Truncate* undo_trunc)
934
925
{
935
926
/* Step-1: Early check to findout if any of the the UNDO tablespace
@@ -977,7 +968,7 @@ trx_purge_initiate_truncate(
977
968
undo != NULL && all_free;
978
969
undo = UT_LIST_GET_NEXT (undo_list, undo)) {
979
970
980
- if (limit-> trx_no < undo->trx_id ) {
971
+ if (limit. trx_no < undo->trx_id ) {
981
972
all_free = false ;
982
973
} else {
983
974
cached_undo_size += undo->size ;
@@ -1080,30 +1071,23 @@ trx_purge_initiate_truncate(
1080
1071
/* *
1081
1072
Removes unnecessary history data from rollback segments. NOTE that when this
1082
1073
function is called, the caller must not have any latches on undo log pages!
1083
-
1084
- @param[in] limit truncate limit
1085
1074
*/
1086
- static void trx_purge_truncate_history (purge_iter_t *limit )
1075
+ static void trx_purge_truncate_history ()
1087
1076
{
1088
1077
ut_ad (purge_sys->head <= purge_sys->tail );
1078
+ purge_sys_t ::iterator& head = purge_sys->head .trx_no
1079
+ ? purge_sys->head : purge_sys->tail ;
1089
1080
1090
- /* We play safe and set the truncate limit at most to the purge view
1091
- low_limit number, though this is not necessary */
1092
-
1093
- if (limit->trx_no >= purge_sys->view .low_limit_no ()) {
1094
- limit->trx_no = purge_sys->view .low_limit_no ();
1095
- limit->undo_no = 0 ;
1096
- limit->undo_rseg_space = ULINT_UNDEFINED;
1081
+ if (head.trx_no >= purge_sys->view .low_limit_no ()) {
1082
+ /* This is sometimes necessary. TODO: find out why. */
1083
+ head.trx_no = purge_sys->view .low_limit_no ();
1084
+ head.undo_no = 0 ;
1097
1085
}
1098
1086
1099
- ut_ad (limit->trx_no <= purge_sys->view .low_limit_no ());
1100
-
1101
1087
for (ulint i = 0 ; i < TRX_SYS_N_RSEGS; ++i) {
1102
- trx_rseg_t * rseg = trx_sys.rseg_array [i];
1103
-
1104
- if (rseg != NULL ) {
1105
- ut_a (rseg->id == i);
1106
- trx_purge_truncate_rseg_history (rseg, limit);
1088
+ if (trx_rseg_t * rseg = trx_sys.rseg_array [i]) {
1089
+ ut_ad (rseg->id == i);
1090
+ trx_purge_truncate_rseg_history (*rseg, head);
1107
1091
}
1108
1092
}
1109
1093
@@ -1112,7 +1096,7 @@ static void trx_purge_truncate_history(purge_iter_t *limit)
1112
1096
try and truncate all the UNDO tablespaces. */
1113
1097
for (ulint i = srv_undo_tablespaces_active; i--; ) {
1114
1098
trx_purge_mark_undo_for_truncate (&purge_sys->undo_trunc );
1115
- trx_purge_initiate_truncate (limit , &purge_sys->undo_trunc );
1099
+ trx_purge_initiate_truncate (head , &purge_sys->undo_trunc );
1116
1100
}
1117
1101
}
1118
1102
@@ -1139,7 +1123,6 @@ trx_purge_rseg_get_next_history_log(
1139
1123
1140
1124
purge_sys->tail .trx_no = rseg->last_trx_no + 1 ;
1141
1125
purge_sys->tail .undo_no = 0 ;
1142
- purge_sys->tail .undo_rseg_space = ULINT_UNDEFINED;
1143
1126
purge_sys->next_stored = false ;
1144
1127
1145
1128
mtr_start (&mtr);
@@ -1216,7 +1199,6 @@ trx_purge_read_undo_rec()
1216
1199
ulint offset;
1217
1200
ulint page_no;
1218
1201
ib_uint64_t undo_no;
1219
- ulint undo_rseg_space;
1220
1202
1221
1203
purge_sys->hdr_offset = purge_sys->rseg ->last_offset ;
1222
1204
page_no = purge_sys->hdr_page_no = purge_sys->rseg ->last_page_no ;
@@ -1230,25 +1212,21 @@ trx_purge_read_undo_rec()
1230
1212
1231
1213
offset = page_offset (undo_rec);
1232
1214
undo_no = trx_undo_rec_get_undo_no (undo_rec);
1233
- undo_rseg_space = purge_sys->rseg ->space ;
1234
1215
page_no = page_get_page_no (page_align (undo_rec));
1235
1216
} else {
1236
1217
offset = 0 ;
1237
1218
undo_no = 0 ;
1238
- undo_rseg_space = ULINT_UNDEFINED;
1239
1219
}
1240
1220
1241
1221
mtr.commit ();
1242
1222
} else {
1243
1223
offset = 0 ;
1244
1224
undo_no = 0 ;
1245
- undo_rseg_space = ULINT_UNDEFINED;
1246
1225
}
1247
1226
1248
1227
purge_sys->offset = offset;
1249
1228
purge_sys->page_no = page_no;
1250
1229
purge_sys->tail .undo_no = undo_no;
1251
- purge_sys->tail .undo_rseg_space = undo_rseg_space;
1252
1230
1253
1231
purge_sys->next_stored = true ;
1254
1232
}
@@ -1352,7 +1330,6 @@ trx_purge_get_next_rec(
1352
1330
purge_sys->offset = rec2 - page;
1353
1331
purge_sys->page_no = page_get_page_no (page);
1354
1332
purge_sys->tail .undo_no = trx_undo_rec_get_undo_no (rec2);
1355
- purge_sys->tail .undo_rseg_space = space;
1356
1333
1357
1334
if (undo_page != page) {
1358
1335
/* We advance to a new page of the undo log: */
@@ -1667,10 +1644,7 @@ trx_purge(
1667
1644
ut_a (purge_sys->n_submitted == purge_sys->n_completed );
1668
1645
1669
1646
if (truncate) {
1670
- trx_purge_truncate_history (
1671
- purge_sys->head .trx_no
1672
- ? &purge_sys->head
1673
- : &purge_sys->tail );
1647
+ trx_purge_truncate_history ();
1674
1648
}
1675
1649
1676
1650
MONITOR_INC_VALUE (MONITOR_PURGE_INVOKED, 1 );
0 commit comments