Skip to content

Commit 95c8816

Browse files
committed
Bug#20652173 MDL FOR TABLESPACES MUST BE REFLECTED IN P_S
MDL for tablespaces was introduced without the required updates to the P_S implementation. This bugfix adds the required P_S changes to map from the new MDL namespace to an entry in a P_S internal enumeration, mapping to correct object type name, etc. A new test case is added to the MDL tablespace test to verify correct P_S output as well as proper synchronization with I_S contents.
1 parent 44395ac commit 95c8816

File tree

5 files changed

+165
-4
lines changed

5 files changed

+165
-4
lines changed

mysql-test/r/mdl_tablespace.result

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
# table related DDL be rejected. Verify that implicit
6464
# invalid tablespace names (e.g., present in an .FRM
6565
# file from a previous MySQL version) are ignored.
66-
#
66+
# 16. Verify correct P_S information.
6767
###########################################################
6868
#
6969
# Test setup: Create reusable connections:
@@ -787,6 +787,58 @@ DROP TABLE table_like;
787787
DROP TABLESPACE ts1;
788788
SET DEBUG_SYNC= 'RESET';
789789
###########################################################
790+
# TC16. Verify correct P_S information.
791+
#
792+
#
793+
# Start executing CREATE TABLESPACE, but wait after
794+
# getting the MDL X lock on the tablespace name.
795+
connection con1;
796+
SET DEBUG_SYNC= 'after_wait_locked_tablespace_name
797+
SIGNAL got_lock_con1
798+
WAIT_FOR cont_con1';
799+
CREATE TABLESPACE ts1 ADD DATAFILE 'ts1_1.ibd';
800+
#
801+
# Start executing ALTER TABLESPACE.
802+
connection con2;
803+
SET DEBUG_SYNC= 'now WAIT_FOR got_lock_con1';
804+
ALTER TABLESPACE ts1 ADD DATAFILE 'ts1_2.ibd';
805+
#
806+
# Verify that the ALTER TABLESPACE is waiting for an MDL
807+
# X lock on the tablespace name (not logged). Then, verify
808+
# that we are also seeing the correct entries in the P_S MDL
809+
# and events_waits_current tables. Further, signal con1 to
810+
# make the CREATE TABLESPACE proceed.
811+
connection default;
812+
SELECT object_type, object_name, lock_type, lock_duration, lock_status
813+
FROM performance_schema.metadata_locks
814+
WHERE object_type LIKE 'TABLESPACE';
815+
object_type object_name lock_type lock_duration lock_status
816+
TABLESPACE ts1 EXCLUSIVE TRANSACTION GRANTED
817+
TABLESPACE ts1 EXCLUSIVE TRANSACTION PENDING
818+
SELECT event_name, object_name, object_type, operation
819+
FROM performance_schema.events_waits_current
820+
WHERE object_type LIKE 'TABLESPACE';
821+
event_name object_name object_type operation
822+
wait/lock/metadata/sql/mdl ts1 TABLESPACE metadata lock
823+
SET DEBUG_SYNC= 'now SIGNAL cont_con1';
824+
#
825+
# Now, the tablespace MDL information will eventually be
826+
# gone from both I_S and P_S, except it will remain in the
827+
# P_S event wait history.
828+
SELECT event_name, object_name, object_type, operation
829+
FROM performance_schema.events_waits_history
830+
WHERE object_type LIKE 'TABLESPACE' AND object_name LIKE 'ts1';
831+
event_name object_name object_type operation
832+
wait/lock/metadata/sql/mdl ts1 TABLESPACE metadata lock
833+
#
834+
# Reap the connections, reset DEBUG_SYNC and drop objects.
835+
connection con1;
836+
connection con2;
837+
ERROR 42000: The storage engine for the table doesn't support ALTER TABLESPACE
838+
connection default;
839+
DROP TABLESPACE ts1;
840+
SET DEBUG_SYNC= 'RESET';
841+
###########################################################
790842
#
791843
# Test teardown: Disconnect
792844
#

