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