Skip to content

Commit be19f81

Browse files
committed
Merge branch '10.6' into 10.9
2 parents 3476240 + 98de15a commit be19f81

File tree

4 files changed

+64
-64
lines changed

4 files changed

+64
-64
lines changed

storage/innobase/include/trx0sys.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ class trx_sys_t
10531053
void close();
10541054

10551055
/** @return total number of active (non-prepared) transactions */
1056-
ulint any_active_transactions();
1056+
size_t any_active_transactions(size_t *prepared= nullptr);
10571057

10581058

10591059
/**

storage/innobase/srv/srv0srv.cc

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ void srv_master_callback(void*)
15141514
}
15151515

15161516
/** @return whether purge should exit due to shutdown */
1517-
static bool srv_purge_should_exit()
1517+
static bool srv_purge_should_exit(size_t old_history_size)
15181518
{
15191519
ut_ad(srv_shutdown_state <= SRV_SHUTDOWN_CLEANUP);
15201520

@@ -1525,8 +1525,12 @@ static bool srv_purge_should_exit()
15251525
return true;
15261526

15271527
/* Slow shutdown was requested. */
1528+
size_t prepared, active= trx_sys.any_active_transactions(&prepared);
15281529
const size_t history_size= trx_sys.history_size();
1529-
if (history_size)
1530+
1531+
if (!history_size);
1532+
else if (!active && history_size == old_history_size && prepared);
1533+
else
15301534
{
15311535
static time_t progress_time;
15321536
time_t now= time(NULL);
@@ -1543,7 +1547,7 @@ static bool srv_purge_should_exit()
15431547
return false;
15441548
}
15451549

1546-
return !trx_sys.any_active_transactions();
1550+
return !active;
15471551
}
15481552

15491553
/*********************************************************************//**
@@ -1686,7 +1690,7 @@ inline void purge_coordinator_state::do_purge()
16861690
break;
16871691
}
16881692

1689-
if (!srv_purge_should_exit())
1693+
if (!srv_purge_should_exit(history_size))
16901694
goto loop;
16911695
}
16921696

@@ -1882,15 +1886,19 @@ ulint srv_get_task_queue_length()
18821886
/** Shut down the purge threads. */
18831887
void srv_purge_shutdown()
18841888
{
1885-
if (purge_sys.enabled()) {
1886-
if (!srv_fast_shutdown && !opt_bootstrap)
1887-
srv_update_purge_thread_count(innodb_purge_threads_MAX);
1888-
while(!srv_purge_should_exit()) {
1889-
ut_a(!purge_sys.paused());
1890-
srv_wake_purge_thread_if_not_active();
1891-
purge_coordinator_task.wait();
1892-
}
1893-
purge_sys.coordinator_shutdown();
1894-
srv_shutdown_purge_tasks();
1895-
}
1889+
if (purge_sys.enabled())
1890+
{
1891+
if (!srv_fast_shutdown && !opt_bootstrap)
1892+
srv_update_purge_thread_count(innodb_purge_threads_MAX);
1893+
size_t history_size= trx_sys.history_size();
1894+
while (!srv_purge_should_exit(history_size))
1895+
{
1896+
history_size= trx_sys.history_size();
1897+
ut_a(!purge_sys.paused());
1898+
srv_wake_purge_thread_if_not_active();
1899+
purge_coordinator_task.wait();
1900+
}
1901+
purge_sys.coordinator_shutdown();
1902+
srv_shutdown_purge_tasks();
1903+
}
18961904
}

storage/innobase/trx/trx0purge.cc

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -369,19 +369,6 @@ trx_purge_add_undo_to_history(const trx_t* trx, trx_undo_t*& undo, mtr_t* mtr)
369369
undo = NULL;
370370
}
371371