mysql-test/t/mdl_tablespace.test

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
--echo # table related DDL be rejected. Verify that implicit
6969
--echo # invalid tablespace names (e.g., present in an .FRM
7070
--echo # file from a previous MySQL version) are ignored.
71-
--echo #
71+
--echo # 16. Verify correct P_S information.
7272
--echo ###########################################################
7373
--echo #
7474
--echo # Test setup: Create reusable connections:
@@ -1043,6 +1043,100 @@ DROP TABLESPACE ts1;
10431043
SET DEBUG_SYNC= 'RESET';
10441044

10451045

1046+
--echo ###########################################################
1047+
--echo # TC16. Verify correct P_S information.
1048+
--echo #
1049+
1050+
--echo #
1051+
--echo # Start executing CREATE TABLESPACE, but wait after
1052+
--echo # getting the MDL X lock on the tablespace name.
1053+
1054+
--connection con1
1055+
SET DEBUG_SYNC= 'after_wait_locked_tablespace_name
1056+
SIGNAL got_lock_con1
1057+
WAIT_FOR cont_con1';
1058+
--send CREATE TABLESPACE ts1 ADD DATAFILE 'ts1_1.ibd'
1059+
1060+
--echo #
1061+
--echo # Start executing ALTER TABLESPACE.
1062+
1063+
--connection con2
1064+
SET DEBUG_SYNC= 'now WAIT_FOR got_lock_con1';
1065+
--send ALTER TABLESPACE ts1 ADD DATAFILE 'ts1_2.ibd'
1066+
1067+
--echo #
1068+
--echo # Verify that the ALTER TABLESPACE is waiting for an MDL
1069+
--echo # X lock on the tablespace name (not logged). Then, verify
1070+
--echo # that we are also seeing the correct entries in the P_S MDL
1071+
--echo # and events_waits_current tables. Further, signal con1 to
1072+
--echo # make the CREATE TABLESPACE proceed.
1073+
1074+
--connection default
1075+
LET $wait_condition=
1076+
SELECT COUNT(*) = 1 FROM information_schema.processlist
1077+
WHERE state LIKE 'Waiting for tablespace metadata lock' AND
1078+
info LIKE 'ALTER TABLESPACE%';
1079+
--source include/wait_condition.inc
1080+
1081+
LET $wait_condition=
1082+
SELECT COUNT(*) = 2 FROM performance_schema.metadata_locks
1083+
WHERE object_type LIKE 'TABLESPACE';
1084+
--source include/wait_condition.inc
1085+
1086+
SELECT object_type, object_name, lock_type, lock_duration, lock_status
1087+
FROM performance_schema.metadata_locks
1088+
WHERE object_type LIKE 'TABLESPACE';
1089+
1090+
LET $wait_condition=
1091+
SELECT COUNT(*) = 1 FROM performance_schema.events_waits_current
1092+
WHERE object_type LIKE 'TABLESPACE';
1093+
--source include/wait_condition.inc
1094+
1095+
SELECT event_name, object_name, object_type, operation
1096+
FROM performance_schema.events_waits_current
1097+
WHERE object_type LIKE 'TABLESPACE';
1098+
1099+
SET DEBUG_SYNC= 'now SIGNAL cont_con1';
1100+
1101+
--echo #
1102+
--echo # Now, the tablespace MDL information will eventually be
1103+
--echo # gone from both I_S and P_S, except it will remain in the
1104+
--echo # P_S event wait history.
1105+
1106+
LET $wait_condition=
1107+
SELECT COUNT(*) = 0 FROM information_schema.processlist
1108+
WHERE state LIKE 'Waiting for tablespace metadata lock' AND
1109+
info LIKE 'ALTER TABLESPACE%';
1110+
--source include/wait_condition.inc
1111+
1112+
LET $wait_condition=
1113+
SELECT COUNT(*) = 0 FROM performance_schema.metadata_locks
1114+
WHERE object_type LIKE 'TABLESPACE';
1115+
--source include/wait_condition.inc
1116+
1117+
LET $wait_condition=
1118+
SELECT COUNT(*) = 1 FROM performance_schema.events_waits_history
1119+
WHERE object_type LIKE 'TABLESPACE' AND object_name LIKE 'ts1';
1120+
--source include/wait_condition.inc
1121+
1122+
SELECT event_name, object_name, object_type, operation
1123+
FROM performance_schema.events_waits_history
1124+
WHERE object_type LIKE 'TABLESPACE' AND object_name LIKE 'ts1';
1125+
1126+
--echo #
1127+
--echo # Reap the connections, reset DEBUG_SYNC and drop objects.
1128+
1129+
--connection con1
1130+
--reap
1131+
--connection con2
1132+
# InnoDB does not support ALTER TABLESPACE
1133+
--error ER_CHECK_NOT_IMPLEMENTED
1134+
--reap
1135+
--connection default
1136+
DROP TABLESPACE ts1;
1137+
SET DEBUG_SYNC= 'RESET';
1138+
1139+
10461140
--echo ###########################################################
10471141
--echo #
10481142
--echo # Test teardown: Disconnect

