diff options
133 files changed, 5200 insertions, 2297 deletions
diff --git a/client/client_priv.h b/client/client_priv.h index 97a8920f744..9cd151f6160 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -101,7 +101,7 @@ enum options_client /** First mysql version supporting the performance schema. */ -#define FIRST_PERFORMANCE_SCHEMA_VERSION 50600 +#define FIRST_PERFORMANCE_SCHEMA_VERSION 50599 /** Name of the performance schema database. diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index 2a425edb379..d56ada00266 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -501,7 +501,19 @@ int init_embedded_server(int argc, char **argv, char **groups) */ logger.init_base(); - if (init_common_variables("my", *argcp, *argvp, (const char **)groups)) + orig_argc= *argcp; + orig_argv= *argvp; + load_defaults("my", (const char **)groups, argcp, argvp); + defaults_argc= *argcp; + defaults_argv= *argvp; + remaining_argc= argc; + remaining_argv= argv; + + /* Must be initialized early for comparison of options name */ + system_charset_info= &my_charset_utf8_general_ci; + sys_var_init(); + + if (init_common_variables()) { mysql_server_end(); return 1; diff --git a/mysql-test/include/have_perfschema.inc b/mysql-test/include/have_perfschema.inc new file mode 100644 index 00000000000..6d52a53b6b1 --- /dev/null +++ b/mysql-test/include/have_perfschema.inc @@ -0,0 +1,20 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +if (!`SELECT count(*) FROM information_schema.engines WHERE + (support = 'YES' OR support = 'DEFAULT') AND + engine = 'PERFORMANCE_SCHEMA'`){ + skip Need performance schema compiled in; +} diff --git a/mysql-test/suite/sys_vars/r/all_vars.result b/mysql-test/suite/sys_vars/r/all_vars.result index abd1f5d2bd6..0f741ff930a 100644 --- a/mysql-test/suite/sys_vars/r/all_vars.result +++ b/mysql-test/suite/sys_vars/r/all_vars.result @@ -1,12 +1,14 @@ create table t1 (test_name text); +create table t2 (variable_name text); load data infile "MYSQLTEST_VARDIR/tmp/sys_vars.all_vars.txt" into table t1; -select variable_name as `There should be *no* variables listed below:` - from information_schema.global_variables -left join t1 on variable_name=test_name where -test_name is null -union -select variable_name from information_schema.session_variables -left join t1 on variable_name=test_name where -test_name is null; +insert into t2 select variable_name from information_schema.global_variables; +insert into t2 select variable_name from information_schema.session_variables; +update t2 set variable_name= replace(variable_name, "PERFORMANCE_SCHEMA_", "PFS_"); +select variable_name as `There should be *no* long test name listed below:` from t2 +where length(variable_name) > 50; +There should be *no* long test name listed below: +select variable_name as `There should be *no* variables listed below:` from t2 +left join t1 on variable_name=test_name where test_name is null; There should be *no* variables listed below: drop table t1; +drop table t2; diff --git a/mysql-test/suite/sys_vars/r/performance_schema_basic.result b/mysql-test/suite/sys_vars/r/performance_schema_basic.result new file mode 100644 index 00000000000..d494b64502b --- /dev/null +++ b/mysql-test/suite/sys_vars/r/performance_schema_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema; +@@global.performance_schema +1 +select @@session.performance_schema; +ERROR HY000: Variable 'performance_schema' is a GLOBAL variable +show global variables like 'performance_schema'; +Variable_name Value +performance_schema ON +show session variables like 'performance_schema'; +Variable_name Value +performance_schema ON +select * from information_schema.global_variables +where variable_name='performance_schema'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA ON +select * from information_schema.session_variables +where variable_name='performance_schema'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA ON +set global performance_schema=1; +ERROR HY000: Variable 'performance_schema' is a read only variable +set session performance_schema=1; +ERROR HY000: Variable 'performance_schema' is a read only variable diff --git a/mysql-test/suite/sys_vars/r/pfs_events_waits_history_long_size_basic.result b/mysql-test/suite/sys_vars/r/pfs_events_waits_history_long_size_basic.result new file mode 100644 index 00000000000..6aa1b0b6325 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/pfs_events_waits_history_long_size_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema_events_waits_history_long_size; +@@global.performance_schema_events_waits_history_long_size +15000 +select @@session.performance_schema_events_waits_history_long_size; +ERROR HY000: Variable 'performance_schema_events_waits_history_long_size' is a GLOBAL variable +show global variables like 'performance_schema_events_waits_history_long_size'; +Variable_name Value +performance_schema_events_waits_history_long_size 15000 +show session variables like 'performance_schema_events_waits_history_long_size'; +Variable_name Value +performance_schema_events_waits_history_long_size 15000 +select * from information_schema.global_variables +where variable_name='performance_schema_events_waits_history_long_size'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_EVENTS_WAITS_HISTORY_LONG_SIZE 15000 +select * from information_schema.session_variables +where variable_name='performance_schema_events_waits_history_long_size'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_EVENTS_WAITS_HISTORY_LONG_SIZE 15000 +set global performance_schema_events_waits_history_long_size=1; +ERROR HY000: Variable 'performance_schema_events_waits_history_long_size' is a read only variable +set session performance_schema_events_waits_history_long_size=1; +ERROR HY000: Variable 'performance_schema_events_waits_history_long_size' is a read only variable diff --git a/mysql-test/suite/sys_vars/r/pfs_events_waits_history_size_basic.result b/mysql-test/suite/sys_vars/r/pfs_events_waits_history_size_basic.result new file mode 100644 index 00000000000..defa4eca1d4 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/pfs_events_waits_history_size_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema_events_waits_history_size; +@@global.performance_schema_events_waits_history_size +15 +select @@session.performance_schema_events_waits_history_size; +ERROR HY000: Variable 'performance_schema_events_waits_history_size' is a GLOBAL variable +show global variables like 'performance_schema_events_waits_history_size'; +Variable_name Value +performance_schema_events_waits_history_size 15 +show session variables like 'performance_schema_events_waits_history_size'; +Variable_name Value +performance_schema_events_waits_history_size 15 +select * from information_schema.global_variables +where variable_name='performance_schema_events_waits_history_size'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_EVENTS_WAITS_HISTORY_SIZE 15 +select * from information_schema.session_variables +where variable_name='performance_schema_events_waits_history_size'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_EVENTS_WAITS_HISTORY_SIZE 15 +set global performance_schema_events_waits_history_size=1; +ERROR HY000: Variable 'performance_schema_events_waits_history_size' is a read only variable +set session performance_schema_events_waits_history_size=1; +ERROR HY000: Variable 'performance_schema_events_waits_history_size' is a read only variable diff --git a/mysql-test/suite/sys_vars/r/pfs_max_cond_classes_basic.result b/mysql-test/suite/sys_vars/r/pfs_max_cond_classes_basic.result new file mode 100644 index 00000000000..ec980a90cbd --- /dev/null +++ b/mysql-test/suite/sys_vars/r/pfs_max_cond_classes_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema_max_cond_classes; +@@global.performance_schema_max_cond_classes +123 +select @@session.performance_schema_max_cond_classes; +ERROR HY000: Variable 'performance_schema_max_cond_classes' is a GLOBAL variable +show global variables like 'performance_schema_max_cond_classes'; +Variable_name Value +performance_schema_max_cond_classes 123 +show session variables like 'performance_schema_max_cond_classes'; +Variable_name Value +performance_schema_max_cond_classes 123 +select * from information_schema.global_variables +where variable_name='performance_schema_max_cond_classes'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_COND_CLASSES 123 +select * from information_schema.session_variables +where variable_name='performance_schema_max_cond_classes'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_COND_CLASSES 123 +set global performance_schema_max_cond_classes=1; +ERROR HY000: Variable 'performance_schema_max_cond_classes' is a read only variable +set session performance_schema_max_cond_classes=1; +ERROR HY000: Variable 'performance_schema_max_cond_classes' is a read only variable diff --git a/mysql-test/suite/sys_vars/r/pfs_max_cond_instances_basic.result b/mysql-test/suite/sys_vars/r/pfs_max_cond_instances_basic.result new file mode 100644 index 00000000000..5bdb24ed0b8 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/pfs_max_cond_instances_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema_max_cond_instances; +@@global.performance_schema_max_cond_instances +123 +select @@session.performance_schema_max_cond_instances; +ERROR HY000: Variable 'performance_schema_max_cond_instances' is a GLOBAL variable +show global variables like 'performance_schema_max_cond_instances'; +Variable_name Value +performance_schema_max_cond_instances 123 +show session variables like 'performance_schema_max_cond_instances'; +Variable_name Value +performance_schema_max_cond_instances 123 +select * from information_schema.global_variables +where variable_name='performance_schema_max_cond_instances'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_COND_INSTANCES 123 +select * from information_schema.session_variables +where variable_name='performance_schema_max_cond_instances'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_COND_INSTANCES 123 +set global performance_schema_max_cond_instances=1; +ERROR HY000: Variable 'performance_schema_max_cond_instances' is a read only variable +set session performance_schema_max_cond_instances=1; +ERROR HY000: Variable 'performance_schema_max_cond_instances' is a read only variable diff --git a/mysql-test/suite/sys_vars/r/pfs_max_file_classes_basic.result b/mysql-test/suite/sys_vars/r/pfs_max_file_classes_basic.result new file mode 100644 index 00000000000..47eaa449106 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/pfs_max_file_classes_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema_max_file_classes; +@@global.performance_schema_max_file_classes +123 +select @@session.performance_schema_max_file_classes; +ERROR HY000: Variable 'performance_schema_max_file_classes' is a GLOBAL variable +show global variables like 'performance_schema_max_file_classes'; +Variable_name Value +performance_schema_max_file_classes 123 +show session variables like 'performance_schema_max_file_classes'; +Variable_name Value +performance_schema_max_file_classes 123 +select * from information_schema.global_variables +where variable_name='performance_schema_max_file_classes'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_FILE_CLASSES 123 +select * from information_schema.session_variables +where variable_name='performance_schema_max_file_classes'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_FILE_CLASSES 123 +set global performance_schema_max_file_classes=1; +ERROR HY000: Variable 'performance_schema_max_file_classes' is a read only variable +set session performance_schema_max_file_classes=1; +ERROR HY000: Variable 'performance_schema_max_file_classes' is a read only variable diff --git a/mysql-test/suite/sys_vars/r/pfs_max_file_handles_basic.result b/mysql-test/suite/sys_vars/r/pfs_max_file_handles_basic.result new file mode 100644 index 00000000000..7d210ea3103 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/pfs_max_file_handles_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema_max_file_handles; +@@global.performance_schema_max_file_handles +123 +select @@session.performance_schema_max_file_handles; +ERROR HY000: Variable 'performance_schema_max_file_handles' is a GLOBAL variable +show global variables like 'performance_schema_max_file_handles'; +Variable_name Value +performance_schema_max_file_handles 123 +show session variables like 'performance_schema_max_file_handles'; +Variable_name Value +performance_schema_max_file_handles 123 +select * from information_schema.global_variables +where variable_name='performance_schema_max_file_handles'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_FILE_HANDLES 123 +select * from information_schema.session_variables +where variable_name='performance_schema_max_file_handles'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_FILE_HANDLES 123 +set global performance_schema_max_file_handles=1; +ERROR HY000: Variable 'performance_schema_max_file_handles' is a read only variable +set session performance_schema_max_file_handles=1; +ERROR HY000: Variable 'performance_schema_max_file_handles' is a read only variable diff --git a/mysql-test/suite/sys_vars/r/pfs_max_file_instances_basic.result b/mysql-test/suite/sys_vars/r/pfs_max_file_instances_basic.result new file mode 100644 index 00000000000..097d4c14ed1 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/pfs_max_file_instances_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema_max_file_instances; +@@global.performance_schema_max_file_instances +123 +select @@session.performance_schema_max_file_instances; +ERROR HY000: Variable 'performance_schema_max_file_instances' is a GLOBAL variable +show global variables like 'performance_schema_max_file_instances'; +Variable_name Value +performance_schema_max_file_instances 123 +show session variables like 'performance_schema_max_file_instances'; +Variable_name Value +performance_schema_max_file_instances 123 +select * from information_schema.global_variables +where variable_name='performance_schema_max_file_instances'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_FILE_INSTANCES 123 +select * from information_schema.session_variables +where variable_name='performance_schema_max_file_instances'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_FILE_INSTANCES 123 +set global performance_schema_max_file_instances=1; +ERROR HY000: Variable 'performance_schema_max_file_instances' is a read only variable +set session performance_schema_max_file_instances=1; +ERROR HY000: Variable 'performance_schema_max_file_instances' is a read only variable diff --git a/mysql-test/suite/sys_vars/r/pfs_max_mutex_classes_basic.result b/mysql-test/suite/sys_vars/r/pfs_max_mutex_classes_basic.result new file mode 100644 index 00000000000..f2b75ef9540 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/pfs_max_mutex_classes_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema_max_mutex_classes; +@@global.performance_schema_max_mutex_classes +123 +select @@session.performance_schema_max_mutex_classes; +ERROR HY000: Variable 'performance_schema_max_mutex_classes' is a GLOBAL variable +show global variables like 'performance_schema_max_mutex_classes'; +Variable_name Value +performance_schema_max_mutex_classes 123 +show session variables like 'performance_schema_max_mutex_classes'; +Variable_name Value +performance_schema_max_mutex_classes 123 +select * from information_schema.global_variables +where variable_name='performance_schema_max_mutex_classes'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_MUTEX_CLASSES 123 +select * from information_schema.session_variables +where variable_name='performance_schema_max_mutex_classes'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_MUTEX_CLASSES 123 +set global performance_schema_max_mutex_classes=1; +ERROR HY000: Variable 'performance_schema_max_mutex_classes' is a read only variable +set session performance_schema_max_mutex_classes=1; +ERROR HY000: Variable 'performance_schema_max_mutex_classes' is a read only variable diff --git a/mysql-test/suite/sys_vars/r/pfs_max_mutex_instances_basic.result b/mysql-test/suite/sys_vars/r/pfs_max_mutex_instances_basic.result new file mode 100644 index 00000000000..f12fa6ace03 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/pfs_max_mutex_instances_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema_max_mutex_instances; +@@global.performance_schema_max_mutex_instances +123 +select @@session.performance_schema_max_mutex_instances; +ERROR HY000: Variable 'performance_schema_max_mutex_instances' is a GLOBAL variable +show global variables like 'performance_schema_max_mutex_instances'; +Variable_name Value +performance_schema_max_mutex_instances 123 +show session variables like 'performance_schema_max_mutex_instances'; +Variable_name Value +performance_schema_max_mutex_instances 123 +select * from information_schema.global_variables +where variable_name='performance_schema_max_mutex_instances'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_MUTEX_INSTANCES 123 +select * from information_schema.session_variables +where variable_name='performance_schema_max_mutex_instances'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_MUTEX_INSTANCES 123 +set global performance_schema_max_mutex_instances=1; +ERROR HY000: Variable 'performance_schema_max_mutex_instances' is a read only variable +set session performance_schema_max_mutex_instances=1; +ERROR HY000: Variable 'performance_schema_max_mutex_instances' is a read only variable diff --git a/mysql-test/suite/sys_vars/r/pfs_max_rwlock_classes_basic.result b/mysql-test/suite/sys_vars/r/pfs_max_rwlock_classes_basic.result new file mode 100644 index 00000000000..6c2d4b773c0 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/pfs_max_rwlock_classes_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema_max_rwlock_classes; +@@global.performance_schema_max_rwlock_classes +123 +select @@session.performance_schema_max_rwlock_classes; +ERROR HY000: Variable 'performance_schema_max_rwlock_classes' is a GLOBAL variable +show global variables like 'performance_schema_max_rwlock_classes'; +Variable_name Value +performance_schema_max_rwlock_classes 123 +show session variables like 'performance_schema_max_rwlock_classes'; +Variable_name Value +performance_schema_max_rwlock_classes 123 +select * from information_schema.global_variables +where variable_name='performance_schema_max_rwlock_classes'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_RWLOCK_CLASSES 123 +select * from information_schema.session_variables +where variable_name='performance_schema_max_rwlock_classes'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_RWLOCK_CLASSES 123 +set global performance_schema_max_rwlock_classes=1; +ERROR HY000: Variable 'performance_schema_max_rwlock_classes' is a read only variable +set session performance_schema_max_rwlock_classes=1; +ERROR HY000: Variable 'performance_schema_max_rwlock_classes' is a read only variable diff --git a/mysql-test/suite/sys_vars/r/pfs_max_rwlock_instances_basic.result b/mysql-test/suite/sys_vars/r/pfs_max_rwlock_instances_basic.result new file mode 100644 index 00000000000..169387d369d --- /dev/null +++ b/mysql-test/suite/sys_vars/r/pfs_max_rwlock_instances_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema_max_rwlock_instances; +@@global.performance_schema_max_rwlock_instances +123 +select @@session.performance_schema_max_rwlock_instances; +ERROR HY000: Variable 'performance_schema_max_rwlock_instances' is a GLOBAL variable +show global variables like 'performance_schema_max_rwlock_instances'; +Variable_name Value +performance_schema_max_rwlock_instances 123 +show session variables like 'performance_schema_max_rwlock_instances'; +Variable_name Value +performance_schema_max_rwlock_instances 123 +select * from information_schema.global_variables +where variable_name='performance_schema_max_rwlock_instances'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_RWLOCK_INSTANCES 123 +select * from information_schema.session_variables +where variable_name='performance_schema_max_rwlock_instances'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_RWLOCK_INSTANCES 123 +set global performance_schema_max_rwlock_instances=1; +ERROR HY000: Variable 'performance_schema_max_rwlock_instances' is a read only variable +set session performance_schema_max_rwlock_instances=1; +ERROR HY000: Variable 'performance_schema_max_rwlock_instances' is a read only variable diff --git a/mysql-test/suite/sys_vars/r/pfs_max_table_handles_basic.result b/mysql-test/suite/sys_vars/r/pfs_max_table_handles_basic.result new file mode 100644 index 00000000000..5f661b0ecdd --- /dev/null +++ b/mysql-test/suite/sys_vars/r/pfs_max_table_handles_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema_max_table_handles; +@@global.performance_schema_max_table_handles +123 +select @@session.performance_schema_max_table_handles; +ERROR HY000: Variable 'performance_schema_max_table_handles' is a GLOBAL variable +show global variables like 'performance_schema_max_table_handles'; +Variable_name Value +performance_schema_max_table_handles 123 +show session variables like 'performance_schema_max_table_handles'; +Variable_name Value +performance_schema_max_table_handles 123 +select * from information_schema.global_variables +where variable_name='performance_schema_max_table_handles'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_TABLE_HANDLES 123 +select * from information_schema.session_variables +where variable_name='performance_schema_max_table_handles'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_TABLE_HANDLES 123 +set global performance_schema_max_table_handles=1; +ERROR HY000: Variable 'performance_schema_max_table_handles' is a read only variable +set session performance_schema_max_table_handles=1; +ERROR HY000: Variable 'performance_schema_max_table_handles' is a read only variable diff --git a/mysql-test/suite/sys_vars/r/pfs_max_table_instances_basic.result b/mysql-test/suite/sys_vars/r/pfs_max_table_instances_basic.result new file mode 100644 index 00000000000..8497527abb5 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/pfs_max_table_instances_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema_max_table_instances; +@@global.performance_schema_max_table_instances +123 +select @@session.performance_schema_max_table_instances; +ERROR HY000: Variable 'performance_schema_max_table_instances' is a GLOBAL variable +show global variables like 'performance_schema_max_table_instances'; +Variable_name Value +performance_schema_max_table_instances 123 +show session variables like 'performance_schema_max_table_instances'; +Variable_name Value +performance_schema_max_table_instances 123 +select * from information_schema.global_variables +where variable_name='performance_schema_max_table_instances'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_TABLE_INSTANCES 123 +select * from information_schema.session_variables +where variable_name='performance_schema_max_table_instances'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_TABLE_INSTANCES 123 +set global performance_schema_max_table_instances=1; +ERROR HY000: Variable 'performance_schema_max_table_instances' is a read only variable +set session performance_schema_max_table_instances=1; +ERROR HY000: Variable 'performance_schema_max_table_instances' is a read only variable diff --git a/mysql-test/suite/sys_vars/r/pfs_max_thread_classes_basic.result b/mysql-test/suite/sys_vars/r/pfs_max_thread_classes_basic.result new file mode 100644 index 00000000000..9d45e13b46e --- /dev/null +++ b/mysql-test/suite/sys_vars/r/pfs_max_thread_classes_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema_max_thread_classes; +@@global.performance_schema_max_thread_classes +123 +select @@session.performance_schema_max_thread_classes; +ERROR HY000: Variable 'performance_schema_max_thread_classes' is a GLOBAL variable +show global variables like 'performance_schema_max_thread_classes'; +Variable_name Value +performance_schema_max_thread_classes 123 +show session variables like 'performance_schema_max_thread_classes'; +Variable_name Value +performance_schema_max_thread_classes 123 +select * from information_schema.global_variables +where variable_name='performance_schema_max_thread_classes'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_THREAD_CLASSES 123 +select * from information_schema.session_variables +where variable_name='performance_schema_max_thread_classes'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_THREAD_CLASSES 123 +set global performance_schema_max_thread_classes=1; +ERROR HY000: Variable 'performance_schema_max_thread_classes' is a read only variable +set session performance_schema_max_thread_classes=1; +ERROR HY000: Variable 'performance_schema_max_thread_classes' is a read only variable diff --git a/mysql-test/suite/sys_vars/r/pfs_max_thread_instances_basic.result b/mysql-test/suite/sys_vars/r/pfs_max_thread_instances_basic.result new file mode 100644 index 00000000000..dbb3967ad33 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/pfs_max_thread_instances_basic.result @@ -0,0 +1,23 @@ +select @@global.performance_schema_max_thread_instances; +@@global.performance_schema_max_thread_instances +123 +select @@session.performance_schema_max_thread_instances; +ERROR HY000: Variable 'performance_schema_max_thread_instances' is a GLOBAL variable +show global variables like 'performance_schema_max_thread_instances'; +Variable_name Value +performance_schema_max_thread_instances 123 +show session variables like 'performance_schema_max_thread_instances'; +Variable_name Value +performance_schema_max_thread_instances 123 +select * from information_schema.global_variables +where variable_name='performance_schema_max_thread_instances'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_THREAD_INSTANCES 123 +select * from information_schema.session_variables +where variable_name='performance_schema_max_thread_instances'; +VARIABLE_NAME VARIABLE_VALUE +PERFORMANCE_SCHEMA_MAX_THREAD_INSTANCES 123 +set global performance_schema_max_thread_instances=1; +ERROR HY000: Variable 'performance_schema_max_thread_instances' is a read only variable +set session performance_schema_max_thread_instances=1; +ERROR HY000: Variable 'performance_schema_max_thread_instances' is a read only variable diff --git a/mysql-test/suite/sys_vars/t/all_vars.test b/mysql-test/suite/sys_vars/t/all_vars.test index c6c228d842f..6a18b5e3d37 100644 --- a/mysql-test/suite/sys_vars/t/all_vars.test +++ b/mysql-test/suite/sys_vars/t/all_vars.test @@ -1,3 +1,18 @@ +# Copyright (C) 2009-2010 Sun Microsystems, Inc. +# +# 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 + --source include/not_embedded.inc # @@ -20,16 +35,26 @@ perl; EOF create table t1 (test_name text); +create table t2 (variable_name text); --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR eval load data infile "$MYSQLTEST_VARDIR/tmp/sys_vars.all_vars.txt" into table t1; -select variable_name as `There should be *no* variables listed below:` - from information_schema.global_variables - left join t1 on variable_name=test_name where - test_name is null - union -select variable_name from information_schema.session_variables - left join t1 on variable_name=test_name where - test_name is null; +insert into t2 select variable_name from information_schema.global_variables; +insert into t2 select variable_name from information_schema.session_variables; + +# Performance schema variables are too long for files named +# 'mysql-test/suite/sys_vars/t/' ... +# ... 'performance_schema_events_waits_history_long_size_basic-master.opt' +# to fit in the tar source distribution (limit in old tar) +# Renaming the tests to aliases below. + +update t2 set variable_name= replace(variable_name, "PERFORMANCE_SCHEMA_", "PFS_"); + +select variable_name as `There should be *no* long test name listed below:` from t2 + where length(variable_name) > 50; + +select variable_name as `There should be *no* variables listed below:` from t2 + left join t1 on variable_name=test_name where test_name is null; drop table t1; +drop table t2; diff --git a/mysql-test/suite/sys_vars/t/performance_schema_basic-master.opt b/mysql-test/suite/sys_vars/t/performance_schema_basic-master.opt new file mode 100644 index 00000000000..542720c44d7 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/performance_schema_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema diff --git a/mysql-test/suite/sys_vars/t/performance_schema_basic.test b/mysql-test/suite/sys_vars/t/performance_schema_basic.test new file mode 100644 index 00000000000..804e6261921 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/performance_schema_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema; + +show global variables like 'performance_schema'; + +show session variables like 'performance_schema'; + +select * from information_schema.global_variables + where variable_name='performance_schema'; + +select * from information_schema.session_variables + where variable_name='performance_schema'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema=1; + diff --git a/mysql-test/suite/sys_vars/t/pfs_events_waits_history_long_size_basic-master.opt b/mysql-test/suite/sys_vars/t/pfs_events_waits_history_long_size_basic-master.opt new file mode 100644 index 00000000000..ff1dd2a8c05 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_events_waits_history_long_size_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema --loose-performance-schema-events-waits-history-long-size=15000 diff --git a/mysql-test/suite/sys_vars/t/pfs_events_waits_history_long_size_basic.test b/mysql-test/suite/sys_vars/t/pfs_events_waits_history_long_size_basic.test new file mode 100644 index 00000000000..bf6638803bc --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_events_waits_history_long_size_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema_events_waits_history_long_size; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema_events_waits_history_long_size; + +show global variables like 'performance_schema_events_waits_history_long_size'; + +show session variables like 'performance_schema_events_waits_history_long_size'; + +select * from information_schema.global_variables + where variable_name='performance_schema_events_waits_history_long_size'; + +select * from information_schema.session_variables + where variable_name='performance_schema_events_waits_history_long_size'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema_events_waits_history_long_size=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema_events_waits_history_long_size=1; + diff --git a/mysql-test/suite/sys_vars/t/pfs_events_waits_history_size_basic-master.opt b/mysql-test/suite/sys_vars/t/pfs_events_waits_history_size_basic-master.opt new file mode 100644 index 00000000000..488707fc962 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_events_waits_history_size_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema --loose-performance-schema-events-waits-history-size=15 diff --git a/mysql-test/suite/sys_vars/t/pfs_events_waits_history_size_basic.test b/mysql-test/suite/sys_vars/t/pfs_events_waits_history_size_basic.test new file mode 100644 index 00000000000..28338ad1ffd --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_events_waits_history_size_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema_events_waits_history_size; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema_events_waits_history_size; + +show global variables like 'performance_schema_events_waits_history_size'; + +show session variables like 'performance_schema_events_waits_history_size'; + +select * from information_schema.global_variables + where variable_name='performance_schema_events_waits_history_size'; + +select * from information_schema.session_variables + where variable_name='performance_schema_events_waits_history_size'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema_events_waits_history_size=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema_events_waits_history_size=1; + diff --git a/mysql-test/suite/sys_vars/t/pfs_max_cond_classes_basic-master.opt b/mysql-test/suite/sys_vars/t/pfs_max_cond_classes_basic-master.opt new file mode 100644 index 00000000000..438bc463289 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_cond_classes_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema --loose-performance-schema-max-cond-classes=123 diff --git a/mysql-test/suite/sys_vars/t/pfs_max_cond_classes_basic.test b/mysql-test/suite/sys_vars/t/pfs_max_cond_classes_basic.test new file mode 100644 index 00000000000..70a757087f8 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_cond_classes_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema_max_cond_classes; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema_max_cond_classes; + +show global variables like 'performance_schema_max_cond_classes'; + +show session variables like 'performance_schema_max_cond_classes'; + +select * from information_schema.global_variables + where variable_name='performance_schema_max_cond_classes'; + +select * from information_schema.session_variables + where variable_name='performance_schema_max_cond_classes'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema_max_cond_classes=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema_max_cond_classes=1; + diff --git a/mysql-test/suite/sys_vars/t/pfs_max_cond_instances_basic-master.opt b/mysql-test/suite/sys_vars/t/pfs_max_cond_instances_basic-master.opt new file mode 100644 index 00000000000..47b9d629655 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_cond_instances_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema --loose-performance-schema-max-cond-instances=123 diff --git a/mysql-test/suite/sys_vars/t/pfs_max_cond_instances_basic.test b/mysql-test/suite/sys_vars/t/pfs_max_cond_instances_basic.test new file mode 100644 index 00000000000..597ad334295 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_cond_instances_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema_max_cond_instances; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema_max_cond_instances; + +show global variables like 'performance_schema_max_cond_instances'; + +show session variables like 'performance_schema_max_cond_instances'; + +select * from information_schema.global_variables + where variable_name='performance_schema_max_cond_instances'; + +select * from information_schema.session_variables + where variable_name='performance_schema_max_cond_instances'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema_max_cond_instances=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema_max_cond_instances=1; + diff --git a/mysql-test/suite/sys_vars/t/pfs_max_file_classes_basic-master.opt b/mysql-test/suite/sys_vars/t/pfs_max_file_classes_basic-master.opt new file mode 100644 index 00000000000..6ed54f9f99d --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_file_classes_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema --loose-performance-schema-max-file-classes=123 diff --git a/mysql-test/suite/sys_vars/t/pfs_max_file_classes_basic.test b/mysql-test/suite/sys_vars/t/pfs_max_file_classes_basic.test new file mode 100644 index 00000000000..8536a703afa --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_file_classes_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema_max_file_classes; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema_max_file_classes; + +show global variables like 'performance_schema_max_file_classes'; + +show session variables like 'performance_schema_max_file_classes'; + +select * from information_schema.global_variables + where variable_name='performance_schema_max_file_classes'; + +select * from information_schema.session_variables + where variable_name='performance_schema_max_file_classes'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema_max_file_classes=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema_max_file_classes=1; + diff --git a/mysql-test/suite/sys_vars/t/pfs_max_file_handles_basic-master.opt b/mysql-test/suite/sys_vars/t/pfs_max_file_handles_basic-master.opt new file mode 100644 index 00000000000..04633ae0897 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_file_handles_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema --loose-performance-schema-max-file-handles=123 diff --git a/mysql-test/suite/sys_vars/t/pfs_max_file_handles_basic.test b/mysql-test/suite/sys_vars/t/pfs_max_file_handles_basic.test new file mode 100644 index 00000000000..ba702a030d7 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_file_handles_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema_max_file_handles; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema_max_file_handles; + +show global variables like 'performance_schema_max_file_handles'; + +show session variables like 'performance_schema_max_file_handles'; + +select * from information_schema.global_variables + where variable_name='performance_schema_max_file_handles'; + +select * from information_schema.session_variables + where variable_name='performance_schema_max_file_handles'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema_max_file_handles=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema_max_file_handles=1; + diff --git a/mysql-test/suite/sys_vars/t/pfs_max_file_instances_basic-master.opt b/mysql-test/suite/sys_vars/t/pfs_max_file_instances_basic-master.opt new file mode 100644 index 00000000000..078a998c1e7 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_file_instances_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema --loose-performance-schema-max-file-instances=123 diff --git a/mysql-test/suite/sys_vars/t/pfs_max_file_instances_basic.test b/mysql-test/suite/sys_vars/t/pfs_max_file_instances_basic.test new file mode 100644 index 00000000000..829df39bbe9 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_file_instances_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema_max_file_instances; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema_max_file_instances; + +show global variables like 'performance_schema_max_file_instances'; + +show session variables like 'performance_schema_max_file_instances'; + +select * from information_schema.global_variables + where variable_name='performance_schema_max_file_instances'; + +select * from information_schema.session_variables + where variable_name='performance_schema_max_file_instances'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema_max_file_instances=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema_max_file_instances=1; + diff --git a/mysql-test/suite/sys_vars/t/pfs_max_mutex_classes_basic-master.opt b/mysql-test/suite/sys_vars/t/pfs_max_mutex_classes_basic-master.opt new file mode 100644 index 00000000000..1525916a1ef --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_mutex_classes_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema --loose-performance-schema-max-mutex-classes=123 diff --git a/mysql-test/suite/sys_vars/t/pfs_max_mutex_classes_basic.test b/mysql-test/suite/sys_vars/t/pfs_max_mutex_classes_basic.test new file mode 100644 index 00000000000..633d1a3487c --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_mutex_classes_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema_max_mutex_classes; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema_max_mutex_classes; + +show global variables like 'performance_schema_max_mutex_classes'; + +show session variables like 'performance_schema_max_mutex_classes'; + +select * from information_schema.global_variables + where variable_name='performance_schema_max_mutex_classes'; + +select * from information_schema.session_variables + where variable_name='performance_schema_max_mutex_classes'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema_max_mutex_classes=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema_max_mutex_classes=1; + diff --git a/mysql-test/suite/sys_vars/t/pfs_max_mutex_instances_basic-master.opt b/mysql-test/suite/sys_vars/t/pfs_max_mutex_instances_basic-master.opt new file mode 100644 index 00000000000..98ce2ff3df9 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_mutex_instances_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema --loose-performance-schema-max-mutex-instances=123 diff --git a/mysql-test/suite/sys_vars/t/pfs_max_mutex_instances_basic.test b/mysql-test/suite/sys_vars/t/pfs_max_mutex_instances_basic.test new file mode 100644 index 00000000000..2a8f5e5ae00 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_mutex_instances_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema_max_mutex_instances; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema_max_mutex_instances; + +show global variables like 'performance_schema_max_mutex_instances'; + +show session variables like 'performance_schema_max_mutex_instances'; + +select * from information_schema.global_variables + where variable_name='performance_schema_max_mutex_instances'; + +select * from information_schema.session_variables + where variable_name='performance_schema_max_mutex_instances'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema_max_mutex_instances=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema_max_mutex_instances=1; + diff --git a/mysql-test/suite/sys_vars/t/pfs_max_rwlock_classes_basic-master.opt b/mysql-test/suite/sys_vars/t/pfs_max_rwlock_classes_basic-master.opt new file mode 100644 index 00000000000..b5d5318635f --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_rwlock_classes_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema --loose-performance-schema-max-rwlock-classes=123 diff --git a/mysql-test/suite/sys_vars/t/pfs_max_rwlock_classes_basic.test b/mysql-test/suite/sys_vars/t/pfs_max_rwlock_classes_basic.test new file mode 100644 index 00000000000..ce911b60049 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_rwlock_classes_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema_max_rwlock_classes; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema_max_rwlock_classes; + +show global variables like 'performance_schema_max_rwlock_classes'; + +show session variables like 'performance_schema_max_rwlock_classes'; + +select * from information_schema.global_variables + where variable_name='performance_schema_max_rwlock_classes'; + +select * from information_schema.session_variables + where variable_name='performance_schema_max_rwlock_classes'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema_max_rwlock_classes=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema_max_rwlock_classes=1; + diff --git a/mysql-test/suite/sys_vars/t/pfs_max_rwlock_instances_basic-master.opt b/mysql-test/suite/sys_vars/t/pfs_max_rwlock_instances_basic-master.opt new file mode 100644 index 00000000000..5dcecd99c0a --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_rwlock_instances_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema --loose-performance-schema-max-rwlock-instances=123 diff --git a/mysql-test/suite/sys_vars/t/pfs_max_rwlock_instances_basic.test b/mysql-test/suite/sys_vars/t/pfs_max_rwlock_instances_basic.test new file mode 100644 index 00000000000..d16c1c46f68 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_rwlock_instances_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema_max_rwlock_instances; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema_max_rwlock_instances; + +show global variables like 'performance_schema_max_rwlock_instances'; + +show session variables like 'performance_schema_max_rwlock_instances'; + +select * from information_schema.global_variables + where variable_name='performance_schema_max_rwlock_instances'; + +select * from information_schema.session_variables + where variable_name='performance_schema_max_rwlock_instances'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema_max_rwlock_instances=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema_max_rwlock_instances=1; + diff --git a/mysql-test/suite/sys_vars/t/pfs_max_table_handles_basic-master.opt b/mysql-test/suite/sys_vars/t/pfs_max_table_handles_basic-master.opt new file mode 100644 index 00000000000..45e73c51f8c --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_table_handles_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema --loose-performance-schema-max-table-handles=123 diff --git a/mysql-test/suite/sys_vars/t/pfs_max_table_handles_basic.test b/mysql-test/suite/sys_vars/t/pfs_max_table_handles_basic.test new file mode 100644 index 00000000000..3ede0985a70 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_table_handles_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema_max_table_handles; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema_max_table_handles; + +show global variables like 'performance_schema_max_table_handles'; + +show session variables like 'performance_schema_max_table_handles'; + +select * from information_schema.global_variables + where variable_name='performance_schema_max_table_handles'; + +select * from information_schema.session_variables + where variable_name='performance_schema_max_table_handles'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema_max_table_handles=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema_max_table_handles=1; + diff --git a/mysql-test/suite/sys_vars/t/pfs_max_table_instances_basic-master.opt b/mysql-test/suite/sys_vars/t/pfs_max_table_instances_basic-master.opt new file mode 100644 index 00000000000..b8b0ba4b40b --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_table_instances_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema --loose-performance-schema-max-table-instances=123 diff --git a/mysql-test/suite/sys_vars/t/pfs_max_table_instances_basic.test b/mysql-test/suite/sys_vars/t/pfs_max_table_instances_basic.test new file mode 100644 index 00000000000..fcd4886ca22 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_table_instances_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema_max_table_instances; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema_max_table_instances; + +show global variables like 'performance_schema_max_table_instances'; + +show session variables like 'performance_schema_max_table_instances'; + +select * from information_schema.global_variables + where variable_name='performance_schema_max_table_instances'; + +select * from information_schema.session_variables + where variable_name='performance_schema_max_table_instances'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema_max_table_instances=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema_max_table_instances=1; + diff --git a/mysql-test/suite/sys_vars/t/pfs_max_thread_classes_basic-master.opt b/mysql-test/suite/sys_vars/t/pfs_max_thread_classes_basic-master.opt new file mode 100644 index 00000000000..c0b64e5889a --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_thread_classes_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema --loose-performance-schema-max-thread-classes=123 diff --git a/mysql-test/suite/sys_vars/t/pfs_max_thread_classes_basic.test b/mysql-test/suite/sys_vars/t/pfs_max_thread_classes_basic.test new file mode 100644 index 00000000000..4704e87cf06 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_thread_classes_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema_max_thread_classes; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema_max_thread_classes; + +show global variables like 'performance_schema_max_thread_classes'; + +show session variables like 'performance_schema_max_thread_classes'; + +select * from information_schema.global_variables + where variable_name='performance_schema_max_thread_classes'; + +select * from information_schema.session_variables + where variable_name='performance_schema_max_thread_classes'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema_max_thread_classes=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema_max_thread_classes=1; + diff --git a/mysql-test/suite/sys_vars/t/pfs_max_thread_instances_basic-master.opt b/mysql-test/suite/sys_vars/t/pfs_max_thread_instances_basic-master.opt new file mode 100644 index 00000000000..b70eda8acb1 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_thread_instances_basic-master.opt @@ -0,0 +1 @@ +--loose-enable-performance-schema --loose-performance-schema-max-thread-instances=123 diff --git a/mysql-test/suite/sys_vars/t/pfs_max_thread_instances_basic.test b/mysql-test/suite/sys_vars/t/pfs_max_thread_instances_basic.test new file mode 100644 index 00000000000..d709c097f20 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/pfs_max_thread_instances_basic.test @@ -0,0 +1,47 @@ +# Copyright (C) 2010 Sun Microsystems, Inc. +# +# 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 + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +# +# Only global +# + +select @@global.performance_schema_max_thread_instances; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.performance_schema_max_thread_instances; + +show global variables like 'performance_schema_max_thread_instances'; + +show session variables like 'performance_schema_max_thread_instances'; + +select * from information_schema.global_variables + where variable_name='performance_schema_max_thread_instances'; + +select * from information_schema.session_variables + where variable_name='performance_schema_max_thread_instances'; + +# +# Read-only +# + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set global performance_schema_max_thread_instances=1; + +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +set session performance_schema_max_thread_instances=1; + diff --git a/mysys/my_init.c b/mysys/my_init.c index 8145dc6fb6a..31adc5ed99e 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -600,7 +600,7 @@ PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock, key_THR_LOCK_isam, key_THR_LOCK_lock, key_THR_LOCK_malloc, key_THR_LOCK_mutex, key_THR_LOCK_myisam, key_THR_LOCK_net, key_THR_LOCK_open, key_THR_LOCK_threads, key_THR_LOCK_time, - key_TMPDIR_mutex; + key_TMPDIR_mutex, key_THR_LOCK_myisam_mmap; static PSI_mutex_info all_mysys_mutexes[]= { @@ -630,7 +630,8 @@ static PSI_mutex_info all_mysys_mutexes[]= { &key_THR_LOCK_open, "THR_LOCK_open", PSI_FLAG_GLOBAL}, { &key_THR_LOCK_threads, "THR_LOCK_threads", PSI_FLAG_GLOBAL}, { &key_THR_LOCK_time, "THR_LOCK_time", PSI_FLAG_GLOBAL}, - { &key_TMPDIR_mutex, "TMPDIR_mutex", PSI_FLAG_GLOBAL} + { &key_TMPDIR_mutex, "TMPDIR_mutex", PSI_FLAG_GLOBAL}, + { &key_THR_LOCK_myisam_mmap, "THR_LOCK_myisam_mmap", PSI_FLAG_GLOBAL} }; PSI_cond_key key_COND_alarm, key_IO_CACHE_SHARE_cond, diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index a06bbb64c8b..83d35863eca 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -24,8 +24,8 @@ #ifdef THREAD pthread_key(struct st_my_thread_var*, THR_KEY_mysys); -mysql_mutex_t THR_LOCK_malloc,THR_LOCK_open, - THR_LOCK_lock,THR_LOCK_isam,THR_LOCK_myisam,THR_LOCK_heap, +mysql_mutex_t THR_LOCK_malloc, THR_LOCK_open, + THR_LOCK_lock, THR_LOCK_isam, THR_LOCK_myisam, THR_LOCK_heap, THR_LOCK_net, THR_LOCK_charset, THR_LOCK_threads, THR_LOCK_time, THR_LOCK_myisam_mmap; diff --git a/mysys/mysys_priv.h b/mysys/mysys_priv.h index 3a663dfefbf..1f84d8d3aab 100644 --- a/mysys/mysys_priv.h +++ b/mysys/mysys_priv.h @@ -47,7 +47,7 @@ extern PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock, key_THR_LOCK_isam, key_THR_LOCK_lock, key_THR_LOCK_malloc, key_THR_LOCK_mutex, key_THR_LOCK_myisam, key_THR_LOCK_net, key_THR_LOCK_open, key_THR_LOCK_threads, key_THR_LOCK_time, - key_TMPDIR_mutex; + key_TMPDIR_mutex, key_THR_LOCK_myisam_mmap; extern PSI_cond_key key_COND_alarm, key_IO_CACHE_SHARE_cond, key_IO_CACHE_SHARE_cond_writer, key_my_thread_var_suspend, diff --git a/sql/authors.h b/sql/authors.h index ec46e368f5f..555fe2ae43a 100644 --- a/sql/authors.h +++ b/sql/authors.h @@ -39,7 +39,7 @@ struct show_table_authors_st { struct show_table_authors_st show_table_authors[]= { { "Brian (Krow) Aker", "Seattle, WA, USA", "Architecture, archive, federated, bunch of little stuff :)" }, - { "Marc Alff", "Denver, CO, USA", "Signal, Resignal" }, + { "Marc Alff", "Denver, CO, USA", "Signal, Resignal, Performance schema" }, { "Venu Anuganti", "", "Client/server protocol (4.1)" }, { "David Axmark", "Uppsala, Sweden", "Small stuff long time ago, Monty ripped it out!" }, diff --git a/sql/derror.cc b/sql/derror.cc index 95481e3212f..8e47dda7bbe 100644 --- a/sql/derror.cc +++ b/sql/derror.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2005 MySQL AB +/* Copyright (C) 2000-2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -107,10 +107,10 @@ bool read_texts(const char *file_name, const char *language, funktpos=0; convert_dirname(lang_path, language, NullS); (void) my_load_path(lang_path, lang_path, lc_messages_dir); - if ((file=my_open(fn_format(name,file_name, - lang_path, "", 4), - O_RDONLY | O_SHARE | O_BINARY, - MYF(0))) < 0) + if ((file= mysql_file_open(key_file_ERRMSG, + fn_format(name, file_name, lang_path, "", 4), + O_RDONLY | O_SHARE | O_BINARY, + MYF(0))) < 0) { /* Trying pre-5.4 sematics of the --language parameter. @@ -118,16 +118,18 @@ bool read_texts(const char *file_name, const char *language, --language=/path/to/english/ */ - if ((file= my_open(fn_format(name, file_name, lc_messages_dir, "", 4), - O_RDONLY | O_SHARE | O_BINARY, - MYF(0))) < 0) + if ((file= mysql_file_open(key_file_ERRMSG, + fn_format(name, file_name, lc_messages_dir, "", 4), + O_RDONLY | O_SHARE | O_BINARY, + MYF(0))) < 0) goto err; sql_print_error("An old style --language value with language specific part detected: %s", lc_messages_dir); sql_print_error("Use --lc-messages-dir without language specific part instead."); } funktpos=1; - if (my_read(file,(uchar*) head,32,MYF(MY_NABP))) goto err; + if (mysql_file_read(file, (uchar*) head, 32, MYF(MY_NABP))) + goto err; if (head[0] != (uchar) 254 || head[1] != (uchar) 254 || head[2] != 2 || head[3] != 1) goto err; /* purecov: inspected */ @@ -143,7 +145,7 @@ Error message file '%s' had only %d error messages,\n\ but it should contain at least %d error messages.\n\ Check that the above file is the right version for this program!", name,count,error_messages); - (void) my_close(file,MYF(MY_WME)); + (void) mysql_file_close(file, MYF(MY_WME)); DBUG_RETURN(1); } @@ -156,21 +158,21 @@ Check that the above file is the right version for this program!", } buff= (uchar*) (*point + count); - if (my_read(file, buff, (size_t) count*2,MYF(MY_NABP))) + if (mysql_file_read(file, buff, (size_t) count*2, MYF(MY_NABP))) goto err; for (i=0, pos= buff ; i< count ; i++) { (*point)[i]= (char*) buff+uint2korr(pos); pos+=2; } - if (my_read(file, buff, length, MYF(MY_NABP))) + if (mysql_file_read(file, buff, length, MYF(MY_NABP))) goto err; for (i=1 ; i < textcount ; i++) { point[i]= *point +uint2korr(head+10+i+i); } - (void) my_close(file,MYF(0)); + (void) mysql_file_close(file, MYF(0)); DBUG_RETURN(0); err: @@ -187,7 +189,7 @@ err: } sql_print_error(errmsg, name); if (file != FERR) - (void) my_close(file,MYF(MY_WME)); + (void) mysql_file_close(file, MYF(MY_WME)); DBUG_RETURN(1); } /* read_texts */ diff --git a/sql/des_key_file.cc b/sql/des_key_file.cc index 87ad6ff12b0..c2b632e521b 100644 --- a/sql/des_key_file.cc +++ b/sql/des_key_file.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2003, 2005 MySQL AB +/* Copyright (C) 2001-2003, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -43,8 +43,9 @@ load_des_key_file(const char *file_name) DBUG_ENTER("load_des_key_file"); DBUG_PRINT("enter",("name: %s",file_name)); - pthread_mutex_lock(&LOCK_des_key_file); - if ((file=my_open(file_name,O_RDONLY | O_BINARY ,MYF(MY_WME))) < 0 || + mysql_mutex_lock(&LOCK_des_key_file); + if ((file= mysql_file_open(key_file_des_key_file, file_name, + O_RDONLY | O_BINARY, MYF(MY_WME))) < 0 || init_io_cache(&io, file, IO_SIZE*2, READ_CACHE, 0, 0, MYF(MY_WME))) goto error; @@ -93,10 +94,10 @@ load_des_key_file(const char *file_name) error: if (file >= 0) { - my_close(file,MYF(0)); + mysql_file_close(file, MYF(0)); end_io_cache(&io); } - pthread_mutex_unlock(&LOCK_des_key_file); + mysql_mutex_unlock(&LOCK_des_key_file); DBUG_RETURN(result); } #endif /* HAVE_OPENSSL */ diff --git a/sql/discover.cc b/sql/discover.cc index f475cfbf72a..fcc26042fe2 100644 --- a/sql/discover.cc +++ b/sql/discover.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2004 MySQL AB +/* Copyright (C) 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -57,15 +57,16 @@ int readfrm(const char *name, uchar **frmdata, size_t *len) *frmdata= NULL; // In case of errors *len= 0; error= 1; - if ((file=my_open(fn_format(index_file,name,"",reg_ext, - MY_UNPACK_FILENAME|MY_APPEND_EXT), - O_RDONLY | O_SHARE, - MYF(0))) < 0) + if ((file= mysql_file_open(key_file_frm, + fn_format(index_file, name, "", reg_ext, + MY_UNPACK_FILENAME|MY_APPEND_EXT), + O_RDONLY | O_SHARE, + MYF(0))) < 0) goto err_end; // Get length of file error= 2; - if (my_fstat(file, &state, MYF(0))) + if (mysql_file_fstat(file, &state, MYF(0))) goto err; read_len= state.st_size; @@ -82,7 +83,7 @@ int readfrm(const char *name, uchar **frmdata, size_t *len) err: if (file > 0) - (void) my_close(file,MYF(MY_WME)); + (void) mysql_file_close(file, MYF(MY_WME)); err_end: /* Here when no file */ DBUG_RETURN (error); @@ -112,13 +113,15 @@ int writefrm(const char *name, const uchar *frmdata, size_t len) DBUG_PRINT("enter",("name: '%s' len: %lu ",name, (ulong) len)); error= 0; - if ((file=my_create(fn_format(index_file,name,"",reg_ext, - MY_UNPACK_FILENAME|MY_APPEND_EXT), - CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0) + if ((file= mysql_file_create(key_file_frm, + fn_format(index_file, name, "", reg_ext, + MY_UNPACK_FILENAME | MY_APPEND_EXT), + CREATE_MODE, O_RDWR | O_TRUNC, + MYF(MY_WME))) >= 0) { - if (my_write(file, frmdata, len,MYF(MY_WME | MY_NABP))) + if (mysql_file_write(file, frmdata, len, MYF(MY_WME | MY_NABP))) error= 2; - (void) my_close(file,MYF(0)); + (void) mysql_file_close(file, MYF(0)); } DBUG_RETURN(error); } /* writefrm */ diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc index b2bbd340e14..fd9561eb132 100644 --- a/sql/event_data_objects.cc +++ b/sql/event_data_objects.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2006 MySQL AB +/* Copyright (C) 2004-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -1402,8 +1402,7 @@ Event_job_data::execute(THD *thd, bool drop) } #endif - if (check_access(thd, EVENT_ACL, dbname.str, - 0, 0, 0, is_schema_db(dbname.str))) + if (check_access(thd, EVENT_ACL, dbname.str, NULL, NULL, 0, 0)) { /* This aspect of behavior is defined in the worklog, diff --git a/sql/event_queue.cc b/sql/event_queue.cc index 04d4f858b43..7d987db411a 100644 --- a/sql/event_queue.cc +++ b/sql/event_queue.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2006 MySQL AB +/* Copyright (C) 2004-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -94,16 +94,16 @@ Event_queue::Event_queue() mutex_queue_data_attempting_lock(FALSE), waiting_on_cond(FALSE) { - pthread_mutex_init(&LOCK_event_queue, MY_MUTEX_INIT_FAST); - pthread_cond_init(&COND_queue_state, NULL); + mysql_mutex_init(key_LOCK_event_queue, &LOCK_event_queue, MY_MUTEX_INIT_FAST); + mysql_cond_init(key_COND_queue_state, &COND_queue_state, NULL); } Event_queue::~Event_queue() { deinit_queue(); - pthread_mutex_destroy(&LOCK_event_queue); - pthread_cond_destroy(&COND_queue_state); + mysql_mutex_destroy(&LOCK_event_queue); + mysql_cond_destroy(&COND_queue_state); } @@ -210,7 +210,7 @@ Event_queue::create_event(THD *thd, Event_queue_element *new_element, LOCK_QUEUE_DATA(); *created= (queue_insert_safe(&queue, (uchar *) new_element) == FALSE); dbug_dump_queue(thd->query_start()); - pthread_cond_broadcast(&COND_queue_state); + mysql_cond_broadcast(&COND_queue_state); UNLOCK_QUEUE_DATA(); DBUG_RETURN(!*created); @@ -258,7 +258,7 @@ Event_queue::update_event(THD *thd, LEX_STRING dbname, LEX_STRING name, { DBUG_PRINT("info", ("new event in the queue: 0x%lx", (long) new_element)); queue_insert_safe(&queue, (uchar *) new_element); - pthread_cond_broadcast(&COND_queue_state); + mysql_cond_broadcast(&COND_queue_state); } dbug_dump_queue(thd->query_start()); @@ -669,7 +669,7 @@ Event_queue::lock_data(const char *func, uint line) mutex_last_attempted_lock_in_func= func; mutex_last_attempted_lock_at_line= line; mutex_queue_data_attempting_lock= TRUE; - pthread_mutex_lock(&LOCK_event_queue); + mysql_mutex_lock(&LOCK_event_queue); mutex_last_attempted_lock_in_func= ""; mutex_last_attempted_lock_at_line= 0; mutex_queue_data_attempting_lock= FALSE; @@ -700,7 +700,7 @@ Event_queue::unlock_data(const char *func, uint line) mutex_last_unlocked_at_line= line; mutex_queue_data_locked= FALSE; mutex_last_unlocked_in_func= func; - pthread_mutex_unlock(&LOCK_event_queue); + mysql_mutex_unlock(&LOCK_event_queue); DBUG_VOID_RETURN; } @@ -731,9 +731,9 @@ Event_queue::cond_wait(THD *thd, struct timespec *abstime, const char* msg, DBUG_PRINT("info", ("pthread_cond_%swait", abstime? "timed":"")); if (!abstime) - pthread_cond_wait(&COND_queue_state, &LOCK_event_queue); + mysql_cond_wait(&COND_queue_state, &LOCK_event_queue); else - pthread_cond_timedwait(&COND_queue_state, &LOCK_event_queue, abstime); + mysql_cond_timedwait(&COND_queue_state, &LOCK_event_queue, abstime); mutex_last_locked_in_func= func; mutex_last_locked_at_line= line; diff --git a/sql/event_queue.h b/sql/event_queue.h index 2870ecb4d0b..aac9eb04e98 100644 --- a/sql/event_queue.h +++ b/sql/event_queue.h @@ -1,6 +1,6 @@ #ifndef _EVENT_QUEUE_H_ #define _EVENT_QUEUE_H_ -/* Copyright (C) 2004-2006 MySQL AB +/* Copyright (C) 2004-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -25,6 +25,11 @@ Queue of events awaiting execution. */ +#ifdef HAVE_PSI_INTERFACE +extern PSI_mutex_key key_LOCK_event_queue; +extern PSI_cond_key key_COND_queue_state; +#endif /* HAVE_PSI_INTERFACE */ + class Event_basic; class Event_queue_element; class Event_queue_element_for_exec; @@ -101,8 +106,8 @@ private: dbug_dump_queue(time_t now); /* LOCK_event_queue is the mutex which protects the access to the queue. */ - pthread_mutex_t LOCK_event_queue; - pthread_cond_t COND_queue_state; + mysql_mutex_t LOCK_event_queue; + mysql_cond_t COND_queue_state; /* The sorted queue with the Event_queue_element objects */ QUEUE queue; diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc index 00d03e04b70..486b03fc58e 100644 --- a/sql/event_scheduler.cc +++ b/sql/event_scheduler.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2006 MySQL AB +/* Copyright (C) 2004-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -163,7 +163,7 @@ deinit_event_thread(THD *thd) /* - Performs pre- pthread_create() initialisation of THD. Do this + Performs pre- mysql_thread_create() initialisation of THD. Do this in the thread that will pass THD to the child thread. In the child thread call post_init_event_thread(). @@ -227,6 +227,9 @@ event_scheduler_thread(void *arg) bool res; thd->thread_stack= (char *)&thd; // remember where our stack is + + mysql_thread_set_psi_id(thd->thread_id); + res= post_init_event_thread(thd); DBUG_ENTER("event_scheduler_thread"); @@ -259,6 +262,8 @@ event_worker_thread(void *arg) thd= event->thd; + mysql_thread_set_psi_id(thd->thread_id); + Event_worker_thread worker_thread; worker_thread.run(thd, event); @@ -335,16 +340,17 @@ Event_scheduler::Event_scheduler(Event_queue *queue_arg) waiting_on_cond(FALSE), started_events(0) { - pthread_mutex_init(&LOCK_scheduler_state, MY_MUTEX_INIT_FAST); - pthread_cond_init(&COND_state, NULL); + mysql_mutex_init(key_event_scheduler_LOCK_scheduler_state, + &LOCK_scheduler_state, MY_MUTEX_INIT_FAST); + mysql_cond_init(key_event_scheduler_COND_state, &COND_state, NULL); } Event_scheduler::~Event_scheduler() { stop(); /* does nothing if not running */ - pthread_mutex_destroy(&LOCK_scheduler_state); - pthread_cond_destroy(&COND_state); + mysql_mutex_destroy(&LOCK_scheduler_state); + mysql_cond_destroy(&COND_state); } @@ -403,8 +409,9 @@ Event_scheduler::start() DBUG_PRINT("info", ("Setting state go RUNNING")); state= RUNNING; DBUG_PRINT("info", ("Forking new thread for scheduler. THD: 0x%lx", (long) new_thd)); - if (pthread_create(&th, &connection_attrib, event_scheduler_thread, - (void*)scheduler_param_value)) + if (mysql_thread_create(key_thread_event_scheduler, + &th, &connection_attrib, event_scheduler_thread, + (void*)scheduler_param_value)) { DBUG_PRINT("error", ("cannot create a new thread")); state= INITIALIZED; @@ -487,7 +494,7 @@ Event_scheduler::run(THD *thd) scheduler_thd= NULL; state= INITIALIZED; DBUG_PRINT("info", ("Signalling back to the stopper COND_state")); - pthread_cond_signal(&COND_state); + mysql_cond_signal(&COND_state); UNLOCK_DATA(); DBUG_RETURN(res); @@ -531,8 +538,9 @@ Event_scheduler::execute_top(Event_queue_element_for_exec *event_name) reasonable level. */ /* Major failure */ - if ((res= pthread_create(&th, &connection_attrib, event_worker_thread, - event_name))) + if ((res= mysql_thread_create(key_thread_event_worker, + &th, &connection_attrib, event_worker_thread, + event_name))) goto error; ++started_events; @@ -632,13 +640,13 @@ Event_scheduler::stop() DBUG_PRINT("info", ("Scheduler thread has id %lu", scheduler_thd->thread_id)); /* Lock from delete */ - pthread_mutex_lock(&scheduler_thd->LOCK_thd_data); + mysql_mutex_lock(&scheduler_thd->LOCK_thd_data); /* This will wake up the thread if it waits on Queue's conditional */ sql_print_information("Event Scheduler: Killing the scheduler thread, " "thread id %lu", scheduler_thd->thread_id); scheduler_thd->awake(THD::KILL_CONNECTION); - pthread_mutex_unlock(&scheduler_thd->LOCK_thd_data); + mysql_mutex_unlock(&scheduler_thd->LOCK_thd_data); /* thd could be 0x0, when shutting down */ sql_print_information("Event Scheduler: " @@ -693,7 +701,7 @@ Event_scheduler::lock_data(const char *func, uint line) { DBUG_ENTER("Event_scheduler::lock_data"); DBUG_PRINT("enter", ("func=%s line=%u", func, line)); - pthread_mutex_lock(&LOCK_scheduler_state); + mysql_mutex_lock(&LOCK_scheduler_state); mutex_last_locked_in_func= func; mutex_last_locked_at_line= line; mutex_scheduler_data_locked= TRUE; @@ -719,7 +727,7 @@ Event_scheduler::unlock_data(const char *func, uint line) mutex_last_unlocked_at_line= line; mutex_scheduler_data_locked= FALSE; mutex_last_unlocked_in_func= func; - pthread_mutex_unlock(&LOCK_scheduler_state); + mysql_mutex_unlock(&LOCK_scheduler_state); DBUG_VOID_RETURN; } @@ -750,9 +758,9 @@ Event_scheduler::cond_wait(THD *thd, struct timespec *abstime, const char* msg, DBUG_PRINT("info", ("pthread_cond_%swait", abstime? "timed":"")); if (!abstime) - pthread_cond_wait(&COND_state, &LOCK_scheduler_state); + mysql_cond_wait(&COND_state, &LOCK_scheduler_state); else - pthread_cond_timedwait(&COND_state, &LOCK_scheduler_state, abstime); + mysql_cond_timedwait(&COND_state, &LOCK_scheduler_state, abstime); if (thd) { /* diff --git a/sql/event_scheduler.h b/sql/event_scheduler.h index 0be93a65d33..2988f354f63 100644 --- a/sql/event_scheduler.h +++ b/sql/event_scheduler.h @@ -1,6 +1,6 @@ #ifndef _EVENT_SCHEDULER_H_ #define _EVENT_SCHEDULER_H_ -/* Copyright (C) 2004-2006 MySQL AB +/* Copyright (C) 2004-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -115,7 +115,7 @@ private: cond_wait(THD *thd, struct timespec *abstime, const char* msg, const char *func, uint line); - pthread_mutex_t LOCK_scheduler_state; + mysql_mutex_t LOCK_scheduler_state; enum enum_state { @@ -129,7 +129,7 @@ private: THD *scheduler_thd; - pthread_cond_t COND_state; + mysql_cond_t COND_state; Event_queue *queue; diff --git a/sql/events.cc b/sql/events.cc index b0803ab57d0..8b81fa7951d 100644 --- a/sql/events.cc +++ b/sql/events.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2006 MySQL AB +/* Copyright (C) 2004-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -68,7 +68,7 @@ Event_queue *Events::event_queue; Event_scheduler *Events::scheduler; Event_db_repository *Events::db_repository; uint Events::opt_event_scheduler= Events::EVENTS_OFF; -pthread_mutex_t Events::LOCK_event_metadata; +mysql_mutex_t Events::LOCK_event_metadata; bool Events::check_system_tables_error= FALSE; @@ -319,8 +319,7 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, /* At create, one of them must be set */ DBUG_ASSERT(parse_data->expression || parse_data->execute_at); - if (check_access(thd, EVENT_ACL, parse_data->dbname.str, 0, 0, 0, - is_schema_db(parse_data->dbname.str))) + if (check_access(thd, EVENT_ACL, parse_data->dbname.str, NULL, NULL, 0, 0)) DBUG_RETURN(TRUE); if (check_db_dir_existence(parse_data->dbname.str)) @@ -338,7 +337,7 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, if (thd->current_stmt_binlog_row_based) thd->clear_current_stmt_binlog_row_based(); - pthread_mutex_lock(&LOCK_event_metadata); + mysql_mutex_lock(&LOCK_event_metadata); /* On error conditions my_error() is called so no need to handle here */ if (!(ret= db_repository->create_event(thd, parse_data, if_not_exists))) @@ -383,7 +382,7 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, ret= write_bin_log(thd, TRUE, log_query.c_ptr(), log_query.length()); } } - pthread_mutex_unlock(&LOCK_event_metadata); + mysql_mutex_unlock(&LOCK_event_metadata); DBUG_RETURN(ret); } @@ -430,8 +429,7 @@ Events::update_event(THD *thd, Event_parse_data *parse_data, if (parse_data->check_parse_data(thd) || parse_data->do_not_create) DBUG_RETURN(TRUE); - if (check_access(thd, EVENT_ACL, parse_data->dbname.str, 0, 0, 0, - is_schema_db(parse_data->dbname.str))) + if (check_access(thd, EVENT_ACL, parse_data->dbname.str, NULL, NULL, 0, 0)) DBUG_RETURN(TRUE); if (new_dbname) /* It's a rename */ @@ -452,8 +450,7 @@ Events::update_event(THD *thd, Event_parse_data *parse_data, to tell the user that a database doesn't exist if they can not access it. */ - if (check_access(thd, EVENT_ACL, new_dbname->str, 0, 0, 0, - is_schema_db(new_dbname->str))) + if (check_access(thd, EVENT_ACL, new_dbname->str, NULL, NULL, 0, 0)) DBUG_RETURN(TRUE); /* Check that the target database exists */ @@ -471,7 +468,7 @@ Events::update_event(THD *thd, Event_parse_data *parse_data, if (thd->current_stmt_binlog_row_based) thd->clear_current_stmt_binlog_row_based(); - pthread_mutex_lock(&LOCK_event_metadata); + mysql_mutex_lock(&LOCK_event_metadata); /* On error conditions my_error() is called so no need to handle here */ if (!(ret= db_repository->update_event(thd, parse_data, @@ -504,7 +501,7 @@ Events::update_event(THD *thd, Event_parse_data *parse_data, ret= write_bin_log(thd, TRUE, thd->query(), thd->query_length()); } } - pthread_mutex_unlock(&LOCK_event_metadata); + mysql_mutex_unlock(&LOCK_event_metadata); DBUG_RETURN(ret); } @@ -557,8 +554,7 @@ Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists) if (check_if_system_tables_error()) DBUG_RETURN(TRUE); - if (check_access(thd, EVENT_ACL, dbname.str, 0, 0, 0, - is_schema_db(dbname.str))) + if (check_access(thd, EVENT_ACL, dbname.str, NULL, NULL, 0, 0)) DBUG_RETURN(TRUE); /* @@ -568,7 +564,7 @@ Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists) if (thd->current_stmt_binlog_row_based) thd->clear_current_stmt_binlog_row_based(); - pthread_mutex_lock(&LOCK_event_metadata); + mysql_mutex_lock(&LOCK_event_metadata); /* On error conditions my_error() is called so no need to handle here */ if (!(ret= db_repository->drop_event(thd, dbname, name, if_exists))) { @@ -578,7 +574,7 @@ Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists) DBUG_ASSERT(thd->query() && thd->query_length()); ret= write_bin_log(thd, TRUE, thd->query(), thd->query_length()); } - pthread_mutex_unlock(&LOCK_event_metadata); + mysql_mutex_unlock(&LOCK_event_metadata); DBUG_RETURN(ret); } @@ -607,11 +603,11 @@ Events::drop_schema_events(THD *thd, char *db) are damaged, as intended. */ - pthread_mutex_lock(&LOCK_event_metadata); + mysql_mutex_lock(&LOCK_event_metadata); if (event_queue) event_queue->drop_schema_events(thd, db_lex); db_repository->drop_schema_events(thd, db_lex); - pthread_mutex_unlock(&LOCK_event_metadata); + mysql_mutex_unlock(&LOCK_event_metadata); DBUG_VOID_RETURN; } @@ -714,8 +710,7 @@ Events::show_create_event(THD *thd, LEX_STRING dbname, LEX_STRING name) if (check_if_system_tables_error()) DBUG_RETURN(TRUE); - if (check_access(thd, EVENT_ACL, dbname.str, 0, 0, 0, - is_schema_db(dbname.str))) + if (check_access(thd, EVENT_ACL, dbname.str, NULL, NULL, 0, 0)) DBUG_RETURN(TRUE); /* @@ -773,8 +768,9 @@ Events::fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */) if (thd->lex->sql_command == SQLCOM_SHOW_EVENTS) { DBUG_ASSERT(thd->lex->select_lex.db); - if (!is_schema_db(thd->lex->select_lex.db) && // There is no events in I_S - check_access(thd, EVENT_ACL, thd->lex->select_lex.db, 0, 0, 0, 0)) + if (!is_infoschema_db(thd->lex->select_lex.db) && // There is no events in I_S + check_access(thd, EVENT_ACL, thd->lex->select_lex.db, + NULL, NULL, 0, 0)) DBUG_RETURN(1); db= thd->lex->select_lex.db; } @@ -934,6 +930,51 @@ Events::deinit() DBUG_VOID_RETURN; } +#ifdef HAVE_PSI_INTERFACE +PSI_mutex_key key_LOCK_event_metadata, key_LOCK_event_queue, + key_event_scheduler_LOCK_scheduler_state; + +static PSI_mutex_info all_events_mutexes[]= +{ + { &key_LOCK_event_metadata, "LOCK_event_metadata", PSI_FLAG_GLOBAL}, + { &key_LOCK_event_queue, "LOCK_event_queue", PSI_FLAG_GLOBAL}, + { &key_event_scheduler_LOCK_scheduler_state, "Event_scheduler::LOCK_scheduler_state", PSI_FLAG_GLOBAL} +}; + +PSI_cond_key key_event_scheduler_COND_state, key_COND_queue_state; + +static PSI_cond_info all_events_conds[]= +{ + { &key_event_scheduler_COND_state, "Event_scheduler::COND_state", PSI_FLAG_GLOBAL}, + { &key_COND_queue_state, "COND_queue_state", PSI_FLAG_GLOBAL}, +}; + +PSI_thread_key key_thread_event_scheduler, key_thread_event_worker; + +static PSI_thread_info all_events_threads[]= +{ + { &key_thread_event_scheduler, "event_scheduler", PSI_FLAG_GLOBAL}, + { &key_thread_event_worker, "event_worker", 0} +}; + +static void init_events_psi_keys(void) +{ + const char* category= "sql"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_events_mutexes); + PSI_server->register_mutex(category, all_events_mutexes, count); + + count= array_elements(all_events_conds); + PSI_server->register_cond(category, all_events_conds, count); + + count= array_elements(all_events_threads); + PSI_server->register_thread(category, all_events_threads, count); +} +#endif /* HAVE_PSI_INTERFACE */ /** Inits Events mutexes @@ -946,7 +987,12 @@ Events::deinit() void Events::init_mutexes() { - pthread_mutex_init(&LOCK_event_metadata, MY_MUTEX_INIT_FAST); +#ifdef HAVE_PSI_INTERFACE + init_events_psi_keys(); +#endif + + mysql_mutex_init(key_LOCK_event_metadata, + &LOCK_event_metadata, MY_MUTEX_INIT_FAST); } @@ -960,7 +1006,7 @@ Events::init_mutexes() void Events::destroy_mutexes() { - pthread_mutex_destroy(&LOCK_event_metadata); + mysql_mutex_destroy(&LOCK_event_metadata); } @@ -982,7 +1028,7 @@ Events::dump_internal_status() puts("LLA = Last Locked At LUA = Last Unlocked At"); puts("WOC = Waiting On Condition DL = Data Locked"); - pthread_mutex_lock(&LOCK_event_metadata); + mysql_mutex_lock(&LOCK_event_metadata); if (opt_event_scheduler == EVENTS_DISABLED) puts("The Event Scheduler is disabled"); else @@ -991,7 +1037,7 @@ Events::dump_internal_status() event_queue->dump_internal_status(); } - pthread_mutex_unlock(&LOCK_event_metadata); + mysql_mutex_unlock(&LOCK_event_metadata); DBUG_VOID_RETURN; } diff --git a/sql/events.h b/sql/events.h index 8f68d5a8029..881ade37cbf 100644 --- a/sql/events.h +++ b/sql/events.h @@ -1,6 +1,6 @@ #ifndef _EVENT_H_ #define _EVENT_H_ -/* Copyright (C) 2004-2006 MySQL AB +/* Copyright (C) 2004-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -25,6 +25,13 @@ A public interface of Events_Scheduler module. */ +#ifdef HAVE_PSI_INTERFACE +extern PSI_mutex_key key_LOCK_event_metadata, + key_event_scheduler_LOCK_scheduler_state; +extern PSI_cond_key key_event_scheduler_COND_state; +extern PSI_thread_key key_thread_event_scheduler, key_thread_event_worker; +#endif /* HAVE_PSI_INTERFACE */ + class Event_parse_data; class Event_db_repository; class Event_queue; @@ -77,7 +84,7 @@ public: */ enum enum_opt_event_scheduler { EVENTS_OFF, EVENTS_ON, EVENTS_DISABLED }; static uint opt_event_scheduler; - static pthread_mutex_t LOCK_event_metadata; + static mysql_mutex_t LOCK_event_metadata; static bool check_if_system_tables_error(); static bool start(); static bool stop(); diff --git a/sql/filesort.cc b/sql/filesort.cc index 3104e6824b0..c6156b8243f 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -1119,8 +1119,9 @@ uint read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek, if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count))) { - if (my_pread(fromfile->file,(uchar*) buffpek->base, - (length= rec_length*count),buffpek->file_pos,MYF_RW)) + if (mysql_file_pread(fromfile->file, (uchar*) buffpek->base, + (length= rec_length*count), + buffpek->file_pos, MYF_RW)) return((uint) -1); /* purecov: inspected */ buffpek->key=buffpek->base; buffpek->file_pos+= length; /* New filepos */ diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index b820b6d939d..b254d5d387c 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -264,7 +264,7 @@ Ndb_cluster_connection* g_ndb_cluster_connection= NULL; uchar g_node_id_map[max_ndb_nodes]; /// Handler synchronization -pthread_mutex_t ndbcluster_mutex; +mysql_mutex_t ndbcluster_mutex; /// Table lock handling HASH ndbcluster_open_tables; @@ -281,9 +281,9 @@ static int ndb_get_table_statistics(ha_ndbcluster*, bool, Ndb*, const NDBTAB *, // Util thread variables pthread_t ndb_util_thread; int ndb_util_thread_running= 0; -pthread_mutex_t LOCK_ndb_util_thread; -pthread_cond_t COND_ndb_util_thread; -pthread_cond_t COND_ndb_util_ready; +mysql_mutex_t LOCK_ndb_util_thread; +mysql_cond_t COND_ndb_util_thread; +mysql_cond_t COND_ndb_util_ready; pthread_handler_t ndb_util_thread_func(void *arg); /** @@ -4778,11 +4778,11 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type) thd_ndb->changed_tables.push_back(m_share, &thd->transaction.mem_root); } - pthread_mutex_lock(&m_share->mutex); + mysql_mutex_lock(&m_share->mutex); DBUG_PRINT("info", ("Invalidating commit_count")); m_share->commit_count= 0; m_share->commit_count_lock++; - pthread_mutex_unlock(&m_share->mutex); + mysql_mutex_unlock(&m_share->mutex); } if (!--thd_ndb->lock_count) @@ -4943,12 +4943,12 @@ static int ndbcluster_commit(handlerton *hton, THD *thd, bool all) List_iterator_fast<NDB_SHARE> it(thd_ndb->changed_tables); while ((share= it++)) { - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); DBUG_PRINT("info", ("Invalidate commit_count for %s, share->commit_count: %lu", share->table_name, (ulong) share->commit_count)); share->commit_count= 0; share->commit_count_lock++; - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); } thd_ndb->changed_tables.empty(); @@ -5622,7 +5622,7 @@ int ha_ndbcluster::create(const char *name, if (!my_errno) { NDB_SHARE *share= 0; - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); /* First make sure we get a "fresh" share here, not an old trailing one... */ @@ -5647,7 +5647,7 @@ int ha_ndbcluster::create(const char *name, DBUG_PRINT("NDB_SHARE", ("%s binlog create use_count: %u", share->key, share->use_count)); } - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); while (!IS_TMP_PREFIX(m_tabname)) { @@ -6286,7 +6286,7 @@ retry_temporary_error1: /* the drop table failed for some reason, drop the share anyways */ if (share) { - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); if (share->state != NSS_DROPPED) { /* @@ -6302,7 +6302,7 @@ retry_temporary_error1: DBUG_PRINT("NDB_SHARE", ("%s temporary free use_count: %u", share->key, share->use_count)); free_share(&share, TRUE); - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); } #endif DBUG_RETURN(res); @@ -6343,7 +6343,7 @@ retry_temporary_error1: if (share) { - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); if (share->state != NSS_DROPPED) { /* @@ -6359,7 +6359,7 @@ retry_temporary_error1: DBUG_PRINT("NDB_SHARE", ("%s temporary free use_count: %u", share->key, share->use_count)); free_share(&share, TRUE); - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); } #endif DBUG_RETURN(0); @@ -7451,7 +7451,7 @@ int ndbcluster_find_files(handlerton *hton, THD *thd, /* Call back after cluster connect */ static int connect_callback() { - pthread_mutex_lock(&LOCK_ndb_util_thread); + mysql_mutex_lock(&LOCK_ndb_util_thread); update_status_variables(g_ndb_cluster_connection); uint node_id, i= 0; @@ -7460,13 +7460,92 @@ static int connect_callback() while ((node_id= g_ndb_cluster_connection->get_next_node(node_iter))) g_node_id_map[node_id]= i++; - pthread_cond_signal(&COND_ndb_util_thread); - pthread_mutex_unlock(&LOCK_ndb_util_thread); + mysql_cond_signal(&COND_ndb_util_thread); + mysql_mutex_unlock(&LOCK_ndb_util_thread); return 0; } extern int ndb_dictionary_is_mysqld; -extern pthread_mutex_t LOCK_plugin; +extern mysql_mutex_t LOCK_plugin; + +#ifdef HAVE_PSI_INTERFACE + +#ifdef HAVE_NDB_BINLOG +PSI_mutex_key key_injector_mutex, key_ndb_schema_share_mutex, + key_ndb_schema_object_mutex; +#endif /* HAVE_NDB_BINLOG */ + +PSI_mutex_key key_NDB_SHARE_mutex, key_ndbcluster_mutex, + key_LOCK_ndb_util_thread; + +static PSI_mutex_info all_ndbcluster_mutexes[]= +{ +#ifdef HAVE_NDB_BINLOG + {& key_injector_mutex, "injector_mutex", PSI_FLAG_GLOBAL}, + {& key_ndb_schema_share_mutex, "ndb_schema_share_mutex", PSI_FLAG_GLOBAL}, + {& key_ndb_schema_object_mutex, "ndb_schema_object_mutex", PSI_FLAG_GLOBAL}, +#endif /* HAVE_NDB_BINLOG */ + {& key_NDB_SHARE_mutex, "NDB_SHARE::mutex", PSI_FLAG_GLOBAL}, + {& key_ndbcluster_mutex, "ndbcluster_mutex", PSI_FLAG_GLOBAL}, + {& key_LOCK_ndb_util_thread, "LOCK_ndb_util_thread", PSI_FLAG_GLOBAL} +}; + +#ifdef HAVE_NDB_BINLOG +PSI_cond_key key_injector_cond; +#endif /* HAVE_NDB_BINLOG */ + +PSI_cond_key key_COND_ndb_util_thread, key_COND_ndb_util_ready; + +static PSI_cond_info all_ndbcluster_conds[]= +{ +#ifdef HAVE_NDB_BINLOG + {& key_injector_cond, "injector_cond", PSI_FLAG_GLOBAL}, +#endif /* HAVE_NDB_BINLOG */ + {& key_COND_ndb_util_thread, "COND_ndb_util_thread", PSI_FLAG_GLOBAL}, + {& key_COND_ndb_util_ready, "COND_ndb_util_ready", PSI_FLAG_GLOBAL} +}; + +#ifdef HAVE_NDB_BINLOG +PSI_thread_key key_thread_ndb_binlog; +#endif /* HAVE_NDB_BINLOG */ +PSI_thread_key key_thread_ndb_util; + +static PSI_thread_info all_ndbcluster_threads[]= +{ +#ifdef HAVE_NDB_BINLOG + { &key_thread_ndb_binlog, "ndb_binlog", PSI_FLAG_GLOBAL}, +#endif /* HAVE_NDB_BINLOG */ + { &key_thread_ndb_util, "ndb_util", PSI_FLAG_GLOBAL} +}; + +PSI_file_key key_file_ndb; + +static PSI_file_info all_ndbcluster_files[]= +{ + { &key_file_ndb, "ndb", 0} +}; + +void init_ndbcluster_psi_keys() +{ + const char* category= "ndbcluster"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_ndbcluster_mutexes); + PSI_server->register_mutex(category, all_ndbcluster_mutexes, count); + + count= array_elements(all_ndbcluster_conds); + PSI_server->register_cond(category, all_ndbcluster_conds, count); + + count= array_elements(all_ndbcluster_threads); + PSI_server->register_thread(category, all_ndbcluster_threads, count); + + count= array_elements(all_ndbcluster_files); + PSI_server->register_file(category, all_ndbcluster_files, count); +} +#endif /* HAVE_PSI_INTERFACE */ static int ndbcluster_init(void *p) { @@ -7476,17 +7555,23 @@ static int ndbcluster_init(void *p) if (ndbcluster_inited) DBUG_RETURN(FALSE); +#ifdef HAVE_PSI_INTERFACE + init_ndbcluster_psi_keys(); +#endif + /* Below we create new THD's. They'll need LOCK_plugin, but it's taken now by plugin initialization code. Release it to avoid deadlocks. It's safe, as there're no threads that may concurrently access plugin control structures. */ - pthread_mutex_unlock(&LOCK_plugin); - - pthread_mutex_init(&ndbcluster_mutex,MY_MUTEX_INIT_FAST); - pthread_mutex_init(&LOCK_ndb_util_thread, MY_MUTEX_INIT_FAST); - pthread_cond_init(&COND_ndb_util_thread, NULL); - pthread_cond_init(&COND_ndb_util_ready, NULL); + mysql_mutex_unlock(&LOCK_plugin); + + mysql_mutex_init(key_ndbcluster_mutex, + &ndbcluster_mutex, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_ndb_util_thread, + &LOCK_ndb_util_thread, MY_MUTEX_INIT_FAST); + mysql_cond_init(key_COND_ndb_util_thread, &COND_ndb_util_thread, NULL); + mysql_cond_init(key_COND_ndb_util_ready, &COND_ndb_util_ready, NULL); ndb_util_thread_running= -1; ndbcluster_terminating= 0; ndb_dictionary_is_mysqld= 1; @@ -7608,35 +7693,36 @@ static int ndbcluster_init(void *p) // Create utility thread pthread_t tmp; - if (pthread_create(&tmp, &connection_attrib, ndb_util_thread_func, 0)) + if (mysql_thread_create(key_thread_ndb_util, + &tmp, &connection_attrib, ndb_util_thread_func, 0)) { DBUG_PRINT("error", ("Could not create ndb utility thread")); my_hash_free(&ndbcluster_open_tables); - pthread_mutex_destroy(&ndbcluster_mutex); - pthread_mutex_destroy(&LOCK_ndb_util_thread); - pthread_cond_destroy(&COND_ndb_util_thread); - pthread_cond_destroy(&COND_ndb_util_ready); + mysql_mutex_destroy(&ndbcluster_mutex); + mysql_mutex_destroy(&LOCK_ndb_util_thread); + mysql_cond_destroy(&COND_ndb_util_thread); + mysql_cond_destroy(&COND_ndb_util_ready); goto ndbcluster_init_error; } /* Wait for the util thread to start */ - pthread_mutex_lock(&LOCK_ndb_util_thread); + mysql_mutex_lock(&LOCK_ndb_util_thread); while (ndb_util_thread_running < 0) - pthread_cond_wait(&COND_ndb_util_ready, &LOCK_ndb_util_thread); - pthread_mutex_unlock(&LOCK_ndb_util_thread); + mysql_cond_wait(&COND_ndb_util_ready, &LOCK_ndb_util_thread); + mysql_mutex_unlock(&LOCK_ndb_util_thread); if (!ndb_util_thread_running) { DBUG_PRINT("error", ("ndb utility thread exited prematurely")); my_hash_free(&ndbcluster_open_tables); - pthread_mutex_destroy(&ndbcluster_mutex); - pthread_mutex_destroy(&LOCK_ndb_util_thread); - pthread_cond_destroy(&COND_ndb_util_thread); - pthread_cond_destroy(&COND_ndb_util_ready); + mysql_mutex_destroy(&ndbcluster_mutex); + mysql_mutex_destroy(&LOCK_ndb_util_thread); + mysql_cond_destroy(&COND_ndb_util_thread); + mysql_cond_destroy(&COND_ndb_util_ready); goto ndbcluster_init_error; } - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); ndbcluster_inited= 1; DBUG_RETURN(FALSE); @@ -7650,7 +7736,7 @@ ndbcluster_init_error: g_ndb_cluster_connection= NULL; ndbcluster_hton->state= SHOW_OPTION_DISABLED; // If we couldn't use handler - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); DBUG_RETURN(TRUE); } @@ -7693,17 +7779,17 @@ static int ndbcluster_end(handlerton *hton, ha_panic_function type) /* wait for util thread to finish */ sql_print_information("Stopping Cluster Utility thread"); - pthread_mutex_lock(&LOCK_ndb_util_thread); + mysql_mutex_lock(&LOCK_ndb_util_thread); ndbcluster_terminating= 1; - pthread_cond_signal(&COND_ndb_util_thread); + mysql_cond_signal(&COND_ndb_util_thread); while (ndb_util_thread_running > 0) - pthread_cond_wait(&COND_ndb_util_ready, &LOCK_ndb_util_thread); - pthread_mutex_unlock(&LOCK_ndb_util_thread); + mysql_cond_wait(&COND_ndb_util_ready, &LOCK_ndb_util_thread); + mysql_mutex_unlock(&LOCK_ndb_util_thread); #ifdef HAVE_NDB_BINLOG { - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); while (ndbcluster_open_tables.records) { NDB_SHARE *share= @@ -7714,7 +7800,7 @@ static int ndbcluster_end(handlerton *hton, ha_panic_function type) #endif ndbcluster_real_free_share(&share); } - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); } #endif my_hash_free(&ndbcluster_open_tables); @@ -7743,10 +7829,10 @@ static int ndbcluster_end(handlerton *hton, ha_panic_function type) // cleanup ndb interface ndb_end_internal(); - pthread_mutex_destroy(&ndbcluster_mutex); - pthread_mutex_destroy(&LOCK_ndb_util_thread); - pthread_cond_destroy(&COND_ndb_util_thread); - pthread_cond_destroy(&COND_ndb_util_ready); + mysql_mutex_destroy(&ndbcluster_mutex); + mysql_mutex_destroy(&LOCK_ndb_util_thread); + mysql_cond_destroy(&COND_ndb_util_thread); + mysql_cond_destroy(&COND_ndb_util_ready); DBUG_RETURN(0); } @@ -8049,12 +8135,12 @@ uint ndb_get_commitcount(THD *thd, char *dbname, char *tabname, build_table_filename(name, sizeof(name) - 1, dbname, tabname, "", 0); DBUG_PRINT("enter", ("name: %s", name)); - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); if (!(share=(NDB_SHARE*) my_hash_search(&ndbcluster_open_tables, (uchar*) name, strlen(name)))) { - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); DBUG_PRINT("info", ("Table %s not found in ndbcluster_open_tables", name)); DBUG_RETURN(1); } @@ -8062,9 +8148,9 @@ uint ndb_get_commitcount(THD *thd, char *dbname, char *tabname, share->use_count++; DBUG_PRINT("NDB_SHARE", ("%s temporary use_count: %u", share->key, share->use_count)); - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); if (opt_ndb_cache_check_time > 0) { if (share->commit_count != 0) @@ -8075,7 +8161,7 @@ uint ndb_get_commitcount(THD *thd, char *dbname, char *tabname, #endif DBUG_PRINT("info", ("Getting commit_count: %s from share", llstr(share->commit_count, buff))); - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); /* ndb_share reference temporary free */ DBUG_PRINT("NDB_SHARE", ("%s temporary free use_count: %u", share->key, share->use_count)); @@ -8092,7 +8178,7 @@ uint ndb_get_commitcount(THD *thd, char *dbname, char *tabname, ERR_RETURN(ndb->getNdbError()); } uint lock= share->commit_count_lock; - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); struct Ndb_statistics stat; { @@ -8108,7 +8194,7 @@ uint ndb_get_commitcount(THD *thd, char *dbname, char *tabname, } } - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); if (share->commit_count_lock == lock) { #ifndef DBUG_OFF @@ -8124,7 +8210,7 @@ uint ndb_get_commitcount(THD *thd, char *dbname, char *tabname, DBUG_PRINT("info", ("Discarding commit_count, comit_count_lock changed")); *commit_count= 0; } - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); /* ndb_share reference temporary free */ DBUG_PRINT("NDB_SHARE", ("%s temporary free use_count: %u", share->key, share->use_count)); @@ -8340,7 +8426,7 @@ static void print_ndbcluster_open_tables() to avoid segmentation faults. There is a risk that the memory for this trailing share leaks. - Must be called with previous pthread_mutex_lock(&ndbcluster_mutex) + Must be called with previous mysql_mutex_lock(&ndbcluster_mutex) */ int handle_trailing_share(NDB_SHARE *share) { @@ -8352,7 +8438,7 @@ int handle_trailing_share(NDB_SHARE *share) ++share->use_count; DBUG_PRINT("NDB_SHARE", ("%s temporary use_count: %u", share->key, share->use_count)); - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); TABLE_LIST table_list; bzero((char*) &table_list,sizeof(table_list)); @@ -8361,7 +8447,7 @@ int handle_trailing_share(NDB_SHARE *share) mysql_mutex_assert_owner(&LOCK_open); close_cached_tables(thd, &table_list, TRUE, FALSE, FALSE); - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); /* ndb_share reference temporary free */ DBUG_PRINT("NDB_SHARE", ("%s temporary free use_count: %u", share->key, share->use_count)); @@ -8452,7 +8538,7 @@ int handle_trailing_share(NDB_SHARE *share) static int rename_share(NDB_SHARE *share, const char *new_key) { NDB_SHARE *tmp; - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); uint new_length= (uint) strlen(new_key); DBUG_PRINT("rename_share", ("old_key: %s old__length: %d", share->key, share->key_length)); @@ -8490,7 +8576,7 @@ static int rename_share(NDB_SHARE *share, const char *new_key) share->key)); } dbug_print_open_tables(); - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); return -1; } dbug_print_open_tables(); @@ -8515,7 +8601,7 @@ static int rename_share(NDB_SHARE *share, const char *new_key) share->old_names= old_key; // ToDo free old_names after ALTER EVENT - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); return 0; } #endif @@ -8526,12 +8612,12 @@ static int rename_share(NDB_SHARE *share, const char *new_key) */ NDB_SHARE *ndbcluster_get_share(NDB_SHARE *share) { - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); share->use_count++; dbug_print_open_tables(); dbug_print_share("ndbcluster_get_share:", share); - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); return share; } @@ -8548,7 +8634,7 @@ NDB_SHARE *ndbcluster_get_share(NDB_SHARE *share) create_if_not_exists == FALSE: returns 0 if share does not exist - have_lock == TRUE, pthread_mutex_lock(&ndbcluster_mutex) already taken + have_lock == TRUE, mysql_mutex_lock(&ndbcluster_mutex) already taken */ NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table, @@ -8561,7 +8647,7 @@ NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table, DBUG_PRINT("enter", ("key: '%s'", key)); if (!have_lock) - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); if (!(share= (NDB_SHARE*) my_hash_search(&ndbcluster_open_tables, (uchar*) key, length))) @@ -8570,7 +8656,7 @@ NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table, { DBUG_PRINT("error", ("get_share: %s does not exist", key)); if (!have_lock) - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); DBUG_RETURN(0); } if ((share= (NDB_SHARE*) my_malloc(sizeof(*share), @@ -8592,11 +8678,11 @@ NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table, my_free((uchar*) share, 0); *root_ptr= old_root; if (!have_lock) - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); DBUG_RETURN(0); } thr_lock_init(&share->lock); - pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_NDB_SHARE_mutex, &share->mutex, MY_MUTEX_INIT_FAST); share->commit_count= 0; share->commit_count_lock= 0; share->db= share->key + length + 1; @@ -8610,7 +8696,7 @@ NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table, ndbcluster_real_free_share(&share); *root_ptr= old_root; if (!have_lock) - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); DBUG_RETURN(0); } #endif @@ -8620,7 +8706,7 @@ NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table, { DBUG_PRINT("error", ("get_share: failed to alloc share")); if (!have_lock) - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); my_error(ER_OUTOFMEMORY, MYF(0), sizeof(*share)); DBUG_RETURN(0); } @@ -8630,7 +8716,7 @@ NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table, dbug_print_open_tables(); dbug_print_share("ndbcluster_get_share:", share); if (!have_lock) - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); DBUG_RETURN(share); } @@ -8642,7 +8728,7 @@ void ndbcluster_real_free_share(NDB_SHARE **share) my_hash_delete(&ndbcluster_open_tables, (uchar*) *share); thr_lock_delete(&(*share)->lock); - pthread_mutex_destroy(&(*share)->mutex); + mysql_mutex_destroy(&(*share)->mutex); #ifdef HAVE_NDB_BINLOG if ((*share)->table) @@ -8671,7 +8757,7 @@ void ndbcluster_real_free_share(NDB_SHARE **share) void ndbcluster_free_share(NDB_SHARE **share, bool have_lock) { if (!have_lock) - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); if ((*share)->util_lock == current_thd) (*share)->util_lock= 0; if (!--(*share)->use_count) @@ -8684,7 +8770,7 @@ void ndbcluster_free_share(NDB_SHARE **share, bool have_lock) dbug_print_share("ndbcluster_free_share:", *share); } if (!have_lock) - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); } @@ -8844,11 +8930,12 @@ int ha_ndbcluster::write_ndb_file(const char *name) (void)strxnmov(path, FN_REFLEN-1, mysql_data_home,"/",name,ha_ndb_ext,NullS); - if ((file=my_create(path, CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0) + if ((file= mysql_file_create(key_file_ndb, path, CREATE_MODE, + O_RDWR | O_TRUNC, MYF(MY_WME))) >= 0) { // It's an empty file error=0; - my_close(file,MYF(0)); + mysql_file_close(file, MYF(0)); } DBUG_RETURN(error); } @@ -9401,7 +9488,7 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused))) DBUG_ENTER("ndb_util_thread"); DBUG_PRINT("enter", ("cache_check_time: %lu", opt_ndb_cache_check_time)); - pthread_mutex_lock(&LOCK_ndb_util_thread); + mysql_mutex_lock(&LOCK_ndb_util_thread); thd= new THD; /* note that contructor of THD uses DBUG_ */ if (thd == NULL) @@ -9434,45 +9521,45 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused))) /* Signal successful initialization */ ndb_util_thread_running= 1; - pthread_cond_signal(&COND_ndb_util_ready); - pthread_mutex_unlock(&LOCK_ndb_util_thread); + mysql_cond_signal(&COND_ndb_util_ready); + mysql_mutex_unlock(&LOCK_ndb_util_thread); /* wait for mysql server to start */ - pthread_mutex_lock(&LOCK_server_started); + mysql_mutex_lock(&LOCK_server_started); while (!mysqld_server_started) { set_timespec(abstime, 1); - pthread_cond_timedwait(&COND_server_started, &LOCK_server_started, - &abstime); + mysql_cond_timedwait(&COND_server_started, &LOCK_server_started, + &abstime); if (ndbcluster_terminating) { - pthread_mutex_unlock(&LOCK_server_started); - pthread_mutex_lock(&LOCK_ndb_util_thread); + mysql_mutex_unlock(&LOCK_server_started); + mysql_mutex_lock(&LOCK_ndb_util_thread); goto ndb_util_thread_end; } } - pthread_mutex_unlock(&LOCK_server_started); + mysql_mutex_unlock(&LOCK_server_started); /* Wait for cluster to start */ - pthread_mutex_lock(&LOCK_ndb_util_thread); + mysql_mutex_lock(&LOCK_ndb_util_thread); while (!ndb_cluster_node_id && (ndbcluster_hton->slot != ~(uint)0)) { /* ndb not connected yet */ - pthread_cond_wait(&COND_ndb_util_thread, &LOCK_ndb_util_thread); + mysql_cond_wait(&COND_ndb_util_thread, &LOCK_ndb_util_thread); if (ndbcluster_terminating) goto ndb_util_thread_end; } - pthread_mutex_unlock(&LOCK_ndb_util_thread); + mysql_mutex_unlock(&LOCK_ndb_util_thread); /* Get thd_ndb for this thread */ if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb())) { sql_print_error("Could not allocate Thd_ndb object"); - pthread_mutex_lock(&LOCK_ndb_util_thread); + mysql_mutex_lock(&LOCK_ndb_util_thread); goto ndb_util_thread_end; } set_thd_ndb(thd, thd_ndb); @@ -9493,14 +9580,14 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused))) set_timespec(abstime, 0); for (;;) { - pthread_mutex_lock(&LOCK_ndb_util_thread); + mysql_mutex_lock(&LOCK_ndb_util_thread); if (!ndbcluster_terminating) - pthread_cond_timedwait(&COND_ndb_util_thread, - &LOCK_ndb_util_thread, - &abstime); + mysql_cond_timedwait(&COND_ndb_util_thread, + &LOCK_ndb_util_thread, + &abstime); if (ndbcluster_terminating) /* Shutting down server */ goto ndb_util_thread_end; - pthread_mutex_unlock(&LOCK_ndb_util_thread); + mysql_mutex_unlock(&LOCK_ndb_util_thread); #ifdef NDB_EXTRA_DEBUG_UTIL_THREAD DBUG_PRINT("ndb_util_thread", ("Started, opt_ndb_cache_check_time: %lu", opt_ndb_cache_check_time)); @@ -9525,7 +9612,7 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused))) /* Lock mutex and fill list with pointers to all open tables */ NDB_SHARE *share; - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); uint i, open_count, record_count= ndbcluster_open_tables.records; if (share_list_size < record_count) { @@ -9534,7 +9621,7 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused))) { sql_print_warning("ndb util thread: malloc failure, " "query cache not maintained properly"); - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); goto next; // At least do not crash } delete [] share_list; @@ -9561,7 +9648,7 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused))) /* Store pointer to table */ share_list[open_count++]= share; } - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); /* Iterate through the open files list */ for (i= 0; i < open_count; i++) @@ -9586,9 +9673,9 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused))) struct Ndb_statistics stat; uint lock; - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); lock= share->commit_count_lock; - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); { /* Contact NDB to get commit count for table */ Ndb* ndb= thd_ndb->ndb; @@ -9619,10 +9706,10 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused))) } } loop_next: - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); if (share->commit_count_lock == lock) share->commit_count= stat.commit_count; - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); /* ndb_share reference temporary free */ DBUG_PRINT("NDB_SHARE", ("%s temporary free use_count: %u", @@ -9652,7 +9739,7 @@ next: } } - pthread_mutex_lock(&LOCK_ndb_util_thread); + mysql_mutex_lock(&LOCK_ndb_util_thread); ndb_util_thread_end: net_end(&thd->net); @@ -9664,8 +9751,8 @@ ndb_util_thread_fail: /* signal termination */ ndb_util_thread_running= 0; - pthread_cond_signal(&COND_ndb_util_ready); - pthread_mutex_unlock(&LOCK_ndb_util_thread); + mysql_cond_signal(&COND_ndb_util_ready); + mysql_mutex_unlock(&LOCK_ndb_util_thread); DBUG_PRINT("exit", ("ndb_util_thread")); DBUG_LEAVE; // Must match DBUG_ENTER() diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h index a51dc38bf93..63da24e8dda 100644 --- a/sql/ha_ndbcluster.h +++ b/sql/ha_ndbcluster.h @@ -1,7 +1,7 @@ #ifndef HA_NDBCLUSTER_INCLUDED #define HA_NDBCLUSTER_INCLUDED -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -35,6 +35,10 @@ #define NDB_HIDDEN_PRIMARY_KEY_LENGTH 8 +#ifdef HAVE_PSI_INTERFACE +extern PSI_file_key key_file_ndb; +#endif /* HAVE_PSI_INTERFACE */ + class Ndb; // Forward declaration class NdbOperation; // Forward declaration @@ -102,7 +106,7 @@ typedef struct st_ndbcluster_share { NDB_SHARE_STATE state; MEM_ROOT mem_root; THR_LOCK lock; - pthread_mutex_t mutex; + mysql_mutex_t mutex; char *key; uint key_length; THD *util_lock; @@ -131,9 +135,9 @@ NDB_SHARE_STATE get_ndb_share_state(NDB_SHARE *share) { NDB_SHARE_STATE state; - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); state= share->state; - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); return state; } @@ -141,19 +145,19 @@ inline void set_ndb_share_state(NDB_SHARE *share, NDB_SHARE_STATE state) { - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); share->state= state; - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); } struct Ndb_tuple_id_range_guard { Ndb_tuple_id_range_guard(NDB_SHARE* _share) : share(_share), range(share->tuple_id_range) { - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); } ~Ndb_tuple_id_range_guard() { - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); } NDB_SHARE* share; Ndb::TupleIdRange& range; @@ -578,6 +582,6 @@ static const char ndbcluster_hton_name[]= "ndbcluster"; static const int ndbcluster_hton_name_length=sizeof(ndbcluster_hton_name)-1; extern int ndbcluster_terminating; extern int ndb_util_thread_running; -extern pthread_cond_t COND_ndb_util_ready; +extern mysql_cond_t COND_ndb_util_ready; #endif /* HA_NDBCLUSTER_INCLUDED */ diff --git a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc index b59e686d131..25f8474feae 100644 --- a/sql/ha_ndbcluster_binlog.cc +++ b/sql/ha_ndbcluster_binlog.cc @@ -79,7 +79,7 @@ THD *injector_thd= 0; to enable ndb injector thread receiving events. Must therefore always be used with a surrounding - pthread_mutex_lock(&injector_mutex), when doing create/dropEventOperation + mysql_mutex_lock(&injector_mutex), when doing create/dropEventOperation */ static Ndb *injector_ndb= 0; static Ndb *schema_ndb= 0; @@ -106,8 +106,8 @@ static int ndbcluster_binlog_terminating= 0; and injector thread */ pthread_t ndb_binlog_thread; -pthread_mutex_t injector_mutex; -pthread_cond_t injector_cond; +mysql_mutex_t injector_mutex; +mysql_cond_t injector_cond; /* NDB Injector thread (used for binlog creation) */ static ulonglong ndb_latest_applied_binlog_epoch= 0; @@ -116,7 +116,7 @@ static ulonglong ndb_latest_received_binlog_epoch= 0; NDB_SHARE *ndb_apply_status_share= 0; NDB_SHARE *ndb_schema_share= 0; -pthread_mutex_t ndb_schema_share_mutex; +mysql_mutex_t ndb_schema_share_mutex; extern my_bool opt_log_slave_updates; static my_bool g_ndb_log_slave_updates; @@ -124,7 +124,7 @@ static my_bool g_ndb_log_slave_updates; /* Schema object distribution handling */ HASH ndb_schema_objects; typedef struct st_ndb_schema_object { - pthread_mutex_t mutex; + mysql_mutex_t mutex; char *key; uint key_length; uint use_count; @@ -641,28 +641,28 @@ static int ndbcluster_binlog_end(THD *thd) however be a likely case as the ndbcluster_binlog_end is supposed to be called before ndb_cluster_end(). */ - pthread_mutex_lock(&LOCK_ndb_util_thread); + mysql_mutex_lock(&LOCK_ndb_util_thread); /* Ensure mutex are not freed if ndb_cluster_end is running at same time */ ndb_util_thread_running++; ndbcluster_terminating= 1; - pthread_cond_signal(&COND_ndb_util_thread); + mysql_cond_signal(&COND_ndb_util_thread); while (ndb_util_thread_running > 1) - pthread_cond_wait(&COND_ndb_util_ready, &LOCK_ndb_util_thread); + mysql_cond_wait(&COND_ndb_util_ready, &LOCK_ndb_util_thread); ndb_util_thread_running--; - pthread_mutex_unlock(&LOCK_ndb_util_thread); + mysql_mutex_unlock(&LOCK_ndb_util_thread); } /* wait for injector thread to finish */ ndbcluster_binlog_terminating= 1; - pthread_mutex_lock(&injector_mutex); - pthread_cond_signal(&injector_cond); + mysql_mutex_lock(&injector_mutex); + mysql_cond_signal(&injector_cond); while (ndb_binlog_thread_running > 0) - pthread_cond_wait(&injector_cond, &injector_mutex); - pthread_mutex_unlock(&injector_mutex); + mysql_cond_wait(&injector_cond, &injector_mutex); + mysql_mutex_unlock(&injector_mutex); - pthread_mutex_destroy(&injector_mutex); - pthread_cond_destroy(&injector_cond); - pthread_mutex_destroy(&ndb_schema_share_mutex); + mysql_mutex_destroy(&injector_mutex); + mysql_cond_destroy(&injector_cond); + mysql_mutex_destroy(&ndb_schema_share_mutex); #endif DBUG_RETURN(0); @@ -742,14 +742,14 @@ void ndbcluster_binlog_init_handlerton() */ static NDB_SHARE *ndbcluster_check_ndb_apply_status_share() { - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); void *share= my_hash_search(&ndbcluster_open_tables, (uchar*) NDB_APPLY_TABLE_FILE, sizeof(NDB_APPLY_TABLE_FILE) - 1); DBUG_PRINT("info",("ndbcluster_check_ndb_apply_status_share %s 0x%lx", NDB_APPLY_TABLE_FILE, (long) share)); - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); return (NDB_SHARE*) share; } @@ -760,14 +760,14 @@ static NDB_SHARE *ndbcluster_check_ndb_apply_status_share() */ static NDB_SHARE *ndbcluster_check_ndb_schema_share() { - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); void *share= my_hash_search(&ndbcluster_open_tables, (uchar*) NDB_SCHEMA_TABLE_FILE, sizeof(NDB_SCHEMA_TABLE_FILE) - 1); DBUG_PRINT("info",("ndbcluster_check_ndb_schema_share %s 0x%lx", NDB_SCHEMA_TABLE_FILE, (long) share)); - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); return (NDB_SHARE*) share; } @@ -802,7 +802,7 @@ static int ndbcluster_create_ndb_apply_status_table(THD *thd) { build_table_filename(buf, sizeof(buf) - 1, NDB_REP_DB, NDB_APPLY_TABLE, reg_ext, 0); - my_delete(buf, MYF(0)); + mysql_file_delete(key_file_frm, buf, MYF(0)); } /* @@ -860,7 +860,7 @@ static int ndbcluster_create_schema_table(THD *thd) { build_table_filename(buf, sizeof(buf) - 1, NDB_REP_DB, NDB_SCHEMA_TABLE, reg_ext, 0); - my_delete(buf, MYF(0)); + mysql_file_delete(key_file_frm, buf, MYF(0)); } /* @@ -928,7 +928,7 @@ int ndbcluster_setup_binlog_table_shares(THD *thd) close_cached_tables(NULL, NULL, TRUE, FALSE, FALSE); mysql_mutex_unlock(&LOCK_open); /* Signal injector thread that all is setup */ - pthread_cond_signal(&injector_cond); + mysql_cond_signal(&injector_cond); } return 0; } @@ -1239,12 +1239,12 @@ static void ndb_report_waiting(const char *key, { ulonglong ndb_latest_epoch= 0; const char *proc_info= "<no info>"; - pthread_mutex_lock(&injector_mutex); + mysql_mutex_lock(&injector_mutex); if (injector_ndb) ndb_latest_epoch= injector_ndb->getLatestGCI(); if (injector_thd) proc_info= injector_thd->proc_info; - pthread_mutex_unlock(&injector_mutex); + mysql_mutex_unlock(&injector_mutex); sql_print_information("NDB %s:" " waiting max %u sec for %s %s." " epochs: (%u,%u,%u)" @@ -1357,15 +1357,15 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, bitmap_set_all(&schema_subscribers); /* begin protect ndb_schema_share */ - pthread_mutex_lock(&ndb_schema_share_mutex); + mysql_mutex_lock(&ndb_schema_share_mutex); if (ndb_schema_share == 0) { - pthread_mutex_unlock(&ndb_schema_share_mutex); + mysql_mutex_unlock(&ndb_schema_share_mutex); if (ndb_schema_object) ndb_free_schema_object(&ndb_schema_object, FALSE); DBUG_RETURN(0); } - (void) pthread_mutex_lock(&ndb_schema_share->mutex); + mysql_mutex_lock(&ndb_schema_share->mutex); for (i= 0; i < no_storage_nodes; i++) { MY_BITMAP *table_subscribers= &ndb_schema_share->subscriber_bitmap[i]; @@ -1376,8 +1376,8 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, updated= 1; } } - (void) pthread_mutex_unlock(&ndb_schema_share->mutex); - pthread_mutex_unlock(&ndb_schema_share_mutex); + mysql_mutex_unlock(&ndb_schema_share->mutex); + mysql_mutex_unlock(&ndb_schema_share_mutex); /* end protect ndb_schema_share */ if (updated) @@ -1397,10 +1397,10 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, if (ndb_schema_object) { - (void) pthread_mutex_lock(&ndb_schema_object->mutex); + mysql_mutex_lock(&ndb_schema_object->mutex); memcpy(ndb_schema_object->slock, schema_subscribers.bitmap, sizeof(ndb_schema_object->slock)); - (void) pthread_mutex_unlock(&ndb_schema_object->mutex); + mysql_mutex_unlock(&ndb_schema_object->mutex); } DBUG_DUMP("schema_subscribers", (uchar*)schema_subscribers.bitmap, @@ -1566,7 +1566,7 @@ end: dict->forceGCPWait(); int max_timeout= DEFAULT_SYNC_TIMEOUT; - (void) pthread_mutex_lock(&ndb_schema_object->mutex); + mysql_mutex_lock(&ndb_schema_object->mutex); if (have_lock_open) { mysql_mutex_assert_owner(&LOCK_open); @@ -1578,20 +1578,20 @@ end: int i; int no_storage_nodes= g_ndb_cluster_connection->no_db_nodes(); set_timespec(abstime, 1); - int ret= pthread_cond_timedwait(&injector_cond, - &ndb_schema_object->mutex, - &abstime); + int ret= mysql_cond_timedwait(&injector_cond, + &ndb_schema_object->mutex, + &abstime); if (thd->killed) break; /* begin protect ndb_schema_share */ - pthread_mutex_lock(&ndb_schema_share_mutex); + mysql_mutex_lock(&ndb_schema_share_mutex); if (ndb_schema_share == 0) { - pthread_mutex_unlock(&ndb_schema_share_mutex); + mysql_mutex_unlock(&ndb_schema_share_mutex); break; } - (void) pthread_mutex_lock(&ndb_schema_share->mutex); + mysql_mutex_lock(&ndb_schema_share->mutex); for (i= 0; i < no_storage_nodes; i++) { /* remove any unsubscribed from schema_subscribers */ @@ -1599,8 +1599,8 @@ end: if (!bitmap_is_clear_all(tmp)) bitmap_intersect(&schema_subscribers, tmp); } - (void) pthread_mutex_unlock(&ndb_schema_share->mutex); - pthread_mutex_unlock(&ndb_schema_share_mutex); + mysql_mutex_unlock(&ndb_schema_share->mutex); + mysql_mutex_unlock(&ndb_schema_share_mutex); /* end protect ndb_schema_share */ /* remove any unsubscribed from ndb_schema_object->slock */ @@ -1631,7 +1631,7 @@ end: { mysql_mutex_lock(&LOCK_open); } - (void) pthread_mutex_unlock(&ndb_schema_object->mutex); + mysql_mutex_unlock(&ndb_schema_object->mutex); } if (ndb_schema_object) @@ -1761,11 +1761,11 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp, if (is_online_alter_table) { /* Signal ha_ndbcluster::alter_table that drop is done */ - (void) pthread_cond_signal(&injector_cond); + mysql_cond_signal(&injector_cond); DBUG_RETURN(0); } - (void) pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); if (is_rename_table && !is_remote_change) { DBUG_PRINT("info", ("Detected name change of table %s.%s", @@ -1801,10 +1801,10 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp, // either just us or drop table handling as well /* Signal ha_ndbcluster::delete/rename_table that drop is done */ - (void) pthread_mutex_unlock(&share->mutex); - (void) pthread_cond_signal(&injector_cond); + mysql_mutex_unlock(&share->mutex); + mysql_cond_signal(&injector_cond); - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); /* ndb_share reference binlog free */ DBUG_PRINT("NDB_SHARE", ("%s binlog free use_count: %u", share->key, share->use_count)); @@ -1830,14 +1830,14 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp, } else share= 0; - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); pOp->setCustomData(0); - pthread_mutex_lock(&injector_mutex); + mysql_mutex_lock(&injector_mutex); ndb->dropEventOperation(pOp); pOp= 0; - pthread_mutex_unlock(&injector_mutex); + mysql_mutex_unlock(&injector_mutex); if (do_close_cached_tables) { @@ -2072,7 +2072,7 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, "read only on reconnect."); /* begin protect ndb_schema_share */ - pthread_mutex_lock(&ndb_schema_share_mutex); + mysql_mutex_lock(&ndb_schema_share_mutex); /* ndb_share reference binlog extra free */ DBUG_PRINT("NDB_SHARE", ("%s binlog extra free use_count: %u", ndb_schema_share->key, @@ -2080,7 +2080,7 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, free_share(&ndb_schema_share); ndb_schema_share= 0; ndb_binlog_tables_inited= 0; - pthread_mutex_unlock(&ndb_schema_share_mutex); + mysql_mutex_unlock(&ndb_schema_share_mutex); /* end protect ndb_schema_share */ close_cached_tables(NULL, NULL, FALSE, FALSE, FALSE); @@ -2092,7 +2092,7 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, { uint8 node_id= g_node_id_map[pOp->getNdbdNodeId()]; DBUG_ASSERT(node_id != 0xFF); - (void) pthread_mutex_lock(&tmp_share->mutex); + mysql_mutex_lock(&tmp_share->mutex); bitmap_clear_all(&tmp_share->subscriber_bitmap[node_id]); DBUG_PRINT("info",("NODE_FAILURE UNSUBSCRIBE[%d]", node_id)); if (opt_ndb_extra_logging) @@ -2103,8 +2103,8 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, tmp_share->subscriber_bitmap[node_id].bitmap[1], tmp_share->subscriber_bitmap[node_id].bitmap[0]); } - (void) pthread_mutex_unlock(&tmp_share->mutex); - (void) pthread_cond_signal(&injector_cond); + mysql_mutex_unlock(&tmp_share->mutex); + mysql_cond_signal(&injector_cond); break; } case NDBEVENT::TE_SUBSCRIBE: @@ -2112,7 +2112,7 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, uint8 node_id= g_node_id_map[pOp->getNdbdNodeId()]; uint8 req_id= pOp->getReqNodeId(); DBUG_ASSERT(req_id != 0 && node_id != 0xFF); - (void) pthread_mutex_lock(&tmp_share->mutex); + mysql_mutex_lock(&tmp_share->mutex); bitmap_set_bit(&tmp_share->subscriber_bitmap[node_id], req_id); DBUG_PRINT("info",("SUBSCRIBE[%d] %d", node_id, req_id)); if (opt_ndb_extra_logging) @@ -2124,8 +2124,8 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, tmp_share->subscriber_bitmap[node_id].bitmap[1], tmp_share->subscriber_bitmap[node_id].bitmap[0]); } - (void) pthread_mutex_unlock(&tmp_share->mutex); - (void) pthread_cond_signal(&injector_cond); + mysql_mutex_unlock(&tmp_share->mutex); + mysql_cond_signal(&injector_cond); break; } case NDBEVENT::TE_UNSUBSCRIBE: @@ -2133,7 +2133,7 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, uint8 node_id= g_node_id_map[pOp->getNdbdNodeId()]; uint8 req_id= pOp->getReqNodeId(); DBUG_ASSERT(req_id != 0 && node_id != 0xFF); - (void) pthread_mutex_lock(&tmp_share->mutex); + mysql_mutex_lock(&tmp_share->mutex); bitmap_clear_bit(&tmp_share->subscriber_bitmap[node_id], req_id); DBUG_PRINT("info",("UNSUBSCRIBE[%d] %d", node_id, req_id)); if (opt_ndb_extra_logging) @@ -2145,8 +2145,8 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb, tmp_share->subscriber_bitmap[node_id].bitmap[1], tmp_share->subscriber_bitmap[node_id].bitmap[0]); } - (void) pthread_mutex_unlock(&tmp_share->mutex); - (void) pthread_cond_signal(&injector_cond); + mysql_mutex_unlock(&tmp_share->mutex); + mysql_cond_signal(&injector_cond); break; } default: @@ -2186,22 +2186,22 @@ ndb_binlog_thread_handle_schema_event_post_epoch(THD *thd, build_table_filename(key, sizeof(key) - 1, schema->db, schema->name, "", 0); if (schema_type == SOT_CLEAR_SLOCK) { - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); NDB_SCHEMA_OBJECT *ndb_schema_object= (NDB_SCHEMA_OBJECT*) my_hash_search(&ndb_schema_objects, (uchar*) key, strlen(key)); if (ndb_schema_object) { - pthread_mutex_lock(&ndb_schema_object->mutex); + mysql_mutex_lock(&ndb_schema_object->mutex); memcpy(ndb_schema_object->slock, schema->slock, sizeof(ndb_schema_object->slock)); DBUG_DUMP("ndb_schema_object->slock_bitmap.bitmap", (uchar*)ndb_schema_object->slock_bitmap.bitmap, no_bytes_in_map(&ndb_schema_object->slock_bitmap)); - pthread_mutex_unlock(&ndb_schema_object->mutex); - pthread_cond_signal(&injector_cond); + mysql_mutex_unlock(&ndb_schema_object->mutex); + mysql_cond_signal(&injector_cond); } - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); continue; } /* ndb_share reference temporary, free below */ @@ -2462,27 +2462,29 @@ int ndbcluster_binlog_start() DBUG_RETURN(-1); } - pthread_mutex_init(&injector_mutex, MY_MUTEX_INIT_FAST); - pthread_cond_init(&injector_cond, NULL); - pthread_mutex_init(&ndb_schema_share_mutex, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_injector_mutex, &injector_mutex, MY_MUTEX_INIT_FAST); + mysql_cond_init(key_injector_cond, &injector_cond, NULL); + mysql_mutex_init(key_ndb_schema_share_mutex, + &ndb_schema_share_mutex, MY_MUTEX_INIT_FAST); /* Create injector thread */ - if (pthread_create(&ndb_binlog_thread, &connection_attrib, - ndb_binlog_thread_func, 0)) + if (mysql_thread_create(key_thread_ndb_binlog, + &ndb_binlog_thread, &connection_attrib, + ndb_binlog_thread_func, 0)) { DBUG_PRINT("error", ("Could not create ndb injector thread")); - pthread_cond_destroy(&injector_cond); - pthread_mutex_destroy(&injector_mutex); + mysql_cond_destroy(&injector_cond); + mysql_mutex_destroy(&injector_mutex); DBUG_RETURN(-1); } ndbcluster_binlog_inited= 1; /* Wait for the injector thread to start */ - pthread_mutex_lock(&injector_mutex); + mysql_mutex_lock(&injector_mutex); while (!ndb_binlog_thread_running) - pthread_cond_wait(&injector_cond, &injector_mutex); - pthread_mutex_unlock(&injector_mutex); + mysql_cond_wait(&injector_cond, &injector_mutex); + mysql_mutex_unlock(&injector_mutex); if (ndb_binlog_thread_running < 0) DBUG_RETURN(-1); @@ -2572,7 +2574,7 @@ int ndbcluster_create_binlog_setup(Ndb *ndb, const char *key, DBUG_ASSERT(! IS_NDB_BLOB_PREFIX(table_name)); DBUG_ASSERT(strlen(key) == key_len); - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); /* Handle any trailing share */ NDB_SHARE *share= (NDB_SHARE*) my_hash_search(&ndbcluster_open_tables, @@ -2584,7 +2586,7 @@ int ndbcluster_create_binlog_setup(Ndb *ndb, const char *key, share->op != 0 || share->op_old != 0) { - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); DBUG_RETURN(0); // replication already setup, or should not } } @@ -2594,7 +2596,7 @@ int ndbcluster_create_binlog_setup(Ndb *ndb, const char *key, if (share->op || share->op_old) { my_errno= HA_ERR_TABLE_EXIST; - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); DBUG_RETURN(1); } if (!share_may_exist || share->connect_count != @@ -2637,10 +2639,10 @@ int ndbcluster_create_binlog_setup(Ndb *ndb, const char *key, if (!do_event_op) { share->flags|= NSF_NO_BINLOG; - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); DBUG_RETURN(0); } - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); while (share && !IS_TMP_PREFIX(table_name)) { @@ -2933,14 +2935,14 @@ ndbcluster_create_event_ops(NDB_SHARE *share, const NDBTAB *ndbtab, int retry_sleep= 100; while (1) { - pthread_mutex_lock(&injector_mutex); + mysql_mutex_lock(&injector_mutex); Ndb *ndb= injector_ndb; if (do_ndb_schema_share) ndb= schema_ndb; if (ndb == 0) { - pthread_mutex_unlock(&injector_mutex); + mysql_mutex_unlock(&injector_mutex); DBUG_RETURN(-1); } @@ -2965,7 +2967,7 @@ ndbcluster_create_event_ops(NDB_SHARE *share, const NDBTAB *ndbtab, ndb->getNdbError().code, ndb->getNdbError().message, "NDB"); - pthread_mutex_unlock(&injector_mutex); + mysql_mutex_unlock(&injector_mutex); DBUG_RETURN(-1); } @@ -3015,7 +3017,7 @@ ndbcluster_create_event_ops(NDB_SHARE *share, const NDBTAB *ndbtab, op->getNdbError().message, "NDB"); ndb->dropEventOperation(op); - pthread_mutex_unlock(&injector_mutex); + mysql_mutex_unlock(&injector_mutex); DBUG_RETURN(-1); } } @@ -3057,7 +3059,7 @@ ndbcluster_create_event_ops(NDB_SHARE *share, const NDBTAB *ndbtab, op->getNdbError().code, op->getNdbError().message); } ndb->dropEventOperation(op); - pthread_mutex_unlock(&injector_mutex); + mysql_mutex_unlock(&injector_mutex); if (retries) { my_sleep(retry_sleep); @@ -3065,7 +3067,7 @@ ndbcluster_create_event_ops(NDB_SHARE *share, const NDBTAB *ndbtab, } DBUG_RETURN(-1); } - pthread_mutex_unlock(&injector_mutex); + mysql_mutex_unlock(&injector_mutex); break; } @@ -3079,7 +3081,7 @@ ndbcluster_create_event_ops(NDB_SHARE *share, const NDBTAB *ndbtab, ndb_apply_status_share= get_share(share); DBUG_PRINT("NDB_SHARE", ("%s binlog extra use_count: %u", share->key, share->use_count)); - (void) pthread_cond_signal(&injector_cond); + mysql_cond_signal(&injector_cond); } else if (do_ndb_schema_share) { @@ -3087,7 +3089,7 @@ ndbcluster_create_event_ops(NDB_SHARE *share, const NDBTAB *ndbtab, ndb_schema_share= get_share(share); DBUG_PRINT("NDB_SHARE", ("%s binlog extra use_count: %u", share->key, share->use_count)); - (void) pthread_cond_signal(&injector_cond); + mysql_cond_signal(&injector_cond); } DBUG_PRINT("info",("%s share->op: 0x%lx share->use_count: %u", @@ -3158,7 +3160,7 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, #define SYNC_DROP_ #ifdef SYNC_DROP_ thd->proc_info= "Syncing ndb table schema operation and binlog"; - (void) pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); mysql_mutex_assert_owner(&LOCK_open); mysql_mutex_unlock(&LOCK_open); int max_timeout= DEFAULT_SYNC_TIMEOUT; @@ -3166,9 +3168,9 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, { struct timespec abstime; set_timespec(abstime, 1); - int ret= pthread_cond_timedwait(&injector_cond, - &share->mutex, - &abstime); + int ret= mysql_cond_timedwait(&injector_cond, + &share->mutex, + &abstime); if (thd->killed || share->op == 0) break; @@ -3187,12 +3189,12 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, } } mysql_mutex_lock(&LOCK_open); - (void) pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); #else - (void) pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); share->op_old= share->op; share->op= 0; - (void) pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); #endif thd->proc_info= save_proc_info; @@ -3560,7 +3562,7 @@ static NDB_SCHEMA_OBJECT *ndb_get_schema_object(const char *key, DBUG_PRINT("enter", ("key: '%s'", key)); if (!have_lock) - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); while (!(ndb_schema_object= (NDB_SCHEMA_OBJECT*) my_hash_search(&ndb_schema_objects, (uchar*) key, @@ -3586,7 +3588,7 @@ static NDB_SCHEMA_OBJECT *ndb_get_schema_object(const char *key, my_free((uchar*) ndb_schema_object, 0); break; } - pthread_mutex_init(&ndb_schema_object->mutex, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_ndb_schema_object_mutex, &ndb_schema_object->mutex, MY_MUTEX_INIT_FAST); bitmap_init(&ndb_schema_object->slock_bitmap, ndb_schema_object->slock, sizeof(ndb_schema_object->slock)*8, FALSE); bitmap_clear_all(&ndb_schema_object->slock_bitmap); @@ -3598,7 +3600,7 @@ static NDB_SCHEMA_OBJECT *ndb_get_schema_object(const char *key, DBUG_PRINT("info", ("use_count: %d", ndb_schema_object->use_count)); } if (!have_lock) - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); DBUG_RETURN(ndb_schema_object); } @@ -3609,12 +3611,12 @@ static void ndb_free_schema_object(NDB_SCHEMA_OBJECT **ndb_schema_object, DBUG_ENTER("ndb_free_schema_object"); DBUG_PRINT("enter", ("key: '%s'", (*ndb_schema_object)->key)); if (!have_lock) - pthread_mutex_lock(&ndbcluster_mutex); + mysql_mutex_lock(&ndbcluster_mutex); if (!--(*ndb_schema_object)->use_count) { DBUG_PRINT("info", ("use_count: %d", (*ndb_schema_object)->use_count)); my_hash_delete(&ndb_schema_objects, (uchar*) *ndb_schema_object); - pthread_mutex_destroy(&(*ndb_schema_object)->mutex); + mysql_mutex_destroy(&(*ndb_schema_object)->mutex); my_free((uchar*) *ndb_schema_object, MYF(0)); *ndb_schema_object= 0; } @@ -3623,7 +3625,7 @@ static void ndb_free_schema_object(NDB_SCHEMA_OBJECT **ndb_schema_object, DBUG_PRINT("info", ("use_count: %d", (*ndb_schema_object)->use_count)); } if (!have_lock) - pthread_mutex_unlock(&ndbcluster_mutex); + mysql_mutex_unlock(&ndbcluster_mutex); DBUG_VOID_RETURN; } @@ -3644,7 +3646,7 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) Timer main_timer; #endif - pthread_mutex_lock(&injector_mutex); + mysql_mutex_lock(&injector_mutex); /* Set up the Thread */ @@ -3661,14 +3663,16 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) thd->thread_id= thread_id++; pthread_mutex_unlock(&LOCK_thread_count); + mysql_thread_set_psi_id(thd->thread_id); + thd->thread_stack= (char*) &thd; /* remember where our stack is */ if (thd->store_globals()) { thd->cleanup(); delete thd; ndb_binlog_thread_running= -1; - pthread_mutex_unlock(&injector_mutex); - pthread_cond_signal(&injector_cond); + mysql_mutex_unlock(&injector_mutex); + mysql_cond_signal(&injector_cond); DBUG_LEAVE; // Must match DBUG_ENTER() my_thread_end(); @@ -3703,8 +3707,8 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) { sql_print_error("NDB Binlog: Getting Schema Ndb object failed"); ndb_binlog_thread_running= -1; - pthread_mutex_unlock(&injector_mutex); - pthread_cond_signal(&injector_cond); + mysql_mutex_unlock(&injector_mutex); + mysql_cond_signal(&injector_cond); goto err; } @@ -3714,8 +3718,8 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) { sql_print_error("NDB Binlog: Getting Ndb object failed"); ndb_binlog_thread_running= -1; - pthread_mutex_unlock(&injector_mutex); - pthread_cond_signal(&injector_cond); + mysql_mutex_unlock(&injector_mutex); + mysql_cond_signal(&injector_cond); goto err; } @@ -3728,7 +3732,7 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) Used by both sql client thread and binlog thread to interact with the storage - pthread_mutex_lock(&injector_mutex); + mysql_mutex_lock(&injector_mutex); */ injector_thd= thd; injector_ndb= i_ndb; @@ -3743,27 +3747,27 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) /* Thread start up completed */ ndb_binlog_thread_running= 1; - pthread_mutex_unlock(&injector_mutex); - pthread_cond_signal(&injector_cond); + mysql_mutex_unlock(&injector_mutex); + mysql_cond_signal(&injector_cond); /* wait for mysql server to start (so that the binlog is started and thus can receive the first GAP event) */ - pthread_mutex_lock(&LOCK_server_started); + mysql_mutex_lock(&LOCK_server_started); while (!mysqld_server_started) { struct timespec abstime; set_timespec(abstime, 1); - pthread_cond_timedwait(&COND_server_started, &LOCK_server_started, - &abstime); + mysql_cond_timedwait(&COND_server_started, &LOCK_server_started, + &abstime); if (ndbcluster_terminating) { - pthread_mutex_unlock(&LOCK_server_started); + mysql_mutex_unlock(&LOCK_server_started); goto err; } } - pthread_mutex_unlock(&LOCK_server_started); + mysql_mutex_unlock(&LOCK_server_started); restart: /* Main NDB Injector loop @@ -3806,21 +3810,21 @@ restart: { thd->proc_info= "Waiting for ndbcluster to start"; - pthread_mutex_lock(&injector_mutex); + mysql_mutex_lock(&injector_mutex); while (!ndb_schema_share || (ndb_binlog_running && !ndb_apply_status_share)) { /* ndb not connected yet */ struct timespec abstime; set_timespec(abstime, 1); - pthread_cond_timedwait(&injector_cond, &injector_mutex, &abstime); + mysql_cond_timedwait(&injector_cond, &injector_mutex, &abstime); if (ndbcluster_binlog_terminating) { - pthread_mutex_unlock(&injector_mutex); + mysql_mutex_unlock(&injector_mutex); goto err; } } - pthread_mutex_unlock(&injector_mutex); + mysql_mutex_unlock(&injector_mutex); if (thd_ndb == NULL) { @@ -4291,13 +4295,13 @@ err: DBUG_PRINT("info",("Shutting down cluster binlog thread")); thd->proc_info= "Shutting down"; close_thread_tables(thd); - pthread_mutex_lock(&injector_mutex); + mysql_mutex_lock(&injector_mutex); /* don't mess with the injector_ndb anymore from other threads */ injector_thd= 0; injector_ndb= 0; p_latest_trans_gci= 0; schema_ndb= 0; - pthread_mutex_unlock(&injector_mutex); + mysql_mutex_unlock(&injector_mutex); thd->db= 0; // as not to try to free memory if (ndb_apply_status_share) @@ -4312,7 +4316,7 @@ err: if (ndb_schema_share) { /* begin protect ndb_schema_share */ - pthread_mutex_lock(&ndb_schema_share_mutex); + mysql_mutex_lock(&ndb_schema_share_mutex); /* ndb_share reference binlog extra free */ DBUG_PRINT("NDB_SHARE", ("%s binlog extra free use_count: %u", ndb_schema_share->key, @@ -4320,7 +4324,7 @@ err: free_share(&ndb_schema_share); ndb_schema_share= 0; ndb_binlog_tables_inited= 0; - pthread_mutex_unlock(&ndb_schema_share_mutex); + mysql_mutex_unlock(&ndb_schema_share_mutex); /* end protect ndb_schema_share */ } @@ -4380,7 +4384,7 @@ err: ndb_binlog_thread_running= -1; ndb_binlog_running= FALSE; - (void) pthread_cond_signal(&injector_cond); + mysql_cond_signal(&injector_cond); DBUG_PRINT("exit", ("ndb_binlog_thread")); @@ -4399,12 +4403,12 @@ ndbcluster_show_status_binlog(THD* thd, stat_print_fn *stat_print, ulonglong ndb_latest_epoch= 0; DBUG_ENTER("ndbcluster_show_status_binlog"); - pthread_mutex_lock(&injector_mutex); + mysql_mutex_lock(&injector_mutex); if (injector_ndb) { char buff1[22],buff2[22],buff3[22],buff4[22],buff5[22]; ndb_latest_epoch= injector_ndb->getLatestGCI(); - pthread_mutex_unlock(&injector_mutex); + mysql_mutex_unlock(&injector_mutex); buflen= snprintf(buf, sizeof(buf), @@ -4424,7 +4428,7 @@ ndbcluster_show_status_binlog(THD* thd, stat_print_fn *stat_print, DBUG_RETURN(TRUE); } else - pthread_mutex_unlock(&injector_mutex); + mysql_mutex_unlock(&injector_mutex); DBUG_RETURN(FALSE); } diff --git a/sql/ha_ndbcluster_binlog.h b/sql/ha_ndbcluster_binlog.h index 4c64aa23c5b..32dac553ee8 100644 --- a/sql/ha_ndbcluster_binlog.h +++ b/sql/ha_ndbcluster_binlog.h @@ -1,7 +1,7 @@ #ifndef HA_NDBCLUSTER_BINLOG_INCLUDED #define HA_NDBCLUSTER_BINLOG_INCLUDED -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -104,16 +104,24 @@ private: }; #ifdef HAVE_NDB_BINLOG + +#ifdef HAVE_PSI_INTERFACE +extern PSI_mutex_key key_injector_mutex, key_ndb_schema_share_mutex, + key_ndb_schema_object_mutex; +extern PSI_cond_key key_injector_cond; +extern PSI_thread_key key_thread_ndb_binlog; +#endif /* HAVE_PSI_INTERFACE */ + extern pthread_t ndb_binlog_thread; -extern pthread_mutex_t injector_mutex; -extern pthread_cond_t injector_cond; +extern mysql_mutex_t injector_mutex; +extern mysql_cond_t injector_cond; extern unsigned char g_node_id_map[max_ndb_nodes]; extern pthread_t ndb_util_thread; -extern pthread_mutex_t LOCK_ndb_util_thread; -extern pthread_cond_t COND_ndb_util_thread; +extern mysql_mutex_t LOCK_ndb_util_thread; +extern mysql_cond_t COND_ndb_util_thread; extern int ndbcluster_util_inited; -extern pthread_mutex_t ndbcluster_mutex; +extern mysql_mutex_t ndbcluster_mutex; extern HASH ndbcluster_open_tables; extern Ndb_cluster_connection* g_ndb_cluster_connection; extern long ndb_number_of_storage_nodes; diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index d46d416e275..792dbf5d1c8 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -500,9 +500,9 @@ int ha_partition::create_handler_files(const char *path, strxmov(name, path, ha_par_ext, NullS); strxmov(old_name, old_path, ha_par_ext, NullS); if ((action_flag == CHF_DELETE_FLAG && - my_delete(name, MYF(MY_WME))) || + mysql_file_delete(key_file_partition, name, MYF(MY_WME))) || (action_flag == CHF_RENAME_FLAG && - my_rename(old_name, name, MYF(MY_WME)))) + mysql_file_rename(key_file_partition, old_name, name, MYF(MY_WME)))) { DBUG_RETURN(TRUE); } @@ -2205,12 +2205,13 @@ bool ha_partition::create_handler_file(const char *name) to be used at open, delete_table and rename_table */ fn_format(file_name, name, "", ha_par_ext, MY_APPEND_EXT); - if ((file= my_create(file_name, CREATE_MODE, O_RDWR | O_TRUNC, - MYF(MY_WME))) >= 0) + if ((file= mysql_file_create(key_file_partition, + file_name, CREATE_MODE, O_RDWR | O_TRUNC, + MYF(MY_WME))) >= 0) { - result= my_write(file, (uchar *) file_buffer, tot_len_byte, - MYF(MY_WME | MY_NABP)) != 0; - (void) my_close(file, MYF(0)); + result= mysql_file_write(file, (uchar *) file_buffer, tot_len_byte, + MYF(MY_WME | MY_NABP)) != 0; + (void) mysql_file_close(file, MYF(0)); } else result= TRUE; @@ -2387,17 +2388,18 @@ bool ha_partition::get_from_handler_file(const char *name, MEM_ROOT *mem_root) DBUG_RETURN(FALSE); fn_format(buff, name, "", ha_par_ext, MY_APPEND_EXT); - /* Following could be done with my_stat to read in whole file */ - if ((file= my_open(buff, O_RDONLY | O_SHARE, MYF(0))) < 0) + /* Following could be done with mysql_file_stat to read in whole file */ + if ((file= mysql_file_open(key_file_partition, + buff, O_RDONLY | O_SHARE, MYF(0))) < 0) DBUG_RETURN(TRUE); - if (my_read(file, (uchar *) & buff[0], 8, MYF(MY_NABP))) + if (mysql_file_read(file, (uchar *) &buff[0], 8, MYF(MY_NABP))) goto err1; len_words= uint4korr(buff); len_bytes= 4 * len_words; if (!(file_buffer= (char*) my_malloc(len_bytes, MYF(0)))) goto err1; - my_seek(file, 0, MY_SEEK_SET, MYF(0)); - if (my_read(file, (uchar *) file_buffer, len_bytes, MYF(MY_NABP))) + mysql_file_seek(file, 0, MY_SEEK_SET, MYF(0)); + if (mysql_file_read(file, (uchar *) file_buffer, len_bytes, MYF(MY_NABP))) goto err2; chksum= 0; @@ -2418,7 +2420,7 @@ bool ha_partition::get_from_handler_file(const char *name, MEM_ROOT *mem_root) if (len_words != (tot_partition_words + tot_name_words + 4)) goto err3; name_buffer_ptr= file_buffer + 16 + 4 * tot_partition_words; - (void) my_close(file, MYF(0)); + (void) mysql_file_close(file, MYF(0)); m_file_buffer= file_buffer; // Will be freed in clear_handler_file() m_name_buffer_ptr= name_buffer_ptr; @@ -2443,7 +2445,7 @@ err3: err2: my_free(file_buffer, MYF(0)); err1: - (void) my_close(file, MYF(0)); + (void) mysql_file_close(file, MYF(0)); DBUG_RETURN(TRUE); } @@ -2606,7 +2608,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) for the same table. */ if (is_not_tmp_table) - pthread_mutex_lock(&table_share->mutex); + mysql_mutex_lock(&table_share->mutex); if (!table_share->ha_data) { HA_DATA_PARTITION *ha_data; @@ -2617,7 +2619,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) if (!ha_data) { if (is_not_tmp_table) - pthread_mutex_unlock(&table_share->mutex); + mysql_mutex_unlock(&table_share->mutex); goto err_handler; } DBUG_PRINT("info", ("table_share->ha_data 0x%p", ha_data)); @@ -2626,7 +2628,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) pthread_mutex_init(&ha_data->mutex, MY_MUTEX_INIT_FAST); } if (is_not_tmp_table) - pthread_mutex_unlock(&table_share->mutex); + mysql_mutex_unlock(&table_share->mutex); /* Some handlers update statistics as part of the open call. This will in some cases corrupt the statistics of the partition handler and thus @@ -6633,7 +6635,7 @@ int ha_partition::indexes_are_disabled(void) #ifdef NOT_USED static HASH partition_open_tables; -static pthread_mutex_t partition_mutex; +static mysql_mutex_t partition_mutex; static int partition_init= 0; @@ -6671,17 +6673,17 @@ static PARTITION_SHARE *get_share(const char *table_name, TABLE *table) if (!partition_init) { /* Hijack a mutex for init'ing the storage engine */ - pthread_mutex_lock(&LOCK_mysql_create_db); + mysql_mutex_lock(&LOCK_mysql_create_db); if (!partition_init) { partition_init++; - pthread_mutex_init(&partition_mutex, MY_MUTEX_INIT_FAST); + mysql_mutex_init(INSTRUMENT_ME, &partition_mutex, MY_MUTEX_INIT_FAST); (void) hash_init(&partition_open_tables, system_charset_info, 32, 0, 0, (hash_get_key) partition_get_key, 0, 0); } - pthread_mutex_unlock(&LOCK_mysql_create_db); + mysql_mutex_unlock(&LOCK_mysql_create_db); } - pthread_mutex_lock(&partition_mutex); + mysql_mutex_lock(&partition_mutex); length= (uint) strlen(table_name); if (!(share= (PARTITION_SHARE *) hash_search(&partition_open_tables, @@ -6692,7 +6694,7 @@ static PARTITION_SHARE *get_share(const char *table_name, TABLE *table) &share, (uint) sizeof(*share), &tmp_name, (uint) length + 1, NullS))) { - pthread_mutex_unlock(&partition_mutex); + mysql_mutex_unlock(&partition_mutex); return NULL; } @@ -6703,15 +6705,15 @@ static PARTITION_SHARE *get_share(const char *table_name, TABLE *table) if (my_hash_insert(&partition_open_tables, (uchar *) share)) goto error; thr_lock_init(&share->lock); - pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST); + mysql_mutex_init(INSTRUMENT_ME, &share->mutex, MY_MUTEX_INIT_FAST); } share->use_count++; - pthread_mutex_unlock(&partition_mutex); + mysql_mutex_unlock(&partition_mutex); return share; error: - pthread_mutex_unlock(&partition_mutex); + mysql_mutex_unlock(&partition_mutex); my_free((uchar*) share, MYF(0)); return NULL; @@ -6726,15 +6728,15 @@ error: static int free_share(PARTITION_SHARE *share) { - pthread_mutex_lock(&partition_mutex); + mysql_mutex_lock(&partition_mutex); if (!--share->use_count) { hash_delete(&partition_open_tables, (uchar *) share); thr_lock_delete(&share->lock); - pthread_mutex_destroy(&share->mutex); + mysql_mutex_destroy(&share->mutex); my_free((uchar*) share, MYF(0)); } - pthread_mutex_unlock(&partition_mutex); + mysql_mutex_unlock(&partition_mutex); return 0; } diff --git a/sql/ha_partition.h b/sql/ha_partition.h index d4579d013fd..e2e6c674c5e 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -36,7 +36,7 @@ typedef struct st_partition_share { char *table_name; uint table_name_length, use_count; - pthread_mutex_t mutex; + mysql_mutex_t mutex; THR_LOCK lock; } PARTITION_SHARE; #endif @@ -933,7 +933,7 @@ private: if(table_share->tmp_table == NO_TMP_TABLE) { auto_increment_lock= TRUE; - pthread_mutex_lock(&table_share->mutex); + mysql_mutex_lock(&table_share->mutex); } } virtual void unlock_auto_increment() @@ -946,7 +946,7 @@ private: */ if(auto_increment_lock && !auto_increment_safe_stmt_log_lock) { - pthread_mutex_unlock(&table_share->mutex); + mysql_mutex_unlock(&table_share->mutex); auto_increment_lock= FALSE; } } diff --git a/sql/handler.cc b/sql/handler.cc index 784d02d7f4c..fa53c112156 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1,4 +1,4 @@ -/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. +/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. 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 @@ -1682,7 +1682,7 @@ bool mysql_xa_recover(THD *thd) Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) DBUG_RETURN(1); - pthread_mutex_lock(&LOCK_xid_cache); + mysql_mutex_lock(&LOCK_xid_cache); while ((xs= (XID_STATE*) my_hash_element(&xid_cache, i++))) { if (xs->xa_state==XA_PREPARED) @@ -1695,13 +1695,13 @@ bool mysql_xa_recover(THD *thd) &my_charset_bin); if (protocol->write()) { - pthread_mutex_unlock(&LOCK_xid_cache); + mysql_mutex_unlock(&LOCK_xid_cache); DBUG_RETURN(1); } } } - pthread_mutex_unlock(&LOCK_xid_cache); + mysql_mutex_unlock(&LOCK_xid_cache); my_eof(thd); DBUG_RETURN(0); } @@ -2104,6 +2104,10 @@ THD *handler::ha_thd(void) const return (table && table->in_use) ? table->in_use : current_thd; } +PSI_table_share *handler::ha_table_share_psi(const TABLE_SHARE *share) const +{ + return share->m_psi; +} /** @brief Open database-handler. @@ -2993,7 +2997,8 @@ static bool update_frm_version(TABLE *table) strxmov(path, table->s->normalized_path.str, reg_ext, NullS); - if ((file= my_open(path, O_RDWR|O_BINARY, MYF(MY_WME))) >= 0) + if ((file= mysql_file_open(key_file_frm, + path, O_RDWR|O_BINARY, MYF(MY_WME))) >= 0) { uchar version[4]; char *key= table->s->table_cache_key.str; @@ -3003,7 +3008,7 @@ static bool update_frm_version(TABLE *table) int4store(version, MYSQL_VERSION_ID); - if ((result= my_pwrite(file,(uchar*) version,4,51L,MYF_RW))) + if ((result= mysql_file_pwrite(file, (uchar*) version, 4, 51L, MYF_RW))) goto err; for (entry=(TABLE*) my_hash_first(&open_cache,(uchar*) key,key_length, &state); @@ -3013,7 +3018,7 @@ static bool update_frm_version(TABLE *table) } err: if (file >= 0) - (void) my_close(file,MYF(MY_WME)); + (void) mysql_file_close(file, MYF(MY_WME)); DBUG_RETURN(result); } @@ -3060,7 +3065,7 @@ int handler::delete_table(const char *name) for (const char **ext=bas_ext(); *ext ; ext++) { fn_format(buff, name, "", *ext, MY_UNPACK_FILENAME|MY_APPEND_EXT); - if (my_delete_with_symlink(buff, MYF(0))) + if (mysql_file_delete_with_symlink(key_file_misc, buff, MYF(0))) { if (my_errno != ENOENT) { @@ -3717,12 +3722,12 @@ int ha_init_key_cache(const char *name, KEY_CACHE *key_cache) if (!key_cache->key_cache_inited) { - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); size_t tmp_buff_size= (size_t) key_cache->param_buff_size; uint tmp_block_size= (uint) key_cache->param_block_size; uint division_limit= key_cache->param_division_limit; uint age_threshold= key_cache->param_age_threshold; - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); DBUG_RETURN(!init_key_cache(key_cache, tmp_block_size, tmp_buff_size, @@ -3741,12 +3746,12 @@ int ha_resize_key_cache(KEY_CACHE *key_cache) if (key_cache->key_cache_inited) { - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); size_t tmp_buff_size= (size_t) key_cache->param_buff_size; long tmp_block_size= (long) key_cache->param_block_size; uint division_limit= key_cache->param_division_limit; uint age_threshold= key_cache->param_age_threshold; - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); DBUG_RETURN(!resize_key_cache(key_cache, tmp_block_size, tmp_buff_size, division_limit, age_threshold)); @@ -3762,10 +3767,10 @@ int ha_change_key_cache_param(KEY_CACHE *key_cache) { if (key_cache->key_cache_inited) { - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); uint division_limit= key_cache->param_division_limit; uint age_threshold= key_cache->param_age_threshold; - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); change_key_cache_param(key_cache, division_limit, age_threshold); } return 0; @@ -4794,7 +4799,8 @@ int example_of_iterator_using_for_logs_cleanup(handlerton *hton) { printf("%s\n", data.filename.str); if (data.status == HA_LOG_STATUS_FREE && - my_delete(data.filename.str, MYF(MY_WME))) + mysql_file_delete(INSTRUMENT_ME, + data.filename.str, MYF(MY_WME))) goto err; } res= 0; @@ -4822,7 +4828,7 @@ err: enum log_status fl_get_log_status(char *log) { MY_STAT stat_buff; - if (my_stat(log, &stat_buff, MYF(0))) + if (mysql_file_stat(INSTRUMENT_ME, log, &stat_buff, MYF(0))) return HA_LOG_STATUS_INUSE; return HA_LOG_STATUS_NOSUCHLOG; } diff --git a/sql/handler.h b/sql/handler.h index 6d43c56edbf..711cc823f96 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1,7 +1,7 @@ #ifndef HANDLER_INCLUDED #define HANDLER_INCLUDED -/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. +/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. 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 @@ -16,7 +16,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - /* Definitions for parameters to do with handler-routines */ #ifdef USE_PRAGMA_INTERFACE @@ -305,6 +304,8 @@ enum legacy_db_type DB_TYPE_MEMCACHE, DB_TYPE_FALCON, DB_TYPE_MARIA, + /** Performance schema engine. */ + DB_TYPE_PERFORMANCE_SCHEMA, DB_TYPE_FIRST_DYNAMIC=42, DB_TYPE_DEFAULT=127 // Must be last }; @@ -1216,6 +1217,20 @@ public: */ uint auto_inc_intervals_count; + /** + Instrumented table associated with this handler. + This member should be set to NULL when no instrumentation is in place, + so that linking an instrumented/non instrumented server/plugin works. + For example: + - the server is compiled with the instrumentation. + The server expects either NULL or valid pointers in m_psi. + - an engine plugin is compiled without instrumentation. + The plugin can not leave this pointer uninitialized, + or can not leave a trash value on purpose in this pointer, + as this would crash the server. + */ + PSI_table *m_psi; + handler(handlerton *ht_arg, TABLE_SHARE *share_arg) :table_share(share_arg), table(0), estimation_rows_to_insert(0), ht(ht_arg), @@ -1224,7 +1239,8 @@ public: ft_handler(0), inited(NONE), locked(FALSE), implicit_emptied(0), pushed_cond(0), next_insert_id(0), insert_id_for_cur_row(0), - auto_inc_intervals_count(0) + auto_inc_intervals_count(0), + m_psi(NULL) {} virtual ~handler(void) { @@ -1825,6 +1841,39 @@ protected: THD *ha_thd(void) const; /** + Acquire the instrumented table information from a table share. + @param share a table share + @return an instrumented table share, or NULL. + */ + PSI_table_share *ha_table_share_psi(const TABLE_SHARE *share) const; + + inline void psi_open() + { + DBUG_ASSERT(m_psi == NULL); + DBUG_ASSERT(table_share != NULL); +#ifdef HAVE_PSI_INTERFACE + if (PSI_server) + { + PSI_table_share *share_psi= ha_table_share_psi(table_share); + if (share_psi) + m_psi= PSI_server->open_table(share_psi, this); + } +#endif + } + + inline void psi_close() + { +#ifdef HAVE_PSI_INTERFACE + if (PSI_server && m_psi) + { + PSI_server->close_table(m_psi); + m_psi= NULL; /* instrumentation handle, invalid after close_table() */ + } +#endif + DBUG_ASSERT(m_psi == NULL); + } + + /** Default rename_table() and delete_table() rename/delete files with a given name and extensions from bas_ext(). diff --git a/sql/hash_filo.h b/sql/hash_filo.h index 5d17b880b4d..805e1262020 100644 --- a/sql/hash_filo.h +++ b/sql/hash_filo.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003, 2005 MySQL AB +/* Copyright (C) 2000-2003, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -45,7 +45,7 @@ class hash_filo hash_filo_element *first_link,*last_link; public: - pthread_mutex_t lock; + mysql_mutex_t lock; HASH cache; hash_filo(uint size_arg, uint key_offset_arg , uint key_length_arg, @@ -64,7 +64,7 @@ public: { if (cache.array.buffer) /* Avoid problems with thread library */ (void) my_hash_free(&cache); - pthread_mutex_destroy(&lock); + mysql_mutex_destroy(&lock); } } void clear(bool locked=0) @@ -72,15 +72,15 @@ public: if (!init) { init=1; - (void) pthread_mutex_init(&lock,MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_hash_filo_lock, &lock, MY_MUTEX_INIT_FAST); } if (!locked) - (void) pthread_mutex_lock(&lock); + mysql_mutex_lock(&lock); (void) my_hash_free(&cache); (void) my_hash_init(&cache,hash_charset,size,key_offset, key_length, get_key, free_element,0); if (!locked) - (void) pthread_mutex_unlock(&lock); + mysql_mutex_unlock(&lock); first_link=last_link=0; } diff --git a/sql/hostname.cc b/sql/hostname.cc index cf35e60061f..5517d85527c 100644 --- a/sql/hostname.cc +++ b/sql/hostname.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -169,11 +169,11 @@ static bool add_hostname(const char *ip_key, const char *hostname) if (specialflag & SPECIAL_NO_HOST_CACHE) return FALSE; - pthread_mutex_lock(&hostname_cache->lock); + mysql_mutex_lock(&hostname_cache->lock); bool err_status= add_hostname_impl(ip_key, hostname); - pthread_mutex_unlock(&hostname_cache->lock); + mysql_mutex_unlock(&hostname_cache->lock); return err_status; } @@ -186,14 +186,14 @@ void inc_host_errors(const char *ip_string) char ip_key[HOST_ENTRY_KEY_SIZE]; prepare_hostname_cache_key(ip_string, ip_key); - pthread_mutex_lock(&hostname_cache->lock); + mysql_mutex_lock(&hostname_cache->lock); Host_entry *entry= hostname_cache_search(ip_key); if (entry) entry->connect_errors++; - pthread_mutex_unlock(&hostname_cache->lock); + mysql_mutex_unlock(&hostname_cache->lock); } @@ -205,14 +205,14 @@ void reset_host_errors(const char *ip_string) char ip_key[HOST_ENTRY_KEY_SIZE]; prepare_hostname_cache_key(ip_string, ip_key); - pthread_mutex_lock(&hostname_cache->lock); + mysql_mutex_lock(&hostname_cache->lock); Host_entry *entry= hostname_cache_search(ip_key); if (entry) entry->connect_errors= 0; - pthread_mutex_unlock(&hostname_cache->lock); + mysql_mutex_unlock(&hostname_cache->lock); } @@ -319,7 +319,7 @@ bool ip_to_hostname(struct sockaddr_storage *ip_storage, if (!(specialflag & SPECIAL_NO_HOST_CACHE)) { - pthread_mutex_lock(&hostname_cache->lock); + mysql_mutex_lock(&hostname_cache->lock); Host_entry *entry= hostname_cache_search(ip_key); @@ -337,12 +337,12 @@ bool ip_to_hostname(struct sockaddr_storage *ip_storage, (const char *) (*hostname? *hostname : "null"), (int) *connect_errors)); - pthread_mutex_unlock(&hostname_cache->lock); + mysql_mutex_unlock(&hostname_cache->lock); DBUG_RETURN(FALSE); } - pthread_mutex_unlock(&hostname_cache->lock); + mysql_mutex_unlock(&hostname_cache->lock); } /* diff --git a/sql/item_func.cc b/sql/item_func.cc index ec0f76717fd..557561789b2 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -5008,7 +5008,7 @@ void Item_func_get_system_var::fix_length_and_dec() break; case SHOW_CHAR: case SHOW_CHAR_PTR: - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); cptr= var->show_type() == SHOW_CHAR ? (char*) var->value_ptr(current_thd, var_type, &component) : *(char**) var->value_ptr(current_thd, var_type, &component); @@ -5016,19 +5016,19 @@ void Item_func_get_system_var::fix_length_and_dec() max_length= system_charset_info->cset->numchars(system_charset_info, cptr, cptr + strlen(cptr)); - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); collation.set(system_charset_info, DERIVATION_SYSCONST); max_length*= system_charset_info->mbmaxlen; decimals=NOT_FIXED_DEC; break; case SHOW_LEX_STRING: { - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); LEX_STRING *ls= ((LEX_STRING*)var->value_ptr(current_thd, var_type, &component)); max_length= system_charset_info->cset->numchars(system_charset_info, ls->str, ls->str + ls->length); - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); collation.set(system_charset_info, DERIVATION_SYSCONST); max_length*= system_charset_info->mbmaxlen; decimals=NOT_FIXED_DEC; @@ -5113,9 +5113,9 @@ enum_field_types Item_func_get_system_var::field_type() const #define get_sys_var_safe(type) \ do { \ type value; \ - pthread_mutex_lock(&LOCK_global_system_variables); \ + mysql_mutex_lock(&LOCK_global_system_variables); \ value= *(type*) var->value_ptr(thd, var_type, &component); \ - pthread_mutex_unlock(&LOCK_global_system_variables); \ + mysql_mutex_unlock(&LOCK_global_system_variables); \ cache_present |= GET_SYS_VAR_CACHE_LONG; \ used_query_id= thd->query_id; \ cached_llval= null_value ? 0 : (longlong) value; \ @@ -5238,7 +5238,7 @@ String* Item_func_get_system_var::val_str(String* str) case SHOW_CHAR_PTR: case SHOW_LEX_STRING: { - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); char *cptr= var->show_type() == SHOW_CHAR ? (char*) var->value_ptr(thd, var_type, &component) : *(char**) var->value_ptr(thd, var_type, &component); @@ -5258,7 +5258,7 @@ String* Item_func_get_system_var::val_str(String* str) null_value= TRUE; str= NULL; } - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); break; } @@ -5323,9 +5323,9 @@ double Item_func_get_system_var::val_real() switch (var->show_type()) { case SHOW_DOUBLE: - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); cached_dval= *(double*) var->value_ptr(thd, var_type, &component); - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); used_query_id= thd->query_id; cached_null_value= null_value; if (null_value) @@ -5336,7 +5336,7 @@ double Item_func_get_system_var::val_real() case SHOW_LEX_STRING: case SHOW_CHAR_PTR: { - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); char *cptr= var->show_type() == SHOW_CHAR ? (char*) var->value_ptr(thd, var_type, &component) : *(char**) var->value_ptr(thd, var_type, &component); @@ -5348,7 +5348,7 @@ double Item_func_get_system_var::val_real() null_value= TRUE; cached_dval= 0; } - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); used_query_id= thd->query_id; cached_null_value= null_value; cache_present|= GET_SYS_VAR_CACHE_DOUBLE; @@ -6281,8 +6281,8 @@ void uuid_short_init() longlong Item_func_uuid_short::val_int() { ulonglong val; - pthread_mutex_lock(&LOCK_uuid_generator); + mysql_mutex_lock(&LOCK_uuid_generator); val= uuid_value++; - pthread_mutex_unlock(&LOCK_uuid_generator); + mysql_mutex_unlock(&LOCK_uuid_generator); return (longlong) val; } diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index d63226f2dbb..d9ca1d17d82 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -465,18 +465,18 @@ String *Item_func_des_encrypt::val_str(String *str) if (arg_count == 1) { /* Protect against someone doing FLUSH DES_KEY_FILE */ - pthread_mutex_lock(&LOCK_des_key_file); + mysql_mutex_lock(&LOCK_des_key_file); keyschedule= des_keyschedule[key_number=des_default_key]; - pthread_mutex_unlock(&LOCK_des_key_file); + mysql_mutex_unlock(&LOCK_des_key_file); } else if (args[1]->result_type() == INT_RESULT) { key_number= (uint) args[1]->val_int(); if (key_number > 9) goto error; - pthread_mutex_lock(&LOCK_des_key_file); + mysql_mutex_lock(&LOCK_des_key_file); keyschedule= des_keyschedule[key_number]; - pthread_mutex_unlock(&LOCK_des_key_file); + mysql_mutex_unlock(&LOCK_des_key_file); } else { @@ -566,9 +566,9 @@ String *Item_func_des_decrypt::val_str(String *str) key_number > 9) goto error; - pthread_mutex_lock(&LOCK_des_key_file); + mysql_mutex_lock(&LOCK_des_key_file); keyschedule= des_keyschedule[key_number]; - pthread_mutex_unlock(&LOCK_des_key_file); + mysql_mutex_unlock(&LOCK_des_key_file); } else { @@ -1702,17 +1702,17 @@ String *Item_func_encrypt::val_str(String *str) return 0; salt_ptr= salt_str->c_ptr_safe(); } - pthread_mutex_lock(&LOCK_crypt); + mysql_mutex_lock(&LOCK_crypt); char *tmp= crypt(res->c_ptr_safe(),salt_ptr); if (!tmp) { - pthread_mutex_unlock(&LOCK_crypt); + mysql_mutex_unlock(&LOCK_crypt); null_value= 1; return 0; } str->set(tmp, (uint) strlen(tmp), &my_charset_bin); str->copy(); - pthread_mutex_unlock(&LOCK_crypt); + mysql_mutex_unlock(&LOCK_crypt); return str; #else null_value=1; @@ -2998,7 +2998,7 @@ String *Item_load_file::val_str(String *str) strncmp(opt_secure_file_priv, path, strlen(opt_secure_file_priv))) goto err; - if (!my_stat(path, &stat_info, MYF(0))) + if (!mysql_file_stat(key_file_loadfile, path, &stat_info, MYF(0))) goto err; if (!(stat_info.st_mode & S_IROTH)) @@ -3016,15 +3016,17 @@ String *Item_load_file::val_str(String *str) } if (tmp_value.alloc(stat_info.st_size)) goto err; - if ((file = my_open(file_name->ptr(), O_RDONLY, MYF(0))) < 0) + if ((file= mysql_file_open(key_file_loadfile, + file_name->ptr(), O_RDONLY, MYF(0))) < 0) goto err; - if (my_read(file, (uchar*) tmp_value.ptr(), stat_info.st_size, MYF(MY_NABP))) + if (mysql_file_read(file, (uchar*) tmp_value.ptr(), stat_info.st_size, + MYF(MY_NABP))) { - my_close(file, MYF(0)); + mysql_file_close(file, MYF(0)); goto err; } tmp_value.length(stat_info.st_size); - my_close(file, MYF(0)); + mysql_file_close(file, MYF(0)); null_value = 0; DBUG_RETURN(&tmp_value); @@ -3468,7 +3470,7 @@ String *Item_func_uuid::val_str(String *str) char *s; THD *thd= current_thd; - pthread_mutex_lock(&LOCK_uuid_generator); + mysql_mutex_lock(&LOCK_uuid_generator); if (! uuid_time) /* first UUID() call. initializing data */ { ulong tmp=sql_rnd_with_mutex(); @@ -3558,7 +3560,7 @@ String *Item_func_uuid::val_str(String *str) } uuid_time=tv; - pthread_mutex_unlock(&LOCK_uuid_generator); + mysql_mutex_unlock(&LOCK_uuid_generator); uint32 time_low= (uint32) (tv & 0xFFFFFFFF); uint16 time_mid= (uint16) ((tv >> 32) & 0xFFFF); diff --git a/sql/lock.cc b/sql/lock.cc index e60259f6acc..0235c4ae881 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -1436,7 +1436,7 @@ bool lock_global_read_lock(THD *thd) if (!thd->global_read_lock) { const char *old_message; - (void) pthread_mutex_lock(&LOCK_global_read_lock); + mysql_mutex_lock(&LOCK_global_read_lock); old_message=thd->enter_cond(&COND_global_read_lock, &LOCK_global_read_lock, "Waiting to get readlock"); DBUG_PRINT("info", @@ -1445,7 +1445,7 @@ bool lock_global_read_lock(THD *thd) waiting_for_read_lock++; while (protect_against_global_read_lock && !thd->killed) - pthread_cond_wait(&COND_global_read_lock, &LOCK_global_read_lock); + mysql_cond_wait(&COND_global_read_lock, &LOCK_global_read_lock); waiting_for_read_lock--; if (thd->killed) { @@ -1476,16 +1476,16 @@ void unlock_global_read_lock(THD *thd) ("global_read_lock: %u global_read_lock_blocks_commit: %u", global_read_lock, global_read_lock_blocks_commit)); - pthread_mutex_lock(&LOCK_global_read_lock); + mysql_mutex_lock(&LOCK_global_read_lock); tmp= --global_read_lock; if (thd->global_read_lock == MADE_GLOBAL_READ_LOCK_BLOCK_COMMIT) --global_read_lock_blocks_commit; - pthread_mutex_unlock(&LOCK_global_read_lock); + mysql_mutex_unlock(&LOCK_global_read_lock); /* Send the signal outside the mutex to avoid a context switch */ if (!tmp) { DBUG_PRINT("signal", ("Broadcasting COND_global_read_lock")); - pthread_cond_broadcast(&COND_global_read_lock); + mysql_cond_broadcast(&COND_global_read_lock); } thd->global_read_lock= 0; @@ -1510,7 +1510,7 @@ bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh, */ mysql_mutex_assert_not_owner(&LOCK_open); - (void) pthread_mutex_lock(&LOCK_global_read_lock); + mysql_mutex_lock(&LOCK_global_read_lock); if ((need_exit_cond= must_wait)) { if (thd->global_read_lock) // This thread had the read locks @@ -1518,7 +1518,7 @@ bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh, if (is_not_commit) my_message(ER_CANT_UPDATE_WITH_READLOCK, ER(ER_CANT_UPDATE_WITH_READLOCK), MYF(0)); - (void) pthread_mutex_unlock(&LOCK_global_read_lock); + mysql_mutex_unlock(&LOCK_global_read_lock); /* We allow FLUSHer to COMMIT; we assume FLUSHer knows what it does. This allowance is needed to not break existing versions of innobackup @@ -1532,7 +1532,7 @@ bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh, (!abort_on_refresh || thd->version == refresh_version)) { DBUG_PRINT("signal", ("Waiting for COND_global_read_lock")); - (void) pthread_cond_wait(&COND_global_read_lock, &LOCK_global_read_lock); + mysql_cond_wait(&COND_global_read_lock, &LOCK_global_read_lock); DBUG_PRINT("signal", ("Got COND_global_read_lock")); } if (thd->killed) @@ -1547,7 +1547,7 @@ bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh, if (unlikely(need_exit_cond)) thd->exit_cond(old_message); // this unlocks LOCK_global_read_lock else - pthread_mutex_unlock(&LOCK_global_read_lock); + mysql_mutex_unlock(&LOCK_global_read_lock); DBUG_RETURN(result); } @@ -1558,13 +1558,13 @@ void start_waiting_global_read_lock(THD *thd) DBUG_ENTER("start_waiting_global_read_lock"); if (unlikely(thd->global_read_lock)) DBUG_VOID_RETURN; - (void) pthread_mutex_lock(&LOCK_global_read_lock); + mysql_mutex_lock(&LOCK_global_read_lock); DBUG_ASSERT(protect_against_global_read_lock); tmp= (!--protect_against_global_read_lock && (waiting_for_read_lock || global_read_lock_blocks_commit)); - (void) pthread_mutex_unlock(&LOCK_global_read_lock); + mysql_mutex_unlock(&LOCK_global_read_lock); if (tmp) - pthread_cond_broadcast(&COND_global_read_lock); + mysql_cond_broadcast(&COND_global_read_lock); DBUG_VOID_RETURN; } @@ -1580,7 +1580,7 @@ bool make_global_read_lock_block_commit(THD *thd) */ if (thd->global_read_lock != GOT_GLOBAL_READ_LOCK) DBUG_RETURN(0); - pthread_mutex_lock(&LOCK_global_read_lock); + mysql_mutex_lock(&LOCK_global_read_lock); /* increment this BEFORE waiting on cond (otherwise race cond) */ global_read_lock_blocks_commit++; /* For testing we set up some blocking, to see if we can be killed */ @@ -1589,7 +1589,7 @@ bool make_global_read_lock_block_commit(THD *thd) old_message= thd->enter_cond(&COND_global_read_lock, &LOCK_global_read_lock, "Waiting for all running commits to finish"); while (protect_against_global_read_lock && !thd->killed) - pthread_cond_wait(&COND_global_read_lock, &LOCK_global_read_lock); + mysql_cond_wait(&COND_global_read_lock, &LOCK_global_read_lock); DBUG_EXECUTE_IF("make_global_read_lock_block_commit_loop", protect_against_global_read_lock--;); if ((error= test(thd->killed))) @@ -1623,7 +1623,7 @@ bool make_global_read_lock_block_commit(THD *thd) void broadcast_refresh(void) { mysql_cond_broadcast(&COND_refresh); - pthread_cond_broadcast(&COND_global_read_lock); + mysql_cond_broadcast(&COND_global_read_lock); } /** diff --git a/sql/log.cc b/sql/log.cc index 74239555c88..3680398f068 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1,4 +1,4 @@ -/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. +/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. 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 @@ -168,24 +168,24 @@ char *make_log_name(char *buff, const char *name, const char* log_ext) class Mutex_sentry { public: - Mutex_sentry(pthread_mutex_t *mutex) + Mutex_sentry(mysql_mutex_t *mutex) : m_mutex(mutex) { if (m_mutex) - pthread_mutex_lock(mutex); + mysql_mutex_lock(mutex); } ~Mutex_sentry() { if (m_mutex) - pthread_mutex_unlock(m_mutex); + mysql_mutex_unlock(m_mutex); #ifndef DBUG_OFF m_mutex= 0; #endif } private: - pthread_mutex_t *m_mutex; + mysql_mutex_t *m_mutex; // It's not allowed to copy this object in any way Mutex_sentry(Mutex_sentry const&); @@ -437,7 +437,7 @@ bool Log_to_csv_event_handler:: table_list.db_length= MYSQL_SCHEMA_NAME.length; /* - 1) open_performance_schema_table generates an error of the + 1) open_log_table generates an error of the table can not be opened or is corrupted. 2) "INSERT INTO general_log" can generate warning sometimes. @@ -450,8 +450,7 @@ bool Log_to_csv_event_handler:: thd->push_internal_handler(& error_handler); need_pop= TRUE; - if (!(table= open_performance_schema_table(thd, & table_list, - & open_tables_backup))) + if (!(table= open_log_table(thd, &table_list, &open_tables_backup))) goto err; need_close= TRUE; @@ -531,7 +530,7 @@ err: if (need_pop) thd->pop_internal_handler(); if (need_close) - close_performance_schema_table(thd, & open_tables_backup); + close_log_table(thd, &open_tables_backup); thd->variables.option_bits= save_thd_options; thd->time_zone_used= save_time_zone_used; @@ -601,8 +600,7 @@ bool Log_to_csv_event_handler:: table_list.db= MYSQL_SCHEMA_NAME.str; table_list.db_length= MYSQL_SCHEMA_NAME.length; - if (!(table= open_performance_schema_table(thd, & table_list, - & open_tables_backup))) + if (!(table= open_log_table(thd, &table_list, &open_tables_backup))) goto err; need_close= TRUE; @@ -727,7 +725,7 @@ err: table->file->ha_release_auto_increment(); } if (need_close) - close_performance_schema_table(thd, & open_tables_backup); + close_log_table(thd, &open_tables_backup); thd->time_zone_used= save_time_zone_used; DBUG_RETURN(result); } @@ -761,12 +759,11 @@ int Log_to_csv_event_handler:: table_list.db= MYSQL_SCHEMA_NAME.str; table_list.db_length= MYSQL_SCHEMA_NAME.length; - table= open_performance_schema_table(thd, & table_list, - & open_tables_backup); + table= open_log_table(thd, &table_list, &open_tables_backup); if (table) { result= 0; - close_performance_schema_table(thd, & open_tables_backup); + close_log_table(thd, &open_tables_backup); } else result= 1; @@ -902,7 +899,7 @@ bool LOGGER::error_log_print(enum loglevel level, const char *format, void LOGGER::cleanup_base() { DBUG_ASSERT(inited == 1); - rwlock_destroy(&LOCK_logger); + mysql_rwlock_destroy(&LOCK_logger); if (table_log_handler) { table_log_handler->cleanup(); @@ -947,7 +944,7 @@ void LOGGER::init_base() init_error_log(LOG_FILE); file_log_handler->init_pthread_objects(); - my_rwlock_init(&LOCK_logger, NULL); + mysql_rwlock_init(key_rwlock_LOCK_logger, &LOCK_logger); } @@ -1815,8 +1812,9 @@ File open_binlog(IO_CACHE *log, const char *log_file_name, const char **errmsg) File file; DBUG_ENTER("open_binlog"); - if ((file = my_open(log_file_name, O_RDONLY | O_BINARY | O_SHARE, - MYF(MY_WME))) < 0) + if ((file= mysql_file_open(key_file_binlog, + log_file_name, O_RDONLY | O_BINARY | O_SHARE, + MYF(MY_WME))) < 0) { sql_print_error("Failed to open log (file '%s', errno %d)", log_file_name, my_errno); @@ -1838,7 +1836,7 @@ File open_binlog(IO_CACHE *log, const char *log_file_name, const char **errmsg) err: if (file >= 0) { - my_close(file,MYF(0)); + mysql_file_close(file, MYF(0)); end_io_cache(log); } DBUG_RETURN(-1); @@ -2048,10 +2046,11 @@ bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg, db[0]= 0; - if ((file= my_open(log_file_name, open_flags, - MYF(MY_WME | ME_WAITTANG))) < 0 || + if ((file= mysql_file_open(key_file_MYSQL_LOG, + log_file_name, open_flags, + MYF(MY_WME | ME_WAITTANG))) < 0 || init_io_cache(&log_file, file, IO_SIZE, io_cache_type, - my_tell(file, MYF(MY_WME)), 0, + mysql_file_tell(file, MYF(MY_WME)), 0, MYF(MY_WME | MY_NABP | ((log_type == LOG_BIN) ? MY_WAIT_IF_FULL : 0)))) goto err; @@ -2089,7 +2088,7 @@ Turning logging off for the whole duration of the MySQL server process. \ To turn it on again: fix the cause, \ shutdown the MySQL server and restart it.", name, errno); if (file >= 0) - my_close(file, MYF(0)); + mysql_file_close(file, MYF(0)); end_io_cache(&log_file); safeFree(name); log_state= LOG_CLOSED; @@ -2113,7 +2112,7 @@ void MYSQL_LOG::init_pthread_objects() { DBUG_ASSERT(inited == 0); inited= 1; - (void) pthread_mutex_init(&LOCK_log, MY_MUTEX_INIT_SLOW); + mysql_mutex_init(key_LOG_LOCK_log, &LOCK_log, MY_MUTEX_INIT_SLOW); } /* @@ -2138,13 +2137,13 @@ void MYSQL_LOG::close(uint exiting) { end_io_cache(&log_file); - if (my_sync(log_file.file, MYF(MY_WME)) && ! write_error) + if (mysql_file_sync(log_file.file, MYF(MY_WME)) && ! write_error) { write_error= 1; sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno); } - if (my_close(log_file.file, MYF(MY_WME)) && ! write_error) + if (mysql_file_close(log_file.file, MYF(MY_WME)) && ! write_error) { write_error= 1; sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno); @@ -2164,7 +2163,7 @@ void MYSQL_LOG::cleanup() if (inited) { inited= 0; - (void) pthread_mutex_destroy(&LOCK_log); + mysql_mutex_destroy(&LOCK_log); close(0); } DBUG_VOID_RETURN; @@ -2219,7 +2218,7 @@ void MYSQL_QUERY_LOG::reopen_file() DBUG_VOID_RETURN; } - pthread_mutex_lock(&LOCK_log); + mysql_mutex_lock(&LOCK_log); save_name= name; name= 0; // Don't free name @@ -2232,7 +2231,7 @@ void MYSQL_QUERY_LOG::reopen_file() open(save_name, log_type, 0, io_cache_type); my_free(save_name, MYF(0)); - pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); DBUG_VOID_RETURN; } @@ -2274,7 +2273,7 @@ bool MYSQL_QUERY_LOG::write(time_t event_time, const char *user_host, struct tm start; uint time_buff_len= 0; - (void) pthread_mutex_lock(&LOCK_log); + mysql_mutex_lock(&LOCK_log); /* Test if someone closed between the is_open test and lock */ if (is_open()) @@ -2323,7 +2322,7 @@ bool MYSQL_QUERY_LOG::write(time_t event_time, const char *user_host, goto err; } - (void) pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); return FALSE; err: @@ -2332,7 +2331,7 @@ err: write_error= 1; sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno); } - (void) pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); return TRUE; } @@ -2375,11 +2374,11 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time, bool error= 0; DBUG_ENTER("MYSQL_QUERY_LOG::write"); - (void) pthread_mutex_lock(&LOCK_log); + mysql_mutex_lock(&LOCK_log); if (!is_open()) { - (void) pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); DBUG_RETURN(0); } @@ -2488,7 +2487,7 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time, } } } - (void) pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); DBUG_RETURN(error); } @@ -2550,9 +2549,9 @@ void MYSQL_BIN_LOG::cleanup() close(LOG_CLOSE_INDEX|LOG_CLOSE_STOP_EVENT); delete description_event_for_queue; delete description_event_for_exec; - (void) pthread_mutex_destroy(&LOCK_log); - (void) pthread_mutex_destroy(&LOCK_index); - (void) pthread_cond_destroy(&update_cond); + mysql_mutex_destroy(&LOCK_log); + mysql_mutex_destroy(&LOCK_index); + mysql_cond_destroy(&update_cond); } DBUG_VOID_RETURN; } @@ -2573,9 +2572,9 @@ void MYSQL_BIN_LOG::init_pthread_objects() { DBUG_ASSERT(inited == 0); inited= 1; - (void) pthread_mutex_init(&LOCK_log, MY_MUTEX_INIT_SLOW); - (void) pthread_mutex_init(&LOCK_index, MY_MUTEX_INIT_SLOW); - (void) pthread_cond_init(&update_cond, 0); + mysql_mutex_init(key_LOG_LOCK_log, &LOCK_log, MY_MUTEX_INIT_SLOW); + mysql_mutex_init(key_BINLOG_LOCK_index, &LOCK_index, MY_MUTEX_INIT_SLOW); + mysql_cond_init(key_BINLOG_update_cond, &update_cond, 0); } @@ -2598,23 +2597,25 @@ bool MYSQL_BIN_LOG::open_index_file(const char *index_file_name_arg, } fn_format(index_file_name, index_file_name_arg, mysql_data_home, ".index", opt); - if ((index_file_nr= my_open(index_file_name, - O_RDWR | O_CREAT | O_BINARY , - MYF(MY_WME))) < 0 || - my_sync(index_file_nr, MYF(MY_WME)) || + if ((index_file_nr= mysql_file_open(key_file_binlog_index, + index_file_name, + O_RDWR | O_CREAT | O_BINARY, + MYF(MY_WME))) < 0 || + mysql_file_sync(index_file_nr, MYF(MY_WME)) || init_io_cache(&index_file, index_file_nr, IO_SIZE, WRITE_CACHE, - my_seek(index_file_nr,0L,MY_SEEK_END,MYF(0)), - 0, MYF(MY_WME | MY_WAIT_IF_FULL)) || + mysql_file_seek(index_file_nr, 0L, MY_SEEK_END, MYF(0)), + 0, MYF(MY_WME | MY_WAIT_IF_FULL)) || DBUG_EVALUATE_IF("fault_injection_openning_index", 1, 0)) { /* TODO: all operations creating/deleting the index file or a log, should call my_sync_dir() or my_sync_dir_by_file() to be durable. - TODO: file creation should be done with my_create() not my_open(). + TODO: file creation should be done with mysql_file_create() + not mysql_file_open(). */ if (index_file_nr >= 0) - my_close(index_file_nr,MYF(0)); + mysql_file_close(index_file_nr, MYF(0)); return TRUE; } @@ -2778,7 +2779,7 @@ bool MYSQL_BIN_LOG::open(const char *log_name, bytes_written+= description_event_for_queue->data_written; } if (flush_io_cache(&log_file) || - my_sync(log_file.file, MYF(MY_WME))) + mysql_file_sync(log_file.file, MYF(MY_WME))) goto err; if (write_file_name_to_index_file) @@ -2799,7 +2800,7 @@ bool MYSQL_BIN_LOG::open(const char *log_name, strlen(log_file_name)) || my_b_write(&index_file, (uchar*) "\n", 1) || flush_io_cache(&index_file) || - my_sync(index_file.file, MYF(MY_WME))) + mysql_file_sync(index_file.file, MYF(MY_WME))) goto err; #ifdef HAVE_REPLICATION @@ -2826,7 +2827,7 @@ Turning logging off for the whole duration of the MySQL server process. \ To turn it on again: fix the cause, \ shutdown the MySQL server and restart it.", name, errno); if (file >= 0) - my_close(file,MYF(0)); + mysql_file_close(file, MYF(0)); end_io_cache(&log_file); end_io_cache(&index_file); safeFree(name); @@ -2837,9 +2838,9 @@ shutdown the MySQL server and restart it.", name, errno); int MYSQL_BIN_LOG::get_current_log(LOG_INFO* linfo) { - pthread_mutex_lock(&LOCK_log); + mysql_mutex_lock(&LOCK_log); int ret = raw_get_current_log(linfo); - pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); return ret; } @@ -2879,19 +2880,20 @@ static bool copy_up_file_and_fill(IO_CACHE *index_file, my_off_t offset) for (;; offset+= bytes_read) { - (void) my_seek(file, offset, MY_SEEK_SET, MYF(0)); - if ((bytes_read= (int) my_read(file, io_buf, sizeof(io_buf), MYF(MY_WME))) + mysql_file_seek(file, offset, MY_SEEK_SET, MYF(0)); + if ((bytes_read= (int) mysql_file_read(file, io_buf, sizeof(io_buf), + MYF(MY_WME))) < 0) goto err; if (!bytes_read) break; // end of file - (void) my_seek(file, offset-init_offset, MY_SEEK_SET, MYF(0)); - if (my_write(file, io_buf, bytes_read, MYF(MY_WME | MY_NABP))) + mysql_file_seek(file, offset-init_offset, MY_SEEK_SET, MYF(0)); + if (mysql_file_write(file, io_buf, bytes_read, MYF(MY_WME | MY_NABP))) goto err; } /* The following will either truncate the file or fill the end with \n' */ - if (my_chsize(file, offset - init_offset, '\n', MYF(MY_WME)) || - my_sync(file, MYF(MY_WME))) + if (mysql_file_chsize(file, offset - init_offset, '\n', MYF(MY_WME)) || + mysql_file_sync(file, MYF(MY_WME))) goto err; /* Reset data in old index cache */ @@ -2940,8 +2942,8 @@ int MYSQL_BIN_LOG::find_log_pos(LOG_INFO *linfo, const char *log_name, move from under our feet */ if (need_lock) - pthread_mutex_lock(&LOCK_index); - safe_mutex_assert_owner(&LOCK_index); + mysql_mutex_lock(&LOCK_index); + mysql_mutex_assert_owner(&LOCK_index); /* As the file is flushed, we can't get an error here */ (void) reinit_io_cache(&index_file, READ_CACHE, (my_off_t) 0, 0, 0); @@ -2975,7 +2977,7 @@ int MYSQL_BIN_LOG::find_log_pos(LOG_INFO *linfo, const char *log_name, } if (need_lock) - pthread_mutex_unlock(&LOCK_index); + mysql_mutex_unlock(&LOCK_index); DBUG_RETURN(error); } @@ -3011,8 +3013,8 @@ int MYSQL_BIN_LOG::find_next_log(LOG_INFO* linfo, bool need_lock) char *fname= linfo->log_file_name; if (need_lock) - pthread_mutex_lock(&LOCK_index); - safe_mutex_assert_owner(&LOCK_index); + mysql_mutex_lock(&LOCK_index); + mysql_mutex_assert_owner(&LOCK_index); /* As the file is flushed, we can't get an error here */ (void) reinit_io_cache(&index_file, READ_CACHE, linfo->index_file_offset, 0, @@ -3029,7 +3031,7 @@ int MYSQL_BIN_LOG::find_next_log(LOG_INFO* linfo, bool need_lock) err: if (need_lock) - pthread_mutex_unlock(&LOCK_index); + mysql_mutex_unlock(&LOCK_index); return error; } @@ -3064,8 +3066,8 @@ bool MYSQL_BIN_LOG::reset_logs(THD* thd) We need to get both locks to be sure that no one is trying to write to the index log file. */ - pthread_mutex_lock(&LOCK_log); - pthread_mutex_lock(&LOCK_index); + mysql_mutex_lock(&LOCK_log); + mysql_mutex_lock(&LOCK_index); /* The following mutex is needed to ensure that no threads call @@ -3167,8 +3169,8 @@ err: if (error == 1) name= const_cast<char*>(save_name); pthread_mutex_unlock(&LOCK_thread_count); - pthread_mutex_unlock(&LOCK_index); - pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_index); + mysql_mutex_unlock(&LOCK_log); DBUG_RETURN(error); } @@ -3222,7 +3224,7 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included) DBUG_ASSERT(rli->slave_running == 1); DBUG_ASSERT(!strcmp(rli->linfo.log_file_name,rli->event_relay_log_name)); - pthread_mutex_lock(&LOCK_index); + mysql_mutex_lock(&LOCK_index); to_purge_if_included= my_strdup(rli->group_relay_log_name, MYF(0)); /* @@ -3266,19 +3268,19 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included) DBUG_EXECUTE_IF("crash_before_purge_logs", abort();); - pthread_mutex_lock(&rli->log_space_lock); + mysql_mutex_lock(&rli->log_space_lock); rli->relay_log.purge_logs(to_purge_if_included, included, 0, 0, &rli->log_space_total); // Tell the I/O thread to take the relay_log_space_limit into account rli->ignore_log_space_limit= 0; - pthread_mutex_unlock(&rli->log_space_lock); + mysql_mutex_unlock(&rli->log_space_lock); /* Ok to broadcast after the critical region as there is no risk of the mutex being destroyed by this thread later - this helps save context switches */ - pthread_cond_broadcast(&rli->log_space_cond); + mysql_cond_broadcast(&rli->log_space_cond); /* * Need to update the log pos because purge logs has been called @@ -3300,7 +3302,7 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included) err: my_free(to_purge_if_included, MYF(0)); - pthread_mutex_unlock(&LOCK_index); + mysql_mutex_unlock(&LOCK_index); DBUG_RETURN(error); } @@ -3340,7 +3342,7 @@ int MYSQL_BIN_LOG::update_log_index(LOG_INFO* log_info, bool need_update_threads LOG_INFO_EOF to_log not found LOG_INFO_EMFILE too many files opened LOG_INFO_FATAL if any other than ENOENT error from - my_stat() or my_delete() + mysql_file_stat() or mysql_file_delete() */ int MYSQL_BIN_LOG::purge_logs(const char *to_log, @@ -3357,7 +3359,7 @@ int MYSQL_BIN_LOG::purge_logs(const char *to_log, DBUG_PRINT("info",("to_log= %s",to_log)); if (need_mutex) - pthread_mutex_lock(&LOCK_index); + mysql_mutex_lock(&LOCK_index); if ((error=find_log_pos(&log_info, to_log, 0 /*no mutex*/))) { sql_print_error("MYSQL_BIN_LOG::purge_logs was called with file %s not " @@ -3420,7 +3422,7 @@ err: DBUG_EXECUTE_IF("crash_purge_non_critical_after_update_index", abort();); if (need_mutex) - pthread_mutex_unlock(&LOCK_index); + mysql_mutex_unlock(&LOCK_index); DBUG_RETURN(error); } @@ -3559,7 +3561,7 @@ int MYSQL_BIN_LOG::purge_index_entry(THD *thd, ulonglong *decrease_log_space, /* Get rid of the trailing '\n' */ log_info.log_file_name[length-1]= 0; - if (!my_stat(log_info.log_file_name, &s, MYF(0))) + if (!mysql_file_stat(key_file_binlog, log_info.log_file_name, &s, MYF(0))) { if (my_errno == ENOENT) { @@ -3573,7 +3575,7 @@ int MYSQL_BIN_LOG::purge_index_entry(THD *thd, ulonglong *decrease_log_space, ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE), log_info.log_file_name); } - sql_print_information("Failed to execute my_stat on file '%s'", + sql_print_information("Failed to execute mysql_file_stat on file '%s'", log_info.log_file_name); my_errno= 0; } @@ -3711,7 +3713,7 @@ err: @retval LOG_INFO_PURGE_NO_ROTATE Binary file that can't be rotated LOG_INFO_FATAL if any other than ENOENT error from - my_stat() or my_delete() + mysql_file_stat() or mysql_file_delete() */ int MYSQL_BIN_LOG::purge_logs_before_date(time_t purge_time) @@ -3724,7 +3726,7 @@ int MYSQL_BIN_LOG::purge_logs_before_date(time_t purge_time) DBUG_ENTER("purge_logs_before_date"); - pthread_mutex_lock(&LOCK_index); + mysql_mutex_lock(&LOCK_index); to_log[0]= 0; if ((error=find_log_pos(&log_info, NullS, 0 /*no mutex*/))) @@ -3734,7 +3736,8 @@ int MYSQL_BIN_LOG::purge_logs_before_date(time_t purge_time) !is_active(log_info.log_file_name) && !log_in_use(log_info.log_file_name)) { - if (!my_stat(log_info.log_file_name, &stat_area, MYF(0))) + if (!mysql_file_stat(key_file_binlog, + log_info.log_file_name, &stat_area, MYF(0))) { if (my_errno == ENOENT) { @@ -3783,7 +3786,7 @@ int MYSQL_BIN_LOG::purge_logs_before_date(time_t purge_time) error= (to_log[0] ? purge_logs(to_log, 1, 0, 1, (ulonglong *) 0) : 0); err: - pthread_mutex_unlock(&LOCK_index); + mysql_mutex_unlock(&LOCK_index); DBUG_RETURN(error); } #endif /* HAVE_REPLICATION */ @@ -3859,11 +3862,11 @@ void MYSQL_BIN_LOG::new_file_impl(bool need_lock) } if (need_lock) - pthread_mutex_lock(&LOCK_log); - pthread_mutex_lock(&LOCK_index); + mysql_mutex_lock(&LOCK_log); + mysql_mutex_lock(&LOCK_index); - safe_mutex_assert_owner(&LOCK_log); - safe_mutex_assert_owner(&LOCK_index); + mysql_mutex_assert_owner(&LOCK_log); + mysql_mutex_assert_owner(&LOCK_index); /* if binlog is used as tc log, be sure all xids are "unlogged", @@ -3877,12 +3880,12 @@ void MYSQL_BIN_LOG::new_file_impl(bool need_lock) if (prepared_xids) { tc_log_page_waits++; - pthread_mutex_lock(&LOCK_prep_xids); + mysql_mutex_lock(&LOCK_prep_xids); while (prepared_xids) { DBUG_PRINT("info", ("prepared_xids=%lu", prepared_xids)); - pthread_cond_wait(&COND_prep_xids, &LOCK_prep_xids); + mysql_cond_wait(&COND_prep_xids, &LOCK_prep_xids); } - pthread_mutex_unlock(&LOCK_prep_xids); + mysql_mutex_unlock(&LOCK_prep_xids); } /* Reuse old name if not binlog and not update log */ @@ -3942,8 +3945,8 @@ void MYSQL_BIN_LOG::new_file_impl(bool need_lock) end: if (need_lock) - pthread_mutex_unlock(&LOCK_log); - pthread_mutex_unlock(&LOCK_index); + mysql_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_index); DBUG_VOID_RETURN; } @@ -3952,7 +3955,7 @@ end: bool MYSQL_BIN_LOG::append(Log_event* ev) { bool error = 0; - pthread_mutex_lock(&LOCK_log); + mysql_mutex_lock(&LOCK_log); DBUG_ENTER("MYSQL_BIN_LOG::append"); DBUG_ASSERT(log_file.type == SEQ_READ_APPEND); @@ -3973,7 +3976,7 @@ bool MYSQL_BIN_LOG::append(Log_event* ev) new_file_without_locking(); err: - pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); signal_update(); // Safe as we don't call close DBUG_RETURN(error); } @@ -3988,7 +3991,7 @@ bool MYSQL_BIN_LOG::appendv(const char* buf, uint len,...) DBUG_ASSERT(log_file.type == SEQ_READ_APPEND); - safe_mutex_assert_owner(&LOCK_log); + mysql_mutex_assert_owner(&LOCK_log); do { if (my_b_append(&log_file,(uchar*) buf,len)) @@ -4015,14 +4018,14 @@ bool MYSQL_BIN_LOG::flush_and_sync(bool *synced) int err=0, fd=log_file.file; if (synced) *synced= 0; - safe_mutex_assert_owner(&LOCK_log); + mysql_mutex_assert_owner(&LOCK_log); if (flush_io_cache(&log_file)) return 1; uint sync_period= get_sync_period(); if (sync_period && ++sync_counter >= sync_period) { sync_counter= 0; - err=my_sync(fd, MYF(MY_WME)); + err= mysql_file_sync(fd, MYF(MY_WME)); if (synced) *synced= 1; } @@ -4281,14 +4284,14 @@ MYSQL_BIN_LOG::flush_and_set_pending_rows_event(THD *thd, m_table_map_version below, and that change has to be protected by the LOCK_log mutex. */ - pthread_mutex_lock(&LOCK_log); + mysql_mutex_lock(&LOCK_log); /* Write pending event to log file or transaction cache */ if (pending->write(file)) { - pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); set_write_error(thd); DBUG_RETURN(1); } @@ -4323,7 +4326,7 @@ MYSQL_BIN_LOG::flush_and_set_pending_rows_event(THD *thd, } } - pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); } thd->binlog_set_pending_rows_event(event); @@ -4367,7 +4370,7 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info) if (thd->binlog_flush_pending_rows_event(end_stmt)) DBUG_RETURN(error); - pthread_mutex_lock(&LOCK_log); + mysql_mutex_lock(&LOCK_log); /* In most cases this is only called if 'is_open()' is true; in fact this is @@ -4387,7 +4390,7 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info) if ((thd && !(thd->variables.option_bits & OPTION_BIN_LOG)) || (!binlog_filter->db_ok(local_db))) { - pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); DBUG_RETURN(0); } #endif /* HAVE_REPLICATION */ @@ -4523,7 +4526,7 @@ err: if (event_info->flags & LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F) ++m_table_map_version; - pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); DBUG_RETURN(error); } @@ -4603,7 +4606,7 @@ void MYSQL_BIN_LOG::rotate_and_purge(uint flags) bool check_purge= false; #endif if (!(flags & RP_LOCK_LOG_IS_ALREADY_LOCKED)) - pthread_mutex_lock(&LOCK_log); + mysql_mutex_lock(&LOCK_log); if ((flags & RP_FORCE_ROTATE) || (my_b_tell(&log_file) >= (my_off_t) max_size)) { @@ -4613,7 +4616,7 @@ void MYSQL_BIN_LOG::rotate_and_purge(uint flags) #endif } if (!(flags & RP_LOCK_LOG_IS_ALREADY_LOCKED)) - pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); #ifdef HAVE_REPLICATION /* @@ -4632,9 +4635,9 @@ void MYSQL_BIN_LOG::rotate_and_purge(uint flags) uint MYSQL_BIN_LOG::next_file_id() { uint res; - pthread_mutex_lock(&LOCK_log); + mysql_mutex_lock(&LOCK_log); res = file_id++; - pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); return res; } @@ -4818,7 +4821,7 @@ bool MYSQL_BIN_LOG::write_incident(THD *thd, bool lock) Incident incident= INCIDENT_LOST_EVENTS; Incident_log_event ev(thd, incident, write_error_msg); if (lock) - pthread_mutex_lock(&LOCK_log); + mysql_mutex_lock(&LOCK_log); error= ev.write(&log_file); if (lock) { @@ -4827,7 +4830,7 @@ bool MYSQL_BIN_LOG::write_incident(THD *thd, bool lock) signal_update(); rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED); } - pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); } DBUG_RETURN(error); } @@ -4860,7 +4863,7 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event, bool incident) { DBUG_ENTER("MYSQL_BIN_LOG::write(THD *, IO_CACHE *, Log_event *)"); - pthread_mutex_lock(&LOCK_log); + mysql_mutex_lock(&LOCK_log); /* NULL would represent nothing to replicate after ROLLBACK */ DBUG_ASSERT(commit_event != NULL); @@ -4942,14 +4945,14 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event, */ if (commit_event && commit_event->get_type_code() == XID_EVENT) { - pthread_mutex_lock(&LOCK_prep_xids); + mysql_mutex_lock(&LOCK_prep_xids); prepared_xids++; - pthread_mutex_unlock(&LOCK_prep_xids); + mysql_mutex_unlock(&LOCK_prep_xids); } else rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED); } - pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); DBUG_RETURN(0); @@ -4959,7 +4962,7 @@ err: write_error= 1; sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno); } - pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); DBUG_RETURN(1); } @@ -4981,10 +4984,10 @@ void MYSQL_BIN_LOG::wait_for_update_relay_log(THD* thd) DBUG_ENTER("wait_for_update_relay_log"); old_msg= thd->enter_cond(&update_cond, &LOCK_log, - "Slave has read all relay log; " + "Slave has read all relay log; " "waiting for the slave I/O " "thread to update it" ); - pthread_cond_wait(&update_cond, &LOCK_log); + mysql_cond_wait(&update_cond, &LOCK_log); thd->exit_cond(old_msg); DBUG_VOID_RETURN; } @@ -5015,10 +5018,10 @@ int MYSQL_BIN_LOG::wait_for_update_bin_log(THD* thd, "Master has sent all binlog to slave; " "waiting for binlog to be updated"); if (!timeout) - pthread_cond_wait(&update_cond, &LOCK_log); + mysql_cond_wait(&update_cond, &LOCK_log); else - ret= pthread_cond_timedwait(&update_cond, &LOCK_log, - const_cast<struct timespec *>(timeout)); + ret= mysql_cond_timedwait(&update_cond, &LOCK_log, + const_cast<struct timespec *>(timeout)); DBUG_RETURN(ret); } @@ -5058,16 +5061,16 @@ void MYSQL_BIN_LOG::close(uint exiting) if (log_file.type == WRITE_CACHE && log_type == LOG_BIN) { my_off_t offset= BIN_LOG_HEADER_SIZE + FLAGS_OFFSET; - my_off_t org_position= my_tell(log_file.file, MYF(0)); + my_off_t org_position= mysql_file_tell(log_file.file, MYF(0)); uchar flags= 0; // clearing LOG_EVENT_BINLOG_IN_USE_F - my_pwrite(log_file.file, &flags, 1, offset, MYF(0)); + mysql_file_pwrite(log_file.file, &flags, 1, offset, MYF(0)); /* Restore position so that anything we have in the IO_cache is written to the correct position. - We need the seek here, as my_pwrite() is not guaranteed to keep the + We need the seek here, as mysql_file_pwrite() is not guaranteed to keep the original position on system that doesn't support pwrite(). */ - my_seek(log_file.file, org_position, MY_SEEK_SET, MYF(0)); + mysql_file_seek(log_file.file, org_position, MY_SEEK_SET, MYF(0)); } /* this will cleanup IO_CACHE, sync and close the file */ @@ -5082,7 +5085,7 @@ void MYSQL_BIN_LOG::close(uint exiting) if ((exiting & LOG_CLOSE_INDEX) && my_b_inited(&index_file)) { end_io_cache(&index_file); - if (my_close(index_file.file, MYF(0)) < 0 && ! write_error) + if (mysql_file_close(index_file.file, MYF(0)) < 0 && ! write_error) { write_error= 1; sql_print_error(ER(ER_ERROR_ON_WRITE), index_file_name, errno); @@ -5104,10 +5107,10 @@ void MYSQL_BIN_LOG::set_max_size(ulong max_size_arg) it's like if the SET command was never run. */ DBUG_ENTER("MYSQL_BIN_LOG::set_max_size"); - pthread_mutex_lock(&LOCK_log); + mysql_mutex_lock(&LOCK_log); if (is_open()) max_size= max_size_arg; - pthread_mutex_unlock(&LOCK_log); + mysql_mutex_unlock(&LOCK_log); DBUG_VOID_RETURN; } @@ -5179,7 +5182,7 @@ bool flush_error_log() char err_renamed[FN_REFLEN], *end; end= strmake(err_renamed,log_error_file,FN_REFLEN-4); strmov(end, "-old"); - pthread_mutex_lock(&LOCK_error_log); + mysql_mutex_lock(&LOCK_error_log); #ifdef __WIN__ char err_temp[FN_REFLEN+4]; /* @@ -5187,7 +5190,7 @@ bool flush_error_log() the current error file. */ strxmov(err_temp, err_renamed,"-tmp",NullS); - (void) my_delete(err_temp, MYF(0)); + my_delete(err_temp, MYF(0)); if (freopen(err_temp,"a+",stdout)) { int fd; @@ -5196,27 +5199,27 @@ bool flush_error_log() freopen(err_temp,"a+",stderr); setbuf(stderr, NULL); - (void) my_delete(err_renamed, MYF(0)); - my_rename(log_error_file,err_renamed,MYF(0)); + my_delete(err_renamed, MYF(0)); + my_rename(log_error_file, err_renamed, MYF(0)); if (freopen(log_error_file,"a+",stdout)) { freopen(log_error_file,"a+",stderr); setbuf(stderr, NULL); } - if ((fd = my_open(err_temp, O_RDONLY, MYF(0))) >= 0) + if ((fd= my_open(err_temp, O_RDONLY, MYF(0))) >= 0) { - while ((bytes= my_read(fd, buf, IO_SIZE, MYF(0))) && + while ((bytes= mysql_file_read(fd, buf, IO_SIZE, MYF(0))) && bytes != MY_FILE_ERROR) my_fwrite(stderr, buf, bytes, MYF(0)); - my_close(fd, MYF(0)); + mysql_file_close(fd, MYF(0)); } - (void) my_delete(err_temp, MYF(0)); + my_delete(err_temp, MYF(0)); } else result= 1; #else - my_rename(log_error_file,err_renamed,MYF(0)); + my_rename(log_error_file, err_renamed, MYF(0)); if (freopen(log_error_file,"a+",stdout)) { FILE *reopen; @@ -5226,7 +5229,7 @@ bool flush_error_log() else result= 1; #endif - pthread_mutex_unlock(&LOCK_error_log); + mysql_mutex_unlock(&LOCK_error_log); } return result; } @@ -5235,7 +5238,7 @@ void MYSQL_BIN_LOG::signal_update() { DBUG_ENTER("MYSQL_BIN_LOG::signal_update"); signal_cnt++; - pthread_cond_broadcast(&update_cond); + mysql_cond_broadcast(&update_cond); DBUG_VOID_RETURN; } @@ -5301,7 +5304,7 @@ static void print_buffer_to_file(enum loglevel level, const char *buffer) DBUG_ENTER("print_buffer_to_file"); DBUG_PRINT("enter",("buffer: %s", buffer)); - pthread_mutex_lock(&LOCK_error_log); + mysql_mutex_lock(&LOCK_error_log); skr= my_time(0); localtime_r(&skr, &tm_tmp); @@ -5320,7 +5323,7 @@ static void print_buffer_to_file(enum loglevel level, const char *buffer) fflush(stderr); - pthread_mutex_unlock(&LOCK_error_log); + mysql_mutex_unlock(&LOCK_error_log); DBUG_VOID_RETURN; } @@ -5444,17 +5447,18 @@ int TC_LOG_MMAP::open(const char *opt_name) DBUG_ASSERT(TC_LOG_PAGE_SIZE % tc_log_page_size == 0); fn_format(logname,opt_name,mysql_data_home,"",MY_UNPACK_FILENAME); - if ((fd= my_open(logname, O_RDWR, MYF(0))) < 0) + if ((fd= mysql_file_open(key_file_tclog, logname, O_RDWR, MYF(0))) < 0) { if (my_errno != ENOENT) goto err; if (using_heuristic_recover()) return 1; - if ((fd= my_create(logname, CREATE_MODE, O_RDWR, MYF(MY_WME))) < 0) + if ((fd= mysql_file_create(key_file_tclog, logname, CREATE_MODE, + O_RDWR, MYF(MY_WME))) < 0) goto err; inited=1; file_length= opt_tc_log_size; - if (my_chsize(fd, file_length, 0, MYF(MY_WME))) + if (mysql_file_chsize(fd, file_length, 0, MYF(MY_WME))) goto err; } else @@ -5468,7 +5472,7 @@ int TC_LOG_MMAP::open(const char *opt_name) "--tc-heuristic-recover is used"); goto err; } - file_length= my_seek(fd, 0L, MY_SEEK_END, MYF(MY_WME+MY_FAE)); + file_length= mysql_file_seek(fd, 0L, MY_SEEK_END, MYF(MY_WME+MY_FAE)); if (file_length == MY_FILEPOS_ERROR || file_length % tc_log_page_size) goto err; } @@ -5492,8 +5496,8 @@ int TC_LOG_MMAP::open(const char *opt_name) pg->next=pg+1; pg->waiters=0; pg->state=POOL; - pthread_mutex_init(&pg->lock, MY_MUTEX_INIT_FAST); - pthread_cond_init (&pg->cond, 0); + mysql_mutex_init(key_PAGE_lock, &pg->lock, MY_MUTEX_INIT_FAST); + mysql_cond_init(key_PAGE_cond, &pg->cond, 0); pg->start=(my_xid *)(data + i*tc_log_page_size); pg->end=(my_xid *)(pg->start + tc_log_page_size); pg->size=pg->free=tc_log_page_size/sizeof(my_xid); @@ -5512,11 +5516,11 @@ int TC_LOG_MMAP::open(const char *opt_name) my_msync(fd, data, tc_log_page_size, MS_SYNC); inited=5; - pthread_mutex_init(&LOCK_sync, MY_MUTEX_INIT_FAST); - pthread_mutex_init(&LOCK_active, MY_MUTEX_INIT_FAST); - pthread_mutex_init(&LOCK_pool, MY_MUTEX_INIT_FAST); - pthread_cond_init(&COND_active, 0); - pthread_cond_init(&COND_pool, 0); + mysql_mutex_init(key_LOCK_sync, &LOCK_sync, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_active, &LOCK_active, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_pool, &LOCK_pool, MY_MUTEX_INIT_FAST); + mysql_cond_init(key_COND_active, &COND_active, 0); + mysql_cond_init(key_COND_pool, &COND_pool, 0); inited=6; @@ -5550,7 +5554,7 @@ void TC_LOG_MMAP::get_active_from_pool() int best_free; if (syncing) - pthread_mutex_lock(&LOCK_pool); + mysql_mutex_lock(&LOCK_pool); do { @@ -5583,7 +5587,7 @@ void TC_LOG_MMAP::get_active_from_pool() pool_last=*best_p; if (syncing) - pthread_mutex_unlock(&LOCK_pool); + mysql_mutex_unlock(&LOCK_pool); } /** @@ -5598,7 +5602,7 @@ int TC_LOG_MMAP::overflow() let's check the behaviour of tc_log_page_waits first */ tc_log_page_waits++; - pthread_cond_wait(&COND_pool, &LOCK_pool); + mysql_cond_wait(&COND_pool, &LOCK_pool); return 1; // always return 1 } @@ -5635,7 +5639,7 @@ int TC_LOG_MMAP::log_xid(THD *thd, my_xid xid) PAGE *p; ulong cookie; - pthread_mutex_lock(&LOCK_active); + mysql_mutex_lock(&LOCK_active); /* if active page is full - just wait... @@ -5645,14 +5649,14 @@ int TC_LOG_MMAP::log_xid(THD *thd, my_xid xid) unlog() does not signal COND_active. */ while (unlikely(active && active->free == 0)) - pthread_cond_wait(&COND_active, &LOCK_active); + mysql_cond_wait(&COND_active, &LOCK_active); /* no active page ? take one from the pool */ if (active == 0) get_active_from_pool(); p=active; - pthread_mutex_lock(&p->lock); + mysql_mutex_lock(&p->lock); /* searching for an empty slot */ while (*p->ptr) @@ -5668,9 +5672,9 @@ int TC_LOG_MMAP::log_xid(THD *thd, my_xid xid) p->state= DIRTY; /* to sync or not to sync - this is the question */ - pthread_mutex_unlock(&LOCK_active); - pthread_mutex_lock(&LOCK_sync); - pthread_mutex_unlock(&p->lock); + mysql_mutex_unlock(&LOCK_active); + mysql_mutex_lock(&LOCK_sync); + mysql_mutex_unlock(&p->lock); if (syncing) { // somebody's syncing. let's wait @@ -5680,24 +5684,24 @@ int TC_LOG_MMAP::log_xid(THD *thd, my_xid xid) as p->state may be not DIRTY when we come here */ while (p->state == DIRTY && syncing) - pthread_cond_wait(&p->cond, &LOCK_sync); + mysql_cond_wait(&p->cond, &LOCK_sync); p->waiters--; err= p->state == ERROR; if (p->state != DIRTY) // page was synced { if (p->waiters == 0) - pthread_cond_signal(&COND_pool); // in case somebody's waiting - pthread_mutex_unlock(&LOCK_sync); + mysql_cond_signal(&COND_pool); // in case somebody's waiting + mysql_mutex_unlock(&LOCK_sync); goto done; // we're done } } // page was not synced! do it now DBUG_ASSERT(active == p && syncing == 0); - pthread_mutex_lock(&LOCK_active); + mysql_mutex_lock(&LOCK_active); syncing=p; // place is vacant - take it active=0; // page is not active anymore - pthread_cond_broadcast(&COND_active); // in case somebody's waiting - pthread_mutex_unlock(&LOCK_active); - pthread_mutex_unlock(&LOCK_sync); + mysql_cond_broadcast(&COND_active); // in case somebody's waiting + mysql_mutex_unlock(&LOCK_active); + mysql_mutex_unlock(&LOCK_sync); err= sync(); done: @@ -5717,20 +5721,20 @@ int TC_LOG_MMAP::sync() err= my_msync(fd, syncing->start, 1, MS_SYNC); /* page is synced. let's move it to the pool */ - pthread_mutex_lock(&LOCK_pool); + mysql_mutex_lock(&LOCK_pool); pool_last->next=syncing; pool_last=syncing; syncing->next=0; syncing->state= err ? ERROR : POOL; - pthread_cond_broadcast(&syncing->cond); // signal "sync done" - pthread_cond_signal(&COND_pool); // in case somebody's waiting - pthread_mutex_unlock(&LOCK_pool); + mysql_cond_broadcast(&syncing->cond); // signal "sync done" + mysql_cond_signal(&COND_pool); // in case somebody's waiting + mysql_mutex_unlock(&LOCK_pool); /* marking 'syncing' slot free */ - pthread_mutex_lock(&LOCK_sync); + mysql_mutex_lock(&LOCK_sync); syncing=0; - pthread_cond_signal(&active->cond); // wake up a new syncer - pthread_mutex_unlock(&LOCK_sync); + mysql_cond_signal(&active->cond); // wake up a new syncer + mysql_mutex_unlock(&LOCK_sync); return err; } @@ -5748,15 +5752,15 @@ void TC_LOG_MMAP::unlog(ulong cookie, my_xid xid) DBUG_ASSERT(x >= p->start && x < p->end); *x=0; - pthread_mutex_lock(&p->lock); + mysql_mutex_lock(&p->lock); p->free++; DBUG_ASSERT(p->free <= p->size); set_if_smaller(p->ptr, x); if (p->free == p->size) // the page is completely empty statistic_decrement(tc_log_cur_pages_used, &LOCK_status); if (p->waiters == 0) // the page is in pool and ready to rock - pthread_cond_signal(&COND_pool); // ping ... for overflow() - pthread_mutex_unlock(&p->lock); + mysql_cond_signal(&COND_pool); // ping ... for overflow() + mysql_mutex_unlock(&p->lock); } void TC_LOG_MMAP::close() @@ -5764,29 +5768,29 @@ void TC_LOG_MMAP::close() uint i; switch (inited) { case 6: - pthread_mutex_destroy(&LOCK_sync); - pthread_mutex_destroy(&LOCK_active); - pthread_mutex_destroy(&LOCK_pool); - pthread_cond_destroy(&COND_pool); + mysql_mutex_destroy(&LOCK_sync); + mysql_mutex_destroy(&LOCK_active); + mysql_mutex_destroy(&LOCK_pool); + mysql_cond_destroy(&COND_pool); case 5: - data[0]='A'; // garble the first (signature) byte, in case my_delete fails + data[0]='A'; // garble the first (signature) byte, in case mysql_file_delete fails case 4: for (i=0; i < npages; i++) { if (pages[i].ptr == 0) break; - pthread_mutex_destroy(&pages[i].lock); - pthread_cond_destroy(&pages[i].cond); + mysql_mutex_destroy(&pages[i].lock); + mysql_cond_destroy(&pages[i].cond); } case 3: my_free((uchar*)pages, MYF(0)); case 2: my_munmap((char*)data, (size_t)file_length); case 1: - my_close(fd, MYF(0)); + mysql_file_close(fd, MYF(0)); } if (inited>=5) // cannot do in the switch because of Windows - my_delete(logname, MYF(MY_WME)); + mysql_file_delete(key_file_tclog, logname, MYF(MY_WME)); inited=0; } @@ -5891,8 +5895,9 @@ int TC_LOG_BINLOG::open(const char *opt_name) DBUG_ASSERT(total_ha_2pc > 1); DBUG_ASSERT(opt_name && opt_name[0]); - pthread_mutex_init(&LOCK_prep_xids, MY_MUTEX_INIT_FAST); - pthread_cond_init (&COND_prep_xids, 0); + mysql_mutex_init(key_BINLOG_LOCK_prep_xids, + &LOCK_prep_xids, MY_MUTEX_INIT_FAST); + mysql_cond_init(key_BINLOG_COND_prep_xids, &COND_prep_xids, 0); if (!my_b_inited(&index_file)) { @@ -5958,7 +5963,7 @@ int TC_LOG_BINLOG::open(const char *opt_name) delete ev; end_io_cache(&log); - my_close(file, MYF(MY_WME)); + mysql_file_close(file, MYF(MY_WME)); if (error) goto err; @@ -5972,8 +5977,8 @@ err: void TC_LOG_BINLOG::close() { DBUG_ASSERT(prepared_xids==0); - pthread_mutex_destroy(&LOCK_prep_xids); - pthread_cond_destroy (&COND_prep_xids); + mysql_mutex_destroy(&LOCK_prep_xids); + mysql_cond_destroy(&COND_prep_xids); } /** @@ -6000,13 +6005,13 @@ int TC_LOG_BINLOG::log_xid(THD *thd, my_xid xid) void TC_LOG_BINLOG::unlog(ulong cookie, my_xid xid) { - pthread_mutex_lock(&LOCK_prep_xids); + mysql_mutex_lock(&LOCK_prep_xids); DBUG_ASSERT(prepared_xids > 0); if (--prepared_xids == 0) { DBUG_PRINT("info", ("prepared_xids=%lu", prepared_xids)); - pthread_cond_signal(&COND_prep_xids); + mysql_cond_signal(&COND_prep_xids); } - pthread_mutex_unlock(&LOCK_prep_xids); + mysql_mutex_unlock(&LOCK_prep_xids); rotate_and_purge(0); // as ::write() did not rotate } diff --git a/sql/log.h b/sql/log.h index 847fa3db6f9..db774bc62fb 100644 --- a/sql/log.h +++ b/sql/log.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2005 MySQL AB +/* Copyright (C) 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -65,8 +65,8 @@ class TC_LOG_MMAP: public TC_LOG int size, free; // max and current number of free xid slots on the page int waiters; // number of waiters on condition PAGE_STATE state; // see above - pthread_mutex_t lock; // to access page data or control structure - pthread_cond_t cond; // to wait for a sync + mysql_mutex_t lock; // to access page data or control structure + mysql_cond_t cond; // to wait for a sync } PAGE; char logname[FN_REFLEN]; @@ -81,8 +81,8 @@ class TC_LOG_MMAP: public TC_LOG one has to use active->lock. Same for LOCK_pool and LOCK_sync */ - pthread_mutex_t LOCK_active, LOCK_pool, LOCK_sync; - pthread_cond_t COND_pool, COND_active; + mysql_mutex_t LOCK_active, LOCK_pool, LOCK_sync; + mysql_cond_t COND_pool, COND_active; public: TC_LOG_MMAP(): inited(0) {} @@ -136,21 +136,25 @@ extern TC_LOG_DUMMY tc_log_dummy; class Relay_log_info; +#ifdef HAVE_PSI_INTERFACE +extern PSI_mutex_key key_LOG_INFO_lock; +#endif + typedef struct st_log_info { char log_file_name[FN_REFLEN]; my_off_t index_file_offset, index_file_start_offset; my_off_t pos; bool fatal; // if the purge happens to give us a negative offset - pthread_mutex_t lock; + mysql_mutex_t lock; st_log_info() : index_file_offset(0), index_file_start_offset(0), pos(0), fatal(0) { log_file_name[0] = '\0'; - pthread_mutex_init(&lock, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOG_INFO_lock, &lock, MY_MUTEX_INIT_FAST); } - ~st_log_info() { pthread_mutex_destroy(&lock);} + ~st_log_info() { mysql_mutex_destroy(&lock);} } LOG_INFO; /* @@ -198,7 +202,7 @@ public: int generate_new_name(char *new_name, const char *log_name); protected: /* LOCK_log is inited by init_pthread_objects() */ - pthread_mutex_t LOCK_log; + mysql_mutex_t LOCK_log; char *name; char log_file_name[FN_REFLEN]; char time_buff[20], db[NAME_LEN + 1]; @@ -244,10 +248,10 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG { private: /* LOCK_log and LOCK_index are inited by init_pthread_objects() */ - pthread_mutex_t LOCK_index; - pthread_mutex_t LOCK_prep_xids; - pthread_cond_t COND_prep_xids; - pthread_cond_t update_cond; + mysql_mutex_t LOCK_index; + mysql_mutex_t LOCK_prep_xids; + mysql_cond_t COND_prep_xids; + mysql_cond_t update_cond; ulonglong bytes_written; IO_CACHE index_file; char index_file_name[FN_REFLEN]; @@ -452,11 +456,11 @@ public: inline char* get_index_fname() { return index_file_name;} inline char* get_log_fname() { return log_file_name; } inline char* get_name() { return name; } - inline pthread_mutex_t* get_log_lock() { return &LOCK_log; } + inline mysql_mutex_t* get_log_lock() { return &LOCK_log; } inline IO_CACHE* get_log_file() { return &log_file; } - inline void lock_index() { pthread_mutex_lock(&LOCK_index);} - inline void unlock_index() { pthread_mutex_unlock(&LOCK_index);} + inline void lock_index() { mysql_mutex_lock(&LOCK_index);} + inline void unlock_index() { mysql_mutex_unlock(&LOCK_index);} inline IO_CACHE *get_index_file() { return &index_file;} inline uint32 get_open_count() { return open_count; } }; @@ -551,7 +555,7 @@ public: /* Class which manages slow, general and error log event handlers */ class LOGGER { - rw_lock_t LOCK_logger; + mysql_rwlock_t LOCK_logger; /* flag to check whether logger mutex is initialized */ uint inited; @@ -571,9 +575,9 @@ public: LOGGER() : inited(0), table_log_handler(NULL), file_log_handler(NULL), is_log_tables_initialized(FALSE) {} - void lock_shared() { rw_rdlock(&LOCK_logger); } - void lock_exclusive() { rw_wrlock(&LOCK_logger); } - void unlock() { rw_unlock(&LOCK_logger); } + void lock_shared() { mysql_rwlock_rdlock(&LOCK_logger); } + void lock_exclusive() { mysql_rwlock_wrlock(&LOCK_logger); } + void unlock() { mysql_rwlock_unlock(&LOCK_logger); } bool is_log_table_enabled(uint log_table_type); bool log_command(THD *thd, enum enum_server_command command); diff --git a/sql/log_event.cc b/sql/log_event.cc index c03ac278e8a..985d2110c9b 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1,4 +1,4 @@ -/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. +/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. 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 @@ -497,7 +497,7 @@ static void cleanup_load_tmpdir() if (is_prefix(file->name, prefbuf)) { fn_format(fname,file->name,slave_load_tmpdir,"",MY_UNPACK_FILENAME); - my_delete(fname, MYF(0)); + mysql_file_delete(key_file_misc, fname, MYF(0)); } } @@ -967,7 +967,7 @@ bool Log_event::write_header(IO_CACHE* file, ulong event_data_length) */ int Log_event::read_log_event(IO_CACHE* file, String* packet, - pthread_mutex_t* log_lock) + mysql_mutex_t* log_lock) { ulong data_len; int result=0; @@ -975,7 +975,7 @@ int Log_event::read_log_event(IO_CACHE* file, String* packet, DBUG_ENTER("Log_event::read_log_event"); if (log_lock) - pthread_mutex_lock(log_lock); + mysql_mutex_lock(log_lock); if (my_b_read(file, (uchar*) buf, sizeof(buf))) { /* @@ -1033,14 +1033,14 @@ int Log_event::read_log_event(IO_CACHE* file, String* packet, end: if (log_lock) - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); DBUG_RETURN(result); } #endif /* !MYSQL_CLIENT */ #ifndef MYSQL_CLIENT -#define UNLOCK_MUTEX if (log_lock) pthread_mutex_unlock(log_lock); -#define LOCK_MUTEX if (log_lock) pthread_mutex_lock(log_lock); +#define UNLOCK_MUTEX if (log_lock) mysql_mutex_unlock(log_lock); +#define LOCK_MUTEX if (log_lock) mysql_mutex_lock(log_lock); #else #define UNLOCK_MUTEX #define LOCK_MUTEX @@ -1052,7 +1052,7 @@ end: Allocates memory; The caller is responsible for clean-up. */ Log_event* Log_event::read_log_event(IO_CACHE* file, - pthread_mutex_t* log_lock, + mysql_mutex_t* log_lock, const Format_description_log_event *description_event) #else @@ -4932,7 +4932,7 @@ int Rotate_log_event::do_update_pos(Relay_log_info *rli) !is_relay_log_event() && !rli->is_in_group()) { - pthread_mutex_lock(&rli->data_lock); + mysql_mutex_lock(&rli->data_lock); DBUG_PRINT("info", ("old group_master_log_name: '%s' " "old group_master_log_pos: %lu", rli->group_master_log_name, @@ -4944,7 +4944,7 @@ int Rotate_log_event::do_update_pos(Relay_log_info *rli) "new group_master_log_pos: %lu", rli->group_master_log_name, (ulong) rli->group_master_log_pos)); - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); flush_relay_log_info(rli); /* @@ -5765,8 +5765,8 @@ Slave_log_event::Slave_log_event(THD* thd_arg, Master_info* mi = rli->mi; // TODO: re-write this better without holding both locks at the same time - pthread_mutex_lock(&mi->data_lock); - pthread_mutex_lock(&rli->data_lock); + mysql_mutex_lock(&mi->data_lock); + mysql_mutex_lock(&rli->data_lock); master_host_len = strlen(mi->host); master_log_len = strlen(rli->group_master_log_name); // on OOM, just do not initialize the structure and print the error @@ -5784,8 +5784,8 @@ Slave_log_event::Slave_log_event(THD* thd_arg, } else sql_print_error("Out of memory while recording slave event"); - pthread_mutex_unlock(&rli->data_lock); - pthread_mutex_unlock(&mi->data_lock); + mysql_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&mi->data_lock); DBUG_VOID_RETURN; } #endif /* !MYSQL_CLIENT */ @@ -6142,10 +6142,12 @@ int Create_file_log_event::do_apply_event(Relay_log_info const *rli) fname_buf= strmov(proc_info, "Making temp file "); ext= slave_load_file_stem(fname_buf, file_id, server_id, ".info"); thd_proc_info(thd, proc_info); - my_delete(fname_buf, MYF(0)); // old copy may exist already - if ((fd= my_create(fname_buf, CREATE_MODE, - O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW, - MYF(MY_WME))) < 0 || + /* old copy may exist already */ + mysql_file_delete(key_file_log_event_info, fname_buf, MYF(0)); + if ((fd= mysql_file_create(key_file_log_event_info, + fname_buf, CREATE_MODE, + O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW, + MYF(MY_WME))) < 0 || init_io_cache(&file, fd, IO_SIZE, WRITE_CACHE, (my_off_t)0, 0, MYF(MY_WME|MY_NABP))) { @@ -6167,20 +6169,22 @@ int Create_file_log_event::do_apply_event(Relay_log_info const *rli) goto err; } end_io_cache(&file); - my_close(fd, MYF(0)); + mysql_file_close(fd, MYF(0)); // fname_buf now already has .data, not .info, because we did our trick - my_delete(fname_buf, MYF(0)); // old copy may exist already - if ((fd= my_create(fname_buf, CREATE_MODE, - O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW, - MYF(MY_WME))) < 0) + /* old copy may exist already */ + mysql_file_delete(key_file_log_event_data, fname_buf, MYF(0)); + if ((fd= mysql_file_create(key_file_log_event_data, + fname_buf, CREATE_MODE, + O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW, + MYF(MY_WME))) < 0) { rli->report(ERROR_LEVEL, my_errno, "Error in Create_file event: could not open file '%s'", fname_buf); goto err; } - if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP))) + if (mysql_file_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP))) { rli->report(ERROR_LEVEL, my_errno, "Error in Create_file event: write to '%s' failed", @@ -6193,7 +6197,7 @@ err: if (error) end_io_cache(&file); if (fd >= 0) - my_close(fd, MYF(0)); + mysql_file_close(fd, MYF(0)); thd_proc_info(thd, 0); return error != 0; } @@ -6325,10 +6329,12 @@ int Append_block_log_event::do_apply_event(Relay_log_info const *rli) */ lex_start(thd); mysql_reset_thd_for_next_command(thd); - my_delete(fname, MYF(0)); // old copy may exist already - if ((fd= my_create(fname, CREATE_MODE, - O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW, - MYF(MY_WME))) < 0) + /* old copy may exist already */ + mysql_file_delete(key_file_log_event_data, fname, MYF(0)); + if ((fd= mysql_file_create(key_file_log_event_data, + fname, CREATE_MODE, + O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW, + MYF(MY_WME))) < 0) { rli->report(ERROR_LEVEL, my_errno, "Error in %s event: could not create file '%s'", @@ -6336,8 +6342,10 @@ int Append_block_log_event::do_apply_event(Relay_log_info const *rli) goto err; } } - else if ((fd = my_open(fname, O_WRONLY | O_APPEND | O_BINARY | O_NOFOLLOW, - MYF(MY_WME))) < 0) + else if ((fd= mysql_file_open(key_file_log_event_data, + fname, + O_WRONLY | O_APPEND | O_BINARY | O_NOFOLLOW, + MYF(MY_WME))) < 0) { rli->report(ERROR_LEVEL, my_errno, "Error in %s event: could not open file '%s'", @@ -6345,10 +6353,14 @@ int Append_block_log_event::do_apply_event(Relay_log_info const *rli) goto err; } - DBUG_EXECUTE_IF("remove_slave_load_file_before_write", - my_close(fd,MYF(0)); fd= -1; my_delete(fname, MYF(0));); + DBUG_EXECUTE_IF("remove_slave_load_file_before_write", + { + mysql_file_close(fd, MYF(0)); + fd= -1; + mysql_file_delete(0, fname, MYF(0)); + }); - if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP))) + if (mysql_file_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP))) { rli->report(ERROR_LEVEL, my_errno, "Error in %s event: write to '%s' failed", @@ -6359,7 +6371,7 @@ int Append_block_log_event::do_apply_event(Relay_log_info const *rli) err: if (fd >= 0) - my_close(fd, MYF(0)); + mysql_file_close(fd, MYF(0)); thd_proc_info(thd, 0); DBUG_RETURN(error); } @@ -6453,9 +6465,9 @@ int Delete_file_log_event::do_apply_event(Relay_log_info const *rli) { char fname[FN_REFLEN+10]; char *ext= slave_load_file_stem(fname, file_id, server_id, ".data"); - (void) my_delete(fname, MYF(MY_WME)); + mysql_file_delete(key_file_log_event_data, fname, MYF(MY_WME)); strmov(ext, ".info"); - (void) my_delete(fname, MYF(MY_WME)); + mysql_file_delete(key_file_log_event_info, fname, MYF(MY_WME)); return 0; } #endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */ @@ -6556,8 +6568,9 @@ int Execute_load_log_event::do_apply_event(Relay_log_info const *rli) Load_log_event *lev= 0; ext= slave_load_file_stem(fname, file_id, server_id, ".info"); - if ((fd = my_open(fname, O_RDONLY | O_BINARY | O_NOFOLLOW, - MYF(MY_WME))) < 0 || + if ((fd= mysql_file_open(key_file_log_event_info, + fname, O_RDONLY | O_BINARY | O_NOFOLLOW, + MYF(MY_WME))) < 0 || init_io_cache(&file, fd, IO_SIZE, READ_CACHE, (my_off_t)0, 0, MYF(MY_WME|MY_NABP))) { @@ -6567,7 +6580,7 @@ int Execute_load_log_event::do_apply_event(Relay_log_info const *rli) goto err; } if (!(lev = (Load_log_event*)Log_event::read_log_event(&file, - (pthread_mutex_t*)0, + (mysql_mutex_t*)0, rli->relay_log.description_event_for_exec)) || lev->get_type_code() != NEW_LOAD_EVENT) { @@ -6607,24 +6620,24 @@ int Execute_load_log_event::do_apply_event(Relay_log_info const *rli) } /* We have an open file descriptor to the .info file; we need to close it - or Windows will refuse to delete the file in my_delete(). + or Windows will refuse to delete the file in mysql_file_delete(). */ if (fd >= 0) { - my_close(fd, MYF(0)); + mysql_file_close(fd, MYF(0)); end_io_cache(&file); fd= -1; } - (void) my_delete(fname, MYF(MY_WME)); + mysql_file_delete(key_file_log_event_info, fname, MYF(MY_WME)); memcpy(ext, ".data", 6); - (void) my_delete(fname, MYF(MY_WME)); + mysql_file_delete(key_file_log_event_data, fname, MYF(MY_WME)); error = 0; err: delete lev; if (fd >= 0) { - my_close(fd, MYF(0)); + mysql_file_close(fd, MYF(0)); end_io_cache(&file); } return error; @@ -6863,7 +6876,7 @@ Execute_load_query_log_event::do_apply_event(Relay_log_info const *rli) file so that we can re-execute this event at START SLAVE. */ if (!error) - (void) my_delete(fname, MYF(MY_WME)); + mysql_file_delete(key_file_log_event_data, fname, MYF(MY_WME)); my_free(buf, MYF(MY_ALLOW_ZERO_PTR)); return error; diff --git a/sql/log_event.h b/sql/log_event.h index 1fdd7a05968..5dd5de26fcf 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -946,11 +946,11 @@ public: constructor and pass description_event as an argument. */ static Log_event* read_log_event(IO_CACHE* file, - pthread_mutex_t* log_lock, + mysql_mutex_t* log_lock, const Format_description_log_event *description_event); static int read_log_event(IO_CACHE* file, String* packet, - pthread_mutex_t* log_lock); + mysql_mutex_t* log_lock); /* init_show_field_list() prepares the column names and types for the output of SHOW BINLOG EVENTS; it is used only by SHOW BINLOG diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 1615ca97073..33ca7eee89b 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -891,7 +891,10 @@ inline bool check_routine_access(THD *thd,ulong want_access,char *db, char *name, bool is_proc, bool no_errors) { return false; } inline bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table) -{ return false; } +{ + table->grant.privilege= want_access; + return false; +} inline bool check_merge_table_access(THD *thd, char *db, TABLE_LIST *table_list) { return false; } inline bool check_some_routine_access(THD *thd, const char *db, @@ -1041,6 +1044,7 @@ int check_user(THD *thd, enum enum_server_command command, const char *passwd, uint passwd_len, const char *db, bool check_count); pthread_handler_t handle_one_connection(void *arg); +void do_handle_one_connection(THD *thd_arg); bool init_new_connection_handler_thread(); void reset_mqh(LEX_USER *lu, bool get_them); bool check_mqh(THD *thd, uint check_command); @@ -1093,6 +1097,7 @@ void init_max_user_conn(void); void init_update_queries(void); void free_max_user_conn(void); pthread_handler_t handle_bootstrap(void *arg); +void do_handle_bootstrap(THD *thd); int mysql_execute_command(THD *thd); bool do_command(THD *thd); bool dispatch_command(enum enum_server_command command, THD *thd, @@ -1117,15 +1122,17 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, bool *write_to_binlog); #ifndef NO_EMBEDDED_ACCESS_CHECKS bool check_access(THD *thd, ulong access, const char *db, ulong *save_priv, - bool no_grant, bool no_errors, bool schema_db); -bool check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables, + GRANT_INTERNAL_INFO *grant_internal_info, + bool no_grant, bool no_errors); +bool check_table_access(THD *thd, ulong requirements, TABLE_LIST *tables, bool any_combination_of_privileges_will_do, uint number, bool no_errors); #else inline bool check_access(THD *thd, ulong access, const char *db, - ulong *save_priv, bool no_grant, bool no_errors, - bool schema_db) + ulong *save_priv, + GRANT_INTERNAL_INFO *grant_internal_info, + bool no_grant, bool no_errors) { if (save_priv) *save_priv= GLOBAL_ACLS; @@ -1314,7 +1321,7 @@ bool table_is_used(TABLE *table, bool wait_for_name_lock); TABLE *drop_locked_tables(THD *thd,const char *db, const char *table_name); void abort_locked_tables(THD *thd,const char *db, const char *table_name); void execute_init_command(THD *thd, LEX_STRING *init_command, - rw_lock_t *var_mutex); + mysql_rwlock_t *var_mutex); extern Field *not_found_field; extern Field *view_ref_found; @@ -1355,7 +1362,7 @@ struct st_des_keyschedule extern char *des_key_file; extern struct st_des_keyschedule des_keyschedule[10]; extern uint des_default_key; -extern pthread_mutex_t LOCK_des_key_file; +extern mysql_mutex_t LOCK_des_key_file; bool load_des_key_file(const char *file_name); #endif /* HAVE_OPENSSL */ @@ -1402,6 +1409,8 @@ void free_status_vars(); void reset_status_vars(); /* information schema */ extern LEX_STRING INFORMATION_SCHEMA_NAME; +/* performance schema */ +extern LEX_STRING PERFORMANCE_SCHEMA_DB_NAME; /* log tables */ extern LEX_STRING MYSQL_SCHEMA_NAME; extern LEX_STRING GENERAL_LOG_NAME; @@ -1423,9 +1432,11 @@ bool get_schema_tables_result(JOIN *join, enum enum_schema_table_state executed_place); enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table); -#define is_schema_db(X) \ +#define is_infoschema_db(X) \ !my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X)) +void initialize_information_schema_acl(); + /* sql_handler.cc */ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen); bool mysql_ha_close(THD *thd, TABLE_LIST *tables); @@ -1728,7 +1739,7 @@ void release_ddl_log(); void execute_ddl_log_recovery(); bool execute_ddl_log_entry(THD *thd, uint first_entry); -extern pthread_mutex_t LOCK_gdl; +extern mysql_mutex_t LOCK_gdl; #define WFRM_WRITE_SHADOW 1 #define WFRM_INSTALL_SHADOW 2 @@ -1745,9 +1756,8 @@ bool open_system_tables_for_read(THD *thd, TABLE_LIST *table_list, void close_system_tables(THD *thd, Open_tables_state *backup); TABLE *open_system_table_for_update(THD *thd, TABLE_LIST *one_table); -TABLE *open_performance_schema_table(THD *thd, TABLE_LIST *one_table, - Open_tables_state *backup); -void close_performance_schema_table(THD *thd, Open_tables_state *backup); +TABLE *open_log_table(THD *thd, TABLE_LIST *one_table, Open_tables_state *backup); +void close_log_table(THD *thd, Open_tables_state *backup); bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock, bool wait_for_refresh, bool wait_for_placeholders); @@ -2034,31 +2044,29 @@ extern my_bool old_mode; extern MYSQL_PLUGIN_IMPORT MYSQL_BIN_LOG mysql_bin_log; extern LOGGER logger; extern TABLE_LIST general_log, slow_log; -extern FILE *bootstrap_file; +extern MYSQL_FILE *bootstrap_file; extern int bootstrap_error; extern FILE *stderror_file; extern pthread_key(MEM_ROOT**,THR_MALLOC); -extern pthread_mutex_t LOCK_mapped_file, - LOCK_error_log, LOCK_uuid_generator, - LOCK_crypt, LOCK_timezone, +extern mysql_mutex_t LOCK_mysql_create_db, LOCK_open, LOCK_lock_db, + LOCK_mapped_file, LOCK_user_locks, LOCK_status, + LOCK_error_log, LOCK_delayed_insert, LOCK_uuid_generator, + LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone, LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_global_read_lock, LOCK_global_system_variables, LOCK_user_conn, LOCK_prepared_stmt_count, LOCK_error_messages, LOCK_connection_count; -extern mysql_mutex_t LOCK_mysql_create_db, LOCK_lock_db, LOCK_open, - LOCK_user_locks, LOCK_status, LOCK_delayed_status, LOCK_delayed_insert, - LOCK_delayed_create; extern MYSQL_PLUGIN_IMPORT pthread_mutex_t LOCK_thread_count; #ifdef HAVE_OPENSSL -extern pthread_mutex_t LOCK_des_key_file; +extern mysql_mutex_t LOCK_des_key_file; #endif -extern pthread_mutex_t LOCK_server_started; -extern pthread_cond_t COND_server_started; +extern mysql_mutex_t LOCK_server_started; +extern mysql_cond_t COND_server_started; extern int mysqld_server_started; -extern rw_lock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave; -extern rw_lock_t LOCK_system_variables_hash; -extern mysql_cond_t COND_refresh; -extern pthread_cond_t COND_thread_count, COND_manager; -extern pthread_cond_t COND_global_read_lock; +extern mysql_rwlock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave; +extern mysql_rwlock_t LOCK_system_variables_hash; +extern pthread_cond_t COND_thread_count; +extern mysql_cond_t COND_refresh, COND_manager; +extern mysql_cond_t COND_global_read_lock; extern pthread_attr_t connection_attrib; extern I_List<THD> threads; extern MY_BITMAP temp_pool; @@ -2081,7 +2089,6 @@ extern String null_string; extern HASH open_cache, lock_db_cache; extern TABLE *unused_tables; extern const char* any_db; -extern struct my_option my_long_options[]; extern const LEX_STRING view_type; extern scheduler_functions thread_scheduler; extern TYPELIB thread_handling_typelib; @@ -2644,4 +2651,69 @@ extern "C" int test_if_data_home_dir(const char *dir); #endif /* MYSQL_CLIENT */ +#ifdef MYSQL_SERVER +#ifdef HAVE_PSI_INTERFACE +#ifdef HAVE_MMAP +extern PSI_mutex_key key_PAGE_lock, key_LOCK_sync, key_LOCK_active, + key_LOCK_pool; +#endif /* HAVE_MMAP */ + +#ifdef HAVE_OPENSSL +extern PSI_mutex_key key_LOCK_des_key_file; +#endif + +extern PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_prep_xids, + key_delayed_insert_mutex, key_hash_filo_lock, key_LOCK_active_mi, + key_LOCK_connection_count, key_LOCK_crypt, key_LOCK_delayed_create, + key_LOCK_delayed_insert, key_LOCK_delayed_status, key_LOCK_error_log, + key_LOCK_gdl, key_LOCK_global_read_lock, key_LOCK_global_system_variables, + key_LOCK_lock_db, key_LOCK_logger, key_LOCK_manager, key_LOCK_mapped_file, + key_LOCK_mysql_create_db, key_LOCK_open, key_LOCK_prepared_stmt_count, + key_LOCK_rpl_status, key_LOCK_server_started, key_LOCK_status, + key_LOCK_table_share, key_LOCK_thd_data, + key_LOCK_user_conn, key_LOCK_uuid_generator, key_LOG_LOCK_log, + key_master_info_data_lock, key_master_info_run_lock, + key_mutex_slave_reporting_capability_err_lock, key_relay_log_info_data_lock, + key_relay_log_info_log_space_lock, key_relay_log_info_run_lock, + key_structure_guard_mutex, key_TABLE_SHARE_mutex, key_LOCK_error_messages; + +extern PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger, + key_rwlock_LOCK_sys_init_connect, key_rwlock_LOCK_sys_init_slave, + key_rwlock_LOCK_system_variables_hash, key_rwlock_query_cache_query_lock; + +#ifdef HAVE_MMAP +extern PSI_cond_key key_PAGE_cond, key_COND_active, key_COND_pool; +#endif /* HAVE_MMAP */ + +extern PSI_cond_key key_BINLOG_COND_prep_xids, key_BINLOG_update_cond, + key_COND_cache_status_changed, key_COND_global_read_lock, key_COND_manager, + key_COND_refresh, key_COND_rpl_status, key_COND_server_started, + key_delayed_insert_cond, key_delayed_insert_cond_client, + key_item_func_sleep_cond, key_master_info_data_cond, + key_master_info_start_cond, key_master_info_stop_cond, + key_relay_log_info_data_cond, key_relay_log_info_log_space_cond, + key_relay_log_info_start_cond, key_relay_log_info_stop_cond, + key_TABLE_SHARE_cond, key_user_level_lock_cond; + +extern PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert, + key_thread_handle_manager, key_thread_kill_server, key_thread_main, + key_thread_one_connection, key_thread_signal_hand; + +#ifdef HAVE_MMAP +extern PSI_file_key key_file_map; +#endif /* HAVE_MMAP */ + +extern PSI_file_key key_file_binlog, key_file_binlog_index, key_file_casetest, + key_file_dbopt, key_file_des_key_file, key_file_ERRMSG, key_select_to_file, + key_file_fileparser, key_file_frm, key_file_global_ddl_log, key_file_load, + key_file_loadfile, key_file_log_event_data, key_file_log_event_info, + key_file_master_info, key_file_misc, key_file_MYSQL_LOG, key_file_partition, + key_file_pid, key_file_relay_log_info, key_file_send_file, key_file_tclog, + key_file_trg, key_file_trn, key_file_init; + +void init_server_psi_keys(); +#endif /* HAVE_PSI_INTERFACE */ +#endif /* MYSQL_SERVER */ + + #endif /* MYSQL_PRIV_H */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index d49e893aaa1..f07410e0d43 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -28,6 +28,11 @@ #include "events.h" #include "probes_mysql.h" #include "debug_sync.h" + +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE +#include "../storage/perfschema/pfs_server.h" +#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ + #include "keycaches.h" #include "../storage/myisam/ha_myisam.h" #include "set_var.h" @@ -294,6 +299,24 @@ TYPELIB log_output_typelib= {array_elements(log_output_names)-1,"", /* static variables */ +#ifdef HAVE_PSI_INTERFACE +#if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY) +static PSI_thread_key key_thread_handle_con_namedpipes; +#endif /* _WIN32 || HAVE_SMEM && !EMBEDDED_LIBRARY */ + +#if defined(HAVE_SMEM) && !defined(EMBEDDED_LIBRARY) +static PSI_thread_key key_thread_handle_con_sharedmem; +#endif /* HAVE_SMEM && !EMBEDDED_LIBRARY */ + +#if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY) +static PSI_thread_key key_thread_handle_con_sockets; +#endif /* _WIN32 || HAVE_SMEM && !EMBEDDED_LIBRARY */ + +#ifdef __WIN__ +static PSI_thread_key key_thread_handle_shutdown; +#endif /* __WIN__ */ +#endif /* HAVE_PSI_INTERFACE */ + /* the default log output is log tables */ static bool lower_case_table_names_used= 0; static bool volatile select_thread_in_use, signal_thread_in_use; @@ -318,6 +341,7 @@ static bool binlog_format_used= false; LEX_STRING opt_init_connect, opt_init_slave; +/* Not instrumented because of LOCK_thread_count */ static pthread_cond_t COND_thread_cache, COND_flush_thread_cache; /* Global variables */ @@ -545,7 +569,7 @@ Lt_creator lt_creator; Ge_creator ge_creator; Le_creator le_creator; -FILE *bootstrap_file; +MYSQL_FILE *bootstrap_file; int bootstrap_error; FILE *stderror_file=0; @@ -577,16 +601,16 @@ SHOW_COMP_OPTION have_profiling; pthread_key(MEM_ROOT**,THR_MALLOC); pthread_key(THD*, THR_THD); -pthread_mutex_t LOCK_thread_count, - LOCK_mapped_file, LOCK_global_read_lock, - LOCK_error_log, LOCK_uuid_generator, - LOCK_crypt, - LOCK_global_system_variables, - LOCK_user_conn, LOCK_slave_list, LOCK_active_mi, - LOCK_connection_count, LOCK_error_messages; -mysql_mutex_t LOCK_open, LOCK_mysql_create_db, LOCK_status, LOCK_delayed_status, - LOCK_delayed_insert, LOCK_delayed_create; - +/* Not instrumented because of Bug#47396 */ +pthread_mutex_t LOCK_thread_count; +mysql_mutex_t LOCK_mysql_create_db, LOCK_open, + LOCK_mapped_file, LOCK_status, LOCK_global_read_lock, + LOCK_error_log, LOCK_uuid_generator, + LOCK_delayed_insert, LOCK_delayed_status, LOCK_delayed_create, + LOCK_crypt, + LOCK_global_system_variables, + LOCK_user_conn, LOCK_slave_list, LOCK_active_mi, + LOCK_connection_count, LOCK_error_messages; /** The below lock protects access to two global server variables: max_prepared_stmt_count and prepared_stmt_count. These variables @@ -594,18 +618,18 @@ mysql_mutex_t LOCK_open, LOCK_mysql_create_db, LOCK_status, LOCK_delayed_status, in the server, respectively. As PREPARE/DEALLOCATE rate in a loaded server may be fairly high, we need a dedicated lock. */ -pthread_mutex_t LOCK_prepared_stmt_count; +mysql_mutex_t LOCK_prepared_stmt_count; #ifdef HAVE_OPENSSL -pthread_mutex_t LOCK_des_key_file; +mysql_mutex_t LOCK_des_key_file; #endif -rw_lock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave; -rw_lock_t LOCK_system_variables_hash; -mysql_cond_t COND_refresh; -pthread_cond_t COND_thread_count, COND_global_read_lock; +mysql_rwlock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave; +mysql_rwlock_t LOCK_system_variables_hash; +pthread_cond_t COND_thread_count; +mysql_cond_t COND_refresh, COND_global_read_lock; pthread_t signal_thread; pthread_attr_t connection_attrib; -pthread_mutex_t LOCK_server_started; -pthread_cond_t COND_server_started; +mysql_mutex_t LOCK_server_started; +mysql_cond_t COND_server_started; int mysqld_server_started= 0; @@ -630,13 +654,176 @@ static int cleanup_done; static ulong opt_specialflag; static char *opt_update_logname, *opt_binlog_index_name; char *mysql_home_ptr, *pidfile_name_ptr; +/** Initial command line arguments (count), after load_defaults().*/ static int defaults_argc; +/** + Initial command line arguments (arguments), after load_defaults(). + This memory is allocated by @c load_defaults() and should be freed + using @c free_defaults(). + Do not modify defaults_argc / defaults_argv, + use remaining_argc / remaining_argv instead to parse the command + line arguments in multiple steps. +*/ static char **defaults_argv; +/** Remaining command line arguments (count), filtered by handle_options().*/ +static int remaining_argc; +/** Remaining command line arguments (arguments), filtered by handle_options().*/ +static char **remaining_argv; static char *opt_bin_logname; int orig_argc; char **orig_argv; +/* + Since buffered_option_error_reporter is only used currently + for parsing performance schema options, this code is not needed + when the performance schema is not compiled in. +*/ +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE +/** + A log message for the error log, buffered in memory. + Log messages are temporarily buffered when generated before the error log + is initialized, and then printed once the error log is ready. +*/ +class Buffered_log : public Sql_alloc +{ +public: + Buffered_log(enum loglevel level, const char *message); + + ~Buffered_log() + {} + + void print(void); + +private: + /** Log message level. */ + enum loglevel m_level; + /** Log message text. */ + String m_message; +}; + +/** + Constructor. + @param level the message log level + @param message the message text +*/ +Buffered_log::Buffered_log(enum loglevel level, const char *message) + : m_level(level), m_message() +{ + m_message.copy(message, strlen(message), &my_charset_latin1); +} + +/** + Print a buffered log to the real log file. +*/ +void Buffered_log::print() +{ + /* + Since messages are buffered, they can be printed out + of order with other entries in the log. + Add "Buffered xxx" to the message text to prevent confusion. + */ + switch(m_level) + { + case ERROR_LEVEL: + sql_print_error("Buffered error: %s\n", m_message.c_ptr_safe()); + break; + case WARNING_LEVEL: + sql_print_warning("Buffered warning: %s\n", m_message.c_ptr_safe()); + break; + case INFORMATION_LEVEL: + sql_print_information("Buffered information: %s\n", m_message.c_ptr_safe()); + break; + } +} + +/** + Collection of all the buffered log messages. +*/ +class Buffered_logs +{ +public: + Buffered_logs() + {} + + ~Buffered_logs() + {} + + void init(); + void cleanup(); + + void buffer(enum loglevel m_level, const char *msg); + void print(); +private: + /** + Memory root to use to store buffered logs. + This memory root lifespan is between init and cleanup. + Once the buffered logs are printed, they are not needed anymore, + and all the memory used is reclaimed. + */ + MEM_ROOT m_root; + /** List of buffered log messages. */ + List<Buffered_log> m_list; +}; + +void Buffered_logs::init() +{ + init_alloc_root(&m_root, 1024, 0); +} + +void Buffered_logs::cleanup() +{ + m_list.delete_elements(); + free_root(&m_root, MYF(0)); +} + +/** + Add a log message to the buffer. +*/ +void Buffered_logs::buffer(enum loglevel level, const char *msg) +{ + /* + Do not let Sql_alloc::operator new(size_t) allocate memory, + there is no memory root associated with the main() thread. + Give explicitly the proper memory root to use to + Sql_alloc::operator new(size_t, MEM_ROOT *) instead. + */ + Buffered_log *log= new (&m_root) Buffered_log(level, msg); + if (log) + m_list.push_back(log, &m_root); +} + +/** + Print buffered log messages. +*/ +void Buffered_logs::print() +{ + Buffered_log *log; + List_iterator_fast<Buffered_log> it(m_list); + while ((log= it++)) + log->print(); +} + +/** Logs reported before a logger is available. */ +static Buffered_logs buffered_logs; + +/** + Error reporter that buffer log messages. + @param level log message level + @param format log message format string +*/ +void buffered_option_error_reporter(enum loglevel level, const char *format, ...) +{ + va_list args; + char buffer[1024]; + + va_start(args, format); + my_vsnprintf(buffer, sizeof(buffer), format, args); + va_end(args); + buffered_logs.buffer(level, buffer); +} +#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ + static my_socket unix_sock,ip_sock; struct rand_struct sql_rand; ///< used by sql_class.cc:THD::THD() @@ -710,7 +897,7 @@ char *opt_ssl_ca= NULL, *opt_ssl_capath= NULL, *opt_ssl_cert= NULL, #ifndef HAVE_YASSL typedef struct CRYPTO_dynlock_value { - rw_lock_t lock; + mysql_rwlock_t lock; } openssl_lock_t; static openssl_lock_t *openssl_stdlocks; @@ -734,10 +921,14 @@ uint connection_count= 0; pthread_handler_t signal_hand(void *arg); static int mysql_init_variables(void); -static int get_options(int *argc,char **argv); +extern "C" void option_error_reporter(enum loglevel level, const char *format, ...); +static int get_options(int *argc_ptr, char ***argv_ptr); +static bool add_terminator(DYNAMIC_ARRAY *options); extern "C" my_bool mysqld_get_one_option(int, const struct my_option *, char *); static void set_server_version(void); static int init_thread_environment(); +static void init_error_log_mutex(); +static void clean_up_error_log_mutex(); static char *get_relative_path(const char *path); static int fix_paths(void); void handle_connections_sockets(); @@ -745,7 +936,7 @@ void handle_connections_sockets(); pthread_handler_t handle_connections_sockets_thread(void *arg); #endif pthread_handler_t kill_server_thread(void *arg); -static void bootstrap(FILE *file); +static void bootstrap(MYSQL_FILE *file); static bool read_init_file(char *file_name); #ifdef _WIN32 pthread_handler_t handle_connections_namedpipes(void *arg); @@ -898,7 +1089,7 @@ static void close_connections(void) mysql_mutex_unlock(&tmp->mysys_var->mutex); } } - (void) pthread_mutex_unlock(&LOCK_thread_count); // For unlink from list + pthread_mutex_unlock(&LOCK_thread_count); // For unlink from list Events::deinit(); end_slave(); @@ -1034,8 +1225,9 @@ void kill_mysql(void) { pthread_t tmp; abort_loop=1; - if (pthread_create(&tmp,&connection_attrib, kill_server_thread, - (void*) 0)) + if (mysql_thread_create(0, /* Not instrumented */ + &tmp, &connection_attrib, kill_server_thread, + (void*) 0)) sql_print_error("Can't create thread to kill server"); } #endif @@ -1185,6 +1377,7 @@ extern "C" void unireg_abort(int exit_code) DBUG_PRINT("quit",("done with cleanup in unireg_abort")); wait_for_signal_thread_to_end(); clean_up_mutexes(); + clean_up_error_log_mutex(); my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); exit(exit_code); /* purecov: inspected */ } @@ -1272,7 +1465,7 @@ void clean_up(bool print_message) #if !defined(EMBEDDED_LIBRARY) if (!opt_bootstrap) - (void) my_delete(pidfile_name,MYF(0)); // This may not always exist + mysql_file_delete(key_file_pid, pidfile_name, MYF(0)); // This may not always exist #endif if (print_message && my_default_lc_messages && server_start_time) sql_print_information(ER_DEFAULT(ER_SHUTDOWN_COMPLETE),my_progname); @@ -1328,47 +1521,46 @@ static void clean_up_mutexes() { mysql_mutex_destroy(&LOCK_mysql_create_db); mysql_mutex_destroy(&LOCK_lock_db); - (void) rwlock_destroy(&LOCK_grant); + mysql_rwlock_destroy(&LOCK_grant); mysql_mutex_destroy(&LOCK_open); - (void) pthread_mutex_destroy(&LOCK_thread_count); - (void) pthread_mutex_destroy(&LOCK_mapped_file); + pthread_mutex_destroy(&LOCK_thread_count); + mysql_mutex_destroy(&LOCK_mapped_file); mysql_mutex_destroy(&LOCK_status); - (void) pthread_mutex_destroy(&LOCK_error_log); mysql_mutex_destroy(&LOCK_delayed_insert); mysql_mutex_destroy(&LOCK_delayed_status); mysql_mutex_destroy(&LOCK_delayed_create); - (void) pthread_mutex_destroy(&LOCK_manager); - (void) pthread_mutex_destroy(&LOCK_crypt); - (void) pthread_mutex_destroy(&LOCK_user_conn); - (void) pthread_mutex_destroy(&LOCK_connection_count); + mysql_mutex_destroy(&LOCK_manager); + mysql_mutex_destroy(&LOCK_crypt); + mysql_mutex_destroy(&LOCK_user_conn); + mysql_mutex_destroy(&LOCK_connection_count); Events::destroy_mutexes(); #ifdef HAVE_OPENSSL - (void) pthread_mutex_destroy(&LOCK_des_key_file); + mysql_mutex_destroy(&LOCK_des_key_file); #ifndef HAVE_YASSL for (int i= 0; i < CRYPTO_num_locks(); ++i) - (void) rwlock_destroy(&openssl_stdlocks[i].lock); + rwlock_destroy(&openssl_stdlocks[i].lock); OPENSSL_free(openssl_stdlocks); #endif #endif #ifdef HAVE_REPLICATION - (void) pthread_mutex_destroy(&LOCK_rpl_status); - (void) pthread_cond_destroy(&COND_rpl_status); -#endif - (void) pthread_mutex_destroy(&LOCK_active_mi); - (void) rwlock_destroy(&LOCK_sys_init_connect); - (void) rwlock_destroy(&LOCK_sys_init_slave); - (void) pthread_mutex_destroy(&LOCK_global_system_variables); - (void) rwlock_destroy(&LOCK_system_variables_hash); - (void) pthread_mutex_destroy(&LOCK_global_read_lock); - (void) pthread_mutex_destroy(&LOCK_uuid_generator); - (void) pthread_mutex_destroy(&LOCK_prepared_stmt_count); - (void) pthread_mutex_destroy(&LOCK_error_messages); - (void) pthread_cond_destroy(&COND_thread_count); + mysql_mutex_destroy(&LOCK_rpl_status); + mysql_cond_destroy(&COND_rpl_status); +#endif + mysql_mutex_destroy(&LOCK_active_mi); + mysql_rwlock_destroy(&LOCK_sys_init_connect); + mysql_rwlock_destroy(&LOCK_sys_init_slave); + mysql_mutex_destroy(&LOCK_global_system_variables); + mysql_rwlock_destroy(&LOCK_system_variables_hash); + mysql_mutex_destroy(&LOCK_global_read_lock); + mysql_mutex_destroy(&LOCK_uuid_generator); + mysql_mutex_destroy(&LOCK_prepared_stmt_count); + mysql_mutex_destroy(&LOCK_error_messages); + pthread_cond_destroy(&COND_thread_count); mysql_cond_destroy(&COND_refresh); - (void) pthread_cond_destroy(&COND_global_read_lock); - (void) pthread_cond_destroy(&COND_thread_cache); - (void) pthread_cond_destroy(&COND_flush_thread_cache); - (void) pthread_cond_destroy(&COND_manager); + mysql_cond_destroy(&COND_global_read_lock); + pthread_cond_destroy(&COND_thread_cache); + pthread_cond_destroy(&COND_flush_thread_cache); + mysql_cond_destroy(&COND_manager); } #endif /*EMBEDDED_LIBRARY*/ @@ -1829,11 +2021,11 @@ void unlink_thd(THD *thd) DBUG_PRINT("enter", ("thd: 0x%lx", (long) thd)); thd->cleanup(); - pthread_mutex_lock(&LOCK_connection_count); + mysql_mutex_lock(&LOCK_connection_count); --connection_count; - pthread_mutex_unlock(&LOCK_connection_count); + mysql_mutex_unlock(&LOCK_connection_count); - (void) pthread_mutex_lock(&LOCK_thread_count); + pthread_mutex_lock(&LOCK_thread_count); thread_count--; delete thd; DBUG_VOID_RETURN; @@ -1934,7 +2126,7 @@ bool one_thread_per_connection_end(THD *thd, bool put_in_cache) void flush_thread_cache() { - (void) pthread_mutex_lock(&LOCK_thread_count); + pthread_mutex_lock(&LOCK_thread_count); kill_cached_threads++; while (cached_thread_count) { @@ -1942,7 +2134,7 @@ void flush_thread_cache() pthread_cond_wait(&COND_flush_thread_cache,&LOCK_thread_count); } kill_cached_threads--; - (void) pthread_mutex_unlock(&LOCK_thread_count); + pthread_mutex_unlock(&LOCK_thread_count); } @@ -2636,8 +2828,9 @@ static void start_signal_handler(void) #endif #endif - (void) pthread_mutex_lock(&LOCK_thread_count); - if ((error=pthread_create(&signal_thread,&thr_attr,signal_hand,0))) + pthread_mutex_lock(&LOCK_thread_count); + if ((error= mysql_thread_create(key_thread_signal_hand, + &signal_thread, &thr_attr, signal_hand, 0))) { sql_print_error("Can't create interrupt-thread (error %d, errno: %d)", error,errno); @@ -2704,9 +2897,9 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused))) At this pointer there is no other threads running, so there should not be any other pthread_cond_signal() calls. */ - (void) pthread_mutex_lock(&LOCK_thread_count); - (void) pthread_mutex_unlock(&LOCK_thread_count); - (void) pthread_cond_broadcast(&COND_thread_count); + pthread_mutex_lock(&LOCK_thread_count); + pthread_mutex_unlock(&LOCK_thread_count); + pthread_cond_broadcast(&COND_thread_count); (void) pthread_sigmask(SIG_BLOCK,&set,NULL); for (;;) @@ -2744,8 +2937,9 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused))) abort_loop=1; // mark abort for threads #ifdef USE_ONE_SIGNAL_HAND pthread_t tmp; - if (pthread_create(&tmp,&connection_attrib, kill_server_thread, - (void*) &sig)) + if (mysql_thread_create(0, /* Not instrumented */ + &tmp, &connection_attrib, kill_server_thread, + (void*) &sig)) sql_print_error("Can't create thread to kill server"); #else kill_server((void*) sig); // MIT THREAD has a alarm thread @@ -3083,8 +3277,7 @@ static inline char *make_default_log_name(char *buff,const char* log_ext) return make_log_name(buff, default_logfile_name, log_ext); } -static int init_common_variables(const char *conf_file_name, int argc, - char **argv, const char **groups) +static int init_common_variables() { char buff[FN_REFLEN]; umask(((~my_umask) & 0666)); @@ -3179,13 +3372,7 @@ static int init_common_variables(const char *conf_file_name, int argc, SQLCOM_END + 8); #endif - orig_argc=argc; - orig_argv=argv; - if (load_defaults(conf_file_name, groups, &argc, &argv)) - return 1; - defaults_argv=argv; - defaults_argc=argc; - if (get_options(&defaults_argc, defaults_argv)) + if (get_options(&remaining_argc, &remaining_argv)) return 1; set_server_version(); @@ -3489,6 +3676,15 @@ You should consider changing lower_case_table_names to 1 or 2", return 0; } +static void init_error_log_mutex() +{ + mysql_mutex_init(key_LOCK_error_log, &LOCK_error_log, MY_MUTEX_INIT_FAST); +} + +static void clean_up_error_log_mutex() +{ + mysql_mutex_destroy(&LOCK_error_log); +} static int init_thread_environment() { @@ -3496,34 +3692,42 @@ static int init_thread_environment() &LOCK_mysql_create_db, MY_MUTEX_INIT_SLOW); mysql_mutex_init(key_LOCK_lock_db, &LOCK_lock_db, MY_MUTEX_INIT_SLOW); mysql_mutex_init(key_LOCK_open, &LOCK_open, MY_MUTEX_INIT_FAST); - (void) pthread_mutex_init(&LOCK_thread_count,MY_MUTEX_INIT_FAST); - (void) pthread_mutex_init(&LOCK_mapped_file,MY_MUTEX_INIT_SLOW); + pthread_mutex_init(&LOCK_thread_count, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_mapped_file, &LOCK_mapped_file, MY_MUTEX_INIT_SLOW); mysql_mutex_init(key_LOCK_status, &LOCK_status, MY_MUTEX_INIT_FAST); - (void) pthread_mutex_init(&LOCK_error_log,MY_MUTEX_INIT_FAST); - mysql_mutex_init(key_LOCK_deleyed_insert, + mysql_mutex_init(key_LOCK_delayed_insert, &LOCK_delayed_insert, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_delayed_status, &LOCK_delayed_status, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_delayed_create, &LOCK_delayed_create, MY_MUTEX_INIT_SLOW); - (void) pthread_mutex_init(&LOCK_manager,MY_MUTEX_INIT_FAST); - (void) pthread_mutex_init(&LOCK_crypt,MY_MUTEX_INIT_FAST); - (void) pthread_mutex_init(&LOCK_user_conn, MY_MUTEX_INIT_FAST); - (void) pthread_mutex_init(&LOCK_active_mi, MY_MUTEX_INIT_FAST); - (void) pthread_mutex_init(&LOCK_global_system_variables, MY_MUTEX_INIT_FAST); - (void) my_rwlock_init(&LOCK_system_variables_hash, NULL); - (void) pthread_mutex_init(&LOCK_global_read_lock, MY_MUTEX_INIT_FAST); - (void) pthread_mutex_init(&LOCK_prepared_stmt_count, MY_MUTEX_INIT_FAST); - (void) pthread_mutex_init(&LOCK_error_messages, MY_MUTEX_INIT_FAST); - (void) pthread_mutex_init(&LOCK_uuid_generator, MY_MUTEX_INIT_FAST); - (void) pthread_mutex_init(&LOCK_connection_count, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_manager, + &LOCK_manager, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_crypt, &LOCK_crypt, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_user_conn, &LOCK_user_conn, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_active_mi, &LOCK_active_mi, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_global_system_variables, + &LOCK_global_system_variables, MY_MUTEX_INIT_FAST); + mysql_rwlock_init(key_rwlock_LOCK_system_variables_hash, + &LOCK_system_variables_hash); + mysql_mutex_init(key_LOCK_global_read_lock, + &LOCK_global_read_lock, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_prepared_stmt_count, + &LOCK_prepared_stmt_count, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_error_messages, + &LOCK_error_messages, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_uuid_generator, + &LOCK_uuid_generator, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_connection_count, + &LOCK_connection_count, MY_MUTEX_INIT_FAST); #ifdef HAVE_OPENSSL - (void) pthread_mutex_init(&LOCK_des_key_file,MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_des_key_file, + &LOCK_des_key_file, MY_MUTEX_INIT_FAST); #ifndef HAVE_YASSL openssl_stdlocks= (openssl_lock_t*) OPENSSL_malloc(CRYPTO_num_locks() * sizeof(openssl_lock_t)); for (int i= 0; i < CRYPTO_num_locks(); ++i) - (void) my_rwlock_init(&openssl_stdlocks[i].lock, NULL); + my_rwlock_init(&openssl_stdlocks[i].lock, NULL); CRYPTO_set_dynlock_create_callback(openssl_dynlock_create); CRYPTO_set_dynlock_destroy_callback(openssl_dynlock_destroy); CRYPTO_set_dynlock_lock_callback(openssl_lock); @@ -3531,21 +3735,22 @@ static int init_thread_environment() CRYPTO_set_id_callback(openssl_id_function); #endif #endif - (void) my_rwlock_init(&LOCK_sys_init_connect, NULL); - (void) my_rwlock_init(&LOCK_sys_init_slave, NULL); - (void) my_rwlock_init(&LOCK_grant, NULL); - (void) pthread_cond_init(&COND_thread_count,NULL); + mysql_rwlock_init(key_rwlock_LOCK_sys_init_connect, &LOCK_sys_init_connect); + mysql_rwlock_init(key_rwlock_LOCK_sys_init_slave, &LOCK_sys_init_slave); + mysql_rwlock_init(key_rwlock_LOCK_grant, &LOCK_grant); + pthread_cond_init(&COND_thread_count, NULL); mysql_cond_init(key_COND_refresh, &COND_refresh, NULL); - (void) pthread_cond_init(&COND_global_read_lock,NULL); - (void) pthread_cond_init(&COND_thread_cache,NULL); - (void) pthread_cond_init(&COND_flush_thread_cache,NULL); - (void) pthread_cond_init(&COND_manager,NULL); + mysql_cond_init(key_COND_global_read_lock, &COND_global_read_lock, NULL); + pthread_cond_init(&COND_thread_cache, NULL); + pthread_cond_init(&COND_flush_thread_cache, NULL); + mysql_cond_init(key_COND_manager, &COND_manager, NULL); #ifdef HAVE_REPLICATION - (void) pthread_mutex_init(&LOCK_rpl_status, MY_MUTEX_INIT_FAST); - (void) pthread_cond_init(&COND_rpl_status, NULL); + mysql_mutex_init(key_LOCK_rpl_status, &LOCK_rpl_status, MY_MUTEX_INIT_FAST); + mysql_cond_init(key_COND_rpl_status, &COND_rpl_status, NULL); #endif - (void) pthread_mutex_init(&LOCK_server_started, MY_MUTEX_INIT_FAST); - (void) pthread_cond_init(&COND_server_started,NULL); + mysql_mutex_init(key_LOCK_server_started, + &LOCK_server_started, MY_MUTEX_INIT_FAST); + mysql_cond_init(key_COND_server_started, &COND_server_started, NULL); sp_cache_init(); #ifdef HAVE_EVENT_SCHEDULER Events::init_mutexes(); @@ -3731,6 +3936,18 @@ static int init_server_components() } } +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE + /* + Parsing the performance schema command line option may have reported + warnings/information messages. + Now that the logger is finally available, and redirected + to the proper file when the --log--error option is used, + print the buffered messages to the log. + */ + buffered_logs.print(); + buffered_logs.cleanup(); +#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ + if (xid_cache_init()) { sql_print_error("Out of memory"); @@ -3889,7 +4106,7 @@ a file name for --log-bin-index option", opt_binlog_index_name); if (ha_init_errors()) DBUG_RETURN(1); - if (plugin_init(&defaults_argc, defaults_argv, + if (plugin_init(&remaining_argc, remaining_argv, (opt_noacl ? PLUGIN_INIT_SKIP_PLUGIN_TABLE : 0) | (opt_help ? PLUGIN_INIT_SKIP_INITIALIZATION : 0))) { @@ -3906,10 +4123,9 @@ a file name for --log-bin-index option", opt_binlog_index_name); MYSQL_STORAGE_ENGINE_PLUGIN); /* we do want to exit if there are any other unknown options */ - if (defaults_argc > 1) + if (remaining_argc > 1) { int ho_error; - char **tmp_argv= defaults_argv; struct my_option no_opts[]= { {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} @@ -3917,21 +4133,22 @@ a file name for --log-bin-index option", opt_binlog_index_name); /* We need to eat any 'loose' arguments first before we conclude that there are unprocessed options. - But we need to preserve defaults_argv pointer intact for - free_defaults() to work. Thus we use a copy here. */ my_getopt_skip_unknown= 0; - if ((ho_error= handle_options(&defaults_argc, &tmp_argv, no_opts, + if ((ho_error= handle_options(&remaining_argc, &remaining_argv, no_opts, mysqld_get_one_option))) unireg_abort(ho_error); + /* Add back the program name handle_options removes */ + remaining_argc++; + remaining_argv--; my_getopt_skip_unknown= TRUE; - if (defaults_argc) + if (remaining_argc > 1) { fprintf(stderr, "%s: Too many arguments (first extra is '%s').\n" "Use --verbose --help to get a list of available options\n", - my_progname, *tmp_argv); + my_progname, remaining_argv[1]); unireg_abort(1); } } @@ -4095,7 +4312,8 @@ static void create_shutdown_thread() #ifdef __WIN__ hEventShutdown=CreateEvent(0, FALSE, FALSE, shutdown_event_name); pthread_t hThread; - if (pthread_create(&hThread,&connection_attrib,handle_shutdown,0)) + if (mysql_thread_create(key_thread_handle_shutdown, + &hThread, &connection_attrib, handle_shutdown, 0)) sql_print_warning("Can't create thread to handle shutdown requests"); // On "Stop Service" we have to do regular shutdown @@ -4125,8 +4343,9 @@ static void handle_connections_methods() if (hPipe != INVALID_HANDLE_VALUE) { handler_count++; - if (pthread_create(&hThread,&connection_attrib, - handle_connections_namedpipes, 0)) + if (mysql_thread_create(key_thread_handle_con_namedpipes, + &hThread, &connection_attrib, + handle_connections_namedpipes, 0)) { sql_print_warning("Can't create thread to handle named pipes"); handler_count--; @@ -4135,8 +4354,9 @@ static void handle_connections_methods() if (have_tcpip && !opt_disable_networking) { handler_count++; - if (pthread_create(&hThread,&connection_attrib, - handle_connections_sockets_thread, 0)) + if (mysql_thread_create(key_thread_handle_con_sockets, + &hThread, &connection_attrib, + handle_connections_sockets_thread, 0)) { sql_print_warning("Can't create thread to handle TCP/IP"); handler_count--; @@ -4146,8 +4366,9 @@ static void handle_connections_methods() if (opt_enable_shared_memory) { handler_count++; - if (pthread_create(&hThread,&connection_attrib, - handle_connections_shared_memory, 0)) + if (mysql_thread_create(key_thread_handle_con_sharedmem, + &hThread, &connection_attrib, + handle_connections_shared_memory, 0)) { sql_print_warning("Can't create thread to handle shared memory"); handler_count--; @@ -4212,15 +4433,134 @@ static void test_lc_time_sz() } #endif//DBUG_OFF - #ifdef __WIN__ int win_main(int argc, char **argv) #else int main(int argc, char **argv) #endif { - MY_INIT(argv[0]); // init my_sys library & pthreads - /* nothing should come before this line ^^^ */ + /* + Perform basic thread library and malloc initialization, + to be able to read defaults files and parse options. + */ + my_progname= argv[0]; + if (my_basic_init()) + { + fprintf(stderr, "my_basic_init() failed."); + return 1; + } + + orig_argc= argc; + orig_argv= argv; + if (load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv)) + return 1; + defaults_argc= argc; + defaults_argv= argv; + remaining_argc= argc; + remaining_argv= argv; + + /* Must be initialized early for comparison of options name */ + system_charset_info= &my_charset_utf8_general_ci; + + sys_var_init(); + +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE + /* + The performance schema needs to be initialized as early as possible, + before to-be-instrumented objects of the server are initialized. + */ + int ho_error; + DYNAMIC_ARRAY all_early_options; + + my_getopt_register_get_addr(NULL); + /* Skip unknown options so that they may be processed later */ + my_getopt_skip_unknown= TRUE; + + /* prepare all_early_options array */ + my_init_dynamic_array(&all_early_options, sizeof(my_option), 100, 25); + sys_var_add_options(&all_early_options, sys_var::PARSE_EARLY); + add_terminator(&all_early_options); + + /* + Logs generated while parsing the command line + options are buffered and printed later. + */ + buffered_logs.init(); + my_getopt_error_reporter= buffered_option_error_reporter; + + ho_error= handle_options(&remaining_argc, &remaining_argv, + (my_option*)(all_early_options.buffer), NULL); + delete_dynamic(&all_early_options); + if (ho_error == 0) + { + /* Add back the program name handle_options removes */ + remaining_argc++; + remaining_argv--; + if (pfs_param.m_enabled) + { + PSI_hook= initialize_performance_schema(&pfs_param); + if (PSI_hook == NULL) + { + pfs_param.m_enabled= false; + buffered_logs.buffer(WARNING_LEVEL, + "Performance schema disabled (reason: init failed)."); + } + else + { + buffered_logs.buffer(INFORMATION_LEVEL, + "Performance schema enabled."); + } + } + else + { + buffered_logs.buffer(INFORMATION_LEVEL, + "Performance schema disabled (reason: start parameters)."); + } + } +#else + /* + Other provider of the instrumentation interface should + initialize PSI_hook here: + - HAVE_PSI_INTERFACE is for the instrumentation interface + - WITH_PERFSCHEMA_STORAGE_ENGINE is for one implementation + of the interface, + but there could be alternate implementations, which is why + these two defines are kept separate. + */ +#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ + +#ifdef HAVE_PSI_INTERFACE + /* + Obtain the current performance schema instrumentation interface, + if available. + */ + if (PSI_hook) + PSI_server= (PSI*) PSI_hook->get_interface(PSI_CURRENT_VERSION); + + if (PSI_server) + { + /* + Now that we have parsed the command line arguments, and have initialized + the performance schema itself, the next step is to register all the + server instruments. + */ + init_server_psi_keys(); + /* Instrument the main thread */ + PSI_thread *psi= PSI_server->new_thread(key_thread_main, NULL, 0); + if (psi) + PSI_server->set_thread(psi); + + /* + Now that some instrumentation is in place, + recreate objects which were initialised early, + so that they are instrumented as well. + */ + my_thread_basic_global_reinit(); + } +#endif /* HAVE_PSI_INTERFACE */ + + my_init(); // init my_sys library & pthreads + init_error_log_mutex(); /* Set signal used to kill MySQL */ #if defined(SIGUSR2) @@ -4235,6 +4575,28 @@ int main(int argc, char **argv) */ logger.init_base(); +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE + if (ho_error) + { + /* + Parsing command line option failed, + Since we don't have a workable remaining_argc/remaining_argv + to continue the server initialization, this is as far as this + code can go. + This is the best effort to log meaningful messages: + - messages will be printed to stderr, which is not redirected yet, + - messages will be printed in the NT event log, for windows. + */ + buffered_logs.print(); + buffered_logs.cleanup(); + /* + Not enough initializations for unireg_abort() + Using exit() for windows. + */ + exit (ho_error); + } +#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ + #ifdef _CUSTOMSTARTUPCONFIG_ if (_cust_check_startup()) { @@ -4254,13 +4616,13 @@ int main(int argc, char **argv) { /* errors are not read yet, so we use english text here */ my_message(ER_WSAS_FAILED, "WSAStartup Failed", MYF(0)); - unireg_abort(1); + /* Not enough initializations for unireg_abort() */ + return 1; } } #endif /* __WIN__ */ - if (init_common_variables(MYSQL_CONFIG_NAME, - argc, argv, load_default_groups)) + if (init_common_variables()) unireg_abort(1); // Will do exit init_signals(); @@ -4381,7 +4743,7 @@ int main(int argc, char **argv) #endif /* __NETWARE__ */ if (!opt_bootstrap) - (void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore + mysql_file_delete(key_file_pid, pidfile_name, MYF(MY_WME)); // Not needed anymore if (unix_sock != INVALID_SOCKET) unlink(mysqld_unix_port); @@ -4415,6 +4777,13 @@ int main(int argc, char **argv) unireg_abort(1); } +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE + initialize_performance_schema_acl(opt_bootstrap); + check_performance_schema(); +#endif + + initialize_information_schema_acl(); + execute_ddl_log_recovery(); if (Events::init(opt_noacl || opt_bootstrap)) @@ -4423,7 +4792,7 @@ int main(int argc, char **argv) if (opt_bootstrap) { select_thread_in_use= 0; // Allow 'kill' to work - bootstrap(stdin); + bootstrap(mysql_stdin); unireg_abort(bootstrap_error ? 1 : 0); } if (opt_init_file && *opt_init_file) @@ -4446,10 +4815,10 @@ int main(int argc, char **argv) /* Signal threads waiting for server to be started */ - pthread_mutex_lock(&LOCK_server_started); + mysql_mutex_lock(&LOCK_server_started); mysqld_server_started= 1; - pthread_cond_signal(&COND_server_started); - pthread_mutex_unlock(&LOCK_server_started); + mysql_cond_signal(&COND_server_started); + mysql_mutex_unlock(&LOCK_server_started); #if defined(_WIN32) || defined(HAVE_SMEM) handle_connections_methods(); @@ -4492,8 +4861,26 @@ int main(int argc, char **argv) } #endif clean_up(1); + /* + Important note: we wait for the signal thread to end, + but if a kill -15 signal was sent, the signal thread did + spawn the kill_server_thread thread, which is running concurrently. + */ wait_for_signal_thread_to_end(); clean_up_mutexes(); + clean_up_error_log_mutex(); +#ifdef HAVE_PSI_INTERFACE + /* + Disable the instrumentation, to avoid recording events + during the shutdown. + */ + if (PSI_server) + { + PSI_server->delete_current_thread(); + PSI_server= NULL; + } + shutdown_performance_schema(); +#endif my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); exit(0); @@ -4711,7 +5098,7 @@ int main(int argc, char **argv) create MySQL privilege tables without having to start a full MySQL server. */ -static void bootstrap(FILE *file) +static void bootstrap(MYSQL_FILE *file) { DBUG_ENTER("bootstrap"); @@ -4726,24 +5113,25 @@ static void bootstrap(FILE *file) bootstrap_file=file; #ifndef EMBEDDED_LIBRARY // TODO: Enable this - if (pthread_create(&thd->real_id,&connection_attrib,handle_bootstrap, - (void*) thd)) + if (mysql_thread_create(key_thread_bootstrap, + &thd->real_id, &connection_attrib, handle_bootstrap, + (void*) thd)) { sql_print_warning("Can't create thread to handle bootstrap"); bootstrap_error=-1; DBUG_VOID_RETURN; } /* Wait for thread to die */ - (void) pthread_mutex_lock(&LOCK_thread_count); + pthread_mutex_lock(&LOCK_thread_count); while (in_bootstrap) { - (void) pthread_cond_wait(&COND_thread_count,&LOCK_thread_count); + pthread_cond_wait(&COND_thread_count, &LOCK_thread_count); DBUG_PRINT("quit",("One thread died (count=%u)",thread_count)); } - (void) pthread_mutex_unlock(&LOCK_thread_count); + pthread_mutex_unlock(&LOCK_thread_count); #else thd->mysql= 0; - handle_bootstrap((void *)thd); + do_handle_bootstrap(thd); #endif DBUG_VOID_RETURN; @@ -4752,13 +5140,14 @@ static void bootstrap(FILE *file) static bool read_init_file(char *file_name) { - FILE *file; + MYSQL_FILE *file; DBUG_ENTER("read_init_file"); DBUG_PRINT("enter",("name: %s",file_name)); - if (!(file=my_fopen(file_name,O_RDONLY,MYF(MY_WME)))) + if (!(file= mysql_file_fopen(key_file_init, file_name, + O_RDONLY, MYF(MY_WME)))) DBUG_RETURN(TRUE); bootstrap(file); - (void) my_fclose(file,MYF(MY_WME)); + mysql_file_fclose(file, MYF(MY_WME)); DBUG_RETURN(FALSE); } @@ -4782,7 +5171,7 @@ void handle_connection_in_main_thread(THD *thd) threads.append(thd); pthread_mutex_unlock(&LOCK_thread_count); thd->start_utime= my_micro_time(); - handle_one_connection(thd); + do_handle_one_connection(thd); } @@ -4808,9 +5197,10 @@ void create_thread_to_handle_connection(THD *thd) threads.append(thd); DBUG_PRINT("info",(("creating thread %lu"), thd->thread_id)); thd->prior_thr_create_utime= thd->start_utime= my_micro_time(); - if ((error=pthread_create(&thd->real_id,&connection_attrib, - handle_one_connection, - (void*) thd))) + if ((error= mysql_thread_create(key_thread_one_connection, + &thd->real_id, &connection_attrib, + handle_one_connection, + (void*) thd))) { /* purecov: begin inspected */ DBUG_PRINT("error", @@ -4818,26 +5208,26 @@ void create_thread_to_handle_connection(THD *thd) error)); thread_count--; thd->killed= THD::KILL_CONNECTION; // Safety - (void) pthread_mutex_unlock(&LOCK_thread_count); + pthread_mutex_unlock(&LOCK_thread_count); - pthread_mutex_lock(&LOCK_connection_count); + mysql_mutex_lock(&LOCK_connection_count); --connection_count; - pthread_mutex_unlock(&LOCK_connection_count); + mysql_mutex_unlock(&LOCK_connection_count); statistic_increment(aborted_connects,&LOCK_status); /* Can't use my_error() since store_globals has not been called. */ my_snprintf(error_message_buff, sizeof(error_message_buff), ER(ER_CANT_CREATE_THREAD), error); net_send_error(thd, ER_CANT_CREATE_THREAD, error_message_buff, NULL); - (void) pthread_mutex_lock(&LOCK_thread_count); + pthread_mutex_lock(&LOCK_thread_count); close_connection(thd,0,0); delete thd; - (void) pthread_mutex_unlock(&LOCK_thread_count); + pthread_mutex_unlock(&LOCK_thread_count); return; /* purecov: end */ } } - (void) pthread_mutex_unlock(&LOCK_thread_count); + pthread_mutex_unlock(&LOCK_thread_count); DBUG_PRINT("info",("Thread created")); } @@ -4864,11 +5254,11 @@ static void create_new_thread(THD *thd) only (max_connections + 1) connections. */ - pthread_mutex_lock(&LOCK_connection_count); + mysql_mutex_lock(&LOCK_connection_count); if (connection_count >= max_connections + 1 || abort_loop) { - pthread_mutex_unlock(&LOCK_connection_count); + mysql_mutex_unlock(&LOCK_connection_count); DBUG_PRINT("error",("Too many connections")); close_connection(thd, ER_CON_COUNT_ERROR, 1); @@ -4881,7 +5271,7 @@ static void create_new_thread(THD *thd) if (connection_count > max_used_connections) max_used_connections= connection_count; - pthread_mutex_unlock(&LOCK_connection_count); + mysql_mutex_unlock(&LOCK_connection_count); /* Start a new thread to handle connection. */ @@ -5490,7 +5880,7 @@ DYNAMIC_ARRAY all_options; to be listed here. */ -struct my_option my_long_options[] = +struct my_option my_long_options[]= { {"help", '?', "Display this help and exit.", (uchar**) &opt_help, (uchar**) &opt_help, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, @@ -5931,12 +6321,12 @@ static int show_rpl_status(THD *thd, SHOW_VAR *var, char *buff) static int show_slave_running(THD *thd, SHOW_VAR *var, char *buff) { var->type= SHOW_MY_BOOL; - pthread_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&LOCK_active_mi); var->value= buff; *((my_bool *)buff)= (my_bool) (active_mi && active_mi->slave_running == MYSQL_SLAVE_RUN_CONNECT && active_mi->rli.slave_running); - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&LOCK_active_mi); return 0; } @@ -5946,41 +6336,41 @@ static int show_slave_retried_trans(THD *thd, SHOW_VAR *var, char *buff) TODO: with multimaster, have one such counter per line in SHOW SLAVE STATUS, and have the sum over all lines here. */ - pthread_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&LOCK_active_mi); if (active_mi) { var->type= SHOW_LONG; var->value= buff; - pthread_mutex_lock(&active_mi->rli.data_lock); + mysql_mutex_lock(&active_mi->rli.data_lock); *((long *)buff)= (long)active_mi->rli.retried_trans; - pthread_mutex_unlock(&active_mi->rli.data_lock); + mysql_mutex_unlock(&active_mi->rli.data_lock); } else var->type= SHOW_UNDEF; - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&LOCK_active_mi); return 0; } static int show_slave_received_heartbeats(THD *thd, SHOW_VAR *var, char *buff) { - pthread_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&LOCK_active_mi); if (active_mi) { var->type= SHOW_LONGLONG; var->value= buff; - pthread_mutex_lock(&active_mi->rli.data_lock); + mysql_mutex_lock(&active_mi->rli.data_lock); *((longlong *)buff)= active_mi->received_heartbeats; - pthread_mutex_unlock(&active_mi->rli.data_lock); + mysql_mutex_unlock(&active_mi->rli.data_lock); } else var->type= SHOW_UNDEF; - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&LOCK_active_mi); return 0; } static int show_heartbeat_period(THD *thd, SHOW_VAR *var, char *buff) { - pthread_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&LOCK_active_mi); if (active_mi) { var->type= SHOW_CHAR; @@ -5989,7 +6379,7 @@ static int show_heartbeat_period(THD *thd, SHOW_VAR *var, char *buff) } else var->type= SHOW_UNDEF; - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&LOCK_active_mi); return 0; } @@ -6008,9 +6398,9 @@ static int show_prepared_stmt_count(THD *thd, SHOW_VAR *var, char *buff) { var->type= SHOW_LONG; var->value= buff; - pthread_mutex_lock(&LOCK_prepared_stmt_count); + mysql_mutex_lock(&LOCK_prepared_stmt_count); *((long *)buff)= (long)prepared_stmt_count; - pthread_mutex_unlock(&LOCK_prepared_stmt_count); + mysql_mutex_unlock(&LOCK_prepared_stmt_count); return 0; } @@ -6411,10 +6801,10 @@ SHOW_VAR status_vars[]= { {NullS, NullS, SHOW_LONG} }; -static bool all_options_add_terminator() +bool add_terminator(DYNAMIC_ARRAY *options) { my_option empty_element= {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}; - return insert_dynamic(&all_options, (uchar *)&empty_element); + return insert_dynamic(options, (uchar *)&empty_element); } #ifndef EMBEDDED_LIBRARY @@ -6458,9 +6848,10 @@ static void print_help() init_alloc_root(&mem_root, 4096, 4096); pop_dynamic(&all_options); + sys_var_add_options(&all_options, sys_var::PARSE_EARLY); add_plugin_options(&all_options, &mem_root); sort_dynamic(&all_options, (qsort_cmp) option_cmp); - all_options_add_terminator(); + add_terminator(&all_options); my_print_help((my_option*) all_options.buffer); my_print_variables((my_option*) all_options.buffer); @@ -6557,8 +6948,6 @@ static int mysql_init_variables(void) mqh_used= 0; segfaulted= kill_in_progress= 0; cleanup_done= 0; - defaults_argc= 0; - defaults_argv= 0; server_id_supplied= 0; test_flags= select_errors= dropping_tables= ha_open_options=0; thread_count= thread_running= kill_cached_threads= wake_thread=0; @@ -7041,9 +7430,6 @@ mysql_getopt_value(const char *keyname, uint key_length, return option->value; } - -extern "C" void option_error_reporter(enum loglevel level, const char *format, ...); - void option_error_reporter(enum loglevel level, const char *format, ...) { va_list args; @@ -7060,38 +7446,46 @@ void option_error_reporter(enum loglevel level, const char *format, ...) /** + Get server options from the command line, + and perform related server initializations. + @param [in, out] argc_ptr command line options (count) + @param [in, out] argv_ptr command line options (values) + @return 0 on success + @todo - FIXME add EXIT_TOO_MANY_ARGUMENTS to "mysys_err.h" and return that code? */ -static int get_options(int *argc,char **argv) +static int get_options(int *argc_ptr, char ***argv_ptr) { int ho_error; my_getopt_register_get_addr(mysql_getopt_value); my_getopt_error_reporter= option_error_reporter; - /* prepare all_options array */ - my_init_dynamic_array(&all_options, sizeof(my_option), - array_elements(my_long_options), array_elements(my_long_options)/4); + /* prepare all_options array */ + my_init_dynamic_array(&all_options, sizeof(my_option), + array_elements(my_long_options), + array_elements(my_long_options)/4); for (my_option *opt= my_long_options; opt < my_long_options + array_elements(my_long_options) - 1; opt++) - insert_dynamic(&all_options, (uchar*) opt); - sys_var_init(&all_options); - all_options_add_terminator(); + insert_dynamic(&all_options, (uchar*) opt); + sys_var_add_options(&all_options, sys_var::PARSE_NORMAL); + add_terminator(&all_options); /* Skip unknown options so that they may be processed later by plugins */ my_getopt_skip_unknown= TRUE; - if ((ho_error= handle_options(argc, &argv, (my_option*)(all_options.buffer), + if ((ho_error= handle_options(argc_ptr, argv_ptr, (my_option*)(all_options.buffer), mysqld_get_one_option))) return ho_error; if (!opt_help) delete_dynamic(&all_options); - (*argc)++; /* add back one for the progname handle_options removes */ - /* no need to do this for argv as we are discarding it. */ + /* Add back the program name handle_options removes */ + (*argc_ptr)++; + (*argv_ptr)--; /* Options have been parsed. Now some of them need additional special @@ -7372,16 +7766,17 @@ static int test_if_case_insensitive(const char *dir_name) MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR); fn_format(buff2, glob_hostname, dir_name, ".LOWER-TEST", MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR); - (void) my_delete(buff2, MYF(0)); - if ((file= my_create(buff, 0666, O_RDWR, MYF(0))) < 0) + mysql_file_delete(key_file_casetest, buff2, MYF(0)); + if ((file= mysql_file_create(key_file_casetest, + buff, 0666, O_RDWR, MYF(0))) < 0) { sql_print_warning("Can't create test file %s", buff); DBUG_RETURN(-1); } - my_close(file, MYF(0)); - if (my_stat(buff2, &stat_info, MYF(0))) + mysql_file_close(file, MYF(0)); + if (mysql_file_stat(key_file_casetest, buff2, &stat_info, MYF(0))) result= 1; // Can access file - (void) my_delete(buff, MYF(MY_WME)); + mysql_file_delete(key_file_casetest, buff, MYF(MY_WME)); DBUG_PRINT("exit", ("result: %d", result)); DBUG_RETURN(result); } @@ -7395,18 +7790,19 @@ static int test_if_case_insensitive(const char *dir_name) static void create_pid_file() { File file; - if ((file = my_create(pidfile_name,0664, - O_WRONLY | O_TRUNC, MYF(MY_WME))) >= 0) + if ((file= mysql_file_create(key_file_pid, pidfile_name, 0664, + O_WRONLY | O_TRUNC, MYF(MY_WME))) >= 0) { char buff[21], *end; end= int10_to_str((long) getpid(), buff, 10); *end++= '\n'; - if (!my_write(file, (uchar*) buff, (uint) (end-buff), MYF(MY_WME | MY_NABP))) + if (!mysql_file_write(file, (uchar*) buff, (uint) (end-buff), + MYF(MY_WME | MY_NABP))) { - (void) my_close(file, MYF(0)); + mysql_file_close(file, MYF(0)); return; } - (void) my_close(file, MYF(0)); + mysql_file_close(file, MYF(0)); } sql_perror("Can't start server: can't create PID file"); exit(1); @@ -7462,3 +7858,244 @@ template class I_List<i_string_pair>; template class I_List<Statement>; template class I_List_iterator<Statement>; #endif + +#ifdef HAVE_PSI_INTERFACE +#ifdef HAVE_MMAP +PSI_mutex_key key_PAGE_lock, key_LOCK_sync, key_LOCK_active, key_LOCK_pool; +#endif /* HAVE_MMAP */ + +#ifdef HAVE_OPENSSL +PSI_mutex_key key_LOCK_des_key_file; +#endif /* HAVE_OPENSSL */ + +PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_prep_xids, + key_delayed_insert_mutex, key_hash_filo_lock, key_LOCK_active_mi, + key_LOCK_connection_count, key_LOCK_crypt, key_LOCK_delayed_create, + key_LOCK_delayed_insert, key_LOCK_delayed_status, key_LOCK_error_log, + key_LOCK_gdl, key_LOCK_global_read_lock, key_LOCK_global_system_variables, + key_LOCK_lock_db, key_LOCK_manager, key_LOCK_mapped_file, + key_LOCK_mysql_create_db, key_LOCK_open, key_LOCK_prepared_stmt_count, + key_LOCK_rpl_status, key_LOCK_server_started, key_LOCK_status, + key_LOCK_system_variables_hash, key_LOCK_table_share, key_LOCK_thd_data, + key_LOCK_user_conn, key_LOCK_uuid_generator, key_LOG_LOCK_log, + key_master_info_data_lock, key_master_info_run_lock, + key_mutex_slave_reporting_capability_err_lock, key_relay_log_info_data_lock, + key_relay_log_info_log_space_lock, key_relay_log_info_run_lock, + key_structure_guard_mutex, key_TABLE_SHARE_mutex, key_LOCK_error_messages, + key_LOG_INFO_lock; + +static PSI_mutex_info all_server_mutexes[]= +{ +#ifdef HAVE_MMAP + { &key_PAGE_lock, "PAGE::lock", 0}, + { &key_LOCK_sync, "TC_LOG_MMAP::LOCK_sync", 0}, + { &key_LOCK_active, "TC_LOG_MMAP::LOCK_active", 0}, + { &key_LOCK_pool, "TC_LOG_MMAP::LOCK_pool", 0}, +#endif /* HAVE_MMAP */ + +#ifdef HAVE_OPENSSL + { &key_LOCK_des_key_file, "LOCK_des_key_file", PSI_FLAG_GLOBAL}, +#endif /* HAVE_OPENSSL */ + + { &key_BINLOG_LOCK_index, "MYSQL_BIN_LOG::LOCK_index", 0}, + { &key_BINLOG_LOCK_prep_xids, "MYSQL_BIN_LOG::LOCK_prep_xids", 0}, + { &key_delayed_insert_mutex, "Delayed_insert::mutex", 0}, + { &key_hash_filo_lock, "hash_filo::lock", 0}, + { &key_LOCK_active_mi, "LOCK_active_mi", PSI_FLAG_GLOBAL}, + { &key_LOCK_connection_count, "LOCK_connection_count", PSI_FLAG_GLOBAL}, + { &key_LOCK_crypt, "LOCK_crypt", PSI_FLAG_GLOBAL}, + { &key_LOCK_delayed_create, "LOCK_delayed_create", PSI_FLAG_GLOBAL}, + { &key_LOCK_delayed_insert, "LOCK_delayed_insert", PSI_FLAG_GLOBAL}, + { &key_LOCK_delayed_status, "LOCK_delayed_status", PSI_FLAG_GLOBAL}, + { &key_LOCK_error_log, "LOCK_error_log", PSI_FLAG_GLOBAL}, + { &key_LOCK_gdl, "LOCK_gdl", PSI_FLAG_GLOBAL}, + { &key_LOCK_global_read_lock, "LOCK_global_read_lock", PSI_FLAG_GLOBAL}, + { &key_LOCK_global_system_variables, "LOCK_global_system_variables", PSI_FLAG_GLOBAL}, + { &key_LOCK_lock_db, "LOCK_lock_db", PSI_FLAG_GLOBAL}, + { &key_LOCK_manager, "LOCK_manager", PSI_FLAG_GLOBAL}, + { &key_LOCK_mapped_file, "LOCK_mapped_file", PSI_FLAG_GLOBAL}, + { &key_LOCK_mysql_create_db, "LOCK_mysql_create_db", PSI_FLAG_GLOBAL}, + { &key_LOCK_open, "LOCK_open", PSI_FLAG_GLOBAL}, + { &key_LOCK_prepared_stmt_count, "LOCK_prepared_stmt_count", PSI_FLAG_GLOBAL}, + { &key_LOCK_rpl_status, "LOCK_rpl_status", PSI_FLAG_GLOBAL}, + { &key_LOCK_server_started, "LOCK_server_started", PSI_FLAG_GLOBAL}, + { &key_LOCK_status, "LOCK_status", PSI_FLAG_GLOBAL}, + { &key_LOCK_system_variables_hash, "LOCK_system_variables_hash", PSI_FLAG_GLOBAL}, + { &key_LOCK_table_share, "LOCK_table_share", PSI_FLAG_GLOBAL}, + { &key_LOCK_thd_data, "THD::LOCK_thd_data", 0}, + { &key_LOCK_user_conn, "LOCK_user_conn", PSI_FLAG_GLOBAL}, + { &key_LOCK_uuid_generator, "LOCK_uuid_generator", PSI_FLAG_GLOBAL}, + { &key_LOG_LOCK_log, "LOG::LOCK_log", 0}, + { &key_master_info_data_lock, "Master_info::data_lock", 0}, + { &key_master_info_run_lock, "Master_info::run_lock", 0}, + { &key_mutex_slave_reporting_capability_err_lock, "Slave_reporting_capability::err_lock", 0}, + { &key_relay_log_info_data_lock, "Relay_log_info::data_lock", 0}, + { &key_relay_log_info_log_space_lock, "Relay_log_info::log_space_lock", 0}, + { &key_relay_log_info_run_lock, "Relay_log_info::run_lock", 0}, + { &key_structure_guard_mutex, "Query_cache::structure_guard_mutex", 0}, + { &key_TABLE_SHARE_mutex, "TABLE_SHARE::mutex", 0}, + { &key_LOCK_error_messages, "LOCK_error_messages", PSI_FLAG_GLOBAL}, + { &key_LOG_INFO_lock, "LOG_INFO::lock", 0} +}; + +PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger, + key_rwlock_LOCK_sys_init_connect, key_rwlock_LOCK_sys_init_slave, + key_rwlock_LOCK_system_variables_hash, key_rwlock_query_cache_query_lock; + +static PSI_rwlock_info all_server_rwlocks[]= +{ + { &key_rwlock_LOCK_grant, "LOCK_grant", PSI_FLAG_GLOBAL}, + { &key_rwlock_LOCK_logger, "LOGGER::LOCK_logger", 0}, + { &key_rwlock_LOCK_sys_init_connect, "LOCK_sys_init_connect", PSI_FLAG_GLOBAL}, + { &key_rwlock_LOCK_sys_init_slave, "LOCK_sys_init_slave", PSI_FLAG_GLOBAL}, + { &key_rwlock_LOCK_system_variables_hash, "LOCK_system_variables_hash", PSI_FLAG_GLOBAL}, + { &key_rwlock_query_cache_query_lock, "Query_cache_query::lock", 0} +}; + +#ifdef HAVE_MMAP +PSI_cond_key key_PAGE_cond, key_COND_active, key_COND_pool; +#endif /* HAVE_MMAP */ + +PSI_cond_key key_BINLOG_COND_prep_xids, key_BINLOG_update_cond, + key_COND_cache_status_changed, key_COND_global_read_lock, key_COND_manager, + key_COND_refresh, key_COND_rpl_status, key_COND_server_started, + key_delayed_insert_cond, key_delayed_insert_cond_client, + key_item_func_sleep_cond, key_master_info_data_cond, + key_master_info_start_cond, key_master_info_stop_cond, + key_relay_log_info_data_cond, key_relay_log_info_log_space_cond, + key_relay_log_info_start_cond, key_relay_log_info_stop_cond, + key_TABLE_SHARE_cond, key_user_level_lock_cond; + +static PSI_cond_info all_server_conds[]= +{ +#ifdef HAVE_MMAP + { &key_PAGE_cond, "PAGE::cond", 0}, + { &key_COND_active, "TC_LOG_MMAP::COND_active", 0}, + { &key_COND_pool, "TC_LOG_MMAP::COND_pool", 0}, +#endif /* HAVE_MMAP */ + { &key_BINLOG_COND_prep_xids, "MYSQL_BIN_LOG::COND_prep_xids", 0}, + { &key_BINLOG_update_cond, "MYSQL_BIN_LOG::update_cond", 0}, + { &key_COND_cache_status_changed, "Query_cache::COND_cache_status_changed", 0}, + { &key_COND_global_read_lock, "COND_global_read_lock", PSI_FLAG_GLOBAL}, + { &key_COND_manager, "COND_manager", PSI_FLAG_GLOBAL}, + { &key_COND_refresh, "COND_refresh", PSI_FLAG_GLOBAL}, + { &key_COND_rpl_status, "COND_rpl_status", PSI_FLAG_GLOBAL}, + { &key_COND_server_started, "COND_server_started", PSI_FLAG_GLOBAL}, + { &key_delayed_insert_cond, "Delayed_insert::cond", 0}, + { &key_delayed_insert_cond_client, "Delayed_insert::cond_client", 0}, + { &key_item_func_sleep_cond, "Item_func_sleep::cond", 0}, + { &key_master_info_data_cond, "Master_info::data_cond", 0}, + { &key_master_info_start_cond, "Master_info::start_cond", 0}, + { &key_master_info_stop_cond, "Master_info::stop_cond", 0}, + { &key_relay_log_info_data_cond, "Relay_log_info::data_cond", 0}, + { &key_relay_log_info_log_space_cond, "Relay_log_info::log_space_cond", 0}, + { &key_relay_log_info_start_cond, "Relay_log_info::start_cond", 0}, + { &key_relay_log_info_stop_cond, "Relay_log_info::stop_cond", 0}, + { &key_TABLE_SHARE_cond, "TABLE_SHARE::cond", 0}, + { &key_user_level_lock_cond, "User_level_lock::cond", 0} +}; + +PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert, + key_thread_handle_manager, key_thread_main, + key_thread_one_connection, key_thread_signal_hand; + +static PSI_thread_info all_server_threads[]= +{ +#if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY) + { &key_thread_handle_con_namedpipes, "con_named_pipes", PSI_FLAG_GLOBAL}, +#endif /* _WIN32 || HAVE_SMEM && !EMBEDDED_LIBRARY */ + +#if defined(HAVE_SMEM) && !defined(EMBEDDED_LIBRARY) + { &key_thread_handle_con_sharedmem, "con_shared_mem", PSI_FLAG_GLOBAL}, +#endif /* HAVE_SMEM && !EMBEDDED_LIBRARY */ + +#if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY) + { &key_thread_handle_con_sockets, "con_sockets", PSI_FLAG_GLOBAL}, +#endif /* _WIN32 || HAVE_SMEM && !EMBEDDED_LIBRARY */ + +#ifdef __WIN__ + { &key_thread_handle_shutdown, "shutdown", PSI_FLAG_GLOBAL}, +#endif /* __WIN__ */ + + { &key_thread_bootstrap, "bootstrap", PSI_FLAG_GLOBAL}, + { &key_thread_delayed_insert, "delayed_insert", 0}, + { &key_thread_handle_manager, "manager", PSI_FLAG_GLOBAL}, + { &key_thread_main, "main", PSI_FLAG_GLOBAL}, + { &key_thread_one_connection, "one_connection", 0}, + { &key_thread_signal_hand, "signal_handler", PSI_FLAG_GLOBAL} +}; + +#ifdef HAVE_MMAP +PSI_file_key key_file_map; +#endif /* HAVE_MMAP */ + +PSI_file_key key_file_binlog, key_file_binlog_index, key_file_casetest, + key_file_dbopt, key_file_des_key_file, key_file_ERRMSG, key_select_to_file, + key_file_fileparser, key_file_frm, key_file_global_ddl_log, key_file_load, + key_file_loadfile, key_file_log_event_data, key_file_log_event_info, + key_file_master_info, key_file_misc, key_file_MYSQL_LOG, key_file_partition, + key_file_pid, key_file_relay_log_info, key_file_send_file, key_file_tclog, + key_file_trg, key_file_trn, key_file_init; + +static PSI_file_info all_server_files[]= +{ +#ifdef HAVE_MMAP + { &key_file_map, "map", 0}, +#endif /* HAVE_MMAP */ + { &key_file_binlog, "binlog", 0}, + { &key_file_binlog_index, "binlog_index", 0}, + { &key_file_casetest, "casetest", 0}, + { &key_file_dbopt, "dbopt", 0}, + { &key_file_des_key_file, "des_key_file", 0}, + { &key_file_ERRMSG, "ERRMSG", 0}, + { &key_select_to_file, "select_to_file", 0}, + { &key_file_fileparser, "file_parser", 0}, + { &key_file_frm, "FRM", 0}, + { &key_file_global_ddl_log, "global_ddl_log", 0}, + { &key_file_load, "load", 0}, + { &key_file_loadfile, "LOAD_FILE", 0}, + { &key_file_log_event_data, "log_event_data", 0}, + { &key_file_log_event_info, "log_event_info", 0}, + { &key_file_master_info, "master_info", 0}, + { &key_file_misc, "misc", 0}, + { &key_file_MYSQL_LOG, "MYSQL_LOG", 0}, + { &key_file_partition, "partition", 0}, + { &key_file_pid, "pid", 0}, + { &key_file_relay_log_info, "relay_log_info", 0}, + { &key_file_send_file, "send_file", 0}, + { &key_file_tclog, "tclog", 0}, + { &key_file_trg, "trigger_name", 0}, + { &key_file_trn, "trigger", 0}, + { &key_file_init, "init", 0} +}; + +/** + Initialise all the performance schema instrumentation points + used by the server. +*/ +void init_server_psi_keys(void) +{ + const char* category= "sql"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_server_mutexes); + PSI_server->register_mutex(category, all_server_mutexes, count); + + count= array_elements(all_server_rwlocks); + PSI_server->register_rwlock(category, all_server_rwlocks, count); + + count= array_elements(all_server_conds); + PSI_server->register_cond(category, all_server_conds, count); + + count= array_elements(all_server_threads); + PSI_server->register_thread(category, all_server_threads, count); + + count= array_elements(all_server_files); + PSI_server->register_file(category, all_server_files, count); +} + +#endif /* HAVE_PSI_INTERFACE */ + diff --git a/sql/parse_file.cc b/sql/parse_file.cc index 3d65fa1de31..d94ab3d940d 100644 --- a/sql/parse_file.cc +++ b/sql/parse_file.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2004 MySQL AB +/* Copyright (C) 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -237,8 +237,9 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name, // temporary file name path[path_end]='~'; path[path_end+1]= '\0'; - if ((handler= my_create(path, CREATE_MODE, O_RDWR | O_TRUNC, - MYF(MY_WME))) <= 0) + if ((handler= mysql_file_create(key_file_fileparser, + path, CREATE_MODE, O_RDWR | O_TRUNC, + MYF(MY_WME))) <= 0) { DBUG_RETURN(TRUE); } @@ -267,11 +268,11 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name, goto err_w_file; if (opt_sync_frm) { - if (my_sync(handler, MYF(MY_WME))) + if (mysql_file_sync(handler, MYF(MY_WME))) goto err_w_file; } - if (my_close(handler, MYF(MY_WME))) + if (mysql_file_close(handler, MYF(MY_WME))) { DBUG_RETURN(TRUE); } @@ -283,7 +284,7 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name, char path_to[FN_REFLEN]; memcpy(path_to, path, path_end+1); path[path_end]='~'; - if (my_rename(path, path_to, MYF(MY_WME))) + if (mysql_file_rename(key_file_fileparser, path, path_to, MYF(MY_WME))) { DBUG_RETURN(TRUE); } @@ -292,7 +293,7 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name, err_w_cache: end_io_cache(&file); err_w_file: - my_close(handler, MYF(MY_WME)); + mysql_file_close(handler, MYF(MY_WME)); DBUG_RETURN(TRUE); } @@ -321,7 +322,7 @@ my_bool rename_in_schema_file(THD *thd, build_table_filename(new_path, sizeof(new_path) - 1, new_db, new_name, reg_ext, 0); - if (my_rename(old_path, new_path, MYF(MY_WME))) + if (mysql_file_rename(key_file_frm, old_path, new_path, MYF(MY_WME))) return 1; /* check if arc_dir exists: disabled unused feature (see bug #17823). */ @@ -365,7 +366,8 @@ sql_parse_prepare(const LEX_STRING *file_name, MEM_ROOT *mem_root, File file; DBUG_ENTER("sql_parse_prepare"); - if (!my_stat(file_name->str, &stat_info, MYF(MY_WME))) + if (!mysql_file_stat(key_file_fileparser, + file_name->str, &stat_info, MYF(MY_WME))) { DBUG_RETURN(0); } @@ -386,20 +388,21 @@ sql_parse_prepare(const LEX_STRING *file_name, MEM_ROOT *mem_root, DBUG_RETURN(0); } - if ((file= my_open(file_name->str, O_RDONLY | O_SHARE, MYF(MY_WME))) < 0) + if ((file= mysql_file_open(key_file_fileparser, file_name->str, + O_RDONLY | O_SHARE, MYF(MY_WME))) < 0) { DBUG_RETURN(0); } - if ((len= my_read(file, (uchar *)parser->buff, - stat_info.st_size, MYF(MY_WME))) == + if ((len= mysql_file_read(file, (uchar *)parser->buff, + stat_info.st_size, MYF(MY_WME))) == MY_FILE_ERROR) { - my_close(file, MYF(MY_WME)); + mysql_file_close(file, MYF(MY_WME)); DBUG_RETURN(0); } - if (my_close(file, MYF(MY_WME))) + if (mysql_file_close(file, MYF(MY_WME))) { DBUG_RETURN(0); } diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc index c4df268279a..5f206f194e4 100644 --- a/sql/repl_failsafe.cc +++ b/sql/repl_failsafe.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2006 MySQL AB & Sasha +/* Copyright (C) 2001-2006 MySQL AB & Sasha, 2008-2009 Sun Microsystems, Inc 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 @@ -39,8 +39,8 @@ uint rpl_status=RPL_NULL; -pthread_mutex_t LOCK_rpl_status; -pthread_cond_t COND_rpl_status; +mysql_mutex_t LOCK_rpl_status; +mysql_cond_t COND_rpl_status; HASH slave_list; const char *rpl_role_type[] = {"MASTER","SLAVE",NullS}; @@ -107,11 +107,11 @@ static int init_failsafe_rpl_thread(THD* thd) void change_rpl_status(RPL_STATUS from_status, RPL_STATUS to_status) { - pthread_mutex_lock(&LOCK_rpl_status); + mysql_mutex_lock(&LOCK_rpl_status); if (rpl_status == from_status || rpl_status == RPL_ANY) rpl_status = to_status; - pthread_cond_signal(&COND_rpl_status); - pthread_mutex_unlock(&LOCK_rpl_status); + mysql_cond_signal(&COND_rpl_status); + mysql_mutex_unlock(&LOCK_rpl_status); } @@ -140,7 +140,7 @@ void unregister_slave(THD* thd, bool only_mine, bool need_mutex) if (thd->server_id) { if (need_mutex) - pthread_mutex_lock(&LOCK_slave_list); + mysql_mutex_lock(&LOCK_slave_list); SLAVE_INFO* old_si; if ((old_si = (SLAVE_INFO*)my_hash_search(&slave_list, @@ -149,7 +149,7 @@ void unregister_slave(THD* thd, bool only_mine, bool need_mutex) my_hash_delete(&slave_list, (uchar*)old_si); if (need_mutex) - pthread_mutex_unlock(&LOCK_slave_list); + mysql_mutex_unlock(&LOCK_slave_list); } } @@ -170,7 +170,7 @@ int register_slave(THD* thd, uchar* packet, uint packet_length) uchar *p= packet, *p_end= packet + packet_length; const char *errmsg= "Wrong parameters to function register_slave"; - if (check_access(thd, REPL_SLAVE_ACL, any_db,0,0,0,0)) + if (check_access(thd, REPL_SLAVE_ACL, any_db, NULL, NULL, 0, 0)) return 1; if (!(si = (SLAVE_INFO*)my_malloc(sizeof(SLAVE_INFO), MYF(MY_WME)))) goto err2; @@ -189,10 +189,10 @@ int register_slave(THD* thd, uchar* packet, uint packet_length) si->master_id= server_id; si->thd= thd; - pthread_mutex_lock(&LOCK_slave_list); + mysql_mutex_lock(&LOCK_slave_list); unregister_slave(thd,0,0); res= my_hash_insert(&slave_list, (uchar*) si); - pthread_mutex_unlock(&LOCK_slave_list); + mysql_mutex_unlock(&LOCK_slave_list); return res; err: @@ -215,12 +215,37 @@ extern "C" void slave_info_free(void *s) my_free(s, MYF(MY_WME)); } +#ifdef HAVE_PSI_INTERFACE +static PSI_mutex_key key_LOCK_slave_list; + +static PSI_mutex_info all_slave_list_mutexes[]= +{ + { &key_LOCK_slave_list, "LOCK_slave_list", PSI_FLAG_GLOBAL} +}; + +static void init_all_slave_list_mutexes(void) +{ + const char* category= "sql"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_slave_list_mutexes); + PSI_server->register_mutex(category, all_slave_list_mutexes, count); +} +#endif /* HAVE_PSI_INTERFACE */ + void init_slave_list() { +#ifdef HAVE_PSI_INTERFACE + init_all_slave_list_mutexes(); +#endif + my_hash_init(&slave_list, system_charset_info, SLAVE_LIST_CHUNK, 0, 0, (my_hash_get_key) slave_list_key, (my_hash_free_key) slave_info_free, 0); - pthread_mutex_init(&LOCK_slave_list, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_slave_list, &LOCK_slave_list, MY_MUTEX_INIT_FAST); } void end_slave_list() @@ -229,7 +254,7 @@ void end_slave_list() if (my_hash_inited(&slave_list)) { my_hash_free(&slave_list); - pthread_mutex_destroy(&LOCK_slave_list); + mysql_mutex_destroy(&LOCK_slave_list); } } @@ -241,7 +266,7 @@ static int find_target_pos(LEX_MASTER_INFO *mi, IO_CACHE *log, char *errmsg) for (;;) { Log_event* ev; - if (!(ev = Log_event::read_log_event(log, (pthread_mutex_t*) 0, 0))) + if (!(ev= Log_event::read_log_event(log, (mysql_mutex_t*) 0, 0))) { if (log->error > 0) strmov(errmsg, "Binary log truncated in the middle of event"); @@ -283,7 +308,7 @@ int translate_master(THD* thd, LEX_MASTER_INFO* mi, char* errmsg) char last_log_name[FN_REFLEN]; IO_CACHE log; File file = -1, last_file = -1; - pthread_mutex_t *log_lock; + mysql_mutex_t *log_lock; const char* errmsg_p; Slave_log_event* sev = 0; my_off_t last_pos = 0; @@ -313,7 +338,7 @@ int translate_master(THD* thd, LEX_MASTER_INFO* mi, char* errmsg) bzero((char*) &log,sizeof(log)); log_lock = mysql_bin_log.get_log_lock(); - pthread_mutex_lock(log_lock); + mysql_mutex_lock(log_lock); for (;;) { @@ -345,7 +370,7 @@ int translate_master(THD* thd, LEX_MASTER_INFO* mi, char* errmsg) goto err; } end_io_cache(&log); - (void) my_close(file, MYF(MY_WME)); + mysql_file_close(file, MYF(MY_WME)); if (init_io_cache(&log, (file = last_file), IO_SIZE, READ_CACHE, 0, 0, MYF(MY_WME))) { @@ -361,7 +386,7 @@ int translate_master(THD* thd, LEX_MASTER_INFO* mi, char* errmsg) switch (mysql_bin_log.find_next_log(&linfo, 1)) { case LOG_INFO_EOF: if (last_file >= 0) - (void)my_close(last_file, MYF(MY_WME)); + mysql_file_close(last_file, MYF(MY_WME)); last_file = -1; goto found_log; case 0: @@ -373,7 +398,7 @@ int translate_master(THD* thd, LEX_MASTER_INFO* mi, char* errmsg) end_io_cache(&log); if (last_file >= 0) - (void) my_close(last_file, MYF(MY_WME)); + mysql_file_close(last_file, MYF(MY_WME)); last_file = file; } @@ -386,15 +411,15 @@ found_log: mi_inited: error = 0; err: - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); end_io_cache(&log); pthread_mutex_lock(&LOCK_thread_count); thd->current_linfo = 0; pthread_mutex_unlock(&LOCK_thread_count); if (file >= 0) - (void) my_close(file, MYF(MY_WME)); + mysql_file_close(file, MYF(MY_WME)); if (last_file >= 0 && last_file != file) - (void) my_close(last_file, MYF(MY_WME)); + mysql_file_close(last_file, MYF(MY_WME)); DBUG_RETURN(error); } @@ -415,7 +440,7 @@ static Slave_log_event* find_slave_event(IO_CACHE* log, for (i = 0; i < 2; i++) { - if (!(ev = Log_event::read_log_event(log, (pthread_mutex_t*)0, 0))) + if (!(ev= Log_event::read_log_event(log, (mysql_mutex_t*)0, 0))) { my_snprintf(errmsg, SLAVE_ERRMSG_SIZE, "Error reading event in log '%s'", @@ -537,7 +562,7 @@ HOSTS"; goto err; } - pthread_mutex_lock(&LOCK_slave_list); + mysql_mutex_lock(&LOCK_slave_list); while ((row= mysql_fetch_row(res))) { @@ -552,14 +577,14 @@ HOSTS"; if (!(si = (SLAVE_INFO*)my_malloc(sizeof(SLAVE_INFO), MYF(MY_WME)))) { error= "the slave is out of memory"; - pthread_mutex_unlock(&LOCK_slave_list); + mysql_mutex_unlock(&LOCK_slave_list); goto err; } si->server_id = log_server_id; if (my_hash_insert(&slave_list, (uchar*)si)) { error= "the slave is out of memory"; - pthread_mutex_unlock(&LOCK_slave_list); + mysql_mutex_unlock(&LOCK_slave_list); goto err; } } @@ -573,7 +598,7 @@ HOSTS"; strmake(si->password, row[3], sizeof(si->password)-1); } } - pthread_mutex_unlock(&LOCK_slave_list); + mysql_mutex_unlock(&LOCK_slave_list); err: if (res) @@ -611,13 +636,13 @@ pthread_handler_t handle_failsafe_rpl(void *arg) sql_print_error("Could not initialize failsafe replication thread"); goto err; } - pthread_mutex_lock(&LOCK_rpl_status); + mysql_mutex_lock(&LOCK_rpl_status); msg= thd->enter_cond(&COND_rpl_status, &LOCK_rpl_status, "Waiting for request"); while (!thd->killed && !abort_loop) { bool break_req_chain = 0; - pthread_cond_wait(&COND_rpl_status, &LOCK_rpl_status); + mysql_cond_wait(&COND_rpl_status, &LOCK_rpl_status); thd_proc_info(thd, "Processing request"); while (!break_req_chain) { @@ -680,7 +705,7 @@ bool show_slave_hosts(THD* thd) Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) DBUG_RETURN(TRUE); - pthread_mutex_lock(&LOCK_slave_list); + mysql_mutex_lock(&LOCK_slave_list); for (uint i = 0; i < slave_list.records; ++i) { @@ -697,11 +722,11 @@ bool show_slave_hosts(THD* thd) protocol->store((uint32) si->master_id); if (protocol->write()) { - pthread_mutex_unlock(&LOCK_slave_list); + mysql_mutex_unlock(&LOCK_slave_list); DBUG_RETURN(TRUE); } } - pthread_mutex_unlock(&LOCK_slave_list); + mysql_mutex_unlock(&LOCK_slave_list); my_eof(thd); DBUG_RETURN(FALSE); } diff --git a/sql/repl_failsafe.h b/sql/repl_failsafe.h index f140b026bc1..dd6770be0b4 100644 --- a/sql/repl_failsafe.h +++ b/sql/repl_failsafe.h @@ -1,7 +1,7 @@ #ifndef REPL_FAILSAFE_INCLUDED #define REPL_FAILSAFE_INCLUDED -/* Copyright (C) 2001-2005 MySQL AB & Sasha +/* Copyright (C) 2001-2005 MySQL AB & Sasha, 2008-2009 Sun Microsystems, Inc 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 @@ -28,8 +28,8 @@ typedef enum {RPL_AUTH_MASTER=0,RPL_IDLE_SLAVE,RPL_ACTIVE_SLAVE, RPL_ANY /* wild card used by change_rpl_status */ } RPL_STATUS; extern uint rpl_status; -extern pthread_mutex_t LOCK_rpl_status; -extern pthread_cond_t COND_rpl_status; +extern mysql_mutex_t LOCK_rpl_status; +extern mysql_cond_t COND_rpl_status; extern TYPELIB rpl_role_typelib, rpl_status_typelib; extern const char* rpl_role_type[], *rpl_status_type[]; diff --git a/sql/rpl_mi.cc b/sql/rpl_mi.cc index 4f8c3f50ded..38382fd2a0e 100644 --- a/sql/rpl_mi.cc +++ b/sql/rpl_mi.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -44,21 +44,21 @@ Master_info::Master_info(bool is_slave_recovery) my_init_dynamic_array(&ignore_server_ids, sizeof(::server_id), 16, 16); bzero((char*) &file, sizeof(file)); - pthread_mutex_init(&run_lock, MY_MUTEX_INIT_FAST); - pthread_mutex_init(&data_lock, MY_MUTEX_INIT_FAST); - pthread_cond_init(&data_cond, NULL); - pthread_cond_init(&start_cond, NULL); - pthread_cond_init(&stop_cond, NULL); + mysql_mutex_init(key_master_info_run_lock, &run_lock, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_master_info_data_lock, &data_lock, MY_MUTEX_INIT_FAST); + mysql_cond_init(key_master_info_data_cond, &data_cond, NULL); + mysql_cond_init(key_master_info_start_cond, &start_cond, NULL); + mysql_cond_init(key_master_info_stop_cond, &stop_cond, NULL); } Master_info::~Master_info() { delete_dynamic(&ignore_server_ids); - pthread_mutex_destroy(&run_lock); - pthread_mutex_destroy(&data_lock); - pthread_cond_destroy(&data_cond); - pthread_cond_destroy(&start_cond); - pthread_cond_destroy(&stop_cond); + mysql_mutex_destroy(&run_lock); + mysql_mutex_destroy(&data_lock); + mysql_cond_destroy(&data_cond); + mysql_cond_destroy(&start_cond); + mysql_cond_destroy(&stop_cond); } /** @@ -175,7 +175,7 @@ int init_master_info(Master_info* mi, const char* master_info_fname, keep other threads from reading bogus info */ - pthread_mutex_lock(&mi->data_lock); + mysql_mutex_lock(&mi->data_lock); fd = mi->fd; /* does master.info exist ? */ @@ -184,7 +184,7 @@ int init_master_info(Master_info* mi, const char* master_info_fname, { if (abort_if_no_master_info_file) { - pthread_mutex_unlock(&mi->data_lock); + mysql_mutex_unlock(&mi->data_lock); DBUG_RETURN(0); } /* @@ -192,8 +192,9 @@ int init_master_info(Master_info* mi, const char* master_info_fname, the old descriptor and re-create the old file */ if (fd >= 0) - my_close(fd, MYF(MY_WME)); - if ((fd = my_open(fname, O_CREAT|O_RDWR|O_BINARY, MYF(MY_WME))) < 0 ) + mysql_file_close(fd, MYF(MY_WME)); + if ((fd= mysql_file_open(key_file_master_info, + fname, O_CREAT|O_RDWR|O_BINARY, MYF(MY_WME))) < 0 ) { sql_print_error("Failed to create a new master info file (\ file '%s', errno %d)", fname, my_errno); @@ -217,7 +218,8 @@ file '%s')", fname); reinit_io_cache(&mi->file, READ_CACHE, 0L,0,0); else { - if ((fd = my_open(fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0 ) + if ((fd= mysql_file_open(key_file_master_info, + fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0 ) { sql_print_error("Failed to open the existing master info file (\ file '%s', errno %d)", fname, my_errno); @@ -369,7 +371,7 @@ file '%s')", fname); reinit_io_cache(&mi->file, WRITE_CACHE, 0L, 0, 1); if ((error=test(flush_master_info(mi, 1)))) sql_print_error("Failed to flush master info file"); - pthread_mutex_unlock(&mi->data_lock); + mysql_mutex_unlock(&mi->data_lock); DBUG_RETURN(error); errwithmsg: @@ -378,11 +380,11 @@ errwithmsg: err: if (fd >= 0) { - my_close(fd, MYF(0)); + mysql_file_close(fd, MYF(0)); end_io_cache(&mi->file); } mi->fd= -1; - pthread_mutex_unlock(&mi->data_lock); + mysql_mutex_unlock(&mi->data_lock); DBUG_RETURN(1); } @@ -494,7 +496,7 @@ void end_master_info(Master_info* mi) if (mi->fd >= 0) { end_io_cache(&mi->file); - (void)my_close(mi->fd, MYF(MY_WME)); + mysql_file_close(mi->fd, MYF(MY_WME)); mi->fd = -1; } mi->inited = 0; diff --git a/sql/rpl_mi.h b/sql/rpl_mi.h index 6e4e2f9cdc7..6dd9fab7904 100644 --- a/sql/rpl_mi.h +++ b/sql/rpl_mi.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -77,8 +77,8 @@ class Master_info : public Slave_reporting_capability File fd; // we keep the file open, so we need to remember the file pointer IO_CACHE file; - pthread_mutex_t data_lock,run_lock; - pthread_cond_t data_cond,start_cond,stop_cond; + mysql_mutex_t data_lock, run_lock; + mysql_cond_t data_cond, start_cond, stop_cond; THD *io_thd; MYSQL* mysql; uint32 file_id; /* for 3.23 load data infile */ diff --git a/sql/rpl_reporting.cc b/sql/rpl_reporting.cc index a09140de3c4..ae9d100eeb4 100644 --- a/sql/rpl_reporting.cc +++ b/sql/rpl_reporting.cc @@ -1,7 +1,29 @@ +/* Copyright (C) 2008-2009 Sun Microsystems, Inc + + 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 */ + #include "mysql_priv.h" #include "rpl_reporting.h" +Slave_reporting_capability::Slave_reporting_capability(char const *thread_name) + : m_thread_name(thread_name) +{ + mysql_mutex_init(key_mutex_slave_reporting_capability_err_lock, + &err_lock, MY_MUTEX_INIT_FAST); +} + void Slave_reporting_capability::report(loglevel level, int err_code, const char *msg, ...) const @@ -13,7 +35,7 @@ Slave_reporting_capability::report(loglevel level, int err_code, va_list args; va_start(args, msg); - pthread_mutex_lock(&err_lock); + mysql_mutex_lock(&err_lock); switch (level) { case ERROR_LEVEL: @@ -39,7 +61,7 @@ Slave_reporting_capability::report(loglevel level, int err_code, my_vsnprintf(pbuff, pbuffsize, msg, args); - pthread_mutex_unlock(&err_lock); + mysql_mutex_unlock(&err_lock); va_end(args); /* If the msg string ends with '.', do not add a ',' it would be ugly */ @@ -51,5 +73,5 @@ Slave_reporting_capability::report(loglevel level, int err_code, Slave_reporting_capability::~Slave_reporting_capability() { - pthread_mutex_destroy(&err_lock); + mysql_mutex_destroy(&err_lock); } diff --git a/sql/rpl_reporting.h b/sql/rpl_reporting.h index ce33407e516..b8d9c049653 100644 --- a/sql/rpl_reporting.h +++ b/sql/rpl_reporting.h @@ -1,6 +1,21 @@ #ifndef RPL_REPORTING_H #define RPL_REPORTING_H +/* Copyright (C) 2008-2009 Sun Microsystems, Inc + + 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 */ + /** Maximum size of an error message from a slave thread. */ @@ -17,17 +32,13 @@ class Slave_reporting_capability { public: /** lock used to synchronize m_last_error on 'SHOW SLAVE STATUS' **/ - mutable pthread_mutex_t err_lock; + mutable mysql_mutex_t err_lock; /** Constructor. @param thread_name Printable name of the slave thread that is reporting. */ - Slave_reporting_capability(char const *thread_name) - : m_thread_name(thread_name) - { - pthread_mutex_init(&err_lock, MY_MUTEX_INIT_FAST); - } + Slave_reporting_capability(char const *thread_name); /** Writes a message and, if it's an error message, to Last_Error @@ -47,9 +58,9 @@ public: STATUS</code>. */ void clear_error() { - pthread_mutex_lock(&err_lock); + mysql_mutex_lock(&err_lock); m_last_error.clear(); - pthread_mutex_unlock(&err_lock); + mysql_mutex_unlock(&err_lock); } /** diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index 70d24f42985..a982cfd25a4 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -54,13 +54,15 @@ Relay_log_info::Relay_log_info(bool is_slave_recovery) bzero((char*) &info_file, sizeof(info_file)); bzero((char*) &cache_buf, sizeof(cache_buf)); cached_charset_invalidate(); - pthread_mutex_init(&run_lock, MY_MUTEX_INIT_FAST); - pthread_mutex_init(&data_lock, MY_MUTEX_INIT_FAST); - pthread_mutex_init(&log_space_lock, MY_MUTEX_INIT_FAST); - pthread_cond_init(&data_cond, NULL); - pthread_cond_init(&start_cond, NULL); - pthread_cond_init(&stop_cond, NULL); - pthread_cond_init(&log_space_cond, NULL); + mysql_mutex_init(key_relay_log_info_run_lock, &run_lock, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_relay_log_info_data_lock, + &data_lock, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_relay_log_info_log_space_lock, + &log_space_lock, MY_MUTEX_INIT_FAST); + mysql_cond_init(key_relay_log_info_data_cond, &data_cond, NULL); + mysql_cond_init(key_relay_log_info_start_cond, &start_cond, NULL); + mysql_cond_init(key_relay_log_info_stop_cond, &stop_cond, NULL); + mysql_cond_init(key_relay_log_info_log_space_cond, &log_space_cond, NULL); relay_log.init_pthread_objects(); DBUG_VOID_RETURN; } @@ -70,13 +72,13 @@ Relay_log_info::~Relay_log_info() { DBUG_ENTER("Relay_log_info::~Relay_log_info"); - pthread_mutex_destroy(&run_lock); - pthread_mutex_destroy(&data_lock); - pthread_mutex_destroy(&log_space_lock); - pthread_cond_destroy(&data_cond); - pthread_cond_destroy(&start_cond); - pthread_cond_destroy(&stop_cond); - pthread_cond_destroy(&log_space_cond); + mysql_mutex_destroy(&run_lock); + mysql_mutex_destroy(&data_lock); + mysql_mutex_destroy(&log_space_lock); + mysql_cond_destroy(&data_cond); + mysql_cond_destroy(&start_cond); + mysql_cond_destroy(&stop_cond); + mysql_cond_destroy(&log_space_cond); relay_log.cleanup(); DBUG_VOID_RETURN; } @@ -95,7 +97,7 @@ int init_relay_log_info(Relay_log_info* rli, if (rli->inited) // Set if this function called DBUG_RETURN(0); fn_format(fname, info_fname, mysql_data_home, "", 4+32); - pthread_mutex_lock(&rli->data_lock); + mysql_mutex_lock(&rli->data_lock); info_fd = rli->info_fd; rli->cur_log_fd = -1; rli->slave_skip_counter=0; @@ -110,7 +112,7 @@ int init_relay_log_info(Relay_log_info* rli, if (fn_format(pattern, PREFIX_SQL_LOAD, pattern, "", MY_SAFE_PATH | MY_RETURN_REAL_PATH) == NullS) { - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); sql_print_error("Unable to use slave's temporary directory %s", slave_load_tmpdir); DBUG_RETURN(1); @@ -139,7 +141,7 @@ int init_relay_log_info(Relay_log_info* rli, if (opt_relay_logname && opt_relay_logname[strlen(opt_relay_logname) - 1] == FN_LIBCHAR) { - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); sql_print_error("Path '%s' is a directory name, please specify \ a file name for --relay-log option", opt_relay_logname); DBUG_RETURN(1); @@ -151,7 +153,7 @@ a file name for --relay-log option", opt_relay_logname); opt_relaylog_index_name[strlen(opt_relaylog_index_name) - 1] == FN_LIBCHAR) { - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); sql_print_error("Path '%s' is a directory name, please specify \ a file name for --relay-log-index option", opt_relaylog_index_name); DBUG_RETURN(1); @@ -188,7 +190,7 @@ a file name for --relay-log-index option", opt_relaylog_index_name); (max_relay_log_size ? max_relay_log_size : max_binlog_size), 1, TRUE)) { - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); sql_print_error("Failed in open_log() called from init_relay_log_info()"); DBUG_RETURN(1); } @@ -203,8 +205,9 @@ a file name for --relay-log-index option", opt_relaylog_index_name); the old descriptor and re-create the old file */ if (info_fd >= 0) - my_close(info_fd, MYF(MY_WME)); - if ((info_fd = my_open(fname, O_CREAT|O_RDWR|O_BINARY, MYF(MY_WME))) < 0) + mysql_file_close(info_fd, MYF(MY_WME)); + if ((info_fd= mysql_file_open(key_file_relay_log_info, + fname, O_CREAT|O_RDWR|O_BINARY, MYF(MY_WME))) < 0) { sql_print_error("Failed to create a new relay log info file (\ file '%s', errno %d)", fname, my_errno); @@ -238,7 +241,8 @@ file '%s', errno %d)", fname, my_errno); else { int error=0; - if ((info_fd = my_open(fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0) + if ((info_fd= mysql_file_open(key_file_relay_log_info, + fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0) { sql_print_error("\ Failed to open the existing relay log info file '%s' (errno %d)", @@ -255,10 +259,10 @@ Failed to open the existing relay log info file '%s' (errno %d)", if (error) { if (info_fd >= 0) - my_close(info_fd, MYF(0)); + mysql_file_close(info_fd, MYF(0)); rli->info_fd= -1; rli->relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT); - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); DBUG_RETURN(1); } } @@ -327,17 +331,17 @@ Failed to open the existing relay log info file '%s' (errno %d)", goto err; } rli->inited= 1; - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); DBUG_RETURN(error); err: sql_print_error("%s", msg); end_io_cache(&rli->info_file); if (info_fd >= 0) - my_close(info_fd, MYF(0)); + mysql_file_close(info_fd, MYF(0)); rli->info_fd= -1; rli->relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT); - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); DBUG_RETURN(1); } @@ -346,7 +350,8 @@ static inline int add_relay_log(Relay_log_info* rli,LOG_INFO* linfo) { MY_STAT s; DBUG_ENTER("add_relay_log"); - if (!my_stat(linfo->log_file_name,&s,MYF(0))) + if (!mysql_file_stat(key_file_binlog, + linfo->log_file_name, &s, MYF(0))) { sql_print_error("log %s listed in the index, but failed to stat", linfo->log_file_name); @@ -446,10 +451,10 @@ int init_relay_log_pos(Relay_log_info* rli,const char* log, DBUG_PRINT("info", ("pos: %lu", (ulong) pos)); *errmsg=0; - pthread_mutex_t *log_lock=rli->relay_log.get_log_lock(); + mysql_mutex_t *log_lock= rli->relay_log.get_log_lock(); if (need_data_lock) - pthread_mutex_lock(&rli->data_lock); + mysql_mutex_lock(&rli->data_lock); /* Slave threads are not the only users of init_relay_log_pos(). CHANGE MASTER @@ -469,13 +474,13 @@ int init_relay_log_pos(Relay_log_info* rli,const char* log, rli->relay_log.description_event_for_exec= new Format_description_log_event(3); - pthread_mutex_lock(log_lock); + mysql_mutex_lock(log_lock); /* Close log file and free buffers if it's already open */ if (rli->cur_log_fd >= 0) { end_io_cache(&rli->cache_buf); - my_close(rli->cur_log_fd, MYF(MY_WME)); + mysql_file_close(rli->cur_log_fd, MYF(MY_WME)); rli->cur_log_fd = -1; } @@ -609,12 +614,12 @@ err: */ if (!relay_log_purge) rli->log_space_limit= 0; - pthread_cond_broadcast(&rli->data_cond); + mysql_cond_broadcast(&rli->data_cond); - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); if (need_data_lock) - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); if (!rli->relay_log.description_event_for_exec->is_valid() && !*errmsg) *errmsg= "Invalid Format_description log event; could be out of memory"; @@ -665,7 +670,7 @@ int Relay_log_info::wait_for_pos(THD* thd, String* log_name, log_name->c_ptr(), (ulong) log_pos, (ulong) timeout)); set_timespec(abstime,timeout); - pthread_mutex_lock(&data_lock); + mysql_mutex_lock(&data_lock); msg= thd->enter_cond(&data_cond, &data_lock, "Waiting for the slave SQL thread to " "advance position"); @@ -778,26 +783,26 @@ int Relay_log_info::wait_for_pos(THD* thd, String* log_name, DBUG_PRINT("info",("Waiting for master update")); /* - We are going to pthread_cond_(timed)wait(); if the SQL thread stops it + We are going to mysql_cond_(timed)wait(); if the SQL thread stops it will wake us up. */ if (timeout > 0) { /* - Note that pthread_cond_timedwait checks for the timeout + Note that mysql_cond_timedwait checks for the timeout before for the condition ; i.e. it returns ETIMEDOUT if the system time equals or exceeds the time specified by abstime before the condition variable is signaled or broadcast, _or_ if the absolute time specified by abstime has already passed at the time of the call. - For that reason, pthread_cond_timedwait will do the "timeoutting" job + For that reason, mysql_cond_timedwait will do the "timeoutting" job even if its condition is always immediately signaled (case of a loaded master). */ - error=pthread_cond_timedwait(&data_cond, &data_lock, &abstime); + error= mysql_cond_timedwait(&data_cond, &data_lock, &abstime); } else - pthread_cond_wait(&data_cond, &data_lock); + mysql_cond_wait(&data_cond, &data_lock); DBUG_PRINT("info",("Got signal of master update or timed out")); if (error == ETIMEDOUT || error == ETIME) { @@ -833,7 +838,7 @@ void Relay_log_info::inc_group_relay_log_pos(ulonglong log_pos, DBUG_ENTER("Relay_log_info::inc_group_relay_log_pos"); if (!skip_lock) - pthread_mutex_lock(&data_lock); + mysql_mutex_lock(&data_lock); inc_event_relay_log_pos(); group_relay_log_pos= event_relay_log_pos; strmake(group_relay_log_name,event_relay_log_name, @@ -877,9 +882,9 @@ void Relay_log_info::inc_group_relay_log_pos(ulonglong log_pos, { group_master_log_pos= log_pos; } - pthread_cond_broadcast(&data_cond); + mysql_cond_broadcast(&data_cond); if (!skip_lock) - pthread_mutex_unlock(&data_lock); + mysql_mutex_unlock(&data_lock); DBUG_VOID_RETURN; } @@ -948,7 +953,7 @@ int purge_relay_logs(Relay_log_info* rli, THD *thd, bool just_reset, DBUG_ASSERT(rli->mi->slave_running == 0); rli->slave_skip_counter=0; - pthread_mutex_lock(&rli->data_lock); + mysql_mutex_lock(&rli->data_lock); /* we close the relay log fd possibly left open by the slave SQL thread, @@ -959,7 +964,7 @@ int purge_relay_logs(Relay_log_info* rli, THD *thd, bool just_reset, if (rli->cur_log_fd >= 0) { end_io_cache(&rli->cache_buf); - my_close(rli->cur_log_fd, MYF(MY_WME)); + mysql_file_close(rli->cur_log_fd, MYF(MY_WME)); rli->cur_log_fd= -1; } @@ -991,7 +996,7 @@ err: char buf[22]; #endif DBUG_PRINT("info",("log_space_total: %s",llstr(rli->log_space_total,buf))); - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); DBUG_RETURN(error); } diff --git a/sql/rpl_rli.h b/sql/rpl_rli.h index 33b708cb1bd..c7bef125d40 100644 --- a/sql/rpl_rli.h +++ b/sql/rpl_rli.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2005 MySQL AB +/* Copyright (C) 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -123,17 +123,17 @@ public: TABLE *save_temporary_tables; /* - standard lock acquistion order to avoid deadlocks: + standard lock acquisition order to avoid deadlocks: run_lock, data_lock, relay_log.LOCK_log, relay_log.LOCK_index */ - pthread_mutex_t data_lock,run_lock; + mysql_mutex_t data_lock, run_lock; /* start_cond is broadcast when SQL thread is started stop_cond - when stopped data_cond - when data protected by data_lock changes */ - pthread_cond_t start_cond, stop_cond, data_cond; + mysql_cond_t start_cond, stop_cond, data_cond; /* parent Master_info structure */ Master_info *mi; @@ -215,8 +215,8 @@ public: volatile uint32 slave_skip_counter; volatile ulong abort_pos_wait; /* Incremented on change master */ volatile ulong slave_run_id; /* Incremented on slave start */ - pthread_mutex_t log_space_lock; - pthread_cond_t log_space_cond; + mysql_mutex_t log_space_lock; + mysql_cond_t log_space_cond; THD * sql_thd; #ifndef DBUG_OFF int events_till_abort; diff --git a/sql/set_var.cc b/sql/set_var.cc index 989934456df..73989b9c96f 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -1,4 +1,4 @@ -/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. +/* Copyright 2000-2008 MySQL AB, 2008-2010 Sun Microsystems, Inc. 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 @@ -38,16 +38,12 @@ static uchar *get_sys_var_length(const sys_var *var, size_t *length, sys_var_chain all_sys_vars = { NULL, NULL }; -int sys_var_init(DYNAMIC_ARRAY *long_options) +int sys_var_init() { - uint count= 0; - uint saved_elements= long_options->elements; - DBUG_ENTER("sys_var_init"); - for (sys_var *var=all_sys_vars.first; var; var= var->next, count++) - if (var->register_option(long_options)) - goto error; + /* Must be already initialized. */ + DBUG_ASSERT(system_charset_info != NULL); if (my_hash_init(&system_variable_hash, system_charset_info, 100, 0, 0, (my_hash_get_key) get_sys_var_length, 0, HASH_UNIQUE)) @@ -60,6 +56,25 @@ int sys_var_init(DYNAMIC_ARRAY *long_options) error: fprintf(stderr, "failed to initialize System variables"); + DBUG_RETURN(1); +} + +int sys_var_add_options(DYNAMIC_ARRAY *long_options, int parse_flags) +{ + uint saved_elements= long_options->elements; + + DBUG_ENTER("sys_var_add_options"); + + for (sys_var *var=all_sys_vars.first; var; var= var->next) + { + if (var->register_option(long_options, parse_flags)) + goto error; + } + + DBUG_RETURN(0); + +error: + fprintf(stderr, "failed to initialize System variables"); long_options->elements= saved_elements; DBUG_RETURN(1); } @@ -99,6 +114,7 @@ void sys_var_end() @param deprecated_version if not 0 - when this variable will go away @param substitute if not 0 - what one should use instead when this deprecated variable + @param parse_flag either PARSE_EARLY or PARSE_NORMAL */ sys_var::sys_var(sys_var_chain *chain, const char *name_arg, const char *comment, int flags_arg, ptrdiff_t off, @@ -107,10 +123,11 @@ sys_var::sys_var(sys_var_chain *chain, const char *name_arg, PolyLock *lock, enum binlog_status_enum binlog_status_arg, on_check_function on_check_func, on_update_function on_update_func, - uint deprecated_version, const char *substitute) : + uint deprecated_version, const char *substitute, + int parse_flag) : next(0), binlog_status(binlog_status_arg), - flags(flags_arg), show_val_type(show_val_type_arg), + flags(flags_arg), m_parse_flag(parse_flag), show_val_type(show_val_type_arg), guard(lock), offset(off), on_check(on_check_func), on_update(on_update_func), is_os_charset(FALSE) { @@ -203,7 +220,7 @@ uchar *sys_var::value_ptr(THD *thd, enum_var_type type, LEX_STRING *base) { if (type == OPT_GLOBAL || scope() == GLOBAL) { - safe_mutex_assert_owner(&LOCK_global_system_variables); + mysql_mutex_assert_owner(&LOCK_global_system_variables); AutoRLock lock(guard); return global_value_ptr(thd, base); } diff --git a/sql/set_var.h b/sql/set_var.h index d878e85cec0..4a212d3b685 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -1,6 +1,6 @@ #ifndef SET_VAR_INCLUDED #define SET_VAR_INCLUDED -/* Copyright 2000-2008 MySQL AB, 2009 Sun Microsystems, Inc. +/* Copyright (C) 2000-2008 MySQL AB, 2008-2010 Sun Microsystems, Inc. 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 @@ -56,6 +56,8 @@ public: LEX_CSTRING name; enum flag_enum { GLOBAL, SESSION, ONLY_SESSION, SCOPE_MASK=1023, READONLY=1024, ALLOCATED=2048 }; + static const int PARSE_EARLY= 1; + static const int PARSE_NORMAL= 2; /** Enumeration type to indicate for a system variable whether it will be written to the binlog or not. @@ -68,6 +70,7 @@ protected: typedef bool (*on_update_function)(sys_var *self, THD *thd, enum_var_type type); int flags; ///< or'ed flag_enum values + int m_parse_flag; ///< either PARSE_EARLY or PARSE_NORMAL. const SHOW_TYPE show_val_type; ///< what value_ptr() returns for sql_show.cc my_option option; ///< min, max, default values are stored here PolyLock *guard; ///< *second* lock that protects the variable @@ -83,7 +86,7 @@ public: enum get_opt_arg_type getopt_arg_type, SHOW_TYPE show_val_type_arg, longlong def_val, PolyLock *lock, enum binlog_status_enum binlog_status_arg, on_check_function on_check_func, on_update_function on_update_func, - uint deprecated_version, const char *substitute); + uint deprecated_version, const char *substitute, int parse_flag); /** The instance should only be destroyed on shutdown, as it doesn't unlink itself from the chain. @@ -122,8 +125,11 @@ public: } return true; // keep gcc happy } - bool register_option(DYNAMIC_ARRAY *array) - { return option.id != -1 && insert_dynamic(array, (uchar*)&option); } + bool register_option(DYNAMIC_ARRAY *array, int parse_flags) + { + return (option.id != -1) && (m_parse_flag & parse_flags) && + insert_dynamic(array, (uchar*)&option); + } private: virtual bool do_check(THD *thd, set_var *var) = 0; @@ -289,7 +295,8 @@ extern sys_var *Sys_autocommit_ptr; CHARSET_INFO *get_old_charset_by_name(const char *old_name); -int sys_var_init(DYNAMIC_ARRAY *long_options); +int sys_var_init(); +int sys_var_add_options(DYNAMIC_ARRAY *long_options, int parse_flags); void sys_var_end(void); #endif diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 69fd6e0fbe2..d19dd61bdde 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -6266,3 +6266,8 @@ ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT eng "The syntax '%s' is deprecated and will be removed in MySQL %s." ger "Die Syntax '%s' ist veraltet und wird in MySQL %s entfernt." +ER_WRONG_NATIVE_TABLE_STRUCTURE + eng "Native table '%-.64s'.'%-.64s' has the wrong structure" + +ER_WRONG_PERFSCHEMA_USAGE + eng "Invalid performance_schema usage." diff --git a/sql/slave.cc b/sql/slave.cc index 4dea78596ba..654ccfe72b5 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -148,8 +148,8 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi); static Log_event* next_event(Relay_log_info* rli); static int queue_event(Master_info* mi,const char* buf,ulong event_len); static int terminate_slave_thread(THD *thd, - pthread_mutex_t *term_lock, - pthread_cond_t *term_cond, + mysql_mutex_t *term_lock, + mysql_cond_t *term_cond, volatile uint *slave_running, bool skip_lock); static bool check_io_slave_killed(THD *thd, Master_info *mi, const char *info); @@ -198,8 +198,8 @@ void lock_slave_threads(Master_info* mi) DBUG_ENTER("lock_slave_threads"); //TODO: see if we can do this without dual mutex - pthread_mutex_lock(&mi->run_lock); - pthread_mutex_lock(&mi->rli.run_lock); + mysql_mutex_lock(&mi->run_lock); + mysql_mutex_lock(&mi->rli.run_lock); DBUG_VOID_RETURN; } @@ -213,11 +213,32 @@ void unlock_slave_threads(Master_info* mi) DBUG_ENTER("unlock_slave_threads"); //TODO: see if we can do this without dual mutex - pthread_mutex_unlock(&mi->rli.run_lock); - pthread_mutex_unlock(&mi->run_lock); + mysql_mutex_unlock(&mi->rli.run_lock); + mysql_mutex_unlock(&mi->run_lock); DBUG_VOID_RETURN; } +#ifdef HAVE_PSI_INTERFACE +static PSI_thread_key key_thread_slave_io, key_thread_slave_sql; + +static PSI_thread_info all_slave_threads[]= +{ + { &key_thread_slave_io, "slave_io", PSI_FLAG_GLOBAL}, + { &key_thread_slave_sql, "slave_sql", PSI_FLAG_GLOBAL} +}; + +static void init_slave_psi_keys(void) +{ + const char* category= "sql"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_slave_threads); + PSI_server->register_thread(category, all_slave_threads, count); +} +#endif /* HAVE_PSI_INTERFACE */ /* Initialize slave structures */ @@ -226,12 +247,16 @@ int init_slave() DBUG_ENTER("init_slave"); int error= 0; +#ifdef HAVE_PSI_INTERFACE + init_slave_psi_keys(); +#endif + /* This is called when mysqld starts. Before client connections are accepted. However bootstrap may conflict with us if it does START SLAVE. So it's safer to take the lock. */ - pthread_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&LOCK_active_mi); /* TODO: re-write this to interate through the list of files for multi-master @@ -288,7 +313,7 @@ int init_slave() } err: - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&LOCK_active_mi); DBUG_RETURN(error); } @@ -466,7 +491,7 @@ int terminate_slave_threads(Master_info* mi,int thread_mask,bool skip_lock) if (!mi->inited) DBUG_RETURN(0); /* successfully do nothing */ int error,force_all = (thread_mask & SLAVE_FORCE_ALL); - pthread_mutex_t *sql_lock = &mi->rli.run_lock, *io_lock = &mi->run_lock; + mysql_mutex_t *sql_lock = &mi->rli.run_lock, *io_lock = &mi->run_lock; if (thread_mask & (SLAVE_IO|SLAVE_FORCE_ALL)) { @@ -530,19 +555,19 @@ int terminate_slave_threads(Master_info* mi,int thread_mask,bool skip_lock) */ static int terminate_slave_thread(THD *thd, - pthread_mutex_t *term_lock, - pthread_cond_t *term_cond, + mysql_mutex_t *term_lock, + mysql_cond_t *term_cond, volatile uint *slave_running, bool skip_lock) { DBUG_ENTER("terminate_slave_thread"); if (!skip_lock) { - pthread_mutex_lock(term_lock); + mysql_mutex_lock(term_lock); } else { - safe_mutex_assert_owner(term_lock); + mysql_mutex_assert_owner(term_lock); } if (!*slave_running) { @@ -552,7 +577,7 @@ terminate_slave_thread(THD *thd, if run_lock (term_lock) is acquired locally then either slave_running status is fine */ - pthread_mutex_unlock(term_lock); + mysql_mutex_unlock(term_lock); DBUG_RETURN(0); } else @@ -573,7 +598,7 @@ terminate_slave_thread(THD *thd, int error; DBUG_PRINT("loop", ("killing slave thread")); - pthread_mutex_lock(&thd->LOCK_thd_data); + mysql_mutex_lock(&thd->LOCK_thd_data); #ifndef DONT_USE_THR_ALARM /* Error codes from pthread_kill are: @@ -584,7 +609,7 @@ terminate_slave_thread(THD *thd, DBUG_ASSERT(err != EINVAL); #endif thd->awake(THD::NOT_KILLED); - pthread_mutex_unlock(&thd->LOCK_thd_data); + mysql_mutex_unlock(&thd->LOCK_thd_data); /* There is a small chance that slave thread might miss the first @@ -592,21 +617,25 @@ terminate_slave_thread(THD *thd, */ struct timespec abstime; set_timespec(abstime,2); - error= pthread_cond_timedwait(term_cond, term_lock, &abstime); + error= mysql_cond_timedwait(term_cond, term_lock, &abstime); DBUG_ASSERT(error == ETIMEDOUT || error == 0); } DBUG_ASSERT(*slave_running == 0); if (!skip_lock) - pthread_mutex_unlock(term_lock); + mysql_mutex_unlock(term_lock); DBUG_RETURN(0); } -int start_slave_thread(pthread_handler h_func, pthread_mutex_t *start_lock, - pthread_mutex_t *cond_lock, - pthread_cond_t *start_cond, +int start_slave_thread( +#ifdef HAVE_PSI_INTERFACE + PSI_thread_key thread_key, +#endif + pthread_handler h_func, mysql_mutex_t *start_lock, + mysql_mutex_t *cond_lock, + mysql_cond_t *start_cond, volatile uint *slave_running, volatile ulong *slave_run_id, Master_info* mi) @@ -618,13 +647,13 @@ int start_slave_thread(pthread_handler h_func, pthread_mutex_t *start_lock, DBUG_ASSERT(mi->inited); if (start_lock) - pthread_mutex_lock(start_lock); + mysql_mutex_lock(start_lock); if (!server_id) { if (start_cond) - pthread_cond_broadcast(start_cond); + mysql_cond_broadcast(start_cond); if (start_lock) - pthread_mutex_unlock(start_lock); + mysql_mutex_unlock(start_lock); sql_print_error("Server id not set, will not start slave"); DBUG_RETURN(ER_BAD_SLAVE); } @@ -632,17 +661,18 @@ int start_slave_thread(pthread_handler h_func, pthread_mutex_t *start_lock, if (*slave_running) { if (start_cond) - pthread_cond_broadcast(start_cond); + mysql_cond_broadcast(start_cond); if (start_lock) - pthread_mutex_unlock(start_lock); + mysql_mutex_unlock(start_lock); DBUG_RETURN(ER_SLAVE_MUST_STOP); } start_id= *slave_run_id; DBUG_PRINT("info",("Creating new slave thread")); - if (pthread_create(&th, &connection_attrib, h_func, (void*)mi)) + if (mysql_thread_create(thread_key, + &th, &connection_attrib, h_func, (void*)mi)) { if (start_lock) - pthread_mutex_unlock(start_lock); + mysql_mutex_unlock(start_lock); DBUG_RETURN(ER_SLAVE_THREAD); } if (start_cond && cond_lock) // caller has cond_lock @@ -653,19 +683,19 @@ int start_slave_thread(pthread_handler h_func, pthread_mutex_t *start_lock, DBUG_PRINT("sleep",("Waiting for slave thread to start")); const char* old_msg = thd->enter_cond(start_cond,cond_lock, "Waiting for slave thread to start"); - pthread_cond_wait(start_cond, cond_lock); + mysql_cond_wait(start_cond, cond_lock); thd->exit_cond(old_msg); - pthread_mutex_lock(cond_lock); // re-acquire it as exit_cond() released + mysql_mutex_lock(cond_lock); // re-acquire it as exit_cond() released if (thd->killed) { if (start_lock) - pthread_mutex_unlock(start_lock); + mysql_mutex_unlock(start_lock); DBUG_RETURN(thd->killed_errno()); } } } if (start_lock) - pthread_mutex_unlock(start_lock); + mysql_mutex_unlock(start_lock); DBUG_RETURN(0); } @@ -683,8 +713,8 @@ int start_slave_threads(bool need_slave_mutex, bool wait_for_start, Master_info* mi, const char* master_info_fname, const char* slave_info_fname, int thread_mask) { - pthread_mutex_t *lock_io=0,*lock_sql=0,*lock_cond_io=0,*lock_cond_sql=0; - pthread_cond_t* cond_io=0,*cond_sql=0; + mysql_mutex_t *lock_io=0, *lock_sql=0, *lock_cond_io=0, *lock_cond_sql=0; + mysql_cond_t* cond_io=0, *cond_sql=0; int error=0; DBUG_ENTER("start_slave_threads"); @@ -702,16 +732,24 @@ int start_slave_threads(bool need_slave_mutex, bool wait_for_start, } if (thread_mask & SLAVE_IO) - error=start_slave_thread(handle_slave_io,lock_io,lock_cond_io, - cond_io, - &mi->slave_running, &mi->slave_run_id, - mi); + error= start_slave_thread( +#ifdef HAVE_PSI_INTERFACE + key_thread_slave_io, +#endif + handle_slave_io, lock_io, lock_cond_io, + cond_io, + &mi->slave_running, &mi->slave_run_id, + mi); if (!error && (thread_mask & SLAVE_SQL)) { - error=start_slave_thread(handle_slave_sql,lock_sql,lock_cond_sql, - cond_sql, - &mi->rli.slave_running, &mi->rli.slave_run_id, - mi); + error= start_slave_thread( +#ifdef HAVE_PSI_INTERFACE + key_thread_slave_sql, +#endif + handle_slave_sql, lock_sql, lock_cond_sql, + cond_sql, + &mi->rli.slave_running, &mi->rli.slave_run_id, + mi); if (error) terminate_slave_threads(mi, thread_mask & SLAVE_IO, !need_slave_mutex); } @@ -748,7 +786,7 @@ void end_slave() will make us wait until slave threads have started, and START SLAVE returns, then we terminate them here. */ - pthread_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&LOCK_active_mi); if (active_mi) { /* @@ -758,7 +796,7 @@ void end_slave() */ terminate_slave_threads(active_mi,SLAVE_FORCE_ALL); } - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&LOCK_active_mi); DBUG_VOID_RETURN; } @@ -773,14 +811,14 @@ void end_slave() */ void close_active_mi() { - pthread_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&LOCK_active_mi); if (active_mi) { end_master_info(active_mi); delete active_mi; active_mi= 0; } - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&LOCK_active_mi); } static bool io_slave_killed(THD* thd, Master_info* mi) @@ -1479,7 +1517,7 @@ static bool wait_for_relay_log_space(Relay_log_info* rli) THD* thd = mi->io_thd; DBUG_ENTER("wait_for_relay_log_space"); - pthread_mutex_lock(&rli->log_space_lock); + mysql_mutex_lock(&rli->log_space_lock); save_proc_info= thd->enter_cond(&rli->log_space_cond, &rli->log_space_lock, "\ @@ -1487,7 +1525,7 @@ Waiting for the slave SQL thread to free enough relay log space"); while (rli->log_space_limit < rli->log_space_total && !(slave_killed=io_slave_killed(thd,mi)) && !rli->ignore_log_space_limit) - pthread_cond_wait(&rli->log_space_cond, &rli->log_space_lock); + mysql_cond_wait(&rli->log_space_cond, &rli->log_space_lock); thd->exit_cond(save_proc_info); DBUG_RETURN(slave_killed); } @@ -1509,11 +1547,11 @@ Waiting for the slave SQL thread to free enough relay log space"); static void write_ignored_events_info_to_relay_log(THD *thd, Master_info *mi) { Relay_log_info *rli= &mi->rli; - pthread_mutex_t *log_lock= rli->relay_log.get_log_lock(); + mysql_mutex_t *log_lock= rli->relay_log.get_log_lock(); DBUG_ENTER("write_ignored_events_info_to_relay_log"); DBUG_ASSERT(thd == mi->io_thd); - pthread_mutex_lock(log_lock); + mysql_mutex_lock(log_lock); if (rli->ign_master_log_name_end[0]) { DBUG_PRINT("info",("writing a Rotate event to track down ignored events")); @@ -1522,7 +1560,7 @@ static void write_ignored_events_info_to_relay_log(THD *thd, Master_info *mi) Rotate_log_event::DUP_NAME); rli->ign_master_log_name_end[0]= 0; /* can unlock before writing as slave SQL thd will soon see our Rotate */ - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); if (likely((bool)ev)) { ev->server_id= 0; // don't be ignored by slave SQL thread @@ -1544,7 +1582,7 @@ static void write_ignored_events_info_to_relay_log(THD *thd, Master_info *mi) " SHOW SLAVE STATUS may be inaccurate"); } else - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); DBUG_VOID_RETURN; } @@ -1715,14 +1753,14 @@ bool show_master_info(THD* thd, Master_info* mi) slave_running can be accessed without run_lock but not other non-volotile members like mi->io_thd, which is guarded by the mutex. */ - pthread_mutex_lock(&mi->run_lock); + mysql_mutex_lock(&mi->run_lock); protocol->store(mi->io_thd ? mi->io_thd->proc_info : "", &my_charset_bin); - pthread_mutex_unlock(&mi->run_lock); + mysql_mutex_unlock(&mi->run_lock); - pthread_mutex_lock(&mi->data_lock); - pthread_mutex_lock(&mi->rli.data_lock); - pthread_mutex_lock(&mi->err_lock); - pthread_mutex_lock(&mi->rli.err_lock); + mysql_mutex_lock(&mi->data_lock); + mysql_mutex_lock(&mi->rli.data_lock); + mysql_mutex_lock(&mi->err_lock); + mysql_mutex_lock(&mi->rli.err_lock); protocol->store(mi->host, &my_charset_bin); protocol->store(mi->user, &my_charset_bin); protocol->store((uint32) mi->port); @@ -1849,10 +1887,10 @@ bool show_master_info(THD* thd, Master_info* mi) // Master_Server_id protocol->store((uint32) mi->master_id); - pthread_mutex_unlock(&mi->rli.err_lock); - pthread_mutex_unlock(&mi->err_lock); - pthread_mutex_unlock(&mi->rli.data_lock); - pthread_mutex_unlock(&mi->data_lock); + mysql_mutex_unlock(&mi->rli.err_lock); + mysql_mutex_unlock(&mi->err_lock); + mysql_mutex_unlock(&mi->rli.data_lock); + mysql_mutex_unlock(&mi->data_lock); if (my_net_write(&thd->net, (uchar*) thd->packet.ptr(), packet->length())) DBUG_RETURN(TRUE); @@ -2228,7 +2266,7 @@ int apply_event_and_update_pos(Log_event* ev, THD* thd, Relay_log_info* rli) int reason= ev->shall_skip(rli); if (reason == Log_event::EVENT_SKIP_COUNT) sql_slave_skip_counter= --rli->slave_skip_counter; - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); if (reason == Log_event::EVENT_SKIP_NOT) exec_res= ev->apply_event(rli); @@ -2334,7 +2372,7 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli) event execution. But we will release it in places where we will wait for something for example inside of next_event(). */ - pthread_mutex_lock(&rli->data_lock); + mysql_mutex_lock(&rli->data_lock); Log_event * ev = next_event(rli); @@ -2342,7 +2380,7 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli) if (sql_slave_killed(thd,rli)) { - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); delete ev; DBUG_RETURN(1); } @@ -2365,7 +2403,7 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli) error in query execution to be printed. */ rli->abort_slave= 1; - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); delete ev; DBUG_RETURN(1); } @@ -2383,7 +2421,7 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli) { DBUG_ASSERT(thd->transaction.all.modified_non_trans_table); rli->abort_slave= 1; - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); delete ev; rli->inc_event_relay_log_pos(); DBUG_RETURN(0); @@ -2447,10 +2485,10 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli) /* chance for concurrent connection to get more locks */ safe_sleep(thd, min(rli->trans_retries, MAX_SLAVE_RETRY_PAUSE), (CHECK_KILLED_FUNC)sql_slave_killed, (void*)rli); - pthread_mutex_lock(&rli->data_lock); // because of SHOW STATUS + mysql_mutex_lock(&rli->data_lock); // because of SHOW STATUS rli->trans_retries++; rli->retried_trans++; - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); DBUG_PRINT("info", ("Slave retries transaction " "rli->trans_retries: %lu", rli->trans_retries)); } @@ -2478,7 +2516,7 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli) } DBUG_RETURN(exec_res); } - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); rli->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_READ_FAILURE, ER(ER_SLAVE_RELAY_LOG_READ_FAILURE), "\ Could not parse relay log event entry. The possible reasons are: the master's \ @@ -2609,7 +2647,7 @@ pthread_handler_t handle_slave_io(void *arg) mysql= NULL ; retry_count= 0; - pthread_mutex_lock(&mi->run_lock); + mysql_mutex_lock(&mi->run_lock); /* Inform waiting threads that slave has started */ mi->slave_run_id++; @@ -2626,8 +2664,8 @@ pthread_handler_t handle_slave_io(void *arg) mi->clear_error(); if (init_slave_thread(thd, SLAVE_THD_IO)) { - pthread_cond_broadcast(&mi->start_cond); - pthread_mutex_unlock(&mi->run_lock); + mysql_cond_broadcast(&mi->start_cond); + mysql_mutex_unlock(&mi->run_lock); sql_print_error("Failed during slave I/O thread initialization"); goto err; } @@ -2636,8 +2674,8 @@ pthread_handler_t handle_slave_io(void *arg) pthread_mutex_unlock(&LOCK_thread_count); mi->slave_running = 1; mi->abort_slave = 0; - pthread_mutex_unlock(&mi->run_lock); - pthread_cond_broadcast(&mi->start_cond); + mysql_mutex_unlock(&mi->run_lock); + mysql_cond_broadcast(&mi->start_cond); DBUG_PRINT("master_info",("log_file_name: '%s' position: %s", mi->master_log_name, @@ -2920,7 +2958,7 @@ err: } write_ignored_events_info_to_relay_log(thd, mi); thd_proc_info(thd, "Waiting for slave mutex on exit"); - pthread_mutex_lock(&mi->run_lock); + mysql_mutex_lock(&mi->run_lock); /* Forget the relay log's format */ delete mi->rli.relay_log.description_event_for_queue; @@ -2942,9 +2980,9 @@ err: is important. Otherwise a killer_thread can execute between the calls and delete the mi structure leading to a crash! (see BUG#25306 for details) */ - pthread_cond_broadcast(&mi->stop_cond); // tell the world we are done + mysql_cond_broadcast(&mi->stop_cond); // tell the world we are done DBUG_EXECUTE_IF("simulate_slave_delay_at_terminate_bug38694", sleep(5);); - pthread_mutex_unlock(&mi->run_lock); + mysql_mutex_unlock(&mi->run_lock); DBUG_LEAVE; // Must match DBUG_ENTER() my_thread_end(); @@ -2981,16 +3019,17 @@ int check_temp_dir(char* tmp_file) /* Check permissions to create a file. */ - if ((fd= my_create(tmp_file, CREATE_MODE, - O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW, - MYF(MY_WME))) < 0) + if ((fd= mysql_file_create(key_file_misc, + tmp_file, CREATE_MODE, + O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW, + MYF(MY_WME))) < 0) DBUG_RETURN(1); /* Clean up. */ - my_close(fd, MYF(0)); - my_delete(tmp_file, MYF(0)); + mysql_file_close(fd, MYF(0)); + mysql_file_delete(key_file_misc, tmp_file, MYF(0)); DBUG_RETURN(0); } @@ -3016,7 +3055,7 @@ pthread_handler_t handle_slave_sql(void *arg) DBUG_ENTER("handle_slave_sql"); DBUG_ASSERT(rli->inited); - pthread_mutex_lock(&rli->run_lock); + mysql_mutex_lock(&rli->run_lock); DBUG_ASSERT(!rli->slave_running); errmsg= 0; #ifndef DBUG_OFF @@ -3038,8 +3077,8 @@ pthread_handler_t handle_slave_sql(void *arg) TODO: this is currently broken - slave start and change master will be stuck if we fail here */ - pthread_cond_broadcast(&rli->start_cond); - pthread_mutex_unlock(&rli->run_lock); + mysql_cond_broadcast(&rli->start_cond); + mysql_mutex_unlock(&rli->run_lock); rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, "Failed during slave thread initialization"); goto err; @@ -3059,8 +3098,8 @@ pthread_handler_t handle_slave_sql(void *arg) Seconds_Behind_Master grows. No big deal. */ rli->abort_slave = 0; - pthread_mutex_unlock(&rli->run_lock); - pthread_cond_broadcast(&rli->start_cond); + mysql_mutex_unlock(&rli->run_lock); + mysql_cond_broadcast(&rli->start_cond); /* Reset errors for a clean start (otherwise, if the master is idle, the SQL @@ -3075,9 +3114,9 @@ pthread_handler_t handle_slave_sql(void *arg) rli->clear_error(); //tell the I/O thread to take relay_log_space_limit into account from now on - pthread_mutex_lock(&rli->log_space_lock); + mysql_mutex_lock(&rli->log_space_lock); rli->ignore_log_space_limit= 0; - pthread_mutex_unlock(&rli->log_space_lock); + mysql_mutex_unlock(&rli->log_space_lock); rli->trans_retries= 0; // start from "no error" DBUG_PRINT("info", ("rli->trans_retries: %lu", rli->trans_retries)); @@ -3151,17 +3190,17 @@ log '%s' at position %s, relay log '%s' position: %s", RPL_LOG_NAME, First check until condition - probably there is nothing to execute. We do not want to wait for next event in this case. */ - pthread_mutex_lock(&rli->data_lock); + mysql_mutex_lock(&rli->data_lock); if (rli->until_condition != Relay_log_info::UNTIL_NONE && rli->is_until_satisfied(thd, NULL)) { char buf[22]; sql_print_information("Slave SQL thread stopped because it reached its" " UNTIL position %s", llstr(rli->until_pos(), buf)); - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); goto err; } - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); /* Read queries from the IO/THREAD until this thread is killed */ @@ -3264,9 +3303,9 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \ thd->set_query(NULL, 0); thd->reset_db(NULL, 0); thd_proc_info(thd, "Waiting for slave mutex on exit"); - pthread_mutex_lock(&rli->run_lock); + mysql_mutex_lock(&rli->run_lock); /* We need data_lock, at least to wake up any waiting master_pos_wait() */ - pthread_mutex_lock(&rli->data_lock); + mysql_mutex_lock(&rli->data_lock); DBUG_ASSERT(rli->slave_running == 1); // tracking buffer overrun /* When master_pos_wait() wakes up it will check this and terminate */ rli->slave_running= 0; @@ -3274,9 +3313,9 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \ delete rli->relay_log.description_event_for_exec; rli->relay_log.description_event_for_exec= 0; /* Wake up master_pos_wait() */ - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); DBUG_PRINT("info",("Signaling possibly waiting master_pos_wait() functions")); - pthread_cond_broadcast(&rli->data_cond); + mysql_cond_broadcast(&rli->data_cond); rli->ignore_log_space_limit= 0; /* don't need any lock */ /* we die so won't remember charset - re-update them on next thread start */ rli->cached_charset_invalidate(); @@ -3302,9 +3341,9 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \ is important. Otherwise a killer_thread can execute between the calls and delete the mi structure leading to a crash! (see BUG#25306 for details) */ - pthread_cond_broadcast(&rli->stop_cond); + mysql_cond_broadcast(&rli->stop_cond); DBUG_EXECUTE_IF("simulate_slave_delay_at_terminate_bug38694", sleep(5);); - pthread_mutex_unlock(&rli->run_lock); // tell the world we are done + mysql_mutex_unlock(&rli->run_lock); // tell the world we are done DBUG_LEAVE; // Must match DBUG_ENTER() my_thread_end(); @@ -3447,7 +3486,7 @@ err: static int process_io_rotate(Master_info *mi, Rotate_log_event *rev) { DBUG_ENTER("process_io_rotate"); - safe_mutex_assert_owner(&mi->data_lock); + mysql_mutex_assert_owner(&mi->data_lock); if (unlikely(!rev->is_valid())) DBUG_RETURN(1); @@ -3543,7 +3582,7 @@ static int queue_binlog_ver_1_event(Master_info *mi, const char *buf, DBUG_RETURN(1); } - pthread_mutex_lock(&mi->data_lock); + mysql_mutex_lock(&mi->data_lock); ev->log_pos= mi->master_log_pos; /* 3.23 events don't contain log_pos */ switch (ev->get_type_code()) { case STOP_EVENT: @@ -3554,7 +3593,7 @@ static int queue_binlog_ver_1_event(Master_info *mi, const char *buf, if (unlikely(process_io_rotate(mi,(Rotate_log_event*)ev))) { delete ev; - pthread_mutex_unlock(&mi->data_lock); + mysql_mutex_unlock(&mi->data_lock); DBUG_RETURN(1); } inc_pos= 0; @@ -3575,7 +3614,7 @@ static int queue_binlog_ver_1_event(Master_info *mi, const char *buf, delete ev; mi->master_log_pos += inc_pos; DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos)); - pthread_mutex_unlock(&mi->data_lock); + mysql_mutex_unlock(&mi->data_lock); my_free((char*)tmp_buf, MYF(0)); DBUG_RETURN(error); } @@ -3594,7 +3633,7 @@ static int queue_binlog_ver_1_event(Master_info *mi, const char *buf, if (unlikely(rli->relay_log.append(ev))) { delete ev; - pthread_mutex_unlock(&mi->data_lock); + mysql_mutex_unlock(&mi->data_lock); DBUG_RETURN(1); } rli->relay_log.harvest_bytes_written(&rli->log_space_total); @@ -3602,7 +3641,7 @@ static int queue_binlog_ver_1_event(Master_info *mi, const char *buf, delete ev; mi->master_log_pos+= inc_pos; DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos)); - pthread_mutex_unlock(&mi->data_lock); + mysql_mutex_unlock(&mi->data_lock); DBUG_RETURN(0); } @@ -3630,7 +3669,7 @@ static int queue_binlog_ver_3_event(Master_info *mi, const char *buf, my_free((char*) tmp_buf, MYF(MY_ALLOW_ZERO_PTR)); DBUG_RETURN(1); } - pthread_mutex_lock(&mi->data_lock); + mysql_mutex_lock(&mi->data_lock); switch (ev->get_type_code()) { case STOP_EVENT: goto err; @@ -3638,7 +3677,7 @@ static int queue_binlog_ver_3_event(Master_info *mi, const char *buf, if (unlikely(process_io_rotate(mi,(Rotate_log_event*)ev))) { delete ev; - pthread_mutex_unlock(&mi->data_lock); + mysql_mutex_unlock(&mi->data_lock); DBUG_RETURN(1); } inc_pos= 0; @@ -3650,7 +3689,7 @@ static int queue_binlog_ver_3_event(Master_info *mi, const char *buf, if (unlikely(rli->relay_log.append(ev))) { delete ev; - pthread_mutex_unlock(&mi->data_lock); + mysql_mutex_unlock(&mi->data_lock); DBUG_RETURN(1); } rli->relay_log.harvest_bytes_written(&rli->log_space_total); @@ -3658,7 +3697,7 @@ static int queue_binlog_ver_3_event(Master_info *mi, const char *buf, mi->master_log_pos+= inc_pos; err: DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos)); - pthread_mutex_unlock(&mi->data_lock); + mysql_mutex_unlock(&mi->data_lock); DBUG_RETURN(0); } @@ -3708,7 +3747,7 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len) String error_msg; ulong inc_pos; Relay_log_info *rli= &mi->rli; - pthread_mutex_t *log_lock= rli->relay_log.get_log_lock(); + mysql_mutex_t *log_lock= rli->relay_log.get_log_lock(); ulong s_id; DBUG_ENTER("queue_event"); @@ -3719,7 +3758,7 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len) DBUG_RETURN(queue_old_event(mi,buf,event_len)); LINT_INIT(inc_pos); - pthread_mutex_lock(&mi->data_lock); + mysql_mutex_lock(&mi->data_lock); switch (buf[EVENT_TYPE_OFFSET]) { case STOP_EVENT: @@ -3855,7 +3894,7 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len) direct master (an unsupported, useless setup!). */ - pthread_mutex_lock(log_lock); + mysql_mutex_lock(log_lock); s_id= uint4korr(buf + SERVER_ID_OFFSET); if ((s_id == ::server_id && !mi->rli.replicate_same_server_id) || /* @@ -3917,12 +3956,12 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len) } rli->ign_master_log_name_end[0]= 0; // last event is not ignored } - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); skip_relay_logging: err: - pthread_mutex_unlock(&mi->data_lock); + mysql_mutex_unlock(&mi->data_lock); DBUG_PRINT("info", ("error: %d", error)); if (error) mi->report(ERROR_LEVEL, error, ER(error), @@ -3942,13 +3981,13 @@ void end_relay_log_info(Relay_log_info* rli) if (rli->info_fd >= 0) { end_io_cache(&rli->info_file); - (void) my_close(rli->info_fd, MYF(MY_WME)); + mysql_file_close(rli->info_fd, MYF(MY_WME)); rli->info_fd = -1; } if (rli->cur_log_fd >= 0) { end_io_cache(&rli->cache_buf); - (void)my_close(rli->cur_log_fd, MYF(MY_WME)); + mysql_file_close(rli->cur_log_fd, MYF(MY_WME)); rli->cur_log_fd = -1; } rli->inited = 0; @@ -4304,7 +4343,7 @@ static Log_event* next_event(Relay_log_info* rli) { Log_event* ev; IO_CACHE* cur_log = rli->cur_log; - pthread_mutex_t *log_lock = rli->relay_log.get_log_lock(); + mysql_mutex_t *log_lock = rli->relay_log.get_log_lock(); const char* errmsg=0; THD* thd = rli->sql_thd; DBUG_ENTER("next_event"); @@ -4321,9 +4360,9 @@ static Log_event* next_event(Relay_log_info* rli) so we assume calling function acquired this mutex for us and we will hold it for the most of the loop below However, we will release it whenever it is worth the hassle, and in the cases when we go into a - pthread_cond_wait() with the non-data_lock mutex + mysql_cond_wait() with the non-data_lock mutex */ - safe_mutex_assert_owner(&rli->data_lock); + mysql_mutex_assert_owner(&rli->data_lock); while (!sql_slave_killed(thd,rli)) { @@ -4342,7 +4381,7 @@ static Log_event* next_event(Relay_log_info* rli) if ((hot_log = (cur_log != &rli->cache_buf))) { DBUG_ASSERT(rli->cur_log_fd == -1); // foreign descriptor - pthread_mutex_lock(log_lock); + mysql_mutex_lock(log_lock); /* Reading xxx_file_id is safe because the log will only @@ -4352,7 +4391,7 @@ static Log_event* next_event(Relay_log_info* rli) { // The master has switched to a new log file; Reopen the old log file cur_log=reopen_relay_log(rli, &errmsg); - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); if (!cur_log) // No more log files goto err; hot_log=0; // Using old binary log @@ -4399,7 +4438,7 @@ static Log_event* next_event(Relay_log_info* rli) */ rli->future_event_relay_log_pos= my_b_tell(cur_log); if (hot_log) - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); DBUG_RETURN(ev); } DBUG_ASSERT(thd==rli->sql_thd); @@ -4409,7 +4448,7 @@ static Log_event* next_event(Relay_log_info* rli) { errmsg = "slave SQL thread aborted because of I/O error"; if (hot_log) - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); goto err; } if (!cur_log->error) /* EOF */ @@ -4456,7 +4495,7 @@ static Log_event* next_event(Relay_log_info* rli) 0, rli->ign_master_log_pos_end, Rotate_log_event::DUP_NAME); rli->ign_master_log_name_end[0]= 0; - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); if (unlikely(!ev)) { errmsg= "Slave SQL thread failed to create a Rotate event " @@ -4471,7 +4510,7 @@ static Log_event* next_event(Relay_log_info* rli) We can, and should release data_lock while we are waiting for update. If we do not, show slave status will block */ - pthread_mutex_unlock(&rli->data_lock); + mysql_mutex_unlock(&rli->data_lock); /* Possible deadlock : @@ -4497,7 +4536,7 @@ static Log_event* next_event(Relay_log_info* rli) be stopped, and the SQL thread sets ignore_log_space_limit to 0 when it stops. */ - pthread_mutex_lock(&rli->log_space_lock); + mysql_mutex_lock(&rli->log_space_lock); // prevent the I/O thread from blocking next times rli->ignore_log_space_limit= 1; /* @@ -4506,12 +4545,12 @@ static Log_event* next_event(Relay_log_info* rli) ~Relay_log_info(), i.e. when rli is destroyed, and rli will not be destroyed before we exit the present function. */ - pthread_mutex_unlock(&rli->log_space_lock); - pthread_cond_broadcast(&rli->log_space_cond); + mysql_mutex_unlock(&rli->log_space_lock); + mysql_cond_broadcast(&rli->log_space_cond); // Note that wait_for_update_relay_log unlocks lock_log ! rli->relay_log.wait_for_update_relay_log(rli->sql_thd); // re-acquire data lock since we released it earlier - pthread_mutex_lock(&rli->data_lock); + mysql_mutex_lock(&rli->data_lock); rli->last_master_timestamp= save_timestamp; continue; } @@ -4522,7 +4561,7 @@ static Log_event* next_event(Relay_log_info* rli) */ end_io_cache(cur_log); DBUG_ASSERT(rli->cur_log_fd >= 0); - my_close(rli->cur_log_fd, MYF(MY_WME)); + mysql_file_close(rli->cur_log_fd, MYF(MY_WME)); rli->cur_log_fd = -1; if (relay_log_purge) @@ -4579,7 +4618,7 @@ static Log_event* next_event(Relay_log_info* rli) DBUG_PRINT("info",("hot_log: %d",hot_log)); if (!hot_log) /* if hot_log, we already have this mutex */ - pthread_mutex_lock(log_lock); + mysql_mutex_lock(log_lock); if (rli->relay_log.is_active(rli->linfo.log_file_name)) { #ifdef EXTRA_DEBUG @@ -4600,13 +4639,16 @@ static Log_event* next_event(Relay_log_info* rli) */ if (check_binlog_magic(cur_log,&errmsg)) { - if (!hot_log) pthread_mutex_unlock(log_lock); + if (!hot_log) + mysql_mutex_unlock(log_lock); goto err; } - if (!hot_log) pthread_mutex_unlock(log_lock); + if (!hot_log) + mysql_mutex_unlock(log_lock); continue; } - if (!hot_log) pthread_mutex_unlock(log_lock); + if (!hot_log) + mysql_mutex_unlock(log_lock); /* if we get here, the log was not hot, so we will have to open it ourselves. We are sure that the log is still not hot now (a log can get @@ -4629,7 +4671,7 @@ static Log_event* next_event(Relay_log_info* rli) TODO: come up with something better to handle this error */ if (hot_log) - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); sql_print_error("Slave SQL thread: I/O error reading \ event(errno: %d cur_log->error: %d)", my_errno,cur_log->error); diff --git a/sql/slave.h b/sql/slave.h index 69290ecac0a..421f838f188 100644 --- a/sql/slave.h +++ b/sql/slave.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -160,12 +160,17 @@ int start_slave_threads(bool need_slave_mutex, bool wait_for_start, inside the start_lock section, but at the same time we want a pthread_cond_wait() on start_cond,start_lock */ -int start_slave_thread(pthread_handler h_func, pthread_mutex_t* start_lock, - pthread_mutex_t *cond_lock, - pthread_cond_t* start_cond, - volatile uint *slave_running, - volatile ulong *slave_run_id, - Master_info* mi); +int start_slave_thread( +#ifdef HAVE_PSI_INTERFACE + PSI_thread_key thread_key, +#endif + pthread_handler h_func, + mysql_mutex_t *start_lock, + mysql_mutex_t *cond_lock, + mysql_cond_t *start_cond, + volatile uint *slave_running, + volatile ulong *slave_run_id, + Master_info *mi); /* If fd is -1, dump to NET */ int mysql_table_dump(THD* thd, const char* db, diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 4cbae0bbb5a..1f5ac826bdf 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -371,23 +371,23 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables) DBUG_PRINT("info",("user table fields: %d, password length: %d", table->s->fields, password_length)); - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); if (password_length < SCRAMBLED_PASSWORD_CHAR_LENGTH) { if (opt_secure_auth) { - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); sql_print_error("Fatal error: mysql.user table is in old format, " "but server started with --secure-auth option."); goto end; } mysql_user_table_is_in_short_password_format= true; if (global_system_variables.old_passwords) - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); else { global_system_variables.old_passwords= 1; - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); sql_print_warning("mysql.user table is not updated to new password format; " "Disabling new password usage until " "mysql_fix_privilege_tables is run"); @@ -397,7 +397,7 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables) else { mysql_user_table_is_in_short_password_format= false; - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); } allow_all_hosts=0; @@ -689,7 +689,7 @@ my_bool acl_reload(THD *thd) } if ((old_initialized=initialized)) - pthread_mutex_lock(&acl_cache->lock); + mysql_mutex_lock(&acl_cache->lock); old_acl_hosts=acl_hosts; old_acl_users=acl_users; @@ -716,7 +716,7 @@ my_bool acl_reload(THD *thd) delete_dynamic(&old_acl_dbs); } if (old_initialized) - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); end: close_thread_tables(thd); DBUG_RETURN(return_val); @@ -868,7 +868,7 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, DBUG_RETURN(0); } - pthread_mutex_lock(&acl_cache->lock); + mysql_mutex_lock(&acl_cache->lock); /* Find acl entry in user database. Note, that find_acl_user is not the same, @@ -1047,7 +1047,7 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, else *sctx->priv_host= 0; } - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); DBUG_RETURN(res); } @@ -1094,7 +1094,7 @@ bool acl_getroot_no_password(Security_context *sctx, char *user, char *host, DBUG_RETURN(FALSE); } - pthread_mutex_lock(&acl_cache->lock); + mysql_mutex_lock(&acl_cache->lock); sctx->master_access= 0; sctx->db_access= 0; @@ -1148,7 +1148,7 @@ bool acl_getroot_no_password(Security_context *sctx, char *user, char *host, else *sctx->priv_host= 0; } - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); DBUG_RETURN(res); } @@ -1169,7 +1169,7 @@ static void acl_update_user(const char *user, const char *host, USER_RESOURCES *mqh, ulong privileges) { - safe_mutex_assert_owner(&acl_cache->lock); + mysql_mutex_assert_owner(&acl_cache->lock); for (uint i=0 ; i < acl_users.elements ; i++) { @@ -1221,7 +1221,7 @@ static void acl_insert_user(const char *user, const char *host, { ACL_USER acl_user; - safe_mutex_assert_owner(&acl_cache->lock); + mysql_mutex_assert_owner(&acl_cache->lock); acl_user.user=*user ? strdup_root(&mem,user) : 0; update_hostname(&acl_user.host, *host ? strdup_root(&mem, host): 0); @@ -1252,7 +1252,7 @@ static void acl_insert_user(const char *user, const char *host, static void acl_update_db(const char *user, const char *host, const char *db, ulong privileges) { - safe_mutex_assert_owner(&acl_cache->lock); + mysql_mutex_assert_owner(&acl_cache->lock); for (uint i=0 ; i < acl_dbs.elements ; i++) { @@ -1297,7 +1297,7 @@ static void acl_insert_db(const char *user, const char *host, const char *db, ulong privileges) { ACL_DB acl_db; - safe_mutex_assert_owner(&acl_cache->lock); + mysql_mutex_assert_owner(&acl_cache->lock); acl_db.user=strdup_root(&mem,user); update_hostname(&acl_db.host, *host ? strdup_root(&mem,host) : 0); acl_db.db=strdup_root(&mem,db); @@ -1327,7 +1327,7 @@ ulong acl_get(const char *host, const char *ip, acl_entry *entry; DBUG_ENTER("acl_get"); - pthread_mutex_lock(&acl_cache->lock); + mysql_mutex_lock(&acl_cache->lock); end=strmov((tmp_db=strmov(strmov(key, ip ? ip : "")+1,user)+1),db); if (lower_case_table_names) { @@ -1339,7 +1339,7 @@ ulong acl_get(const char *host, const char *ip, key_length))) { db_access=entry->access; - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); DBUG_PRINT("exit", ("access: 0x%lx", db_access)); DBUG_RETURN(db_access); } @@ -1393,7 +1393,7 @@ exit: memcpy((uchar*) entry->key,key,key_length); acl_cache->add(entry); } - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); DBUG_PRINT("exit", ("access: 0x%lx", db_access & host_access)); DBUG_RETURN(db_access & host_access); } @@ -1475,12 +1475,12 @@ bool acl_check_host(const char *host, const char *ip) { if (allow_all_hosts) return 0; - pthread_mutex_lock(&acl_cache->lock); + mysql_mutex_lock(&acl_cache->lock); if ((host && my_hash_search(&acl_check_hosts,(uchar*) host,strlen(host))) || (ip && my_hash_search(&acl_check_hosts,(uchar*) ip, strlen(ip)))) { - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); return 0; // Found host } for (uint i=0 ; i < acl_wild_hosts.elements ; i++) @@ -1488,11 +1488,11 @@ bool acl_check_host(const char *host, const char *ip) acl_host_and_ip *acl=dynamic_element(&acl_wild_hosts,i,acl_host_and_ip*); if (compare_hostname(acl, host, ip)) { - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); return 0; // Host ok } } - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); return 1; // Host is not allowed } @@ -1528,7 +1528,7 @@ int check_change_password(THD *thd, const char *host, const char *user, my_strcasecmp(system_charset_info, host, thd->security_ctx->priv_host))) { - if (check_access(thd, UPDATE_ACL, "mysql",0,1,0,0)) + if (check_access(thd, UPDATE_ACL, "mysql", NULL, NULL, 1, 0)) return(1); } if (!thd->slave_thread && !thd->security_ctx->user[0]) @@ -1606,11 +1606,11 @@ bool change_password(THD *thd, const char *host, const char *user, if (!(table= open_ltable(thd, &tables, TL_WRITE, 0))) DBUG_RETURN(1); - pthread_mutex_lock(&acl_cache->lock); + mysql_mutex_lock(&acl_cache->lock); ACL_USER *acl_user; if (!(acl_user= find_acl_user(host, user, TRUE))) { - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), MYF(0)); goto end; } @@ -1622,12 +1622,12 @@ bool change_password(THD *thd, const char *host, const char *user, acl_user->user ? acl_user->user : "", new_password, new_password_len)) { - pthread_mutex_unlock(&acl_cache->lock); /* purecov: deadcode */ + mysql_mutex_unlock(&acl_cache->lock); /* purecov: deadcode */ goto end; } acl_cache->clear(1); // Clear locked hostname cache - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); result= 0; if (mysql_bin_log.is_open()) { @@ -1668,9 +1668,9 @@ bool is_acl_user(const char *host, const char *user) if (!initialized) return TRUE; - pthread_mutex_lock(&acl_cache->lock); + mysql_mutex_lock(&acl_cache->lock); res= find_acl_user(host, user, TRUE) != NULL; - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); return res; } @@ -1685,7 +1685,7 @@ find_acl_user(const char *host, const char *user, my_bool exact) DBUG_ENTER("find_acl_user"); DBUG_PRINT("enter",("host: '%s' user: '%s'",host,user)); - safe_mutex_assert_owner(&acl_cache->lock); + mysql_mutex_assert_owner(&acl_cache->lock); for (uint i=0 ; i < acl_users.elements ; i++) { @@ -1947,7 +1947,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, LEX *lex= thd->lex; DBUG_ENTER("replace_user_table"); - safe_mutex_assert_owner(&acl_cache->lock); + mysql_mutex_assert_owner(&acl_cache->lock); if (combo.password.str && combo.password.str[0]) { @@ -3147,8 +3147,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, if (!revoke_grant) create_new_users= test_if_create_new_users(thd); bool result= FALSE; - rw_wrlock(&LOCK_grant); - pthread_mutex_lock(&acl_cache->lock); + mysql_rwlock_wrlock(&LOCK_grant); + mysql_mutex_lock(&acl_cache->lock); MEM_ROOT *old_root= thd->mem_root; thd->mem_root= &memex; grant_version++; @@ -3253,14 +3253,14 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, } } thd->mem_root= old_root; - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); if (!result) /* success */ { result= write_bin_log(thd, TRUE, thd->query(), thd->query_length()); } - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); if (!result) /* success */ my_ok(thd); @@ -3357,8 +3357,8 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc, if (!revoke_grant) create_new_users= test_if_create_new_users(thd); - rw_wrlock(&LOCK_grant); - pthread_mutex_lock(&acl_cache->lock); + mysql_rwlock_wrlock(&LOCK_grant); + mysql_mutex_lock(&acl_cache->lock); MEM_ROOT *old_root= thd->mem_root; thd->mem_root= &memex; @@ -3419,7 +3419,7 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc, } } thd->mem_root= old_root; - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); if (write_to_binlog) { @@ -3427,7 +3427,7 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc, result= TRUE; } - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); /* Tables are automatically closed */ DBUG_RETURN(result); @@ -3499,8 +3499,8 @@ bool mysql_grant(THD *thd, const char *db, List <LEX_USER> &list, create_new_users= test_if_create_new_users(thd); /* go through users in user_list */ - rw_wrlock(&LOCK_grant); - pthread_mutex_lock(&acl_cache->lock); + mysql_rwlock_wrlock(&LOCK_grant); + mysql_mutex_lock(&acl_cache->lock); grant_version++; int result=0; @@ -3539,14 +3539,14 @@ bool mysql_grant(THD *thd, const char *db, List <LEX_USER> &list, } } } - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); if (!result) { result= write_bin_log(thd, TRUE, thd->query(), thd->query_length()); } - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); close_thread_tables(thd); if (!result) @@ -3810,7 +3810,7 @@ static my_bool grant_reload_procs_priv(THD *thd) DBUG_RETURN(TRUE); } - rw_wrlock(&LOCK_grant); + mysql_rwlock_wrlock(&LOCK_grant); /* Save a copy of the current hash if we need to undo the grant load */ old_proc_priv_hash= proc_priv_hash; old_func_priv_hash= func_priv_hash; @@ -3828,7 +3828,7 @@ static my_bool grant_reload_procs_priv(THD *thd) my_hash_free(&old_proc_priv_hash); my_hash_free(&old_func_priv_hash); } - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); close_thread_tables(thd); DBUG_RETURN(return_val); @@ -3876,7 +3876,7 @@ my_bool grant_reload(THD *thd) if (simple_open_n_lock_tables(thd, tables)) goto end; - rw_wrlock(&LOCK_grant); + mysql_rwlock_wrlock(&LOCK_grant); old_column_priv_hash= column_priv_hash; /* @@ -3898,7 +3898,7 @@ my_bool grant_reload(THD *thd) my_hash_free(&old_column_priv_hash); free_root(&old_mem,MYF(0)); } - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); close_thread_tables(thd); /* @@ -3908,9 +3908,9 @@ my_bool grant_reload(THD *thd) if (grant_reload_procs_priv(thd)) return_val= 1; - rw_wrlock(&LOCK_grant); + mysql_rwlock_wrlock(&LOCK_grant); grant_version++; - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); end: DBUG_RETURN(return_val); @@ -3962,6 +3962,7 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, TABLE_LIST *table, *first_not_own_table= thd->lex->first_not_own_table(); Security_context *sctx= thd->security_ctx; uint i; + ulong orig_want_access= want_access; DBUG_ENTER("check_grant"); DBUG_ASSERT(number > 0); @@ -3986,7 +3987,7 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, table->grant.orig_want_privilege= (want_access & ~SHOW_VIEW_ACL); } - rw_rdlock(&LOCK_grant); + mysql_rwlock_rdlock(&LOCK_grant); for (table= tables; table && number-- && table != first_not_own_table; table= table->next_global) @@ -3995,6 +3996,33 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, sctx = test(table->security_ctx) ? table->security_ctx : thd->security_ctx; + const ACL_internal_table_access *access; + access= get_cached_table_access(&table->grant.m_internal, + table->get_db_name(), + table->get_table_name()); + + if (access) + { + switch(access->check(orig_want_access, &table->grant.privilege)) + { + case ACL_INTERNAL_ACCESS_GRANTED: + /* + Currently, + - the information_schema does not subclass ACL_internal_table_access, + there are no per table privilege checks for I_S, + - the performance schema does use per tables checks, but at most + returns 'CHECK_GRANT', and never 'ACCESS_GRANTED'. + so this branch is not used. + */ + DBUG_ASSERT(0); + case ACL_INTERNAL_ACCESS_DENIED: + goto err; + case ACL_INTERNAL_ACCESS_CHECK_GRANT: + break; + } + } + + want_access= orig_want_access; want_access&= ~sctx->master_access; if (!want_access) continue; // ok @@ -4047,11 +4075,11 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, goto err; // impossible } } - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); DBUG_RETURN(FALSE); err: - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); if (!no_errors) // Not a silent skip of table { char command[128]; @@ -4066,96 +4094,6 @@ err: } -/** - Check if all tables in the table list has any of the requested table level - privileges matching the current user. - - @param thd A pointer to the thread context. - @param required_access Set of privileges to compare against. - @param tables[in,out] A list of tables to be checked. - - @note If the table grant hash contains any grant table, this table will be - attached to the corresponding TABLE_LIST object in 'tables'. - - @return - @retval TRUE There is a privilege on the table level granted to the - current user. - @retval FALSE There are no privileges on the table level granted to the - current user. -*/ - -bool has_any_table_level_privileges(THD *thd, ulong required_access, - TABLE_LIST *tables) -{ - - Security_context *sctx; - GRANT_TABLE *grant_table; - TABLE_LIST *table; - - /* For each table in tables */ - for (table= tables; table; table= table->next_global) - { - /* - If this table is a VIEW, then it will supply its own security context. - This is because VIEWs can have a DEFINER or an INVOKER security role. - */ - sctx= table->security_ctx ? table->security_ctx : thd->security_ctx; - - /* - Get privileges from table_priv and column_priv tables by searching - the cache. - */ - rw_rdlock(&LOCK_grant); - grant_table= table_hash_search(sctx->host, sctx->ip, - table->db, sctx->priv_user, - table->table_name,0); - rw_unlock(&LOCK_grant); - - /* Stop if there are no grants for the current user */ - if (!grant_table) - return FALSE; - - /* - Save a pointer to the found grant_table in the table object. - This pointer can later be used to verify other access requirements - without having to look up the grant table in the hash. - */ - table->grant.grant_table= grant_table; - table->grant.version= grant_version; - table->grant.privilege|= grant_table->privs; - /* - Save all privileges which might be subject to column privileges - but not which aren't yet granted by table level ACLs. - This is can later be used for column privilege checks. - */ - table->grant.want_privilege= ((required_access & COL_ACLS) - & ~table->grant.privilege); - - /* - If the requested privileges share any intersection with the current - table privileges we have found at least one common privilege on the - table level. - */ - if (grant_table->privs & required_access) - continue; /* Check next table */ - - /* - There are no table level privileges which satisfies any of the - requested privileges. There might still be column privileges which - does though. - */ - return FALSE; - } - - /* - All tables in TABLE_LIST satisfy the requirement of having any - privilege on the table level. - */ - - return TRUE; -} - - /* Check column rights in given security context @@ -4187,7 +4125,7 @@ bool check_grant_column(THD *thd, GRANT_INFO *grant, if (!want_access) DBUG_RETURN(0); // Already checked - rw_rdlock(&LOCK_grant); + mysql_rwlock_rdlock(&LOCK_grant); /* reload table if someone has modified any grants */ @@ -4205,12 +4143,12 @@ bool check_grant_column(THD *thd, GRANT_INFO *grant, grant_column=column_hash_search(grant_table, name, length); if (grant_column && !(~grant_column->rights & want_access)) { - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); DBUG_RETURN(0); } err: - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); char command[128]; get_privilege_desc(command, sizeof(command), want_access); my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0), @@ -4325,7 +4263,7 @@ bool check_grant_all_columns(THD *thd, ulong want_access_arg, */ bool using_column_privileges= FALSE; - rw_rdlock(&LOCK_grant); + mysql_rwlock_rdlock(&LOCK_grant); for (; !fields->end_of_fields(); fields->next()) { @@ -4366,11 +4304,11 @@ bool check_grant_all_columns(THD *thd, ulong want_access_arg, goto err; } } - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); return 0; err: - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); char command[128]; get_privilege_desc(command, sizeof(command), want_access); @@ -4428,7 +4366,7 @@ bool check_grant_db(THD *thd,const char *db) len= (uint) (strmov(strmov(helping, sctx->priv_user) + 1, db) - helping) + 1; - rw_rdlock(&LOCK_grant); + mysql_rwlock_rdlock(&LOCK_grant); for (uint idx=0 ; idx < column_priv_hash.records ; idx++) { @@ -4448,7 +4386,7 @@ bool check_grant_db(THD *thd,const char *db) error= check_grant_db_routine(thd, db, &proc_priv_hash) && check_grant_db_routine(thd, db, &func_priv_hash); - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); return error; } @@ -4484,7 +4422,7 @@ bool check_grant_routine(THD *thd, ulong want_access, if (!want_access) DBUG_RETURN(0); // ok - rw_rdlock(&LOCK_grant); + mysql_rwlock_rdlock(&LOCK_grant); for (table= procs; table; table= table->next_global) { GRANT_NAME *grant_proc; @@ -4498,10 +4436,10 @@ bool check_grant_routine(THD *thd, ulong want_access, goto err; } } - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); DBUG_RETURN(0); err: - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); if (!no_errors) { char buff[1024]; @@ -4542,13 +4480,13 @@ bool check_routine_level_acl(THD *thd, const char *db, const char *name, bool no_routine_acl= 1; GRANT_NAME *grant_proc; Security_context *sctx= thd->security_ctx; - rw_rdlock(&LOCK_grant); + mysql_rwlock_rdlock(&LOCK_grant); if ((grant_proc= routine_hash_search(sctx->priv_host, sctx->ip, db, sctx->priv_user, name, is_proc, 0))) no_routine_acl= !(grant_proc->privs & SHOW_PROC_ACLS); - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); return no_routine_acl; } @@ -4564,7 +4502,7 @@ ulong get_table_grant(THD *thd, TABLE_LIST *table) const char *db = table->db ? table->db : thd->db; GRANT_TABLE *grant_table; - rw_rdlock(&LOCK_grant); + mysql_rwlock_rdlock(&LOCK_grant); #ifdef EMBEDDED_LIBRARY grant_table= NULL; #else @@ -4576,7 +4514,7 @@ ulong get_table_grant(THD *thd, TABLE_LIST *table) if (grant_table) table->grant.privilege|= grant_table->privs; privilege= table->grant.privilege; - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); return privilege; } @@ -4607,7 +4545,7 @@ ulong get_column_grant(THD *thd, GRANT_INFO *grant, GRANT_COLUMN *grant_column; ulong priv; - rw_rdlock(&LOCK_grant); + mysql_rwlock_rdlock(&LOCK_grant); /* reload table if someone has modified any grants */ if (grant->version != grant_version) { @@ -4630,7 +4568,7 @@ ulong get_column_grant(THD *thd, GRANT_INFO *grant, else priv= (grant->privilege | grant_table->privs | grant_column->rights); } - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); return priv; } @@ -4697,14 +4635,14 @@ bool mysql_show_grants(THD *thd,LEX_USER *lex_user) DBUG_RETURN(TRUE); } - rw_rdlock(&LOCK_grant); - pthread_mutex_lock(&acl_cache->lock); + mysql_rwlock_rdlock(&LOCK_grant); + mysql_mutex_lock(&acl_cache->lock); acl_user= find_acl_user(lex_user->host.str, lex_user->user.str, TRUE); if (!acl_user) { - pthread_mutex_unlock(&acl_cache->lock); - rw_unlock(&LOCK_grant); + mysql_mutex_unlock(&acl_cache->lock); + mysql_rwlock_unlock(&LOCK_grant); my_error(ER_NONEXISTING_GRANT, MYF(0), lex_user->user.str, lex_user->host.str); @@ -4721,8 +4659,8 @@ bool mysql_show_grants(THD *thd,LEX_USER *lex_user) if (protocol->send_result_set_metadata(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) { - pthread_mutex_unlock(&acl_cache->lock); - rw_unlock(&LOCK_grant); + mysql_mutex_unlock(&acl_cache->lock); + mysql_rwlock_unlock(&LOCK_grant); DBUG_RETURN(TRUE); } @@ -5032,8 +4970,8 @@ bool mysql_show_grants(THD *thd,LEX_USER *lex_user) } end: - pthread_mutex_unlock(&acl_cache->lock); - rw_unlock(&LOCK_grant); + mysql_mutex_unlock(&acl_cache->lock); + mysql_rwlock_unlock(&LOCK_grant); my_eof(thd); DBUG_RETURN(error); @@ -5157,14 +5095,14 @@ void get_mqh(const char *user, const char *host, USER_CONN *uc) { ACL_USER *acl_user; - pthread_mutex_lock(&acl_cache->lock); + mysql_mutex_lock(&acl_cache->lock); if (initialized && (acl_user= find_acl_user(host,user, FALSE))) uc->user_resources= acl_user->user_resource; else bzero((char*) &uc->user_resources, sizeof(uc->user_resources)); - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); } /* @@ -5250,7 +5188,7 @@ ACL_USER *check_acl_user(LEX_USER *user_name, ACL_USER *acl_user= 0; uint counter; - safe_mutex_assert_owner(&acl_cache->lock); + mysql_mutex_assert_owner(&acl_cache->lock); for (counter= 0 ; counter < acl_users.elements ; counter++) { @@ -5519,7 +5457,7 @@ static int handle_grant_struct(uint struct_no, bool drop, LINT_INIT(user); LINT_INIT(host); - safe_mutex_assert_owner(&acl_cache->lock); + mysql_mutex_assert_owner(&acl_cache->lock); /* Get the number of elements in the in-memory structure. */ switch (struct_no) { @@ -5829,8 +5767,8 @@ bool mysql_create_user(THD *thd, List <LEX_USER> &list) if ((result= open_grant_tables(thd, tables))) DBUG_RETURN(result != 1); - rw_wrlock(&LOCK_grant); - pthread_mutex_lock(&acl_cache->lock); + mysql_rwlock_wrlock(&LOCK_grant); + mysql_mutex_lock(&acl_cache->lock); while ((tmp_user_name= user_list++)) { @@ -5860,7 +5798,7 @@ bool mysql_create_user(THD *thd, List <LEX_USER> &list) } } - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); if (result) my_error(ER_CANNOT_USER, MYF(0), "CREATE USER", wrong_users.c_ptr_safe()); @@ -5868,7 +5806,7 @@ bool mysql_create_user(THD *thd, List <LEX_USER> &list) if (some_users_created) result |= write_bin_log(thd, FALSE, thd->query(), thd->query_length()); - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); close_thread_tables(thd); DBUG_RETURN(result); } @@ -5911,8 +5849,8 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list) thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH; - rw_wrlock(&LOCK_grant); - pthread_mutex_lock(&acl_cache->lock); + mysql_rwlock_wrlock(&LOCK_grant); + mysql_mutex_lock(&acl_cache->lock); while ((tmp_user_name= user_list++)) { @@ -5933,7 +5871,7 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list) /* Rebuild 'acl_check_hosts' since 'acl_users' has been modified */ rebuild_check_host(); - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); if (result) my_error(ER_CANNOT_USER, MYF(0), "DROP USER", wrong_users.c_ptr_safe()); @@ -5941,7 +5879,7 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list) if (some_users_deleted) result |= write_bin_log(thd, FALSE, thd->query(), thd->query_length()); - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); close_thread_tables(thd); thd->variables.sql_mode= old_sql_mode; DBUG_RETURN(result); @@ -5983,8 +5921,8 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list) if ((result= open_grant_tables(thd, tables))) DBUG_RETURN(result != 1); - rw_wrlock(&LOCK_grant); - pthread_mutex_lock(&acl_cache->lock); + mysql_rwlock_wrlock(&LOCK_grant); + mysql_mutex_lock(&acl_cache->lock); while ((tmp_user_from= user_list++)) { @@ -6018,7 +5956,7 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list) /* Rebuild 'acl_check_hosts' since 'acl_users' has been modified */ rebuild_check_host(); - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); if (result) my_error(ER_CANNOT_USER, MYF(0), "RENAME USER", wrong_users.c_ptr_safe()); @@ -6026,7 +5964,7 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list) if (some_users_renamed && mysql_bin_log.is_open()) result |= write_bin_log(thd, FALSE, thd->query(), thd->query_length()); - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); close_thread_tables(thd); DBUG_RETURN(result); } @@ -6064,8 +6002,8 @@ bool mysql_revoke_all(THD *thd, List <LEX_USER> &list) if ((result= open_grant_tables(thd, tables))) DBUG_RETURN(result != 1); - rw_wrlock(&LOCK_grant); - pthread_mutex_lock(&acl_cache->lock); + mysql_rwlock_wrlock(&LOCK_grant); + mysql_mutex_lock(&acl_cache->lock); LEX_USER *lex_user, *tmp_lex_user; List_iterator <LEX_USER> user_list(list); @@ -6204,12 +6142,12 @@ bool mysql_revoke_all(THD *thd, List <LEX_USER> &list) } while (revoked); } - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); int binlog_error= write_bin_log(thd, FALSE, thd->query(), thd->query_length()); - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); close_thread_tables(thd); /* error for writing binary log has already been reported */ @@ -6314,8 +6252,8 @@ bool sp_revoke_privileges(THD *thd, const char *sp_db, const char *sp_name, /* Be sure to pop this before exiting this scope! */ thd->push_internal_handler(&error_handler); - rw_wrlock(&LOCK_grant); - pthread_mutex_lock(&acl_cache->lock); + mysql_rwlock_wrlock(&LOCK_grant); + mysql_mutex_lock(&acl_cache->lock); /* This statement will be replicated as a statement, even when using @@ -6353,8 +6291,8 @@ bool sp_revoke_privileges(THD *thd, const char *sp_db, const char *sp_name, } } while (revoked); - pthread_mutex_unlock(&acl_cache->lock); - rw_unlock(&LOCK_grant); + mysql_mutex_unlock(&acl_cache->lock); + mysql_rwlock_unlock(&LOCK_grant); close_thread_tables(thd); thd->pop_internal_handler(); @@ -6394,7 +6332,7 @@ bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, combo->user.str= sctx->user; - pthread_mutex_lock(&acl_cache->lock); + mysql_mutex_lock(&acl_cache->lock); if ((au= find_acl_user(combo->host.str=(char*)sctx->host_or_ip,combo->user.str,FALSE))) goto found_acl; @@ -6405,11 +6343,11 @@ bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, if((au= find_acl_user(combo->host.str=(char*)"%", combo->user.str, FALSE))) goto found_acl; - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); DBUG_RETURN(TRUE); found_acl: - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); bzero((char*)tables, sizeof(TABLE_LIST)); user_list.empty(); @@ -6562,13 +6500,14 @@ int fill_schema_user_privileges(THD *thd, TABLE_LIST *tables, COND *cond) ulong want_access; char buff[100]; TABLE *table= tables->table; - bool no_global_access= check_access(thd, SELECT_ACL, "mysql",0,1,1,0); + bool no_global_access= check_access(thd, SELECT_ACL, "mysql", + NULL, NULL, 1, 1); char *curr_host= thd->security_ctx->priv_host_name(); DBUG_ENTER("fill_schema_user_privileges"); if (!initialized) DBUG_RETURN(0); - pthread_mutex_lock(&acl_cache->lock); + mysql_mutex_lock(&acl_cache->lock); for (counter=0 ; counter < acl_users.elements ; counter++) { @@ -6618,7 +6557,7 @@ int fill_schema_user_privileges(THD *thd, TABLE_LIST *tables, COND *cond) } } err: - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); DBUG_RETURN(error); #else @@ -6636,13 +6575,14 @@ int fill_schema_schema_privileges(THD *thd, TABLE_LIST *tables, COND *cond) ulong want_access; char buff[100]; TABLE *table= tables->table; - bool no_global_access= check_access(thd, SELECT_ACL, "mysql",0,1,1,0); + bool no_global_access= check_access(thd, SELECT_ACL, "mysql", + NULL, NULL, 1, 1); char *curr_host= thd->security_ctx->priv_host_name(); DBUG_ENTER("fill_schema_schema_privileges"); if (!initialized) DBUG_RETURN(0); - pthread_mutex_lock(&acl_cache->lock); + mysql_mutex_lock(&acl_cache->lock); for (counter=0 ; counter < acl_dbs.elements ; counter++) { @@ -6695,7 +6635,7 @@ int fill_schema_schema_privileges(THD *thd, TABLE_LIST *tables, COND *cond) } } err: - pthread_mutex_unlock(&acl_cache->lock); + mysql_mutex_unlock(&acl_cache->lock); DBUG_RETURN(error); #else @@ -6711,11 +6651,12 @@ int fill_schema_table_privileges(THD *thd, TABLE_LIST *tables, COND *cond) uint index; char buff[100]; TABLE *table= tables->table; - bool no_global_access= check_access(thd, SELECT_ACL, "mysql",0,1,1,0); + bool no_global_access= check_access(thd, SELECT_ACL, "mysql", + NULL, NULL, 1, 1); char *curr_host= thd->security_ctx->priv_host_name(); DBUG_ENTER("fill_schema_table_privileges"); - rw_rdlock(&LOCK_grant); + mysql_rwlock_rdlock(&LOCK_grant); for (index=0 ; index < column_priv_hash.records ; index++) { @@ -6778,7 +6719,7 @@ int fill_schema_table_privileges(THD *thd, TABLE_LIST *tables, COND *cond) } } err: - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); DBUG_RETURN(error); #else @@ -6794,11 +6735,12 @@ int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond) uint index; char buff[100]; TABLE *table= tables->table; - bool no_global_access= check_access(thd, SELECT_ACL, "mysql",0,1,1,0); + bool no_global_access= check_access(thd, SELECT_ACL, "mysql", + NULL, NULL, 1, 1); char *curr_host= thd->security_ctx->priv_host_name(); DBUG_ENTER("fill_schema_table_privileges"); - rw_rdlock(&LOCK_grant); + mysql_rwlock_rdlock(&LOCK_grant); for (index=0 ; index < column_priv_hash.records ; index++) { @@ -6859,7 +6801,7 @@ int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond) } } err: - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); DBUG_RETURN(error); #else @@ -6911,7 +6853,7 @@ void fill_effective_table_privileges(THD *thd, GRANT_INFO *grant, grant->privilege|= acl_get(sctx->host, sctx->ip, sctx->priv_user, db, 0); /* table privileges */ - rw_rdlock(&LOCK_grant); + mysql_rwlock_rdlock(&LOCK_grant); if (grant->version != grant_version) { grant->grant_table= @@ -6924,7 +6866,7 @@ void fill_effective_table_privileges(THD *thd, GRANT_INFO *grant, { grant->privilege|= grant->grant_table->privs; } - rw_unlock(&LOCK_grant); + mysql_rwlock_unlock(&LOCK_grant); DBUG_PRINT("info", ("privilege 0x%lx", grant->privilege)); DBUG_VOID_RETURN; @@ -6943,3 +6885,104 @@ bool check_routine_level_acl(THD *thd, const char *db, const char *name, } #endif + +struct ACL_internal_schema_registry_entry +{ + const LEX_STRING *m_name; + const ACL_internal_schema_access *m_access; +}; + +/** + Internal schema registered. + Currently, this is only: + - performance_schema + - information_schema, + This can be reused later for: + - mysql +*/ +static ACL_internal_schema_registry_entry registry_array[2]; +static uint m_registry_array_size= 0; + +/** + Add an internal schema to the registry. + @param name the schema name + @param access the schema ACL specific rules +*/ +void ACL_internal_schema_registry::register_schema + (const LEX_STRING *name, const ACL_internal_schema_access *access) +{ + DBUG_ASSERT(m_registry_array_size < array_elements(registry_array)); + + /* Not thread safe, and does not need to be. */ + registry_array[m_registry_array_size].m_name= name; + registry_array[m_registry_array_size].m_access= access; + m_registry_array_size++; +} + +/** + Search per internal schema ACL by name. + @param name a schema name + @return per schema rules, or NULL +*/ +const ACL_internal_schema_access * +ACL_internal_schema_registry::lookup(const char *name) +{ + DBUG_ASSERT(name != NULL); + + uint i; + + for (i= 0; i<m_registry_array_size; i++) + { + if (my_strcasecmp(system_charset_info, registry_array[i].m_name->str, + name) == 0) + return registry_array[i].m_access; + } + return NULL; +} + +/** + Get a cached internal schema access. + @param grant_internal_info the cache + @param schema_name the name of the internal schema +*/ +const ACL_internal_schema_access * +get_cached_schema_access(GRANT_INTERNAL_INFO *grant_internal_info, + const char *schema_name) +{ + if (grant_internal_info) + { + if (! grant_internal_info->m_schema_lookup_done) + { + grant_internal_info->m_schema_access= + ACL_internal_schema_registry::lookup(schema_name); + grant_internal_info->m_schema_lookup_done= TRUE; + } + return grant_internal_info->m_schema_access; + } + return ACL_internal_schema_registry::lookup(schema_name); +} + +/** + Get a cached internal table access. + @param grant_internal_info the cache + @param schema_name the name of the internal schema + @param table_name the name of the internal table +*/ +const ACL_internal_table_access * +get_cached_table_access(GRANT_INTERNAL_INFO *grant_internal_info, + const char *schema_name, + const char *table_name) +{ + DBUG_ASSERT(grant_internal_info); + if (! grant_internal_info->m_table_lookup_done) + { + const ACL_internal_schema_access *schema_access; + schema_access= get_cached_schema_access(grant_internal_info, schema_name); + if (schema_access) + grant_internal_info->m_table_access= schema_access->lookup(table_name); + grant_internal_info->m_table_lookup_done= TRUE; + } + return grant_internal_info->m_table_access; +} + + diff --git a/sql/sql_acl.h b/sql/sql_acl.h index 59409299f73..8d521be2bc4 100644 --- a/sql/sql_acl.h +++ b/sql/sql_acl.h @@ -1,7 +1,7 @@ #ifndef SQL_ACL_INCLUDED #define SQL_ACL_INCLUDED -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -278,12 +278,139 @@ bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, bool check_routine_level_acl(THD *thd, const char *db, const char *name, bool is_proc); bool is_acl_user(const char *host, const char *user); -bool has_any_table_level_privileges(THD *thd, ulong required_access, - TABLE_LIST *tables); #ifdef NO_EMBEDDED_ACCESS_CHECKS #define check_grant(A,B,C,D,E,F) 0 #define check_grant_db(A,B) 0 -#define has_any_table_level_privileges(A,B,C) 0 #endif + +/** + Result of an access check for an internal schema or table. + Internal ACL checks are always performed *before* using + the grant tables. + This mechanism enforces that the server implementation has full + control on its internal tables. + Depending on the internal check result, the server implementation + can choose to: + - always allow access, + - always deny access, + - delegate the decision to the database administrator, + by using the grant tables. +*/ +enum ACL_internal_access_result +{ + /** + Access granted for all the requested privileges, + do not use the grant tables. + This flag is used only for the INFORMATION_SCHEMA privileges, + for compatibility reasons. + */ + ACL_INTERNAL_ACCESS_GRANTED, + /** Access denied, do not use the grant tables. */ + ACL_INTERNAL_ACCESS_DENIED, + /** No decision yet, use the grant tables. */ + ACL_INTERNAL_ACCESS_CHECK_GRANT +}; + +/** + Per internal table ACL access rules. + This class is an interface. + Per table(s) specific access rule should be implemented in a subclass. + @sa ACL_internal_schema_access +*/ +class ACL_internal_table_access +{ +public: + ACL_internal_table_access() + {} + + virtual ~ACL_internal_table_access() + {} + + /** + Check access to an internal table. + When a privilege is granted, this method add the requested privilege + to save_priv. + @param want_access the privileges requested + @param [in, out] save_priv the privileges granted + @return + @retval ACL_INTERNAL_ACCESS_GRANTED All the requested privileges + are granted, and saved in save_priv. + @retval ACL_INTERNAL_ACCESS_DENIED At least one of the requested + privileges was denied. + @retval ACL_INTERNAL_ACCESS_CHECK_GRANT No requested privilege + was denied, and grant should be checked for at least one + privilege. Requested privileges that are granted, if any, are saved + in save_priv. + */ + virtual ACL_internal_access_result check(ulong want_access, + ulong *save_priv) const= 0; +}; + +/** + Per internal schema ACL access rules. + This class is an interface. + Each per schema specific access rule should be implemented + in a different subclass, and registered. + Per schema access rules can control: + - every schema privileges on schema.* + - every table privileges on schema.table + @sa ACL_internal_schema_registry +*/ +class ACL_internal_schema_access +{ +public: + ACL_internal_schema_access() + {} + + virtual ~ACL_internal_schema_access() + {} + + /** + Check access to an internal schema. + @param want_access the privileges requested + @param [in, out] save_priv the privileges granted + @return + @retval ACL_INTERNAL_ACCESS_GRANTED All the requested privileges + are granted, and saved in save_priv. + @retval ACL_INTERNAL_ACCESS_DENIED At least one of the requested + privileges was denied. + @retval ACL_INTERNAL_ACCESS_CHECK_GRANT No requested privilege + was denied, and grant should be checked for at least one + privilege. Requested privileges that are granted, if any, are saved + in save_priv. + */ + virtual ACL_internal_access_result check(ulong want_access, + ulong *save_priv) const= 0; + + /** + Search for per table ACL access rules by table name. + @param name the table name + @return per table access rules, or NULL + */ + virtual const ACL_internal_table_access *lookup(const char *name) const= 0; +}; + +/** + A registry for per internal schema ACL. + An 'internal schema' is a database schema maintained by the + server implementation, such as 'performance_schema' and 'INFORMATION_SCHEMA'. +*/ +class ACL_internal_schema_registry +{ +public: + static void register_schema(const LEX_STRING *name, + const ACL_internal_schema_access *access); + static const ACL_internal_schema_access *lookup(const char *name); +}; + +const ACL_internal_schema_access * +get_cached_schema_access(GRANT_INTERNAL_INFO *grant_internal_info, + const char *schema_name); + +const ACL_internal_table_access * +get_cached_table_access(GRANT_INTERNAL_INFO *grant_internal_info, + const char *schema_name, + const char *table_name); + #endif /* SQL_ACL_INCLUDED */ diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 348f4305b02..a287fd533b7 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -100,7 +100,7 @@ TABLE *unused_tables; /* Used by mysql_test */ HASH open_cache; /* Used by mysql_test */ static HASH table_def_cache; static TABLE_SHARE *oldest_unused_share, end_of_unused_share; -static pthread_mutex_t LOCK_table_share; +static mysql_mutex_t LOCK_table_share; static bool table_def_inited= 0; static int open_unireg_entry(THD *thd, TABLE *entry, TABLE_LIST *table_list, @@ -272,10 +272,10 @@ static void table_def_free_entry(TABLE_SHARE *share) if (share->prev) { /* remove from old_unused_share list */ - pthread_mutex_lock(&LOCK_table_share); + mysql_mutex_lock(&LOCK_table_share); *share->prev= share->next; share->next->prev= share->prev; - pthread_mutex_unlock(&LOCK_table_share); + mysql_mutex_unlock(&LOCK_table_share); } free_table_share(share); DBUG_VOID_RETURN; @@ -285,7 +285,7 @@ static void table_def_free_entry(TABLE_SHARE *share) bool table_def_init(void) { table_def_inited= 1; - pthread_mutex_init(&LOCK_table_share, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_table_share, &LOCK_table_share, MY_MUTEX_INIT_FAST); oldest_unused_share= &end_of_unused_share; end_of_unused_share.prev= &oldest_unused_share; @@ -301,7 +301,7 @@ void table_def_free(void) if (table_def_inited) { table_def_inited= 0; - pthread_mutex_destroy(&LOCK_table_share); + mysql_mutex_destroy(&LOCK_table_share); my_hash_free(&table_def_cache); } DBUG_VOID_RETURN; @@ -361,7 +361,7 @@ TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key, Lock mutex to be able to read table definition from file without conflicts */ - (void) pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); /* We assign a new table id under the protection of the LOCK_open and @@ -392,7 +392,7 @@ TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key, share->ref_count++; // Mark in use DBUG_PRINT("exit", ("share: 0x%lx ref_count: %u", (ulong) share, share->ref_count)); - (void) pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); DBUG_RETURN(share); found: @@ -402,18 +402,18 @@ found: */ /* We must do a lock to ensure that the structure is initialized */ - (void) pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); if (share->error) { /* Table definition contained an error */ open_table_error(share, share->error, share->open_errno, share->errarg); - (void) pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); DBUG_RETURN(0); } if (share->is_view && !(db_flags & OPEN_VIEW)) { open_table_error(share, 1, ENOENT, 0); - (void) pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); DBUG_RETURN(0); } @@ -424,20 +424,20 @@ found: Unlink share from this list */ DBUG_PRINT("info", ("Unlinking from not used list")); - pthread_mutex_lock(&LOCK_table_share); + mysql_mutex_lock(&LOCK_table_share); *share->prev= share->next; share->next->prev= share->prev; share->next= 0; share->prev= 0; - pthread_mutex_unlock(&LOCK_table_share); + mysql_mutex_unlock(&LOCK_table_share); } - (void) pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); /* Free cache if too big */ while (table_def_cache.records > table_def_size && oldest_unused_share->next) { - pthread_mutex_lock(&oldest_unused_share->mutex); + mysql_mutex_lock(&oldest_unused_share->mutex); my_hash_delete(&table_def_cache, (uchar*) oldest_unused_share); } @@ -568,7 +568,7 @@ void release_table_share(TABLE_SHARE *share, enum release_type type) mysql_mutex_assert_owner(&LOCK_open); - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); if (!--share->ref_count) { if (share->version != refresh_version) @@ -579,12 +579,12 @@ void release_table_share(TABLE_SHARE *share, enum release_type type) DBUG_PRINT("info",("moving share to unused list")); DBUG_ASSERT(share->next == 0); - pthread_mutex_lock(&LOCK_table_share); + mysql_mutex_lock(&LOCK_table_share); share->prev= end_of_unused_share.prev; *end_of_unused_share.prev= share; end_of_unused_share.prev= &share->next; share->next= &end_of_unused_share; - pthread_mutex_unlock(&LOCK_table_share); + mysql_mutex_unlock(&LOCK_table_share); to_be_deleted= (table_def_cache.records > table_def_size); } @@ -596,7 +596,7 @@ void release_table_share(TABLE_SHARE *share, enum release_type type) my_hash_delete(&table_def_cache, (uchar*) share); DBUG_VOID_RETURN; } - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); DBUG_VOID_RETURN; } @@ -880,7 +880,7 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock, /* Free table shares */ while (oldest_unused_share->next) { - pthread_mutex_lock(&oldest_unused_share->mutex); + mysql_mutex_lock(&oldest_unused_share->mutex); (void) my_hash_delete(&table_def_cache, (uchar*) oldest_unused_share); } DBUG_PRINT("tcache", ("incremented global refresh_version to: %lu", @@ -2866,7 +2866,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, */ if (table->in_use != thd) { - /* wait_for_conditionwill unlock LOCK_open for us */ + /* wait_for_condition will unlock LOCK_open for us */ wait_for_condition(thd, &LOCK_open, &COND_refresh); } else @@ -4459,6 +4459,7 @@ thr_lock_type read_lock_type_for_table(THD *thd, TABLE *table) bool log_on= mysql_bin_log.is_open() && (thd->variables.option_bits & OPTION_BIN_LOG); ulong binlog_format= thd->variables.binlog_format; if ((log_on == FALSE) || (binlog_format == BINLOG_FORMAT_ROW) || + (table->s->table_category == TABLE_CATEGORY_LOG) || (table->s->table_category == TABLE_CATEGORY_PERFORMANCE)) return TL_READ; else @@ -5168,9 +5169,12 @@ int decide_logging_format(THD *thd, TABLE_LIST *tables) void* prev_ht= NULL; for (TABLE_LIST *table= tables; table; table= table->next_global) { + TABLE_CATEGORY category; if (table->placeholder()) continue; - if (table->table->s->table_category == TABLE_CATEGORY_PERFORMANCE) + category= table->table->s->table_category; + if ((category == TABLE_CATEGORY_LOG) || + (category == TABLE_CATEGORY_PERFORMANCE)) thd->lex->set_stmt_unsafe(); if (table->lock_type >= TL_WRITE_ALLOW_WRITE) { @@ -5595,7 +5599,7 @@ bool rm_temporary_table(handlerton *base, char *path) DBUG_ENTER("rm_temporary_table"); strmov(ext= strend(path), reg_ext); - if (my_delete(path,MYF(0))) + if (mysql_file_delete(key_file_frm, path, MYF(0))) error=1; /* purecov: inspected */ *ext= 0; // remove extension file= get_new_handler((TABLE_SHARE*) 0, current_thd->mem_root, base); @@ -8384,7 +8388,7 @@ my_bool mysql_rm_tmp_tables(void) So we hide error messages which happnes during deleting of these files(MYF(0)). */ - (void) my_delete(filePath, MYF(0)); + (void) mysql_file_delete(key_file_misc, filePath, MYF(0)); } } my_dirend(dirp); @@ -8562,7 +8566,7 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, share->version= 0; // Mark for delete if (share->ref_count == 0) { - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); my_hash_delete(&table_def_cache, (uchar*) share); } } @@ -9021,19 +9025,18 @@ open_system_table_for_update(THD *thd, TABLE_LIST *one_table) } /** - Open a performance schema table. + Open a log table. Opening such tables is performed internally in the server implementation, and is a 'nested' open, since some tables might be already opened by the current thread. The thread context before this call is saved, and is restored - when calling close_performance_schema_table(). + when calling close_log_table(). @param thd The current thread - @param one_table Performance schema table to open + @param one_table Log table to open @param backup [out] Temporary storage used to save the thread context */ TABLE * -open_performance_schema_table(THD *thd, TABLE_LIST *one_table, - Open_tables_state *backup) +open_log_table(THD *thd, TABLE_LIST *one_table, Open_tables_state *backup) { uint flags= ( MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK | MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | @@ -9042,13 +9045,13 @@ open_performance_schema_table(THD *thd, TABLE_LIST *one_table, TABLE *table; /* Save value that is changed in mysql_lock_tables() */ ulonglong save_utime_after_lock= thd->utime_after_lock; - DBUG_ENTER("open_performance_schema_table"); + DBUG_ENTER("open_log_table"); thd->reset_n_backup_open_tables_state(backup); if ((table= open_ltable(thd, one_table, one_table->lock_type, flags))) { - DBUG_ASSERT(table->s->table_category == TABLE_CATEGORY_PERFORMANCE); + DBUG_ASSERT(table->s->table_category == TABLE_CATEGORY_LOG); /* Make sure all columns get assigned to a default value */ table->use_all_columns(); table->no_replicate= 1; @@ -9076,18 +9079,18 @@ open_performance_schema_table(THD *thd, TABLE_LIST *one_table, } /** - Close a performance schema table. - The last table opened by open_performance_schema_table() + Close a log table. + The last table opened by open_log_table() is closed, then the thread context is restored. @param thd The current thread @param backup [in] the context to restore. */ -void close_performance_schema_table(THD *thd, Open_tables_state *backup) +void close_log_table(THD *thd, Open_tables_state *backup) { bool found_old_table; /* - If open_performance_schema_table() fails, + If open_log_table() fails, this function should not be called. */ DBUG_ASSERT(thd->lock != NULL); diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 07d36b1551a..0fd8d6e9b0f 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -1,4 +1,4 @@ -/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. +/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. 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 @@ -341,18 +341,14 @@ TODO list: #endif #if !defined(EXTRA_DBUG) && !defined(DBUG_OFF) -#define MUTEX_LOCK(M) { DBUG_PRINT("lock", ("mutex lock 0x%lx", (ulong)(M))); \ - pthread_mutex_lock(M);} -#define MUTEX_UNLOCK(M) {DBUG_PRINT("lock", ("mutex unlock 0x%lx",\ - (ulong)(M))); pthread_mutex_unlock(M);} #define RW_WLOCK(M) {DBUG_PRINT("lock", ("rwlock wlock 0x%lx",(ulong)(M))); \ - if (!rw_wrlock(M)) DBUG_PRINT("lock", ("rwlock wlock ok")); \ + if (!mysql_rwlock_wrlock(M)) DBUG_PRINT("lock", ("rwlock wlock ok")); \ else DBUG_PRINT("lock", ("rwlock wlock FAILED %d", errno)); } #define RW_RLOCK(M) {DBUG_PRINT("lock", ("rwlock rlock 0x%lx", (ulong)(M))); \ - if (!rw_rdlock(M)) DBUG_PRINT("lock", ("rwlock rlock ok")); \ + if (!mysql_rwlock_rdlock(M)) DBUG_PRINT("lock", ("rwlock rlock ok")); \ else DBUG_PRINT("lock", ("rwlock wlock FAILED %d", errno)); } #define RW_UNLOCK(M) {DBUG_PRINT("lock", ("rwlock unlock 0x%lx",(ulong)(M))); \ - if (!rw_unlock(M)) DBUG_PRINT("lock", ("rwlock unlock ok")); \ + if (!mysql_rwlock_unlock(M)) DBUG_PRINT("lock", ("rwlock unlock ok")); \ else DBUG_PRINT("lock", ("rwlock unlock FAILED %d", errno)); } #define BLOCK_LOCK_WR(B) {DBUG_PRINT("lock", ("%d LOCK_WR 0x%lx",\ __LINE__,(ulong)(B))); \ @@ -395,11 +391,9 @@ static void debug_wait_for_kill(const char *info) } #else -#define MUTEX_LOCK(M) pthread_mutex_lock(M) -#define MUTEX_UNLOCK(M) pthread_mutex_unlock(M) -#define RW_WLOCK(M) rw_wrlock(M) -#define RW_RLOCK(M) rw_rdlock(M) -#define RW_UNLOCK(M) rw_unlock(M) +#define RW_WLOCK(M) mysql_rwlock_wrlock(M) +#define RW_RLOCK(M) mysql_rwlock_rdlock(M) +#define RW_UNLOCK(M) mysql_rwlock_unlock(M) #define BLOCK_LOCK_WR(B) B->query()->lock_writing() #define BLOCK_LOCK_RD(B) B->query()->lock_reading() #define BLOCK_UNLOCK_WR(B) B->query()->unlock_writing() @@ -430,7 +424,7 @@ bool Query_cache::try_lock(bool use_timeout) bool interrupt= FALSE; DBUG_ENTER("Query_cache::try_lock"); - pthread_mutex_lock(&structure_guard_mutex); + mysql_mutex_lock(&structure_guard_mutex); while (1) { if (m_cache_lock_status == Query_cache::UNLOCKED) @@ -463,8 +457,8 @@ bool Query_cache::try_lock(bool use_timeout) { struct timespec waittime; set_timespec_nsec(waittime,(ulong)(50000000L)); /* Wait for 50 msec */ - int res= pthread_cond_timedwait(&COND_cache_status_changed, - &structure_guard_mutex,&waittime); + int res= mysql_cond_timedwait(&COND_cache_status_changed, + &structure_guard_mutex, &waittime); if (res == ETIMEDOUT) { interrupt= TRUE; @@ -473,11 +467,11 @@ bool Query_cache::try_lock(bool use_timeout) } else { - pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex); + mysql_cond_wait(&COND_cache_status_changed, &structure_guard_mutex); } } } - pthread_mutex_unlock(&structure_guard_mutex); + mysql_mutex_unlock(&structure_guard_mutex); DBUG_RETURN(interrupt); } @@ -498,9 +492,9 @@ void Query_cache::lock_and_suspend(void) { DBUG_ENTER("Query_cache::lock_and_suspend"); - pthread_mutex_lock(&structure_guard_mutex); + mysql_mutex_lock(&structure_guard_mutex); while (m_cache_lock_status != Query_cache::UNLOCKED) - pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex); + mysql_cond_wait(&COND_cache_status_changed, &structure_guard_mutex); m_cache_lock_status= Query_cache::LOCKED_NO_WAIT; #ifndef DBUG_OFF THD *thd= current_thd; @@ -508,8 +502,8 @@ void Query_cache::lock_and_suspend(void) m_cache_lock_thread_id= thd->thread_id; #endif /* Wake up everybody, a whole cache flush is starting! */ - pthread_cond_broadcast(&COND_cache_status_changed); - pthread_mutex_unlock(&structure_guard_mutex); + mysql_cond_broadcast(&COND_cache_status_changed); + mysql_mutex_unlock(&structure_guard_mutex); DBUG_VOID_RETURN; } @@ -526,16 +520,16 @@ void Query_cache::lock(void) { DBUG_ENTER("Query_cache::lock"); - pthread_mutex_lock(&structure_guard_mutex); + mysql_mutex_lock(&structure_guard_mutex); while (m_cache_lock_status != Query_cache::UNLOCKED) - pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex); + mysql_cond_wait(&COND_cache_status_changed, &structure_guard_mutex); m_cache_lock_status= Query_cache::LOCKED; #ifndef DBUG_OFF THD *thd= current_thd; if (thd) m_cache_lock_thread_id= thd->thread_id; #endif - pthread_mutex_unlock(&structure_guard_mutex); + mysql_mutex_unlock(&structure_guard_mutex); DBUG_VOID_RETURN; } @@ -548,7 +542,7 @@ void Query_cache::lock(void) void Query_cache::unlock(void) { DBUG_ENTER("Query_cache::unlock"); - pthread_mutex_lock(&structure_guard_mutex); + mysql_mutex_lock(&structure_guard_mutex); #ifndef DBUG_OFF THD *thd= current_thd; if (thd) @@ -558,8 +552,8 @@ void Query_cache::unlock(void) m_cache_lock_status == Query_cache::LOCKED_NO_WAIT); m_cache_lock_status= Query_cache::UNLOCKED; DBUG_PRINT("Query_cache",("Sending signal")); - pthread_cond_signal(&COND_cache_status_changed); - pthread_mutex_unlock(&structure_guard_mutex); + mysql_cond_signal(&COND_cache_status_changed); + mysql_mutex_unlock(&structure_guard_mutex); DBUG_VOID_RETURN; } @@ -728,7 +722,7 @@ inline void Query_cache_query::lock_writing() my_bool Query_cache_query::try_lock_writing() { DBUG_ENTER("Query_cache_block::try_lock_writing"); - if (rw_trywrlock(&lock)!=0) + if (mysql_rwlock_trywrlock(&lock) != 0) { DBUG_PRINT("info", ("can't lock rwlock")); DBUG_RETURN(0); @@ -760,7 +754,7 @@ void Query_cache_query::init_n_lock() { DBUG_ENTER("Query_cache_query::init_n_lock"); res=0; wri = 0; len = 0; - my_rwlock_init(&lock, NULL); + mysql_rwlock_init(key_rwlock_query_cache_query_lock, &lock); lock_writing(); DBUG_PRINT("qcache", ("inited & locked query for block 0x%lx", (long) (((uchar*) this) - @@ -780,7 +774,7 @@ void Query_cache_query::unlock_n_destroy() active semaphore */ this->unlock_writing(); - rwlock_destroy(&lock); + mysql_rwlock_destroy(&lock); DBUG_VOID_RETURN; } @@ -1984,8 +1978,8 @@ void Query_cache::destroy() free_cache(); unlock(); - pthread_cond_destroy(&COND_cache_status_changed); - pthread_mutex_destroy(&structure_guard_mutex); + mysql_cond_destroy(&COND_cache_status_changed); + mysql_mutex_destroy(&structure_guard_mutex); initialized = 0; } DBUG_VOID_RETURN; @@ -1999,8 +1993,10 @@ void Query_cache::destroy() void Query_cache::init() { DBUG_ENTER("Query_cache::init"); - pthread_mutex_init(&structure_guard_mutex,MY_MUTEX_INIT_FAST); - pthread_cond_init(&COND_cache_status_changed, NULL); + mysql_mutex_init(key_structure_guard_mutex, + &structure_guard_mutex, MY_MUTEX_INIT_FAST); + mysql_cond_init(key_COND_cache_status_changed, + &COND_cache_status_changed, NULL); m_cache_lock_status= Query_cache::UNLOCKED; initialized = 1; /* @@ -3846,7 +3842,7 @@ my_bool Query_cache::move_by_type(uchar **border, } while ( result_block != first_result_block ); } Query_cache_query *new_query= ((Query_cache_query *) new_block->data()); - my_rwlock_init(&new_query->lock, NULL); + mysql_rwlock_init(key_rwlock_query_cache_query_lock, &new_query->lock); /* If someone is writing to this block, inform the writer that the block diff --git a/sql/sql_cache.h b/sql/sql_cache.h index 33e535b2580..9d1f32d6ef1 100644 --- a/sql/sql_cache.h +++ b/sql/sql_cache.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2006 MySQL AB +/* Copyright (C) 2001-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -137,7 +137,7 @@ struct Query_cache_block struct Query_cache_query { ulonglong limit_found_rows; - rw_lock_t lock; + mysql_rwlock_t lock; Query_cache_block *res; Query_cache_tls *wri; ulong len; @@ -277,7 +277,7 @@ private: #ifndef DBUG_OFF my_thread_id m_cache_lock_thread_id; #endif - pthread_cond_t COND_cache_status_changed; + mysql_cond_t COND_cache_status_changed; enum Cache_lock_status { UNLOCKED, LOCKED_NO_WAIT, LOCKED }; Cache_lock_status m_cache_lock_status; @@ -302,7 +302,7 @@ protected: is other threads that were going to do cache flush---they'll wait till the end of a flush operation. */ - pthread_mutex_t structure_guard_mutex; + mysql_mutex_t structure_guard_mutex; uchar *cache; // cache memory Query_cache_block *first_block; // physical location block list Query_cache_block *queries_blocks; // query list (LIFO) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 53a96f8b9d9..2a82b0058da 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -268,8 +268,8 @@ const char *set_thd_proc_info(THD *thd, const char *info, } extern "C" -const char* thd_enter_cond(MYSQL_THD thd, pthread_cond_t *cond, - pthread_mutex_t *mutex, const char *msg) +const char* thd_enter_cond(MYSQL_THD thd, mysql_cond_t *cond, + mysql_mutex_t *mutex, const char *msg) { if (!thd) thd= current_thd; @@ -385,7 +385,7 @@ char *thd_security_context(THD *thd, char *buffer, unsigned int length, str.append(proc_info); } - pthread_mutex_lock(&thd->LOCK_thd_data); + mysql_mutex_lock(&thd->LOCK_thd_data); if (thd->query()) { @@ -397,7 +397,7 @@ char *thd_security_context(THD *thd, char *buffer, unsigned int length, str.append(thd->query(), len); } - pthread_mutex_unlock(&thd->LOCK_thd_data); + mysql_mutex_unlock(&thd->LOCK_thd_data); if (str.c_ptr_safe() == buffer) return buffer; @@ -536,7 +536,7 @@ THD::THD() #ifdef SIGNAL_WITH_VIO_CLOSE active_vio = 0; #endif - pthread_mutex_init(&LOCK_thd_data, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_thd_data, &LOCK_thd_data, MY_MUTEX_INIT_FAST); /* Variables with default values */ proc_info="login"; @@ -885,7 +885,7 @@ extern "C" THD *_current_thd_noinline(void) void THD::init(void) { - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); plugin_thdvar_init(this); /* variables= global_system_variables above has reset @@ -893,7 +893,7 @@ void THD::init(void) avoid temporary tables replication failure. */ variables.pseudo_thread_id= thread_id; - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); server_status= SERVER_STATUS_AUTOCOMMIT; if (variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES; @@ -1023,8 +1023,8 @@ THD::~THD() THD_CHECK_SENTRY(this); DBUG_ENTER("~THD()"); /* Ensure that no one is using THD */ - pthread_mutex_lock(&LOCK_thd_data); - pthread_mutex_unlock(&LOCK_thd_data); + mysql_mutex_lock(&LOCK_thd_data); + mysql_mutex_unlock(&LOCK_thd_data); add_to_status(&global_status_var, &status_var); /* Close connection */ @@ -1048,7 +1048,7 @@ THD::~THD() safeFree(db); free_root(&transaction.mem_root,MYF(0)); mysys_var=0; // Safety (shouldn't be needed) - pthread_mutex_destroy(&LOCK_thd_data); + mysql_mutex_destroy(&LOCK_thd_data); #ifndef DBUG_OFF dbug_sentry= THD_SENTRY_GONE; #endif @@ -1121,7 +1121,7 @@ void THD::awake(THD::killed_state state_to_set) DBUG_ENTER("THD::awake"); DBUG_PRINT("enter", ("this: 0x%lx", (long) this)); THD_CHECK_SENTRY(this); - safe_mutex_assert_owner(&LOCK_thd_data); + mysql_mutex_assert_owner(&LOCK_thd_data); killed= state_to_set; if (state_to_set != THD::KILL_QUERY) @@ -1524,7 +1524,7 @@ int THD::send_explain_fields(select_result *result) void THD::close_active_vio() { DBUG_ENTER("close_active_vio"); - safe_mutex_assert_owner(&LOCK_thd_data); + mysql_mutex_assert_owner(&LOCK_thd_data); #ifndef EMBEDDED_LIBRARY if (active_vio) { @@ -1756,8 +1756,9 @@ void select_to_file::send_error(uint errcode,const char *err) if (file > 0) { (void) end_io_cache(&cache); - (void) my_close(file,MYF(0)); - (void) my_delete(path,MYF(0)); // Delete file on error + mysql_file_close(file, MYF(0)); + /* Delete file on error */ + mysql_file_delete(key_select_to_file, path, MYF(0)); file= -1; } } @@ -1766,7 +1767,7 @@ void select_to_file::send_error(uint errcode,const char *err) bool select_to_file::send_eof() { int error= test(end_io_cache(&cache)); - if (my_close(file,MYF(MY_WME))) + if (mysql_file_close(file, MYF(MY_WME))) error= 1; if (!error) { @@ -1788,7 +1789,7 @@ void select_to_file::cleanup() if (file >= 0) { (void) end_io_cache(&cache); - (void) my_close(file,MYF(0)); + mysql_file_close(file, MYF(0)); file= -1; } path[0]= '\0'; @@ -1801,7 +1802,7 @@ select_to_file::~select_to_file() if (file >= 0) { // This only happens in case of error (void) end_io_cache(&cache); - (void) my_close(file,MYF(0)); + mysql_file_close(file, MYF(0)); file= -1; } } @@ -1865,7 +1866,8 @@ static File create_file(THD *thd, char *path, sql_exchange *exchange, return -1; } /* Create the file world readable */ - if ((file= my_create(path, 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0) + if ((file= mysql_file_create(key_select_to_file, + path, 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0) return file; #ifdef HAVE_FCHMOD (void) fchmod(file, 0666); // Because of umask() @@ -1874,8 +1876,9 @@ static File create_file(THD *thd, char *path, sql_exchange *exchange, #endif if (init_io_cache(cache, file, 0L, WRITE_CACHE, 0L, 1, MYF(MY_WME))) { - my_close(file, MYF(0)); - my_delete(path, MYF(0)); // Delete file on error, it was just created + mysql_file_close(file, MYF(0)); + /* Delete file on error, it was just created */ + mysql_file_delete(key_select_to_file, path, MYF(0)); return -1; } return file; @@ -2668,7 +2671,7 @@ int Statement_map::insert(THD *thd, Statement *statement) my_error(ER_OUT_OF_RESOURCES, MYF(0)); goto err_names_hash; } - pthread_mutex_lock(&LOCK_prepared_stmt_count); + mysql_mutex_lock(&LOCK_prepared_stmt_count); /* We don't check that prepared_stmt_count is <= max_prepared_stmt_count because we would like to allow to lower the total limit @@ -2678,13 +2681,13 @@ int Statement_map::insert(THD *thd, Statement *statement) */ if (prepared_stmt_count >= max_prepared_stmt_count) { - pthread_mutex_unlock(&LOCK_prepared_stmt_count); + mysql_mutex_unlock(&LOCK_prepared_stmt_count); my_error(ER_MAX_PREPARED_STMT_COUNT_REACHED, MYF(0), max_prepared_stmt_count); goto err_max; } prepared_stmt_count++; - pthread_mutex_unlock(&LOCK_prepared_stmt_count); + mysql_mutex_unlock(&LOCK_prepared_stmt_count); last_found_statement= statement; return 0; @@ -2717,20 +2720,20 @@ void Statement_map::erase(Statement *statement) my_hash_delete(&names_hash, (uchar *) statement); my_hash_delete(&st_hash, (uchar *) statement); - pthread_mutex_lock(&LOCK_prepared_stmt_count); + mysql_mutex_lock(&LOCK_prepared_stmt_count); DBUG_ASSERT(prepared_stmt_count > 0); prepared_stmt_count--; - pthread_mutex_unlock(&LOCK_prepared_stmt_count); + mysql_mutex_unlock(&LOCK_prepared_stmt_count); } void Statement_map::reset() { /* Must be first, hash_free will reset st_hash.records */ - pthread_mutex_lock(&LOCK_prepared_stmt_count); + mysql_mutex_lock(&LOCK_prepared_stmt_count); DBUG_ASSERT(prepared_stmt_count >= st_hash.records); prepared_stmt_count-= st_hash.records; - pthread_mutex_unlock(&LOCK_prepared_stmt_count); + mysql_mutex_unlock(&LOCK_prepared_stmt_count); my_hash_reset(&names_hash); my_hash_reset(&st_hash); @@ -2741,10 +2744,10 @@ void Statement_map::reset() Statement_map::~Statement_map() { /* Must go first, hash_free will reset st_hash.records */ - pthread_mutex_lock(&LOCK_prepared_stmt_count); + mysql_mutex_lock(&LOCK_prepared_stmt_count); DBUG_ASSERT(prepared_stmt_count >= st_hash.records); prepared_stmt_count-= st_hash.records; - pthread_mutex_unlock(&LOCK_prepared_stmt_count); + mysql_mutex_unlock(&LOCK_prepared_stmt_count); my_hash_free(&names_hash); my_hash_free(&st_hash); @@ -3248,9 +3251,9 @@ void THD::restore_sub_statement_state(Sub_statement_state *backup) void THD::set_statement(Statement *stmt) { - pthread_mutex_lock(&LOCK_thd_data); + mysql_mutex_lock(&LOCK_thd_data); Statement::set_statement(stmt); - pthread_mutex_unlock(&LOCK_thd_data); + mysql_mutex_unlock(&LOCK_thd_data); } @@ -3258,9 +3261,9 @@ void THD::set_statement(Statement *stmt) void THD::set_query(char *query_arg, uint32 query_length_arg) { - pthread_mutex_lock(&LOCK_thd_data); + mysql_mutex_lock(&LOCK_thd_data); set_query_inner(query_arg, query_length_arg); - pthread_mutex_unlock(&LOCK_thd_data); + mysql_mutex_unlock(&LOCK_thd_data); } /** Assign a new value to thd->query and thd->query_id. */ @@ -3268,19 +3271,19 @@ void THD::set_query(char *query_arg, uint32 query_length_arg) void THD::set_query_and_id(char *query_arg, uint32 query_length_arg, query_id_t new_query_id) { - pthread_mutex_lock(&LOCK_thd_data); + mysql_mutex_lock(&LOCK_thd_data); set_query_inner(query_arg, query_length_arg); query_id= new_query_id; - pthread_mutex_unlock(&LOCK_thd_data); + mysql_mutex_unlock(&LOCK_thd_data); } /** Assign a new value to thd->query_id. */ void THD::set_query_id(query_id_t new_query_id) { - pthread_mutex_lock(&LOCK_thd_data); + mysql_mutex_lock(&LOCK_thd_data); query_id= new_query_id; - pthread_mutex_unlock(&LOCK_thd_data); + mysql_mutex_unlock(&LOCK_thd_data); } @@ -3313,7 +3316,7 @@ void mark_transaction_to_rollback(THD *thd, bool all) Handling of XA id cacheing ***************************************************************************/ -pthread_mutex_t LOCK_xid_cache; +mysql_mutex_t LOCK_xid_cache; HASH xid_cache; extern "C" uchar *xid_get_hash_key(const uchar *, size_t *, my_bool); @@ -3332,9 +3335,34 @@ void xid_free_hash(void *ptr) my_free((uchar*)ptr, MYF(0)); } +#ifdef HAVE_PSI_INTERFACE +static PSI_mutex_key key_LOCK_xid_cache; + +static PSI_mutex_info all_xid_mutexes[]= +{ + { &key_LOCK_xid_cache, "LOCK_xid_cache", PSI_FLAG_GLOBAL} +}; + +static void init_xid_psi_keys(void) +{ + const char* category= "sql"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_xid_mutexes); + PSI_server->register_mutex(category, all_xid_mutexes, count); +} +#endif /* HAVE_PSI_INTERFACE */ + bool xid_cache_init() { - pthread_mutex_init(&LOCK_xid_cache, MY_MUTEX_INIT_FAST); +#ifdef HAVE_PSI_INTERFACE + init_xid_psi_keys(); +#endif + + mysql_mutex_init(key_LOCK_xid_cache, &LOCK_xid_cache, MY_MUTEX_INIT_FAST); return my_hash_init(&xid_cache, &my_charset_bin, 100, 0, 0, xid_get_hash_key, xid_free_hash, 0) != 0; } @@ -3344,16 +3372,16 @@ void xid_cache_free() if (my_hash_inited(&xid_cache)) { my_hash_free(&xid_cache); - pthread_mutex_destroy(&LOCK_xid_cache); + mysql_mutex_destroy(&LOCK_xid_cache); } } XID_STATE *xid_cache_search(XID *xid) { - pthread_mutex_lock(&LOCK_xid_cache); + mysql_mutex_lock(&LOCK_xid_cache); XID_STATE *res=(XID_STATE *)my_hash_search(&xid_cache, xid->key(), xid->key_length()); - pthread_mutex_unlock(&LOCK_xid_cache); + mysql_mutex_unlock(&LOCK_xid_cache); return res; } @@ -3362,7 +3390,7 @@ bool xid_cache_insert(XID *xid, enum xa_states xa_state) { XID_STATE *xs; my_bool res; - pthread_mutex_lock(&LOCK_xid_cache); + mysql_mutex_lock(&LOCK_xid_cache); if (my_hash_search(&xid_cache, xid->key(), xid->key_length())) res=0; else if (!(xs=(XID_STATE *)my_malloc(sizeof(*xs), MYF(MY_WME)))) @@ -3374,27 +3402,27 @@ bool xid_cache_insert(XID *xid, enum xa_states xa_state) xs->in_thd=0; res=my_hash_insert(&xid_cache, (uchar*)xs); } - pthread_mutex_unlock(&LOCK_xid_cache); + mysql_mutex_unlock(&LOCK_xid_cache); return res; } bool xid_cache_insert(XID_STATE *xid_state) { - pthread_mutex_lock(&LOCK_xid_cache); + mysql_mutex_lock(&LOCK_xid_cache); DBUG_ASSERT(my_hash_search(&xid_cache, xid_state->xid.key(), xid_state->xid.key_length())==0); my_bool res=my_hash_insert(&xid_cache, (uchar*)xid_state); - pthread_mutex_unlock(&LOCK_xid_cache); + mysql_mutex_unlock(&LOCK_xid_cache); return res; } void xid_cache_delete(XID_STATE *xid_state) { - pthread_mutex_lock(&LOCK_xid_cache); + mysql_mutex_lock(&LOCK_xid_cache); my_hash_delete(&xid_cache, (uchar *)xid_state); - pthread_mutex_unlock(&LOCK_xid_cache); + mysql_mutex_unlock(&LOCK_xid_cache); } /* diff --git a/sql/sql_class.h b/sql/sql_class.h index 03f06e5aa26..b3cc1fc68c0 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -775,7 +775,7 @@ typedef struct st_xid_state { uint rm_error; } XID_STATE; -extern pthread_mutex_t LOCK_xid_cache; +extern mysql_mutex_t LOCK_xid_cache; extern HASH xid_cache; bool xid_cache_init(void); void xid_cache_free(void); @@ -1236,7 +1236,7 @@ public: - thd->mysys_var (used by KILL statement and shutdown). Is locked when THD is deleted. */ - pthread_mutex_t LOCK_thd_data; + mysql_mutex_t LOCK_thd_data; /* all prepared statements and cursors of this connection */ Statement_map stmt_map; @@ -1810,15 +1810,15 @@ public: #ifdef SIGNAL_WITH_VIO_CLOSE inline void set_active_vio(Vio* vio) { - pthread_mutex_lock(&LOCK_thd_data); + mysql_mutex_lock(&LOCK_thd_data); active_vio = vio; - pthread_mutex_unlock(&LOCK_thd_data); + mysql_mutex_unlock(&LOCK_thd_data); } inline void clear_active_vio() { - pthread_mutex_lock(&LOCK_thd_data); + mysql_mutex_lock(&LOCK_thd_data); active_vio = 0; - pthread_mutex_unlock(&LOCK_thd_data); + mysql_mutex_unlock(&LOCK_thd_data); } void close_active_vio(); #endif @@ -1865,12 +1865,6 @@ public: proc_info = msg; return old_msg; } - inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t *mutex, - const char *msg) - { - /* TO BE REMOVED: temporary helper, to help with merges */ - return enter_cond((mysql_cond_t*) cond, (mysql_mutex_t*) mutex, msg); - } inline void exit_cond(const char* old_msg) { /* diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index a966d4a6bd4..ccc176624ed 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2007 MySQL AB +/* Copyright (C) 2007 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -60,7 +60,7 @@ static int get_or_create_user_conn(THD *thd, const char *user, user_len= strlen(user); temp_len= (strmov(strmov(temp_user, user)+1, host) - temp_user)+1; - (void) pthread_mutex_lock(&LOCK_user_conn); + mysql_mutex_lock(&LOCK_user_conn); if (!(uc = (struct user_conn *) my_hash_search(&hash_user_connections, (uchar*) temp_user, temp_len))) { @@ -91,7 +91,7 @@ static int get_or_create_user_conn(THD *thd, const char *user, thd->user_connect=uc; uc->connections++; end: - (void) pthread_mutex_unlock(&LOCK_user_conn); + mysql_mutex_unlock(&LOCK_user_conn); return return_val; } @@ -120,7 +120,7 @@ int check_for_max_user_connections(THD *thd, USER_CONN *uc) int error=0; DBUG_ENTER("check_for_max_user_connections"); - (void) pthread_mutex_lock(&LOCK_user_conn); + mysql_mutex_lock(&LOCK_user_conn); if (global_system_variables.max_user_connections && !uc->user_resources.user_conn && global_system_variables.max_user_connections < (uint) uc->connections) @@ -161,7 +161,7 @@ end: */ thd->user_connect= NULL; } - (void) pthread_mutex_unlock(&LOCK_user_conn); + mysql_mutex_unlock(&LOCK_user_conn); DBUG_RETURN(error); } @@ -187,14 +187,14 @@ end: void decrease_user_connections(USER_CONN *uc) { DBUG_ENTER("decrease_user_connections"); - (void) pthread_mutex_lock(&LOCK_user_conn); + mysql_mutex_lock(&LOCK_user_conn); DBUG_ASSERT(uc->connections); if (!--uc->connections && !mqh_used) { /* Last connection for user; Delete it */ (void) my_hash_delete(&hash_user_connections,(uchar*) uc); } - (void) pthread_mutex_unlock(&LOCK_user_conn); + mysql_mutex_unlock(&LOCK_user_conn); DBUG_VOID_RETURN; } @@ -242,7 +242,7 @@ bool check_mqh(THD *thd, uint check_command) DBUG_ENTER("check_mqh"); DBUG_ASSERT(uc != 0); - (void) pthread_mutex_lock(&LOCK_user_conn); + mysql_mutex_lock(&LOCK_user_conn); time_out_user_resource_limits(thd, uc); @@ -269,7 +269,7 @@ bool check_mqh(THD *thd, uint check_command) } } end: - (void) pthread_mutex_unlock(&LOCK_user_conn); + mysql_mutex_unlock(&LOCK_user_conn); DBUG_RETURN(error); } @@ -330,9 +330,9 @@ check_user(THD *thd, enum enum_server_command command, #else my_bool opt_secure_auth_local; - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); opt_secure_auth_local= opt_secure_auth; - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); /* If the server is running in secure auth mode, short scrambles are @@ -409,10 +409,10 @@ check_user(THD *thd, enum enum_server_command command, if (check_count) { - pthread_mutex_lock(&LOCK_connection_count); + mysql_mutex_lock(&LOCK_connection_count); bool count_ok= connection_count <= max_connections || (thd->main_security_ctx.master_access & SUPER_ACL); - pthread_mutex_unlock(&LOCK_connection_count); + mysql_mutex_unlock(&LOCK_connection_count); if (!count_ok) { // too many connections @@ -557,7 +557,7 @@ void free_max_user_conn(void) void reset_mqh(LEX_USER *lu, bool get_them= 0) { #ifndef NO_EMBEDDED_ACCESS_CHECKS - (void) pthread_mutex_lock(&LOCK_user_conn); + mysql_mutex_lock(&LOCK_user_conn); if (lu) // for GRANT { USER_CONN *uc; @@ -591,7 +591,7 @@ void reset_mqh(LEX_USER *lu, bool get_them= 0) uc->conn_per_hour=0; } } - (void) pthread_mutex_unlock(&LOCK_user_conn); + mysql_mutex_unlock(&LOCK_user_conn); #endif /* NO_EMBEDDED_ACCESS_CHECKS */ } @@ -1107,6 +1107,16 @@ pthread_handler_t handle_one_connection(void *arg) { THD *thd= (THD*) arg; + mysql_thread_set_psi_id(thd->thread_id); + + do_handle_one_connection(thd); + return 0; +} + +void do_handle_one_connection(THD *thd_arg) +{ + THD *thd= thd_arg; + thd->thr_create_utime= my_micro_time(); if (thread_scheduler.init_new_connection_thread()) @@ -1114,7 +1124,7 @@ pthread_handler_t handle_one_connection(void *arg) close_connection(thd, ER_OUT_OF_RESOURCES, 1); statistic_increment(aborted_connects,&LOCK_status); thread_scheduler.end_thread(thd,0); - return 0; + return; } /* @@ -1141,7 +1151,7 @@ pthread_handler_t handle_one_connection(void *arg) */ thd->thread_stack= (char*) &thd; if (setup_connection_thread_globals(thd)) - return 0; + return; for (;;) { @@ -1167,7 +1177,7 @@ pthread_handler_t handle_one_connection(void *arg) end_thread: close_connection(thd, 0, 1); if (thread_scheduler.end_thread(thd,1)) - return 0; // Probably no-threads + return; // Probably no-threads /* If end_thread() returns, we are either running with diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 9368053c658..71ea1a37cdc 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -341,7 +341,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, MY_RETURN_REAL_PATH); #if !defined(__WIN__) && ! defined(__NETWARE__) MY_STAT stat_info; - if (!my_stat(name,&stat_info,MYF(MY_WME))) + if (!mysql_file_stat(key_file_load, name, &stat_info, MYF(MY_WME))) DBUG_RETURN(TRUE); // if we are not in slave thread, the file must be: @@ -394,7 +394,8 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, } } - if ((file=my_open(name,O_RDONLY,MYF(MY_WME))) < 0) + if ((file= mysql_file_open(key_file_load, + name, O_RDONLY, MYF(MY_WME))) < 0) DBUG_RETURN(TRUE); } @@ -412,8 +413,8 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, info.escape_char, read_file_from_client, is_fifo); if (read_info.error) { - if (file >= 0) - my_close(file,MYF(0)); // no files in net reading + if (file >= 0) + mysql_file_close(file, MYF(0)); // no files in net reading DBUG_RETURN(TRUE); // Can't allocate buffers } @@ -484,7 +485,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, table->next_number_field=0; } if (file >= 0) - my_close(file,MYF(0)); + mysql_file_close(file, MYF(0)); free_blobs(table); /* if pack_blob was used */ table->copy_blobs=0; thd->count_cuted_fields= CHECK_FIELD_IGNORE; diff --git a/sql/sql_manager.cc b/sql/sql_manager.cc index b082f65bfb9..4f3e4e1c6d1 100644 --- a/sql/sql_manager.cc +++ b/sql/sql_manager.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000, 2002, 2005 MySQL AB +/* Copyright (C) 2000, 2002, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -28,8 +28,8 @@ static bool volatile manager_thread_in_use; static bool abort_manager; pthread_t manager_thread; -pthread_mutex_t LOCK_manager; -pthread_cond_t COND_manager; +mysql_mutex_t LOCK_manager; +mysql_cond_t COND_manager; struct handler_cb { struct handler_cb *next; @@ -42,7 +42,7 @@ bool mysql_manager_submit(void (*action)()) { bool result= FALSE; struct handler_cb * volatile *cb; - pthread_mutex_lock(&LOCK_manager); + mysql_mutex_lock(&LOCK_manager); cb= &cb_list; while (*cb && (*cb)->action != action) cb= &(*cb)->next; @@ -57,7 +57,7 @@ bool mysql_manager_submit(void (*action)()) (*cb)->action= action; } } - pthread_mutex_unlock(&LOCK_manager); + mysql_mutex_unlock(&LOCK_manager); return result; } @@ -76,7 +76,7 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused))) for (;;) { - pthread_mutex_lock(&LOCK_manager); + mysql_mutex_lock(&LOCK_manager); /* XXX: This will need to be made more general to handle different * polling needs. */ if (flush_time) @@ -87,19 +87,19 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused))) reset_flush_time = FALSE; } while ((!error || error == EINTR) && !abort_manager) - error= pthread_cond_timedwait(&COND_manager, &LOCK_manager, &abstime); + error= mysql_cond_timedwait(&COND_manager, &LOCK_manager, &abstime); } else { while ((!error || error == EINTR) && !abort_manager) - error= pthread_cond_wait(&COND_manager, &LOCK_manager); + error= mysql_cond_wait(&COND_manager, &LOCK_manager); } if (cb == NULL) { cb= cb_list; cb_list= NULL; } - pthread_mutex_unlock(&LOCK_manager); + mysql_mutex_unlock(&LOCK_manager); if (abort_manager) break; @@ -134,7 +134,8 @@ void start_handle_manager() if (flush_time && flush_time != ~(ulong) 0L) { pthread_t hThread; - if (pthread_create(&hThread,&connection_attrib,handle_manager,0)) + if (mysql_thread_create(key_thread_handle_manager, + &hThread, &connection_attrib, handle_manager, 0)) sql_print_warning("Can't create handle_manager thread"); } DBUG_VOID_RETURN; @@ -146,14 +147,14 @@ void stop_handle_manager() { DBUG_ENTER("stop_handle_manager"); abort_manager = true; - pthread_mutex_lock(&LOCK_manager); + mysql_mutex_lock(&LOCK_manager); if (manager_thread_in_use) { DBUG_PRINT("quit", ("initiate shutdown of handle manager thread: 0x%lx", (ulong)manager_thread)); - pthread_cond_signal(&COND_manager); + mysql_cond_signal(&COND_manager); } - pthread_mutex_unlock(&LOCK_manager); + mysql_mutex_unlock(&LOCK_manager); DBUG_VOID_RETURN; } diff --git a/sql/sql_map.cc b/sql/sql_map.cc index 7f77ce1212d..e4e85c51d17 100644 --- a/sql/sql_map.cc +++ b/sql/sql_map.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2004-2005 MySQL AB +/* Copyright (C) 2000-2001, 2004-2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -32,10 +32,10 @@ mapped_files::mapped_files(const char * filename,uchar *magic,uint magic_length) error=0; map=0; size=0; - if ((file=my_open(name,O_RDONLY,MYF(MY_WME))) >= 0) + if ((file= mysql_file_open(key_file_map, name, O_RDONLY, MYF(MY_WME))) >= 0) { struct stat stat_buf; - if (!fstat(file,&stat_buf)) + if (!fstat(file, &stat_buf)) { if (!(map=(uchar*) my_mmap(0,(size_t)(size= stat_buf.st_size),PROT_READ, MAP_SHARED | MAP_NORESERVE,file, @@ -53,7 +53,7 @@ mapped_files::mapped_files(const char * filename,uchar *magic,uint magic_length) } if (!map) { - (void) my_close(file,MYF(0)); + (void) mysql_file_close(file, MYF(0)); file= -1; } } @@ -67,7 +67,7 @@ mapped_files::~mapped_files() if (file >= 0) { (void) my_munmap((char*) map,(size_t)size); - (void) my_close(file,MYF(0)); + (void) mysql_file_close(file, MYF(0)); file= -1; map=0; } my_free(name,MYF(0)); @@ -85,7 +85,7 @@ static I_List<mapped_files> maps_in_use; mapped_files *map_file(const char * name,uchar *magic,uint magic_length) { #ifdef HAVE_MMAP - pthread_mutex_lock(&LOCK_mapped_file); + mysql_mutex_lock(&LOCK_mapped_file); I_List_iterator<mapped_files> list(maps_in_use); mapped_files *map; char path[FN_REFLEN]; @@ -108,7 +108,7 @@ mapped_files *map_file(const char * name,uchar *magic,uint magic_length) if (!map->map) my_error(ER_NO_FILE_MAPPING, MYF(0), path, map->error); } - pthread_mutex_unlock(&LOCK_mapped_file); + mysql_mutex_unlock(&LOCK_mapped_file); return map; #else return NULL; @@ -122,10 +122,10 @@ mapped_files *map_file(const char * name,uchar *magic,uint magic_length) void unmap_file(mapped_files *map) { #ifdef HAVE_MMAP - pthread_mutex_lock(&LOCK_mapped_file); + mysql_mutex_lock(&LOCK_mapped_file); if (!map->use_count--) delete map; - pthread_mutex_unlock(&LOCK_mapped_file); + mysql_mutex_unlock(&LOCK_mapped_file); #endif } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 63a8c17e145..49d18cbe5d7 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -376,15 +376,15 @@ bool is_log_table_write_query(enum enum_sql_command command) } void execute_init_command(THD *thd, LEX_STRING *init_command, - rw_lock_t *var_lock) + mysql_rwlock_t *var_lock) { Vio* save_vio; ulong save_client_capabilities; - rw_rdlock(var_lock); + mysql_rwlock_rdlock(var_lock); if (!init_command->length) { - rw_unlock(var_lock); + mysql_rwlock_unlock(var_lock); return; } @@ -395,7 +395,7 @@ void execute_init_command(THD *thd, LEX_STRING *init_command, */ size_t len= init_command->length; char *buf= thd->strmake(init_command->str, len); - rw_unlock(var_lock); + mysql_rwlock_unlock(var_lock); #if defined(ENABLED_PROFILING) thd->profiling.start_new_query(); @@ -423,7 +423,7 @@ void execute_init_command(THD *thd, LEX_STRING *init_command, static void handle_bootstrap_impl(THD *thd) { - FILE *file=bootstrap_file; + MYSQL_FILE *file= bootstrap_file; char *buff; const char* found_semicolon= NULL; @@ -448,12 +448,12 @@ static void handle_bootstrap_impl(THD *thd) buff= (char*) thd->net.buff; thd->init_for_queries(); - while (fgets(buff, thd->net.max_packet, file)) + while (mysql_file_fgets(buff, thd->net.max_packet, file)) { - char *query, *res; - /* strlen() can't be deleted because fgets() doesn't return length */ + char *query; + /* strlen() can't be deleted because mysql_file_fgets() doesn't return length */ ulong length= (ulong) strlen(buff); - while (buff[length-1] != '\n' && !feof(file)) + while (buff[length-1] != '\n' && !mysql_file_feof(file)) { /* We got only a part of the current string. Will try to increase @@ -467,7 +467,7 @@ static void handle_bootstrap_impl(THD *thd) break; } buff= (char*) thd->net.buff; - res= fgets(buff + length, thd->net.max_packet - length, file); + mysql_file_fgets(buff + length, thd->net.max_packet - length, file); length+= (ulong) strlen(buff + length); /* purecov: end */ } @@ -529,6 +529,14 @@ pthread_handler_t handle_bootstrap(void *arg) { THD *thd=(THD*) arg; + mysql_thread_set_psi_id(thd->thread_id); + + do_handle_bootstrap(thd); + return 0; +} + +void do_handle_bootstrap(THD *thd) +{ /* The following must be called before DBUG_ENTER */ thd->thread_stack= (char*) &thd; if (my_thread_init() || thd->store_globals()) @@ -557,7 +565,7 @@ end: pthread_exit(0); #endif - return 0; + return; } @@ -1225,8 +1233,10 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (lower_case_table_names) my_casedn_str(files_charset_info, table_list.table_name); - if (check_access(thd,SELECT_ACL,table_list.db,&table_list.grant.privilege, - 0, 0, test(table_list.schema_table))) + if (check_access(thd, SELECT_ACL, table_list.db, + &table_list.grant.privilege, + &table_list.grant.m_internal, + 0, 0)) break; if (check_grant(thd, SELECT_ACL, &table_list, TRUE, UINT_MAX, FALSE)) break; @@ -2113,7 +2123,7 @@ mysql_execute_command(THD *thd) privileges_requested, all_tables, FALSE, UINT_MAX, FALSE); else - res= check_access(thd, privileges_requested, any_db, 0, 0, 0, 0); + res= check_access(thd, privileges_requested, any_db, NULL, NULL, 0, 0); if (res) break; @@ -2253,8 +2263,9 @@ case SQLCOM_PREPARE: { DBUG_ASSERT(first_table == all_tables && first_table != 0); if (check_access(thd, INDEX_ACL, first_table->db, - &first_table->grant.privilege, 0, 0, - test(first_table->schema_table))) + &first_table->grant.privilege, + &first_table->grant.m_internal, + 0, 0)) goto error; res= mysql_assign_to_keycache(thd, first_table, &lex->ident); break; @@ -2263,8 +2274,9 @@ case SQLCOM_PREPARE: { DBUG_ASSERT(first_table == all_tables && first_table != 0); if (check_access(thd, INDEX_ACL, first_table->db, - &first_table->grant.privilege, 0, 0, - test(first_table->schema_table))) + &first_table->grant.privilege, + &first_table->grant.m_internal, + 0, 0)) goto error; res = mysql_preload_keys(thd, first_table); break; @@ -2274,9 +2286,9 @@ case SQLCOM_PREPARE: { if (check_global_access(thd, SUPER_ACL)) goto error; - pthread_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&LOCK_active_mi); res = change_master(thd,active_mi); - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&LOCK_active_mi); break; } case SQLCOM_SHOW_SLAVE_STAT: @@ -2284,7 +2296,7 @@ case SQLCOM_PREPARE: /* Accept one of two privileges */ if (check_global_access(thd, SUPER_ACL | REPL_CLIENT_ACL)) goto error; - pthread_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&LOCK_active_mi); if (active_mi != NULL) { res = show_master_info(thd, active_mi); @@ -2295,7 +2307,7 @@ case SQLCOM_PREPARE: WARN_NO_MASTER_INFO, ER(WARN_NO_MASTER_INFO)); my_ok(thd); } - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&LOCK_active_mi); break; } case SQLCOM_SHOW_MASTER_STAT: @@ -2607,9 +2619,9 @@ end_with_restore_list: #ifdef HAVE_REPLICATION case SQLCOM_SLAVE_START: { - pthread_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&LOCK_active_mi); start_slave(thd,active_mi,1 /* net report*/); - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&LOCK_active_mi); break; } case SQLCOM_SLAVE_STOP: @@ -2633,9 +2645,9 @@ end_with_restore_list: goto error; } { - pthread_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&LOCK_active_mi); stop_slave(thd,active_mi,1/* net report*/); - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&LOCK_active_mi); break; } #endif /* HAVE_REPLICATION */ @@ -2666,10 +2678,13 @@ end_with_restore_list: /* Must be set in the parser */ DBUG_ASSERT(select_lex->db); if (check_access(thd, priv_needed, first_table->db, - &first_table->grant.privilege, 0, 0, - test(first_table->schema_table)) || - check_access(thd,INSERT_ACL | CREATE_ACL,select_lex->db,&priv,0,0, - is_schema_db(select_lex->db))|| + &first_table->grant.privilege, + &first_table->grant.m_internal, + 0, 0) || + check_access(thd, INSERT_ACL | CREATE_ACL, select_lex->db, + &priv, + NULL, /* Do not use first_table->grant with select_lex->db */ + 0, 0) || check_merge_table_access(thd, first_table->db, (TABLE_LIST *) create_info.merge_list.first)) @@ -2726,10 +2741,13 @@ end_with_restore_list: for (table= first_table; table; table= table->next_local->next_local) { if (check_access(thd, ALTER_ACL | DROP_ACL, table->db, - &table->grant.privilege,0,0, test(table->schema_table)) || - check_access(thd, INSERT_ACL | CREATE_ACL, table->next_local->db, - &table->next_local->grant.privilege, 0, 0, - test(table->next_local->schema_table))) + &table->grant.privilege, + &table->grant.m_internal, + 0, 0) || + check_access(thd, INSERT_ACL | CREATE_ACL, table->next_local->db, + &table->next_local->grant.privilege, + &table->next_local->grant.m_internal, + 0, 0)) goto error; TABLE_LIST old_list, new_list; /* @@ -2797,42 +2815,13 @@ end_with_restore_list: } else { - ulong save_priv; - - /* - If it is an INFORMATION_SCHEMA table, SELECT_ACL privilege is the - only privilege allowed. For any other privilege check_access() - reports an error. That's how internal implementation protects - INFORMATION_SCHEMA from updates. - - For ordinary tables any privilege from the SHOW_CREATE_TABLE_ACLS - set is sufficient. - */ - - ulong check_privs= test(first_table->schema_table) ? - SELECT_ACL : SHOW_CREATE_TABLE_ACLS; - - if (check_access(thd, check_privs, first_table->db, - &save_priv, FALSE, FALSE, - test(first_table->schema_table))) - goto error; - /* - save_priv contains any privileges actually granted by check_access - (i.e. save_priv contains global (user- and database-level) - privileges). - - The fact that check_access() returned FALSE does not mean that - access is granted. We need to check if save_priv contains any - table-specific privilege. If not, we need to check table-level - privileges. - - If there are no global privileges and no table-level privileges, - access is denied. + The fact that check_some_access() returned FALSE does not mean that + access is granted. We need to check if first_table->grant.privilege + contains any table-specific privilege. */ - - if (!(save_priv & (SHOW_CREATE_TABLE_ACLS)) && - !has_any_table_level_privileges(thd, SHOW_CREATE_TABLE_ACLS, first_table)) + if (check_some_access(thd, SHOW_CREATE_TABLE_ACLS, first_table) || + (first_table->grant.privilege & SHOW_CREATE_TABLE_ACLS) == 0) { my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0), "SHOW", thd->security_ctx->priv_user, @@ -3338,7 +3327,7 @@ end_with_restore_list: goto error; #else { - if (check_access(thd, FILE_ACL, any_db,0,0,0,0)) + if (check_access(thd, FILE_ACL, any_db, NULL, NULL, 0, 0)) goto error; res= ha_show_status(thd, lex->create_info.db_type, HA_ENGINE_LOGS); break; @@ -3507,8 +3496,7 @@ end_with_restore_list: break; } #endif - if (check_access(thd,CREATE_ACL,lex->name.str, 0, 1, 0, - is_schema_db(lex->name.str))) + if (check_access(thd, CREATE_ACL, lex->name.str, NULL, NULL, 1, 0)) break; res= mysql_create_db(thd,(lower_case_table_names == 2 ? alias : lex->name.str), &create_info, 0); @@ -3542,8 +3530,7 @@ end_with_restore_list: break; } #endif - if (check_access(thd,DROP_ACL,lex->name.str,0,1,0, - is_schema_db(lex->name.str))) + if (check_access(thd, DROP_ACL, lex->name.str, NULL, NULL, 1, 0)) break; if (thd->locked_tables || thd->active_transaction()) { @@ -3577,9 +3564,9 @@ end_with_restore_list: my_error(ER_WRONG_DB_NAME, MYF(0), db->str); break; } - if (check_access(thd, ALTER_ACL, db->str, 0, 1, 0, is_schema_db(db->str)) || - check_access(thd, DROP_ACL, db->str, 0, 1, 0, is_schema_db(db->str)) || - check_access(thd, CREATE_ACL, db->str, 0, 1, 0, is_schema_db(db->str))) + if (check_access(thd, ALTER_ACL, db->str, NULL, NULL, 1, 0) || + check_access(thd, DROP_ACL, db->str, NULL, NULL, 1, 0) || + check_access(thd, CREATE_ACL, db->str, NULL, NULL, 1, 0)) { res= 1; break; @@ -3622,7 +3609,7 @@ end_with_restore_list: break; } #endif - if (check_access(thd, ALTER_ACL, db->str, 0, 1, 0, is_schema_db(db->str))) + if (check_access(thd, ALTER_ACL, db->str, NULL, NULL, 1, 0)) break; if (thd->locked_tables || thd->active_transaction()) { @@ -3707,7 +3694,7 @@ end_with_restore_list: #endif case SQLCOM_CREATE_FUNCTION: // UDF function { - if (check_access(thd,INSERT_ACL,"mysql",0,1,0,0)) + if (check_access(thd, INSERT_ACL, "mysql", NULL, NULL, 1, 0)) break; #ifdef HAVE_DLOPEN if (!(res = mysql_create_function(thd, &lex->udf))) @@ -3721,7 +3708,7 @@ end_with_restore_list: #ifndef NO_EMBEDDED_ACCESS_CHECKS case SQLCOM_CREATE_USER: { - if (check_access(thd, INSERT_ACL, "mysql", 0, 1, 1, 0) && + if (check_access(thd, INSERT_ACL, "mysql", NULL, NULL, 1, 1) && check_global_access(thd,CREATE_USER_ACL)) break; if (end_active_trans(thd)) @@ -3733,7 +3720,7 @@ end_with_restore_list: } case SQLCOM_DROP_USER: { - if (check_access(thd, DELETE_ACL, "mysql", 0, 1, 1, 0) && + if (check_access(thd, DELETE_ACL, "mysql", NULL, NULL, 1, 1) && check_global_access(thd,CREATE_USER_ACL)) break; if (end_active_trans(thd)) @@ -3745,7 +3732,7 @@ end_with_restore_list: } case SQLCOM_RENAME_USER: { - if (check_access(thd, UPDATE_ACL, "mysql", 0, 1, 1, 0) && + if (check_access(thd, UPDATE_ACL, "mysql", NULL, NULL, 1, 1) && check_global_access(thd,CREATE_USER_ACL)) break; if (end_active_trans(thd)) @@ -3759,7 +3746,7 @@ end_with_restore_list: { if (end_active_trans(thd)) goto error; - if (check_access(thd, UPDATE_ACL, "mysql", 0, 1, 1, 0) && + if (check_access(thd, UPDATE_ACL, "mysql", NULL, NULL, 1, 1) && check_global_access(thd,CREATE_USER_ACL)) break; /* Conditionally writes to binlog */ @@ -3774,11 +3761,10 @@ end_with_restore_list: goto error; if (check_access(thd, lex->grant | lex->grant_tot_col | GRANT_ACL, - first_table ? first_table->db : select_lex->db, - first_table ? &first_table->grant.privilege : 0, - first_table ? 0 : 1, 0, - first_table ? (bool) first_table->schema_table : - select_lex->db ? is_schema_db(select_lex->db) : 0)) + first_table ? first_table->db : select_lex->db, + first_table ? &first_table->grant.privilege : NULL, + first_table ? &first_table->grant.m_internal : NULL, + first_table ? 0 : 1, 0)) goto error; if (thd->security_ctx->user) // If not replication @@ -3805,7 +3791,7 @@ end_with_restore_list: // TODO: use check_change_password() if (is_acl_user(user->host.str, user->user.str) && user->password.str && - check_access(thd, UPDATE_ACL,"mysql",0,1,1,0)) + check_access(thd, UPDATE_ACL, "mysql", NULL, NULL, 1, 1)) { my_message(ER_PASSWORD_NOT_ALLOWED, ER(ER_PASSWORD_NOT_ALLOWED), MYF(0)); @@ -3937,7 +3923,7 @@ end_with_restore_list: goto error; if ((thd->security_ctx->priv_user && !strcmp(thd->security_ctx->priv_user, grant_user->user.str)) || - !check_access(thd, SELECT_ACL, "mysql",0,1,0,0)) + !check_access(thd, SELECT_ACL, "mysql", NULL, NULL, 1, 0)) { res = mysql_show_grants(thd, grant_user); } @@ -4121,8 +4107,8 @@ end_with_restore_list: goto create_sp_error; } - if (check_access(thd, CREATE_PROC_ACL, lex->sphead->m_db.str, 0, 0, 0, - is_schema_db(lex->sphead->m_db.str))) + if (check_access(thd, CREATE_PROC_ACL, lex->sphead->m_db.str, + NULL, NULL, 0, 0)) goto create_sp_error; if (end_active_trans(thd)) @@ -4447,7 +4433,7 @@ create_sp_error: lex->spname->m_name.length); if (udf) { - if (check_access(thd, DELETE_ACL, "mysql", 0, 1, 0, 0)) + if (check_access(thd, DELETE_ACL, "mysql", NULL, NULL, 1, 0)) goto error; if (!(res = mysql_drop_function(thd, &lex->spname->m_name))) @@ -5006,8 +4992,9 @@ bool check_single_table_access(THD *thd, ulong privilege, db_name= all_tables->db; if (check_access(thd, privilege, db_name, - &all_tables->grant.privilege, 0, no_errors, - test(all_tables->schema_table))) + &all_tables->grant.privilege, + &all_tables->grant.m_internal, + 0, no_errors)) goto deny; /* Show only 1 table for check_grant */ @@ -5073,17 +5060,17 @@ bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *all_tables) @param want_access The requested access privileges. @param db A pointer to the Db name. @param[out] save_priv A pointer to the granted privileges will be stored. + @param grant_internal_info A pointer to the internal grant cache. @param dont_check_global_grants True if no global grants are checked. @param no_error True if no errors should be sent to the client. - @param schema_db True if the db specified belongs to the meta data tables. 'save_priv' is used to save the User-table (global) and Db-table grants for the supplied db name. Note that we don't store db level grants if the global grants is enough to satisfy the request AND the global grants contains a SELECT grant. - A meta data table (from INFORMATION_SCHEMA) can always be accessed with - a SELECT_ACL. + For internal databases (INFORMATION_SCHEMA, PERFORMANCE_SCHEMA), + additional rules apply, see ACL_internal_schema_access. @see check_grant @@ -5095,7 +5082,8 @@ bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *all_tables) bool check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, - bool dont_check_global_grants, bool no_errors, bool schema_db) + GRANT_INTERNAL_INFO *grant_internal_info, + bool dont_check_global_grants, bool no_errors) { Security_context *sctx= thd->security_ctx; ulong db_access; @@ -5118,7 +5106,10 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, if (save_priv) *save_priv=0; else + { save_priv= &dummy; + dummy= 0; + } thd_proc_info(thd, "checking permissions"); if ((!db || !db[0]) && !thd->db && !dont_check_global_grants) @@ -5130,55 +5121,65 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, DBUG_RETURN(TRUE); /* purecov: tested */ } - if (schema_db) + if ((db != NULL) && (db != any_db)) { - /* - We don't allow any simple privileges but SELECT_ACL or CREATE_VIEW_ACL - on the information_schema database. - */ - want_access &= ~SELECT_ACL; - if (want_access & DB_ACLS) + const ACL_internal_schema_access *access; + access= get_cached_schema_access(grant_internal_info, db); + if (access) { - if (!no_errors) + switch (access->check(want_access, save_priv)) { - const char *db_name= db ? db : thd->db; - my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), - sctx->priv_user, sctx->priv_host, db_name); + case ACL_INTERNAL_ACCESS_GRANTED: + /* + All the privileges requested have been granted internally. + [out] *save_privileges= Internal privileges. + */ + DBUG_RETURN(FALSE); + case ACL_INTERNAL_ACCESS_DENIED: + if (! no_errors) + { + my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), + sctx->priv_user, sctx->priv_host, db); + } + DBUG_RETURN(TRUE); + case ACL_INTERNAL_ACCESS_CHECK_GRANT: + /* + Only some of the privilege requested have been granted internally, + proceed with the remaining bits of the request (want_access). + */ + want_access&= ~(*save_priv); + break; } - /* - Access denied; - [out] *save_privileges= 0 - */ - DBUG_RETURN(TRUE); - } - else - { - /* Access granted */ - *save_priv= SELECT_ACL; - DBUG_RETURN(FALSE); } } if ((sctx->master_access & want_access) == want_access) { - /* get access for current db */ - db_access= sctx->db_access; /* 1. If we don't have a global SELECT privilege, we have to get the database specific access rights to be able to handle queries of type UPDATE t1 SET a=1 WHERE b > 0 2. Change db access if it isn't current db which is being addressed */ - if (!(sctx->master_access & SELECT_ACL) && - (db && (!thd->db || db_is_pattern || strcmp(db,thd->db)))) - db_access=acl_get(sctx->host, sctx->ip, sctx->priv_user, db, - db_is_pattern); - - /* - The effective privileges are the union of the global privileges - and the the intersection of db- and host-privileges. - */ - *save_priv=sctx->master_access | db_access; + if (!(sctx->master_access & SELECT_ACL)) + { + if (db && (!thd->db || db_is_pattern || strcmp(db, thd->db))) + db_access= acl_get(sctx->host, sctx->ip, sctx->priv_user, db, + db_is_pattern); + else + { + /* get access for current db */ + db_access= sctx->db_access; + } + /* + The effective privileges are the union of the global privileges + and the intersection of db- and host-privileges, + plus the internal privileges. + */ + *save_priv|= sctx->master_access | db_access; + } + else + *save_priv|= sctx->master_access; DBUG_RETURN(FALSE); } if (((want_access & ~sctx->master_access) & ~DB_ACLS) || @@ -5214,10 +5215,10 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, /* Save the union of User-table and the intersection between Db-table and - Host-table privileges. + Host-table privileges, with the already saved internal privileges. */ db_access= (db_access | sctx->master_access); - *save_priv= db_access; + *save_priv|= db_access; /* We need to investigate column- and table access if all requested privileges @@ -5238,14 +5239,14 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, { /* Ok; but need to check table- and column privileges. - [out] *save_privileges is (User-priv | (Db-priv & Host-priv)) + [out] *save_privileges is (User-priv | (Db-priv & Host-priv) | Internal-priv) */ DBUG_RETURN(FALSE); } /* Access is denied; - [out] *save_privileges is (User-priv | (Db-priv & Host-priv)) + [out] *save_privileges is (User-priv | (Db-priv & Host-priv) | Internal-priv) */ DBUG_PRINT("error",("Access denied")); if (!no_errors) @@ -5261,6 +5262,18 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, static bool check_show_access(THD *thd, TABLE_LIST *table) { + /* + This is a SHOW command using an INFORMATION_SCHEMA table. + check_access() has not been called for 'table', + and SELECT is currently always granted on the I_S, so we automatically + grant SELECT on table here, to bypass a call to check_access(). + Note that not calling check_access(table) is an optimization, + which needs to be revisited if the INFORMATION_SCHEMA does + not always automatically grant SELECT but use the grant tables. + See Bug#38837 need a way to disable information_schema for security + */ + table->grant.privilege= SELECT_ACL; + switch (get_schema_table_idx(table->schema_table)) { case SCH_SCHEMATA: return (specialflag & SPECIAL_SKIP_SHOW_DB) && @@ -5277,8 +5290,7 @@ static bool check_show_access(THD *thd, TABLE_LIST *table) DBUG_ASSERT(dst_db_name); if (check_access(thd, SELECT_ACL, dst_db_name, - &thd->col_access, FALSE, FALSE, - is_schema_db(dst_db_name))) + &thd->col_access, NULL, FALSE, FALSE)) return TRUE; if (!thd->col_access && check_grant_db(thd, dst_db_name)) @@ -5302,8 +5314,9 @@ static bool check_show_access(THD *thd, TABLE_LIST *table) DBUG_ASSERT(dst_table); if (check_access(thd, SELECT_ACL, dst_table->db, - &dst_table->grant.privilege, FALSE, FALSE, - test(dst_table->schema_table))) + &dst_table->grant.privilege, + &dst_table->grant.m_internal, + FALSE, FALSE)) return TRUE; /* Access denied */ /* @@ -5384,23 +5397,6 @@ check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables, sctx= backup_ctx; /* - Always allow SELECT on schema tables. This is done by removing the - required SELECT_ACL privilege in the want_access parameter. - Disallow any other DDL or DML operation on any schema table. - */ - if (tables->schema_table) - { - want_access &= ~SELECT_ACL; - if (want_access & DB_ACLS) - { - if (!no_errors) - my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), - sctx->priv_user, sctx->priv_host, - INFORMATION_SCHEMA_NAME.str); - goto deny; - } - } - /* Register access for view underlying table. Remove SHOW_VIEW_ACL, because it will be checked during making view */ @@ -5420,18 +5416,11 @@ check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables, (int)tables->table->s->tmp_table)) continue; thd->security_ctx= sctx; - if ((sctx->master_access & want_access) == want_access && - thd->db) - tables->grant.privilege= want_access; - else if (tables->db && thd->db && strcmp(tables->db, thd->db) == 0) - { - if (check_access(thd, want_access, tables->get_db_name(), - &tables->grant.privilege, 0, no_errors, - test(tables->schema_table))) - goto deny; // Access denied - } - else if (check_access(thd, want_access, tables->get_db_name(), - &tables->grant.privilege, 0, no_errors, 0)) + + if (check_access(thd, want_access, tables->get_db_name(), + &tables->grant.privilege, + &tables->grant.m_internal, + 0, no_errors)) goto deny; } thd->security_ctx= backup_ctx; @@ -5459,11 +5448,20 @@ check_routine_access(THD *thd, ulong want_access,char *db, char *name, calculating db_access) under the assumption that it's common to give persons global right to execute all stored SP (but not necessary to create them). + Note that this effectively bypasses the ACL_internal_schema_access checks + that are implemented for the INFORMATION_SCHEMA and PERFORMANCE_SCHEMA, + which are located in check_access(). + Since the I_S and P_S do not contain routines, this bypass is ok, + as long as this code path is not abused to create routines. + The assert enforce that. */ + DBUG_ASSERT((want_access & CREATE_PROC_ACL) == 0); if ((thd->security_ctx->master_access & want_access) == want_access) tables->grant.privilege= want_access; - else if (check_access(thd,want_access,db,&tables->grant.privilege, - 0, no_errors, 0)) + else if (check_access(thd, want_access, db, + &tables->grant.privilege, + &tables->grant.m_internal, + 0, no_errors)) return TRUE; return check_grant_routine(thd, want_access, tables, is_proc, no_errors); @@ -5487,13 +5485,18 @@ bool check_some_routine_access(THD *thd, const char *db, const char *name, bool is_proc) { ulong save_priv; - if (thd->security_ctx->master_access & SHOW_PROC_ACLS) - return FALSE; /* - There are no routines in information_schema db. So we can safely - pass zero to last paramter of check_access function + The following test is just a shortcut for check_access() (to avoid + calculating db_access) + Note that this effectively bypasses the ACL_internal_schema_access checks + that are implemented for the INFORMATION_SCHEMA and PERFORMANCE_SCHEMA, + which are located in check_access(). + Since the I_S and P_S do not contain routines, this bypass is ok, + as it only opens SHOW_PROC_ACLS. */ - if (!check_access(thd, SHOW_PROC_ACLS, db, &save_priv, 0, 1, 0) || + if (thd->security_ctx->master_access & SHOW_PROC_ACLS) + return FALSE; + if (!check_access(thd, SHOW_PROC_ACLS, db, &save_priv, NULL, 0, 1) || (save_priv & SHOW_PROC_ACLS)) return FALSE; return check_routine_level_acl(thd, db, name, is_proc); @@ -5523,8 +5526,9 @@ bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table) if (access & want_access) { if (!check_access(thd, access, table->db, - &table->grant.privilege, 0, 1, - test(table->schema_table)) && + &table->grant.privilege, + &table->grant.m_internal, + 0, 1) && !check_grant(thd, access, table, FALSE, 1, TRUE)) DBUG_RETURN(0); } @@ -6864,9 +6868,9 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, mysql_bin_log.rotate_and_purge(RP_FORCE_ROTATE); } #ifdef HAVE_REPLICATION - pthread_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&LOCK_active_mi); rotate_relay_log(active_mi); - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&LOCK_active_mi); #endif /* flush slow and general logs */ @@ -6969,10 +6973,10 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, if (options & REFRESH_SLAVE) { tmp_write_to_binlog= 0; - pthread_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&LOCK_active_mi); if (reset_slave(thd, active_mi)) result=1; - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&LOCK_active_mi); } #endif if (options & REFRESH_USER_RESOURCES) @@ -7007,7 +7011,7 @@ uint kill_one_thread(THD *thd, ulong id, bool only_kill_query) continue; if (tmp->thread_id == id) { - pthread_mutex_lock(&tmp->LOCK_thd_data); // Lock from delete + mysql_mutex_lock(&tmp->LOCK_thd_data); // Lock from delete break; } } @@ -7040,7 +7044,7 @@ uint kill_one_thread(THD *thd, ulong id, bool only_kill_query) } else error=ER_KILL_DENIED_ERROR; - pthread_mutex_unlock(&tmp->LOCK_thd_data); + mysql_mutex_unlock(&tmp->LOCK_thd_data); } DBUG_PRINT("exit", ("%d", error)); DBUG_RETURN(error); @@ -7221,12 +7225,14 @@ bool multi_update_precheck(THD *thd, TABLE_LIST *tables) if (table->derived) table->grant.privilege= SELECT_ACL; else if ((check_access(thd, UPDATE_ACL, table->db, - &table->grant.privilege, 0, 1, - test(table->schema_table)) || + &table->grant.privilege, + &table->grant.m_internal, + 0, 1) || check_grant(thd, UPDATE_ACL, table, FALSE, 1, TRUE)) && (check_access(thd, SELECT_ACL, table->db, - &table->grant.privilege, 0, 0, - test(table->schema_table)) || + &table->grant.privilege, + &table->grant.m_internal, + 0, 0) || check_grant(thd, SELECT_ACL, table, FALSE, 1, FALSE))) DBUG_RETURN(TRUE); @@ -7243,8 +7249,9 @@ bool multi_update_precheck(THD *thd, TABLE_LIST *tables) if (!table->table_in_first_from_clause) { if (check_access(thd, SELECT_ACL, table->db, - &table->grant.privilege, 0, 0, - test(table->schema_table)) || + &table->grant.privilege, + &table->grant.m_internal, + 0, 0) || check_grant(thd, SELECT_ACL, table, FALSE, 1, FALSE)) DBUG_RETURN(TRUE); } @@ -7525,8 +7532,9 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables, (select_lex->item_list.elements ? INSERT_ACL : 0); if (check_access(thd, want_priv, create_table->db, - &create_table->grant.privilege, 0, 0, - test(create_table->schema_table)) || + &create_table->grant.privilege, + &create_table->grant.m_internal, + 0, 0) || check_merge_table_access(thd, create_table->db, (TABLE_LIST *) lex->create_info.merge_list.first)) diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index a5ae5d24796..91cf0333fb5 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -1880,7 +1880,7 @@ end: static int add_write(File fptr, const char *buf, uint len) { - uint ret_code= my_write(fptr, (const uchar*)buf, len, MYF(MY_FNABP)); + uint ret_code= mysql_file_write(fptr, (const uchar*)buf, len, MYF(MY_FNABP)); if (likely(ret_code == 0)) return 0; @@ -2592,10 +2592,11 @@ char *generate_partition_syntax(partition_info *part_info, } if (err) goto close_file; - buffer_length= my_seek(fptr, 0L,MY_SEEK_END,MYF(0)); + buffer_length= mysql_file_seek(fptr, 0L, MY_SEEK_END, MYF(0)); if (unlikely(buffer_length == MY_FILEPOS_ERROR)) goto close_file; - if (unlikely(my_seek(fptr, 0L, MY_SEEK_SET, MYF(0)) == MY_FILEPOS_ERROR)) + if (unlikely(mysql_file_seek(fptr, 0L, MY_SEEK_SET, MYF(0)) + == MY_FILEPOS_ERROR)) goto close_file; *buf_length= (uint)buffer_length; if (use_sql_alloc) @@ -2605,7 +2606,7 @@ char *generate_partition_syntax(partition_info *part_info, if (!buf) goto close_file; - if (unlikely(my_read(fptr, (uchar*)buf, *buf_length, MYF(MY_FNABP)))) + if (unlikely(mysql_file_read(fptr, (uchar*)buf, *buf_length, MYF(MY_FNABP)))) { if (!use_sql_alloc) my_free(buf, MYF(0)); @@ -2616,7 +2617,7 @@ char *generate_partition_syntax(partition_info *part_info, buf[*buf_length]= 0; close_file: - my_close(fptr, MYF(0)); + mysql_file_close(fptr, MYF(0)); DBUG_RETURN(buf); } @@ -5962,7 +5963,7 @@ static bool write_log_drop_shadow_frm(ALTER_PARTITION_PARAM_TYPE *lpt) DBUG_ENTER("write_log_drop_shadow_frm"); build_table_shadow_filename(shadow_path, sizeof(shadow_path) - 1, lpt); - pthread_mutex_lock(&LOCK_gdl); + mysql_mutex_lock(&LOCK_gdl); if (write_log_replace_delete_frm(lpt, 0UL, NULL, (const char*)shadow_path, FALSE)) goto error; @@ -5970,13 +5971,13 @@ static bool write_log_drop_shadow_frm(ALTER_PARTITION_PARAM_TYPE *lpt) if (write_execute_ddl_log_entry(log_entry->entry_pos, FALSE, &exec_log_entry)) goto error; - pthread_mutex_unlock(&LOCK_gdl); + mysql_mutex_unlock(&LOCK_gdl); set_part_info_exec_log_entry(part_info, exec_log_entry); DBUG_RETURN(FALSE); error: release_part_info_log_entries(part_info->first_log_entry); - pthread_mutex_unlock(&LOCK_gdl); + mysql_mutex_unlock(&LOCK_gdl); part_info->first_log_entry= NULL; my_error(ER_DDL_LOG_ERROR, MYF(0)); DBUG_RETURN(TRUE); @@ -6010,7 +6011,7 @@ static bool write_log_rename_frm(ALTER_PARTITION_PARAM_TYPE *lpt) build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0); build_table_shadow_filename(shadow_path, sizeof(shadow_path) - 1, lpt); - pthread_mutex_lock(&LOCK_gdl); + mysql_mutex_lock(&LOCK_gdl); if (write_log_replace_delete_frm(lpt, 0UL, shadow_path, path, TRUE)) goto error; log_entry= part_info->first_log_entry; @@ -6019,12 +6020,12 @@ static bool write_log_rename_frm(ALTER_PARTITION_PARAM_TYPE *lpt) FALSE, &exec_log_entry)) goto error; release_part_info_log_entries(old_first_log_entry); - pthread_mutex_unlock(&LOCK_gdl); + mysql_mutex_unlock(&LOCK_gdl); DBUG_RETURN(FALSE); error: release_part_info_log_entries(part_info->first_log_entry); - pthread_mutex_unlock(&LOCK_gdl); + mysql_mutex_unlock(&LOCK_gdl); part_info->first_log_entry= old_first_log_entry; part_info->frm_log_entry= NULL; my_error(ER_DDL_LOG_ERROR, MYF(0)); @@ -6063,7 +6064,7 @@ static bool write_log_drop_partition(ALTER_PARTITION_PARAM_TYPE *lpt) lpt->table_name, "", 0); build_table_filename(tmp_path, sizeof(tmp_path) - 1, lpt->db, lpt->table_name, "#", 0); - pthread_mutex_lock(&LOCK_gdl); + mysql_mutex_lock(&LOCK_gdl); if (write_log_dropped_partitions(lpt, &next_entry, (const char*)path, FALSE)) goto error; @@ -6076,12 +6077,12 @@ static bool write_log_drop_partition(ALTER_PARTITION_PARAM_TYPE *lpt) FALSE, &exec_log_entry)) goto error; release_part_info_log_entries(old_first_log_entry); - pthread_mutex_unlock(&LOCK_gdl); + mysql_mutex_unlock(&LOCK_gdl); DBUG_RETURN(FALSE); error: release_part_info_log_entries(part_info->first_log_entry); - pthread_mutex_unlock(&LOCK_gdl); + mysql_mutex_unlock(&LOCK_gdl); part_info->first_log_entry= old_first_log_entry; part_info->frm_log_entry= NULL; my_error(ER_DDL_LOG_ERROR, MYF(0)); @@ -6120,7 +6121,7 @@ static bool write_log_add_change_partition(ALTER_PARTITION_PARAM_TYPE *lpt) lpt->table_name, "", 0); build_table_filename(tmp_path, sizeof(tmp_path) - 1, lpt->db, lpt->table_name, "#", 0); - pthread_mutex_lock(&LOCK_gdl); + mysql_mutex_lock(&LOCK_gdl); if (write_log_dropped_partitions(lpt, &next_entry, (const char*)path, FALSE)) goto error; @@ -6131,13 +6132,13 @@ static bool write_log_add_change_partition(ALTER_PARTITION_PARAM_TYPE *lpt) if (write_execute_ddl_log_entry(log_entry->entry_pos, FALSE, &exec_log_entry)) goto error; - pthread_mutex_unlock(&LOCK_gdl); + mysql_mutex_unlock(&LOCK_gdl); set_part_info_exec_log_entry(part_info, exec_log_entry); DBUG_RETURN(FALSE); error: release_part_info_log_entries(part_info->first_log_entry); - pthread_mutex_unlock(&LOCK_gdl); + mysql_mutex_unlock(&LOCK_gdl); part_info->first_log_entry= NULL; my_error(ER_DDL_LOG_ERROR, MYF(0)); DBUG_RETURN(TRUE); @@ -6175,7 +6176,7 @@ static bool write_log_final_change_partition(ALTER_PARTITION_PARAM_TYPE *lpt) build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0); build_table_shadow_filename(shadow_path, sizeof(shadow_path) - 1, lpt); - pthread_mutex_lock(&LOCK_gdl); + mysql_mutex_lock(&LOCK_gdl); if (write_log_dropped_partitions(lpt, &next_entry, (const char*)path, lpt->alter_info->flags & ALTER_REORGANIZE_PARTITION)) goto error; @@ -6189,12 +6190,12 @@ static bool write_log_final_change_partition(ALTER_PARTITION_PARAM_TYPE *lpt) FALSE, &exec_log_entry)) goto error; release_part_info_log_entries(old_first_log_entry); - pthread_mutex_unlock(&LOCK_gdl); + mysql_mutex_unlock(&LOCK_gdl); DBUG_RETURN(FALSE); error: release_part_info_log_entries(part_info->first_log_entry); - pthread_mutex_unlock(&LOCK_gdl); + mysql_mutex_unlock(&LOCK_gdl); part_info->first_log_entry= old_first_log_entry; part_info->frm_log_entry= NULL; my_error(ER_DDL_LOG_ERROR, MYF(0)); @@ -6221,7 +6222,7 @@ static void write_log_completed(ALTER_PARTITION_PARAM_TYPE *lpt, DBUG_ENTER("write_log_completed"); DBUG_ASSERT(log_entry); - pthread_mutex_lock(&LOCK_gdl); + mysql_mutex_lock(&LOCK_gdl); if (write_execute_ddl_log_entry(0UL, TRUE, &log_entry)) { /* @@ -6235,7 +6236,7 @@ static void write_log_completed(ALTER_PARTITION_PARAM_TYPE *lpt, } release_part_info_log_entries(part_info->first_log_entry); release_part_info_log_entries(part_info->exec_log_entry); - pthread_mutex_unlock(&LOCK_gdl); + mysql_mutex_unlock(&LOCK_gdl); part_info->exec_log_entry= NULL; part_info->first_log_entry= NULL; DBUG_VOID_RETURN; @@ -6253,10 +6254,10 @@ static void write_log_completed(ALTER_PARTITION_PARAM_TYPE *lpt, static void release_log_entries(partition_info *part_info) { - pthread_mutex_lock(&LOCK_gdl); + mysql_mutex_lock(&LOCK_gdl); release_part_info_log_entries(part_info->first_log_entry); release_part_info_log_entries(part_info->exec_log_entry); - pthread_mutex_unlock(&LOCK_gdl); + mysql_mutex_unlock(&LOCK_gdl); part_info->first_log_entry= NULL; part_info->exec_log_entry= NULL; } diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index c5f737434be..0a7864631ae 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -109,7 +109,7 @@ static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= following variables/structures. We are always manipulating ref count, so a rwlock here is unneccessary. */ -pthread_mutex_t LOCK_plugin; +mysql_mutex_t LOCK_plugin; static DYNAMIC_ARRAY plugin_dl_array; static DYNAMIC_ARRAY plugin_array; static HASH plugin_hash[MYSQL_MAX_PLUGIN_TYPE_NUM]; @@ -196,7 +196,7 @@ public: (plugin_var_arg->flags & PLUGIN_VAR_THDLOCAL ? SESSION : GLOBAL) | (plugin_var_arg->flags & PLUGIN_VAR_READONLY ? READONLY : 0), 0, -1, NO_ARG, pluginvar_show_type(plugin_var_arg), 0, 0, - VARIABLE_NOT_IN_BINLOG, 0, 0, 0, 0), + VARIABLE_NOT_IN_BINLOG, 0, 0, 0, 0, PARSE_NORMAL), plugin_var(plugin_var_arg), orig_pluginvar_name(plugin_var_arg->name) { plugin_var->name= name_arg; } sys_var_pluginvar *cast_pluginvar() { return this; } @@ -557,7 +557,7 @@ static void plugin_dl_del(const LEX_STRING *dl) uint i; DBUG_ENTER("plugin_dl_del"); - safe_mutex_assert_owner(&LOCK_plugin); + mysql_mutex_assert_owner(&LOCK_plugin); for (i= 0; i < plugin_dl_array.elements; i++) { @@ -589,7 +589,7 @@ static struct st_plugin_int *plugin_find_internal(const LEX_STRING *name, int ty if (! initialized) DBUG_RETURN(0); - safe_mutex_assert_owner(&LOCK_plugin); + mysql_mutex_assert_owner(&LOCK_plugin); if (type == MYSQL_ANY_PLUGIN) { @@ -614,14 +614,14 @@ static SHOW_COMP_OPTION plugin_status(const LEX_STRING *name, int type) SHOW_COMP_OPTION rc= SHOW_OPTION_NO; struct st_plugin_int *plugin; DBUG_ENTER("plugin_is_ready"); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); if ((plugin= plugin_find_internal(name, type))) { rc= SHOW_OPTION_DISABLED; if (plugin->state == PLUGIN_IS_READY) rc= SHOW_OPTION_YES; } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_RETURN(rc); } @@ -647,7 +647,7 @@ static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc CALLER_INFO_PROTO) st_plugin_int *pi= plugin_ref_to_int(rc); DBUG_ENTER("intern_plugin_lock"); - safe_mutex_assert_owner(&LOCK_plugin); + mysql_mutex_assert_owner(&LOCK_plugin); if (pi->state & (PLUGIN_IS_READY | PLUGIN_IS_UNINITIALIZED)) { @@ -686,9 +686,9 @@ plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO) LEX *lex= thd ? thd->lex : 0; plugin_ref rc; DBUG_ENTER("plugin_lock"); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); rc= my_intern_plugin_lock_ci(lex, *ptr); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_RETURN(rc); } @@ -700,10 +700,10 @@ plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, int type plugin_ref rc= NULL; st_plugin_int *plugin; DBUG_ENTER("plugin_lock_by_name"); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); if ((plugin= plugin_find_internal(name, type))) rc= my_intern_plugin_lock_ci(lex, plugin_int_to_ref(plugin)); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_RETURN(rc); } @@ -816,7 +816,7 @@ static void plugin_deinitialize(struct st_plugin_int *plugin, bool ref_check) deinitialization to deadlock if plugins have worker threads with plugin locks */ - safe_mutex_assert_not_owner(&LOCK_plugin); + mysql_mutex_assert_not_owner(&LOCK_plugin); if (plugin->plugin->status_vars) { @@ -869,11 +869,11 @@ static void plugin_deinitialize(struct st_plugin_int *plugin, bool ref_check) static void plugin_del(struct st_plugin_int *plugin) { DBUG_ENTER("plugin_del(plugin)"); - safe_mutex_assert_owner(&LOCK_plugin); + mysql_mutex_assert_owner(&LOCK_plugin); /* Free allocated strings before deleting the plugin. */ - rw_wrlock(&LOCK_system_variables_hash); + mysql_rwlock_wrlock(&LOCK_system_variables_hash); mysql_del_sys_var_chain(plugin->system_vars); - rw_unlock(&LOCK_system_variables_hash); + mysql_rwlock_unlock(&LOCK_system_variables_hash); restore_pluginvar_names(plugin->system_vars); plugin_vars_free_values(plugin->system_vars); my_hash_delete(&plugin_hash[plugin->plugin->type], (uchar*)plugin); @@ -903,7 +903,7 @@ static void reap_plugins(void) uint count, idx; struct st_plugin_int *plugin, **reap, **list; - safe_mutex_assert_owner(&LOCK_plugin); + mysql_mutex_assert_owner(&LOCK_plugin); if (!reap_needed) return; @@ -924,13 +924,13 @@ static void reap_plugins(void) } } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); list= reap; while ((plugin= *(--list))) plugin_deinitialize(plugin, true); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); while ((plugin= *(--reap))) plugin_del(plugin); @@ -944,7 +944,7 @@ static void intern_plugin_unlock(LEX *lex, plugin_ref plugin) st_plugin_int *pi; DBUG_ENTER("intern_plugin_unlock"); - safe_mutex_assert_owner(&LOCK_plugin); + mysql_mutex_assert_owner(&LOCK_plugin); if (!plugin) DBUG_VOID_RETURN; @@ -997,10 +997,10 @@ void plugin_unlock(THD *thd, plugin_ref plugin) if (!plugin_dlib(plugin)) DBUG_VOID_RETURN; #endif - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); intern_plugin_unlock(lex, plugin); reap_plugins(); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_VOID_RETURN; } @@ -1010,11 +1010,11 @@ void plugin_unlock_list(THD *thd, plugin_ref *list, uint count) LEX *lex= thd ? thd->lex : 0; DBUG_ENTER("plugin_unlock_list"); DBUG_ASSERT(list); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); while (count--) intern_plugin_unlock(lex, *list++); reap_plugins(); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_VOID_RETURN; } @@ -1024,7 +1024,7 @@ static int plugin_initialize(struct st_plugin_int *plugin) int ret= 1; DBUG_ENTER("plugin_initialize"); - safe_mutex_assert_owner(&LOCK_plugin); + mysql_mutex_assert_owner(&LOCK_plugin); if (plugin_type_initialize[plugin->plugin->type]) { if ((*plugin_type_initialize[plugin->plugin->type])(plugin)) @@ -1130,6 +1130,26 @@ static inline void convert_underscore_to_dash(char *str, int len) *p= '-'; } +#ifdef HAVE_PSI_INTERFACE +static PSI_mutex_key key_LOCK_plugin; + +static PSI_mutex_info all_plugin_mutexes[]= +{ + { &key_LOCK_plugin, "LOCK_plugin", PSI_FLAG_GLOBAL} +}; + +static void init_plugin_psi_keys(void) +{ + const char* category= "sql"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_plugin_mutexes); + PSI_server->register_mutex(category, all_plugin_mutexes, count); +} +#endif /* HAVE_PSI_INTERFACE */ /* The logic is that we first load and initialize all compiled in plugins. @@ -1153,6 +1173,10 @@ int plugin_init(int *argc, char **argv, int flags) if (initialized) DBUG_RETURN(0); +#ifdef HAVE_PSI_INTERFACE + init_plugin_psi_keys(); +#endif + init_alloc_root(&plugin_mem_root, 4096, 4096); init_alloc_root(&tmp_root, 4096, 4096); @@ -1161,7 +1185,7 @@ int plugin_init(int *argc, char **argv, int flags) goto err; - pthread_mutex_init(&LOCK_plugin, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_plugin, &LOCK_plugin, MY_MUTEX_INIT_FAST); if (my_init_dynamic_array(&plugin_dl_array, sizeof(struct st_plugin_dl *),16,16) || @@ -1176,7 +1200,7 @@ int plugin_init(int *argc, char **argv, int flags) goto err; } - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); initialized= 1; @@ -1204,6 +1228,26 @@ int plugin_init(int *argc, char **argv, int flags) tmp.name.length= strlen(plugin->name); tmp.state= 0; tmp.is_mandatory= mandatory; + + /* + If the performance schema is compiled in, + treat the storage engine plugin as 'mandatory', + to suppress any plugin-level options such as '--performance-schema'. + This is specific to the performance schema, and is done on purpose: + the server-level option '--performance-schema' controls the overall + performance schema initialization, which consists of much more that + the underlying storage engine initialization. + See mysqld.cc, set_vars.cc. + Suppressing ways to interfere directly with the storage engine alone + prevents awkward situations where: + - the user wants the performance schema functionality, by using + '--enable-performance-schema' (the server option), + - yet disable explicitly a component needed for the functionality + to work, by using '--skip-performance-schema' (the plugin) + */ + if (!my_strcasecmp(&my_charset_latin1, plugin->name, "PERFORMANCE_SCHEMA")) + tmp.is_mandatory= true; + free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE)); if (test_plugin_options(&tmp_root, &tmp, argc, argv)) tmp.state= PLUGIN_IS_DISABLED; @@ -1239,7 +1283,7 @@ int plugin_init(int *argc, char **argv, int flags) /* should now be set to MyISAM storage engine */ DBUG_ASSERT(global_system_variables.table_plugin); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); /* Register all dynamic plugins */ if (!(flags & PLUGIN_INIT_SKIP_DYNAMIC_LOADING)) @@ -1257,7 +1301,7 @@ int plugin_init(int *argc, char **argv, int flags) Now we initialize all remaining plugins */ - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); reap= (st_plugin_int **) my_alloca((plugin_array.elements+1) * sizeof(void*)); *(reap++)= NULL; @@ -1279,15 +1323,15 @@ int plugin_init(int *argc, char **argv, int flags) */ while ((plugin_ptr= *(--reap))) { - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); if (plugin_ptr->is_mandatory) reaped_mandatory_plugin= TRUE; plugin_deinitialize(plugin_ptr, true); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); plugin_del(plugin_ptr); } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); my_afree(reap); if (reaped_mandatory_plugin) goto err; @@ -1298,7 +1342,7 @@ end: DBUG_RETURN(0); err_unlock: - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); err: free_root(&tmp_root, MYF(0)); DBUG_RETURN(1); @@ -1352,8 +1396,8 @@ bool plugin_register_builtin(THD *thd, struct st_mysql_plugin *plugin) tmp.name.str= (char *)plugin->name; tmp.name.length= strlen(plugin->name); - pthread_mutex_lock(&LOCK_plugin); - rw_wrlock(&LOCK_system_variables_hash); + mysql_mutex_lock(&LOCK_plugin); + mysql_rwlock_wrlock(&LOCK_system_variables_hash); if (test_plugin_options(thd->mem_root, &tmp, &dummy_argc, NULL)) goto end; @@ -1365,8 +1409,8 @@ bool plugin_register_builtin(THD *thd, struct st_mysql_plugin *plugin) } end: - rw_unlock(&LOCK_system_variables_hash); - pthread_mutex_unlock(&LOCK_plugin); + mysql_rwlock_unlock(&LOCK_system_variables_hash); + mysql_mutex_unlock(&LOCK_plugin); DBUG_RETURN(result);; } @@ -1429,10 +1473,10 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) /* there're no other threads running yet, so we don't need a mutex. but plugin_add() before is designed to work in multi-threaded - environment, and it uses safe_mutex_assert_owner(), so we lock + environment, and it uses mysql_mutex_assert_owner(), so we lock the mutex here to satisfy the assert */ - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); while (!(error= read_record_info.read_record(&read_record_info))) { DBUG_PRINT("info", ("init plugin record")); @@ -1448,7 +1492,7 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) str_name.c_ptr(), str_dl.c_ptr()); free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE)); } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); if (error > 0) sql_print_error(ER(ER_GET_ERRNO), my_errno); end_read_record(&read_record_info); @@ -1500,7 +1544,7 @@ static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv, } dl= name; - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); if ((plugin_dl= plugin_dl_add(&dl, REPORT_TO_LOG))) { for (plugin= plugin_dl->plugins; plugin->info; plugin++) @@ -1518,11 +1562,11 @@ static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv, else { free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE)); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); if (plugin_add(tmp_root, &name, &dl, argc, argv, REPORT_TO_LOG)) goto error; } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); name.length= dl.length= 0; dl.str= NULL; name.str= p= buffer; str= &name; @@ -1543,7 +1587,7 @@ static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv, } DBUG_RETURN(FALSE); error: - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); sql_print_error("Couldn't load plugin named '%s' with soname '%s'.", name.str, dl.str); DBUG_RETURN(TRUE); @@ -1559,7 +1603,7 @@ void plugin_shutdown(void) if (initialized) { - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); reap_needed= true; @@ -1604,7 +1648,7 @@ void plugin_shutdown(void) if (plugins[i]->state == PLUGIN_IS_DELETED) plugins[i]->state= PLUGIN_IS_DYING; } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); /* We loop through all plugins and call deinit() if they have one. @@ -1625,9 +1669,9 @@ void plugin_shutdown(void) /* It's perfectly safe not to lock LOCK_plugin, as there're no concurrent threads anymore. But some functions called from here - use safe_mutex_assert_owner(), so we lock the mutex to satisfy it + use mysql_mutex_assert_owner(), so we lock the mutex to satisfy it */ - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); /* We defer checking ref_counts until after all plugins are deinitialized @@ -1648,10 +1692,10 @@ void plugin_shutdown(void) cleanup_variables(NULL, &global_system_variables); cleanup_variables(NULL, &max_system_variables); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); initialized= 0; - pthread_mutex_destroy(&LOCK_plugin); + mysql_mutex_destroy(&LOCK_plugin); my_afree(plugins); } @@ -1699,14 +1743,14 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl if (! (table = open_ltable(thd, &tables, TL_WRITE, 0))) DBUG_RETURN(TRUE); - pthread_mutex_lock(&LOCK_plugin); - rw_wrlock(&LOCK_system_variables_hash); + mysql_mutex_lock(&LOCK_plugin); + mysql_rwlock_wrlock(&LOCK_system_variables_hash); my_load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv, NULL); error= plugin_add(thd->mem_root, name, dl, &argc, argv, REPORT_TO_USER); if (argv) free_defaults(argv); - rw_unlock(&LOCK_system_variables_hash); + mysql_rwlock_unlock(&LOCK_system_variables_hash); if (error || !(tmp= plugin_find_internal(name, MYSQL_ANY_PLUGIN))) goto err; @@ -1746,14 +1790,14 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl goto deinit; } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_RETURN(FALSE); deinit: tmp->state= PLUGIN_IS_DELETED; reap_needed= true; reap_plugins(); err: - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_RETURN(TRUE); } @@ -1773,7 +1817,7 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name) if (! (table= open_ltable(thd, &tables, TL_WRITE, 0))) DBUG_RETURN(TRUE); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); if (!(plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN))) { my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PLUGIN", name->str); @@ -1794,7 +1838,7 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name) else reap_needed= true; reap_plugins(); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); uchar user_key[MAX_KEY_LENGTH]; table->use_all_columns(); @@ -1821,7 +1865,7 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name) } DBUG_RETURN(FALSE); err: - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_RETURN(TRUE); } @@ -1839,7 +1883,7 @@ bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func, state_mask= ~state_mask; // do it only once - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); total= type == MYSQL_ANY_PLUGIN ? plugin_array.elements : plugin_hash[type].records; /* @@ -1864,17 +1908,17 @@ bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func, plugins[idx]= !(plugin->state & state_mask) ? plugin : NULL; } } - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); for (idx= 0; idx < total; idx++) { if (unlikely(version != plugin_array_version)) { - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); for (uint i=idx; i < total; i++) if (plugins[i] && plugins[i]->state & state_mask) plugins[i]=0; - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); } plugin= plugins[idx]; /* It will stop iterating on first engine error when "func" returns TRUE */ @@ -2196,12 +2240,12 @@ sys_var *find_sys_var(THD *thd, const char *str, uint length) plugin_ref plugin; DBUG_ENTER("find_sys_var"); - pthread_mutex_lock(&LOCK_plugin); - rw_rdlock(&LOCK_system_variables_hash); + mysql_mutex_lock(&LOCK_plugin); + mysql_rwlock_rdlock(&LOCK_system_variables_hash); if ((var= intern_find_sys_var(str, length)) && (pi= var->cast_pluginvar())) { - rw_unlock(&LOCK_system_variables_hash); + mysql_rwlock_unlock(&LOCK_system_variables_hash); LEX *lex= thd ? thd->lex : 0; if (!(plugin= my_intern_plugin_lock(lex, plugin_int_to_ref(pi->plugin)))) var= NULL; /* failed to lock it, it must be uninstalling */ @@ -2214,8 +2258,8 @@ sys_var *find_sys_var(THD *thd, const char *str, uint length) } } else - rw_unlock(&LOCK_system_variables_hash); - pthread_mutex_unlock(&LOCK_plugin); + mysql_rwlock_unlock(&LOCK_system_variables_hash); + mysql_mutex_unlock(&LOCK_plugin); /* If the variable exists but the plugin it is associated with is not ready @@ -2403,7 +2447,7 @@ static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock) { uint idx; - rw_rdlock(&LOCK_system_variables_hash); + mysql_rwlock_rdlock(&LOCK_system_variables_hash); thd->variables.dynamic_variables_ptr= (char*) my_realloc(thd->variables.dynamic_variables_ptr, @@ -2411,9 +2455,9 @@ static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock) MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR)); if (global_lock) - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); - safe_mutex_assert_owner(&LOCK_global_system_variables); + mysql_mutex_assert_owner(&LOCK_global_system_variables); memcpy(thd->variables.dynamic_variables_ptr + thd->variables.dynamic_variables_size, @@ -2452,7 +2496,7 @@ static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock) } if (global_lock) - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); thd->variables.dynamic_variables_version= global_system_variables.dynamic_variables_version; @@ -2461,7 +2505,7 @@ static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock) thd->variables.dynamic_variables_size= global_system_variables.dynamic_variables_size; - rw_unlock(&LOCK_system_variables_hash); + mysql_rwlock_unlock(&LOCK_system_variables_hash); } return (uchar*)thd->variables.dynamic_variables_ptr + offset; } @@ -2488,11 +2532,11 @@ void plugin_thdvar_init(THD *thd) thd->variables.dynamic_variables_size= 0; thd->variables.dynamic_variables_ptr= 0; - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); thd->variables.table_plugin= my_intern_plugin_lock(NULL, global_system_variables.table_plugin); intern_plugin_unlock(NULL, old_table_plugin); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); DBUG_VOID_RETURN; } @@ -2521,7 +2565,7 @@ static void cleanup_variables(THD *thd, struct system_variables *vars) int flags; uint idx; - rw_rdlock(&LOCK_system_variables_hash); + mysql_rwlock_rdlock(&LOCK_system_variables_hash); for (idx= 0; idx < bookmark_hash.records; idx++) { v= (st_bookmark*) my_hash_element(&bookmark_hash, idx); @@ -2541,7 +2585,7 @@ static void cleanup_variables(THD *thd, struct system_variables *vars) *ptr= NULL; } } - rw_unlock(&LOCK_system_variables_hash); + mysql_rwlock_unlock(&LOCK_system_variables_hash); DBUG_ASSERT(vars->table_plugin == NULL); @@ -2558,7 +2602,7 @@ void plugin_thdvar_cleanup(THD *thd) plugin_ref *list; DBUG_ENTER("plugin_thdvar_cleanup"); - pthread_mutex_lock(&LOCK_plugin); + mysql_mutex_lock(&LOCK_plugin); unlock_variables(thd, &thd->variables); cleanup_variables(thd, &thd->variables); @@ -2572,7 +2616,7 @@ void plugin_thdvar_cleanup(THD *thd) } reap_plugins(); - pthread_mutex_unlock(&LOCK_plugin); + mysql_mutex_unlock(&LOCK_plugin); reset_dynamic(&thd->lex->plugins); @@ -2724,11 +2768,11 @@ bool sys_var_pluginvar::session_update(THD *thd, set_var *var) DBUG_ASSERT(plugin_var->flags & PLUGIN_VAR_THDLOCAL); DBUG_ASSERT(thd == current_thd); - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); void *tgt= real_value_ptr(thd, var->type); const void *src= var->value ? (void*)&var->save_result : (void*)real_value_ptr(thd, OPT_GLOBAL); - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); plugin_var->update(thd, plugin_var, tgt, src); return false; @@ -2737,7 +2781,7 @@ bool sys_var_pluginvar::session_update(THD *thd, set_var *var) bool sys_var_pluginvar::global_update(THD *thd, set_var *var) { DBUG_ASSERT(!is_readonly()); - safe_mutex_assert_owner(&LOCK_global_system_variables); + mysql_mutex_assert_owner(&LOCK_global_system_variables); void *tgt= real_value_ptr(thd, var->type); const void *src= &var->save_result; @@ -3274,7 +3318,7 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, if (!tmp->is_mandatory) opts[0].def_value= opts[1].def_value= plugin_load_policy; - error= handle_options(argc, &argv, opts, get_one_plugin_option); + error= handle_options(argc, &argv, opts, NULL); (*argc)++; /* add back one for the program name */ if (error) diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h index bec880b21d2..1a870ec260e 100644 --- a/sql/sql_plugin.h +++ b/sql/sql_plugin.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2005 MySQL AB +/* Copyright (C) 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index f19f12ddc13..63b7649bad5 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2002 MySQL AB +/* Copyright (C) 1995-2002 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -1414,7 +1414,7 @@ static int mysql_test_select(Prepared_statement *stmt, if (check_table_access(thd, privilege, tables, FALSE, UINT_MAX, FALSE)) goto error; } - else if (check_access(thd, privilege, any_db,0,0,0,0)) + else if (check_access(thd, privilege, any_db, NULL, NULL, 0, 0)) goto error; if (!lex->result && !(lex->result= new (stmt->mem_root) select_send)) diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 517fbb97b73..960a0adab2e 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB & Sasha +/* Copyright (C) 2000-2006 MySQL AB & Sasha, 2008-2009 Sun Microsystems, Inc 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 @@ -151,13 +151,14 @@ static int send_file(THD *thd) if (!strcmp(fname,"/dev/null")) goto end; - if ((fd = my_open(fname, O_RDONLY, MYF(0))) < 0) + if ((fd= mysql_file_open(key_file_send_file, + fname, O_RDONLY, MYF(0))) < 0) { errmsg = "on open of file"; goto err; } - while ((long) (bytes= my_read(fd, buf, IO_SIZE, MYF(0))) > 0) + while ((long) (bytes= mysql_file_read(fd, buf, IO_SIZE, MYF(0))) > 0) { if (my_net_write(net, buf, bytes)) { @@ -178,7 +179,7 @@ static int send_file(THD *thd) err: my_net_set_read_timeout(net, old_timeout); if (fd >= 0) - (void) my_close(fd, MYF(0)); + mysql_file_close(fd, MYF(0)); if (errmsg) { sql_print_error("Failed in send_file() %s", errmsg); @@ -221,7 +222,7 @@ void adjust_linfo_offsets(my_off_t purge_offset) LOG_INFO* linfo; if ((linfo = tmp->current_linfo)) { - pthread_mutex_lock(&linfo->lock); + mysql_mutex_lock(&linfo->lock); /* Index file offset can be less that purge offset only if we just started reading the index file. In that case @@ -231,7 +232,7 @@ void adjust_linfo_offsets(my_off_t purge_offset) linfo->fatal = (linfo->index_file_offset != 0); else linfo->index_file_offset -= purge_offset; - pthread_mutex_unlock(&linfo->lock); + mysql_mutex_unlock(&linfo->lock); } } pthread_mutex_unlock(&LOCK_thread_count); @@ -252,10 +253,10 @@ bool log_in_use(const char* log_name) LOG_INFO* linfo; if ((linfo = tmp->current_linfo)) { - pthread_mutex_lock(&linfo->lock); + mysql_mutex_lock(&linfo->lock); result = !bcmp((uchar*) log_name, (uchar*) linfo->log_file_name, log_name_len); - pthread_mutex_unlock(&linfo->lock); + mysql_mutex_unlock(&linfo->lock); if (result) break; } @@ -444,7 +445,7 @@ void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, int error; const char *errmsg = "Unknown error"; NET* net = &thd->net; - pthread_mutex_t *log_lock; + mysql_mutex_t *log_lock; bool binlog_can_be_corrupted= FALSE; #ifndef DBUG_OFF int left_events = max_binlog_dump_events; @@ -797,11 +798,11 @@ impossible position"; has not been updated since last read. */ - pthread_mutex_lock(log_lock); - switch (error= Log_event::read_log_event(&log, packet, (pthread_mutex_t*) 0)) { + mysql_mutex_lock(log_lock); + switch (error= Log_event::read_log_event(&log, packet, (mysql_mutex_t*) 0)) { case 0: /* we read successfully, so we'll need to send it to the slave */ - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); read_packet = 1; if (coord) coord->pos= uint4korr(packet->ptr() + ev_offset + LOG_POS_OFFSET); @@ -815,7 +816,7 @@ impossible position"; DBUG_PRINT("wait",("waiting for data in binary log")); if (thd->server_id==0) // for mysqlbinlog (mysqlbinlog.server_id==0) { - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); goto end; } @@ -850,7 +851,7 @@ impossible position"; { errmsg = "Failed on my_net_write()"; my_errno= ER_UNKNOWN_ERROR; - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); goto err; } } @@ -859,12 +860,12 @@ impossible position"; DBUG_PRINT("wait",("binary log received update or a broadcast signal caught")); } } while (signal_cnt == mysql_bin_log.signal_cnt && !thd->killed); - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); } break; default: - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); test_for_non_eof_log_read_errors(error, &errmsg); goto err; } @@ -931,7 +932,7 @@ impossible position"; break; end_io_cache(&log); - (void) my_close(file, MYF(MY_WME)); + mysql_file_close(file, MYF(MY_WME)); /* reset transmit packet for the possible fake rotate event */ if (reset_transmit_packet(thd, flags, &ev_offset, &errmsg)) @@ -961,7 +962,7 @@ impossible position"; end: end_io_cache(&log); - (void)my_close(file, MYF(MY_WME)); + mysql_file_close(file, MYF(MY_WME)); RUN_HOOK(binlog_transmit, transmit_stop, (thd, flags)); my_eof(thd); @@ -986,7 +987,7 @@ err: thd->current_linfo = 0; pthread_mutex_unlock(&LOCK_thread_count); if (file >= 0) - (void) my_close(file, MYF(MY_WME)); + mysql_file_close(file, MYF(MY_WME)); my_message(my_errno, errmsg, MYF(0)); DBUG_VOID_RETURN; @@ -1012,7 +1013,7 @@ int start_slave(THD* thd , Master_info* mi, bool net_report) int thread_mask; DBUG_ENTER("start_slave"); - if (check_access(thd, SUPER_ACL, any_db,0,0,0,0)) + if (check_access(thd, SUPER_ACL, any_db, NULL, NULL, 0, 0)) DBUG_RETURN(1); lock_slave_threads(mi); // this allows us to cleanly read slave_running // Get a mask of _stopped_ threads @@ -1039,7 +1040,7 @@ int start_slave(THD* thd , Master_info* mi, bool net_report) */ if (thread_mask & SLAVE_SQL) { - pthread_mutex_lock(&mi->rli.data_lock); + mysql_mutex_lock(&mi->rli.data_lock); if (thd->lex->mi.pos) { @@ -1093,7 +1094,7 @@ int start_slave(THD* thd , Master_info* mi, bool net_report) ER(ER_MISSING_SKIP_SLAVE)); } - pthread_mutex_unlock(&mi->rli.data_lock); + mysql_mutex_unlock(&mi->rli.data_lock); } else if (thd->lex->mi.pos || thd->lex->mi.relay_log_pos) push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_UNTIL_COND_IGNORED, @@ -1152,7 +1153,7 @@ int stop_slave(THD* thd, Master_info* mi, bool net_report ) if (!thd) thd = current_thd; - if (check_access(thd, SUPER_ACL, any_db,0,0,0,0)) + if (check_access(thd, SUPER_ACL, any_db, NULL, NULL, 0, 0)) DBUG_RETURN(1); thd_proc_info(thd, "Killing slave"); int thread_mask; @@ -1250,14 +1251,16 @@ int reset_slave(THD *thd, Master_info* mi) end_master_info(mi); // and delete these two files fn_format(fname, master_info_file, mysql_data_home, "", 4+32); - if (my_stat(fname, &stat_area, MYF(0)) && my_delete(fname, MYF(MY_WME))) + if (mysql_file_stat(key_file_master_info, fname, &stat_area, MYF(0)) && + mysql_file_delete(key_file_master_info, fname, MYF(MY_WME))) { error=1; goto err; } // delete relay_log_info_file fn_format(fname, relay_log_info_file, mysql_data_home, "", 4+32); - if (my_stat(fname, &stat_area, MYF(0)) && my_delete(fname, MYF(MY_WME))) + if (mysql_file_stat(key_file_relay_log_info, fname, &stat_area, MYF(0)) && + mysql_file_delete(key_file_relay_log_info, fname, MYF(MY_WME))) { error=1; goto err; @@ -1275,7 +1278,7 @@ err: Kill all Binlog_dump threads which previously talked to the same slave ("same" means with the same server id). Indeed, if the slave stops, if the - Binlog_dump thread is waiting (pthread_cond_wait) for binlog update, then it + Binlog_dump thread is waiting (mysql_cond_wait) for binlog update, then it will keep existing until a query is written to the binlog. If the master is idle, then this could last long, and if the slave reconnects, we could have 2 Binlog_dump threads in SHOW PROCESSLIST, until a query is written to the @@ -1302,7 +1305,7 @@ void kill_zombie_dump_threads(uint32 slave_server_id) if (tmp->command == COM_BINLOG_DUMP && tmp->server_id == slave_server_id) { - pthread_mutex_lock(&tmp->LOCK_thd_data); // Lock from delete + mysql_mutex_lock(&tmp->LOCK_thd_data); // Lock from delete break; } } @@ -1315,7 +1318,7 @@ void kill_zombie_dump_threads(uint32 slave_server_id) again. We just to do kill the thread ourselves. */ tmp->awake(THD::KILL_QUERY); - pthread_mutex_unlock(&tmp->LOCK_thd_data); + mysql_mutex_unlock(&tmp->LOCK_thd_data); } } @@ -1572,7 +1575,7 @@ bool change_master(THD* thd, Master_info* mi) if (!mi->rli.group_master_log_name[0]) // uninitialized case mi->rli.group_master_log_pos=0; - pthread_mutex_lock(&mi->rli.data_lock); + mysql_mutex_lock(&mi->rli.data_lock); mi->rli.abort_pos_wait++; /* for MASTER_POS_WAIT() to abort */ /* Clear the errors, for a clean start */ mi->rli.clear_error(); @@ -1585,8 +1588,8 @@ bool change_master(THD* thd, Master_info* mi) not exist anymore). */ flush_relay_log_info(&mi->rli); - pthread_cond_broadcast(&mi->data_cond); - pthread_mutex_unlock(&mi->rli.data_lock); + mysql_cond_broadcast(&mi->data_cond); + mysql_mutex_unlock(&mi->rli.data_lock); err: unlock_slave_threads(mi); @@ -1699,7 +1702,7 @@ bool mysql_show_binlog_events(THD* thd) my_off_t pos = max(BIN_LOG_HEADER_SIZE, lex_mi->pos); // user-friendly char search_file_name[FN_REFLEN], *name; const char *log_file_name = lex_mi->log_file_name; - pthread_mutex_t *log_lock = binary_log->get_log_lock(); + mysql_mutex_t *log_lock = binary_log->get_log_lock(); LOG_INFO linfo; Log_event* ev; @@ -1733,7 +1736,7 @@ bool mysql_show_binlog_events(THD* thd) */ thd->variables.max_allowed_packet += MAX_LOG_EVENT_HEADER; - pthread_mutex_lock(log_lock); + mysql_mutex_lock(log_lock); /* open_binlog() sought to position 4. @@ -1743,7 +1746,7 @@ bool mysql_show_binlog_events(THD* thd) This code will fail on a mixed relay log (one which has Format_desc then Rotate then Format_desc). */ - ev = Log_event::read_log_event(&log,(pthread_mutex_t*)0,description_event); + ev= Log_event::read_log_event(&log, (mysql_mutex_t*)0, description_event); if (ev) { if (ev->get_type_code() == FORMAT_DESCRIPTION_EVENT) @@ -1764,7 +1767,7 @@ bool mysql_show_binlog_events(THD* thd) } for (event_count = 0; - (ev = Log_event::read_log_event(&log,(pthread_mutex_t*) 0, + (ev = Log_event::read_log_event(&log, (mysql_mutex_t*) 0, description_event)); ) { if (event_count >= limit_start && @@ -1772,7 +1775,7 @@ bool mysql_show_binlog_events(THD* thd) { errmsg = "Net error"; delete ev; - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); goto err; } @@ -1786,11 +1789,11 @@ bool mysql_show_binlog_events(THD* thd) if (event_count < limit_end && log.error) { errmsg = "Wrong offset or I/O error"; - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); goto err; } - pthread_mutex_unlock(log_lock); + mysql_mutex_unlock(log_lock); } ret= FALSE; @@ -1800,7 +1803,7 @@ err: if (file >= 0) { end_io_cache(&log); - (void) my_close(file, MYF(MY_WME)); + mysql_file_close(file, MYF(MY_WME)); } if (errmsg) @@ -1892,12 +1895,12 @@ bool show_binlogs(THD* thd) Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) DBUG_RETURN(TRUE); - pthread_mutex_lock(mysql_bin_log.get_log_lock()); + mysql_mutex_lock(mysql_bin_log.get_log_lock()); mysql_bin_log.lock_index(); index_file=mysql_bin_log.get_index_file(); mysql_bin_log.raw_get_current_log(&cur); // dont take mutex - pthread_mutex_unlock(mysql_bin_log.get_log_lock()); // lockdep, OK + mysql_mutex_unlock(mysql_bin_log.get_log_lock()); // lockdep, OK cur_dir_len= dirname_length(cur.log_file_name); @@ -1920,11 +1923,12 @@ bool show_binlogs(THD* thd) else { /* this is an old log, open it and find the size */ - if ((file= my_open(fname, O_RDONLY | O_SHARE | O_BINARY, - MYF(0))) >= 0) + if ((file= mysql_file_open(key_file_binlog, + fname, O_RDONLY | O_SHARE | O_BINARY, + MYF(0))) >= 0) { - file_length= (ulonglong) my_seek(file, 0L, MY_SEEK_END, MYF(0)); - my_close(file, MYF(0)); + file_length= (ulonglong) mysql_file_seek(file, 0L, MY_SEEK_END, MYF(0)); + mysql_file_close(file, MYF(0)); } } protocol->store(file_length); diff --git a/sql/sql_servers.cc b/sql/sql_servers.cc index cde0a5c5069..141e00cf50f 100644 --- a/sql/sql_servers.cc +++ b/sql/sql_servers.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -47,7 +47,7 @@ static HASH servers_cache; static MEM_ROOT mem; -static rw_lock_t THR_LOCK_servers; +static mysql_rwlock_t THR_LOCK_servers; static bool get_server_from_table_to_cache(TABLE *table); @@ -89,6 +89,26 @@ static uchar *servers_cache_get_key(FOREIGN_SERVER *server, size_t *length, DBUG_RETURN((uchar*) server->server_name); } +#ifdef HAVE_PSI_INTERFACE +static PSI_rwlock_key key_rwlock_THR_LOCK_servers; + +static PSI_rwlock_info all_servers_cache_rwlocks[]= +{ + { &key_rwlock_THR_LOCK_servers, "THR_LOCK_servers", PSI_FLAG_GLOBAL} +}; + +static void init_servers_cache_psi_keys(void) +{ + const char* category= "sql"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_servers_cache_rwlocks); + PSI_server->register_rwlock(category, all_servers_cache_rwlocks, count); +} +#endif /* HAVE_PSI_INTERFACE */ /* Initialize structures responsible for servers used in federated @@ -115,8 +135,12 @@ bool servers_init(bool dont_read_servers_table) bool return_val= FALSE; DBUG_ENTER("servers_init"); +#ifdef HAVE_PSI_INTERFACE + init_servers_cache_psi_keys(); +#endif + /* init the mutex */ - if (my_rwlock_init(&THR_LOCK_servers, NULL)) + if (mysql_rwlock_init(key_rwlock_THR_LOCK_servers, &THR_LOCK_servers)) DBUG_RETURN(TRUE); /* initialise our servers cache */ @@ -231,7 +255,7 @@ bool servers_reload(THD *thd) } DBUG_PRINT("info", ("locking servers_cache")); - rw_wrlock(&THR_LOCK_servers); + mysql_rwlock_wrlock(&THR_LOCK_servers); bzero((char*) tables, sizeof(tables)); tables[0].alias= tables[0].table_name= (char*) "servers"; @@ -256,7 +280,7 @@ bool servers_reload(THD *thd) end: close_thread_tables(thd); DBUG_PRINT("info", ("unlocking servers_cache")); - rw_unlock(&THR_LOCK_servers); + mysql_rwlock_unlock(&THR_LOCK_servers); DBUG_RETURN(return_val); } @@ -586,7 +610,7 @@ int drop_server(THD *thd, LEX_SERVER_OPTIONS *server_options) tables.db= (char*) "mysql"; tables.alias= tables.table_name= (char*) "servers"; - rw_wrlock(&THR_LOCK_servers); + mysql_rwlock_wrlock(&THR_LOCK_servers); /* hit the memory hit first */ if ((error= delete_server_record_in_cache(server_options))) @@ -610,7 +634,7 @@ int drop_server(THD *thd, LEX_SERVER_OPTIONS *server_options) } end: - rw_unlock(&THR_LOCK_servers); + mysql_rwlock_unlock(&THR_LOCK_servers); DBUG_RETURN(error); } @@ -962,7 +986,7 @@ int create_server(THD *thd, LEX_SERVER_OPTIONS *server_options) DBUG_PRINT("info", ("server_options->server_name %s", server_options->server_name)); - rw_wrlock(&THR_LOCK_servers); + mysql_rwlock_wrlock(&THR_LOCK_servers); /* hit the memory first */ if (my_hash_search(&servers_cache, (uchar*) server_options->server_name, @@ -983,7 +1007,7 @@ int create_server(THD *thd, LEX_SERVER_OPTIONS *server_options) DBUG_PRINT("info", ("error returned %d", error)); end: - rw_unlock(&THR_LOCK_servers); + mysql_rwlock_unlock(&THR_LOCK_servers); DBUG_RETURN(error); } @@ -1012,7 +1036,7 @@ int alter_server(THD *thd, LEX_SERVER_OPTIONS *server_options) DBUG_PRINT("info", ("server_options->server_name %s", server_options->server_name)); - rw_wrlock(&THR_LOCK_servers); + mysql_rwlock_wrlock(&THR_LOCK_servers); if (!(existing= (FOREIGN_SERVER *) my_hash_search(&servers_cache, (uchar*) name.str, @@ -1037,7 +1061,7 @@ int alter_server(THD *thd, LEX_SERVER_OPTIONS *server_options) end: DBUG_PRINT("info", ("error returned %d", error)); - rw_unlock(&THR_LOCK_servers); + mysql_rwlock_unlock(&THR_LOCK_servers); DBUG_RETURN(error); } @@ -1203,7 +1227,7 @@ void servers_free(bool end) my_hash_reset(&servers_cache); DBUG_VOID_RETURN; } - rwlock_destroy(&THR_LOCK_servers); + mysql_rwlock_destroy(&THR_LOCK_servers); free_root(&mem,MYF(0)); my_hash_free(&servers_cache); DBUG_VOID_RETURN; @@ -1285,7 +1309,7 @@ FOREIGN_SERVER *get_server_by_name(MEM_ROOT *mem, const char *server_name, } DBUG_PRINT("info", ("locking servers_cache")); - rw_rdlock(&THR_LOCK_servers); + mysql_rwlock_rdlock(&THR_LOCK_servers); if (!(server= (FOREIGN_SERVER *) my_hash_search(&servers_cache, (uchar*) server_name, server_name_length))) @@ -1299,7 +1323,7 @@ FOREIGN_SERVER *get_server_by_name(MEM_ROOT *mem, const char *server_name, server= clone_server(mem, server, buff); DBUG_PRINT("info", ("unlocking servers_cache")); - rw_unlock(&THR_LOCK_servers); + mysql_rwlock_unlock(&THR_LOCK_servers); DBUG_RETURN(server); } diff --git a/sql/sql_show.cc b/sql/sql_show.cc index ece6cb7a4db..d562739f913 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -433,7 +433,7 @@ find_files(THD *thd, List<LEX_STRING> *files, const char *db, end= strend(buff); if (end != buff && end[-1] == FN_LIBCHAR) end[-1]= 0; // Remove end FN_LIBCHAR - if (!my_stat(buff, file->mystat, MYF(0))) + if (!mysql_file_stat(key_file_misc, buff, file->mystat, MYF(0))) continue; } #endif @@ -1769,13 +1769,13 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) thd_info->start_time= tmp->start_time; thd_info->query=0; /* Lock THD mutex that protects its data when looking at it. */ - pthread_mutex_lock(&tmp->LOCK_thd_data); + mysql_mutex_lock(&tmp->LOCK_thd_data); if (tmp->query()) { uint length= min(max_query_length, tmp->query_length()); thd_info->query= (char*) thd->strmake(tmp->query(),length); } - pthread_mutex_unlock(&tmp->LOCK_thd_data); + mysql_mutex_unlock(&tmp->LOCK_thd_data); thread_infos.append(thd_info); } } @@ -2147,7 +2147,7 @@ static bool show_status_array(THD *thd, const char *wild, char *value=var->value; const char *pos, *end; // We assign a lot of const's - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); if (show_type == SHOW_SYS) { @@ -2244,7 +2244,7 @@ static bool show_status_array(THD *thd, const char *wild, thd->count_cuted_fields= CHECK_FIELD_IGNORE; table->field[1]->set_notnull(); - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); if (schema_table_store_record(thd, table)) { @@ -3289,8 +3289,8 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) while ((db_name= it++)) { #ifndef NO_EMBEDDED_ACCESS_CHECKS - if (!check_access(thd,SELECT_ACL, db_name->str, - &thd->col_access, 0, 1, with_i_schema) || + if (!check_access(thd, SELECT_ACL, db_name->str, + &thd->col_access, NULL, 0, 1) || sctx->master_access & (DB_ACLS | SHOW_DB_ACL) || acl_get(sctx->host, sctx->ip, sctx->priv_user, db_name->str, 0) || !check_grant_db(thd, db_name->str)) @@ -3488,7 +3488,7 @@ int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond) path_len= build_table_filename(path, sizeof(path) - 1, lookup_field_vals.db_value.str, "", "", 0); path[path_len-1]= 0; - if (!my_stat(path,&stat_info,MYF(0))) + if (!mysql_file_stat(key_file_misc, path, &stat_info, MYF(0))) DBUG_RETURN(0); } @@ -3778,9 +3778,10 @@ static int get_schema_column_record(THD *thd, TABLE_LIST *tables, #ifndef NO_EMBEDDED_ACCESS_CHECKS uint col_access; - check_access(thd,SELECT_ACL, db_name->str, - &tables->grant.privilege, FALSE, FALSE, - test(tables->schema_table)); + check_access(thd, SELECT_ACL, db_name->str, + &tables->grant.privilege, + &tables->grant.m_internal, + FALSE, FALSE); col_access= get_column_grant(thd, &tables->grant, db_name->str, table_name->str, field->field_name) & COL_ACLS; @@ -5309,8 +5310,7 @@ copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table) has access. */ if (thd->lex->sql_command != SQLCOM_SHOW_EVENTS && - check_access(thd, EVENT_ACL, et.dbname.str, 0, 0, 1, - is_schema_db(et.dbname.str))) + check_access(thd, EVENT_ACL, et.dbname.str, NULL, NULL, 0, 1)) DBUG_RETURN(0); sch_table->field[ISE_EVENT_CATALOG]->store(STRING_WITH_LEN("def"), scs); @@ -5494,10 +5494,10 @@ int fill_variables(THD *thd, TABLE_LIST *tables, COND *cond) schema_table_idx == SCH_GLOBAL_VARIABLES) option_type= OPT_GLOBAL; - rw_rdlock(&LOCK_system_variables_hash); + mysql_rwlock_rdlock(&LOCK_system_variables_hash); res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars, option_type), option_type, NULL, "", tables->table, upper_case_names, cond); - rw_unlock(&LOCK_system_variables_hash); + mysql_rwlock_unlock(&LOCK_system_variables_hash); DBUG_RETURN(res); } @@ -7316,6 +7316,56 @@ bool show_create_trigger(THD *thd, const sp_name *trg_name) */ } +class IS_internal_schema_access : public ACL_internal_schema_access +{ +public: + IS_internal_schema_access() + {} + + ~IS_internal_schema_access() + {} + + ACL_internal_access_result check(ulong want_access, + ulong *save_priv) const; + + const ACL_internal_table_access *lookup(const char *name) const; +}; + +ACL_internal_access_result +IS_internal_schema_access::check(ulong want_access, + ulong *save_priv) const +{ + want_access &= ~SELECT_ACL; + + /* + We don't allow any simple privileges but SELECT_ACL on + the information_schema database. + */ + if (unlikely(want_access & DB_ACLS)) + return ACL_INTERNAL_ACCESS_DENIED; + + /* Always grant SELECT for the information schema. */ + *save_priv|= SELECT_ACL; + + return want_access ? ACL_INTERNAL_ACCESS_CHECK_GRANT : + ACL_INTERNAL_ACCESS_GRANTED; +} + +const ACL_internal_table_access * +IS_internal_schema_access::lookup(const char *name) const +{ + /* There are no per table rules for the information schema. */ + return NULL; +} + +static IS_internal_schema_access is_internal_schema_access; + +void initialize_information_schema_acl() +{ + ACL_internal_schema_registry::register_schema(&INFORMATION_SCHEMA_NAME, + &is_internal_schema_access); +} + /* Convert a string in character set in column character set format to utf8 character set if possible, the utf8 character set string diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 633c405ea25..190c1cb9c70 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -607,7 +607,7 @@ struct st_global_ddl_log st_global_ddl_log global_ddl_log; -pthread_mutex_t LOCK_gdl; +mysql_mutex_t LOCK_gdl; #define DDL_LOG_ENTRY_TYPE_POS 0 #define DDL_LOG_ACTION_TYPE_POS 1 @@ -637,8 +637,8 @@ static bool read_ddl_log_file_entry(uint entry_no) uint io_size= global_ddl_log.io_size; DBUG_ENTER("read_ddl_log_file_entry"); - if (my_pread(file_id, file_entry_buf, io_size, io_size * entry_no, - MYF(MY_WME)) != io_size) + if (mysql_file_pread(file_id, file_entry_buf, io_size, io_size * entry_no, + MYF(MY_WME)) != io_size) error= TRUE; DBUG_RETURN(error); } @@ -661,8 +661,8 @@ static bool write_ddl_log_file_entry(uint entry_no) char *file_entry_buf= (char*)global_ddl_log.file_entry_buf; DBUG_ENTER("write_ddl_log_file_entry"); - if (my_pwrite(file_id, (uchar*)file_entry_buf, - IO_SIZE, IO_SIZE * entry_no, MYF(MY_WME)) != IO_SIZE) + if (mysql_file_pwrite(file_id, (uchar*)file_entry_buf, + IO_SIZE, IO_SIZE * entry_no, MYF(MY_WME)) != IO_SIZE) error= TRUE; DBUG_RETURN(error); } @@ -738,8 +738,9 @@ static uint read_ddl_log_header() DBUG_ENTER("read_ddl_log_header"); create_ddl_log_file_name(file_name); - if ((global_ddl_log.file_id= my_open(file_name, - O_RDWR | O_BINARY, MYF(0))) >= 0) + if ((global_ddl_log.file_id= mysql_file_open(key_file_global_ddl_log, + file_name, + O_RDWR | O_BINARY, MYF(0))) >= 0) { if (read_ddl_log_file_entry(0UL)) { @@ -764,7 +765,7 @@ static uint read_ddl_log_header() global_ddl_log.first_free= NULL; global_ddl_log.first_used= NULL; global_ddl_log.num_entries= 0; - pthread_mutex_init(&LOCK_gdl, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_LOCK_gdl, &LOCK_gdl, MY_MUTEX_INIT_FAST); global_ddl_log.do_release= true; DBUG_RETURN(entry_no); } @@ -834,10 +835,10 @@ static bool init_ddl_log() global_ddl_log.io_size= IO_SIZE; create_ddl_log_file_name(file_name); - if ((global_ddl_log.file_id= my_create(file_name, - CREATE_MODE, - O_RDWR | O_TRUNC | O_BINARY, - MYF(MY_WME))) < 0) + if ((global_ddl_log.file_id= mysql_file_create(key_file_global_ddl_log, + file_name, CREATE_MODE, + O_RDWR | O_TRUNC | O_BINARY, + MYF(MY_WME))) < 0) { /* Couldn't create ddl log file, this is serious error */ sql_print_error("Failed to open ddl log file"); @@ -846,7 +847,7 @@ static bool init_ddl_log() global_ddl_log.inited= TRUE; if (write_ddl_log_header()) { - (void) my_close(global_ddl_log.file_id, MYF(MY_WME)); + (void) mysql_file_close(global_ddl_log.file_id, MYF(MY_WME)); global_ddl_log.inited= FALSE; DBUG_RETURN(TRUE); } @@ -916,14 +917,14 @@ static int execute_ddl_log_action(THD *thd, DDL_LOG_ENTRY *ddl_log_entry) if (frm_action) { strxmov(to_path, ddl_log_entry->name, reg_ext, NullS); - if ((error= my_delete(to_path, MYF(MY_WME)))) + if ((error= mysql_file_delete(key_file_frm, to_path, MYF(MY_WME)))) { if (my_errno != ENOENT) break; } #ifdef WITH_PARTITION_STORAGE_ENGINE strxmov(to_path, ddl_log_entry->name, par_ext, NullS); - (void) my_delete(to_path, MYF(MY_WME)); + (void) mysql_file_delete(key_file_partition, to_path, MYF(MY_WME)); #endif } else @@ -955,12 +956,12 @@ static int execute_ddl_log_action(THD *thd, DDL_LOG_ENTRY *ddl_log_entry) { strxmov(to_path, ddl_log_entry->name, reg_ext, NullS); strxmov(from_path, ddl_log_entry->from_name, reg_ext, NullS); - if (my_rename(from_path, to_path, MYF(MY_WME))) + if (mysql_file_rename(key_file_frm, from_path, to_path, MYF(MY_WME))) break; #ifdef WITH_PARTITION_STORAGE_ENGINE strxmov(to_path, ddl_log_entry->name, par_ext, NullS); strxmov(from_path, ddl_log_entry->from_name, par_ext, NullS); - (void) my_rename(from_path, to_path, MYF(MY_WME)); + (void) mysql_file_rename(key_file_partition, from_path, to_path, MYF(MY_WME)); #endif } else @@ -1277,7 +1278,7 @@ bool sync_ddl_log() { DBUG_RETURN(TRUE); } - if (my_sync(global_ddl_log.file_id, MYF(0))) + if (mysql_file_sync(global_ddl_log.file_id, MYF(0))) { /* Write to error log */ sql_print_error("Failed to sync ddl log"); @@ -1333,7 +1334,7 @@ bool execute_ddl_log_entry(THD *thd, uint first_entry) uint read_entry= first_entry; DBUG_ENTER("execute_ddl_log_entry"); - pthread_mutex_lock(&LOCK_gdl); + mysql_mutex_lock(&LOCK_gdl); do { if (read_ddl_log_entry(read_entry, &ddl_log_entry)) @@ -1355,7 +1356,7 @@ bool execute_ddl_log_entry(THD *thd, uint first_entry) } read_entry= ddl_log_entry.next_entry; } while (read_entry); - pthread_mutex_unlock(&LOCK_gdl); + mysql_mutex_unlock(&LOCK_gdl); DBUG_RETURN(FALSE); } @@ -1373,7 +1374,7 @@ static void close_ddl_log() DBUG_ENTER("close_ddl_log"); if (global_ddl_log.file_id >= 0) { - (void) my_close(global_ddl_log.file_id, MYF(MY_WME)); + (void) mysql_file_close(global_ddl_log.file_id, MYF(MY_WME)); global_ddl_log.file_id= (File) -1; } DBUG_VOID_RETURN; @@ -1433,7 +1434,7 @@ void execute_ddl_log_recovery() } close_ddl_log(); create_ddl_log_file_name(file_name); - (void) my_delete(file_name, MYF(0)); + (void) mysql_file_delete(key_file_global_ddl_log, file_name, MYF(0)); global_ddl_log.recovery_phase= FALSE; delete thd; /* Remember that we don't have a THD */ @@ -1459,7 +1460,7 @@ void release_ddl_log() if (!global_ddl_log.do_release) DBUG_VOID_RETURN; - pthread_mutex_lock(&LOCK_gdl); + mysql_mutex_lock(&LOCK_gdl); while (used_list) { DDL_LOG_MEMORY_ENTRY *tmp= used_list->next_log_entry; @@ -1474,8 +1475,8 @@ void release_ddl_log() } close_ddl_log(); global_ddl_log.inited= 0; - pthread_mutex_unlock(&LOCK_gdl); - pthread_mutex_destroy(&LOCK_gdl); + mysql_mutex_unlock(&LOCK_gdl); + mysql_mutex_destroy(&LOCK_gdl); global_ddl_log.do_release= false; DBUG_VOID_RETURN; } @@ -1607,7 +1608,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) CHF_CREATE_FLAG, lpt->create_info)) { - my_delete(shadow_frm_name, MYF(0)); + mysql_file_delete(key_file_frm, shadow_frm_name, MYF(0)); error= 1; goto end; } @@ -1631,7 +1632,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) error= 1; goto end; } - error= my_delete(shadow_frm_name, MYF(MY_WME)); + error= mysql_file_delete(key_file_frm, shadow_frm_name, MYF(MY_WME)); } if (flags & WFRM_INSTALL_SHADOW) { @@ -1655,7 +1656,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) deactivate it. */ mysql_mutex_lock(&LOCK_open); - if (my_delete(frm_name, MYF(MY_WME)) || + if (mysql_file_delete(key_file_frm, frm_name, MYF(MY_WME)) || #ifdef WITH_PARTITION_STORAGE_ENGINE lpt->table->file->ha_create_handler_files(path, shadow_path, CHF_DELETE_FLAG, NULL) || @@ -1663,11 +1664,13 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) (sync_ddl_log(), FALSE) || #endif #ifdef WITH_PARTITION_STORAGE_ENGINE - my_rename(shadow_frm_name, frm_name, MYF(MY_WME)) || + mysql_file_rename(key_file_frm, + shadow_frm_name, frm_name, MYF(MY_WME)) || lpt->table->file->ha_create_handler_files(path, shadow_path, CHF_RENAME_FLAG, NULL)) #else - my_rename(shadow_frm_name, frm_name, MYF(MY_WME))) + mysql_file_rename(key_file_frm, + shadow_frm_name, frm_name, MYF(MY_WME))) #endif { error= 1; @@ -1888,7 +1891,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, table->db_type= share->db_type(); /* Disable drop of enabled log tables */ - if (share && (share->table_category == TABLE_CATEGORY_PERFORMANCE) && + if (share && (share->table_category == TABLE_CATEGORY_LOG) && check_if_log_table(table->db_length, table->db, table->table_name_length, table->table_name, 1)) { @@ -2043,7 +2046,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, int new_error; /* Delete the table definition file */ strmov(end,reg_ext); - if (!(new_error=my_delete(path,MYF(MY_WME)))) + if (!(new_error= mysql_file_delete(key_file_frm, path, MYF(MY_WME)))) { some_tables_deleted=1; new_error= Table_triggers_list::drop_all_triggers(thd, db, @@ -2186,7 +2189,7 @@ bool quick_rm_table(handlerton *base,const char *db, uint path_length= build_table_filename(path, sizeof(path) - 1, db, table_name, reg_ext, flags); - if (my_delete(path,MYF(0))) + if (mysql_file_delete(key_file_frm, path, MYF(0))) error= 1; /* purecov: inspected */ path[path_length - reg_ext_length]= '\0'; // Remove reg_ext if (!(flags & FRM_ONLY)) @@ -4414,7 +4417,7 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list, // Name of data file strxmov(from, table->s->normalized_path.str, ext[1], NullS); - if (!my_stat(from, &stat_info, MYF(0))) + if (!mysql_file_stat(key_file_misc, from, &stat_info, MYF(0))) goto end; // Can't use USE_FRM flag my_snprintf(tmp, sizeof(tmp), "%s-%lx_%lx", @@ -4432,7 +4435,7 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list, error= -1; goto end; } - if (my_rename(from, tmp, MYF(MY_WME))) + if (mysql_file_rename(key_file_misc, from, tmp, MYF(MY_WME))) { mysql_mutex_lock(&LOCK_open); unlock_table_name(thd, table_list); @@ -4450,7 +4453,7 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list, "Failed generating table from .frm file"); goto end; } - if (my_rename(tmp, from, MYF(MY_WME))) + if (mysql_file_rename(key_file_misc, tmp, from, MYF(MY_WME))) { mysql_mutex_lock(&LOCK_open); unlock_table_name(thd, table_list); @@ -5042,14 +5045,14 @@ bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables, DBUG_ENTER("mysql_assign_to_keycache"); check_opt.init(); - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); if (!(key_cache= get_key_cache(key_cache_name))) { - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); my_error(ER_UNKNOWN_KEY_CACHE, MYF(0), key_cache_name->str); DBUG_RETURN(TRUE); } - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); check_opt.key_cache= key_cache; DBUG_RETURN(mysql_admin_table(thd, tables, &check_opt, "assign_to_keycache", TL_READ_NO_INSERT, 0, 0, diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 4ab9bba03ae..6f0602cedfd 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -804,7 +804,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, return 0; err_with_cleanup: - my_delete(trigname_buff, MYF(MY_WME)); + mysql_file_delete(key_file_trn, trigname_buff, MYF(MY_WME)); return 1; } @@ -827,7 +827,7 @@ static bool rm_trigger_file(char *path, const char *db, const char *table_name) { build_table_filename(path, FN_REFLEN-1, db, table_name, TRG_EXT, 0); - return my_delete(path, MYF(MY_WME)); + return mysql_file_delete(key_file_trg, path, MYF(MY_WME)); } @@ -849,7 +849,7 @@ static bool rm_trigname_file(char *path, const char *db, const char *trigger_name) { build_table_filename(path, FN_REFLEN - 1, db, trigger_name, TRN_EXT, 0); - return my_delete(path, MYF(MY_WME)); + return mysql_file_delete(key_file_trn, path, MYF(MY_WME)); } diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index 3a7309a0ea4..94e9fde6a33 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -44,7 +44,7 @@ extern "C" static bool initialized = 0; static MEM_ROOT mem; static HASH udf_hash; -static rw_lock_t THR_LOCK_udf; +static mysql_rwlock_t THR_LOCK_udf; static udf_func *add_udf(LEX_STRING *name, Item_result ret, @@ -100,6 +100,26 @@ extern "C" uchar* get_hash_key(const uchar *buff, size_t *length, return (uchar*) udf->name.str; } +#ifdef HAVE_PSI_INTERFACE +static PSI_rwlock_key key_rwlock_THR_LOCK_udf; + +static PSI_rwlock_info all_udf_rwlocks[]= +{ + { &key_rwlock_THR_LOCK_udf, "THR_LOCK_udf", PSI_FLAG_GLOBAL} +}; + +static void init_udf_psi_keys(void) +{ + const char* category= "sql"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_udf_rwlocks); + PSI_server->register_rwlock(category, all_udf_rwlocks, count); +} +#endif /* Read all predeclared functions from mysql.func and accept all that @@ -119,8 +139,12 @@ void udf_init() if (initialized) DBUG_VOID_RETURN; - my_rwlock_init(&THR_LOCK_udf,NULL); - +#ifdef HAVE_PSI_INTERFACE + init_udf_psi_keys(); +#endif + + mysql_rwlock_init(key_rwlock_THR_LOCK_udf, &THR_LOCK_udf); + init_sql_alloc(&mem, UDF_ALLOC_BLOCK_SIZE, 0); THD *new_thd = new THD; if (!new_thd || @@ -256,7 +280,7 @@ void udf_free() if (initialized) { initialized= 0; - rwlock_destroy(&THR_LOCK_udf); + mysql_rwlock_destroy(&THR_LOCK_udf); } DBUG_VOID_RETURN; } @@ -294,7 +318,7 @@ void free_udf(udf_func *udf) if (!initialized) DBUG_VOID_RETURN; - rw_wrlock(&THR_LOCK_udf); + mysql_rwlock_wrlock(&THR_LOCK_udf); if (!--udf->usage_count) { /* @@ -306,7 +330,7 @@ void free_udf(udf_func *udf) if (!find_udf_dl(udf->dl)) dlclose(udf->dlhandle); } - rw_unlock(&THR_LOCK_udf); + mysql_rwlock_unlock(&THR_LOCK_udf); DBUG_VOID_RETURN; } @@ -323,9 +347,9 @@ udf_func *find_udf(const char *name,uint length,bool mark_used) /* TODO: This should be changed to reader locks someday! */ if (mark_used) - rw_wrlock(&THR_LOCK_udf); /* Called during fix_fields */ + mysql_rwlock_wrlock(&THR_LOCK_udf); /* Called during fix_fields */ else - rw_rdlock(&THR_LOCK_udf); /* Called during parsing */ + mysql_rwlock_rdlock(&THR_LOCK_udf); /* Called during parsing */ if ((udf=(udf_func*) my_hash_search(&udf_hash,(uchar*) name, length ? length : (uint) strlen(name)))) @@ -335,7 +359,7 @@ udf_func *find_udf(const char *name,uint length,bool mark_used) else if (mark_used) udf->usage_count++; } - rw_unlock(&THR_LOCK_udf); + mysql_rwlock_unlock(&THR_LOCK_udf); DBUG_RETURN(udf); } @@ -439,7 +463,7 @@ int mysql_create_function(THD *thd,udf_func *udf) if (thd->current_stmt_binlog_row_based) thd->clear_current_stmt_binlog_row_based(); - rw_wrlock(&THR_LOCK_udf); + mysql_rwlock_wrlock(&THR_LOCK_udf); if ((my_hash_search(&udf_hash,(uchar*) udf->name.str, udf->name.length))) { my_error(ER_UDF_EXISTS, MYF(0), udf->name.str); @@ -502,7 +526,7 @@ int mysql_create_function(THD *thd,udf_func *udf) del_udf(u_d); goto err; } - rw_unlock(&THR_LOCK_udf); + mysql_rwlock_unlock(&THR_LOCK_udf); /* Binlog the create function. */ if (write_bin_log(thd, TRUE, thd->query(), thd->query_length())) @@ -512,7 +536,7 @@ int mysql_create_function(THD *thd,udf_func *udf) err: if (new_dl) dlclose(dl); - rw_unlock(&THR_LOCK_udf); + mysql_rwlock_unlock(&THR_LOCK_udf); DBUG_RETURN(1); } @@ -542,7 +566,7 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name) if (thd->current_stmt_binlog_row_based) thd->clear_current_stmt_binlog_row_based(); - rw_wrlock(&THR_LOCK_udf); + mysql_rwlock_wrlock(&THR_LOCK_udf); if (!(udf=(udf_func*) my_hash_search(&udf_hash,(uchar*) udf_name->str, (uint) udf_name->length))) { @@ -577,14 +601,14 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name) } close_thread_tables(thd); - rw_unlock(&THR_LOCK_udf); + mysql_rwlock_unlock(&THR_LOCK_udf); /* Binlog the drop function. */ if (write_bin_log(thd, TRUE, thd->query(), thd->query_length())) DBUG_RETURN(1); DBUG_RETURN(0); err: - rw_unlock(&THR_LOCK_udf); + mysql_rwlock_unlock(&THR_LOCK_udf); DBUG_RETURN(1); } diff --git a/sql/sql_update.cc b/sql/sql_update.cc index b197434d798..dec83f199ab 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -1,4 +1,4 @@ -/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. +/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. 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 @@ -1074,9 +1074,10 @@ reopen_tables: if (!tl->derived) { uint want_privilege= tl->updating ? UPDATE_ACL : SELECT_ACL; - if (check_access(thd, want_privilege, - tl->db, &tl->grant.privilege, 0, 0, - test(tl->schema_table)) || + if (check_access(thd, want_privilege, tl->db, + &tl->grant.privilege, + &tl->grant.m_internal, + 0, 0) || check_grant(thd, want_privilege, tl, FALSE, 1, FALSE)) DBUG_RETURN(TRUE); } diff --git a/sql/sql_view.cc b/sql/sql_view.cc index cb60c3b34e4..e088eb1ff59 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -258,12 +258,16 @@ bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view, checked that we have not more privileges on correspondent column of view table (i.e. user will not get some privileges by view creation) */ - if ((check_access(thd, CREATE_VIEW_ACL, view->db, &view->grant.privilege, - 0, 0, is_schema_db(view->db)) || + if ((check_access(thd, CREATE_VIEW_ACL, view->db, + &view->grant.privilege, + &view->grant.m_internal, + 0, 0) || check_grant(thd, CREATE_VIEW_ACL, view, FALSE, 1, FALSE)) || (mode != VIEW_CREATE_NEW && - (check_access(thd, DROP_ACL, view->db, &view->grant.privilege, - 0, 0, is_schema_db(view->db)) || + (check_access(thd, DROP_ACL, view->db, + &view->grant.privilege, + &view->grant.m_internal, + 0, 0) || check_grant(thd, DROP_ACL, view, FALSE, 1, FALSE)))) goto err; @@ -313,7 +317,9 @@ bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view, if (!tbl->table_in_first_from_clause) { if (check_access(thd, SELECT_ACL, tbl->db, - &tbl->grant.privilege, 0, 0, test(tbl->schema_table)) || + &tbl->grant.privilege, + &tbl->grant.m_internal, + 0, 0) || check_grant(thd, SELECT_ACL, tbl, FALSE, 1, FALSE)) goto err; } @@ -1608,7 +1614,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) } continue; } - if (my_delete(path, MYF(MY_WME))) + if (mysql_file_delete(key_file_frm, path, MYF(MY_WME))) error= TRUE; some_views_deleted= TRUE; @@ -1620,10 +1626,10 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) if ((share= get_cached_table_share(view->db, view->table_name))) { DBUG_ASSERT(share->ref_count == 0); - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); share->ref_count++; share->version= 0; - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); release_table_share(share, RELEASE_WAIT_FOR_DROP); } query_cache_invalidate3(thd, view, 0); @@ -1683,10 +1689,11 @@ frm_type_enum mysql_frm_type(THD *thd, char *path, enum legacy_db_type *dbt) *dbt= DB_TYPE_UNKNOWN; - if ((file= my_open(path, O_RDONLY | O_SHARE, MYF(0))) < 0) + if ((file= mysql_file_open(key_file_frm, + path, O_RDONLY | O_SHARE, MYF(0))) < 0) DBUG_RETURN(FRMTYPE_ERROR); - error= my_read(file, (uchar*) header, sizeof(header), MYF(MY_NABP)); - my_close(file, MYF(MY_WME)); + error= mysql_file_read(file, (uchar*) header, sizeof(header), MYF(MY_NABP)); + mysql_file_close(file, MYF(MY_WME)); if (error) DBUG_RETURN(FRMTYPE_ERROR); diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index da507edbdb4..1bac48d053f 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2002-2006 MySQL AB, 2009 Sun Microsystems, Inc. +/* Copyright (C) 2002-2006 MySQL AB, 2009-2010 Sun Microsystems, Inc. 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 @@ -34,6 +34,10 @@ #include "slave.h" #include "rpl_mi.h" +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE +#include "../storage/perfschema/pfs_server.h" +#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ + /* The rule for this file: everything should be 'static'. When a sys_var variable or a function from this file is - in very rare cases - needed @@ -42,6 +46,141 @@ */ #define export /* not static */ +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE + +#define PFS_TRAILING_PROPERTIES \ + NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL), ON_UPDATE(NULL), \ + 0, NULL, sys_var::PARSE_EARLY + +static Sys_var_mybool Sys_pfs_enabled( + "performance_schema", + "Enable the performance schema.", + READ_ONLY GLOBAL_VAR(pfs_param.m_enabled), + CMD_LINE(OPT_ARG), DEFAULT(FALSE), + PFS_TRAILING_PROPERTIES); + +static Sys_var_ulong Sys_pfs_events_waits_history_long_size( + "performance_schema_events_waits_history_long_size", + "Number of rows in EVENTS_WAITS_HISTORY_LONG.", + READ_ONLY GLOBAL_VAR(pfs_param.m_events_waits_history_long_sizing), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024*1024), + DEFAULT(PFS_WAITS_HISTORY_LONG_SIZE), + BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES); + +static Sys_var_ulong Sys_pfs_events_waits_history_size( + "performance_schema_events_waits_history_size", + "Number of rows per thread in EVENTS_WAITS_HISTORY.", + READ_ONLY GLOBAL_VAR(pfs_param.m_events_waits_history_sizing), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024), + DEFAULT(PFS_WAITS_HISTORY_SIZE), + BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES); + +static Sys_var_ulong Sys_pfs_max_cond_classes( + "performance_schema_max_cond_classes", + "Maximum number of condition instruments.", + READ_ONLY GLOBAL_VAR(pfs_param.m_cond_class_sizing), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256), + DEFAULT(PFS_MAX_COND_CLASS), + BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES); + +static Sys_var_ulong Sys_pfs_max_cond_instances( + "performance_schema_max_cond_instances", + "Maximum number of instrumented condition objects.", + READ_ONLY GLOBAL_VAR(pfs_param.m_cond_sizing), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024*1024), + DEFAULT(PFS_MAX_COND), + BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES); + +static Sys_var_ulong Sys_pfs_max_file_classes( + "performance_schema_max_file_classes", + "Maximum number of file instruments.", + READ_ONLY GLOBAL_VAR(pfs_param.m_file_class_sizing), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256), + DEFAULT(PFS_MAX_FILE_CLASS), + BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES); + +static Sys_var_ulong Sys_pfs_max_file_handles( + "performance_schema_max_file_handles", + "Maximum number of opened instrumented files.", + READ_ONLY GLOBAL_VAR(pfs_param.m_file_handle_sizing), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024*1024), + DEFAULT(PFS_MAX_FILE_HANDLE), + BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES); + +static Sys_var_ulong Sys_pfs_max_file_instances( + "performance_schema_max_file_instances", + "Maximum number of instrumented files.", + READ_ONLY GLOBAL_VAR(pfs_param.m_file_sizing), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024*1024), + DEFAULT(PFS_MAX_FILE), + BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES); + +static Sys_var_ulong Sys_pfs_max_mutex_classes( + "performance_schema_max_mutex_classes", + "Maximum number of mutex instruments.", + READ_ONLY GLOBAL_VAR(pfs_param.m_mutex_class_sizing), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256), + DEFAULT(PFS_MAX_MUTEX_CLASS), + BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES); + +static Sys_var_ulong Sys_pfs_max_mutex_instances( + "performance_schema_max_mutex_instances", + "Maximum number of instrumented MUTEX objects.", + READ_ONLY GLOBAL_VAR(pfs_param.m_mutex_sizing), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024*1024), + DEFAULT(PFS_MAX_MUTEX), + BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES); + +static Sys_var_ulong Sys_pfs_max_rwlock_classes( + "performance_schema_max_rwlock_classes", + "Maximum number of rwlock instruments.", + READ_ONLY GLOBAL_VAR(pfs_param.m_rwlock_class_sizing), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256), + DEFAULT(PFS_MAX_RWLOCK_CLASS), + BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES); + +static Sys_var_ulong Sys_pfs_max_rwlock_instances( + "performance_schema_max_rwlock_instances", + "Maximum number of instrumented RWLOCK objects.", + READ_ONLY GLOBAL_VAR(pfs_param.m_rwlock_sizing), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024*1024), + DEFAULT(PFS_MAX_RWLOCK), + BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES); + +static Sys_var_ulong Sys_pfs_max_table_handles( + "performance_schema_max_table_handles", + "Maximum number of opened instrumented tables.", + READ_ONLY GLOBAL_VAR(pfs_param.m_table_sizing), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024*1024), + DEFAULT(PFS_MAX_TABLE), + BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES); + +static Sys_var_ulong Sys_pfs_max_table_instances( + "performance_schema_max_table_instances", + "Maximum number of instrumented tables.", + READ_ONLY GLOBAL_VAR(pfs_param.m_table_share_sizing), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024*1024), + DEFAULT(PFS_MAX_TABLE_SHARE), + BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES); + +static Sys_var_ulong Sys_pfs_max_thread_classes( + "performance_schema_max_thread_classes", + "Maximum number of thread instruments.", + READ_ONLY GLOBAL_VAR(pfs_param.m_thread_class_sizing), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256), + DEFAULT(PFS_MAX_THREAD_CLASS), + BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES); + +static Sys_var_ulong Sys_pfs_max_thread_instances( + "performance_schema_max_thread_instances", + "Maximum number of instrumented threads.", + READ_ONLY GLOBAL_VAR(pfs_param.m_thread_sizing), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024*1024), + DEFAULT(PFS_MAX_THREAD), + BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES); + +#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ + static Sys_var_ulong Sys_auto_increment_increment( "auto_increment_increment", "Auto-increment columns are incremented by this", @@ -446,7 +585,7 @@ static bool event_scheduler_check(sys_var *self, THD *thd, set_var *var) } static bool event_scheduler_update(sys_var *self, THD *thd, enum_var_type type) { - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); /* Events::start() is heavyweight. In particular it creates a new THD, which takes LOCK_global_system_variables internally. @@ -457,9 +596,9 @@ static bool event_scheduler_update(sys_var *self, THD *thd, enum_var_type type) bool ret= Events::opt_event_scheduler == Events::EVENTS_ON ? Events::start() : Events::stop(); - pthread_mutex_unlock(&Events::LOCK_event_metadata); - pthread_mutex_lock(&LOCK_global_system_variables); - pthread_mutex_lock(&Events::LOCK_event_metadata); + mysql_mutex_unlock(&Events::LOCK_event_metadata); + mysql_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&Events::LOCK_event_metadata); if (ret) my_error(ER_EVENT_SET_VAR_ERROR, MYF(0)); return ret; @@ -1217,7 +1356,7 @@ static bool fix_read_only(sys_var *self, THD *thd, enum_var_type type) */ read_only= opt_readonly; - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); if (lock_global_read_lock(thd)) goto end_with_mutex_unlock; @@ -1245,7 +1384,7 @@ static bool fix_read_only(sys_var *self, THD *thd, enum_var_type type) /* Release the lock */ unlock_global_read_lock(thd); end_with_mutex_unlock: - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); end: read_only= opt_readonly; DBUG_RETURN(result); @@ -2327,11 +2466,11 @@ static bool fix_log(char** logname, const char* default_logname, return true; } logger.lock_exclusive(); - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); if (enabled) reopen(*logname); logger.unlock(); - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); return false; } static void reopen_general_log(char* name) @@ -2487,7 +2626,7 @@ static bool fix_log_state(sys_var *self, THD *thd, enum_var_type type) *newvalptr= oldval; // [de]activate_log_handler works that way (sigh) - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); if (!newval) { logger.deactivate_log_handler(thd, log_type); @@ -2495,7 +2634,7 @@ static bool fix_log_state(sys_var *self, THD *thd, enum_var_type type) } else res= logger.activate_log_handler(thd, log_type); - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); return res; } @@ -2564,7 +2703,7 @@ static Sys_var_charptr Sys_slave_load_tmpdir( static bool fix_slave_net_timeout(sys_var *self, THD *thd, enum_var_type type) { - pthread_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&LOCK_active_mi); DBUG_PRINT("info", ("slave_net_timeout=%lu mi->heartbeat_period=%.3f", slave_net_timeout, (active_mi? active_mi->heartbeat_period : 0.0))); @@ -2575,7 +2714,7 @@ static bool fix_slave_net_timeout(sys_var *self, THD *thd, enum_var_type type) " exceeds the new value of `slave_net_timeout' sec." " A sensible value for the period should be" " less than the timeout."); - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&LOCK_active_mi); return false; } static Sys_var_ulong Sys_slave_net_timeout( @@ -2589,21 +2728,21 @@ static Sys_var_ulong Sys_slave_net_timeout( static bool check_slave_skip_counter(sys_var *self, THD *thd, set_var *var) { bool result= false; - pthread_mutex_lock(&LOCK_active_mi); - pthread_mutex_lock(&active_mi->rli.run_lock); + mysql_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&active_mi->rli.run_lock); if (active_mi->rli.slave_running) { my_message(ER_SLAVE_MUST_STOP, ER(ER_SLAVE_MUST_STOP), MYF(0)); result= true; } - pthread_mutex_unlock(&active_mi->rli.run_lock); - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&active_mi->rli.run_lock); + mysql_mutex_unlock(&LOCK_active_mi); return result; } static bool fix_slave_skip_counter(sys_var *self, THD *thd, enum_var_type type) { - pthread_mutex_lock(&LOCK_active_mi); - pthread_mutex_lock(&active_mi->rli.run_lock); + mysql_mutex_lock(&LOCK_active_mi); + mysql_mutex_lock(&active_mi->rli.run_lock); /* The following test should normally never be true as we test this in the check function; To be safe against multiple @@ -2611,12 +2750,12 @@ static bool fix_slave_skip_counter(sys_var *self, THD *thd, enum_var_type type) */ if (!active_mi->rli.slave_running) { - pthread_mutex_lock(&active_mi->rli.data_lock); + mysql_mutex_lock(&active_mi->rli.data_lock); active_mi->rli.slave_skip_counter= sql_slave_skip_counter; - pthread_mutex_unlock(&active_mi->rli.data_lock); + mysql_mutex_unlock(&active_mi->rli.data_lock); } - pthread_mutex_unlock(&active_mi->rli.run_lock); - pthread_mutex_unlock(&LOCK_active_mi); + mysql_mutex_unlock(&active_mi->rli.run_lock); + mysql_mutex_unlock(&LOCK_active_mi); return 0; } static Sys_var_uint Sys_slave_skip_counter( @@ -2708,7 +2847,7 @@ static bool check_locale(sys_var *self, THD *thd, set_var *var) if (!locale->errmsgs->errmsgs) { - pthread_mutex_lock(&LOCK_error_messages); + mysql_mutex_lock(&LOCK_error_messages); if (!locale->errmsgs->errmsgs && read_texts(ERRMSG_FILE, locale->errmsgs->language, &locale->errmsgs->errmsgs, @@ -2717,10 +2856,10 @@ static bool check_locale(sys_var *self, THD *thd, set_var *var) push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR, "Can't process error message file for locale '%s'", locale->name); - pthread_mutex_unlock(&LOCK_error_messages); + mysql_mutex_unlock(&LOCK_error_messages); return true; } - pthread_mutex_unlock(&LOCK_error_messages); + mysql_mutex_unlock(&LOCK_error_messages); } return false; } diff --git a/sql/sys_vars.h b/sql/sys_vars.h index bdbbcbbbd59..ccc36c72786 100644 --- a/sql/sys_vars.h +++ b/sql/sys_vars.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2002-2006 MySQL AB, 2009 Sun Microsystems, Inc. +/* Copyright (C) 2002-2006 MySQL AB, 2009-2010 Sun Microsystems, Inc. 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 @@ -107,11 +107,12 @@ public: enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=0, on_update_function on_update_func=0, - uint deprecated_version=0, const char *substitute=0) + uint deprecated_version=0, const char *substitute=0, + int parse_flag= PARSE_NORMAL) : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id, getopt.arg_type, SHOWT, def_val, lock, binlog_status_arg, on_check_func, on_update_func, deprecated_version, - substitute) + substitute, parse_flag) { option.var_type= ARGT; option.min_value= min_val; @@ -194,11 +195,11 @@ public: ulonglong def_val, PolyLock *lock, enum binlog_status_enum binlog_status_arg, on_check_function on_check_func, on_update_function on_update_func, - uint deprecated_version, const char *substitute) + uint deprecated_version, const char *substitute, int parse_flag= PARSE_NORMAL) : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id, getopt.arg_type, show_val_type_arg, def_val, lock, binlog_status_arg, on_check_func, - on_update_func, deprecated_version, substitute) + on_update_func, deprecated_version, substitute, parse_flag) { for (typelib.count= 0; values[typelib.count]; typelib.count++) /*no-op */; typelib.name=""; @@ -308,11 +309,12 @@ public: enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=0, on_update_function on_update_func=0, - uint deprecated_version=0, const char *substitute=0) + uint deprecated_version=0, const char *substitute=0, + int parse_flag= PARSE_NORMAL) : Sys_var_typelib(name_arg, comment, flag_args, off, getopt, SHOW_MY_BOOL, bool_values, def_val, lock, binlog_status_arg, on_check_func, on_update_func, - deprecated_version, substitute) + deprecated_version, substitute, parse_flag) { option.var_type= GET_BOOL; global_var(my_bool)= def_val; @@ -363,11 +365,12 @@ public: enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=0, on_update_function on_update_func=0, - uint deprecated_version=0, const char *substitute=0) + uint deprecated_version=0, const char *substitute=0, + int parse_flag= PARSE_NORMAL) : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id, getopt.arg_type, SHOW_CHAR_PTR, (intptr)def_val, lock, binlog_status_arg, on_check_func, on_update_func, - deprecated_version, substitute) + deprecated_version, substitute, parse_flag) { is_os_charset= is_os_charset_arg == IN_FS_CHARSET; /* @@ -510,11 +513,12 @@ public: enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=0, on_update_function on_update_func=0, - uint deprecated_version=0, const char *substitute=0) + uint deprecated_version=0, const char *substitute=0, + int parse_flag= PARSE_NORMAL) : sys_var(&all_sys_vars, name_arg, comment, flag_args, 0, getopt.id, getopt.arg_type, SHOW_CHAR, (intptr)def_val, lock, binlog_status_arg, on_check_func, on_update_func, - deprecated_version, substitute) + deprecated_version, substitute, parse_flag) { option.var_type= GET_NO_ARG; } bool do_check(THD *thd, set_var *var) { @@ -666,7 +670,7 @@ static bool update_buffer_size(THD *thd, KEY_CACHE *key_cache, and clear the old key cache. */ key_cache->in_init= 1; - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); key_cache->param_buff_size= 0; ha_resize_key_cache(key_cache); ha_change_key_cache(key_cache, dflt_key_cache); @@ -674,7 +678,7 @@ static bool update_buffer_size(THD *thd, KEY_CACHE *key_cache, We don't delete the key cache as some running threads my still be in the key cache code with a pointer to the deleted (empty) key cache */ - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); key_cache->in_init= 0; } return error; @@ -684,14 +688,14 @@ static bool update_buffer_size(THD *thd, KEY_CACHE *key_cache, /* If key cache didn't exist initialize it, else resize it */ key_cache->in_init= 1; - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); if (!key_cache->key_cache_inited) error= ha_init_key_cache(0, key_cache); else error= ha_resize_key_cache(key_cache); - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); key_cache->in_init= 0; return error; @@ -706,10 +710,10 @@ static bool update_keycache_param(THD *thd, KEY_CACHE *key_cache, keycache_var(key_cache, offset)= new_value; key_cache->in_init= 1; - pthread_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_global_system_variables); error= ha_resize_key_cache(key_cache); - pthread_mutex_lock(&LOCK_global_system_variables); + mysql_mutex_lock(&LOCK_global_system_variables); key_cache->in_init= 0; return error; @@ -732,10 +736,12 @@ public: enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=0, on_update_function on_update_func=0, - uint deprecated_version=0, const char *substitute=0) + uint deprecated_version=0, const char *substitute=0, + int parse_flag= PARSE_NORMAL) : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id, getopt.arg_type, SHOW_DOUBLE, def_val, lock, binlog_status_arg, - on_check_func, on_update_func, deprecated_version, substitute) + on_check_func, on_update_func, deprecated_version, substitute, + parse_flag) { option.var_type= GET_DOUBLE; option.min_value= min_val; @@ -1053,11 +1059,12 @@ public: enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=0, on_update_function on_update_func=0, - uint deprecated_version=0, const char *substitute=0) + uint deprecated_version=0, const char *substitute=0, + int parse_flag= PARSE_NORMAL) : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id, getopt.arg_type, SHOW_CHAR, (intptr)def_val, lock, binlog_status_arg, on_check_func, on_update_func, - deprecated_version, substitute), + deprecated_version, substitute, parse_flag), plugin_type(plugin_type_arg) { option.var_type= GET_STR; @@ -1165,11 +1172,12 @@ public: enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=0, on_update_function on_update_func=0, - uint deprecated_version=0, const char *substitute=0) + uint deprecated_version=0, const char *substitute=0, + int parse_flag= PARSE_NORMAL) : sys_var(&all_sys_vars, name_arg, comment, flag_args, 0, getopt.id, getopt.arg_type, SHOW_CHAR, (intptr)def_val, lock, binlog_status_arg, on_check_func, on_update_func, - deprecated_version, substitute) + deprecated_version, substitute, parse_flag) { DBUG_ASSERT(scope() == ONLY_SESSION); option.var_type= GET_NO_ARG; @@ -1383,11 +1391,12 @@ public: enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=0, on_update_function on_update_func=0, - uint deprecated_version=0, const char *substitute=0) + uint deprecated_version=0, const char *substitute=0, + int parse_flag= PARSE_NORMAL) : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id, getopt.arg_type, SHOW_CHAR, 0, lock, binlog_status_arg, on_check_func, on_update_func, - deprecated_version, substitute) + deprecated_version, substitute, parse_flag) { DBUG_ASSERT(scope() == GLOBAL); DBUG_ASSERT(getopt.id == -1); @@ -1451,11 +1460,13 @@ public: enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=0, on_update_function on_update_func=0, - uint deprecated_version=0, const char *substitute=0) + uint deprecated_version=0, const char *substitute=0, + int parse_flag= PARSE_NORMAL) : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id, getopt.arg_type, SHOW_CHAR, (intptr)def_val, lock, binlog_status_arg, on_check_func, on_update_func, - deprecated_version, substitute), name_offset(name_off) + deprecated_version, substitute, parse_flag), + name_offset(name_off) { option.var_type= GET_STR; /* @@ -1519,11 +1530,12 @@ public: enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=0, on_update_function on_update_func=0, - uint deprecated_version=0, const char *substitute=0) + uint deprecated_version=0, const char *substitute=0, + int parse_flag= PARSE_NORMAL) : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id, getopt.arg_type, SHOW_CHAR, (intptr)def_val, lock, binlog_status_arg, on_check_func, on_update_func, - deprecated_version, substitute) + deprecated_version, substitute, parse_flag) { DBUG_ASSERT(getopt.id == -1); DBUG_ASSERT(size == sizeof(Time_zone *)); diff --git a/sql/sys_vars_shared.h b/sql/sys_vars_shared.h index e996fdba52e..a8ef9034715 100644 --- a/sql/sys_vars_shared.h +++ b/sql/sys_vars_shared.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2002-2006 MySQL AB, 2009 Sun Microsystems, Inc. +/* Copyright (C) 2002-2006 MySQL AB, 2009-2010 Sun Microsystems, Inc. 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 @@ -45,22 +45,22 @@ public: class PolyLock_mutex: public PolyLock { - pthread_mutex_t *mutex; + mysql_mutex_t *mutex; public: - PolyLock_mutex(pthread_mutex_t *arg): mutex(arg) {} - void rdlock() { pthread_mutex_lock(mutex); } - void wrlock() { pthread_mutex_lock(mutex); } - void unlock() { pthread_mutex_unlock(mutex); } + PolyLock_mutex(mysql_mutex_t *arg): mutex(arg) {} + void rdlock() { mysql_mutex_lock(mutex); } + void wrlock() { mysql_mutex_lock(mutex); } + void unlock() { mysql_mutex_unlock(mutex); } }; class PolyLock_rwlock: public PolyLock { - rw_lock_t *rwlock; + mysql_rwlock_t *rwlock; public: - PolyLock_rwlock(rw_lock_t *arg): rwlock(arg) {} - void rdlock() { rw_rdlock(rwlock); } - void wrlock() { rw_wrlock(rwlock); } - void unlock() { rw_unlock(rwlock); } + PolyLock_rwlock(mysql_rwlock_t *arg): rwlock(arg) {} + void rdlock() { mysql_rwlock_rdlock(rwlock); } + void wrlock() { mysql_rwlock_wrlock(rwlock); } + void unlock() { mysql_rwlock_unlock(rwlock); } }; class AutoWLock diff --git a/sql/table.cc b/sql/table.cc index ea36a856d2c..c0c365f4901 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1,4 +1,4 @@ -/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. +/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. 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 @@ -24,6 +24,9 @@ /* INFORMATION_SCHEMA name */ LEX_STRING INFORMATION_SCHEMA_NAME= {C_STRING_WITH_LEN("information_schema")}; +/* PERFORMANCE_SCHEMA name */ +LEX_STRING PERFORMANCE_SCHEMA_DB_NAME= {C_STRING_WITH_LEN("performance_schema")}; + /* MYSQL_SCHEMA name */ LEX_STRING MYSQL_SCHEMA_NAME= {C_STRING_WITH_LEN("mysql")}; @@ -214,37 +217,35 @@ TABLE_CATEGORY get_table_category(const LEX_STRING *db, const LEX_STRING *name) if ((db->length == INFORMATION_SCHEMA_NAME.length) && (my_strcasecmp(system_charset_info, - INFORMATION_SCHEMA_NAME.str, - db->str) == 0)) - { + INFORMATION_SCHEMA_NAME.str, + db->str) == 0)) return TABLE_CATEGORY_INFORMATION; - } + + if ((db->length == PERFORMANCE_SCHEMA_DB_NAME.length) && + (my_strcasecmp(system_charset_info, + PERFORMANCE_SCHEMA_DB_NAME.str, + db->str) == 0)) + return TABLE_CATEGORY_PERFORMANCE; if ((db->length == MYSQL_SCHEMA_NAME.length) && (my_strcasecmp(system_charset_info, - MYSQL_SCHEMA_NAME.str, - db->str) == 0)) + MYSQL_SCHEMA_NAME.str, + db->str) == 0)) { if (is_system_table_name(name->str, name->length)) - { return TABLE_CATEGORY_SYSTEM; - } if ((name->length == GENERAL_LOG_NAME.length) && (my_strcasecmp(system_charset_info, - GENERAL_LOG_NAME.str, - name->str) == 0)) - { - return TABLE_CATEGORY_PERFORMANCE; - } + GENERAL_LOG_NAME.str, + name->str) == 0)) + return TABLE_CATEGORY_LOG; if ((name->length == SLOW_LOG_NAME.length) && (my_strcasecmp(system_charset_info, - SLOW_LOG_NAME.str, - name->str) == 0)) - { - return TABLE_CATEGORY_PERFORMANCE; - } + SLOW_LOG_NAME.str, + name->str) == 0)) + return TABLE_CATEGORY_LOG; } return TABLE_CATEGORY_USER; @@ -317,8 +318,8 @@ TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key, share->cached_row_logging_check= -1; memcpy((char*) &share->mem_root, (char*) &mem_root, sizeof(mem_root)); - pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST); - pthread_cond_init(&share->cond, NULL); + mysql_mutex_init(key_TABLE_SHARE_mutex, &share->mutex, MY_MUTEX_INIT_FAST); + mysql_cond_init(key_TABLE_SHARE_cond, &share->cond, NULL); } DBUG_RETURN(share); } @@ -415,13 +416,13 @@ void free_table_share(TABLE_SHARE *share) /* share->mutex is locked in release_table_share() */ while (share->waiting_on_cond) { - pthread_cond_broadcast(&share->cond); - pthread_cond_wait(&share->cond, &share->mutex); + mysql_cond_broadcast(&share->cond); + mysql_cond_wait(&share->cond, &share->mutex); } /* No thread refers to this anymore */ - pthread_mutex_unlock(&share->mutex); - pthread_mutex_destroy(&share->mutex); - pthread_cond_destroy(&share->cond); + mysql_mutex_unlock(&share->mutex); + mysql_mutex_destroy(&share->mutex); + mysql_cond_destroy(&share->cond); } my_hash_free(&share->name_hash); @@ -539,7 +540,8 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags) disk_buff= NULL; strxmov(path, share->normalized_path.str, reg_ext, NullS); - if ((file= my_open(path, O_RDONLY | O_SHARE, MYF(0))) < 0) + if ((file= mysql_file_open(key_file_frm, + path, O_RDONLY | O_SHARE, MYF(0))) < 0) { /* We don't try to open 5.0 unencoded name, if @@ -550,7 +552,7 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags) - non-encoded db or table name contain "#mysql50#" prefix. This kind of tables must have been opened only by the - my_open() above. + mysql_file_open() above. */ if (strchr(share->table_name.str, '@') || !strncmp(share->db.str, MYSQL50_TABLE_NAME_PREFIX, @@ -576,7 +578,8 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags) so no need to check the old file name. */ if (length == share->normalized_path.length || - ((file= my_open(path, O_RDONLY | O_SHARE, MYF(0))) < 0)) + ((file= mysql_file_open(key_file_frm, + path, O_RDONLY | O_SHARE, MYF(0))) < 0)) goto err_not_open; /* Unencoded 5.0 table name found */ @@ -586,7 +589,7 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags) } error= 4; - if (my_read(file, head, 64, MYF(MY_NABP))) + if (mysql_file_read(file, head, 64, MYF(MY_NABP))) goto err; if (head[0] == (uchar) 254 && head[1] == 1) @@ -639,7 +642,7 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags) thd->status_var.opened_shares++; err: - my_close(file, MYF(MY_WME)); + mysql_file_close(file, MYF(MY_WME)); err_not_open: if (error && !error_given) @@ -753,7 +756,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, /* Read keyinformation */ key_info_length= (uint) uint2korr(head+28); - my_seek(file,(ulong) uint2korr(head+6),MY_SEEK_SET,MYF(0)); + mysql_file_seek(file, (ulong) uint2korr(head+6), MY_SEEK_SET, MYF(0)); if (read_string(file,(uchar**) &disk_buff,key_info_length)) goto err; /* purecov: inspected */ if (disk_buff[0] & 0x80) @@ -857,8 +860,8 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, DBUG_PRINT("info", ("extra segment size is %u bytes", n_length)); if (!(next_chunk= buff= (uchar*) my_malloc(n_length, MYF(MY_WME)))) goto err; - if (my_pread(file, buff, n_length, record_offset + share->reclength, - MYF(MY_NABP))) + if (mysql_file_pread(file, buff, n_length, record_offset + share->reclength, + MYF(MY_NABP))) { my_free(buff, MYF(0)); goto err; @@ -1027,12 +1030,12 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, rec_buff_length))) goto err; /* purecov: inspected */ share->default_values= record; - if (my_pread(file, record, (size_t) share->reclength, - record_offset, MYF(MY_NABP))) + if (mysql_file_pread(file, record, (size_t) share->reclength, + record_offset, MYF(MY_NABP))) goto err; /* purecov: inspected */ - my_seek(file,pos,MY_SEEK_SET,MYF(0)); - if (my_read(file, head,288,MYF(MY_NABP))) + mysql_file_seek(file, pos, MY_SEEK_SET, MYF(0)); + if (mysql_file_read(file, head, 288, MYF(MY_NABP))) goto err; #ifdef HAVE_CRYPTED_FRM if (crypted) @@ -2059,11 +2062,11 @@ ulong get_form_pos(File file, uchar *head, TYPELIB *save_names) if (names) { length=uint2korr(head+4); - my_seek(file,64L,MY_SEEK_SET,MYF(0)); + mysql_file_seek(file, 64L, MY_SEEK_SET, MYF(0)); if (!(buf= (uchar*) my_malloc((size_t) length+a_length+names*4, MYF(MY_WME))) || - my_read(file, buf+a_length, (size_t) (length+names*4), - MYF(MY_NABP))) + mysql_file_read(file, buf+a_length, (size_t) (length+names*4), + MYF(MY_NABP))) { /* purecov: inspected */ x_free((uchar*) buf); /* purecov: inspected */ DBUG_RETURN(0L); /* purecov: inspected */ @@ -2101,7 +2104,7 @@ int read_string(File file, uchar**to, size_t length) x_free(*to); if (!(*to= (uchar*) my_malloc(length+1,MYF(MY_WME))) || - my_read(file, *to, length,MYF(MY_NABP))) + mysql_file_read(file, *to, length, MYF(MY_NABP))) { x_free(*to); /* purecov: inspected */ *to= 0; /* purecov: inspected */ @@ -2133,23 +2136,24 @@ ulong make_new_entry(File file, uchar *fileinfo, TYPELIB *formnames, { /* Expand file */ newpos+=IO_SIZE; int4store(fileinfo+10,newpos); - endpos=(ulong) my_seek(file,0L,MY_SEEK_END,MYF(0));/* Copy from file-end */ + /* Copy from file-end */ + endpos= (ulong) mysql_file_seek(file, 0L, MY_SEEK_END, MYF(0)); bufflength= (uint) (endpos & (IO_SIZE-1)); /* IO_SIZE is a power of 2 */ while (endpos > maxlength) { - my_seek(file,(ulong) (endpos-bufflength),MY_SEEK_SET,MYF(0)); - if (my_read(file, buff, bufflength, MYF(MY_NABP+MY_WME))) + mysql_file_seek(file, (ulong) (endpos-bufflength), MY_SEEK_SET, MYF(0)); + if (mysql_file_read(file, buff, bufflength, MYF(MY_NABP+MY_WME))) DBUG_RETURN(0L); - my_seek(file,(ulong) (endpos-bufflength+IO_SIZE),MY_SEEK_SET, - MYF(0)); - if ((my_write(file, buff,bufflength,MYF(MY_NABP+MY_WME)))) + mysql_file_seek(file, (ulong) (endpos-bufflength+IO_SIZE), MY_SEEK_SET, + MYF(0)); + if ((mysql_file_write(file, buff, bufflength, MYF(MY_NABP+MY_WME)))) DBUG_RETURN(0); endpos-=bufflength; bufflength=IO_SIZE; } bzero(buff,IO_SIZE); /* Null new block */ - my_seek(file,(ulong) maxlength,MY_SEEK_SET,MYF(0)); - if (my_write(file,buff,bufflength,MYF(MY_NABP+MY_WME))) + mysql_file_seek(file, (ulong) maxlength, MY_SEEK_SET, MYF(0)); + if (mysql_file_write(file, buff, bufflength, MYF(MY_NABP+MY_WME))) DBUG_RETURN(0L); maxlength+=IO_SIZE; /* Fix old ref */ int2store(fileinfo+6,maxlength); @@ -2168,16 +2172,17 @@ ulong make_new_entry(File file, uchar *fileinfo, TYPELIB *formnames, } else (void) strxmov((char*) buff,newname,"/",NullS); /* purecov: inspected */ - my_seek(file,63L+(ulong) n_length,MY_SEEK_SET,MYF(0)); - if (my_write(file, buff, (size_t) length+1,MYF(MY_NABP+MY_WME)) || - (names && my_write(file,(uchar*) (*formnames->type_names+n_length-1), - names*4, MYF(MY_NABP+MY_WME))) || - my_write(file, fileinfo+10, 4,MYF(MY_NABP+MY_WME))) + mysql_file_seek(file, 63L+(ulong) n_length, MY_SEEK_SET, MYF(0)); + if (mysql_file_write(file, buff, (size_t) length+1, MYF(MY_NABP+MY_WME)) || + (names && mysql_file_write(file, + (uchar*) (*formnames->type_names+n_length-1), + names*4, MYF(MY_NABP+MY_WME))) || + mysql_file_write(file, fileinfo+10, 4, MYF(MY_NABP+MY_WME))) DBUG_RETURN(0L); /* purecov: inspected */ int2store(fileinfo+8,names+1); int2store(fileinfo+4,n_length+length); - (void) my_chsize(file, newpos, 0, MYF(MY_WME));/* Append file with '\0' */ + (void) mysql_file_chsize(file, newpos, 0, MYF(MY_WME));/* Append file with '\0' */ DBUG_RETURN(newpos); } /* make_new_entry */ @@ -2459,7 +2464,8 @@ File create_frm(THD *thd, const char *name, const char *db, if (create_info->min_rows > UINT_MAX32) create_info->min_rows= UINT_MAX32; - if ((file= my_create(name, CREATE_MODE, create_flags, MYF(0))) >= 0) + if ((file= mysql_file_create(key_file_frm, + name, CREATE_MODE, create_flags, MYF(0))) >= 0) { uint key_length, tmp_key_length, tmp, csid; bzero((char*) fileinfo,64); @@ -2529,10 +2535,10 @@ File create_frm(THD *thd, const char *name, const char *db, bzero(fill,IO_SIZE); for (; length > IO_SIZE ; length-= IO_SIZE) { - if (my_write(file,fill, IO_SIZE, MYF(MY_WME | MY_NABP))) + if (mysql_file_write(file, fill, IO_SIZE, MYF(MY_WME | MY_NABP))) { - (void) my_close(file,MYF(0)); - (void) my_delete(name,MYF(0)); + (void) mysql_file_close(file, MYF(0)); + (void) mysql_file_delete(key_file_frm, name, MYF(0)); return(-1); } } @@ -2571,7 +2577,7 @@ rename_file_ext(const char * from,const char * to,const char * ext) char from_b[FN_REFLEN],to_b[FN_REFLEN]; (void) strxmov(from_b,from,ext,NullS); (void) strxmov(to_b,to,ext,NullS); - return (my_rename(from_b,to_b,MYF(MY_WME))); + return (mysql_file_rename(key_file_frm, from_b, to_b, MYF(MY_WME))); } @@ -3935,7 +3941,7 @@ const char *Natural_join_column::db_name() DBUG_ASSERT(!strcmp(table_ref->db, table_ref->table->s->db.str) || (table_ref->schema_table && - is_schema_db(table_ref->table->s->db.str))); + is_infoschema_db(table_ref->table->s->db.str))); return table_ref->db; } @@ -4153,7 +4159,7 @@ const char *Field_iterator_table_ref::get_db_name() */ DBUG_ASSERT(!strcmp(table_ref->db, table_ref->table->s->db.str) || (table_ref->schema_table && - is_schema_db(table_ref->table->s->db.str))); + is_infoschema_db(table_ref->table->s->db.str))); return table_ref->db; } diff --git a/sql/table.h b/sql/table.h index e2f47c9c588..b2b84ed283d 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1,7 +1,7 @@ #ifndef TABLE_INCLUDED #define TABLE_INCLUDED -/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. +/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. 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 @@ -16,7 +16,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - /* Structs that defines the TABLE */ class Item; /* Needed by ORDER */ @@ -28,6 +27,8 @@ class st_select_lex; class partition_info; class COND_EQUAL; class Security_context; +class ACL_internal_schema_access; +class ACL_internal_table_access; /*************************************************************************/ @@ -71,6 +72,25 @@ typedef struct st_order { } ORDER; /** + State information for internal tables grants. + This structure is part of the TABLE_LIST, and is updated + during the ACL check process. + @sa GRANT_INFO +*/ +struct st_grant_internal_info +{ + /** True if the internal lookup by schema name was done. */ + bool m_schema_lookup_done; + /** Cached internal schema access. */ + const ACL_internal_schema_access *m_schema_access; + /** True if the internal lookup by table name was done. */ + bool m_table_lookup_done; + /** Cached internal table access. */ + const ACL_internal_table_access *m_table_access; +}; +typedef struct st_grant_internal_info GRANT_INTERNAL_INFO; + +/** @brief The current state of the privilege checking process for the current user, SQL statement and SQL object. @@ -131,6 +151,8 @@ typedef struct st_grant_info check access rights to the underlying tables of a view. */ ulong orig_want_privilege; + /** The grant state for internal tables. */ + GRANT_INTERNAL_INFO m_internal; } GRANT_INFO; enum tmp_table_type @@ -247,7 +269,7 @@ enum enum_table_category - LOCK TABLE t FOR READ/WRITE - FLUSH TABLES WITH READ LOCK - SET GLOBAL READ_ONLY = ON - as there is no point in locking explicitely + as there is no point in locking explicitly an INFORMATION_SCHEMA table. Nothing is directly written to information schema tables. Note that this value is not used currently, @@ -262,16 +284,16 @@ enum enum_table_category TABLE_CATEGORY_INFORMATION=4, /** - Performance schema tables. + Log tables. These tables are an interface provided by the system - to inspect the system performance data. + to inspect the system logs. These tables do *not* honor: - LOCK TABLE t FOR READ/WRITE - FLUSH TABLES WITH READ LOCK - SET GLOBAL READ_ONLY = ON - as there is no point in locking explicitely - a PERFORMANCE_SCHEMA table. - An example of PERFORMANCE_SCHEMA tables are: + as there is no point in locking explicitly + a LOG table. + An example of LOG tables are: - mysql.slow_log - mysql.general_log, which *are* updated even when there is either @@ -279,9 +301,31 @@ enum enum_table_category User queries do not write directly to these tables (there are exceptions for log tables). The server implementation perform writes. + Log tables are cached in the table cache. + */ + TABLE_CATEGORY_LOG=5, + + /** + Performance schema tables. + These tables are an interface provided by the system + to inspect the system performance data. + These tables do *not* honor: + - LOCK TABLE t FOR READ/WRITE + - FLUSH TABLES WITH READ LOCK + - SET GLOBAL READ_ONLY = ON + as there is no point in locking explicitly + a PERFORMANCE_SCHEMA table. + An example of PERFORMANCE_SCHEMA tables are: + - performance_schema.* + which *are* updated (but not using the handler interface) + even when there is either + a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect. + User queries do not write directly to these tables + (there are exceptions for SETUP_* tables). + The server implementation perform writes. Performance tables are cached in the table cache. */ - TABLE_CATEGORY_PERFORMANCE=5 + TABLE_CATEGORY_PERFORMANCE=6 }; typedef enum enum_table_category TABLE_CATEGORY; @@ -336,8 +380,8 @@ struct TABLE_SHARE TYPELIB keynames; /* Pointers to keynames */ TYPELIB fieldnames; /* Pointer to fieldnames */ TYPELIB *intervals; /* pointer to interval info */ - pthread_mutex_t mutex; /* For locking the share */ - pthread_cond_t cond; /* To signal that share is ready */ + mysql_mutex_t mutex; /* For locking the share */ + mysql_cond_t cond; /* To signal that share is ready */ TABLE_SHARE *next, **prev; /* Link to unused shares */ /* The following is copied to each TABLE on OPEN */ @@ -466,6 +510,8 @@ struct TABLE_SHARE void *ha_data; void (*ha_data_destroy)(void *); /* An optional destructor for ha_data */ + /** Instrumentation for this table share. */ + PSI_table_share *m_psi; /* Set share's table cache key and update its db and table name appropriately. @@ -527,7 +573,7 @@ struct TABLE_SHARE inline bool require_write_privileges() { - return (table_category == TABLE_CATEGORY_PERFORMANCE); + return (table_category == TABLE_CATEGORY_LOG); } inline ulong get_table_def_version() diff --git a/sql/tztime.cc b/sql/tztime.cc index 0784b73f353..442669d9c3d 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2004 MySQL AB +/* Copyright (C) 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -40,6 +40,7 @@ #include "tzfile.h" #include <m_string.h> #include <my_dir.h> +#include <mysql/psi/mysql_file.h> /* Now we don't use abbreviations in server but we will do this in future. @@ -156,9 +157,9 @@ tz_load(const char *name, TIME_ZONE_INFO *sp, MEM_ROOT *storage) uchar *p; int read_from_file; uint i; - FILE *file; + MYSQL_FILE *file; - if (!(file= my_fopen(name, O_RDONLY|O_BINARY, MYF(MY_WME)))) + if (!(file= mysql_file_fopen(0, name, O_RDONLY|O_BINARY, MYF(MY_WME)))) return 1; { union @@ -175,9 +176,9 @@ tz_load(const char *name, TIME_ZONE_INFO *sp, MEM_ROOT *storage) uint ttisgmtcnt; char *tzinfo_buf; - read_from_file= my_fread(file, u.buf, sizeof(u.buf), MYF(MY_WME)); + read_from_file= mysql_file_fread(file, u.buf, sizeof(u.buf), MYF(MY_WME)); - if (my_fclose(file, MYF(MY_WME)) != 0) + if (mysql_file_fclose(file, MYF(MY_WME)) != 0) return 1; if (read_from_file < (int)sizeof(struct tzhead)) @@ -1432,7 +1433,7 @@ static MEM_ROOT tz_storage; time zone in offset_tzs or creating if it didn't existed before in tz_storage. So contention is low. */ -static pthread_mutex_t tz_LOCK; +static mysql_mutex_t tz_LOCK; static bool tz_inited= 0; /* @@ -1532,6 +1533,27 @@ tz_init_table_list(TABLE_LIST *tz_tabs) } } +#ifdef HAVE_PSI_INTERFACE +static PSI_mutex_key key_tz_LOCK; + +static PSI_mutex_info all_tz_mutexes[]= +{ + { & key_tz_LOCK, "tz_LOCK", PSI_FLAG_GLOBAL} +}; + +static void init_tz_psi_keys(void) +{ + const char* category= "sql"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_tz_mutexes); + PSI_server->register_mutex(category, all_tz_mutexes, count); +} +#endif /* HAVE_PSI_INTERFACE */ + /* Initialize time zone support infrastructure. @@ -1571,6 +1593,10 @@ my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap) int res; DBUG_ENTER("my_tz_init"); +#ifdef HAVE_PSI_INTERFACE + init_tz_psi_keys(); +#endif + /* To be able to run this from boot, we allocate a temporary THD */ @@ -1594,7 +1620,7 @@ my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap) goto end; } init_sql_alloc(&tz_storage, 32 * 1024, 0); - pthread_mutex_init(&tz_LOCK, MY_MUTEX_INIT_FAST); + mysql_mutex_init(key_tz_LOCK, &tz_LOCK, MY_MUTEX_INIT_FAST); tz_inited= 1; /* Add 'SYSTEM' time zone to tz_names hash */ @@ -1776,7 +1802,7 @@ void my_tz_free() if (tz_inited) { tz_inited= 0; - pthread_mutex_destroy(&tz_LOCK); + mysql_mutex_destroy(&tz_LOCK); my_hash_free(&offset_tzs); my_hash_free(&tz_names); free_root(&tz_storage, MYF(0)); @@ -2265,7 +2291,7 @@ my_tz_find(THD *thd, const String *name) if (!name) DBUG_RETURN(0); - pthread_mutex_lock(&tz_LOCK); + mysql_mutex_lock(&tz_LOCK); if (!str_to_offset(name->ptr(), name->length(), &offset)) { @@ -2308,7 +2334,7 @@ my_tz_find(THD *thd, const String *name) } } - pthread_mutex_unlock(&tz_LOCK); + mysql_mutex_unlock(&tz_LOCK); DBUG_RETURN(result_tz); } diff --git a/sql/unireg.cc b/sql/unireg.cc index 8328cf735b5..b20e759efbb 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -258,27 +258,27 @@ bool mysql_create_frm(THD *thd, const char *file_name, #endif int2store(fileinfo+59,db_file->extra_rec_buf_length()); - if (my_pwrite(file, fileinfo, 64, 0L, MYF_RW) || - my_pwrite(file, keybuff, key_info_length, - (ulong) uint2korr(fileinfo+6),MYF_RW)) + if (mysql_file_pwrite(file, fileinfo, 64, 0L, MYF_RW) || + mysql_file_pwrite(file, keybuff, key_info_length, + (ulong) uint2korr(fileinfo+6), MYF_RW)) goto err; - my_seek(file, - (ulong) uint2korr(fileinfo+6)+ (ulong) key_buff_length, - MY_SEEK_SET,MYF(0)); + mysql_file_seek(file, + (ulong) uint2korr(fileinfo+6) + (ulong) key_buff_length, + MY_SEEK_SET, MYF(0)); if (make_empty_rec(thd,file,ha_legacy_type(create_info->db_type), create_info->table_options, create_fields,reclength, data_offset, db_file)) goto err; int2store(buff, create_info->connect_string.length); - if (my_write(file, (const uchar*)buff, 2, MYF(MY_NABP)) || - my_write(file, (const uchar*)create_info->connect_string.str, + if (mysql_file_write(file, (const uchar*)buff, 2, MYF(MY_NABP)) || + mysql_file_write(file, (const uchar*)create_info->connect_string.str, create_info->connect_string.length, MYF(MY_NABP))) goto err; int2store(buff, str_db_type.length); - if (my_write(file, (const uchar*)buff, 2, MYF(MY_NABP)) || - my_write(file, (const uchar*)str_db_type.str, + if (mysql_file_write(file, (const uchar*)buff, 2, MYF(MY_NABP)) || + mysql_file_write(file, (const uchar*)str_db_type.str, str_db_type.length, MYF(MY_NABP))) goto err; @@ -287,32 +287,32 @@ bool mysql_create_frm(THD *thd, const char *file_name, { char auto_partitioned= part_info->is_auto_partitioned ? 1 : 0; int4store(buff, part_info->part_info_len); - if (my_write(file, (const uchar*)buff, 4, MYF_RW) || - my_write(file, (const uchar*)part_info->part_info_string, + if (mysql_file_write(file, (const uchar*)buff, 4, MYF_RW) || + mysql_file_write(file, (const uchar*)part_info->part_info_string, part_info->part_info_len + 1, MYF_RW) || - my_write(file, (const uchar*)&auto_partitioned, 1, MYF_RW)) + mysql_file_write(file, (const uchar*)&auto_partitioned, 1, MYF_RW)) goto err; } else #endif { bzero((uchar*) buff, 6); - if (my_write(file, (uchar*) buff, 6, MYF_RW)) + if (mysql_file_write(file, (uchar*) buff, 6, MYF_RW)) goto err; } for (i= 0; i < keys; i++) { if (key_info[i].parser_name) { - if (my_write(file, (const uchar*)key_info[i].parser_name->str, - key_info[i].parser_name->length + 1, MYF(MY_NABP))) + if (mysql_file_write(file, (const uchar*)key_info[i].parser_name->str, + key_info[i].parser_name->length + 1, MYF(MY_NABP))) goto err; } } - my_seek(file,filepos,MY_SEEK_SET,MYF(0)); - if (my_write(file, forminfo, 288, MYF_RW) || - my_write(file, screen_buff, info_length, MYF_RW) || + mysql_file_seek(file, filepos, MY_SEEK_SET, MYF(0)); + if (mysql_file_write(file, forminfo, 288, MYF_RW) || + mysql_file_write(file, screen_buff, info_length, MYF_RW) || pack_fields(file, create_fields, data_offset)) goto err; @@ -321,15 +321,15 @@ bool mysql_create_frm(THD *thd, const char *file_name, { char tmp=2,*disk_buff=0; SQL_CRYPT *crypted=new SQL_CRYPT(create_info->password); - if (!crypted || my_pwrite(file,&tmp,1,26,MYF_RW)) // Mark crypted + if (!crypted || mysql_file_pwrite(file, &tmp, 1, 26, MYF_RW))// Mark crypted goto err; uint read_length=uint2korr(forminfo)-256; - my_seek(file,filepos+256,MY_SEEK_SET,MYF(0)); + mysql_file_seek(file, filepos+256, MY_SEEK_SET, MYF(0)); if (read_string(file,(uchar**) &disk_buff,read_length)) goto err; crypted->encode(disk_buff,read_length); delete crypted; - if (my_pwrite(file,disk_buff,read_length,filepos+256,MYF_RW)) + if (mysql_file_pwrite(file, disk_buff, read_length, filepos+256, MYF_RW)) { my_free(disk_buff,MYF(0)); goto err; @@ -342,11 +342,11 @@ bool mysql_create_frm(THD *thd, const char *file_name, my_free(keybuff, MYF(0)); if (opt_sync_frm && !(create_info->options & HA_LEX_CREATE_TMP_TABLE) && - (my_sync(file, MYF(MY_WME)) || + (mysql_file_sync(file, MYF(MY_WME)) || my_sync_dir_by_file(file_name, MYF(MY_WME)))) goto err2; - if (my_close(file,MYF(MY_WME))) + if (mysql_file_close(file, MYF(MY_WME))) goto err3; { @@ -371,9 +371,9 @@ err: my_free(screen_buff, MYF(0)); my_free(keybuff, MYF(0)); err2: - (void) my_close(file,MYF(MY_WME)); + (void) mysql_file_close(file, MYF(MY_WME)); err3: - my_delete(file_name,MYF(0)); + mysql_file_delete(key_file_frm, file_name, MYF(0)); DBUG_RETURN(1); } /* mysql_create_frm */ @@ -426,7 +426,7 @@ int rea_create_table(THD *thd, const char *path, err_handler: (void) file->ha_create_handler_files(path, NULL, CHF_DELETE_FLAG, create_info); - my_delete(frm_name, MYF(0)); + mysql_file_delete(key_file_frm, frm_name, MYF(0)); DBUG_RETURN(1); } /* rea_create_table */ @@ -825,13 +825,13 @@ static bool pack_fields(File file, List<Create_field> &create_fields, int2store(buff+15, field->comment.length); comment_length+= field->comment.length; set_if_bigger(int_count,field->interval_id); - if (my_write(file, buff, FCOMP, MYF_RW)) + if (mysql_file_write(file, buff, FCOMP, MYF_RW)) DBUG_RETURN(1); } /* Write fieldnames */ buff[0]=(uchar) NAMES_SEP_CHAR; - if (my_write(file, buff, 1, MYF_RW)) + if (mysql_file_write(file, buff, 1, MYF_RW)) DBUG_RETURN(1); i=0; it.rewind(); @@ -841,7 +841,7 @@ static bool pack_fields(File file, List<Create_field> &create_fields, *pos++=NAMES_SEP_CHAR; if (i == create_fields.elements-1) *pos++=0; - if (my_write(file, buff, (size_t) (pos-(char*) buff),MYF_RW)) + if (mysql_file_write(file, buff, (size_t) (pos-(char*) buff), MYF_RW)) DBUG_RETURN(1); i++; } @@ -901,7 +901,7 @@ static bool pack_fields(File file, List<Create_field> &create_fields, tmp.append('\0'); // End of intervall } } - if (my_write(file,(uchar*) tmp.ptr(),tmp.length(),MYF_RW)) + if (mysql_file_write(file, (uchar*) tmp.ptr(), tmp.length(), MYF_RW)) DBUG_RETURN(1); } if (comment_length) @@ -911,8 +911,8 @@ static bool pack_fields(File file, List<Create_field> &create_fields, while ((field=it++)) { if (field->comment.length) - if (my_write(file, (uchar*) field->comment.str, field->comment.length, - MYF_RW)) + if (mysql_file_write(file, (uchar*) field->comment.str, + field->comment.length, MYF_RW)) DBUG_RETURN(1); } } @@ -1035,7 +1035,7 @@ static bool make_empty_rec(THD *thd, File file,enum legacy_db_type table_type, if (null_count & 7) *(null_pos + null_count / 8)|= ~(((uchar) 1 << (null_count & 7)) - 1); - error= my_write(file, buff, (size_t) reclength,MYF_RW) != 0; + error= mysql_file_write(file, buff, (size_t) reclength, MYF_RW) != 0; err: my_free(buff, MYF(MY_FAE)); diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index d09eefda463..1117e8fff15 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -1709,7 +1709,7 @@ int ha_myisam::info(uint flag) /* Update share */ if (share->tmp_table == NO_TMP_TABLE) - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->mutex); share->keys_in_use.set_prefix(share->keys); share->keys_in_use.intersect_extended(misam_info.key_map); share->keys_for_keyread.intersect(share->keys_in_use); @@ -1719,7 +1719,7 @@ int ha_myisam::info(uint flag) (char*) misam_info.rec_per_key, sizeof(table->key_info[0].rec_per_key[0])*share->key_parts); if (share->tmp_table == NO_TMP_TABLE) - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->mutex); /* Set data_file_name and index_file_name to point at the symlink value |