Commit c91ec6a5 authored by Monty's avatar Monty

Added Lock_time_ms and Table_catalog columns to metadata_lock_info

If compiled for debugging, LOCK_DURATION is also filled in.
parent 243dee74
This diff is collapsed.
......@@ -217,58 +217,51 @@ create table test.t1 (i int) engine=myisam;
create table mysqltest2.t2 like test.t1;
lock table test.t1 write, mysqltest2.t2 write;
--source ../suite/innodb/include/wait_all_purged.inc
--replace_column 1 #
--sorted_result
select * from information_schema.metadata_lock_info;
select LOCK_MODE,LOCK_TYPE, TABLE_SCHEMA,TABLE_NAME from information_schema.metadata_lock_info;
--error ER_TABLE_MUST_HAVE_COLUMNS
create or replace table test.t1;
show tables;
--replace_column 1 #
--sorted_result
select * from information_schema.metadata_lock_info;
select LOCK_MODE,LOCK_TYPE, TABLE_SCHEMA,TABLE_NAME from information_schema.metadata_lock_info;
--error ER_TABLE_MUST_HAVE_COLUMNS
create or replace table mysqltest2.t2;
--replace_column 1 #
--sorted_result
select * from information_schema.metadata_lock_info;
select LOCK_MODE,LOCK_TYPE, TABLE_SCHEMA,TABLE_NAME from information_schema.metadata_lock_info;
create table t1 (i int);
drop table t1;
create table test.t1 (i int);
create table mysqltest2.t2 like test.t1;
lock table test.t1 write, mysqltest2.t2 write;
--replace_column 1 #
--sorted_result
select * from information_schema.metadata_lock_info;
select LOCK_MODE,LOCK_TYPE, TABLE_SCHEMA,TABLE_NAME from information_schema.metadata_lock_info;
--error ER_DUP_FIELDNAME
create or replace table test.t1 (a int) select 1 as 'a', 2 as 'a';
show tables;
--replace_column 1 #
select LOCK_MODE,LOCK_TYPE, TABLE_SCHEMA,TABLE_NAME from information_schema.metadata_lock_info;
--sorted_result
select * from information_schema.metadata_lock_info;
select LOCK_MODE,LOCK_TYPE, TABLE_SCHEMA,TABLE_NAME from information_schema.metadata_lock_info;
--error ER_DUP_FIELDNAME
create or replace table mysqltest2.t2 (a int) select 1 as 'a', 2 as 'a';
--replace_column 1 #
--sorted_result
select * from information_schema.metadata_lock_info;
select LOCK_MODE,LOCK_TYPE, TABLE_SCHEMA,TABLE_NAME from information_schema.metadata_lock_info;
create table t1 (i int);
drop table t1;
create table test.t1 (i int) engine=innodb;
create table mysqltest2.t2 like test.t1;
lock table test.t1 write, mysqltest2.t2 write;
--replace_column 1 #
--sorted_result
select * from information_schema.metadata_lock_info;
select LOCK_MODE,LOCK_TYPE, TABLE_SCHEMA,TABLE_NAME from information_schema.metadata_lock_info;
unlock tables;
drop table test.t1,mysqltest2.t2;
create table test.t1 (i int) engine=aria transactional=1 checksum=1;
create table mysqltest2.t2 like test.t1;
lock table test.t1 write, mysqltest2.t2 write;
--replace_column 1 #
--sorted_result
select * from information_schema.metadata_lock_info;
select LOCK_MODE,LOCK_TYPE, TABLE_SCHEMA,TABLE_NAME from information_schema.metadata_lock_info;
unlock tables;
drop table t1;
......@@ -282,15 +275,13 @@ drop table test.t1;
--echo #
create table t1 (i int);
lock table t1 write;
--replace_column 1 #
--sorted_result
select * from information_schema.metadata_lock_info;
select LOCK_MODE,LOCK_TYPE, TABLE_SCHEMA,TABLE_NAME from information_schema.metadata_lock_info;
--error ER_DATA_TOO_LONG
create or replace table t1 (a char(1)) engine=Innodb select 'foo' as a;
show tables;
--replace_column 1 #
--sorted_result
select * from information_schema.metadata_lock_info;
select LOCK_MODE,LOCK_TYPE, TABLE_SCHEMA,TABLE_NAME from information_schema.metadata_lock_info;
create table t1 (i int);
drop table t1;
--enable_view_protocol
......@@ -366,22 +357,18 @@ drop view t1;
create table t1 (a int);
lock table t1 write, t2 read;
--replace_column 1 #
--sorted_result
select * from information_schema.metadata_lock_info;
select LOCK_MODE,LOCK_TYPE, TABLE_SCHEMA,TABLE_NAME from information_schema.metadata_lock_info;
create or replace table t1 (i int);
--replace_column 1 #
--sorted_result
select * from information_schema.metadata_lock_info;
select LOCK_MODE,LOCK_TYPE, TABLE_SCHEMA,TABLE_NAME from information_schema.metadata_lock_info;
create or replace table t1 like t2;
--replace_column 1 #
--sorted_result
select * from information_schema.metadata_lock_info;
select LOCK_MODE,LOCK_TYPE, TABLE_SCHEMA,TABLE_NAME from information_schema.metadata_lock_info;
create or replace table t1 select 1 as f1;
--replace_column 1 #
--sorted_result
select * from information_schema.metadata_lock_info;
select LOCK_MODE,LOCK_TYPE, TABLE_SCHEMA,TABLE_NAME from information_schema.metadata_lock_info;
drop table t1;
unlock tables;
......
......@@ -32,14 +32,25 @@ static const LEX_STRING metadata_lock_info_lock_name[] = {
{ C_STRING_WITH_LEN("User lock") },
};
#ifndef DBUG_OFF
static const LEX_STRING duration_name[] = {
{ C_STRING_WITH_LEN("statement") },
{ C_STRING_WITH_LEN("transaction") },
{ C_STRING_WITH_LEN("explicit") },
};
#endif
namespace Show {
static ST_FIELD_INFO i_s_metadata_lock_info_fields_info[] =
{
Column("THREAD_ID", ULonglong(20), NOT_NULL, "thread_id"),
Column("LOCK_MODE", Varchar(24), NULLABLE, "lock_mode"),
Column("LOCK_DURATION", Varchar(30), NULLABLE, "lock_duration"),
Column("LOCK_TYPE", Varchar(33), NULLABLE, "lock_type"),
Column("LOCK_MODE", Varchar(24), NOT_NULL, "lock_mode"),
Column("LOCK_DURATION", Varchar(33), NULLABLE, "lock_duration"),
Column("LOCK_TIME_MS", ULonglong(8), NULLABLE, "lock_time_ms"),
Column("LOCK_TYPE", Varchar(33), NOT_NULL, "lock_type"),
Column("TABLE_CATALOG", Name(), NULLABLE, "table_catalog"),
Column("TABLE_SCHEMA", Name(), NULLABLE, "table_schema"),
Column("TABLE_NAME", Name(), NULLABLE, "table_name"),
CEnd()
......@@ -71,17 +82,31 @@ int i_s_metadata_lock_info_fill_row(
table->field[0]->store((longlong) mdl_ctx->get_thread_id(), TRUE);
table->field[1]->set_notnull();
table->field[1]->store(mdl_ticket->get_type_name(), system_charset_info);
#ifndef DBUG_OFF
table->field[2]->set_notnull();
table->field[2]->store( &duration_name[mdl_ticket->m_duration],
system_charset_info);
#else
table->field[2]->set_null();
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);
#endif
if (!mdl_ticket->m_time)
table->field[3]->set_null();
else
{
ulonglong now= microsecond_interval_timer();
table->field[3]->set_notnull();
table->field[3]->store((now - mdl_ticket->m_time) / 1000, TRUE);
}
table->field[4]->set_notnull();
table->field[4]->store(mdl_key->db_name(),
mdl_key->db_name_length(), system_charset_info);
table->field[4]->store(&metadata_lock_info_lock_name[(int) mdl_namespace],
system_charset_info);
table->field[5]->set_notnull();
table->field[5]->store(mdl_key->name(),
table->field[5]->store(STRING_WITH_LEN("def"), system_charset_info);
table->field[6]->set_notnull();
table->field[6]->store(mdl_key->db_name(),
mdl_key->db_name_length(), system_charset_info);
table->field[7]->set_notnull();
table->field[7]->store(mdl_key->name(),
mdl_key->name_length(), system_charset_info);
if (schema_table_store_record(thd, table))
DBUG_RETURN(1);
......@@ -112,6 +137,7 @@ static int i_s_metadata_lock_info_init(
schema->fields_info = Show::i_s_metadata_lock_info_fields_info;
schema->fill_table = i_s_metadata_lock_info_fill_table;
schema->idx_field1 = 0;
metadata_lock_info_plugin_loaded= 1;
DBUG_RETURN(0);
}
......@@ -119,6 +145,7 @@ static int i_s_metadata_lock_info_deinit(
void *p
) {
DBUG_ENTER("i_s_metadata_lock_info_deinit");
metadata_lock_info_plugin_loaded= 0;
DBUG_RETURN(0);
}
......
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_duration lock_type table_schema table_name
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_type table_schema table_name
FLUSH TABLES WITH READ LOCK;
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_duration lock_type table_schema table_name
MDL_BACKUP_FTWRL2 NULL Backup lock
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_type table_schema table_name
MDL_BACKUP_FTWRL2 Backup lock
UNLOCK TABLES;
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_duration lock_type table_schema table_name
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_type table_schema table_name
CREATE TABLE IF NOT EXISTS t1(a int);
BEGIN;
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_duration lock_type table_schema table_name
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_type table_schema table_name
SELECT * FROM t1;
a
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_duration lock_type table_schema table_name
MDL_SHARED_READ NULL Table metadata lock test t1
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_type table_schema table_name
MDL_SHARED_READ Table metadata lock test t1
ROLLBACK;
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_duration lock_type table_schema table_name
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_type table_schema table_name
DROP TABLE t1;
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_duration lock_type table_schema table_name
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_type table_schema table_name
SELECT GET_LOCK('LOCK1',0);
GET_LOCK('LOCK1',0)
1
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_duration lock_type table_schema table_name
MDL_SHARED_NO_WRITE NULL User lock LOCK1
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_type table_schema table_name
MDL_SHARED_NO_WRITE User lock LOCK1
SELECT RELEASE_LOCK('LOCK1');
RELEASE_LOCK('LOCK1')
1
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_duration lock_type table_schema table_name
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
lock_mode lock_type table_schema table_name
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
FLUSH TABLES WITH READ LOCK;
--sorted_result
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
UNLOCK TABLES;
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
CREATE TABLE IF NOT EXISTS t1(a int);
BEGIN;
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
SELECT * FROM t1;
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
ROLLBACK;
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
DROP TABLE t1;
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
SELECT GET_LOCK('LOCK1',0);
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
SELECT RELEASE_LOCK('LOCK1');
SELECT lock_mode, lock_duration, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
SELECT lock_mode, lock_type, table_schema, table_name FROM information_schema.metadata_lock_info;
......@@ -2130,6 +2130,8 @@ MDL_context::try_acquire_lock_impl(MDL_request *mdl_request,
if (lock->can_grant_lock(mdl_request->type, this, false))
{
if (metadata_lock_info_plugin_loaded)
ticket->m_time= microsecond_interval_timer();
lock->m_granted.add_ticket(ticket);
mysql_prlock_unlock(&lock->m_rwlock);
......@@ -2201,6 +2203,7 @@ MDL_context::clone_ticket(MDL_request *mdl_request)
DBUG_ASSERT(mdl_request->ticket->has_stronger_or_equal_type(ticket->m_type));
ticket->m_lock= mdl_request->ticket->m_lock;
ticket->m_time= mdl_request->ticket->m_time;
mdl_request->ticket= ticket;
mysql_prlock_wrlock(&ticket->m_lock->m_rwlock);
......@@ -2344,6 +2347,8 @@ MDL_context::acquire_lock(MDL_request *mdl_request, double lock_wait_timeout)
}
#endif /* WITH_WSREP */
if (metadata_lock_info_plugin_loaded)
ticket->m_time= microsecond_interval_timer();
lock->m_waiting.add_ticket(ticket);
/*
......
......@@ -699,7 +699,17 @@ class MDL_ticket : public MDL_wait_for_subgraph, public ilist_node<>
*/
MDL_ticket *next_in_context;
MDL_ticket **prev_in_context;
#ifndef DBUG_OFF
/**
Duration of lock represented by this ticket.
Context public. Debug-only.
*/
public:
enum_mdl_duration m_duration;
#endif
ulonglong m_time;
#ifdef WITH_WSREP
void wsrep_report(bool debug) const;
#endif /* WITH_WSREP */
......@@ -741,10 +751,12 @@ class MDL_ticket : public MDL_wait_for_subgraph, public ilist_node<>
, enum_mdl_duration duration_arg
#endif
)
: m_type(type_arg),
:
#ifndef DBUG_OFF
m_duration(duration_arg),
#endif
m_time(0),
m_type(type_arg),
m_ctx(ctx_arg),
m_lock(NULL),
m_psi(NULL)
......@@ -764,13 +776,7 @@ class MDL_ticket : public MDL_wait_for_subgraph, public ilist_node<>
private:
/** Type of metadata lock. Externally accessible. */
enum enum_mdl_type m_type;
#ifndef DBUG_OFF
/**
Duration of lock represented by this ticket.
Context private. Debug-only.
*/
enum_mdl_duration m_duration;
#endif
/**
Context of the owner of the metadata lock ticket. Externally accessible.
*/
......
......@@ -761,7 +761,11 @@ char *opt_relay_logname = 0, *opt_relaylog_index_name=0;
char *opt_logname, *opt_slow_logname, *opt_bin_logname;
char *opt_binlog_index_name=0;
/*
Flag if the METADATA_LOCK_INFO is used. In this case we store the time
when we take a MDL lock.
*/
bool metadata_lock_info_plugin_loaded= 0;
/* Static variables */
......
......@@ -143,6 +143,7 @@ extern my_bool opt_old_style_user_limits, trust_function_creators;
extern uint opt_crash_binlog_innodb;
extern const char *shared_memory_base_name;
extern MYSQL_PLUGIN_IMPORT char *mysqld_unix_port;
extern MYSQL_PLUGIN_IMPORT bool metadata_lock_info_plugin_loaded;
extern my_bool opt_enable_shared_memory;
extern ulong opt_replicate_events_marked_for_skip;
extern char *default_tz_name;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment