Skip to content

Commit 903160e

Browse files
committed
MDEV-6089 - MySQL WL#7305 "Improve MDL scalability by using lock-free hash"
Removed MDL objects cache. Won't be needed when this MDEV is implemented.
1 parent 87b0cc9 commit 903160e

File tree

8 files changed

+35
-163
lines changed

8 files changed

+35
-163
lines changed

mysql-test/r/mysqld--help.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ The following options may be given as the first argument:
452452
in between
453453
--memlock Lock mysqld in memory.
454454
--metadata-locks-cache-size=#
455-
Size of unused metadata locks cache
455+
Unused
456456
--metadata-locks-hash-instances=#
457457
Number of metadata locks hash instances
458458
--min-examined-row-limit=#

mysql-test/suite/sys_vars/r/sysvars_server_embedded,32bit.rdiff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@
491491
VARIABLE_SCOPE GLOBAL
492492
-VARIABLE_TYPE BIGINT UNSIGNED
493493
+VARIABLE_TYPE INT UNSIGNED
494-
VARIABLE_COMMENTSize of unused metadata locks cache
494+
VARIABLE_COMMENTUnused
495495
NUMERIC_MIN_VALUE 1
496496
NUMERIC_MAX_VALUE 1048576
497497
@@ -1973,7 +1973,7 @@

mysql-test/suite/sys_vars/r/sysvars_server_embedded.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,7 @@ GLOBAL_VALUE_ORIGIN COMPILE-TIME
19881988
DEFAULT_VALUE 1024
19891989
VARIABLE_SCOPE GLOBAL
19901990
VARIABLE_TYPE BIGINT UNSIGNED
1991-
VARIABLE_COMMENTSize of unused metadata locks cache
1991+
VARIABLE_COMMENTUnused
19921992
NUMERIC_MIN_VALUE 1
19931993
NUMERIC_MAX_VALUE 1048576
19941994
NUMERIC_BLOCK_SIZE 1

mysql-test/suite/sys_vars/r/sysvars_server_notembedded,32bit.rdiff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@
491491
VARIABLE_SCOPE GLOBAL
492492
-VARIABLE_TYPE BIGINT UNSIGNED
493493
+VARIABLE_TYPE INT UNSIGNED
494-
VARIABLE_COMMENTSize of unused metadata locks cache
494+
VARIABLE_COMMENTUnused
495495
NUMERIC_MIN_VALUE 1
496496
NUMERIC_MAX_VALUE 1048576
497497
@@ -2169,7 +2169,7 @@

mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2156,7 +2156,7 @@ GLOBAL_VALUE_ORIGIN COMPILE-TIME
21562156
DEFAULT_VALUE 1024
21572157
VARIABLE_SCOPE GLOBAL
21582158
VARIABLE_TYPE BIGINT UNSIGNED
2159-
VARIABLE_COMMENTSize of unused metadata locks cache
2159+
VARIABLE_COMMENTUnused
21602160
NUMERIC_MIN_VALUE 1
21612161
NUMERIC_MAX_VALUE 1048576
21622162
NUMERIC_BLOCK_SIZE 1

sql/mdl.cc

Lines changed: 27 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ void MDL_key::init_psi_keys()
111111
static bool mdl_initialized= 0;
112112

113113

114-
class MDL_object_lock;
115-
class MDL_object_lock_cache_adapter;
116-
117-
118114
/**
119115
A partition in a collection of all MDL locks.
120116
MDL_map is partitioned for scalability reasons.
@@ -135,25 +131,6 @@ class MDL_map_partition
135131
HASH m_locks;
136132
/* Protects access to m_locks hash. */
137133
mysql_mutex_t m_mutex;
138-
/**
139-
Cache of (unused) MDL_lock objects available for re-use.
140-
141-
On some systems (e.g. Windows XP) constructing/destructing
142-
MDL_lock objects can be fairly expensive. We use this cache
143-
to avoid these costs in scenarios in which they can have
144-
significant negative effect on performance. For example, when
145-
there is only one thread constantly executing statements in
146-
auto-commit mode and thus constantly causing creation/
147-
destruction of MDL_lock objects for the tables it uses.
148-
149-
Note that this cache contains only MDL_object_lock objects.
150-
151-
Protected by m_mutex mutex.
152-
*/
153-
typedef I_P_List<MDL_object_lock, MDL_object_lock_cache_adapter,
154-
I_P_List_counter>
155-
Lock_cache;
156-
Lock_cache m_unused_locks_cache;
157134
friend int mdl_iterate(int (*)(MDL_ticket *, void *), void *);
158135
};
159136

@@ -577,26 +554,6 @@ class MDL_object_lock : public MDL_lock
577554
: MDL_lock(key_arg, map_part)
578555
{ }
579556

