You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2666 lines
77 KiB

20 years ago
20 years ago
20 years ago
branches/zip: Improve the LRU algorithm with a separate unzip_LRU list of blocks that contains uncompressed and compressed frames. This patch was designed by Heikki and Inaam, implemented by Inaam, and refined and reviewed by Marko and Sunny. buf_buddy_n_frames, buf_buddy_min_n_frames, buf_buddy_max_n_frames: Remove. buf_page_belongs_to_unzip_LRU(): New predicate: bpage->zip.data && buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE. buf_pool_t, buf_block_t: Add the linked list unzip_LRU. A block in the regular LRU list is in unzip_LRU iff buf_page_belongs_to_unzip_LRU() holds. buf_LRU_free_block(): Add a third return value to refine the case "cannot free the block". buf_LRU_search_and_free_block(): Update the documentation to reflect the implementation. buf_LRU_stat_t, buf_LRU_stat_cur, buf_LRU_stat_sum, buf_LRU_stat_arr[]: Statistics for the unzip_LRU algorithm. buf_LRU_stat_update(): New function: Update the statistics. Called once per second by srv_error_monitor_thread(). buf_LRU_validate(): Validate the unzip_LRU list as well. buf_LRU_evict_from_unzip_LRU(): New predicate: Use the unzip_LRU before falling back to the regular LRU? buf_LRU_free_from_unzip_LRU_list(), buf_LRU_free_from_common_LRU_list(): Subfunctions of buf_LRU_search_and_free_block(). buf_LRU_search_and_free_block(): Reimplement. Try to evict an uncompressed page from the unzip_LRU list before falling back to evicting an entire block from the common LRU list. buf_unzip_LRU_remove_block_if_needed(): New function. buf_unzip_LRU_add_block(): New function: Add a block to the unzip_LRU list.
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge 2929:3458 from branches/5.1 (resolving conflict in c3257, note also that r3363 reverted r2933 so there are not changes in mysql-test/innodb-autoinc.result with the current merge): ------------------------------------------------------------------------ r2933 | calvin | 2008-10-30 02:57:31 +0200 (Thu, 30 Oct 2008) | 10 lines Changed paths: M /branches/5.1/mysql-test/innodb-autoinc.result branches/5.1: correct the result file innodb-autoinc.result Change the followings: auto_increment_increment auto_increment_offset to auto-increment-increment auto-increment-offset ------------------------------------------------------------------------ r2981 | marko | 2008-11-07 14:54:10 +0200 (Fri, 07 Nov 2008) | 5 lines Changed paths: M /branches/5.1/row/row0mysql.c branches/5.0: row_mysql_store_col_in_innobase_format(): Correct a misleading comment. In the UTF-8 encoding, ASCII takes 1 byte per character, while the "latin1" character set (normally ISO-8859-1, but in MySQL it actually refers to the Windows Code Page 1252 a.k.a. CP1252, WinLatin1) takes 1 to 3 bytes (1 to 2 bytes for the ISO-8859-1 subset). ------------------------------------------------------------------------ r3114 | calvin | 2008-11-14 20:31:48 +0200 (Fri, 14 Nov 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: fix bug#40386: Not flushing query cache after truncate ha_statistics.records can not be 0 unless the table is empty, set to 1 instead. The original problem of bug#29507 is fixed in the server. Additional test was done with the fix of bug#29507 in the server. Approved by: Heikki (on IM) ------------------------------------------------------------------------ r3257 | inaam | 2008-11-24 22:06:50 +0200 (Mon, 24 Nov 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/srv/srv0srv.c M /branches/5.1/trx/trx0trx.c branches/5.1 bug#40760 The config param innodb_thread_concurrency is dynamically set and is read when a thread enters/exits innodb. If the value is changed between the enter and exit time the behaviour becomes erratic. The fix is not to use srv_thread_concurrency when exiting, instead use the flag trx->declared_to_be_inside_innodb. rb://57 Approved by: Marko ------------------------------------------------------------------------ r3363 | calvin | 2008-12-04 19:00:20 +0200 (Thu, 04 Dec 2008) | 13 lines Changed paths: M /branches/5.1/mysql-test/innodb-autoinc.result branches/5.1: revert the changes in r2933 The changes in r2933 causes test failure on Linux. More investigation is needed for Windows. Change the followings in innodb-autoinc.result: auto-increment-increment auto-increment-offset back to: auto_increment_increment auto_increment_offset ------------------------------------------------------------------------ r3412 | vasil | 2008-12-05 10:46:18 +0200 (Fri, 05 Dec 2008) | 7 lines Changed paths: M /branches/5.1/trx/trx0undo.c branches/5.1: Add the traditional 2 spaces after the timestamp so the message does not look like: 070223 13:26:01InnoDB: Warning: canno.... ------------------------------------------------------------------------ r3458 | vasil | 2008-12-09 11:21:08 +0200 (Tue, 09 Dec 2008) | 51 lines Changed paths: M /branches/5.1/mysql-test/innodb_bug34300.test branches/5.1: Merge a change from MySQL to fix the failing innodb_bug34300 mysql-test: main.innodb_bug34300 [ fail ] mysqltest: At line 11: query 'SET @@max_allowed_packet=16777216' failed: 1621: SESSION variable 'max_allowed_packet' is read-only. Use SET GLOBAL to assign the value Aborting: main.innodb_bug34300 failed in default mode. The changeset is this: ------------------------------------------------------------ revno: 2709.1.10 committer: Staale Smedseng <staale.smedseng@sun.com> branch nick: b22891-51-bugteam timestamp: Thu 2008-11-20 08:51:48 +0100 message: A fix for Bug#22891 "session level max_allowed_packet can be set but is ignored". This patch makes @@session.max_allowed_packed and @@session.net_buffer_length read-only as suggested in the bug report. The user will have to use SET GLOBAL (and reconnect) to alter the session values of these variables. The error string ER_VARIABLE_IS_READONLY is introduced. Tests are modified accordingly. modified: mysql-test/r/func_compress.result mysql-test/r/max_allowed_packet_basic.result mysql-test/r/max_allowed_packet_func.result mysql-test/r/net_buffer_length_basic.result mysql-test/r/packet.result mysql-test/r/union.result mysql-test/r/variables.result mysql-test/t/func_compress.test mysql-test/t/innodb_bug34300.test mysql-test/t/max_allowed_packet_basic.test mysql-test/t/max_allowed_packet_func.test mysql-test/t/net_buffer_length_basic.test mysql-test/t/packet.test mysql-test/t/union.test mysql-test/t/variables.test sql/set_var.cc sql/set_var.h sql/share/errmsg.txt ------------------------------------------------------------ ------------------------------------------------------------------------
17 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge 2929:3458 from branches/5.1 (resolving conflict in c3257, note also that r3363 reverted r2933 so there are not changes in mysql-test/innodb-autoinc.result with the current merge): ------------------------------------------------------------------------ r2933 | calvin | 2008-10-30 02:57:31 +0200 (Thu, 30 Oct 2008) | 10 lines Changed paths: M /branches/5.1/mysql-test/innodb-autoinc.result branches/5.1: correct the result file innodb-autoinc.result Change the followings: auto_increment_increment auto_increment_offset to auto-increment-increment auto-increment-offset ------------------------------------------------------------------------ r2981 | marko | 2008-11-07 14:54:10 +0200 (Fri, 07 Nov 2008) | 5 lines Changed paths: M /branches/5.1/row/row0mysql.c branches/5.0: row_mysql_store_col_in_innobase_format(): Correct a misleading comment. In the UTF-8 encoding, ASCII takes 1 byte per character, while the "latin1" character set (normally ISO-8859-1, but in MySQL it actually refers to the Windows Code Page 1252 a.k.a. CP1252, WinLatin1) takes 1 to 3 bytes (1 to 2 bytes for the ISO-8859-1 subset). ------------------------------------------------------------------------ r3114 | calvin | 2008-11-14 20:31:48 +0200 (Fri, 14 Nov 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: fix bug#40386: Not flushing query cache after truncate ha_statistics.records can not be 0 unless the table is empty, set to 1 instead. The original problem of bug#29507 is fixed in the server. Additional test was done with the fix of bug#29507 in the server. Approved by: Heikki (on IM) ------------------------------------------------------------------------ r3257 | inaam | 2008-11-24 22:06:50 +0200 (Mon, 24 Nov 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/srv/srv0srv.c M /branches/5.1/trx/trx0trx.c branches/5.1 bug#40760 The config param innodb_thread_concurrency is dynamically set and is read when a thread enters/exits innodb. If the value is changed between the enter and exit time the behaviour becomes erratic. The fix is not to use srv_thread_concurrency when exiting, instead use the flag trx->declared_to_be_inside_innodb. rb://57 Approved by: Marko ------------------------------------------------------------------------ r3363 | calvin | 2008-12-04 19:00:20 +0200 (Thu, 04 Dec 2008) | 13 lines Changed paths: M /branches/5.1/mysql-test/innodb-autoinc.result branches/5.1: revert the changes in r2933 The changes in r2933 causes test failure on Linux. More investigation is needed for Windows. Change the followings in innodb-autoinc.result: auto-increment-increment auto-increment-offset back to: auto_increment_increment auto_increment_offset ------------------------------------------------------------------------ r3412 | vasil | 2008-12-05 10:46:18 +0200 (Fri, 05 Dec 2008) | 7 lines Changed paths: M /branches/5.1/trx/trx0undo.c branches/5.1: Add the traditional 2 spaces after the timestamp so the message does not look like: 070223 13:26:01InnoDB: Warning: canno.... ------------------------------------------------------------------------ r3458 | vasil | 2008-12-09 11:21:08 +0200 (Tue, 09 Dec 2008) | 51 lines Changed paths: M /branches/5.1/mysql-test/innodb_bug34300.test branches/5.1: Merge a change from MySQL to fix the failing innodb_bug34300 mysql-test: main.innodb_bug34300 [ fail ] mysqltest: At line 11: query 'SET @@max_allowed_packet=16777216' failed: 1621: SESSION variable 'max_allowed_packet' is read-only. Use SET GLOBAL to assign the value Aborting: main.innodb_bug34300 failed in default mode. The changeset is this: ------------------------------------------------------------ revno: 2709.1.10 committer: Staale Smedseng <staale.smedseng@sun.com> branch nick: b22891-51-bugteam timestamp: Thu 2008-11-20 08:51:48 +0100 message: A fix for Bug#22891 "session level max_allowed_packet can be set but is ignored". This patch makes @@session.max_allowed_packed and @@session.net_buffer_length read-only as suggested in the bug report. The user will have to use SET GLOBAL (and reconnect) to alter the session values of these variables. The error string ER_VARIABLE_IS_READONLY is introduced. Tests are modified accordingly. modified: mysql-test/r/func_compress.result mysql-test/r/max_allowed_packet_basic.result mysql-test/r/max_allowed_packet_func.result mysql-test/r/net_buffer_length_basic.result mysql-test/r/packet.result mysql-test/r/union.result mysql-test/r/variables.result mysql-test/t/func_compress.test mysql-test/t/innodb_bug34300.test mysql-test/t/max_allowed_packet_basic.test mysql-test/t/max_allowed_packet_func.test mysql-test/t/net_buffer_length_basic.test mysql-test/t/packet.test mysql-test/t/union.test mysql-test/t/variables.test sql/set_var.cc sql/set_var.h sql/share/errmsg.txt ------------------------------------------------------------ ------------------------------------------------------------------------
17 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge 2929:3458 from branches/5.1 (resolving conflict in c3257, note also that r3363 reverted r2933 so there are not changes in mysql-test/innodb-autoinc.result with the current merge): ------------------------------------------------------------------------ r2933 | calvin | 2008-10-30 02:57:31 +0200 (Thu, 30 Oct 2008) | 10 lines Changed paths: M /branches/5.1/mysql-test/innodb-autoinc.result branches/5.1: correct the result file innodb-autoinc.result Change the followings: auto_increment_increment auto_increment_offset to auto-increment-increment auto-increment-offset ------------------------------------------------------------------------ r2981 | marko | 2008-11-07 14:54:10 +0200 (Fri, 07 Nov 2008) | 5 lines Changed paths: M /branches/5.1/row/row0mysql.c branches/5.0: row_mysql_store_col_in_innobase_format(): Correct a misleading comment. In the UTF-8 encoding, ASCII takes 1 byte per character, while the "latin1" character set (normally ISO-8859-1, but in MySQL it actually refers to the Windows Code Page 1252 a.k.a. CP1252, WinLatin1) takes 1 to 3 bytes (1 to 2 bytes for the ISO-8859-1 subset). ------------------------------------------------------------------------ r3114 | calvin | 2008-11-14 20:31:48 +0200 (Fri, 14 Nov 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: fix bug#40386: Not flushing query cache after truncate ha_statistics.records can not be 0 unless the table is empty, set to 1 instead. The original problem of bug#29507 is fixed in the server. Additional test was done with the fix of bug#29507 in the server. Approved by: Heikki (on IM) ------------------------------------------------------------------------ r3257 | inaam | 2008-11-24 22:06:50 +0200 (Mon, 24 Nov 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/srv/srv0srv.c M /branches/5.1/trx/trx0trx.c branches/5.1 bug#40760 The config param innodb_thread_concurrency is dynamically set and is read when a thread enters/exits innodb. If the value is changed between the enter and exit time the behaviour becomes erratic. The fix is not to use srv_thread_concurrency when exiting, instead use the flag trx->declared_to_be_inside_innodb. rb://57 Approved by: Marko ------------------------------------------------------------------------ r3363 | calvin | 2008-12-04 19:00:20 +0200 (Thu, 04 Dec 2008) | 13 lines Changed paths: M /branches/5.1/mysql-test/innodb-autoinc.result branches/5.1: revert the changes in r2933 The changes in r2933 causes test failure on Linux. More investigation is needed for Windows. Change the followings in innodb-autoinc.result: auto-increment-increment auto-increment-offset back to: auto_increment_increment auto_increment_offset ------------------------------------------------------------------------ r3412 | vasil | 2008-12-05 10:46:18 +0200 (Fri, 05 Dec 2008) | 7 lines Changed paths: M /branches/5.1/trx/trx0undo.c branches/5.1: Add the traditional 2 spaces after the timestamp so the message does not look like: 070223 13:26:01InnoDB: Warning: canno.... ------------------------------------------------------------------------ r3458 | vasil | 2008-12-09 11:21:08 +0200 (Tue, 09 Dec 2008) | 51 lines Changed paths: M /branches/5.1/mysql-test/innodb_bug34300.test branches/5.1: Merge a change from MySQL to fix the failing innodb_bug34300 mysql-test: main.innodb_bug34300 [ fail ] mysqltest: At line 11: query 'SET @@max_allowed_packet=16777216' failed: 1621: SESSION variable 'max_allowed_packet' is read-only. Use SET GLOBAL to assign the value Aborting: main.innodb_bug34300 failed in default mode. The changeset is this: ------------------------------------------------------------ revno: 2709.1.10 committer: Staale Smedseng <staale.smedseng@sun.com> branch nick: b22891-51-bugteam timestamp: Thu 2008-11-20 08:51:48 +0100 message: A fix for Bug#22891 "session level max_allowed_packet can be set but is ignored". This patch makes @@session.max_allowed_packed and @@session.net_buffer_length read-only as suggested in the bug report. The user will have to use SET GLOBAL (and reconnect) to alter the session values of these variables. The error string ER_VARIABLE_IS_READONLY is introduced. Tests are modified accordingly. modified: mysql-test/r/func_compress.result mysql-test/r/max_allowed_packet_basic.result mysql-test/r/max_allowed_packet_func.result mysql-test/r/net_buffer_length_basic.result mysql-test/r/packet.result mysql-test/r/union.result mysql-test/r/variables.result mysql-test/t/func_compress.test mysql-test/t/innodb_bug34300.test mysql-test/t/max_allowed_packet_basic.test mysql-test/t/max_allowed_packet_func.test mysql-test/t/net_buffer_length_basic.test mysql-test/t/packet.test mysql-test/t/union.test mysql-test/t/variables.test sql/set_var.cc sql/set_var.h sql/share/errmsg.txt ------------------------------------------------------------ ------------------------------------------------------------------------
17 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge 2929:3458 from branches/5.1 (resolving conflict in c3257, note also that r3363 reverted r2933 so there are not changes in mysql-test/innodb-autoinc.result with the current merge): ------------------------------------------------------------------------ r2933 | calvin | 2008-10-30 02:57:31 +0200 (Thu, 30 Oct 2008) | 10 lines Changed paths: M /branches/5.1/mysql-test/innodb-autoinc.result branches/5.1: correct the result file innodb-autoinc.result Change the followings: auto_increment_increment auto_increment_offset to auto-increment-increment auto-increment-offset ------------------------------------------------------------------------ r2981 | marko | 2008-11-07 14:54:10 +0200 (Fri, 07 Nov 2008) | 5 lines Changed paths: M /branches/5.1/row/row0mysql.c branches/5.0: row_mysql_store_col_in_innobase_format(): Correct a misleading comment. In the UTF-8 encoding, ASCII takes 1 byte per character, while the "latin1" character set (normally ISO-8859-1, but in MySQL it actually refers to the Windows Code Page 1252 a.k.a. CP1252, WinLatin1) takes 1 to 3 bytes (1 to 2 bytes for the ISO-8859-1 subset). ------------------------------------------------------------------------ r3114 | calvin | 2008-11-14 20:31:48 +0200 (Fri, 14 Nov 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: fix bug#40386: Not flushing query cache after truncate ha_statistics.records can not be 0 unless the table is empty, set to 1 instead. The original problem of bug#29507 is fixed in the server. Additional test was done with the fix of bug#29507 in the server. Approved by: Heikki (on IM) ------------------------------------------------------------------------ r3257 | inaam | 2008-11-24 22:06:50 +0200 (Mon, 24 Nov 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/srv/srv0srv.c M /branches/5.1/trx/trx0trx.c branches/5.1 bug#40760 The config param innodb_thread_concurrency is dynamically set and is read when a thread enters/exits innodb. If the value is changed between the enter and exit time the behaviour becomes erratic. The fix is not to use srv_thread_concurrency when exiting, instead use the flag trx->declared_to_be_inside_innodb. rb://57 Approved by: Marko ------------------------------------------------------------------------ r3363 | calvin | 2008-12-04 19:00:20 +0200 (Thu, 04 Dec 2008) | 13 lines Changed paths: M /branches/5.1/mysql-test/innodb-autoinc.result branches/5.1: revert the changes in r2933 The changes in r2933 causes test failure on Linux. More investigation is needed for Windows. Change the followings in innodb-autoinc.result: auto-increment-increment auto-increment-offset back to: auto_increment_increment auto_increment_offset ------------------------------------------------------------------------ r3412 | vasil | 2008-12-05 10:46:18 +0200 (Fri, 05 Dec 2008) | 7 lines Changed paths: M /branches/5.1/trx/trx0undo.c branches/5.1: Add the traditional 2 spaces after the timestamp so the message does not look like: 070223 13:26:01InnoDB: Warning: canno.... ------------------------------------------------------------------------ r3458 | vasil | 2008-12-09 11:21:08 +0200 (Tue, 09 Dec 2008) | 51 lines Changed paths: M /branches/5.1/mysql-test/innodb_bug34300.test branches/5.1: Merge a change from MySQL to fix the failing innodb_bug34300 mysql-test: main.innodb_bug34300 [ fail ] mysqltest: At line 11: query 'SET @@max_allowed_packet=16777216' failed: 1621: SESSION variable 'max_allowed_packet' is read-only. Use SET GLOBAL to assign the value Aborting: main.innodb_bug34300 failed in default mode. The changeset is this: ------------------------------------------------------------ revno: 2709.1.10 committer: Staale Smedseng <staale.smedseng@sun.com> branch nick: b22891-51-bugteam timestamp: Thu 2008-11-20 08:51:48 +0100 message: A fix for Bug#22891 "session level max_allowed_packet can be set but is ignored". This patch makes @@session.max_allowed_packed and @@session.net_buffer_length read-only as suggested in the bug report. The user will have to use SET GLOBAL (and reconnect) to alter the session values of these variables. The error string ER_VARIABLE_IS_READONLY is introduced. Tests are modified accordingly. modified: mysql-test/r/func_compress.result mysql-test/r/max_allowed_packet_basic.result mysql-test/r/max_allowed_packet_func.result mysql-test/r/net_buffer_length_basic.result mysql-test/r/packet.result mysql-test/r/union.result mysql-test/r/variables.result mysql-test/t/func_compress.test mysql-test/t/innodb_bug34300.test mysql-test/t/max_allowed_packet_basic.test mysql-test/t/max_allowed_packet_func.test mysql-test/t/net_buffer_length_basic.test mysql-test/t/packet.test mysql-test/t/union.test mysql-test/t/variables.test sql/set_var.cc sql/set_var.h sql/share/errmsg.txt ------------------------------------------------------------ ------------------------------------------------------------------------
17 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge 2437:2485 from branches/5.1: (r2478 was skipped for the obvious reason) ------------------------------------------------------------------------ r2464 | vasil | 2008-05-19 17:59:42 +0300 (Mon, 19 May 2008) | 9 lines branches/5.1: Fix Bug#36600 SHOW STATUS takes a lot of CPU in buf_get_latched_pages_number by removing the Innodb_buffer_pool_pages_latched variable from SHOW STATUS output in non-UNIV_DEBUG compilation. Approved by: Heikki ------------------------------------------------------------------------ r2466 | calvin | 2008-05-20 01:37:14 +0300 (Tue, 20 May 2008) | 12 lines branches/5.1: Fix Bug#11894 innodb_file_per_table crashes w/ Windows .sym symbolic link hack The crash was due to un-handled error 3 (path not found). In the case of file per table, change the call to os_file_handle_error_no_exit() from os_file_handle_error(). Also, checks for full path pattern during table create (Windows only), which is used in symbolic link and temp table creation. Approved by: Heikki ------------------------------------------------------------------------ r2478 | sunny | 2008-05-23 08:29:08 +0300 (Fri, 23 May 2008) | 3 lines branches/5.1: Fix for bug# 36793. This is a back port from branches/zip. This code has been tested on a big-endian machine too. ------------------------------------------------------------------------ r2480 | vasil | 2008-05-27 11:40:07 +0300 (Tue, 27 May 2008) | 11 lines branches/5.1: Fix Bug#36819 ut_usectime does not handle errors from gettimeofday by retrying gettimeofday() several times if it fails in ut_usectime(). If it fails on all calls then return error to the caller to be handled at higher level. Update the variable innodb_row_lock_time_max in SHOW STATUS output only if ut_usectime() was successful. ------------------------------------------------------------------------ r2482 | sunny | 2008-05-28 12:18:35 +0300 (Wed, 28 May 2008) | 5 lines branches/5.1: Fix for Bug#35602, "Failed to read auto-increment value from storage engine". The test for REPLACE was an error of ommission since it's classified as a simple INSERT. For REPLACE statements we don't acquire the special AUTOINC lock for AUTOINC_NEW_STYLE_LOCKING with this fix. ------------------------------------------------------------------------ r2485 | vasil | 2008-05-28 16:01:14 +0300 (Wed, 28 May 2008) | 9 lines branches/5.1: Fix Bug#36149 Read buffer overflow in srv0start.c found during "make test" Use strncmp(3) instead of memcmp(3) to avoid reading past end of the string if it is empty (*str == '\0'). This bug is _not_ a buffer overflow. Discussed with: Sunny (via IM) ------------------------------------------------------------------------
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge 2437:2485 from branches/5.1: (r2478 was skipped for the obvious reason) ------------------------------------------------------------------------ r2464 | vasil | 2008-05-19 17:59:42 +0300 (Mon, 19 May 2008) | 9 lines branches/5.1: Fix Bug#36600 SHOW STATUS takes a lot of CPU in buf_get_latched_pages_number by removing the Innodb_buffer_pool_pages_latched variable from SHOW STATUS output in non-UNIV_DEBUG compilation. Approved by: Heikki ------------------------------------------------------------------------ r2466 | calvin | 2008-05-20 01:37:14 +0300 (Tue, 20 May 2008) | 12 lines branches/5.1: Fix Bug#11894 innodb_file_per_table crashes w/ Windows .sym symbolic link hack The crash was due to un-handled error 3 (path not found). In the case of file per table, change the call to os_file_handle_error_no_exit() from os_file_handle_error(). Also, checks for full path pattern during table create (Windows only), which is used in symbolic link and temp table creation. Approved by: Heikki ------------------------------------------------------------------------ r2478 | sunny | 2008-05-23 08:29:08 +0300 (Fri, 23 May 2008) | 3 lines branches/5.1: Fix for bug# 36793. This is a back port from branches/zip. This code has been tested on a big-endian machine too. ------------------------------------------------------------------------ r2480 | vasil | 2008-05-27 11:40:07 +0300 (Tue, 27 May 2008) | 11 lines branches/5.1: Fix Bug#36819 ut_usectime does not handle errors from gettimeofday by retrying gettimeofday() several times if it fails in ut_usectime(). If it fails on all calls then return error to the caller to be handled at higher level. Update the variable innodb_row_lock_time_max in SHOW STATUS output only if ut_usectime() was successful. ------------------------------------------------------------------------ r2482 | sunny | 2008-05-28 12:18:35 +0300 (Wed, 28 May 2008) | 5 lines branches/5.1: Fix for Bug#35602, "Failed to read auto-increment value from storage engine". The test for REPLACE was an error of ommission since it's classified as a simple INSERT. For REPLACE statements we don't acquire the special AUTOINC lock for AUTOINC_NEW_STYLE_LOCKING with this fix. ------------------------------------------------------------------------ r2485 | vasil | 2008-05-28 16:01:14 +0300 (Wed, 28 May 2008) | 9 lines branches/5.1: Fix Bug#36149 Read buffer overflow in srv0start.c found during "make test" Use strncmp(3) instead of memcmp(3) to avoid reading past end of the string if it is empty (*str == '\0'). This bug is _not_ a buffer overflow. Discussed with: Sunny (via IM) ------------------------------------------------------------------------
18 years ago
20 years ago
20 years ago
branches/zip: Merge 2437:2485 from branches/5.1: (r2478 was skipped for the obvious reason) ------------------------------------------------------------------------ r2464 | vasil | 2008-05-19 17:59:42 +0300 (Mon, 19 May 2008) | 9 lines branches/5.1: Fix Bug#36600 SHOW STATUS takes a lot of CPU in buf_get_latched_pages_number by removing the Innodb_buffer_pool_pages_latched variable from SHOW STATUS output in non-UNIV_DEBUG compilation. Approved by: Heikki ------------------------------------------------------------------------ r2466 | calvin | 2008-05-20 01:37:14 +0300 (Tue, 20 May 2008) | 12 lines branches/5.1: Fix Bug#11894 innodb_file_per_table crashes w/ Windows .sym symbolic link hack The crash was due to un-handled error 3 (path not found). In the case of file per table, change the call to os_file_handle_error_no_exit() from os_file_handle_error(). Also, checks for full path pattern during table create (Windows only), which is used in symbolic link and temp table creation. Approved by: Heikki ------------------------------------------------------------------------ r2478 | sunny | 2008-05-23 08:29:08 +0300 (Fri, 23 May 2008) | 3 lines branches/5.1: Fix for bug# 36793. This is a back port from branches/zip. This code has been tested on a big-endian machine too. ------------------------------------------------------------------------ r2480 | vasil | 2008-05-27 11:40:07 +0300 (Tue, 27 May 2008) | 11 lines branches/5.1: Fix Bug#36819 ut_usectime does not handle errors from gettimeofday by retrying gettimeofday() several times if it fails in ut_usectime(). If it fails on all calls then return error to the caller to be handled at higher level. Update the variable innodb_row_lock_time_max in SHOW STATUS output only if ut_usectime() was successful. ------------------------------------------------------------------------ r2482 | sunny | 2008-05-28 12:18:35 +0300 (Wed, 28 May 2008) | 5 lines branches/5.1: Fix for Bug#35602, "Failed to read auto-increment value from storage engine". The test for REPLACE was an error of ommission since it's classified as a simple INSERT. For REPLACE statements we don't acquire the special AUTOINC lock for AUTOINC_NEW_STYLE_LOCKING with this fix. ------------------------------------------------------------------------ r2485 | vasil | 2008-05-28 16:01:14 +0300 (Wed, 28 May 2008) | 9 lines branches/5.1: Fix Bug#36149 Read buffer overflow in srv0start.c found during "make test" Use strncmp(3) instead of memcmp(3) to avoid reading past end of the string if it is empty (*str == '\0'). This bug is _not_ a buffer overflow. Discussed with: Sunny (via IM) ------------------------------------------------------------------------
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge 2437:2485 from branches/5.1: (r2478 was skipped for the obvious reason) ------------------------------------------------------------------------ r2464 | vasil | 2008-05-19 17:59:42 +0300 (Mon, 19 May 2008) | 9 lines branches/5.1: Fix Bug#36600 SHOW STATUS takes a lot of CPU in buf_get_latched_pages_number by removing the Innodb_buffer_pool_pages_latched variable from SHOW STATUS output in non-UNIV_DEBUG compilation. Approved by: Heikki ------------------------------------------------------------------------ r2466 | calvin | 2008-05-20 01:37:14 +0300 (Tue, 20 May 2008) | 12 lines branches/5.1: Fix Bug#11894 innodb_file_per_table crashes w/ Windows .sym symbolic link hack The crash was due to un-handled error 3 (path not found). In the case of file per table, change the call to os_file_handle_error_no_exit() from os_file_handle_error(). Also, checks for full path pattern during table create (Windows only), which is used in symbolic link and temp table creation. Approved by: Heikki ------------------------------------------------------------------------ r2478 | sunny | 2008-05-23 08:29:08 +0300 (Fri, 23 May 2008) | 3 lines branches/5.1: Fix for bug# 36793. This is a back port from branches/zip. This code has been tested on a big-endian machine too. ------------------------------------------------------------------------ r2480 | vasil | 2008-05-27 11:40:07 +0300 (Tue, 27 May 2008) | 11 lines branches/5.1: Fix Bug#36819 ut_usectime does not handle errors from gettimeofday by retrying gettimeofday() several times if it fails in ut_usectime(). If it fails on all calls then return error to the caller to be handled at higher level. Update the variable innodb_row_lock_time_max in SHOW STATUS output only if ut_usectime() was successful. ------------------------------------------------------------------------ r2482 | sunny | 2008-05-28 12:18:35 +0300 (Wed, 28 May 2008) | 5 lines branches/5.1: Fix for Bug#35602, "Failed to read auto-increment value from storage engine". The test for REPLACE was an error of ommission since it's classified as a simple INSERT. For REPLACE statements we don't acquire the special AUTOINC lock for AUTOINC_NEW_STYLE_LOCKING with this fix. ------------------------------------------------------------------------ r2485 | vasil | 2008-05-28 16:01:14 +0300 (Wed, 28 May 2008) | 9 lines branches/5.1: Fix Bug#36149 Read buffer overflow in srv0start.c found during "make test" Use strncmp(3) instead of memcmp(3) to avoid reading past end of the string if it is empty (*str == '\0'). This bug is _not_ a buffer overflow. Discussed with: Sunny (via IM) ------------------------------------------------------------------------
18 years ago
branches/zip: Merge 2437:2485 from branches/5.1: (r2478 was skipped for the obvious reason) ------------------------------------------------------------------------ r2464 | vasil | 2008-05-19 17:59:42 +0300 (Mon, 19 May 2008) | 9 lines branches/5.1: Fix Bug#36600 SHOW STATUS takes a lot of CPU in buf_get_latched_pages_number by removing the Innodb_buffer_pool_pages_latched variable from SHOW STATUS output in non-UNIV_DEBUG compilation. Approved by: Heikki ------------------------------------------------------------------------ r2466 | calvin | 2008-05-20 01:37:14 +0300 (Tue, 20 May 2008) | 12 lines branches/5.1: Fix Bug#11894 innodb_file_per_table crashes w/ Windows .sym symbolic link hack The crash was due to un-handled error 3 (path not found). In the case of file per table, change the call to os_file_handle_error_no_exit() from os_file_handle_error(). Also, checks for full path pattern during table create (Windows only), which is used in symbolic link and temp table creation. Approved by: Heikki ------------------------------------------------------------------------ r2478 | sunny | 2008-05-23 08:29:08 +0300 (Fri, 23 May 2008) | 3 lines branches/5.1: Fix for bug# 36793. This is a back port from branches/zip. This code has been tested on a big-endian machine too. ------------------------------------------------------------------------ r2480 | vasil | 2008-05-27 11:40:07 +0300 (Tue, 27 May 2008) | 11 lines branches/5.1: Fix Bug#36819 ut_usectime does not handle errors from gettimeofday by retrying gettimeofday() several times if it fails in ut_usectime(). If it fails on all calls then return error to the caller to be handled at higher level. Update the variable innodb_row_lock_time_max in SHOW STATUS output only if ut_usectime() was successful. ------------------------------------------------------------------------ r2482 | sunny | 2008-05-28 12:18:35 +0300 (Wed, 28 May 2008) | 5 lines branches/5.1: Fix for Bug#35602, "Failed to read auto-increment value from storage engine". The test for REPLACE was an error of ommission since it's classified as a simple INSERT. For REPLACE statements we don't acquire the special AUTOINC lock for AUTOINC_NEW_STYLE_LOCKING with this fix. ------------------------------------------------------------------------ r2485 | vasil | 2008-05-28 16:01:14 +0300 (Wed, 28 May 2008) | 9 lines branches/5.1: Fix Bug#36149 Read buffer overflow in srv0start.c found during "make test" Use strncmp(3) instead of memcmp(3) to avoid reading past end of the string if it is empty (*str == '\0'). This bug is _not_ a buffer overflow. Discussed with: Sunny (via IM) ------------------------------------------------------------------------
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Improve the LRU algorithm with a separate unzip_LRU list of blocks that contains uncompressed and compressed frames. This patch was designed by Heikki and Inaam, implemented by Inaam, and refined and reviewed by Marko and Sunny. buf_buddy_n_frames, buf_buddy_min_n_frames, buf_buddy_max_n_frames: Remove. buf_page_belongs_to_unzip_LRU(): New predicate: bpage->zip.data && buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE. buf_pool_t, buf_block_t: Add the linked list unzip_LRU. A block in the regular LRU list is in unzip_LRU iff buf_page_belongs_to_unzip_LRU() holds. buf_LRU_free_block(): Add a third return value to refine the case "cannot free the block". buf_LRU_search_and_free_block(): Update the documentation to reflect the implementation. buf_LRU_stat_t, buf_LRU_stat_cur, buf_LRU_stat_sum, buf_LRU_stat_arr[]: Statistics for the unzip_LRU algorithm. buf_LRU_stat_update(): New function: Update the statistics. Called once per second by srv_error_monitor_thread(). buf_LRU_validate(): Validate the unzip_LRU list as well. buf_LRU_evict_from_unzip_LRU(): New predicate: Use the unzip_LRU before falling back to the regular LRU? buf_LRU_free_from_unzip_LRU_list(), buf_LRU_free_from_common_LRU_list(): Subfunctions of buf_LRU_search_and_free_block(). buf_LRU_search_and_free_block(): Reimplement. Try to evict an uncompressed page from the unzip_LRU list before falling back to evicting an entire block from the common LRU list. buf_unzip_LRU_remove_block_if_needed(): New function. buf_unzip_LRU_add_block(): New function: Add a block to the unzip_LRU list.
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
  1. /******************************************************
  2. The database server main program
  3. NOTE: SQL Server 7 uses something which the documentation
  4. calls user mode scheduled threads (UMS threads). One such
  5. thread is usually allocated per processor. Win32
  6. documentation does not know any UMS threads, which suggests
  7. that the concept is internal to SQL Server 7. It may mean that
  8. SQL Server 7 does all the scheduling of threads itself, even
  9. in i/o waits. We should maybe modify InnoDB to use the same
  10. technique, because thread switches within NT may be too slow.
  11. SQL Server 7 also mentions fibers, which are cooperatively
  12. scheduled threads. They can boost performance by 5 %,
  13. according to the Delaney and Soukup's book.
  14. Windows 2000 will have something called thread pooling
  15. (see msdn website), which we could possibly use.
  16. Another possibility could be to use some very fast user space
  17. thread library. This might confuse NT though.
  18. (c) 1995 Innobase Oy
  19. Created 10/8/1995 Heikki Tuuri
  20. *******************************************************/
  21. /***********************************************************************
  22. # Copyright (c) 2008, Google Inc.
  23. # All rights reserved.
  24. #
  25. # Redistribution and use in source and binary forms, with or without
  26. # modification, are permitted provided that the following conditions
  27. # are met:
  28. # * Redistributions of source code must retain the above copyright
  29. # notice, this list of conditions and the following disclaimer.
  30. # * Redistributions in binary form must reproduce the above
  31. # copyright notice, this list of conditions and the following
  32. # disclaimer in the documentation and/or other materials
  33. # provided with the distribution.
  34. # * Neither the name of the Google Inc. nor the names of its
  35. # contributors may be used to endorse or promote products
  36. # derived from this software without specific prior written
  37. # permission.
  38. #
  39. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  40. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  41. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  42. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  43. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  44. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  45. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  46. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  47. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  48. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  49. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  50. #
  51. # Note, the BSD license applies to the new code. The old code is GPL.
  52. ***********************************************************************/
  53. /* Dummy comment */
  54. #include "srv0srv.h"
  55. #include "ut0mem.h"
  56. #include "ut0ut.h"
  57. #include "os0proc.h"
  58. #include "mem0mem.h"
  59. #include "mem0pool.h"
  60. #include "sync0sync.h"
  61. #include "thr0loc.h"
  62. #include "que0que.h"
  63. #include "srv0que.h"
  64. #include "log0recv.h"
  65. #include "pars0pars.h"
  66. #include "usr0sess.h"
  67. #include "lock0lock.h"
  68. #include "trx0purge.h"
  69. #include "ibuf0ibuf.h"
  70. #include "buf0flu.h"
  71. #include "buf0lru.h"
  72. #include "btr0sea.h"
  73. #include "dict0load.h"
  74. #include "dict0boot.h"
  75. #include "srv0start.h"
  76. #include "row0mysql.h"
  77. #include "ha_prototypes.h"
  78. #include "trx0i_s.h"
  79. /* This is set to TRUE if the MySQL user has set it in MySQL; currently
  80. affects only FOREIGN KEY definition parsing */
  81. UNIV_INTERN ibool srv_lower_case_table_names = FALSE;
  82. /* The following counter is incremented whenever there is some user activity
  83. in the server */
  84. UNIV_INTERN ulint srv_activity_count = 0;
  85. /* The following is the maximum allowed duration of a lock wait. */
  86. UNIV_INTERN ulint srv_fatal_semaphore_wait_threshold = 600;
  87. /* How much data manipulation language (DML) statements need to be delayed,
  88. in microseconds, in order to reduce the lagging of the purge thread. */
  89. UNIV_INTERN ulint srv_dml_needed_delay = 0;
  90. UNIV_INTERN ibool srv_lock_timeout_and_monitor_active = FALSE;
  91. UNIV_INTERN ibool srv_error_monitor_active = FALSE;
  92. UNIV_INTERN const char* srv_main_thread_op_info = "";
  93. /* Prefix used by MySQL to indicate pre-5.1 table name encoding */
  94. UNIV_INTERN const char srv_mysql50_table_name_prefix[9] = "#mysql50#";
  95. /* Server parameters which are read from the initfile */
  96. /* The following three are dir paths which are catenated before file
  97. names, where the file name itself may also contain a path */
  98. UNIV_INTERN char* srv_data_home = NULL;
  99. #ifdef UNIV_LOG_ARCHIVE
  100. UNIV_INTERN char* srv_arch_dir = NULL;
  101. #endif /* UNIV_LOG_ARCHIVE */
  102. /* store to its own file each table created by an user; data
  103. dictionary tables are in the system tablespace 0 */
  104. UNIV_INTERN my_bool srv_file_per_table;
  105. /* The file format to use on new *.ibd files. */
  106. UNIV_INTERN ulint srv_file_format = 0;
  107. /* Whether to check file format during startup a value of
  108. DICT_TF_FORMAT_MAX + 1 means no checking ie. FALSE. The default is to
  109. set it to the highest format we support. */
  110. UNIV_INTERN ulint srv_check_file_format_at_startup = DICT_TF_FORMAT_MAX;
  111. #if DICT_TF_FORMAT_51
  112. # error "DICT_TF_FORMAT_51 must be 0!"
  113. #endif
  114. /* Place locks to records only i.e. do not use next-key locking except
  115. on duplicate key checking and foreign key checking */
  116. UNIV_INTERN ibool srv_locks_unsafe_for_binlog = FALSE;
  117. UNIV_INTERN ulint srv_n_data_files = 0;
  118. UNIV_INTERN char** srv_data_file_names = NULL;
  119. /* size in database pages */
  120. UNIV_INTERN ulint* srv_data_file_sizes = NULL;
  121. /* if TRUE, then we auto-extend the last data file */
  122. UNIV_INTERN ibool srv_auto_extend_last_data_file = FALSE;
  123. /* if != 0, this tells the max size auto-extending may increase the
  124. last data file size */
  125. UNIV_INTERN ulint srv_last_file_size_max = 0;
  126. /* If the last data file is auto-extended, we add this
  127. many pages to it at a time */
  128. UNIV_INTERN ulong srv_auto_extend_increment = 8;
  129. UNIV_INTERN ulint* srv_data_file_is_raw_partition = NULL;
  130. /* If the following is TRUE we do not allow inserts etc. This protects
  131. the user from forgetting the 'newraw' keyword to my.cnf */
  132. UNIV_INTERN ibool srv_created_new_raw = FALSE;
  133. UNIV_INTERN char** srv_log_group_home_dirs = NULL;
  134. UNIV_INTERN ulint srv_n_log_groups = ULINT_MAX;
  135. UNIV_INTERN ulint srv_n_log_files = ULINT_MAX;
  136. /* size in database pages */
  137. UNIV_INTERN ulint srv_log_file_size = ULINT_MAX;
  138. /* size in database pages */
  139. UNIV_INTERN ulint srv_log_buffer_size = ULINT_MAX;
  140. UNIV_INTERN ulong srv_flush_log_at_trx_commit = 1;
  141. /* The sort order table of the MySQL latin1_swedish_ci character set
  142. collation */
  143. UNIV_INTERN const byte* srv_latin1_ordering;
  144. /* use os/external memory allocator */
  145. UNIV_INTERN my_bool srv_use_sys_malloc = FALSE;
  146. /* requested size in kilobytes */
  147. UNIV_INTERN ulint srv_buf_pool_size = ULINT_MAX;
  148. /* previously requested size */
  149. UNIV_INTERN ulint srv_buf_pool_old_size;
  150. /* current size in kilobytes */
  151. UNIV_INTERN ulint srv_buf_pool_curr_size = 0;
  152. /* size in bytes */
  153. UNIV_INTERN ulint srv_mem_pool_size = ULINT_MAX;
  154. UNIV_INTERN ulint srv_lock_table_size = ULINT_MAX;
  155. UNIV_INTERN ulint srv_n_file_io_threads = ULINT_MAX;
  156. #ifdef UNIV_LOG_ARCHIVE
  157. UNIV_INTERN ibool srv_log_archive_on = FALSE;
  158. UNIV_INTERN ibool srv_archive_recovery = 0;
  159. UNIV_INTERN ib_uint64_t srv_archive_recovery_limit_lsn;
  160. #endif /* UNIV_LOG_ARCHIVE */
  161. /* This parameter is used to throttle the number of insert buffers that are
  162. merged in a batch. By increasing this parameter on a faster disk you can
  163. possibly reduce the number of I/O operations performed to complete the
  164. merge operation. The value of this parameter is used as is by the
  165. background loop when the system is idle (low load), on a busy system
  166. the parameter is scaled down by a factor of 4, this is to avoid putting
  167. a heavier load on the I/O sub system. */
  168. UNIV_INTERN ulong srv_insert_buffer_batch_size = 20;
  169. UNIV_INTERN char* srv_file_flush_method_str = NULL;
  170. UNIV_INTERN ulint srv_unix_file_flush_method = SRV_UNIX_FSYNC;
  171. UNIV_INTERN ulint srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
  172. UNIV_INTERN ulint srv_max_n_open_files = 300;
  173. /* The InnoDB main thread tries to keep the ratio of modified pages
  174. in the buffer pool to all database pages in the buffer pool smaller than
  175. the following number. But it is not guaranteed that the value stays below
  176. that during a time of heavy update/insert activity. */
  177. UNIV_INTERN ulong srv_max_buf_pool_modified_pct = 90;
  178. /* variable counts amount of data read in total (in bytes) */
  179. UNIV_INTERN ulint srv_data_read = 0;
  180. /* here we count the amount of data written in total (in bytes) */
  181. UNIV_INTERN ulint srv_data_written = 0;
  182. /* the number of the log write requests done */
  183. UNIV_INTERN ulint srv_log_write_requests = 0;
  184. /* the number of physical writes to the log performed */
  185. UNIV_INTERN ulint srv_log_writes = 0;
  186. /* amount of data written to the log files in bytes */
  187. UNIV_INTERN ulint srv_os_log_written = 0;
  188. /* amount of writes being done to the log files */
  189. UNIV_INTERN ulint srv_os_log_pending_writes = 0;
  190. /* we increase this counter, when there we don't have enough space in the
  191. log buffer and have to flush it */
  192. UNIV_INTERN ulint srv_log_waits = 0;
  193. /* this variable counts the amount of times, when the doublewrite buffer
  194. was flushed */
  195. UNIV_INTERN ulint srv_dblwr_writes = 0;
  196. /* here we store the number of pages that have been flushed to the
  197. doublewrite buffer */
  198. UNIV_INTERN ulint srv_dblwr_pages_written = 0;
  199. /* in this variable we store the number of write requests issued */
  200. UNIV_INTERN ulint srv_buf_pool_write_requests = 0;
  201. /* here we store the number of times when we had to wait for a free page
  202. in the buffer pool. It happens when the buffer pool is full and we need
  203. to make a flush, in order to be able to read or create a page. */
  204. UNIV_INTERN ulint srv_buf_pool_wait_free = 0;
  205. /* variable to count the number of pages that were written from buffer
  206. pool to the disk */
  207. UNIV_INTERN ulint srv_buf_pool_flushed = 0;
  208. /* variable to count the number of buffer pool reads that led to the
  209. reading of a disk page */
  210. UNIV_INTERN ulint srv_buf_pool_reads = 0;
  211. /* variable to count the number of sequential read-aheads */
  212. UNIV_INTERN ulint srv_read_ahead_seq = 0;
  213. /* variable to count the number of random read-aheads */
  214. UNIV_INTERN ulint srv_read_ahead_rnd = 0;
  215. /* structure to pass status variables to MySQL */
  216. UNIV_INTERN export_struc export_vars;
  217. /* If the following is != 0 we do not allow inserts etc. This protects
  218. the user from forgetting the innodb_force_recovery keyword to my.cnf */
  219. UNIV_INTERN ulint srv_force_recovery = 0;
  220. /*-----------------------*/
  221. /* We are prepared for a situation that we have this many threads waiting for
  222. a semaphore inside InnoDB. innobase_start_or_create_for_mysql() sets the
  223. value. */
  224. UNIV_INTERN ulint srv_max_n_threads = 0;
  225. /* The following controls how many threads we let inside InnoDB concurrently:
  226. threads waiting for locks are not counted into the number because otherwise
  227. we could get a deadlock. MySQL creates a thread for each user session, and
  228. semaphore contention and convoy problems can occur withput this restriction.
  229. Value 10 should be good if there are less than 4 processors + 4 disks in the
  230. computer. Bigger computers need bigger values. Value 0 will disable the
  231. concurrency check. */
  232. UNIV_INTERN ulong srv_thread_concurrency = 0;
  233. UNIV_INTERN ulong srv_commit_concurrency = 0;
  234. /* this mutex protects srv_conc data structures */
  235. UNIV_INTERN os_fast_mutex_t srv_conc_mutex;
  236. /* number of transactions that have declared_to_be_inside_innodb set.
  237. It used to be a non-error for this value to drop below zero temporarily.
  238. This is no longer true. We'll, however, keep the lint datatype to add
  239. assertions to catch any corner cases that we may have missed. */
  240. UNIV_INTERN lint srv_conc_n_threads = 0;
  241. /* number of OS threads waiting in the FIFO for a permission to enter
  242. InnoDB */
  243. UNIV_INTERN ulint srv_conc_n_waiting_threads = 0;
  244. typedef struct srv_conc_slot_struct srv_conc_slot_t;
  245. struct srv_conc_slot_struct{
  246. os_event_t event; /* event to wait */
  247. ibool reserved; /* TRUE if slot
  248. reserved */
  249. ibool wait_ended; /* TRUE when another
  250. thread has already set
  251. the event and the
  252. thread in this slot is
  253. free to proceed; but
  254. reserved may still be
  255. TRUE at that point */
  256. UT_LIST_NODE_T(srv_conc_slot_t) srv_conc_queue; /* queue node */
  257. };
  258. /* queue of threads waiting to get in */
  259. UNIV_INTERN UT_LIST_BASE_NODE_T(srv_conc_slot_t) srv_conc_queue;
  260. /* array of wait slots */
  261. UNIV_INTERN srv_conc_slot_t* srv_conc_slots;
  262. /* Number of times a thread is allowed to enter InnoDB within the same
  263. SQL query after it has once got the ticket at srv_conc_enter_innodb */
  264. #define SRV_FREE_TICKETS_TO_ENTER srv_n_free_tickets_to_enter
  265. #define SRV_THREAD_SLEEP_DELAY srv_thread_sleep_delay
  266. /*-----------------------*/
  267. /* If the following is set to 1 then we do not run purge and insert buffer
  268. merge to completion before shutdown. If it is set to 2, do not even flush the
  269. buffer pool to data files at the shutdown: we effectively 'crash'
  270. InnoDB (but lose no committed transactions). */
  271. UNIV_INTERN ulint srv_fast_shutdown = 0;
  272. /* Generate a innodb_status.<pid> file */
  273. UNIV_INTERN ibool srv_innodb_status = FALSE;
  274. /* When estimating number of different key values in an index, sample
  275. this many index pages */
  276. UNIV_INTERN unsigned long long srv_stats_sample_pages = 8;
  277. UNIV_INTERN ibool srv_use_doublewrite_buf = TRUE;
  278. UNIV_INTERN ibool srv_use_checksums = TRUE;
  279. UNIV_INTERN ibool srv_set_thread_priorities = TRUE;
  280. UNIV_INTERN int srv_query_thread_priority = 0;
  281. UNIV_INTERN ulong srv_replication_delay = 0;
  282. /*-------------------------------------------*/
  283. UNIV_INTERN ulong srv_n_spin_wait_rounds = 20;
  284. UNIV_INTERN ulong srv_n_free_tickets_to_enter = 500;
  285. UNIV_INTERN ulong srv_thread_sleep_delay = 10000;
  286. UNIV_INTERN ulint srv_spin_wait_delay = 5;
  287. UNIV_INTERN ibool srv_priority_boost = TRUE;
  288. #ifdef UNIV_DEBUG
  289. UNIV_INTERN ibool srv_print_thread_releases = FALSE;
  290. UNIV_INTERN ibool srv_print_lock_waits = FALSE;
  291. UNIV_INTERN ibool srv_print_buf_io = FALSE;
  292. UNIV_INTERN ibool srv_print_log_io = FALSE;
  293. UNIV_INTERN ibool srv_print_latch_waits = FALSE;
  294. #endif /* UNIV_DEBUG */
  295. UNIV_INTERN ulint srv_n_rows_inserted = 0;
  296. UNIV_INTERN ulint srv_n_rows_updated = 0;
  297. UNIV_INTERN ulint srv_n_rows_deleted = 0;
  298. UNIV_INTERN ulint srv_n_rows_read = 0;
  299. #ifndef UNIV_HOTBACKUP
  300. static ulint srv_n_rows_inserted_old = 0;
  301. static ulint srv_n_rows_updated_old = 0;
  302. static ulint srv_n_rows_deleted_old = 0;
  303. static ulint srv_n_rows_read_old = 0;
  304. #endif /* !UNIV_HOTBACKUP */
  305. UNIV_INTERN ulint srv_n_lock_wait_count = 0;
  306. UNIV_INTERN ulint srv_n_lock_wait_current_count = 0;
  307. UNIV_INTERN ib_int64_t srv_n_lock_wait_time = 0;
  308. UNIV_INTERN ulint srv_n_lock_max_wait_time = 0;
  309. /*
  310. Set the following to 0 if you want InnoDB to write messages on
  311. stderr on startup/shutdown
  312. */
  313. UNIV_INTERN ibool srv_print_verbose_log = TRUE;
  314. UNIV_INTERN ibool srv_print_innodb_monitor = FALSE;
  315. UNIV_INTERN ibool srv_print_innodb_lock_monitor = FALSE;
  316. UNIV_INTERN ibool srv_print_innodb_tablespace_monitor = FALSE;
  317. UNIV_INTERN ibool srv_print_innodb_table_monitor = FALSE;
  318. /* Array of English strings describing the current state of an
  319. i/o handler thread */
  320. UNIV_INTERN const char* srv_io_thread_op_info[SRV_MAX_N_IO_THREADS];
  321. UNIV_INTERN const char* srv_io_thread_function[SRV_MAX_N_IO_THREADS];
  322. UNIV_INTERN time_t srv_last_monitor_time;
  323. UNIV_INTERN mutex_t srv_innodb_monitor_mutex;
  324. /* Mutex for locking srv_monitor_file */
  325. UNIV_INTERN mutex_t srv_monitor_file_mutex;
  326. /* Temporary file for innodb monitor output */
  327. UNIV_INTERN FILE* srv_monitor_file;
  328. /* Mutex for locking srv_dict_tmpfile.
  329. This mutex has a very high rank; threads reserving it should not
  330. be holding any InnoDB latches. */
  331. UNIV_INTERN mutex_t srv_dict_tmpfile_mutex;
  332. /* Temporary file for output from the data dictionary */
  333. UNIV_INTERN FILE* srv_dict_tmpfile;
  334. /* Mutex for locking srv_misc_tmpfile.
  335. This mutex has a very low rank; threads reserving it should not
  336. acquire any further latches or sleep before releasing this one. */
  337. UNIV_INTERN mutex_t srv_misc_tmpfile_mutex;
  338. /* Temporary file for miscellanous diagnostic output */
  339. UNIV_INTERN FILE* srv_misc_tmpfile;
  340. UNIV_INTERN ulint srv_main_thread_process_no = 0;
  341. UNIV_INTERN ulint srv_main_thread_id = 0;
  342. /*
  343. IMPLEMENTATION OF THE SERVER MAIN PROGRAM
  344. =========================================
  345. There is the following analogue between this database
  346. server and an operating system kernel:
  347. DB concept equivalent OS concept
  348. ---------- ---------------------
  349. transaction -- process;
  350. query thread -- thread;
  351. lock -- semaphore;
  352. transaction set to
  353. the rollback state -- kill signal delivered to a process;
  354. kernel -- kernel;
  355. query thread execution:
  356. (a) without kernel mutex
  357. reserved -- process executing in user mode;
  358. (b) with kernel mutex reserved
  359. -- process executing in kernel mode;
  360. The server is controlled by a master thread which runs at
  361. a priority higher than normal, that is, higher than user threads.
  362. It sleeps most of the time, and wakes up, say, every 300 milliseconds,
  363. to check whether there is anything happening in the server which
  364. requires intervention of the master thread. Such situations may be,
  365. for example, when flushing of dirty blocks is needed in the buffer
  366. pool or old version of database rows have to be cleaned away.
  367. The threads which we call user threads serve the queries of
  368. the clients and input from the console of the server.
  369. They run at normal priority. The server may have several
  370. communications endpoints. A dedicated set of user threads waits
  371. at each of these endpoints ready to receive a client request.
  372. Each request is taken by a single user thread, which then starts
  373. processing and, when the result is ready, sends it to the client
  374. and returns to wait at the same endpoint the thread started from.
  375. So, we do not have dedicated communication threads listening at
  376. the endpoints and dealing the jobs to dedicated worker threads.
  377. Our architecture saves one thread swithch per request, compared
  378. to the solution with dedicated communication threads
  379. which amounts to 15 microseconds on 100 MHz Pentium
  380. running NT. If the client
  381. is communicating over a network, this saving is negligible, but
  382. if the client resides in the same machine, maybe in an SMP machine
  383. on a different processor from the server thread, the saving
  384. can be important as the threads can communicate over shared
  385. memory with an overhead of a few microseconds.
  386. We may later implement a dedicated communication thread solution
  387. for those endpoints which communicate over a network.
  388. Our solution with user threads has two problems: for each endpoint
  389. there has to be a number of listening threads. If there are many
  390. communication endpoints, it may be difficult to set the right number
  391. of concurrent threads in the system, as many of the threads
  392. may always be waiting at less busy endpoints. Another problem
  393. is queuing of the messages, as the server internally does not
  394. offer any queue for jobs.
  395. Another group of user threads is intended for splitting the
  396. queries and processing them in parallel. Let us call these
  397. parallel communication threads. These threads are waiting for
  398. parallelized tasks, suspended on event semaphores.
  399. A single user thread waits for input from the console,
  400. like a command to shut the database.
  401. Utility threads are a different group of threads which takes
  402. care of the buffer pool flushing and other, mainly background
  403. operations, in the server.
  404. Some of these utility threads always run at a lower than normal
  405. priority, so that they are always in background. Some of them
  406. may dynamically boost their priority by the pri_adjust function,
  407. even to higher than normal priority, if their task becomes urgent.
  408. The running of utilities is controlled by high- and low-water marks
  409. of urgency. The urgency may be measured by the number of dirty blocks
  410. in the buffer pool, in the case of the flush thread, for example.
  411. When the high-water mark is exceeded, an utility starts running, until
  412. the urgency drops under the low-water mark. Then the utility thread
  413. suspend itself to wait for an event. The master thread is
  414. responsible of signaling this event when the utility thread is
  415. again needed.
  416. For each individual type of utility, some threads always remain
  417. at lower than normal priority. This is because pri_adjust is implemented
  418. so that the threads at normal or higher priority control their
  419. share of running time by calling sleep. Thus, if the load of the
  420. system sudenly drops, these threads cannot necessarily utilize
  421. the system fully. The background priority threads make up for this,
  422. starting to run when the load drops.
  423. When there is no activity in the system, also the master thread
  424. suspends itself to wait for an event making
  425. the server totally silent. The responsibility to signal this
  426. event is on the user thread which again receives a message
  427. from a client.
  428. There is still one complication in our server design. If a
  429. background utility thread obtains a resource (e.g., mutex) needed by a user
  430. thread, and there is also some other user activity in the system,
  431. the user thread may have to wait indefinitely long for the
  432. resource, as the OS does not schedule a background thread if
  433. there is some other runnable user thread. This problem is called
  434. priority inversion in real-time programming.
  435. One solution to the priority inversion problem would be to
  436. keep record of which thread owns which resource and
  437. in the above case boost the priority of the background thread
  438. so that it will be scheduled and it can release the resource.
  439. This solution is called priority inheritance in real-time programming.
  440. A drawback of this solution is that the overhead of acquiring a mutex
  441. increases slightly, maybe 0.2 microseconds on a 100 MHz Pentium, because
  442. the thread has to call os_thread_get_curr_id.
  443. This may be compared to 0.5 microsecond overhead for a mutex lock-unlock
  444. pair. Note that the thread
  445. cannot store the information in the resource, say mutex, itself,
  446. because competing threads could wipe out the information if it is
  447. stored before acquiring the mutex, and if it stored afterwards,
  448. the information is outdated for the time of one machine instruction,
  449. at least. (To be precise, the information could be stored to
  450. lock_word in mutex if the machine supports atomic swap.)
  451. The above solution with priority inheritance may become actual in the
  452. future, but at the moment we plan to implement a more coarse solution,
  453. which could be called a global priority inheritance. If a thread
  454. has to wait for a long time, say 300 milliseconds, for a resource,
  455. we just guess that it may be waiting for a resource owned by a background
  456. thread, and boost the the priority of all runnable background threads
  457. to the normal level. The background threads then themselves adjust
  458. their fixed priority back to background after releasing all resources
  459. they had (or, at some fixed points in their program code).
  460. What is the performance of the global priority inheritance solution?
  461. We may weigh the length of the wait time 300 milliseconds, during
  462. which the system processes some other thread
  463. to the cost of boosting the priority of each runnable background
  464. thread, rescheduling it, and lowering the priority again.
  465. On 100 MHz Pentium + NT this overhead may be of the order 100
  466. microseconds per thread. So, if the number of runnable background
  467. threads is not very big, say < 100, the cost is tolerable.
  468. Utility threads probably will access resources used by
  469. user threads not very often, so collisions of user threads
  470. to preempted utility threads should not happen very often.
  471. The thread table contains
  472. information of the current status of each thread existing in the system,
  473. and also the event semaphores used in suspending the master thread
  474. and utility and parallel communication threads when they have nothing to do.
  475. The thread table can be seen as an analogue to the process table
  476. in a traditional Unix implementation.
  477. The thread table is also used in the global priority inheritance
  478. scheme. This brings in one additional complication: threads accessing
  479. the thread table must have at least normal fixed priority,
  480. because the priority inheritance solution does not work if a background
  481. thread is preempted while possessing the mutex protecting the thread table.
  482. So, if a thread accesses the thread table, its priority has to be
  483. boosted at least to normal. This priority requirement can be seen similar to
  484. the privileged mode used when processing the kernel calls in traditional
  485. Unix.*/
  486. /* Thread slot in the thread table */
  487. struct srv_slot_struct{
  488. os_thread_id_t id; /* thread id */
  489. os_thread_t handle; /* thread handle */
  490. unsigned type:3; /* thread type: user, utility etc. */
  491. unsigned in_use:1; /* TRUE if this slot is in use */
  492. unsigned suspended:1; /* TRUE if the thread is waiting
  493. for the event of this slot */
  494. ib_time_t suspend_time; /* time when the thread was
  495. suspended */
  496. os_event_t event; /* event used in suspending the
  497. thread when it has nothing to do */
  498. que_thr_t* thr; /* suspended query thread (only
  499. used for MySQL threads) */
  500. };
  501. /* Table for MySQL threads where they will be suspended to wait for locks */
  502. UNIV_INTERN srv_slot_t* srv_mysql_table = NULL;
  503. UNIV_INTERN os_event_t srv_lock_timeout_thread_event;
  504. UNIV_INTERN srv_sys_t* srv_sys = NULL;
  505. /* padding to prevent other memory update hotspots from residing on
  506. the same memory cache line */
  507. UNIV_INTERN byte srv_pad1[64];
  508. /* mutex protecting the server, trx structs, query threads, and lock table */
  509. UNIV_INTERN mutex_t* kernel_mutex_temp;
  510. /* padding to prevent other memory update hotspots from residing on
  511. the same memory cache line */
  512. UNIV_INTERN byte srv_pad2[64];
  513. #if 0
  514. /* The following three values measure the urgency of the jobs of
  515. buffer, version, and insert threads. They may vary from 0 - 1000.
  516. The server mutex protects all these variables. The low-water values
  517. tell that the server can acquiesce the utility when the value
  518. drops below this low-water mark. */
  519. static ulint srv_meter[SRV_MASTER + 1];
  520. static ulint srv_meter_low_water[SRV_MASTER + 1];
  521. static ulint srv_meter_high_water[SRV_MASTER + 1];
  522. static ulint srv_meter_high_water2[SRV_MASTER + 1];
  523. static ulint srv_meter_foreground[SRV_MASTER + 1];
  524. #endif
  525. /* The following values give info about the activity going on in
  526. the database. They are protected by the server mutex. The arrays
  527. are indexed by the type of the thread. */
  528. UNIV_INTERN ulint srv_n_threads_active[SRV_MASTER + 1];
  529. UNIV_INTERN ulint srv_n_threads[SRV_MASTER + 1];
  530. /*************************************************************************
  531. Sets the info describing an i/o thread current state. */
  532. UNIV_INTERN
  533. void
  534. srv_set_io_thread_op_info(
  535. /*======================*/
  536. ulint i, /* in: the 'segment' of the i/o thread */
  537. const char* str) /* in: constant char string describing the
  538. state */
  539. {
  540. ut_a(i < SRV_MAX_N_IO_THREADS);
  541. srv_io_thread_op_info[i] = str;
  542. }
  543. /*************************************************************************
  544. Accessor function to get pointer to n'th slot in the server thread
  545. table. */
  546. static
  547. srv_slot_t*
  548. srv_table_get_nth_slot(
  549. /*===================*/
  550. /* out: pointer to the slot */
  551. ulint index) /* in: index of the slot */
  552. {
  553. ut_a(index < OS_THREAD_MAX_N);
  554. return(srv_sys->threads + index);
  555. }
  556. #ifndef UNIV_HOTBACKUP
  557. /*************************************************************************
  558. Gets the number of threads in the system. */
  559. UNIV_INTERN
  560. ulint
  561. srv_get_n_threads(void)
  562. /*===================*/
  563. {
  564. ulint i;
  565. ulint n_threads = 0;
  566. mutex_enter(&kernel_mutex);
  567. for (i = SRV_COM; i < SRV_MASTER + 1; i++) {
  568. n_threads += srv_n_threads[i];
  569. }
  570. mutex_exit(&kernel_mutex);
  571. return(n_threads);
  572. }
  573. /*************************************************************************
  574. Reserves a slot in the thread table for the current thread. Also creates the
  575. thread local storage struct for the current thread. NOTE! The server mutex
  576. has to be reserved by the caller! */
  577. static
  578. ulint
  579. srv_table_reserve_slot(
  580. /*===================*/
  581. /* out: reserved slot index */
  582. enum srv_thread_type type) /* in: type of the thread */
  583. {
  584. srv_slot_t* slot;
  585. ulint i;
  586. ut_a(type > 0);
  587. ut_a(type <= SRV_MASTER);
  588. i = 0;
  589. slot = srv_table_get_nth_slot(i);
  590. while (slot->in_use) {
  591. i++;
  592. slot = srv_table_get_nth_slot(i);
  593. }
  594. ut_a(slot->in_use == FALSE);
  595. slot->in_use = TRUE;
  596. slot->suspended = FALSE;
  597. slot->type = type;
  598. slot->id = os_thread_get_curr_id();
  599. slot->handle = os_thread_get_curr();
  600. thr_local_create();
  601. thr_local_set_slot_no(os_thread_get_curr_id(), i);
  602. return(i);
  603. }
  604. /*************************************************************************
  605. Suspends the calling thread to wait for the event in its thread slot.
  606. NOTE! The server mutex has to be reserved by the caller! */
  607. static
  608. os_event_t
  609. srv_suspend_thread(void)
  610. /*====================*/
  611. /* out: event for the calling thread to wait */
  612. {
  613. srv_slot_t* slot;
  614. os_event_t event;
  615. ulint slot_no;
  616. enum srv_thread_type type;
  617. ut_ad(mutex_own(&kernel_mutex));
  618. slot_no = thr_local_get_slot_no(os_thread_get_curr_id());
  619. if (srv_print_thread_releases) {
  620. fprintf(stderr,
  621. "Suspending thread %lu to slot %lu\n",
  622. (ulong) os_thread_get_curr_id(), (ulong) slot_no);
  623. }
  624. slot = srv_table_get_nth_slot(slot_no);
  625. type = slot->type;
  626. ut_ad(type >= SRV_WORKER);
  627. ut_ad(type <= SRV_MASTER);
  628. event = slot->event;
  629. slot->suspended = TRUE;
  630. ut_ad(srv_n_threads_active[type] > 0);
  631. srv_n_threads_active[type]--;
  632. os_event_reset(event);
  633. return(event);
  634. }
  635. #endif /* !UNIV_HOTBACKUP */
  636. /*************************************************************************
  637. Releases threads of the type given from suspension in the thread table.
  638. NOTE! The server mutex has to be reserved by the caller! */
  639. UNIV_INTERN
  640. ulint
  641. srv_release_threads(
  642. /*================*/
  643. /* out: number of threads
  644. released: this may be < n if
  645. not enough threads were
  646. suspended at the moment */
  647. enum srv_thread_type type, /* in: thread type */
  648. ulint n) /* in: number of threads to release */
  649. {
  650. srv_slot_t* slot;
  651. ulint i;
  652. ulint count = 0;
  653. ut_ad(type >= SRV_WORKER);
  654. ut_ad(type <= SRV_MASTER);
  655. ut_ad(n > 0);
  656. ut_ad(mutex_own(&kernel_mutex));
  657. for (i = 0; i < OS_THREAD_MAX_N; i++) {
  658. slot = srv_table_get_nth_slot(i);
  659. if (slot->in_use && slot->type == type && slot->suspended) {
  660. slot->suspended = FALSE;
  661. srv_n_threads_active[type]++;
  662. os_event_set(slot->event);
  663. if (srv_print_thread_releases) {
  664. fprintf(stderr,
  665. "Releasing thread %lu type %lu"
  666. " from slot %lu\n",
  667. (ulong) slot->id, (ulong) type,
  668. (ulong) i);
  669. }
  670. count++;
  671. if (count == n) {
  672. break;
  673. }
  674. }
  675. }
  676. return(count);
  677. }
  678. /*************************************************************************
  679. Returns the calling thread type. */
  680. UNIV_INTERN
  681. enum srv_thread_type
  682. srv_get_thread_type(void)
  683. /*=====================*/
  684. /* out: SRV_COM, ... */
  685. {
  686. ulint slot_no;
  687. srv_slot_t* slot;
  688. enum srv_thread_type type;
  689. mutex_enter(&kernel_mutex);
  690. slot_no = thr_local_get_slot_no(os_thread_get_curr_id());
  691. slot = srv_table_get_nth_slot(slot_no);
  692. type = slot->type;
  693. ut_ad(type >= SRV_WORKER);
  694. ut_ad(type <= SRV_MASTER);
  695. mutex_exit(&kernel_mutex);
  696. return(type);
  697. }
  698. /*************************************************************************
  699. Initializes the server. */
  700. UNIV_INTERN
  701. void
  702. srv_init(void)
  703. /*==========*/
  704. {
  705. srv_conc_slot_t* conc_slot;
  706. srv_slot_t* slot;
  707. dict_table_t* table;
  708. ulint i;
  709. srv_sys = mem_alloc(sizeof(srv_sys_t));
  710. kernel_mutex_temp = mem_alloc(sizeof(mutex_t));
  711. mutex_create(&kernel_mutex, SYNC_KERNEL);
  712. mutex_create(&srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
  713. srv_sys->threads = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
  714. for (i = 0; i < OS_THREAD_MAX_N; i++) {
  715. slot = srv_table_get_nth_slot(i);
  716. slot->in_use = FALSE;
  717. slot->type=0; /* Avoid purify errors */
  718. slot->event = os_event_create(NULL);
  719. ut_a(slot->event);
  720. }
  721. srv_mysql_table = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
  722. for (i = 0; i < OS_THREAD_MAX_N; i++) {
  723. slot = srv_mysql_table + i;
  724. slot->in_use = FALSE;
  725. slot->type = 0;
  726. slot->event = os_event_create(NULL);
  727. ut_a(slot->event);
  728. }
  729. srv_lock_timeout_thread_event = os_event_create(NULL);
  730. for (i = 0; i < SRV_MASTER + 1; i++) {
  731. srv_n_threads_active[i] = 0;
  732. srv_n_threads[i] = 0;
  733. #if 0
  734. srv_meter[i] = 30;
  735. srv_meter_low_water[i] = 50;
  736. srv_meter_high_water[i] = 100;
  737. srv_meter_high_water2[i] = 200;
  738. srv_meter_foreground[i] = 250;
  739. #endif
  740. }
  741. UT_LIST_INIT(srv_sys->tasks);
  742. /* create dummy table and index for old-style infimum and supremum */
  743. table = dict_mem_table_create("SYS_DUMMY1",
  744. DICT_HDR_SPACE, 1, 0);
  745. dict_mem_table_add_col(table, NULL, NULL, DATA_CHAR,
  746. DATA_ENGLISH | DATA_NOT_NULL, 8);
  747. srv_sys->dummy_ind1 = dict_mem_index_create(
  748. "SYS_DUMMY1", "SYS_DUMMY1", DICT_HDR_SPACE, 0, 1);
  749. dict_index_add_col(srv_sys->dummy_ind1, table,
  750. dict_table_get_nth_col(table, 0), 0);
  751. srv_sys->dummy_ind1->table = table;
  752. /* create dummy table and index for new-style infimum and supremum */
  753. table = dict_mem_table_create("SYS_DUMMY2",
  754. DICT_HDR_SPACE, 1, DICT_TF_COMPACT);
  755. dict_mem_table_add_col(table, NULL, NULL, DATA_CHAR,
  756. DATA_ENGLISH | DATA_NOT_NULL, 8);
  757. srv_sys->dummy_ind2 = dict_mem_index_create(
  758. "SYS_DUMMY2", "SYS_DUMMY2", DICT_HDR_SPACE, 0, 1);
  759. dict_index_add_col(srv_sys->dummy_ind2, table,
  760. dict_table_get_nth_col(table, 0), 0);
  761. srv_sys->dummy_ind2->table = table;
  762. /* avoid ut_ad(index->cached) in dict_index_get_n_unique_in_tree */
  763. srv_sys->dummy_ind1->cached = srv_sys->dummy_ind2->cached = TRUE;
  764. /* Init the server concurrency restriction data structures */
  765. os_fast_mutex_init(&srv_conc_mutex);
  766. UT_LIST_INIT(srv_conc_queue);
  767. srv_conc_slots = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_conc_slot_t));
  768. for (i = 0; i < OS_THREAD_MAX_N; i++) {
  769. conc_slot = srv_conc_slots + i;
  770. conc_slot->reserved = FALSE;
  771. conc_slot->event = os_event_create(NULL);
  772. ut_a(conc_slot->event);
  773. }
  774. /* Initialize some INFORMATION SCHEMA internal structures */
  775. trx_i_s_cache_init(trx_i_s_cache);
  776. }
  777. /*************************************************************************
  778. Frees the OS fast mutex created in srv_init(). */
  779. UNIV_INTERN
  780. void
  781. srv_free(void)
  782. /*==========*/
  783. {
  784. os_fast_mutex_free(&srv_conc_mutex);
  785. }
  786. /*************************************************************************
  787. Initializes the synchronization primitives, memory system, and the thread
  788. local storage. */
  789. UNIV_INTERN
  790. void
  791. srv_general_init(void)
  792. /*==================*/
  793. {
  794. os_sync_init();
  795. sync_init();
  796. mem_init(srv_mem_pool_size);
  797. thr_local_init();
  798. }
  799. /*======================= InnoDB Server FIFO queue =======================*/
  800. /* Maximum allowable purge history length. <=0 means 'infinite'. */
  801. UNIV_INTERN ulong srv_max_purge_lag = 0;
  802. /*************************************************************************
  803. Puts an OS thread to wait if there are too many concurrent threads
  804. (>= srv_thread_concurrency) inside InnoDB. The threads wait in a FIFO queue. */
  805. UNIV_INTERN
  806. void
  807. srv_conc_enter_innodb(
  808. /*==================*/
  809. trx_t* trx) /* in: transaction object associated with the
  810. thread */
  811. {
  812. ibool has_slept = FALSE;
  813. srv_conc_slot_t* slot = NULL;
  814. ulint i;
  815. if (trx->mysql_thd != NULL
  816. && thd_is_replication_slave_thread(trx->mysql_thd)) {
  817. UT_WAIT_FOR(srv_conc_n_threads
  818. < (lint)srv_thread_concurrency,
  819. srv_replication_delay * 1000);
  820. return;
  821. }
  822. /* If trx has 'free tickets' to enter the engine left, then use one
  823. such ticket */
  824. if (trx->n_tickets_to_enter_innodb > 0) {
  825. trx->n_tickets_to_enter_innodb--;
  826. return;
  827. }
  828. os_fast_mutex_lock(&srv_conc_mutex);
  829. retry:
  830. if (trx->declared_to_be_inside_innodb) {
  831. ut_print_timestamp(stderr);
  832. fputs(" InnoDB: Error: trying to declare trx"
  833. " to enter InnoDB, but\n"
  834. "InnoDB: it already is declared.\n", stderr);
  835. trx_print(stderr, trx, 0);
  836. putc('\n', stderr);
  837. os_fast_mutex_unlock(&srv_conc_mutex);
  838. return;
  839. }
  840. ut_ad(srv_conc_n_threads >= 0);
  841. if (srv_conc_n_threads < (lint)srv_thread_concurrency) {
  842. srv_conc_n_threads++;
  843. trx->declared_to_be_inside_innodb = TRUE;
  844. trx->n_tickets_to_enter_innodb = SRV_FREE_TICKETS_TO_ENTER;
  845. os_fast_mutex_unlock(&srv_conc_mutex);
  846. return;
  847. }
  848. /* If the transaction is not holding resources, let it sleep
  849. for SRV_THREAD_SLEEP_DELAY microseconds, and try again then */
  850. if (!has_slept && !trx->has_search_latch
  851. && NULL == UT_LIST_GET_FIRST(trx->trx_locks)) {
  852. has_slept = TRUE; /* We let it sleep only once to avoid
  853. starvation */
  854. srv_conc_n_waiting_threads++;
  855. os_fast_mutex_unlock(&srv_conc_mutex);
  856. trx->op_info = "sleeping before joining InnoDB queue";
  857. /* Peter Zaitsev suggested that we take the sleep away
  858. altogether. But the sleep may be good in pathological
  859. situations of lots of thread switches. Simply put some
  860. threads aside for a while to reduce the number of thread
  861. switches. */
  862. if (SRV_THREAD_SLEEP_DELAY > 0) {
  863. os_thread_sleep(SRV_THREAD_SLEEP_DELAY);
  864. }
  865. trx->op_info = "";
  866. os_fast_mutex_lock(&srv_conc_mutex);
  867. srv_conc_n_waiting_threads--;
  868. goto retry;
  869. }
  870. /* Too many threads inside: put the current thread to a queue */
  871. for (i = 0; i < OS_THREAD_MAX_N; i++) {
  872. slot = srv_conc_slots + i;
  873. if (!slot->reserved) {
  874. break;
  875. }
  876. }
  877. if (i == OS_THREAD_MAX_N) {
  878. /* Could not find a free wait slot, we must let the
  879. thread enter */
  880. srv_conc_n_threads++;
  881. trx->declared_to_be_inside_innodb = TRUE;
  882. trx->n_tickets_to_enter_innodb = 0;
  883. os_fast_mutex_unlock(&srv_conc_mutex);
  884. return;
  885. }
  886. /* Release possible search system latch this thread has */
  887. if (trx->has_search_latch) {
  888. trx_search_latch_release_if_reserved(trx);
  889. }
  890. /* Add to the queue */
  891. slot->reserved = TRUE;
  892. slot->wait_ended = FALSE;
  893. UT_LIST_ADD_LAST(srv_conc_queue, srv_conc_queue, slot);
  894. os_event_reset(slot->event);
  895. srv_conc_n_waiting_threads++;
  896. os_fast_mutex_unlock(&srv_conc_mutex);
  897. /* Go to wait for the event; when a thread leaves InnoDB it will
  898. release this thread */
  899. trx->op_info = "waiting in InnoDB queue";
  900. os_event_wait(slot->event);
  901. trx->op_info = "";
  902. os_fast_mutex_lock(&srv_conc_mutex);
  903. srv_conc_n_waiting_threads--;
  904. /* NOTE that the thread which released this thread already
  905. incremented the thread counter on behalf of this thread */
  906. slot->reserved = FALSE;
  907. UT_LIST_REMOVE(srv_conc_queue, srv_conc_queue, slot);
  908. trx->declared_to_be_inside_innodb = TRUE;
  909. trx->n_tickets_to_enter_innodb = SRV_FREE_TICKETS_TO_ENTER;
  910. os_fast_mutex_unlock(&srv_conc_mutex);
  911. }
  912. /*************************************************************************
  913. This lets a thread enter InnoDB regardless of the number of threads inside
  914. InnoDB. This must be called when a thread ends a lock wait. */
  915. UNIV_INTERN
  916. void
  917. srv_conc_force_enter_innodb(
  918. /*========================*/
  919. trx_t* trx) /* in: transaction object associated with the
  920. thread */
  921. {
  922. if (UNIV_LIKELY(!srv_thread_concurrency)) {
  923. return;
  924. }
  925. ut_ad(srv_conc_n_threads >= 0);
  926. os_fast_mutex_lock(&srv_conc_mutex);
  927. srv_conc_n_threads++;
  928. trx->declared_to_be_inside_innodb = TRUE;
  929. trx->n_tickets_to_enter_innodb = 1;
  930. os_fast_mutex_unlock(&srv_conc_mutex);
  931. }
  932. /*************************************************************************
  933. This must be called when a thread exits InnoDB in a lock wait or at the
  934. end of an SQL statement. */
  935. UNIV_INTERN
  936. void
  937. srv_conc_force_exit_innodb(
  938. /*=======================*/
  939. trx_t* trx) /* in: transaction object associated with the
  940. thread */
  941. {
  942. srv_conc_slot_t* slot = NULL;
  943. if (trx->mysql_thd != NULL
  944. && thd_is_replication_slave_thread(trx->mysql_thd)) {
  945. return;
  946. }
  947. if (trx->declared_to_be_inside_innodb == FALSE) {
  948. return;
  949. }
  950. os_fast_mutex_lock(&srv_conc_mutex);
  951. ut_ad(srv_conc_n_threads > 0);
  952. srv_conc_n_threads--;
  953. trx->declared_to_be_inside_innodb = FALSE;
  954. trx->n_tickets_to_enter_innodb = 0;
  955. if (srv_conc_n_threads < (lint)srv_thread_concurrency) {
  956. /* Look for a slot where a thread is waiting and no other
  957. thread has yet released the thread */
  958. slot = UT_LIST_GET_FIRST(srv_conc_queue);
  959. while (slot && slot->wait_ended == TRUE) {
  960. slot = UT_LIST_GET_NEXT(srv_conc_queue, slot);
  961. }
  962. if (slot != NULL) {
  963. slot->wait_ended = TRUE;
  964. /* We increment the count on behalf of the released
  965. thread */
  966. srv_conc_n_threads++;
  967. }
  968. }
  969. os_fast_mutex_unlock(&srv_conc_mutex);
  970. if (slot != NULL) {
  971. os_event_set(slot->event);
  972. }
  973. }
  974. /*************************************************************************
  975. This must be called when a thread exits InnoDB. */
  976. UNIV_INTERN
  977. void
  978. srv_conc_exit_innodb(
  979. /*=================*/
  980. trx_t* trx) /* in: transaction object associated with the
  981. thread */
  982. {
  983. if (trx->n_tickets_to_enter_innodb > 0) {
  984. /* We will pretend the thread is still inside InnoDB though it
  985. now leaves the InnoDB engine. In this way we save
  986. a lot of semaphore operations. srv_conc_force_exit_innodb is
  987. used to declare the thread definitely outside InnoDB. It
  988. should be called when there is a lock wait or an SQL statement
  989. ends. */
  990. return;
  991. }
  992. srv_conc_force_exit_innodb(trx);
  993. }
  994. /*========================================================================*/
  995. /*************************************************************************
  996. Normalizes init parameter values to use units we use inside InnoDB. */
  997. static
  998. ulint
  999. srv_normalize_init_values(void)
  1000. /*===========================*/
  1001. /* out: DB_SUCCESS or error code */
  1002. {
  1003. ulint n;
  1004. ulint i;
  1005. n = srv_n_data_files;
  1006. for (i = 0; i < n; i++) {
  1007. srv_data_file_sizes[i] = srv_data_file_sizes[i]
  1008. * ((1024 * 1024) / UNIV_PAGE_SIZE);
  1009. }
  1010. srv_last_file_size_max = srv_last_file_size_max
  1011. * ((1024 * 1024) / UNIV_PAGE_SIZE);
  1012. srv_log_file_size = srv_log_file_size / UNIV_PAGE_SIZE;
  1013. srv_log_buffer_size = srv_log_buffer_size / UNIV_PAGE_SIZE;
  1014. srv_lock_table_size = 5 * (srv_buf_pool_size / UNIV_PAGE_SIZE);
  1015. return(DB_SUCCESS);
  1016. }
  1017. /*************************************************************************
  1018. Boots the InnoDB server. */
  1019. UNIV_INTERN
  1020. ulint
  1021. srv_boot(void)
  1022. /*==========*/
  1023. /* out: DB_SUCCESS or error code */
  1024. {
  1025. ulint err;
  1026. /* Transform the init parameter values given by MySQL to
  1027. use units we use inside InnoDB: */
  1028. err = srv_normalize_init_values();
  1029. if (err != DB_SUCCESS) {
  1030. return(err);
  1031. }
  1032. /* Initialize synchronization primitives, memory management, and thread
  1033. local storage */
  1034. srv_general_init();
  1035. /* Initialize this module */
  1036. srv_init();
  1037. return(DB_SUCCESS);
  1038. }
  1039. #ifndef UNIV_HOTBACKUP
  1040. /*************************************************************************
  1041. Reserves a slot in the thread table for the current MySQL OS thread.
  1042. NOTE! The kernel mutex has to be reserved by the caller! */
  1043. static
  1044. srv_slot_t*
  1045. srv_table_reserve_slot_for_mysql(void)
  1046. /*==================================*/
  1047. /* out: reserved slot */
  1048. {
  1049. srv_slot_t* slot;
  1050. ulint i;
  1051. ut_ad(mutex_own(&kernel_mutex));
  1052. i = 0;
  1053. slot = srv_mysql_table + i;
  1054. while (slot->in_use) {
  1055. i++;
  1056. if (i >= OS_THREAD_MAX_N) {
  1057. ut_print_timestamp(stderr);
  1058. fprintf(stderr,
  1059. " InnoDB: There appear to be %lu MySQL"
  1060. " threads currently waiting\n"
  1061. "InnoDB: inside InnoDB, which is the"
  1062. " upper limit. Cannot continue operation.\n"
  1063. "InnoDB: We intentionally generate"
  1064. " a seg fault to print a stack trace\n"
  1065. "InnoDB: on Linux. But first we print"
  1066. " a list of waiting threads.\n", (ulong) i);
  1067. for (i = 0; i < OS_THREAD_MAX_N; i++) {
  1068. slot = srv_mysql_table + i;
  1069. fprintf(stderr,
  1070. "Slot %lu: thread id %lu, type %lu,"
  1071. " in use %lu, susp %lu, time %lu\n",
  1072. (ulong) i,
  1073. (ulong) os_thread_pf(slot->id),
  1074. (ulong) slot->type,
  1075. (ulong) slot->in_use,
  1076. (ulong) slot->suspended,
  1077. (ulong) difftime(ut_time(),
  1078. slot->suspend_time));
  1079. }
  1080. ut_error;
  1081. }
  1082. slot = srv_mysql_table + i;
  1083. }
  1084. ut_a(slot->in_use == FALSE);
  1085. slot->in_use = TRUE;
  1086. slot->id = os_thread_get_curr_id();
  1087. slot->handle = os_thread_get_curr();
  1088. return(slot);
  1089. }
  1090. #endif /* !UNIV_HOTBACKUP */
  1091. /*******************************************************************
  1092. Puts a MySQL OS thread to wait for a lock to be released. If an error
  1093. occurs during the wait trx->error_state associated with thr is
  1094. != DB_SUCCESS when we return. DB_LOCK_WAIT_TIMEOUT and DB_DEADLOCK
  1095. are possible errors. DB_DEADLOCK is returned if selective deadlock
  1096. resolution chose this transaction as a victim. */
  1097. UNIV_INTERN
  1098. void
  1099. srv_suspend_mysql_thread(
  1100. /*=====================*/
  1101. que_thr_t* thr) /* in: query thread associated with the MySQL
  1102. OS thread */
  1103. {
  1104. #ifndef UNIV_HOTBACKUP
  1105. srv_slot_t* slot;
  1106. os_event_t event;
  1107. double wait_time;
  1108. trx_t* trx;
  1109. ulint had_dict_lock;
  1110. ibool was_declared_inside_innodb = FALSE;
  1111. ib_int64_t start_time = 0;
  1112. ib_int64_t finish_time;
  1113. ulint diff_time;
  1114. ulint sec;
  1115. ulint ms;
  1116. ulong lock_wait_timeout;
  1117. ut_ad(!mutex_own(&kernel_mutex));
  1118. trx = thr_get_trx(thr);
  1119. os_event_set(srv_lock_timeout_thread_event);
  1120. mutex_enter(&kernel_mutex);
  1121. trx->error_state = DB_SUCCESS;
  1122. if (thr->state == QUE_THR_RUNNING) {
  1123. ut_ad(thr->is_active == TRUE);
  1124. /* The lock has already been released or this transaction
  1125. was chosen as a deadlock victim: no need to suspend */
  1126. if (trx->was_chosen_as_deadlock_victim) {
  1127. trx->error_state = DB_DEADLOCK;
  1128. trx->was_chosen_as_deadlock_victim = FALSE;
  1129. }
  1130. mutex_exit(&kernel_mutex);
  1131. return;
  1132. }
  1133. ut_ad(thr->is_active == FALSE);
  1134. slot = srv_table_reserve_slot_for_mysql();
  1135. event = slot->event;
  1136. slot->thr = thr;
  1137. os_event_reset(event);
  1138. slot->suspend_time = ut_time();
  1139. if (thr->lock_state == QUE_THR_LOCK_ROW) {
  1140. srv_n_lock_wait_count++;
  1141. srv_n_lock_wait_current_count++;
  1142. if (ut_usectime(&sec, &ms) == -1) {
  1143. start_time = -1;
  1144. } else {
  1145. start_time = (ib_int64_t) sec * 1000000 + ms;
  1146. }
  1147. }
  1148. /* Wake the lock timeout monitor thread, if it is suspended */
  1149. os_event_set(srv_lock_timeout_thread_event);
  1150. mutex_exit(&kernel_mutex);
  1151. if (trx->declared_to_be_inside_innodb) {
  1152. was_declared_inside_innodb = TRUE;
  1153. /* We must declare this OS thread to exit InnoDB, since a
  1154. possible other thread holding a lock which this thread waits
  1155. for must be allowed to enter, sooner or later */
  1156. srv_conc_force_exit_innodb(trx);
  1157. }
  1158. had_dict_lock = trx->dict_operation_lock_mode;
  1159. switch (had_dict_lock) {
  1160. case RW_S_LATCH:
  1161. /* Release foreign key check latch */
  1162. row_mysql_unfreeze_data_dictionary(trx);
  1163. break;
  1164. case RW_X_LATCH:
  1165. /* Release fast index creation latch */
  1166. row_mysql_unlock_data_dictionary(trx);
  1167. break;
  1168. }
  1169. ut_a(trx->dict_operation_lock_mode == 0);
  1170. /* Suspend this thread and wait for the event. */
  1171. os_event_wait(event);
  1172. /* After resuming, reacquire the data dictionary latch if
  1173. necessary. */
  1174. switch (had_dict_lock) {
  1175. case RW_S_LATCH:
  1176. row_mysql_freeze_data_dictionary(trx);
  1177. break;
  1178. case RW_X_LATCH:
  1179. row_mysql_lock_data_dictionary(trx);
  1180. break;
  1181. }
  1182. if (was_declared_inside_innodb) {
  1183. /* Return back inside InnoDB */
  1184. srv_conc_force_enter_innodb(trx);
  1185. }
  1186. mutex_enter(&kernel_mutex);
  1187. /* Release the slot for others to use */
  1188. slot->in_use = FALSE;
  1189. wait_time = ut_difftime(ut_time(), slot->suspend_time);
  1190. if (thr->lock_state == QUE_THR_LOCK_ROW) {
  1191. if (ut_usectime(&sec, &ms) == -1) {
  1192. finish_time = -1;
  1193. } else {
  1194. finish_time = (ib_int64_t) sec * 1000000 + ms;
  1195. }
  1196. diff_time = (ulint) (finish_time - start_time);
  1197. srv_n_lock_wait_current_count--;
  1198. srv_n_lock_wait_time = srv_n_lock_wait_time + diff_time;
  1199. if (diff_time > srv_n_lock_max_wait_time &&
  1200. /* only update the variable if we successfully
  1201. retrieved the start and finish times. See Bug#36819. */
  1202. start_time != -1 && finish_time != -1) {
  1203. srv_n_lock_max_wait_time = diff_time;
  1204. }
  1205. }
  1206. if (trx->was_chosen_as_deadlock_victim) {
  1207. trx->error_state = DB_DEADLOCK;
  1208. trx->was_chosen_as_deadlock_victim = FALSE;
  1209. }
  1210. mutex_exit(&kernel_mutex);
  1211. /* InnoDB system transactions (such as the purge, and
  1212. incomplete transactions that are being rolled back after crash
  1213. recovery) will use the global value of
  1214. innodb_lock_wait_timeout, because trx->mysql_thd == NULL. */
  1215. lock_wait_timeout = thd_lock_wait_timeout(trx->mysql_thd);
  1216. if (lock_wait_timeout < 100000000
  1217. && wait_time > (double) lock_wait_timeout) {
  1218. trx->error_state = DB_LOCK_WAIT_TIMEOUT;
  1219. }
  1220. #else /* UNIV_HOTBACKUP */
  1221. /* This function depends on MySQL code that is not included in
  1222. InnoDB Hot Backup builds. Besides, this function should never
  1223. be called in InnoDB Hot Backup. */
  1224. ut_error;
  1225. #endif /* UNIV_HOTBACKUP */
  1226. }
  1227. /************************************************************************
  1228. Releases a MySQL OS thread waiting for a lock to be released, if the
  1229. thread is already suspended. */
  1230. UNIV_INTERN
  1231. void
  1232. srv_release_mysql_thread_if_suspended(
  1233. /*==================================*/
  1234. que_thr_t* thr) /* in: query thread associated with the
  1235. MySQL OS thread */
  1236. {
  1237. #ifndef UNIV_HOTBACKUP
  1238. srv_slot_t* slot;
  1239. ulint i;
  1240. ut_ad(mutex_own(&kernel_mutex));
  1241. for (i = 0; i < OS_THREAD_MAX_N; i++) {
  1242. slot = srv_mysql_table + i;
  1243. if (slot->in_use && slot->thr == thr) {
  1244. /* Found */
  1245. os_event_set(slot->event);
  1246. return;
  1247. }
  1248. }
  1249. /* not found */
  1250. #else /* UNIV_HOTBACKUP */
  1251. /* This function depends on MySQL code that is not included in
  1252. InnoDB Hot Backup builds. Besides, this function should never
  1253. be called in InnoDB Hot Backup. */
  1254. ut_error;
  1255. #endif /* UNIV_HOTBACKUP */
  1256. }
  1257. #ifndef UNIV_HOTBACKUP
  1258. /**********************************************************************
  1259. Refreshes the values used to calculate per-second averages. */
  1260. static
  1261. void
  1262. srv_refresh_innodb_monitor_stats(void)
  1263. /*==================================*/
  1264. {
  1265. mutex_enter(&srv_innodb_monitor_mutex);
  1266. srv_last_monitor_time = time(NULL);
  1267. os_aio_refresh_stats();
  1268. btr_cur_n_sea_old = btr_cur_n_sea;
  1269. btr_cur_n_non_sea_old = btr_cur_n_non_sea;
  1270. log_refresh_stats();
  1271. buf_refresh_io_stats();
  1272. srv_n_rows_inserted_old = srv_n_rows_inserted;
  1273. srv_n_rows_updated_old = srv_n_rows_updated;
  1274. srv_n_rows_deleted_old = srv_n_rows_deleted;
  1275. srv_n_rows_read_old = srv_n_rows_read;
  1276. mutex_exit(&srv_innodb_monitor_mutex);
  1277. }
  1278. /**********************************************************************
  1279. Outputs to a file the output of the InnoDB Monitor. */
  1280. UNIV_INTERN
  1281. void
  1282. srv_printf_innodb_monitor(
  1283. /*======================*/
  1284. FILE* file, /* in: output stream */
  1285. ulint* trx_start, /* out: file position of the start of
  1286. the list of active transactions */
  1287. ulint* trx_end) /* out: file position of the end of
  1288. the list of active transactions */
  1289. {
  1290. double time_elapsed;
  1291. time_t current_time;
  1292. ulint n_reserved;
  1293. mutex_enter(&srv_innodb_monitor_mutex);
  1294. current_time = time(NULL);
  1295. /* We add 0.001 seconds to time_elapsed to prevent division
  1296. by zero if two users happen to call SHOW INNODB STATUS at the same
  1297. time */
  1298. time_elapsed = difftime(current_time, srv_last_monitor_time)
  1299. + 0.001;
  1300. srv_last_monitor_time = time(NULL);
  1301. fputs("\n=====================================\n", file);
  1302. ut_print_timestamp(file);
  1303. fprintf(file,
  1304. " INNODB MONITOR OUTPUT\n"
  1305. "=====================================\n"
  1306. "Per second averages calculated from the last %lu seconds\n",
  1307. (ulong)time_elapsed);
  1308. fputs("----------\n"
  1309. "SEMAPHORES\n"
  1310. "----------\n", file);
  1311. sync_print(file);
  1312. /* Conceptually, srv_innodb_monitor_mutex has a very high latching
  1313. order level in sync0sync.h, while dict_foreign_err_mutex has a very
  1314. low level 135. Therefore we can reserve the latter mutex here without
  1315. a danger of a deadlock of threads. */
  1316. mutex_enter(&dict_foreign_err_mutex);
  1317. if (ftell(dict_foreign_err_file) != 0L) {
  1318. fputs("------------------------\n"
  1319. "LATEST FOREIGN KEY ERROR\n"
  1320. "------------------------\n", file);
  1321. ut_copy_file(file, dict_foreign_err_file);
  1322. }
  1323. mutex_exit(&dict_foreign_err_mutex);
  1324. lock_print_info_summary(file);
  1325. if (trx_start) {
  1326. long t = ftell(file);
  1327. if (t < 0) {
  1328. *trx_start = ULINT_UNDEFINED;
  1329. } else {
  1330. *trx_start = (ulint) t;
  1331. }
  1332. }
  1333. lock_print_info_all_transactions(file);
  1334. if (trx_end) {
  1335. long t = ftell(file);
  1336. if (t < 0) {
  1337. *trx_end = ULINT_UNDEFINED;
  1338. } else {
  1339. *trx_end = (ulint) t;
  1340. }
  1341. }
  1342. fputs("--------\n"
  1343. "FILE I/O\n"
  1344. "--------\n", file);
  1345. os_aio_print(file);
  1346. fputs("-------------------------------------\n"
  1347. "INSERT BUFFER AND ADAPTIVE HASH INDEX\n"
  1348. "-------------------------------------\n", file);
  1349. ibuf_print(file);
  1350. ha_print_info(file, btr_search_sys->hash_index);
  1351. fprintf(file,
  1352. "%.2f hash searches/s, %.2f non-hash searches/s\n",
  1353. (btr_cur_n_sea - btr_cur_n_sea_old)
  1354. / time_elapsed,
  1355. (btr_cur_n_non_sea - btr_cur_n_non_sea_old)
  1356. / time_elapsed);
  1357. btr_cur_n_sea_old = btr_cur_n_sea;
  1358. btr_cur_n_non_sea_old = btr_cur_n_non_sea;
  1359. fputs("---\n"
  1360. "LOG\n"
  1361. "---\n", file);
  1362. log_print(file);
  1363. fputs("----------------------\n"
  1364. "BUFFER POOL AND MEMORY\n"
  1365. "----------------------\n", file);
  1366. fprintf(file,
  1367. "Total memory allocated " ULINTPF
  1368. "; in additional pool allocated " ULINTPF "\n",
  1369. ut_total_allocated_memory,
  1370. mem_pool_get_reserved(mem_comm_pool));
  1371. fprintf(file, "Dictionary memory allocated " ULINTPF "\n",
  1372. dict_sys->size);
  1373. buf_print_io(file);
  1374. fputs("--------------\n"
  1375. "ROW OPERATIONS\n"
  1376. "--------------\n", file);
  1377. fprintf(file, "%ld queries inside InnoDB, %lu queries in queue\n",
  1378. (long) srv_conc_n_threads,
  1379. (ulong) srv_conc_n_waiting_threads);
  1380. fprintf(file, "%lu read views open inside InnoDB\n",
  1381. UT_LIST_GET_LEN(trx_sys->view_list));
  1382. n_reserved = fil_space_get_n_reserved_extents(0);
  1383. if (n_reserved > 0) {
  1384. fprintf(file,
  1385. "%lu tablespace extents now reserved for"
  1386. " B-tree split operations\n",
  1387. (ulong) n_reserved);
  1388. }
  1389. #ifdef UNIV_LINUX
  1390. fprintf(file, "Main thread process no. %lu, id %lu, state: %s\n",
  1391. (ulong) srv_main_thread_process_no,
  1392. (ulong) srv_main_thread_id,
  1393. srv_main_thread_op_info);
  1394. #else
  1395. fprintf(file, "Main thread id %lu, state: %s\n",
  1396. (ulong) srv_main_thread_id,
  1397. srv_main_thread_op_info);
  1398. #endif
  1399. fprintf(file,
  1400. "Number of rows inserted " ULINTPF
  1401. ", updated " ULINTPF ", deleted " ULINTPF
  1402. ", read " ULINTPF "\n",
  1403. srv_n_rows_inserted,
  1404. srv_n_rows_updated,
  1405. srv_n_rows_deleted,
  1406. srv_n_rows_read);
  1407. fprintf(file,
  1408. "%.2f inserts/s, %.2f updates/s,"
  1409. " %.2f deletes/s, %.2f reads/s\n",
  1410. (srv_n_rows_inserted - srv_n_rows_inserted_old)
  1411. / time_elapsed,
  1412. (srv_n_rows_updated - srv_n_rows_updated_old)
  1413. / time_elapsed,
  1414. (srv_n_rows_deleted - srv_n_rows_deleted_old)
  1415. / time_elapsed,
  1416. (srv_n_rows_read - srv_n_rows_read_old)
  1417. / time_elapsed);
  1418. srv_n_rows_inserted_old = srv_n_rows_inserted;
  1419. srv_n_rows_updated_old = srv_n_rows_updated;
  1420. srv_n_rows_deleted_old = srv_n_rows_deleted;
  1421. srv_n_rows_read_old = srv_n_rows_read;
  1422. fputs("----------------------------\n"
  1423. "END OF INNODB MONITOR OUTPUT\n"
  1424. "============================\n", file);
  1425. mutex_exit(&srv_innodb_monitor_mutex);
  1426. fflush(file);
  1427. }
  1428. /**********************************************************************
  1429. Function to pass InnoDB status variables to MySQL */
  1430. UNIV_INTERN
  1431. void
  1432. srv_export_innodb_status(void)
  1433. {
  1434. mutex_enter(&srv_innodb_monitor_mutex);
  1435. export_vars.innodb_data_pending_reads
  1436. = os_n_pending_reads;
  1437. export_vars.innodb_data_pending_writes
  1438. = os_n_pending_writes;
  1439. export_vars.innodb_data_pending_fsyncs
  1440. = fil_n_pending_log_flushes
  1441. + fil_n_pending_tablespace_flushes;
  1442. export_vars.innodb_data_fsyncs = os_n_fsyncs;
  1443. export_vars.innodb_data_read = srv_data_read;
  1444. export_vars.innodb_data_reads = os_n_file_reads;
  1445. export_vars.innodb_data_writes = os_n_file_writes;
  1446. export_vars.innodb_data_written = srv_data_written;
  1447. export_vars.innodb_buffer_pool_read_requests = buf_pool->n_page_gets;
  1448. export_vars.innodb_buffer_pool_write_requests
  1449. = srv_buf_pool_write_requests;
  1450. export_vars.innodb_buffer_pool_wait_free = srv_buf_pool_wait_free;
  1451. export_vars.innodb_buffer_pool_pages_flushed = srv_buf_pool_flushed;
  1452. export_vars.innodb_buffer_pool_reads = srv_buf_pool_reads;
  1453. export_vars.innodb_buffer_pool_read_ahead_rnd = srv_read_ahead_rnd;
  1454. export_vars.innodb_buffer_pool_read_ahead_seq = srv_read_ahead_seq;
  1455. export_vars.innodb_buffer_pool_pages_data
  1456. = UT_LIST_GET_LEN(buf_pool->LRU);
  1457. export_vars.innodb_buffer_pool_pages_dirty
  1458. = UT_LIST_GET_LEN(buf_pool->flush_list);
  1459. export_vars.innodb_buffer_pool_pages_free
  1460. = UT_LIST_GET_LEN(buf_pool->free);
  1461. #ifdef UNIV_DEBUG
  1462. export_vars.innodb_buffer_pool_pages_latched
  1463. = buf_get_latched_pages_number();
  1464. #endif /* UNIV_DEBUG */
  1465. export_vars.innodb_buffer_pool_pages_total = buf_pool->curr_size;
  1466. export_vars.innodb_buffer_pool_pages_misc = buf_pool->curr_size
  1467. - UT_LIST_GET_LEN(buf_pool->LRU)
  1468. - UT_LIST_GET_LEN(buf_pool->free);
  1469. #ifdef HAVE_GCC_ATOMIC_BUILTINS
  1470. export_vars.innodb_have_atomic_builtins = 1;
  1471. #else
  1472. export_vars.innodb_have_atomic_builtins = 0;
  1473. #endif
  1474. export_vars.innodb_page_size = UNIV_PAGE_SIZE;
  1475. export_vars.innodb_log_waits = srv_log_waits;
  1476. export_vars.innodb_os_log_written = srv_os_log_written;
  1477. export_vars.innodb_os_log_fsyncs = fil_n_log_flushes;
  1478. export_vars.innodb_os_log_pending_fsyncs = fil_n_pending_log_flushes;
  1479. export_vars.innodb_os_log_pending_writes = srv_os_log_pending_writes;
  1480. export_vars.innodb_log_write_requests = srv_log_write_requests;
  1481. export_vars.innodb_log_writes = srv_log_writes;
  1482. export_vars.innodb_dblwr_pages_written = srv_dblwr_pages_written;
  1483. export_vars.innodb_dblwr_writes = srv_dblwr_writes;
  1484. export_vars.innodb_pages_created = buf_pool->n_pages_created;
  1485. export_vars.innodb_pages_read = buf_pool->n_pages_read;
  1486. export_vars.innodb_pages_written = buf_pool->n_pages_written;
  1487. export_vars.innodb_row_lock_waits = srv_n_lock_wait_count;
  1488. export_vars.innodb_row_lock_current_waits
  1489. = srv_n_lock_wait_current_count;
  1490. export_vars.innodb_row_lock_time = srv_n_lock_wait_time / 1000;
  1491. if (srv_n_lock_wait_count > 0) {
  1492. export_vars.innodb_row_lock_time_avg = (ulint)
  1493. (srv_n_lock_wait_time / 1000 / srv_n_lock_wait_count);
  1494. } else {
  1495. export_vars.innodb_row_lock_time_avg = 0;
  1496. }
  1497. export_vars.innodb_row_lock_time_max
  1498. = srv_n_lock_max_wait_time / 1000;
  1499. export_vars.innodb_rows_read = srv_n_rows_read;
  1500. export_vars.innodb_rows_inserted = srv_n_rows_inserted;
  1501. export_vars.innodb_rows_updated = srv_n_rows_updated;
  1502. export_vars.innodb_rows_deleted = srv_n_rows_deleted;
  1503. mutex_exit(&srv_innodb_monitor_mutex);
  1504. }
  1505. /*************************************************************************
  1506. A thread which wakes up threads whose lock wait may have lasted too long.
  1507. This also prints the info output by various InnoDB monitors. */
  1508. UNIV_INTERN
  1509. os_thread_ret_t
  1510. srv_lock_timeout_and_monitor_thread(
  1511. /*================================*/
  1512. /* out: a dummy parameter */
  1513. void* arg __attribute__((unused)))
  1514. /* in: a dummy parameter required by
  1515. os_thread_create */
  1516. {
  1517. srv_slot_t* slot;
  1518. double time_elapsed;
  1519. time_t current_time;
  1520. time_t last_table_monitor_time;
  1521. time_t last_tablespace_monitor_time;
  1522. time_t last_monitor_time;
  1523. ibool some_waits;
  1524. double wait_time;
  1525. ulint i;
  1526. #ifdef UNIV_DEBUG_THREAD_CREATION
  1527. fprintf(stderr, "Lock timeout thread starts, id %lu\n",
  1528. os_thread_pf(os_thread_get_curr_id()));
  1529. #endif
  1530. UT_NOT_USED(arg);
  1531. srv_last_monitor_time = time(NULL);
  1532. last_table_monitor_time = time(NULL);
  1533. last_tablespace_monitor_time = time(NULL);
  1534. last_monitor_time = time(NULL);
  1535. loop:
  1536. srv_lock_timeout_and_monitor_active = TRUE;
  1537. /* When someone is waiting for a lock, we wake up every second
  1538. and check if a timeout has passed for a lock wait */
  1539. os_thread_sleep(1000000);
  1540. current_time = time(NULL);
  1541. time_elapsed = difftime(current_time, last_monitor_time);
  1542. if (time_elapsed > 15) {
  1543. last_monitor_time = time(NULL);
  1544. if (srv_print_innodb_monitor) {
  1545. srv_printf_innodb_monitor(stderr, NULL, NULL);
  1546. }
  1547. if (srv_innodb_status) {
  1548. mutex_enter(&srv_monitor_file_mutex);
  1549. rewind(srv_monitor_file);
  1550. srv_printf_innodb_monitor(srv_monitor_file, NULL,
  1551. NULL);
  1552. os_file_set_eof(srv_monitor_file);
  1553. mutex_exit(&srv_monitor_file_mutex);
  1554. }
  1555. if (srv_print_innodb_tablespace_monitor
  1556. && difftime(current_time,
  1557. last_tablespace_monitor_time) > 60) {
  1558. last_tablespace_monitor_time = time(NULL);
  1559. fputs("========================"
  1560. "========================\n",
  1561. stderr);
  1562. ut_print_timestamp(stderr);
  1563. fputs(" INNODB TABLESPACE MONITOR OUTPUT\n"
  1564. "========================"
  1565. "========================\n",
  1566. stderr);
  1567. fsp_print(0);
  1568. fputs("Validating tablespace\n", stderr);
  1569. fsp_validate(0);
  1570. fputs("Validation ok\n"
  1571. "---------------------------------------\n"
  1572. "END OF INNODB TABLESPACE MONITOR OUTPUT\n"
  1573. "=======================================\n",
  1574. stderr);
  1575. }
  1576. if (srv_print_innodb_table_monitor
  1577. && difftime(current_time, last_table_monitor_time) > 60) {
  1578. last_table_monitor_time = time(NULL);
  1579. fputs("===========================================\n",
  1580. stderr);
  1581. ut_print_timestamp(stderr);
  1582. fputs(" INNODB TABLE MONITOR OUTPUT\n"
  1583. "===========================================\n",
  1584. stderr);
  1585. dict_print();
  1586. fputs("-----------------------------------\n"
  1587. "END OF INNODB TABLE MONITOR OUTPUT\n"
  1588. "==================================\n",
  1589. stderr);
  1590. }
  1591. }
  1592. mutex_enter(&kernel_mutex);
  1593. some_waits = FALSE;
  1594. /* Check of all slots if a thread is waiting there, and if it
  1595. has exceeded the time limit */
  1596. for (i = 0; i < OS_THREAD_MAX_N; i++) {
  1597. slot = srv_mysql_table + i;
  1598. if (slot->in_use) {
  1599. trx_t* trx;
  1600. ulong lock_wait_timeout;
  1601. some_waits = TRUE;
  1602. wait_time = ut_difftime(ut_time(), slot->suspend_time);
  1603. trx = thr_get_trx(slot->thr);
  1604. lock_wait_timeout = thd_lock_wait_timeout(
  1605. trx->mysql_thd);
  1606. if (lock_wait_timeout < 100000000
  1607. && (wait_time > (double) lock_wait_timeout
  1608. || wait_time < 0)) {
  1609. /* Timeout exceeded or a wrap-around in system
  1610. time counter: cancel the lock request queued
  1611. by the transaction and release possible
  1612. other transactions waiting behind; it is
  1613. possible that the lock has already been
  1614. granted: in that case do nothing */
  1615. if (trx->wait_lock) {
  1616. lock_cancel_waiting_and_release(
  1617. trx->wait_lock);
  1618. }
  1619. }
  1620. }
  1621. }
  1622. os_event_reset(srv_lock_timeout_thread_event);
  1623. mutex_exit(&kernel_mutex);
  1624. if (srv_shutdown_state >= SRV_SHUTDOWN_CLEANUP) {
  1625. goto exit_func;
  1626. }
  1627. if (some_waits || srv_print_innodb_monitor
  1628. || srv_print_innodb_lock_monitor
  1629. || srv_print_innodb_tablespace_monitor
  1630. || srv_print_innodb_table_monitor) {
  1631. goto loop;
  1632. }
  1633. /* No one was waiting for a lock and no monitor was active:
  1634. suspend this thread */
  1635. srv_lock_timeout_and_monitor_active = FALSE;
  1636. #if 0
  1637. /* The following synchronisation is disabled, since
  1638. the InnoDB monitor output is to be updated every 15 seconds. */
  1639. os_event_wait(srv_lock_timeout_thread_event);
  1640. #endif
  1641. goto loop;
  1642. exit_func:
  1643. srv_lock_timeout_and_monitor_active = FALSE;
  1644. /* We count the number of threads in os_thread_exit(). A created
  1645. thread should always use that to exit and not use return() to exit. */
  1646. os_thread_exit(NULL);
  1647. OS_THREAD_DUMMY_RETURN;
  1648. }
  1649. /*************************************************************************
  1650. A thread which prints warnings about semaphore waits which have lasted
  1651. too long. These can be used to track bugs which cause hangs. */
  1652. UNIV_INTERN
  1653. os_thread_ret_t
  1654. srv_error_monitor_thread(
  1655. /*=====================*/
  1656. /* out: a dummy parameter */
  1657. void* arg __attribute__((unused)))
  1658. /* in: a dummy parameter required by
  1659. os_thread_create */
  1660. {
  1661. /* number of successive fatal timeouts observed */
  1662. ulint fatal_cnt = 0;
  1663. ib_uint64_t old_lsn;
  1664. ib_uint64_t new_lsn;
  1665. old_lsn = srv_start_lsn;
  1666. #ifdef UNIV_DEBUG_THREAD_CREATION
  1667. fprintf(stderr, "Error monitor thread starts, id %lu\n",
  1668. os_thread_pf(os_thread_get_curr_id()));
  1669. #endif
  1670. loop:
  1671. srv_error_monitor_active = TRUE;
  1672. /* Try to track a strange bug reported by Harald Fuchs and others,
  1673. where the lsn seems to decrease at times */
  1674. new_lsn = log_get_lsn();
  1675. if (new_lsn < old_lsn) {
  1676. ut_print_timestamp(stderr);
  1677. fprintf(stderr,
  1678. " InnoDB: Error: old log sequence number %llu"
  1679. " was greater\n"
  1680. "InnoDB: than the new log sequence number %llu!\n"
  1681. "InnoDB: Please submit a bug report"
  1682. " to http://bugs.mysql.com\n",
  1683. old_lsn, new_lsn);
  1684. }
  1685. old_lsn = new_lsn;
  1686. if (difftime(time(NULL), srv_last_monitor_time) > 60) {
  1687. /* We referesh InnoDB Monitor values so that averages are
  1688. printed from at most 60 last seconds */
  1689. srv_refresh_innodb_monitor_stats();
  1690. }
  1691. /* Update the statistics collected for deciding LRU
  1692. eviction policy. */
  1693. buf_LRU_stat_update();
  1694. /* In case mutex_exit is not a memory barrier, it is
  1695. theoretically possible some threads are left waiting though
  1696. the semaphore is already released. Wake up those threads: */
  1697. sync_arr_wake_threads_if_sema_free();
  1698. if (sync_array_print_long_waits()) {
  1699. fatal_cnt++;
  1700. if (fatal_cnt > 10) {
  1701. fprintf(stderr,
  1702. "InnoDB: Error: semaphore wait has lasted"
  1703. " > %lu seconds\n"
  1704. "InnoDB: We intentionally crash the server,"
  1705. " because it appears to be hung.\n",
  1706. (ulong) srv_fatal_semaphore_wait_threshold);
  1707. ut_error;
  1708. }
  1709. } else {
  1710. fatal_cnt = 0;
  1711. }
  1712. /* Flush stderr so that a database user gets the output
  1713. to possible MySQL error file */
  1714. fflush(stderr);
  1715. os_thread_sleep(1000000);
  1716. if (srv_shutdown_state < SRV_SHUTDOWN_CLEANUP) {
  1717. goto loop;
  1718. }
  1719. srv_error_monitor_active = FALSE;
  1720. /* We count the number of threads in os_thread_exit(). A created
  1721. thread should always use that to exit and not use return() to exit. */
  1722. os_thread_exit(NULL);
  1723. OS_THREAD_DUMMY_RETURN;
  1724. }
  1725. /***********************************************************************
  1726. Tells the InnoDB server that there has been activity in the database
  1727. and wakes up the master thread if it is suspended (not sleeping). Used
  1728. in the MySQL interface. Note that there is a small chance that the master
  1729. thread stays suspended (we do not protect our operation with the kernel
  1730. mutex, for performace reasons). */
  1731. UNIV_INTERN
  1732. void
  1733. srv_active_wake_master_thread(void)
  1734. /*===============================*/
  1735. {
  1736. srv_activity_count++;
  1737. if (srv_n_threads_active[SRV_MASTER] == 0) {
  1738. mutex_enter(&kernel_mutex);
  1739. srv_release_threads(SRV_MASTER, 1);
  1740. mutex_exit(&kernel_mutex);
  1741. }
  1742. }
  1743. /***********************************************************************
  1744. Wakes up the master thread if it is suspended or being suspended. */
  1745. UNIV_INTERN
  1746. void
  1747. srv_wake_master_thread(void)
  1748. /*========================*/
  1749. {
  1750. srv_activity_count++;
  1751. mutex_enter(&kernel_mutex);
  1752. srv_release_threads(SRV_MASTER, 1);
  1753. mutex_exit(&kernel_mutex);
  1754. }
  1755. /*************************************************************************
  1756. The master thread controlling the server. */
  1757. UNIV_INTERN
  1758. os_thread_ret_t
  1759. srv_master_thread(
  1760. /*==============*/
  1761. /* out: a dummy parameter */
  1762. void* arg __attribute__((unused)))
  1763. /* in: a dummy parameter required by
  1764. os_thread_create */
  1765. {
  1766. os_event_t event;
  1767. time_t last_flush_time;
  1768. time_t current_time;
  1769. ulint old_activity_count;
  1770. ulint n_pages_purged = 0;
  1771. ulint n_bytes_merged;
  1772. ulint n_pages_flushed;
  1773. ulint n_bytes_archived;
  1774. ulint n_tables_to_drop;
  1775. ulint n_ios;
  1776. ulint n_ios_old;
  1777. ulint n_ios_very_old;
  1778. ulint n_pend_ios;
  1779. ibool skip_sleep = FALSE;
  1780. ulint i;
  1781. #ifdef UNIV_DEBUG_THREAD_CREATION
  1782. fprintf(stderr, "Master thread starts, id %lu\n",
  1783. os_thread_pf(os_thread_get_curr_id()));
  1784. #endif
  1785. srv_main_thread_process_no = os_proc_get_number();
  1786. srv_main_thread_id = os_thread_pf(os_thread_get_curr_id());
  1787. srv_table_reserve_slot(SRV_MASTER);
  1788. mutex_enter(&kernel_mutex);
  1789. srv_n_threads_active[SRV_MASTER]++;
  1790. mutex_exit(&kernel_mutex);
  1791. loop:
  1792. /*****************************************************************/
  1793. /* ---- When there is database activity by users, we cycle in this
  1794. loop */
  1795. srv_main_thread_op_info = "reserving kernel mutex";
  1796. n_ios_very_old = log_sys->n_log_ios + buf_pool->n_pages_read
  1797. + buf_pool->n_pages_written;
  1798. mutex_enter(&kernel_mutex);
  1799. /* Store the user activity counter at the start of this loop */
  1800. old_activity_count = srv_activity_count;
  1801. mutex_exit(&kernel_mutex);
  1802. if (srv_force_recovery >= SRV_FORCE_NO_BACKGROUND) {
  1803. goto suspend_thread;
  1804. }
  1805. /* ---- We run the following loop approximately once per second
  1806. when there is database activity */
  1807. skip_sleep = FALSE;
  1808. for (i = 0; i < 10; i++) {
  1809. n_ios_old = log_sys->n_log_ios + buf_pool->n_pages_read
  1810. + buf_pool->n_pages_written;
  1811. srv_main_thread_op_info = "sleeping";
  1812. if (!skip_sleep) {
  1813. os_thread_sleep(1000000);
  1814. }
  1815. skip_sleep = FALSE;
  1816. /* ALTER TABLE in MySQL requires on Unix that the table handler
  1817. can drop tables lazily after there no longer are SELECT
  1818. queries to them. */
  1819. srv_main_thread_op_info = "doing background drop tables";
  1820. row_drop_tables_for_mysql_in_background();
  1821. srv_main_thread_op_info = "";
  1822. if (srv_fast_shutdown && srv_shutdown_state > 0) {
  1823. goto background_loop;
  1824. }
  1825. /* We flush the log once in a second even if no commit
  1826. is issued or the we have specified in my.cnf no flush
  1827. at transaction commit */
  1828. srv_main_thread_op_info = "flushing log";
  1829. log_buffer_flush_to_disk();
  1830. srv_main_thread_op_info = "making checkpoint";
  1831. log_free_check();
  1832. /* If there were less than 5 i/os during the
  1833. one second sleep, we assume that there is free
  1834. disk i/o capacity available, and it makes sense to
  1835. do an insert buffer merge. */
  1836. n_pend_ios = buf_get_n_pending_ios()
  1837. + log_sys->n_pending_writes;
  1838. n_ios = log_sys->n_log_ios + buf_pool->n_pages_read
  1839. + buf_pool->n_pages_written;
  1840. if (n_pend_ios < 3 && (n_ios - n_ios_old < 5)) {
  1841. srv_main_thread_op_info = "doing insert buffer merge";
  1842. ibuf_contract_for_n_pages(
  1843. TRUE, srv_insert_buffer_batch_size / 4);
  1844. srv_main_thread_op_info = "flushing log";
  1845. log_buffer_flush_to_disk();
  1846. }
  1847. if (UNIV_UNLIKELY(buf_get_modified_ratio_pct()
  1848. > srv_max_buf_pool_modified_pct)) {
  1849. /* Try to keep the number of modified pages in the
  1850. buffer pool under the limit wished by the user */
  1851. n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST, 100,
  1852. IB_ULONGLONG_MAX);
  1853. /* If we had to do the flush, it may have taken
  1854. even more than 1 second, and also, there may be more
  1855. to flush. Do not sleep 1 second during the next
  1856. iteration of this loop. */
  1857. skip_sleep = TRUE;
  1858. }
  1859. if (srv_activity_count == old_activity_count) {
  1860. /* There is no user activity at the moment, go to
  1861. the background loop */
  1862. goto background_loop;
  1863. }
  1864. }
  1865. /* ---- We perform the following code approximately once per
  1866. 10 seconds when there is database activity */
  1867. #ifdef MEM_PERIODIC_CHECK
  1868. /* Check magic numbers of every allocated mem block once in 10
  1869. seconds */
  1870. mem_validate_all_blocks();
  1871. #endif
  1872. /* If there were less than 200 i/os during the 10 second period,
  1873. we assume that there is free disk i/o capacity available, and it
  1874. makes sense to flush 100 pages. */
  1875. n_pend_ios = buf_get_n_pending_ios() + log_sys->n_pending_writes;
  1876. n_ios = log_sys->n_log_ios + buf_pool->n_pages_read
  1877. + buf_pool->n_pages_written;
  1878. if (n_pend_ios < 3 && (n_ios - n_ios_very_old < 200)) {
  1879. srv_main_thread_op_info = "flushing buffer pool pages";
  1880. buf_flush_batch(BUF_FLUSH_LIST, 100, IB_ULONGLONG_MAX);
  1881. srv_main_thread_op_info = "flushing log";
  1882. log_buffer_flush_to_disk();
  1883. }
  1884. /* We run a batch of insert buffer merge every 10 seconds,
  1885. even if the server were active */
  1886. srv_main_thread_op_info = "doing insert buffer merge";
  1887. ibuf_contract_for_n_pages(TRUE, srv_insert_buffer_batch_size / 4);
  1888. srv_main_thread_op_info = "flushing log";
  1889. log_buffer_flush_to_disk();
  1890. /* We run a full purge every 10 seconds, even if the server
  1891. were active */
  1892. last_flush_time = time(NULL);
  1893. do {
  1894. if (srv_fast_shutdown && srv_shutdown_state > 0) {
  1895. goto background_loop;
  1896. }
  1897. srv_main_thread_op_info = "purging";
  1898. n_pages_purged = trx_purge();
  1899. current_time = time(NULL);
  1900. if (difftime(current_time, last_flush_time) > 1) {
  1901. srv_main_thread_op_info = "flushing log";
  1902. log_buffer_flush_to_disk();
  1903. last_flush_time = current_time;
  1904. }
  1905. } while (n_pages_purged);
  1906. srv_main_thread_op_info = "flushing buffer pool pages";
  1907. /* Flush a few oldest pages to make a new checkpoint younger */
  1908. if (buf_get_modified_ratio_pct() > 70) {
  1909. /* If there are lots of modified pages in the buffer pool
  1910. (> 70 %), we assume we can afford reserving the disk(s) for
  1911. the time it requires to flush 100 pages */
  1912. n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST, 100,
  1913. IB_ULONGLONG_MAX);
  1914. } else {
  1915. /* Otherwise, we only flush a small number of pages so that
  1916. we do not unnecessarily use much disk i/o capacity from
  1917. other work */
  1918. n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST, 10,
  1919. IB_ULONGLONG_MAX);
  1920. }
  1921. srv_main_thread_op_info = "making checkpoint";
  1922. /* Make a new checkpoint about once in 10 seconds */
  1923. log_checkpoint(TRUE, FALSE);
  1924. srv_main_thread_op_info = "reserving kernel mutex";
  1925. mutex_enter(&kernel_mutex);
  1926. /* ---- When there is database activity, we jump from here back to
  1927. the start of loop */
  1928. if (srv_activity_count != old_activity_count) {
  1929. mutex_exit(&kernel_mutex);
  1930. goto loop;
  1931. }
  1932. mutex_exit(&kernel_mutex);
  1933. /* If the database is quiet, we enter the background loop */
  1934. /*****************************************************************/
  1935. background_loop:
  1936. /* ---- In this loop we run background operations when the server
  1937. is quiet from user activity. Also in the case of a shutdown, we
  1938. loop here, flushing the buffer pool to the data files. */
  1939. /* The server has been quiet for a while: start running background
  1940. operations */
  1941. srv_main_thread_op_info = "doing background drop tables";
  1942. n_tables_to_drop = row_drop_tables_for_mysql_in_background();
  1943. if (n_tables_to_drop > 0) {
  1944. /* Do not monopolize the CPU even if there are tables waiting
  1945. in the background drop queue. (It is essentially a bug if
  1946. MySQL tries to drop a table while there are still open handles
  1947. to it and we had to put it to the background drop queue.) */
  1948. os_thread_sleep(100000);
  1949. }
  1950. srv_main_thread_op_info = "purging";
  1951. /* Run a full purge */
  1952. last_flush_time = time(NULL);
  1953. do {
  1954. if (srv_fast_shutdown && srv_shutdown_state > 0) {
  1955. break;
  1956. }
  1957. srv_main_thread_op_info = "purging";
  1958. n_pages_purged = trx_purge();
  1959. current_time = time(NULL);
  1960. if (difftime(current_time, last_flush_time) > 1) {
  1961. srv_main_thread_op_info = "flushing log";
  1962. log_buffer_flush_to_disk();
  1963. last_flush_time = current_time;
  1964. }
  1965. } while (n_pages_purged);
  1966. srv_main_thread_op_info = "reserving kernel mutex";
  1967. mutex_enter(&kernel_mutex);
  1968. if (srv_activity_count != old_activity_count) {
  1969. mutex_exit(&kernel_mutex);
  1970. goto loop;
  1971. }
  1972. mutex_exit(&kernel_mutex);
  1973. srv_main_thread_op_info = "doing insert buffer merge";
  1974. if (srv_fast_shutdown && srv_shutdown_state > 0) {
  1975. n_bytes_merged = 0;
  1976. } else {
  1977. n_bytes_merged = ibuf_contract_for_n_pages(
  1978. TRUE, srv_insert_buffer_batch_size);
  1979. }
  1980. srv_main_thread_op_info = "reserving kernel mutex";
  1981. mutex_enter(&kernel_mutex);
  1982. if (srv_activity_count != old_activity_count) {
  1983. mutex_exit(&kernel_mutex);
  1984. goto loop;
  1985. }
  1986. mutex_exit(&kernel_mutex);
  1987. flush_loop:
  1988. srv_main_thread_op_info = "flushing buffer pool pages";
  1989. if (srv_fast_shutdown < 2) {
  1990. n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST, 100,
  1991. IB_ULONGLONG_MAX);
  1992. } else {
  1993. /* In the fastest shutdown we do not flush the buffer pool
  1994. to data files: we set n_pages_flushed to 0 artificially. */
  1995. n_pages_flushed = 0;
  1996. }
  1997. srv_main_thread_op_info = "reserving kernel mutex";
  1998. mutex_enter(&kernel_mutex);
  1999. if (srv_activity_count != old_activity_count) {
  2000. mutex_exit(&kernel_mutex);
  2001. goto loop;
  2002. }
  2003. mutex_exit(&kernel_mutex);
  2004. srv_main_thread_op_info = "waiting for buffer pool flush to end";
  2005. buf_flush_wait_batch_end(BUF_FLUSH_LIST);
  2006. srv_main_thread_op_info = "flushing log";
  2007. log_buffer_flush_to_disk();
  2008. srv_main_thread_op_info = "making checkpoint";
  2009. log_checkpoint(TRUE, FALSE);
  2010. if (buf_get_modified_ratio_pct() > srv_max_buf_pool_modified_pct) {
  2011. /* Try to keep the number of modified pages in the
  2012. buffer pool under the limit wished by the user */
  2013. goto flush_loop;
  2014. }
  2015. srv_main_thread_op_info = "reserving kernel mutex";
  2016. mutex_enter(&kernel_mutex);
  2017. if (srv_activity_count != old_activity_count) {
  2018. mutex_exit(&kernel_mutex);
  2019. goto loop;
  2020. }
  2021. mutex_exit(&kernel_mutex);
  2022. /*
  2023. srv_main_thread_op_info = "archiving log (if log archive is on)";
  2024. log_archive_do(FALSE, &n_bytes_archived);
  2025. */
  2026. n_bytes_archived = 0;
  2027. /* Keep looping in the background loop if still work to do */
  2028. if (srv_fast_shutdown && srv_shutdown_state > 0) {
  2029. if (n_tables_to_drop + n_pages_flushed
  2030. + n_bytes_archived != 0) {
  2031. /* If we are doing a fast shutdown (= the default)
  2032. we do not do purge or insert buffer merge. But we
  2033. flush the buffer pool completely to disk.
  2034. In a 'very fast' shutdown we do not flush the buffer
  2035. pool to data files: we have set n_pages_flushed to
  2036. 0 artificially. */
  2037. goto background_loop;
  2038. }
  2039. } else if (n_tables_to_drop
  2040. + n_pages_purged + n_bytes_merged + n_pages_flushed
  2041. + n_bytes_archived != 0) {
  2042. /* In a 'slow' shutdown we run purge and the insert buffer
  2043. merge to completion */
  2044. goto background_loop;
  2045. }
  2046. /* There is no work for background operations either: suspend
  2047. master thread to wait for more server activity */
  2048. suspend_thread:
  2049. srv_main_thread_op_info = "suspending";
  2050. mutex_enter(&kernel_mutex);
  2051. if (row_get_background_drop_list_len_low() > 0) {
  2052. mutex_exit(&kernel_mutex);
  2053. goto loop;
  2054. }
  2055. event = srv_suspend_thread();
  2056. mutex_exit(&kernel_mutex);
  2057. /* DO NOT CHANGE THIS STRING. innobase_start_or_create_for_mysql()
  2058. waits for database activity to die down when converting < 4.1.x
  2059. databases, and relies on this string being exactly as it is. InnoDB
  2060. manual also mentions this string in several places. */
  2061. srv_main_thread_op_info = "waiting for server activity";
  2062. os_event_wait(event);
  2063. if (srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS) {
  2064. /* This is only extra safety, the thread should exit
  2065. already when the event wait ends */
  2066. os_thread_exit(NULL);
  2067. }
  2068. /* When there is user activity, InnoDB will set the event and the
  2069. main thread goes back to loop. */
  2070. goto loop;
  2071. OS_THREAD_DUMMY_RETURN; /* Not reached, avoid compiler warning */
  2072. }
  2073. #endif /* !UNIV_HOTBACKUP */