Skip to content

Commit 685c5ff

Browse files
author
Dmitry Lenev
committed
A pre-requisite for patch fixing bug #52044 "FLUSH TABLES
WITH READ LOCK and FLUSH TABLES <list> WITH READ LOCK are incompatible", which adds information about waits caused by FLUSH TABLES statement to deadlock detector in MDL subsystem. Remove API supporting caching of pointers to TABLE_SHARE object in MDL subsystem and all code related to it. The problem was that locking requirements of code implementing this API conflicted with locking requirements of code which adds information about waits caused by flushes to deadlock detector in MDL subsystem (the former needed to lock LOCK_open or its future equivalent while having write-lock on MDL_lock's rwlock, and the latter needs to be able to read-lock MDL_lock rwlock while owning LOCK_open or its future equivalent). Since caching of pointers to TABLE_SHARE objects in MDL subsystem didn't bring expected performance benefits we decided to remove caching API rather than try to come up with some complex solution for this problem. --BZR-- revision-id: [email protected] property-branch-nick: mysql-trunk-rt-pre-52044 testament3-sha1: 409d639d19f0344e8a51ff23d516df3d92b251ef
1 parent bb1efc0 commit 685c5ff

File tree

3 files changed

+45
-338
lines changed

3 files changed

+45
-338
lines changed

sql/mdl.cc

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ class MDL_lock
284284
public:
285285
/** The key of the object (data) being protected. */
286286
MDL_key key;
287-
/** A cached reference to the TABLE_SHARE. Protected by LOCK_open. */
288-
void *m_cached_object;
289287
/**
290288
Read-write lock protecting this lock context.
291289
@@ -362,16 +360,13 @@ class MDL_lock
362360

363361
MDL_lock(const MDL_key *key_arg)
364362
: key(key_arg),
365-
m_cached_object(NULL),
366363
m_ref_usage(0),
367364
m_ref_release(0),
368365
m_is_destroyed(FALSE)
369366
{
370367
mysql_prlock_init(key_MDL_lock_rwlock, &m_rwlock);
371368
}
372369

373-
/* Overridden for TABLE objects, to support TABLE_SHARE cache in MDL. */
374-
virtual void release_cached_object() {}
375370
virtual ~MDL_lock()
376371
{
377372
mysql_prlock_destroy(&m_rwlock);
@@ -460,25 +455,6 @@ class MDL_object_lock : public MDL_lock
460455
};
461456

462457

463-
/**
464-
A lock implementation for MDL_key::TABLE.
465-
*/
466-
467-
class MDL_table_lock: public MDL_object_lock
468-
{
469-
public:
470-
MDL_table_lock(const MDL_key *key_arg)
471-
: MDL_object_lock(key_arg)
472-
{ }
473-
#ifdef DISABLED_UNTIL_GRL_IS_MADE_PART_OF_MDL
474-
virtual void release_cached_object()
475-
{
476-
tdc_release_cached_share(&m_cached_object);
477-
}
478-
#endif
479-
};
480-
481-
482458
static MDL_map mdl_locks;
483459

484460
extern "C"
@@ -695,8 +671,6 @@ void MDL_map::remove(MDL_lock *lock)
695671
{
696672
uint ref_usage, ref_release;
697673

698-
lock->release_cached_object();
699-
700674
/*
701675
Destroy the MDL_lock object, but ensure that anyone that is
702676
holding a reference to the object is not remaining, if so he
@@ -860,8 +834,6 @@ inline MDL_lock *MDL_lock::create(const MDL_key *mdl_key)
860834
case MDL_key::GLOBAL:
861835
case MDL_key::SCHEMA:
862836
return new MDL_scoped_lock(mdl_key);
863-
case MDL_key::TABLE:
864-
return new MDL_table_lock(mdl_key);
865837
default:
866838
return new MDL_object_lock(mdl_key);
867839
}
@@ -1682,9 +1654,6 @@ MDL_context::try_acquire_lock_impl(MDL_request *mdl_request,
16821654

16831655
m_tickets.push_front(ticket);
16841656

1685-
if (ticket->get_type() == MDL_EXCLUSIVE)
1686-
ticket->clear_cached_object();
1687-
16881657
mdl_request->ticket= ticket;
16891658
}
16901659
else
@@ -1886,9 +1855,6 @@ MDL_context::acquire_lock(MDL_request *mdl_request, ulong lock_wait_timeout)
18861855
*/
18871856
DBUG_ASSERT(wait_status == MDL_wait::GRANTED);
18881857

1889-
if (ticket->get_type() == MDL_EXCLUSIVE)
1890-
ticket->clear_cached_object();
1891-
18921858
m_tickets.push_front(ticket);
18931859

18941860
mdl_request->ticket= ticket;
@@ -2451,75 +2417,6 @@ bool MDL_ticket::has_pending_conflicting_lock() const
24512417
}
24522418