580-
/**
581-
Reset unused MDL_object_lock object to represent the lock context for a
582-
different object.
583-
*/
584-
void reset(const MDL_key *new_key)
585-
{
586-
/* We need to change only object's key. */
587-
key.mdl_key_init(new_key);
588-
/* m_granted and m_waiting should be already in the empty/initial state. */
589-
DBUG_ASSERT(is_empty());
590-
/* Object should not be marked as destroyed. */
591-
DBUG_ASSERT(! m_is_destroyed);
592-
/*
593-
Values of the rest of the fields should be preserved between old and
594-
new versions of the object. E.g., m_version and m_ref_usage/release
595-
should be kept intact to properly handle possible remaining references
596-
to the old version of the object.
597-
*/
598-
}
599-
600557
virtual const bitmap_t *incompatible_granted_types_bitmap() const
601558
{
602559
return m_granted_incompatible;
@@ -626,28 +583,10 @@ class MDL_object_lock : public MDL_lock
626583
private:
627584
static const bitmap_t m_granted_incompatible[MDL_TYPE_END];
628585
static const bitmap_t m_waiting_incompatible[MDL_TYPE_END];
629-
630-
public:
631-
/** Members for linking the object into the list of unused objects. */
632-
MDL_object_lock *next_in_cache, **prev_in_cache;
633-
};
634-
635-
636-
/**
637-
Helper class for linking MDL_object_lock objects into the unused objects list.
638-
*/
639-
class MDL_object_lock_cache_adapter :
640-
public I_P_List_adapter<MDL_object_lock, &MDL_object_lock::next_in_cache,
641-
&MDL_object_lock::prev_in_cache>
642-
{
643586
};
644587

645588

646589
static MDL_map mdl_locks;
647-
/**
648-
Start-up parameter for the maximum size of the unused MDL_lock objects cache.
649-
*/
650-
ulong mdl_locks_cache_size;
651590

652591

653592
extern "C"
@@ -839,10 +778,6 @@ MDL_map_partition::~MDL_map_partition()
839778
DBUG_ASSERT(!m_locks.records);
840779
mysql_mutex_destroy(&m_mutex);
841780
my_hash_free(&m_locks);
842-
843-
MDL_object_lock *lock;
844-
while ((lock= m_unused_locks_cache.pop_front()))
845-
MDL_lock::destroy(lock);
846781
}
847782

848783

