1/*****************************************************************************
2
3Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
4Copyright (c) 2008, 2009, Google Inc.
5Copyright (c) 2009, Percona Inc.
6Copyright (c) 2013, 2017, MariaDB Corporation.
7
8Portions of this file contain modifications contributed and copyrighted by
9Google, Inc. Those modifications are gratefully acknowledged and are described
10briefly in the InnoDB documentation. The contributions by Google are
11incorporated with their permission, and subject to the conditions contained in
12the file COPYING.Google.
13
14Portions of this file contain modifications contributed and copyrighted
15by Percona Inc.. Those modifications are
16gratefully acknowledged and are described briefly in the InnoDB
17documentation. The contributions by Percona Inc. are incorporated with
18their permission, and subject to the conditions contained in the file
19COPYING.Percona.
20
21This program is free software; you can redistribute it and/or modify it under
22the terms of the GNU General Public License as published by the Free Software
23Foundation; version 2 of the License.
24
25This program is distributed in the hope that it will be useful, but WITHOUT
26ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
27FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
28
29You should have received a copy of the GNU General Public License along with
30this program; if not, write to the Free Software Foundation, Inc.,
3151 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
32
33*****************************************************************************/
34
35/**************************************************//**
36@file include/srv0srv.h
37The server main program
38
39Created 10/10/1995 Heikki Tuuri
40*******************************************************/
41
42#ifndef srv0srv_h
43#define srv0srv_h
44
45#include "my_global.h"
46
47#include "mysql/psi/mysql_stage.h"
48#include "mysql/psi/psi.h"
49
50#include "univ.i"
51#include "os0event.h"
52#include "que0types.h"
53#include "trx0types.h"
54#include "srv0conc.h"
55#include "buf0checksum.h"
56#include "ut0counter.h"
57#include "fil0fil.h"
58
59/** Global counters used inside InnoDB. */
60struct srv_stats_t
61{
62 typedef ib_counter_t<ulint, 64> ulint_ctr_64_t;
63 typedef simple_counter<lsn_t> lsn_ctr_1_t;
64 typedef simple_counter<ulint> ulint_ctr_1_t;
65 typedef simple_counter<int64_t> int64_ctr_1_t;
66
67 /** Count the amount of data written in total (in bytes) */
68 ulint_ctr_1_t data_written;
69
70 /** Number of the log write requests done */
71 ulint_ctr_1_t log_write_requests;
72
73 /** Number of physical writes to the log performed */
74 ulint_ctr_1_t log_writes;
75
76 /** Amount of data padded for log write ahead */
77 ulint_ctr_1_t log_padded;
78
79 /** Amount of data written to the log files in bytes */
80 lsn_ctr_1_t os_log_written;
81
82 /** Number of writes being done to the log files.
83 Protected by log_sys.write_mutex. */
84 ulint_ctr_1_t os_log_pending_writes;
85
86 /** We increase this counter, when we don't have enough
87 space in the log buffer and have to flush it */
88 ulint_ctr_1_t log_waits;
89
90 /** Count the number of times the doublewrite buffer was flushed */
91 ulint_ctr_1_t dblwr_writes;
92
93 /** Store the number of pages that have been flushed to the
94 doublewrite buffer */
95 ulint_ctr_1_t dblwr_pages_written;
96
97 /** Store the number of write requests issued */
98 ulint_ctr_1_t buf_pool_write_requests;
99
100 /** Store the number of times when we had to wait for a free page
101 in the buffer pool. It happens when the buffer pool is full and we
102 need to make a flush, in order to be able to read or create a page. */
103 ulint_ctr_1_t buf_pool_wait_free;
104
105 /** Count the number of pages that were written from buffer
106 pool to the disk */
107 ulint_ctr_1_t buf_pool_flushed;
108
109 /** Number of buffer pool reads that led to the reading of
110 a disk page */
111 ulint_ctr_1_t buf_pool_reads;
112
113 /** Number of bytes saved by page compression */
114 ulint_ctr_64_t page_compression_saved;
115 /* Number of index pages written */
116 ulint_ctr_64_t index_pages_written;
117 /* Number of non index pages written */
118 ulint_ctr_64_t non_index_pages_written;
119 /* Number of pages compressed with page compression */
120 ulint_ctr_64_t pages_page_compressed;
121 /* Number of TRIM operations induced by page compression */
122 ulint_ctr_64_t page_compressed_trim_op;
123 /* Number of pages decompressed with page compression */
124 ulint_ctr_64_t pages_page_decompressed;
125 /* Number of page compression errors */
126 ulint_ctr_64_t pages_page_compression_error;
127 /* Number of pages encrypted */
128 ulint_ctr_64_t pages_encrypted;
129 /* Number of pages decrypted */
130 ulint_ctr_64_t pages_decrypted;
131 /* Number of merge blocks encrypted */
132 ulint_ctr_64_t n_merge_blocks_encrypted;
133 /* Number of merge blocks decrypted */
134 ulint_ctr_64_t n_merge_blocks_decrypted;
135 /* Number of row log blocks encrypted */
136 ulint_ctr_64_t n_rowlog_blocks_encrypted;
137 /* Number of row log blocks decrypted */
138 ulint_ctr_64_t n_rowlog_blocks_decrypted;
139
140 /** Number of data read in total (in bytes) */
141 ulint_ctr_1_t data_read;
142
143 /** Wait time of database locks */
144 int64_ctr_1_t n_lock_wait_time;
145
146 /** Number of database lock waits */
147 ulint_ctr_1_t n_lock_wait_count;
148
149 /** Number of threads currently waiting on database locks */
150 simple_atomic_counter<> n_lock_wait_current_count;
151
152 /** Number of rows read. */
153 ulint_ctr_64_t n_rows_read;
154
155 /** Number of rows updated */
156 ulint_ctr_64_t n_rows_updated;
157
158 /** Number of rows deleted */
159 ulint_ctr_64_t n_rows_deleted;
160
161 /** Number of rows inserted */
162 ulint_ctr_64_t n_rows_inserted;
163
164 /** Number of system rows read. */
165 ulint_ctr_64_t n_system_rows_read;
166
167 /** Number of system rows updated */
168 ulint_ctr_64_t n_system_rows_updated;
169
170 /** Number of system rows deleted */
171 ulint_ctr_64_t n_system_rows_deleted;
172
173 /** Number of system rows inserted */
174 ulint_ctr_64_t n_system_rows_inserted;
175
176 /** Number of times secondary index lookup triggered cluster lookup */
177 ulint_ctr_64_t n_sec_rec_cluster_reads;
178
179 /** Number of times prefix optimization avoided triggering cluster lookup */
180 ulint_ctr_64_t n_sec_rec_cluster_reads_avoided;
181
182 /** Number of times page 0 is read from tablespace */
183 ulint_ctr_64_t page0_read;
184
185 /** Number of encryption_get_latest_key_version calls */
186 ulint_ctr_64_t n_key_requests;
187
188 /** Number of log scrub operations */
189 ulint_ctr_64_t n_log_scrubs;
190
191 /** Number of spaces in keyrotation list */
192 ulint_ctr_64_t key_rotation_list_length;
193};
194
195extern const char* srv_main_thread_op_info;
196
197/** Prefix used by MySQL to indicate pre-5.1 table name encoding */
198extern const char srv_mysql50_table_name_prefix[10];
199
200/** Event to signal srv_monitor_thread. Not protected by a mutex.
201Set after setting srv_print_innodb_monitor. */
202extern os_event_t srv_monitor_event;
203
204/** Event to signal the shutdown of srv_error_monitor_thread.
205Not protected by a mutex. */
206extern os_event_t srv_error_event;
207
208/** Event for waking up buf_dump_thread. Not protected by a mutex.
209Set on shutdown or by buf_dump_start() or buf_load_start(). */
210extern os_event_t srv_buf_dump_event;
211
212/** The buffer pool resize thread waits on this event. */
213extern os_event_t srv_buf_resize_event;
214
215/** The buffer pool dump/load file name */
216#define SRV_BUF_DUMP_FILENAME_DEFAULT "ib_buffer_pool"
217extern char* srv_buf_dump_filename;
218
219/** Boolean config knobs that tell InnoDB to dump the buffer pool at shutdown
220and/or load it during startup. */
221extern char srv_buffer_pool_dump_at_shutdown;
222extern char srv_buffer_pool_load_at_startup;
223
224/* Whether to disable file system cache if it is defined */
225extern char srv_disable_sort_file_cache;
226
227/* If the last data file is auto-extended, we add this many pages to it
228at a time */
229#define SRV_AUTO_EXTEND_INCREMENT (srv_sys_space.get_autoextend_increment())
230
231/** Mutex protecting page_zip_stat_per_index */
232extern ib_mutex_t page_zip_stat_per_index_mutex;
233/* Mutex for locking srv_monitor_file. Not created if srv_read_only_mode */
234extern ib_mutex_t srv_monitor_file_mutex;
235/* Temporary file for innodb monitor output */
236extern FILE* srv_monitor_file;
237/* Mutex for locking srv_misc_tmpfile. Only created if !srv_read_only_mode.
238This mutex has a very low rank; threads reserving it should not
239acquire any further latches or sleep before releasing this one. */
240extern ib_mutex_t srv_misc_tmpfile_mutex;
241/* Temporary file for miscellanous diagnostic output */
242extern FILE* srv_misc_tmpfile;
243
244/* Server parameters which are read from the initfile */
245
246extern char* srv_data_home;
247
248/** Set if InnoDB must operate in read-only mode. We don't do any
249recovery and open all tables in RO mode instead of RW mode. We don't
250sync the max trx id to disk either. */
251extern my_bool srv_read_only_mode;
252/** Set if InnoDB operates in read-only mode or innodb-force-recovery
253is greater than SRV_FORCE_NO_TRX_UNDO. */
254extern my_bool high_level_read_only;
255/** store to its own file each table created by an user; data
256dictionary tables are in the system tablespace 0 */
257extern my_bool srv_file_per_table;
258/** Sleep delay for threads waiting to enter InnoDB. In micro-seconds. */
259extern ulong srv_thread_sleep_delay;
260/** Maximum sleep delay (in micro-seconds), value of 0 disables it.*/
261extern ulong srv_adaptive_max_sleep_delay;
262
263/** Place locks to records only i.e. do not use next-key locking except
264on duplicate key checking and foreign key checking */
265extern ibool srv_locks_unsafe_for_binlog;
266
267/** Sort buffer size in index creation */
268extern ulong srv_sort_buf_size;
269/** Maximum modification log file size for online index creation */
270extern unsigned long long srv_online_max_size;
271
272/* If this flag is TRUE, then we will use the native aio of the
273OS (provided we compiled Innobase with it in), otherwise we will
274use simulated aio we build below with threads.
275Currently we support native aio on windows and linux */
276extern my_bool srv_use_native_aio;
277extern my_bool srv_numa_interleave;
278
279/* Use atomic writes i.e disable doublewrite buffer */
280extern my_bool srv_use_atomic_writes;
281
282/* Compression algorithm*/
283extern ulong innodb_compression_algorithm;
284
285/** TRUE if the server was successfully started */
286extern bool srv_was_started;
287
288/** Server undo tablespaces directory, can be absolute path. */
289extern char* srv_undo_dir;
290
291/** Number of undo tablespaces to use. */
292extern ulong srv_undo_tablespaces;
293
294/** The number of UNDO tablespaces that are open and ready to use. */
295extern ulint srv_undo_tablespaces_open;
296
297/** The number of UNDO tablespaces that are active (hosting some rollback
298segment). It is quite possible that some of the tablespaces doesn't host
299any of the rollback-segment based on configuration used. */
300extern ulint srv_undo_tablespaces_active;
301
302/** Undo tablespaces starts with space_id. */
303extern ulint srv_undo_space_id_start;
304
305/** Check whether given space id is undo tablespace id
306@param[in] space_id space id to check
307@return true if it is undo tablespace else false. */
308inline
309bool
310srv_is_undo_tablespace(ulint space_id)
311{
312 return srv_undo_space_id_start > 0
313 && space_id >= srv_undo_space_id_start
314 && space_id < (srv_undo_space_id_start
315 + srv_undo_tablespaces_open);
316}
317
318/** The number of undo segments to use */
319extern ulong srv_undo_logs;
320
321/** Maximum size of undo tablespace. */
322extern unsigned long long srv_max_undo_log_size;
323
324extern uint srv_n_fil_crypt_threads;
325extern uint srv_n_fil_crypt_threads_started;
326
327/** Rate at which UNDO records should be purged. */
328extern ulong srv_purge_rseg_truncate_frequency;
329
330/** Enable or Disable Truncate of UNDO tablespace. */
331extern my_bool srv_undo_log_truncate;
332
333/* Optimize prefix index queries to skip cluster index lookup when possible */
334/* Enables or disables this prefix optimization. Disabled by default. */
335extern my_bool srv_prefix_index_cluster_optimization;
336
337/** Default size of UNDO tablespace while it is created new. */
338extern const ulint SRV_UNDO_TABLESPACE_SIZE_IN_PAGES;
339
340extern char* srv_log_group_home_dir;
341
342extern ulong srv_n_log_files;
343/** The InnoDB redo log file size, or 0 when changing the redo log format
344at startup (while disallowing writes to the redo log). */
345extern ulonglong srv_log_file_size;
346extern ulong srv_log_buffer_size;
347extern ulong srv_flush_log_at_trx_commit;
348extern uint srv_flush_log_at_timeout;
349extern ulong srv_log_write_ahead_size;
350extern my_bool srv_adaptive_flushing;
351extern my_bool srv_flush_sync;
352
353#ifdef WITH_INNODB_DISALLOW_WRITES
354/* When this event is reset we do not allow any file writes to take place. */
355extern os_event_t srv_allow_writes_event;
356#endif /* WITH_INNODB_DISALLOW_WRITES */
357
358/* If this flag is TRUE, then we will load the indexes' (and tables') metadata
359even if they are marked as "corrupted". Mostly it is for DBA to process
360corrupted index and table */
361extern my_bool srv_load_corrupted;
362
363/** Requested size in bytes */
364extern ulint srv_buf_pool_size;
365/** Minimum pool size in bytes */
366extern const ulint srv_buf_pool_min_size;
367/** Default pool size in bytes */
368extern const ulint srv_buf_pool_def_size;
369/** Requested buffer pool chunk size. Each buffer pool instance consists
370of one or more chunks. */
371extern ulong srv_buf_pool_chunk_unit;
372/** Requested number of buffer pool instances */
373extern ulong srv_buf_pool_instances;
374/** Default number of buffer pool instances */
375extern const ulong srv_buf_pool_instances_default;
376/** Number of locks to protect buf_pool->page_hash */
377extern ulong srv_n_page_hash_locks;
378/** Scan depth for LRU flush batch i.e.: number of blocks scanned*/
379extern ulong srv_LRU_scan_depth;
380/** Whether or not to flush neighbors of a block */
381extern ulong srv_flush_neighbors;
382/** Previously requested size */
383extern ulint srv_buf_pool_old_size;
384/** Current size as scaling factor for the other components */
385extern ulint srv_buf_pool_base_size;
386/** Current size in bytes */
387extern ulint srv_buf_pool_curr_size;
388/** Dump this % of each buffer pool during BP dump */
389extern ulong srv_buf_pool_dump_pct;
390#ifdef UNIV_DEBUG
391/** Abort load after this amount of pages */
392extern ulong srv_buf_pool_load_pages_abort;
393#endif
394/** Lock table size in bytes */
395extern ulint srv_lock_table_size;
396
397extern ulint srv_n_file_io_threads;
398extern my_bool srv_random_read_ahead;
399extern ulong srv_read_ahead_threshold;
400extern ulong srv_n_read_io_threads;
401extern ulong srv_n_write_io_threads;
402
403/* Defragmentation, Origianlly facebook default value is 100, but it's too high */
404#define SRV_DEFRAGMENT_FREQUENCY_DEFAULT 40
405extern my_bool srv_defragment;
406extern uint srv_defragment_n_pages;
407extern uint srv_defragment_stats_accuracy;
408extern uint srv_defragment_fill_factor_n_recs;
409extern double srv_defragment_fill_factor;
410extern uint srv_defragment_frequency;
411extern ulonglong srv_defragment_interval;
412
413extern ulong srv_idle_flush_pct;
414
415extern uint srv_change_buffer_max_size;
416
417/* Number of IO operations per second the server can do */
418extern ulong srv_io_capacity;
419
420/* We use this dummy default value at startup for max_io_capacity.
421The real value is set based on the value of io_capacity. */
422#define SRV_MAX_IO_CAPACITY_DUMMY_DEFAULT (~0UL)
423#define SRV_MAX_IO_CAPACITY_LIMIT (~0UL)
424extern ulong srv_max_io_capacity;
425/* Returns the number of IO operations that is X percent of the
426capacity. PCT_IO(5) -> returns the number of IO operations that
427is 5% of the max where max is srv_io_capacity. */
428#define PCT_IO(p) ((ulong) (srv_io_capacity * ((double) (p) / 100.0)))
429
430/* The "innodb_stats_method" setting, decides how InnoDB is going
431to treat NULL value when collecting statistics. It is not defined
432as enum type because the configure option takes unsigned integer type. */
433extern ulong srv_innodb_stats_method;
434
435extern ulint srv_max_n_open_files;
436
437extern ulong srv_n_page_cleaners;
438
439extern double srv_max_dirty_pages_pct;
440extern double srv_max_dirty_pages_pct_lwm;
441
442extern double srv_adaptive_flushing_lwm;
443extern ulong srv_flushing_avg_loops;
444
445extern ulong srv_force_recovery;
446
447extern uint srv_fast_shutdown; /*!< If this is 1, do not do a
448 purge and index buffer merge.
449 If this 2, do not even flush the
450 buffer pool to data files at the
451 shutdown: we effectively 'crash'
452 InnoDB (but lose no committed
453 transactions). */
454
455/** Signal to shut down InnoDB (NULL if shutdown was signaled, or if
456running in innodb_read_only mode, srv_read_only_mode) */
457extern st_my_thread_var *srv_running;
458
459extern ibool srv_innodb_status;
460
461extern unsigned long long srv_stats_transient_sample_pages;
462extern my_bool srv_stats_persistent;
463extern unsigned long long srv_stats_persistent_sample_pages;
464extern my_bool srv_stats_auto_recalc;
465extern my_bool srv_stats_include_delete_marked;
466extern unsigned long long srv_stats_modified_counter;
467extern my_bool srv_stats_sample_traditional;
468
469extern my_bool srv_use_doublewrite_buf;
470extern ulong srv_doublewrite_batch_size;
471extern ulong srv_checksum_algorithm;
472
473extern double srv_max_buf_pool_modified_pct;
474extern my_bool srv_force_primary_key;
475
476extern double srv_max_buf_pool_modified_pct;
477extern ulong srv_max_purge_lag;
478extern ulong srv_max_purge_lag_delay;
479
480extern ulong srv_replication_delay;
481/*-------------------------------------------*/
482
483/** Modes of operation */
484enum srv_operation_mode {
485 /** Normal mode (MariaDB Server) */
486 SRV_OPERATION_NORMAL,
487 /** Mariabackup taking a backup */
488 SRV_OPERATION_BACKUP,
489 /** Mariabackup restoring a backup for subsequent --copy-back */
490 SRV_OPERATION_RESTORE,
491 /** Mariabackup restoring the incremental part of a backup */
492 SRV_OPERATION_RESTORE_DELTA,
493 /** Mariabackup restoring a backup for subsequent --export */
494 SRV_OPERATION_RESTORE_EXPORT
495};
496
497/** Current mode of operation */
498extern enum srv_operation_mode srv_operation;
499
500extern my_bool srv_print_innodb_monitor;
501extern my_bool srv_print_innodb_lock_monitor;
502extern ibool srv_print_verbose_log;
503
504extern bool srv_monitor_active;
505extern bool srv_error_monitor_active;
506
507/* TRUE during the lifetime of the buffer pool dump/load thread */
508extern bool srv_buf_dump_thread_active;
509
510/* true during the lifetime of the buffer pool resize thread */
511extern bool srv_buf_resize_thread_active;
512
513/* TRUE during the lifetime of the stats thread */
514extern bool srv_dict_stats_thread_active;
515
516/* TRUE if enable log scrubbing */
517extern my_bool srv_scrub_log;
518
519extern ulong srv_n_spin_wait_rounds;
520extern ulong srv_n_free_tickets_to_enter;
521extern ulong srv_thread_sleep_delay;
522extern uint srv_spin_wait_delay;
523
524extern ulint srv_truncated_status_writes;
525/** Number of initialized rollback segments for persistent undo log */
526extern ulong srv_available_undo_logs;
527
528#if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
529extern my_bool srv_ibuf_disable_background_merge;
530#endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
531
532#ifdef UNIV_DEBUG
533extern my_bool srv_sync_debug;
534extern my_bool srv_purge_view_update_only_debug;
535
536/** Value of MySQL global used to disable master thread. */
537extern my_bool srv_master_thread_disabled_debug;
538/** InnoDB system tablespace to set during recovery */
539extern uint srv_sys_space_size_debug;
540/** whether redo log files have been created at startup */
541extern bool srv_log_files_created;
542#endif /* UNIV_DEBUG */
543
544#define SRV_SEMAPHORE_WAIT_EXTENSION 7200
545extern ulint srv_dml_needed_delay;
546
547#define SRV_MAX_N_IO_THREADS 130
548
549/* Array of English strings describing the current state of an
550i/o handler thread */
551extern const char* srv_io_thread_op_info[];
552extern const char* srv_io_thread_function[];
553
554/* the number of purge threads to use from the worker pool (currently 0 or 1) */
555extern ulong srv_n_purge_threads;
556
557/* the number of pages to purge in one batch */
558extern ulong srv_purge_batch_size;
559
560/* the number of sync wait arrays */
561extern ulong srv_sync_array_size;
562
563/* print all user-level transactions deadlocks to mysqld stderr */
564extern my_bool srv_print_all_deadlocks;
565
566extern my_bool srv_cmp_per_index_enabled;
567
568/* is encryption enabled */
569extern ulong srv_encrypt_tables;
570
571/** Status variables to be passed to MySQL */
572extern struct export_var_t export_vars;
573
574/** Global counters */
575extern srv_stats_t srv_stats;
576
577/** Simulate compression failures. */
578extern uint srv_simulate_comp_failures;
579
580/** Fatal semaphore wait threshold = maximum number of seconds
581that semaphore times out in InnoDB */
582#define DEFAULT_SRV_FATAL_SEMAPHORE_TIMEOUT 600
583extern ulong srv_fatal_semaphore_wait_threshold;
584
585/** Buffer pool dump status frequence in percentages */
586extern ulong srv_buf_dump_status_frequency;
587
588# ifdef UNIV_PFS_THREAD
589/* Keys to register InnoDB threads with performance schema */
590extern mysql_pfs_key_t buf_dump_thread_key;
591extern mysql_pfs_key_t dict_stats_thread_key;
592extern mysql_pfs_key_t io_handler_thread_key;
593extern mysql_pfs_key_t io_ibuf_thread_key;
594extern mysql_pfs_key_t io_log_thread_key;
595extern mysql_pfs_key_t io_read_thread_key;
596extern mysql_pfs_key_t io_write_thread_key;
597extern mysql_pfs_key_t page_cleaner_thread_key;
598extern mysql_pfs_key_t recv_writer_thread_key;
599extern mysql_pfs_key_t srv_error_monitor_thread_key;
600extern mysql_pfs_key_t srv_lock_timeout_thread_key;
601extern mysql_pfs_key_t srv_master_thread_key;
602extern mysql_pfs_key_t srv_monitor_thread_key;
603extern mysql_pfs_key_t srv_purge_thread_key;
604extern mysql_pfs_key_t srv_worker_thread_key;
605extern mysql_pfs_key_t trx_rollback_clean_thread_key;
606
607/* This macro register the current thread and its key with performance
608schema */
609# define pfs_register_thread(key) \
610do { \
611 struct PSI_thread* psi = PSI_CALL_new_thread(key, NULL, 0);\
612 /* JAN: TODO: MYSQL 5.7 PSI \
613 PSI_CALL_set_thread_os_id(psi); */ \
614 PSI_CALL_set_thread(psi); \
615} while (0)
616
617/* This macro delist the current thread from performance schema */
618# define pfs_delete_thread() \
619do { \
620 PSI_CALL_delete_current_thread(); \
621} while (0)
622# else
623# define pfs_register_thread(key)
624# define pfs_delete_thread()
625# endif /* UNIV_PFS_THREAD */
626
627#ifdef HAVE_PSI_STAGE_INTERFACE
628/** Performance schema stage event for monitoring ALTER TABLE progress
629everything after flush log_make_checkpoint_at(). */
630extern PSI_stage_info srv_stage_alter_table_end;
631
632/** Performance schema stage event for monitoring ALTER TABLE progress
633log_make_checkpoint_at(). */
634extern PSI_stage_info srv_stage_alter_table_flush;
635
636/** Performance schema stage event for monitoring ALTER TABLE progress
637row_merge_insert_index_tuples(). */
638extern PSI_stage_info srv_stage_alter_table_insert;
639
640/** Performance schema stage event for monitoring ALTER TABLE progress
641row_log_apply(). */
642extern PSI_stage_info srv_stage_alter_table_log_index;
643
644/** Performance schema stage event for monitoring ALTER TABLE progress
645row_log_table_apply(). */
646extern PSI_stage_info srv_stage_alter_table_log_table;
647
648/** Performance schema stage event for monitoring ALTER TABLE progress
649row_merge_sort(). */
650extern PSI_stage_info srv_stage_alter_table_merge_sort;
651
652/** Performance schema stage event for monitoring ALTER TABLE progress
653row_merge_read_clustered_index(). */
654extern PSI_stage_info srv_stage_alter_table_read_pk_internal_sort;
655
656/** Performance schema stage event for monitoring buffer pool load progress. */
657extern PSI_stage_info srv_stage_buffer_pool_load;
658#endif /* HAVE_PSI_STAGE_INTERFACE */
659
660
661/** Alternatives for innodb_flush_method */
662enum srv_flush_t {
663 SRV_FSYNC = 0, /*!< fsync, the default */
664 SRV_O_DSYNC, /*!< open log files in O_SYNC mode */
665 SRV_LITTLESYNC, /*!< do not call os_file_flush()
666 when writing data files, but do flush
667 after writing to log files */
668 SRV_NOSYNC, /*!< do not flush after writing */
669 SRV_O_DIRECT, /*!< invoke os_file_set_nocache() on
670 data files. This implies using
671 non-buffered IO but still using fsync,
672 the reason for which is that some FS
673 do not flush meta-data when
674 unbuffered IO happens */
675 SRV_O_DIRECT_NO_FSYNC
676 /*!< do not use fsync() when using
677 direct IO i.e.: it can be set to avoid
678 the fsync() call that we make when
679 using SRV_UNIX_O_DIRECT. However, in
680 this case user/DBA should be sure about
681 the integrity of the meta-data */
682#ifdef _WIN32
683 ,SRV_ALL_O_DIRECT_FSYNC
684 /*!< Traditional Windows appoach to open
685 all files without caching, and do FileFlushBuffers()*/
686#endif
687};
688/** innodb_flush_method */
689extern ulong srv_file_flush_method;
690
691/** Alternatives for srv_force_recovery. Non-zero values are intended
692to help the user get a damaged database up so that he can dump intact
693tables and rows with SELECT INTO OUTFILE. The database must not otherwise
694be used with these options! A bigger number below means that all precautions
695of lower numbers are included. */
696enum {
697 SRV_FORCE_IGNORE_CORRUPT = 1, /*!< let the server run even if it
698 detects a corrupt page */
699 SRV_FORCE_NO_BACKGROUND = 2, /*!< prevent the main thread from
700 running: if a crash would occur
701 in purge, this prevents it */
702 SRV_FORCE_NO_TRX_UNDO = 3, /*!< do not run trx rollback after
703 recovery */
704 SRV_FORCE_NO_IBUF_MERGE = 4, /*!< prevent also ibuf operations:
705 if they would cause a crash, better
706 not do them */
707 SRV_FORCE_NO_UNDO_LOG_SCAN = 5, /*!< do not look at undo logs when
708 starting the database: InnoDB will
709 treat even incomplete transactions
710 as committed */
711 SRV_FORCE_NO_LOG_REDO = 6 /*!< do not do the log roll-forward
712 in connection with recovery */
713};
714
715/* Alternatives for srv_innodb_stats_method, which could be changed by
716setting innodb_stats_method */
717enum srv_stats_method_name_enum {
718 SRV_STATS_NULLS_EQUAL, /* All NULL values are treated as
719 equal. This is the default setting
720 for innodb_stats_method */
721 SRV_STATS_NULLS_UNEQUAL, /* All NULL values are treated as
722 NOT equal. */
723 SRV_STATS_NULLS_IGNORED /* NULL values are ignored */
724};
725
726typedef enum srv_stats_method_name_enum srv_stats_method_name_t;
727
728/** Types of threads existing in the system. */
729enum srv_thread_type {
730 SRV_NONE, /*!< None */
731 SRV_WORKER, /*!< threads serving parallelized
732 queries and queries released from
733 lock wait */
734 SRV_PURGE, /*!< Purge coordinator thread */
735 SRV_MASTER /*!< the master thread, (whose type
736 number must be biggest) */
737};
738
739/*********************************************************************//**
740Boots Innobase server. */
741void
742srv_boot(void);
743/*==========*/
744/*********************************************************************//**
745Frees the data structures created in srv_init(). */
746void
747srv_free(void);
748/*==========*/
749/*********************************************************************//**
750Sets the info describing an i/o thread current state. */
751void
752srv_set_io_thread_op_info(
753/*======================*/
754 ulint i, /*!< in: the 'segment' of the i/o thread */
755 const char* str); /*!< in: constant char string describing the
756 state */
757/*********************************************************************//**
758Resets the info describing an i/o thread current state. */
759void
760srv_reset_io_thread_op_info();
761
762/** Wake up the purge threads if there is work to do. */
763void
764srv_wake_purge_thread_if_not_active();
765/** Wake up the InnoDB master thread if it was suspended (not sleeping). */
766void
767srv_active_wake_master_thread_low();
768
769#define srv_active_wake_master_thread() \
770 do { \
771 if (!srv_read_only_mode) { \
772 srv_active_wake_master_thread_low(); \
773 } \
774 } while (0)
775/** Wake up the master thread if it is suspended or being suspended. */
776void
777srv_wake_master_thread();
778
779/******************************************************************//**
780Outputs to a file the output of the InnoDB Monitor.
781@return FALSE if not all information printed
782due to failure to obtain necessary mutex */
783ibool
784srv_printf_innodb_monitor(
785/*======================*/
786 FILE* file, /*!< in: output stream */
787 ibool nowait, /*!< in: whether to wait for the
788 lock_sys_t::mutex */
789 ulint* trx_start, /*!< out: file position of the start of
790 the list of active transactions */
791 ulint* trx_end); /*!< out: file position of the end of
792 the list of active transactions */
793
794/******************************************************************//**
795Function to pass InnoDB status variables to MySQL */
796void
797srv_export_innodb_status(void);
798/*==========================*/
799/*******************************************************************//**
800Get current server activity count. We don't hold srv_sys::mutex while
801reading this value as it is only used in heuristics.
802@return activity count. */
803ulint
804srv_get_activity_count(void);
805/*========================*/
806/*******************************************************************//**
807Check if there has been any activity.
808@return FALSE if no change in activity counter. */
809ibool
810srv_check_activity(
811/*===============*/
812 ulint old_activity_count); /*!< old activity count */
813/******************************************************************//**
814Increment the server activity counter. */
815void
816srv_inc_activity_count(void);
817/*=========================*/
818
819/**********************************************************************//**
820Enqueues a task to server task queue and releases a worker thread, if there
821is a suspended one. */
822void
823srv_que_task_enqueue_low(
824/*=====================*/
825 que_thr_t* thr); /*!< in: query thread */
826
827/**********************************************************************//**
828Check whether any background thread is active. If so, return the thread
829type.
830@return SRV_NONE if all are are suspended or have exited, thread
831type if any are still active. */
832enum srv_thread_type
833srv_get_active_thread_type(void);
834/*============================*/
835
836extern "C" {
837
838/*********************************************************************//**
839A thread which prints the info output by various InnoDB monitors.
840@return a dummy parameter */
841os_thread_ret_t
842DECLARE_THREAD(srv_monitor_thread)(
843/*===============================*/
844 void* arg); /*!< in: a dummy parameter required by
845 os_thread_create */
846
847/*********************************************************************//**
848The master thread controlling the server.
849@return a dummy parameter */
850os_thread_ret_t
851DECLARE_THREAD(srv_master_thread)(
852/*==============================*/
853 void* arg); /*!< in: a dummy parameter required by
854 os_thread_create */
855
856/*************************************************************************
857A thread which prints warnings about semaphore waits which have lasted
858too long. These can be used to track bugs which cause hangs.
859@return a dummy parameter */
860os_thread_ret_t
861DECLARE_THREAD(srv_error_monitor_thread)(
862/*=====================================*/
863 void* arg); /*!< in: a dummy parameter required by
864 os_thread_create */
865
866/*********************************************************************//**
867Purge coordinator thread that schedules the purge tasks.
868@return a dummy parameter */
869os_thread_ret_t
870DECLARE_THREAD(srv_purge_coordinator_thread)(
871/*=========================================*/
872 void* arg MY_ATTRIBUTE((unused))); /*!< in: a dummy parameter
873 required by os_thread_create */
874
875/*********************************************************************//**
876Worker thread that reads tasks from the work queue and executes them.
877@return a dummy parameter */
878os_thread_ret_t
879DECLARE_THREAD(srv_worker_thread)(
880/*==============================*/
881 void* arg MY_ATTRIBUTE((unused))); /*!< in: a dummy parameter
882 required by os_thread_create */
883} /* extern "C" */
884
885/**********************************************************************//**
886Get count of tasks in the queue.
887@return number of tasks in queue */
888ulint
889srv_get_task_queue_length(void);
890/*===========================*/
891
892/** Ensure that a given number of threads of the type given are running
893(or are already terminated).
894@param[in] type thread type
895@param[in] n number of threads that have to run */
896void
897srv_release_threads(enum srv_thread_type type, ulint n);
898
899/** Wakeup the purge threads. */
900void
901srv_purge_wakeup();
902
903/** Check if tablespace is being truncated.
904(Ignore system-tablespace as we don't re-create the tablespace
905and so some of the action that are suppressed by this function
906for independent tablespace are not applicable to system-tablespace).
907@param space_id space_id to check for truncate action
908@return true if being truncated, false if not being
909 truncated or tablespace is system-tablespace. */
910bool
911srv_is_tablespace_truncated(ulint space_id);
912
913/** Check if tablespace was truncated.
914@param[in] space space object to check for truncate action
915@return true if tablespace was truncated and we still have an active
916MLOG_TRUNCATE REDO log record. */
917bool
918srv_was_tablespace_truncated(const fil_space_t* space);
919
920#ifdef UNIV_DEBUG
921/** Disables master thread. It's used by:
922 SET GLOBAL innodb_master_thread_disabled_debug = 1 (0).
923@param[in] save immediate result from check function */
924void
925srv_master_thread_disabled_debug_update(THD*, st_mysql_sys_var*, void*,
926 const void* save);
927#endif /* UNIV_DEBUG */
928
929/** Status variables to be passed to MySQL */
930struct export_var_t{
931 ulint innodb_data_pending_reads; /*!< Pending reads */
932 ulint innodb_data_pending_writes; /*!< Pending writes */
933 ulint innodb_data_pending_fsyncs; /*!< Pending fsyncs */
934 ulint innodb_data_fsyncs; /*!< Number of fsyncs so far */
935 ulint innodb_data_read; /*!< Data bytes read */
936 ulint innodb_data_writes; /*!< I/O write requests */
937 ulint innodb_data_written; /*!< Data bytes written */
938 ulint innodb_data_reads; /*!< I/O read requests */
939 char innodb_buffer_pool_dump_status[OS_FILE_MAX_PATH + 128];/*!< Buf pool dump status */
940 char innodb_buffer_pool_load_status[OS_FILE_MAX_PATH + 128];/*!< Buf pool load status */
941 char innodb_buffer_pool_resize_status[512];/*!< Buf pool resize status */
942 my_bool innodb_buffer_pool_load_incomplete;/*!< Buf pool load incomplete */
943 ulint innodb_buffer_pool_pages_total; /*!< Buffer pool size */
944 ulint innodb_buffer_pool_pages_data; /*!< Data pages */
945 ulint innodb_buffer_pool_bytes_data; /*!< File bytes used */
946 ulint innodb_buffer_pool_pages_dirty; /*!< Dirty data pages */
947 ulint innodb_buffer_pool_bytes_dirty; /*!< File bytes modified */
948 ulint innodb_buffer_pool_pages_misc; /*!< Miscellanous pages */
949 ulint innodb_buffer_pool_pages_free; /*!< Free pages */
950#ifdef UNIV_DEBUG
951 ulint innodb_buffer_pool_pages_latched; /*!< Latched pages */
952#endif /* UNIV_DEBUG */
953 ulint innodb_buffer_pool_read_requests; /*!< buf_pool->stat.n_page_gets */
954 ulint innodb_buffer_pool_reads; /*!< srv_buf_pool_reads */
955 ulint innodb_buffer_pool_wait_free; /*!< srv_buf_pool_wait_free */
956 ulint innodb_buffer_pool_pages_flushed; /*!< srv_buf_pool_flushed */
957 ulint innodb_buffer_pool_write_requests;/*!< srv_buf_pool_write_requests */
958 ulint innodb_buffer_pool_read_ahead_rnd;/*!< srv_read_ahead_rnd */
959 ulint innodb_buffer_pool_read_ahead; /*!< srv_read_ahead */
960 ulint innodb_buffer_pool_read_ahead_evicted;/*!< srv_read_ahead evicted*/
961 ulint innodb_dblwr_pages_written; /*!< srv_dblwr_pages_written */
962 ulint innodb_dblwr_writes; /*!< srv_dblwr_writes */
963 ibool innodb_have_atomic_builtins; /*!< HAVE_ATOMIC_BUILTINS */
964 ulint innodb_log_waits; /*!< srv_log_waits */
965 ulint innodb_log_write_requests; /*!< srv_log_write_requests */
966 ulint innodb_log_writes; /*!< srv_log_writes */
967 lsn_t innodb_os_log_written; /*!< srv_os_log_written */
968 ulint innodb_os_log_fsyncs; /*!< fil_n_log_flushes */
969 ulint innodb_os_log_pending_writes; /*!< srv_os_log_pending_writes */
970 ulint innodb_os_log_pending_fsyncs; /*!< fil_n_pending_log_flushes */
971 ulint innodb_page_size; /*!< srv_page_size */
972 ulint innodb_pages_created; /*!< buf_pool->stat.n_pages_created */
973 ulint innodb_pages_read; /*!< buf_pool->stat.n_pages_read*/
974 ulint innodb_page0_read; /*!< srv_stats.page0_read */
975 ulint innodb_pages_written; /*!< buf_pool->stat.n_pages_written */
976 ulint innodb_row_lock_waits; /*!< srv_n_lock_wait_count */
977 ulint innodb_row_lock_current_waits; /*!< srv_n_lock_wait_current_count */
978 int64_t innodb_row_lock_time; /*!< srv_n_lock_wait_time
979 / 1000 */
980 ulint innodb_row_lock_time_avg; /*!< srv_n_lock_wait_time
981 / 1000
982 / srv_n_lock_wait_count */
983 ulint innodb_row_lock_time_max; /*!< srv_n_lock_max_wait_time
984 / 1000 */
985 ulint innodb_rows_read; /*!< srv_n_rows_read */
986 ulint innodb_rows_inserted; /*!< srv_n_rows_inserted */
987 ulint innodb_rows_updated; /*!< srv_n_rows_updated */
988 ulint innodb_rows_deleted; /*!< srv_n_rows_deleted */
989 ulint innodb_system_rows_read; /*!< srv_n_system_rows_read */
990 ulint innodb_system_rows_inserted; /*!< srv_n_system_rows_inserted */
991 ulint innodb_system_rows_updated; /*!< srv_n_system_rows_updated */
992 ulint innodb_system_rows_deleted; /*!< srv_n_system_rows_deleted*/
993 ulint innodb_num_open_files; /*!< fil_n_file_opened */
994 ulint innodb_truncated_status_writes; /*!< srv_truncated_status_writes */
995 ulint innodb_available_undo_logs; /*!< srv_available_undo_logs
996 */
997 ulint innodb_defragment_compression_failures; /*!< Number of
998 defragment re-compression
999 failures */
1000
1001 ulint innodb_defragment_failures; /*!< Number of defragment
1002 failures*/
1003 ulint innodb_defragment_count; /*!< Number of defragment
1004 operations*/
1005
1006 /** Number of instant ALTER TABLE operations that affect columns */
1007 ulong innodb_instant_alter_column;
1008
1009 ulint innodb_onlineddl_rowlog_rows; /*!< Online alter rows */
1010 ulint innodb_onlineddl_rowlog_pct_used; /*!< Online alter percentage
1011 of used row log buffer */
1012 ulint innodb_onlineddl_pct_progress; /*!< Online alter progress */
1013
1014#ifdef UNIV_DEBUG
1015 ulint innodb_ahi_drop_lookups; /*!< number of adaptive hash
1016 index lookups when freeing
1017 file pages */
1018#endif /* UNIV_DEBUG */
1019
1020 int64_t innodb_page_compression_saved;/*!< Number of bytes saved
1021 by page compression */
1022 int64_t innodb_index_pages_written; /*!< Number of index pages
1023 written */
1024 int64_t innodb_non_index_pages_written; /*!< Number of non index pages
1025 written */
1026 int64_t innodb_pages_page_compressed;/*!< Number of pages
1027 compressed by page compression */
1028 int64_t innodb_page_compressed_trim_op;/*!< Number of TRIM operations
1029 induced by page compression */
1030 int64_t innodb_pages_page_decompressed;/*!< Number of pages
1031 decompressed by page
1032 compression */
1033 int64_t innodb_pages_page_compression_error;/*!< Number of page
1034 compression errors */
1035 int64_t innodb_pages_encrypted; /*!< Number of pages
1036 encrypted */
1037 int64_t innodb_pages_decrypted; /*!< Number of pages
1038 decrypted */
1039
1040 /*!< Number of merge blocks encrypted */
1041 ib_int64_t innodb_n_merge_blocks_encrypted;
1042 /*!< Number of merge blocks decrypted */
1043 ib_int64_t innodb_n_merge_blocks_decrypted;
1044 /*!< Number of row log blocks encrypted */
1045 ib_int64_t innodb_n_rowlog_blocks_encrypted;
1046 /*!< Number of row log blocks decrypted */
1047 ib_int64_t innodb_n_rowlog_blocks_decrypted;
1048
1049 ulint innodb_sec_rec_cluster_reads; /*!< srv_sec_rec_cluster_reads */
1050 ulint innodb_sec_rec_cluster_reads_avoided;/*!< srv_sec_rec_cluster_reads_avoided */
1051
1052 ulint innodb_encryption_rotation_pages_read_from_cache;
1053 ulint innodb_encryption_rotation_pages_read_from_disk;
1054 ulint innodb_encryption_rotation_pages_modified;
1055 ulint innodb_encryption_rotation_pages_flushed;
1056 ulint innodb_encryption_rotation_estimated_iops;
1057 int64_t innodb_encryption_key_requests;
1058 int64_t innodb_key_rotation_list_length;
1059
1060 ulint innodb_scrub_page_reorganizations;
1061 ulint innodb_scrub_page_splits;
1062 ulint innodb_scrub_page_split_failures_underflow;
1063 ulint innodb_scrub_page_split_failures_out_of_filespace;
1064 ulint innodb_scrub_page_split_failures_missing_index;
1065 ulint innodb_scrub_page_split_failures_unknown;
1066 int64_t innodb_scrub_log;
1067};
1068
1069/** Thread slot in the thread table. */
1070struct srv_slot_t{
1071 srv_thread_type type; /*!< thread type: user,
1072 utility etc. */
1073 ibool in_use; /*!< TRUE if this slot
1074 is in use */
1075 ibool suspended; /*!< TRUE if the thread is
1076 waiting for the event of this
1077 slot */
1078 ib_time_t suspend_time; /*!< time when the thread was
1079 suspended. Initialized by
1080 lock_wait_table_reserve_slot()
1081 for lock wait */
1082 ulong wait_timeout; /*!< wait time that if exceeded
1083 the thread will be timed out.
1084 Initialized by
1085 lock_wait_table_reserve_slot()
1086 for lock wait */
1087 os_event_t event; /*!< event used in suspending
1088 the thread when it has nothing
1089 to do */
1090 que_thr_t* thr; /*!< suspended query thread
1091 (only used for user threads) */
1092};
1093
1094#ifdef WITH_WSREP
1095UNIV_INTERN
1096void
1097wsrep_srv_conc_cancel_wait(
1098/*==================*/
1099 trx_t* trx); /*!< in: transaction object associated with the
1100 thread */
1101#endif /* WITH_WSREP */
1102
1103#endif
1104