24532419

2454-
/**
2455-
Associate pointer to an opaque object with a lock.
2456-
2457-
@param cached_object Pointer to the object
2458-
@param release_hook Cleanup function to be called when MDL subsystem
2459-
decides to remove lock or associate another object.
2460-
2461-
This is used to cache a pointer to TABLE_SHARE in the lock
2462-
structure. Such caching can save one acquisition of LOCK_open
2463-
and one table definition cache lookup for every table.
2464-
2465-
Since the pointer may be stored only inside an acquired lock,
2466-
the caching is only effective when there is more than one lock
2467-
granted on a given table.
2468-
2469-
This function has the following usage pattern:
2470-
- try to acquire an MDL lock
2471-
- when done, call for get_cached_object(). If it returns NULL, our
2472-
thread has the only lock on this table.
2473-
- look up TABLE_SHARE in the table definition cache
2474-
- call mdl_set_cache_object() to assign the share to the opaque pointer.
2475-
2476-
The release hook is invoked when the last shared metadata
2477-
lock on this name is released.
2478-
*/
2479-
2480-
void
2481-
MDL_ticket::set_cached_object(void *cached_object)
2482-
{
2483-
DBUG_ENTER("MDL_ticket::set_cached_object");
2484-
DBUG_PRINT("enter", ("db=%s name=%s cached_object=%p",
2485-
m_lock->key.db_name(), m_lock->key.name(),
2486-
cached_object));
2487-
mysql_mutex_assert_owner(&LOCK_open);
2488-
DBUG_ASSERT(m_lock->key.mdl_namespace() == MDL_key::TABLE);
2489-
DBUG_ASSERT(!m_lock->m_cached_object);
2490-
2491-
m_lock->m_cached_object= cached_object;
2492-
2493-
DBUG_VOID_RETURN;
2494-
}
2495-
2496-
2497-
/**
2498-
A helper function to flush the table share cached in MDL.
2499-
@pre The ticket is acquired.
2500-
*/
2501-
2502-
void MDL_ticket::clear_cached_object()
2503-
{
2504-
m_lock->release_cached_object();
2505-
}
2506-
2507-
2508-
/**
2509-
Get a pointer to an opaque object that associated with the lock.
2510-
2511-
@param ticket Lock ticket for the lock which the object is associated to.
2512-
2513-
@return Pointer to an opaque object associated with the lock.
2514-
*/
2515-
2516-
void *MDL_ticket::get_cached_object()
2517-
{
2518-
mysql_mutex_assert_owner(&LOCK_open);
2519-
return m_lock->m_cached_object;
2520-
}
2521-
2522-
25232420
/**
25242421
Releases metadata locks that were acquired after a specific savepoint.
25252422

sql/mdl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,6 @@ class MDL_ticket
398398
public:
399399
bool has_pending_conflicting_lock() const;
400400

401-
void *get_cached_object();
402-
void set_cached_object(void *cached_object);
403-
void clear_cached_object();
404401
MDL_context *get_ctx() const { return m_ctx; }
405402
bool is_upgradable_or_exclusive() const
406403
{
@@ -728,7 +725,6 @@ extern "C" const char *set_thd_proc_info(void *thd_arg, const char *info,
728725
const char *calling_function,
729726
const char *calling_file,
730727
const unsigned int calling_line);
731-
extern void tdc_release_cached_share(void *ptr);
732728
#ifndef DBUG_OFF
733729
extern mysql_mutex_t LOCK_open;
734730
#endif

0 commit comments

Comments
 (0)