00001 /****************************************************** 00002 The server main program 00003 00004 (c) 1995 Innobase Oy 00005 00006 Created 10/10/1995 Heikki Tuuri 00007 *******************************************************/ 00008 00009 00010 #ifndef srv0srv_h 00011 #define srv0srv_h 00012 00013 #include "univ.i" 00014 #include "sync0sync.h" 00015 #include "os0sync.h" 00016 #include "que0types.h" 00017 #include "trx0types.h" 00018 00019 extern const char* srv_main_thread_op_info; 00020 00021 /* Prefix used by MySQL to indicate pre-5.1 table name encoding */ 00022 extern const char srv_mysql50_table_name_prefix[9]; 00023 00024 /* When this event is set the lock timeout and InnoDB monitor 00025 thread starts running */ 00026 extern os_event_t srv_lock_timeout_thread_event; 00027 00028 /* If the last data file is auto-extended, we add this many pages to it 00029 at a time */ 00030 #define SRV_AUTO_EXTEND_INCREMENT \ 00031 (srv_auto_extend_increment * ((1024 * 1024) / UNIV_PAGE_SIZE)) 00032 00033 /* This is set to TRUE if the MySQL user has set it in MySQL */ 00034 extern ibool srv_lower_case_table_names; 00035 00036 /* Mutex for locking srv_monitor_file */ 00037 extern mutex_t srv_monitor_file_mutex; 00038 /* Temporary file for innodb monitor output */ 00039 extern FILE* srv_monitor_file; 00040 /* Mutex for locking srv_dict_tmpfile. 00041 This mutex has a very high rank; threads reserving it should not 00042 be holding any InnoDB latches. */ 00043 extern mutex_t srv_dict_tmpfile_mutex; 00044 /* Temporary file for output from the data dictionary */ 00045 extern FILE* srv_dict_tmpfile; 00046 /* Mutex for locking srv_misc_tmpfile. 00047 This mutex has a very low rank; threads reserving it should not 00048 acquire any further latches or sleep before releasing this one. */ 00049 extern mutex_t srv_misc_tmpfile_mutex; 00050 /* Temporary file for miscellanous diagnostic output */ 00051 extern FILE* srv_misc_tmpfile; 00052 00053 /* Server parameters which are read from the initfile */ 00054 00055 extern char* srv_data_home; 00056 #ifdef UNIV_LOG_ARCHIVE 00057 extern char* srv_arch_dir; 00058 #endif /* UNIV_LOG_ARCHIVE */ 00059 00060 extern ibool srv_file_per_table; 00061 extern ibool srv_locks_unsafe_for_binlog; 00062 00063 extern ulint srv_n_data_files; 00064 extern char** srv_data_file_names; 00065 extern ulint* srv_data_file_sizes; 00066 extern ulint* srv_data_file_is_raw_partition; 00067 00068 extern ibool srv_auto_extend_last_data_file; 00069 extern ulint srv_last_file_size_max; 00070 extern ulong srv_auto_extend_increment; 00071 00072 extern ibool srv_created_new_raw; 00073 00074 #define SRV_NEW_RAW 1 00075 #define SRV_OLD_RAW 2 00076 00077 extern char** srv_log_group_home_dirs; 00078 00079 extern ulint srv_n_log_groups; 00080 extern ulint srv_n_log_files; 00081 extern ulint srv_log_file_size; 00082 extern ulint srv_log_buffer_size; 00083 extern ulong srv_flush_log_at_trx_commit; 00084 00085 extern byte srv_latin1_ordering[256];/* The sort order table of the latin1 00086 character set */ 00087 extern ulint srv_pool_size; 00088 extern ulint srv_awe_window_size; 00089 extern ulint srv_mem_pool_size; 00090 extern ulint srv_lock_table_size; 00091 00092 extern ulint srv_n_file_io_threads; 00093 00094 #ifdef UNIV_LOG_ARCHIVE 00095 extern ibool srv_log_archive_on; 00096 extern ibool srv_archive_recovery; 00097 extern dulint srv_archive_recovery_limit_lsn; 00098 #endif /* UNIV_LOG_ARCHIVE */ 00099 00100 extern ulint srv_lock_wait_timeout; 00101 00102 extern char* srv_file_flush_method_str; 00103 extern ulint srv_unix_file_flush_method; 00104 extern ulint srv_win_file_flush_method; 00105 00106 extern ulint srv_max_n_open_files; 00107 00108 extern ulint srv_max_dirty_pages_pct; 00109 00110 extern ulint srv_force_recovery; 00111 extern ulong srv_thread_concurrency; 00112 extern ulong srv_commit_concurrency; 00113 00114 extern ulint srv_max_n_threads; 00115 00116 extern lint srv_conc_n_threads; 00117 00118 extern ulint srv_fast_shutdown; /* If this is 1, do not do a 00119 purge and index buffer merge. 00120 If this 2, do not even flush the 00121 buffer pool to data files at the 00122 shutdown: we effectively 'crash' 00123 InnoDB (but lose no committed 00124 transactions). */ 00125 extern ibool srv_innodb_status; 00126 00127 extern ibool srv_use_doublewrite_buf; 00128 extern ibool srv_use_checksums; 00129 00130 extern ibool srv_set_thread_priorities; 00131 extern int srv_query_thread_priority; 00132 00133 extern ulong srv_max_buf_pool_modified_pct; 00134 extern ulong srv_max_purge_lag; 00135 extern ibool srv_use_awe; 00136 extern ibool srv_use_adaptive_hash_indexes; 00137 /*-------------------------------------------*/ 00138 00139 extern ulint srv_n_rows_inserted; 00140 extern ulint srv_n_rows_updated; 00141 extern ulint srv_n_rows_deleted; 00142 extern ulint srv_n_rows_read; 00143 00144 extern ibool srv_print_innodb_monitor; 00145 extern ibool srv_print_innodb_lock_monitor; 00146 extern ibool srv_print_innodb_tablespace_monitor; 00147 extern ibool srv_print_verbose_log; 00148 extern ibool srv_print_innodb_table_monitor; 00149 00150 extern ibool srv_lock_timeout_and_monitor_active; 00151 extern ibool srv_error_monitor_active; 00152 00153 extern ulong srv_n_spin_wait_rounds; 00154 extern ulong srv_n_free_tickets_to_enter; 00155 extern ulong srv_thread_sleep_delay; 00156 extern ulint srv_spin_wait_delay; 00157 extern ibool srv_priority_boost; 00158 00159 extern ulint srv_pool_size; 00160 extern ulint srv_mem_pool_size; 00161 extern ulint srv_lock_table_size; 00162 00163 extern ibool srv_print_thread_releases; 00164 extern ibool srv_print_lock_waits; 00165 extern ibool srv_print_buf_io; 00166 extern ibool srv_print_log_io; 00167 extern ibool srv_print_latch_waits; 00168 00169 extern ulint srv_activity_count; 00170 extern ulint srv_fatal_semaphore_wait_threshold; 00171 extern ulint srv_dml_needed_delay; 00172 00173 extern mutex_t* kernel_mutex_temp;/* mutex protecting the server, trx structs, 00174 query threads, and lock table: we allocate 00175 it from dynamic memory to get it to the 00176 same DRAM page as other hotspot semaphores */ 00177 #define kernel_mutex (*kernel_mutex_temp) 00178 00179 #define SRV_MAX_N_IO_THREADS 100 00180 00181 /* Array of English strings describing the current state of an 00182 i/o handler thread */ 00183 extern const char* srv_io_thread_op_info[]; 00184 extern const char* srv_io_thread_function[]; 00185 00186 /* the number of the log write requests done */ 00187 extern ulint srv_log_write_requests; 00188 00189 /* the number of physical writes to the log performed */ 00190 extern ulint srv_log_writes; 00191 00192 /* amount of data written to the log files in bytes */ 00193 extern ulint srv_os_log_written; 00194 00195 /* amount of writes being done to the log files */ 00196 extern ulint srv_os_log_pending_writes; 00197 00198 /* we increase this counter, when there we don't have enough space in the 00199 log buffer and have to flush it */ 00200 extern ulint srv_log_waits; 00201 00202 /* variable that counts amount of data read in total (in bytes) */ 00203 extern ulint srv_data_read; 00204 00205 /* here we count the amount of data written in total (in bytes) */ 00206 extern ulint srv_data_written; 00207 00208 /* this variable counts the amount of times, when the doublewrite buffer 00209 was flushed */ 00210 extern ulint srv_dblwr_writes; 00211 00212 /* here we store the number of pages that have been flushed to the 00213 doublewrite buffer */ 00214 extern ulint srv_dblwr_pages_written; 00215 00216 /* in this variable we store the number of write requests issued */ 00217 extern ulint srv_buf_pool_write_requests; 00218 00219 /* here we store the number of times when we had to wait for a free page 00220 in the buffer pool. It happens when the buffer pool is full and we need 00221 to make a flush, in order to be able to read or create a page. */ 00222 extern ulint srv_buf_pool_wait_free; 00223 00224 /* variable to count the number of pages that were written from the 00225 buffer pool to disk */ 00226 extern ulint srv_buf_pool_flushed; 00227 00228 /* variable to count the number of buffer pool reads that led to the 00229 reading of a disk page */ 00230 extern ulint srv_buf_pool_reads; 00231 00232 /* variable to count the number of sequential read-aheads were done */ 00233 extern ulint srv_read_ahead_seq; 00234 00235 /* variable to count the number of random read-aheads were done */ 00236 extern ulint srv_read_ahead_rnd; 00237 00238 /* In this structure we store status variables to be passed to MySQL */ 00239 typedef struct export_var_struct export_struc; 00240 00241 extern export_struc export_vars; 00242 00243 typedef struct srv_sys_struct srv_sys_t; 00244 00245 /* The server system */ 00246 extern srv_sys_t* srv_sys; 00247 00248 /* Alternatives for the file flush option in Unix; see the InnoDB manual 00249 about what these mean */ 00250 #define SRV_UNIX_FDATASYNC 1 /* This is the default; it is 00251 currently mapped to a call of 00252 fsync() because fdatasync() seemed 00253 to corrupt files in Linux and 00254 Solaris */ 00255 #define SRV_UNIX_O_DSYNC 2 00256 #define SRV_UNIX_LITTLESYNC 3 00257 #define SRV_UNIX_NOSYNC 4 00258 #define SRV_UNIX_O_DIRECT 5 00259 00260 /* Alternatives for file i/o in Windows */ 00261 #define SRV_WIN_IO_NORMAL 1 00262 #define SRV_WIN_IO_UNBUFFERED 2 /* This is the default */ 00263 00264 /* Alternatives for srv_force_recovery. Non-zero values are intended 00265 to help the user get a damaged database up so that he can dump intact 00266 tables and rows with SELECT INTO OUTFILE. The database must not otherwise 00267 be used with these options! A bigger number below means that all precautions 00268 of lower numbers are included. */ 00269 00270 #define SRV_FORCE_IGNORE_CORRUPT 1 /* let the server run even if it 00271 detects a corrupt page */ 00272 #define SRV_FORCE_NO_BACKGROUND 2 /* prevent the main thread from 00273 running: if a crash would occur 00274 in purge, this prevents it */ 00275 #define SRV_FORCE_NO_TRX_UNDO 3 /* do not run trx rollback after 00276 recovery */ 00277 #define SRV_FORCE_NO_IBUF_MERGE 4 /* prevent also ibuf operations: 00278 if they would cause a crash, better 00279 not do them */ 00280 #define SRV_FORCE_NO_UNDO_LOG_SCAN 5 /* do not look at undo logs when 00281 starting the database: InnoDB will 00282 treat even incomplete transactions 00283 as committed */ 00284 #define SRV_FORCE_NO_LOG_REDO 6 /* do not do the log roll-forward 00285 in connection with recovery */ 00286 00287 /************************************************************************* 00288 Boots Innobase server. */ 00289 00290 ulint 00291 srv_boot(void); 00292 /*==========*/ 00293 /* out: DB_SUCCESS or error code */ 00294 /************************************************************************* 00295 Initializes the server. */ 00296 00297 void 00298 srv_init(void); 00299 /*==========*/ 00300 /************************************************************************* 00301 Frees the OS fast mutex created in srv_boot(). */ 00302 00303 void 00304 srv_free(void); 00305 /*==========*/ 00306 /************************************************************************* 00307 Initializes the synchronization primitives, memory system, and the thread 00308 local storage. */ 00309 00310 void 00311 srv_general_init(void); 00312 /*==================*/ 00313 /************************************************************************* 00314 Gets the number of threads in the system. */ 00315 00316 ulint 00317 srv_get_n_threads(void); 00318 /*===================*/ 00319 /************************************************************************* 00320 Returns the calling thread type. */ 00321 00322 ulint 00323 srv_get_thread_type(void); 00324 /*=====================*/ 00325 /* out: SRV_COM, ... */ 00326 /************************************************************************* 00327 Sets the info describing an i/o thread current state. */ 00328 00329 void 00330 srv_set_io_thread_op_info( 00331 /*======================*/ 00332 ulint i, /* in: the 'segment' of the i/o thread */ 00333 const char* str); /* in: constant char string describing the 00334 state */ 00335 /************************************************************************* 00336 Releases threads of the type given from suspension in the thread table. 00337 NOTE! The server mutex has to be reserved by the caller! */ 00338 00339 ulint 00340 srv_release_threads( 00341 /*================*/ 00342 /* out: number of threads released: this may be 00343 < n if not enough threads were suspended at the 00344 moment */ 00345 ulint type, /* in: thread type */ 00346 ulint n); /* in: number of threads to release */ 00347 /************************************************************************* 00348 The master thread controlling the server. */ 00349 00350 os_thread_ret_t 00351 srv_master_thread( 00352 /*==============*/ 00353 /* out: a dummy parameter */ 00354 void* arg); /* in: a dummy parameter required by 00355 os_thread_create */ 00356 /*********************************************************************** 00357 Tells the Innobase server that there has been activity in the database 00358 and wakes up the master thread if it is suspended (not sleeping). Used 00359 in the MySQL interface. Note that there is a small chance that the master 00360 thread stays suspended (we do not protect our operation with the kernel 00361 mutex, for performace reasons). */ 00362 00363 void 00364 srv_active_wake_master_thread(void); 00365 /*===============================*/ 00366 /*********************************************************************** 00367 Wakes up the master thread if it is suspended or being suspended. */ 00368 00369 void 00370 srv_wake_master_thread(void); 00371 /*========================*/ 00372 /************************************************************************* 00373 Puts an OS thread to wait if there are too many concurrent threads 00374 (>= srv_thread_concurrency) inside InnoDB. The threads wait in a FIFO queue. */ 00375 00376 void 00377 srv_conc_enter_innodb( 00378 /*==================*/ 00379 trx_t* trx); /* in: transaction object associated with the 00380 thread */ 00381 /************************************************************************* 00382 This lets a thread enter InnoDB regardless of the number of threads inside 00383 InnoDB. This must be called when a thread ends a lock wait. */ 00384 00385 void 00386 srv_conc_force_enter_innodb( 00387 /*========================*/ 00388 trx_t* trx); /* in: transaction object associated with the 00389 thread */ 00390 /************************************************************************* 00391 This must be called when a thread exits InnoDB in a lock wait or at the 00392 end of an SQL statement. */ 00393 00394 void 00395 srv_conc_force_exit_innodb( 00396 /*=======================*/ 00397 trx_t* trx); /* in: transaction object associated with the 00398 thread */ 00399 /************************************************************************* 00400 This must be called when a thread exits InnoDB. */ 00401 00402 void 00403 srv_conc_exit_innodb( 00404 /*=================*/ 00405 trx_t* trx); /* in: transaction object associated with the 00406 thread */ 00407 /******************************************************************* 00408 Puts a MySQL OS thread to wait for a lock to be released. If an error 00409 occurs during the wait trx->error_state associated with thr is 00410 != DB_SUCCESS when we return. DB_LOCK_WAIT_TIMEOUT and DB_DEADLOCK 00411 are possible errors. DB_DEADLOCK is returned if selective deadlock 00412 resolution chose this transaction as a victim. */ 00413 00414 void 00415 srv_suspend_mysql_thread( 00416 /*=====================*/ 00417 que_thr_t* thr); /* in: query thread associated with the MySQL 00418 OS thread */ 00419 /************************************************************************ 00420 Releases a MySQL OS thread waiting for a lock to be released, if the 00421 thread is already suspended. */ 00422 00423 void 00424 srv_release_mysql_thread_if_suspended( 00425 /*==================================*/ 00426 que_thr_t* thr); /* in: query thread associated with the 00427 MySQL OS thread */ 00428 /************************************************************************* 00429 A thread which wakes up threads whose lock wait may have lasted too long. 00430 This also prints the info output by various InnoDB monitors. */ 00431 00432 os_thread_ret_t 00433 srv_lock_timeout_and_monitor_thread( 00434 /*================================*/ 00435 /* out: a dummy parameter */ 00436 void* arg); /* in: a dummy parameter required by 00437 os_thread_create */ 00438 /************************************************************************* 00439 A thread which prints warnings about semaphore waits which have lasted 00440 too long. These can be used to track bugs which cause hangs. */ 00441 00442 os_thread_ret_t 00443 srv_error_monitor_thread( 00444 /*=====================*/ 00445 /* out: a dummy parameter */ 00446 void* arg); /* in: a dummy parameter required by 00447 os_thread_create */ 00448 /********************************************************************** 00449 Outputs to a file the output of the InnoDB Monitor. */ 00450 00451 void 00452 srv_printf_innodb_monitor( 00453 /*======================*/ 00454 FILE* file, /* in: output stream */ 00455 ulint* trx_start, /* out: file position of the start of 00456 the list of active transactions */ 00457 ulint* trx_end); /* out: file position of the end of 00458 the list of active transactions */ 00459 00460 /********************************************************************** 00461 Function to pass InnoDB status variables to MySQL */ 00462 00463 void 00464 srv_export_innodb_status(void); 00465 /*=====================*/ 00466 00467 /* Types for the threads existing in the system. Threads of types 4 - 9 00468 are called utility threads. Note that utility threads are mainly disk 00469 bound, except that version threads 6 - 7 may also be CPU bound, if 00470 cleaning versions from the buffer pool. */ 00471 00472 #define SRV_COM 1 /* threads serving communication and queries */ 00473 #define SRV_CONSOLE 2 /* thread serving console */ 00474 #define SRV_WORKER 3 /* threads serving parallelized queries and 00475 queries released from lock wait */ 00476 #define SRV_BUFFER 4 /* thread flushing dirty buffer blocks, 00477 not currently in use */ 00478 #define SRV_RECOVERY 5 /* threads finishing a recovery, 00479 not currently in use */ 00480 #define SRV_INSERT 6 /* thread flushing the insert buffer to disk, 00481 not currently in use */ 00482 #define SRV_MASTER 7 /* the master thread, (whose type number must 00483 be biggest) */ 00484 00485 /* Thread slot in the thread table */ 00486 typedef struct srv_slot_struct srv_slot_t; 00487 00488 /* Thread table is an array of slots */ 00489 typedef srv_slot_t srv_table_t; 00490 00491 /* In this structure we store status variables to be passed to MySQL */ 00492 struct export_var_struct{ 00493 ulint innodb_data_pending_reads; 00494 ulint innodb_data_pending_writes; 00495 ulint innodb_data_pending_fsyncs; 00496 ulint innodb_data_fsyncs; 00497 ulint innodb_data_read; 00498 ulint innodb_data_writes; 00499 ulint innodb_data_written; 00500 ulint innodb_data_reads; 00501 ulint innodb_buffer_pool_pages_total; 00502 ulint innodb_buffer_pool_pages_data; 00503 ulint innodb_buffer_pool_pages_dirty; 00504 ulint innodb_buffer_pool_pages_misc; 00505 ulint innodb_buffer_pool_pages_free; 00506 ulint innodb_buffer_pool_pages_latched; 00507 ulint innodb_buffer_pool_read_requests; 00508 ulint innodb_buffer_pool_reads; 00509 ulint innodb_buffer_pool_wait_free; 00510 ulint innodb_buffer_pool_pages_flushed; 00511 ulint innodb_buffer_pool_write_requests; 00512 ulint innodb_buffer_pool_read_ahead_seq; 00513 ulint innodb_buffer_pool_read_ahead_rnd; 00514 ulint innodb_dblwr_pages_written; 00515 ulint innodb_dblwr_writes; 00516 ulint innodb_log_waits; 00517 ulint innodb_log_write_requests; 00518 ulint innodb_log_writes; 00519 ulint innodb_os_log_written; 00520 ulint innodb_os_log_fsyncs; 00521 ulint innodb_os_log_pending_writes; 00522 ulint innodb_os_log_pending_fsyncs; 00523 ulint innodb_page_size; 00524 ulint innodb_pages_created; 00525 ulint innodb_pages_read; 00526 ulint innodb_pages_written; 00527 ulint innodb_row_lock_waits; 00528 ulint innodb_row_lock_current_waits; 00529 ib_longlong innodb_row_lock_time; 00530 ulint innodb_row_lock_time_avg; 00531 ulint innodb_row_lock_time_max; 00532 ulint innodb_rows_read; 00533 ulint innodb_rows_inserted; 00534 ulint innodb_rows_updated; 00535 ulint innodb_rows_deleted; 00536 }; 00537 00538 /* The server system struct */ 00539 struct srv_sys_struct{ 00540 srv_table_t* threads; /* server thread table */ 00541 UT_LIST_BASE_NODE_T(que_thr_t) 00542 tasks; /* task queue */ 00543 dict_index_t* dummy_ind1; /* dummy index for old-style 00544 supremum and infimum records */ 00545 dict_index_t* dummy_ind2; /* dummy index for new-style 00546 supremum and infimum records */ 00547 }; 00548 00549 extern ulint srv_n_threads_active[]; 00550 00551 #endif 00552
1.4.7