372-
MY_ATTRIBUTE((nonnull, warn_unused_result))
373-
/** Remove undo log header from the history list.
374-
@param[in,out] rseg rollback segment header page
375-
@param[in] log undo log segment header page
376-
@param[in] offset byte offset in the undo log segment header page
377-
@param[in,out] mtr mini-transaction */
378-
static dberr_t trx_purge_remove_log_hdr(buf_block_t *rseg, buf_block_t* log,
379-
uint16_t offset, mtr_t *mtr)
380-
{
381-
return flst_remove(rseg, TRX_RSEG + TRX_RSEG_HISTORY, log,
382-
uint16_t(offset + TRX_UNDO_HISTORY_NODE), mtr);
383-
}
384-
385372
/** Free an undo log segment.
386373
@param block rollback segment header page
387374
@param mtr mini-transaction */
@@ -391,7 +378,7 @@ static void trx_purge_free_segment(buf_block_t *block, mtr_t &mtr)
391378
block->page.frame, &mtr))
392379
{
393380
block->fix();
394-
const page_id_t id{block->page.id()};
381+
ut_d(const page_id_t id{block->page.id()});
395382
mtr.commit();
396383
/* NOTE: If the server is killed after the log that was produced
397384
up to this point was written, and before the log from the mtr.commit()
@@ -403,29 +390,22 @@ static void trx_purge_free_segment(buf_block_t *block, mtr_t &mtr)
403390
log_free_check();
404391
mtr.start();
405392
block->page.lock.x_lock();
406-
if (UNIV_UNLIKELY(block->page.id() != id))
407-
{
408-
block->unfix();
409-
block->page.lock.x_unlock();
410-
block= buf_page_get_gen(id, 0, RW_X_LATCH, nullptr, BUF_GET, &mtr);
411-
if (!block)
412-
return;
413-
}
414-
else
415-
mtr.memo_push(block, MTR_MEMO_PAGE_X_MODIFY);
393+
ut_ad(block->page.id() == id);
394+
mtr.memo_push(block, MTR_MEMO_PAGE_X_MODIFY);
416395
}
417396

418397
while (!fseg_free_step(TRX_UNDO_SEG_HDR + TRX_UNDO_FSEG_HEADER +
419398
block->page.frame, &mtr));
420399
}
421400

422401
/** Remove unnecessary history data from a rollback segment.
423-
@param[in,out] rseg rollback segment
424-
@param[in] limit truncate anything before this
402+
@param rseg rollback segment
403+
@param limit truncate anything before this
404+
@param all whether everything can be truncated
425405
@return error code */
426406
static dberr_t
427-
trx_purge_truncate_rseg_history(trx_rseg_t& rseg,
428-
const purge_sys_t::iterator& limit)
407+
trx_purge_truncate_rseg_history(trx_rseg_t &rseg,
408+
const purge_sys_t::iterator &limit, bool all)
429409
{
430410
fil_addr_t hdr_addr;
431411
mtr_t mtr;
@@ -434,7 +414,6 @@ trx_purge_truncate_rseg_history(trx_rseg_t& rseg,
434414
mtr.start();
435415

436416
dberr_t err;
437-
reget:
438417
buf_block_t *rseg_hdr= rseg.get(&mtr, &err);
439418
if (!rseg_hdr)
440419
{
@@ -469,23 +448,24 @@ trx_purge_truncate_rseg_history(trx_rseg_t& rseg,
469448
goto func_exit;
470449
}
471450

451+
if (!all)
452+
goto func_exit;
453+
472454
fil_addr_t prev_hdr_addr=
473455
flst_get_prev_addr(b->page.frame + hdr_addr.boffset +
474456
TRX_UNDO_HISTORY_NODE);
475457
prev_hdr_addr.boffset= static_cast<uint16_t>(prev_hdr_addr.boffset -
476458
TRX_UNDO_HISTORY_NODE);
477-
err= trx_purge_remove_log_hdr(rseg_hdr, b, hdr_addr.boffset, &mtr);
459+
460+
err= flst_remove(rseg_hdr, TRX_RSEG + TRX_RSEG_HISTORY, b,
461+
uint16_t(hdr_addr.boffset + TRX_UNDO_HISTORY_NODE), &mtr);
478462
if (UNIV_UNLIKELY(err != DB_SUCCESS))
479463
goto func_exit;
480464

481465
rseg_hdr->fix();
482466

483-
if (mach_read_from_2(b->page.frame + hdr_addr.boffset + TRX_UNDO_NEXT_LOG) ||
484-
rseg.is_referenced() ||
485-
rseg.needs_purge > (purge_sys.head.trx_no
486-
? purge_sys.head.trx_no
487-
: purge_sys.tail.trx_no))
488-
/* We cannot free the entire undo page. */;
467+
if (mach_read_from_2(b->page.frame + hdr_addr.boffset + TRX_UNDO_NEXT_LOG))
468+
/* We cannot free the entire undo log segment. */;
489469
else
490470
{
491471
const uint32_t seg_size=
@@ -535,12 +515,7 @@ trx_purge_truncate_rseg_history(trx_rseg_t& rseg,
535515
log_free_check();
536516
mtr.start();
537517
rseg_hdr->page.lock.x_lock();
538-
if (UNIV_UNLIKELY(rseg_hdr->page.id() != rseg.page_id()))
539-
{
540-
rseg_hdr->unfix();
541-
rseg_hdr->page.lock.x_unlock();
542-
goto reget;
543-
}
518+
ut_ad(rseg_hdr->page.id() == rseg.page_id());
544519
mtr.memo_push(rseg_hdr, MTR_MEMO_PAGE_X_MODIFY);
545520

546521
goto loop;
@@ -613,7 +588,10 @@ TRANSACTIONAL_TARGET static void trx_purge_truncate_history()
613588
{
614589
ut_ad(rseg.is_persistent());
615590
rseg.latch.wr_lock(SRW_LOCK_CALL);
616-
if (dberr_t e= trx_purge_truncate_rseg_history(rseg, head))
591+
if (dberr_t e=
592+
trx_purge_truncate_rseg_history(rseg, head,
593+
!rseg.is_referenced() &&
594+
rseg.needs_purge <= head.trx_no))
617595
err= e;
618596
rseg.latch.wr_unlock();
619597
}

storage/innobase/trx/trx0sys.cc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,29 @@ trx_sys_t::close()
343343
}
344344

345345
/** @return total number of active (non-prepared) transactions */
346-
ulint trx_sys_t::any_active_transactions()
346+
size_t trx_sys_t::any_active_transactions(size_t *prepared)
347347
{
348-
uint32_t total_trx= 0;
348+
size_t total_trx= 0, prepared_trx= 0;
349349

350-
trx_sys.trx_list.for_each([&total_trx](const trx_t &trx) {
351-
if (trx.state == TRX_STATE_COMMITTED_IN_MEMORY ||
352-
(trx.state == TRX_STATE_ACTIVE && trx.id))
350+
trx_sys.trx_list.for_each([&](const trx_t &trx) {
351+
switch (trx.state) {
352+
case TRX_STATE_NOT_STARTED:
353+
break;
354+
case TRX_STATE_ACTIVE:
355+
if (!trx.id)
356+
break;
357+
/* fall through */
358+
case TRX_STATE_COMMITTED_IN_MEMORY:
353359
total_trx++;
360+
break;
361+
case TRX_STATE_PREPARED:
362+
case TRX_STATE_PREPARED_RECOVERED:
363+
prepared_trx++;
364+
}
354365
});
355366

367+
if (prepared)
368+
*prepared= prepared_trx;
369+
356370
return total_trx;
357371
}

0 commit comments

Comments
 (0)