1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.
4 Copyright (c) 2008, 2009, Google Inc.
5 Copyright (c) 2009, Percona Inc.
6 
7 Portions of this file contain modifications contributed and copyrighted by
8 Google, Inc. Those modifications are gratefully acknowledged and are described
9 briefly in the InnoDB documentation. The contributions by Google are
10 incorporated with their permission, and subject to the conditions contained in
11 the file COPYING.Google.
12 
13 Portions of this file contain modifications contributed and copyrighted
14 by Percona Inc.. Those modifications are
15 gratefully acknowledged and are described briefly in the InnoDB
16 documentation. The contributions by Percona Inc. are incorporated with
17 their permission, and subject to the conditions contained in the file
18 COPYING.Percona.
19 
20 This program is free software; you can redistribute it and/or modify it under
21 the terms of the GNU General Public License, version 2.0, as published by the
22 Free Software Foundation.
23 
24 This program is also distributed with certain software (including but not
25 limited to OpenSSL) that is licensed under separate terms, as designated in a
26 particular file or component or in included license documentation. The authors
27 of MySQL hereby grant you an additional permission to link the program and
28 your derivative works with the separately licensed software that they have
29 included with MySQL.
30 
31 This program is distributed in the hope that it will be useful, but WITHOUT
32 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
33 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
34 for more details.
35 
36 You should have received a copy of the GNU General Public License along with
37 this program; if not, write to the Free Software Foundation, Inc.,
38 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
39 
40 *****************************************************************************/
41 
42 /** @file include/srv0srv.h
43  The server main program
44 
45  Created 10/10/1995 Heikki Tuuri
46  *******************************************************/
47 
48 #ifndef srv0srv_h
49 #define srv0srv_h
50 
51 #include "buf0checksum.h"
52 #include "fil0fil.h"
53 #include "log0types.h"
54 #include "mysql/psi/mysql_stage.h"
55 #include "univ.i"
56 
57 #ifndef UNIV_HOTBACKUP
58 #include "log0ddl.h"
59 #include "os0event.h"
60 #include "os0file.h"
61 #include "os0thread.h"
62 #include "que0types.h"
63 #include "srv0conc.h"
64 #include "trx0types.h"
65 #include "ut0counter.h"
66 
67 #include <future>
68 
69 /* Global counters used inside InnoDB. */
70 struct srv_stats_t {
71   typedef ib_counter_t<ulint, 64> ulint_ctr_64_t;
72   typedef ib_counter_t<lsn_t, 1, single_indexer_t> lsn_ctr_1_t;
73   typedef ib_counter_t<ulint, 1, single_indexer_t> ulint_ctr_1_t;
74   typedef ib_counter_t<lint, 1, single_indexer_t> lint_ctr_1_t;
75   typedef ib_counter_t<int64_t, 1, single_indexer_t> int64_ctr_1_t;
76 
77   /** Count the amount of data written in total (in bytes) */
78   ulint_ctr_1_t data_written;
79 
80   /** Number of the log write requests done */
81   ulint_ctr_1_t log_write_requests;
82 
83   /** Number of physical writes to the log performed */
84   ulint_ctr_1_t log_writes;
85 
86   /** Amount of data written to the log files in bytes */
87   lsn_ctr_1_t os_log_written;
88 
89   /** Number of writes being done to the log files */
90   lint_ctr_1_t os_log_pending_writes;
91 
92   /** We increase this counter, when we don't have enough
93   space in the log buffer and have to flush it */
94   ulint_ctr_1_t log_waits;
95 
96   /** Count the number of times the doublewrite buffer was flushed */
97   ulint_ctr_1_t dblwr_writes;
98 
99   /** Store the number of pages that have been flushed to the
100   doublewrite buffer */
101   ulint_ctr_1_t dblwr_pages_written;
102 
103   /** Store the number of write requests issued */
104   ulint_ctr_1_t buf_pool_write_requests;
105 
106   /** Store the number of times when we had to wait for a free page
107   in the buffer pool. It happens when the buffer pool is full and we
108   need to make a flush, in order to be able to read or create a page. */
109   ulint_ctr_1_t buf_pool_wait_free;
110 
111   /** Count the number of pages that were written from buffer
112   pool to the disk */
113   ulint_ctr_1_t buf_pool_flushed;
114 
115   /** Number of buffer pool reads that led to the reading of
116   a disk page */
117   ulint_ctr_1_t buf_pool_reads;
118 
119   /** Number of data read in total (in bytes) */
120   ulint_ctr_1_t data_read;
121 
122   /** Wait time of database locks */
123   int64_ctr_1_t n_lock_wait_time;
124 
125   /** Number of database lock waits */
126   ulint_ctr_1_t n_lock_wait_count;
127 
128   /** Number of threads currently waiting on database locks */
129   lint_ctr_1_t n_lock_wait_current_count;
130 
131   /** Number of rows read. */
132   ulint_ctr_64_t n_rows_read;
133 
134   /** Number of rows updated */
135   ulint_ctr_64_t n_rows_updated;
136 
137   /** Number of rows deleted */
138   ulint_ctr_64_t n_rows_deleted;
139 
140   /** Number of rows inserted */
141   ulint_ctr_64_t n_rows_inserted;
142 
143   /** Number of system rows read. */
144   ulint_ctr_64_t n_system_rows_read;
145 
146   /** Number of system rows updated */
147   ulint_ctr_64_t n_system_rows_updated;
148 
149   /** Number of system rows deleted */
150   ulint_ctr_64_t n_system_rows_deleted;
151 
152   /** Number of system rows inserted */
153   ulint_ctr_64_t n_system_rows_inserted;
154 
155   /** Number of sampled pages read */
156   ulint_ctr_64_t n_sampled_pages_read;
157 
158   /** Number of sampled pages skipped */
159   ulint_ctr_64_t n_sampled_pages_skipped;
160 };
161 
162 /** Structure which keeps shared future objects for InnoDB background
163 threads. One should use these objects to check if threads exited. */
164 struct Srv_threads {
165   /** Monitor thread (prints info). */
166   IB_thread m_monitor;
167 
168   /** Error monitor thread. */
169   IB_thread m_error_monitor;
170 
171   /** Redo closer thread. */
172   IB_thread m_log_closer;
173 
174   /** Redo checkpointer thread. */
175   IB_thread m_log_checkpointer;
176 
177   /** Redo writer thread. */
178   IB_thread m_log_writer;
179 
180   /** Redo flusher thread. */
181   IB_thread m_log_flusher;
182 
183   /** Redo write notifier thread. */
184   IB_thread m_log_write_notifier;
185 
186   /** Redo flush notifier thread. */
187   IB_thread m_log_flush_notifier;
188 
189   /** Redo log archiver (used by backup). */
190   IB_thread m_backup_log_archiver;
191 
192   /** Buffer pool dump thread. */
193   IB_thread m_buf_dump;
194 
195   /** Buffer pool resize thread. */
196   IB_thread m_buf_resize;
197 
198   /** Dict stats background thread. */
199   IB_thread m_dict_stats;
200 
201   /** Thread detecting lock wait timeouts. */
202   IB_thread m_lock_wait_timeout;
203 
204   /** The master thread. */
205   IB_thread m_master;
206 
207   /** The ts_alter_encrypt thread. */
208   IB_thread m_ts_alter_encrypt;
209 
210   /** Thread doing rollbacks during recovery. */
211   IB_thread m_trx_recovery_rollback;
212 
213   /** Thread writing recovered pages during recovery. */
214   IB_thread m_recv_writer;
215 
216   /** Purge coordinator (also being a worker) */
217   IB_thread m_purge_coordinator;
218 
219   /** Number of purge workers and size of array below. */
220   size_t m_purge_workers_n;
221 
222   /** Purge workers. Note that the m_purge_workers[0] is the same shared
223   state as m_purge_coordinator. */
224   IB_thread *m_purge_workers;
225 
226   /** Page cleaner coordinator (also being a worker). */
227   IB_thread m_page_cleaner_coordinator;
228 
229   /** Number of page cleaner workers and size of array below. */
230   size_t m_page_cleaner_workers_n;
231 
232   /** Page cleaner workers. Note that m_page_cleaner_workers[0] is the
233   same shared state as m_page_cleaner_coordinator. */
234   IB_thread *m_page_cleaner_workers;
235 
236   /** Archiver's log archiver (used by Clone). */
237   IB_thread m_log_archiver;
238 
239   /** Archiver's page archiver (used by Clone). */
240   IB_thread m_page_archiver;
241 
242   /** Thread doing optimization for FTS index. */
243   IB_thread m_fts_optimize;
244 
245   /** Thread for GTID persistence */
246   IB_thread m_gtid_persister;
247 
248 #ifdef UNIV_DEBUG
249   /** Used in test scenario to delay threads' cleanup until the pre_dd_shutdown
250   is ended and final plugin's shutdown is started (when plugin is DELETED).
251   Note that you may only delay the shutdown for threads for which there is no
252   waiting procedure used in the pre_dd_shutdown. */
253   os_event_t m_shutdown_cleanup_dbg;
254 #endif /* UNIV_DEBUG */
255 
256   /** When the master thread notices that shutdown has started (by noticing
257   srv_shutdown_state >= SRV_SHUTDOWN_PRE_DD_AND_SYSTEM_TRANSACTIONS), it exits
258   its main loop. Then the master thread proceeds with actions related to tasks:
259     - which it has been responsible for,
260     - and which might depend on DD objects.
261   After finishing them, the master thread sets this event.
262   @remarks We use this event to wait in srv_pre_dd_shutdown before we enter
263   next phase (SRV_SHUTDOWN_PURGE) in which master thread is not allowed to
264   use system transactions or touch DD objects. */
265   os_event_t m_master_ready_for_dd_shutdown;
266 };
267 
268 /** Check if given thread is still active. */
269 bool srv_thread_is_active(const IB_thread &thread);
270 
271 /** Delay the thread after it discovered that the shutdown_state
272 is greater or equal to SRV_SHUTDOWN_CLEANUP, before it proceeds
273 with further clean up. This is used in the tests to see if such
274 a possible delay does not have impact on the clean shutdown.
275 @param[in]  wait_for_signal   wait until shutdown phase starts */
276 void srv_thread_delay_cleanup_if_needed(bool wait_for_signal);
277 
278 struct Srv_cpu_usage {
279   int n_cpu;
280   double utime_abs;
281   double stime_abs;
282   double utime_pct;
283   double stime_pct;
284 };
285 
286 /** Structure with state of srv background threads. */
287 extern Srv_threads srv_threads;
288 
289 /** Structure with cpu usage information. */
290 extern Srv_cpu_usage srv_cpu_usage;
291 
292 extern Log_DDL *log_ddl;
293 
294 #ifdef INNODB_DD_TABLE
295 extern bool srv_is_upgrade_mode;
296 extern bool srv_downgrade_logs;
297 extern bool srv_upgrade_old_undo_found;
298 #endif /* INNODB_DD_TABLE */
299 
300 extern bool srv_downgrade_partition_files;
301 
302 extern const char *srv_main_thread_op_info;
303 
304 /* The monitor thread waits on this event. */
305 extern os_event_t srv_monitor_event;
306 
307 /* The error monitor thread waits on this event. */
308 extern os_event_t srv_error_event;
309 
310 /** The buffer pool dump/load thread waits on this event. */
311 extern os_event_t srv_buf_dump_event;
312 
313 /** The buffer pool resize thread waits on this event. */
314 extern os_event_t srv_buf_resize_event;
315 #endif /* !UNIV_HOTBACKUP */
316 
317 /** The buffer pool dump/load file name */
318 #define SRV_BUF_DUMP_FILENAME_DEFAULT "ib_buffer_pool"
319 extern char *srv_buf_dump_filename;
320 
321 /** Boolean config knobs that tell InnoDB to dump the buffer pool at shutdown
322 and/or load it during startup. */
323 extern bool srv_buffer_pool_dump_at_shutdown;
324 extern bool srv_buffer_pool_load_at_startup;
325 
326 /* Whether to disable file system cache if it is defined */
327 extern bool srv_disable_sort_file_cache;
328 
329 /* If the last data file is auto-extended, we add this many pages to it
330 at a time */
331 #define SRV_AUTO_EXTEND_INCREMENT (srv_sys_space.get_autoextend_increment())
332 
333 #ifndef UNIV_HOTBACKUP
334 /** Mutex protecting page_zip_stat_per_index */
335 extern ib_mutex_t page_zip_stat_per_index_mutex;
336 /* Mutex for locking srv_monitor_file. Not created if srv_read_only_mode */
337 extern ib_mutex_t srv_monitor_file_mutex;
338 /* Temporary file for innodb monitor output */
339 extern FILE *srv_monitor_file;
340 /* Mutex for locking srv_misc_tmpfile. Only created if !srv_read_only_mode.
341 This mutex has a very low rank; threads reserving it should not
342 acquire any further latches or sleep before releasing this one. */
343 extern ib_mutex_t srv_misc_tmpfile_mutex;
344 /* Temporary file for miscellanous diagnostic output */
345 extern FILE *srv_misc_tmpfile;
346 #endif /* !UNIV_HOTBACKUP */
347 
348 /* Server parameters which are read from the initfile */
349 
350 extern char *srv_data_home;
351 
352 /** Number of pages per doublewrite thread/segment */
353 extern ulong srv_dblwr_pages;
354 
355 /** Set if InnoDB must operate in read-only mode. We don't do any
356 recovery and open all tables in RO mode instead of RW mode. We don't
357 sync the max trx id to disk either. */
358 extern bool srv_read_only_mode;
359 /** Set if InnoDB operates in read-only mode or innodb-force-recovery
360 is greater than SRV_FORCE_NO_TRX_UNDO. */
361 extern bool high_level_read_only;
362 /** store to its own file each table created by an user; data
363 dictionary tables are in the system tablespace 0 */
364 extern bool srv_file_per_table;
365 /** Sleep delay for threads waiting to enter InnoDB. In micro-seconds. */
366 extern ulong srv_thread_sleep_delay;
367 /** Maximum sleep delay (in micro-seconds), value of 0 disables it.*/
368 extern ulong srv_adaptive_max_sleep_delay;
369 
370 /** Sort buffer size in index creation */
371 extern ulong srv_sort_buf_size;
372 
373 /** Maximum modification log file size for online index creation */
374 extern unsigned long long srv_online_max_size;
375 
376 /** Number of threads to use for parallel reads. */
377 extern ulong srv_parallel_read_threads;
378 
379 /* If this flag is TRUE, then we will use the native aio of the
380 OS (provided we compiled Innobase with it in), otherwise we will
381 use simulated aio we build below with threads.
382 Currently we support native aio on windows and linux */
383 extern bool srv_use_native_aio;
384 extern bool srv_numa_interleave;
385 
386 /* The innodb_directories variable value. This a list of directories
387 deliminated by ';', i.e the FIL_PATH_SEPARATOR. */
388 extern char *srv_innodb_directories;
389 
390 /** Server undo tablespaces directory, can be absolute path. */
391 extern char *srv_undo_dir;
392 
393 /** Number of undo tablespaces to use. */
394 extern ulong srv_undo_tablespaces;
395 
396 /** The number of rollback segments per tablespace */
397 extern ulong srv_rollback_segments;
398 
399 /** Maximum size of undo tablespace. */
400 extern unsigned long long srv_max_undo_tablespace_size;
401 
402 /** Rate at which UNDO records should be purged. */
403 extern ulong srv_purge_rseg_truncate_frequency;
404 
405 /** Enable or Disable Truncate of UNDO tablespace. */
406 extern bool srv_undo_log_truncate;
407 
408 /** Enable or disable Encrypt of UNDO tablespace. */
409 extern bool srv_undo_log_encrypt;
410 
411 /** Default size of UNDO tablespace while it is created new. */
412 extern const page_no_t SRV_UNDO_TABLESPACE_SIZE_IN_PAGES;
413 
414 /** Maximum number of recently truncated undo tablespace IDs for
415 the same undo number. */
416 extern const size_t CONCURRENT_UNDO_TRUNCATE_LIMIT;
417 
418 extern char *srv_log_group_home_dir;
419 
420 /** Enable or Disable Encrypt of REDO tablespace. */
421 extern bool srv_redo_log_encrypt;
422 
423 /* Maximum number of redo files of a cloned DB. */
424 #define SRV_N_LOG_FILES_CLONE_MAX 1000
425 
426 /** Maximum number of srv_n_log_files, or innodb_log_files_in_group */
427 #define SRV_N_LOG_FILES_MAX 100
428 extern ulong srv_n_log_files;
429 
430 #ifdef UNIV_DEBUG_DEDICATED
431 extern ulong srv_debug_system_mem_size;
432 #endif /* UNIV_DEBUG_DEDICATED */
433 
434 /** At startup, this is the current redo log file size.
435 During startup, if this is different from srv_log_file_size_requested
436 (innodb_log_file_size), the redo log will be rebuilt and this size
437 will be initialized to srv_log_file_size_requested.
438 When upgrading from a previous redo log format, this will be set to 0,
439 and writing to the redo log is not allowed.
440 
441 During startup, this is in bytes, and later converted to pages. */
442 extern ulonglong srv_log_file_size;
443 
444 /** The value of the startup parameter innodb_log_file_size. */
445 extern ulonglong srv_log_file_size_requested;
446 
447 /** Space for log buffer, expressed in bytes. Note, that log buffer
448 will use only the largest power of two, which is not greater than
449 the assigned space. */
450 extern ulong srv_log_buffer_size;
451 
452 /** When log writer follows links in the log recent written buffer,
453 it stops when it has reached at least that many bytes to write,
454 limiting how many bytes can be written in single call. */
455 extern ulong srv_log_write_max_size;
456 
457 /** Size of block, used for writing ahead to avoid read-on-write. */
458 extern ulong srv_log_write_ahead_size;
459 
460 /** Number of events used for notifications about redo write. */
461 extern ulong srv_log_write_events;
462 
463 /** Number of events used for notifications about redo flush. */
464 extern ulong srv_log_flush_events;
465 
466 /** Number of slots in a small buffer, which is used to allow concurrent
467 writes to log buffer. The slots are addressed by LSN values modulo number
468 of the slots. */
469 extern ulong srv_log_recent_written_size;
470 
471 /** Number of slots in a small buffer, which is used to break requirement
472 for total order of dirty pages, when they are added to flush lists.
473 The slots are addressed by LSN values modulo number of the slots. */
474 extern ulong srv_log_recent_closed_size;
475 
476 /** Minimum absolute value of cpu time for which spin-delay is used. */
477 extern uint srv_log_spin_cpu_abs_lwm;
478 
479 /** Maximum percentage of cpu time for which spin-delay is used. */
480 extern uint srv_log_spin_cpu_pct_hwm;
481 
482 /** Number of spin iterations, when spinning and waiting for log buffer
483 written up to given LSN, before we fallback to loop with sleeps.
484 This is not used when user thread has to wait for log flushed to disk. */
485 extern ulong srv_log_wait_for_write_spin_delay;
486 
487 /** Timeout used when waiting for redo write (microseconds). */
488 extern ulong srv_log_wait_for_write_timeout;
489 
490 /** Number of spin iterations, when spinning and waiting for log flushed. */
491 extern ulong srv_log_wait_for_flush_spin_delay;
492 
493 /** Maximum value of average log flush time for which spin-delay is used.
494 When flushing takes longer, user threads no longer spin when waiting for
495 flushed redo. Expressed in microseconds. */
496 extern ulong srv_log_wait_for_flush_spin_hwm;
497 
498 /** Timeout used when waiting for redo flush (microseconds). */
499 extern ulong srv_log_wait_for_flush_timeout;
500 
501 /** Number of spin iterations, for which log writer thread is waiting
502 for new data to write or flush without sleeping. */
503 extern ulong srv_log_writer_spin_delay;
504 
505 /** Initial timeout used to wait on writer_event. */
506 extern ulong srv_log_writer_timeout;
507 
508 /** Number of milliseconds every which a periodical checkpoint is written
509 by the log checkpointer thread (unless periodical checkpoints are disabled,
510 which is a case during initial phase of startup). */
511 extern ulong srv_log_checkpoint_every;
512 
513 /** Number of spin iterations, for which log flusher thread is waiting
514 for new data to flush, without sleeping. */
515 extern ulong srv_log_flusher_spin_delay;
516 
517 /** Initial timeout used to wait on flusher_event. */
518 extern ulong srv_log_flusher_timeout;
519 
520 /** Number of spin iterations, for which log write notifier thread is waiting
521 for advanced writeed_to_disk_lsn without sleeping. */
522 extern ulong srv_log_write_notifier_spin_delay;
523 
524 /** Initial timeout used to wait on write_notifier_event. */
525 extern ulong srv_log_write_notifier_timeout;
526 
527 /** Number of spin iterations, for which log flush notifier thread is waiting
528 for advanced flushed_to_disk_lsn without sleeping. */
529 extern ulong srv_log_flush_notifier_spin_delay;
530 
531 /** Initial timeout used to wait on flush_notifier_event. */
532 extern ulong srv_log_flush_notifier_timeout;
533 
534 /** Number of spin iterations, for which log closerr thread is waiting
535 for a reachable untraversed link in recent_closed. */
536 extern ulong srv_log_closer_spin_delay;
537 
538 /** Initial sleep used in log closer after spin delay is finished. */
539 extern ulong srv_log_closer_timeout;
540 
541 /** Whether to generate and require checksums on the redo log pages. */
542 extern bool srv_log_checksums;
543 
544 #ifdef UNIV_DEBUG
545 
546 /** If true then disable checkpointing. */
547 extern bool srv_checkpoint_disabled;
548 
549 /* Used to inject a failure to find a free rollback segment. */
550 extern bool srv_inject_too_many_concurrent_trxs;
551 
552 #endif /* UNIV_DEBUG */
553 
554 extern ulong srv_flush_log_at_trx_commit;
555 extern uint srv_flush_log_at_timeout;
556 extern ulong srv_log_write_ahead_size;
557 extern bool srv_adaptive_flushing;
558 extern bool srv_flush_sync;
559 
560 /* If this flag is TRUE, then we will load the indexes' (and tables') metadata
561 even if they are marked as "corrupted". Mostly it is for DBA to process
562 corrupted index and table */
563 extern bool srv_load_corrupted;
564 
565 /** Dedicated server setting */
566 extern bool srv_dedicated_server;
567 /** Requested size in bytes */
568 extern ulint srv_buf_pool_size;
569 /** Minimum pool size in bytes */
570 extern const ulint srv_buf_pool_min_size;
571 /** Default pool size in bytes */
572 extern const ulint srv_buf_pool_def_size;
573 /** Maximum pool size in bytes */
574 extern const longlong srv_buf_pool_max_size;
575 /** Requested buffer pool chunk size. Each buffer pool instance consists
576 of one or more chunks. */
577 extern ulonglong srv_buf_pool_chunk_unit;
578 /** Minimum buffer pool chunk size. */
579 extern const ulonglong srv_buf_pool_chunk_unit_min;
580 /** The buffer pool chunk size must be a multiple of this number. */
581 extern const ulonglong srv_buf_pool_chunk_unit_blk_sz;
582 /** Maximum buffer pool chunk size. */
583 extern const ulonglong srv_buf_pool_chunk_unit_max;
584 
585 /** Requested number of buffer pool instances */
586 extern ulong srv_buf_pool_instances;
587 /** Default number of buffer pool instances */
588 extern const ulong srv_buf_pool_instances_default;
589 /** Number of locks to protect buf_pool->page_hash */
590 extern ulong srv_n_page_hash_locks;
591 /** Whether to validate InnoDB tablespace paths on startup */
592 extern bool srv_validate_tablespace_paths;
593 /** Scan depth for LRU flush batch i.e.: number of blocks scanned*/
594 extern ulong srv_LRU_scan_depth;
595 /** Whether or not to flush neighbors of a block */
596 extern ulong srv_flush_neighbors;
597 /** Previously requested size. Accesses protected by memory barriers. */
598 extern ulint srv_buf_pool_old_size;
599 /** Current size as scaling factor for the other components */
600 extern ulint srv_buf_pool_base_size;
601 /** Current size in bytes */
602 extern long long srv_buf_pool_curr_size;
603 /** Dump this % of each buffer pool during BP dump */
604 extern ulong srv_buf_pool_dump_pct;
605 /** Lock table size in bytes */
606 extern ulint srv_lock_table_size;
607 
608 extern ulint srv_n_file_io_threads;
609 extern bool srv_random_read_ahead;
610 extern ulong srv_read_ahead_threshold;
611 extern ulong srv_n_read_io_threads;
612 extern ulong srv_n_write_io_threads;
613 
614 extern uint srv_change_buffer_max_size;
615 
616 /** Default value of srv_idle_flush_pct */
617 extern const ulong srv_idle_flush_pct_default;
618 /** How much flush to be done in case of server is idle */
619 extern ulong srv_idle_flush_pct;
620 
621 /* Number of IO operations per second the server can do */
622 extern ulong srv_io_capacity;
623 
624 /* We use this dummy default value at startup for max_io_capacity.
625 The real value is set based on the value of io_capacity. */
626 #define SRV_MAX_IO_CAPACITY_DUMMY_DEFAULT (~0UL)
627 #define SRV_MAX_IO_CAPACITY_LIMIT (~0UL)
628 extern ulong srv_max_io_capacity;
629 /* Returns the number of IO operations that is X percent of the
630 capacity. PCT_IO(5) -> returns the number of IO operations that
631 is 5% of the max where max is srv_io_capacity.  */
632 #define PCT_IO(p) ((ulong)(srv_io_capacity * ((double)(p) / 100.0)))
633 
634 /** Maximum number of purge threads, including the purge coordinator */
635 #define MAX_PURGE_THREADS 32
636 
637 /* The "innodb_stats_method" setting, decides how InnoDB is going
638 to treat NULL value when collecting statistics. It is not defined
639 as enum type because the configure option takes unsigned integer type. */
640 extern ulong srv_innodb_stats_method;
641 
642 extern ulint srv_max_n_open_files;
643 
644 extern ulong srv_n_page_cleaners;
645 
646 extern double srv_max_dirty_pages_pct;
647 extern double srv_max_dirty_pages_pct_lwm;
648 
649 extern ulong srv_adaptive_flushing_lwm;
650 extern ulong srv_flushing_avg_loops;
651 
652 extern ulong srv_force_recovery;
653 #ifdef UNIV_DEBUG
654 extern ulong srv_force_recovery_crash;
655 #endif /* UNIV_DEBUG */
656 
657 /** The value of the configuration parameter innodb_fast_shutdown,
658 controlling the InnoDB shutdown.
659 
660 If innodb_fast_shutdown=0, InnoDB shutdown will purge all undo log
661 records (except XA PREPARE transactions) and complete the merge of the
662 entire change buffer, and then shut down the redo log.
663 
664 If innodb_fast_shutdown=1, InnoDB shutdown will only flush the buffer
665 pool to data files, cleanly shutting down the redo log.
666 
667 If innodb_fast_shutdown=2, shutdown will effectively 'crash' InnoDB
668 (but lose no committed transactions). */
669 extern ulong srv_fast_shutdown;
670 extern ibool srv_innodb_status;
671 
672 extern unsigned long long srv_stats_transient_sample_pages;
673 extern bool srv_stats_persistent;
674 extern unsigned long long srv_stats_persistent_sample_pages;
675 extern bool srv_stats_auto_recalc;
676 extern bool srv_stats_include_delete_marked;
677 
678 extern ulong srv_checksum_algorithm;
679 
680 extern double srv_max_buf_pool_modified_pct;
681 extern ulong srv_max_purge_lag;
682 extern ulong srv_max_purge_lag_delay;
683 
684 extern ulong srv_replication_delay;
685 
686 extern bool srv_apply_log_only;
687 
688 extern bool srv_backup_mode;
689 extern bool srv_close_files;
690 extern bool srv_rollback_prepared_trx;
691 
692 /*-------------------------------------------*/
693 
694 extern bool srv_print_innodb_monitor;
695 extern bool srv_print_innodb_lock_monitor;
696 
697 extern ulong srv_n_spin_wait_rounds;
698 extern ulong srv_n_free_tickets_to_enter;
699 extern ulong srv_thread_sleep_delay;
700 extern ulong srv_spin_wait_delay;
701 extern ibool srv_priority_boost;
702 
703 extern ulint srv_truncated_status_writes;
704 
705 #if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
706 extern bool srv_ibuf_disable_background_merge;
707 #endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
708 
709 #ifdef UNIV_DEBUG
710 extern bool srv_buf_pool_debug;
711 extern bool srv_sync_debug;
712 extern bool srv_purge_view_update_only_debug;
713 
714 /** Value of MySQL global used to disable master thread. */
715 extern bool srv_master_thread_disabled_debug;
716 #endif /* UNIV_DEBUG */
717 
718 extern ulong srv_fatal_semaphore_wait_threshold;
719 #define SRV_SEMAPHORE_WAIT_EXTENSION 7200
720 extern ulint srv_dml_needed_delay;
721 
722 #ifdef UNIV_HOTBACKUP
723 // MAHI: changed from 130 to 1 assuming the apply-log is single threaded
724 #define SRV_MAX_N_IO_THREADS 1
725 #else /* UNIV_HOTBACKUP */
726 #define SRV_MAX_N_IO_THREADS 130
727 #endif /* UNIV_HOTBACKUP */
728 
729 /* Array of English strings describing the current state of an
730 i/o handler thread */
731 extern const char *srv_io_thread_op_info[];
732 extern const char *srv_io_thread_function[];
733 
734 /* the number of purge threads to use from the worker pool (currently 0 or 1) */
735 extern ulong srv_n_purge_threads;
736 
737 /* the number of pages to purge in one batch */
738 extern ulong srv_purge_batch_size;
739 
740 /* the number of sync wait arrays */
741 extern ulong srv_sync_array_size;
742 
743 /* print all user-level transactions deadlocks to mysqld stderr */
744 extern bool srv_print_all_deadlocks;
745 
746 /** Print all DDL logs to mysqld stderr */
747 extern bool srv_print_ddl_logs;
748 
749 extern bool srv_cmp_per_index_enabled;
750 
751 extern bool srv_redo_log;
752 
753 /** Status variables to be passed to MySQL */
754 extern struct export_var_t export_vars;
755 
756 #ifndef UNIV_HOTBACKUP
757 /** Global counters */
758 extern srv_stats_t srv_stats;
759 
760 /* Keys to register InnoDB threads with performance schema */
761 
762 #ifdef UNIV_PFS_THREAD
763 extern mysql_pfs_key_t log_archiver_thread_key;
764 extern mysql_pfs_key_t page_archiver_thread_key;
765 extern mysql_pfs_key_t buf_dump_thread_key;
766 extern mysql_pfs_key_t buf_resize_thread_key;
767 extern mysql_pfs_key_t clone_ddl_thread_key;
768 extern mysql_pfs_key_t clone_gtid_thread_key;
769 extern mysql_pfs_key_t dict_stats_thread_key;
770 extern mysql_pfs_key_t fts_optimize_thread_key;
771 extern mysql_pfs_key_t fts_parallel_merge_thread_key;
772 extern mysql_pfs_key_t fts_parallel_tokenization_thread_key;
773 extern mysql_pfs_key_t io_handler_thread_key;
774 extern mysql_pfs_key_t io_ibuf_thread_key;
775 extern mysql_pfs_key_t io_log_thread_key;
776 extern mysql_pfs_key_t io_read_thread_key;
777 extern mysql_pfs_key_t io_write_thread_key;
778 extern mysql_pfs_key_t log_writer_thread_key;
779 extern mysql_pfs_key_t log_closer_thread_key;
780 extern mysql_pfs_key_t log_checkpointer_thread_key;
781 extern mysql_pfs_key_t log_flusher_thread_key;
782 extern mysql_pfs_key_t log_write_notifier_thread_key;
783 extern mysql_pfs_key_t log_flush_notifier_thread_key;
784 extern mysql_pfs_key_t page_flush_coordinator_thread_key;
785 extern mysql_pfs_key_t page_flush_thread_key;
786 extern mysql_pfs_key_t recv_writer_thread_key;
787 extern mysql_pfs_key_t srv_error_monitor_thread_key;
788 extern mysql_pfs_key_t srv_lock_timeout_thread_key;
789 extern mysql_pfs_key_t srv_master_thread_key;
790 extern mysql_pfs_key_t srv_monitor_thread_key;
791 extern mysql_pfs_key_t srv_purge_thread_key;
792 extern mysql_pfs_key_t srv_worker_thread_key;
793 extern mysql_pfs_key_t trx_recovery_rollback_thread_key;
794 extern mysql_pfs_key_t srv_ts_alter_encrypt_thread_key;
795 extern mysql_pfs_key_t parallel_read_thread_key;
796 extern mysql_pfs_key_t parallel_read_ahead_thread_key;
797 #endif /* UNIV_PFS_THREAD */
798 #endif /* !UNIV_HOTBACKUP */
799 
800 #ifdef HAVE_PSI_STAGE_INTERFACE
801 /** Performance schema stage event for monitoring ALTER TABLE progress
802 everything after flush log_make_latest_checkpoint(). */
803 extern PSI_stage_info srv_stage_alter_table_end;
804 
805 /** Performance schema stage event for monitoring ALTER TABLE progress
806 log_make_latest_checkpoint(). */
807 extern PSI_stage_info srv_stage_alter_table_flush;
808 
809 /** Performance schema stage event for monitoring ALTER TABLE progress
810 row_merge_insert_index_tuples(). */
811 extern PSI_stage_info srv_stage_alter_table_insert;
812 
813 /** Performance schema stage event for monitoring ALTER TABLE progress
814 row_log_apply(). */
815 extern PSI_stage_info srv_stage_alter_table_log_index;
816 
817 /** Performance schema stage event for monitoring ALTER TABLE progress
818 row_log_table_apply(). */
819 extern PSI_stage_info srv_stage_alter_table_log_table;
820 
821 /** Performance schema stage event for monitoring ALTER TABLE progress
822 row_merge_sort(). */
823 extern PSI_stage_info srv_stage_alter_table_merge_sort;
824 
825 /** Performance schema stage event for monitoring ALTER TABLE progress
826 row_merge_read_clustered_index(). */
827 extern PSI_stage_info srv_stage_alter_table_read_pk_internal_sort;
828 
829 /** Performance schema stage event for monitoring ALTER TABLESPACE
830 ENCRYPTION progress. */
831 extern PSI_stage_info srv_stage_alter_tablespace_encryption;
832 
833 /** Performance schema stage event for monitoring buffer pool load progress. */
834 extern PSI_stage_info srv_stage_buffer_pool_load;
835 #endif /* HAVE_PSI_STAGE_INTERFACE */
836 
837 /** Performance schema stage event for monitoring clone file copy progress. */
838 extern PSI_stage_info srv_stage_clone_file_copy;
839 
840 /** Performance schema stage event for monitoring clone redo copy progress. */
841 extern PSI_stage_info srv_stage_clone_redo_copy;
842 
843 /** Performance schema stage event for monitoring clone page copy progress. */
844 extern PSI_stage_info srv_stage_clone_page_copy;
845 
846 #ifndef _WIN32
847 /** Alternatives for the file flush option in Unix.
848 @see innodb_flush_method_names */
849 enum srv_unix_flush_t {
850   SRV_UNIX_FSYNC = 0,  /*!< fsync, the default */
851   SRV_UNIX_O_DSYNC,    /*!< open log files in O_SYNC mode */
852   SRV_UNIX_LITTLESYNC, /*!< do not call os_file_flush()
853                        when writing data files, but do flush
854                        after writing to log files */
855   SRV_UNIX_NOSYNC,     /*!< do not flush after writing */
856   SRV_UNIX_O_DIRECT,   /*!< invoke os_file_set_nocache() on
857                        data files. This implies using
858                        non-buffered IO but still using fsync,
859                        the reason for which is that some FS
860                        do not flush meta-data when
861                        unbuffered IO happens */
862   SRV_UNIX_O_DIRECT_NO_FSYNC
863   /*!< do not use fsync() when using
864   direct IO i.e.: it can be set to avoid
865   the fsync() call that we make when
866   using SRV_UNIX_O_DIRECT. However, in
867   this case user/DBA should be sure about
868   the integrity of the meta-data */
869 };
870 extern enum srv_unix_flush_t srv_unix_file_flush_method;
871 
srv_is_direct_io()872 inline bool srv_is_direct_io() {
873   return (srv_unix_file_flush_method == SRV_UNIX_O_DIRECT ||
874           srv_unix_file_flush_method == SRV_UNIX_O_DIRECT_NO_FSYNC);
875 }
876 
877 #else
878 /** Alternatives for file i/o in Windows. @see innodb_flush_method_names. */
879 enum srv_win_flush_t {
880   /** unbuffered I/O; this is the default */
881   SRV_WIN_IO_UNBUFFERED = 0,
882   /** buffered I/O */
883   SRV_WIN_IO_NORMAL,
884 };
885 extern enum srv_win_flush_t srv_win_file_flush_method;
886 
srv_is_direct_io()887 inline bool srv_is_direct_io() {
888   return (srv_win_file_flush_method == SRV_WIN_IO_UNBUFFERED);
889 }
890 
891 #endif /* _WIN32 */
892 
893 /** Alternatives for srv_force_recovery. Non-zero values are intended
894 to help the user get a damaged database up so that he can dump intact
895 tables and rows with SELECT INTO OUTFILE. The database must not otherwise
896 be used with these options! A bigger number below means that all precautions
897 of lower numbers are included. */
898 enum {
899   SRV_FORCE_IGNORE_CORRUPT = 1,   /*!< let the server run even if it
900                                   detects a corrupt page */
901   SRV_FORCE_NO_BACKGROUND = 2,    /*!< prevent the main thread from
902                                   running: if a crash would occur
903                                   in purge, this prevents it */
904   SRV_FORCE_NO_TRX_UNDO = 3,      /*!< do not run trx rollback after
905                                   recovery */
906   SRV_FORCE_NO_IBUF_MERGE = 4,    /*!< prevent also ibuf operations:
907                                   if they would cause a crash, better
908                                   not do them */
909   SRV_FORCE_NO_UNDO_LOG_SCAN = 5, /*!< do not look at undo logs when
910                                   starting the database: InnoDB will
911                                   treat even incomplete transactions
912                                   as committed */
913   SRV_FORCE_NO_LOG_REDO = 6       /*!< do not do the log roll-forward
914                                   in connection with recovery */
915 };
916 
917 /* Alternatives for srv_innodb_stats_method, which could be changed by
918 setting innodb_stats_method */
919 enum srv_stats_method_name_enum {
920   SRV_STATS_NULLS_EQUAL,   /* All NULL values are treated as
921                            equal. This is the default setting
922                            for innodb_stats_method */
923   SRV_STATS_NULLS_UNEQUAL, /* All NULL values are treated as
924                            NOT equal. */
925   SRV_STATS_NULLS_IGNORED  /* NULL values are ignored */
926 };
927 
928 typedef enum srv_stats_method_name_enum srv_stats_method_name_t;
929 
930 #ifdef UNIV_DEBUG
931 /** Force all user tables to use page compression. */
932 extern ulong srv_debug_compress;
933 #endif /* UNIV_DEBUG */
934 
935 /** Types of threads existing in the system. */
936 enum srv_thread_type {
937   SRV_NONE,   /*!< None */
938   SRV_WORKER, /*!< threads serving parallelized
939               queries and queries released from
940               lock wait */
941   SRV_PURGE,  /*!< Purge coordinator thread */
942   SRV_MASTER  /*!< the master thread, (whose type
943               number must be biggest) */
944 };
945 
946 /** Boots Innobase server. */
947 void srv_boot(void);
948 /** Frees the data structures created in srv_init(). */
949 void srv_free(void);
950 /** Sets the info describing an i/o thread current state. */
951 void srv_set_io_thread_op_info(
952     ulint i,          /*!< in: the 'segment' of the i/o thread */
953     const char *str); /*!< in: constant char string describing the
954                       state */
955 /** Resets the info describing an i/o thread current state. */
956 void srv_reset_io_thread_op_info();
957 /** Tells the purge thread that there has been activity in the database
958  and wakes up the purge thread if it is suspended (not sleeping).  Note
959  that there is a small chance that the purge thread stays suspended
960  (we do not protect our operation with the srv_sys_t:mutex, for
961  performance reasons). */
962 void srv_wake_purge_thread_if_not_active(void);
963 /** Tells the Innobase server that there has been activity in the database
964  and wakes up the master thread if it is suspended (not sleeping). Used
965  in the MySQL interface. Note that there is a small chance that the master
966  thread stays suspended (we do not protect our operation with the kernel
967  mutex, for performace reasons). */
968 void srv_active_wake_master_thread_low(void);
969 #define srv_active_wake_master_thread()    \
970   do {                                     \
971     if (!srv_read_only_mode) {             \
972       srv_active_wake_master_thread_low(); \
973     }                                      \
974   } while (0)
975 /** Wakes up the master thread if it is suspended or being suspended. */
976 void srv_wake_master_thread(void);
977 #ifndef UNIV_HOTBACKUP
978 /** Outputs to a file the output of the InnoDB Monitor.
979 @param[in]    file      output stream
980 @param[in]    nowait    whether to wait for the exclusive global lock_sys latch
981 @param[out]   trx_start file position of the start of the list of active
982                         transactions
983 @param[out]   trx_end   file position of the end of the list of active
984                         transactions
985 @return false if not all information printed due to failure to obtain necessary
986         mutex */
987 bool srv_printf_innodb_monitor(FILE *file, bool nowait, ulint *trx_start,
988                                ulint *trx_end);
989 
990 /** Function to pass InnoDB status variables to MySQL */
991 void srv_export_innodb_status(void);
992 /** Get current server activity count. We don't hold srv_sys::mutex while
993  reading this value as it is only used in heuristics.
994  @return activity count. */
995 ulint srv_get_activity_count(void);
996 /** Check if there has been any activity.
997  @return false if no change in activity counter. */
998 ibool srv_check_activity(ulint old_activity_count); /*!< old activity count */
999 /** Increment the server activity counter. */
1000 void srv_inc_activity_count(void);
1001 
1002 /** Enqueues a task to server task queue and releases a worker thread, if there
1003  is a suspended one. */
1004 void srv_que_task_enqueue_low(que_thr_t *thr); /*!< in: query thread */
1005 
1006 /** A thread which prints the info output by various InnoDB monitors. */
1007 void srv_monitor_thread();
1008 
1009 /** A thread which prints warnings about semaphore waits which have lasted
1010 too long. These can be used to track bugs which cause hangs. */
1011 void srv_error_monitor_thread();
1012 
1013 /** The master thread controlling the server. */
1014 void srv_master_thread();
1015 
1016 /** Purge coordinator thread that schedules the purge tasks. */
1017 void srv_purge_coordinator_thread();
1018 
1019 /** Worker thread that reads tasks from the work queue and executes them. */
1020 void srv_worker_thread();
1021 
1022 /** Rotate default master key for UNDO tablespace. */
1023 void undo_rotate_default_master_key();
1024 
1025 /** Set encryption for UNDO tablespace with given space id.
1026 @param[in] space_id     undo tablespace id
1027 @param[in] mtr          mini-transaction
1028 @param[in] is_boot	true if it is called during server start up.
1029 @return false for success, true otherwise */
1030 bool set_undo_tablespace_encryption(space_id_t space_id, mtr_t *mtr,
1031                                     bool is_boot);
1032 
1033 /** Enable UNDO tablespaces encryption.
1034 @param[in] is_boot	true if it is called during server start up. In this
1035                         case, default master key will be used which will be
1036                         rotated later with actual master key from kyering.
1037 @return false for success, true otherwise. */
1038 bool srv_enable_undo_encryption(bool is_boot);
1039 
1040 /** Enable REDO log encryption.
1041 @param[in] is_boot	true if it is called during server start up. In this
1042                         case, default master key will be used which will be
1043                         rotated later with actual master key from kyering.
1044 @return false for success, true otherwise. */
1045 bool srv_enable_redo_encryption(bool is_boot);
1046 
1047 /** Get count of tasks in the queue.
1048  @return number of tasks in queue */
1049 ulint srv_get_task_queue_length(void);
1050 
1051 /** Releases threads of the type given from suspension in the thread table.
1052  NOTE! The server mutex has to be reserved by the caller!
1053  @return number of threads released: this may be less than n if not
1054  enough threads were suspended at the moment */
1055 ulint srv_release_threads(enum srv_thread_type type, /*!< in: thread type */
1056                           ulint n); /*!< in: number of threads to release */
1057 
1058 /** Check whether the master thread is active.
1059 This is polled during the final phase of shutdown.
1060 The first phase of server shutdown must have already been executed
1061 (or the server must not have been fully started up).
1062 @see srv_pre_dd_shutdown()
1063 @retval true   if any thread is active
1064 @retval false  if no thread is active */
1065 bool srv_master_thread_is_active();
1066 
1067 /** Wakeup the purge threads. */
1068 void srv_purge_wakeup(void);
1069 
1070 /** Check if the purge threads are active, both coordinator and worker threads
1071 @return true if any thread is active, false if no thread is active */
1072 bool srv_purge_threads_active();
1073 
1074 /** Initializes the synchronization primitives, memory system, and the thread
1075  local storage. */
1076 void srv_general_init();
1077 
1078 /** Create an undo tablespace with an explicit file name
1079 @param[in]	space_name	tablespace name
1080 @param[in]	file_name	file name
1081 @param[out]	space_id	Tablespace ID chosen
1082 @return DB_SUCCESS or error code */
1083 dberr_t srv_undo_tablespace_create(const char *space_name,
1084                                    const char *file_name, space_id_t space_id);
1085 
1086 /** Initialize undo::spaces and trx_sys_undo_spaces,
1087 called once during srv_start(). */
1088 void undo_spaces_init();
1089 
1090 /** Free the resources occupied by undo::spaces and trx_sys_undo_spaces,
1091 called once during thread de-initialization. */
1092 void undo_spaces_deinit();
1093 
1094 /** Set redo log variable for performance schema global status.
1095 @param[in]	enable	true => redo log enabled, false => redo log disabled */
1096 void set_srv_redo_log(bool enable);
1097 
1098 #ifdef UNIV_DEBUG
1099 struct SYS_VAR;
1100 
1101 /** Disables master thread. It's used by:
1102         SET GLOBAL innodb_master_thread_disabled_debug = 1 (0).
1103 @param[in]	thd		thread handle
1104 @param[in]	var		pointer to system variable
1105 @param[out]	var_ptr		where the formal string goes
1106 @param[in]	save		immediate result from check function */
1107 void srv_master_thread_disabled_debug_update(THD *thd, SYS_VAR *var,
1108                                              void *var_ptr, const void *save);
1109 #endif /* UNIV_DEBUG */
1110 #endif /* !UNIV_HOTBACKUP */
1111 
1112 /** Status variables to be passed to MySQL */
1113 struct export_var_t {
1114   ulint innodb_data_pending_reads;  /*!< Pending reads */
1115   ulint innodb_data_pending_writes; /*!< Pending writes */
1116   ulint innodb_data_pending_fsyncs; /*!< Pending fsyncs */
1117   ulint innodb_data_fsyncs;         /*!< Number of fsyncs so far */
1118   ulint innodb_data_read;           /*!< Data bytes read */
1119   ulint innodb_data_writes;         /*!< I/O write requests */
1120   ulint innodb_data_written;        /*!< Data bytes written */
1121   ulint innodb_data_reads;          /*!< I/O read requests */
1122   char innodb_buffer_pool_dump_status[OS_FILE_MAX_PATH +
1123                                       128]; /*!< Buf pool dump status */
1124   char innodb_buffer_pool_load_status[OS_FILE_MAX_PATH +
1125                                       128];   /*!< Buf pool load status */
1126   char innodb_buffer_pool_resize_status[512]; /*!< Buf pool resize status */
1127   ulint innodb_buffer_pool_pages_total;       /*!< Buffer pool size */
1128   ulint innodb_buffer_pool_pages_data;        /*!< Data pages */
1129   ulint innodb_buffer_pool_bytes_data;        /*!< File bytes used */
1130   ulint innodb_buffer_pool_pages_dirty;       /*!< Dirty data pages */
1131   ulint innodb_buffer_pool_bytes_dirty;       /*!< File bytes modified */
1132   ulint innodb_buffer_pool_pages_misc;        /*!< Miscellanous pages */
1133   ulint innodb_buffer_pool_pages_free;        /*!< Free pages */
1134 #ifdef UNIV_DEBUG
1135   ulint innodb_buffer_pool_pages_latched;  /*!< Latched pages */
1136 #endif                                     /* UNIV_DEBUG */
1137   ulint innodb_buffer_pool_read_requests;  /*!< buf_pool->stat.n_page_gets */
1138   ulint innodb_buffer_pool_reads;          /*!< srv_buf_pool_reads */
1139   ulint innodb_buffer_pool_wait_free;      /*!< srv_buf_pool_wait_free */
1140   ulint innodb_buffer_pool_pages_flushed;  /*!< srv_buf_pool_flushed */
1141   ulint innodb_buffer_pool_write_requests; /*!< srv_buf_pool_write_requests */
1142   ulint innodb_buffer_pool_read_ahead_rnd; /*!< srv_read_ahead_rnd */
1143   ulint innodb_buffer_pool_read_ahead;     /*!< srv_read_ahead */
1144   ulint innodb_buffer_pool_read_ahead_evicted; /*!< srv_read_ahead evicted*/
1145   ulint innodb_dblwr_pages_written;            /*!< srv_dblwr_pages_written */
1146   ulint innodb_dblwr_writes;                   /*!< srv_dblwr_writes */
1147   ulint innodb_log_waits;                      /*!< srv_log_waits */
1148   ulint innodb_log_write_requests;             /*!< srv_log_write_requests */
1149   ulint innodb_log_writes;                     /*!< srv_log_writes */
1150   lsn_t innodb_os_log_written;                 /*!< srv_os_log_written */
1151   ulint innodb_os_log_fsyncs;                  /*!< fil_n_log_flushes */
1152   ulint innodb_os_log_pending_writes;          /*!< srv_os_log_pending_writes */
1153   ulint innodb_os_log_pending_fsyncs;          /*!< fil_n_pending_log_flushes */
1154   ulint innodb_page_size;                      /*!< UNIV_PAGE_SIZE */
1155   ulint innodb_pages_created;          /*!< buf_pool->stat.n_pages_created */
1156   ulint innodb_pages_read;             /*!< buf_pool->stat.n_pages_read */
1157   ulint innodb_pages_written;          /*!< buf_pool->stat.n_pages_written */
1158   bool innodb_redo_log_enabled;        /*!< srv_redo_log */
1159   ulint innodb_row_lock_waits;         /*!< srv_n_lock_wait_count */
1160   ulint innodb_row_lock_current_waits; /*!< srv_n_lock_wait_current_count */
1161   int64_t innodb_row_lock_time;        /*!< srv_n_lock_wait_time
1162                                        / 1000 */
1163   ulint innodb_row_lock_time_avg;      /*!< srv_n_lock_wait_time
1164                                        / 1000
1165                                        / srv_n_lock_wait_count */
1166   ulint innodb_row_lock_time_max;      /*!< srv_n_lock_max_wait_time
1167                                        / 1000 */
1168   ulint innodb_rows_read;              /*!< srv_n_rows_read */
1169   ulint innodb_rows_inserted;          /*!< srv_n_rows_inserted */
1170   ulint innodb_rows_updated;           /*!< srv_n_rows_updated */
1171   ulint innodb_rows_deleted;           /*!< srv_n_rows_deleted */
1172   ulint innodb_system_rows_read;       /*!< srv_n_system_rows_read */
1173   ulint innodb_system_rows_inserted;   /*!< srv_n_system_rows_inserted */
1174   ulint innodb_system_rows_updated;    /*!< srv_n_system_rows_updated */
1175   ulint innodb_system_rows_deleted;    /*!< srv_n_system_rows_deleted*/
1176   ulint innodb_sampled_pages_read;
1177   ulint innodb_sampled_pages_skipped;
1178   ulint innodb_num_open_files;            /*!< fil_n_file_opened */
1179   ulint innodb_truncated_status_writes;   /*!< srv_truncated_status_writes */
1180   ulint innodb_undo_tablespaces_total;    /*!< total number of undo tablespaces
1181                                           innoDB is tracking. */
1182   ulint innodb_undo_tablespaces_implicit; /*!< number of undo tablespaces
1183                                           innoDB created implicitly. */
1184   ulint innodb_undo_tablespaces_explicit; /*!< number of undo tablespaces
1185                                           the dba created explicitly. */
1186   ulint innodb_undo_tablespaces_active;   /*!< number of active undo
1187                                           tablespaces */
1188 #ifdef UNIV_DEBUG
1189   ulint innodb_purge_trx_id_age;      /*!< rw_max_trx_no - purged trx_no */
1190   ulint innodb_purge_view_trx_id_age; /*!< rw_max_trx_no
1191                                       - purged view's min trx_no */
1192   ulint innodb_ahi_drop_lookups;      /*!< number of adaptive hash
1193                                       index lookups when freeing
1194                                       file pages */
1195 #endif                                /* UNIV_DEBUG */
1196 };
1197 
1198 #ifndef UNIV_HOTBACKUP
1199 /** Thread slot in the thread table.  */
1200 struct srv_slot_t {
1201   /** Thread type: user, utility etc. */
1202   srv_thread_type type;
1203 
1204   /** TRUE if this slot is in use. */
1205   bool in_use;
1206 
1207   /** TRUE if the thread is waiting for the event of this slot. */
1208   bool suspended;
1209 
1210   /** Time when the thread was suspended. Initialized by
1211   lock_wait_table_reserve_slot() for lock wait. */
1212   ib_time_monotonic_t suspend_time;
1213 
1214   /** Stores the current value of lock_wait_table_reservations, when
1215   lock_wait_table_reserve_slot is called.
1216   This can be used as a version number to avoid ABA problems.
1217   The difference lock_wait_table_reservations - reservation_no tells us how many
1218   other threads got suspended while our thr was sleeping.
1219   This can be used to determine if the wait was unfairly long, and it is time to
1220   boost trx->lock.schedule_weight.
1221   Protected by lock->wait_mutex. */
1222   uint64_t reservation_no;
1223 
1224   /** Wait time that if exceeded the thread will be timed out.
1225   Initialized by lock_wait_table_reserve_slot() for lock wait. */
1226   ulong wait_timeout;
1227 
1228   /** Event used in suspending the thread when it has nothing to do. */
1229   os_event_t event;
1230 
1231   /** Suspended query thread (only used for user threads). */
1232   que_thr_t *thr;
1233 };
1234 #endif /* !UNIV_HOTBACKUP */
1235 
1236 #endif
1237