mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / innobase / include / srv0srv.h
blobe1dbc4d11faf915ab21ab465973052182878bf65
1 /******************************************************
2 The server main program
4 (c) 1995 Innobase Oy
6 Created 10/10/1995 Heikki Tuuri
7 *******************************************************/
10 #ifndef srv0srv_h
11 #define srv0srv_h
13 #include "univ.i"
14 #include "sync0sync.h"
15 #include "os0sync.h"
16 #include "que0types.h"
17 #include "trx0types.h"
19 extern const char* srv_main_thread_op_info;
21 /* Prefix used by MySQL to indicate pre-5.1 table name encoding */
22 extern const char srv_mysql50_table_name_prefix[9];
24 /* When this event is set the lock timeout and InnoDB monitor
25 thread starts running */
26 extern os_event_t srv_lock_timeout_thread_event;
28 /* If the last data file is auto-extended, we add this many pages to it
29 at a time */
30 #define SRV_AUTO_EXTEND_INCREMENT \
31 (srv_auto_extend_increment * ((1024 * 1024) / UNIV_PAGE_SIZE))
33 /* This is set to TRUE if the MySQL user has set it in MySQL */
34 extern ibool srv_lower_case_table_names;
36 /* Mutex for locking srv_monitor_file */
37 extern mutex_t srv_monitor_file_mutex;
38 /* Temporary file for innodb monitor output */
39 extern FILE* srv_monitor_file;
40 /* Mutex for locking srv_dict_tmpfile.
41 This mutex has a very high rank; threads reserving it should not
42 be holding any InnoDB latches. */
43 extern mutex_t srv_dict_tmpfile_mutex;
44 /* Temporary file for output from the data dictionary */
45 extern FILE* srv_dict_tmpfile;
46 /* Mutex for locking srv_misc_tmpfile.
47 This mutex has a very low rank; threads reserving it should not
48 acquire any further latches or sleep before releasing this one. */
49 extern mutex_t srv_misc_tmpfile_mutex;
50 /* Temporary file for miscellanous diagnostic output */
51 extern FILE* srv_misc_tmpfile;
53 /* Server parameters which are read from the initfile */
55 extern char* srv_data_home;
56 #ifdef UNIV_LOG_ARCHIVE
57 extern char* srv_arch_dir;
58 #endif /* UNIV_LOG_ARCHIVE */
60 extern ibool srv_file_per_table;
61 extern ibool srv_locks_unsafe_for_binlog;
63 extern ulint srv_n_data_files;
64 extern char** srv_data_file_names;
65 extern ulint* srv_data_file_sizes;
66 extern ulint* srv_data_file_is_raw_partition;
68 extern ibool srv_auto_extend_last_data_file;
69 extern ulint srv_last_file_size_max;
70 extern ulong srv_auto_extend_increment;
72 extern ibool srv_created_new_raw;
74 #define SRV_NEW_RAW 1
75 #define SRV_OLD_RAW 2
77 extern char** srv_log_group_home_dirs;
79 extern ulint srv_n_log_groups;
80 extern ulint srv_n_log_files;
81 extern ulint srv_log_file_size;
82 extern ulint srv_log_buffer_size;
83 extern ulong srv_flush_log_at_trx_commit;
85 extern byte srv_latin1_ordering[256];/* The sort order table of the latin1
86 character set */
87 extern ulint srv_pool_size;
88 extern ulint srv_awe_window_size;
89 extern ulint srv_mem_pool_size;
90 extern ulint srv_lock_table_size;
92 extern ulint srv_n_file_io_threads;
94 /* The "innodb_stats_method" setting, decides how InnoDB is going
95 to treat NULL value when collecting statistics. It is not defined
96 as enum type because the configure option takes unsigned integer type. */
97 extern ulong srv_innodb_stats_method;
99 #ifdef UNIV_LOG_ARCHIVE
100 extern ibool srv_log_archive_on;
101 extern ibool srv_archive_recovery;
102 extern dulint srv_archive_recovery_limit_lsn;
103 #endif /* UNIV_LOG_ARCHIVE */
105 extern ulint srv_lock_wait_timeout;
107 extern char* srv_file_flush_method_str;
108 extern ulint srv_unix_file_flush_method;
109 extern ulint srv_win_file_flush_method;
111 extern ulint srv_max_n_open_files;
113 extern ulint srv_max_dirty_pages_pct;
115 extern ulint srv_force_recovery;
116 extern ulong srv_thread_concurrency;
118 extern ulint srv_max_n_threads;
120 extern lint srv_conc_n_threads;
122 extern ulint srv_fast_shutdown; /* If this is 1, do not do a
123 purge and index buffer merge.
124 If this 2, do not even flush the
125 buffer pool to data files at the
126 shutdown: we effectively 'crash'
127 InnoDB (but lose no committed
128 transactions). */
129 extern ibool srv_innodb_status;
131 extern ibool srv_use_doublewrite_buf;
132 extern ibool srv_use_checksums;
134 extern ibool srv_set_thread_priorities;
135 extern int srv_query_thread_priority;
137 extern ulong srv_max_buf_pool_modified_pct;
138 extern ulong srv_max_purge_lag;
139 extern ibool srv_use_awe;
140 extern ibool srv_use_adaptive_hash_indexes;
141 /*-------------------------------------------*/
143 extern ulint srv_n_rows_inserted;
144 extern ulint srv_n_rows_updated;
145 extern ulint srv_n_rows_deleted;
146 extern ulint srv_n_rows_read;
148 extern ibool srv_print_innodb_monitor;
149 extern ibool srv_print_innodb_lock_monitor;
150 extern ibool srv_print_innodb_tablespace_monitor;
151 extern ibool srv_print_verbose_log;
152 extern ibool srv_print_innodb_table_monitor;
154 extern ibool srv_lock_timeout_active;
155 extern ibool srv_monitor_active;
156 extern ibool srv_error_monitor_active;
158 extern ulong srv_n_spin_wait_rounds;
159 extern ulong srv_n_free_tickets_to_enter;
160 extern ulong srv_thread_sleep_delay;
161 extern ulint srv_spin_wait_delay;
162 extern ibool srv_priority_boost;
164 extern ulint srv_pool_size;
165 extern ulint srv_mem_pool_size;
166 extern ulint srv_lock_table_size;
168 extern ibool srv_print_thread_releases;
169 extern ibool srv_print_lock_waits;
170 extern ibool srv_print_buf_io;
171 extern ibool srv_print_log_io;
172 extern ibool srv_print_latch_waits;
174 extern ulint srv_activity_count;
175 extern ulint srv_fatal_semaphore_wait_threshold;
176 #define SRV_SEMAPHORE_WAIT_EXTENSION 7200
177 extern ulint srv_dml_needed_delay;
179 #ifdef UNIV_DEBUG
180 extern my_bool srv_purge_view_update_only_debug;
181 #endif /* UNIV_DEBUG */
183 extern mutex_t* kernel_mutex_temp;/* mutex protecting the server, trx structs,
184 query threads, and lock table: we allocate
185 it from dynamic memory to get it to the
186 same DRAM page as other hotspot semaphores */
187 #define kernel_mutex (*kernel_mutex_temp)
189 #define SRV_MAX_N_IO_THREADS 100
191 /* Array of English strings describing the current state of an
192 i/o handler thread */
193 extern const char* srv_io_thread_op_info[];
194 extern const char* srv_io_thread_function[];
196 /* the number of the log write requests done */
197 extern ulint srv_log_write_requests;
199 /* the number of physical writes to the log performed */
200 extern ulint srv_log_writes;
202 /* amount of data written to the log files in bytes */
203 extern ulint srv_os_log_written;
205 /* amount of writes being done to the log files */
206 extern ulint srv_os_log_pending_writes;
208 /* we increase this counter, when there we don't have enough space in the
209 log buffer and have to flush it */
210 extern ulint srv_log_waits;
212 /* variable that counts amount of data read in total (in bytes) */
213 extern ulint srv_data_read;
215 /* here we count the amount of data written in total (in bytes) */
216 extern ulint srv_data_written;
218 /* this variable counts the amount of times, when the doublewrite buffer
219 was flushed */
220 extern ulint srv_dblwr_writes;
222 /* here we store the number of pages that have been flushed to the
223 doublewrite buffer */
224 extern ulint srv_dblwr_pages_written;
226 /* in this variable we store the number of write requests issued */
227 extern ulint srv_buf_pool_write_requests;
229 /* here we store the number of times when we had to wait for a free page
230 in the buffer pool. It happens when the buffer pool is full and we need
231 to make a flush, in order to be able to read or create a page. */
232 extern ulint srv_buf_pool_wait_free;
234 /* variable to count the number of pages that were written from the
235 buffer pool to disk */
236 extern ulint srv_buf_pool_flushed;
238 /* variable to count the number of buffer pool reads that led to the
239 reading of a disk page */
240 extern ulint srv_buf_pool_reads;
242 /* variable to count the number of sequential read-aheads were done */
243 extern ulint srv_read_ahead_seq;
245 /* variable to count the number of random read-aheads were done */
246 extern ulint srv_read_ahead_rnd;
248 /* An option to enable the fix for "Bug#43660 SHOW INDEXES/ANALYZE does
249 NOT update cardinality for indexes of InnoDB table". By default we are
250 running with the fix disabled because MySQL 5.1 is frozen for such
251 behavioral changes. */
252 extern char srv_use_legacy_cardinality_algorithm;
254 /* In this structure we store status variables to be passed to MySQL */
255 typedef struct export_var_struct export_struc;
257 extern export_struc export_vars;
259 typedef struct srv_sys_struct srv_sys_t;
261 /* The server system */
262 extern srv_sys_t* srv_sys;
264 /* Alternatives for the file flush option in Unix; see the InnoDB manual
265 about what these mean */
266 #define SRV_UNIX_FSYNC 1 /* This is the default */
267 #define SRV_UNIX_O_DSYNC 2
268 #define SRV_UNIX_LITTLESYNC 3
269 #define SRV_UNIX_NOSYNC 4
270 #define SRV_UNIX_O_DIRECT 5
272 /* Alternatives for file i/o in Windows */
273 #define SRV_WIN_IO_NORMAL 1
274 #define SRV_WIN_IO_UNBUFFERED 2 /* This is the default */
276 /* Alternatives for srv_force_recovery. Non-zero values are intended
277 to help the user get a damaged database up so that he can dump intact
278 tables and rows with SELECT INTO OUTFILE. The database must not otherwise
279 be used with these options! A bigger number below means that all precautions
280 of lower numbers are included. */
282 #define SRV_FORCE_IGNORE_CORRUPT 1 /* let the server run even if it
283 detects a corrupt page */
284 #define SRV_FORCE_NO_BACKGROUND 2 /* prevent the main thread from
285 running: if a crash would occur
286 in purge, this prevents it */
287 #define SRV_FORCE_NO_TRX_UNDO 3 /* do not run trx rollback after
288 recovery */
289 #define SRV_FORCE_NO_IBUF_MERGE 4 /* prevent also ibuf operations:
290 if they would cause a crash, better
291 not do them */
292 #define SRV_FORCE_NO_UNDO_LOG_SCAN 5 /* do not look at undo logs when
293 starting the database: InnoDB will
294 treat even incomplete transactions
295 as committed */
296 #define SRV_FORCE_NO_LOG_REDO 6 /* do not do the log roll-forward
297 in connection with recovery */
299 /* Alternatives for srv_innodb_stats_method, which could be changed by
300 setting innodb_stats_method */
301 enum srv_stats_method_name_enum {
302 SRV_STATS_NULLS_EQUAL, /* All NULL values are treated as
303 equal. This is the default setting
304 for innodb_stats_method */
305 SRV_STATS_NULLS_UNEQUAL, /* All NULL values are treated as
306 NOT equal. */
307 SRV_STATS_NULLS_IGNORED /* NULL values are ignored */
310 typedef enum srv_stats_method_name_enum srv_stats_method_name_t;
312 /*************************************************************************
313 Boots Innobase server. */
315 ulint
316 srv_boot(void);
317 /*==========*/
318 /* out: DB_SUCCESS or error code */
319 /*************************************************************************
320 Initializes the server. */
322 void
323 srv_init(void);
324 /*==========*/
325 /*************************************************************************
326 Frees the OS fast mutex created in srv_boot(). */
328 void
329 srv_free(void);
330 /*==========*/
331 /*************************************************************************
332 Initializes the synchronization primitives, memory system, and the thread
333 local storage. */
335 void
336 srv_general_init(void);
337 /*==================*/
338 /*************************************************************************
339 Gets the number of threads in the system. */
341 ulint
342 srv_get_n_threads(void);
343 /*===================*/
344 /*************************************************************************
345 Returns the calling thread type. */
347 ulint
348 srv_get_thread_type(void);
349 /*=====================*/
350 /* out: SRV_COM, ... */
351 /*************************************************************************
352 Sets the info describing an i/o thread current state. */
354 void
355 srv_set_io_thread_op_info(
356 /*======================*/
357 ulint i, /* in: the 'segment' of the i/o thread */
358 const char* str); /* in: constant char string describing the
359 state */
360 /*************************************************************************
361 Releases threads of the type given from suspension in the thread table.
362 NOTE! The server mutex has to be reserved by the caller! */
364 ulint
365 srv_release_threads(
366 /*================*/
367 /* out: number of threads released: this may be
368 < n if not enough threads were suspended at the
369 moment */
370 ulint type, /* in: thread type */
371 ulint n); /* in: number of threads to release */
372 /*************************************************************************
373 The master thread controlling the server. */
375 os_thread_ret_t
376 srv_master_thread(
377 /*==============*/
378 /* out: a dummy parameter */
379 void* arg); /* in: a dummy parameter required by
380 os_thread_create */
381 /***********************************************************************
382 Tells the Innobase server that there has been activity in the database
383 and wakes up the master thread if it is suspended (not sleeping). Used
384 in the MySQL interface. Note that there is a small chance that the master
385 thread stays suspended (we do not protect our operation with the kernel
386 mutex, for performace reasons). */
388 void
389 srv_active_wake_master_thread(void);
390 /*===============================*/
391 /***********************************************************************
392 Wakes up the master thread if it is suspended or being suspended. */
394 void
395 srv_wake_master_thread(void);
396 /*========================*/
397 /*************************************************************************
398 Puts an OS thread to wait if there are too many concurrent threads
399 (>= srv_thread_concurrency) inside InnoDB. The threads wait in a FIFO queue. */
401 void
402 srv_conc_enter_innodb(
403 /*==================*/
404 trx_t* trx); /* in: transaction object associated with the
405 thread */
406 /*************************************************************************
407 This lets a thread enter InnoDB regardless of the number of threads inside
408 InnoDB. This must be called when a thread ends a lock wait. */
410 void
411 srv_conc_force_enter_innodb(
412 /*========================*/
413 trx_t* trx); /* in: transaction object associated with the
414 thread */
415 /*************************************************************************
416 This must be called when a thread exits InnoDB in a lock wait or at the
417 end of an SQL statement. */
419 void
420 srv_conc_force_exit_innodb(
421 /*=======================*/
422 trx_t* trx); /* in: transaction object associated with the
423 thread */
424 /*************************************************************************
425 This must be called when a thread exits InnoDB. */
427 void
428 srv_conc_exit_innodb(
429 /*=================*/
430 trx_t* trx); /* in: transaction object associated with the
431 thread */
432 /*******************************************************************
433 Puts a MySQL OS thread to wait for a lock to be released. If an error
434 occurs during the wait trx->error_state associated with thr is
435 != DB_SUCCESS when we return. DB_LOCK_WAIT_TIMEOUT and DB_DEADLOCK
436 are possible errors. DB_DEADLOCK is returned if selective deadlock
437 resolution chose this transaction as a victim. */
439 void
440 srv_suspend_mysql_thread(
441 /*=====================*/
442 que_thr_t* thr); /* in: query thread associated with the MySQL
443 OS thread */
444 /************************************************************************
445 Releases a MySQL OS thread waiting for a lock to be released, if the
446 thread is already suspended. */
448 void
449 srv_release_mysql_thread_if_suspended(
450 /*==================================*/
451 que_thr_t* thr); /* in: query thread associated with the
452 MySQL OS thread */
453 /*************************************************************************
454 A thread which wakes up threads whose lock wait may have lasted too
455 long. */
457 os_thread_ret_t
458 srv_lock_timeout_thread(
459 /*====================*/
460 /* out: a dummy parameter */
461 void* arg); /* in: a dummy parameter required by
462 os_thread_create */
463 /*************************************************************************
464 A thread which prints the info output by various InnoDB monitors. */
466 os_thread_ret_t
467 srv_monitor_thread(
468 /*===============*/
469 /* out: a dummy parameter */
470 void* arg); /* in: a dummy parameter required by
471 os_thread_create */
472 /*************************************************************************
473 A thread which prints warnings about semaphore waits which have lasted
474 too long. These can be used to track bugs which cause hangs. */
476 os_thread_ret_t
477 srv_error_monitor_thread(
478 /*=====================*/
479 /* out: a dummy parameter */
480 void* arg); /* in: a dummy parameter required by
481 os_thread_create */
482 /**********************************************************************
483 Outputs to a file the output of the InnoDB Monitor. */
485 ibool
486 srv_printf_innodb_monitor(
487 /*======================*/
488 /* out: FALSE if not all information printed
489 due to failure to obtain necessary mutex */
490 FILE* file, /* in: output stream */
491 ibool nowait, /* in: whether to wait for kernel
492 mutex. */
493 ulint* trx_start, /* out: file position of the start of
494 the list of active transactions */
495 ulint* trx_end); /* out: file position of the end of
496 the list of active transactions */
498 /**********************************************************************
499 Function to pass InnoDB status variables to MySQL */
501 void
502 srv_export_innodb_status(void);
503 /*=====================*/
505 /* Types for the threads existing in the system. Threads of types 4 - 9
506 are called utility threads. Note that utility threads are mainly disk
507 bound, except that version threads 6 - 7 may also be CPU bound, if
508 cleaning versions from the buffer pool. */
510 #define SRV_COM 1 /* threads serving communication and queries */
511 #define SRV_CONSOLE 2 /* thread serving console */
512 #define SRV_WORKER 3 /* threads serving parallelized queries and
513 queries released from lock wait */
514 #define SRV_BUFFER 4 /* thread flushing dirty buffer blocks,
515 not currently in use */
516 #define SRV_RECOVERY 5 /* threads finishing a recovery,
517 not currently in use */
518 #define SRV_INSERT 6 /* thread flushing the insert buffer to disk,
519 not currently in use */
520 #define SRV_MASTER 7 /* the master thread, (whose type number must
521 be biggest) */
523 /* Thread slot in the thread table */
524 typedef struct srv_slot_struct srv_slot_t;
526 /* Thread table is an array of slots */
527 typedef srv_slot_t srv_table_t;
529 /* In this structure we store status variables to be passed to MySQL */
530 struct export_var_struct{
531 ulint innodb_data_pending_reads;
532 ulint innodb_data_pending_writes;
533 ulint innodb_data_pending_fsyncs;
534 ulint innodb_data_fsyncs;
535 ulint innodb_data_read;
536 ulint innodb_data_writes;
537 ulint innodb_data_written;
538 ulint innodb_data_reads;
539 ulint innodb_buffer_pool_pages_total;
540 ulint innodb_buffer_pool_pages_data;
541 ulint innodb_buffer_pool_pages_dirty;
542 ulint innodb_buffer_pool_pages_misc;
543 ulint innodb_buffer_pool_pages_free;
544 #ifdef UNIV_DEBUG
545 ulint innodb_buffer_pool_pages_latched;
546 #endif /* UNIV_DEBUG */
547 ulint innodb_buffer_pool_read_requests;
548 ulint innodb_buffer_pool_reads;
549 ulint innodb_buffer_pool_wait_free;
550 ulint innodb_buffer_pool_pages_flushed;
551 ulint innodb_buffer_pool_write_requests;
552 ulint innodb_buffer_pool_read_ahead_seq;
553 ulint innodb_buffer_pool_read_ahead_rnd;
554 ulint innodb_dblwr_pages_written;
555 ulint innodb_dblwr_writes;
556 ulint innodb_log_waits;
557 ulint innodb_log_write_requests;
558 ulint innodb_log_writes;
559 ulint innodb_os_log_written;
560 ulint innodb_os_log_fsyncs;
561 ulint innodb_os_log_pending_writes;
562 ulint innodb_os_log_pending_fsyncs;
563 ulint innodb_page_size;
564 ulint innodb_pages_created;
565 ulint innodb_pages_read;
566 ulint innodb_pages_written;
567 ulint innodb_row_lock_waits;
568 ulint innodb_row_lock_current_waits;
569 ib_longlong innodb_row_lock_time;
570 ulint innodb_row_lock_time_avg;
571 ulint innodb_row_lock_time_max;
572 ulint innodb_rows_read;
573 ulint innodb_rows_inserted;
574 ulint innodb_rows_updated;
575 ulint innodb_rows_deleted;
576 #ifdef UNIV_DEBUG
577 ulint innodb_purge_trx_id_age;
578 ulint innodb_purge_view_trx_id_age;
579 #endif /* UNIV_DEBUG */
582 /* The server system struct */
583 struct srv_sys_struct{
584 srv_table_t* threads; /* server thread table */
585 UT_LIST_BASE_NODE_T(que_thr_t)
586 tasks; /* task queue */
587 dict_index_t* dummy_ind1; /* dummy index for old-style
588 supremum and infimum records */
589 dict_index_t* dummy_ind2; /* dummy index for new-style
590 supremum and infimum records */
593 extern ulint srv_n_threads_active[];
595 #endif