diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 1a65c5f..0cf9216 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -99,9 +99,7 @@ this program; if not, write to the Free Software Foundation, Inc., #include "srv0mon.h" #include "srv0srv.h" #include "srv0start.h" -#ifdef UNIV_DEBUG #include "trx0purge.h" -#endif /* UNIV_DEBUG */ #include "trx0roll.h" #include "trx0sys.h" #include "trx0trx.h" @@ -19064,6 +19062,53 @@ innodb_log_checksums_update( mutex_exit(&log_sys->mutex); } +/** Wakeup purge thread while turning down innodb_max_undo_log_size. +@param[in] thd thread handle +@param[in] var system variable +@param[out] var_ptr current value +@param[in] save immediate result from check function */ +static +void +innobase_max_undo_tablespace_update( + THD* thd, + struct st_mysql_sys_var* var, + void* var_ptr, + const void* save) +{ + ulonglong prev_val = srv_max_undo_log_size; + srv_max_undo_log_size = *static_cast(save); + + if (srv_undo_log_truncate + && srv_max_undo_log_size < prev_val) { + /* Set the flag and wakeup purge thread */ + purge_sys->undo_trunc.set_immediate_check(); + srv_wake_purge_thread_if_not_active(); + } +} + +/** Wakeup purge thread while turning on innodb_undo_log_truncate +@param[in] thd thread handle +@param[in] var system variable +@param[out] var_ptr current value +@param[in] save immediate result from check function */ +static +void +innobase_undo_truncate_update( + THD* thd, + struct st_mysql_sys_var* var, + void* var_ptr, + const void* save) +{ + bool prev_val = srv_undo_log_truncate; + srv_undo_log_truncate = *static_cast(save); + + if (srv_undo_log_truncate && !prev_val) { + /* Set the flag and wakeup purge thread */ + purge_sys->undo_trunc.set_immediate_check(); + srv_wake_purge_thread_if_not_active(); + } +} + static SHOW_VAR innodb_status_variables_export[]= { {"Innodb", (char*) &show_innodb_vars, SHOW_FUNC, SHOW_SCOPE_GLOBAL}, {NullS, NullS, SHOW_LONG, SHOW_SCOPE_GLOBAL} @@ -19751,7 +19796,7 @@ static MYSQL_SYSVAR_ULONGLONG(max_undo_log_size, srv_max_undo_log_size, PLUGIN_VAR_OPCMDARG, "Maximum size of UNDO tablespace in MB (If UNDO tablespace grows" " beyond this size it will be truncated in due course). ", - NULL, NULL, + NULL, innobase_max_undo_tablespace_update, 1024 * 1024 * 1024L, 10 * 1024 * 1024L, ~0ULL, 0); @@ -19766,7 +19811,7 @@ static MYSQL_SYSVAR_ULONG(purge_rseg_truncate_frequency, static MYSQL_SYSVAR_BOOL(undo_log_truncate, srv_undo_log_truncate, PLUGIN_VAR_OPCMDARG, "Enable or Disable Truncate of UNDO tablespace.", - NULL, NULL, FALSE); + NULL, innobase_undo_truncate_update, FALSE); /* Alias for innodb_undo_logs, this config variable is deprecated. */ static MYSQL_SYSVAR_ULONG(rollback_segments, srv_undo_logs, diff --git a/storage/innobase/include/trx0purge.h b/storage/innobase/include/trx0purge.h index 8917169..150e915 100644 --- a/storage/innobase/include/trx0purge.h +++ b/storage/innobase/include/trx0purge.h @@ -332,6 +332,23 @@ namespace undo { != s_fix_up_spaces.end()); } + /* Set the flag to indicate that the purge thread need to check + undo tablespace immediately. */ + void set_immediate_check(void) + { + undo_trunc_check = true; + } + + /** Return the value of flag and then clear it */ + bool need_immediate_check(void) { + bool ret = undo_trunc_check; + + /* Reset the flag */ + undo_trunc_check = false; + + return (ret); + } + /** Get local rseg purge truncate frequency @return rseg purge truncate frequency. */ ulint get_rseg_truncate_frequency() const @@ -377,6 +394,10 @@ namespace undo { /** List of UNDO tablespace(s) to truncate. */ static undo_spaces_t s_spaces_to_truncate; + + /** True if the purge thread need to check undo tablespace + immediately */ + bool undo_trunc_check; public: /** Undo tablespaces that were truncated at startup */ static undo_spaces_t s_fix_up_spaces; diff --git a/storage/innobase/srv/srv0srv.cc b/storage/innobase/srv/srv0srv.cc index 508e86b..352de8c 100644 --- a/storage/innobase/srv/srv0srv.cc +++ b/storage/innobase/srv/srv0srv.cc @@ -2614,7 +2614,8 @@ srv_do_purge( n_pages_purged = trx_purge( n_use_threads, srv_purge_batch_size, - (++count % rseg_truncate_frequency) == 0); + (++count % rseg_truncate_frequency) == 0 + || purge_sys->undo_trunc.need_immediate_check()); *n_total_purged += n_pages_purged;