#include <my_service_manager.h> /* The following is the maximum allowed duration of a lock wait. */
ulong srv_fatal_semaphore_wait_threshold = DEFAULT_SRV_FATAL_SEMAPHORE_TIMEOUT;
/* How much data manipulation language (DML) statements need to be delayed,
in microseconds, in order to reduce the lagging of the purge thread. */
ulint srv_dml_needed_delay;
constchar* srv_main_thread_op_info = "";
/** Prefix used by MySQL to indicate pre-5.1 table name encoding */ constchar srv_mysql50_table_name_prefix[10] = "#mysql50#";
/* Server parameters which are read from the initfile */
/* The following three are dir paths which are catenated before file
names, where the file name itself may also contain a path */
char* srv_data_home;
/** Rollback files directory, can be absolute. */ char* srv_undo_dir;
/** The number of tablespaces to use for rollback segments. */
uint srv_undo_tablespaces;
/** The number of UNDO tablespaces that are open and ready to use. */
uint32_t srv_undo_tablespaces_open;
/** The number of UNDO tablespaces that are active (hosting some rollback segment).Itisquitepossiblethatsomeofthetablespacesdoesn'thost
any of the rollback-segment based on configuration used. */
uint32_t srv_undo_tablespaces_active;
/** Enable or Disable Truncate of UNDO tablespace. Note:IfenabledthenUNDOtablespacewillbeselectedfortruncate. WhileServerwaitsforundo-tablespacetotruncateifuserdisables it,truncateactioniscompletedbutnonewtablespaceismarked
for truncate (action is never aborted). */
my_bool srv_undo_log_truncate;
/** Maximum size of undo tablespace. */ unsignedlonglong srv_max_undo_log_size;
/** Set if InnoDB must operate in read-only mode. We don't do any recoveryandopenalltablesinROmodeinsteadofRWmode.Wedon't
sync the max trx id to disk either. */
my_bool srv_read_only_mode; /** store to its own file each table created by an user; data
dictionary tables are in the system tablespace 0 */
my_bool srv_file_per_table; /** Set if innodb_read_only is set or innodb_force_recovery
is SRV_FORCE_NO_UNDO_LOG_SCAN or greater. */ bool high_level_read_only;
/** Sort buffer size in index creation */
ulong srv_sort_buf_size; /** Maximum modification log file size for online index creation */ unsignedlonglong srv_online_max_size;
/* If this flag is TRUE, then we will use the native aio of the OS(providedwecompiledInnobasewithitin),otherwisewewill usesimulatedaiowebuildbelowwiththreads.
Currently we support native aio on windows and linux */
my_bool srv_use_native_aio; #ifdef __linux__ /* This enum is defined which linux native io method to use */
ulong srv_linux_aio_method; #endif
my_bool srv_numa_interleave; /** copy of innodb_use_atomic_writes; @see innodb_init_params() */
my_bool srv_use_atomic_writes; /** innodb_compression_algorithm; used with page compression */
ulong innodb_compression_algorithm;
/** The InnoDB redo log file size, or 0 when changing the redo log format
at startup (while disallowing writes to the redo log). */
ulonglong srv_log_file_size; /** innodb_flush_log_at_trx_commit */
ulong srv_flush_log_at_trx_commit; /** innodb_flush_log_at_timeout */
uint srv_flush_log_at_timeout; /** innodb_page_size */
ulong srv_page_size; /** log2 of innodb_page_size; @see innodb_init_params() */
uint32_t srv_page_size_shift;
/** innodb_adaptive_flushing; try to flush dirty pages so as to avoid
IO bursts at the checkpoints. */
my_bool srv_adaptive_flushing;
/** innodb_flush_sync; whether to ignore io_capacity at log checkpoints */
my_bool srv_flush_sync;
/** common thread pool*/
tpool::thread_pool* srv_thread_pool;
/** Maximum number of times allowed to conditionally acquire
mutex before switching to blocking wait on the mutex */ #define MAX_MUTEX_NOWAIT 2
/** Check whether the number of failed nonblocking mutex acquisitionattemptsexceedsmaximumallowedvalue.Ifso, srv_printf_innodb_monitor()willrequestmutexacquisition
with mysql_mutex_lock(), which will wait until it gets the mutex. */ #define MUTEX_NOWAIT(mutex_skipped) ((mutex_skipped) < MAX_MUTEX_NOWAIT)
/** Dump this % of each buffer pool during BP dump */
ulong srv_buf_pool_dump_pct; /** Abort load after this amount of pages */ #ifdef UNIV_DEBUG
ulong srv_buf_pool_load_pages_abort = LONG_MAX; #endif /** Lock table size in bytes */
ulint srv_lock_table_size = ULINT_MAX;
/** the value of innodb_checksum_algorithm */
ulong srv_checksum_algorithm;
/** innodb_random_read_ahead */
my_bool srv_random_read_ahead; /** innodb_read_ahead_threshold; the number of pages that must be present inthebuffercacheandaccessedsequentiallyforInnoDBtotriggera
readahead request. */
ulong srv_read_ahead_threshold;
/** copy of innodb_open_files; @see innodb_init_params() */
ulint srv_max_n_open_files;
/* The InnoDB main thread tries to keep the ratio of modified pages inthebufferpooltoalldatabasepagesinthebufferpoolsmallerthan thefollowingnumber.Butitisnotguaranteedthatthevaluestaysbelow
that during a time of heavy update/insert activity. */
/** innodb_adaptive_flushing_lwm; the percentage of log capacity at
which adaptive flushing, if enabled, will kick in. */ double srv_adaptive_flushing_lwm;
/** innodb_flushing_avg_loops; number of iterations over which
adaptive flushing is averaged */
ulong srv_flushing_avg_loops;
/** innodb_purge_threads; the number of purge tasks to use */
uint srv_n_purge_threads;
/** innodb_purge_batch_size, in pages */
ulong srv_purge_batch_size;
/** innodb_stats_method decides how InnoDB treats NULLvaluewhencollectingstatistics.Bydefault,itissetto
SRV_STATS_NULLS_EQUAL(0), ie. all NULL value are treated equal */
ulong srv_innodb_stats_method;
srv_stats_t srv_stats;
/* structure to pass status variables to MySQL */
export_var_t export_vars;
/** Normally 0. When nonzero, skip some phases of crash recovery, startingfromSRV_FORCE_IGNORE_CORRUPT,sothatdatacanberecovered bySELECTormysqldump.Whenthisisnonzero,wedonotallowanyuser
modifications to the data. */
ulong srv_force_recovery;
/** innodb_print_all_deadlocks; whether to print all user-level
transactions deadlocks to the error log */
my_bool srv_print_all_deadlocks;
/** innodb_fast_shutdown=1 skips the purge of transaction history. innodb_fast_shutdown=2effectivelycrashestheserver(nologcheckpoint). innodb_fast_shutdown=3isacleanshutdownthatskipstherollback
of active transaction (to be done on restart). */
uint srv_fast_shutdown;
/** copy of innodb_status_file; generate a innodb_status.<pid> file */
ibool srv_innodb_status;
/** innodb_stats_transient_sample_pages; Whenestimatingnumberofdifferentkeyvaluesinanindex,sample thismanyindexpages,thereare2waystocalculatestatistics: *persistentstatsthatarecalculatedbyANALYZETABLEandsaved intheinnodbdatabase. *quicktransientstats,thatareusedifpersistentstatsforthegiven
table/index are not found in the innodb database */
uint32_t srv_stats_transient_sample_pages; /** innodb_stats_persistent */
my_bool srv_stats_persistent; /** innodb_stats_include_delete_marked */
my_bool srv_stats_include_delete_marked; /** innodb_stats_persistent_sample_pages */
uint32_t srv_stats_persistent_sample_pages; /** innodb_stats_auto_recalc */
my_bool srv_stats_auto_recalc;
/** innodb_stats_modified_counter; The number of rows modified before
we calculate new statistics (default 0 = current limits) */ unsignedlonglong srv_stats_modified_counter;
/** innodb_stats_traditional; enable traditional statistic calculation
based on number of configured pages */
my_bool srv_stats_sample_traditional;
/** Number of initialized rollback segments for persistent undo log */
ulong srv_available_undo_logs;
/** Current mode of operation */ enum srv_operation_mode srv_operation;
/** whether this is the server's first start after mariabackup --prepare */ bool srv_start_after_restore;
/* Set the following to 0 if you want InnoDB to write messages on
stderr on startup/shutdown. Not enabled on the embedded server. */
ibool srv_print_verbose_log;
my_bool srv_print_innodb_monitor;
my_bool srv_print_innodb_lock_monitor; /** innodb_force_primary_key; whether to disallow CREATE TABLE without
PRIMARY KEY */
my_bool srv_force_primary_key;
/** innodb_alter_copy_bulk; Whether to allow bulk insert operation
inside InnoDB alter for copy algorithm; */
my_bool innodb_alter_copy_bulk;
/** Key version to encrypt the temporary tablespace */
my_bool innodb_encrypt_temporary_tables;
/** Mutex for locking srv_monitor_file */
mysql_mutex_t srv_monitor_file_mutex;
/** Temporary file for innodb monitor output */
FILE* srv_monitor_file; /** Mutex for locking srv_misc_tmpfile */
mysql_mutex_t srv_misc_tmpfile_mutex; /** Temporary file for miscellaneous diagnostic output */
FILE* srv_misc_tmpfile;
/* The following counts are used by the srv_master_callback. */
/** Iterations of the loop bounded by 'srv_active' label. */
ulint srv_main_active_loops; /** Iterations of the loop bounded by the 'srv_idle' label. */
ulint srv_main_idle_loops; /** Log writes involving flush. */
ulint srv_log_writes_and_flush;
/* This is only ever touched by the master thread. It records the timewhenthelastflushoflogfilehashappened.Themaster threadensuresthatweflushthelogfilesatleastonceper
second. */ static time_t srv_last_log_flush_time;
/** Buffer pool dump status frequence in percentages */
ulong srv_buf_dump_status_frequency;
Thethreadtablecontainsinformationofthecurrentstatusofeach threadexistinginthesystem,andalsotheeventsemaphoresusedin suspendingthemasterthreadandutilitythreadswhentheyhavenothing todo.Thethreadtablecanbeseenasananaloguetotheprocesstable
in a traditional Unix implementation. */
/** The server system struct */ struct srv_sys_t{
mysql_mutex_t tasks_mutex; /*!< variable protecting the
tasks queue */
UT_LIST_BASE_NODE_T(que_thr_t)
tasks; /*!< task queue */
srv_stats_t::ulint_ctr_1_t
activity_count; /*!< For tracking server
activity */
};
static srv_sys_t srv_sys;
/* Structuresharedbytimerandcoordinator_callback. Noprotectionnecessarysincetimerandtaskneverrun inparallel(beinginthesametaskgroupofsize1).
*/ struct purge_coordinator_state
{ /** Snapshot of the last history length before the purge call.*/
size_t history_size;
Atomic_counter<int> m_running; public: inlinevoid do_purge(trx_t *trx);
};
static purge_coordinator_state purge_state;
/** threadpool timer for srv_monitor_task() */
std::unique_ptr<tpool::timer> srv_monitor_timer;
/** The buffer pool dump/load file name */ char* srv_buf_dump_filename;
/** Boolean config knobs that tell InnoDB to dump the buffer pool at shutdown
and/or load it during startup. */ char srv_buffer_pool_dump_at_shutdown = TRUE; char srv_buffer_pool_load_at_startup = TRUE;
#ifdef HAVE_PSI_STAGE_INTERFACE /** Performance schema stage event for monitoring ALTER TABLE progress
in ha_innobase::commit_inplace_alter_table(). */
PSI_stage_info srv_stage_alter_table_end
= {0, "alter table (end)", PSI_FLAG_STAGE_PROGRESS};
/** Performance schema stage event for monitoring ALTER TABLE progress
row_merge_insert_index_tuples(). */
PSI_stage_info srv_stage_alter_table_insert
= {0, "alter table (insert)", PSI_FLAG_STAGE_PROGRESS};
/* Initialize some INFORMATION SCHEMA internal structures */
trx_i_s_cache_init();
}
/*********************************************************************//**
Frees the data structures created in srv_init(). */ void
srv_free(void) /*==========*/
{ if (!need_srv_free) { return;
}
/*********************************************************************//**
Boots the InnoDB server. */ void srv_boot()
{ #ifndef NO_ELISION if (transactional_lock_enabled())
sql_print_information("InnoDB: Using transactional memory"); #endif
buf_dblwr.init();
srv_thread_pool_init();
trx_pool_init();
btr_search_sys_create();
srv_init();
}
/******************************************************************//**
Refreshes the values used to calculate per-second averages. */ staticvoid srv_refresh_innodb_monitor_stats(time_t current_time)
{
mysql_mutex_lock(&srv_innodb_monitor_mutex);
if (difftime(current_time, srv_last_monitor_time) < 60) { /* We refresh InnoDB Monitor values so that averages are
printed from at most 60 last seconds */
mysql_mutex_unlock(&srv_innodb_monitor_mutex); return;
}
/******************************************************************//**
Outputs to a file the output of the InnoDB Monitor.
@returnFALSEifnot all information printed
due to failure to obtain necessary mutex */
ibool
srv_printf_innodb_monitor( /*======================*/
FILE* file, /*!< in: output stream */
ibool nowait, /*!< in: whether to wait for lock_sys.latch */
ulint* trx_start_pos, /*!< out: file position of the start of
the list of active transactions */
ulint* trx_end) /*!< out: file position of the end of
the list of active transactions */
{ double time_elapsed;
time_t current_time;
ibool ret;
mysql_mutex_lock(&srv_innodb_monitor_mutex);
current_time = time(NULL);
/* We add 0.001 seconds to time_elapsed to prevent division byzeroiftwousershappentocallSHOWENGINEINNODBSTATUSatthe
same time */
ut_print_timestamp(file);
fprintf(file, " INNODB MONITOR OUTPUT\n" "=====================================\n" "Per second averages calculated from the last %lu seconds\n",
(ulong) time_elapsed);
/* This section is intentionally left blank, for tools like "innotop" */
fputs("----------\n" "SEMAPHORES\n" "----------\n", file); /* End of intentionally blank section */
/* Conceptually, srv_innodb_monitor_mutex has a very high latching orderlevel,whiledict_foreign_err_mutexhasaverylowlevel. Thereforewecanreservethelattermutexherewithout
a danger of a deadlock of threads. */
/* Only if lock_print_info_summary proceeds correctly, beforewecallthelock_print_info_all_transactions toprintallthelockinformation.IMPORTANTNOTE:This
function acquires exclusive lock_sys.latch on success. */
ret = lock_print_info_summary(file, nowait);
if (ret) { if (trx_start_pos) { long t = ftell(file); if (t < 0) {
*trx_start_pos = ULINT_UNDEFINED;
} else {
*trx_start_pos = (ulint) t;
}
}
/* NOTE: The following function will release the lock_sys.latch
that lock_print_info_summary() acquired. */
lock_print_info_all_transactions(file);
if (trx_end) { long t = ftell(file); if (t < 0) {
*trx_end = ULINT_UNDEFINED;
} else {
*trx_end = (ulint) t;
}
}
}
/******************************************************************//**
Function to pass InnoDB status variables to MySQL */ void
srv_export_innodb_status(void) /*==========================*/
{
ut_ad(!srv_read_only_mode || recv_sys.rpo);
fil_crypt_stat_t crypt_stat;
if (!recv_sys.rpo) {
fil_crypt_total_stat(&crypt_stat);
}
innodb_io_slots_stats(tpool::aio_opcode::AIO_PREAD,
&export_vars.async_read_stats);
innodb_io_slots_stats(tpool::aio_opcode::AIO_PWRITE,
&export_vars.async_write_stats);
/** Periodic task which prints the info output by various InnoDB monitors.*/ void srv_monitor_task(void*)
{ /* number of successive fatal timeouts observed */ static lsn_t old_lsn = recv_sys.lsn;
ut_ad(!srv_read_only_mode);
/* Try to track a strange bug reported by Harald Fuchs and others,
where the lsn seems to decrease at times */
/** Wake up the purge threads if there is work to do. */ void purge_sys_t::wake_if_not_active()
{ if (enabled() && !paused() && !purge_state.m_running &&
(srv_undo_log_truncate || trx_sys.history_exists()) &&
++purge_state.m_running == 1)
srv_thread_pool->submit_task(&purge_coordinator_task);
}
/** @return whether the purge tasks are active */ bool purge_sys_t::running()
{ return purge_coordinator_task.is_running();
}
/** Resume purge in data dictionary tables */ void purge_sys_t::resume_SYS(void *)
{
ut_d(auto paused=) purge_sys.m_FTS_paused.fetch_sub(PAUSED_SYS);
ut_ad(paused >= PAUSED_SYS);
}
/** Resume purge at UNLOCK TABLES after FLUSH TABLES FOR EXPORT */ void purge_sys_t::resume()
{ if (!enabled())
{ /* Shutdown must have been initiated during FLUSH TABLES FOR EXPORT. */
ut_ad(!srv_undo_sources); return;
}
ut_ad(!srv_read_only_mode);
ut_ad(!recv_sys.rpo);
ut_ad(srv_force_recovery < SRV_FORCE_NO_BACKGROUND);
purge_coordinator_task.enable();
latch.wr_lock(SRW_LOCK_CALL);
int32_t paused= m_paused--;
ut_a(paused);
/*******************************************************************//**
Get current server activity count.
@return activity count. */
ulint
srv_get_activity_count(void) /*========================*/
{ return(srv_sys.activity_count);
}
/** Check if srv_inc_activity_count() has been called. @paramactivity_countcopyofsrv_sys.activity_count
@return whether the activity_count had changed */ staticbool srv_check_activity(ulint *activity_count)
{
ulint new_activity_count= srv_sys.activity_count; if (new_activity_count != *activity_count)
{
*activity_count= new_activity_count; returntrue;
}
returnfalse;
}
/********************************************************************//**
The master thread is tasked to ensure that flush of log file happens
once every second in the background. This is to ensure that not more
than one second of trxs are lost in case of crash when
innodb_flush_logs_at_trx_commit != 1 */ staticvoid srv_sync_log_buffer_in_background()
{
time_t current_time = time(NULL);
/*********************************************************************//**
Fetch and execute a task from the work queue.
@returntrueif a task was executed */ staticbool srv_task_execute(THD *thd)
{
ut_ad(!srv_read_only_mode);
ut_ad(!recv_sys.rpo);
ut_ad(srv_force_recovery < SRV_FORCE_NO_BACKGROUND);
do
{ if (UNIV_UNLIKELY(srv_purge_thread_count_changed))
{ /* Read the fresh value of srv_n_purge_threads, reset
the changed flag. Both are protected by purge_thread_count_mtx. */
{
std::lock_guard<std::mutex> lk(purge_thread_count_mtx);
n_threads= srv_n_purge_threads;
srv_purge_thread_count_changed= false;
}
}
first_loop:
ut_ad(n_threads);
history_size= trx_sys.history_size();
if (!history_size)
{
no_history:
srv_dml_needed_delay= 0;
purge_truncation_task.wait();
trx_purge_truncate_history(); break;
}
ulint n_pages_handled= trx_purge(trx, n_threads, history_size); if (!trx_sys.history_exists()) goto no_history; if (purge_sys.truncating_tablespace() ||
srv_shutdown_state != SRV_SHUTDOWN_NONE)
{
purge_truncation_task.wait();
trx_purge_truncate_history();
} else
srv_thread_pool->submit_task(&purge_truncation_task); if (!n_pages_handled) break;
} while (purge_sys.enabled() && !purge_sys.paused() &&
!srv_purge_should_exit(history_size));
/* Ensure that we have at least n background THDs for purge */ staticvoid purge_create_background_thds(int n)
{
THD *thd= current_thd;
std::unique_lock<std::mutex> lk(purge_thd_mutex); while (n_purge_thds < n)
{
purge_thds.push_back(innobase_create_background_thd("InnoDB purge worker"));
n_purge_thds++;
}
set_current_thd(thd);
}
/**********************************************************************//**
Enqueues a task to server task queue and releases a worker thread, if there
is a suspended one. */ void
srv_que_task_enqueue_low( /*=====================*/
que_thr_t* thr) /*!< in: query thread */
{
ut_ad(!srv_read_only_mode);
ut_ad(!recv_sys.rpo);
mysql_mutex_lock(&srv_sys.tasks_mutex);
UT_LIST_ADD_LAST(srv_sys.tasks, thr);
mysql_mutex_unlock(&srv_sys.tasks_mutex);
}
#ifdef UNIV_DEBUG /** @return number of tasks in queue */
ulint srv_get_task_queue_length()
{
ulint n_tasks;
ut_ad(!srv_read_only_mode);
ut_ad(!recv_sys.rpo);
mysql_mutex_lock(&srv_sys.tasks_mutex);
n_tasks = UT_LIST_GET_LEN(srv_sys.tasks);
mysql_mutex_unlock(&srv_sys.tasks_mutex);
return(n_tasks);
} #endif
/** Shut down the purge threads. */ void srv_purge_shutdown()
{ if (purge_sys.enabled())
{ if (!srv_fast_shutdown && !opt_bootstrap)
{
srv_purge_batch_size= innodb_purge_batch_size_MAX;
srv_update_purge_thread_count(innodb_purge_threads_MAX);
}
size_t history_size= trx_sys.history_size(); while (!srv_purge_should_exit(history_size))
{
history_size= trx_sys.history_size();
ut_a(!purge_sys.paused());
srv_thread_pool->submit_task(&purge_coordinator_task);
purge_coordinator_task.wait();
}
purge_sys.coordinator_shutdown();
srv_shutdown_purge_tasks(); if (!srv_fast_shutdown && !high_level_read_only &&
!recv_sys.rpo && srv_was_started &&
!opt_bootstrap && srv_operation == SRV_OPERATION_NORMAL &&
!srv_sys_space.is_shrink_fail())
fsp_system_tablespace_truncate(true);
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.24 Sekunden
(vorverarbeitet am 2026-10-08)
¤