summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <serg@sergbook.mysql.com>2007-04-15 15:47:27 +0200
committerunknown <serg@sergbook.mysql.com>2007-04-15 15:47:27 +0200
commitadd378761542ade65340b9477ed298e9a1677b10 (patch)
tree4d70d7272be7222d34c74f20067114045c5e0253
parent18f02e0aeb39f9ef25c9b0cfd126c5694ba21996 (diff)
downloadmariadb-git-add378761542ade65340b9477ed298e9a1677b10.tar.gz
more wl#2936 fixes: removed implicit ha_thd() calls (too error-prone),
fixed an assert crash include/mysql/plugin.h: more wl#2936 fixes: no implicit ha_thd() calls mysql-test/mysql-test-run.pl: don't load system-wide plugins mysql-test/r/partition_innodb.result: fix the test mysql-test/t/partition_innodb.test: fix the test sql/handler.cc: more wl#2936 fixes: no implicit ha_thd() calls sql/handler.h: more wl#2936 fixes: no implicit ha_thd() calls sql/sql_class.cc: more wl#2936 fixes: no implicit ha_thd() calls sql/sql_plugin.cc: more wl#2936 fixes: assert crash storage/innobase/handler/ha_innodb.cc: more wl#2936 fixes: no implicit ha_thd() calls
-rw-r--r--include/mysql/plugin.h1
-rwxr-xr-xmysql-test/mysql-test-run.pl7
-rw-r--r--mysql-test/r/partition_innodb.result5
-rw-r--r--mysql-test/t/partition_innodb.test1
-rw-r--r--sql/handler.cc14
-rw-r--r--sql/handler.h4
-rw-r--r--sql/sql_class.cc16
-rw-r--r--sql/sql_plugin.cc10
-rw-r--r--storage/innobase/handler/ha_innodb.cc55
9 files changed, 60 insertions, 53 deletions
diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h
index d15302dc256..751ce516a39 100644
--- a/include/mysql/plugin.h
+++ b/include/mysql/plugin.h
@@ -651,6 +651,7 @@ long long thd_test_options(const MYSQL_THD thd, long long test_options);
int thd_sql_command(const MYSQL_THD thd);
const char *thd_proc_info(MYSQL_THD thd, const char *info);
void **thd_ha_data(const MYSQL_THD thd, const struct handlerton *hton);
+int thd_tx_isolation(const MYSQL_THD thd);
char *thd_security_context(MYSQL_THD thd, char *buffer, unsigned int length,
unsigned int max_query_len);
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index aabd15838e2..fbd1ed4df5b 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -1330,10 +1330,13 @@ sub collect_mysqld_features () {
my $found_variable_list_start= 0;
#
- # Execute "mysqld --no-defaults --help --verbose" to get a
+ # Execute "mysqld --help --verbose" to get a list
# of all features and settings
#
- my $list= `$exe_mysqld --no-defaults --verbose --help`;
+ # --no-defaults and --skip-grant-tables are to avoid loading
+ # system-wide configs and plugins
+ #
+ my $list= `$exe_mysqld --no-defaults --skip-grant-tables --verbose --help`;
foreach my $line (split('\n', $list))
{
diff --git a/mysql-test/r/partition_innodb.result b/mysql-test/r/partition_innodb.result
index 799f1b2c76f..96eee40b9f6 100644
--- a/mysql-test/r/partition_innodb.result
+++ b/mysql-test/r/partition_innodb.result
@@ -66,10 +66,11 @@ engine = innodb
partition by list (a)
(partition p0 values in (0));
alter table t1 engine = x;
-ERROR 42000: Unknown table engine 'x'
+Warnings:
+Warning 1266 Using storage engine MyISAM for table 't1'
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL
-) ENGINE=InnoDB DEFAULT CHARSET=latin1 /*!50100 PARTITION BY LIST (a) (PARTITION p0 VALUES IN (0) ENGINE = InnoDB) */
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 /*!50100 PARTITION BY LIST (a) (PARTITION p0 VALUES IN (0) ENGINE = MyISAM) */
drop table t1;
diff --git a/mysql-test/t/partition_innodb.test b/mysql-test/t/partition_innodb.test
index 9f8792c924f..782e204742f 100644
--- a/mysql-test/t/partition_innodb.test
+++ b/mysql-test/t/partition_innodb.test
@@ -71,7 +71,6 @@ engine = innodb
partition by list (a)
(partition p0 values in (0));
---error ER_UNKNOWN_STORAGE_ENGINE
alter table t1 engine = x;
show create table t1;
drop table t1;
diff --git a/sql/handler.cc b/sql/handler.cc
index b4fc7db3809..583f23b5a93 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -1491,19 +1491,9 @@ void handler::ha_statistic_increment(ulong SSV::*offset) const
statistic_increment(table->in_use->status_var.*offset, &LOCK_status);
}
-enum enum_tx_isolation handler::ha_tx_isolation(void) const
+void **handler::ha_data(THD *thd) const
{
- return (enum_tx_isolation) ha_thd()->variables.tx_isolation;
-}
-
-uint handler::ha_sql_command(void) const
-{
- return (uint) ha_thd()->lex->sql_command;
-}
-
-void **handler::ha_data(void) const
-{
- return (void **) ha_thd()->ha_data + ht->slot;
+ return (void **) thd->ha_data + ht->slot;
}
THD *handler::ha_thd(void) const
diff --git a/sql/handler.h b/sql/handler.h
index 076fffe142e..39751f53b15 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -898,9 +898,7 @@ class handler :public Sql_alloc
virtual ulonglong table_flags(void) const =0;
void ha_statistic_increment(ulong SSV::*offset) const;
- enum enum_tx_isolation ha_tx_isolation(void) const;
- uint ha_sql_command(void) const;
- void **ha_data(void) const;
+ void **ha_data(THD *) const;
THD *ha_thd(void) const;
ha_rows estimation_rows_to_insert;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 20d12a4bd62..170deccea92 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -211,18 +211,24 @@ int thd_sql_command(const THD *thd)
return (int) thd->lex->sql_command;
}
+extern "C"
+int thd_tx_isolation(const THD *thd)
+{
+ return (int) thd->variables.tx_isolation;
+}
+
/*
Dumps a text description of a thread, its security context
(user, host) and the current query.
-
+
SYNOPSIS
thd_security_context()
thd current thread context
buffer pointer to preferred result buffer
length length of buffer
max_query_len how many chars of query to copy (0 for all)
-
+
RETURN VALUES
pointer to string
*/
@@ -234,13 +240,13 @@ char *thd_security_context(THD *thd, char *buffer, unsigned int length,
const Security_context *sctx= &thd->main_security_ctx;
char header[64];
int len;
-
- len= my_snprintf(header, sizeof(header),
+
+ len= my_snprintf(header, sizeof(header),
"MySQL thread id %lu, query id %lu",
thd->thread_id, (ulong) thd->query_id);
str.length(0);
str.append(header, len);
-
+
if (sctx->host)
{
str.append(' ');
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index a2c3c2060e7..a72725fae8c 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -1323,6 +1323,13 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv)
table= tables.table;
init_read_record(&read_record_info, new_thd, table, NULL, 1, 0);
table->use_all_columns();
+ /*
+ 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
+ the mutex here to satisfy the assert
+ */
+ pthread_mutex_lock(&LOCK_plugin);
while (!(error= read_record_info.read_record(&read_record_info)))
{
DBUG_PRINT("info", ("init plugin record"));
@@ -1333,11 +1340,12 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv)
LEX_STRING name= {(char *)str_name.ptr(), str_name.length()};
LEX_STRING dl= {(char *)str_dl.ptr(), str_dl.length()};
- free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
if (plugin_add(tmp_root, &name, &dl, argc, argv, REPORT_TO_LOG))
sql_print_warning("Couldn't load plugin named '%s' with soname '%s'.",
str_name.c_ptr(), str_dl.c_ptr());
+ free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
}
+ pthread_mutex_unlock(&LOCK_plugin);
if (error > 0)
sql_print_error(ER(ER_GET_ERRNO), my_errno);
end_read_record(&read_record_info);
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index b4b6ad2842a..018051ed8b1 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -3220,15 +3220,16 @@ ha_innobase::write_row(
longlong auto_inc;
longlong dummy;
ibool auto_inc_used= FALSE;
+ THD *thd= ha_thd();
DBUG_ENTER("ha_innobase::write_row");
if (prebuilt->trx !=
- *(trx_t**) ha_data()) {
+ *(trx_t**) ha_data(thd)) {
sql_print_error("The transaction object for the table handle is at "
"%p, but for the current thread it is at %p",
prebuilt->trx,
- *(trx_t**) ha_data());
+ *(trx_t**) ha_data(thd));
fputs("InnoDB: Dump of 200 bytes around prebuilt: ", stderr);
ut_print_buf(stderr, ((const byte*)prebuilt) - 100, 200);
@@ -3236,7 +3237,7 @@ ha_innobase::write_row(
"InnoDB: Dump of 200 bytes around transaction.all: ",
stderr);
ut_print_buf(stderr,
- ((byte*)(*(trx_t**) ha_data())) - 100,
+ ((byte*)(*(trx_t**) ha_data(thd))) - 100,
200);
putc('\n', stderr);
ut_error;
@@ -3247,10 +3248,10 @@ ha_innobase::write_row(
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
table->timestamp_field->set_time();
- if ((ha_sql_command() == SQLCOM_ALTER_TABLE
- || ha_sql_command() == SQLCOM_OPTIMIZE
- || ha_sql_command() == SQLCOM_CREATE_INDEX
- || ha_sql_command() == SQLCOM_DROP_INDEX)
+ if ((thd_sql_command(thd) == SQLCOM_ALTER_TABLE
+ || thd_sql_command(thd) == SQLCOM_OPTIMIZE
+ || thd_sql_command(thd) == SQLCOM_CREATE_INDEX
+ || thd_sql_command(thd) == SQLCOM_DROP_INDEX)
&& num_write_row >= 10000) {
/* ALTER TABLE is COMMITted at every 10000 copied rows.
The IX table lock for the original table has to be re-issued.
@@ -3409,9 +3410,9 @@ no_commit:
performing those statements. */
if (error == DB_DUPLICATE_KEY && auto_inc_used
- && (ha_sql_command() == SQLCOM_REPLACE
- || ha_sql_command() == SQLCOM_REPLACE_SELECT
- || (ha_sql_command() == SQLCOM_LOAD
+ && (thd_sql_command(thd) == SQLCOM_REPLACE
+ || thd_sql_command(thd) == SQLCOM_REPLACE_SELECT
+ || (thd_sql_command(thd) == SQLCOM_LOAD
&& prebuilt->trx->allow_duplicates
&& prebuilt->trx->replace_duplicates))) {
@@ -3613,7 +3614,7 @@ ha_innobase::update_row(
DBUG_ENTER("ha_innobase::update_row");
ut_a(prebuilt->trx ==
- *(trx_t**) ha_data());
+ *(trx_t**) ha_data(ha_thd()));
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
table->timestamp_field->set_time();
@@ -3674,7 +3675,7 @@ ha_innobase::delete_row(
DBUG_ENTER("ha_innobase::delete_row");
ut_a(prebuilt->trx ==
- *(trx_t**) ha_data());
+ *(trx_t**) ha_data(ha_thd()));
if (last_query_id != user_thd->query_id) {
prebuilt->sql_stat_start = TRUE;
@@ -3772,7 +3773,7 @@ ha_innobase::try_semi_consistent_read(bool yes)
row_prebuilt_t* prebuilt = (row_prebuilt_t*) innobase_prebuilt;
ut_a(prebuilt->trx ==
- *(trx_t**) ha_data());
+ *(trx_t**) ha_data(ha_thd()));
/* Row read type is set to semi consistent read if this was
requested by the MySQL and either innodb_locks_unsafe_for_binlog
@@ -3939,7 +3940,7 @@ ha_innobase::index_read(
DBUG_ENTER("index_read");
ut_a(prebuilt->trx ==
- *(trx_t**) ha_data());
+ *(trx_t**) ha_data(ha_thd()));
ha_statistic_increment(&SSV::ha_read_key_count);
@@ -4052,7 +4053,7 @@ ha_innobase::change_active_index(
ut_ad(user_thd == current_thd);
ut_a(prebuilt->trx ==
- *(trx_t**) ha_data());
+ *(trx_t**) ha_data(ha_thd()));
active_index = keynr;
@@ -4142,7 +4143,7 @@ ha_innobase::general_fetch(
DBUG_ENTER("general_fetch");
ut_a(prebuilt->trx ==
- *(trx_t**) ha_data());
+ *(trx_t**) ha_data(ha_thd()));
innodb_srv_conc_enter_innodb(prebuilt->trx);
@@ -4371,7 +4372,7 @@ ha_innobase::rnd_pos(
ha_statistic_increment(&SSV::ha_read_rnd_count);
ut_a(prebuilt->trx ==
- *(trx_t**) ha_data());
+ *(trx_t**) ha_data(ha_thd()));
if (prebuilt->clust_index_was_generated) {
/* No primary key was defined for the table and we
@@ -4421,7 +4422,7 @@ ha_innobase::position(
uint len;
ut_a(prebuilt->trx ==
- *(trx_t**) ha_data());
+ *(trx_t**) ha_data(ha_thd()));
if (prebuilt->clust_index_was_generated) {
/* No primary key was defined for the table and we
@@ -4921,7 +4922,7 @@ ha_innobase::discard_or_import_tablespace(
ut_a(prebuilt->trx && prebuilt->trx->magic_n == TRX_MAGIC_N);
ut_a(prebuilt->trx ==
- *(trx_t**) ha_data());
+ *(trx_t**) ha_data(ha_thd()));
dict_table = prebuilt->table;
trx = prebuilt->trx;
@@ -4956,7 +4957,7 @@ ha_innobase::delete_all_rows(void)
update_thd(thd);
- if (ha_sql_command() == SQLCOM_TRUNCATE) {
+ if (thd_sql_command(thd) == SQLCOM_TRUNCATE) {
/* Truncate the table in InnoDB */
error = row_truncate_table_for_mysql(prebuilt->table, prebuilt->trx);
@@ -5250,7 +5251,7 @@ ha_innobase::records_in_range(
DBUG_ENTER("records_in_range");
ut_a(prebuilt->trx ==
- *(trx_t**) ha_data());
+ *(trx_t**) ha_data(ha_thd()));
prebuilt->trx->op_info = (char*)"estimating records in index range";
@@ -5686,7 +5687,7 @@ ha_innobase::check(
ut_a(prebuilt->trx && prebuilt->trx->magic_n == TRX_MAGIC_N);
ut_a(prebuilt->trx ==
- *(trx_t**) ha_data());
+ *(trx_t**) ha_data(ha_thd()));
if (prebuilt->mysql_template == NULL) {
/* Build the template; we will use a dummy template
@@ -5988,7 +5989,7 @@ ha_innobase::can_switch_engines(void)
DBUG_ENTER("ha_innobase::can_switch_engines");
ut_a(prebuilt->trx ==
- *(trx_t**) ha_data());
+ *(trx_t**) ha_data(ha_thd()));
prebuilt->trx->op_info =
"determining if there are foreign key constraints";
@@ -6154,7 +6155,7 @@ ha_innobase::start_stmt(
prebuilt->select_lock_type = LOCK_X;
} else {
if (trx->isolation_level != TRX_ISO_SERIALIZABLE
- && ha_sql_command() == SQLCOM_SELECT
+ && thd_sql_command(thd) == SQLCOM_SELECT
&& lock_type == TL_READ) {
/* For other than temporary tables, we obtain
@@ -6296,7 +6297,7 @@ ha_innobase::external_lock(
if (prebuilt->select_lock_type != LOCK_NONE) {
if (thd_in_lock_tables(thd) &&
- ha_sql_command() == SQLCOM_LOCK_TABLES &&
+ thd_sql_command(thd) == SQLCOM_LOCK_TABLES &&
THDVAR(thd, table_locks) &&
thd_test_options(thd, OPTION_NOT_AUTOCOMMIT)) {
@@ -6768,12 +6769,12 @@ ha_innobase::store_lock(
if (lock_type != TL_IGNORE
&& trx->n_mysql_tables_in_use == 0) {
trx->isolation_level = innobase_map_isolation_level(
- ha_tx_isolation());
+ (enum_tx_isolation)thd_tx_isolation(thd));
}
DBUG_ASSERT(thd == current_thd);
const bool in_lock_tables = thd_in_lock_tables(thd);
- const uint sql_command = ha_sql_command();
+ const uint sql_command = thd_sql_command(thd);
if (sql_command == SQLCOM_DROP_TABLE) {