@@ -111,10 +111,6 @@ void MDL_key::init_psi_keys()
111111static 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
626583private:
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
646589static 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
653592extern " 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
0 commit comments