storage/perfschema/pfs_column_types.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,13 @@ enum enum_object_type
210210
OBJECT_TYPE_GLOBAL= 7,
211211
OBJECT_TYPE_SCHEMA= 8,
212212
OBJECT_TYPE_COMMIT= 9,
213-
OBJECT_TYPE_USER_LEVEL_LOCK= 10
213+
OBJECT_TYPE_USER_LEVEL_LOCK= 10,
214+
OBJECT_TYPE_TABLESPACE= 11
214215
};
215216
/** Integer, first value of @sa enum_object_type. */
216217
#define FIRST_OBJECT_TYPE (static_cast<int> (OBJECT_TYPE_EVENT))
217218
/** Integer, last value of @sa enum_object_type. */
218-
#define LAST_OBJECT_TYPE (static_cast<int> (OBJECT_TYPE_USER_LEVEL_LOCK))
219+
#define LAST_OBJECT_TYPE (static_cast<int> (OBJECT_TYPE_TABLESPACE))
219220
/** Integer, number of values of @sa enum_object_type. */
220221
#define COUNT_OBJECT_TYPE (LAST_OBJECT_TYPE - FIRST_OBJECT_TYPE + 1)
221222

storage/perfschema/table_events_waits.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ int table_events_waits_common::make_metadata_lock_object_columns(PFS_events_wait
425425
m_row.m_object_schema_length= 0;
426426
m_row.m_object_name_length= mdl->name_length();
427427
break;
428+
case MDL_key::TABLESPACE:
429+
m_row.m_object_type= "TABLESPACE";
430+
m_row.m_object_type_length= 10;
431+
m_row.m_object_schema_length= 0;
432+
m_row.m_object_name_length= mdl->name_length();
433+
break;
428434
case MDL_key::NAMESPACE_END:
429435
default:
430436
m_row.m_object_type_length= 0;

storage/perfschema/table_helper.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ int PFS_object_row::make_row(const MDL_key *mdl)
265265
m_schema_name_length= 0;
266266
m_object_name_length= mdl->name_length();
267267
break;
268+
case MDL_key::TABLESPACE:
269+
m_object_type= OBJECT_TYPE_TABLESPACE;
270+
m_schema_name_length= 0;
271+
m_object_name_length= mdl->name_length();
272+
break;
268273
case MDL_key::NAMESPACE_END:
269274
default:
270275
m_object_type= NO_OBJECT_TYPE;
@@ -542,6 +547,9 @@ void set_field_object_type(Field *f, enum_object_type object_type)
542547
case OBJECT_TYPE_USER_LEVEL_LOCK:
543548
PFS_engine_table::set_field_varchar_utf8(f, "USER LEVEL LOCK", 15);
544549
break;
550+
case OBJECT_TYPE_TABLESPACE:
551+
PFS_engine_table::set_field_varchar_utf8(f, "TABLESPACE", 10);
552+
break;
545553
case NO_OBJECT_TYPE:
546554
default:
547555
DBUG_ASSERT(false);

0 commit comments

Comments
 (0)