mirror of
https://github.com/MariaDB/server.git
synced 2025-02-01 11:31:51 +01:00
37312683cc
------------------------------------------------------------------------ r5971 | marko | 2009-09-23 23:03:51 +1000 (Wed, 23 Sep 2009) | 2 lines branches/zip: os_file_pwrite(): Make the code compile in InnoDB Hot Backup when the pwrite system call is not available. ------------------------------------------------------------------------ r5972 | marko | 2009-09-24 05:44:52 +1000 (Thu, 24 Sep 2009) | 5 lines branches/zip: fil_node_open_file(): In InnoDB Hot Backup, determine the page size of single-file tablespaces before computing the file node size. Otherwise, the space->size of compressed tablespaces would be computed with UNIV_PAGE_SIZE instead of key_block_size. This should fix Issue #313. ------------------------------------------------------------------------ r5973 | marko | 2009-09-24 05:53:21 +1000 (Thu, 24 Sep 2009) | 2 lines branches/zip: recv_add_to_hash_table(): Simplify obfuscated pointer arithmetics. ------------------------------------------------------------------------ r5978 | marko | 2009-09-24 17:47:56 +1000 (Thu, 24 Sep 2009) | 1 line branches/zip: Fix warnings and errors when UNIV_HOTBACKUP is defined. ------------------------------------------------------------------------ r5979 | marko | 2009-09-24 20:16:10 +1000 (Thu, 24 Sep 2009) | 4 lines branches/zip: ha_innodb.cc: Define MYSQL_PLUGIN_IMPORT when necessary. This preprocessor symbol has been recently introduced in MySQL 5.1. The InnoDB Plugin should remain source compatible with MySQL 5.1.24 and later. ------------------------------------------------------------------------ r5988 | calvin | 2009-09-26 05:14:43 +1000 (Sat, 26 Sep 2009) | 8 lines branches/zip: fix bug#47055 unconditional exit(1) on ERROR_WORKING_SET_QUOTA 1453 (0x5AD) for InnoDB backend When error ERROR_WORKING_SET_QUOTA or ERROR_NO_SYSTEM_RESOURCES occurs, yields for 100ms and retries the operation. Approved by: Heikki (on IM) ------------------------------------------------------------------------ r5992 | vasil | 2009-09-28 17:10:29 +1000 (Mon, 28 Sep 2009) | 4 lines branches/zip: Add ChangeLog entry for c5988. ------------------------------------------------------------------------ r5994 | marko | 2009-09-28 18:33:59 +1000 (Mon, 28 Sep 2009) | 17 lines branches/zip: Try to prevent the reuse of tablespace identifiers after InnoDB has crashed during table creation. Also, refuse to start if files with duplicate tablespace identifiers are encountered. fil_node_create(): Update fil_system->max_assigned_id. This should prevent the reuse of a space->id when InnoDB does a full crash recovery and invokes fil_load_single_table_tablespaces(). Normally, fil_system->max_assigned_id is initialized from SELECT MAX(ID) FROM SYS_TABLES. fil_open_single_table_tablespace(): Return FALSE when fil_space_create() fails. fil_load_single_table_tablespace(): Exit if fil_space_create() fails and innodb_force_recovery=0. rb://173 approved by Heikki Tuuri. This addresses Issue #335. ------------------------------------------------------------------------ r5995 | marko | 2009-09-28 18:52:25 +1000 (Mon, 28 Sep 2009) | 17 lines branches/zip: Do not write to PAGE_INDEX_ID after page creation, not even when restoring an uncompressed page after a compression failure. btr_page_reorganize_low(): On compression failure, do not restore those page header fields that should not be affected by the reorganization. Instead, compare the fields. page_zip_decompress(): Add the parameter ibool all, for copying all page header fields. Pass the parameter all=TRUE on block read completion, redo log application, and page_zip_validate(); pass all=FALSE in all other cases. page_zip_reorganize(): Do not restore the uncompressed page on failure. It will be restored (to pre-modification state) by the caller anyway. rb://167, Issue #346 ------------------------------------------------------------------------ r5996 | marko | 2009-09-28 22:46:02 +1000 (Mon, 28 Sep 2009) | 4 lines branches/zip: Address Issue #350 in comments. lock_rec_queue_validate(), lock_rec_queue_validate(): Note that this debug code may violate the latching order and cause deadlocks. ------------------------------------------------------------------------ r5997 | marko | 2009-09-28 23:03:58 +1000 (Mon, 28 Sep 2009) | 12 lines branches/zip: Remove an assertion failure when the InnoDB data dictionary is inconsistent with the MySQL .frm file. ha_innobase::index_read(): When the index cannot be found, return an error. ha_innobase::change_active_index(): When prebuilt->index == NULL, set also prebuilt->index_usable = FALSE. This is not needed for correctness, because prebuilt->index_usable is only checked by row_search_for_mysql(), which requires prebuilt->index != NULL. This addresses Issue #349. Approved by Heikki Tuuri over IM. ------------------------------------------------------------------------ r6005 | vasil | 2009-09-29 18:09:52 +1000 (Tue, 29 Sep 2009) | 4 lines branches/zip: ChangeLog: wrap around 78th column, not earlier. ------------------------------------------------------------------------ r6006 | vasil | 2009-09-29 20:15:25 +1000 (Tue, 29 Sep 2009) | 4 lines branches/zip: Add ChangeLog entry for the release of 1.0.4. ------------------------------------------------------------------------ r6007 | vasil | 2009-09-29 23:19:59 +1000 (Tue, 29 Sep 2009) | 6 lines branches/zip: Fix the year, should be 2009. Pointed by: Calvin ------------------------------------------------------------------------ r6026 | marko | 2009-09-30 17:18:24 +1000 (Wed, 30 Sep 2009) | 1 line branches/zip: Add some debug assertions for checking FSEG_MAGIC_N. ------------------------------------------------------------------------ r6028 | marko | 2009-09-30 23:55:23 +1000 (Wed, 30 Sep 2009) | 3 lines branches/zip: recv_no_log_write: New debug flag for tracking down Mantis Issue #347. No modifications should be made to the database while recv_apply_hashed_log_recs() is about to complete. ------------------------------------------------------------------------ r6029 | calvin | 2009-10-01 06:32:02 +1000 (Thu, 01 Oct 2009) | 4 lines branches/zip: non-functional changes Fix typo. ------------------------------------------------------------------------ r6031 | marko | 2009-10-01 21:24:33 +1000 (Thu, 01 Oct 2009) | 49 lines branches/zip: Clean up after a crash during DROP INDEX. When InnoDB crashes while dropping an index, ensure that the index will be completely dropped during crash recovery. row_merge_drop_index(): Before dropping an index, rename the index to start with TEMP_INDEX_PREFIX_STR and commit the change, so that row_merge_drop_temp_indexes() will drop the index after crash recovery if the server crashes while dropping the index. fseg_inode_try_get(): New function, forked from fseg_inode_get(). Return NULL if the file segment index node is free. fseg_inode_get(): Assert that the file segment index node is not free. fseg_free_step(): If the file segment index node is already free, print a diagnostic message and return TRUE. fsp_free_seg_inode(): Write a nonzero number to FSEG_MAGIC_N, so that allocated-and-freed file segment index nodes can be better distinguished from uninitialized ones. This is rb://174, addressing Issue #348. Tested by restarting mysqld upon the completion of the added log_write_up_to() invocation below, during DROP INDEX. The index was dropped after crash recovery, and re-issuing the DROP INDEX did not crash the server. Index: btr/btr0btr.c =================================================================== --- btr/btr0btr.c (revision 6026) +++ btr/btr0btr.c (working copy) @@ -42,6 +42,7 @@ Created 6/2/1994 Heikki Tuuri #include "ibuf0ibuf.h" #include "trx0trx.h" +#include "log0log.h" /* Latching strategy of the InnoDB B-tree -------------------------------------- @@ -873,6 +874,8 @@ leaf_loop: goto leaf_loop; } + + log_write_up_to(mtr.end_lsn, LOG_WAIT_ALL_GROUPS, TRUE); top_loop: mtr_start(&mtr); ------------------------------------------------------------------------ r6033 | calvin | 2009-10-02 06:19:46 +1000 (Fri, 02 Oct 2009) | 4 lines branches/zip: fix a typo in error message Reported as bug#47763. ------------------------------------------------------------------------ r6043 | inaam | 2009-10-06 01:45:35 +1100 (Tue, 06 Oct 2009) | 12 lines branches/zip rb://176 Do not invalidate buffer pool while an LRU batch is active. Added code to buf_pool_invalidate() to wait for the running batches to finish. This patch also resets the state of buf_pool struct at invalidation. This addresses the concern where buf_pool->freed_page_clock becomes non-zero because we read in a system tablespace page for file format info at startup. Approved by: Marko ------------------------------------------------------------------------ r6044 | pekka | 2009-10-07 01:44:54 +1100 (Wed, 07 Oct 2009) | 5 lines branches/zip: Add os_file_is_same() function for Hot Backup (inside ifdef UNIV_HOTBACKUP). This is part of the fix for Issue #186. Note! The Windows implementation is incomplete. ------------------------------------------------------------------------ r6046 | pekka | 2009-10-08 20:24:56 +1100 (Thu, 08 Oct 2009) | 3 lines branches/zip: Revert r6044 which added os_file_is_same() function (issue#186). This functionality is moved to Hot Backup source tree. ------------------------------------------------------------------------ r6048 | vasil | 2009-10-09 16:42:55 +1100 (Fri, 09 Oct 2009) | 16 lines branches/zip: When scanning a directory readdir() is called and stat() after it, if a file is deleted between the two calls stat will fail and the whole precedure will fail. Change this behavior to continue with the next entry if stat() fails because of nonexistent file. This is transparent change as it will make it look as if the file was deleted before the readdir() call. This change is needed in order to fix https://svn.innodb.com/mantis/view.php?id=174 in which we need to abort if os_file_readdir_next_file() encounters "real" errors. Approved by: Marko, Pekka (rb://177) ------------------------------------------------------------------------ r6049 | vasil | 2009-10-10 03:05:26 +1100 (Sat, 10 Oct 2009) | 7 lines branches/zip: Fix compilation warning in Hot Backup: innodb/fil/fil0fil.c: In function 'fil_load_single_table_tablespace': innodb/fil/fil0fil.c:3253: warning: format '%lld' expects type 'long long int', but argument 6 has type 'ib_int64_t' ------------------------------------------------------------------------ r6064 | calvin | 2009-10-14 02:23:35 +1100 (Wed, 14 Oct 2009) | 4 lines branches/zip: non-functional changes Changes from MySQL to fix build issue. ------------------------------------------------------------------------ r6065 | inaam | 2009-10-14 04:43:13 +1100 (Wed, 14 Oct 2009) | 7 lines branches/zip rb://182 Call fsync() on datafiles after a batch of pages is written to disk even when skip_innodb_doublewrite is set. Approved by: Heikki ------------------------------------------------------------------------ r6080 | sunny | 2009-10-15 09:29:01 +1100 (Thu, 15 Oct 2009) | 3 lines branches/zip: Change page_mem_alloc_free() to inline. Fix Bug #47058 - Failure to compile innodb_plugin on solaris 10u7 + spro cc/CC 5.10 ------------------------------------------------------------------------ r6084 | vasil | 2009-10-15 16:21:17 +1100 (Thu, 15 Oct 2009) | 4 lines branches/zip: Add ChangeLog entry for r6080. ------------------------------------------------------------------------ r6095 | vasil | 2009-10-20 00:04:59 +1100 (Tue, 20 Oct 2009) | 7 lines branches/zip: Fix Bug#47808 innodb_information_schema.test fails when run under valgrind by using the wait_until_rows_count macro that loops until the number of rows becomes 14 instead of sleep 0.1, which is obviously very fragile. ------------------------------------------------------------------------ r6096 | vasil | 2009-10-20 00:06:09 +1100 (Tue, 20 Oct 2009) | 4 lines branches/zip: Add ChangeLog entry for r6095. ------------------------------------------------------------------------ r6099 | jyang | 2009-10-22 13:58:39 +1100 (Thu, 22 Oct 2009) | 7 lines branches/zip: Port bug #46000 related changes from 5.1 to zip branch. Due to different code path for creating index in zip branch comparing to 5.1), the index reserved name check function is extended to be used in ha_innobase::add_index(). rb://190 Approved by: Marko ------------------------------------------------------------------------ r6100 | jyang | 2009-10-22 14:51:07 +1100 (Thu, 22 Oct 2009) | 6 lines branches/zip: As a request from mysql, WARN_LEVEL_ERROR cannot be used for push_warning_* call any more. Switch to WARN_LEVEL_WARN. Bug #47233. rb://172 approved by Sunny Bains and Marko. ------------------------------------------------------------------------ r6101 | jyang | 2009-10-23 19:45:50 +1100 (Fri, 23 Oct 2009) | 7 lines branches/zip: Update test result with the WARN_LEVEL_ERROR to WARN_LEVEL_WARN change. This is the same result as submitted in rb://172 review, which approved by Sunny Bains and Marko. ------------------------------------------------------------------------ r6102 | marko | 2009-10-26 18:32:23 +1100 (Mon, 26 Oct 2009) | 1 line branches/zip: row_prebuilt_struct::prebuilts: Unused field, remove. ------------------------------------------------------------------------ r6103 | marko | 2009-10-27 00:46:18 +1100 (Tue, 27 Oct 2009) | 4 lines branches/zip: row_ins_alloc_sys_fields(): Zero out the system columns DB_TRX_ID, DB_ROLL_PTR and DB_ROW_ID, in order to avoid harmless Valgrind warnings about uninitialized data. (The warnings were harmless, because the fields would be initialized at a later stage.) ------------------------------------------------------------------------ r6105 | calvin | 2009-10-28 09:05:52 +1100 (Wed, 28 Oct 2009) | 6 lines branches/zip: backport r3848 from 6.0 branch ---- branches/6.0: innobase_start_or_create_for_mysql(): Make the 10 MB minimum tablespace limit independent of UNIV_PAGE_SIZE. (Bug #41490) ------------------------------------------------------------------------ r6107 | marko | 2009-10-29 01:10:34 +1100 (Thu, 29 Oct 2009) | 5 lines branches/zip: buf_page_set_old(): Improve UNIV_LRU_DEBUG diagnostics in order to catch the buf_pool->LRU_old corruption reported in Issue #381. buf_LRU_old_init(): Set the property from the tail towards the front of the buf_pool->LRU list, in order not to trip the debug check. ------------------------------------------------------------------------ r6108 | calvin | 2009-10-29 16:58:04 +1100 (Thu, 29 Oct 2009) | 5 lines branches/zip: close file handle when building with UNIV_HOTBACKUP The change does not affect regular InnoDB engine. Confirmed by Marko. ------------------------------------------------------------------------ r6109 | jyang | 2009-10-29 19:37:32 +1100 (Thu, 29 Oct 2009) | 7 lines branches/zip: In os_mem_alloc_large(), if we fail to attach the shared memory, reset memory pointer ptr to NULL, and allocate memory from conventional pool. Bug #48237 Error handling in os_mem_alloc_large appears to be incorrect rb://198 Approved by: Marko ------------------------------------------------------------------------ r6110 | marko | 2009-10-29 21:44:57 +1100 (Thu, 29 Oct 2009) | 2 lines branches/zip: Makefile.am (INCLUDES): Merge a change from MySQL: Use $(srcdir)/include instead of $(top_srcdir)/storage/innobase/include. ------------------------------------------------------------------------ r6111 | marko | 2009-10-29 22:04:11 +1100 (Thu, 29 Oct 2009) | 33 lines branches/zip: Fix corruption of buf_pool->LRU_old and improve debug assertions. This was reported as Issue #381. buf_page_set_old(): Assert that blocks may only be set old if buf_pool->LRU_old is initialized and buf_pool->LRU_old_len is nonzero. Assert that buf_pool->LRU_old points to the block at the old/new boundary. buf_LRU_old_adjust_len(): Invoke buf_page_set_old() after adjusting buf_pool->LRU_old and buf_pool->LRU_old_len, in order not to violate the added assertions. buf_LRU_old_init(): Replace buf_page_set_old() with a direct assignment to bpage->old, because these loops that initialize all the blocks would temporarily violate the assertions about buf_pool->LRU_old. buf_LRU_remove_block(): When setting buf_pool->LRU_old = NULL, also clear all bpage->old flags and set buf_pool->LRU_old_len = 0. buf_LRU_add_block_to_end_low(), buf_LRU_add_block_low(): Move the buf_page_set_old() call later in order not to violate the debug assertions. If buf_pool->LRU_old is NULL, set old=FALSE. buf_LRU_free_block(): Replace the UNIV_LRU_DEBUG assertion with a dummy buf_page_set_old() call that performs more thorough checks. buf_LRU_validate(): Do not tolerate garbage in buf_pool->LRU_old_len even if buf_pool->LRU_old is NULL. Check that bpage->old is monotonic. buf_relocate(): Make the UNIV_LRU_DEBUG checks stricter. buf0buf.h: Revise the documentation of buf_page_t::old and buf_pool_t::LRU_old_len. ------------------------------------------------------------------------ r6112 | calvin | 2009-10-30 01:21:15 +1100 (Fri, 30 Oct 2009) | 4 lines branches/zip: consideration for icc compilers Proposed by MySQL, and approved by Marko. ------------------------------------------------------------------------ r6113 | vasil | 2009-10-30 03:15:50 +1100 (Fri, 30 Oct 2009) | 93 lines branches/zip: Merge r5912:6112 from branches/5.1: (after this merge the innodb-autoinc test starts to fail, but I commit anyway because it would be easier to investigate the failure this way) ------------------------------------------------------------------------ r5952 | calvin | 2009-09-22 19:45:07 +0300 (Tue, 22 Sep 2009) | 7 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: fix bug#42383: Can't create table 'test.bug39438' For embedded server, MySQL may pass in full path, which is currently disallowed. It is needed to relax the condition by accepting full paths in the embedded case. Approved by: Heikki (on IM) ------------------------------------------------------------------------ r6032 | vasil | 2009-10-01 15:55:49 +0300 (Thu, 01 Oct 2009) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Fix Bug#38996 Race condition in ANALYZE TABLE by serializing ANALYZE TABLE inside InnoDB. Approved by: Heikki (rb://175) ------------------------------------------------------------------------ r6045 | jyang | 2009-10-08 02:27:08 +0300 (Thu, 08 Oct 2009) | 7 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug47777.result A /branches/5.1/mysql-test/innodb_bug47777.test branches/5.1: Fix bug #47777. Treat the Geometry data same as Binary BLOB in ha_innobase::store_key_val_for_row(), since the Geometry data is stored as Binary BLOB in Innodb. Review: rb://180 approved by Marko Makela. ------------------------------------------------------------------------ r6051 | sunny | 2009-10-12 07:05:00 +0300 (Mon, 12 Oct 2009) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test branches/5.1: Ignore negative values supplied by the user when calculating the next value to store in dict_table_t. Setting autoincrement columns top negative values is undefined behavior and this change should bring the behavior of InnoDB closer to what users expect. Added several tests to check. rb://162 ------------------------------------------------------------------------ r6052 | sunny | 2009-10-12 07:09:56 +0300 (Mon, 12 Oct 2009) | 4 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test branches/5.1: Reset the statement level autoinc counter on ROLLBACK. Fix the test results too. rb://164 ------------------------------------------------------------------------ r6053 | sunny | 2009-10-12 07:37:49 +0300 (Mon, 12 Oct 2009) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test branches/5.1: Copy the maximum AUTOINC value from the old table to the new table when MySQL does a CREATE INDEX ON T. This is required because MySQL does a table copy, rename and drops the old table. Fix Bug#47125: auto_increment start value is ignored if an index is created and engine=innodb rb://168 ------------------------------------------------------------------------ r6076 | vasil | 2009-10-14 19:30:12 +0300 (Wed, 14 Oct 2009) | 4 lines Changed paths: M /branches/5.1/row/row0mysql.c branches/5.1: Fix typo. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r6114 | vasil | 2009-10-30 03:43:51 +1100 (Fri, 30 Oct 2009) | 6 lines branches/zip: * Add ChangeLog entries for latest changes * Obey alphabetical order in the list of the files * White-space fixup ------------------------------------------------------------------------ r6121 | sunny | 2009-10-30 10:42:11 +1100 (Fri, 30 Oct 2009) | 7 lines branches/zip: This test has been problematic for sometime now. The underlying bug is that the data dictionaries get out of sync. In the AUTOINC code we try and apply salve to the symptoms. In the past MySQL made some unrelated change and the dictionaries stopped getting out of sync and this test started to fail. Now, it seems they have reverted that changed and the test is passing again. I suspect this is not he last time that this test will change. ------------------------------------------------------------------------ r6124 | jyang | 2009-10-30 19:02:31 +1100 (Fri, 30 Oct 2009) | 5 lines branches/zip: Correct the bug number for -r6109 change from # 48273 to #48237 ------------------------------------------------------------------------ r6126 | vasil | 2009-10-30 19:36:07 +1100 (Fri, 30 Oct 2009) | 45 lines branches/zip: Merge r6112:6125 from branches/5.1: (skipping r6122 and r6123, Jimmy says these are already present and need not be merged): ------------------------------------------------------------------------ r6122 | jyang | 2009-10-30 05:18:38 +0200 (Fri, 30 Oct 2009) | 7 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/mysql-test/innodb_bug44369.result M /branches/5.1/mysql-test/innodb_bug44369.test M /branches/5.1/mysql-test/innodb_bug46000.result M /branches/5.1/mysql-test/innodb_bug46000.test branches/5.1: Chnage WARN_LEVEL_ERROR to WARN_LEVEL_WARN for push_warning_printf() call in innodb. Fix Bug#47233: Innodb calls push_warning(MYSQL_ERROR::WARN_LEVEL_ERROR) rb://170 approved by Marko. ------------------------------------------------------------------------ r6123 | jyang | 2009-10-30 05:43:06 +0200 (Fri, 30 Oct 2009) | 8 lines Changed paths: M /branches/5.1/os/os0proc.c branches/5.1: In os_mem_alloc_large(), if we fail to attach the shared memory, reset memory pointer ptr to NULL, and allocate memory from conventional pool. This is a port from branches/zip. Bug #48237 Error handling in os_mem_alloc_large appears to be incorrect rb://198 Approved by: Marko ------------------------------------------------------------------------ r6125 | vasil | 2009-10-30 10:31:23 +0200 (Fri, 30 Oct 2009) | 4 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: White-space fixup. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r6130 | marko | 2009-11-02 20:42:56 +1100 (Mon, 02 Nov 2009) | 9 lines branches/zip: Free all resources at shutdown. Set pointers to NULL, so that Valgrind will not complain about freed data structures that are reachable via pointers. This addresses Bug #45992 and Bug #46656. This patch is mostly based on changes copied from branches/embedded-1.0, mainly c5432, c3439, c3134, c2994, c2978, but also some other code was copied. Some added cleanup code is specific to MySQL/InnoDB. rb://199 approved by Sunny Bains ------------------------------------------------------------------------
1022 lines
26 KiB
C
1022 lines
26 KiB
C
/*****************************************************************************
|
|
|
|
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
|
|
Copyright (c) 2008, Google Inc.
|
|
|
|
Portions of this file contain modifications contributed and copyrighted by
|
|
Google, Inc. Those modifications are gratefully acknowledged and are described
|
|
briefly in the InnoDB documentation. The contributions by Google are
|
|
incorporated with their permission, and subject to the conditions contained in
|
|
the file COPYING.Google.
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*****************************************************************************/
|
|
|
|
/**************************************************//**
|
|
@file sync/sync0arr.c
|
|
The wait array used in synchronization primitives
|
|
|
|
Created 9/5/1995 Heikki Tuuri
|
|
*******************************************************/
|
|
|
|
#include "sync0arr.h"
|
|
#ifdef UNIV_NONINL
|
|
#include "sync0arr.ic"
|
|
#endif
|
|
|
|
#include "sync0sync.h"
|
|
#include "sync0rw.h"
|
|
#include "os0sync.h"
|
|
#include "os0file.h"
|
|
#include "srv0srv.h"
|
|
|
|
/*
|
|
WAIT ARRAY
|
|
==========
|
|
|
|
The wait array consists of cells each of which has an
|
|
an operating system event object created for it. The threads
|
|
waiting for a mutex, for example, can reserve a cell
|
|
in the array and suspend themselves to wait for the event
|
|
to become signaled. When using the wait array, remember to make
|
|
sure that some thread holding the synchronization object
|
|
will eventually know that there is a waiter in the array and
|
|
signal the object, to prevent infinite wait.
|
|
Why we chose to implement a wait array? First, to make
|
|
mutexes fast, we had to code our own implementation of them,
|
|
which only in usually uncommon cases resorts to using
|
|
slow operating system primitives. Then we had the choice of
|
|
assigning a unique OS event for each mutex, which would
|
|
be simpler, or using a global wait array. In some operating systems,
|
|
the global wait array solution is more efficient and flexible,
|
|
because we can do with a very small number of OS events,
|
|
say 200. In NT 3.51, allocating events seems to be a quadratic
|
|
algorithm, because 10 000 events are created fast, but
|
|
100 000 events takes a couple of minutes to create.
|
|
|
|
As of 5.0.30 the above mentioned design is changed. Since now
|
|
OS can handle millions of wait events efficiently, we no longer
|
|
have this concept of each cell of wait array having one event.
|
|
Instead, now the event that a thread wants to wait on is embedded
|
|
in the wait object (mutex or rw_lock). We still keep the global
|
|
wait array for the sake of diagnostics and also to avoid infinite
|
|
wait The error_monitor thread scans the global wait array to signal
|
|
any waiting threads who have missed the signal. */
|
|
|
|
/** A cell where an individual thread may wait suspended
|
|
until a resource is released. The suspending is implemented
|
|
using an operating system event semaphore. */
|
|
struct sync_cell_struct {
|
|
void* wait_object; /*!< pointer to the object the
|
|
thread is waiting for; if NULL
|
|
the cell is free for use */
|
|
mutex_t* old_wait_mutex; /*!< the latest wait mutex in cell */
|
|
rw_lock_t* old_wait_rw_lock;
|
|
/*!< the latest wait rw-lock
|
|
in cell */
|
|
ulint request_type; /*!< lock type requested on the
|
|
object */
|
|
const char* file; /*!< in debug version file where
|
|
requested */
|
|
ulint line; /*!< in debug version line where
|
|
requested */
|
|
os_thread_id_t thread; /*!< thread id of this waiting
|
|
thread */
|
|
ibool waiting; /*!< TRUE if the thread has already
|
|
called sync_array_event_wait
|
|
on this cell */
|
|
ib_int64_t signal_count; /*!< We capture the signal_count
|
|
of the wait_object when we
|
|
reset the event. This value is
|
|
then passed on to os_event_wait
|
|
and we wait only if the event
|
|
has not been signalled in the
|
|
period between the reset and
|
|
wait call. */
|
|
time_t reservation_time;/*!< time when the thread reserved
|
|
the wait cell */
|
|
};
|
|
|
|
/* NOTE: It is allowed for a thread to wait
|
|
for an event allocated for the array without owning the
|
|
protecting mutex (depending on the case: OS or database mutex), but
|
|
all changes (set or reset) to the state of the event must be made
|
|
while owning the mutex. */
|
|
|
|
/** Synchronization array */
|
|
struct sync_array_struct {
|
|
ulint n_reserved; /*!< number of currently reserved
|
|
cells in the wait array */
|
|
ulint n_cells; /*!< number of cells in the
|
|
wait array */
|
|
sync_cell_t* array; /*!< pointer to wait array */
|
|
ulint protection; /*!< this flag tells which
|
|
mutex protects the data */
|
|
mutex_t mutex; /*!< possible database mutex
|
|
protecting this data structure */
|
|
os_mutex_t os_mutex; /*!< Possible operating system mutex
|
|
protecting the data structure.
|
|
As this data structure is used in
|
|
constructing the database mutex,
|
|
to prevent infinite recursion
|
|
in implementation, we fall back to
|
|
an OS mutex. */
|
|
ulint sg_count; /*!< count of how many times an
|
|
object has been signalled */
|
|
ulint res_count; /*!< count of cell reservations
|
|
since creation of the array */
|
|
};
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
/******************************************************************//**
|
|
This function is called only in the debug version. Detects a deadlock
|
|
of one or more threads because of waits of semaphores.
|
|
@return TRUE if deadlock detected */
|
|
static
|
|
ibool
|
|
sync_array_detect_deadlock(
|
|
/*=======================*/
|
|
sync_array_t* arr, /*!< in: wait array; NOTE! the caller must
|
|
own the mutex to array */
|
|
sync_cell_t* start, /*!< in: cell where recursive search started */
|
|
sync_cell_t* cell, /*!< in: cell to search */
|
|
ulint depth); /*!< in: recursion depth */
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
/*****************************************************************//**
|
|
Gets the nth cell in array.
|
|
@return cell */
|
|
static
|
|
sync_cell_t*
|
|
sync_array_get_nth_cell(
|
|
/*====================*/
|
|
sync_array_t* arr, /*!< in: sync array */
|
|
ulint n) /*!< in: index */
|
|
{
|
|
ut_a(arr);
|
|
ut_a(n < arr->n_cells);
|
|
|
|
return(arr->array + n);
|
|
}
|
|
|
|
/******************************************************************//**
|
|
Reserves the mutex semaphore protecting a sync array. */
|
|
static
|
|
void
|
|
sync_array_enter(
|
|
/*=============*/
|
|
sync_array_t* arr) /*!< in: sync wait array */
|
|
{
|
|
ulint protection;
|
|
|
|
protection = arr->protection;
|
|
|
|
if (protection == SYNC_ARRAY_OS_MUTEX) {
|
|
os_mutex_enter(arr->os_mutex);
|
|
} else if (protection == SYNC_ARRAY_MUTEX) {
|
|
mutex_enter(&(arr->mutex));
|
|
} else {
|
|
ut_error;
|
|
}
|
|
}
|
|
|
|
/******************************************************************//**
|
|
Releases the mutex semaphore protecting a sync array. */
|
|
static
|
|
void
|
|
sync_array_exit(
|
|
/*============*/
|
|
sync_array_t* arr) /*!< in: sync wait array */
|
|
{
|
|
ulint protection;
|
|
|
|
protection = arr->protection;
|
|
|
|
if (protection == SYNC_ARRAY_OS_MUTEX) {
|
|
os_mutex_exit(arr->os_mutex);
|
|
} else if (protection == SYNC_ARRAY_MUTEX) {
|
|
mutex_exit(&(arr->mutex));
|
|
} else {
|
|
ut_error;
|
|
}
|
|
}
|
|
|
|
/*******************************************************************//**
|
|
Creates a synchronization wait array. It is protected by a mutex
|
|
which is automatically reserved when the functions operating on it
|
|
are called.
|
|
@return own: created wait array */
|
|
UNIV_INTERN
|
|
sync_array_t*
|
|
sync_array_create(
|
|
/*==============*/
|
|
ulint n_cells, /*!< in: number of cells in the array
|
|
to create */
|
|
ulint protection) /*!< in: either SYNC_ARRAY_OS_MUTEX or
|
|
SYNC_ARRAY_MUTEX: determines the type
|
|
of mutex protecting the data structure */
|
|
{
|
|
ulint sz;
|
|
sync_array_t* arr;
|
|
|
|
ut_a(n_cells > 0);
|
|
|
|
/* Allocate memory for the data structures */
|
|
arr = ut_malloc(sizeof(sync_array_t));
|
|
memset(arr, 0x0, sizeof(*arr));
|
|
|
|
sz = sizeof(sync_cell_t) * n_cells;
|
|
arr->array = ut_malloc(sz);
|
|
memset(arr->array, 0x0, sz);
|
|
|
|
arr->n_cells = n_cells;
|
|
arr->protection = protection;
|
|
|
|
/* Then create the mutex to protect the wait array complex */
|
|
if (protection == SYNC_ARRAY_OS_MUTEX) {
|
|
arr->os_mutex = os_mutex_create(NULL);
|
|
} else if (protection == SYNC_ARRAY_MUTEX) {
|
|
mutex_create(&arr->mutex, SYNC_NO_ORDER_CHECK);
|
|
} else {
|
|
ut_error;
|
|
}
|
|
|
|
return(arr);
|
|
}
|
|
|
|
/******************************************************************//**
|
|
Frees the resources in a wait array. */
|
|
UNIV_INTERN
|
|
void
|
|
sync_array_free(
|
|
/*============*/
|
|
sync_array_t* arr) /*!< in, own: sync wait array */
|
|
{
|
|
ulint protection;
|
|
|
|
ut_a(arr->n_reserved == 0);
|
|
|
|
sync_array_validate(arr);
|
|
|
|
protection = arr->protection;
|
|
|
|
/* Release the mutex protecting the wait array complex */
|
|
|
|
if (protection == SYNC_ARRAY_OS_MUTEX) {
|
|
os_mutex_free(arr->os_mutex);
|
|
} else if (protection == SYNC_ARRAY_MUTEX) {
|
|
mutex_free(&(arr->mutex));
|
|
} else {
|
|
ut_error;
|
|
}
|
|
|
|
ut_free(arr->array);
|
|
ut_free(arr);
|
|
}
|
|
|
|
/********************************************************************//**
|
|
Validates the integrity of the wait array. Checks
|
|
that the number of reserved cells equals the count variable. */
|
|
UNIV_INTERN
|
|
void
|
|
sync_array_validate(
|
|
/*================*/
|
|
sync_array_t* arr) /*!< in: sync wait array */
|
|
{
|
|
ulint i;
|
|
sync_cell_t* cell;
|
|
ulint count = 0;
|
|
|
|
sync_array_enter(arr);
|
|
|
|
for (i = 0; i < arr->n_cells; i++) {
|
|
cell = sync_array_get_nth_cell(arr, i);
|
|
if (cell->wait_object != NULL) {
|
|
count++;
|
|
}
|
|
}
|
|
|
|
ut_a(count == arr->n_reserved);
|
|
|
|
sync_array_exit(arr);
|
|
}
|
|
|
|
/*******************************************************************//**
|
|
Returns the event that the thread owning the cell waits for. */
|
|
static
|
|
os_event_t
|
|
sync_cell_get_event(
|
|
/*================*/
|
|
sync_cell_t* cell) /*!< in: non-empty sync array cell */
|
|
{
|
|
ulint type = cell->request_type;
|
|
|
|
if (type == SYNC_MUTEX) {
|
|
return(((mutex_t *) cell->wait_object)->event);
|
|
} else if (type == RW_LOCK_WAIT_EX) {
|
|
return(((rw_lock_t *) cell->wait_object)->wait_ex_event);
|
|
} else { /* RW_LOCK_SHARED and RW_LOCK_EX wait on the same event */
|
|
return(((rw_lock_t *) cell->wait_object)->event);
|
|
}
|
|
}
|
|
|
|
/******************************************************************//**
|
|
Reserves a wait array cell for waiting for an object.
|
|
The event of the cell is reset to nonsignalled state. */
|
|
UNIV_INTERN
|
|
void
|
|
sync_array_reserve_cell(
|
|
/*====================*/
|
|
sync_array_t* arr, /*!< in: wait array */
|
|
void* object, /*!< in: pointer to the object to wait for */
|
|
ulint type, /*!< in: lock request type */
|
|
const char* file, /*!< in: file where requested */
|
|
ulint line, /*!< in: line where requested */
|
|
ulint* index) /*!< out: index of the reserved cell */
|
|
{
|
|
sync_cell_t* cell;
|
|
os_event_t event;
|
|
ulint i;
|
|
|
|
ut_a(object);
|
|
ut_a(index);
|
|
|
|
sync_array_enter(arr);
|
|
|
|
arr->res_count++;
|
|
|
|
/* Reserve a new cell. */
|
|
for (i = 0; i < arr->n_cells; i++) {
|
|
cell = sync_array_get_nth_cell(arr, i);
|
|
|
|
if (cell->wait_object == NULL) {
|
|
|
|
cell->waiting = FALSE;
|
|
cell->wait_object = object;
|
|
|
|
if (type == SYNC_MUTEX) {
|
|
cell->old_wait_mutex = object;
|
|
} else {
|
|
cell->old_wait_rw_lock = object;
|
|
}
|
|
|
|
cell->request_type = type;
|
|
|
|
cell->file = file;
|
|
cell->line = line;
|
|
|
|
arr->n_reserved++;
|
|
|
|
*index = i;
|
|
|
|
sync_array_exit(arr);
|
|
|
|
/* Make sure the event is reset and also store
|
|
the value of signal_count at which the event
|
|
was reset. */
|
|
event = sync_cell_get_event(cell);
|
|
cell->signal_count = os_event_reset(event);
|
|
|
|
cell->reservation_time = time(NULL);
|
|
|
|
cell->thread = os_thread_get_curr_id();
|
|
|
|
return;
|
|
}
|
|
}
|
|
|
|
ut_error; /* No free cell found */
|
|
|
|
return;
|
|
}
|
|
|
|
/******************************************************************//**
|
|
This function should be called when a thread starts to wait on
|
|
a wait array cell. In the debug version this function checks
|
|
if the wait for a semaphore will result in a deadlock, in which
|
|
case prints info and asserts. */
|
|
UNIV_INTERN
|
|
void
|
|
sync_array_wait_event(
|
|
/*==================*/
|
|
sync_array_t* arr, /*!< in: wait array */
|
|
ulint index) /*!< in: index of the reserved cell */
|
|
{
|
|
sync_cell_t* cell;
|
|
os_event_t event;
|
|
|
|
ut_a(arr);
|
|
|
|
sync_array_enter(arr);
|
|
|
|
cell = sync_array_get_nth_cell(arr, index);
|
|
|
|
ut_a(cell->wait_object);
|
|
ut_a(!cell->waiting);
|
|
ut_ad(os_thread_get_curr_id() == cell->thread);
|
|
|
|
event = sync_cell_get_event(cell);
|
|
cell->waiting = TRUE;
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
|
|
/* We use simple enter to the mutex below, because if
|
|
we cannot acquire it at once, mutex_enter would call
|
|
recursively sync_array routines, leading to trouble.
|
|
rw_lock_debug_mutex freezes the debug lists. */
|
|
|
|
rw_lock_debug_mutex_enter();
|
|
|
|
if (TRUE == sync_array_detect_deadlock(arr, cell, cell, 0)) {
|
|
|
|
fputs("########################################\n", stderr);
|
|
ut_error;
|
|
}
|
|
|
|
rw_lock_debug_mutex_exit();
|
|
#endif
|
|
sync_array_exit(arr);
|
|
|
|
os_event_wait_low(event, cell->signal_count);
|
|
|
|
sync_array_free_cell(arr, index);
|
|
}
|
|
|
|
/******************************************************************//**
|
|
Reports info of a wait array cell. */
|
|
static
|
|
void
|
|
sync_array_cell_print(
|
|
/*==================*/
|
|
FILE* file, /*!< in: file where to print */
|
|
sync_cell_t* cell) /*!< in: sync cell */
|
|
{
|
|
mutex_t* mutex;
|
|
rw_lock_t* rwlock;
|
|
ulint type;
|
|
ulint writer;
|
|
|
|
type = cell->request_type;
|
|
|
|
fprintf(file,
|
|
"--Thread %lu has waited at %s line %lu"
|
|
" for %.2f seconds the semaphore:\n",
|
|
(ulong) os_thread_pf(cell->thread), cell->file,
|
|
(ulong) cell->line,
|
|
difftime(time(NULL), cell->reservation_time));
|
|
|
|
if (type == SYNC_MUTEX) {
|
|
/* We use old_wait_mutex in case the cell has already
|
|
been freed meanwhile */
|
|
mutex = cell->old_wait_mutex;
|
|
|
|
fprintf(file,
|
|
"Mutex at %p created file %s line %lu, lock var %lu\n"
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
"Last time reserved in file %s line %lu, "
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
"waiters flag %lu\n",
|
|
(void*) mutex, mutex->cfile_name, (ulong) mutex->cline,
|
|
(ulong) mutex->lock_word,
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
mutex->file_name, (ulong) mutex->line,
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
(ulong) mutex->waiters);
|
|
|
|
} else if (type == RW_LOCK_EX
|
|
|| type == RW_LOCK_WAIT_EX
|
|
|| type == RW_LOCK_SHARED) {
|
|
|
|
fputs(type == RW_LOCK_EX ? "X-lock on" : "S-lock on", file);
|
|
|
|
rwlock = cell->old_wait_rw_lock;
|
|
|
|
fprintf(file,
|
|
" RW-latch at %p created in file %s line %lu\n",
|
|
(void*) rwlock, rwlock->cfile_name,
|
|
(ulong) rwlock->cline);
|
|
writer = rw_lock_get_writer(rwlock);
|
|
if (writer != RW_LOCK_NOT_LOCKED) {
|
|
fprintf(file,
|
|
"a writer (thread id %lu) has"
|
|
" reserved it in mode %s",
|
|
(ulong) os_thread_pf(rwlock->writer_thread),
|
|
writer == RW_LOCK_EX
|
|
? " exclusive\n"
|
|
: " wait exclusive\n");
|
|
}
|
|
|
|
fprintf(file,
|
|
"number of readers %lu, waiters flag %lu, "
|
|
"lock_word: %lx\n"
|
|
"Last time read locked in file %s line %lu\n"
|
|
"Last time write locked in file %s line %lu\n",
|
|
(ulong) rw_lock_get_reader_count(rwlock),
|
|
(ulong) rwlock->waiters,
|
|
rwlock->lock_word,
|
|
rwlock->last_s_file_name,
|
|
(ulong) rwlock->last_s_line,
|
|
rwlock->last_x_file_name,
|
|
(ulong) rwlock->last_x_line);
|
|
} else {
|
|
ut_error;
|
|
}
|
|
|
|
if (!cell->waiting) {
|
|
fputs("wait has ended\n", file);
|
|
}
|
|
}
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
/******************************************************************//**
|
|
Looks for a cell with the given thread id.
|
|
@return pointer to cell or NULL if not found */
|
|
static
|
|
sync_cell_t*
|
|
sync_array_find_thread(
|
|
/*===================*/
|
|
sync_array_t* arr, /*!< in: wait array */
|
|
os_thread_id_t thread) /*!< in: thread id */
|
|
{
|
|
ulint i;
|
|
sync_cell_t* cell;
|
|
|
|
for (i = 0; i < arr->n_cells; i++) {
|
|
|
|
cell = sync_array_get_nth_cell(arr, i);
|
|
|
|
if (cell->wait_object != NULL
|
|
&& os_thread_eq(cell->thread, thread)) {
|
|
|
|
return(cell); /* Found */
|
|
}
|
|
}
|
|
|
|
return(NULL); /* Not found */
|
|
}
|
|
|
|
/******************************************************************//**
|
|
Recursion step for deadlock detection.
|
|
@return TRUE if deadlock detected */
|
|
static
|
|
ibool
|
|
sync_array_deadlock_step(
|
|
/*=====================*/
|
|
sync_array_t* arr, /*!< in: wait array; NOTE! the caller must
|
|
own the mutex to array */
|
|
sync_cell_t* start, /*!< in: cell where recursive search
|
|
started */
|
|
os_thread_id_t thread, /*!< in: thread to look at */
|
|
ulint pass, /*!< in: pass value */
|
|
ulint depth) /*!< in: recursion depth */
|
|
{
|
|
sync_cell_t* new;
|
|
ibool ret;
|
|
|
|
depth++;
|
|
|
|
if (pass != 0) {
|
|
/* If pass != 0, then we do not know which threads are
|
|
responsible of releasing the lock, and no deadlock can
|
|
be detected. */
|
|
|
|
return(FALSE);
|
|
}
|
|
|
|
new = sync_array_find_thread(arr, thread);
|
|
|
|
if (new == start) {
|
|
/* Stop running of other threads */
|
|
|
|
ut_dbg_stop_threads = TRUE;
|
|
|
|
/* Deadlock */
|
|
fputs("########################################\n"
|
|
"DEADLOCK of threads detected!\n", stderr);
|
|
|
|
return(TRUE);
|
|
|
|
} else if (new) {
|
|
ret = sync_array_detect_deadlock(arr, start, new, depth);
|
|
|
|
if (ret) {
|
|
return(TRUE);
|
|
}
|
|
}
|
|
return(FALSE);
|
|
}
|
|
|
|
/******************************************************************//**
|
|
This function is called only in the debug version. Detects a deadlock
|
|
of one or more threads because of waits of semaphores.
|
|
@return TRUE if deadlock detected */
|
|
static
|
|
ibool
|
|
sync_array_detect_deadlock(
|
|
/*=======================*/
|
|
sync_array_t* arr, /*!< in: wait array; NOTE! the caller must
|
|
own the mutex to array */
|
|
sync_cell_t* start, /*!< in: cell where recursive search started */
|
|
sync_cell_t* cell, /*!< in: cell to search */
|
|
ulint depth) /*!< in: recursion depth */
|
|
{
|
|
mutex_t* mutex;
|
|
rw_lock_t* lock;
|
|
os_thread_id_t thread;
|
|
ibool ret;
|
|
rw_lock_debug_t*debug;
|
|
|
|
ut_a(arr);
|
|
ut_a(start);
|
|
ut_a(cell);
|
|
ut_ad(cell->wait_object);
|
|
ut_ad(os_thread_get_curr_id() == start->thread);
|
|
ut_ad(depth < 100);
|
|
|
|
depth++;
|
|
|
|
if (!cell->waiting) {
|
|
|
|
return(FALSE); /* No deadlock here */
|
|
}
|
|
|
|
if (cell->request_type == SYNC_MUTEX) {
|
|
|
|
mutex = cell->wait_object;
|
|
|
|
if (mutex_get_lock_word(mutex) != 0) {
|
|
|
|
thread = mutex->thread_id;
|
|
|
|
/* Note that mutex->thread_id above may be
|
|
also OS_THREAD_ID_UNDEFINED, because the
|
|
thread which held the mutex maybe has not
|
|
yet updated the value, or it has already
|
|
released the mutex: in this case no deadlock
|
|
can occur, as the wait array cannot contain
|
|
a thread with ID_UNDEFINED value. */
|
|
|
|
ret = sync_array_deadlock_step(arr, start, thread, 0,
|
|
depth);
|
|
if (ret) {
|
|
fprintf(stderr,
|
|
"Mutex %p owned by thread %lu file %s line %lu\n",
|
|
mutex, (ulong) os_thread_pf(mutex->thread_id),
|
|
mutex->file_name, (ulong) mutex->line);
|
|
sync_array_cell_print(stderr, cell);
|
|
|
|
return(TRUE);
|
|
}
|
|
}
|
|
|
|
return(FALSE); /* No deadlock */
|
|
|
|
} else if (cell->request_type == RW_LOCK_EX
|
|
|| cell->request_type == RW_LOCK_WAIT_EX) {
|
|
|
|
lock = cell->wait_object;
|
|
|
|
debug = UT_LIST_GET_FIRST(lock->debug_list);
|
|
|
|
while (debug != NULL) {
|
|
|
|
thread = debug->thread_id;
|
|
|
|
if (((debug->lock_type == RW_LOCK_EX)
|
|
&& !os_thread_eq(thread, cell->thread))
|
|
|| ((debug->lock_type == RW_LOCK_WAIT_EX)
|
|
&& !os_thread_eq(thread, cell->thread))
|
|
|| (debug->lock_type == RW_LOCK_SHARED)) {
|
|
|
|
/* The (wait) x-lock request can block
|
|
infinitely only if someone (can be also cell
|
|
thread) is holding s-lock, or someone
|
|
(cannot be cell thread) (wait) x-lock, and
|
|
he is blocked by start thread */
|
|
|
|
ret = sync_array_deadlock_step(
|
|
arr, start, thread, debug->pass,
|
|
depth);
|
|
if (ret) {
|
|
print:
|
|
fprintf(stderr, "rw-lock %p ",
|
|
(void*) lock);
|
|
sync_array_cell_print(stderr, cell);
|
|
rw_lock_debug_print(debug);
|
|
return(TRUE);
|
|
}
|
|
}
|
|
|
|
debug = UT_LIST_GET_NEXT(list, debug);
|
|
}
|
|
|
|
return(FALSE);
|
|
|
|
} else if (cell->request_type == RW_LOCK_SHARED) {
|
|
|
|
lock = cell->wait_object;
|
|
debug = UT_LIST_GET_FIRST(lock->debug_list);
|
|
|
|
while (debug != NULL) {
|
|
|
|
thread = debug->thread_id;
|
|
|
|
if ((debug->lock_type == RW_LOCK_EX)
|
|
|| (debug->lock_type == RW_LOCK_WAIT_EX)) {
|
|
|
|
/* The s-lock request can block infinitely
|
|
only if someone (can also be cell thread) is
|
|
holding (wait) x-lock, and he is blocked by
|
|
start thread */
|
|
|
|
ret = sync_array_deadlock_step(
|
|
arr, start, thread, debug->pass,
|
|
depth);
|
|
if (ret) {
|
|
goto print;
|
|
}
|
|
}
|
|
|
|
debug = UT_LIST_GET_NEXT(list, debug);
|
|
}
|
|
|
|
return(FALSE);
|
|
|
|
} else {
|
|
ut_error;
|
|
}
|
|
|
|
return(TRUE); /* Execution never reaches this line: for compiler
|
|
fooling only */
|
|
}
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
/******************************************************************//**
|
|
Determines if we can wake up the thread waiting for a sempahore. */
|
|
static
|
|
ibool
|
|
sync_arr_cell_can_wake_up(
|
|
/*======================*/
|
|
sync_cell_t* cell) /*!< in: cell to search */
|
|
{
|
|
mutex_t* mutex;
|
|
rw_lock_t* lock;
|
|
|
|
if (cell->request_type == SYNC_MUTEX) {
|
|
|
|
mutex = cell->wait_object;
|
|
|
|
if (mutex_get_lock_word(mutex) == 0) {
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
} else if (cell->request_type == RW_LOCK_EX) {
|
|
|
|
lock = cell->wait_object;
|
|
|
|
if (lock->lock_word > 0) {
|
|
/* Either unlocked or only read locked. */
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
} else if (cell->request_type == RW_LOCK_WAIT_EX) {
|
|
|
|
lock = cell->wait_object;
|
|
|
|
/* lock_word == 0 means all readers have left */
|
|
if (lock->lock_word == 0) {
|
|
|
|
return(TRUE);
|
|
}
|
|
} else if (cell->request_type == RW_LOCK_SHARED) {
|
|
lock = cell->wait_object;
|
|
|
|
/* lock_word > 0 means no writer or reserved writer */
|
|
if (lock->lock_word > 0) {
|
|
|
|
return(TRUE);
|
|
}
|
|
}
|
|
|
|
return(FALSE);
|
|
}
|
|
|
|
/******************************************************************//**
|
|
Frees the cell. NOTE! sync_array_wait_event frees the cell
|
|
automatically! */
|
|
UNIV_INTERN
|
|
void
|
|
sync_array_free_cell(
|
|
/*=================*/
|
|
sync_array_t* arr, /*!< in: wait array */
|
|
ulint index) /*!< in: index of the cell in array */
|
|
{
|
|
sync_cell_t* cell;
|
|
|
|
sync_array_enter(arr);
|
|
|
|
cell = sync_array_get_nth_cell(arr, index);
|
|
|
|
ut_a(cell->wait_object != NULL);
|
|
|
|
cell->waiting = FALSE;
|
|
cell->wait_object = NULL;
|
|
cell->signal_count = 0;
|
|
|
|
ut_a(arr->n_reserved > 0);
|
|
arr->n_reserved--;
|
|
|
|
sync_array_exit(arr);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Increments the signalled count. */
|
|
UNIV_INTERN
|
|
void
|
|
sync_array_object_signalled(
|
|
/*========================*/
|
|
sync_array_t* arr) /*!< in: wait array */
|
|
{
|
|
#ifdef HAVE_ATOMIC_BUILTINS
|
|
(void) os_atomic_increment_ulint(&arr->sg_count, 1);
|
|
#else
|
|
sync_array_enter(arr);
|
|
|
|
arr->sg_count++;
|
|
|
|
sync_array_exit(arr);
|
|
#endif
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
If the wakeup algorithm does not work perfectly at semaphore relases,
|
|
this function will do the waking (see the comment in mutex_exit). This
|
|
function should be called about every 1 second in the server.
|
|
|
|
Note that there's a race condition between this thread and mutex_exit
|
|
changing the lock_word and calling signal_object, so sometimes this finds
|
|
threads to wake up even when nothing has gone wrong. */
|
|
UNIV_INTERN
|
|
void
|
|
sync_arr_wake_threads_if_sema_free(void)
|
|
/*====================================*/
|
|
{
|
|
sync_array_t* arr = sync_primary_wait_array;
|
|
sync_cell_t* cell;
|
|
ulint count;
|
|
ulint i;
|
|
os_event_t event;
|
|
|
|
sync_array_enter(arr);
|
|
|
|
i = 0;
|
|
count = 0;
|
|
|
|
while (count < arr->n_reserved) {
|
|
|
|
cell = sync_array_get_nth_cell(arr, i);
|
|
i++;
|
|
|
|
if (cell->wait_object == NULL) {
|
|
continue;
|
|
}
|
|
count++;
|
|
|
|
if (sync_arr_cell_can_wake_up(cell)) {
|
|
|
|
event = sync_cell_get_event(cell);
|
|
|
|
os_event_set(event);
|
|
}
|
|
|
|
}
|
|
|
|
sync_array_exit(arr);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Prints warnings of long semaphore waits to stderr.
|
|
@return TRUE if fatal semaphore wait threshold was exceeded */
|
|
UNIV_INTERN
|
|
ibool
|
|
sync_array_print_long_waits(void)
|
|
/*=============================*/
|
|
{
|
|
sync_cell_t* cell;
|
|
ibool old_val;
|
|
ibool noticed = FALSE;
|
|
ulint i;
|
|
ulint fatal_timeout = srv_fatal_semaphore_wait_threshold;
|
|
ibool fatal = FALSE;
|
|
|
|
for (i = 0; i < sync_primary_wait_array->n_cells; i++) {
|
|
|
|
cell = sync_array_get_nth_cell(sync_primary_wait_array, i);
|
|
|
|
if (cell->wait_object != NULL && cell->waiting
|
|
&& difftime(time(NULL), cell->reservation_time) > 240) {
|
|
fputs("InnoDB: Warning: a long semaphore wait:\n",
|
|
stderr);
|
|
sync_array_cell_print(stderr, cell);
|
|
noticed = TRUE;
|
|
}
|
|
|
|
if (cell->wait_object != NULL && cell->waiting
|
|
&& difftime(time(NULL), cell->reservation_time)
|
|
> fatal_timeout) {
|
|
fatal = TRUE;
|
|
}
|
|
}
|
|
|
|
if (noticed) {
|
|
fprintf(stderr,
|
|
"InnoDB: ###### Starts InnoDB Monitor"
|
|
" for 30 secs to print diagnostic info:\n");
|
|
old_val = srv_print_innodb_monitor;
|
|
|
|
/* If some crucial semaphore is reserved, then also the InnoDB
|
|
Monitor can hang, and we do not get diagnostics. Since in
|
|
many cases an InnoDB hang is caused by a pwrite() or a pread()
|
|
call hanging inside the operating system, let us print right
|
|
now the values of pending calls of these. */
|
|
|
|
fprintf(stderr,
|
|
"InnoDB: Pending preads %lu, pwrites %lu\n",
|
|
(ulong)os_file_n_pending_preads,
|
|
(ulong)os_file_n_pending_pwrites);
|
|
|
|
srv_print_innodb_monitor = TRUE;
|
|
os_event_set(srv_lock_timeout_thread_event);
|
|
|
|
os_thread_sleep(30000000);
|
|
|
|
srv_print_innodb_monitor = old_val;
|
|
fprintf(stderr,
|
|
"InnoDB: ###### Diagnostic info printed"
|
|
" to the standard error stream\n");
|
|
}
|
|
|
|
return(fatal);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Prints info of the wait array. */
|
|
static
|
|
void
|
|
sync_array_output_info(
|
|
/*===================*/
|
|
FILE* file, /*!< in: file where to print */
|
|
sync_array_t* arr) /*!< in: wait array; NOTE! caller must own the
|
|
mutex */
|
|
{
|
|
sync_cell_t* cell;
|
|
ulint count;
|
|
ulint i;
|
|
|
|
fprintf(file,
|
|
"OS WAIT ARRAY INFO: reservation count %ld, signal count %ld\n",
|
|
(long) arr->res_count, (long) arr->sg_count);
|
|
i = 0;
|
|
count = 0;
|
|
|
|
while (count < arr->n_reserved) {
|
|
|
|
cell = sync_array_get_nth_cell(arr, i);
|
|
|
|
if (cell->wait_object != NULL) {
|
|
count++;
|
|
sync_array_cell_print(file, cell);
|
|
}
|
|
|
|
i++;
|
|
}
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Prints info of the wait array. */
|
|
UNIV_INTERN
|
|
void
|
|
sync_array_print_info(
|
|
/*==================*/
|
|
FILE* file, /*!< in: file where to print */
|
|
sync_array_t* arr) /*!< in: wait array */
|
|
{
|
|
sync_array_enter(arr);
|
|
|
|
sync_array_output_info(file, arr);
|
|
|
|
sync_array_exit(arr);
|
|
}
|