2013-12-11 00:31:04 +09:00
|
|
|
/* Copyright (C) 2013 Kentoku Shiba
|
|
|
|
|
|
|
|
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
|
2017-02-10 13:26:55 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */
|
2013-12-11 00:31:04 +09:00
|
|
|
|
|
|
|
#define MYSQL_SERVER 1
|
2014-10-09 10:30:11 +02:00
|
|
|
#include "my_config.h"
|
2013-12-11 00:31:04 +09:00
|
|
|
#include "mysql_version.h"
|
|
|
|
#include "mysql/plugin.h"
|
|
|
|
#include "sql_class.h"
|
|
|
|
#include "sql_show.h"
|
|
|
|
|
|
|
|
static const LEX_STRING metadata_lock_info_lock_name[] = {
|
|
|
|
{ C_STRING_WITH_LEN("Global read lock") },
|
|
|
|
{ C_STRING_WITH_LEN("Schema metadata lock") },
|
|
|
|
{ C_STRING_WITH_LEN("Table metadata lock") },
|
|
|
|
{ C_STRING_WITH_LEN("Stored function metadata lock") },
|
|
|
|
{ C_STRING_WITH_LEN("Stored procedure metadata lock") },
|
|
|
|
{ C_STRING_WITH_LEN("Trigger metadata lock") },
|
|
|
|
{ C_STRING_WITH_LEN("Event metadata lock") },
|
|
|
|
{ C_STRING_WITH_LEN("Commit lock") },
|
|
|
|
{ C_STRING_WITH_LEN("User lock") },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const LEX_STRING metadata_lock_info_lock_mode[] = {
|
|
|
|
{ C_STRING_WITH_LEN("MDL_INTENTION_EXCLUSIVE") },
|
|
|
|
{ C_STRING_WITH_LEN("MDL_SHARED") },
|
|
|
|
{ C_STRING_WITH_LEN("MDL_SHARED_HIGH_PRIO") },
|
|
|
|
{ C_STRING_WITH_LEN("MDL_SHARED_READ") },
|
|
|
|
{ C_STRING_WITH_LEN("MDL_SHARED_WRITE") },
|
2014-02-05 19:01:59 +02:00
|
|
|
{ C_STRING_WITH_LEN("MDL_SHARED_UPGRADABLE") },
|
MDEV-11227 - mysqlimport -l doesn't issue UNLOCK TABLES
Implementation of MDEV-7660 introduced unwanted incompatible change:
modifications under LOCK TABLES with autocommit enabled are rolled back on
disconnect. Previously everything was committed, because LOCK TABLES didn't
adjust autocommit setting.
This patch restores original behavior by reverting some changes done in
MDEV-7660:
- sql/sql_parse.cc: do not reset autocommit on LOCK TABLES
- sql/sql_base.cc: do not set autocommit on UNLOCK TABLES
- test cases: main.lock_tables_lost_commit, main.partition_explicit_prune,
rpl.rpl_switch_stm_row_mixed, tokudb.nested_txn_implicit_commit,
tokudb_bugs.db806
But it makes InnoDB tables under LOCK TABLES ... READ [LOCAL] not protected
against DML. To restore protection some changes from WL#6671 were merged,
specifically MDL_SHARED_READ_ONLY and test cases.
WL#6671 merge highlights:
- Not all tests merged.
- In MySQL LOCK TABLES ... READ acquires MDL_SHARED_READ_ONLY for all engines,
in MariaDB MDL_SHARED_READ is always acquired first and then upgraded to
MDL_SHARED_READ_ONLY for InnoDB only.
- The above allows us to omit MDL_SHARED_WRITE_LOW_PRIO implementation in
MariaDB, which is rather useless with InnoDB. In MySQL it is needed to
preserve locking behavior between low priority writes and LOCK TABLES ... READ
for non-InnoDB engines (covered by sys_vars.sql_low_priority_updates_func).
- Omitted HA_NO_READ_LOCAL_LOCK, we rely on lock_count() instead.
- Omitted "piglets": in MariaDB stream of DML against InnoDB table may lead to
concurrent LOCK TABLES ... READ starvation.
- HANDLER ... OPEN acquires MDL_SHARED_READ instead of MDL_SHARED in MariaDB.
- Omitted SNRW->X MDL lock upgrade for IMPORT/DISCARD TABLESPAECE under LOCK
TABLES.
- Omitted strong locks for views, triggers and SP under LOCK TABLES.
- Omitted IX schema lock for LOCK TABLES READ.
- Omitted deadlock weight juggling for LOCK TABLES.
Full WL#6671 merge status:
- innodb.innodb-lock: fully merged
- main.alter_table: not merged due to different HANDLER solution
- main.debug_sync: fully merged
- main.handler_innodb: not merged due to different HANDLER solution
- main.handler_myisam: not merged due to different HANDLER solution
- main.innodb_mysql_lock: fully merged
- main.insert_notembedded: fully merged
- main.lock: not merged (due to no strong locks for views)
- main.lock_multi: not merged
- main.lock_sync: fully merged (partially in MDEV-7660)
- main.mdl_sync: not merged
- main.partition_debug_sync: not merged due to different HANDLER solution
- main.status: fully merged
- main.view: fully merged
- perfschema.mdl_func: not merged (no such test in MariaDB)
- perfschema.table_aggregate_global_2u_2t: not merged (didn't fail in MariaDB)
- perfschema.table_aggregate_global_2u_3t: not merged (didn't fail in MariaDB)
- perfschema.table_aggregate_global_4u_2t: not merged (didn't fail in MariaDB)
- perfschema.table_aggregate_global_4u_3t: not merged (didn't fail in MariaDB)
- perfschema.table_aggregate_hist_2u_2t: not merged (didn't fail in MariaDB)
- perfschema.table_aggregate_hist_2u_3t: not merged (didn't fail in MariaDB)
- perfschema.table_aggregate_hist_4u_2t: not merged (didn't fail in MariaDB)
- perfschema.table_aggregate_hist_4u_3t: not merged (didn't fail in MariaDB)
- perfschema.table_aggregate_thread_2u_2t: not merged (didn't fail in MariaDB)
- perfschema.table_aggregate_thread_2u_3t: not merged (didn't fail in MariaDB)
- perfschema.table_aggregate_thread_4u_2t: not merged (didn't fail in MariaDB)
- perfschema.table_aggregate_thread_4u_3t: not merged (didn't fail in MariaDB)
- perfschema.table_lock_aggregate_global_2u_2t: not merged (didn't fail in MariaDB)
- perfschema.table_lock_aggregate_global_2u_3t: not merged (didn't fail in MariaDB)
- perfschema.table_lock_aggregate_global_4u_2t: not merged (didn't fail in MariaDB)
- perfschema.table_lock_aggregate_global_4u_3t: not merged (didn't fail in MariaDB)
- perfschema.table_lock_aggregate_hist_2u_2t: not merged (didn't fail in MariaDB)
- perfschema.table_lock_aggregate_hist_2u_3t: not merged (didn't fail in MariaDB)
- perfschema.table_lock_aggregate_hist_4u_2t: not merged (didn't fail in MariaDB)
- perfschema.table_lock_aggregate_hist_4u_3t: not merged (didn't fail in MariaDB)
- perfschema.table_lock_aggregate_thread_2u_2t: not merged (didn't fail in MariaDB)
- perfschema.table_lock_aggregate_thread_2u_3t: not merged (didn't fail in MariaDB)
- perfschema.table_lock_aggregate_thread_4u_2t: not merged (didn't fail in MariaDB)
- perfschema.table_lock_aggregate_thread_4u_3t: not merged (didn't fail in MariaDB)
- sys_vars.sql_low_priority_updates_func: not merged
- include/thr_rwlock.h: not merged, rw_pr_lock_assert_write_owner and
rw_pr_lock_assert_not_write_owner are macros in MariaDB
- sql/handler.h: not merged (HA_NO_READ_LOCAL_LOCK)
- sql/mdl.cc: partially merged (MDL_SHARED_READ_ONLY only)
- sql/mdl.h: partially merged (MDL_SHARED_READ_ONLY only)
- sql/lock.cc: fully merged
- sql/sp_head.cc: not merged
- sql/sp_head.h: not merged
- sql/sql_base.cc: partially merged (MDL_SHARED_READ_ONLY only)
- sql/sql_base.h: not merged
- sql/sql_class.cc: fully merged
- sql/sql_class.h: fully merged
- sql/sql_handler.cc: merged partially (different solution in MariaDB)
- sql/sql_parse.cc: partially merged, mostly omitted low priority write part
- sql/sql_reload.cc: not merged comment change
- sql/sql_table.cc: not merged SNRW->X upgrade for IMPORT/DISCARD TABLESPACE
- sql/sql_view.cc: not merged
- sql/sql_yacc.yy: not merged (MDL_SHARED_WRITE_LOW_PRIO, MDL_SHARED_READ_ONLY)
- sql/table.cc: not merged (MDL_SHARED_WRITE_LOW_PRIO)
- sql/table.h: not merged (MDL_SHARED_WRITE_LOW_PRIO)
- sql/trigger.cc: not merged
- storage/innobase/handler/ha_innodb.cc: merged store_lock()/lock_count()
changes (in MDEV-7660), didn't merge HA_NO_READ_LOCAL_LOCK
- storage/innobase/handler/ha_innodb.h: fully merged in MDEV-7660
- storage/myisammrg/ha_myisammrg.cc: not merged comment change
- storage/perfschema/table_helper.cc: not merged (no MDL support in MariaDB PFS)
- unittest/gunit/mdl-t.cc: not merged
- unittest/gunit/mdl_sync-t.cc: not merged
MariaDB specific changes:
- handler.heap: different HANDLER solution, MDEV-7660
- handler.innodb: different HANDLER solution, MDEV-7660
- handler.interface: different HANDLER solution, MDEV-7660
- handler.myisam: different HANDLER solution, MDEV-7660
- main.mdl_sync: MDEV-7660 specific changes
- main.partition_debug_sync: removed test due to different HANDLER solution,
MDEV-7660
- main.truncate_coverage: removed test due to different HANDLER solution,
MDEV-7660
- mysql-test/include/mtr_warnings.sql: additional cleanup, MDEV-7660
- mysql-test/lib/v1/mtr_report.pl: additional cleanup, MDEV-7660
- plugin/metadata_lock_info/metadata_lock_info.cc: not in MySQL
- sql/sql_handler.cc: MariaDB specific fix for mysql_ha_read(), MDEV-7660
2016-12-08 14:20:46 +04:00
|
|
|
{ C_STRING_WITH_LEN("MDL_SHARED_READ_ONLY") },
|
2013-12-11 00:31:04 +09:00
|
|
|
{ C_STRING_WITH_LEN("MDL_SHARED_NO_WRITE") },
|
|
|
|
{ C_STRING_WITH_LEN("MDL_SHARED_NO_READ_WRITE") },
|
|
|
|
{ C_STRING_WITH_LEN("MDL_EXCLUSIVE") },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const LEX_STRING metadata_lock_info_duration[] = {
|
|
|
|
{ C_STRING_WITH_LEN("MDL_STATEMENT") },
|
|
|
|
{ C_STRING_WITH_LEN("MDL_TRANSACTION") },
|
|
|
|
{ C_STRING_WITH_LEN("MDL_EXPLICIT") },
|
|
|
|
};
|
|
|
|
|
|
|
|
static ST_FIELD_INFO i_s_metadata_lock_info_fields_info[] =
|
|
|
|
{
|
|
|
|
{"THREAD_ID", 20, MYSQL_TYPE_LONGLONG, 0,
|
|
|
|
MY_I_S_UNSIGNED, "thread_id", SKIP_OPEN_TABLE},
|
|
|
|
{"LOCK_MODE", 24, MYSQL_TYPE_STRING, 0,
|
|
|
|
MY_I_S_MAYBE_NULL, "lock_mode", SKIP_OPEN_TABLE},
|
|
|
|
{"LOCK_DURATION", 30, MYSQL_TYPE_STRING, 0,
|
|
|
|
MY_I_S_MAYBE_NULL, "lock_duration", SKIP_OPEN_TABLE},
|
|
|
|
{"LOCK_TYPE", 30, MYSQL_TYPE_STRING, 0,
|
|
|
|
MY_I_S_MAYBE_NULL, "lock_type", SKIP_OPEN_TABLE},
|
|
|
|
{"TABLE_SCHEMA", 64, MYSQL_TYPE_STRING, 0,
|
|
|
|
MY_I_S_MAYBE_NULL, "table_schema", SKIP_OPEN_TABLE},
|
|
|
|
{"TABLE_NAME", 64, MYSQL_TYPE_STRING, 0,
|
|
|
|
MY_I_S_MAYBE_NULL, "table_name", SKIP_OPEN_TABLE},
|
|
|
|
{NULL, 0, MYSQL_TYPE_STRING, 0, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct st_i_s_metadata_param
|
|
|
|
{
|
|
|
|
THD *thd;
|
|
|
|
TABLE *table;
|
|
|
|
};
|
|
|
|
|
|
|
|
int i_s_metadata_lock_info_fill_row(
|
|
|
|
MDL_ticket *mdl_ticket,
|
|
|
|
void *arg
|
|
|
|
) {
|
|
|
|
st_i_s_metadata_param *param = (st_i_s_metadata_param *) arg;
|
|
|
|
THD *thd = param->thd;
|
|
|
|
TABLE *table = param->table;
|
|
|
|
DBUG_ENTER("i_s_metadata_lock_info_fill_row");
|
|
|
|
MDL_context *mdl_ctx = mdl_ticket->get_ctx();
|
|
|
|
enum_mdl_type mdl_ticket_type = mdl_ticket->get_type();
|
|
|
|
MDL_key *mdl_key = mdl_ticket->get_key();
|
|
|
|
MDL_key::enum_mdl_namespace mdl_namespace = mdl_key->mdl_namespace();
|
|
|
|
table->field[0]->store((longlong) mdl_ctx->get_thread_id(), TRUE);
|
|
|
|
table->field[1]->set_notnull();
|
|
|
|
table->field[1]->store(
|
|
|
|
metadata_lock_info_lock_mode[(int) mdl_ticket_type].str,
|
|
|
|
metadata_lock_info_lock_mode[(int) mdl_ticket_type].length,
|
|
|
|
system_charset_info);
|
2016-06-23 12:16:20 +04:00
|
|
|
table->field[2]->set_null();
|
2013-12-11 00:31:04 +09:00
|
|
|
table->field[3]->set_notnull();
|
|
|
|
table->field[3]->store(
|
|
|
|
metadata_lock_info_lock_name[(int) mdl_namespace].str,
|
|
|
|
metadata_lock_info_lock_name[(int) mdl_namespace].length,
|
|
|
|
system_charset_info);
|
|
|
|
table->field[4]->set_notnull();
|
|
|
|
table->field[4]->store(mdl_key->db_name(),
|
|
|
|
mdl_key->db_name_length(), system_charset_info);
|
|
|
|
table->field[5]->set_notnull();
|
|
|
|
table->field[5]->store(mdl_key->name(),
|
|
|
|
mdl_key->name_length(), system_charset_info);
|
|
|
|
if (schema_table_store_record(thd, table))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int i_s_metadata_lock_info_fill_table(
|
|
|
|
THD *thd,
|
|
|
|
TABLE_LIST *tables,
|
|
|
|
COND *cond
|
|
|
|
) {
|
|
|
|
st_i_s_metadata_param param;
|
|
|
|
DBUG_ENTER("i_s_metadata_lock_info_fill_table");
|
|
|
|
param.table = tables->table;
|
|
|
|
param.thd = thd;
|
|
|
|
DBUG_RETURN(mdl_iterate(i_s_metadata_lock_info_fill_row, ¶m));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int i_s_metadata_lock_info_init(
|
|
|
|
void *p
|
|
|
|
) {
|
2016-03-30 00:35:11 -04:00
|
|
|
|
|
|
|
compile_time_assert(sizeof(metadata_lock_info_lock_name)/sizeof(LEX_STRING)
|
|
|
|
== MDL_key::NAMESPACE_END);
|
|
|
|
compile_time_assert(sizeof(metadata_lock_info_lock_mode)/sizeof(LEX_STRING)
|
|
|
|
== MDL_TYPE_END);
|
|
|
|
compile_time_assert(sizeof(metadata_lock_info_duration)/sizeof(LEX_STRING)
|
|
|
|
== MDL_DURATION_END);
|
|
|
|
|
2013-12-11 00:31:04 +09:00
|
|
|
ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *) p;
|
|
|
|
DBUG_ENTER("i_s_metadata_lock_info_init");
|
|
|
|
schema->fields_info = i_s_metadata_lock_info_fields_info;
|
|
|
|
schema->fill_table = i_s_metadata_lock_info_fill_table;
|
|
|
|
schema->idx_field1 = 0;
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int i_s_metadata_lock_info_deinit(
|
|
|
|
void *p
|
|
|
|
) {
|
|
|
|
DBUG_ENTER("i_s_metadata_lock_info_deinit");
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct st_mysql_information_schema i_s_metadata_lock_info_plugin =
|
|
|
|
{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION };
|
|
|
|
|
|
|
|
#ifdef MARIADB_BASE_VERSION
|
|
|
|
maria_declare_plugin(metadata_lock_info)
|
|
|
|
{
|
|
|
|
MYSQL_INFORMATION_SCHEMA_PLUGIN,
|
|
|
|
&i_s_metadata_lock_info_plugin,
|
|
|
|
"METADATA_LOCK_INFO",
|
|
|
|
"Kentoku Shiba",
|
|
|
|
"Metadata locking viewer",
|
|
|
|
PLUGIN_LICENSE_GPL,
|
|
|
|
i_s_metadata_lock_info_init,
|
|
|
|
i_s_metadata_lock_info_deinit,
|
|
|
|
0x0001,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2016-03-11 08:59:51 +01:00
|
|
|
MariaDB_PLUGIN_MATURITY_STABLE
|
2013-12-11 00:31:04 +09:00
|
|
|
}
|
|
|
|
maria_declare_plugin_end;
|
|
|
|
#else
|
|
|
|
mysql_declare_plugin(metadata_lock_info)
|
|
|
|
{
|
|
|
|
MYSQL_INFORMATION_SCHEMA_PLUGIN,
|
|
|
|
&i_s_metadata_lock_info_plugin,
|
|
|
|
"METADATA_LOCK_INFO",
|
|
|
|
"Kentoku Shiba",
|
|
|
|
"Metadata locking viewer",
|
|
|
|
PLUGIN_LICENSE_GPL,
|
|
|
|
i_s_metadata_lock_info_init,
|
|
|
|
i_s_metadata_lock_info_deinit,
|
|
|
|
0x0001,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
#if MYSQL_VERSION_ID >= 50600
|
|
|
|
0,
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
mysql_declare_plugin_end;
|
|
|
|
#endif
|