@@ -908,48 +843,14 @@ MDL_lock* MDL_map_partition::find_or_insert(const MDL_key *mdl_key)
908843
mdl_key->ptr(),
909844
mdl_key->length())))
910845
{
911-
MDL_object_lock *unused_lock= NULL;
912-
913846
/*
914847
No lock object found so we need to create a new one
915848
or reuse an existing unused object.
916849
*/
917-
if (mdl_key->mdl_namespace() != MDL_key::SCHEMA &&
918-
m_unused_locks_cache.elements())
919-
{
920-
/*
921-
We need a MDL_object_lock type of object and the unused objects
922-
cache has some. Get the first object from the cache and set a new
923-
key for it.
924-
*/
925-
DBUG_ASSERT(mdl_key->mdl_namespace() != MDL_key::GLOBAL &&
926-
mdl_key->mdl_namespace() != MDL_key::COMMIT);
927-
928-
unused_lock= m_unused_locks_cache.pop_front();
929-
unused_lock->reset(mdl_key);
930-
931-
lock= unused_lock;
932-
}
933-
else
934-
{
935-
lock= MDL_lock::create(mdl_key, this);
936-
}
937-
850+
lock= MDL_lock::create(mdl_key, this);
938851
if (!lock || my_hash_insert(&m_locks, (uchar*)lock))
939852
{
940-
if (unused_lock)
941-
{
942-
/*
943-
Note that we can't easily destroy an object from cache here as it
944-
still might be referenced by other threads. So we simply put it
945-
back into the cache.
946-
*/
947-
m_unused_locks_cache.push_front(unused_lock);
948-
}
949-
else
950-
{
951-
MDL_lock::destroy(lock);
952-
}
853+
MDL_lock::destroy(lock);
953854
mysql_mutex_unlock(&m_mutex);
954855
return NULL;
955856
}
@@ -1126,55 +1027,32 @@ void MDL_map_partition::remove(MDL_lock *lock)
11261027
*/
11271028
lock->m_version++;
11281029

1129-
if ((lock->key.mdl_namespace() != MDL_key::SCHEMA) &&
1130-
(m_unused_locks_cache.elements() <
1131-
mdl_locks_cache_size/mdl_locks_hash_partitions))
1132-
{
1133-
/*
1134-
This is an object of MDL_object_lock type and the cache of unused
1135-
objects has not reached its maximum size yet. So instead of destroying
1136-
object we move it to the list of unused objects to allow its later
1137-
re-use with possibly different key. Any threads holding references to
1138-
this object (owning MDL_map_partition::m_mutex or MDL_lock::m_rwlock)
1139-
will notice this thanks to the fact that we have changed the
1140-
MDL_lock::m_version counter.
1141-
*/
1142-
DBUG_ASSERT(lock->key.mdl_namespace() != MDL_key::GLOBAL &&
1143-
lock->key.mdl_namespace() != MDL_key::COMMIT);
1144-
1145-
m_unused_locks_cache.push_front((MDL_object_lock*)lock);
1146-
mysql_mutex_unlock(&m_mutex);
1147-
mysql_prlock_unlock(&lock->m_rwlock);
1148-
}
1149-
else
1150-
{
1151-
/*
1152-
Destroy the MDL_lock object, but ensure that anyone that is
1153-
holding a reference to the object is not remaining, if so he
1154-
has the responsibility to release it.
1155-
1156-
Setting of m_is_destroyed to TRUE while holding _both_
1157-
MDL_map_partition::m_mutex and MDL_lock::m_rwlock mutexes transfers
1158-
the protection of m_ref_usage from MDL_map_partition::m_mutex to
1159-
MDL_lock::m_rwlock while removal of the object from the hash
1160-
(and cache of unused objects) makes it read-only. Therefore
1161-
whoever acquires MDL_lock::m_rwlock next will see the most up
1162-
to date version of m_ref_usage.
1163-
1164-
This means that when m_is_destroyed is TRUE and we hold the
1165-
MDL_lock::m_rwlock we can safely read the m_ref_usage
1166-
member.
1167-
*/
1168-
uint ref_usage, ref_release;
1030+
/*
1031+
Destroy the MDL_lock object, but ensure that anyone that is
1032+
holding a reference to the object is not remaining, if so he
1033+
has the responsibility to release it.
1034+
1035+
Setting of m_is_destroyed to TRUE while holding _both_
1036+
MDL_map_partition::m_mutex and MDL_lock::m_rwlock mutexes transfers
1037+
the protection of m_ref_usage from MDL_map_partition::m_mutex to
1038+
MDL_lock::m_rwlock while removal of the object from the hash
1039+
(and cache of unused objects) makes it read-only. Therefore
1040+
whoever acquires MDL_lock::m_rwlock next will see the most up
1041+
to date version of m_ref_usage.
1042+
1043+
This means that when m_is_destroyed is TRUE and we hold the
1044+
MDL_lock::m_rwlock we can safely read the m_ref_usage
1045+
member.
1046+
*/
1047+
uint ref_usage, ref_release;
11691048

1170-
lock->m_is_destroyed= TRUE;
1171-
ref_usage= lock->m_ref_usage;
1172-
ref_release= lock->m_ref_release;
1173-
mysql_mutex_unlock(&m_mutex);
1174-
mysql_prlock_unlock(&lock->m_rwlock);
1175-
if (ref_usage == ref_release)
1176-
MDL_lock::destroy(lock);
1177-
}
1049+
lock->m_is_destroyed= TRUE;
1050+
ref_usage= lock->m_ref_usage;
1051+
ref_release= lock->m_ref_release;
1052+
mysql_mutex_unlock(&m_mutex);
1053+
mysql_prlock_unlock(&lock->m_rwlock);
1054+
if (ref_usage == ref_release)
1055+
MDL_lock::destroy(lock);
11781056
}
11791057

11801058

sql/mdl.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -981,13 +981,6 @@ extern "C" unsigned long thd_get_thread_id(const MYSQL_THD thd);
981981
extern "C" int thd_is_connected(MYSQL_THD thd);
982982

983983

984-
/*
985-
Start-up parameter for the maximum size of the unused MDL_lock objects cache
986-
and a constant for its default value.
987-
*/
988-
extern ulong mdl_locks_cache_size;
989-
static const ulong MDL_LOCKS_CACHE_SIZE_DEFAULT = 1024;
990-
991984
/*
992985
Start-up parameter for the number of partitions of the hash
993986
containing all the MDL_lock objects and a constant for

sql/sys_vars.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,10 +1403,11 @@ static Sys_var_ulonglong Sys_max_heap_table_size(
14031403
VALID_RANGE(16384, (ulonglong)~(intptr)0), DEFAULT(16*1024*1024),
14041404
BLOCK_SIZE(1024));
14051405

1406+
static ulong mdl_locks_cache_size;
14061407
static Sys_var_ulong Sys_metadata_locks_cache_size(
1407-
"metadata_locks_cache_size", "Size of unused metadata locks cache",
1408+
"metadata_locks_cache_size", "Unused",
14081409
READ_ONLY GLOBAL_VAR(mdl_locks_cache_size), CMD_LINE(REQUIRED_ARG),
1409-
VALID_RANGE(1, 1024*1024), DEFAULT(MDL_LOCKS_CACHE_SIZE_DEFAULT),
1410+
VALID_RANGE(1, 1024*1024), DEFAULT(1024),
14101411
BLOCK_SIZE(1));
14111412

14121413
static Sys_var_ulong Sys_metadata_locks_hash_instances(

0 commit comments

Comments
 (0)