Skip to content

Commit 28bbd66

Browse files
author
Krunal Bauskar krunal.bauskar@oracle.com
committed
- WL#6965: Truncate UNDO logs.
- Change the name of from srv_undo_purge_lag to srv_purge_rseg_truncate_frequency in order to reflect what it exactly does. - Beside this there is also change in how this value is used. - On start undo_trunc cache the truncate frequency. - When tablespace is marked for truncate this undo_trunc cached value is set to 1 on completion it is restored back to global value. - Frequency of rseg truncate is min(undo_trunc cached frequency, global value) This ensures when tablespace is marked for truncate we acclerate rseg purge in turn truncate action and make the tablespace/rsegs active asap.
1 parent 713a429 commit 28bbd66

12 files changed

+39
-34
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--innodb_undo_tablespaces=2 --innodb_undo_logs=35 --innodb_max_undo_log_size=10M --innodb_undo_purge_lag=1
1+
--innodb_undo_tablespaces=2 --innodb_undo_logs=35 --innodb_max_undo_log_size=10M --innodb_purge_rseg_truncate_frequency=1

mysql-test/suite/innodb_undo/t/innodb_wl6965.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
--source include/have_undo_tablespaces.inc
1313

1414
# TC check if truncate is completed in given time frame. When
15-
# test is run under valgrind there is no such time assurance.
15+
# test is run under valgrind there is no such time assurance.
1616
--source include/not_valgrind.inc
1717

1818

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--innodb_undo_tablespaces=2 --innodb_undo_logs=35 --innodb_max_undo_log_size=10M --innodb_undo_purge_lag=1
1+
--innodb_undo_tablespaces=2 --innodb_undo_logs=35 --innodb_max_undo_log_size=10M --innodb_purge_rseg_truncate_frequency=1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--innodb_undo_tablespaces=2 --innodb_max_undo_log_size=10M --innodb_undo_purge_lag=1
1+
--innodb_undo_tablespaces=2 --innodb_max_undo_log_size=10M --innodb_purge_rseg_truncate_frequency=1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--innodb_undo_tablespaces=2 --innodb_undo_logs=35 --innodb_max_undo_log_size=10M --innodb_undo_purge_lag=1
1+
--innodb_undo_tablespaces=2 --innodb_undo_logs=35 --innodb_max_undo_log_size=10M --innodb_purge_rseg_truncate_frequency=1

mysql-test/suite/sys_vars/t/innodb_max_undo_log_size_basic.test

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,3 @@ SELECT COUNT(@@SESSION.innodb_max_undo_log_size);
9393
SELECT COUNT(@@GLOBAL.innodb_max_undo_log_size);
9494
--echo 1 Expected
9595

96-
--Error ER_BAD_FIELD_ERROR
97-
SELECT innodb_max_undo_log_size = @@SESSION.innodb_max_undo_log_size;
98-
--echo Expected error 'Readonly variable'
99-
100-

