diff options
author | unknown <monty@mysql.com> | 2004-12-06 11:38:56 +0200 |
---|---|---|
committer | unknown <monty@mysql.com> | 2004-12-06 11:38:56 +0200 |
commit | 796bd7de96a1d1ec422708b90df5328388201c10 (patch) | |
tree | a7bb331b7dac7ac2b3cda915e99bb8c1333f4fec /sql/lock.cc | |
parent | 289d3b2ee0f912dd4f128e1c61685d7bb170eb90 (diff) | |
parent | f8cdf570979c550ef04c53f691118ed2b1296a7c (diff) | |
download | mariadb-git-796bd7de96a1d1ec422708b90df5328388201c10.tar.gz |
Merge with 4.1
BitKeeper/etc/ignore:
auto-union
BitKeeper/etc/logging_ok:
auto-union
BUILD/SETUP.sh:
Auto merged
Build-tools/Do-compile:
Auto merged
client/mysqladmin.cc:
Auto merged
configure.in:
Auto merged
innobase/include/lock0lock.h:
Auto merged
innobase/os/os0file.c:
Auto merged
libmysqld/Makefile.am:
Auto merged
mysql-test/mysql-test-run.sh:
Auto merged
mysql-test/r/ctype_ucs.result:
Auto merged
mysql-test/r/heap.result:
Auto merged
mysql-test/r/insert_select.result:
Auto merged
mysql-test/r/lowercase_table3.result:
Auto merged
mysql-test/r/rpl_start_stop_slave.result:
Auto merged
mysql-test/r/subselect.result:
Auto merged
mysql-test/t/ctype_ucs.test:
Auto merged
mysql-test/t/rpl_until.test:
Auto merged
mysql-test/t/subselect.test:
Auto merged
ndb/src/kernel/blocks/dblqh/DblqhMain.cpp:
Auto merged
sql/field.cc:
Auto merged
sql/field.h:
Auto merged
sql/ha_myisam.h:
Auto merged
sql/handler.cc:
Auto merged
sql/handler.h:
Auto merged
sql/item.h:
Auto merged
sql/item_cmpfunc.cc:
Auto merged
sql/item_func.cc:
Auto merged
sql/lock.cc:
Auto merged
sql/log_event.h:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/mysqld.cc:
Auto merged
sql/set_var.cc:
Auto merged
sql/slave.cc:
Auto merged
sql/slave.h:
Auto merged
sql/sql_acl.cc:
Auto merged
sql/sql_base.cc:
Auto merged
sql/sql_class.h:
Auto merged
sql/sql_db.cc:
Auto merged
sql/sql_delete.cc:
Auto merged
sql/sql_prepare.cc:
Auto merged
sql/sql_rename.cc:
Auto merged
sql/sql_select.cc:
Auto merged
sql/sql_show.cc:
Auto merged
sql/sql_update.cc:
Auto merged
sql/sql_yacc.yy:
Auto merged
sql/log_event.cc:
Merge with 4.1
Trivial cleanup
Diffstat (limited to 'sql/lock.cc')
-rw-r--r-- | sql/lock.cc | 65 |
1 files changed, 61 insertions, 4 deletions
diff --git a/sql/lock.cc b/sql/lock.cc index 3367c6a2900..8a3619b57dd 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -707,15 +707,70 @@ static void print_lock_error(int error) /**************************************************************************** Handling of global read locks + Taking the global read lock is TWO steps (2nd step is optional; without + it, COMMIT of existing transactions will be allowed): + lock_global_read_lock() THEN make_global_read_lock_block_commit(). + The global locks are handled through the global variables: global_read_lock + count of threads which have the global read lock (i.e. have completed at + least the first step above) global_read_lock_blocks_commit - waiting_for_read_lock + count of threads which have the global read lock and block + commits (i.e. have completed the second step above) + waiting_for_read_lock + count of threads which want to take a global read lock but cannot protect_against_global_read_lock + count of threads which have set protection against global read lock. + + How blocking of threads by global read lock is achieved: that's + advisory. Any piece of code which should be blocked by global read lock must + be designed like this: + - call to wait_if_global_read_lock(). When this returns 0, no global read + lock is owned; if argument abort_on_refresh was 0, none can be obtained. + - job + - if abort_on_refresh was 0, call to start_waiting_global_read_lock() to + allow other threads to get the global read lock. I.e. removal of the + protection. + (Note: it's a bit like an implementation of rwlock). + + [ I am sorry to mention some SQL syntaxes below I know I shouldn't but found + no better descriptive way ] + + Why does FLUSH TABLES WITH READ LOCK need to block COMMIT: because it's used + to read a non-moving SHOW MASTER STATUS, and a COMMIT writes to the binary + log. + + Why getting the global read lock is two steps and not one. Because FLUSH + TABLES WITH READ LOCK needs to insert one other step between the two: + flushing tables. So the order is + 1) lock_global_read_lock() (prevents any new table write locks, i.e. stalls + all new updates) + 2) close_cached_tables() (the FLUSH TABLES), which will wait for tables + currently opened and being updated to close (so it's possible that there is + a moment where all new updates of server are stalled *and* FLUSH TABLES WITH + READ LOCK is, too). + 3) make_global_read_lock_block_commit(). + If we have merged 1) and 3) into 1), we would have had this deadlock: + imagine thread 1 and 2, in non-autocommit mode, thread 3, and an InnoDB + table t. + thd1: SELECT * FROM t FOR UPDATE; + thd2: UPDATE t SET a=1; # blocked by row-level locks of thd1 + thd3: FLUSH TABLES WITH READ LOCK; # blocked in close_cached_tables() by the + table instance of thd2 + thd1: COMMIT; # blocked by thd3. + thd1 blocks thd2 which blocks thd3 which blocks thd1: deadlock. + + Note that we need to support that one thread does + FLUSH TABLES WITH READ LOCK; and then COMMIT; + (that's what innobackup does, for some good reason). + So in this exceptional case the COMMIT should not be blocked by the FLUSH + TABLES WITH READ LOCK. + + TODO in MySQL 5.x: make_global_read_lock_block_commit() should be + killable. Normally CPU does not spend a long time in this function (COMMITs + are quite fast), but it would still be nice. - Taking the global read lock is TWO steps (2nd step is optional; without - it, COMMIT of existing transactions will be allowed): - lock_global_read_lock() THEN make_global_read_lock_block_commit(). ****************************************************************************/ volatile uint global_read_lock=0; @@ -831,6 +886,8 @@ void start_waiting_global_read_lock(THD *thd) { bool tmp; DBUG_ENTER("start_waiting_global_read_lock"); + if (unlikely(thd->global_read_lock)) + DBUG_VOID_RETURN; (void) pthread_mutex_lock(&LOCK_open); tmp= (!--protect_against_global_read_lock && waiting_for_read_lock); (void) pthread_mutex_unlock(&LOCK_open); |