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 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 21 it under the terms of the GNU General Public License, version 2.0, 22 as published by the Free Software Foundation. 23 24 This program is also distributed with certain software (including 25 but not limited to OpenSSL) that is licensed under separate terms, 26 as designated in a particular file or component or in included license 27 documentation. The authors of MySQL hereby grant you an additional 28 permission to link the program and your derivative works with the 29 separately licensed software that they have included with MySQL. 30 31 This program is distributed in the hope that it will be useful, 32 but WITHOUT ANY WARRANTY; without even the implied warranty of 33 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 GNU General Public License, version 2.0, 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 Street, Suite 500, Boston, MA 02110-1335 USA 39 40 *****************************************************************************/ 41 42 /**************************************************//** 43 @file include/srv0srv.h 44 The server main program 45 46 Created 10/10/1995 Heikki Tuuri 47 *******************************************************/ 48 49 #ifndef srv0srv_h 50 #define srv0srv_h 51 52 #include "univ.i" 53 #ifndef UNIV_HOTBACKUP 54 #include "log0log.h" 55 #include "sync0sync.h" 56 #include "os0sync.h" 57 #include "que0types.h" 58 #include "trx0types.h" 59 #include "srv0conc.h" 60 #include "buf0checksum.h" 61 #include "ut0counter.h" 62 63 /* Global counters used inside InnoDB. */ 64 struct srv_stats_t { 65 typedef ib_counter_t<lsn_t, 1, single_indexer_t> lsn_ctr_1_t; 66 typedef ib_counter_t<ulint, 1, single_indexer_t> ulint_ctr_1_t; 67 typedef ib_counter_t<lint, 1, single_indexer_t> lint_ctr_1_t; 68 typedef ib_counter_t<ulint, 64> ulint_ctr_64_t; 69 typedef ib_counter_t<ib_int64_t, 1, single_indexer_t> ib_int64_ctr_1_t; 70 71 /** Count the amount of data written in total (in bytes) */ 72 ulint_ctr_1_t data_written; 73 74 /** Number of the log write requests done */ 75 ulint_ctr_1_t log_write_requests; 76 77 /** Number of physical writes to the log performed */ 78 ulint_ctr_1_t log_writes; 79 80 /** Amount of data written to the log files in bytes */ 81 lsn_ctr_1_t os_log_written; 82 83 /** Number of writes being done to the log files */ 84 lint_ctr_1_t os_log_pending_writes; 85 86 /** We increase this counter, when we don't have enough 87 space in the log buffer and have to flush it */ 88 ulint_ctr_1_t log_waits; 89 90 /** Count the number of times the doublewrite buffer was flushed */ 91 ulint_ctr_1_t dblwr_writes; 92 93 /** Store the number of pages that have been flushed to the 94 doublewrite buffer */ 95 ulint_ctr_1_t dblwr_pages_written; 96 97 /** Store the number of write requests issued */ 98 ulint_ctr_1_t buf_pool_write_requests; 99 100 /** Store the number of times when we had to wait for a free page 101 in the buffer pool. It happens when the buffer pool is full and we 102 need to make a flush, in order to be able to read or create a page. */ 103 ulint_ctr_1_t buf_pool_wait_free; 104 105 /** Count the number of pages that were written from buffer 106 pool to the disk */ 107 ulint_ctr_1_t buf_pool_flushed; 108 109 /** Number of buffer pool reads that led to the reading of 110 a disk page */ 111 ulint_ctr_1_t buf_pool_reads; 112 113 /** Number of data read in total (in bytes) */ 114 ulint_ctr_1_t data_read; 115 116 /** Wait time of database locks */ 117 ib_int64_ctr_1_t n_lock_wait_time; 118 119 /** Number of database lock waits */ 120 ulint_ctr_1_t n_lock_wait_count; 121 122 /** Number of threads currently waiting on database locks */ 123 lint_ctr_1_t n_lock_wait_current_count; 124 125 /** Number of rows read. */ 126 ulint_ctr_64_t n_rows_read; 127 128 /** Number of rows updated */ 129 ulint_ctr_64_t n_rows_updated; 130 131 /** Number of rows deleted */ 132 ulint_ctr_64_t n_rows_deleted; 133 134 /** Number of rows inserted */ 135 ulint_ctr_64_t n_rows_inserted; 136 }; 137 138 extern const char* srv_main_thread_op_info; 139 140 /** Prefix used by MySQL to indicate pre-5.1 table name encoding */ 141 extern const char srv_mysql50_table_name_prefix[10]; 142 143 /* The monitor thread waits on this event. */ 144 extern os_event_t srv_monitor_event; 145 146 /* The error monitor thread waits on this event. */ 147 extern os_event_t srv_error_event; 148 149 /** The buffer pool dump/load thread waits on this event. */ 150 extern os_event_t srv_buf_dump_event; 151 152 /** The buffer pool dump/load file name */ 153 #define SRV_BUF_DUMP_FILENAME_DEFAULT "ib_buffer_pool" 154 extern char* srv_buf_dump_filename; 155 156 /** Boolean config knobs that tell InnoDB to dump the buffer pool at shutdown 157 and/or load it during startup. */ 158 extern char srv_buffer_pool_dump_at_shutdown; 159 extern char srv_buffer_pool_load_at_startup; 160 161 /* Whether to disable file system cache if it is defined */ 162 extern char srv_disable_sort_file_cache; 163 164 /* If the last data file is auto-extended, we add this many pages to it 165 at a time */ 166 #define SRV_AUTO_EXTEND_INCREMENT \ 167 (srv_auto_extend_increment * ((1024 * 1024) / UNIV_PAGE_SIZE)) 168 169 /* Mutex for locking srv_monitor_file. Not created if srv_read_only_mode */ 170 extern ib_mutex_t srv_monitor_file_mutex; 171 /* Temporary file for innodb monitor output */ 172 extern FILE* srv_monitor_file; 173 /* Mutex for locking srv_dict_tmpfile. Only created if !srv_read_only_mode. 174 This mutex has a very high rank; threads reserving it should not 175 be holding any InnoDB latches. */ 176 extern ib_mutex_t srv_dict_tmpfile_mutex; 177 /* Temporary file for output from the data dictionary */ 178 extern FILE* srv_dict_tmpfile; 179 /* Mutex for locking srv_misc_tmpfile. Only created if !srv_read_only_mode. 180 This mutex has a very low rank; threads reserving it should not 181 acquire any further latches or sleep before releasing this one. */ 182 extern ib_mutex_t srv_misc_tmpfile_mutex; 183 /* Temporary file for miscellanous diagnostic output */ 184 extern FILE* srv_misc_tmpfile; 185 186 /* Server parameters which are read from the initfile */ 187 188 extern char* srv_data_home; 189 190 #ifdef UNIV_LOG_ARCHIVE 191 extern char* srv_arch_dir; 192 #endif /* UNIV_LOG_ARCHIVE */ 193 194 /** Set if InnoDB must operate in read-only mode. We don't do any 195 recovery and open all tables in RO mode instead of RW mode. We don't 196 sync the max trx id to disk either. */ 197 extern my_bool srv_read_only_mode; 198 /** Set if InnoDB operates in read-only mode or innodb-force-recovery 199 is greater than SRV_FORCE_NO_TRX_UNDO. */ 200 extern my_bool high_level_read_only; 201 /** store to its own file each table created by an user; data 202 dictionary tables are in the system tablespace 0 */ 203 extern my_bool srv_file_per_table; 204 /** Sleep delay for threads waiting to enter InnoDB. In micro-seconds. */ 205 extern ulong srv_thread_sleep_delay; 206 #if defined(HAVE_ATOMIC_BUILTINS) 207 /** Maximum sleep delay (in micro-seconds), value of 0 disables it.*/ 208 extern ulong srv_adaptive_max_sleep_delay; 209 #endif /* HAVE_ATOMIC_BUILTINS */ 210 211 /** The file format to use on new *.ibd files. */ 212 extern ulint srv_file_format; 213 /** Whether to check file format during startup. A value of 214 UNIV_FORMAT_MAX + 1 means no checking ie. FALSE. The default is to 215 set it to the highest format we support. */ 216 extern ulint srv_max_file_format_at_startup; 217 /** Place locks to records only i.e. do not use next-key locking except 218 on duplicate key checking and foreign key checking */ 219 extern ibool srv_locks_unsafe_for_binlog; 220 221 /** Sort buffer size in index creation */ 222 extern ulong srv_sort_buf_size; 223 /** Maximum modification log file size for online index creation */ 224 extern unsigned long long srv_online_max_size; 225 226 /* If this flag is TRUE, then we will use the native aio of the 227 OS (provided we compiled Innobase with it in), otherwise we will 228 use simulated aio we build below with threads. 229 Currently we support native aio on windows and linux */ 230 extern my_bool srv_use_native_aio; 231 extern my_bool srv_numa_interleave; 232 #ifdef __WIN__ 233 extern ibool srv_use_native_conditions; 234 #endif /* __WIN__ */ 235 #endif /* !UNIV_HOTBACKUP */ 236 237 /** Server undo tablespaces directory, can be absolute path. */ 238 extern char* srv_undo_dir; 239 240 /** Number of undo tablespaces to use. */ 241 extern ulong srv_undo_tablespaces; 242 243 /** The number of UNDO tablespaces that are open and ready to use. */ 244 extern ulint srv_undo_tablespaces_open; 245 246 /* The number of undo segments to use */ 247 extern ulong srv_undo_logs; 248 249 extern ulint srv_n_data_files; 250 extern char** srv_data_file_names; 251 extern ulint* srv_data_file_sizes; 252 extern ulint* srv_data_file_is_raw_partition; 253 254 extern ibool srv_auto_extend_last_data_file; 255 extern ulint srv_last_file_size_max; 256 extern char* srv_log_group_home_dir; 257 #ifndef UNIV_HOTBACKUP 258 extern ulong srv_auto_extend_increment; 259 260 extern ibool srv_created_new_raw; 261 262 /** Maximum number of srv_n_log_files, or innodb_log_files_in_group */ 263 #define SRV_N_LOG_FILES_MAX 100 264 extern ulong srv_n_log_files; 265 extern ib_uint64_t srv_log_file_size; 266 extern ib_uint64_t srv_log_file_size_requested; 267 extern ulint srv_log_buffer_size; 268 extern ulong srv_flush_log_at_trx_commit; 269 extern uint srv_flush_log_at_timeout; 270 extern char srv_adaptive_flushing; 271 272 #ifdef WITH_INNODB_DISALLOW_WRITES 273 /* When this event is reset we do not allow any file writes to take place. */ 274 extern os_event_t srv_allow_writes_event; 275 #endif /* WITH_INNODB_DISALLOW_WRITES */ 276 /* If this flag is TRUE, then we will load the indexes' (and tables') metadata 277 even if they are marked as "corrupted". Mostly it is for DBA to process 278 corrupted index and table */ 279 extern my_bool srv_load_corrupted; 280 281 /* The sort order table of the MySQL latin1_swedish_ci character set 282 collation */ 283 extern const byte* srv_latin1_ordering; 284 #ifndef UNIV_HOTBACKUP 285 extern my_bool srv_use_sys_malloc; 286 #else 287 extern ibool srv_use_sys_malloc; 288 #endif /* UNIV_HOTBACKUP */ 289 extern ulint srv_buf_pool_size; /*!< requested size in bytes */ 290 extern ulint srv_buf_pool_instances; /*!< requested number of buffer pool instances */ 291 extern ulong srv_n_page_hash_locks; /*!< number of locks to 292 protect buf_pool->page_hash */ 293 extern ulong srv_LRU_scan_depth; /*!< Scan depth for LRU 294 flush batch */ 295 extern ulong srv_flush_neighbors; /*!< whether or not to flush 296 neighbors of a block */ 297 extern ulint srv_buf_pool_old_size; /*!< previously requested size */ 298 extern ulint srv_buf_pool_curr_size; /*!< current size in bytes */ 299 extern ulint srv_mem_pool_size; 300 extern ulint srv_lock_table_size; 301 302 extern ulint srv_n_file_io_threads; 303 extern my_bool srv_random_read_ahead; 304 extern ulong srv_read_ahead_threshold; 305 extern ulint srv_n_read_io_threads; 306 extern ulint srv_n_write_io_threads; 307 308 /* Number of IO operations per second the server can do */ 309 extern ulong srv_io_capacity; 310 311 /* We use this dummy default value at startup for max_io_capacity. 312 The real value is set based on the value of io_capacity. */ 313 #define SRV_MAX_IO_CAPACITY_DUMMY_DEFAULT (~0UL) 314 #define SRV_MAX_IO_CAPACITY_LIMIT (~0UL) 315 extern ulong srv_max_io_capacity; 316 /* Returns the number of IO operations that is X percent of the 317 capacity. PCT_IO(5) -> returns the number of IO operations that 318 is 5% of the max where max is srv_io_capacity. */ 319 #define PCT_IO(p) ((ulong) (srv_io_capacity * ((double) (p) / 100.0))) 320 321 /* The "innodb_stats_method" setting, decides how InnoDB is going 322 to treat NULL value when collecting statistics. It is not defined 323 as enum type because the configure option takes unsigned integer type. */ 324 extern ulong srv_innodb_stats_method; 325 326 #ifdef UNIV_LOG_ARCHIVE 327 extern ibool srv_log_archive_on; 328 extern ibool srv_archive_recovery; 329 extern ib_uint64_t srv_archive_recovery_limit_lsn; 330 #endif /* UNIV_LOG_ARCHIVE */ 331 332 extern char* srv_file_flush_method_str; 333 extern ulint srv_unix_file_flush_method; 334 extern ulint srv_win_file_flush_method; 335 336 extern ulint srv_max_n_open_files; 337 338 extern ulong srv_max_dirty_pages_pct; 339 extern ulong srv_max_dirty_pages_pct_lwm; 340 341 extern ulong srv_adaptive_flushing_lwm; 342 extern ulong srv_flushing_avg_loops; 343 344 extern ulong srv_force_recovery; 345 #ifndef DBUG_OFF 346 extern ulong srv_force_recovery_crash; 347 #endif /* !DBUG_OFF */ 348 349 extern ulint srv_fast_shutdown; /*!< If this is 1, do not do a 350 purge and index buffer merge. 351 If this 2, do not even flush the 352 buffer pool to data files at the 353 shutdown: we effectively 'crash' 354 InnoDB (but lose no committed 355 transactions). */ 356 extern ibool srv_innodb_status; 357 358 extern unsigned long long srv_stats_transient_sample_pages; 359 extern my_bool srv_stats_persistent; 360 extern unsigned long long srv_stats_persistent_sample_pages; 361 extern my_bool srv_stats_auto_recalc; 362 extern my_bool srv_stats_include_delete_marked; 363 364 extern ibool srv_use_doublewrite_buf; 365 extern ulong srv_doublewrite_batch_size; 366 extern ulong srv_checksum_algorithm; 367 368 extern ulong srv_max_buf_pool_modified_pct; 369 extern ulong srv_max_purge_lag; 370 extern ulong srv_max_purge_lag_delay; 371 372 extern ulong srv_replication_delay; 373 /*-------------------------------------------*/ 374 375 extern my_bool srv_print_innodb_monitor; 376 extern my_bool srv_print_innodb_lock_monitor; 377 extern ibool srv_print_innodb_tablespace_monitor; 378 extern ibool srv_print_verbose_log; 379 #define DEPRECATED_MSG_INNODB_TABLE_MONITOR \ 380 "Using innodb_table_monitor is deprecated and it may be removed " \ 381 "in future releases. Please use the InnoDB INFORMATION_SCHEMA " \ 382 "tables instead, see " REFMAN "innodb-i_s-tables.html" 383 extern ibool srv_print_innodb_table_monitor; 384 385 extern ibool srv_monitor_active; 386 extern ibool srv_error_monitor_active; 387 388 /* TRUE during the lifetime of the buffer pool dump/load thread */ 389 extern ibool srv_buf_dump_thread_active; 390 391 /* TRUE during the lifetime of the stats thread */ 392 extern ibool srv_dict_stats_thread_active; 393 394 extern ulong srv_n_spin_wait_rounds; 395 extern ulong srv_n_free_tickets_to_enter; 396 extern ulong srv_thread_sleep_delay; 397 extern ulong srv_spin_wait_delay; 398 extern ibool srv_priority_boost; 399 400 extern ulint srv_truncated_status_writes; 401 extern ulint srv_available_undo_logs; 402 403 extern ulint srv_mem_pool_size; 404 extern ulint srv_lock_table_size; 405 406 #ifdef UNIV_DEBUG 407 extern ibool srv_print_thread_releases; 408 extern ibool srv_print_lock_waits; 409 extern ibool srv_print_buf_io; 410 extern ibool srv_print_log_io; 411 extern ibool srv_print_latch_waits; 412 #else /* UNIV_DEBUG */ 413 # define srv_print_thread_releases FALSE 414 # define srv_print_lock_waits FALSE 415 # define srv_print_buf_io FALSE 416 # define srv_print_log_io FALSE 417 # define srv_print_latch_waits FALSE 418 #endif /* UNIV_DEBUG */ 419 420 #if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG 421 extern my_bool srv_ibuf_disable_background_merge; 422 #endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */ 423 424 #ifdef UNIV_DEBUG 425 extern my_bool srv_purge_view_update_only_debug; 426 #endif /* UNIV_DEBUG */ 427 428 extern ulint srv_fatal_semaphore_wait_threshold; 429 #define SRV_SEMAPHORE_WAIT_EXTENSION 7200 430 extern ulint srv_dml_needed_delay; 431 432 #ifndef HAVE_ATOMIC_BUILTINS 433 /** Mutex protecting some server global variables. */ 434 extern ib_mutex_t server_mutex; 435 #endif /* !HAVE_ATOMIC_BUILTINS */ 436 437 #define SRV_MAX_N_IO_THREADS 130 438 439 /* Array of English strings describing the current state of an 440 i/o handler thread */ 441 extern const char* srv_io_thread_op_info[]; 442 extern const char* srv_io_thread_function[]; 443 444 /* the number of purge threads to use from the worker pool (currently 0 or 1) */ 445 extern ulong srv_n_purge_threads; 446 447 /* the number of pages to purge in one batch */ 448 extern ulong srv_purge_batch_size; 449 450 /* the number of sync wait arrays */ 451 extern ulong srv_sync_array_size; 452 453 /* print all user-level transactions deadlocks to mysqld stderr */ 454 extern my_bool srv_print_all_deadlocks; 455 456 extern my_bool srv_cmp_per_index_enabled; 457 458 /** Status variables to be passed to MySQL */ 459 extern struct export_var_t export_vars; 460 461 /** Global counters */ 462 extern srv_stats_t srv_stats; 463 464 # ifdef UNIV_PFS_THREAD 465 /* Keys to register InnoDB threads with performance schema */ 466 extern mysql_pfs_key_t buf_page_cleaner_thread_key; 467 extern mysql_pfs_key_t trx_rollback_clean_thread_key; 468 extern mysql_pfs_key_t io_handler_thread_key; 469 extern mysql_pfs_key_t srv_lock_timeout_thread_key; 470 extern mysql_pfs_key_t srv_error_monitor_thread_key; 471 extern mysql_pfs_key_t srv_monitor_thread_key; 472 extern mysql_pfs_key_t srv_master_thread_key; 473 extern mysql_pfs_key_t srv_purge_thread_key; 474 extern mysql_pfs_key_t recv_writer_thread_key; 475 476 /* This macro register the current thread and its key with performance 477 schema */ 478 # define pfs_register_thread(key) \ 479 do { \ 480 struct PSI_thread* psi = PSI_THREAD_CALL(new_thread)(key, NULL, 0);\ 481 PSI_THREAD_CALL(set_thread)(psi); \ 482 } while (0) 483 484 /* This macro delist the current thread from performance schema */ 485 # define pfs_delete_thread() \ 486 do { \ 487 PSI_THREAD_CALL(delete_current_thread)(); \ 488 } while (0) 489 # endif /* UNIV_PFS_THREAD */ 490 491 #endif /* !UNIV_HOTBACKUP */ 492 493 /** Types of raw partitions in innodb_data_file_path */ 494 enum { 495 SRV_NOT_RAW = 0, /*!< Not a raw partition */ 496 SRV_NEW_RAW, /*!< A 'newraw' partition, only to be 497 initialized */ 498 SRV_OLD_RAW /*!< An initialized raw partition */ 499 }; 500 501 /** Alternatives for the file flush option in Unix; see the InnoDB manual 502 about what these mean */ 503 enum { 504 SRV_UNIX_FSYNC = 1, /*!< fsync, the default */ 505 SRV_UNIX_O_DSYNC, /*!< open log files in O_SYNC mode */ 506 SRV_UNIX_LITTLESYNC, /*!< do not call os_file_flush() 507 when writing data files, but do flush 508 after writing to log files */ 509 SRV_UNIX_NOSYNC, /*!< do not flush after writing */ 510 SRV_UNIX_O_DIRECT, /*!< invoke os_file_set_nocache() on 511 data files. This implies using 512 non-buffered IO but still using fsync, 513 the reason for which is that some FS 514 do not flush meta-data when 515 unbuffered IO happens */ 516 SRV_UNIX_O_DIRECT_NO_FSYNC 517 /*!< do not use fsync() when using 518 direct IO i.e.: it can be set to avoid 519 the fsync() call that we make when 520 using SRV_UNIX_O_DIRECT. However, in 521 this case user/DBA should be sure about 522 the integrity of the meta-data */ 523 }; 524 525 /** Alternatives for file i/o in Windows */ 526 enum { 527 SRV_WIN_IO_NORMAL = 1, /*!< buffered I/O */ 528 SRV_WIN_IO_UNBUFFERED /*!< unbuffered I/O; this is the default */ 529 }; 530 531 /** Alternatives for srv_force_recovery. Non-zero values are intended 532 to help the user get a damaged database up so that he can dump intact 533 tables and rows with SELECT INTO OUTFILE. The database must not otherwise 534 be used with these options! A bigger number below means that all precautions 535 of lower numbers are included. */ 536 enum { 537 SRV_FORCE_IGNORE_CORRUPT = 1, /*!< let the server run even if it 538 detects a corrupt page */ 539 SRV_FORCE_NO_BACKGROUND = 2, /*!< prevent the main thread from 540 running: if a crash would occur 541 in purge, this prevents it */ 542 SRV_FORCE_NO_TRX_UNDO = 3, /*!< do not run trx rollback after 543 recovery */ 544 SRV_FORCE_NO_IBUF_MERGE = 4, /*!< prevent also ibuf operations: 545 if they would cause a crash, better 546 not do them */ 547 SRV_FORCE_NO_UNDO_LOG_SCAN = 5, /*!< do not look at undo logs when 548 starting the database: InnoDB will 549 treat even incomplete transactions 550 as committed */ 551 SRV_FORCE_NO_LOG_REDO = 6 /*!< do not do the log roll-forward 552 in connection with recovery */ 553 }; 554 555 /* Alternatives for srv_innodb_stats_method, which could be changed by 556 setting innodb_stats_method */ 557 enum srv_stats_method_name_enum { 558 SRV_STATS_NULLS_EQUAL, /* All NULL values are treated as 559 equal. This is the default setting 560 for innodb_stats_method */ 561 SRV_STATS_NULLS_UNEQUAL, /* All NULL values are treated as 562 NOT equal. */ 563 SRV_STATS_NULLS_IGNORED /* NULL values are ignored */ 564 }; 565 566 typedef enum srv_stats_method_name_enum srv_stats_method_name_t; 567 568 #ifndef UNIV_HOTBACKUP 569 /** Types of threads existing in the system. */ 570 enum srv_thread_type { 571 SRV_NONE, /*!< None */ 572 SRV_WORKER, /*!< threads serving parallelized 573 queries and queries released from 574 lock wait */ 575 SRV_PURGE, /*!< Purge coordinator thread */ 576 SRV_MASTER /*!< the master thread, (whose type 577 number must be biggest) */ 578 }; 579 580 /*********************************************************************//** 581 Boots Innobase server. */ 582 UNIV_INTERN 583 void 584 srv_boot(void); 585 /*==========*/ 586 /*********************************************************************//** 587 Initializes the server. */ 588 UNIV_INTERN 589 void 590 srv_init(void); 591 /*==========*/ 592 /*********************************************************************//** 593 Frees the data structures created in srv_init(). */ 594 UNIV_INTERN 595 void 596 srv_free(void); 597 /*==========*/ 598 /*********************************************************************//** 599 Initializes the synchronization primitives, memory system, and the thread 600 local storage. */ 601 UNIV_INTERN 602 void 603 srv_general_init(void); 604 /*==================*/ 605 /*********************************************************************//** 606 Sets the info describing an i/o thread current state. */ 607 UNIV_INTERN 608 void 609 srv_set_io_thread_op_info( 610 /*======================*/ 611 ulint i, /*!< in: the 'segment' of the i/o thread */ 612 const char* str); /*!< in: constant char string describing the 613 state */ 614 /*********************************************************************//** 615 Resets the info describing an i/o thread current state. */ 616 UNIV_INTERN 617 void 618 srv_reset_io_thread_op_info(); 619 /*=========================*/ 620 /*******************************************************************//** 621 Tells the purge thread that there has been activity in the database 622 and wakes up the purge thread if it is suspended (not sleeping). Note 623 that there is a small chance that the purge thread stays suspended 624 (we do not protect our operation with the srv_sys_t:mutex, for 625 performance reasons). */ 626 UNIV_INTERN 627 void 628 srv_wake_purge_thread_if_not_active(void); 629 /*=====================================*/ 630 /*******************************************************************//** 631 Tells the Innobase server that there has been activity in the database 632 and wakes up the master thread if it is suspended (not sleeping). Used 633 in the MySQL interface. Note that there is a small chance that the master 634 thread stays suspended (we do not protect our operation with the kernel 635 mutex, for performace reasons). */ 636 UNIV_INTERN 637 void 638 srv_active_wake_master_thread(void); 639 /*===============================*/ 640 /*******************************************************************//** 641 Wakes up the master thread if it is suspended or being suspended. */ 642 UNIV_INTERN 643 void 644 srv_wake_master_thread(void); 645 /*========================*/ 646 /******************************************************************//** 647 Outputs to a file the output of the InnoDB Monitor. 648 @return FALSE if not all information printed 649 due to failure to obtain necessary mutex */ 650 UNIV_INTERN 651 ibool 652 srv_printf_innodb_monitor( 653 /*======================*/ 654 FILE* file, /*!< in: output stream */ 655 ibool nowait, /*!< in: whether to wait for the 656 lock_sys_t::mutex */ 657 ulint* trx_start, /*!< out: file position of the start of 658 the list of active transactions */ 659 ulint* trx_end); /*!< out: file position of the end of 660 the list of active transactions */ 661 662 /******************************************************************//** 663 Function to pass InnoDB status variables to MySQL */ 664 UNIV_INTERN 665 void 666 srv_export_innodb_status(void); 667 /*==========================*/ 668 /*******************************************************************//** 669 Get current server activity count. We don't hold srv_sys::mutex while 670 reading this value as it is only used in heuristics. 671 @return activity count. */ 672 UNIV_INTERN 673 ulint 674 srv_get_activity_count(void); 675 /*========================*/ 676 /*******************************************************************//** 677 Check if there has been any activity. 678 @return FALSE if no change in activity counter. */ 679 UNIV_INTERN 680 ibool 681 srv_check_activity( 682 /*===============*/ 683 ulint old_activity_count); /*!< old activity count */ 684 /******************************************************************//** 685 Increment the server activity counter. */ 686 UNIV_INTERN 687 void 688 srv_inc_activity_count(void); 689 /*=========================*/ 690 691 /**********************************************************************//** 692 Enqueues a task to server task queue and releases a worker thread, if there 693 is a suspended one. */ 694 UNIV_INTERN 695 void 696 srv_que_task_enqueue_low( 697 /*=====================*/ 698 que_thr_t* thr); /*!< in: query thread */ 699 700 /**********************************************************************//** 701 Check whether any background thread is active. If so, return the thread 702 type. 703 @return SRV_NONE if all are are suspended or have exited, thread 704 type if any are still active. */ 705 UNIV_INTERN 706 enum srv_thread_type 707 srv_get_active_thread_type(void); 708 /*============================*/ 709 710 extern "C" { 711 712 /*********************************************************************//** 713 A thread which prints the info output by various InnoDB monitors. 714 @return a dummy parameter */ 715 UNIV_INTERN 716 os_thread_ret_t 717 DECLARE_THREAD(srv_monitor_thread)( 718 /*===============================*/ 719 void* arg); /*!< in: a dummy parameter required by 720 os_thread_create */ 721 722 /*********************************************************************//** 723 The master thread controlling the server. 724 @return a dummy parameter */ 725 UNIV_INTERN 726 os_thread_ret_t 727 DECLARE_THREAD(srv_master_thread)( 728 /*==============================*/ 729 void* arg); /*!< in: a dummy parameter required by 730 os_thread_create */ 731 732 /************************************************************************* 733 A thread which prints warnings about semaphore waits which have lasted 734 too long. These can be used to track bugs which cause hangs. 735 @return a dummy parameter */ 736 UNIV_INTERN 737 os_thread_ret_t 738 DECLARE_THREAD(srv_error_monitor_thread)( 739 /*=====================================*/ 740 void* arg); /*!< in: a dummy parameter required by 741 os_thread_create */ 742 743 /*********************************************************************//** 744 Purge coordinator thread that schedules the purge tasks. 745 @return a dummy parameter */ 746 UNIV_INTERN 747 os_thread_ret_t 748 DECLARE_THREAD(srv_purge_coordinator_thread)( 749 /*=========================================*/ 750 void* arg MY_ATTRIBUTE((unused))); /*!< in: a dummy parameter 751 required by os_thread_create */ 752 753 /*********************************************************************//** 754 Worker thread that reads tasks from the work queue and executes them. 755 @return a dummy parameter */ 756 UNIV_INTERN 757 os_thread_ret_t 758 DECLARE_THREAD(srv_worker_thread)( 759 /*==============================*/ 760 void* arg MY_ATTRIBUTE((unused))); /*!< in: a dummy parameter 761 required by os_thread_create */ 762 } /* extern "C" */ 763 764 /**********************************************************************//** 765 Get count of tasks in the queue. 766 @return number of tasks in queue */ 767 UNIV_INTERN 768 ulint 769 srv_get_task_queue_length(void); 770 /*===========================*/ 771 772 /*********************************************************************//** 773 Releases threads of the type given from suspension in the thread table. 774 NOTE! The server mutex has to be reserved by the caller! 775 @return number of threads released: this may be less than n if not 776 enough threads were suspended at the moment */ 777 UNIV_INTERN 778 ulint 779 srv_release_threads( 780 /*================*/ 781 enum srv_thread_type type, /*!< in: thread type */ 782 ulint n); /*!< in: number of threads to release */ 783 784 /**********************************************************************//** 785 Check whether any background thread are active. If so print which thread 786 is active. Send the threads wakeup signal. 787 @return name of thread that is active or NULL */ 788 UNIV_INTERN 789 const char* 790 srv_any_background_threads_are_active(void); 791 /*=======================================*/ 792 793 /**********************************************************************//** 794 Wakeup the purge threads. */ 795 UNIV_INTERN 796 void 797 srv_purge_wakeup(void); 798 /*==================*/ 799 800 /** Check whether given space id is undo tablespace id 801 @param[in] space_id space id to check 802 @return true if it is undo tablespace else false. */ 803 bool 804 srv_is_undo_tablespace( 805 ulint space_id); 806 807 /** Status variables to be passed to MySQL */ 808 struct export_var_t{ 809 ulint innodb_data_pending_reads; /*!< Pending reads */ 810 ulint innodb_data_pending_writes; /*!< Pending writes */ 811 ulint innodb_data_pending_fsyncs; /*!< Pending fsyncs */ 812 ulint innodb_data_fsyncs; /*!< Number of fsyncs so far */ 813 ulint innodb_data_read; /*!< Data bytes read */ 814 ulint innodb_data_writes; /*!< I/O write requests */ 815 ulint innodb_data_written; /*!< Data bytes written */ 816 ulint innodb_data_reads; /*!< I/O read requests */ 817 char innodb_buffer_pool_dump_status[512];/*!< Buf pool dump status */ 818 char innodb_buffer_pool_load_status[512];/*!< Buf pool load status */ 819 ulint innodb_buffer_pool_pages_total; /*!< Buffer pool size */ 820 ulint innodb_buffer_pool_pages_data; /*!< Data pages */ 821 ulint innodb_buffer_pool_bytes_data; /*!< File bytes used */ 822 ulint innodb_buffer_pool_pages_dirty; /*!< Dirty data pages */ 823 ulint innodb_buffer_pool_bytes_dirty; /*!< File bytes modified */ 824 ulint innodb_buffer_pool_pages_misc; /*!< Miscellanous pages */ 825 ulint innodb_buffer_pool_pages_free; /*!< Free pages */ 826 #ifdef UNIV_DEBUG 827 ulint innodb_buffer_pool_pages_latched; /*!< Latched pages */ 828 #endif /* UNIV_DEBUG */ 829 ulint innodb_buffer_pool_read_requests; /*!< buf_pool->stat.n_page_gets */ 830 ulint innodb_buffer_pool_reads; /*!< srv_buf_pool_reads */ 831 ulint innodb_buffer_pool_wait_free; /*!< srv_buf_pool_wait_free */ 832 ulint innodb_buffer_pool_pages_flushed; /*!< srv_buf_pool_flushed */ 833 ulint innodb_buffer_pool_write_requests;/*!< srv_buf_pool_write_requests */ 834 ulint innodb_buffer_pool_read_ahead_rnd;/*!< srv_read_ahead_rnd */ 835 ulint innodb_buffer_pool_read_ahead; /*!< srv_read_ahead */ 836 ulint innodb_buffer_pool_read_ahead_evicted;/*!< srv_read_ahead evicted*/ 837 ulint innodb_dblwr_pages_written; /*!< srv_dblwr_pages_written */ 838 ulint innodb_dblwr_writes; /*!< srv_dblwr_writes */ 839 ibool innodb_have_atomic_builtins; /*!< HAVE_ATOMIC_BUILTINS */ 840 ulint innodb_log_waits; /*!< srv_log_waits */ 841 ulint innodb_log_write_requests; /*!< srv_log_write_requests */ 842 ulint innodb_log_writes; /*!< srv_log_writes */ 843 lsn_t innodb_os_log_written; /*!< srv_os_log_written */ 844 ulint innodb_os_log_fsyncs; /*!< fil_n_log_flushes */ 845 ulint innodb_os_log_pending_writes; /*!< srv_os_log_pending_writes */ 846 ulint innodb_os_log_pending_fsyncs; /*!< fil_n_pending_log_flushes */ 847 ulint innodb_page_size; /*!< UNIV_PAGE_SIZE */ 848 ulint innodb_pages_created; /*!< buf_pool->stat.n_pages_created */ 849 ulint innodb_pages_read; /*!< buf_pool->stat.n_pages_read */ 850 ulint innodb_pages_written; /*!< buf_pool->stat.n_pages_written */ 851 ulint innodb_row_lock_waits; /*!< srv_n_lock_wait_count */ 852 ulint innodb_row_lock_current_waits; /*!< srv_n_lock_wait_current_count */ 853 ib_int64_t innodb_row_lock_time; /*!< srv_n_lock_wait_time 854 / 1000 */ 855 ulint innodb_row_lock_time_avg; /*!< srv_n_lock_wait_time 856 / 1000 857 / srv_n_lock_wait_count */ 858 ulint innodb_row_lock_time_max; /*!< srv_n_lock_max_wait_time 859 / 1000 */ 860 ulint innodb_rows_read; /*!< srv_n_rows_read */ 861 ulint innodb_rows_inserted; /*!< srv_n_rows_inserted */ 862 ulint innodb_rows_updated; /*!< srv_n_rows_updated */ 863 ulint innodb_rows_deleted; /*!< srv_n_rows_deleted */ 864 ulint innodb_num_open_files; /*!< fil_n_file_opened */ 865 ulint innodb_truncated_status_writes; /*!< srv_truncated_status_writes */ 866 ulint innodb_available_undo_logs; /*!< srv_available_undo_logs */ 867 #ifdef UNIV_DEBUG 868 ulint innodb_purge_trx_id_age; /*!< rw_max_trx_id - purged trx_id */ 869 ulint innodb_purge_view_trx_id_age; /*!< rw_max_trx_id 870 - purged view's min trx_id */ 871 #endif /* UNIV_DEBUG */ 872 }; 873 874 /** Thread slot in the thread table. */ 875 struct srv_slot_t{ 876 srv_thread_type type; /*!< thread type: user, 877 utility etc. */ 878 ibool in_use; /*!< TRUE if this slot 879 is in use */ 880 ibool suspended; /*!< TRUE if the thread is 881 waiting for the event of this 882 slot */ 883 ib_time_t suspend_time; /*!< time when the thread was 884 suspended. Initialized by 885 lock_wait_table_reserve_slot() 886 for lock wait */ 887 ulong wait_timeout; /*!< wait time that if exceeded 888 the thread will be timed out. 889 Initialized by 890 lock_wait_table_reserve_slot() 891 for lock wait */ 892 os_event_t event; /*!< event used in suspending 893 the thread when it has nothing 894 to do */ 895 que_thr_t* thr; /*!< suspended query thread 896 (only used for user threads) */ 897 }; 898 899 #else /* !UNIV_HOTBACKUP */ 900 # define srv_use_adaptive_hash_indexes FALSE 901 # define srv_use_native_aio FALSE 902 # define srv_numa_interleave FALSE 903 # define srv_force_recovery 0UL 904 # define srv_set_io_thread_op_info(t,info) ((void) 0) 905 # define srv_reset_io_thread_op_info() ((void) 0) 906 # define srv_is_being_started 0 907 # define srv_win_file_flush_method SRV_WIN_IO_UNBUFFERED 908 # define srv_unix_file_flush_method SRV_UNIX_O_DSYNC 909 # define srv_start_raw_disk_in_use 0 910 # define srv_file_per_table 1 911 #endif /* !UNIV_HOTBACKUP */ 912 #ifdef WITH_WSREP 913 UNIV_INTERN 914 void 915 wsrep_srv_conc_cancel_wait( 916 /*==================*/ 917 trx_t* trx); /*!< in: transaction object associated with the 918 thread */ 919 #endif /* WITH_WSREP */ 920 921 #endif 922