storage/innobase/fil/fil0fil.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2942,7 +2942,6 @@ fil_truncate_tablespace(
29422942
/* Step-2: Invalidate buffer pool pages belonging to the tablespace
29432943
to re-create. Remove all insert buffer entries for the tablespace */
29442944
buf_LRU_flush_or_remove_pages(space_id, BUF_REMOVE_ALL_NO_WRITE, 0);
2945-
ibuf_delete_for_discarded_space(space_id);
29462945

29472946
/* Step-3: Truncate the tablespace and accordingly update
29482947
the fil_space_t handler that is used to access this tablespace. */

storage/innobase/handler/ha_innodb.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16594,10 +16594,11 @@ static MYSQL_SYSVAR_LONGLONG(max_undo_log_size, innobase_max_undo_log_size,
1659416594
10 * 1024 * 1024L,
1659516595
LONGLONG_MAX, 1024 * 1024L);
1659616596

16597-
static MYSQL_SYSVAR_ULONG(undo_purge_lag, srv_undo_purge_lag,
16597+
static MYSQL_SYSVAR_ULONG(purge_rseg_truncate_frequency,
16598+
srv_purge_rseg_truncate_frequency,
1659816599
PLUGIN_VAR_OPCMDARG,
1659916600
"Dictates rate at which UNDO records are purged. Value N means"
16600-
" purge on every Nth iteration of purge invocation",
16601+
" purge rollback segment(s) on every Nth iteration of purge invocation",
1660116602
NULL, NULL, 128, 1, 128, 0);
1660216603

1660316604
/* Alias for innodb_undo_logs, this config variable is deprecated. */
@@ -16939,7 +16940,7 @@ static struct st_mysql_sys_var* innobase_system_variables[]= {
1693916940
MYSQL_SYSVAR(cmp_per_index_enabled),
1694016941
MYSQL_SYSVAR(undo_logs),
1694116942
MYSQL_SYSVAR(max_undo_log_size),
16942-
MYSQL_SYSVAR(undo_purge_lag),
16943+
MYSQL_SYSVAR(purge_rseg_truncate_frequency),
1694316944
MYSQL_SYSVAR(rollback_segments),
1694416945
MYSQL_SYSVAR(undo_directory),
1694516946
MYSQL_SYSVAR(undo_tablespaces),

storage/innobase/include/srv0srv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ extern ulong srv_undo_logs;
239239
extern ulong srv_max_undo_log_size;
240240

241241
/** Rate at which UNDO records should be purged. */
242-
extern ulong srv_undo_purge_lag;
242+
extern ulong srv_purge_rseg_truncate_frequency;
243243

244244
/** UNDO logs not redo logged, these logs reside in the temp tablespace.*/
245245
extern const ulong srv_tmp_undo_logs;

storage/innobase/include/trx0purge.h

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,8 @@ class undo_trunc_t {
399399
m_undo_for_trunc(ULINT_UNDEFINED),
400400
m_rseg_for_trunc(),
401401
m_scan_start(1),
402-
m_purge_lag()
402+
m_purge_rseg_truncate_frequency(
403+
srv_purge_rseg_truncate_frequency)
403404
{
404405
/* Do Nothing. */
405406
}
@@ -422,6 +423,11 @@ class undo_trunc_t {
422423
/* Note: UNDO tablespace ids starts from 1. */
423424
m_scan_start = 1;
424425
}
426+
427+
/* We found a UNDO-tablespace to truncate so set the
428+
local purge rseg truncate frequency to 1. This will help
429+
accelerate the purge action and in turn truncate action. */
430+
m_purge_rseg_truncate_frequency = 1;
425431
}
426432

427433
/** Get the tablespace marked for truncate.
@@ -460,6 +466,11 @@ class undo_trunc_t {
460466
{
461467
m_undo_for_trunc = ULINT_UNDEFINED;
462468
m_rseg_for_trunc.clear();
469+
470+
/* Sync with global value as we are done with
471+
truncate now. */
472+
m_purge_rseg_truncate_frequency =
473+
srv_purge_rseg_truncate_frequency;
463474
}
464475

465476
/** Get the tablespace id to start scanning from.
@@ -502,18 +513,11 @@ class undo_trunc_t {
502513
s_spaces_to_truncate.end() ? false : true);
503514
}
504515

505-
/** Cache Purge Lag.
506-
@param[in] purge_lag original server purge lag */
507-
void set_purge_lag(ulint purge_lag)
508-
{
509-
m_purge_lag = purge_lag;
510-
}
511-
512-
/** Get purge lag.
513-
@return cached purge lag. */
514-
ulint get_purge_lag()
516+
/** Get local rseg purge truncate frequency
517+
@return rseg purge truncate frequency. */
518+
ulint get_rseg_truncate_frequency() const
515519
{
516-
return(m_purge_lag);
520+
return(m_purge_rseg_truncate_frequency);
517521
}
518522

519523
public:
@@ -535,8 +539,11 @@ class undo_trunc_t {
535539
This is to avoid bias selection of one tablespace always. */
536540
ulint m_scan_start;
537541

538-
/** Purge Lag. */
539-
ulint m_purge_lag;
542+
/** Rollback segment(s) purge frequency. This is local
543+
value maintained along with global value. It is set to global
544+
value on start but when tablespace is marked for truncate it is
545+
updated to 1 and then minimum value among 2 is used by purge action. */
546+
ulint m_purge_rseg_truncate_frequency;
540547
};
541548

542549
/** The control structure used in the purge operation */

storage/innobase/srv/srv0srv.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ ulint srv_undo_tablespaces_open = 8;
106106
ulong srv_undo_logs = 1;
107107

108108
/** Rate at which UNDO records should be purged. */
109-
ulong srv_undo_purge_lag = 128;
109+
ulong srv_purge_rseg_truncate_frequency = 128;
110110

111111
/** Maximum size of undo tablespace. */
112112
ulong srv_max_undo_log_size;
@@ -2434,8 +2434,14 @@ srv_do_purge(
24342434
n_pages_purged = trx_purge(
24352435
n_use_threads, srv_purge_batch_size, false);
24362436

2437+
ulint undo_trunc_freq =
2438+
purge_sys->undo_trunc.get_rseg_truncate_frequency();
24372439

2438-
if (!(count++ % srv_undo_purge_lag)) {
2440+
ulint rseg_truncate_frequency =
2441+
ut_min(srv_purge_rseg_truncate_frequency,
2442+
undo_trunc_freq);
2443+
2444+
if (!(count++ % rseg_truncate_frequency)) {
24392445
/* Force a truncate of the history list. */
24402446
n_pages_purged += trx_purge(
24412447
1, srv_purge_batch_size, true);

storage/innobase/trx/trx0purge.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,6 @@ trx_purge_mark_undo_for_truncate(
683683
"UNDO tablespace with space identifier " ULINTPF
684684
" marked for truncate", undo_trunc->get_undo_mark_for_trunc());
685685
#endif /* UNIV_DEBUG */
686-
undo_trunc->set_purge_lag(srv_undo_purge_lag);
687-
srv_undo_purge_lag = 1;
688686

689687
/* Step-3: Iterate over all the rsegs of selected UNDO tablespace
690688
and mark them temporarily unavailable for allocation.*/
@@ -929,7 +927,6 @@ trx_purge_initiate_truncate(
929927

930928
undo_trunc->reset();
931929
undo_trunc_t::clear_trunc_list();
932-
srv_undo_purge_lag = undo_trunc->get_purge_lag();
933930

934931
DBUG_EXECUTE_IF("ib_undo_trunc_trunc_done",
935932
ib_logf(IB_LOG_LEVEL_INFO, "ib_undo_trunc_trunc_done");

0 commit comments

Comments
 (0)