#At file:///opt/local/work/next-4284-stage/ based on revid:kostja@stripped
3067 Konstantin Osipov 2010-01-28
Bug#46272, review fixes. Remove redundant methods.
modified:
sql/mdl.cc
sql/mdl.h
sql/sql_base.cc
sql/sql_show.cc
sql/sql_table.cc
=== modified file 'sql/mdl.cc'
--- a/sql/mdl.cc 2010-01-27 20:50:22 +0000
+++ b/sql/mdl.cc 2010-01-27 21:44:28 +0000
@@ -1032,34 +1032,6 @@ bool MDL_lock::has_pending_conflicting_l
/**
- Try to acquire global intention exclusive lock.
-
- @param[in/out] mdl_request Lock request object for lock to be acquired
-
- @retval FALSE Success. The lock may have not been acquired.
- One needs to check value of 'MDL_request::ticket'
- to find out what has happened.
- @retval TRUE Error.
-*/
-
-bool
-MDL_context::
-try_acquire_global_intention_exclusive_lock(MDL_request *mdl_request)
-{
- DBUG_ASSERT(mdl_request->key.mdl_namespace() == MDL_key::GLOBAL &&
- mdl_request->type == MDL_INTENTION_EXCLUSIVE);
-
- if (is_lock_owner(MDL_key::GLOBAL, "", "", MDL_SHARED))
- {
- my_error(ER_CANT_UPDATE_WITH_READLOCK, MYF(0));
- return TRUE;
- }
-
- return try_acquire_lock_impl(mdl_request);
-}
-
-
-/**
Acquire global intention exclusive lock.
@param[in] mdl_request Lock request object for lock to be acquired
@@ -1330,15 +1302,22 @@ MDL_context::try_acquire_lock_impl(MDL_r
/**
- Try to acquire one shared lock.
+ Try to acquire one lock.
Unlike exclusive locks, shared locks are acquired one by
one. This is interface is chosen to simplify introduction of
- the new locking API to the system. MDL_context::try_acquire_shared_lock()
+ the new locking API to the system. MDL_context::try_acquire_lock()
is currently used from open_table(), and there we have only one
table to work with.
- In future we may consider allocating multiple shared locks at once.
+ This function may also be used to try to acquire an exclusive
+ lock on a destination table, by ALTER TABLE ... RENAME.
+
+ Returns immediately without any side effect if encounters a lock
+ conflict. Otherwise takes the lock.
+
+ FIXME: Compared to lock_table_name_if_not_cached() (from 5.1)
+ it gives slightly more false negatives.
@param mdl_request [in/out] Lock request object for lock to be acquired
@@ -1351,11 +1330,9 @@ MDL_context::try_acquire_lock_impl(MDL_r
*/
bool
-MDL_context::try_acquire_shared_lock(MDL_request *mdl_request)
+MDL_context::try_acquire_lock(MDL_request *mdl_request)
{
- DBUG_ASSERT(mdl_request->is_shared());
- DBUG_ASSERT((mdl_request->type != MDL_SHARED_NO_WRITE &&
- mdl_request->type != MDL_SHARED_NO_READ_WRITE) ||
+ DBUG_ASSERT(mdl_request->type < MDL_SHARED_NO_WRITE ||
(is_lock_owner(MDL_key::GLOBAL, "", "", MDL_INTENTION_EXCLUSIVE)
&& ! is_lock_owner(MDL_key::GLOBAL, "", "", MDL_SHARED)));
@@ -1415,7 +1392,8 @@ MDL_context::clone_ticket(MDL_request *m
void notify_shared_lock(THD *thd, MDL_ticket *conflicting_ticket)
{
- if (conflicting_ticket->is_shared())
+ /* Only try to abort locks on which we back off. */
+ if (conflicting_ticket->get_type() < MDL_SHARED_NO_WRITE)
{
MDL_context *conflicting_ctx= conflicting_ticket->get_ctx();
THD *conflicting_thd= conflicting_ctx->get_thd();
@@ -1732,7 +1710,10 @@ MDL_context::upgrade_shared_lock_to_excl
safe_mutex_assert_not_owner(&LOCK_open);
- /* Allow this function to be called twice for the same lock request. */
+ /*
+ Do nothing if already upgraded. Used when we FLUSH TABLE under
+ LOCK TABLES and a table is listed twice in LOCK TABLES list.
+ */
if (mdl_ticket->m_type == MDL_EXCLUSIVE)
DBUG_RETURN(FALSE);
@@ -1830,40 +1811,6 @@ MDL_context::upgrade_shared_lock_to_excl
/**
- Try to acquire an exclusive lock on the object if there are
- no conflicting locks.
-
- Similar to the previous function, but returns
- immediately without any side effect if encounters a lock
- conflict. Otherwise takes the lock.
-
- This function is used in CREATE TABLE ... LIKE to acquire a lock
- on the table to be created. In this statement we don't want to
- block and wait for the lock if the table already exists.
-
- @param mdl_request [in] The lock request
- @param conflict [out] Indicates that conflicting lock exists
-
- @retval TRUE Failure: some error occurred (probably OOM).
- @retval FALSE Success: the lock might have not been acquired,
- check request.ticket to find out.
-
- FIXME: Compared to lock_table_name_if_not_cached()
- it gives slightly more false negatives.
-*/
-
-bool
-MDL_context::try_acquire_exclusive_lock(MDL_request *mdl_request)
-{
- DBUG_ASSERT(mdl_request->type == MDL_EXCLUSIVE);
- DBUG_ASSERT(is_lock_owner(MDL_key::GLOBAL, "", "", MDL_INTENTION_EXCLUSIVE)
- && ! is_lock_owner(MDL_key::GLOBAL, "", "", MDL_SHARED));
-
- return try_acquire_lock_impl(mdl_request);
-}
-
-
-/**
Implement a simple deadlock detection heuristic: check if there
are any pending exclusive locks which conflict with shared locks
held by this thread. In that case waiting can be circular,
@@ -1920,12 +1867,6 @@ MDL_context::wait_for_lock(MDL_request *
safe_mutex_assert_not_owner(&LOCK_open);
DBUG_ASSERT(mdl_request->ticket == NULL);
- /*
- To avoid starvation we don't wait if we have a conflict against
- request for MDL_EXCLUSIVE lock.
- */
- DBUG_ASSERT(mdl_request->is_shared() ||
- mdl_request->type == MDL_INTENTION_EXCLUSIVE);
while (!mysys_var->abort)
{
@@ -2121,7 +2062,11 @@ void MDL_ticket::downgrade_exclusive_loc
{
safe_mutex_assert_not_owner(&LOCK_open);
- if (is_shared())
+ /*
+ Do nothing if already donwgraded. Used when we FLUSH TABLE under
+ LOCK TABLES and a table is listed twice in LOCK TABLES list.
+ */
+ if (m_type != MDL_EXCLUSIVE)
return;
pthread_mutex_lock(&m_lock->m_mutex);
=== modified file 'sql/mdl.h'
--- a/sql/mdl.h 2010-01-27 16:44:35 +0000
+++ b/sql/mdl.h 2010-01-27 21:44:28 +0000
@@ -313,10 +313,6 @@ public:
DBUG_ASSERT(ticket == NULL);
type= type_arg;
}
- bool is_shared() const
- {
- return type > MDL_INTENTION_EXCLUSIVE && type < MDL_EXCLUSIVE;
- }
static MDL_request *create(MDL_key::enum_mdl_namespace mdl_namespace,
const char *db, const char *name,
@@ -396,10 +392,6 @@ public:
void set_cached_object(void *cached_object,
mdl_cached_object_release_hook release_hook);
MDL_context *get_ctx() const { return m_ctx; }
- bool is_shared() const
- {
- return m_type > MDL_INTENTION_EXCLUSIVE && m_type < MDL_EXCLUSIVE;
- }
bool is_upgradable_or_exclusive() const
{
return m_type == MDL_SHARED_NO_WRITE ||
@@ -484,11 +476,10 @@ public:
MDL_context();
void destroy();
- bool try_acquire_shared_lock(MDL_request *mdl_request);
+ bool try_acquire_lock(MDL_request *mdl_request);
bool acquire_lock(MDL_request *mdl_request);
bool acquire_exclusive_lock(MDL_request *mdl_request);
bool acquire_exclusive_locks(MDL_request_list *requests);
- bool try_acquire_exclusive_lock(MDL_request *mdl_request);
bool upgrade_shared_lock_to_exclusive(MDL_ticket *mdl_ticket);
bool clone_ticket(MDL_request *mdl_request);
@@ -538,7 +529,6 @@ public:
inline THD *get_thd() const { return m_thd; }
- bool try_acquire_global_intention_exclusive_lock(MDL_request *mdl_request);
bool acquire_global_intention_exclusive_lock(MDL_request *mdl_request);
/**
=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc 2010-01-27 16:44:35 +0000
+++ b/sql/sql_base.cc 2010-01-27 21:44:28 +0000
@@ -2392,7 +2392,7 @@ open_table_get_mdl_lock(THD *thd, TABLE_
ot_ctx->add_request(mdl_request);
- if (thd->mdl_context.try_acquire_shared_lock(mdl_request))
+ if (thd->mdl_context.try_acquire_lock(mdl_request))
return 1;
if (mdl_request->ticket == NULL)
@@ -4013,7 +4013,7 @@ open_and_process_routine(THD *thd, Query
*/
DBUG_ASSERT(rt->mdl_request.type == MDL_SHARED);
- if (thd->mdl_context.try_acquire_shared_lock(&rt->mdl_request))
+ if (thd->mdl_context.try_acquire_lock(&rt->mdl_request))
DBUG_RETURN(TRUE);
if (rt->mdl_request.ticket == NULL)
=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc 2010-01-22 09:38:20 +0000
+++ b/sql/sql_show.cc 2010-01-27 21:44:28 +0000
@@ -3085,7 +3085,7 @@ try_acquire_high_prio_shared_mdl_lock(TH
table->mdl_request.init(MDL_key::TABLE, table->db, table->table_name,
MDL_SHARED_HIGH_PRIO);
while (!(error=
- thd->mdl_context.try_acquire_shared_lock(&table->mdl_request)) &&
+ thd->mdl_context.try_acquire_lock(&table->mdl_request)) &&
!table->mdl_request.ticket && !can_deadlock)
{
if ((error= thd->mdl_context.wait_for_lock(&table->mdl_request)))
=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc 2010-01-26 17:46:07 +0000
+++ b/sql/sql_table.cc 2010-01-27 21:44:28 +0000
@@ -2201,7 +2201,7 @@ err:
Under LOCK TABLES we should release meta-data locks on the tables
which were dropped. Otherwise we can rely on close_thread_tables()
doing this. Unfortunately in this case we are likely to get more
- false positives in try_acquire_exclusive_lock() function. So
+ false positives in try_acquire_lock() function. So
it makes sense to remove exclusive meta-data locks in all cases.
Leave LOCK TABLES mode if we managed to drop all tables which were
@@ -6574,7 +6574,7 @@ view_err:
"", "",
MDL_INTENTION_EXCLUSIVE));
- if (thd->mdl_context.try_acquire_exclusive_lock(&target_mdl_request))
+ if (thd->mdl_context.try_acquire_lock(&target_mdl_request))
DBUG_RETURN(TRUE);
if (target_mdl_request.ticket == NULL)
{
Attachment: [text/bzr-bundle] bzr/kostja@sun.com-20100127214428-x6plwphd4vx4ewuu.bundle
| Thread |
|---|
| • bzr commit into mysql-5.6-next-mr branch (kostja:3067) Bug#46272 | Konstantin Osipov | 27 Jan |