43
42
#include "trx0purge.h"
44
43
#include "ibuf0ibuf.h"
45
44
#include "buf0flu.h"
47
45
#include "btr0sea.h"
48
46
#include "dict0load.h"
49
47
#include "dict0boot.h"
50
48
#include "srv0start.h"
51
49
#include "row0mysql.h"
52
50
#include "ha_prototypes.h"
55
52
/* This is set to TRUE if the MySQL user has set it in MySQL; currently
56
53
affects only FOREIGN KEY definition parsing */
57
UNIV_INTERN ibool srv_lower_case_table_names = FALSE;
54
ibool srv_lower_case_table_names = FALSE;
59
56
/* The following counter is incremented whenever there is some user activity
61
UNIV_INTERN ulint srv_activity_count = 0;
58
ulint srv_activity_count = 0;
63
60
/* The following is the maximum allowed duration of a lock wait. */
64
UNIV_INTERN ulint srv_fatal_semaphore_wait_threshold = 600;
61
ulint srv_fatal_semaphore_wait_threshold = 600;
66
63
/* How much data manipulation language (DML) statements need to be delayed,
67
64
in microseconds, in order to reduce the lagging of the purge thread. */
68
UNIV_INTERN ulint srv_dml_needed_delay = 0;
70
UNIV_INTERN ibool srv_lock_timeout_and_monitor_active = FALSE;
71
UNIV_INTERN ibool srv_error_monitor_active = FALSE;
73
UNIV_INTERN const char* srv_main_thread_op_info = "";
65
ulint srv_dml_needed_delay = 0;
67
ibool srv_lock_timeout_and_monitor_active = FALSE;
68
ibool srv_error_monitor_active = FALSE;
70
const char* srv_main_thread_op_info = "";
75
72
/* Prefix used by MySQL to indicate pre-5.1 table name encoding */
76
UNIV_INTERN const char srv_mysql50_table_name_prefix[9] = "#mysql50#";
73
const char srv_mysql50_table_name_prefix[9] = "#mysql50#";
78
75
/* Server parameters which are read from the initfile */
80
77
/* The following three are dir paths which are catenated before file
81
78
names, where the file name itself may also contain a path */
83
UNIV_INTERN char* srv_data_home = NULL;
80
char* srv_data_home = NULL;
84
81
#ifdef UNIV_LOG_ARCHIVE
85
UNIV_INTERN char* srv_arch_dir = NULL;
82
char* srv_arch_dir = NULL;
86
83
#endif /* UNIV_LOG_ARCHIVE */
88
/* store to its own file each table created by an user; data
89
dictionary tables are in the system tablespace 0 */
90
UNIV_INTERN my_bool srv_file_per_table;
91
/* The file format to use on new *.ibd files. */
92
UNIV_INTERN ulint srv_file_format = 0;
93
/* Whether to check file format during startup a value of
94
DICT_TF_FORMAT_MAX + 1 means no checking ie. FALSE. The default is to
95
set it to the highest format we support. */
96
UNIV_INTERN ulint srv_check_file_format_at_startup = DICT_TF_FORMAT_MAX;
99
# error "DICT_TF_FORMAT_51 must be 0!"
101
/* Place locks to records only i.e. do not use next-key locking except
102
on duplicate key checking and foreign key checking */
103
UNIV_INTERN ibool srv_locks_unsafe_for_binlog = FALSE;
105
UNIV_INTERN ulint srv_n_data_files = 0;
106
UNIV_INTERN char** srv_data_file_names = NULL;
107
/* size in database pages */
108
UNIV_INTERN ulint* srv_data_file_sizes = NULL;
110
/* if TRUE, then we auto-extend the last data file */
111
UNIV_INTERN ibool srv_auto_extend_last_data_file = FALSE;
112
/* if != 0, this tells the max size auto-extending may increase the
113
last data file size */
114
UNIV_INTERN ulint srv_last_file_size_max = 0;
115
/* If the last data file is auto-extended, we add this
116
many pages to it at a time */
117
UNIV_INTERN ulong srv_auto_extend_increment = 8;
118
UNIV_INTERN ulint* srv_data_file_is_raw_partition = NULL;
85
ibool srv_file_per_table = FALSE; /* store to its own file each table
86
created by an user; data dictionary
87
tables are in the system tablespace
89
ibool srv_locks_unsafe_for_binlog = FALSE; /* Place locks to
93
duplicate key checking
96
ulint srv_n_data_files = 0;
97
char** srv_data_file_names = NULL;
98
ulint* srv_data_file_sizes = NULL; /* size in database pages */
100
ibool srv_auto_extend_last_data_file = FALSE; /* if TRUE, then we
101
auto-extend the last data
103
ulint srv_last_file_size_max = 0; /* if != 0, this tells
104
the max size auto-extending
105
may increase the last data
107
ulong srv_auto_extend_increment = 8; /* If the last data file is
108
auto-extended, we add this
109
many pages to it at a time */
110
ulint* srv_data_file_is_raw_partition = NULL;
120
112
/* If the following is TRUE we do not allow inserts etc. This protects
121
113
the user from forgetting the 'newraw' keyword to my.cnf */
123
UNIV_INTERN ibool srv_created_new_raw = FALSE;
125
UNIV_INTERN char** srv_log_group_home_dirs = NULL;
127
UNIV_INTERN ulint srv_n_log_groups = ULINT_MAX;
128
UNIV_INTERN ulint srv_n_log_files = ULINT_MAX;
129
/* size in database pages */
130
UNIV_INTERN ulint srv_log_file_size = ULINT_MAX;
131
/* size in database pages */
132
UNIV_INTERN ulint srv_log_buffer_size = ULINT_MAX;
133
UNIV_INTERN ulong srv_flush_log_at_trx_commit = 1;
135
/* The sort order table of the MySQL latin1_swedish_ci character set
137
UNIV_INTERN const byte srv_latin1_ordering[256] /* The sort order table of the latin1
115
ibool srv_created_new_raw = FALSE;
117
char** srv_log_group_home_dirs = NULL;
119
ulint srv_n_log_groups = ULINT_MAX;
120
ulint srv_n_log_files = ULINT_MAX;
121
ulint srv_log_file_size = ULINT_MAX; /* size in database pages */
122
ulint srv_log_buffer_size = ULINT_MAX; /* size in database pages */
123
ulong srv_flush_log_at_trx_commit = 1;
125
byte srv_latin1_ordering[256] /* The sort order table of the latin1
138
126
character set. The following table is
139
127
the MySQL order as of Feb 10th, 2002 */
172
160
, 0xD8, 0x55, 0x55, 0x55, 0x59, 0x59, 0xDE, 0xFF
176
/* requested size in kilobytes */
177
UNIV_INTERN ulong srv_buf_pool_size = ULINT_MAX;
178
/* previously requested size */
179
UNIV_INTERN ulong srv_buf_pool_old_size;
180
/* current size in kilobytes */
181
UNIV_INTERN ulong srv_buf_pool_curr_size = 0;
183
UNIV_INTERN ulint srv_mem_pool_size = ULINT_MAX;
184
UNIV_INTERN ulint srv_lock_table_size = ULINT_MAX;
186
UNIV_INTERN ulint srv_n_file_io_threads = ULINT_MAX;
163
ulint srv_pool_size = ULINT_MAX; /* size in pages; MySQL inits
164
this to size in kilobytes but
165
we normalize this to pages in
167
ulint srv_awe_window_size = 0; /* size in pages; MySQL inits
168
this to bytes, but we
169
normalize it to pages in
171
ulint srv_mem_pool_size = ULINT_MAX; /* size in bytes */
172
ulint srv_lock_table_size = ULINT_MAX;
174
ulint srv_n_file_io_threads = ULINT_MAX;
188
176
#ifdef UNIV_LOG_ARCHIVE
189
UNIV_INTERN ibool srv_log_archive_on = FALSE;
190
UNIV_INTERN ibool srv_archive_recovery = 0;
191
UNIV_INTERN ib_uint64_t srv_archive_recovery_limit_lsn;
177
ibool srv_log_archive_on = FALSE;
178
ibool srv_archive_recovery = 0;
179
dulint srv_archive_recovery_limit_lsn;
192
180
#endif /* UNIV_LOG_ARCHIVE */
194
UNIV_INTERN ulint srv_lock_wait_timeout = 1024 * 1024 * 1024;
182
ulint srv_lock_wait_timeout = 1024 * 1024 * 1024;
196
184
/* This parameter is used to throttle the number of insert buffers that are
197
185
merged in a batch. By increasing this parameter on a faster disk you can
201
189
the parameter is scaled down by a factor of 4, this is to avoid putting
202
190
a heavier load on the I/O sub system. */
204
UNIV_INTERN ulong srv_insert_buffer_batch_size = 20;
206
UNIV_INTERN char* srv_file_flush_method_str = NULL;
207
UNIV_INTERN ulint srv_unix_file_flush_method = SRV_UNIX_FSYNC;
208
UNIV_INTERN ulint srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
210
UNIV_INTERN ulint srv_max_n_open_files = 300;
192
ulong srv_insert_buffer_batch_size = 20;
194
char* srv_file_flush_method_str = NULL;
195
ulint srv_unix_file_flush_method = SRV_UNIX_FSYNC;
196
ulint srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
198
ulint srv_max_n_open_files = 300;
212
200
/* The InnoDB main thread tries to keep the ratio of modified pages
213
201
in the buffer pool to all database pages in the buffer pool smaller than
214
202
the following number. But it is not guaranteed that the value stays below
215
203
that during a time of heavy update/insert activity. */
217
UNIV_INTERN ulong srv_max_buf_pool_modified_pct = 90;
205
ulong srv_max_buf_pool_modified_pct = 90;
219
207
/* variable counts amount of data read in total (in bytes) */
220
UNIV_INTERN ulint srv_data_read = 0;
208
ulint srv_data_read = 0;
222
210
/* here we count the amount of data written in total (in bytes) */
223
UNIV_INTERN ulint srv_data_written = 0;
211
ulint srv_data_written = 0;
225
213
/* the number of the log write requests done */
226
UNIV_INTERN ulint srv_log_write_requests = 0;
214
ulint srv_log_write_requests = 0;
228
216
/* the number of physical writes to the log performed */
229
UNIV_INTERN ulint srv_log_writes = 0;
217
ulint srv_log_writes = 0;
231
219
/* amount of data written to the log files in bytes */
232
UNIV_INTERN ulint srv_os_log_written = 0;
220
ulint srv_os_log_written = 0;
234
222
/* amount of writes being done to the log files */
235
UNIV_INTERN ulint srv_os_log_pending_writes = 0;
223
ulint srv_os_log_pending_writes = 0;
237
225
/* we increase this counter, when there we don't have enough space in the
238
226
log buffer and have to flush it */
239
UNIV_INTERN ulint srv_log_waits = 0;
227
ulint srv_log_waits = 0;
241
229
/* this variable counts the amount of times, when the doublewrite buffer
243
UNIV_INTERN ulint srv_dblwr_writes = 0;
231
ulint srv_dblwr_writes = 0;
245
233
/* here we store the number of pages that have been flushed to the
246
234
doublewrite buffer */
247
UNIV_INTERN ulint srv_dblwr_pages_written = 0;
235
ulint srv_dblwr_pages_written = 0;
249
237
/* in this variable we store the number of write requests issued */
250
UNIV_INTERN ulint srv_buf_pool_write_requests = 0;
238
ulint srv_buf_pool_write_requests = 0;
252
240
/* here we store the number of times when we had to wait for a free page
253
241
in the buffer pool. It happens when the buffer pool is full and we need
254
242
to make a flush, in order to be able to read or create a page. */
255
UNIV_INTERN ulint srv_buf_pool_wait_free = 0;
243
ulint srv_buf_pool_wait_free = 0;
257
245
/* variable to count the number of pages that were written from buffer
258
246
pool to the disk */
259
UNIV_INTERN ulint srv_buf_pool_flushed = 0;
247
ulint srv_buf_pool_flushed = 0;
261
249
/* variable to count the number of buffer pool reads that led to the
262
250
reading of a disk page */
263
UNIV_INTERN ulint srv_buf_pool_reads = 0;
251
ulint srv_buf_pool_reads = 0;
265
253
/* variable to count the number of sequential read-aheads */
266
UNIV_INTERN ulint srv_read_ahead_seq = 0;
254
ulint srv_read_ahead_seq = 0;
268
256
/* variable to count the number of random read-aheads */
269
UNIV_INTERN ulint srv_read_ahead_rnd = 0;
257
ulint srv_read_ahead_rnd = 0;
271
259
/* structure to pass status variables to MySQL */
272
UNIV_INTERN export_struc export_vars;
260
export_struc export_vars;
274
262
/* If the following is != 0 we do not allow inserts etc. This protects
275
263
the user from forgetting the innodb_force_recovery keyword to my.cnf */
277
UNIV_INTERN ulint srv_force_recovery = 0;
265
ulint srv_force_recovery = 0;
278
266
/*-----------------------*/
279
267
/* We are prepared for a situation that we have this many threads waiting for
280
268
a semaphore inside InnoDB. innobase_start_or_create_for_mysql() sets the
283
UNIV_INTERN ulint srv_max_n_threads = 0;
271
ulint srv_max_n_threads = 0;
285
273
/* The following controls how many threads we let inside InnoDB concurrently:
286
274
threads waiting for locks are not counted into the number because otherwise
290
278
computer. Bigger computers need bigger values. Value 0 will disable the
291
279
concurrency check. */
293
UNIV_INTERN ulong srv_thread_concurrency = 0;
294
UNIV_INTERN ulong srv_commit_concurrency = 0;
281
ulong srv_thread_concurrency = 0;
282
ulong srv_commit_concurrency = 0;
296
/* this mutex protects srv_conc data structures */
297
UNIV_INTERN os_fast_mutex_t srv_conc_mutex;
298
/* number of OS threads currently inside InnoDB; it is not an error if
299
this drops temporarily below zero because we do not demand that every
300
thread increments this, but a thread waiting for a lock decrements
302
UNIV_INTERN lint srv_conc_n_threads = 0;
303
/* number of OS threads waiting in the FIFO for a permission to enter
305
UNIV_INTERN ulint srv_conc_n_waiting_threads = 0;
284
os_fast_mutex_t srv_conc_mutex; /* this mutex protects srv_conc data
286
lint srv_conc_n_threads = 0; /* number of OS threads currently
287
inside InnoDB; it is not an error
288
if this drops temporarily below zero
289
because we do not demand that every
290
thread increments this, but a thread
291
waiting for a lock decrements this
293
ulint srv_conc_n_waiting_threads = 0; /* number of OS threads waiting in the
294
FIFO for a permission to enter InnoDB
307
297
typedef struct srv_conc_slot_struct srv_conc_slot_t;
308
298
struct srv_conc_slot_struct{
333
323
merge to completion before shutdown. If it is set to 2, do not even flush the
334
324
buffer pool to data files at the shutdown: we effectively 'crash'
335
325
InnoDB (but lose no committed transactions). */
336
UNIV_INTERN ulint srv_fast_shutdown = 0;
326
ulint srv_fast_shutdown = 0;
338
328
/* Generate a innodb_status.<pid> file */
339
UNIV_INTERN ibool srv_innodb_status = FALSE;
341
UNIV_INTERN ibool srv_stats_on_metadata = TRUE;
343
UNIV_INTERN ibool srv_use_doublewrite_buf = TRUE;
344
UNIV_INTERN ibool srv_use_checksums = TRUE;
346
UNIV_INTERN ibool srv_set_thread_priorities = TRUE;
347
UNIV_INTERN int srv_query_thread_priority = 0;
349
UNIV_INTERN ulint srv_replication_delay = 0;
329
ibool srv_innodb_status = FALSE;
331
ibool srv_stats_on_metadata = TRUE;
333
ibool srv_use_doublewrite_buf = TRUE;
334
ibool srv_use_checksums = TRUE;
336
ibool srv_set_thread_priorities = TRUE;
337
int srv_query_thread_priority = 0;
339
/* TRUE if the Address Windowing Extensions of Windows are used; then we must
340
disable adaptive hash indexes */
341
ibool srv_use_awe = FALSE;
342
ibool srv_use_adaptive_hash_indexes = TRUE;
351
344
/*-------------------------------------------*/
352
UNIV_INTERN ulong srv_n_spin_wait_rounds = 20;
353
UNIV_INTERN ulong srv_n_free_tickets_to_enter = 500;
354
UNIV_INTERN ulong srv_thread_sleep_delay = 10000;
355
UNIV_INTERN ulint srv_spin_wait_delay = 5;
356
UNIV_INTERN ibool srv_priority_boost = TRUE;
359
UNIV_INTERN ibool srv_print_thread_releases = FALSE;
360
UNIV_INTERN ibool srv_print_lock_waits = FALSE;
361
UNIV_INTERN ibool srv_print_buf_io = FALSE;
362
UNIV_INTERN ibool srv_print_log_io = FALSE;
363
UNIV_INTERN ibool srv_print_latch_waits = FALSE;
364
#endif /* UNIV_DEBUG */
366
UNIV_INTERN ulint srv_n_rows_inserted = 0;
367
UNIV_INTERN ulint srv_n_rows_updated = 0;
368
UNIV_INTERN ulint srv_n_rows_deleted = 0;
369
UNIV_INTERN ulint srv_n_rows_read = 0;
345
ulong srv_n_spin_wait_rounds = 20;
346
ulong srv_n_free_tickets_to_enter = 500;
347
ulong srv_thread_sleep_delay = 10000;
348
ulint srv_spin_wait_delay = 5;
349
ibool srv_priority_boost = TRUE;
351
ibool srv_print_thread_releases = FALSE;
352
ibool srv_print_lock_waits = FALSE;
353
ibool srv_print_buf_io = FALSE;
354
ibool srv_print_log_io = FALSE;
355
ibool srv_print_latch_waits = FALSE;
357
ulint srv_n_rows_inserted = 0;
358
ulint srv_n_rows_updated = 0;
359
ulint srv_n_rows_deleted = 0;
360
ulint srv_n_rows_read = 0;
370
361
#ifndef UNIV_HOTBACKUP
371
362
static ulint srv_n_rows_inserted_old = 0;
372
363
static ulint srv_n_rows_updated_old = 0;
374
365
static ulint srv_n_rows_read_old = 0;
375
366
#endif /* !UNIV_HOTBACKUP */
377
UNIV_INTERN ulint srv_n_lock_wait_count = 0;
378
UNIV_INTERN ulint srv_n_lock_wait_current_count = 0;
379
UNIV_INTERN ib_int64_t srv_n_lock_wait_time = 0;
380
UNIV_INTERN ulint srv_n_lock_max_wait_time = 0;
368
ulint srv_n_lock_wait_count = 0;
369
ulint srv_n_lock_wait_current_count = 0;
370
ib_longlong srv_n_lock_wait_time = 0;
371
ulint srv_n_lock_max_wait_time = 0;
384
375
Set the following to 0 if you want InnoDB to write messages on
385
376
stderr on startup/shutdown
387
UNIV_INTERN ibool srv_print_verbose_log = TRUE;
388
UNIV_INTERN ibool srv_print_innodb_monitor = FALSE;
389
UNIV_INTERN ibool srv_print_innodb_lock_monitor = FALSE;
390
UNIV_INTERN ibool srv_print_innodb_tablespace_monitor = FALSE;
391
UNIV_INTERN ibool srv_print_innodb_table_monitor = FALSE;
378
ibool srv_print_verbose_log = TRUE;
379
ibool srv_print_innodb_monitor = FALSE;
380
ibool srv_print_innodb_lock_monitor = FALSE;
381
ibool srv_print_innodb_tablespace_monitor = FALSE;
382
ibool srv_print_innodb_table_monitor = FALSE;
393
384
/* Array of English strings describing the current state of an
394
385
i/o handler thread */
396
UNIV_INTERN const char* srv_io_thread_op_info[SRV_MAX_N_IO_THREADS];
397
UNIV_INTERN const char* srv_io_thread_function[SRV_MAX_N_IO_THREADS];
399
UNIV_INTERN time_t srv_last_monitor_time;
401
UNIV_INTERN mutex_t srv_innodb_monitor_mutex;
387
const char* srv_io_thread_op_info[SRV_MAX_N_IO_THREADS];
388
const char* srv_io_thread_function[SRV_MAX_N_IO_THREADS];
390
time_t srv_last_monitor_time;
392
mutex_t srv_innodb_monitor_mutex;
403
394
/* Mutex for locking srv_monitor_file */
404
UNIV_INTERN mutex_t srv_monitor_file_mutex;
395
mutex_t srv_monitor_file_mutex;
405
396
/* Temporary file for innodb monitor output */
406
UNIV_INTERN FILE* srv_monitor_file;
397
FILE* srv_monitor_file;
407
398
/* Mutex for locking srv_dict_tmpfile.
408
399
This mutex has a very high rank; threads reserving it should not
409
400
be holding any InnoDB latches. */
410
UNIV_INTERN mutex_t srv_dict_tmpfile_mutex;
401
mutex_t srv_dict_tmpfile_mutex;
411
402
/* Temporary file for output from the data dictionary */
412
UNIV_INTERN FILE* srv_dict_tmpfile;
403
FILE* srv_dict_tmpfile;
413
404
/* Mutex for locking srv_misc_tmpfile.
414
405
This mutex has a very low rank; threads reserving it should not
415
406
acquire any further latches or sleep before releasing this one. */
416
UNIV_INTERN mutex_t srv_misc_tmpfile_mutex;
407
mutex_t srv_misc_tmpfile_mutex;
417
408
/* Temporary file for miscellanous diagnostic output */
418
UNIV_INTERN FILE* srv_misc_tmpfile;
409
FILE* srv_misc_tmpfile;
420
UNIV_INTERN ulint srv_main_thread_process_no = 0;
421
UNIV_INTERN ulint srv_main_thread_id = 0;
411
ulint srv_main_thread_process_no = 0;
412
ulint srv_main_thread_id = 0;
424
415
IMPLEMENTATION OF THE SERVER MAIN PROGRAM
607
598
/* Table for MySQL threads where they will be suspended to wait for locks */
608
UNIV_INTERN srv_slot_t* srv_mysql_table = NULL;
610
UNIV_INTERN os_event_t srv_lock_timeout_thread_event;
612
UNIV_INTERN srv_sys_t* srv_sys = NULL;
614
/* padding to prevent other memory update hotspots from residing on
615
the same memory cache line */
616
UNIV_INTERN byte srv_pad1[64];
617
/* mutex protecting the server, trx structs, query threads, and lock table */
618
UNIV_INTERN mutex_t* kernel_mutex_temp;
619
/* padding to prevent other memory update hotspots from residing on
620
the same memory cache line */
621
UNIV_INTERN byte srv_pad2[64];
599
srv_slot_t* srv_mysql_table = NULL;
601
os_event_t srv_lock_timeout_thread_event;
603
srv_sys_t* srv_sys = NULL;
605
byte srv_pad1[64]; /* padding to prevent other memory update
606
hotspots from residing on the same memory
608
mutex_t* kernel_mutex_temp;/* mutex protecting the server, trx structs,
609
query threads, and lock table */
610
byte srv_pad2[64]; /* padding to prevent other memory update
611
hotspots from residing on the same memory
624
614
/* The following three values measure the urgency of the jobs of
625
615
buffer, version, and insert threads. They may vary from 0 - 1000.
626
616
The server mutex protects all these variables. The low-water values
627
617
tell that the server can acquiesce the utility when the value
628
618
drops below this low-water mark. */
630
static ulint srv_meter[SRV_MASTER + 1];
631
static ulint srv_meter_low_water[SRV_MASTER + 1];
632
static ulint srv_meter_high_water[SRV_MASTER + 1];
633
static ulint srv_meter_high_water2[SRV_MASTER + 1];
634
static ulint srv_meter_foreground[SRV_MASTER + 1];
620
ulint srv_meter[SRV_MASTER + 1];
621
ulint srv_meter_low_water[SRV_MASTER + 1];
622
ulint srv_meter_high_water[SRV_MASTER + 1];
623
ulint srv_meter_high_water2[SRV_MASTER + 1];
624
ulint srv_meter_foreground[SRV_MASTER + 1];
637
626
/* The following values give info about the activity going on in
638
627
the database. They are protected by the server mutex. The arrays
639
628
are indexed by the type of the thread. */
641
UNIV_INTERN ulint srv_n_threads_active[SRV_MASTER + 1];
642
UNIV_INTERN ulint srv_n_threads[SRV_MASTER + 1];
630
ulint srv_n_threads_active[SRV_MASTER + 1];
631
ulint srv_n_threads[SRV_MASTER + 1];
644
633
/*************************************************************************
645
634
Sets the info describing an i/o thread current state. */
648
637
srv_set_io_thread_op_info(
649
638
/*======================*/